aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--CREDITS4
-rw-r--r--Documentation/ABI/testing/sysfs-class-led9
-rw-r--r--Documentation/DocBook/mtdnand.tmpl2
-rw-r--r--Documentation/cgroups/cgroup_event_listener.c2
-rw-r--r--Documentation/cgroups/cgroups.txt8
-rw-r--r--Documentation/cgroups/memcg_test.txt2
-rw-r--r--Documentation/email-clients.txt50
-rw-r--r--Documentation/feature-removal-schedule.txt24
-rw-r--r--Documentation/filesystems/porting9
-rw-r--r--Documentation/gpio.txt2
-rw-r--r--Documentation/hwmon/adm92402
-rw-r--r--Documentation/hwmon/ads78282
-rw-r--r--Documentation/hwmon/dme173712
-rw-r--r--Documentation/hwmon/w83627hf22
-rw-r--r--Documentation/hwmon/w837932
-rw-r--r--Documentation/input/ff.txt4
-rw-r--r--Documentation/ioctl/ioctl-number.txt2
-rw-r--r--Documentation/iostats.txt2
-rw-r--r--Documentation/kdump/kdump.txt15
-rw-r--r--Documentation/kernel-parameters.txt9
-rw-r--r--Documentation/ko_KR/HOWTO4
-rw-r--r--Documentation/kprobes.txt2
-rw-r--r--Documentation/kvm/api.txt180
-rw-r--r--Documentation/kvm/cpuid.txt3
-rw-r--r--Documentation/kvm/msr.txt36
-rw-r--r--Documentation/lguest/lguest.txt7
-rw-r--r--Documentation/magic-number.txt2
-rw-r--r--Documentation/networking/bridge.txt4
-rw-r--r--Documentation/networking/caif/spi_porting.txt2
-rw-r--r--Documentation/networking/dccp.txt4
-rw-r--r--Documentation/networking/generic_netlink.txt2
-rw-r--r--Documentation/nfc/nfc-pn544.txt114
-rw-r--r--Documentation/powerpc/booting-without-of.txt2
-rw-r--r--Documentation/pps/pps.txt46
-rw-r--r--Documentation/scheduler/00-INDEX2
-rw-r--r--Documentation/scsi/ChangeLog.lpfc2
-rw-r--r--Documentation/serial/tty.txt2
-rw-r--r--Documentation/sound/alsa/ALSA-Configuration.txt20
-rw-r--r--Documentation/sound/alsa/HD-Audio-Models.txt1
-rw-r--r--Documentation/sysctl/00-INDEX2
-rw-r--r--Documentation/sysctl/kernel.txt14
-rw-r--r--Documentation/timers/timer_stats.txt2
-rw-r--r--Documentation/trace/events.txt8
-rw-r--r--Documentation/w1/slaves/00-INDEX2
-rw-r--r--Documentation/w1/slaves/w1_ds242347
-rw-r--r--Documentation/x86/boot.txt6
-rw-r--r--Documentation/xz.txt121
-rw-r--r--Documentation/zh_CN/HOWTO4
-rw-r--r--Documentation/zh_CN/SubmittingDrivers2
-rw-r--r--MAINTAINERS66
-rw-r--r--arch/alpha/kernel/time.c2
-rw-r--r--arch/arm/common/it8152.c2
-rw-r--r--arch/arm/common/vic.c2
-rw-r--r--arch/arm/mach-at91/board-ecbat91.c6
-rw-r--r--arch/arm/mach-at91/pm.c2
-rw-r--r--arch/arm/mach-bcmring/csp/chipc/chipcHw.c2
-rw-r--r--arch/arm/mach-bcmring/csp/dmac/dmacHw.c2
-rw-r--r--arch/arm/mach-bcmring/csp/dmac/dmacHw_extra.c2
-rw-r--r--arch/arm/mach-bcmring/csp/tmr/tmrHw.c2
-rw-r--r--arch/arm/mach-bcmring/dma.c2
-rw-r--r--arch/arm/mach-bcmring/include/csp/dmacHw.h2
-rw-r--r--arch/arm/mach-bcmring/include/csp/tmrHw.h4
-rw-r--r--arch/arm/mach-bcmring/include/mach/csp/dmacHw_priv.h2
-rw-r--r--arch/arm/mach-bcmring/include/mach/csp/dmacHw_reg.h2
-rw-r--r--arch/arm/mach-davinci/pm.c2
-rw-r--r--arch/arm/mach-gemini/include/mach/hardware.h2
-rw-r--r--arch/arm/mach-imx/mach-pcm038.c4
-rw-r--r--arch/arm/mach-imx/pm-imx27.c2
-rw-r--r--arch/arm/mach-kirkwood/openrd-setup.c2
-rw-r--r--arch/arm/mach-lpc32xx/pm.c2
-rw-r--r--arch/arm/mach-msm/include/mach/entry-macro-qgic.S2
-rw-r--r--arch/arm/mach-msm/io.c2
-rw-r--r--arch/arm/mach-mx3/mach-mx31_3ds.c4
-rw-r--r--arch/arm/mach-mx3/mach-mx31moboard.c4
-rw-r--r--arch/arm/mach-omap1/pm.c2
-rw-r--r--arch/arm/mach-omap2/Makefile3
-rw-r--r--arch/arm/mach-omap2/board-3430sdp.c12
-rw-r--r--arch/arm/mach-omap2/board-3630sdp.c1
-rw-r--r--arch/arm/mach-omap2/board-am3517evm.c23
-rw-r--r--arch/arm/mach-omap2/board-cm-t35.c23
-rw-r--r--arch/arm/mach-omap2/board-devkit8000.c26
-rw-r--r--arch/arm/mach-omap2/board-igep0020.c12
-rw-r--r--arch/arm/mach-omap2/board-omap3beagle.c12
-rw-r--r--arch/arm/mach-omap2/board-omap3evm.c12
-rw-r--r--arch/arm/mach-omap2/board-omap3stalker.c23
-rw-r--r--arch/arm/mach-omap2/board-zoom-display.c168
-rw-r--r--arch/arm/mach-omap2/board-zoom-peripherals.c49
-rw-r--r--arch/arm/mach-omap2/board-zoom.c1
-rw-r--r--arch/arm/mach-omap2/cpuidle34xx.c2
-rw-r--r--arch/arm/mach-omap2/include/mach/board-zoom.h3
-rw-r--r--arch/arm/mach-omap2/pm24xx.c2
-rw-r--r--arch/arm/mach-omap2/pm34xx.c2
-rw-r--r--arch/arm/mach-omap2/pm44xx.c2
-rw-r--r--arch/arm/mach-omap2/serial.c2
-rw-r--r--arch/arm/mach-pnx4008/pm.c2
-rw-r--r--arch/arm/mach-pxa/mxm8x10.c2
-rw-r--r--arch/arm/mach-pxa/pm.c2
-rw-r--r--arch/arm/mach-pxa/sharpsl_pm.c2
-rw-r--r--arch/arm/mach-s3c2410/mach-h1940.c2
-rw-r--r--arch/arm/mach-s3c2440/mach-rx1950.c2
-rw-r--r--arch/arm/mach-s3c64xx/clock.c2
-rw-r--r--arch/arm/mach-s3c64xx/dev-audio.c75
-rw-r--r--arch/arm/mach-s3c64xx/dma.c2
-rw-r--r--arch/arm/mach-s3c64xx/mach-smdk6410.c2
-rw-r--r--arch/arm/mach-s5p6442/dev-audio.c44
-rw-r--r--arch/arm/mach-s5p64x0/clock-s5p6440.c2
-rw-r--r--arch/arm/mach-s5p64x0/clock-s5p6450.c2
-rw-r--r--arch/arm/mach-s5p64x0/dev-audio.c55
-rw-r--r--arch/arm/mach-s5pc100/dev-audio.c56
-rw-r--r--arch/arm/mach-s5pc100/mach-smdkc100.c2
-rw-r--r--arch/arm/mach-s5pv210/clock.c10
-rw-r--r--arch/arm/mach-s5pv210/dev-audio.c58
-rw-r--r--arch/arm/mach-s5pv310/Kconfig1
-rw-r--r--arch/arm/mach-s5pv310/Makefile3
-rw-r--r--arch/arm/mach-s5pv310/dev-audio.c364
-rw-r--r--arch/arm/mach-s5pv310/dma.c168
-rw-r--r--arch/arm/mach-s5pv310/include/mach/dma.h26
-rw-r--r--arch/arm/mach-s5pv310/include/mach/irqs.h3
-rw-r--r--arch/arm/mach-s5pv310/include/mach/map.h21
-rw-r--r--arch/arm/mach-sa1100/pm.c2
-rw-r--r--arch/arm/mach-shmobile/board-ap4evb.c5
-rw-r--r--arch/arm/mach-spear3xx/spear300.c4
-rw-r--r--arch/arm/mach-spear3xx/spear310.c2
-rw-r--r--arch/arm/mach-spear3xx/spear320.c2
-rw-r--r--arch/arm/mach-spear3xx/spear3xx.c6
-rw-r--r--arch/arm/mach-spear6xx/spear6xx.c4
-rw-r--r--arch/arm/mach-u300/Kconfig2
-rw-r--r--arch/arm/mach-u300/include/mach/coh901318.h4
-rw-r--r--arch/arm/mach-ux500/board-mop500-regulators.c153
-rw-r--r--arch/arm/mach-ux500/board-mop500-regulators.h19
-rw-r--r--arch/arm/mach-ux500/board-mop500.c3
-rw-r--r--arch/arm/mm/flush.c1
-rw-r--r--arch/arm/plat-mxc/include/mach/irqs.h2
-rw-r--r--arch/arm/plat-omap/include/plat/display.h9
-rw-r--r--arch/arm/plat-omap/include/plat/omap_hwmod.h2
-rw-r--r--arch/arm/plat-omap/include/plat/panel-generic-dpi.h37
-rw-r--r--arch/arm/plat-s3c24xx/devs.c19
-rw-r--r--arch/arm/plat-samsung/Makefile1
-rw-r--r--arch/arm/plat-samsung/dev-asocdma.c25
-rw-r--r--arch/arm/plat-samsung/include/plat/audio.h24
-rw-r--r--arch/arm/plat-samsung/include/plat/devs.h11
-rw-r--r--arch/arm/plat-samsung/pm.c2
-rw-r--r--arch/avr32/mach-at32ap/pm.c2
-rw-r--r--arch/blackfin/mach-bf537/include/mach/defBF534.h2
-rw-r--r--arch/blackfin/mach-common/pm.c2
-rw-r--r--arch/cris/arch-v32/lib/nand_init.S2
-rw-r--r--arch/cris/include/asm/etraxgpio.h2
-rw-r--r--arch/cris/kernel/time.c2
-rw-r--r--arch/h8300/Kconfig.debug2
-rw-r--r--arch/ia64/include/asm/kvm_host.h4
-rw-r--r--arch/ia64/kernel/perfmon.c6
-rw-r--r--arch/ia64/kvm/kvm-ia64.c30
-rw-r--r--arch/ia64/kvm/mmio.c2
-rw-r--r--arch/m68k/ifpsp060/src/fpsp.S2
-rw-r--r--arch/m68k/include/asm/m548xgpt.h2
-rw-r--r--arch/m68k/mac/psc.c2
-rw-r--r--arch/mips/alchemy/common/power.c2
-rw-r--r--arch/mips/alchemy/devboards/pm.c2
-rw-r--r--arch/mips/dec/time.c2
-rw-r--r--arch/mips/include/asm/mach-powertv/ioremap.h2
-rw-r--r--arch/mips/include/asm/mc146818-time.h2
-rw-r--r--arch/mips/jz4740/board-qi_lb60.c4
-rw-r--r--arch/mips/jz4740/gpio.c2
-rw-r--r--arch/mips/jz4740/pm.c2
-rw-r--r--arch/mips/loongson/common/pm.c2
-rw-r--r--arch/mips/mti-malta/malta-memory.c2
-rw-r--r--arch/mips/pci/pcie-octeon.c2
-rw-r--r--arch/mips/powertv/memory.c2
-rw-r--r--arch/mips/txx9/generic/pci.c2
-rw-r--r--arch/mn10300/Kconfig6
-rw-r--r--arch/mn10300/kernel/rtc.c2
-rw-r--r--arch/powerpc/include/asm/8xx_immap.h4
-rw-r--r--arch/powerpc/kvm/book3s.c4
-rw-r--r--arch/powerpc/kvm/powerpc.c20
-rw-r--r--arch/powerpc/oprofile/op_model_cell.c2
-rw-r--r--arch/powerpc/platforms/52xx/lite5200_pm.c2
-rw-r--r--arch/powerpc/platforms/52xx/mpc52xx_pm.c2
-rw-r--r--arch/powerpc/platforms/83xx/suspend-asm.S6
-rw-r--r--arch/powerpc/platforms/83xx/suspend.c2
-rw-r--r--arch/powerpc/platforms/85xx/mpc85xx_mds.c2
-rw-r--r--arch/powerpc/platforms/ps3/device-init.c4
-rw-r--r--arch/powerpc/platforms/ps3/interrupt.c2
-rw-r--r--arch/powerpc/platforms/pseries/hvCall_inst.c2
-rw-r--r--arch/powerpc/platforms/pseries/suspend.c2
-rw-r--r--arch/powerpc/sysdev/fsl_pmc.c2
-rw-r--r--arch/powerpc/sysdev/fsl_rio.c1
-rw-r--r--arch/s390/kvm/kvm-s390.c23
-rw-r--r--arch/sh/boards/mach-hp6xx/pm.c2
-rw-r--r--arch/sh/boards/mach-se/7724/setup.c5
-rw-r--r--arch/sh/boards/mach-sh03/rtc.c2
-rw-r--r--arch/sh/kernel/cpu/shmobile/pm.c2
-rw-r--r--arch/sh/mm/cache-sh5.c2
-rw-r--r--arch/sparc/kernel/traps_64.c2
-rw-r--r--arch/um/Kconfig.um2
-rw-r--r--arch/um/drivers/line.c4
-rw-r--r--arch/um/drivers/mmapper_kern.c9
-rw-r--r--arch/x86/Kconfig12
-rw-r--r--arch/x86/boot/compressed/Makefile5
-rw-r--r--arch/x86/boot/compressed/misc.c4
-rw-r--r--arch/x86/boot/compressed/mkpiggy.c2
-rw-r--r--arch/x86/crypto/aesni-intel_asm.S1832
-rw-r--r--arch/x86/crypto/aesni-intel_glue.c540
-rw-r--r--arch/x86/include/asm/boot.h6
-rw-r--r--arch/x86/include/asm/irq.h3
-rw-r--r--arch/x86/include/asm/kvm_emulate.h35
-rw-r--r--arch/x86/include/asm/kvm_host.h99
-rw-r--r--arch/x86/include/asm/kvm_para.h24
-rw-r--r--arch/x86/include/asm/olpc.h10
-rw-r--r--arch/x86/include/asm/olpc_ofw.h9
-rw-r--r--arch/x86/include/asm/pgalloc.h2
-rw-r--r--arch/x86/include/asm/processor.h2
-rw-r--r--arch/x86/include/asm/prom.h1
-rw-r--r--arch/x86/include/asm/svm.h57
-rw-r--r--arch/x86/include/asm/traps.h1
-rw-r--r--arch/x86/include/asm/vmx.h15
-rw-r--r--arch/x86/kernel/amd_iommu.c4
-rw-r--r--arch/x86/kernel/entry_32.S10
-rw-r--r--arch/x86/kernel/entry_64.S3
-rw-r--r--arch/x86/kernel/head_32.S2
-rw-r--r--arch/x86/kernel/i387.c1
-rw-r--r--arch/x86/kernel/irq.c10
-rw-r--r--arch/x86/kernel/kvm.c317
-rw-r--r--arch/x86/kernel/kvmclock.c13
-rw-r--r--arch/x86/kernel/rtc.c2
-rw-r--r--arch/x86/kvm/Kconfig1
-rw-r--r--arch/x86/kvm/Makefile3
-rw-r--r--arch/x86/kvm/emulate.c367
-rw-r--r--arch/x86/kvm/kvm_cache_regs.h22
-rw-r--r--arch/x86/kvm/lapic.c3
-rw-r--r--arch/x86/kvm/mmu.c251
-rw-r--r--arch/x86/kvm/mmu_audit.c39
-rw-r--r--arch/x86/kvm/paging_tmpl.h147
-rw-r--r--arch/x86/kvm/svm.c865
-rw-r--r--arch/x86/kvm/trace.h17
-rw-r--r--arch/x86/kvm/vmx.c156
-rw-r--r--arch/x86/kvm/x86.c474
-rw-r--r--arch/x86/mm/init_32.c2
-rw-r--r--arch/x86/platform/mrst/early_printk_mrst.c2
-rw-r--r--arch/x86/platform/olpc/Makefile1
-rw-r--r--arch/x86/platform/olpc/olpc_dt.c183
-rw-r--r--arch/x86/platform/olpc/olpc_ofw.c5
-rw-r--r--block/cfq-iosched.c2
-rw-r--r--crypto/Kconfig34
-rw-r--r--crypto/Makefile17
-rw-r--r--crypto/af_alg.c483
-rw-r--r--crypto/algif_hash.c319
-rw-r--r--crypto/algif_skcipher.c632
-rw-r--r--crypto/authenc.c22
-rw-r--r--crypto/cast5.c74
-rw-r--r--crypto/crypto_wq.c3
-rw-r--r--crypto/deflate.c3
-rw-r--r--crypto/eseqiv.c18
-rw-r--r--crypto/gcm.c19
-rw-r--r--crypto/pcrypt.c3
-rw-r--r--crypto/rmd128.c3
-rw-r--r--crypto/rmd160.c3
-rw-r--r--crypto/rmd256.c3
-rw-r--r--crypto/rmd320.c3
-rw-r--r--crypto/shash.c8
-rw-r--r--crypto/tcrypt.c11
-rw-r--r--crypto/testmgr.c24
-rw-r--r--crypto/testmgr.h361
-rw-r--r--crypto/zlib.c3
-rw-r--r--drivers/Kconfig2
-rw-r--r--drivers/Makefile2
-rw-r--r--drivers/acpi/acpica/acobject.h2
-rw-r--r--drivers/acpi/apei/einj.c2
-rw-r--r--drivers/acpi/apei/erst.c2
-rw-r--r--drivers/acpi/sleep.c8
-rw-r--r--drivers/acpi/video.c2
-rw-r--r--drivers/ata/libata-core.c4
-rw-r--r--drivers/ata/sata_vsc.c2
-rw-r--r--drivers/atm/idt77252.h2
-rw-r--r--drivers/atm/iphase.c4
-rw-r--r--drivers/base/bus.c2
-rw-r--r--drivers/base/power/main.c2
-rw-r--r--drivers/block/rbd.c19
-rw-r--r--drivers/char/Kconfig9
-rw-r--r--drivers/char/Makefile1
-rw-r--r--drivers/char/hw_random/via-rng.c10
-rw-r--r--drivers/char/ramoops.c13
-rw-r--r--drivers/crypto/mv_cesa.c2
-rw-r--r--drivers/crypto/n2_core.c2
-rw-r--r--drivers/crypto/omap-aes.c260
-rw-r--r--drivers/crypto/omap-sham.c374
-rw-r--r--drivers/crypto/padlock-aes.c2
-rw-r--r--drivers/crypto/padlock-sha.c8
-rw-r--r--drivers/dca/dca-core.c2
-rw-r--r--drivers/dma/intel_mid_dma.c6
-rw-r--r--drivers/edac/amd8131_edac.h2
-rw-r--r--drivers/edac/cell_edac.c4
-rw-r--r--drivers/edac/edac_core.h2
-rw-r--r--drivers/edac/i7core_edac.c6
-rw-r--r--drivers/edac/ppc4xx_edac.c6
-rw-r--r--drivers/gpio/Kconfig14
-rw-r--r--drivers/gpio/Makefile1
-rw-r--r--drivers/gpio/adp5588-gpio.c39
-rw-r--r--drivers/gpio/cs5535-gpio.c52
-rw-r--r--drivers/gpio/langwell_gpio.c16
-rw-r--r--drivers/gpio/max732x.c38
-rw-r--r--drivers/gpio/ml_ioh_gpio.c352
-rw-r--r--drivers/gpio/pca953x.c38
-rw-r--r--drivers/gpio/pl061.c28
-rw-r--r--drivers/gpio/stmpe-gpio.c36
-rw-r--r--drivers/gpio/sx150x.c46
-rw-r--r--drivers/gpio/tc3589x-gpio.c36
-rw-r--r--drivers/gpio/timbgpio.c30
-rw-r--r--drivers/gpio/vr41xx_giu.c48
-rw-r--r--drivers/gpio/wm8994-gpio.c24
-rw-r--r--drivers/gpu/drm/nouveau/nouveau_backlight.c4
-rw-r--r--drivers/gpu/drm/nouveau/nouveau_bios.c4
-rw-r--r--drivers/gpu/drm/radeon/atombios.h2
-rw-r--r--drivers/hid/Kconfig17
-rw-r--r--drivers/hid/Makefile1
-rw-r--r--drivers/hid/hid-cando.c2
-rw-r--r--drivers/hid/hid-core.c7
-rw-r--r--drivers/hid/hid-ids.h7
-rw-r--r--drivers/hid/hid-input.c17
-rw-r--r--drivers/hid/hid-mosart.c1
-rw-r--r--drivers/hid/hid-multitouch.c516
-rw-r--r--drivers/hid/usbhid/hid-quirks.c1
-rw-r--r--drivers/hwmon/Kconfig4
-rw-r--r--drivers/hwmon/adm9240.c32
-rw-r--r--drivers/hwmon/ads7828.c4
-rw-r--r--drivers/hwmon/dme1737.c189
-rw-r--r--drivers/hwmon/emc1403.c16
-rw-r--r--drivers/hwmon/fschmd.c5
-rw-r--r--drivers/hwmon/it87.c30
-rw-r--r--drivers/hwmon/lm78.c14
-rw-r--r--drivers/hwmon/pc87360.c53
-rw-r--r--drivers/hwmon/pc87427.c26
-rw-r--r--drivers/hwmon/via686a.c14
-rw-r--r--drivers/hwmon/w83781d.c29
-rw-r--r--drivers/hwmon/w83792d.c44
-rw-r--r--drivers/hwmon/w83793.c38
-rw-r--r--drivers/hwmon/w83795.c4
-rw-r--r--drivers/i2c/busses/i2c-nomadik.c4
-rw-r--r--drivers/infiniband/hw/cxgb3/cxio_wr.h2
-rw-r--r--drivers/infiniband/hw/cxgb4/iw_cxgb4.h1
-rw-r--r--drivers/infiniband/hw/qib/qib_iba7322.c2
-rw-r--r--drivers/input/joystick/Kconfig10
-rw-r--r--drivers/input/joystick/Makefile1
-rw-r--r--drivers/input/joystick/as5011.c367
-rw-r--r--drivers/input/keyboard/Kconfig12
-rw-r--r--drivers/input/keyboard/Makefile1
-rw-r--r--drivers/input/keyboard/aaed2000_kbd.c186
-rw-r--r--drivers/input/serio/Kconfig2
-rw-r--r--drivers/input/serio/i8042-x86ia64io.h21
-rw-r--r--drivers/input/serio/i8042.c6
-rw-r--r--drivers/input/touchscreen/Kconfig2
-rw-r--r--drivers/input/touchscreen/ad7879-i2c.c17
-rw-r--r--drivers/input/touchscreen/cy8ctmg110_ts.c15
-rw-r--r--drivers/input/touchscreen/eeti_ts.c16
-rw-r--r--drivers/input/touchscreen/mcs5000_ts.c17
-rw-r--r--drivers/input/touchscreen/migor_ts.c12
-rw-r--r--drivers/input/touchscreen/wacom_w8001.c182
-rw-r--r--drivers/isdn/gigaset/bas-gigaset.c4
-rw-r--r--drivers/isdn/gigaset/ser-gigaset.c4
-rw-r--r--drivers/isdn/gigaset/usb-gigaset.c4
-rw-r--r--drivers/isdn/hardware/mISDN/ipac.h4
-rw-r--r--drivers/isdn/hardware/mISDN/isar.h2
-rw-r--r--drivers/isdn/mISDN/dsp_cmx.c2
-rw-r--r--drivers/leds/leds-lp5521.c57
-rw-r--r--drivers/leds/leds-lp5523.c59
-rw-r--r--drivers/leds/leds-pca9532.c66
-rw-r--r--drivers/leds/ledtrig-backlight.c61
-rw-r--r--drivers/macintosh/via-pmu-backlight.c4
-rw-r--r--drivers/macintosh/via-pmu.c2
-rw-r--r--drivers/media/video/cx18/cx23418.h2
-rw-r--r--drivers/media/video/cx25840/cx25840-ir.c2
-rw-r--r--drivers/media/video/davinci/vpif.h2
-rw-r--r--drivers/media/video/davinci/vpss.c2
-rw-r--r--drivers/media/video/omap/omap_vout.c2
-rw-r--r--drivers/media/video/saa7164/saa7164-core.c4
-rw-r--r--drivers/media/video/sn9c102/sn9c102_sensor.h2
-rw-r--r--drivers/media/video/tvp7002.c2
-rw-r--r--drivers/media/video/via-camera.c2
-rw-r--r--drivers/memstick/core/memstick.c19
-rw-r--r--drivers/memstick/core/mspro_block.c151
-rw-r--r--drivers/memstick/host/jmb38x_ms.c120
-rw-r--r--drivers/message/fusion/lsi/mpi_log_sas.h2
-rw-r--r--drivers/message/fusion/mptbase.c2
-rw-r--r--drivers/message/fusion/mptsas.c2
-rw-r--r--drivers/message/i2o/i2o_block.c2
-rw-r--r--drivers/mfd/wm8994-core.c93
-rw-r--r--drivers/misc/Kconfig2
-rw-r--r--drivers/misc/arm-charlcd.c2
-rw-r--r--drivers/misc/vmw_balloon.c13
-rw-r--r--drivers/mmc/card/block.c2
-rw-r--r--drivers/mmc/host/Kconfig2
-rw-r--r--drivers/mmc/host/au1xmmc.c2
-rw-r--r--drivers/mmc/host/sdricoh_cs.c4
-rw-r--r--drivers/mtd/mtdchar.c2
-rw-r--r--drivers/mtd/mtdoops.c5
-rw-r--r--drivers/mtd/nand/nand_base.c2
-rw-r--r--drivers/net/bnx2x/bnx2x.h4
-rw-r--r--drivers/net/bnx2x/bnx2x_main.c2
-rw-r--r--drivers/net/bnx2x/bnx2x_reg.h2
-rw-r--r--drivers/net/bonding/bond_3ad.c6
-rw-r--r--drivers/net/chelsio/subr.c2
-rw-r--r--drivers/net/cxgb3/mc5.c2
-rw-r--r--drivers/net/cxgb3/t3_hw.c2
-rw-r--r--drivers/net/e1000/e1000_hw.h2
-rw-r--r--drivers/net/e1000/e1000_main.c2
-rw-r--r--drivers/net/e1000e/82571.c2
-rw-r--r--drivers/net/e1000e/ich8lan.c2
-rw-r--r--drivers/net/e1000e/phy.c2
-rw-r--r--drivers/net/eepro.c2
-rw-r--r--drivers/net/irda/donauboe.h2
-rw-r--r--drivers/net/ixgbe/ixgbe_82599.c4
-rw-r--r--drivers/net/ll_temac_main.c2
-rw-r--r--drivers/net/sis900.c2
-rw-r--r--drivers/net/tehuti.c6
-rw-r--r--drivers/net/tun.c2
-rw-r--r--drivers/net/via-velocity.c2
-rw-r--r--drivers/net/vxge/vxge-traffic.h2
-rw-r--r--drivers/net/wan/dscc4.c2
-rw-r--r--drivers/net/wimax/i2400m/driver.c2
-rw-r--r--drivers/net/wimax/i2400m/i2400m.h4
-rw-r--r--drivers/net/wireless/ath/ath5k/reg.h6
-rw-r--r--drivers/net/wireless/b43/phy_g.c2
-rw-r--r--drivers/net/wireless/b43legacy/phy.c2
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-agn-ict.c2
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-agn.c4
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-legacy.c2
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-sta.c2
-rw-r--r--drivers/net/wireless/prism54/islpci_dev.c6
-rw-r--r--drivers/net/wireless/prism54/islpci_eth.c2
-rw-r--r--drivers/net/wireless/rt2x00/rt2x00mac.c2
-rw-r--r--drivers/net/wireless/wl1251/acx.h4
-rw-r--r--drivers/net/wireless/wl1251/wl1251.h2
-rw-r--r--drivers/net/wireless/wl12xx/acx.h4
-rw-r--r--drivers/net/wireless/wl12xx/wl12xx.h4
-rw-r--r--drivers/net/wireless/wl3501_cs.c2
-rw-r--r--drivers/nfc/Kconfig30
-rw-r--r--drivers/nfc/Makefile5
-rw-r--r--drivers/nfc/pn544.c891
-rw-r--r--drivers/pcmcia/m32r_cfc.h2
-rw-r--r--drivers/pcmcia/m32r_pcc.h2
-rw-r--r--drivers/pcmcia/m8xx_pcmcia.c2
-rw-r--r--drivers/platform/x86/acer-wmi.c2
-rw-r--r--drivers/platform/x86/asus-laptop.c2
-rw-r--r--drivers/platform/x86/asus_acpi.c2
-rw-r--r--drivers/platform/x86/dell-laptop.c2
-rw-r--r--drivers/platform/x86/eeepc-laptop.c2
-rw-r--r--drivers/platform/x86/fujitsu-laptop.c2
-rw-r--r--drivers/platform/x86/sony-laptop.c2
-rw-r--r--drivers/platform/x86/thinkpad_acpi.c4
-rw-r--r--drivers/platform/x86/toshiba_acpi.c2
-rw-r--r--drivers/power/s3c_adc_battery.c4
-rw-r--r--drivers/pps/Kconfig11
-rw-r--r--drivers/pps/Makefile3
-rw-r--r--drivers/pps/clients/Kconfig7
-rw-r--r--drivers/pps/clients/Makefile1
-rw-r--r--drivers/pps/clients/pps-ktimer.c44
-rw-r--r--drivers/pps/clients/pps-ldisc.c59
-rw-r--r--drivers/pps/clients/pps_parport.c258
-rw-r--r--drivers/pps/generators/Kconfig13
-rw-r--r--drivers/pps/generators/Makefile9
-rw-r--r--drivers/pps/generators/pps_gen_parport.c282
-rw-r--r--drivers/pps/kapi.c210
-rw-r--r--drivers/pps/kc.c122
-rw-r--r--drivers/pps/kc.h46
-rw-r--r--drivers/pps/pps.c156
-rw-r--r--drivers/rapidio/rio-scan.c160
-rw-r--r--drivers/rapidio/rio-sysfs.c4
-rw-r--r--drivers/rapidio/rio.c76
-rw-r--r--drivers/rapidio/switches/idt_gen2.c95
-rw-r--r--drivers/rapidio/switches/idtcps.c6
-rw-r--r--drivers/rapidio/switches/tsi568.c13
-rw-r--r--drivers/rapidio/switches/tsi57x.c56
-rw-r--r--drivers/regulator/88pm8607.c3
-rw-r--r--drivers/regulator/Kconfig22
-rw-r--r--drivers/regulator/Makefile3
-rw-r--r--drivers/regulator/ab3100.c5
-rw-r--r--drivers/regulator/ab8500.c453
-rw-r--r--drivers/regulator/core.c462
-rw-r--r--drivers/regulator/da903x.c17
-rw-r--r--drivers/regulator/isl6271a-regulator.c8
-rw-r--r--drivers/regulator/lp3971.c10
-rw-r--r--drivers/regulator/lp3972.c10
-rw-r--r--drivers/regulator/max1586.c30
-rw-r--r--drivers/regulator/max8649.c3
-rw-r--r--drivers/regulator/max8660.c14
-rw-r--r--drivers/regulator/max8925-regulator.c3
-rw-r--r--drivers/regulator/max8952.c3
-rw-r--r--drivers/regulator/max8998.c8
-rw-r--r--drivers/regulator/mc13783-regulator.c385
-rw-r--r--drivers/regulator/mc13892-regulator.c635
-rw-r--r--drivers/regulator/mc13xxx-regulator-core.c241
-rw-r--r--drivers/regulator/mc13xxx.h101
-rw-r--r--drivers/regulator/pcap-regulator.c7
-rw-r--r--drivers/regulator/pcf50633-regulator.c5
-rw-r--r--drivers/regulator/tps65023-regulator.c9
-rw-r--r--drivers/regulator/tps6507x-regulator.c10
-rw-r--r--drivers/regulator/tps6524x-regulator.c693
-rw-r--r--drivers/regulator/tps6586x-regulator.c15
-rw-r--r--drivers/regulator/twl-regulator.c11
-rw-r--r--drivers/regulator/wm831x-dcdc.c31
-rw-r--r--drivers/regulator/wm831x-ldo.c59
-rw-r--r--drivers/regulator/wm8350-regulator.c24
-rw-r--r--drivers/regulator/wm8400-regulator.c8
-rw-r--r--drivers/regulator/wm8994-regulator.c45
-rw-r--r--drivers/rtc/rtc-cmos.c16
-rw-r--r--drivers/rtc/rtc-max6902.c3
-rw-r--r--drivers/rtc/rtc-omap.c6
-rw-r--r--drivers/s390/net/lcs.c2
-rw-r--r--drivers/s390/scsi/zfcp_cfdc.c2
-rw-r--r--drivers/scsi/a100u2w.c2
-rw-r--r--drivers/scsi/aacraid/commsup.c2
-rw-r--r--drivers/scsi/aic7xxx_old/aic7xxx.seq2
-rw-r--r--drivers/scsi/aic94xx/aic94xx_reg_def.h4
-rw-r--r--drivers/scsi/aic94xx/aic94xx_scb.c2
-rw-r--r--drivers/scsi/aic94xx/aic94xx_seq.c6
-rw-r--r--drivers/scsi/bfa/bfa_fcpim.c2
-rw-r--r--drivers/scsi/bfa/bfa_fcs_lport.c2
-rw-r--r--drivers/scsi/dc395x.c8
-rw-r--r--drivers/scsi/libfc/fc_fcp.c2
-rw-r--r--drivers/scsi/lpfc/lpfc_attr.c2
-rw-r--r--drivers/scsi/lpfc/lpfc_hbadisc.c2
-rw-r--r--drivers/scsi/lpfc/lpfc_init.c2
-rw-r--r--drivers/scsi/lpfc/lpfc_sli.c2
-rw-r--r--drivers/scsi/megaraid.h2
-rw-r--r--drivers/scsi/megaraid/megaraid_mm.c2
-rw-r--r--drivers/scsi/pm8001/pm8001_init.c2
-rw-r--r--drivers/scsi/scsi_netlink.c2
-rw-r--r--drivers/scsi/scsi_sysfs.c6
-rw-r--r--drivers/scsi/sym53c8xx_2/sym_glue.c2
-rw-r--r--drivers/spi/atmel_spi.c4
-rw-r--r--drivers/spi/spidev.c2
-rw-r--r--drivers/staging/Kconfig2
-rw-r--r--drivers/staging/Makefile1
-rw-r--r--drivers/staging/cs5535_gpio/Kconfig11
-rw-r--r--drivers/staging/cs5535_gpio/Makefile1
-rw-r--r--drivers/staging/cs5535_gpio/TODO6
-rw-r--r--drivers/staging/cs5535_gpio/cs5535_gpio.c (renamed from drivers/char/cs5535_gpio.c)0
-rw-r--r--drivers/staging/msm/msm_fb_bl.c2
-rw-r--r--drivers/staging/olpc_dcon/TODO1
-rw-r--r--drivers/staging/olpc_dcon/olpc_dcon.c5
-rw-r--r--drivers/staging/olpc_dcon/olpc_dcon.h20
-rw-r--r--drivers/staging/olpc_dcon/olpc_dcon_xo_1.c168
-rw-r--r--drivers/staging/olpc_dcon/olpc_dcon_xo_1_5.c4
-rw-r--r--drivers/staging/pohmelfs/net.c2
-rw-r--r--drivers/staging/samsung-laptop/samsung-laptop.c2
-rw-r--r--drivers/staging/smbfs/dir.c13
-rw-r--r--drivers/staging/smbfs/inode.c4
-rw-r--r--drivers/staging/smbfs/proto.h2
-rw-r--r--drivers/telephony/ixj.c6
-rw-r--r--drivers/usb/gadget/imx_udc.c2
-rw-r--r--drivers/usb/gadget/langwell_udc.c4
-rw-r--r--drivers/usb/host/fhci-hcd.c4
-rw-r--r--drivers/usb/host/fhci-tds.c4
-rw-r--r--drivers/usb/host/imx21-hcd.c2
-rw-r--r--drivers/usb/host/oxu210hp-hcd.c2
-rw-r--r--drivers/usb/misc/adutux.c2
-rw-r--r--drivers/usb/misc/iowarrior.c2
-rw-r--r--drivers/usb/misc/ldusb.c2
-rw-r--r--drivers/usb/musb/musb_gadget.c4
-rw-r--r--drivers/usb/wusbcore/wa-rpipe.c2
-rw-r--r--drivers/video/Kconfig18
-rw-r--r--drivers/video/atmel_lcdfb.c2
-rw-r--r--drivers/video/aty/aty128fb.c2
-rw-r--r--drivers/video/aty/atyfb_base.c2
-rw-r--r--drivers/video/aty/radeon_backlight.c2
-rw-r--r--drivers/video/backlight/88pm860x_bl.c2
-rw-r--r--drivers/video/backlight/l4f00242t03.c106
-rw-r--r--drivers/video/backlight/max8925_bl.c2
-rw-r--r--drivers/video/console/vgacon.c3
-rw-r--r--drivers/video/imxfb.c2
-rw-r--r--drivers/video/matrox/matroxfb_base.c70
-rw-r--r--drivers/video/modedb.c420
-rw-r--r--drivers/video/nuc900fb.c5
-rw-r--r--drivers/video/nvidia/nv_backlight.c2
-rw-r--r--drivers/video/omap2/displays/Kconfig27
-rw-r--r--drivers/video/omap2/displays/Makefile5
-rw-r--r--drivers/video/omap2/displays/panel-generic-dpi.c365
-rw-r--r--drivers/video/omap2/displays/panel-generic.c174
-rw-r--r--drivers/video/omap2/displays/panel-nec-nl8048hl11-01b.c325
-rw-r--r--drivers/video/omap2/displays/panel-sharp-lq043t1dg01.c165
-rw-r--r--drivers/video/omap2/displays/panel-taal.c2
-rw-r--r--drivers/video/omap2/displays/panel-toppoly-tdo35s.c164
-rw-r--r--drivers/video/omap2/dss/dispc.c636
-rw-r--r--drivers/video/omap2/dss/dpi.c40
-rw-r--r--drivers/video/omap2/dss/dsi.c27
-rw-r--r--drivers/video/omap2/dss/dss.h35
-rw-r--r--drivers/video/omap2/dss/dss_features.c66
-rw-r--r--drivers/video/omap2/dss/dss_features.h10
-rw-r--r--drivers/video/omap2/dss/manager.c80
-rw-r--r--drivers/video/omap2/dss/overlay.c55
-rw-r--r--drivers/video/omap2/dss/rfbi.c20
-rw-r--r--drivers/video/omap2/dss/sdi.c24
-rw-r--r--drivers/video/omap2/omapfb/omapfb-main.c5
-rw-r--r--drivers/video/riva/fbdev.c2
-rw-r--r--drivers/video/s3c2410fb.c5
-rw-r--r--drivers/video/sh_mobile_hdmi.c98
-rw-r--r--drivers/video/sstfb.c2
-rw-r--r--drivers/video/vt8500lcdfb.c28
-rw-r--r--drivers/w1/slaves/Kconfig11
-rw-r--r--drivers/w1/slaves/Makefile1
-rw-r--r--drivers/w1/slaves/w1_ds2423.c166
-rw-r--r--drivers/w1/w1_family.h1
-rw-r--r--drivers/watchdog/Kconfig56
-rw-r--r--drivers/watchdog/Makefile6
-rw-r--r--drivers/watchdog/alim1535_wdt.c2
-rw-r--r--drivers/watchdog/alim7101_wdt.c2
-rw-r--r--drivers/watchdog/ath79_wdt.c305
-rw-r--r--drivers/watchdog/booke_wdt.c35
-rw-r--r--drivers/watchdog/f71808e_wdt.c78
-rw-r--r--drivers/watchdog/iTCO_wdt.c12
-rw-r--r--drivers/watchdog/ks8695_wdt.c2
-rw-r--r--drivers/watchdog/m548x_wdt.c227
-rw-r--r--drivers/watchdog/nv_tco.c512
-rw-r--r--drivers/watchdog/nv_tco.h64
-rw-r--r--drivers/watchdog/sp5100_tco.c480
-rw-r--r--drivers/watchdog/sp5100_tco.h41
-rw-r--r--drivers/watchdog/w83627hf_wdt.c8
-rw-r--r--firmware/ihex2fw.c9
-rw-r--r--fs/9p/v9fs_vfs.h1
-rw-r--r--fs/9p/vfs_dentry.c2
-rw-r--r--fs/9p/vfs_inode.c5
-rw-r--r--fs/9p/vfs_super.c8
-rw-r--r--fs/adfs/dir.c1
-rw-r--r--fs/adfs/super.c4
-rw-r--r--fs/affs/affs.h1
-rw-r--r--fs/affs/namei.c3
-rw-r--r--fs/affs/super.c6
-rw-r--r--fs/afs/dir.c4
-rw-r--r--fs/afs/internal.h1
-rw-r--r--fs/afs/super.c1
-rw-r--r--fs/aio.c29
-rw-r--r--fs/anon_inodes.c27
-rw-r--r--fs/befs/endian.h16
-rw-r--r--fs/befs/linuxvfs.c2
-rw-r--r--fs/binfmt_elf.c23
-rw-r--r--fs/block_dev.c2
-rw-r--r--fs/btrfs/export.c12
-rw-r--r--fs/btrfs/inode.c6
-rw-r--r--fs/btrfs/super.c1
-rw-r--r--fs/ceph/Makefile23
-rw-r--r--fs/ceph/debugfs.c9
-rw-r--r--fs/ceph/dir.c20
-rw-r--r--fs/ceph/export.c2
-rw-r--r--fs/ceph/inode.c4
-rw-r--r--fs/ceph/mds_client.c56
-rw-r--r--fs/ceph/mds_client.h2
-rw-r--r--fs/ceph/super.c13
-rw-r--r--fs/ceph/super.h2
-rw-r--r--fs/char_dev.c13
-rw-r--r--fs/cifs/cifsfs.c6
-rw-r--r--fs/cifs/dir.c25
-rw-r--r--fs/cifs/inode.c8
-rw-r--r--fs/cifs/link.c4
-rw-r--r--fs/cifs/readdir.c5
-rw-r--r--fs/coda/cache.c5
-rw-r--r--fs/coda/cnode.c3
-rw-r--r--fs/coda/coda_cache.h (renamed from include/linux/coda_cache.h)0
-rw-r--r--fs/coda/coda_fs_i.h (renamed from include/linux/coda_fs_i.h)0
-rw-r--r--fs/coda/coda_linux.c3
-rw-r--r--fs/coda/coda_linux.h (renamed from include/linux/coda_linux.h)4
-rw-r--r--fs/coda/dir.c9
-rw-r--r--fs/coda/file.c3
-rw-r--r--fs/coda/inode.c8
-rw-r--r--fs/coda/pioctl.c4
-rw-r--r--fs/coda/psdev.c4
-rw-r--r--fs/coda/symlink.c4
-rw-r--r--fs/coda/upcall.c5
-rw-r--r--fs/configfs/configfs_internal.h1
-rw-r--r--fs/configfs/dir.c6
-rw-r--r--fs/configfs/mount.c1
-rw-r--r--fs/cramfs/inode.c110
-rw-r--r--fs/dcache.c9
-rw-r--r--fs/ecryptfs/inode.c1
-rw-r--r--fs/ecryptfs/main.c155
-rw-r--r--fs/eventpoll.c20
-rw-r--r--fs/ext4/ext4.h2
-rw-r--r--fs/ext4/extents.c8
-rw-r--r--fs/ext4/inode.c9
-rw-r--r--fs/fat/fat.h3
-rw-r--r--fs/fat/inode.c13
-rw-r--r--fs/fat/namei_msdos.c27
-rw-r--r--fs/fat/namei_vfat.c27
-rw-r--r--fs/fuse/dir.c1
-rw-r--r--fs/fuse/inode.c10
-rw-r--r--fs/gfs2/export.c13
-rw-r--r--fs/gfs2/ops_fstype.c2
-rw-r--r--fs/gfs2/ops_inode.c6
-rw-r--r--fs/hfs/dir.c2
-rw-r--r--fs/hfs/super.c3
-rw-r--r--fs/hfsplus/dir.c1
-rw-r--r--fs/hfsplus/super.c2
-rw-r--r--fs/hostfs/hostfs_kern.c2
-rw-r--r--fs/hpfs/dentry.c7
-rw-r--r--fs/hpfs/dir.c1
-rw-r--r--fs/hpfs/hpfs_fn.h2
-rw-r--r--fs/hpfs/super.c2
-rw-r--r--fs/isofs/inode.c13
-rw-r--r--fs/isofs/namei.c2
-rw-r--r--fs/jbd/transaction.c2
-rw-r--r--fs/jbd2/transaction.c2
-rw-r--r--fs/jfs/namei.c10
-rw-r--r--fs/jfs/super.c6
-rw-r--r--fs/libfs.c4
-rw-r--r--fs/minix/namei.c2
-rw-r--r--fs/namei.c7
-rw-r--r--fs/ncpfs/dir.c19
-rw-r--r--fs/ncpfs/file.c3
-rw-r--r--fs/ncpfs/inode.c6
-rw-r--r--fs/ncpfs/ioctl.c4
-rw-r--r--fs/ncpfs/mmap.c4
-rw-r--r--fs/ncpfs/ncp_fs.h98
-rw-r--r--fs/ncpfs/ncp_fs_i.h (renamed from include/linux/ncp_fs_i.h)0
-rw-r--r--fs/ncpfs/ncp_fs_sb.h (renamed from include/linux/ncp_fs_sb.h)24
-rw-r--r--fs/ncpfs/ncplib_kernel.c2
-rw-r--r--fs/ncpfs/ncplib_kernel.h2
-rw-r--r--fs/ncpfs/ncpsign_kernel.c1
-rw-r--r--fs/ncpfs/ncpsign_kernel.h2
-rw-r--r--fs/ncpfs/sock.c2
-rw-r--r--fs/ncpfs/symlink.c4
-rw-r--r--fs/nfs/dir.c4
-rw-r--r--fs/nfs/getroot.c6
-rw-r--r--fs/nfs/super.c1
-rw-r--r--fs/notify/fanotify/Kconfig2
-rw-r--r--fs/ocfs2/export.c6
-rw-r--r--fs/ocfs2/file.c8
-rw-r--r--fs/ocfs2/inode.c2
-rw-r--r--fs/ocfs2/namei.c5
-rw-r--r--fs/ocfs2/suballoc.c2
-rw-r--r--fs/ocfs2/super.c1
-rw-r--r--fs/open.c7
-rw-r--r--fs/pipe.c14
-rw-r--r--fs/proc/Makefile2
-rw-r--r--fs/proc/array.c28
-rw-r--r--fs/proc/base.c53
-rw-r--r--fs/proc/consoles.c (renamed from fs/proc/proc_console.c)4
-rw-r--r--fs/proc/devices.c4
-rw-r--r--fs/proc/generic.c17
-rw-r--r--fs/proc/inode.c7
-rw-r--r--fs/proc/internal.h5
-rw-r--r--fs/proc/kcore.c2
-rw-r--r--fs/proc/page.c2
-rw-r--r--fs/proc/proc_tty.c26
-rw-r--r--fs/proc/softirqs.c6
-rw-r--r--fs/proc/stat.c2
-rw-r--r--fs/proc/task_mmu.c5
-rw-r--r--fs/proc/task_nommu.c7
-rw-r--r--fs/read_write.c27
-rw-r--r--fs/reiserfs/prints.c4
-rw-r--r--fs/select.c2
-rw-r--r--fs/sysv/namei.c1
-rw-r--r--fs/sysv/super.c8
-rw-r--r--fs/xfs/linux-2.6/xfs_iops.c7
-rw-r--r--fs/xfs/linux-2.6/xfs_super.c2
-rw-r--r--include/acpi/actbl1.h2
-rw-r--r--include/asm-generic/gpio.h10
-rw-r--r--include/asm-generic/vmlinux.lds.h3
-rw-r--r--include/crypto/if_alg.h92
-rw-r--r--include/crypto/padlock.h (renamed from drivers/crypto/padlock.h)8
-rw-r--r--include/crypto/scatterwalk.h15
-rw-r--r--include/linux/Kbuild1
-rw-r--r--include/linux/binfmts.h5
-rw-r--r--include/linux/cdev.h2
-rw-r--r--include/linux/ceph/ceph_fs.h16
-rw-r--r--include/linux/ceph/messenger.h5
-rw-r--r--include/linux/cgroup.h2
-rw-r--r--include/linux/cramfs_fs.h2
-rw-r--r--include/linux/cs5535.h6
-rw-r--r--include/linux/decompress/inflate.h3
-rw-r--r--include/linux/decompress/mm.h6
-rw-r--r--include/linux/decompress/unxz.h19
-rw-r--r--include/linux/falloc.h1
-rw-r--r--include/linux/firewire-cdev.h2
-rw-r--r--include/linux/fs.h5
-rw-r--r--include/linux/gpio.h26
-rw-r--r--include/linux/hid.h6
-rw-r--r--include/linux/if_alg.h40
-rw-r--r--include/linux/input.h1
-rw-r--r--include/linux/input/as5011.h20
-rw-r--r--include/linux/kernel.h19
-rw-r--r--include/linux/kmsg_dump.h4
-rw-r--r--include/linux/kvm.h1
-rw-r--r--include/linux/kvm_host.h101
-rw-r--r--include/linux/kvm_types.h7
-rw-r--r--include/linux/leds-lp5521.h1
-rw-r--r--include/linux/leds-lp5523.h1
-rw-r--r--include/linux/mfd/ab8500.h5
-rw-r--r--include/linux/mfd/core.h2
-rw-r--r--include/linux/mfd/mc13783.h67
-rw-r--r--include/linux/mfd/mc13892.h39
-rw-r--r--include/linux/mfd/wm8994/core.h8
-rw-r--r--include/linux/mfd/wm8994/pdata.h17
-rw-r--r--include/linux/mfd/wm8994/registers.h302
-rw-r--r--include/linux/ncp_fs.h100
-rw-r--r--include/linux/ncp_mount.h22
-rw-r--r--include/linux/nfc/pn544.h97
-rw-r--r--include/linux/pci_ids.h2
-rw-r--r--include/linux/poll.h2
-rw-r--r--include/linux/pps.h7
-rw-r--r--include/linux/pps_kernel.h61
-rw-r--r--include/linux/printk.h248
-rw-r--r--include/linux/regulator/ab8500.h24
-rw-r--r--include/linux/regulator/consumer.h1
-rw-r--r--include/linux/regulator/driver.h19
-rw-r--r--include/linux/rio.h100
-rw-r--r--include/linux/rio_drv.h72
-rw-r--r--include/linux/rio_ids.h2
-rw-r--r--include/linux/romfs_fs.h3
-rw-r--r--include/linux/sched.h2
-rw-r--r--include/linux/serial_core.h5
-rw-r--r--include/linux/socket.h5
-rw-r--r--include/linux/suspend.h8
-rw-r--r--include/linux/time.h2
-rw-r--r--include/linux/timex.h1
-rw-r--r--include/linux/toshiba.h2
-rw-r--r--include/linux/tty_ldisc.h7
-rw-r--r--include/linux/u64_stats_sync.h12
-rw-r--r--include/linux/unaligned/packed_struct.h6
-rw-r--r--include/linux/user_namespace.h2
-rw-r--r--include/linux/xz.h264
-rw-r--r--include/media/davinci/vpss.h2
-rw-r--r--include/net/sctp/user.h4
-rw-r--r--include/scsi/fc/fc_fcp.h4
-rw-r--r--include/sound/alc5623.h15
-rw-r--r--include/sound/asound.h3
-rw-r--r--include/sound/control.h4
-rw-r--r--include/sound/hdsp.h1
-rw-r--r--include/sound/minors.h4
-rw-r--r--include/sound/pcm.h1
-rw-r--r--include/sound/soc-dai.h4
-rw-r--r--include/sound/soc-dapm.h99
-rw-r--r--include/sound/soc.h116
-rw-r--r--include/trace/events/asoc.h235
-rw-r--r--include/trace/events/kvm.h121
-rw-r--r--include/trace/events/regulator.h141
-rw-r--r--init/Kconfig22
-rw-r--r--kernel/Makefile2
-rw-r--r--kernel/audit.c2
-rw-r--r--kernel/cgroup.c30
-rw-r--r--kernel/debug/kdb/kdb_main.c2
-rw-r--r--kernel/hrtimer.c2
-rw-r--r--kernel/kexec.c2
-rw-r--r--kernel/latencytop.c23
-rw-r--r--kernel/perf_event.c2
-rw-r--r--kernel/power/hibernate.c4
-rw-r--r--kernel/power/suspend.c4
-rw-r--r--kernel/power/swap.c2
-rw-r--r--kernel/printk.c30
-rw-r--r--kernel/sched.c2
-rw-r--r--kernel/smp.c19
-rw-r--r--kernel/softirq.c19
-rw-r--r--kernel/sys.c6
-rw-r--r--kernel/sysctl.c31
-rw-r--r--kernel/sysctl_binary.c2
-rw-r--r--kernel/taskstats.c2
-rw-r--r--kernel/time.c4
-rw-r--r--kernel/time/clocksource.c2
-rw-r--r--kernel/time/ntp.c425
-rw-r--r--kernel/time/timekeeping.c43
-rw-r--r--kernel/trace/trace_entries.h2
-rw-r--r--kernel/user_namespace.c15
-rw-r--r--lib/Kconfig6
-rw-r--r--lib/Makefile6
-rw-r--r--lib/decompress.c5
-rw-r--r--lib/decompress_bunzip2.c8
-rw-r--r--lib/decompress_inflate.c23
-rw-r--r--lib/decompress_unlzma.c85
-rw-r--r--lib/decompress_unlzo.c105
-rw-r--r--lib/decompress_unxz.c397
-rw-r--r--lib/flex_array.c10
-rw-r--r--lib/hexdump.c2
-rw-r--r--lib/nlattr.c2
-rw-r--r--lib/swiotlb.c2
-rw-r--r--lib/vsprintf.c38
-rw-r--r--lib/xz/Kconfig59
-rw-r--r--lib/xz/Makefile5
-rw-r--r--lib/xz/xz_crc32.c59
-rw-r--r--lib/xz/xz_dec_bcj.c561
-rw-r--r--lib/xz/xz_dec_lzma2.c1171
-rw-r--r--lib/xz/xz_dec_stream.c821
-rw-r--r--lib/xz/xz_dec_syms.c26
-rw-r--r--lib/xz/xz_dec_test.c220
-rw-r--r--lib/xz/xz_lzma2.h204
-rw-r--r--lib/xz/xz_private.h156
-rw-r--r--lib/xz/xz_stream.h62
-rw-r--r--mm/page-writeback.c2
-rw-r--r--mm/page_alloc.c2
-rw-r--r--mm/percpu.c2
-rw-r--r--mm/rmap.c2
-rw-r--r--mm/sparse-vmemmap.c2
-rw-r--r--net/Kconfig4
-rw-r--r--net/ceph/ceph_hash.c3
-rw-r--r--net/ceph/messenger.c46
-rw-r--r--net/ceph/osdmap.c4
-rw-r--r--net/core/dev.c2
-rw-r--r--net/core/sock.c6
-rw-r--r--net/dccp/Kconfig4
-rw-r--r--net/decnet/dn_dev.c2
-rw-r--r--net/ipv4/Kconfig4
-rw-r--r--net/ipv4/tcp_output.c2
-rw-r--r--net/ipv6/af_inet6.c2
-rw-r--r--net/sched/Kconfig2
-rw-r--r--net/socket.c30
-rw-r--r--scripts/Makefile.lib28
-rwxr-xr-xscripts/checkpatch.pl19
-rw-r--r--scripts/gen_initramfs_list.sh2
-rwxr-xr-xscripts/get_maintainer.pl45
-rw-r--r--scripts/mod/modpost.c2
-rw-r--r--scripts/xz_wrap.sh23
-rw-r--r--security/apparmor/include/match.h2
-rw-r--r--sound/ac97_bus.c4
-rw-r--r--sound/aoa/codecs/onyx.c1
-rw-r--r--sound/aoa/core/gpio-feature.c7
-rw-r--r--sound/aoa/core/gpio-pmf.c7
-rw-r--r--sound/core/control.c28
-rw-r--r--sound/core/init.c2
-rw-r--r--sound/core/oss/pcm_oss.c4
-rw-r--r--sound/core/pcm_lib.c22
-rw-r--r--sound/core/pcm_native.c5
-rw-r--r--sound/core/seq/seq.c4
-rw-r--r--sound/core/sound.c18
-rw-r--r--sound/core/timer.c7
-rw-r--r--sound/drivers/ml403-ac97cr.c4
-rw-r--r--sound/i2c/other/ak4113.c5
-rw-r--r--sound/i2c/other/ak4114.c5
-rw-r--r--sound/isa/opl3sa2.c2
-rw-r--r--sound/pci/Kconfig23
-rw-r--r--sound/pci/ac97/ac97_codec.c6
-rw-r--r--sound/pci/azt3328.c406
-rw-r--r--sound/pci/bt87x.c10
-rw-r--r--sound/pci/ca0106/ca0106.h2
-rw-r--r--sound/pci/ca0106/ca0106_main.c2
-rw-r--r--sound/pci/cmipci.c25
-rw-r--r--sound/pci/emu10k1/emu10k1x.c2
-rw-r--r--sound/pci/emu10k1/p16v.h2
-rw-r--r--sound/pci/es1968.c2
-rw-r--r--sound/pci/hda/hda_codec.c3
-rw-r--r--sound/pci/hda/hda_intel.c9
-rw-r--r--sound/pci/hda/patch_analog.c72
-rw-r--r--sound/pci/hda/patch_conexant.c108
-rw-r--r--sound/pci/hda/patch_hdmi.c92
-rw-r--r--sound/pci/hda/patch_realtek.c703
-rw-r--r--sound/pci/hda/patch_sigmatel.c17
-rw-r--r--sound/pci/hda/patch_via.c3
-rw-r--r--sound/pci/ice1712/delta.c49
-rw-r--r--sound/pci/ice1712/delta.h11
-rw-r--r--sound/pci/oxygen/Makefile4
-rw-r--r--sound/pci/oxygen/cs4245.h107
-rw-r--r--sound/pci/oxygen/hifier.c239
-rw-r--r--sound/pci/oxygen/oxygen.c356
-rw-r--r--sound/pci/oxygen/oxygen.h19
-rw-r--r--sound/pci/oxygen/oxygen_io.c4
-rw-r--r--sound/pci/oxygen/oxygen_lib.c71
-rw-r--r--sound/pci/oxygen/oxygen_mixer.c110
-rw-r--r--sound/pci/oxygen/oxygen_pcm.c55
-rw-r--r--sound/pci/oxygen/oxygen_regs.h16
-rw-r--r--sound/pci/oxygen/xonar.h2
-rw-r--r--sound/pci/oxygen/xonar_cs43xx.c84
-rw-r--r--sound/pci/oxygen/xonar_dg.c572
-rw-r--r--sound/pci/oxygen/xonar_dg.h8
-rw-r--r--sound/pci/oxygen/xonar_hdmi.c2
-rw-r--r--sound/pci/oxygen/xonar_lib.c6
-rw-r--r--sound/pci/oxygen/xonar_pcm179x.c473
-rw-r--r--sound/pci/oxygen/xonar_wm87x6.c317
-rw-r--r--sound/pci/rme9652/hdsp.c538
-rw-r--r--sound/pci/rme9652/hdspm.c6
-rw-r--r--sound/pci/ymfpci/ymfpci_main.c12
-rw-r--r--sound/ppc/snd_ps3.c2
-rw-r--r--sound/soc/Kconfig17
-rw-r--r--sound/soc/Makefile2
-rw-r--r--sound/soc/atmel/playpaq_wm8510.c12
-rw-r--r--sound/soc/atmel/sam9g20_wm8731.c18
-rw-r--r--sound/soc/atmel/snd-soc-afeb9260.c14
-rw-r--r--sound/soc/au1x/db1200.c1
-rw-r--r--sound/soc/blackfin/bf5xx-ad1836.c1
-rw-r--r--sound/soc/blackfin/bf5xx-ad193x.c1
-rw-r--r--sound/soc/blackfin/bf5xx-ad73311.c1
-rw-r--r--sound/soc/blackfin/bf5xx-ssm2602.c1
-rw-r--r--sound/soc/codecs/88pm860x-codec.c30
-rw-r--r--sound/soc/codecs/Kconfig20
-rw-r--r--sound/soc/codecs/Makefile12
-rw-r--r--sound/soc/codecs/ad1836.c7
-rw-r--r--sound/soc/codecs/ad193x.c8
-rw-r--r--sound/soc/codecs/ad1980.c1
-rw-r--r--sound/soc/codecs/ak4535.c20
-rw-r--r--sound/soc/codecs/ak4642.c2
-rw-r--r--sound/soc/codecs/ak4671.c11
-rw-r--r--sound/soc/codecs/alc5623.c1117
-rw-r--r--sound/soc/codecs/alc5623.h161
-rw-r--r--sound/soc/codecs/cq93vc.c4
-rw-r--r--sound/soc/codecs/cs4270.c162
-rw-r--r--sound/soc/codecs/cs42l51.c7
-rw-r--r--sound/soc/codecs/cx20442.c16
-rw-r--r--sound/soc/codecs/da7210.c2
-rw-r--r--sound/soc/codecs/dmic.c81
-rw-r--r--sound/soc/codecs/jz4740.c11
-rw-r--r--sound/soc/codecs/max98088.c15
-rw-r--r--sound/soc/codecs/ssm2602.c10
-rw-r--r--sound/soc/codecs/stac9766.c2
-rw-r--r--sound/soc/codecs/tlv320aic23.c10
-rw-r--r--sound/soc/codecs/tlv320aic26.c5
-rw-r--r--sound/soc/codecs/tlv320aic3x.c71
-rw-r--r--sound/soc/codecs/tlv320dac33.c334
-rw-r--r--sound/soc/codecs/tpa6130a2.c99
-rw-r--r--sound/soc/codecs/tpa6130a2.h1
-rw-r--r--sound/soc/codecs/twl4030.c56
-rw-r--r--sound/soc/codecs/twl6040.c859
-rw-r--r--sound/soc/codecs/twl6040.h8
-rw-r--r--sound/soc/codecs/uda134x.c3
-rw-r--r--sound/soc/codecs/uda1380.c15
-rw-r--r--sound/soc/codecs/wl1273.c3
-rw-r--r--sound/soc/codecs/wm2000.c6
-rw-r--r--sound/soc/codecs/wm8350.c105
-rw-r--r--sound/soc/codecs/wm8400.c12
-rw-r--r--sound/soc/codecs/wm8510.c12
-rw-r--r--sound/soc/codecs/wm8523.c12
-rw-r--r--sound/soc/codecs/wm8580.c23
-rw-r--r--sound/soc/codecs/wm8711.c11
-rw-r--r--sound/soc/codecs/wm8728.c12
-rw-r--r--sound/soc/codecs/wm8731.c102
-rw-r--r--sound/soc/codecs/wm8737.c754
-rw-r--r--sound/soc/codecs/wm8737.h322
-rw-r--r--sound/soc/codecs/wm8741.c10
-rw-r--r--sound/soc/codecs/wm8750.c13
-rw-r--r--sound/soc/codecs/wm8753.c49
-rw-r--r--sound/soc/codecs/wm8770.c749
-rw-r--r--sound/soc/codecs/wm8770.h51
-rw-r--r--sound/soc/codecs/wm8776.c10
-rw-r--r--sound/soc/codecs/wm8804.c7
-rw-r--r--sound/soc/codecs/wm8900.c13
-rw-r--r--sound/soc/codecs/wm8903.c222
-rw-r--r--sound/soc/codecs/wm8903.h25
-rw-r--r--sound/soc/codecs/wm8904.c36
-rw-r--r--sound/soc/codecs/wm8940.c8
-rw-r--r--sound/soc/codecs/wm8955.c12
-rw-r--r--sound/soc/codecs/wm8960.c29
-rw-r--r--sound/soc/codecs/wm8961.c13
-rw-r--r--sound/soc/codecs/wm8962.c41
-rw-r--r--sound/soc/codecs/wm8971.c30
-rw-r--r--sound/soc/codecs/wm8974.c13
-rw-r--r--sound/soc/codecs/wm8978.c13
-rw-r--r--sound/soc/codecs/wm8985.c12
-rw-r--r--sound/soc/codecs/wm8988.c11
-rw-r--r--sound/soc/codecs/wm8990.c12
-rw-r--r--sound/soc/codecs/wm8993.c21
-rw-r--r--sound/soc/codecs/wm8994-tables.c3147
-rw-r--r--sound/soc/codecs/wm8994.c2544
-rw-r--r--sound/soc/codecs/wm8994.h14
-rw-r--r--sound/soc/codecs/wm8995.c1818
-rw-r--r--sound/soc/codecs/wm8995.h4269
-rw-r--r--sound/soc/codecs/wm9081.c15
-rw-r--r--sound/soc/codecs/wm9090.c18
-rw-r--r--sound/soc/codecs/wm9705.c7
-rw-r--r--sound/soc/codecs/wm9712.c10
-rw-r--r--sound/soc/codecs/wm9713.c9
-rw-r--r--sound/soc/codecs/wm_hubs.c108
-rw-r--r--sound/soc/codecs/wm_hubs.h3
-rw-r--r--sound/soc/davinci/davinci-evm.c23
-rw-r--r--sound/soc/davinci/davinci-sffsdr.c1
-rw-r--r--sound/soc/ep93xx/ep93xx-i2s.c4
-rw-r--r--sound/soc/ep93xx/ep93xx-pcm.c4
-rw-r--r--sound/soc/ep93xx/snappercl15.c6
-rw-r--r--sound/soc/imx/eukrea-tlv320.c1
-rw-r--r--sound/soc/imx/imx-ssi.c4
-rw-r--r--sound/soc/imx/phycore-ac97.c1
-rw-r--r--sound/soc/imx/wm1133-ev1.c8
-rw-r--r--sound/soc/jz4740/jz4740-i2s.c1
-rw-r--r--sound/soc/jz4740/qi_lb60.c14
-rw-r--r--sound/soc/kirkwood/Kconfig11
-rw-r--r--sound/soc/kirkwood/Makefile2
-rw-r--r--sound/soc/kirkwood/kirkwood-openrd.c2
-rw-r--r--sound/soc/kirkwood/kirkwood-t5325.c141
-rw-r--r--sound/soc/nuc900/nuc900-audio.c1
-rw-r--r--sound/soc/omap/am3517evm.c14
-rw-r--r--sound/soc/omap/ams-delta.c82
-rw-r--r--sound/soc/omap/igep0020.c1
-rw-r--r--sound/soc/omap/n810.c44
-rw-r--r--sound/soc/omap/omap-mcbsp.c35
-rw-r--r--sound/soc/omap/omap-mcbsp.h4
-rw-r--r--sound/soc/omap/omap2evm.c1
-rw-r--r--sound/soc/omap/omap3beagle.c1
-rw-r--r--sound/soc/omap/omap3evm.c1
-rw-r--r--sound/soc/omap/omap3pandora.c45
-rw-r--r--sound/soc/omap/osk5912.c14
-rw-r--r--sound/soc/omap/overo.c1
-rw-r--r--sound/soc/omap/rx51.c27
-rw-r--r--sound/soc/omap/sdp3430.c44
-rw-r--r--sound/soc/omap/sdp4430.c57
-rw-r--r--sound/soc/omap/zoom2.c36
-rw-r--r--sound/soc/pxa/corgi.c52
-rw-r--r--sound/soc/pxa/e740_wm9705.c30
-rw-r--r--sound/soc/pxa/e750_wm9705.c30
-rw-r--r--sound/soc/pxa/e800_wm9712.c8
-rw-r--r--sound/soc/pxa/em-x270.c1
-rw-r--r--sound/soc/pxa/magician.c36
-rw-r--r--sound/soc/pxa/mioa701_wm9713.c18
-rw-r--r--sound/soc/pxa/palm27x.c34
-rw-r--r--sound/soc/pxa/poodle.c26
-rw-r--r--sound/soc/pxa/raumfeld.c1
-rw-r--r--sound/soc/pxa/saarb.c18
-rw-r--r--sound/soc/pxa/spitz.c70
-rw-r--r--sound/soc/pxa/tavorevb3.c18
-rw-r--r--sound/soc/pxa/tosa.c38
-rw-r--r--sound/soc/pxa/z2.c16
-rw-r--r--sound/soc/pxa/zylonite.c12
-rw-r--r--sound/soc/s3c24xx/Kconfig171
-rw-r--r--sound/soc/s3c24xx/Makefile55
-rw-r--r--sound/soc/s3c24xx/aquila_wm8994.c295
-rw-r--r--sound/soc/s3c24xx/s3c64xx-i2s-v4.c230
-rw-r--r--sound/soc/s3c24xx/s3c64xx-i2s.c242
-rw-r--r--sound/soc/s3c24xx/s3c64xx-i2s.h41
-rw-r--r--sound/soc/s6000/s6105-ipcam.c42
-rw-r--r--sound/soc/samsung/Kconfig171
-rw-r--r--sound/soc/samsung/Makefile55
-rw-r--r--sound/soc/samsung/ac97.c (renamed from sound/soc/s3c24xx/s3c-ac97.c)22
-rw-r--r--sound/soc/samsung/ac97.h (renamed from sound/soc/s3c24xx/s3c-ac97.h)8
-rw-r--r--sound/soc/samsung/dma.c (renamed from sound/soc/s3c24xx/s3c-dma.c)134
-rw-r--r--sound/soc/samsung/dma.h (renamed from sound/soc/s3c24xx/s3c-dma.h)2
-rw-r--r--sound/soc/samsung/goni_wm8994.c (renamed from sound/soc/s3c24xx/goni_wm8994.c)66
-rw-r--r--sound/soc/samsung/h1940_uda1380.c296
-rw-r--r--sound/soc/samsung/i2s.c1258
-rw-r--r--sound/soc/samsung/i2s.h29
-rw-r--r--sound/soc/samsung/jive_wm8750.c (renamed from sound/soc/s3c24xx/jive_wm8750.c)26
-rw-r--r--sound/soc/samsung/lm4857.h (renamed from sound/soc/s3c24xx/lm4857.h)0
-rw-r--r--sound/soc/samsung/ln2440sbc_alc650.c (renamed from sound/soc/s3c24xx/ln2440sbc_alc650.c)9
-rw-r--r--sound/soc/samsung/neo1973_gta02_wm8753.c (renamed from sound/soc/s3c24xx/neo1973_gta02_wm8753.c)72
-rw-r--r--sound/soc/samsung/neo1973_wm8753.c (renamed from sound/soc/s3c24xx/neo1973_wm8753.c)130
-rw-r--r--sound/soc/samsung/pcm.c (renamed from sound/soc/s3c24xx/s3c-pcm.c)6
-rw-r--r--sound/soc/samsung/pcm.h (renamed from sound/soc/s3c24xx/s3c-pcm.h)2
-rw-r--r--sound/soc/samsung/regs-i2s-v2.h (renamed from sound/soc/s3c24xx/regs-i2s-v2.h)0
-rw-r--r--sound/soc/samsung/rx1950_uda1380.c (renamed from sound/soc/s3c24xx/rx1950_uda1380.c)17
-rw-r--r--sound/soc/samsung/s3c-i2s-v2.c (renamed from sound/soc/s3c24xx/s3c-i2s-v2.c)4
-rw-r--r--sound/soc/samsung/s3c-i2s-v2.h (renamed from sound/soc/s3c24xx/s3c-i2s-v2.h)2
-rw-r--r--sound/soc/samsung/s3c2412-i2s.c (renamed from sound/soc/s3c24xx/s3c2412-i2s.c)4
-rw-r--r--sound/soc/samsung/s3c2412-i2s.h (renamed from sound/soc/s3c24xx/s3c2412-i2s.h)2
-rw-r--r--sound/soc/samsung/s3c24xx-i2s.c (renamed from sound/soc/s3c24xx/s3c24xx-i2s.c)2
-rw-r--r--sound/soc/samsung/s3c24xx-i2s.h (renamed from sound/soc/s3c24xx/s3c24xx-i2s.h)0
-rw-r--r--sound/soc/samsung/s3c24xx_simtec.c (renamed from sound/soc/s3c24xx/s3c24xx_simtec.c)5
-rw-r--r--sound/soc/samsung/s3c24xx_simtec.h (renamed from sound/soc/s3c24xx/s3c24xx_simtec.h)2
-rw-r--r--sound/soc/samsung/s3c24xx_simtec_hermes.c (renamed from sound/soc/s3c24xx/s3c24xx_simtec_hermes.c)24
-rw-r--r--sound/soc/samsung/s3c24xx_simtec_tlv320aic23.c (renamed from sound/soc/s3c24xx/s3c24xx_simtec_tlv320aic23.c)22
-rw-r--r--sound/soc/samsung/s3c24xx_uda134x.c (renamed from sound/soc/s3c24xx/s3c24xx_uda134x.c)5
-rw-r--r--sound/soc/samsung/smartq_wm8987.c (renamed from sound/soc/s3c24xx/smartq_wm8987.c)64
-rw-r--r--sound/soc/samsung/smdk2443_wm9710.c (renamed from sound/soc/s3c24xx/smdk2443_wm9710.c)9
-rw-r--r--sound/soc/samsung/smdk_spdif.c (renamed from sound/soc/s3c24xx/smdk_spdif.c)27
-rw-r--r--sound/soc/samsung/smdk_wm8580.c (renamed from sound/soc/s3c24xx/smdk64xx_wm8580.c)174
-rw-r--r--sound/soc/samsung/smdk_wm8994.c176
-rw-r--r--sound/soc/samsung/smdk_wm9713.c (renamed from sound/soc/s3c24xx/smdk_wm9713.c)26
-rw-r--r--sound/soc/samsung/spdif.c (renamed from sound/soc/s3c24xx/spdif.c)4
-rw-r--r--sound/soc/samsung/spdif.h (renamed from sound/soc/s3c24xx/spdif.h)2
-rw-r--r--sound/soc/sh/Kconfig4
-rw-r--r--sound/soc/sh/fsi-ak4642.c140
-rw-r--r--sound/soc/sh/fsi-da7210.c2
-rw-r--r--sound/soc/sh/fsi.c273
-rw-r--r--sound/soc/sh/migor.c8
-rw-r--r--sound/soc/sh/sh7760-ac97.c3
-rw-r--r--sound/soc/sh/siu.h2
-rw-r--r--sound/soc/sh/siu_dai.c2
-rw-r--r--sound/soc/sh/siu_pcm.c2
-rw-r--r--sound/soc/soc-cache.c1065
-rw-r--r--sound/soc/soc-core.c575
-rw-r--r--sound/soc/soc-dapm.c860
-rw-r--r--sound/soc/soc-jack.c31
-rw-r--r--sound/usb/format.c5
-rw-r--r--sound/usb/midi.c19
-rw-r--r--sound/usb/mixer.c11
-rw-r--r--sound/usb/quirks-table.h4
-rw-r--r--sound/usb/usx2y/us122l.c41
-rw-r--r--usr/Kconfig18
-rw-r--r--usr/Makefile5
-rw-r--r--virt/kvm/Kconfig3
-rw-r--r--virt/kvm/assigned-dev.c125
-rw-r--r--virt/kvm/async_pf.c216
-rw-r--r--virt/kvm/async_pf.h36
-rw-r--r--virt/kvm/eventfd.c91
-rw-r--r--virt/kvm/irq_comm.c7
-rw-r--r--virt/kvm/kvm_main.c334
1175 files changed, 52311 insertions, 14246 deletions
diff --git a/CREDITS b/CREDITS
index 494b6e4746d7..1d39a6d0a510 100644
--- a/CREDITS
+++ b/CREDITS
@@ -2811,8 +2811,8 @@ D: CDROM driver "sonycd535" (Sony CDU-535/531)
2811N: Stelian Pop 2811N: Stelian Pop
2812E: stelian@popies.net 2812E: stelian@popies.net
2813P: 1024D/EDBB6147 7B36 0E07 04BC 11DC A7A0 D3F7 7185 9E7A EDBB 6147 2813P: 1024D/EDBB6147 7B36 0E07 04BC 11DC A7A0 D3F7 7185 9E7A EDBB 6147
2814D: sonypi, meye drivers, mct_u232 usb serial hacks 2814D: random kernel hacks
2815S: Paris, France 2815S: Paimpont, France
2816 2816
2817N: Pete Popov 2817N: Pete Popov
2818E: pete_popov@yahoo.com 2818E: pete_popov@yahoo.com
diff --git a/Documentation/ABI/testing/sysfs-class-led b/Documentation/ABI/testing/sysfs-class-led
index 9e4541d71cb6..edff6630c805 100644
--- a/Documentation/ABI/testing/sysfs-class-led
+++ b/Documentation/ABI/testing/sysfs-class-led
@@ -26,3 +26,12 @@ Description:
26 scheduler is chosen. Trigger specific parameters can appear in 26 scheduler is chosen. Trigger specific parameters can appear in
27 /sys/class/leds/<led> once a given trigger is selected. 27 /sys/class/leds/<led> once a given trigger is selected.
28 28
29What: /sys/class/leds/<led>/inverted
30Date: January 2011
31KernelVersion: 2.6.38
32Contact: Richard Purdie <rpurdie@rpsys.net>
33Description:
34 Invert the LED on/off state. This parameter is specific to
35 gpio and backlight triggers. In case of the backlight trigger,
36 it is usefull when driving a LED which is intended to indicate
37 a device in a standby like state.
diff --git a/Documentation/DocBook/mtdnand.tmpl b/Documentation/DocBook/mtdnand.tmpl
index 020ac80d4682..620eb3f6a90a 100644
--- a/Documentation/DocBook/mtdnand.tmpl
+++ b/Documentation/DocBook/mtdnand.tmpl
@@ -250,7 +250,7 @@ static void board_hwcontrol(struct mtd_info *mtd, int cmd)
250 <title>Device ready function</title> 250 <title>Device ready function</title>
251 <para> 251 <para>
252 If the hardware interface has the ready busy pin of the NAND chip connected to a 252 If the hardware interface has the ready busy pin of the NAND chip connected to a
253 GPIO or other accesible I/O pin, this function is used to read back the state of the 253 GPIO or other accessible I/O pin, this function is used to read back the state of the
254 pin. The function has no arguments and should return 0, if the device is busy (R/B pin 254 pin. The function has no arguments and should return 0, if the device is busy (R/B pin
255 is low) and 1, if the device is ready (R/B pin is high). 255 is low) and 1, if the device is ready (R/B pin is high).
256 If the hardware interface does not give access to the ready busy pin, then 256 If the hardware interface does not give access to the ready busy pin, then
diff --git a/Documentation/cgroups/cgroup_event_listener.c b/Documentation/cgroups/cgroup_event_listener.c
index 8c2bfc4a6358..3e082f96dc12 100644
--- a/Documentation/cgroups/cgroup_event_listener.c
+++ b/Documentation/cgroups/cgroup_event_listener.c
@@ -91,7 +91,7 @@ int main(int argc, char **argv)
91 91
92 if (ret == -1) { 92 if (ret == -1) {
93 perror("cgroup.event_control " 93 perror("cgroup.event_control "
94 "is not accessable any more"); 94 "is not accessible any more");
95 break; 95 break;
96 } 96 }
97 97
diff --git a/Documentation/cgroups/cgroups.txt b/Documentation/cgroups/cgroups.txt
index 190018b0c649..44b8b7af8019 100644
--- a/Documentation/cgroups/cgroups.txt
+++ b/Documentation/cgroups/cgroups.txt
@@ -355,13 +355,13 @@ subsystems, type:
355 355
356To change the set of subsystems bound to a mounted hierarchy, just 356To change the set of subsystems bound to a mounted hierarchy, just
357remount with different options: 357remount with different options:
358# mount -o remount,cpuset,ns hier1 /dev/cgroup 358# mount -o remount,cpuset,blkio hier1 /dev/cgroup
359 359
360Now memory is removed from the hierarchy and ns is added. 360Now memory is removed from the hierarchy and blkio is added.
361 361
362Note this will add ns to the hierarchy but won't remove memory or 362Note this will add blkio to the hierarchy but won't remove memory or
363cpuset, because the new options are appended to the old ones: 363cpuset, because the new options are appended to the old ones:
364# mount -o remount,ns /dev/cgroup 364# mount -o remount,blkio /dev/cgroup
365 365
366To Specify a hierarchy's release_agent: 366To Specify a hierarchy's release_agent:
367# mount -t cgroup -o cpuset,release_agent="/sbin/cpuset_release_agent" \ 367# mount -t cgroup -o cpuset,release_agent="/sbin/cpuset_release_agent" \
diff --git a/Documentation/cgroups/memcg_test.txt b/Documentation/cgroups/memcg_test.txt
index b7eececfb195..fc8fa97a09ac 100644
--- a/Documentation/cgroups/memcg_test.txt
+++ b/Documentation/cgroups/memcg_test.txt
@@ -398,7 +398,7 @@ Under below explanation, we assume CONFIG_MEM_RES_CTRL_SWAP=y.
398 written to move_charge_at_immigrate. 398 written to move_charge_at_immigrate.
399 399
400 9.10 Memory thresholds 400 9.10 Memory thresholds
401 Memory controler implements memory thresholds using cgroups notification 401 Memory controller implements memory thresholds using cgroups notification
402 API. You can use Documentation/cgroups/cgroup_event_listener.c to test 402 API. You can use Documentation/cgroups/cgroup_event_listener.c to test
403 it. 403 it.
404 404
diff --git a/Documentation/email-clients.txt b/Documentation/email-clients.txt
index 945ff3fda433..a0b58e29f911 100644
--- a/Documentation/email-clients.txt
+++ b/Documentation/email-clients.txt
@@ -104,6 +104,13 @@ Then from the "Message" menu item, select insert file and choose your patch.
104As an added bonus you can customise the message creation toolbar menu 104As an added bonus you can customise the message creation toolbar menu
105and put the "insert file" icon there. 105and put the "insert file" icon there.
106 106
107Make the the composer window wide enough so that no lines wrap. As of
108KMail 1.13.5 (KDE 4.5.4), KMail will apply word wrapping when sending
109the email if the lines wrap in the composer window. Having word wrapping
110disabled in the Options menu isn't enough. Thus, if your patch has very
111long lines, you must make the composer window very wide before sending
112the email. See: https://bugs.kde.org/show_bug.cgi?id=174034
113
107You can safely GPG sign attachments, but inlined text is preferred for 114You can safely GPG sign attachments, but inlined text is preferred for
108patches so do not GPG sign them. Signing patches that have been inserted 115patches so do not GPG sign them. Signing patches that have been inserted
109as inlined text will make them tricky to extract from their 7-bit encoding. 116as inlined text will make them tricky to extract from their 7-bit encoding.
@@ -179,26 +186,8 @@ Sylpheed (GUI)
179~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 186~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
180Thunderbird (GUI) 187Thunderbird (GUI)
181 188
182By default, thunderbird likes to mangle text, but there are ways to 189Thunderbird is an Outlook clone that likes to mangle text, but there are ways
183coerce it into being nice. 190to coerce it into behaving.
184
185- Under account settings, composition and addressing, uncheck "Compose
186 messages in HTML format".
187
188- Edit your Thunderbird config settings to tell it not to wrap lines:
189 user_pref("mailnews.wraplength", 0);
190
191- Edit your Thunderbird config settings so that it won't use format=flowed:
192 user_pref("mailnews.send_plaintext_flowed", false);
193
194- You need to get Thunderbird into preformat mode:
195. If you compose HTML messages by default, it's not too hard. Just select
196 "Preformat" from the drop-down box just under the subject line.
197. If you compose in text by default, you have to tell it to compose a new
198 message in HTML (just as a one-off), and then force it from there back to
199 text, else it will wrap lines. To do this, use shift-click on the Write
200 icon to compose to get HTML compose mode, then select "Preformat" from
201 the drop-down box just under the subject line.
202 191
203- Allows use of an external editor: 192- Allows use of an external editor:
204 The easiest thing to do with Thunderbird and patches is to use an 193 The easiest thing to do with Thunderbird and patches is to use an
@@ -208,6 +197,27 @@ coerce it into being nice.
208 View->Toolbars->Customize... and finally just click on it when in the 197 View->Toolbars->Customize... and finally just click on it when in the
209 Compose dialog. 198 Compose dialog.
210 199
200To beat some sense out of the internal editor, do this:
201
202- Under account settings, composition and addressing, uncheck "Compose
203 messages in HTML format".
204
205- Edit your Thunderbird config settings so that it won't use format=flowed.
206 Go to "edit->preferences->advanced->config editor" to bring up the
207 thunderbird's registry editor, and set "mailnews.send_plaintext_flowed" to
208 "false".
209
210- Enable "preformat" mode: Shft-click on the Write icon to bring up the HTML
211 composer, select "Preformat" from the drop-down box just under the subject
212 line, then close the message without saving. (This setting also applies to
213 the text composer, but the only control for it is in the HTML composer.)
214
215- Install the "toggle wordwrap" extension. Download the file from:
216 https://addons.mozilla.org/thunderbird/addon/2351/
217 Then go to "tools->add ons", select "install" at the bottom of the screen,
218 and browse to where you saved the .xul file. This adds an "Enable
219 Wordwrap" entry under the Options menu of the message composer.
220
211~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 221~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
212TkRat (GUI) 222TkRat (GUI)
213 223
diff --git a/Documentation/feature-removal-schedule.txt b/Documentation/feature-removal-schedule.txt
index 22f10818c2b3..6cbbd20534cf 100644
--- a/Documentation/feature-removal-schedule.txt
+++ b/Documentation/feature-removal-schedule.txt
@@ -193,6 +193,20 @@ Why: /proc/<pid>/oom_adj allows userspace to influence the oom killer's
193 193
194--------------------------- 194---------------------------
195 195
196What: CS5535/CS5536 obsolete GPIO driver
197When: June 2011
198Files: drivers/staging/cs5535_gpio/*
199Check: drivers/staging/cs5535_gpio/cs5535_gpio.c
200Why: A newer driver replaces this; it is drivers/gpio/cs5535-gpio.c, and
201 integrates with the Linux GPIO subsystem. The old driver has been
202 moved to staging, and will be removed altogether around 2.6.40.
203 Please test the new driver, and ensure that the functionality you
204 need and any bugfixes from the old driver are available in the new
205 one.
206Who: Andres Salomon <dilinger@queued.net>
207
208--------------------------
209
196What: remove EXPORT_SYMBOL(kernel_thread) 210What: remove EXPORT_SYMBOL(kernel_thread)
197When: August 2006 211When: August 2006
198Files: arch/*/kernel/*_ksyms.c 212Files: arch/*/kernel/*_ksyms.c
@@ -576,3 +590,13 @@ Why: The functions have been superceded by cancel_delayed_work_sync()
576Who: Tejun Heo <tj@kernel.org> 590Who: Tejun Heo <tj@kernel.org>
577 591
578---------------------------- 592----------------------------
593
594What: Legacy, non-standard chassis intrusion detection interface.
595When: June 2011
596Why: The adm9240, w83792d and w83793 hardware monitoring drivers have
597 legacy interfaces for chassis intrusion detection. A standard
598 interface has been added to each driver, so the legacy interface
599 can be removed.
600Who: Jean Delvare <khali@linux-fr.org>
601
602----------------------------
diff --git a/Documentation/filesystems/porting b/Documentation/filesystems/porting
index 07a32b42cf9c..266d2059b9b8 100644
--- a/Documentation/filesystems/porting
+++ b/Documentation/filesystems/porting
@@ -385,3 +385,12 @@ Documentation/filesystems/vfs.txt for more details.
385on many or all directory inodes on the way down a path walk (to check for 385on many or all directory inodes on the way down a path walk (to check for
386exec permission). These must now be rcu-walk aware (flags & IPERM_RCU). See 386exec permission). These must now be rcu-walk aware (flags & IPERM_RCU). See
387Documentation/filesystems/vfs.txt for more details. 387Documentation/filesystems/vfs.txt for more details.
388
389--
390[mandatory]
391 In ->fallocate() you must check the mode option passed in. If your
392filesystem does not support hole punching (deallocating space in the middle of a
393file) you must return -EOPNOTSUPP if FALLOC_FL_PUNCH_HOLE is set in mode.
394Currently you can only have FALLOC_FL_PUNCH_HOLE with FALLOC_FL_KEEP_SIZE set,
395so the i_size should not change when hole punching, even when puching the end of
396a file off.
diff --git a/Documentation/gpio.txt b/Documentation/gpio.txt
index 792faa3c06cf..a492d92bb098 100644
--- a/Documentation/gpio.txt
+++ b/Documentation/gpio.txt
@@ -135,7 +135,7 @@ setting up a platform_device using the GPIO, is mark its direction:
135 int gpio_direction_input(unsigned gpio); 135 int gpio_direction_input(unsigned gpio);
136 int gpio_direction_output(unsigned gpio, int value); 136 int gpio_direction_output(unsigned gpio, int value);
137 137
138The return value is zero for success, else a negative errno. It should 138The return value is zero for success, else a negative errno. It must
139be checked, since the get/set calls don't have error returns and since 139be checked, since the get/set calls don't have error returns and since
140misconfiguration is possible. You should normally issue these calls from 140misconfiguration is possible. You should normally issue these calls from
141a task context. However, for spinlock-safe GPIOs it's OK to use them 141a task context. However, for spinlock-safe GPIOs it's OK to use them
diff --git a/Documentation/hwmon/adm9240 b/Documentation/hwmon/adm9240
index 2c6f1fed4618..36e8ec6aa868 100644
--- a/Documentation/hwmon/adm9240
+++ b/Documentation/hwmon/adm9240
@@ -155,7 +155,7 @@ connected to a normally open switch.
155The ADM9240 provides an internal open drain on this line, and may output 155The ADM9240 provides an internal open drain on this line, and may output
156a 20 ms active low pulse to reset an external Chassis Intrusion latch. 156a 20 ms active low pulse to reset an external Chassis Intrusion latch.
157 157
158Clear the CI latch by writing value 1 to the sysfs chassis_clear file. 158Clear the CI latch by writing value 0 to the sysfs intrusion0_alarm file.
159 159
160Alarm flags reported as 16-bit word 160Alarm flags reported as 16-bit word
161 161
diff --git a/Documentation/hwmon/ads7828 b/Documentation/hwmon/ads7828
index 75bc4beaf447..2bbebe6f771f 100644
--- a/Documentation/hwmon/ads7828
+++ b/Documentation/hwmon/ads7828
@@ -9,7 +9,7 @@ Supported chips:
9 http://focus.ti.com/lit/ds/symlink/ads7828.pdf 9 http://focus.ti.com/lit/ds/symlink/ads7828.pdf
10 10
11Authors: 11Authors:
12 Steve Hardy <steve@linuxrealtime.co.uk> 12 Steve Hardy <shardy@redhat.com>
13 13
14Module Parameters 14Module Parameters
15----------------- 15-----------------
diff --git a/Documentation/hwmon/dme1737 b/Documentation/hwmon/dme1737
index fc5df7654d63..4d2935145a1c 100644
--- a/Documentation/hwmon/dme1737
+++ b/Documentation/hwmon/dme1737
@@ -42,7 +42,7 @@ Description
42This driver implements support for the hardware monitoring capabilities of the 42This driver implements support for the hardware monitoring capabilities of the
43SMSC DME1737 and Asus A8000 (which are the same), SMSC SCH5027, SCH311x, 43SMSC DME1737 and Asus A8000 (which are the same), SMSC SCH5027, SCH311x,
44and SCH5127 Super-I/O chips. These chips feature monitoring of 3 temp sensors 44and SCH5127 Super-I/O chips. These chips feature monitoring of 3 temp sensors
45temp[1-3] (2 remote diodes and 1 internal), 7 voltages in[0-6] (6 external and 45temp[1-3] (2 remote diodes and 1 internal), 8 voltages in[0-7] (7 external and
461 internal) and up to 6 fan speeds fan[1-6]. Additionally, the chips implement 461 internal) and up to 6 fan speeds fan[1-6]. Additionally, the chips implement
47up to 5 PWM outputs pwm[1-3,5-6] for controlling fan speeds both manually and 47up to 5 PWM outputs pwm[1-3,5-6] for controlling fan speeds both manually and
48automatically. 48automatically.
@@ -105,6 +105,7 @@ SCH5127:
105 in4: V1_IN 0V - 1.5V 105 in4: V1_IN 0V - 1.5V
106 in5: VTR (+3.3V standby) 0V - 4.38V 106 in5: VTR (+3.3V standby) 0V - 4.38V
107 in6: Vbat (+3.0V) 0V - 4.38V 107 in6: Vbat (+3.0V) 0V - 4.38V
108 in7: Vtrip (+1.5V) 0V - 1.99V
108 109
109Each voltage input has associated min and max limits which trigger an alarm 110Each voltage input has associated min and max limits which trigger an alarm
110when crossed. 111when crossed.
@@ -217,10 +218,10 @@ cpu0_vid RO CPU core reference voltage in
217vrm RW Voltage regulator module version 218vrm RW Voltage regulator module version
218 number. 219 number.
219 220
220in[0-6]_input RO Measured voltage in millivolts. 221in[0-7]_input RO Measured voltage in millivolts.
221in[0-6]_min RW Low limit for voltage input. 222in[0-7]_min RW Low limit for voltage input.
222in[0-6]_max RW High limit for voltage input. 223in[0-7]_max RW High limit for voltage input.
223in[0-6]_alarm RO Voltage input alarm. Returns 1 if 224in[0-7]_alarm RO Voltage input alarm. Returns 1 if
224 voltage input is or went outside the 225 voltage input is or went outside the
225 associated min-max range, 0 otherwise. 226 associated min-max range, 0 otherwise.
226 227
@@ -324,3 +325,4 @@ fan5 opt opt
324pwm5 opt opt 325pwm5 opt opt
325fan6 opt opt 326fan6 opt opt
326pwm6 opt opt 327pwm6 opt opt
328in7 yes
diff --git a/Documentation/hwmon/w83627hf b/Documentation/hwmon/w83627hf
index fb145e5e722a..8432e1118173 100644
--- a/Documentation/hwmon/w83627hf
+++ b/Documentation/hwmon/w83627hf
@@ -91,3 +91,25 @@ isaset -y -f 0x2e 0xaa
91 91
92The above sequence assumes a Super-I/O config space at 0x2e/0x2f, but 92The above sequence assumes a Super-I/O config space at 0x2e/0x2f, but
930x4e/0x4f is also possible. 930x4e/0x4f is also possible.
94
95Voltage pin mapping
96-------------------
97
98Here is a summary of the voltage pin mapping for the W83627THF. This
99can be useful to convert data provided by board manufacturers into
100working libsensors configuration statements.
101
102 W83627THF |
103 Pin | Name | Register | Sysfs attribute
104-----------------------------------------------------
105 100 | CPUVCORE | 20h | in0
106 99 | VIN0 | 21h | in1
107 98 | VIN1 | 22h | in2
108 97 | VIN2 | 24h | in4
109 114 | AVCC | 23h | in3
110 61 | 5VSB | 50h (bank 5) | in7
111 74 | VBAT | 51h (bank 5) | in8
112
113For other supported devices, you'll have to take the hard path and
114look up the information in the datasheet yourself (and then add it
115to this document please.)
diff --git a/Documentation/hwmon/w83793 b/Documentation/hwmon/w83793
index 51171a83165b..6cc5f639b721 100644
--- a/Documentation/hwmon/w83793
+++ b/Documentation/hwmon/w83793
@@ -92,7 +92,7 @@ This driver implements support for Winbond W83793G/W83793R chips.
92 92
93* Chassis 93* Chassis
94 If the case open alarm triggers, it will stay in this state unless cleared 94 If the case open alarm triggers, it will stay in this state unless cleared
95 by any write to the sysfs file "chassis". 95 by writing 0 to the sysfs file "intrusion0_alarm".
96 96
97* VID and VRM 97* VID and VRM
98 The VRM version is detected automatically, don't modify the it unless you 98 The VRM version is detected automatically, don't modify the it unless you
diff --git a/Documentation/input/ff.txt b/Documentation/input/ff.txt
index ded4d5f53109..b3867bf49f8f 100644
--- a/Documentation/input/ff.txt
+++ b/Documentation/input/ff.txt
@@ -49,7 +49,9 @@ This information is subject to change.
49#include <linux/input.h> 49#include <linux/input.h>
50#include <sys/ioctl.h> 50#include <sys/ioctl.h>
51 51
52unsigned long features[1 + FF_MAX/sizeof(unsigned long)]; 52#define BITS_TO_LONGS(x) \
53 (((x) + 8 * sizeof (unsigned long) - 1) / (8 * sizeof (unsigned long)))
54unsigned long features[BITS_TO_LONGS(FF_CNT)];
53int ioctl(int file_descriptor, int request, unsigned long *features); 55int ioctl(int file_descriptor, int request, unsigned long *features);
54 56
55"request" must be EVIOCGBIT(EV_FF, size of features array in bytes ) 57"request" must be EVIOCGBIT(EV_FF, size of features array in bytes )
diff --git a/Documentation/ioctl/ioctl-number.txt b/Documentation/ioctl/ioctl-number.txt
index d6a63c7b4478..ac293e955308 100644
--- a/Documentation/ioctl/ioctl-number.txt
+++ b/Documentation/ioctl/ioctl-number.txt
@@ -247,7 +247,7 @@ Code Seq#(hex) Include File Comments
247'p' 40-7F linux/nvram.h 247'p' 40-7F linux/nvram.h
248'p' 80-9F linux/ppdev.h user-space parport 248'p' 80-9F linux/ppdev.h user-space parport
249 <mailto:tim@cyberelk.net> 249 <mailto:tim@cyberelk.net>
250'p' A1-A4 linux/pps.h LinuxPPS 250'p' A1-A5 linux/pps.h LinuxPPS
251 <mailto:giometti@linux.it> 251 <mailto:giometti@linux.it>
252'q' 00-1F linux/serio.h 252'q' 00-1F linux/serio.h
253'q' 80-FF linux/telephony.h Internet PhoneJACK, Internet LineJACK 253'q' 80-FF linux/telephony.h Internet PhoneJACK, Internet LineJACK
diff --git a/Documentation/iostats.txt b/Documentation/iostats.txt
index 59a69ec67c40..f6dece5b7014 100644
--- a/Documentation/iostats.txt
+++ b/Documentation/iostats.txt
@@ -81,7 +81,7 @@ Field 9 -- # of I/Os currently in progress
81 The only field that should go to zero. Incremented as requests are 81 The only field that should go to zero. Incremented as requests are
82 given to appropriate struct request_queue and decremented as they finish. 82 given to appropriate struct request_queue and decremented as they finish.
83Field 10 -- # of milliseconds spent doing I/Os 83Field 10 -- # of milliseconds spent doing I/Os
84 This field is increases so long as field 9 is nonzero. 84 This field increases so long as field 9 is nonzero.
85Field 11 -- weighted # of milliseconds spent doing I/Os 85Field 11 -- weighted # of milliseconds spent doing I/Os
86 This field is incremented at each I/O start, I/O completion, I/O 86 This field is incremented at each I/O start, I/O completion, I/O
87 merge, or read of these stats by the number of I/Os in progress 87 merge, or read of these stats by the number of I/Os in progress
diff --git a/Documentation/kdump/kdump.txt b/Documentation/kdump/kdump.txt
index cab61d842259..7a9e0b4b2903 100644
--- a/Documentation/kdump/kdump.txt
+++ b/Documentation/kdump/kdump.txt
@@ -65,18 +65,21 @@ Install kexec-tools
65 65
662) Download the kexec-tools user-space package from the following URL: 662) Download the kexec-tools user-space package from the following URL:
67 67
68http://www.kernel.org/pub/linux/kernel/people/horms/kexec-tools/kexec-tools.tar.gz 68http://kernel.org/pub/linux/utils/kernel/kexec/kexec-tools.tar.gz
69 69
70This is a symlink to the latest version. 70This is a symlink to the latest version.
71 71
72The latest kexec-tools git tree is available at: 72The latest kexec-tools git tree is available at:
73 73
74git://git.kernel.org/pub/scm/linux/kernel/git/horms/kexec-tools.git 74git://git.kernel.org/pub/scm/utils/kernel/kexec/kexec-tools.git
75or 75and
76http://www.kernel.org/git/?p=linux/kernel/git/horms/kexec-tools.git 76http://www.kernel.org/pub/scm/utils/kernel/kexec/kexec-tools.git
77
78There is also a gitweb interface available at
79http://www.kernel.org/git/?p=utils/kernel/kexec/kexec-tools.git
77 80
78More information about kexec-tools can be found at 81More information about kexec-tools can be found at
79http://www.kernel.org/pub/linux/kernel/people/horms/kexec-tools/README.html 82http://www.kernel.org/pub/linux/utils/kernel/kexec/README.html
80 83
813) Unpack the tarball with the tar command, as follows: 843) Unpack the tarball with the tar command, as follows:
82 85
@@ -439,6 +442,6 @@ To Do
439Contact 442Contact
440======= 443=======
441 444
442Vivek Goyal (vgoyal@in.ibm.com) 445Vivek Goyal (vgoyal@redhat.com)
443Maneesh Soni (maneesh@in.ibm.com) 446Maneesh Soni (maneesh@in.ibm.com)
444 447
diff --git a/Documentation/kernel-parameters.txt b/Documentation/kernel-parameters.txt
index ed3708f8d0db..55fe7599bc8e 100644
--- a/Documentation/kernel-parameters.txt
+++ b/Documentation/kernel-parameters.txt
@@ -659,11 +659,6 @@ and is between 256 and 4096 characters. It is defined in the file
659 659
660 dscc4.setup= [NET] 660 dscc4.setup= [NET]
661 661
662 dynamic_printk Enables pr_debug()/dev_dbg() calls if
663 CONFIG_DYNAMIC_PRINTK_DEBUG has been enabled.
664 These can also be switched on/off via
665 <debugfs>/dynamic_printk/modules
666
667 earlycon= [KNL] Output early console device and options. 662 earlycon= [KNL] Output early console device and options.
668 uart[8250],io,<addr>[,options] 663 uart[8250],io,<addr>[,options]
669 uart[8250],mmio,<addr>[,options] 664 uart[8250],mmio,<addr>[,options]
@@ -888,6 +883,7 @@ and is between 256 and 4096 characters. It is defined in the file
888 controller 883 controller
889 i8042.nopnp [HW] Don't use ACPIPnP / PnPBIOS to discover KBD/AUX 884 i8042.nopnp [HW] Don't use ACPIPnP / PnPBIOS to discover KBD/AUX
890 controllers 885 controllers
886 i8042.notimeout [HW] Ignore timeout condition signalled by conroller
891 i8042.reset [HW] Reset the controller during init and cleanup 887 i8042.reset [HW] Reset the controller during init and cleanup
892 i8042.unlock [HW] Unlock (ignore) the keylock 888 i8042.unlock [HW] Unlock (ignore) the keylock
893 889
@@ -1709,6 +1705,9 @@ and is between 256 and 4096 characters. It is defined in the file
1709 1705
1710 no-kvmclock [X86,KVM] Disable paravirtualized KVM clock driver 1706 no-kvmclock [X86,KVM] Disable paravirtualized KVM clock driver
1711 1707
1708 no-kvmapf [X86,KVM] Disable paravirtualized asynchronous page
1709 fault handling.
1710
1712 nolapic [X86-32,APIC] Do not enable or use the local APIC. 1711 nolapic [X86-32,APIC] Do not enable or use the local APIC.
1713 1712
1714 nolapic_timer [X86-32,APIC] Do not use the local APIC timer. 1713 nolapic_timer [X86-32,APIC] Do not use the local APIC timer.
diff --git a/Documentation/ko_KR/HOWTO b/Documentation/ko_KR/HOWTO
index e3a55b6091e9..ab5189ae3428 100644
--- a/Documentation/ko_KR/HOWTO
+++ b/Documentation/ko_KR/HOWTO
@@ -391,8 +391,8 @@ bugme-new ë©”ì¼ë§ 리스트나(새로운 버그 리í¬íŠ¸ë“¤ë§Œì´ ì´ê³³ì—ì„
391bugme-janitor ë©”ì¼ë§ 리스트(bugzillaì— ëª¨ë“  ë³€í™”ë“¤ì´ ì—¬ê¸°ì„œ ë©”ì¼ë¡œ 전해진다) 391bugme-janitor ë©”ì¼ë§ 리스트(bugzillaì— ëª¨ë“  ë³€í™”ë“¤ì´ ì—¬ê¸°ì„œ ë©”ì¼ë¡œ 전해진다)
392ì— ë“±ë¡í•˜ë©´ ëœë‹¤. 392ì— ë“±ë¡í•˜ë©´ ëœë‹¤.
393 393
394 http://lists.osdl.org/mailman/listinfo/bugme-new 394 https://lists.linux-foundation.org/mailman/listinfo/bugme-new
395 http://lists.osdl.org/mailman/listinfo/bugme-janitors 395 https://lists.linux-foundation.org/mailman/listinfo/bugme-janitors
396 396
397 397
398 398
diff --git a/Documentation/kprobes.txt b/Documentation/kprobes.txt
index 741fe66d6eca..0cfb00fd86ff 100644
--- a/Documentation/kprobes.txt
+++ b/Documentation/kprobes.txt
@@ -598,7 +598,7 @@ a 5-byte jump instruction. So there are several limitations.
598a) The instructions in DCR must be relocatable. 598a) The instructions in DCR must be relocatable.
599b) The instructions in DCR must not include a call instruction. 599b) The instructions in DCR must not include a call instruction.
600c) JTPR must not be targeted by any jump or call instruction. 600c) JTPR must not be targeted by any jump or call instruction.
601d) DCR must not straddle the border betweeen functions. 601d) DCR must not straddle the border between functions.
602 602
603Anyway, these limitations are checked by the in-kernel instruction 603Anyway, these limitations are checked by the in-kernel instruction
604decoder, so you don't need to worry about that. 604decoder, so you don't need to worry about that.
diff --git a/Documentation/kvm/api.txt b/Documentation/kvm/api.txt
index b336266bea5e..ad85797c1cf0 100644
--- a/Documentation/kvm/api.txt
+++ b/Documentation/kvm/api.txt
@@ -874,7 +874,7 @@ Possible values are:
874 - KVM_MP_STATE_HALTED: the vcpu has executed a HLT instruction and 874 - KVM_MP_STATE_HALTED: the vcpu has executed a HLT instruction and
875 is waiting for an interrupt 875 is waiting for an interrupt
876 - KVM_MP_STATE_SIPI_RECEIVED: the vcpu has just received a SIPI (vector 876 - KVM_MP_STATE_SIPI_RECEIVED: the vcpu has just received a SIPI (vector
877 accesible via KVM_GET_VCPU_EVENTS) 877 accessible via KVM_GET_VCPU_EVENTS)
878 878
879This ioctl is only useful after KVM_CREATE_IRQCHIP. Without an in-kernel 879This ioctl is only useful after KVM_CREATE_IRQCHIP. Without an in-kernel
880irqchip, the multiprocessing state must be maintained by userspace. 880irqchip, the multiprocessing state must be maintained by userspace.
@@ -1085,6 +1085,184 @@ of 4 instructions that make up a hypercall.
1085If any additional field gets added to this structure later on, a bit for that 1085If any additional field gets added to this structure later on, a bit for that
1086additional piece of information will be set in the flags bitmap. 1086additional piece of information will be set in the flags bitmap.
1087 1087
10884.47 KVM_ASSIGN_PCI_DEVICE
1089
1090Capability: KVM_CAP_DEVICE_ASSIGNMENT
1091Architectures: x86 ia64
1092Type: vm ioctl
1093Parameters: struct kvm_assigned_pci_dev (in)
1094Returns: 0 on success, -1 on error
1095
1096Assigns a host PCI device to the VM.
1097
1098struct kvm_assigned_pci_dev {
1099 __u32 assigned_dev_id;
1100 __u32 busnr;
1101 __u32 devfn;
1102 __u32 flags;
1103 __u32 segnr;
1104 union {
1105 __u32 reserved[11];
1106 };
1107};
1108
1109The PCI device is specified by the triple segnr, busnr, and devfn.
1110Identification in succeeding service requests is done via assigned_dev_id. The
1111following flags are specified:
1112
1113/* Depends on KVM_CAP_IOMMU */
1114#define KVM_DEV_ASSIGN_ENABLE_IOMMU (1 << 0)
1115
11164.48 KVM_DEASSIGN_PCI_DEVICE
1117
1118Capability: KVM_CAP_DEVICE_DEASSIGNMENT
1119Architectures: x86 ia64
1120Type: vm ioctl
1121Parameters: struct kvm_assigned_pci_dev (in)
1122Returns: 0 on success, -1 on error
1123
1124Ends PCI device assignment, releasing all associated resources.
1125
1126See KVM_CAP_DEVICE_ASSIGNMENT for the data structure. Only assigned_dev_id is
1127used in kvm_assigned_pci_dev to identify the device.
1128
11294.49 KVM_ASSIGN_DEV_IRQ
1130
1131Capability: KVM_CAP_ASSIGN_DEV_IRQ
1132Architectures: x86 ia64
1133Type: vm ioctl
1134Parameters: struct kvm_assigned_irq (in)
1135Returns: 0 on success, -1 on error
1136
1137Assigns an IRQ to a passed-through device.
1138
1139struct kvm_assigned_irq {
1140 __u32 assigned_dev_id;
1141 __u32 host_irq;
1142 __u32 guest_irq;
1143 __u32 flags;
1144 union {
1145 struct {
1146 __u32 addr_lo;
1147 __u32 addr_hi;
1148 __u32 data;
1149 } guest_msi;
1150 __u32 reserved[12];
1151 };
1152};
1153
1154The following flags are defined:
1155
1156#define KVM_DEV_IRQ_HOST_INTX (1 << 0)
1157#define KVM_DEV_IRQ_HOST_MSI (1 << 1)
1158#define KVM_DEV_IRQ_HOST_MSIX (1 << 2)
1159
1160#define KVM_DEV_IRQ_GUEST_INTX (1 << 8)
1161#define KVM_DEV_IRQ_GUEST_MSI (1 << 9)
1162#define KVM_DEV_IRQ_GUEST_MSIX (1 << 10)
1163
1164It is not valid to specify multiple types per host or guest IRQ. However, the
1165IRQ type of host and guest can differ or can even be null.
1166
11674.50 KVM_DEASSIGN_DEV_IRQ
1168
1169Capability: KVM_CAP_ASSIGN_DEV_IRQ
1170Architectures: x86 ia64
1171Type: vm ioctl
1172Parameters: struct kvm_assigned_irq (in)
1173Returns: 0 on success, -1 on error
1174
1175Ends an IRQ assignment to a passed-through device.
1176
1177See KVM_ASSIGN_DEV_IRQ for the data structure. The target device is specified
1178by assigned_dev_id, flags must correspond to the IRQ type specified on
1179KVM_ASSIGN_DEV_IRQ. Partial deassignment of host or guest IRQ is allowed.
1180
11814.51 KVM_SET_GSI_ROUTING
1182
1183Capability: KVM_CAP_IRQ_ROUTING
1184Architectures: x86 ia64
1185Type: vm ioctl
1186Parameters: struct kvm_irq_routing (in)
1187Returns: 0 on success, -1 on error
1188
1189Sets the GSI routing table entries, overwriting any previously set entries.
1190
1191struct kvm_irq_routing {
1192 __u32 nr;
1193 __u32 flags;
1194 struct kvm_irq_routing_entry entries[0];
1195};
1196
1197No flags are specified so far, the corresponding field must be set to zero.
1198
1199struct kvm_irq_routing_entry {
1200 __u32 gsi;
1201 __u32 type;
1202 __u32 flags;
1203 __u32 pad;
1204 union {
1205 struct kvm_irq_routing_irqchip irqchip;
1206 struct kvm_irq_routing_msi msi;
1207 __u32 pad[8];
1208 } u;
1209};
1210
1211/* gsi routing entry types */
1212#define KVM_IRQ_ROUTING_IRQCHIP 1
1213#define KVM_IRQ_ROUTING_MSI 2
1214
1215No flags are specified so far, the corresponding field must be set to zero.
1216
1217struct kvm_irq_routing_irqchip {
1218 __u32 irqchip;
1219 __u32 pin;
1220};
1221
1222struct kvm_irq_routing_msi {
1223 __u32 address_lo;
1224 __u32 address_hi;
1225 __u32 data;
1226 __u32 pad;
1227};
1228
12294.52 KVM_ASSIGN_SET_MSIX_NR
1230
1231Capability: KVM_CAP_DEVICE_MSIX
1232Architectures: x86 ia64
1233Type: vm ioctl
1234Parameters: struct kvm_assigned_msix_nr (in)
1235Returns: 0 on success, -1 on error
1236
1237Set the number of MSI-X interrupts for an assigned device. This service can
1238only be called once in the lifetime of an assigned device.
1239
1240struct kvm_assigned_msix_nr {
1241 __u32 assigned_dev_id;
1242 __u16 entry_nr;
1243 __u16 padding;
1244};
1245
1246#define KVM_MAX_MSIX_PER_DEV 256
1247
12484.53 KVM_ASSIGN_SET_MSIX_ENTRY
1249
1250Capability: KVM_CAP_DEVICE_MSIX
1251Architectures: x86 ia64
1252Type: vm ioctl
1253Parameters: struct kvm_assigned_msix_entry (in)
1254Returns: 0 on success, -1 on error
1255
1256Specifies the routing of an MSI-X assigned device interrupt to a GSI. Setting
1257the GSI vector to zero means disabling the interrupt.
1258
1259struct kvm_assigned_msix_entry {
1260 __u32 assigned_dev_id;
1261 __u32 gsi;
1262 __u16 entry; /* The index of entry in the MSI-X table */
1263 __u16 padding[3];
1264};
1265
10885. The kvm_run structure 12665. The kvm_run structure
1089 1267
1090Application code obtains a pointer to the kvm_run structure by 1268Application code obtains a pointer to the kvm_run structure by
diff --git a/Documentation/kvm/cpuid.txt b/Documentation/kvm/cpuid.txt
index 14a12ea92b7f..882068538c9c 100644
--- a/Documentation/kvm/cpuid.txt
+++ b/Documentation/kvm/cpuid.txt
@@ -36,6 +36,9 @@ KVM_FEATURE_MMU_OP || 2 || deprecated.
36KVM_FEATURE_CLOCKSOURCE2 || 3 || kvmclock available at msrs 36KVM_FEATURE_CLOCKSOURCE2 || 3 || kvmclock available at msrs
37 || || 0x4b564d00 and 0x4b564d01 37 || || 0x4b564d00 and 0x4b564d01
38------------------------------------------------------------------------------ 38------------------------------------------------------------------------------
39KVM_FEATURE_ASYNC_PF || 4 || async pf can be enabled by
40 || || writing to msr 0x4b564d02
41------------------------------------------------------------------------------
39KVM_FEATURE_CLOCKSOURCE_STABLE_BIT || 24 || host will warn if no guest-side 42KVM_FEATURE_CLOCKSOURCE_STABLE_BIT || 24 || host will warn if no guest-side
40 || || per-cpu warps are expected in 43 || || per-cpu warps are expected in
41 || || kvmclock. 44 || || kvmclock.
diff --git a/Documentation/kvm/msr.txt b/Documentation/kvm/msr.txt
index 8ddcfe84c09a..d079aed27e03 100644
--- a/Documentation/kvm/msr.txt
+++ b/Documentation/kvm/msr.txt
@@ -3,7 +3,6 @@ Glauber Costa <glommer@redhat.com>, Red Hat Inc, 2010
3===================================================== 3=====================================================
4 4
5KVM makes use of some custom MSRs to service some requests. 5KVM makes use of some custom MSRs to service some requests.
6At present, this facility is only used by kvmclock.
7 6
8Custom MSRs have a range reserved for them, that goes from 7Custom MSRs have a range reserved for them, that goes from
90x4b564d00 to 0x4b564dff. There are MSRs outside this area, 80x4b564d00 to 0x4b564dff. There are MSRs outside this area,
@@ -151,3 +150,38 @@ MSR_KVM_SYSTEM_TIME: 0x12
151 return PRESENT; 150 return PRESENT;
152 } else 151 } else
153 return NON_PRESENT; 152 return NON_PRESENT;
153
154MSR_KVM_ASYNC_PF_EN: 0x4b564d02
155 data: Bits 63-6 hold 64-byte aligned physical address of a
156 64 byte memory area which must be in guest RAM and must be
157 zeroed. Bits 5-2 are reserved and should be zero. Bit 0 is 1
158 when asynchronous page faults are enabled on the vcpu 0 when
159 disabled. Bit 2 is 1 if asynchronous page faults can be injected
160 when vcpu is in cpl == 0.
161
162 First 4 byte of 64 byte memory location will be written to by
163 the hypervisor at the time of asynchronous page fault (APF)
164 injection to indicate type of asynchronous page fault. Value
165 of 1 means that the page referred to by the page fault is not
166 present. Value 2 means that the page is now available. Disabling
167 interrupt inhibits APFs. Guest must not enable interrupt
168 before the reason is read, or it may be overwritten by another
169 APF. Since APF uses the same exception vector as regular page
170 fault guest must reset the reason to 0 before it does
171 something that can generate normal page fault. If during page
172 fault APF reason is 0 it means that this is regular page
173 fault.
174
175 During delivery of type 1 APF cr2 contains a token that will
176 be used to notify a guest when missing page becomes
177 available. When page becomes available type 2 APF is sent with
178 cr2 set to the token associated with the page. There is special
179 kind of token 0xffffffff which tells vcpu that it should wake
180 up all processes waiting for APFs and no individual type 2 APFs
181 will be sent.
182
183 If APF is disabled while there are outstanding APFs, they will
184 not be delivered.
185
186 Currently type 2 APF will be always delivered on the same vcpu as
187 type 1 was, but guest should not rely on that.
diff --git a/Documentation/lguest/lguest.txt b/Documentation/lguest/lguest.txt
index efb3a6a045a2..6ccaf8e1a00e 100644
--- a/Documentation/lguest/lguest.txt
+++ b/Documentation/lguest/lguest.txt
@@ -111,8 +111,11 @@ Running Lguest:
111 111
112 Then use --tunnet=bridge:lg0 when launching the guest. 112 Then use --tunnet=bridge:lg0 when launching the guest.
113 113
114 See http://linux-net.osdl.org/index.php/Bridge for general information 114 See:
115 on how to get bridging working. 115
116 http://www.linuxfoundation.org/collaborate/workgroups/networking/bridge
117
118 for general information on how to get bridging to work.
116 119
117There is a helpful mailing list at http://ozlabs.org/mailman/listinfo/lguest 120There is a helpful mailing list at http://ozlabs.org/mailman/listinfo/lguest
118 121
diff --git a/Documentation/magic-number.txt b/Documentation/magic-number.txt
index 505f19607542..4b12abcb2ad3 100644
--- a/Documentation/magic-number.txt
+++ b/Documentation/magic-number.txt
@@ -150,7 +150,7 @@ NBD_REPLY_MAGIC 0x96744668 nbd_reply include/linux/nbd.h
150STL_BOARDMAGIC 0xa2267f52 stlbrd include/linux/stallion.h 150STL_BOARDMAGIC 0xa2267f52 stlbrd include/linux/stallion.h
151ENI155_MAGIC 0xa54b872d midway_eprom drivers/atm/eni.h 151ENI155_MAGIC 0xa54b872d midway_eprom drivers/atm/eni.h
152SCI_MAGIC 0xbabeface gs_port drivers/char/sh-sci.h 152SCI_MAGIC 0xbabeface gs_port drivers/char/sh-sci.h
153CODA_MAGIC 0xC0DAC0DA coda_file_info include/linux/coda_fs_i.h 153CODA_MAGIC 0xC0DAC0DA coda_file_info fs/coda/coda_fs_i.h
154DPMEM_MAGIC 0xc0ffee11 gdt_pci_sram drivers/scsi/gdth.h 154DPMEM_MAGIC 0xc0ffee11 gdt_pci_sram drivers/scsi/gdth.h
155STLI_PORTMAGIC 0xe671c7a1 stliport include/linux/istallion.h 155STLI_PORTMAGIC 0xe671c7a1 stliport include/linux/istallion.h
156YAM_MAGIC 0xF10A7654 yam_port drivers/net/hamradio/yam.c 156YAM_MAGIC 0xF10A7654 yam_port drivers/net/hamradio/yam.c
diff --git a/Documentation/networking/bridge.txt b/Documentation/networking/bridge.txt
index bec69a8a1697..a7ba5e4e2c91 100644
--- a/Documentation/networking/bridge.txt
+++ b/Documentation/networking/bridge.txt
@@ -1,8 +1,8 @@
1In order to use the Ethernet bridging functionality, you'll need the 1In order to use the Ethernet bridging functionality, you'll need the
2userspace tools. These programs and documentation are available 2userspace tools. These programs and documentation are available
3at http://www.linux-foundation.org/en/Net:Bridge. The download page is 3at http://www.linuxfoundation.org/en/Net:Bridge. The download page is
4http://prdownloads.sourceforge.net/bridge. 4http://prdownloads.sourceforge.net/bridge.
5 5
6If you still have questions, don't hesitate to post to the mailing list 6If you still have questions, don't hesitate to post to the mailing list
7(more info http://lists.osdl.org/mailman/listinfo/bridge). 7(more info https://lists.linux-foundation.org/mailman/listinfo/bridge).
8 8
diff --git a/Documentation/networking/caif/spi_porting.txt b/Documentation/networking/caif/spi_porting.txt
index 61d7c9247453..0cb8cb9098f4 100644
--- a/Documentation/networking/caif/spi_porting.txt
+++ b/Documentation/networking/caif/spi_porting.txt
@@ -32,7 +32,7 @@ the physical hardware, both with regard to SPI and to GPIOs.
32 This function is called by the CAIF SPI interface to give 32 This function is called by the CAIF SPI interface to give
33 you a chance to set up your hardware to be ready to receive 33 you a chance to set up your hardware to be ready to receive
34 a stream of data from the master. The xfer structure contains 34 a stream of data from the master. The xfer structure contains
35 both physical and logical adresses, as well as the total length 35 both physical and logical addresses, as well as the total length
36 of the transfer in both directions.The dev parameter can be used 36 of the transfer in both directions.The dev parameter can be used
37 to map to different CAIF SPI slave devices. 37 to map to different CAIF SPI slave devices.
38 38
diff --git a/Documentation/networking/dccp.txt b/Documentation/networking/dccp.txt
index 811872b45bee..d718bc2ff1cf 100644
--- a/Documentation/networking/dccp.txt
+++ b/Documentation/networking/dccp.txt
@@ -38,11 +38,11 @@ The Linux DCCP implementation does not currently support all the features that a
38specified in RFCs 4340...42. 38specified in RFCs 4340...42.
39 39
40The known bugs are at: 40The known bugs are at:
41 http://linux-net.osdl.org/index.php/TODO#DCCP 41 http://www.linuxfoundation.org/collaborate/workgroups/networking/todo#DCCP
42 42
43For more up-to-date versions of the DCCP implementation, please consider using 43For more up-to-date versions of the DCCP implementation, please consider using
44the experimental DCCP test tree; instructions for checking this out are on: 44the experimental DCCP test tree; instructions for checking this out are on:
45http://linux-net.osdl.org/index.php/DCCP_Testing#Experimental_DCCP_source_tree 45http://www.linuxfoundation.org/collaborate/workgroups/networking/dccp_testing#Experimental_DCCP_source_tree
46 46
47 47
48Socket options 48Socket options
diff --git a/Documentation/networking/generic_netlink.txt b/Documentation/networking/generic_netlink.txt
index d4f8b8b9b53c..3e071115ca90 100644
--- a/Documentation/networking/generic_netlink.txt
+++ b/Documentation/networking/generic_netlink.txt
@@ -1,3 +1,3 @@
1A wiki document on how to use Generic Netlink can be found here: 1A wiki document on how to use Generic Netlink can be found here:
2 2
3 * http://linux-net.osdl.org/index.php/Generic_Netlink_HOWTO 3 * http://www.linuxfoundation.org/collaborate/workgroups/networking/generic_netlink_howto
diff --git a/Documentation/nfc/nfc-pn544.txt b/Documentation/nfc/nfc-pn544.txt
new file mode 100644
index 000000000000..2fcac9f5996e
--- /dev/null
+++ b/Documentation/nfc/nfc-pn544.txt
@@ -0,0 +1,114 @@
1Kernel driver for the NXP Semiconductors PN544 Near Field
2Communication chip
3
4Author: Jari Vanhala
5Contact: Matti Aaltonen (matti.j.aaltonen at nokia.com)
6
7General
8-------
9
10The PN544 is an integrated transmission module for contactless
11communication. The driver goes under drives/nfc/ and is compiled as a
12module named "pn544". It registers a misc device and creates a device
13file named "/dev/pn544".
14
15Host Interfaces: I2C, SPI and HSU, this driver supports currently only I2C.
16
17The Interface
18-------------
19
20The driver offers a sysfs interface for a hardware test and an IOCTL
21interface for selecting between two operating modes. There are read,
22write and poll functions for transferring messages. The two operating
23modes are the normal (HCI) mode and the firmware update mode.
24
25PN544 is controlled by sending messages from the userspace to the
26chip. The main function of the driver is just to pass those messages
27without caring about the message content.
28
29
30Protocols
31---------
32
33In the normal (HCI) mode and in the firmware update mode read and
34write functions behave a bit differently because the message formats
35or the protocols are different.
36
37In the normal (HCI) mode the protocol used is derived from the ETSI
38HCI specification. The firmware is updated using a specific protocol,
39which is different from HCI.
40
41HCI messages consist of an eight bit header and the message body. The
42header contains the message length. Maximum size for an HCI message is
4333. In HCI mode sent messages are tested for a correct
44checksum. Firmware update messages have the length in the second (MSB)
45and third (LSB) bytes of the message. The maximum FW message length is
461024 bytes.
47
48For the ETSI HCI specification see
49http://www.etsi.org/WebSite/Technologies/ProtocolSpecification.aspx
50
51The Hardware Test
52-----------------
53
54The idea of the test is that it can performed by reading from the
55corresponding sysfs file. The test is implemented in the board file
56and it should test that PN544 can be put into the firmware update
57mode. If the test is not implemented the sysfs file does not get
58created.
59
60Example:
61> cat /sys/module/pn544/drivers/i2c\:pn544/3-002b/nfc_test
621
63
64Normal Operation
65----------------
66
67PN544 is powered up when the device file is opened, otherwise it's
68turned off. Only one instance can use the device at a time.
69
70Userspace applications control PN544 with HCI messages. The hardware
71sends an interrupt when data is available for reading. Data is
72physically read when the read function is called by a userspace
73application. Poll() checks the read interrupt state. Configuration and
74self testing are also done from the userspace using read and write.
75
76Example platform data:
77
78static int rx71_pn544_nfc_request_resources(struct i2c_client *client)
79{
80 /* Get and setup the HW resources for the device */
81}
82
83static void rx71_pn544_nfc_free_resources(void)
84{
85 /* Release the HW resources */
86}
87
88static void rx71_pn544_nfc_enable(int fw)
89{
90 /* Turn the device on */
91}
92
93static int rx71_pn544_nfc_test(void)
94{
95 /*
96 * Put the device into the FW update mode
97 * and then back to the normal mode.
98 * Check the behavior and return one on success,
99 * zero on failure.
100 */
101}
102
103static void rx71_pn544_nfc_disable(void)
104{
105 /* turn the power off */
106}
107
108static struct pn544_nfc_platform_data rx71_nfc_data = {
109 .request_resources = rx71_pn544_nfc_request_resources,
110 .free_resources = rx71_pn544_nfc_free_resources,
111 .enable = rx71_pn544_nfc_enable,
112 .test = rx71_pn544_nfc_test,
113 .disable = rx71_pn544_nfc_disable,
114};
diff --git a/Documentation/powerpc/booting-without-of.txt b/Documentation/powerpc/booting-without-of.txt
index 3272ed59dec7..7400d7555dc3 100644
--- a/Documentation/powerpc/booting-without-of.txt
+++ b/Documentation/powerpc/booting-without-of.txt
@@ -1098,7 +1098,7 @@ supported currently at the toplevel.
1098 * an arbitrary array of bytes 1098 * an arbitrary array of bytes
1099 */ 1099 */
1100 1100
1101 childnode@addresss { /* define a child node named "childnode" 1101 childnode@address { /* define a child node named "childnode"
1102 * whose unit name is "childnode at 1102 * whose unit name is "childnode at
1103 * address" 1103 * address"
1104 */ 1104 */
diff --git a/Documentation/pps/pps.txt b/Documentation/pps/pps.txt
index 125f4ab48998..d35dcdd82ff6 100644
--- a/Documentation/pps/pps.txt
+++ b/Documentation/pps/pps.txt
@@ -170,3 +170,49 @@ and the run ppstest as follow:
170 170
171Please, note that to compile userland programs you need the file timepps.h 171Please, note that to compile userland programs you need the file timepps.h
172(see Documentation/pps/). 172(see Documentation/pps/).
173
174
175Generators
176----------
177
178Sometimes one needs to be able not only to catch PPS signals but to produce
179them also. For example, running a distributed simulation, which requires
180computers' clock to be synchronized very tightly. One way to do this is to
181invent some complicated hardware solutions but it may be neither necessary
182nor affordable. The cheap way is to load a PPS generator on one of the
183computers (master) and PPS clients on others (slaves), and use very simple
184cables to deliver signals using parallel ports, for example.
185
186Parallel port cable pinout:
187pin name master slave
1881 STROBE *------ *
1892 D0 * | *
1903 D1 * | *
1914 D2 * | *
1925 D3 * | *
1936 D4 * | *
1947 D5 * | *
1958 D6 * | *
1969 D7 * | *
19710 ACK * ------*
19811 BUSY * *
19912 PE * *
20013 SEL * *
20114 AUTOFD * *
20215 ERROR * *
20316 INIT * *
20417 SELIN * *
20518-25 GND *-----------*
206
207Please note that parallel port interrupt occurs only on high->low transition,
208so it is used for PPS assert edge. PPS clear edge can be determined only
209using polling in the interrupt handler which actually can be done way more
210precisely because interrupt handling delays can be quite big and random. So
211current parport PPS generator implementation (pps_gen_parport module) is
212geared towards using the clear edge for time synchronization.
213
214Clear edge polling is done with disabled interrupts so it's better to select
215delay between assert and clear edge as small as possible to reduce system
216latencies. But if it is too small slave won't be able to capture clear edge
217transition. The default of 30us should be good enough in most situations.
218The delay can be selected using 'delay' pps_gen_parport module parameter.
diff --git a/Documentation/scheduler/00-INDEX b/Documentation/scheduler/00-INDEX
index 3c00c9c3219e..d2651c47ae27 100644
--- a/Documentation/scheduler/00-INDEX
+++ b/Documentation/scheduler/00-INDEX
@@ -3,7 +3,7 @@
3sched-arch.txt 3sched-arch.txt
4 - CPU Scheduler implementation hints for architecture specific code. 4 - CPU Scheduler implementation hints for architecture specific code.
5sched-design-CFS.txt 5sched-design-CFS.txt
6 - goals, design and implementation of the Complete Fair Scheduler. 6 - goals, design and implementation of the Completely Fair Scheduler.
7sched-domains.txt 7sched-domains.txt
8 - information on scheduling domains. 8 - information on scheduling domains.
9sched-nice-design.txt 9sched-nice-design.txt
diff --git a/Documentation/scsi/ChangeLog.lpfc b/Documentation/scsi/ChangeLog.lpfc
index 337c924cc81f..5e83769c6aa9 100644
--- a/Documentation/scsi/ChangeLog.lpfc
+++ b/Documentation/scsi/ChangeLog.lpfc
@@ -573,7 +573,7 @@ Changes from 20041018 to 20041123
573 * Backround nodev_timeout processing to DPC This enables us to 573 * Backround nodev_timeout processing to DPC This enables us to
574 unblock (stop dev_loss_tmo) when appopriate. 574 unblock (stop dev_loss_tmo) when appopriate.
575 * Fix array discovery with multiple luns. The max_luns was 0 at 575 * Fix array discovery with multiple luns. The max_luns was 0 at
576 the time the host structure was intialized. lpfc_cfg_params 576 the time the host structure was initialized. lpfc_cfg_params
577 then set the max_luns to the correct value afterwards. 577 then set the max_luns to the correct value afterwards.
578 * Remove unused define LPFC_MAX_LUN and set the default value of 578 * Remove unused define LPFC_MAX_LUN and set the default value of
579 lpfc_max_lun parameter to 512. 579 lpfc_max_lun parameter to 512.
diff --git a/Documentation/serial/tty.txt b/Documentation/serial/tty.txt
index 7c900507279f..540db41dfd5d 100644
--- a/Documentation/serial/tty.txt
+++ b/Documentation/serial/tty.txt
@@ -107,7 +107,7 @@ write_wakeup() - May be called at any point between open and close.
107 107
108dcd_change() - Report to the tty line the current DCD pin status 108dcd_change() - Report to the tty line the current DCD pin status
109 changes and the relative timestamp. The timestamp 109 changes and the relative timestamp. The timestamp
110 can be NULL. 110 cannot be NULL.
111 111
112 112
113Driver Access 113Driver Access
diff --git a/Documentation/sound/alsa/ALSA-Configuration.txt b/Documentation/sound/alsa/ALSA-Configuration.txt
index d0eb696d32e8..3c1eddd9fcc7 100644
--- a/Documentation/sound/alsa/ALSA-Configuration.txt
+++ b/Documentation/sound/alsa/ALSA-Configuration.txt
@@ -974,13 +974,6 @@ Prior to version 0.9.0rc4 options had a 'snd_' prefix. This was removed.
974 974
975 See hdspm.txt for details. 975 See hdspm.txt for details.
976 976
977 Module snd-hifier
978 -----------------
979
980 Module for the MediaTek/TempoTec HiFier Fantasia sound card.
981
982 This module supports autoprobe and multiple cards.
983
984 Module snd-ice1712 977 Module snd-ice1712
985 ------------------ 978 ------------------
986 979
@@ -1531,15 +1524,20 @@ Prior to version 0.9.0rc4 options had a 'snd_' prefix. This was removed.
1531 Module snd-oxygen 1524 Module snd-oxygen
1532 ----------------- 1525 -----------------
1533 1526
1534 Module for sound cards based on the C-Media CMI8788 chip: 1527 Module for sound cards based on the C-Media CMI8786/8787/8788 chip:
1535 * Asound A-8788 1528 * Asound A-8788
1529 * Asus Xonar DG
1536 * AuzenTech X-Meridian 1530 * AuzenTech X-Meridian
1531 * AuzenTech X-Meridian 2G
1537 * Bgears b-Enspirer 1532 * Bgears b-Enspirer
1538 * Club3D Theatron DTS 1533 * Club3D Theatron DTS
1539 * HT-Omega Claro (plus) 1534 * HT-Omega Claro (plus)
1540 * HT-Omega Claro halo (XT) 1535 * HT-Omega Claro halo (XT)
1536 * Kuroutoshikou CMI8787-HG2PCI
1541 * Razer Barracuda AC-1 1537 * Razer Barracuda AC-1
1542 * Sondigo Inferno 1538 * Sondigo Inferno
1539 * TempoTec HiFier Fantasia
1540 * TempoTec HiFier Serenade
1543 1541
1544 This module supports autoprobe and multiple cards. 1542 This module supports autoprobe and multiple cards.
1545 1543
@@ -2006,9 +2004,9 @@ Prior to version 0.9.0rc4 options had a 'snd_' prefix. This was removed.
2006 Module snd-virtuoso 2004 Module snd-virtuoso
2007 ------------------- 2005 -------------------
2008 2006
2009 Module for sound cards based on the Asus AV100/AV200 chips, 2007 Module for sound cards based on the Asus AV66/AV100/AV200 chips,
2010 i.e., Xonar D1, DX, D2, D2X, DS, HDAV1.3 (Deluxe), Essence ST 2008 i.e., Xonar D1, DX, D2, D2X, DS, Essence ST (Deluxe), Essence STX,
2011 (Deluxe) and Essence STX. 2009 HDAV1.3 (Deluxe), and HDAV1.3 Slim.
2012 2010
2013 This module supports autoprobe and multiple cards. 2011 This module supports autoprobe and multiple cards.
2014 2012
diff --git a/Documentation/sound/alsa/HD-Audio-Models.txt b/Documentation/sound/alsa/HD-Audio-Models.txt
index 37c6aad5e590..16ae4300c747 100644
--- a/Documentation/sound/alsa/HD-Audio-Models.txt
+++ b/Documentation/sound/alsa/HD-Audio-Models.txt
@@ -149,7 +149,6 @@ ALC882/883/885/888/889
149 acer-aspire-7730g Acer Aspire 7730G 149 acer-aspire-7730g Acer Aspire 7730G
150 acer-aspire-8930g Acer Aspire 8930G 150 acer-aspire-8930g Acer Aspire 8930G
151 medion Medion Laptops 151 medion Medion Laptops
152 medion-md2 Medion MD2
153 targa-dig Targa/MSI 152 targa-dig Targa/MSI
154 targa-2ch-dig Targa/MSI with 2-channel 153 targa-2ch-dig Targa/MSI with 2-channel
155 targa-8ch-dig Targa/MSI with 8-channel (MSI GX620) 154 targa-8ch-dig Targa/MSI with 8-channel (MSI GX620)
diff --git a/Documentation/sysctl/00-INDEX b/Documentation/sysctl/00-INDEX
index 1286f455992f..8cf5d493fd03 100644
--- a/Documentation/sysctl/00-INDEX
+++ b/Documentation/sysctl/00-INDEX
@@ -4,8 +4,6 @@ README
4 - general information about /proc/sys/ sysctl files. 4 - general information about /proc/sys/ sysctl files.
5abi.txt 5abi.txt
6 - documentation for /proc/sys/abi/*. 6 - documentation for /proc/sys/abi/*.
7ctl_unnumbered.txt
8 - explanation of why one should not add new binary sysctl numbers.
9fs.txt 7fs.txt
10 - documentation for /proc/sys/fs/*. 8 - documentation for /proc/sys/fs/*.
11kernel.txt 9kernel.txt
diff --git a/Documentation/sysctl/kernel.txt b/Documentation/sysctl/kernel.txt
index 574067194f38..11d5ceda5bb0 100644
--- a/Documentation/sysctl/kernel.txt
+++ b/Documentation/sysctl/kernel.txt
@@ -34,6 +34,7 @@ show up in /proc/sys/kernel:
34- hotplug 34- hotplug
35- java-appletviewer [ binfmt_java, obsolete ] 35- java-appletviewer [ binfmt_java, obsolete ]
36- java-interpreter [ binfmt_java, obsolete ] 36- java-interpreter [ binfmt_java, obsolete ]
37- kptr_restrict
37- kstack_depth_to_print [ X86 only ] 38- kstack_depth_to_print [ X86 only ]
38- l2cr [ PPC only ] 39- l2cr [ PPC only ]
39- modprobe ==> Documentation/debugging-modules.txt 40- modprobe ==> Documentation/debugging-modules.txt
@@ -261,6 +262,19 @@ This flag controls the L2 cache of G3 processor boards. If
261 262
262============================================================== 263==============================================================
263 264
265kptr_restrict:
266
267This toggle indicates whether restrictions are placed on
268exposing kernel addresses via /proc and other interfaces. When
269kptr_restrict is set to (0), there are no restrictions. When
270kptr_restrict is set to (1), the default, kernel pointers
271printed using the %pK format specifier will be replaced with 0's
272unless the user has CAP_SYSLOG. When kptr_restrict is set to
273(2), kernel pointers printed using %pK will be replaced with 0's
274regardless of privileges.
275
276==============================================================
277
264kstack_depth_to_print: (X86 only) 278kstack_depth_to_print: (X86 only)
265 279
266Controls the number of words to print when dumping the raw 280Controls the number of words to print when dumping the raw
diff --git a/Documentation/timers/timer_stats.txt b/Documentation/timers/timer_stats.txt
index 9bd00fc2e823..8abd40b22b7f 100644
--- a/Documentation/timers/timer_stats.txt
+++ b/Documentation/timers/timer_stats.txt
@@ -19,7 +19,7 @@ Linux system over a sample period:
19 19
20- the pid of the task(process) which initialized the timer 20- the pid of the task(process) which initialized the timer
21- the name of the process which initialized the timer 21- the name of the process which initialized the timer
22- the function where the timer was intialized 22- the function where the timer was initialized
23- the callback function which is associated to the timer 23- the callback function which is associated to the timer
24- the number of events (callbacks) 24- the number of events (callbacks)
25 25
diff --git a/Documentation/trace/events.txt b/Documentation/trace/events.txt
index 09bd8e902989..b510564aac7e 100644
--- a/Documentation/trace/events.txt
+++ b/Documentation/trace/events.txt
@@ -125,7 +125,7 @@ is the size of the data item, in bytes.
125For example, here's the information displayed for the 'sched_wakeup' 125For example, here's the information displayed for the 'sched_wakeup'
126event: 126event:
127 127
128# cat /debug/tracing/events/sched/sched_wakeup/format 128# cat /sys/kernel/debug/tracing/events/sched/sched_wakeup/format
129 129
130name: sched_wakeup 130name: sched_wakeup
131ID: 60 131ID: 60
@@ -201,19 +201,19 @@ to the 'filter' file for the given event.
201 201
202For example: 202For example:
203 203
204# cd /debug/tracing/events/sched/sched_wakeup 204# cd /sys/kernel/debug/tracing/events/sched/sched_wakeup
205# echo "common_preempt_count > 4" > filter 205# echo "common_preempt_count > 4" > filter
206 206
207A slightly more involved example: 207A slightly more involved example:
208 208
209# cd /debug/tracing/events/sched/sched_signal_send 209# cd /sys/kernel/debug/tracing/events/signal/signal_generate
210# echo "((sig >= 10 && sig < 15) || sig == 17) && comm != bash" > filter 210# echo "((sig >= 10 && sig < 15) || sig == 17) && comm != bash" > filter
211 211
212If there is an error in the expression, you'll get an 'Invalid 212If there is an error in the expression, you'll get an 'Invalid
213argument' error when setting it, and the erroneous string along with 213argument' error when setting it, and the erroneous string along with
214an error message can be seen by looking at the filter e.g.: 214an error message can be seen by looking at the filter e.g.:
215 215
216# cd /debug/tracing/events/sched/sched_signal_send 216# cd /sys/kernel/debug/tracing/events/signal/signal_generate
217# echo "((sig >= 10 && sig < 15) || dsig == 17) && comm != bash" > filter 217# echo "((sig >= 10 && sig < 15) || dsig == 17) && comm != bash" > filter
218-bash: echo: write error: Invalid argument 218-bash: echo: write error: Invalid argument
219# cat filter 219# cat filter
diff --git a/Documentation/w1/slaves/00-INDEX b/Documentation/w1/slaves/00-INDEX
index f8101d6b07b7..75613c9ac4db 100644
--- a/Documentation/w1/slaves/00-INDEX
+++ b/Documentation/w1/slaves/00-INDEX
@@ -2,3 +2,5 @@
2 - This file 2 - This file
3w1_therm 3w1_therm
4 - The Maxim/Dallas Semiconductor ds18*20 temperature sensor. 4 - The Maxim/Dallas Semiconductor ds18*20 temperature sensor.
5w1_ds2423
6 - The Maxim/Dallas Semiconductor ds2423 counter device.
diff --git a/Documentation/w1/slaves/w1_ds2423 b/Documentation/w1/slaves/w1_ds2423
new file mode 100644
index 000000000000..90a65d23cf59
--- /dev/null
+++ b/Documentation/w1/slaves/w1_ds2423
@@ -0,0 +1,47 @@
1Kernel driver w1_ds2423
2=======================
3
4Supported chips:
5 * Maxim DS2423 based counter devices.
6
7supported family codes:
8 W1_THERM_DS2423 0x1D
9
10Author: Mika Laitio <lamikr@pilppa.org>
11
12Description
13-----------
14
15Support is provided through the sysfs w1_slave file. Each opening and
16read sequence of w1_slave file initiates the read of counters and ram
17available in DS2423 pages 12 - 15.
18
19Result of each page is provided as an ASCII output where each counter
20value and associated ram buffer is outpputed to own line.
21
22Each lines will contain the values of 42 bytes read from the counter and
23memory page along the crc=YES or NO for indicating whether the read operation
24was successfull and CRC matched.
25If the operation was successfull, there is also in the end of each line
26a counter value expressed as an integer after c=
27
28Meaning of 42 bytes represented is following:
29 - 1 byte from ram page
30 - 4 bytes for the counter value
31 - 4 zero bytes
32 - 2 bytes for crc16 which was calculated from the data read since the previous crc bytes
33 - 31 remaining bytes from the ram page
34 - crc=YES/NO indicating whether read was ok and crc matched
35 - c=<int> current counter value
36
37example from the successfull read:
3800 02 00 00 00 00 00 00 00 6d 38 00 ff ff 00 00 fe ff 00 00 ff ff 00 00 ff ff 00 00 ff ff 00 00 ff ff 00 00 ff ff 00 00 ff ff crc=YES c=2
3900 02 00 00 00 00 00 00 00 e0 1f 00 ff ff 00 00 ff ff 00 00 ff ff 00 00 ff ff 00 00 ff ff 00 00 ff ff 00 00 ff ff 00 00 ff ff crc=YES c=2
4000 29 c6 5d 18 00 00 00 00 04 37 00 ff ff 00 00 ff ff 00 00 ff ff 00 00 ff ff 00 00 ff ff 00 00 ff ff 00 00 ff ff 00 00 ff ff crc=YES c=408798761
4100 05 00 00 00 00 00 00 00 8d 39 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff crc=YES c=5
42
43example from the read with crc errors:
4400 02 00 00 00 00 00 00 00 6d 38 00 ff ff 00 00 fe ff 00 00 ff ff 00 00 ff ff 00 00 ff ff 00 00 ff ff 00 00 ff ff 00 00 ff ff crc=YES c=2
4500 02 00 00 22 00 00 00 00 e0 1f 00 ff ff 00 00 ff ff 00 00 ff ff 00 00 ff ff 00 00 ff ff 00 00 ff ff 00 00 ff ff 00 00 ff ff crc=NO
4600 e1 61 5d 19 00 00 00 00 df 0b 00 ff ff 00 00 ff ff 00 00 ff ff 00 00 ff ff 00 00 ff ff 00 00 ff ff 00 00 ff ff 00 00 ff ff crc=NO
4700 05 00 00 20 00 00 00 00 8d 39 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff crc=NO
diff --git a/Documentation/x86/boot.txt b/Documentation/x86/boot.txt
index bdeb81ccb5f6..9b7221a86df2 100644
--- a/Documentation/x86/boot.txt
+++ b/Documentation/x86/boot.txt
@@ -622,9 +622,9 @@ Protocol: 2.08+
622 The payload may be compressed. The format of both the compressed and 622 The payload may be compressed. The format of both the compressed and
623 uncompressed data should be determined using the standard magic 623 uncompressed data should be determined using the standard magic
624 numbers. The currently supported compression formats are gzip 624 numbers. The currently supported compression formats are gzip
625 (magic numbers 1F 8B or 1F 9E), bzip2 (magic number 42 5A) and LZMA 625 (magic numbers 1F 8B or 1F 9E), bzip2 (magic number 42 5A), LZMA
626 (magic number 5D 00). The uncompressed payload is currently always ELF 626 (magic number 5D 00), and XZ (magic number FD 37). The uncompressed
627 (magic number 7F 45 4C 46). 627 payload is currently always ELF (magic number 7F 45 4C 46).
628 628
629Field name: payload_length 629Field name: payload_length
630Type: read 630Type: read
diff --git a/Documentation/xz.txt b/Documentation/xz.txt
new file mode 100644
index 000000000000..2cf3e2608de3
--- /dev/null
+++ b/Documentation/xz.txt
@@ -0,0 +1,121 @@
1
2XZ data compression in Linux
3============================
4
5Introduction
6
7 XZ is a general purpose data compression format with high compression
8 ratio and relatively fast decompression. The primary compression
9 algorithm (filter) is LZMA2. Additional filters can be used to improve
10 compression ratio even further. E.g. Branch/Call/Jump (BCJ) filters
11 improve compression ratio of executable data.
12
13 The XZ decompressor in Linux is called XZ Embedded. It supports
14 the LZMA2 filter and optionally also BCJ filters. CRC32 is supported
15 for integrity checking. The home page of XZ Embedded is at
16 <http://tukaani.org/xz/embedded.html>, where you can find the
17 latest version and also information about using the code outside
18 the Linux kernel.
19
20 For userspace, XZ Utils provide a zlib-like compression library
21 and a gzip-like command line tool. XZ Utils can be downloaded from
22 <http://tukaani.org/xz/>.
23
24XZ related components in the kernel
25
26 The xz_dec module provides XZ decompressor with single-call (buffer
27 to buffer) and multi-call (stateful) APIs. The usage of the xz_dec
28 module is documented in include/linux/xz.h.
29
30 The xz_dec_test module is for testing xz_dec. xz_dec_test is not
31 useful unless you are hacking the XZ decompressor. xz_dec_test
32 allocates a char device major dynamically to which one can write
33 .xz files from userspace. The decompressed output is thrown away.
34 Keep an eye on dmesg to see diagnostics printed by xz_dec_test.
35 See the xz_dec_test source code for the details.
36
37 For decompressing the kernel image, initramfs, and initrd, there
38 is a wrapper function in lib/decompress_unxz.c. Its API is the
39 same as in other decompress_*.c files, which is defined in
40 include/linux/decompress/generic.h.
41
42 scripts/xz_wrap.sh is a wrapper for the xz command line tool found
43 from XZ Utils. The wrapper sets compression options to values suitable
44 for compressing the kernel image.
45
46 For kernel makefiles, two commands are provided for use with
47 $(call if_needed). The kernel image should be compressed with
48 $(call if_needed,xzkern) which will use a BCJ filter and a big LZMA2
49 dictionary. It will also append a four-byte trailer containing the
50 uncompressed size of the file, which is needed by the boot code.
51 Other things should be compressed with $(call if_needed,xzmisc)
52 which will use no BCJ filter and 1 MiB LZMA2 dictionary.
53
54Notes on compression options
55
56 Since the XZ Embedded supports only streams with no integrity check or
57 CRC32, make sure that you don't use some other integrity check type
58 when encoding files that are supposed to be decoded by the kernel. With
59 liblzma, you need to use either LZMA_CHECK_NONE or LZMA_CHECK_CRC32
60 when encoding. With the xz command line tool, use --check=none or
61 --check=crc32.
62
63 Using CRC32 is strongly recommended unless there is some other layer
64 which will verify the integrity of the uncompressed data anyway.
65 Double checking the integrity would probably be waste of CPU cycles.
66 Note that the headers will always have a CRC32 which will be validated
67 by the decoder; you can only change the integrity check type (or
68 disable it) for the actual uncompressed data.
69
70 In userspace, LZMA2 is typically used with dictionary sizes of several
71 megabytes. The decoder needs to have the dictionary in RAM, thus big
72 dictionaries cannot be used for files that are intended to be decoded
73 by the kernel. 1 MiB is probably the maximum reasonable dictionary
74 size for in-kernel use (maybe more is OK for initramfs). The presets
75 in XZ Utils may not be optimal when creating files for the kernel,
76 so don't hesitate to use custom settings. Example:
77
78 xz --check=crc32 --lzma2=dict=512KiB inputfile
79
80 An exception to above dictionary size limitation is when the decoder
81 is used in single-call mode. Decompressing the kernel itself is an
82 example of this situation. In single-call mode, the memory usage
83 doesn't depend on the dictionary size, and it is perfectly fine to
84 use a big dictionary: for maximum compression, the dictionary should
85 be at least as big as the uncompressed data itself.
86
87Future plans
88
89 Creating a limited XZ encoder may be considered if people think it is
90 useful. LZMA2 is slower to compress than e.g. Deflate or LZO even at
91 the fastest settings, so it isn't clear if LZMA2 encoder is wanted
92 into the kernel.
93
94 Support for limited random-access reading is planned for the
95 decompression code. I don't know if it could have any use in the
96 kernel, but I know that it would be useful in some embedded projects
97 outside the Linux kernel.
98
99Conformance to the .xz file format specification
100
101 There are a couple of corner cases where things have been simplified
102 at expense of detecting errors as early as possible. These should not
103 matter in practice all, since they don't cause security issues. But
104 it is good to know this if testing the code e.g. with the test files
105 from XZ Utils.
106
107Reporting bugs
108
109 Before reporting a bug, please check that it's not fixed already
110 at upstream. See <http://tukaani.org/xz/embedded.html> to get the
111 latest code.
112
113 Report bugs to <lasse.collin@tukaani.org> or visit #tukaani on
114 Freenode and talk to Larhzu. I don't actively read LKML or other
115 kernel-related mailing lists, so if there's something I should know,
116 you should email to me personally or use IRC.
117
118 Don't bother Igor Pavlov with questions about the XZ implementation
119 in the kernel or about XZ Utils. While these two implementations
120 include essential code that is directly based on Igor Pavlov's code,
121 these implementations aren't maintained nor supported by him.
diff --git a/Documentation/zh_CN/HOWTO b/Documentation/zh_CN/HOWTO
index 69160779e432..faf976c0c731 100644
--- a/Documentation/zh_CN/HOWTO
+++ b/Documentation/zh_CN/HOWTO
@@ -347,8 +347,8 @@ bugzilla.kernel.org是Linux内核开å‘者们用æ¥è·Ÿè¸ªå†…æ ¸Bug的网站。æˆ
347最新bug的通知,å¯ä»¥è®¢é˜…bugme-newé‚®ä»¶åˆ—è¡¨ï¼ˆåªæœ‰æ–°çš„bug报告会被寄到这里) 347最新bug的通知,å¯ä»¥è®¢é˜…bugme-newé‚®ä»¶åˆ—è¡¨ï¼ˆåªæœ‰æ–°çš„bug报告会被寄到这里)
348或者订阅bugme-janitor邮件列表(所有bugzillaçš„å˜åŠ¨éƒ½ä¼šè¢«å¯„åˆ°è¿™é‡Œï¼‰ã€‚ 348或者订阅bugme-janitor邮件列表(所有bugzillaçš„å˜åŠ¨éƒ½ä¼šè¢«å¯„åˆ°è¿™é‡Œï¼‰ã€‚
349 349
350 http://lists.osdl.org/mailman/listinfo/bugme-new 350 https://lists.linux-foundation.org/mailman/listinfo/bugme-new
351 http://lists.osdl.org/mailman/listinfo/bugme-janitors 351 https://lists.linux-foundation.org/mailman/listinfo/bugme-janitors
352 352
353 353
354邮件列表 354邮件列表
diff --git a/Documentation/zh_CN/SubmittingDrivers b/Documentation/zh_CN/SubmittingDrivers
index c27b0f6cdd39..5889f8df6312 100644
--- a/Documentation/zh_CN/SubmittingDrivers
+++ b/Documentation/zh_CN/SubmittingDrivers
@@ -61,7 +61,7 @@ Linux 2.4:
61Linux 2.6: 61Linux 2.6:
62 除了éµå¾ªå’Œ 2.4 ç‰ˆå†…æ ¸åŒæ ·çš„规则外,你还需è¦åœ¨ linux-kernel 邮件 62 除了éµå¾ªå’Œ 2.4 ç‰ˆå†…æ ¸åŒæ ·çš„规则外,你还需è¦åœ¨ linux-kernel 邮件
63 列表上跟踪最新的 API å˜åŒ–ã€‚å‘ Linux 2.6 内核æäº¤é©±åŠ¨çš„é¡¶çº§è”系人 63 列表上跟踪最新的 API å˜åŒ–ã€‚å‘ Linux 2.6 内核æäº¤é©±åŠ¨çš„é¡¶çº§è”系人
64 是 Andrew Morton <akpm@osdl.org>。 64 是 Andrew Morton <akpm@linux-foundation.org>。
65 65
66决定设备驱动能å¦è¢«æŽ¥å—çš„æ¡ä»¶ 66决定设备驱动能å¦è¢«æŽ¥å—çš„æ¡ä»¶
67---------------------------- 67----------------------------
diff --git a/MAINTAINERS b/MAINTAINERS
index 64d7621ab35b..3dd5c6fce989 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -496,7 +496,6 @@ S: Supported
496F: arch/x86/kernel/microcode_amd.c 496F: arch/x86/kernel/microcode_amd.c
497 497
498AMS (Apple Motion Sensor) DRIVER 498AMS (Apple Motion Sensor) DRIVER
499M: Stelian Pop <stelian@popies.net>
500M: Michael Hanselmann <linux-kernel@hansmi.ch> 499M: Michael Hanselmann <linux-kernel@hansmi.ch>
501S: Supported 500S: Supported
502F: drivers/macintosh/ams/ 501F: drivers/macintosh/ams/
@@ -1524,6 +1523,14 @@ S: Supported
1524F: block/bsg.c 1523F: block/bsg.c
1525F: include/linux/bsg.h 1524F: include/linux/bsg.h
1526 1525
1526BT87X AUDIO DRIVER
1527M: Clemens Ladisch <clemens@ladisch.de>
1528L: alsa-devel@alsa-project.org (moderated for non-subscribers)
1529T: git git://git.alsa-project.org/alsa-kernel.git
1530S: Maintained
1531F: Documentation/sound/alsa/Bt87x.txt
1532F: sound/pci/bt87x.c
1533
1527BT8XXGPIO DRIVER 1534BT8XXGPIO DRIVER
1528M: Michael Buesch <mb@bu3sch.de> 1535M: Michael Buesch <mb@bu3sch.de>
1529W: http://bu3sch.de/btgpio.php 1536W: http://bu3sch.de/btgpio.php
@@ -1549,6 +1556,13 @@ S: Maintained
1549F: Documentation/video4linux/bttv/ 1556F: Documentation/video4linux/bttv/
1550F: drivers/media/video/bt8xx/bttv* 1557F: drivers/media/video/bt8xx/bttv*
1551 1558
1559C-MEDIA CMI8788 DRIVER
1560M: Clemens Ladisch <clemens@ladisch.de>
1561L: alsa-devel@alsa-project.org (moderated for non-subscribers)
1562T: git git://git.alsa-project.org/alsa-kernel.git
1563S: Maintained
1564F: sound/pci/oxygen/
1565
1552CACHEFILES: FS-CACHE BACKEND FOR CACHING ON MOUNTED FILESYSTEMS 1566CACHEFILES: FS-CACHE BACKEND FOR CACHING ON MOUNTED FILESYSTEMS
1553M: David Howells <dhowells@redhat.com> 1567M: David Howells <dhowells@redhat.com>
1554L: linux-cachefs@redhat.com 1568L: linux-cachefs@redhat.com
@@ -2008,7 +2022,7 @@ F: drivers/scsi/dc395x.*
2008DCCP PROTOCOL 2022DCCP PROTOCOL
2009M: Arnaldo Carvalho de Melo <acme@ghostprotocols.net> 2023M: Arnaldo Carvalho de Melo <acme@ghostprotocols.net>
2010L: dccp@vger.kernel.org 2024L: dccp@vger.kernel.org
2011W: http://linux-net.osdl.org/index.php/DCCP 2025W: http://www.linuxfoundation.org/collaborate/workgroups/networking/dccp
2012S: Maintained 2026S: Maintained
2013F: include/linux/dccp.h 2027F: include/linux/dccp.h
2014F: include/linux/tfrc.h 2028F: include/linux/tfrc.h
@@ -2340,6 +2354,13 @@ W: bluesmoke.sourceforge.net
2340S: Maintained 2354S: Maintained
2341F: drivers/edac/r82600_edac.c 2355F: drivers/edac/r82600_edac.c
2342 2356
2357EDIROL UA-101/UA-1000 DRIVER
2358M: Clemens Ladisch <clemens@ladisch.de>
2359L: alsa-devel@alsa-project.org (moderated for non-subscribers)
2360T: git git://git.alsa-project.org/alsa-kernel.git
2361S: Maintained
2362F: sound/usb/misc/ua101.c
2363
2343EEEPC LAPTOP EXTRAS DRIVER 2364EEEPC LAPTOP EXTRAS DRIVER
2344M: Corentin Chary <corentincj@iksaif.net> 2365M: Corentin Chary <corentincj@iksaif.net>
2345L: acpi4asus-user@lists.sourceforge.net 2366L: acpi4asus-user@lists.sourceforge.net
@@ -2430,7 +2451,7 @@ ETHERNET BRIDGE
2430M: Stephen Hemminger <shemminger@linux-foundation.org> 2451M: Stephen Hemminger <shemminger@linux-foundation.org>
2431L: bridge@lists.linux-foundation.org 2452L: bridge@lists.linux-foundation.org
2432L: netdev@vger.kernel.org 2453L: netdev@vger.kernel.org
2433W: http://www.linux-foundation.org/en/Net:Bridge 2454W: http://www.linuxfoundation.org/en/Net:Bridge
2434S: Maintained 2455S: Maintained
2435F: include/linux/netfilter_bridge/ 2456F: include/linux/netfilter_bridge/
2436F: net/bridge/ 2457F: net/bridge/
@@ -3508,6 +3529,13 @@ L: linux-serial@vger.kernel.org
3508S: Maintained 3529S: Maintained
3509F: drivers/serial/jsm/ 3530F: drivers/serial/jsm/
3510 3531
3532K10TEMP HARDWARE MONITORING DRIVER
3533M: Clemens Ladisch <clemens@ladisch.de>
3534L: lm-sensors@lm-sensors.org
3535S: Maintained
3536F: Documentation/hwmon/k10temp
3537F: drivers/hwmon/k10temp.c
3538
3511K8TEMP HARDWARE MONITORING DRIVER 3539K8TEMP HARDWARE MONITORING DRIVER
3512M: Rudolf Marek <r.marek@assembler.cz> 3540M: Rudolf Marek <r.marek@assembler.cz>
3513L: lm-sensors@lm-sensors.org 3541L: lm-sensors@lm-sensors.org
@@ -4093,9 +4121,8 @@ F: include/linux/module.h
4093F: kernel/module.c 4121F: kernel/module.c
4094 4122
4095MOTION EYE VAIO PICTUREBOOK CAMERA DRIVER 4123MOTION EYE VAIO PICTUREBOOK CAMERA DRIVER
4096M: Stelian Pop <stelian@popies.net>
4097W: http://popies.net/meye/ 4124W: http://popies.net/meye/
4098S: Maintained 4125S: Orphan
4099F: Documentation/video4linux/meye.txt 4126F: Documentation/video4linux/meye.txt
4100F: drivers/media/video/meye.* 4127F: drivers/media/video/meye.*
4101F: include/linux/meye.h 4128F: include/linux/meye.h
@@ -4539,6 +4566,13 @@ F: drivers/of
4539F: include/linux/of*.h 4566F: include/linux/of*.h
4540K: of_get_property 4567K: of_get_property
4541 4568
4569OPL4 DRIVER
4570M: Clemens Ladisch <clemens@ladisch.de>
4571L: alsa-devel@alsa-project.org (moderated for non-subscribers)
4572T: git git://git.alsa-project.org/alsa-kernel.git
4573S: Maintained
4574F: sound/drivers/opl4/
4575
4542OPROFILE 4576OPROFILE
4543M: Robert Richter <robert.richter@amd.com> 4577M: Robert Richter <robert.richter@amd.com>
4544L: oprofile-list@lists.sf.net 4578L: oprofile-list@lists.sf.net
@@ -4635,7 +4669,7 @@ M: Jeremy Fitzhardinge <jeremy@xensource.com>
4635M: Chris Wright <chrisw@sous-sol.org> 4669M: Chris Wright <chrisw@sous-sol.org>
4636M: Alok Kataria <akataria@vmware.com> 4670M: Alok Kataria <akataria@vmware.com>
4637M: Rusty Russell <rusty@rustcorp.com.au> 4671M: Rusty Russell <rusty@rustcorp.com.au>
4638L: virtualization@lists.osdl.org 4672L: virtualization@lists.linux-foundation.org
4639S: Supported 4673S: Supported
4640F: Documentation/ia64/paravirt_ops.txt 4674F: Documentation/ia64/paravirt_ops.txt
4641F: arch/*/kernel/paravirt* 4675F: arch/*/kernel/paravirt*
@@ -5133,11 +5167,6 @@ F: kernel/rcu*
5133F: kernel/srcu* 5167F: kernel/srcu*
5134X: kernel/rcutorture.c 5168X: kernel/rcutorture.c
5135 5169
5136REAL TIME CLOCK DRIVER (LEGACY)
5137M: Paul Gortmaker <p_gortmaker@yahoo.com>
5138S: Maintained
5139F: drivers/char/rtc.c
5140
5141REAL TIME CLOCK (RTC) SUBSYSTEM 5170REAL TIME CLOCK (RTC) SUBSYSTEM
5142M: Alessandro Zummo <a.zummo@towertech.it> 5171M: Alessandro Zummo <a.zummo@towertech.it>
5143L: rtc-linux@googlegroups.com 5172L: rtc-linux@googlegroups.com
@@ -5290,7 +5319,7 @@ SAMSUNG AUDIO (ASoC) DRIVERS
5290M: Jassi Brar <jassi.brar@samsung.com> 5319M: Jassi Brar <jassi.brar@samsung.com>
5291L: alsa-devel@alsa-project.org (moderated for non-subscribers) 5320L: alsa-devel@alsa-project.org (moderated for non-subscribers)
5292S: Supported 5321S: Supported
5293F: sound/soc/s3c24xx 5322F: sound/soc/samsung
5294 5323
5295TIMEKEEPING, NTP 5324TIMEKEEPING, NTP
5296M: John Stultz <johnstul@us.ibm.com> 5325M: John Stultz <johnstul@us.ibm.com>
@@ -6298,6 +6327,13 @@ S: Maintained
6298W: http://www.one-eyed-alien.net/~mdharm/linux-usb/ 6327W: http://www.one-eyed-alien.net/~mdharm/linux-usb/
6299F: drivers/usb/storage/ 6328F: drivers/usb/storage/
6300 6329
6330USB MIDI DRIVER
6331M: Clemens Ladisch <clemens@ladisch.de>
6332L: alsa-devel@alsa-project.org (moderated for non-subscribers)
6333T: git git://git.alsa-project.org/alsa-kernel.git
6334S: Maintained
6335F: sound/usb/midi.*
6336
6301USB OHCI DRIVER 6337USB OHCI DRIVER
6302M: David Brownell <dbrownell@users.sourceforge.net> 6338M: David Brownell <dbrownell@users.sourceforge.net>
6303L: linux-usb@vger.kernel.org 6339L: linux-usb@vger.kernel.org
@@ -6537,7 +6573,7 @@ F: include/linux/virtio_console.h
6537VIRTIO HOST (VHOST) 6573VIRTIO HOST (VHOST)
6538M: "Michael S. Tsirkin" <mst@redhat.com> 6574M: "Michael S. Tsirkin" <mst@redhat.com>
6539L: kvm@vger.kernel.org 6575L: kvm@vger.kernel.org
6540L: virtualization@lists.osdl.org 6576L: virtualization@lists.linux-foundation.org
6541L: netdev@vger.kernel.org 6577L: netdev@vger.kernel.org
6542S: Maintained 6578S: Maintained
6543F: drivers/vhost/ 6579F: drivers/vhost/
@@ -6587,7 +6623,7 @@ F: net/8021q/
6587 6623
6588VLYNQ BUS 6624VLYNQ BUS
6589M: Florian Fainelli <florian@openwrt.org> 6625M: Florian Fainelli <florian@openwrt.org>
6590L: openwrt-devel@lists.openwrt.org 6626L: openwrt-devel@lists.openwrt.org (subscribers-only)
6591S: Maintained 6627S: Maintained
6592F: drivers/vlynq/vlynq.c 6628F: drivers/vlynq/vlynq.c
6593F: include/linux/vlynq.h 6629F: include/linux/vlynq.h
@@ -6807,7 +6843,7 @@ XEN HYPERVISOR INTERFACE
6807M: Jeremy Fitzhardinge <jeremy.fitzhardinge@citrix.com> 6843M: Jeremy Fitzhardinge <jeremy.fitzhardinge@citrix.com>
6808M: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com> 6844M: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
6809L: xen-devel@lists.xensource.com (moderated for non-subscribers) 6845L: xen-devel@lists.xensource.com (moderated for non-subscribers)
6810L: virtualization@lists.osdl.org 6846L: virtualization@lists.linux-foundation.org
6811S: Supported 6847S: Supported
6812F: arch/x86/xen/ 6848F: arch/x86/xen/
6813F: drivers/*/xen-*front.c 6849F: drivers/*/xen-*front.c
diff --git a/arch/alpha/kernel/time.c b/arch/alpha/kernel/time.c
index 0f1d8493cfca..c1f3e7cb82a4 100644
--- a/arch/alpha/kernel/time.c
+++ b/arch/alpha/kernel/time.c
@@ -506,7 +506,7 @@ set_rtc_mmss(unsigned long nowtime)
506 CMOS_WRITE(real_seconds,RTC_SECONDS); 506 CMOS_WRITE(real_seconds,RTC_SECONDS);
507 CMOS_WRITE(real_minutes,RTC_MINUTES); 507 CMOS_WRITE(real_minutes,RTC_MINUTES);
508 } else { 508 } else {
509 printk(KERN_WARNING 509 printk_once(KERN_NOTICE
510 "set_rtc_mmss: can't update from %d to %d\n", 510 "set_rtc_mmss: can't update from %d to %d\n",
511 cmos_minutes, real_minutes); 511 cmos_minutes, real_minutes);
512 retval = -1; 512 retval = -1;
diff --git a/arch/arm/common/it8152.c b/arch/arm/common/it8152.c
index 42ff90b46dfb..665ebf7e62a6 100644
--- a/arch/arm/common/it8152.c
+++ b/arch/arm/common/it8152.c
@@ -236,7 +236,7 @@ static struct resource it8152_mem = {
236 236
237/* 237/*
238 * The following functions are needed for DMA bouncing. 238 * The following functions are needed for DMA bouncing.
239 * ITE8152 chip can addrees up to 64MByte, so all the devices 239 * ITE8152 chip can address up to 64MByte, so all the devices
240 * connected to ITE8152 (PCI and USB) should have limited DMA window 240 * connected to ITE8152 (PCI and USB) should have limited DMA window
241 */ 241 */
242 242
diff --git a/arch/arm/common/vic.c b/arch/arm/common/vic.c
index ba65f6eedca6..cb660bc54d7a 100644
--- a/arch/arm/common/vic.c
+++ b/arch/arm/common/vic.c
@@ -70,7 +70,7 @@ static inline struct vic_device *to_vic(struct sys_device *sys)
70 * vic_init2 - common initialisation code 70 * vic_init2 - common initialisation code
71 * @base: Base of the VIC. 71 * @base: Base of the VIC.
72 * 72 *
73 * Common initialisation code for registeration 73 * Common initialisation code for registration
74 * and resume. 74 * and resume.
75*/ 75*/
76static void vic_init2(void __iomem *base) 76static void vic_init2(void __iomem *base)
diff --git a/arch/arm/mach-at91/board-ecbat91.c b/arch/arm/mach-at91/board-ecbat91.c
index 7b58c948a957..de2fd04e7c8a 100644
--- a/arch/arm/mach-at91/board-ecbat91.c
+++ b/arch/arm/mach-at91/board-ecbat91.c
@@ -128,17 +128,17 @@ static struct spi_board_info __initdata ecb_at91spi_devices[] = {
128 .platform_data = &my_flash0_platform, 128 .platform_data = &my_flash0_platform,
129#endif 129#endif
130 }, 130 },
131 { /* User accessable spi - cs1 (250KHz) */ 131 { /* User accessible spi - cs1 (250KHz) */
132 .modalias = "spi-cs1", 132 .modalias = "spi-cs1",
133 .chip_select = 1, 133 .chip_select = 1,
134 .max_speed_hz = 250 * 1000, 134 .max_speed_hz = 250 * 1000,
135 }, 135 },
136 { /* User accessable spi - cs2 (1MHz) */ 136 { /* User accessible spi - cs2 (1MHz) */
137 .modalias = "spi-cs2", 137 .modalias = "spi-cs2",
138 .chip_select = 2, 138 .chip_select = 2,
139 .max_speed_hz = 1 * 1000 * 1000, 139 .max_speed_hz = 1 * 1000 * 1000,
140 }, 140 },
141 { /* User accessable spi - cs3 (10MHz) */ 141 { /* User accessible spi - cs3 (10MHz) */
142 .modalias = "spi-cs3", 142 .modalias = "spi-cs3",
143 .chip_select = 3, 143 .chip_select = 3,
144 .max_speed_hz = 10 * 1000 * 1000, 144 .max_speed_hz = 10 * 1000 * 1000,
diff --git a/arch/arm/mach-at91/pm.c b/arch/arm/mach-at91/pm.c
index dafbacc25eb1..ea53f4d9b283 100644
--- a/arch/arm/mach-at91/pm.c
+++ b/arch/arm/mach-at91/pm.c
@@ -301,7 +301,7 @@ static void at91_pm_end(void)
301} 301}
302 302
303 303
304static struct platform_suspend_ops at91_pm_ops ={ 304static const struct platform_suspend_ops at91_pm_ops = {
305 .valid = at91_pm_valid_state, 305 .valid = at91_pm_valid_state,
306 .begin = at91_pm_begin, 306 .begin = at91_pm_begin,
307 .enter = at91_pm_enter, 307 .enter = at91_pm_enter,
diff --git a/arch/arm/mach-bcmring/csp/chipc/chipcHw.c b/arch/arm/mach-bcmring/csp/chipc/chipcHw.c
index b3a61d860c65..96273ff34956 100644
--- a/arch/arm/mach-bcmring/csp/chipc/chipcHw.c
+++ b/arch/arm/mach-bcmring/csp/chipc/chipcHw.c
@@ -757,7 +757,7 @@ static int chipcHw_divide(int num, int denom)
757 t = t << 1; 757 t = t << 1;
758 } 758 }
759 759
760 /* Intialize the result */ 760 /* Initialize the result */
761 r = 0; 761 r = 0;
762 762
763 do { 763 do {
diff --git a/arch/arm/mach-bcmring/csp/dmac/dmacHw.c b/arch/arm/mach-bcmring/csp/dmac/dmacHw.c
index 7b9bac2d79a5..6b9be2e98e51 100644
--- a/arch/arm/mach-bcmring/csp/dmac/dmacHw.c
+++ b/arch/arm/mach-bcmring/csp/dmac/dmacHw.c
@@ -893,7 +893,7 @@ int dmacHw_setDataDescriptor(dmacHw_CONFIG_t *pConfig, /* [ IN ] Configuration
893*/ 893*/
894/****************************************************************************/ 894/****************************************************************************/
895uint32_t dmacHw_getDmaControllerAttribute(dmacHw_HANDLE_t handle, /* [ IN ] DMA Channel handle */ 895uint32_t dmacHw_getDmaControllerAttribute(dmacHw_HANDLE_t handle, /* [ IN ] DMA Channel handle */
896 dmacHw_CONTROLLER_ATTRIB_e attr /* [ IN ] DMA Controler attribute of type dmacHw_CONTROLLER_ATTRIB_e */ 896 dmacHw_CONTROLLER_ATTRIB_e attr /* [ IN ] DMA Controller attribute of type dmacHw_CONTROLLER_ATTRIB_e */
897 ) { 897 ) {
898 dmacHw_CBLK_t *pCblk = dmacHw_HANDLE_TO_CBLK(handle); 898 dmacHw_CBLK_t *pCblk = dmacHw_HANDLE_TO_CBLK(handle);
899 899
diff --git a/arch/arm/mach-bcmring/csp/dmac/dmacHw_extra.c b/arch/arm/mach-bcmring/csp/dmac/dmacHw_extra.c
index ff7b436d0935..77f84b40dda9 100644
--- a/arch/arm/mach-bcmring/csp/dmac/dmacHw_extra.c
+++ b/arch/arm/mach-bcmring/csp/dmac/dmacHw_extra.c
@@ -316,7 +316,7 @@ static void DisplayDescRing(void *pDescriptor, /* [ IN ] Descriptor buffer */
316/** 316/**
317* @brief Check if DMA channel is the flow controller 317* @brief Check if DMA channel is the flow controller
318* 318*
319* @return 1 : If DMA is a flow controler 319* @return 1 : If DMA is a flow controller
320* 0 : Peripheral is the flow controller 320* 0 : Peripheral is the flow controller
321* 321*
322* @note 322* @note
diff --git a/arch/arm/mach-bcmring/csp/tmr/tmrHw.c b/arch/arm/mach-bcmring/csp/tmr/tmrHw.c
index 5c1c9a0e5ed2..16225e43f3c3 100644
--- a/arch/arm/mach-bcmring/csp/tmr/tmrHw.c
+++ b/arch/arm/mach-bcmring/csp/tmr/tmrHw.c
@@ -558,7 +558,7 @@ static int tmrHw_divide(int num, int denom)
558 t = t << 1; 558 t = t << 1;
559 } 559 }
560 560
561 /* Intialize the result */ 561 /* Initialize the result */
562 r = 0; 562 r = 0;
563 563
564 do { 564 do {
diff --git a/arch/arm/mach-bcmring/dma.c b/arch/arm/mach-bcmring/dma.c
index 77eb35c89cd0..8d1baf3f4683 100644
--- a/arch/arm/mach-bcmring/dma.c
+++ b/arch/arm/mach-bcmring/dma.c
@@ -671,7 +671,7 @@ static int ConfigChannel(DMA_Handle_t handle)
671 671
672/****************************************************************************/ 672/****************************************************************************/
673/** 673/**
674* Intializes all of the data structures associated with the DMA. 674* Initializes all of the data structures associated with the DMA.
675* @return 675* @return
676* >= 0 - Initialization was successfull. 676* >= 0 - Initialization was successfull.
677* 677*
diff --git a/arch/arm/mach-bcmring/include/csp/dmacHw.h b/arch/arm/mach-bcmring/include/csp/dmacHw.h
index 5d510130a25f..6c8da2b9fc1f 100644
--- a/arch/arm/mach-bcmring/include/csp/dmacHw.h
+++ b/arch/arm/mach-bcmring/include/csp/dmacHw.h
@@ -590,7 +590,7 @@ void dmacHw_printDebugInfo(dmacHw_HANDLE_t handle, /* [ IN ] DMA Channel handle
590*/ 590*/
591/****************************************************************************/ 591/****************************************************************************/
592uint32_t dmacHw_getDmaControllerAttribute(dmacHw_HANDLE_t handle, /* [ IN ] DMA Channel handle */ 592uint32_t dmacHw_getDmaControllerAttribute(dmacHw_HANDLE_t handle, /* [ IN ] DMA Channel handle */
593 dmacHw_CONTROLLER_ATTRIB_e attr /* [ IN ] DMA Controler attribute of type dmacHw_CONTROLLER_ATTRIB_e */ 593 dmacHw_CONTROLLER_ATTRIB_e attr /* [ IN ] DMA Controller attribute of type dmacHw_CONTROLLER_ATTRIB_e */
594 ); 594 );
595 595
596#endif /* _DMACHW_H */ 596#endif /* _DMACHW_H */
diff --git a/arch/arm/mach-bcmring/include/csp/tmrHw.h b/arch/arm/mach-bcmring/include/csp/tmrHw.h
index f1236d00cb97..2cbb530db8ea 100644
--- a/arch/arm/mach-bcmring/include/csp/tmrHw.h
+++ b/arch/arm/mach-bcmring/include/csp/tmrHw.h
@@ -76,7 +76,7 @@ tmrHw_RATE_t tmrHw_setPeriodicTimerRate(tmrHw_ID_t timerId, /* [ IN ] Timer Id
76* certain time interval 76* certain time interval
77* 77*
78* This function initializes a periodic timer to generate timer interrupt 78* This function initializes a periodic timer to generate timer interrupt
79* after every time interval in milisecond 79* after every time interval in millisecond
80* 80*
81* @return On success: Effective interval set in mili-second 81* @return On success: Effective interval set in mili-second
82* On failure: 0 82* On failure: 0
@@ -93,7 +93,7 @@ tmrHw_INTERVAL_t tmrHw_setPeriodicTimerInterval(tmrHw_ID_t timerId, /* [ IN ] T
93* after certain time interval 93* after certain time interval
94* 94*
95* This function initializes a periodic timer to generate a single ticks after 95* This function initializes a periodic timer to generate a single ticks after
96* certain time interval in milisecond 96* certain time interval in millisecond
97* 97*
98* @return On success: Effective interval set in mili-second 98* @return On success: Effective interval set in mili-second
99* On failure: 0 99* On failure: 0
diff --git a/arch/arm/mach-bcmring/include/mach/csp/dmacHw_priv.h b/arch/arm/mach-bcmring/include/mach/csp/dmacHw_priv.h
index cbf334d1c761..d67e2f8c22de 100644
--- a/arch/arm/mach-bcmring/include/mach/csp/dmacHw_priv.h
+++ b/arch/arm/mach-bcmring/include/mach/csp/dmacHw_priv.h
@@ -28,7 +28,7 @@
28 28
29/* Data type for DMA Link List Item */ 29/* Data type for DMA Link List Item */
30typedef struct { 30typedef struct {
31 uint32_t sar; /* Source Adress Register. 31 uint32_t sar; /* Source Address Register.
32 Address must be aligned to CTLx.SRC_TR_WIDTH. */ 32 Address must be aligned to CTLx.SRC_TR_WIDTH. */
33 uint32_t dar; /* Destination Address Register. 33 uint32_t dar; /* Destination Address Register.
34 Address must be aligned to CTLx.DST_TR_WIDTH. */ 34 Address must be aligned to CTLx.DST_TR_WIDTH. */
diff --git a/arch/arm/mach-bcmring/include/mach/csp/dmacHw_reg.h b/arch/arm/mach-bcmring/include/mach/csp/dmacHw_reg.h
index 891cea87e333..f1ecf96f2da5 100644
--- a/arch/arm/mach-bcmring/include/mach/csp/dmacHw_reg.h
+++ b/arch/arm/mach-bcmring/include/mach/csp/dmacHw_reg.h
@@ -35,7 +35,7 @@ typedef struct {
35 35
36/* Data type representing DMA channel registers */ 36/* Data type representing DMA channel registers */
37typedef struct { 37typedef struct {
38 dmacHw_REG64_t ChannelSar; /* Source Adress Register. 64 bits (upper 32 bits are reserved) 38 dmacHw_REG64_t ChannelSar; /* Source Address Register. 64 bits (upper 32 bits are reserved)
39 Address must be aligned to CTLx.SRC_TR_WIDTH. 39 Address must be aligned to CTLx.SRC_TR_WIDTH.
40 */ 40 */
41 dmacHw_REG64_t ChannelDar; /* Destination Address Register.64 bits (upper 32 bits are reserved) 41 dmacHw_REG64_t ChannelDar; /* Destination Address Register.64 bits (upper 32 bits are reserved)
diff --git a/arch/arm/mach-davinci/pm.c b/arch/arm/mach-davinci/pm.c
index fab953b43dea..1bd73a04be20 100644
--- a/arch/arm/mach-davinci/pm.c
+++ b/arch/arm/mach-davinci/pm.c
@@ -110,7 +110,7 @@ static int davinci_pm_enter(suspend_state_t state)
110 return ret; 110 return ret;
111} 111}
112 112
113static struct platform_suspend_ops davinci_pm_ops = { 113static const struct platform_suspend_ops davinci_pm_ops = {
114 .enter = davinci_pm_enter, 114 .enter = davinci_pm_enter,
115 .valid = suspend_valid_only_mem, 115 .valid = suspend_valid_only_mem,
116}; 116};
diff --git a/arch/arm/mach-gemini/include/mach/hardware.h b/arch/arm/mach-gemini/include/mach/hardware.h
index 213a4fcfeb1c..8c950e1d06be 100644
--- a/arch/arm/mach-gemini/include/mach/hardware.h
+++ b/arch/arm/mach-gemini/include/mach/hardware.h
@@ -33,7 +33,7 @@
33#define GEMINI_LPC_HOST_BASE 0x47000000 33#define GEMINI_LPC_HOST_BASE 0x47000000
34#define GEMINI_LPC_IO_BASE 0x47800000 34#define GEMINI_LPC_IO_BASE 0x47800000
35#define GEMINI_INTERRUPT_BASE 0x48000000 35#define GEMINI_INTERRUPT_BASE 0x48000000
36/* TODO: Different interrupt controlers when SMP 36/* TODO: Different interrupt controllers when SMP
37 * #define GEMINI_INTERRUPT0_BASE 0x48000000 37 * #define GEMINI_INTERRUPT0_BASE 0x48000000
38 * #define GEMINI_INTERRUPT1_BASE 0x49000000 38 * #define GEMINI_INTERRUPT1_BASE 0x49000000
39 */ 39 */
diff --git a/arch/arm/mach-imx/mach-pcm038.c b/arch/arm/mach-imx/mach-pcm038.c
index f667a262dfc1..505614803bc6 100644
--- a/arch/arm/mach-imx/mach-pcm038.c
+++ b/arch/arm/mach-imx/mach-pcm038.c
@@ -254,10 +254,10 @@ static struct regulator_init_data cam_data = {
254 254
255static struct mc13783_regulator_init_data pcm038_regulators[] = { 255static struct mc13783_regulator_init_data pcm038_regulators[] = {
256 { 256 {
257 .id = MC13783_REGU_VCAM, 257 .id = MC13783_REG_VCAM,
258 .init_data = &cam_data, 258 .init_data = &cam_data,
259 }, { 259 }, {
260 .id = MC13783_REGU_VMMC1, 260 .id = MC13783_REG_VMMC1,
261 .init_data = &sdhc1_data, 261 .init_data = &sdhc1_data,
262 }, 262 },
263}; 263};
diff --git a/arch/arm/mach-imx/pm-imx27.c b/arch/arm/mach-imx/pm-imx27.c
index 6bf81ceea137..acf17691d2cc 100644
--- a/arch/arm/mach-imx/pm-imx27.c
+++ b/arch/arm/mach-imx/pm-imx27.c
@@ -32,7 +32,7 @@ static int mx27_suspend_enter(suspend_state_t state)
32 return 0; 32 return 0;
33} 33}
34 34
35static struct platform_suspend_ops mx27_suspend_ops = { 35static const struct platform_suspend_ops mx27_suspend_ops = {
36 .enter = mx27_suspend_enter, 36 .enter = mx27_suspend_enter,
37 .valid = suspend_valid_only_mem, 37 .valid = suspend_valid_only_mem,
38}; 38};
diff --git a/arch/arm/mach-kirkwood/openrd-setup.c b/arch/arm/mach-kirkwood/openrd-setup.c
index c9d77fad10ab..cfcca4174e25 100644
--- a/arch/arm/mach-kirkwood/openrd-setup.c
+++ b/arch/arm/mach-kirkwood/openrd-setup.c
@@ -171,7 +171,7 @@ static void __init openrd_init(void)
171 171
172 kirkwood_i2c_init(); 172 kirkwood_i2c_init();
173 173
174 if (machine_is_openrd_client()) { 174 if (machine_is_openrd_client() || machine_is_openrd_ultimate()) {
175 i2c_register_board_info(0, i2c_board_info, 175 i2c_register_board_info(0, i2c_board_info,
176 ARRAY_SIZE(i2c_board_info)); 176 ARRAY_SIZE(i2c_board_info));
177 kirkwood_audio_init(); 177 kirkwood_audio_init();
diff --git a/arch/arm/mach-lpc32xx/pm.c b/arch/arm/mach-lpc32xx/pm.c
index a6e2aed9a49f..e76d41bb7056 100644
--- a/arch/arm/mach-lpc32xx/pm.c
+++ b/arch/arm/mach-lpc32xx/pm.c
@@ -123,7 +123,7 @@ static int lpc32xx_pm_enter(suspend_state_t state)
123 return 0; 123 return 0;
124} 124}
125 125
126static struct platform_suspend_ops lpc32xx_pm_ops = { 126static const struct platform_suspend_ops lpc32xx_pm_ops = {
127 .valid = suspend_valid_only_mem, 127 .valid = suspend_valid_only_mem,
128 .enter = lpc32xx_pm_enter, 128 .enter = lpc32xx_pm_enter,
129}; 129};
diff --git a/arch/arm/mach-msm/include/mach/entry-macro-qgic.S b/arch/arm/mach-msm/include/mach/entry-macro-qgic.S
index 4dc99aa65d07..12467157afb9 100644
--- a/arch/arm/mach-msm/include/mach/entry-macro-qgic.S
+++ b/arch/arm/mach-msm/include/mach/entry-macro-qgic.S
@@ -26,7 +26,7 @@
26 * The interrupt numbering scheme is defined in the 26 * The interrupt numbering scheme is defined in the
27 * interrupt controller spec. To wit: 27 * interrupt controller spec. To wit:
28 * 28 *
29 * Migrated the code from ARM MP port to be more consistant 29 * Migrated the code from ARM MP port to be more consistent
30 * with interrupt processing , the following still holds true 30 * with interrupt processing , the following still holds true
31 * however, all interrupts are treated the same regardless of 31 * however, all interrupts are treated the same regardless of
32 * if they are local IPI or PPI 32 * if they are local IPI or PPI
diff --git a/arch/arm/mach-msm/io.c b/arch/arm/mach-msm/io.c
index 800f327a7ecc..1260007a9dd1 100644
--- a/arch/arm/mach-msm/io.c
+++ b/arch/arm/mach-msm/io.c
@@ -154,7 +154,7 @@ __msm_ioremap(unsigned long phys_addr, size_t size, unsigned int mtype)
154{ 154{
155 if (mtype == MT_DEVICE) { 155 if (mtype == MT_DEVICE) {
156 /* The peripherals in the 88000000 - D0000000 range 156 /* The peripherals in the 88000000 - D0000000 range
157 * are only accessable by type MT_DEVICE_NONSHARED. 157 * are only accessible by type MT_DEVICE_NONSHARED.
158 * Adjust mtype as necessary to make this "just work." 158 * Adjust mtype as necessary to make this "just work."
159 */ 159 */
160 if ((phys_addr >= 0x88000000) && (phys_addr < 0xD0000000)) 160 if ((phys_addr >= 0x88000000) && (phys_addr < 0xD0000000))
diff --git a/arch/arm/mach-mx3/mach-mx31_3ds.c b/arch/arm/mach-mx3/mach-mx31_3ds.c
index 4e516b49a901..899a969e92fa 100644
--- a/arch/arm/mach-mx3/mach-mx31_3ds.c
+++ b/arch/arm/mach-mx3/mach-mx31_3ds.c
@@ -140,10 +140,10 @@ static struct regulator_init_data gpo_init = {
140 140
141static struct mc13783_regulator_init_data mx31_3ds_regulators[] = { 141static struct mc13783_regulator_init_data mx31_3ds_regulators[] = {
142 { 142 {
143 .id = MC13783_REGU_PWGT1SPI, /* Power Gate for ARM core. */ 143 .id = MC13783_REG_PWGT1SPI, /* Power Gate for ARM core. */
144 .init_data = &pwgtx_init, 144 .init_data = &pwgtx_init,
145 }, { 145 }, {
146 .id = MC13783_REGU_PWGT2SPI, /* Power Gate for L2 Cache. */ 146 .id = MC13783_REG_PWGT2SPI, /* Power Gate for L2 Cache. */
147 .init_data = &pwgtx_init, 147 .init_data = &pwgtx_init,
148 }, { 148 }, {
149 149
diff --git a/arch/arm/mach-mx3/mach-mx31moboard.c b/arch/arm/mach-mx3/mach-mx31moboard.c
index 203d21a510aa..1aa8d65fccbb 100644
--- a/arch/arm/mach-mx3/mach-mx31moboard.c
+++ b/arch/arm/mach-mx3/mach-mx31moboard.c
@@ -216,11 +216,11 @@ static struct regulator_init_data cam_vreg_data = {
216 216
217static struct mc13783_regulator_init_data moboard_regulators[] = { 217static struct mc13783_regulator_init_data moboard_regulators[] = {
218 { 218 {
219 .id = MC13783_REGU_VMMC1, 219 .id = MC13783_REG_VMMC1,
220 .init_data = &sdhc_vreg_data, 220 .init_data = &sdhc_vreg_data,
221 }, 221 },
222 { 222 {
223 .id = MC13783_REGU_VCAM, 223 .id = MC13783_REG_VCAM,
224 .init_data = &cam_vreg_data, 224 .init_data = &cam_vreg_data,
225 }, 225 },
226}; 226};
diff --git a/arch/arm/mach-omap1/pm.c b/arch/arm/mach-omap1/pm.c
index 0cca23a85175..98ba9784aa15 100644
--- a/arch/arm/mach-omap1/pm.c
+++ b/arch/arm/mach-omap1/pm.c
@@ -647,7 +647,7 @@ static struct irqaction omap_wakeup_irq = {
647 647
648 648
649 649
650static struct platform_suspend_ops omap_pm_ops ={ 650static const struct platform_suspend_ops omap_pm_ops = {
651 .prepare = omap_pm_prepare, 651 .prepare = omap_pm_prepare,
652 .enter = omap_pm_enter, 652 .enter = omap_pm_enter,
653 .finish = omap_pm_finish, 653 .finish = omap_pm_finish,
diff --git a/arch/arm/mach-omap2/Makefile b/arch/arm/mach-omap2/Makefile
index cd7332f50b2d..1c0c2b02d870 100644
--- a/arch/arm/mach-omap2/Makefile
+++ b/arch/arm/mach-omap2/Makefile
@@ -187,16 +187,19 @@ obj-$(CONFIG_MACH_NOKIA_RX51) += board-rx51.o \
187 hsmmc.o 187 hsmmc.o
188obj-$(CONFIG_MACH_OMAP_ZOOM2) += board-zoom.o \ 188obj-$(CONFIG_MACH_OMAP_ZOOM2) += board-zoom.o \
189 board-zoom-peripherals.o \ 189 board-zoom-peripherals.o \
190 board-zoom-display.o \
190 board-flash.o \ 191 board-flash.o \
191 hsmmc.o \ 192 hsmmc.o \
192 board-zoom-debugboard.o 193 board-zoom-debugboard.o
193obj-$(CONFIG_MACH_OMAP_ZOOM3) += board-zoom.o \ 194obj-$(CONFIG_MACH_OMAP_ZOOM3) += board-zoom.o \
194 board-zoom-peripherals.o \ 195 board-zoom-peripherals.o \
196 board-zoom-display.o \
195 board-flash.o \ 197 board-flash.o \
196 hsmmc.o \ 198 hsmmc.o \
197 board-zoom-debugboard.o 199 board-zoom-debugboard.o
198obj-$(CONFIG_MACH_OMAP_3630SDP) += board-3630sdp.o \ 200obj-$(CONFIG_MACH_OMAP_3630SDP) += board-3630sdp.o \
199 board-zoom-peripherals.o \ 201 board-zoom-peripherals.o \
202 board-zoom-display.o \
200 board-flash.o \ 203 board-flash.o \
201 hsmmc.o 204 hsmmc.o
202obj-$(CONFIG_MACH_CM_T35) += board-cm-t35.o \ 205obj-$(CONFIG_MACH_CM_T35) += board-cm-t35.o \
diff --git a/arch/arm/mach-omap2/board-3430sdp.c b/arch/arm/mach-omap2/board-3430sdp.c
index 3b39ef1a680a..d4e41ef86aa5 100644
--- a/arch/arm/mach-omap2/board-3430sdp.c
+++ b/arch/arm/mach-omap2/board-3430sdp.c
@@ -38,6 +38,7 @@
38#include <plat/dma.h> 38#include <plat/dma.h>
39#include <plat/gpmc.h> 39#include <plat/gpmc.h>
40#include <plat/display.h> 40#include <plat/display.h>
41#include <plat/panel-generic-dpi.h>
41 42
42#include <plat/gpmc-smc91x.h> 43#include <plat/gpmc-smc91x.h>
43 44
@@ -270,13 +271,18 @@ static struct omap_dss_device sdp3430_lcd_device = {
270 .platform_disable = sdp3430_panel_disable_lcd, 271 .platform_disable = sdp3430_panel_disable_lcd,
271}; 272};
272 273
274static struct panel_generic_dpi_data dvi_panel = {
275 .name = "generic",
276 .platform_enable = sdp3430_panel_enable_dvi,
277 .platform_disable = sdp3430_panel_disable_dvi,
278};
279
273static struct omap_dss_device sdp3430_dvi_device = { 280static struct omap_dss_device sdp3430_dvi_device = {
274 .name = "dvi", 281 .name = "dvi",
275 .driver_name = "generic_panel",
276 .type = OMAP_DISPLAY_TYPE_DPI, 282 .type = OMAP_DISPLAY_TYPE_DPI,
283 .driver_name = "generic_dpi_panel",
284 .data = &dvi_panel,
277 .phy.dpi.data_lines = 24, 285 .phy.dpi.data_lines = 24,
278 .platform_enable = sdp3430_panel_enable_dvi,
279 .platform_disable = sdp3430_panel_disable_dvi,
280}; 286};
281 287
282static struct omap_dss_device sdp3430_tv_device = { 288static struct omap_dss_device sdp3430_tv_device = {
diff --git a/arch/arm/mach-omap2/board-3630sdp.c b/arch/arm/mach-omap2/board-3630sdp.c
index 5d41dbe059a3..62645640f5e4 100644
--- a/arch/arm/mach-omap2/board-3630sdp.c
+++ b/arch/arm/mach-omap2/board-3630sdp.c
@@ -207,6 +207,7 @@ static void __init omap_sdp_init(void)
207{ 207{
208 omap3_mux_init(board_mux, OMAP_PACKAGE_CBP); 208 omap3_mux_init(board_mux, OMAP_PACKAGE_CBP);
209 zoom_peripherals_init(); 209 zoom_peripherals_init();
210 zoom_display_init();
210 board_smc91x_init(); 211 board_smc91x_init();
211 board_flash_init(sdp_flash_partitions, chip_sel_sdp); 212 board_flash_init(sdp_flash_partitions, chip_sel_sdp);
212 enable_board_wakeup_source(); 213 enable_board_wakeup_source();
diff --git a/arch/arm/mach-omap2/board-am3517evm.c b/arch/arm/mach-omap2/board-am3517evm.c
index bc1562648020..10d60b7743cf 100644
--- a/arch/arm/mach-omap2/board-am3517evm.c
+++ b/arch/arm/mach-omap2/board-am3517evm.c
@@ -35,6 +35,7 @@
35#include <plat/common.h> 35#include <plat/common.h>
36#include <plat/usb.h> 36#include <plat/usb.h>
37#include <plat/display.h> 37#include <plat/display.h>
38#include <plat/panel-generic-dpi.h>
38 39
39#include "mux.h" 40#include "mux.h"
40#include "control.h" 41#include "control.h"
@@ -303,13 +304,18 @@ static void am3517_evm_panel_disable_lcd(struct omap_dss_device *dssdev)
303 lcd_enabled = 0; 304 lcd_enabled = 0;
304} 305}
305 306
307static struct panel_generic_dpi_data lcd_panel = {
308 .name = "sharp_lq",
309 .platform_enable = am3517_evm_panel_enable_lcd,
310 .platform_disable = am3517_evm_panel_disable_lcd,
311};
312
306static struct omap_dss_device am3517_evm_lcd_device = { 313static struct omap_dss_device am3517_evm_lcd_device = {
307 .type = OMAP_DISPLAY_TYPE_DPI, 314 .type = OMAP_DISPLAY_TYPE_DPI,
308 .name = "lcd", 315 .name = "lcd",
309 .driver_name = "sharp_lq_panel", 316 .driver_name = "generic_dpi_panel",
317 .data = &lcd_panel,
310 .phy.dpi.data_lines = 16, 318 .phy.dpi.data_lines = 16,
311 .platform_enable = am3517_evm_panel_enable_lcd,
312 .platform_disable = am3517_evm_panel_disable_lcd,
313}; 319};
314 320
315static int am3517_evm_panel_enable_tv(struct omap_dss_device *dssdev) 321static int am3517_evm_panel_enable_tv(struct omap_dss_device *dssdev)
@@ -346,13 +352,18 @@ static void am3517_evm_panel_disable_dvi(struct omap_dss_device *dssdev)
346 dvi_enabled = 0; 352 dvi_enabled = 0;
347} 353}
348 354
355static struct panel_generic_dpi_data dvi_panel = {
356 .name = "generic",
357 .platform_enable = am3517_evm_panel_enable_dvi,
358 .platform_disable = am3517_evm_panel_disable_dvi,
359};
360
349static struct omap_dss_device am3517_evm_dvi_device = { 361static struct omap_dss_device am3517_evm_dvi_device = {
350 .type = OMAP_DISPLAY_TYPE_DPI, 362 .type = OMAP_DISPLAY_TYPE_DPI,
351 .name = "dvi", 363 .name = "dvi",
352 .driver_name = "generic_panel", 364 .driver_name = "generic_dpi_panel",
365 .data = &dvi_panel,
353 .phy.dpi.data_lines = 24, 366 .phy.dpi.data_lines = 24,
354 .platform_enable = am3517_evm_panel_enable_dvi,
355 .platform_disable = am3517_evm_panel_disable_dvi,
356}; 367};
357 368
358static struct omap_dss_device *am3517_evm_dss_devices[] = { 369static struct omap_dss_device *am3517_evm_dss_devices[] = {
diff --git a/arch/arm/mach-omap2/board-cm-t35.c b/arch/arm/mach-omap2/board-cm-t35.c
index 486a3de5f401..dac141610666 100644
--- a/arch/arm/mach-omap2/board-cm-t35.c
+++ b/arch/arm/mach-omap2/board-cm-t35.c
@@ -46,6 +46,7 @@
46#include <plat/gpmc.h> 46#include <plat/gpmc.h>
47#include <plat/usb.h> 47#include <plat/usb.h>
48#include <plat/display.h> 48#include <plat/display.h>
49#include <plat/panel-generic-dpi.h>
49#include <plat/mcspi.h> 50#include <plat/mcspi.h>
50 51
51#include <mach/hardware.h> 52#include <mach/hardware.h>
@@ -351,22 +352,32 @@ static void cm_t35_panel_disable_tv(struct omap_dss_device *dssdev)
351{ 352{
352} 353}
353 354
355static struct panel_generic_dpi_data lcd_panel = {
356 .name = "toppoly_tdo35s",
357 .platform_enable = cm_t35_panel_enable_lcd,
358 .platform_disable = cm_t35_panel_disable_lcd,
359};
360
354static struct omap_dss_device cm_t35_lcd_device = { 361static struct omap_dss_device cm_t35_lcd_device = {
355 .name = "lcd", 362 .name = "lcd",
356 .driver_name = "toppoly_tdo35s_panel",
357 .type = OMAP_DISPLAY_TYPE_DPI, 363 .type = OMAP_DISPLAY_TYPE_DPI,
364 .driver_name = "generic_dpi_panel",
365 .data = &lcd_panel,
358 .phy.dpi.data_lines = 18, 366 .phy.dpi.data_lines = 18,
359 .platform_enable = cm_t35_panel_enable_lcd, 367};
360 .platform_disable = cm_t35_panel_disable_lcd, 368
369static struct panel_generic_dpi_data dvi_panel = {
370 .name = "generic",
371 .platform_enable = cm_t35_panel_enable_dvi,
372 .platform_disable = cm_t35_panel_disable_dvi,
361}; 373};
362 374
363static struct omap_dss_device cm_t35_dvi_device = { 375static struct omap_dss_device cm_t35_dvi_device = {
364 .name = "dvi", 376 .name = "dvi",
365 .driver_name = "generic_panel",
366 .type = OMAP_DISPLAY_TYPE_DPI, 377 .type = OMAP_DISPLAY_TYPE_DPI,
378 .driver_name = "generic_dpi_panel",
379 .data = &dvi_panel,
367 .phy.dpi.data_lines = 24, 380 .phy.dpi.data_lines = 24,
368 .platform_enable = cm_t35_panel_enable_dvi,
369 .platform_disable = cm_t35_panel_disable_dvi,
370}; 381};
371 382
372static struct omap_dss_device cm_t35_tv_device = { 383static struct omap_dss_device cm_t35_tv_device = {
diff --git a/arch/arm/mach-omap2/board-devkit8000.c b/arch/arm/mach-omap2/board-devkit8000.c
index 451e7ff08b18..00bb1fc5e017 100644
--- a/arch/arm/mach-omap2/board-devkit8000.c
+++ b/arch/arm/mach-omap2/board-devkit8000.c
@@ -46,6 +46,7 @@
46#include <plat/nand.h> 46#include <plat/nand.h>
47#include <plat/usb.h> 47#include <plat/usb.h>
48#include <plat/display.h> 48#include <plat/display.h>
49#include <plat/panel-generic-dpi.h>
49 50
50#include <plat/mcspi.h> 51#include <plat/mcspi.h>
51#include <linux/input/matrix_keypad.h> 52#include <linux/input/matrix_keypad.h>
@@ -149,23 +150,32 @@ static struct regulator_consumer_supply devkit8000_vmmc1_supply =
149static struct regulator_consumer_supply devkit8000_vio_supply = 150static struct regulator_consumer_supply devkit8000_vio_supply =
150 REGULATOR_SUPPLY("vcc", "spi2.0"); 151 REGULATOR_SUPPLY("vcc", "spi2.0");
151 152
153static struct panel_generic_dpi_data lcd_panel = {
154 .name = "generic",
155 .platform_enable = devkit8000_panel_enable_lcd,
156 .platform_disable = devkit8000_panel_disable_lcd,
157};
158
152static struct omap_dss_device devkit8000_lcd_device = { 159static struct omap_dss_device devkit8000_lcd_device = {
153 .name = "lcd", 160 .name = "lcd",
154 .driver_name = "generic_panel",
155 .type = OMAP_DISPLAY_TYPE_DPI, 161 .type = OMAP_DISPLAY_TYPE_DPI,
162 .driver_name = "generic_dpi_panel",
163 .data = &lcd_panel,
156 .phy.dpi.data_lines = 24, 164 .phy.dpi.data_lines = 24,
157 .reset_gpio = -EINVAL, /* will be replaced */
158 .platform_enable = devkit8000_panel_enable_lcd,
159 .platform_disable = devkit8000_panel_disable_lcd,
160}; 165};
166
167static struct panel_generic_dpi_data dvi_panel = {
168 .name = "generic",
169 .platform_enable = devkit8000_panel_enable_dvi,
170 .platform_disable = devkit8000_panel_disable_dvi,
171};
172
161static struct omap_dss_device devkit8000_dvi_device = { 173static struct omap_dss_device devkit8000_dvi_device = {
162 .name = "dvi", 174 .name = "dvi",
163 .driver_name = "generic_panel",
164 .type = OMAP_DISPLAY_TYPE_DPI, 175 .type = OMAP_DISPLAY_TYPE_DPI,
176 .driver_name = "generic_dpi_panel",
177 .data = &dvi_panel,
165 .phy.dpi.data_lines = 24, 178 .phy.dpi.data_lines = 24,
166 .reset_gpio = -EINVAL, /* will be replaced */
167 .platform_enable = devkit8000_panel_enable_dvi,
168 .platform_disable = devkit8000_panel_disable_dvi,
169}; 179};
170 180
171static struct omap_dss_device devkit8000_tv_device = { 181static struct omap_dss_device devkit8000_tv_device = {
diff --git a/arch/arm/mach-omap2/board-igep0020.c b/arch/arm/mach-omap2/board-igep0020.c
index 0afa3011db0f..ebaa230e67ed 100644
--- a/arch/arm/mach-omap2/board-igep0020.c
+++ b/arch/arm/mach-omap2/board-igep0020.c
@@ -31,6 +31,7 @@
31#include <plat/gpmc.h> 31#include <plat/gpmc.h>
32#include <plat/usb.h> 32#include <plat/usb.h>
33#include <plat/display.h> 33#include <plat/display.h>
34#include <plat/panel-generic-dpi.h>
34#include <plat/onenand.h> 35#include <plat/onenand.h>
35 36
36#include "mux.h" 37#include "mux.h"
@@ -459,13 +460,18 @@ static void igep2_disable_dvi(struct omap_dss_device *dssdev)
459 gpio_direction_output(IGEP2_GPIO_DVI_PUP, 0); 460 gpio_direction_output(IGEP2_GPIO_DVI_PUP, 0);
460} 461}
461 462
463static struct panel_generic_dpi_data dvi_panel = {
464 .name = "generic",
465 .platform_enable = igep2_enable_dvi,
466 .platform_disable = igep2_disable_dvi,
467};
468
462static struct omap_dss_device igep2_dvi_device = { 469static struct omap_dss_device igep2_dvi_device = {
463 .type = OMAP_DISPLAY_TYPE_DPI, 470 .type = OMAP_DISPLAY_TYPE_DPI,
464 .name = "dvi", 471 .name = "dvi",
465 .driver_name = "generic_panel", 472 .driver_name = "generic_dpi_panel",
473 .data = &dvi_panel,
466 .phy.dpi.data_lines = 24, 474 .phy.dpi.data_lines = 24,
467 .platform_enable = igep2_enable_dvi,
468 .platform_disable = igep2_disable_dvi,
469}; 475};
470 476
471static struct omap_dss_device *igep2_dss_devices[] = { 477static struct omap_dss_device *igep2_dss_devices[] = {
diff --git a/arch/arm/mach-omap2/board-omap3beagle.c b/arch/arm/mach-omap2/board-omap3beagle.c
index 6c127605942f..a4fe8e1ee1bd 100644
--- a/arch/arm/mach-omap2/board-omap3beagle.c
+++ b/arch/arm/mach-omap2/board-omap3beagle.c
@@ -41,6 +41,7 @@
41#include <plat/board.h> 41#include <plat/board.h>
42#include <plat/common.h> 42#include <plat/common.h>
43#include <plat/display.h> 43#include <plat/display.h>
44#include <plat/panel-generic-dpi.h>
44#include <plat/gpmc.h> 45#include <plat/gpmc.h>
45#include <plat/nand.h> 46#include <plat/nand.h>
46#include <plat/usb.h> 47#include <plat/usb.h>
@@ -194,14 +195,19 @@ static void beagle_disable_dvi(struct omap_dss_device *dssdev)
194 gpio_set_value(dssdev->reset_gpio, 0); 195 gpio_set_value(dssdev->reset_gpio, 0);
195} 196}
196 197
198static struct panel_generic_dpi_data dvi_panel = {
199 .name = "generic",
200 .platform_enable = beagle_enable_dvi,
201 .platform_disable = beagle_disable_dvi,
202};
203
197static struct omap_dss_device beagle_dvi_device = { 204static struct omap_dss_device beagle_dvi_device = {
198 .type = OMAP_DISPLAY_TYPE_DPI, 205 .type = OMAP_DISPLAY_TYPE_DPI,
199 .name = "dvi", 206 .name = "dvi",
200 .driver_name = "generic_panel", 207 .driver_name = "generic_dpi_panel",
208 .data = &dvi_panel,
201 .phy.dpi.data_lines = 24, 209 .phy.dpi.data_lines = 24,
202 .reset_gpio = 170, 210 .reset_gpio = 170,
203 .platform_enable = beagle_enable_dvi,
204 .platform_disable = beagle_disable_dvi,
205}; 211};
206 212
207static struct omap_dss_device beagle_tv_device = { 213static struct omap_dss_device beagle_tv_device = {
diff --git a/arch/arm/mach-omap2/board-omap3evm.c b/arch/arm/mach-omap2/board-omap3evm.c
index 3de8d9b8ec76..323c3809ce39 100644
--- a/arch/arm/mach-omap2/board-omap3evm.c
+++ b/arch/arm/mach-omap2/board-omap3evm.c
@@ -43,6 +43,7 @@
43#include <plat/common.h> 43#include <plat/common.h>
44#include <plat/mcspi.h> 44#include <plat/mcspi.h>
45#include <plat/display.h> 45#include <plat/display.h>
46#include <plat/panel-generic-dpi.h>
46 47
47#include "mux.h" 48#include "mux.h"
48#include "sdram-micron-mt46h32m32lf-6.h" 49#include "sdram-micron-mt46h32m32lf-6.h"
@@ -301,13 +302,18 @@ static void omap3_evm_disable_dvi(struct omap_dss_device *dssdev)
301 dvi_enabled = 0; 302 dvi_enabled = 0;
302} 303}
303 304
305static struct panel_generic_dpi_data dvi_panel = {
306 .name = "generic",
307 .platform_enable = omap3_evm_enable_dvi,
308 .platform_disable = omap3_evm_disable_dvi,
309};
310
304static struct omap_dss_device omap3_evm_dvi_device = { 311static struct omap_dss_device omap3_evm_dvi_device = {
305 .name = "dvi", 312 .name = "dvi",
306 .driver_name = "generic_panel",
307 .type = OMAP_DISPLAY_TYPE_DPI, 313 .type = OMAP_DISPLAY_TYPE_DPI,
314 .driver_name = "generic_dpi_panel",
315 .data = &dvi_panel,
308 .phy.dpi.data_lines = 24, 316 .phy.dpi.data_lines = 24,
309 .platform_enable = omap3_evm_enable_dvi,
310 .platform_disable = omap3_evm_disable_dvi,
311}; 317};
312 318
313static struct omap_dss_device *omap3_evm_dss_devices[] = { 319static struct omap_dss_device *omap3_evm_dss_devices[] = {
diff --git a/arch/arm/mach-omap2/board-omap3stalker.c b/arch/arm/mach-omap2/board-omap3stalker.c
index 9df9d9367608..2a2dad447e86 100644
--- a/arch/arm/mach-omap2/board-omap3stalker.c
+++ b/arch/arm/mach-omap2/board-omap3stalker.c
@@ -40,6 +40,7 @@
40#include <plat/nand.h> 40#include <plat/nand.h>
41#include <plat/usb.h> 41#include <plat/usb.h>
42#include <plat/display.h> 42#include <plat/display.h>
43#include <plat/panel-generic-dpi.h>
43 44
44#include <plat/mcspi.h> 45#include <plat/mcspi.h>
45#include <linux/input/matrix_keypad.h> 46#include <linux/input/matrix_keypad.h>
@@ -160,13 +161,18 @@ static void omap3_stalker_disable_lcd(struct omap_dss_device *dssdev)
160 lcd_enabled = 0; 161 lcd_enabled = 0;
161} 162}
162 163
164static struct panel_generic_dpi_data lcd_panel = {
165 .name = "generic",
166 .platform_enable = omap3_stalker_enable_lcd,
167 .platform_disable = omap3_stalker_disable_lcd,
168};
169
163static struct omap_dss_device omap3_stalker_lcd_device = { 170static struct omap_dss_device omap3_stalker_lcd_device = {
164 .name = "lcd", 171 .name = "lcd",
165 .driver_name = "generic_panel", 172 .driver_name = "generic_dpi_panel",
173 .data = &lcd_panel,
166 .phy.dpi.data_lines = 24, 174 .phy.dpi.data_lines = 24,
167 .type = OMAP_DISPLAY_TYPE_DPI, 175 .type = OMAP_DISPLAY_TYPE_DPI,
168 .platform_enable = omap3_stalker_enable_lcd,
169 .platform_disable = omap3_stalker_disable_lcd,
170}; 176};
171 177
172static int omap3_stalker_enable_tv(struct omap_dss_device *dssdev) 178static int omap3_stalker_enable_tv(struct omap_dss_device *dssdev)
@@ -208,13 +214,18 @@ static void omap3_stalker_disable_dvi(struct omap_dss_device *dssdev)
208 dvi_enabled = 0; 214 dvi_enabled = 0;
209} 215}
210 216
217static struct panel_generic_dpi_data dvi_panel = {
218 .name = "generic",
219 .platform_enable = omap3_stalker_enable_dvi,
220 .platform_disable = omap3_stalker_disable_dvi,
221};
222
211static struct omap_dss_device omap3_stalker_dvi_device = { 223static struct omap_dss_device omap3_stalker_dvi_device = {
212 .name = "dvi", 224 .name = "dvi",
213 .driver_name = "generic_panel",
214 .type = OMAP_DISPLAY_TYPE_DPI, 225 .type = OMAP_DISPLAY_TYPE_DPI,
226 .driver_name = "generic_dpi_panel",
227 .data = &dvi_panel,
215 .phy.dpi.data_lines = 24, 228 .phy.dpi.data_lines = 24,
216 .platform_enable = omap3_stalker_enable_dvi,
217 .platform_disable = omap3_stalker_disable_dvi,
218}; 229};
219 230
220static struct omap_dss_device *omap3_stalker_dss_devices[] = { 231static struct omap_dss_device *omap3_stalker_dss_devices[] = {
diff --git a/arch/arm/mach-omap2/board-zoom-display.c b/arch/arm/mach-omap2/board-zoom-display.c
new file mode 100644
index 000000000000..6bcd43657aed
--- /dev/null
+++ b/arch/arm/mach-omap2/board-zoom-display.c
@@ -0,0 +1,168 @@
1/*
2 * Copyright (C) 2010 Texas Instruments Inc.
3 *
4 * Modified from mach-omap2/board-zoom-peripherals.c
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/init.h>
13#include <linux/platform_device.h>
14#include <linux/gpio.h>
15#include <linux/i2c/twl.h>
16#include <linux/spi/spi.h>
17#include <plat/mcspi.h>
18#include <plat/display.h>
19
20#define LCD_PANEL_RESET_GPIO_PROD 96
21#define LCD_PANEL_RESET_GPIO_PILOT 55
22#define LCD_PANEL_QVGA_GPIO 56
23
24static void zoom_lcd_panel_init(void)
25{
26 int ret;
27 unsigned char lcd_panel_reset_gpio;
28
29 lcd_panel_reset_gpio = (omap_rev() > OMAP3430_REV_ES3_0) ?
30 LCD_PANEL_RESET_GPIO_PROD :
31 LCD_PANEL_RESET_GPIO_PILOT;
32
33 ret = gpio_request(lcd_panel_reset_gpio, "lcd reset");
34 if (ret) {
35 pr_err("Failed to get LCD reset GPIO (gpio%d).\n",
36 lcd_panel_reset_gpio);
37 return;
38 }
39 gpio_direction_output(lcd_panel_reset_gpio, 1);
40
41 ret = gpio_request(LCD_PANEL_QVGA_GPIO, "lcd qvga");
42 if (ret) {
43 pr_err("Failed to get LCD_PANEL_QVGA_GPIO (gpio%d).\n",
44 LCD_PANEL_QVGA_GPIO);
45 goto err0;
46 }
47 gpio_direction_output(LCD_PANEL_QVGA_GPIO, 1);
48
49 return;
50err0:
51 gpio_free(lcd_panel_reset_gpio);
52}
53
54static int zoom_panel_enable_lcd(struct omap_dss_device *dssdev)
55{
56 return 0;
57}
58
59static void zoom_panel_disable_lcd(struct omap_dss_device *dssdev)
60{
61}
62
63/*
64 * PWMA/B register offsets (TWL4030_MODULE_PWMA)
65 */
66#define TWL_INTBR_PMBR1 0xD
67#define TWL_INTBR_GPBR1 0xC
68#define TWL_LED_PWMON 0x0
69#define TWL_LED_PWMOFF 0x1
70
71static int zoom_set_bl_intensity(struct omap_dss_device *dssdev, int level)
72{
73 unsigned char c;
74 u8 mux_pwm, enb_pwm;
75
76 if (level > 100)
77 return -1;
78
79 twl_i2c_read_u8(TWL4030_MODULE_INTBR, &mux_pwm, TWL_INTBR_PMBR1);
80 twl_i2c_read_u8(TWL4030_MODULE_INTBR, &enb_pwm, TWL_INTBR_GPBR1);
81
82 if (level == 0) {
83 /* disable pwm1 output and clock */
84 enb_pwm = enb_pwm & 0xF5;
85 /* change pwm1 pin to gpio pin */
86 mux_pwm = mux_pwm & 0xCF;
87 twl_i2c_write_u8(TWL4030_MODULE_INTBR,
88 enb_pwm, TWL_INTBR_GPBR1);
89 twl_i2c_write_u8(TWL4030_MODULE_INTBR,
90 mux_pwm, TWL_INTBR_PMBR1);
91 return 0;
92 }
93
94 if (!((enb_pwm & 0xA) && (mux_pwm & 0x30))) {
95 /* change gpio pin to pwm1 pin */
96 mux_pwm = mux_pwm | 0x30;
97 /* enable pwm1 output and clock*/
98 enb_pwm = enb_pwm | 0x0A;
99 twl_i2c_write_u8(TWL4030_MODULE_INTBR,
100 mux_pwm, TWL_INTBR_PMBR1);
101 twl_i2c_write_u8(TWL4030_MODULE_INTBR,
102 enb_pwm, TWL_INTBR_GPBR1);
103 }
104
105 c = ((50 * (100 - level)) / 100) + 1;
106 twl_i2c_write_u8(TWL4030_MODULE_PWM1, 0x7F, TWL_LED_PWMOFF);
107 twl_i2c_write_u8(TWL4030_MODULE_PWM1, c, TWL_LED_PWMON);
108
109 return 0;
110}
111
112static struct omap_dss_device zoom_lcd_device = {
113 .name = "lcd",
114 .driver_name = "NEC_8048_panel",
115 .type = OMAP_DISPLAY_TYPE_DPI,
116 .phy.dpi.data_lines = 24,
117 .platform_enable = zoom_panel_enable_lcd,
118 .platform_disable = zoom_panel_disable_lcd,
119 .max_backlight_level = 100,
120 .set_backlight = zoom_set_bl_intensity,
121};
122
123static struct omap_dss_device *zoom_dss_devices[] = {
124 &zoom_lcd_device,
125};
126
127static struct omap_dss_board_info zoom_dss_data = {
128 .num_devices = ARRAY_SIZE(zoom_dss_devices),
129 .devices = zoom_dss_devices,
130 .default_device = &zoom_lcd_device,
131};
132
133static struct platform_device zoom_dss_device = {
134 .name = "omapdss",
135 .id = -1,
136 .dev = {
137 .platform_data = &zoom_dss_data,
138 },
139};
140
141static struct omap2_mcspi_device_config dss_lcd_mcspi_config = {
142 .turbo_mode = 1,
143 .single_channel = 1, /* 0: slave, 1: master */
144};
145
146static struct spi_board_info nec_8048_spi_board_info[] __initdata = {
147 [0] = {
148 .modalias = "nec_8048_spi",
149 .bus_num = 1,
150 .chip_select = 2,
151 .max_speed_hz = 375000,
152 .controller_data = &dss_lcd_mcspi_config,
153 },
154};
155
156static struct platform_device *zoom_display_devices[] __initdata = {
157 &zoom_dss_device,
158};
159
160void __init zoom_display_init(void)
161{
162 platform_add_devices(zoom_display_devices,
163 ARRAY_SIZE(zoom_display_devices));
164 spi_register_board_info(nec_8048_spi_board_info,
165 ARRAY_SIZE(nec_8048_spi_board_info));
166 zoom_lcd_panel_init();
167}
168
diff --git a/arch/arm/mach-omap2/board-zoom-peripherals.c b/arch/arm/mach-omap2/board-zoom-peripherals.c
index 3fbd0edd712e..14d95afa3f0d 100644
--- a/arch/arm/mach-omap2/board-zoom-peripherals.c
+++ b/arch/arm/mach-omap2/board-zoom-peripherals.c
@@ -35,6 +35,8 @@
35#define OMAP_ZOOM_WLAN_PMENA_GPIO (101) 35#define OMAP_ZOOM_WLAN_PMENA_GPIO (101)
36#define OMAP_ZOOM_WLAN_IRQ_GPIO (162) 36#define OMAP_ZOOM_WLAN_IRQ_GPIO (162)
37 37
38#define LCD_PANEL_ENABLE_GPIO (7 + OMAP_MAX_GPIO_LINES)
39
38/* Zoom2 has Qwerty keyboard*/ 40/* Zoom2 has Qwerty keyboard*/
39static uint32_t board_keymap[] = { 41static uint32_t board_keymap[] = {
40 KEY(0, 0, KEY_E), 42 KEY(0, 0, KEY_E),
@@ -224,9 +226,43 @@ static struct omap2_hsmmc_info mmc[] = {
224 {} /* Terminator */ 226 {} /* Terminator */
225}; 227};
226 228
229static struct regulator_consumer_supply zoom_vpll2_supply =
230 REGULATOR_SUPPLY("vdds_dsi", "omapdss");
231
232static struct regulator_consumer_supply zoom_vdda_dac_supply =
233 REGULATOR_SUPPLY("vdda_dac", "omapdss");
234
235static struct regulator_init_data zoom_vpll2 = {
236 .constraints = {
237 .min_uV = 1800000,
238 .max_uV = 1800000,
239 .valid_modes_mask = REGULATOR_MODE_NORMAL
240 | REGULATOR_MODE_STANDBY,
241 .valid_ops_mask = REGULATOR_CHANGE_MODE
242 | REGULATOR_CHANGE_STATUS,
243 },
244 .num_consumer_supplies = 1,
245 .consumer_supplies = &zoom_vpll2_supply,
246};
247
248static struct regulator_init_data zoom_vdac = {
249 .constraints = {
250 .min_uV = 1800000,
251 .max_uV = 1800000,
252 .valid_modes_mask = REGULATOR_MODE_NORMAL
253 | REGULATOR_MODE_STANDBY,
254 .valid_ops_mask = REGULATOR_CHANGE_MODE
255 | REGULATOR_CHANGE_STATUS,
256 },
257 .num_consumer_supplies = 1,
258 .consumer_supplies = &zoom_vdda_dac_supply,
259};
260
227static int zoom_twl_gpio_setup(struct device *dev, 261static int zoom_twl_gpio_setup(struct device *dev,
228 unsigned gpio, unsigned ngpio) 262 unsigned gpio, unsigned ngpio)
229{ 263{
264 int ret;
265
230 /* gpio + 0 is "mmc0_cd" (input/IRQ) */ 266 /* gpio + 0 is "mmc0_cd" (input/IRQ) */
231 mmc[0].gpio_cd = gpio + 0; 267 mmc[0].gpio_cd = gpio + 0;
232 omap2_hsmmc_init(mmc); 268 omap2_hsmmc_init(mmc);
@@ -238,7 +274,15 @@ static int zoom_twl_gpio_setup(struct device *dev,
238 zoom_vsim_supply.dev = mmc[0].dev; 274 zoom_vsim_supply.dev = mmc[0].dev;
239 zoom_vmmc2_supply.dev = mmc[1].dev; 275 zoom_vmmc2_supply.dev = mmc[1].dev;
240 276
241 return 0; 277 ret = gpio_request(LCD_PANEL_ENABLE_GPIO, "lcd enable");
278 if (ret) {
279 pr_err("Failed to get LCD_PANEL_ENABLE_GPIO (gpio%d).\n",
280 LCD_PANEL_ENABLE_GPIO);
281 return ret;
282 }
283 gpio_direction_output(LCD_PANEL_ENABLE_GPIO, 0);
284
285 return ret;
242} 286}
243 287
244/* EXTMUTE callback function */ 288/* EXTMUTE callback function */
@@ -301,7 +345,8 @@ static struct twl4030_platform_data zoom_twldata = {
301 .vmmc1 = &zoom_vmmc1, 345 .vmmc1 = &zoom_vmmc1,
302 .vmmc2 = &zoom_vmmc2, 346 .vmmc2 = &zoom_vmmc2,
303 .vsim = &zoom_vsim, 347 .vsim = &zoom_vsim,
304 348 .vpll2 = &zoom_vpll2,
349 .vdac = &zoom_vdac,
305}; 350};
306 351
307static struct i2c_board_info __initdata zoom_i2c_boardinfo[] = { 352static struct i2c_board_info __initdata zoom_i2c_boardinfo[] = {
diff --git a/arch/arm/mach-omap2/board-zoom.c b/arch/arm/mach-omap2/board-zoom.c
index e041c537ea37..e26754c24ee8 100644
--- a/arch/arm/mach-omap2/board-zoom.c
+++ b/arch/arm/mach-omap2/board-zoom.c
@@ -130,6 +130,7 @@ static void __init omap_zoom_init(void)
130 ARRAY_SIZE(zoom_nand_partitions), ZOOM_NAND_CS); 130 ARRAY_SIZE(zoom_nand_partitions), ZOOM_NAND_CS);
131 zoom_debugboard_init(); 131 zoom_debugboard_init();
132 zoom_peripherals_init(); 132 zoom_peripherals_init();
133 zoom_display_init();
133} 134}
134 135
135MACHINE_START(OMAP_ZOOM2, "OMAP Zoom2 board") 136MACHINE_START(OMAP_ZOOM2, "OMAP Zoom2 board")
diff --git a/arch/arm/mach-omap2/cpuidle34xx.c b/arch/arm/mach-omap2/cpuidle34xx.c
index f3e043fe5eb8..11b89e9687f3 100644
--- a/arch/arm/mach-omap2/cpuidle34xx.c
+++ b/arch/arm/mach-omap2/cpuidle34xx.c
@@ -252,7 +252,7 @@ static int omap3_enter_idle_bm(struct cpuidle_device *dev,
252 * FIXME: we currently manage device-specific idle states 252 * FIXME: we currently manage device-specific idle states
253 * for PER and CORE in combination with CPU-specific 253 * for PER and CORE in combination with CPU-specific
254 * idle states. This is wrong, and device-specific 254 * idle states. This is wrong, and device-specific
255 * idle managment needs to be separated out into 255 * idle management needs to be separated out into
256 * its own code. 256 * its own code.
257 */ 257 */
258 258
diff --git a/arch/arm/mach-omap2/include/mach/board-zoom.h b/arch/arm/mach-omap2/include/mach/board-zoom.h
index f93ca3928c3b..d20bd9c1a106 100644
--- a/arch/arm/mach-omap2/include/mach/board-zoom.h
+++ b/arch/arm/mach-omap2/include/mach/board-zoom.h
@@ -1,9 +1,12 @@
1/* 1/*
2 * Defines for zoom boards 2 * Defines for zoom boards
3 */ 3 */
4#include <plat/display.h>
5
4#define ZOOM_NAND_CS 0 6#define ZOOM_NAND_CS 0
5 7
6extern int __init zoom_debugboard_init(void); 8extern int __init zoom_debugboard_init(void);
7extern void __init zoom_peripherals_init(void); 9extern void __init zoom_peripherals_init(void);
10extern void __init zoom_display_init(void);
8 11
9#define ZOOM2_HEADSET_EXTMUTE_GPIO 153 12#define ZOOM2_HEADSET_EXTMUTE_GPIO 153
diff --git a/arch/arm/mach-omap2/pm24xx.c b/arch/arm/mach-omap2/pm24xx.c
index dac2d1d9987d..9e5dc8ed51e9 100644
--- a/arch/arm/mach-omap2/pm24xx.c
+++ b/arch/arm/mach-omap2/pm24xx.c
@@ -350,7 +350,7 @@ static void omap2_pm_end(void)
350 enable_hlt(); 350 enable_hlt();
351} 351}
352 352
353static struct platform_suspend_ops omap_pm_ops = { 353static const struct platform_suspend_ops omap_pm_ops = {
354 .begin = omap2_pm_begin, 354 .begin = omap2_pm_begin,
355 .enter = omap2_pm_enter, 355 .enter = omap2_pm_enter,
356 .end = omap2_pm_end, 356 .end = omap2_pm_end,
diff --git a/arch/arm/mach-omap2/pm34xx.c b/arch/arm/mach-omap2/pm34xx.c
index 5b323f28da2d..8cbbeade4b8a 100644
--- a/arch/arm/mach-omap2/pm34xx.c
+++ b/arch/arm/mach-omap2/pm34xx.c
@@ -605,7 +605,7 @@ static void omap3_pm_end(void)
605 return; 605 return;
606} 606}
607 607
608static struct platform_suspend_ops omap_pm_ops = { 608static const struct platform_suspend_ops omap_pm_ops = {
609 .begin = omap3_pm_begin, 609 .begin = omap3_pm_begin,
610 .end = omap3_pm_end, 610 .end = omap3_pm_end,
611 .enter = omap3_pm_enter, 611 .enter = omap3_pm_enter,
diff --git a/arch/arm/mach-omap2/pm44xx.c b/arch/arm/mach-omap2/pm44xx.c
index e9f4862c4de4..76cfff2db514 100644
--- a/arch/arm/mach-omap2/pm44xx.c
+++ b/arch/arm/mach-omap2/pm44xx.c
@@ -65,7 +65,7 @@ static void omap4_pm_end(void)
65 return; 65 return;
66} 66}
67 67
68static struct platform_suspend_ops omap_pm_ops = { 68static const struct platform_suspend_ops omap_pm_ops = {
69 .begin = omap4_pm_begin, 69 .begin = omap4_pm_begin,
70 .end = omap4_pm_end, 70 .end = omap4_pm_end,
71 .enter = omap4_pm_enter, 71 .enter = omap4_pm_enter,
diff --git a/arch/arm/mach-omap2/serial.c b/arch/arm/mach-omap2/serial.c
index c64578853a8d..302da7403a10 100644
--- a/arch/arm/mach-omap2/serial.c
+++ b/arch/arm/mach-omap2/serial.c
@@ -852,7 +852,7 @@ void __init omap_serial_init_port(struct omap_board_data *bdata)
852} 852}
853 853
854/** 854/**
855 * omap_serial_init() - intialize all supported serial ports 855 * omap_serial_init() - initialize all supported serial ports
856 * 856 *
857 * Initializes all available UARTs as serial ports. Platforms 857 * Initializes all available UARTs as serial ports. Platforms
858 * can call this function when they want to have default behaviour 858 * can call this function when they want to have default behaviour
diff --git a/arch/arm/mach-pnx4008/pm.c b/arch/arm/mach-pnx4008/pm.c
index ee3c29c57ae3..f3e60a049f98 100644
--- a/arch/arm/mach-pnx4008/pm.c
+++ b/arch/arm/mach-pnx4008/pm.c
@@ -119,7 +119,7 @@ static int pnx4008_pm_valid(suspend_state_t state)
119 (state == PM_SUSPEND_MEM); 119 (state == PM_SUSPEND_MEM);
120} 120}
121 121
122static struct platform_suspend_ops pnx4008_pm_ops = { 122static const struct platform_suspend_ops pnx4008_pm_ops = {
123 .enter = pnx4008_pm_enter, 123 .enter = pnx4008_pm_enter,
124 .valid = pnx4008_pm_valid, 124 .valid = pnx4008_pm_valid,
125}; 125};
diff --git a/arch/arm/mach-pxa/mxm8x10.c b/arch/arm/mach-pxa/mxm8x10.c
index 462167ac05f9..cdf7f41e2bb3 100644
--- a/arch/arm/mach-pxa/mxm8x10.c
+++ b/arch/arm/mach-pxa/mxm8x10.c
@@ -337,7 +337,7 @@ void __init mxm_8x10_mmc_init(void)
337} 337}
338#endif 338#endif
339 339
340/* USB Open Host Controler Interface */ 340/* USB Open Host Controller Interface */
341static struct pxaohci_platform_data mxm_8x10_ohci_platform_data = { 341static struct pxaohci_platform_data mxm_8x10_ohci_platform_data = {
342 .port_mode = PMM_NPS_MODE, 342 .port_mode = PMM_NPS_MODE,
343 .flags = ENABLE_PORT_ALL 343 .flags = ENABLE_PORT_ALL
diff --git a/arch/arm/mach-pxa/pm.c b/arch/arm/mach-pxa/pm.c
index 166c15f62916..978e1b289544 100644
--- a/arch/arm/mach-pxa/pm.c
+++ b/arch/arm/mach-pxa/pm.c
@@ -96,7 +96,7 @@ void pxa_pm_finish(void)
96 pxa_cpu_pm_fns->finish(); 96 pxa_cpu_pm_fns->finish();
97} 97}
98 98
99static struct platform_suspend_ops pxa_pm_ops = { 99static const struct platform_suspend_ops pxa_pm_ops = {
100 .valid = pxa_pm_valid, 100 .valid = pxa_pm_valid,
101 .enter = pxa_pm_enter, 101 .enter = pxa_pm_enter,
102 .prepare = pxa_pm_prepare, 102 .prepare = pxa_pm_prepare,
diff --git a/arch/arm/mach-pxa/sharpsl_pm.c b/arch/arm/mach-pxa/sharpsl_pm.c
index e68d46d415f3..785880f67b60 100644
--- a/arch/arm/mach-pxa/sharpsl_pm.c
+++ b/arch/arm/mach-pxa/sharpsl_pm.c
@@ -869,7 +869,7 @@ static void sharpsl_apm_get_power_status(struct apm_power_info *info)
869} 869}
870 870
871#ifdef CONFIG_PM 871#ifdef CONFIG_PM
872static struct platform_suspend_ops sharpsl_pm_ops = { 872static const struct platform_suspend_ops sharpsl_pm_ops = {
873 .prepare = pxa_pm_prepare, 873 .prepare = pxa_pm_prepare,
874 .finish = pxa_pm_finish, 874 .finish = pxa_pm_finish,
875 .enter = corgi_pxa_pm_enter, 875 .enter = corgi_pxa_pm_enter,
diff --git a/arch/arm/mach-s3c2410/mach-h1940.c b/arch/arm/mach-s3c2410/mach-h1940.c
index d7ada8c7e41f..1a81fe12ccd7 100644
--- a/arch/arm/mach-s3c2410/mach-h1940.c
+++ b/arch/arm/mach-s3c2410/mach-h1940.c
@@ -387,7 +387,7 @@ static struct platform_device *h1940_devices[] __initdata = {
387 &s3c_device_wdt, 387 &s3c_device_wdt,
388 &s3c_device_i2c0, 388 &s3c_device_i2c0,
389 &s3c_device_iis, 389 &s3c_device_iis,
390 &s3c_device_pcm, 390 &samsung_asoc_dma,
391 &s3c_device_usbgadget, 391 &s3c_device_usbgadget,
392 &h1940_device_leds, 392 &h1940_device_leds,
393 &h1940_device_bluetooth, 393 &h1940_device_bluetooth,
diff --git a/arch/arm/mach-s3c2440/mach-rx1950.c b/arch/arm/mach-s3c2440/mach-rx1950.c
index e0622bbb6dfa..eab6ae50683c 100644
--- a/arch/arm/mach-s3c2440/mach-rx1950.c
+++ b/arch/arm/mach-s3c2440/mach-rx1950.c
@@ -692,7 +692,7 @@ static struct platform_device *rx1950_devices[] __initdata = {
692 &s3c_device_wdt, 692 &s3c_device_wdt,
693 &s3c_device_i2c0, 693 &s3c_device_i2c0,
694 &s3c_device_iis, 694 &s3c_device_iis,
695 &s3c_device_pcm, 695 &samsung_asoc_dma,
696 &s3c_device_usbgadget, 696 &s3c_device_usbgadget,
697 &s3c_device_rtc, 697 &s3c_device_rtc,
698 &s3c_device_nand, 698 &s3c_device_nand,
diff --git a/arch/arm/mach-s3c64xx/clock.c b/arch/arm/mach-s3c64xx/clock.c
index 7e03f0ae2fc8..1c98d2ff2ed6 100644
--- a/arch/arm/mach-s3c64xx/clock.c
+++ b/arch/arm/mach-s3c64xx/clock.c
@@ -695,7 +695,7 @@ static struct clksrc_clk clksrcs[] = {
695 }, { 695 }, {
696 .clk = { 696 .clk = {
697 .name = "audio-bus", 697 .name = "audio-bus",
698 .id = -1, /* There's only one IISv4 port */ 698 .id = 2,
699 .ctrlbit = S3C6410_CLKCON_SCLK_AUDIO2, 699 .ctrlbit = S3C6410_CLKCON_SCLK_AUDIO2,
700 .enable = s3c64xx_sclk_ctrl, 700 .enable = s3c64xx_sclk_ctrl,
701 }, 701 },
diff --git a/arch/arm/mach-s3c64xx/dev-audio.c b/arch/arm/mach-s3c64xx/dev-audio.c
index 76426a32c013..cad67022fa25 100644
--- a/arch/arm/mach-s3c64xx/dev-audio.c
+++ b/arch/arm/mach-s3c64xx/dev-audio.c
@@ -22,7 +22,12 @@
22#include <plat/audio.h> 22#include <plat/audio.h>
23#include <plat/gpio-cfg.h> 23#include <plat/gpio-cfg.h>
24 24
25static int s3c64xx_i2sv3_cfg_gpio(struct platform_device *pdev) 25static const char *rclksrc[] = {
26 [0] = "iis",
27 [1] = "audio-bus",
28};
29
30static int s3c64xx_i2s_cfg_gpio(struct platform_device *pdev)
26{ 31{
27 unsigned int base; 32 unsigned int base;
28 33
@@ -33,6 +38,12 @@ static int s3c64xx_i2sv3_cfg_gpio(struct platform_device *pdev)
33 case 1: 38 case 1:
34 base = S3C64XX_GPE(0); 39 base = S3C64XX_GPE(0);
35 break; 40 break;
41 case 2:
42 s3c_gpio_cfgpin(S3C64XX_GPC(4), S3C_GPIO_SFN(5));
43 s3c_gpio_cfgpin(S3C64XX_GPC(5), S3C_GPIO_SFN(5));
44 s3c_gpio_cfgpin(S3C64XX_GPC(7), S3C_GPIO_SFN(5));
45 s3c_gpio_cfgpin_range(S3C64XX_GPH(6), 4, S3C_GPIO_SFN(5));
46 return 0;
36 default: 47 default:
37 printk(KERN_DEBUG "Invalid I2S Controller number: %d\n", 48 printk(KERN_DEBUG "Invalid I2S Controller number: %d\n",
38 pdev->id); 49 pdev->id);
@@ -44,16 +55,6 @@ static int s3c64xx_i2sv3_cfg_gpio(struct platform_device *pdev)
44 return 0; 55 return 0;
45} 56}
46 57
47static int s3c64xx_i2sv4_cfg_gpio(struct platform_device *pdev)
48{
49 s3c_gpio_cfgpin(S3C64XX_GPC(4), S3C_GPIO_SFN(5));
50 s3c_gpio_cfgpin(S3C64XX_GPC(5), S3C_GPIO_SFN(5));
51 s3c_gpio_cfgpin(S3C64XX_GPC(7), S3C_GPIO_SFN(5));
52 s3c_gpio_cfgpin_range(S3C64XX_GPH(6), 4, S3C_GPIO_SFN(5));
53
54 return 0;
55}
56
57static struct resource s3c64xx_iis0_resource[] = { 58static struct resource s3c64xx_iis0_resource[] = {
58 [0] = { 59 [0] = {
59 .start = S3C64XX_PA_IIS0, 60 .start = S3C64XX_PA_IIS0,
@@ -72,17 +73,22 @@ static struct resource s3c64xx_iis0_resource[] = {
72 }, 73 },
73}; 74};
74 75
75static struct s3c_audio_pdata s3c_i2s0_pdata = { 76static struct s3c_audio_pdata i2sv3_pdata = {
76 .cfg_gpio = s3c64xx_i2sv3_cfg_gpio, 77 .cfg_gpio = s3c64xx_i2s_cfg_gpio,
78 .type = {
79 .i2s = {
80 .src_clk = rclksrc,
81 },
82 },
77}; 83};
78 84
79struct platform_device s3c64xx_device_iis0 = { 85struct platform_device s3c64xx_device_iis0 = {
80 .name = "s3c64xx-iis", 86 .name = "samsung-i2s",
81 .id = 0, 87 .id = 0,
82 .num_resources = ARRAY_SIZE(s3c64xx_iis0_resource), 88 .num_resources = ARRAY_SIZE(s3c64xx_iis0_resource),
83 .resource = s3c64xx_iis0_resource, 89 .resource = s3c64xx_iis0_resource,
84 .dev = { 90 .dev = {
85 .platform_data = &s3c_i2s0_pdata, 91 .platform_data = &i2sv3_pdata,
86 }, 92 },
87}; 93};
88EXPORT_SYMBOL(s3c64xx_device_iis0); 94EXPORT_SYMBOL(s3c64xx_device_iis0);
@@ -105,17 +111,13 @@ static struct resource s3c64xx_iis1_resource[] = {
105 }, 111 },
106}; 112};
107 113
108static struct s3c_audio_pdata s3c_i2s1_pdata = {
109 .cfg_gpio = s3c64xx_i2sv3_cfg_gpio,
110};
111
112struct platform_device s3c64xx_device_iis1 = { 114struct platform_device s3c64xx_device_iis1 = {
113 .name = "s3c64xx-iis", 115 .name = "samsung-i2s",
114 .id = 1, 116 .id = 1,
115 .num_resources = ARRAY_SIZE(s3c64xx_iis1_resource), 117 .num_resources = ARRAY_SIZE(s3c64xx_iis1_resource),
116 .resource = s3c64xx_iis1_resource, 118 .resource = s3c64xx_iis1_resource,
117 .dev = { 119 .dev = {
118 .platform_data = &s3c_i2s1_pdata, 120 .platform_data = &i2sv3_pdata,
119 }, 121 },
120}; 122};
121EXPORT_SYMBOL(s3c64xx_device_iis1); 123EXPORT_SYMBOL(s3c64xx_device_iis1);
@@ -138,17 +140,23 @@ static struct resource s3c64xx_iisv4_resource[] = {
138 }, 140 },
139}; 141};
140 142
141static struct s3c_audio_pdata s3c_i2sv4_pdata = { 143static struct s3c_audio_pdata i2sv4_pdata = {
142 .cfg_gpio = s3c64xx_i2sv4_cfg_gpio, 144 .cfg_gpio = s3c64xx_i2s_cfg_gpio,
145 .type = {
146 .i2s = {
147 .quirks = QUIRK_PRI_6CHAN,
148 .src_clk = rclksrc,
149 },
150 },
143}; 151};
144 152
145struct platform_device s3c64xx_device_iisv4 = { 153struct platform_device s3c64xx_device_iisv4 = {
146 .name = "s3c64xx-iis-v4", 154 .name = "samsung-i2s",
147 .id = -1, 155 .id = 2,
148 .num_resources = ARRAY_SIZE(s3c64xx_iisv4_resource), 156 .num_resources = ARRAY_SIZE(s3c64xx_iisv4_resource),
149 .resource = s3c64xx_iisv4_resource, 157 .resource = s3c64xx_iisv4_resource,
150 .dev = { 158 .dev = {
151 .platform_data = &s3c_i2sv4_pdata, 159 .platform_data = &i2sv4_pdata,
152 }, 160 },
153}; 161};
154EXPORT_SYMBOL(s3c64xx_device_iisv4); 162EXPORT_SYMBOL(s3c64xx_device_iisv4);
@@ -288,7 +296,7 @@ static struct s3c_audio_pdata s3c_ac97_pdata;
288static u64 s3c64xx_ac97_dmamask = DMA_BIT_MASK(32); 296static u64 s3c64xx_ac97_dmamask = DMA_BIT_MASK(32);
289 297
290struct platform_device s3c64xx_device_ac97 = { 298struct platform_device s3c64xx_device_ac97 = {
291 .name = "s3c-ac97", 299 .name = "samsung-ac97",
292 .id = -1, 300 .id = -1,
293 .num_resources = ARRAY_SIZE(s3c64xx_ac97_resource), 301 .num_resources = ARRAY_SIZE(s3c64xx_ac97_resource),
294 .resource = s3c64xx_ac97_resource, 302 .resource = s3c64xx_ac97_resource,
@@ -307,16 +315,3 @@ void __init s3c64xx_ac97_setup_gpio(int num)
307 else 315 else
308 s3c_ac97_pdata.cfg_gpio = s3c64xx_ac97_cfg_gpe; 316 s3c_ac97_pdata.cfg_gpio = s3c64xx_ac97_cfg_gpe;
309} 317}
310
311static u64 s3c_device_audio_dmamask = 0xffffffffUL;
312
313struct platform_device s3c_device_pcm = {
314 .name = "s3c24xx-pcm-audio",
315 .id = -1,
316 .dev = {
317 .dma_mask = &s3c_device_audio_dmamask,
318 .coherent_dma_mask = 0xffffffffUL
319 }
320};
321EXPORT_SYMBOL(s3c_device_pcm);
322
diff --git a/arch/arm/mach-s3c64xx/dma.c b/arch/arm/mach-s3c64xx/dma.c
index e7d03ab41d80..372ea6855454 100644
--- a/arch/arm/mach-s3c64xx/dma.c
+++ b/arch/arm/mach-s3c64xx/dma.c
@@ -740,7 +740,7 @@ static int __init s3c64xx_dma_init(void)
740 /* Set all DMA configuration to be DMA, not SDMA */ 740 /* Set all DMA configuration to be DMA, not SDMA */
741 writel(0xffffff, S3C_SYSREG(0x110)); 741 writel(0xffffff, S3C_SYSREG(0x110));
742 742
743 /* Register standard DMA controlers */ 743 /* Register standard DMA controllers */
744 s3c64xx_dma_init1(0, DMACH_UART0, IRQ_DMA0, 0x75000000); 744 s3c64xx_dma_init1(0, DMACH_UART0, IRQ_DMA0, 0x75000000);
745 s3c64xx_dma_init1(8, DMACH_PCM1_TX, IRQ_DMA1, 0x75100000); 745 s3c64xx_dma_init1(8, DMACH_PCM1_TX, IRQ_DMA1, 0x75100000);
746 746
diff --git a/arch/arm/mach-s3c64xx/mach-smdk6410.c b/arch/arm/mach-s3c64xx/mach-smdk6410.c
index 77488facfe4c..e85192a86fbe 100644
--- a/arch/arm/mach-s3c64xx/mach-smdk6410.c
+++ b/arch/arm/mach-s3c64xx/mach-smdk6410.c
@@ -283,7 +283,7 @@ static struct platform_device *smdk6410_devices[] __initdata = {
283 &s3c_device_fb, 283 &s3c_device_fb,
284 &s3c_device_ohci, 284 &s3c_device_ohci,
285 &s3c_device_usb_hsotg, 285 &s3c_device_usb_hsotg,
286 &s3c_device_pcm, 286 &samsung_asoc_dma,
287 &s3c64xx_device_iisv4, 287 &s3c64xx_device_iisv4,
288 &samsung_device_keypad, 288 &samsung_device_keypad,
289 289
diff --git a/arch/arm/mach-s5p6442/dev-audio.c b/arch/arm/mach-s5p6442/dev-audio.c
index 3462197ff352..8719dc41fe32 100644
--- a/arch/arm/mach-s5p6442/dev-audio.c
+++ b/arch/arm/mach-s5p6442/dev-audio.c
@@ -29,7 +29,7 @@ static int s5p6442_cfg_i2s(struct platform_device *pdev)
29 base = S5P6442_GPC1(0); 29 base = S5P6442_GPC1(0);
30 break; 30 break;
31 31
32 case -1: 32 case 0:
33 base = S5P6442_GPC0(0); 33 base = S5P6442_GPC0(0);
34 break; 34 break;
35 35
@@ -42,8 +42,19 @@ static int s5p6442_cfg_i2s(struct platform_device *pdev)
42 return 0; 42 return 0;
43} 43}
44 44
45static struct s3c_audio_pdata s3c_i2s_pdata = { 45static const char *rclksrc_v35[] = {
46 [0] = "busclk",
47 [1] = "i2sclk",
48};
49
50static struct s3c_audio_pdata i2sv35_pdata = {
46 .cfg_gpio = s5p6442_cfg_i2s, 51 .cfg_gpio = s5p6442_cfg_i2s,
52 .type = {
53 .i2s = {
54 .quirks = QUIRK_SEC_DAI | QUIRK_NEED_RSTCLR,
55 .src_clk = rclksrc_v35,
56 },
57 },
47}; 58};
48 59
49static struct resource s5p6442_iis0_resource[] = { 60static struct resource s5p6442_iis0_resource[] = {
@@ -62,15 +73,34 @@ static struct resource s5p6442_iis0_resource[] = {
62 .end = DMACH_I2S0_RX, 73 .end = DMACH_I2S0_RX,
63 .flags = IORESOURCE_DMA, 74 .flags = IORESOURCE_DMA,
64 }, 75 },
76 [3] = {
77 .start = DMACH_I2S0S_TX,
78 .end = DMACH_I2S0S_TX,
79 .flags = IORESOURCE_DMA,
80 },
65}; 81};
66 82
67struct platform_device s5p6442_device_iis0 = { 83struct platform_device s5p6442_device_iis0 = {
68 .name = "s3c64xx-iis-v4", 84 .name = "samsung-i2s",
69 .id = -1, 85 .id = 0,
70 .num_resources = ARRAY_SIZE(s5p6442_iis0_resource), 86 .num_resources = ARRAY_SIZE(s5p6442_iis0_resource),
71 .resource = s5p6442_iis0_resource, 87 .resource = s5p6442_iis0_resource,
72 .dev = { 88 .dev = {
73 .platform_data = &s3c_i2s_pdata, 89 .platform_data = &i2sv35_pdata,
90 },
91};
92
93static const char *rclksrc_v3[] = {
94 [0] = "iis",
95 [1] = "sclk_audio",
96};
97
98static struct s3c_audio_pdata i2sv3_pdata = {
99 .cfg_gpio = s5p6442_cfg_i2s,
100 .type = {
101 .i2s = {
102 .src_clk = rclksrc_v3,
103 },
74 }, 104 },
75}; 105};
76 106
@@ -93,12 +123,12 @@ static struct resource s5p6442_iis1_resource[] = {
93}; 123};
94 124
95struct platform_device s5p6442_device_iis1 = { 125struct platform_device s5p6442_device_iis1 = {
96 .name = "s3c64xx-iis", 126 .name = "samsung-i2s",
97 .id = 1, 127 .id = 1,
98 .num_resources = ARRAY_SIZE(s5p6442_iis1_resource), 128 .num_resources = ARRAY_SIZE(s5p6442_iis1_resource),
99 .resource = s5p6442_iis1_resource, 129 .resource = s5p6442_iis1_resource,
100 .dev = { 130 .dev = {
101 .platform_data = &s3c_i2s_pdata, 131 .platform_data = &i2sv3_pdata,
102 }, 132 },
103}; 133};
104 134
diff --git a/arch/arm/mach-s5p64x0/clock-s5p6440.c b/arch/arm/mach-s5p64x0/clock-s5p6440.c
index e4883dc1c8d7..409c5fc3670d 100644
--- a/arch/arm/mach-s5p64x0/clock-s5p6440.c
+++ b/arch/arm/mach-s5p64x0/clock-s5p6440.c
@@ -261,7 +261,7 @@ static struct clk init_clocks_disable[] = {
261 .enable = s5p64x0_pclk_ctrl, 261 .enable = s5p64x0_pclk_ctrl,
262 .ctrlbit = (1 << 25), 262 .ctrlbit = (1 << 25),
263 }, { 263 }, {
264 .name = "i2s_v40", 264 .name = "iis",
265 .id = 0, 265 .id = 0,
266 .parent = &clk_pclk_low.clk, 266 .parent = &clk_pclk_low.clk,
267 .enable = s5p64x0_pclk_ctrl, 267 .enable = s5p64x0_pclk_ctrl,
diff --git a/arch/arm/mach-s5p64x0/clock-s5p6450.c b/arch/arm/mach-s5p64x0/clock-s5p6450.c
index 7dbf3c968f53..7fc6abd35914 100644
--- a/arch/arm/mach-s5p64x0/clock-s5p6450.c
+++ b/arch/arm/mach-s5p64x0/clock-s5p6450.c
@@ -256,7 +256,7 @@ static struct clk init_clocks_disable[] = {
256 .ctrlbit = (1 << 22), 256 .ctrlbit = (1 << 22),
257 }, { 257 }, {
258 .name = "iis", 258 .name = "iis",
259 .id = -1, 259 .id = 0,
260 .parent = &clk_pclk_low.clk, 260 .parent = &clk_pclk_low.clk,
261 .enable = s5p64x0_pclk_ctrl, 261 .enable = s5p64x0_pclk_ctrl,
262 .ctrlbit = (1 << 26), 262 .ctrlbit = (1 << 26),
diff --git a/arch/arm/mach-s5p64x0/dev-audio.c b/arch/arm/mach-s5p64x0/dev-audio.c
index 396bacc0a39a..14f89e73b8de 100644
--- a/arch/arm/mach-s5p64x0/dev-audio.c
+++ b/arch/arm/mach-s5p64x0/dev-audio.c
@@ -19,15 +19,19 @@
19#include <mach/dma.h> 19#include <mach/dma.h>
20#include <mach/irqs.h> 20#include <mach/irqs.h>
21 21
22static int s5p6440_cfg_i2s(struct platform_device *pdev) 22static const char *rclksrc[] = {
23 [0] = "iis",
24 [1] = "sclk_audio2",
25};
26
27static int s5p64x0_cfg_i2s(struct platform_device *pdev)
23{ 28{
24 /* configure GPIO for i2s port */ 29 /* configure GPIO for i2s port */
25 switch (pdev->id) { 30 switch (pdev->id) {
26 case -1: 31 case 0:
27 s3c_gpio_cfgpin_range(S5P6440_GPR(4), 5, S3C_GPIO_SFN(5)); 32 s3c_gpio_cfgpin_range(S5P6440_GPR(4), 5, S3C_GPIO_SFN(5));
28 s3c_gpio_cfgpin_range(S5P6440_GPR(13), 2, S3C_GPIO_SFN(5)); 33 s3c_gpio_cfgpin_range(S5P6440_GPR(13), 2, S3C_GPIO_SFN(5));
29 break; 34 break;
30
31 default: 35 default:
32 printk(KERN_ERR "Invalid Device %d\n", pdev->id); 36 printk(KERN_ERR "Invalid Device %d\n", pdev->id);
33 return -EINVAL; 37 return -EINVAL;
@@ -36,31 +40,14 @@ static int s5p6440_cfg_i2s(struct platform_device *pdev)
36 return 0; 40 return 0;
37} 41}
38 42
39static int s5p6450_cfg_i2s(struct platform_device *pdev) 43static struct s3c_audio_pdata s5p64x0_i2s_pdata = {
40{ 44 .cfg_gpio = s5p64x0_cfg_i2s,
41 /* configure GPIO for i2s port */ 45 .type = {
42 switch (pdev->id) { 46 .i2s = {
43 case -1: 47 .quirks = QUIRK_PRI_6CHAN,
44 s3c_gpio_cfgpin(S5P6450_GPB(4), S3C_GPIO_SFN(5)); 48 .src_clk = rclksrc,
45 s3c_gpio_cfgpin_range(S5P6450_GPR(4), 5, S3C_GPIO_SFN(5)); 49 },
46 s3c_gpio_cfgpin_range(S5P6450_GPR(13), 2, S3C_GPIO_SFN(5)); 50 },
47
48 break;
49
50 default:
51 printk(KERN_ERR "Invalid Device %d\n", pdev->id);
52 return -EINVAL;
53 }
54
55 return 0;
56}
57
58static struct s3c_audio_pdata s5p6440_i2s_pdata = {
59 .cfg_gpio = s5p6440_cfg_i2s,
60};
61
62static struct s3c_audio_pdata s5p6450_i2s_pdata = {
63 .cfg_gpio = s5p6450_cfg_i2s,
64}; 51};
65 52
66static struct resource s5p64x0_iis0_resource[] = { 53static struct resource s5p64x0_iis0_resource[] = {
@@ -82,22 +69,22 @@ static struct resource s5p64x0_iis0_resource[] = {
82}; 69};
83 70
84struct platform_device s5p6440_device_iis = { 71struct platform_device s5p6440_device_iis = {
85 .name = "s3c64xx-iis-v4", 72 .name = "samsung-i2s",
86 .id = -1, 73 .id = 0,
87 .num_resources = ARRAY_SIZE(s5p64x0_iis0_resource), 74 .num_resources = ARRAY_SIZE(s5p64x0_iis0_resource),
88 .resource = s5p64x0_iis0_resource, 75 .resource = s5p64x0_iis0_resource,
89 .dev = { 76 .dev = {
90 .platform_data = &s5p6440_i2s_pdata, 77 .platform_data = &s5p64x0_i2s_pdata,
91 }, 78 },
92}; 79};
93 80
94struct platform_device s5p6450_device_iis0 = { 81struct platform_device s5p6450_device_iis0 = {
95 .name = "s3c64xx-iis-v4", 82 .name = "samsung-i2s",
96 .id = -1, 83 .id = 0,
97 .num_resources = ARRAY_SIZE(s5p64x0_iis0_resource), 84 .num_resources = ARRAY_SIZE(s5p64x0_iis0_resource),
98 .resource = s5p64x0_iis0_resource, 85 .resource = s5p64x0_iis0_resource,
99 .dev = { 86 .dev = {
100 .platform_data = &s5p6450_i2s_pdata, 87 .platform_data = &s5p64x0_i2s_pdata,
101 }, 88 },
102}; 89};
103 90
diff --git a/arch/arm/mach-s5pc100/dev-audio.c b/arch/arm/mach-s5pc100/dev-audio.c
index 564e195ec493..ab2d27172cbc 100644
--- a/arch/arm/mach-s5pc100/dev-audio.c
+++ b/arch/arm/mach-s5pc100/dev-audio.c
@@ -23,17 +23,14 @@ static int s5pc100_cfg_i2s(struct platform_device *pdev)
23{ 23{
24 /* configure GPIO for i2s port */ 24 /* configure GPIO for i2s port */
25 switch (pdev->id) { 25 switch (pdev->id) {
26 case 0: /* Dedicated pins */
27 break;
26 case 1: 28 case 1:
27 s3c_gpio_cfgpin_range(S5PC100_GPC(0), 5, S3C_GPIO_SFN(2)); 29 s3c_gpio_cfgpin_range(S5PC100_GPC(0), 5, S3C_GPIO_SFN(2));
28 break; 30 break;
29
30 case 2: 31 case 2:
31 s3c_gpio_cfgpin_range(S5PC100_GPG3(0), 5, S3C_GPIO_SFN(4)); 32 s3c_gpio_cfgpin_range(S5PC100_GPG3(0), 5, S3C_GPIO_SFN(4));
32 break; 33 break;
33
34 case -1: /* Dedicated pins */
35 break;
36
37 default: 34 default:
38 printk(KERN_ERR "Invalid Device %d\n", pdev->id); 35 printk(KERN_ERR "Invalid Device %d\n", pdev->id);
39 return -EINVAL; 36 return -EINVAL;
@@ -42,8 +39,20 @@ static int s5pc100_cfg_i2s(struct platform_device *pdev)
42 return 0; 39 return 0;
43} 40}
44 41
45static struct s3c_audio_pdata s3c_i2s_pdata = { 42static const char *rclksrc_v5[] = {
43 [0] = "iis",
44 [1] = "i2sclkd2",
45};
46
47static struct s3c_audio_pdata i2sv5_pdata = {
46 .cfg_gpio = s5pc100_cfg_i2s, 48 .cfg_gpio = s5pc100_cfg_i2s,
49 .type = {
50 .i2s = {
51 .quirks = QUIRK_PRI_6CHAN | QUIRK_SEC_DAI
52 | QUIRK_NEED_RSTCLR,
53 .src_clk = rclksrc_v5,
54 },
55 },
47}; 56};
48 57
49static struct resource s5pc100_iis0_resource[] = { 58static struct resource s5pc100_iis0_resource[] = {
@@ -62,15 +71,34 @@ static struct resource s5pc100_iis0_resource[] = {
62 .end = DMACH_I2S0_RX, 71 .end = DMACH_I2S0_RX,
63 .flags = IORESOURCE_DMA, 72 .flags = IORESOURCE_DMA,
64 }, 73 },
74 [3] = {
75 .start = DMACH_I2S0S_TX,
76 .end = DMACH_I2S0S_TX,
77 .flags = IORESOURCE_DMA,
78 },
65}; 79};
66 80
67struct platform_device s5pc100_device_iis0 = { 81struct platform_device s5pc100_device_iis0 = {
68 .name = "s3c64xx-iis-v4", 82 .name = "samsung-i2s",
69 .id = -1, 83 .id = 0,
70 .num_resources = ARRAY_SIZE(s5pc100_iis0_resource), 84 .num_resources = ARRAY_SIZE(s5pc100_iis0_resource),
71 .resource = s5pc100_iis0_resource, 85 .resource = s5pc100_iis0_resource,
72 .dev = { 86 .dev = {
73 .platform_data = &s3c_i2s_pdata, 87 .platform_data = &i2sv5_pdata,
88 },
89};
90
91static const char *rclksrc_v3[] = {
92 [0] = "iis",
93 [1] = "sclk_audio",
94};
95
96static struct s3c_audio_pdata i2sv3_pdata = {
97 .cfg_gpio = s5pc100_cfg_i2s,
98 .type = {
99 .i2s = {
100 .src_clk = rclksrc_v3,
101 },
74 }, 102 },
75}; 103};
76 104
@@ -93,12 +121,12 @@ static struct resource s5pc100_iis1_resource[] = {
93}; 121};
94 122
95struct platform_device s5pc100_device_iis1 = { 123struct platform_device s5pc100_device_iis1 = {
96 .name = "s3c64xx-iis", 124 .name = "samsung-i2s",
97 .id = 1, 125 .id = 1,
98 .num_resources = ARRAY_SIZE(s5pc100_iis1_resource), 126 .num_resources = ARRAY_SIZE(s5pc100_iis1_resource),
99 .resource = s5pc100_iis1_resource, 127 .resource = s5pc100_iis1_resource,
100 .dev = { 128 .dev = {
101 .platform_data = &s3c_i2s_pdata, 129 .platform_data = &i2sv3_pdata,
102 }, 130 },
103}; 131};
104 132
@@ -121,12 +149,12 @@ static struct resource s5pc100_iis2_resource[] = {
121}; 149};
122 150
123struct platform_device s5pc100_device_iis2 = { 151struct platform_device s5pc100_device_iis2 = {
124 .name = "s3c64xx-iis", 152 .name = "samsung-i2s",
125 .id = 2, 153 .id = 2,
126 .num_resources = ARRAY_SIZE(s5pc100_iis2_resource), 154 .num_resources = ARRAY_SIZE(s5pc100_iis2_resource),
127 .resource = s5pc100_iis2_resource, 155 .resource = s5pc100_iis2_resource,
128 .dev = { 156 .dev = {
129 .platform_data = &s3c_i2s_pdata, 157 .platform_data = &i2sv3_pdata,
130 }, 158 },
131}; 159};
132 160
@@ -253,7 +281,7 @@ static struct s3c_audio_pdata s3c_ac97_pdata = {
253static u64 s5pc100_ac97_dmamask = DMA_BIT_MASK(32); 281static u64 s5pc100_ac97_dmamask = DMA_BIT_MASK(32);
254 282
255struct platform_device s5pc100_device_ac97 = { 283struct platform_device s5pc100_device_ac97 = {
256 .name = "s3c-ac97", 284 .name = "samsung-ac97",
257 .id = -1, 285 .id = -1,
258 .num_resources = ARRAY_SIZE(s5pc100_ac97_resource), 286 .num_resources = ARRAY_SIZE(s5pc100_ac97_resource),
259 .resource = s5pc100_ac97_resource, 287 .resource = s5pc100_ac97_resource,
diff --git a/arch/arm/mach-s5pc100/mach-smdkc100.c b/arch/arm/mach-s5pc100/mach-smdkc100.c
index 18b405d514d6..dd192a27524d 100644
--- a/arch/arm/mach-s5pc100/mach-smdkc100.c
+++ b/arch/arm/mach-s5pc100/mach-smdkc100.c
@@ -96,6 +96,7 @@ static struct s3c2410_uartcfg smdkc100_uartcfgs[] __initdata = {
96 96
97/* I2C0 */ 97/* I2C0 */
98static struct i2c_board_info i2c_devs0[] __initdata = { 98static struct i2c_board_info i2c_devs0[] __initdata = {
99 {I2C_BOARD_INFO("wm8580", 0x1b),},
99}; 100};
100 101
101/* I2C1 */ 102/* I2C1 */
@@ -190,6 +191,7 @@ static struct platform_device *smdkc100_devices[] __initdata = {
190 &s3c_device_ts, 191 &s3c_device_ts,
191 &s3c_device_wdt, 192 &s3c_device_wdt,
192 &smdkc100_lcd_powerdev, 193 &smdkc100_lcd_powerdev,
194 &samsung_asoc_dma,
193 &s5pc100_device_iis0, 195 &s5pc100_device_iis0,
194 &samsung_device_keypad, 196 &samsung_device_keypad,
195 &s5pc100_device_ac97, 197 &s5pc100_device_ac97,
diff --git a/arch/arm/mach-s5pv210/clock.c b/arch/arm/mach-s5pv210/clock.c
index 019c3a69b0e4..b774ff1805db 100644
--- a/arch/arm/mach-s5pv210/clock.c
+++ b/arch/arm/mach-s5pv210/clock.c
@@ -467,20 +467,20 @@ static struct clk init_clocks_disable[] = {
467 .enable = s5pv210_clk_ip3_ctrl, 467 .enable = s5pv210_clk_ip3_ctrl,
468 .ctrlbit = (1<<21), 468 .ctrlbit = (1<<21),
469 }, { 469 }, {
470 .name = "i2s_v50", 470 .name = "iis",
471 .id = 0, 471 .id = 0,
472 .parent = &clk_p, 472 .parent = &clk_p,
473 .enable = s5pv210_clk_ip3_ctrl, 473 .enable = s5pv210_clk_ip3_ctrl,
474 .ctrlbit = (1<<4), 474 .ctrlbit = (1<<4),
475 }, { 475 }, {
476 .name = "i2s_v32", 476 .name = "iis",
477 .id = 0, 477 .id = 1,
478 .parent = &clk_p, 478 .parent = &clk_p,
479 .enable = s5pv210_clk_ip3_ctrl, 479 .enable = s5pv210_clk_ip3_ctrl,
480 .ctrlbit = (1 << 5), 480 .ctrlbit = (1 << 5),
481 }, { 481 }, {
482 .name = "i2s_v32", 482 .name = "iis",
483 .id = 1, 483 .id = 2,
484 .parent = &clk_p, 484 .parent = &clk_p,
485 .enable = s5pv210_clk_ip3_ctrl, 485 .enable = s5pv210_clk_ip3_ctrl,
486 .ctrlbit = (1 << 6), 486 .ctrlbit = (1 << 6),
diff --git a/arch/arm/mach-s5pv210/dev-audio.c b/arch/arm/mach-s5pv210/dev-audio.c
index 1303fcb12b51..8d58f1926241 100644
--- a/arch/arm/mach-s5pv210/dev-audio.c
+++ b/arch/arm/mach-s5pv210/dev-audio.c
@@ -19,22 +19,24 @@
19#include <mach/dma.h> 19#include <mach/dma.h>
20#include <mach/irqs.h> 20#include <mach/irqs.h>
21 21
22static const char *rclksrc[] = {
23 [0] = "busclk",
24 [1] = "i2sclk",
25};
26
22static int s5pv210_cfg_i2s(struct platform_device *pdev) 27static int s5pv210_cfg_i2s(struct platform_device *pdev)
23{ 28{
24 /* configure GPIO for i2s port */ 29 /* configure GPIO for i2s port */
25 switch (pdev->id) { 30 switch (pdev->id) {
31 case 0:
32 s3c_gpio_cfgpin_range(S5PV210_GPI(0), 7, S3C_GPIO_SFN(2));
33 break;
26 case 1: 34 case 1:
27 s3c_gpio_cfgpin_range(S5PV210_GPC0(0), 5, S3C_GPIO_SFN(2)); 35 s3c_gpio_cfgpin_range(S5PV210_GPC0(0), 5, S3C_GPIO_SFN(2));
28 break; 36 break;
29
30 case 2: 37 case 2:
31 s3c_gpio_cfgpin_range(S5PV210_GPC1(0), 5, S3C_GPIO_SFN(4)); 38 s3c_gpio_cfgpin_range(S5PV210_GPC1(0), 5, S3C_GPIO_SFN(4));
32 break; 39 break;
33
34 case -1:
35 s3c_gpio_cfgpin_range(S5PV210_GPI(0), 7, S3C_GPIO_SFN(2));
36 break;
37
38 default: 40 default:
39 printk(KERN_ERR "Invalid Device %d\n", pdev->id); 41 printk(KERN_ERR "Invalid Device %d\n", pdev->id);
40 return -EINVAL; 42 return -EINVAL;
@@ -43,8 +45,15 @@ static int s5pv210_cfg_i2s(struct platform_device *pdev)
43 return 0; 45 return 0;
44} 46}
45 47
46static struct s3c_audio_pdata s3c_i2s_pdata = { 48static struct s3c_audio_pdata i2sv5_pdata = {
47 .cfg_gpio = s5pv210_cfg_i2s, 49 .cfg_gpio = s5pv210_cfg_i2s,
50 .type = {
51 .i2s = {
52 .quirks = QUIRK_PRI_6CHAN | QUIRK_SEC_DAI
53 | QUIRK_NEED_RSTCLR,
54 .src_clk = rclksrc,
55 },
56 },
48}; 57};
49 58
50static struct resource s5pv210_iis0_resource[] = { 59static struct resource s5pv210_iis0_resource[] = {
@@ -63,15 +72,34 @@ static struct resource s5pv210_iis0_resource[] = {
63 .end = DMACH_I2S0_RX, 72 .end = DMACH_I2S0_RX,
64 .flags = IORESOURCE_DMA, 73 .flags = IORESOURCE_DMA,
65 }, 74 },
75 [3] = {
76 .start = DMACH_I2S0S_TX,
77 .end = DMACH_I2S0S_TX,
78 .flags = IORESOURCE_DMA,
79 },
66}; 80};
67 81
68struct platform_device s5pv210_device_iis0 = { 82struct platform_device s5pv210_device_iis0 = {
69 .name = "s3c64xx-iis-v4", 83 .name = "samsung-i2s",
70 .id = -1, 84 .id = 0,
71 .num_resources = ARRAY_SIZE(s5pv210_iis0_resource), 85 .num_resources = ARRAY_SIZE(s5pv210_iis0_resource),
72 .resource = s5pv210_iis0_resource, 86 .resource = s5pv210_iis0_resource,
73 .dev = { 87 .dev = {
74 .platform_data = &s3c_i2s_pdata, 88 .platform_data = &i2sv5_pdata,
89 },
90};
91
92static const char *rclksrc_v3[] = {
93 [0] = "iis",
94 [1] = "audio-bus",
95};
96
97static struct s3c_audio_pdata i2sv3_pdata = {
98 .cfg_gpio = s5pv210_cfg_i2s,
99 .type = {
100 .i2s = {
101 .src_clk = rclksrc_v3,
102 },
75 }, 103 },
76}; 104};
77 105
@@ -94,12 +122,12 @@ static struct resource s5pv210_iis1_resource[] = {
94}; 122};
95 123
96struct platform_device s5pv210_device_iis1 = { 124struct platform_device s5pv210_device_iis1 = {
97 .name = "s3c64xx-iis", 125 .name = "samsung-i2s",
98 .id = 1, 126 .id = 1,
99 .num_resources = ARRAY_SIZE(s5pv210_iis1_resource), 127 .num_resources = ARRAY_SIZE(s5pv210_iis1_resource),
100 .resource = s5pv210_iis1_resource, 128 .resource = s5pv210_iis1_resource,
101 .dev = { 129 .dev = {
102 .platform_data = &s3c_i2s_pdata, 130 .platform_data = &i2sv3_pdata,
103 }, 131 },
104}; 132};
105 133
@@ -122,12 +150,12 @@ static struct resource s5pv210_iis2_resource[] = {
122}; 150};
123 151
124struct platform_device s5pv210_device_iis2 = { 152struct platform_device s5pv210_device_iis2 = {
125 .name = "s3c64xx-iis", 153 .name = "samsung-i2s",
126 .id = 2, 154 .id = 2,
127 .num_resources = ARRAY_SIZE(s5pv210_iis2_resource), 155 .num_resources = ARRAY_SIZE(s5pv210_iis2_resource),
128 .resource = s5pv210_iis2_resource, 156 .resource = s5pv210_iis2_resource,
129 .dev = { 157 .dev = {
130 .platform_data = &s3c_i2s_pdata, 158 .platform_data = &i2sv3_pdata,
131 }, 159 },
132}; 160};
133 161
@@ -283,7 +311,7 @@ static struct s3c_audio_pdata s3c_ac97_pdata = {
283static u64 s5pv210_ac97_dmamask = DMA_BIT_MASK(32); 311static u64 s5pv210_ac97_dmamask = DMA_BIT_MASK(32);
284 312
285struct platform_device s5pv210_device_ac97 = { 313struct platform_device s5pv210_device_ac97 = {
286 .name = "s3c-ac97", 314 .name = "samsung-ac97",
287 .id = -1, 315 .id = -1,
288 .num_resources = ARRAY_SIZE(s5pv210_ac97_resource), 316 .num_resources = ARRAY_SIZE(s5pv210_ac97_resource),
289 .resource = s5pv210_ac97_resource, 317 .resource = s5pv210_ac97_resource,
diff --git a/arch/arm/mach-s5pv310/Kconfig b/arch/arm/mach-s5pv310/Kconfig
index 1150b360f38c..d64efe0d4c97 100644
--- a/arch/arm/mach-s5pv310/Kconfig
+++ b/arch/arm/mach-s5pv310/Kconfig
@@ -11,6 +11,7 @@ if ARCH_S5PV310
11 11
12config CPU_S5PV310 12config CPU_S5PV310
13 bool 13 bool
14 select S3C_PL330_DMA
14 help 15 help
15 Enable S5PV310 CPU support 16 Enable S5PV310 CPU support
16 17
diff --git a/arch/arm/mach-s5pv310/Makefile b/arch/arm/mach-s5pv310/Makefile
index 84afc64e7c01..61e3cb654269 100644
--- a/arch/arm/mach-s5pv310/Makefile
+++ b/arch/arm/mach-s5pv310/Makefile
@@ -13,7 +13,7 @@ obj- :=
13# Core support for S5PV310 system 13# Core support for S5PV310 system
14 14
15obj-$(CONFIG_CPU_S5PV310) += cpu.o init.o clock.o irq-combiner.o 15obj-$(CONFIG_CPU_S5PV310) += cpu.o init.o clock.o irq-combiner.o
16obj-$(CONFIG_CPU_S5PV310) += setup-i2c0.o time.o gpiolib.o irq-eint.o 16obj-$(CONFIG_CPU_S5PV310) += setup-i2c0.o time.o gpiolib.o irq-eint.o dma.o
17 17
18obj-$(CONFIG_SMP) += platsmp.o headsmp.o 18obj-$(CONFIG_SMP) += platsmp.o headsmp.o
19obj-$(CONFIG_LOCAL_TIMERS) += localtimer.o 19obj-$(CONFIG_LOCAL_TIMERS) += localtimer.o
@@ -27,6 +27,7 @@ obj-$(CONFIG_MACH_UNIVERSAL_C210) += mach-universal_c210.o
27 27
28# device support 28# device support
29 29
30obj-y += dev-audio.o
30obj-$(CONFIG_S5PV310_SETUP_I2C1) += setup-i2c1.o 31obj-$(CONFIG_S5PV310_SETUP_I2C1) += setup-i2c1.o
31obj-$(CONFIG_S5PV310_SETUP_I2C2) += setup-i2c2.o 32obj-$(CONFIG_S5PV310_SETUP_I2C2) += setup-i2c2.o
32obj-$(CONFIG_S5PV310_SETUP_I2C3) += setup-i2c3.o 33obj-$(CONFIG_S5PV310_SETUP_I2C3) += setup-i2c3.o
diff --git a/arch/arm/mach-s5pv310/dev-audio.c b/arch/arm/mach-s5pv310/dev-audio.c
new file mode 100644
index 000000000000..a1964242f0fa
--- /dev/null
+++ b/arch/arm/mach-s5pv310/dev-audio.c
@@ -0,0 +1,364 @@
1/* linux/arch/arm/mach-s5pv310/dev-audio.c
2 *
3 * Copyright (c) 2010 Samsung Electronics Co. Ltd
4 * Jaswinder Singh <jassi.brar@samsung.com>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
9 */
10
11#include <linux/platform_device.h>
12#include <linux/dma-mapping.h>
13#include <linux/gpio.h>
14
15#include <plat/gpio-cfg.h>
16#include <plat/audio.h>
17
18#include <mach/map.h>
19#include <mach/dma.h>
20#include <mach/irqs.h>
21
22static const char *rclksrc[] = {
23 [0] = "busclk",
24 [1] = "i2sclk",
25};
26
27static int s5pv310_cfg_i2s(struct platform_device *pdev)
28{
29 /* configure GPIO for i2s port */
30 switch (pdev->id) {
31 case 0:
32 s3c_gpio_cfgpin_range(S5PV310_GPZ(0), 7, S3C_GPIO_SFN(2));
33 break;
34 case 1:
35 s3c_gpio_cfgpin_range(S5PV310_GPC0(0), 5, S3C_GPIO_SFN(2));
36 break;
37 case 2:
38 s3c_gpio_cfgpin_range(S5PV310_GPC1(0), 5, S3C_GPIO_SFN(4));
39 break;
40 default:
41 printk(KERN_ERR "Invalid Device %d\n", pdev->id);
42 return -EINVAL;
43 }
44
45 return 0;
46}
47
48static struct s3c_audio_pdata i2sv5_pdata = {
49 .cfg_gpio = s5pv310_cfg_i2s,
50 .type = {
51 .i2s = {
52 .quirks = QUIRK_PRI_6CHAN | QUIRK_SEC_DAI
53 | QUIRK_NEED_RSTCLR,
54 .src_clk = rclksrc,
55 },
56 },
57};
58
59static struct resource s5pv310_i2s0_resource[] = {
60 [0] = {
61 .start = S5PV310_PA_I2S0,
62 .end = S5PV310_PA_I2S0 + 0x100 - 1,
63 .flags = IORESOURCE_MEM,
64 },
65 [1] = {
66 .start = DMACH_I2S0_TX,
67 .end = DMACH_I2S0_TX,
68 .flags = IORESOURCE_DMA,
69 },
70 [2] = {
71 .start = DMACH_I2S0_RX,
72 .end = DMACH_I2S0_RX,
73 .flags = IORESOURCE_DMA,
74 },
75 [3] = {
76 .start = DMACH_I2S0S_TX,
77 .end = DMACH_I2S0S_TX,
78 .flags = IORESOURCE_DMA,
79 },
80};
81
82struct platform_device s5pv310_device_i2s0 = {
83 .name = "samsung-i2s",
84 .id = 0,
85 .num_resources = ARRAY_SIZE(s5pv310_i2s0_resource),
86 .resource = s5pv310_i2s0_resource,
87 .dev = {
88 .platform_data = &i2sv5_pdata,
89 },
90};
91
92static const char *rclksrc_v3[] = {
93 [0] = "sclk_i2s",
94 [1] = "no_such_clock",
95};
96
97static struct s3c_audio_pdata i2sv3_pdata = {
98 .cfg_gpio = s5pv310_cfg_i2s,
99 .type = {
100 .i2s = {
101 .quirks = QUIRK_NO_MUXPSR,
102 .src_clk = rclksrc_v3,
103 },
104 },
105};
106
107static struct resource s5pv310_i2s1_resource[] = {
108 [0] = {
109 .start = S5PV310_PA_I2S1,
110 .end = S5PV310_PA_I2S1 + 0x100 - 1,
111 .flags = IORESOURCE_MEM,
112 },
113 [1] = {
114 .start = DMACH_I2S1_TX,
115 .end = DMACH_I2S1_TX,
116 .flags = IORESOURCE_DMA,
117 },
118 [2] = {
119 .start = DMACH_I2S1_RX,
120 .end = DMACH_I2S1_RX,
121 .flags = IORESOURCE_DMA,
122 },
123};
124
125struct platform_device s5pv310_device_i2s1 = {
126 .name = "samsung-i2s",
127 .id = 1,
128 .num_resources = ARRAY_SIZE(s5pv310_i2s1_resource),
129 .resource = s5pv310_i2s1_resource,
130 .dev = {
131 .platform_data = &i2sv3_pdata,
132 },
133};
134
135static struct resource s5pv310_i2s2_resource[] = {
136 [0] = {
137 .start = S5PV310_PA_I2S2,
138 .end = S5PV310_PA_I2S2 + 0x100 - 1,
139 .flags = IORESOURCE_MEM,
140 },
141 [1] = {
142 .start = DMACH_I2S2_TX,
143 .end = DMACH_I2S2_TX,
144 .flags = IORESOURCE_DMA,
145 },
146 [2] = {
147 .start = DMACH_I2S2_RX,
148 .end = DMACH_I2S2_RX,
149 .flags = IORESOURCE_DMA,
150 },
151};
152
153struct platform_device s5pv310_device_i2s2 = {
154 .name = "samsung-i2s",
155 .id = 2,
156 .num_resources = ARRAY_SIZE(s5pv310_i2s2_resource),
157 .resource = s5pv310_i2s2_resource,
158 .dev = {
159 .platform_data = &i2sv3_pdata,
160 },
161};
162
163/* PCM Controller platform_devices */
164
165static int s5pv310_pcm_cfg_gpio(struct platform_device *pdev)
166{
167 switch (pdev->id) {
168 case 0:
169 s3c_gpio_cfgpin_range(S5PV310_GPZ(0), 5, S3C_GPIO_SFN(3));
170 break;
171 case 1:
172 s3c_gpio_cfgpin_range(S5PV310_GPC0(0), 5, S3C_GPIO_SFN(3));
173 break;
174 case 2:
175 s3c_gpio_cfgpin_range(S5PV310_GPC1(0), 5, S3C_GPIO_SFN(3));
176 break;
177 default:
178 printk(KERN_DEBUG "Invalid PCM Controller number!");
179 return -EINVAL;
180 }
181
182 return 0;
183}
184
185static struct s3c_audio_pdata s3c_pcm_pdata = {
186 .cfg_gpio = s5pv310_pcm_cfg_gpio,
187};
188
189static struct resource s5pv310_pcm0_resource[] = {
190 [0] = {
191 .start = S5PV310_PA_PCM0,
192 .end = S5PV310_PA_PCM0 + 0x100 - 1,
193 .flags = IORESOURCE_MEM,
194 },
195 [1] = {
196 .start = DMACH_PCM0_TX,
197 .end = DMACH_PCM0_TX,
198 .flags = IORESOURCE_DMA,
199 },
200 [2] = {
201 .start = DMACH_PCM0_RX,
202 .end = DMACH_PCM0_RX,
203 .flags = IORESOURCE_DMA,
204 },
205};
206
207struct platform_device s5pv310_device_pcm0 = {
208 .name = "samsung-pcm",
209 .id = 0,
210 .num_resources = ARRAY_SIZE(s5pv310_pcm0_resource),
211 .resource = s5pv310_pcm0_resource,
212 .dev = {
213 .platform_data = &s3c_pcm_pdata,
214 },
215};
216
217static struct resource s5pv310_pcm1_resource[] = {
218 [0] = {
219 .start = S5PV310_PA_PCM1,
220 .end = S5PV310_PA_PCM1 + 0x100 - 1,
221 .flags = IORESOURCE_MEM,
222 },
223 [1] = {
224 .start = DMACH_PCM1_TX,
225 .end = DMACH_PCM1_TX,
226 .flags = IORESOURCE_DMA,
227 },
228 [2] = {
229 .start = DMACH_PCM1_RX,
230 .end = DMACH_PCM1_RX,
231 .flags = IORESOURCE_DMA,
232 },
233};
234
235struct platform_device s5pv310_device_pcm1 = {
236 .name = "samsung-pcm",
237 .id = 1,
238 .num_resources = ARRAY_SIZE(s5pv310_pcm1_resource),
239 .resource = s5pv310_pcm1_resource,
240 .dev = {
241 .platform_data = &s3c_pcm_pdata,
242 },
243};
244
245static struct resource s5pv310_pcm2_resource[] = {
246 [0] = {
247 .start = S5PV310_PA_PCM2,
248 .end = S5PV310_PA_PCM2 + 0x100 - 1,
249 .flags = IORESOURCE_MEM,
250 },
251 [1] = {
252 .start = DMACH_PCM2_TX,
253 .end = DMACH_PCM2_TX,
254 .flags = IORESOURCE_DMA,
255 },
256 [2] = {
257 .start = DMACH_PCM2_RX,
258 .end = DMACH_PCM2_RX,
259 .flags = IORESOURCE_DMA,
260 },
261};
262
263struct platform_device s5pv310_device_pcm2 = {
264 .name = "samsung-pcm",
265 .id = 2,
266 .num_resources = ARRAY_SIZE(s5pv310_pcm2_resource),
267 .resource = s5pv310_pcm2_resource,
268 .dev = {
269 .platform_data = &s3c_pcm_pdata,
270 },
271};
272
273/* AC97 Controller platform devices */
274
275static int s5pv310_ac97_cfg_gpio(struct platform_device *pdev)
276{
277 return s3c_gpio_cfgpin_range(S5PV310_GPC0(0), 5, S3C_GPIO_SFN(4));
278}
279
280static struct resource s5pv310_ac97_resource[] = {
281 [0] = {
282 .start = S5PV310_PA_AC97,
283 .end = S5PV310_PA_AC97 + 0x100 - 1,
284 .flags = IORESOURCE_MEM,
285 },
286 [1] = {
287 .start = DMACH_AC97_PCMOUT,
288 .end = DMACH_AC97_PCMOUT,
289 .flags = IORESOURCE_DMA,
290 },
291 [2] = {
292 .start = DMACH_AC97_PCMIN,
293 .end = DMACH_AC97_PCMIN,
294 .flags = IORESOURCE_DMA,
295 },
296 [3] = {
297 .start = DMACH_AC97_MICIN,
298 .end = DMACH_AC97_MICIN,
299 .flags = IORESOURCE_DMA,
300 },
301 [4] = {
302 .start = IRQ_AC97,
303 .end = IRQ_AC97,
304 .flags = IORESOURCE_IRQ,
305 },
306};
307
308static struct s3c_audio_pdata s3c_ac97_pdata = {
309 .cfg_gpio = s5pv310_ac97_cfg_gpio,
310};
311
312static u64 s5pv310_ac97_dmamask = DMA_BIT_MASK(32);
313
314struct platform_device s5pv310_device_ac97 = {
315 .name = "samsung-ac97",
316 .id = -1,
317 .num_resources = ARRAY_SIZE(s5pv310_ac97_resource),
318 .resource = s5pv310_ac97_resource,
319 .dev = {
320 .platform_data = &s3c_ac97_pdata,
321 .dma_mask = &s5pv310_ac97_dmamask,
322 .coherent_dma_mask = DMA_BIT_MASK(32),
323 },
324};
325
326/* S/PDIF Controller platform_device */
327
328static int s5pv310_spdif_cfg_gpio(struct platform_device *pdev)
329{
330 s3c_gpio_cfgpin_range(S5PV310_GPC1(0), 2, S3C_GPIO_SFN(3));
331
332 return 0;
333}
334
335static struct resource s5pv310_spdif_resource[] = {
336 [0] = {
337 .start = S5PV310_PA_SPDIF,
338 .end = S5PV310_PA_SPDIF + 0x100 - 1,
339 .flags = IORESOURCE_MEM,
340 },
341 [1] = {
342 .start = DMACH_SPDIF,
343 .end = DMACH_SPDIF,
344 .flags = IORESOURCE_DMA,
345 },
346};
347
348static struct s3c_audio_pdata samsung_spdif_pdata = {
349 .cfg_gpio = s5pv310_spdif_cfg_gpio,
350};
351
352static u64 s5pv310_spdif_dmamask = DMA_BIT_MASK(32);
353
354struct platform_device s5pv310_device_spdif = {
355 .name = "samsung-spdif",
356 .id = -1,
357 .num_resources = ARRAY_SIZE(s5pv310_spdif_resource),
358 .resource = s5pv310_spdif_resource,
359 .dev = {
360 .platform_data = &samsung_spdif_pdata,
361 .dma_mask = &s5pv310_spdif_dmamask,
362 .coherent_dma_mask = DMA_BIT_MASK(32),
363 },
364};
diff --git a/arch/arm/mach-s5pv310/dma.c b/arch/arm/mach-s5pv310/dma.c
new file mode 100644
index 000000000000..20066c7c9e56
--- /dev/null
+++ b/arch/arm/mach-s5pv310/dma.c
@@ -0,0 +1,168 @@
1/*
2 * Copyright (C) 2010 Samsung Electronics Co. Ltd.
3 * Jaswinder Singh <jassi.brar@samsung.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 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 */
19
20#include <linux/platform_device.h>
21#include <linux/dma-mapping.h>
22
23#include <plat/devs.h>
24#include <plat/irqs.h>
25
26#include <mach/map.h>
27#include <mach/irqs.h>
28
29#include <plat/s3c-pl330-pdata.h>
30
31static u64 dma_dmamask = DMA_BIT_MASK(32);
32
33static struct resource s5pv310_pdma0_resource[] = {
34 [0] = {
35 .start = S5PV310_PA_PDMA0,
36 .end = S5PV310_PA_PDMA0 + SZ_4K,
37 .flags = IORESOURCE_MEM,
38 },
39 [1] = {
40 .start = IRQ_PDMA0,
41 .end = IRQ_PDMA0,
42 .flags = IORESOURCE_IRQ,
43 },
44};
45
46static struct s3c_pl330_platdata s5pv310_pdma0_pdata = {
47 .peri = {
48 [0] = DMACH_PCM0_RX,
49 [1] = DMACH_PCM0_TX,
50 [2] = DMACH_PCM2_RX,
51 [3] = DMACH_PCM2_TX,
52 [4] = DMACH_MSM_REQ0,
53 [5] = DMACH_MSM_REQ2,
54 [6] = DMACH_SPI0_RX,
55 [7] = DMACH_SPI0_TX,
56 [8] = DMACH_SPI2_RX,
57 [9] = DMACH_SPI2_TX,
58 [10] = DMACH_I2S0S_TX,
59 [11] = DMACH_I2S0_RX,
60 [12] = DMACH_I2S0_TX,
61 [13] = DMACH_I2S2_RX,
62 [14] = DMACH_I2S2_TX,
63 [15] = DMACH_UART0_RX,
64 [16] = DMACH_UART0_TX,
65 [17] = DMACH_UART2_RX,
66 [18] = DMACH_UART2_TX,
67 [19] = DMACH_UART4_RX,
68 [20] = DMACH_UART4_TX,
69 [21] = DMACH_SLIMBUS0_RX,
70 [22] = DMACH_SLIMBUS0_TX,
71 [23] = DMACH_SLIMBUS2_RX,
72 [24] = DMACH_SLIMBUS2_TX,
73 [25] = DMACH_SLIMBUS4_RX,
74 [26] = DMACH_SLIMBUS4_TX,
75 [27] = DMACH_AC97_MICIN,
76 [28] = DMACH_AC97_PCMIN,
77 [29] = DMACH_AC97_PCMOUT,
78 [30] = DMACH_MAX,
79 [31] = DMACH_MAX,
80 },
81};
82
83static struct platform_device s5pv310_device_pdma0 = {
84 .name = "s3c-pl330",
85 .id = 0,
86 .num_resources = ARRAY_SIZE(s5pv310_pdma0_resource),
87 .resource = s5pv310_pdma0_resource,
88 .dev = {
89 .dma_mask = &dma_dmamask,
90 .coherent_dma_mask = DMA_BIT_MASK(32),
91 .platform_data = &s5pv310_pdma0_pdata,
92 },
93};
94
95static struct resource s5pv310_pdma1_resource[] = {
96 [0] = {
97 .start = S5PV310_PA_PDMA1,
98 .end = S5PV310_PA_PDMA1 + SZ_4K,
99 .flags = IORESOURCE_MEM,
100 },
101 [1] = {
102 .start = IRQ_PDMA1,
103 .end = IRQ_PDMA1,
104 .flags = IORESOURCE_IRQ,
105 },
106};
107
108static struct s3c_pl330_platdata s5pv310_pdma1_pdata = {
109 .peri = {
110 [0] = DMACH_PCM0_RX,
111 [1] = DMACH_PCM0_TX,
112 [2] = DMACH_PCM1_RX,
113 [3] = DMACH_PCM1_TX,
114 [4] = DMACH_MSM_REQ1,
115 [5] = DMACH_MSM_REQ3,
116 [6] = DMACH_SPI1_RX,
117 [7] = DMACH_SPI1_TX,
118 [8] = DMACH_I2S0S_TX,
119 [9] = DMACH_I2S0_RX,
120 [10] = DMACH_I2S0_TX,
121 [11] = DMACH_I2S1_RX,
122 [12] = DMACH_I2S1_TX,
123 [13] = DMACH_UART0_RX,
124 [14] = DMACH_UART0_TX,
125 [15] = DMACH_UART1_RX,
126 [16] = DMACH_UART1_TX,
127 [17] = DMACH_UART3_RX,
128 [18] = DMACH_UART3_TX,
129 [19] = DMACH_SLIMBUS1_RX,
130 [20] = DMACH_SLIMBUS1_TX,
131 [21] = DMACH_SLIMBUS3_RX,
132 [22] = DMACH_SLIMBUS3_TX,
133 [23] = DMACH_SLIMBUS5_RX,
134 [24] = DMACH_SLIMBUS5_TX,
135 [25] = DMACH_SLIMBUS0AUX_RX,
136 [26] = DMACH_SLIMBUS0AUX_TX,
137 [27] = DMACH_SPDIF,
138 [28] = DMACH_MAX,
139 [29] = DMACH_MAX,
140 [30] = DMACH_MAX,
141 [31] = DMACH_MAX,
142 },
143};
144
145static struct platform_device s5pv310_device_pdma1 = {
146 .name = "s3c-pl330",
147 .id = 1,
148 .num_resources = ARRAY_SIZE(s5pv310_pdma1_resource),
149 .resource = s5pv310_pdma1_resource,
150 .dev = {
151 .dma_mask = &dma_dmamask,
152 .coherent_dma_mask = DMA_BIT_MASK(32),
153 .platform_data = &s5pv310_pdma1_pdata,
154 },
155};
156
157static struct platform_device *s5pv310_dmacs[] __initdata = {
158 &s5pv310_device_pdma0,
159 &s5pv310_device_pdma1,
160};
161
162static int __init s5pv310_dma_init(void)
163{
164 platform_add_devices(s5pv310_dmacs, ARRAY_SIZE(s5pv310_dmacs));
165
166 return 0;
167}
168arch_initcall(s5pv310_dma_init);
diff --git a/arch/arm/mach-s5pv310/include/mach/dma.h b/arch/arm/mach-s5pv310/include/mach/dma.h
new file mode 100644
index 000000000000..81209eb1409b
--- /dev/null
+++ b/arch/arm/mach-s5pv310/include/mach/dma.h
@@ -0,0 +1,26 @@
1/*
2 * Copyright (C) 2010 Samsung Electronics Co. Ltd.
3 * Jaswinder Singh <jassi.brar@samsung.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 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 */
19
20#ifndef __MACH_DMA_H
21#define __MACH_DMA_H
22
23/* This platform uses the common S3C DMA API driver for PL330 */
24#include <plat/s3c-dma-pl330.h>
25
26#endif /* __MACH_DMA_H */
diff --git a/arch/arm/mach-s5pv310/include/mach/irqs.h b/arch/arm/mach-s5pv310/include/mach/irqs.h
index 99e7dad8a85a..3c05c58b5392 100644
--- a/arch/arm/mach-s5pv310/include/mach/irqs.h
+++ b/arch/arm/mach-s5pv310/include/mach/irqs.h
@@ -54,6 +54,9 @@
54#define COMBINER_GROUP(x) ((x) * MAX_IRQ_IN_COMBINER + IRQ_SPI(64)) 54#define COMBINER_GROUP(x) ((x) * MAX_IRQ_IN_COMBINER + IRQ_SPI(64))
55#define COMBINER_IRQ(x, y) (COMBINER_GROUP(x) + y) 55#define COMBINER_IRQ(x, y) (COMBINER_GROUP(x) + y)
56 56
57#define IRQ_PDMA0 COMBINER_IRQ(21, 0)
58#define IRQ_PDMA1 COMBINER_IRQ(21, 1)
59
57#define IRQ_TIMER0_VIC COMBINER_IRQ(22, 0) 60#define IRQ_TIMER0_VIC COMBINER_IRQ(22, 0)
58#define IRQ_TIMER1_VIC COMBINER_IRQ(22, 1) 61#define IRQ_TIMER1_VIC COMBINER_IRQ(22, 1)
59#define IRQ_TIMER2_VIC COMBINER_IRQ(22, 2) 62#define IRQ_TIMER2_VIC COMBINER_IRQ(22, 2)
diff --git a/arch/arm/mach-s5pv310/include/mach/map.h b/arch/arm/mach-s5pv310/include/mach/map.h
index 7acf4e77e92e..53994467605d 100644
--- a/arch/arm/mach-s5pv310/include/mach/map.h
+++ b/arch/arm/mach-s5pv310/include/mach/map.h
@@ -52,6 +52,11 @@
52#define S5PV310_PA_GIC_DIST (0x10501000) 52#define S5PV310_PA_GIC_DIST (0x10501000)
53#define S5PV310_PA_L2CC (0x10502000) 53#define S5PV310_PA_L2CC (0x10502000)
54 54
55/* DMA */
56#define S5PV310_PA_MDMA 0x10810000
57#define S5PV310_PA_PDMA0 0x12680000
58#define S5PV310_PA_PDMA1 0x12690000
59
55#define S5PV310_PA_GPIO1 (0x11400000) 60#define S5PV310_PA_GPIO1 (0x11400000)
56#define S5PV310_PA_GPIO2 (0x11000000) 61#define S5PV310_PA_GPIO2 (0x11000000)
57#define S5PV310_PA_GPIO3 (0x03860000) 62#define S5PV310_PA_GPIO3 (0x03860000)
@@ -60,6 +65,22 @@
60 65
61#define S5PV310_PA_SROMC (0x12570000) 66#define S5PV310_PA_SROMC (0x12570000)
62 67
68/* S/PDIF */
69#define S5PV310_PA_SPDIF 0xE1100000
70
71/* I2S */
72#define S5PV310_PA_I2S0 0x03830000
73#define S5PV310_PA_I2S1 0xE3100000
74#define S5PV310_PA_I2S2 0xE2A00000
75
76/* PCM */
77#define S5PV310_PA_PCM0 0x03840000
78#define S5PV310_PA_PCM1 0x13980000
79#define S5PV310_PA_PCM2 0x13990000
80
81/* AC97 */
82#define S5PV310_PA_AC97 0x139A0000
83
63#define S5PV310_PA_UART (0x13800000) 84#define S5PV310_PA_UART (0x13800000)
64 85
65#define S5P_PA_UART(x) (S5PV310_PA_UART + ((x) * S3C_UART_OFFSET)) 86#define S5P_PA_UART(x) (S5PV310_PA_UART + ((x) * S3C_UART_OFFSET))
diff --git a/arch/arm/mach-sa1100/pm.c b/arch/arm/mach-sa1100/pm.c
index c83fdc80edfd..ab9fc4470d36 100644
--- a/arch/arm/mach-sa1100/pm.c
+++ b/arch/arm/mach-sa1100/pm.c
@@ -120,7 +120,7 @@ unsigned long sleep_phys_sp(void *sp)
120 return virt_to_phys(sp); 120 return virt_to_phys(sp);
121} 121}
122 122
123static struct platform_suspend_ops sa11x0_pm_ops = { 123static const struct platform_suspend_ops sa11x0_pm_ops = {
124 .enter = sa11x0_pm_enter, 124 .enter = sa11x0_pm_enter,
125 .valid = suspend_valid_only_mem, 125 .valid = suspend_valid_only_mem,
126}; 126};
diff --git a/arch/arm/mach-shmobile/board-ap4evb.c b/arch/arm/mach-shmobile/board-ap4evb.c
index cd79d7c1ba0d..5b9937c910ff 100644
--- a/arch/arm/mach-shmobile/board-ap4evb.c
+++ b/arch/arm/mach-shmobile/board-ap4evb.c
@@ -711,6 +711,10 @@ static struct platform_device fsi_device = {
711 }, 711 },
712}; 712};
713 713
714static struct platform_device fsi_ak4643_device = {
715 .name = "sh_fsi2_a_ak4643",
716};
717
714static struct sh_mobile_lcdc_info sh_mobile_lcdc1_info = { 718static struct sh_mobile_lcdc_info sh_mobile_lcdc1_info = {
715 .clock_source = LCDC_CLK_EXTERNAL, 719 .clock_source = LCDC_CLK_EXTERNAL,
716 .ch[0] = { 720 .ch[0] = {
@@ -933,6 +937,7 @@ static struct platform_device *ap4evb_devices[] __initdata = {
933 &sdhi1_device, 937 &sdhi1_device,
934 &usb1_host_device, 938 &usb1_host_device,
935 &fsi_device, 939 &fsi_device,
940 &fsi_ak4643_device,
936 &sh_mmcif_device, 941 &sh_mmcif_device,
937 &lcdc1_device, 942 &lcdc1_device,
938 &lcdc_device, 943 &lcdc_device,
diff --git a/arch/arm/mach-spear3xx/spear300.c b/arch/arm/mach-spear3xx/spear300.c
index 3560f8c1e723..5aa2d54ebfaa 100644
--- a/arch/arm/mach-spear3xx/spear300.c
+++ b/arch/arm/mach-spear3xx/spear300.c
@@ -371,7 +371,7 @@ struct pmx_driver pmx_driver = {
371}; 371};
372 372
373/* Add spear300 specific devices here */ 373/* Add spear300 specific devices here */
374/* arm gpio1 device registeration */ 374/* arm gpio1 device registration */
375static struct pl061_platform_data gpio1_plat_data = { 375static struct pl061_platform_data gpio1_plat_data = {
376 .gpio_base = 8, 376 .gpio_base = 8,
377 .irq_base = SPEAR_GPIO1_INT_BASE, 377 .irq_base = SPEAR_GPIO1_INT_BASE,
@@ -451,7 +451,7 @@ void __init spear300_init(void)
451 /* call spear3xx family common init function */ 451 /* call spear3xx family common init function */
452 spear3xx_init(); 452 spear3xx_init();
453 453
454 /* shared irq registeration */ 454 /* shared irq registration */
455 shirq_ras1.regs.base = 455 shirq_ras1.regs.base =
456 ioremap(SPEAR300_TELECOM_BASE, SPEAR300_TELECOM_REG_SIZE); 456 ioremap(SPEAR300_TELECOM_BASE, SPEAR300_TELECOM_REG_SIZE);
457 if (shirq_ras1.regs.base) { 457 if (shirq_ras1.regs.base) {
diff --git a/arch/arm/mach-spear3xx/spear310.c b/arch/arm/mach-spear3xx/spear310.c
index 96a1ab824bac..53b41b52d7ee 100644
--- a/arch/arm/mach-spear3xx/spear310.c
+++ b/arch/arm/mach-spear3xx/spear310.c
@@ -266,7 +266,7 @@ void __init spear310_init(void)
266 /* call spear3xx family common init function */ 266 /* call spear3xx family common init function */
267 spear3xx_init(); 267 spear3xx_init();
268 268
269 /* shared irq registeration */ 269 /* shared irq registration */
270 base = ioremap(SPEAR310_SOC_CONFIG_BASE, SPEAR310_SOC_CONFIG_SIZE); 270 base = ioremap(SPEAR310_SOC_CONFIG_BASE, SPEAR310_SOC_CONFIG_SIZE);
271 if (base) { 271 if (base) {
272 /* shirq 1 */ 272 /* shirq 1 */
diff --git a/arch/arm/mach-spear3xx/spear320.c b/arch/arm/mach-spear3xx/spear320.c
index 6a1219549369..88b465284c36 100644
--- a/arch/arm/mach-spear3xx/spear320.c
+++ b/arch/arm/mach-spear3xx/spear320.c
@@ -519,7 +519,7 @@ void __init spear320_init(void)
519 /* call spear3xx family common init function */ 519 /* call spear3xx family common init function */
520 spear3xx_init(); 520 spear3xx_init();
521 521
522 /* shared irq registeration */ 522 /* shared irq registration */
523 base = ioremap(SPEAR320_SOC_CONFIG_BASE, SPEAR320_SOC_CONFIG_SIZE); 523 base = ioremap(SPEAR320_SOC_CONFIG_BASE, SPEAR320_SOC_CONFIG_SIZE);
524 if (base) { 524 if (base) {
525 /* shirq 1 */ 525 /* shirq 1 */
diff --git a/arch/arm/mach-spear3xx/spear3xx.c b/arch/arm/mach-spear3xx/spear3xx.c
index e87313aeae20..52f553c8c46d 100644
--- a/arch/arm/mach-spear3xx/spear3xx.c
+++ b/arch/arm/mach-spear3xx/spear3xx.c
@@ -22,7 +22,7 @@
22#include <mach/spear.h> 22#include <mach/spear.h>
23 23
24/* Add spear3xx machines common devices here */ 24/* Add spear3xx machines common devices here */
25/* gpio device registeration */ 25/* gpio device registration */
26static struct pl061_platform_data gpio_plat_data = { 26static struct pl061_platform_data gpio_plat_data = {
27 .gpio_base = 0, 27 .gpio_base = 0,
28 .irq_base = SPEAR_GPIO_INT_BASE, 28 .irq_base = SPEAR_GPIO_INT_BASE,
@@ -41,7 +41,7 @@ struct amba_device gpio_device = {
41 .irq = {IRQ_BASIC_GPIO, NO_IRQ}, 41 .irq = {IRQ_BASIC_GPIO, NO_IRQ},
42}; 42};
43 43
44/* uart device registeration */ 44/* uart device registration */
45struct amba_device uart_device = { 45struct amba_device uart_device = {
46 .dev = { 46 .dev = {
47 .init_name = "uart", 47 .init_name = "uart",
@@ -543,6 +543,6 @@ void spear_pmx_init(struct pmx_driver *pmx_driver, uint base, uint size)
543 543
544pmx_fail: 544pmx_fail:
545 if (ret) 545 if (ret)
546 printk(KERN_ERR "padmux: registeration failed. err no: %d\n", 546 printk(KERN_ERR "padmux: registration failed. err no: %d\n",
547 ret); 547 ret);
548} 548}
diff --git a/arch/arm/mach-spear6xx/spear6xx.c b/arch/arm/mach-spear6xx/spear6xx.c
index baf6bcc3169c..f2fe14e8471d 100644
--- a/arch/arm/mach-spear6xx/spear6xx.c
+++ b/arch/arm/mach-spear6xx/spear6xx.c
@@ -23,7 +23,7 @@
23#include <mach/spear.h> 23#include <mach/spear.h>
24 24
25/* Add spear6xx machines common devices here */ 25/* Add spear6xx machines common devices here */
26/* uart device registeration */ 26/* uart device registration */
27struct amba_device uart_device[] = { 27struct amba_device uart_device[] = {
28 { 28 {
29 .dev = { 29 .dev = {
@@ -50,7 +50,7 @@ struct amba_device uart_device[] = {
50 } 50 }
51}; 51};
52 52
53/* gpio device registeration */ 53/* gpio device registration */
54static struct pl061_platform_data gpio_plat_data[] = { 54static struct pl061_platform_data gpio_plat_data[] = {
55 { 55 {
56 .gpio_base = 0, 56 .gpio_base = 0,
diff --git a/arch/arm/mach-u300/Kconfig b/arch/arm/mach-u300/Kconfig
index 801b21e7f677..32a7b0f7e9f7 100644
--- a/arch/arm/mach-u300/Kconfig
+++ b/arch/arm/mach-u300/Kconfig
@@ -64,7 +64,7 @@ config MACH_U300_DUAL_RAM
64 bool "Dual RAM" 64 bool "Dual RAM"
65 help 65 help
66 Select this if you want support for Dual RAM phones. 66 Select this if you want support for Dual RAM phones.
67 This is two RAM memorys on different EMIFs. 67 This is two RAM memories on different EMIFs.
68endchoice 68endchoice
69 69
70config U300_DEBUG 70config U300_DEBUG
diff --git a/arch/arm/mach-u300/include/mach/coh901318.h b/arch/arm/mach-u300/include/mach/coh901318.h
index 193da2df732c..6193aaa47794 100644
--- a/arch/arm/mach-u300/include/mach/coh901318.h
+++ b/arch/arm/mach-u300/include/mach/coh901318.h
@@ -24,7 +24,7 @@
24 * @src_addr: transfer source address 24 * @src_addr: transfer source address
25 * @dst_addr: transfer destination address 25 * @dst_addr: transfer destination address
26 * @link_addr: physical address to next lli 26 * @link_addr: physical address to next lli
27 * @virt_link_addr: virtual addres of next lli (only used by pool_free) 27 * @virt_link_addr: virtual address of next lli (only used by pool_free)
28 * @phy_this: physical address of current lli (only used by pool_free) 28 * @phy_this: physical address of current lli (only used by pool_free)
29 */ 29 */
30struct coh901318_lli { 30struct coh901318_lli {
@@ -90,7 +90,7 @@ struct powersave {
90 * struct coh901318_platform - platform arch structure 90 * struct coh901318_platform - platform arch structure
91 * @chans_slave: specifying dma slave channels 91 * @chans_slave: specifying dma slave channels
92 * @chans_memcpy: specifying dma memcpy channels 92 * @chans_memcpy: specifying dma memcpy channels
93 * @access_memory_state: requesting DMA memeory access (on / off) 93 * @access_memory_state: requesting DMA memory access (on / off)
94 * @chan_conf: dma channel configurations 94 * @chan_conf: dma channel configurations
95 * @max_channels: max number of dma chanenls 95 * @max_channels: max number of dma chanenls
96 */ 96 */
diff --git a/arch/arm/mach-ux500/board-mop500-regulators.c b/arch/arm/mach-ux500/board-mop500-regulators.c
index 1187f1fc2e53..533967c2d095 100644
--- a/arch/arm/mach-ux500/board-mop500-regulators.c
+++ b/arch/arm/mach-ux500/board-mop500-regulators.c
@@ -3,99 +3,94 @@
3 * 3 *
4 * License Terms: GNU General Public License v2 4 * License Terms: GNU General Public License v2
5 * 5 *
6 * Author: Sundar Iyer <sundar.iyer@stericsson.com> 6 * Authors: Sundar Iyer <sundar.iyer@stericsson.com>
7 * Bengt Jonsson <bengt.g.jonsson@stericsson.com>
7 * 8 *
8 * MOP500 board specific initialization for regulators 9 * MOP500 board specific initialization for regulators
9 */ 10 */
10#include <linux/kernel.h> 11#include <linux/kernel.h>
11#include <linux/regulator/machine.h> 12#include <linux/regulator/machine.h>
13#include <linux/regulator/ab8500.h>
12 14
13/* supplies to the display/camera */ 15/* AB8500 regulators */
14static struct regulator_init_data ab8500_vaux1_regulator = { 16struct regulator_init_data ab8500_regulators[AB8500_NUM_REGULATORS] = {
15 .constraints = { 17 /* supplies to the display/camera */
16 .name = "V-DISPLAY", 18 [AB8500_LDO_AUX1] = {
17 .min_uV = 2500000, 19 .constraints = {
18 .max_uV = 2900000, 20 .name = "V-DISPLAY",
19 .valid_ops_mask = REGULATOR_CHANGE_VOLTAGE| 21 .min_uV = 2500000,
20 REGULATOR_CHANGE_STATUS, 22 .max_uV = 2900000,
23 .valid_ops_mask = REGULATOR_CHANGE_VOLTAGE |
24 REGULATOR_CHANGE_STATUS,
25 },
21 }, 26 },
22}; 27 /* supplies to the on-board eMMC */
23 28 [AB8500_LDO_AUX2] = {
24/* supplies to the on-board eMMC */ 29 .constraints = {
25static struct regulator_init_data ab8500_vaux2_regulator = { 30 .name = "V-eMMC1",
26 .constraints = { 31 .min_uV = 1100000,
27 .name = "V-eMMC1", 32 .max_uV = 3300000,
28 .min_uV = 1100000, 33 .valid_ops_mask = REGULATOR_CHANGE_VOLTAGE |
29 .max_uV = 3300000, 34 REGULATOR_CHANGE_STATUS,
30 .valid_ops_mask = REGULATOR_CHANGE_VOLTAGE| 35 },
31 REGULATOR_CHANGE_STATUS,
32 }, 36 },
33}; 37 /* supply for VAUX3, supplies to SDcard slots */
34 38 [AB8500_LDO_AUX3] = {
35/* supply for VAUX3, supplies to SDcard slots */ 39 .constraints = {
36static struct regulator_init_data ab8500_vaux3_regulator = { 40 .name = "V-MMC-SD",
37 .constraints = { 41 .min_uV = 1100000,
38 .name = "V-MMC-SD", 42 .max_uV = 3300000,
39 .min_uV = 1100000, 43 .valid_ops_mask = REGULATOR_CHANGE_VOLTAGE |
40 .max_uV = 3300000, 44 REGULATOR_CHANGE_STATUS,
41 .valid_ops_mask = REGULATOR_CHANGE_VOLTAGE| 45 },
42 REGULATOR_CHANGE_STATUS,
43 }, 46 },
44}; 47 /* supply for tvout, gpadc, TVOUT LDO */
45 48 [AB8500_LDO_TVOUT] = {
46/* supply for tvout, gpadc, TVOUT LDO */ 49 .constraints = {
47static struct regulator_init_data ab8500_vtvout_init = { 50 .name = "V-TVOUT",
48 .constraints = { 51 .valid_ops_mask = REGULATOR_CHANGE_STATUS,
49 .name = "V-TVOUT", 52 },
50 .valid_ops_mask = REGULATOR_CHANGE_STATUS,
51 }, 53 },
52}; 54 /* supply for ab8500-vaudio, VAUDIO LDO */
53 55 [AB8500_LDO_AUDIO] = {
54/* supply for ab8500-vaudio, VAUDIO LDO */ 56 .constraints = {
55static struct regulator_init_data ab8500_vaudio_init = { 57 .name = "V-AUD",
56 .constraints = { 58 .valid_ops_mask = REGULATOR_CHANGE_STATUS,
57 .name = "V-AUD", 59 },
58 .valid_ops_mask = REGULATOR_CHANGE_STATUS,
59 }, 60 },
60}; 61 /* supply for v-anamic1 VAMic1-LDO */
61 62 [AB8500_LDO_ANAMIC1] = {
62/* supply for v-anamic1 VAMic1-LDO */ 63 .constraints = {
63static struct regulator_init_data ab8500_vamic1_init = { 64 .name = "V-AMIC1",
64 .constraints = { 65 .valid_ops_mask = REGULATOR_CHANGE_STATUS,
65 .name = "V-AMIC1", 66 },
66 .valid_ops_mask = REGULATOR_CHANGE_STATUS,
67 }, 67 },
68}; 68 /* supply for v-amic2, VAMIC2 LDO, reuse constants for AMIC1 */
69 69 [AB8500_LDO_ANAMIC2] = {
70/* supply for v-amic2, VAMIC2 LDO, reuse constants for AMIC1 */ 70 .constraints = {
71static struct regulator_init_data ab8500_vamic2_init = { 71 .name = "V-AMIC2",
72 .constraints = { 72 .valid_ops_mask = REGULATOR_CHANGE_STATUS,
73 .name = "V-AMIC2", 73 },
74 .valid_ops_mask = REGULATOR_CHANGE_STATUS,
75 }, 74 },
76}; 75 /* supply for v-dmic, VDMIC LDO */
77 76 [AB8500_LDO_DMIC] = {
78/* supply for v-dmic, VDMIC LDO */ 77 .constraints = {
79static struct regulator_init_data ab8500_vdmic_init = { 78 .name = "V-DMIC",
80 .constraints = { 79 .valid_ops_mask = REGULATOR_CHANGE_STATUS,
81 .name = "V-DMIC", 80 },
82 .valid_ops_mask = REGULATOR_CHANGE_STATUS,
83 }, 81 },
84}; 82 /* supply for v-intcore12, VINTCORE12 LDO */
85 83 [AB8500_LDO_INTCORE] = {
86/* supply for v-intcore12, VINTCORE12 LDO */ 84 .constraints = {
87static struct regulator_init_data ab8500_vintcore_init = { 85 .name = "V-INTCORE",
88 .constraints = { 86 .valid_ops_mask = REGULATOR_CHANGE_STATUS,
89 .name = "V-INTCORE", 87 },
90 .valid_ops_mask = REGULATOR_CHANGE_STATUS,
91 }, 88 },
92}; 89 /* supply for U8500 CSI/DSI, VANA LDO */
93 90 [AB8500_LDO_ANA] = {
94/* supply for U8500 CSI/DSI, VANA LDO */ 91 .constraints = {
95static struct regulator_init_data ab8500_vana_init = { 92 .name = "V-CSI/DSI",
96 .constraints = { 93 .valid_ops_mask = REGULATOR_CHANGE_STATUS,
97 .name = "V-CSI/DSI", 94 },
98 .valid_ops_mask = REGULATOR_CHANGE_STATUS,
99 }, 95 },
100}; 96};
101
diff --git a/arch/arm/mach-ux500/board-mop500-regulators.h b/arch/arm/mach-ux500/board-mop500-regulators.h
new file mode 100644
index 000000000000..2675fae52537
--- /dev/null
+++ b/arch/arm/mach-ux500/board-mop500-regulators.h
@@ -0,0 +1,19 @@
1/*
2 * Copyright (C) ST-Ericsson SA 2010
3 *
4 * License Terms: GNU General Public License v2
5 *
6 * Author: Bengt Jonsson <bengt.g.jonsson@stericsson.com> for ST-Ericsson
7 *
8 * MOP500 board specific initialization for regulators
9 */
10
11#ifndef __BOARD_MOP500_REGULATORS_H
12#define __BOARD_MOP500_REGULATORS_H
13
14#include <linux/regulator/machine.h>
15#include <linux/regulator/ab8500.h>
16
17extern struct regulator_init_data ab8500_regulators[AB8500_NUM_REGULATORS];
18
19#endif
diff --git a/arch/arm/mach-ux500/board-mop500.c b/arch/arm/mach-ux500/board-mop500.c
index a1c9ea1a66df..a393f57ed2a8 100644
--- a/arch/arm/mach-ux500/board-mop500.c
+++ b/arch/arm/mach-ux500/board-mop500.c
@@ -35,6 +35,7 @@
35#include "devices-db8500.h" 35#include "devices-db8500.h"
36#include "pins-db8500.h" 36#include "pins-db8500.h"
37#include "board-mop500.h" 37#include "board-mop500.h"
38#include "board-mop500-regulators.h"
38 39
39static pin_cfg_t mop500_pins[] = { 40static pin_cfg_t mop500_pins[] = {
40 /* SSP0 */ 41 /* SSP0 */
@@ -80,6 +81,8 @@ static pin_cfg_t mop500_pins[] = {
80 81
81static struct ab8500_platform_data ab8500_platdata = { 82static struct ab8500_platform_data ab8500_platdata = {
82 .irq_base = MOP500_AB8500_IRQ_BASE, 83 .irq_base = MOP500_AB8500_IRQ_BASE,
84 .regulator = ab8500_regulators,
85 .num_regulator = ARRAY_SIZE(ab8500_regulators),
83}; 86};
84 87
85static struct resource ab8500_resources[] = { 88static struct resource ab8500_resources[] = {
diff --git a/arch/arm/mm/flush.c b/arch/arm/mm/flush.c
index c29f2839f1d2..2b269c955524 100644
--- a/arch/arm/mm/flush.c
+++ b/arch/arm/mm/flush.c
@@ -18,7 +18,6 @@
18#include <asm/smp_plat.h> 18#include <asm/smp_plat.h>
19#include <asm/system.h> 19#include <asm/system.h>
20#include <asm/tlbflush.h> 20#include <asm/tlbflush.h>
21#include <asm/smp_plat.h>
22 21
23#include "mm.h" 22#include "mm.h"
24 23
diff --git a/arch/arm/plat-mxc/include/mach/irqs.h b/arch/arm/plat-mxc/include/mach/irqs.h
index 58a49cc83797..ba65c9231a78 100644
--- a/arch/arm/plat-mxc/include/mach/irqs.h
+++ b/arch/arm/plat-mxc/include/mach/irqs.h
@@ -70,7 +70,7 @@ extern int imx_irq_set_priority(unsigned char irq, unsigned char prio);
70 70
71/* all normal IRQs can be FIQs */ 71/* all normal IRQs can be FIQs */
72#define FIQ_START 0 72#define FIQ_START 0
73/* switch betwean IRQ and FIQ */ 73/* switch between IRQ and FIQ */
74extern int mxc_set_irq_fiq(unsigned int irq, unsigned int type); 74extern int mxc_set_irq_fiq(unsigned int irq, unsigned int type);
75 75
76#endif /* __ASM_ARCH_MXC_IRQS_H__ */ 76#endif /* __ASM_ARCH_MXC_IRQS_H__ */
diff --git a/arch/arm/plat-omap/include/plat/display.h b/arch/arm/plat-omap/include/plat/display.h
index c915a661f1f5..537f4e449f50 100644
--- a/arch/arm/plat-omap/include/plat/display.h
+++ b/arch/arm/plat-omap/include/plat/display.h
@@ -42,6 +42,10 @@
42#define DISPC_IRQ_SYNC_LOST (1 << 14) 42#define DISPC_IRQ_SYNC_LOST (1 << 14)
43#define DISPC_IRQ_SYNC_LOST_DIGIT (1 << 15) 43#define DISPC_IRQ_SYNC_LOST_DIGIT (1 << 15)
44#define DISPC_IRQ_WAKEUP (1 << 16) 44#define DISPC_IRQ_WAKEUP (1 << 16)
45#define DISPC_IRQ_SYNC_LOST2 (1 << 17)
46#define DISPC_IRQ_VSYNC2 (1 << 18)
47#define DISPC_IRQ_ACBIAS_COUNT_STAT2 (1 << 21)
48#define DISPC_IRQ_FRAMEDONE2 (1 << 22)
45 49
46struct omap_dss_device; 50struct omap_dss_device;
47struct omap_overlay_manager; 51struct omap_overlay_manager;
@@ -64,6 +68,7 @@ enum omap_plane {
64enum omap_channel { 68enum omap_channel {
65 OMAP_DSS_CHANNEL_LCD = 0, 69 OMAP_DSS_CHANNEL_LCD = 0,
66 OMAP_DSS_CHANNEL_DIGIT = 1, 70 OMAP_DSS_CHANNEL_DIGIT = 1,
71 OMAP_DSS_CHANNEL_LCD2 = 2,
67}; 72};
68 73
69enum omap_color_mode { 74enum omap_color_mode {
@@ -142,6 +147,7 @@ enum omap_dss_display_state {
142enum omap_dss_overlay_managers { 147enum omap_dss_overlay_managers {
143 OMAP_DSS_OVL_MGR_LCD, 148 OMAP_DSS_OVL_MGR_LCD,
144 OMAP_DSS_OVL_MGR_TV, 149 OMAP_DSS_OVL_MGR_TV,
150 OMAP_DSS_OVL_MGR_LCD2,
145}; 151};
146 152
147enum omap_dss_rotation_type { 153enum omap_dss_rotation_type {
@@ -268,6 +274,7 @@ struct omap_overlay_info {
268 u16 out_width; /* if 0, out_width == width */ 274 u16 out_width; /* if 0, out_width == width */
269 u16 out_height; /* if 0, out_height == height */ 275 u16 out_height; /* if 0, out_height == height */
270 u8 global_alpha; 276 u8 global_alpha;
277 u8 pre_mult_alpha;
271}; 278};
272 279
273struct omap_overlay { 280struct omap_overlay {
@@ -351,6 +358,8 @@ struct omap_dss_device {
351 358
352 enum omap_display_type type; 359 enum omap_display_type type;
353 360
361 enum omap_channel channel;
362
354 union { 363 union {
355 struct { 364 struct {
356 u8 data_lines; 365 u8 data_lines;
diff --git a/arch/arm/plat-omap/include/plat/omap_hwmod.h b/arch/arm/plat-omap/include/plat/omap_hwmod.h
index 6864a997f2ca..1eee85a8abb3 100644
--- a/arch/arm/plat-omap/include/plat/omap_hwmod.h
+++ b/arch/arm/plat-omap/include/plat/omap_hwmod.h
@@ -351,7 +351,7 @@ struct omap_hwmod_omap2_prcm {
351/** 351/**
352 * struct omap_hwmod_omap4_prcm - OMAP4-specific PRCM data 352 * struct omap_hwmod_omap4_prcm - OMAP4-specific PRCM data
353 * @clkctrl_reg: PRCM address of the clock control register 353 * @clkctrl_reg: PRCM address of the clock control register
354 * @rstctrl_reg: adress of the XXX_RSTCTRL register located in the PRM 354 * @rstctrl_reg: address of the XXX_RSTCTRL register located in the PRM
355 * @submodule_wkdep_bit: bit shift of the WKDEP range 355 * @submodule_wkdep_bit: bit shift of the WKDEP range
356 */ 356 */
357struct omap_hwmod_omap4_prcm { 357struct omap_hwmod_omap4_prcm {
diff --git a/arch/arm/plat-omap/include/plat/panel-generic-dpi.h b/arch/arm/plat-omap/include/plat/panel-generic-dpi.h
new file mode 100644
index 000000000000..790619734bcd
--- /dev/null
+++ b/arch/arm/plat-omap/include/plat/panel-generic-dpi.h
@@ -0,0 +1,37 @@
1/*
2 * Header for generic DPI panel driver
3 *
4 * Copyright (C) 2010 Canonical Ltd.
5 * Author: Bryan Wu <bryan.wu@canonical.com>
6 *
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License version 2 as published by
9 * the Free Software Foundation.
10 *
11 * This program is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 * more details.
15 *
16 * You should have received a copy of the GNU General Public License along with
17 * this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#ifndef __ARCH_ARM_PLAT_OMAP_PANEL_GENERIC_DPI_H
21#define __ARCH_ARM_PLAT_OMAP_PANEL_GENERIC_DPI_H
22
23#include "display.h"
24
25/**
26 * struct panel_generic_dpi_data - panel driver configuration data
27 * @name: panel name
28 * @platform_enable: platform specific panel enable function
29 * @platform_disable: platform specific panel disable function
30 */
31struct panel_generic_dpi_data {
32 const char *name;
33 int (*platform_enable)(struct omap_dss_device *dssdev);
34 void (*platform_disable)(struct omap_dss_device *dssdev);
35};
36
37#endif /* __ARCH_ARM_PLAT_OMAP_PANEL_GENERIC_DPI_H */
diff --git a/arch/arm/plat-s3c24xx/devs.c b/arch/arm/plat-s3c24xx/devs.c
index 2f91057a0c02..8a42bc48dbf0 100644
--- a/arch/arm/plat-s3c24xx/devs.c
+++ b/arch/arm/plat-s3c24xx/devs.c
@@ -259,21 +259,6 @@ struct platform_device s3c_device_iis = {
259 259
260EXPORT_SYMBOL(s3c_device_iis); 260EXPORT_SYMBOL(s3c_device_iis);
261 261
262/* ASoC PCM DMA */
263
264static u64 s3c_device_audio_dmamask = 0xffffffffUL;
265
266struct platform_device s3c_device_pcm = {
267 .name = "s3c24xx-pcm-audio",
268 .id = -1,
269 .dev = {
270 .dma_mask = &s3c_device_audio_dmamask,
271 .coherent_dma_mask = 0xffffffffUL
272 }
273};
274
275EXPORT_SYMBOL(s3c_device_pcm);
276
277/* RTC */ 262/* RTC */
278 263
279static struct resource s3c_rtc_resource[] = { 264static struct resource s3c_rtc_resource[] = {
@@ -496,8 +481,10 @@ static struct resource s3c_ac97_resource[] = {
496 }, 481 },
497}; 482};
498 483
484static u64 s3c_device_audio_dmamask = 0xffffffffUL;
485
499struct platform_device s3c_device_ac97 = { 486struct platform_device s3c_device_ac97 = {
500 .name = "s3c-ac97", 487 .name = "samsung-ac97",
501 .id = -1, 488 .id = -1,
502 .num_resources = ARRAY_SIZE(s3c_ac97_resource), 489 .num_resources = ARRAY_SIZE(s3c_ac97_resource),
503 .resource = s3c_ac97_resource, 490 .resource = s3c_ac97_resource,
diff --git a/arch/arm/plat-samsung/Makefile b/arch/arm/plat-samsung/Makefile
index afcce474af8e..19d8a16c3066 100644
--- a/arch/arm/plat-samsung/Makefile
+++ b/arch/arm/plat-samsung/Makefile
@@ -17,6 +17,7 @@ obj-y += clock.o
17obj-y += pwm-clock.o 17obj-y += pwm-clock.o
18obj-y += gpio.o 18obj-y += gpio.o
19obj-y += gpio-config.o 19obj-y += gpio-config.o
20obj-y += dev-asocdma.o
20 21
21obj-$(CONFIG_SAMSUNG_GPIOLIB_4BIT) += gpiolib.o 22obj-$(CONFIG_SAMSUNG_GPIOLIB_4BIT) += gpiolib.o
22obj-$(CONFIG_SAMSUNG_CLKSRC) += clock-clksrc.o 23obj-$(CONFIG_SAMSUNG_CLKSRC) += clock-clksrc.o
diff --git a/arch/arm/plat-samsung/dev-asocdma.c b/arch/arm/plat-samsung/dev-asocdma.c
new file mode 100644
index 000000000000..a068c4f42d56
--- /dev/null
+++ b/arch/arm/plat-samsung/dev-asocdma.c
@@ -0,0 +1,25 @@
1/* linux/arch/arm/plat-samsung/dev-asocdma.c
2 *
3 * Copyright (c) 2010 Samsung Electronics Co. Ltd
4 * Jaswinder Singh <jassi.brar@samsung.com>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
9 */
10
11#include <linux/platform_device.h>
12#include <linux/dma-mapping.h>
13#include <plat/devs.h>
14
15static u64 audio_dmamask = DMA_BIT_MASK(32);
16
17struct platform_device samsung_asoc_dma = {
18 .name = "samsung-audio",
19 .id = -1,
20 .dev = {
21 .dma_mask = &audio_dmamask,
22 .coherent_dma_mask = DMA_BIT_MASK(32),
23 }
24};
25EXPORT_SYMBOL(samsung_asoc_dma);
diff --git a/arch/arm/plat-samsung/include/plat/audio.h b/arch/arm/plat-samsung/include/plat/audio.h
index 7712ff6336f4..a0826ed2f9fe 100644
--- a/arch/arm/plat-samsung/include/plat/audio.h
+++ b/arch/arm/plat-samsung/include/plat/audio.h
@@ -25,10 +25,34 @@ extern void s3c64xx_ac97_setup_gpio(int);
25#define S5PC100_SPDIF_GPG3 1 25#define S5PC100_SPDIF_GPG3 1
26extern void s5pc100_spdif_setup_gpio(int); 26extern void s5pc100_spdif_setup_gpio(int);
27 27
28struct samsung_i2s {
29/* If the Primary DAI has 5.1 Channels */
30#define QUIRK_PRI_6CHAN (1 << 0)
31/* If the I2S block has a Stereo Overlay Channel */
32#define QUIRK_SEC_DAI (1 << 1)
33/*
34 * If the I2S block has no internal prescalar or MUX (I2SMOD[10] bit)
35 * The Machine driver must provide suitably set clock to the I2S block.
36 */
37#define QUIRK_NO_MUXPSR (1 << 2)
38#define QUIRK_NEED_RSTCLR (1 << 3)
39 /* Quirks of the I2S controller */
40 u32 quirks;
41
42 /*
43 * Array of clock names that can be used to generate I2S signals.
44 * Also corresponds to clocks of I2SMOD[10]
45 */
46 const char **src_clk;
47};
48
28/** 49/**
29 * struct s3c_audio_pdata - common platform data for audio device drivers 50 * struct s3c_audio_pdata - common platform data for audio device drivers
30 * @cfg_gpio: Callback function to setup mux'ed pins in I2S/PCM/AC97 mode 51 * @cfg_gpio: Callback function to setup mux'ed pins in I2S/PCM/AC97 mode
31 */ 52 */
32struct s3c_audio_pdata { 53struct s3c_audio_pdata {
33 int (*cfg_gpio)(struct platform_device *); 54 int (*cfg_gpio)(struct platform_device *);
55 union {
56 struct samsung_i2s i2s;
57 } type;
34}; 58};
diff --git a/arch/arm/plat-samsung/include/plat/devs.h b/arch/arm/plat-samsung/include/plat/devs.h
index 2d82a6cb1444..e9e3b6e3ec74 100644
--- a/arch/arm/plat-samsung/include/plat/devs.h
+++ b/arch/arm/plat-samsung/include/plat/devs.h
@@ -32,7 +32,7 @@ extern struct platform_device s3c64xx_device_iisv4;
32extern struct platform_device s3c64xx_device_spi0; 32extern struct platform_device s3c64xx_device_spi0;
33extern struct platform_device s3c64xx_device_spi1; 33extern struct platform_device s3c64xx_device_spi1;
34 34
35extern struct platform_device s3c_device_pcm; 35extern struct platform_device samsung_asoc_dma;
36 36
37extern struct platform_device s3c64xx_device_pcm0; 37extern struct platform_device s3c64xx_device_pcm0;
38extern struct platform_device s3c64xx_device_pcm1; 38extern struct platform_device s3c64xx_device_pcm1;
@@ -96,6 +96,15 @@ extern struct platform_device s5pv210_device_iis1;
96extern struct platform_device s5pv210_device_iis2; 96extern struct platform_device s5pv210_device_iis2;
97extern struct platform_device s5pv210_device_spdif; 97extern struct platform_device s5pv210_device_spdif;
98 98
99extern struct platform_device s5pv310_device_ac97;
100extern struct platform_device s5pv310_device_pcm0;
101extern struct platform_device s5pv310_device_pcm1;
102extern struct platform_device s5pv310_device_pcm2;
103extern struct platform_device s5pv310_device_i2s0;
104extern struct platform_device s5pv310_device_i2s1;
105extern struct platform_device s5pv310_device_i2s2;
106extern struct platform_device s5pv310_device_spdif;
107
99extern struct platform_device s5p6442_device_pcm0; 108extern struct platform_device s5p6442_device_pcm0;
100extern struct platform_device s5p6442_device_pcm1; 109extern struct platform_device s5p6442_device_pcm1;
101extern struct platform_device s5p6442_device_iis0; 110extern struct platform_device s5p6442_device_iis0;
diff --git a/arch/arm/plat-samsung/pm.c b/arch/arm/plat-samsung/pm.c
index 27cfca597699..5bf3f2f09e74 100644
--- a/arch/arm/plat-samsung/pm.c
+++ b/arch/arm/plat-samsung/pm.c
@@ -355,7 +355,7 @@ static void s3c_pm_finish(void)
355 s3c_pm_check_cleanup(); 355 s3c_pm_check_cleanup();
356} 356}
357 357
358static struct platform_suspend_ops s3c_pm_ops = { 358static const struct platform_suspend_ops s3c_pm_ops = {
359 .enter = s3c_pm_enter, 359 .enter = s3c_pm_enter,
360 .prepare = s3c_pm_prepare, 360 .prepare = s3c_pm_prepare,
361 .finish = s3c_pm_finish, 361 .finish = s3c_pm_finish,
diff --git a/arch/avr32/mach-at32ap/pm.c b/arch/avr32/mach-at32ap/pm.c
index f021edfeaab0..32d680eb6f48 100644
--- a/arch/avr32/mach-at32ap/pm.c
+++ b/arch/avr32/mach-at32ap/pm.c
@@ -176,7 +176,7 @@ out:
176 return 0; 176 return 0;
177} 177}
178 178
179static struct platform_suspend_ops avr32_pm_ops = { 179static const struct platform_suspend_ops avr32_pm_ops = {
180 .valid = avr32_pm_valid_state, 180 .valid = avr32_pm_valid_state,
181 .enter = avr32_pm_enter, 181 .enter = avr32_pm_enter,
182}; 182};
diff --git a/arch/blackfin/mach-bf537/include/mach/defBF534.h b/arch/blackfin/mach-bf537/include/mach/defBF534.h
index 32529a03b266..725bb35f3aaa 100644
--- a/arch/blackfin/mach-bf537/include/mach/defBF534.h
+++ b/arch/blackfin/mach-bf537/include/mach/defBF534.h
@@ -1418,7 +1418,7 @@
1418#define SADD_LEN 0x0002 /* Slave Address Length */ 1418#define SADD_LEN 0x0002 /* Slave Address Length */
1419#define STDVAL 0x0004 /* Slave Transmit Data Valid */ 1419#define STDVAL 0x0004 /* Slave Transmit Data Valid */
1420#define NAK 0x0008 /* NAK/ACK* Generated At Conclusion Of Transfer */ 1420#define NAK 0x0008 /* NAK/ACK* Generated At Conclusion Of Transfer */
1421#define GEN 0x0010 /* General Call Adrress Matching Enabled */ 1421#define GEN 0x0010 /* General Call Address Matching Enabled */
1422 1422
1423/* TWI_SLAVE_STAT Masks */ 1423/* TWI_SLAVE_STAT Masks */
1424#define SDIR 0x0001 /* Slave Transfer Direction (Transmit/Receive*) */ 1424#define SDIR 0x0001 /* Slave Transfer Direction (Transmit/Receive*) */
diff --git a/arch/blackfin/mach-common/pm.c b/arch/blackfin/mach-common/pm.c
index 42fa87e8375c..3c648a077e75 100644
--- a/arch/blackfin/mach-common/pm.c
+++ b/arch/blackfin/mach-common/pm.c
@@ -223,7 +223,7 @@ static int bfin_pm_enter(suspend_state_t state)
223 return 0; 223 return 0;
224} 224}
225 225
226struct platform_suspend_ops bfin_pm_ops = { 226static const struct platform_suspend_ops bfin_pm_ops = {
227 .enter = bfin_pm_enter, 227 .enter = bfin_pm_enter,
228 .valid = bfin_pm_valid, 228 .valid = bfin_pm_valid,
229}; 229};
diff --git a/arch/cris/arch-v32/lib/nand_init.S b/arch/cris/arch-v32/lib/nand_init.S
index e705f5cce969..d671fed451c9 100644
--- a/arch/cris/arch-v32/lib/nand_init.S
+++ b/arch/cris/arch-v32/lib/nand_init.S
@@ -139,7 +139,7 @@ copy_nand_to_ram:
139 lsrq 8, $r4 139 lsrq 8, $r4
140 move.b $r4, [$r1] ; Row address 140 move.b $r4, [$r1] ; Row address
141 lsrq 8, $r4 141 lsrq 8, $r4
142 move.b $r4, [$r1] ; Row adddress 142 move.b $r4, [$r1] ; Row address
143 moveq 20, $r4 143 moveq 20, $r4
1442: bne 2b 1442: bne 2b
145 subq 1, $r4 145 subq 1, $r4
diff --git a/arch/cris/include/asm/etraxgpio.h b/arch/cris/include/asm/etraxgpio.h
index d474818a537e..461c089db765 100644
--- a/arch/cris/include/asm/etraxgpio.h
+++ b/arch/cris/include/asm/etraxgpio.h
@@ -1,5 +1,5 @@
1/* 1/*
2 * The following devices are accessable using this driver using 2 * The following devices are accessible using this driver using
3 * GPIO_MAJOR (120) and a couple of minor numbers. 3 * GPIO_MAJOR (120) and a couple of minor numbers.
4 * 4 *
5 * For ETRAX 100LX (CONFIG_ETRAX_ARCH_V10): 5 * For ETRAX 100LX (CONFIG_ETRAX_ARCH_V10):
diff --git a/arch/cris/kernel/time.c b/arch/cris/kernel/time.c
index b5096430ce1c..4e73092e85c0 100644
--- a/arch/cris/kernel/time.c
+++ b/arch/cris/kernel/time.c
@@ -86,7 +86,7 @@ int set_rtc_mmss(unsigned long nowtime)
86 CMOS_WRITE(real_seconds,RTC_SECONDS); 86 CMOS_WRITE(real_seconds,RTC_SECONDS);
87 CMOS_WRITE(real_minutes,RTC_MINUTES); 87 CMOS_WRITE(real_minutes,RTC_MINUTES);
88 } else { 88 } else {
89 printk(KERN_WARNING 89 printk_once(KERN_NOTICE
90 "set_rtc_mmss: can't update from %d to %d\n", 90 "set_rtc_mmss: can't update from %d to %d\n",
91 cmos_minutes, real_minutes); 91 cmos_minutes, real_minutes);
92 retval = -1; 92 retval = -1;
diff --git a/arch/h8300/Kconfig.debug b/arch/h8300/Kconfig.debug
index ee671c3f2c74..e8d1b236ad8c 100644
--- a/arch/h8300/Kconfig.debug
+++ b/arch/h8300/Kconfig.debug
@@ -48,7 +48,7 @@ config DEFAULT_CMDLINE
48 builtin kernel commandline enabled. 48 builtin kernel commandline enabled.
49 49
50config KERNEL_COMMAND 50config KERNEL_COMMAND
51 string "Buildin commmand string" 51 string "Buildin command string"
52 depends on DEFAULT_CMDLINE 52 depends on DEFAULT_CMDLINE
53 help 53 help
54 builtin kernel commandline strings. 54 builtin kernel commandline strings.
diff --git a/arch/ia64/include/asm/kvm_host.h b/arch/ia64/include/asm/kvm_host.h
index 2f229e5de498..2689ee54a1c9 100644
--- a/arch/ia64/include/asm/kvm_host.h
+++ b/arch/ia64/include/asm/kvm_host.h
@@ -590,6 +590,10 @@ int kvm_emulate_halt(struct kvm_vcpu *vcpu);
590int kvm_pal_emul(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run); 590int kvm_pal_emul(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run);
591void kvm_sal_emul(struct kvm_vcpu *vcpu); 591void kvm_sal_emul(struct kvm_vcpu *vcpu);
592 592
593#define __KVM_HAVE_ARCH_VM_ALLOC 1
594struct kvm *kvm_arch_alloc_vm(void);
595void kvm_arch_free_vm(struct kvm *kvm);
596
593#endif /* __ASSEMBLY__*/ 597#endif /* __ASSEMBLY__*/
594 598
595#endif 599#endif
diff --git a/arch/ia64/kernel/perfmon.c b/arch/ia64/kernel/perfmon.c
index d92d5b5161fc..ac76da099a6d 100644
--- a/arch/ia64/kernel/perfmon.c
+++ b/arch/ia64/kernel/perfmon.c
@@ -617,11 +617,14 @@ pfm_get_unmapped_area(struct file *file, unsigned long addr, unsigned long len,
617 return get_unmapped_area(file, addr, len, pgoff, flags); 617 return get_unmapped_area(file, addr, len, pgoff, flags);
618} 618}
619 619
620/* forward declaration */
621static static const struct dentry_operations pfmfs_dentry_operations;
620 622
621static struct dentry * 623static struct dentry *
622pfmfs_mount(struct file_system_type *fs_type, int flags, const char *dev_name, void *data) 624pfmfs_mount(struct file_system_type *fs_type, int flags, const char *dev_name, void *data)
623{ 625{
624 return mount_pseudo(fs_type, "pfm:", NULL, PFMFS_MAGIC); 626 return mount_pseudo(fs_type, "pfm:", NULL, &pfmfs_dentry_operations,
627 PFMFS_MAGIC);
625} 628}
626 629
627static struct file_system_type pfm_fs_type = { 630static struct file_system_type pfm_fs_type = {
@@ -2232,7 +2235,6 @@ pfm_alloc_file(pfm_context_t *ctx)
2232 } 2235 }
2233 path.mnt = mntget(pfmfs_mnt); 2236 path.mnt = mntget(pfmfs_mnt);
2234 2237
2235 d_set_d_op(path.dentry, &pfmfs_dentry_operations);
2236 d_add(path.dentry, inode); 2238 d_add(path.dentry, inode);
2237 2239
2238 file = alloc_file(&path, FMODE_READ, &pfm_file_ops); 2240 file = alloc_file(&path, FMODE_READ, &pfm_file_ops);
diff --git a/arch/ia64/kvm/kvm-ia64.c b/arch/ia64/kvm/kvm-ia64.c
index f56a6316e134..70d224d4264c 100644
--- a/arch/ia64/kvm/kvm-ia64.c
+++ b/arch/ia64/kvm/kvm-ia64.c
@@ -749,7 +749,7 @@ out:
749 return r; 749 return r;
750} 750}
751 751
752static struct kvm *kvm_alloc_kvm(void) 752struct kvm *kvm_arch_alloc_vm(void)
753{ 753{
754 754
755 struct kvm *kvm; 755 struct kvm *kvm;
@@ -760,7 +760,7 @@ static struct kvm *kvm_alloc_kvm(void)
760 vm_base = __get_free_pages(GFP_KERNEL, get_order(KVM_VM_DATA_SIZE)); 760 vm_base = __get_free_pages(GFP_KERNEL, get_order(KVM_VM_DATA_SIZE));
761 761
762 if (!vm_base) 762 if (!vm_base)
763 return ERR_PTR(-ENOMEM); 763 return NULL;
764 764
765 memset((void *)vm_base, 0, KVM_VM_DATA_SIZE); 765 memset((void *)vm_base, 0, KVM_VM_DATA_SIZE);
766 kvm = (struct kvm *)(vm_base + 766 kvm = (struct kvm *)(vm_base +
@@ -806,10 +806,12 @@ static void kvm_build_io_pmt(struct kvm *kvm)
806#define GUEST_PHYSICAL_RR4 0x2739 806#define GUEST_PHYSICAL_RR4 0x2739
807#define VMM_INIT_RR 0x1660 807#define VMM_INIT_RR 0x1660
808 808
809static void kvm_init_vm(struct kvm *kvm) 809int kvm_arch_init_vm(struct kvm *kvm)
810{ 810{
811 BUG_ON(!kvm); 811 BUG_ON(!kvm);
812 812
813 kvm->arch.is_sn2 = ia64_platform_is("sn2");
814
813 kvm->arch.metaphysical_rr0 = GUEST_PHYSICAL_RR0; 815 kvm->arch.metaphysical_rr0 = GUEST_PHYSICAL_RR0;
814 kvm->arch.metaphysical_rr4 = GUEST_PHYSICAL_RR4; 816 kvm->arch.metaphysical_rr4 = GUEST_PHYSICAL_RR4;
815 kvm->arch.vmm_init_rr = VMM_INIT_RR; 817 kvm->arch.vmm_init_rr = VMM_INIT_RR;
@@ -823,21 +825,8 @@ static void kvm_init_vm(struct kvm *kvm)
823 825
824 /* Reserve bit 0 of irq_sources_bitmap for userspace irq source */ 826 /* Reserve bit 0 of irq_sources_bitmap for userspace irq source */
825 set_bit(KVM_USERSPACE_IRQ_SOURCE_ID, &kvm->arch.irq_sources_bitmap); 827 set_bit(KVM_USERSPACE_IRQ_SOURCE_ID, &kvm->arch.irq_sources_bitmap);
826}
827
828struct kvm *kvm_arch_create_vm(void)
829{
830 struct kvm *kvm = kvm_alloc_kvm();
831
832 if (IS_ERR(kvm))
833 return ERR_PTR(-ENOMEM);
834
835 kvm->arch.is_sn2 = ia64_platform_is("sn2");
836
837 kvm_init_vm(kvm);
838
839 return kvm;
840 828
829 return 0;
841} 830}
842 831
843static int kvm_vm_ioctl_get_irqchip(struct kvm *kvm, 832static int kvm_vm_ioctl_get_irqchip(struct kvm *kvm,
@@ -962,7 +951,9 @@ long kvm_arch_vm_ioctl(struct file *filp,
962 goto out; 951 goto out;
963 r = kvm_setup_default_irq_routing(kvm); 952 r = kvm_setup_default_irq_routing(kvm);
964 if (r) { 953 if (r) {
954 mutex_lock(&kvm->slots_lock);
965 kvm_ioapic_destroy(kvm); 955 kvm_ioapic_destroy(kvm);
956 mutex_unlock(&kvm->slots_lock);
966 goto out; 957 goto out;
967 } 958 }
968 break; 959 break;
@@ -1357,7 +1348,7 @@ int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu,
1357 return -EINVAL; 1348 return -EINVAL;
1358} 1349}
1359 1350
1360static void free_kvm(struct kvm *kvm) 1351void kvm_arch_free_vm(struct kvm *kvm)
1361{ 1352{
1362 unsigned long vm_base = kvm->arch.vm_base; 1353 unsigned long vm_base = kvm->arch.vm_base;
1363 1354
@@ -1399,9 +1390,6 @@ void kvm_arch_destroy_vm(struct kvm *kvm)
1399#endif 1390#endif
1400 kfree(kvm->arch.vioapic); 1391 kfree(kvm->arch.vioapic);
1401 kvm_release_vm_pages(kvm); 1392 kvm_release_vm_pages(kvm);
1402 kvm_free_physmem(kvm);
1403 cleanup_srcu_struct(&kvm->srcu);
1404 free_kvm(kvm);
1405} 1393}
1406 1394
1407void kvm_arch_vcpu_put(struct kvm_vcpu *vcpu) 1395void kvm_arch_vcpu_put(struct kvm_vcpu *vcpu)
diff --git a/arch/ia64/kvm/mmio.c b/arch/ia64/kvm/mmio.c
index fb8f9f59a1ed..f1e17d3d6cd9 100644
--- a/arch/ia64/kvm/mmio.c
+++ b/arch/ia64/kvm/mmio.c
@@ -130,7 +130,7 @@ static void mmio_access(struct kvm_vcpu *vcpu, u64 src_pa, u64 *dest,
130 130
131 local_irq_save(psr); 131 local_irq_save(psr);
132 132
133 /*Intercept the acces for PIB range*/ 133 /*Intercept the access for PIB range*/
134 if (iot == GPFN_PIB) { 134 if (iot == GPFN_PIB) {
135 if (!dir) 135 if (!dir)
136 lsapic_write(vcpu, src_pa, s, *dest); 136 lsapic_write(vcpu, src_pa, s, *dest);
diff --git a/arch/m68k/ifpsp060/src/fpsp.S b/arch/m68k/ifpsp060/src/fpsp.S
index 73613b5f1ee5..26e85e2b7a5e 100644
--- a/arch/m68k/ifpsp060/src/fpsp.S
+++ b/arch/m68k/ifpsp060/src/fpsp.S
@@ -3881,7 +3881,7 @@ _fpsp_fline:
3881# FP Unimplemented Instruction stack frame and jump to that entry 3881# FP Unimplemented Instruction stack frame and jump to that entry
3882# point. 3882# point.
3883# 3883#
3884# but, if the FPU is disabled, then we need to jump to the FPU diabled 3884# but, if the FPU is disabled, then we need to jump to the FPU disabled
3885# entry point. 3885# entry point.
3886 movc %pcr,%d0 3886 movc %pcr,%d0
3887 btst &0x1,%d0 3887 btst &0x1,%d0
diff --git a/arch/m68k/include/asm/m548xgpt.h b/arch/m68k/include/asm/m548xgpt.h
index c8ef158a1c4e..33b2eef90f0a 100644
--- a/arch/m68k/include/asm/m548xgpt.h
+++ b/arch/m68k/include/asm/m548xgpt.h
@@ -59,11 +59,13 @@
59#define MCF_GPT_GMS_GPIO_INPUT (0x00000000) 59#define MCF_GPT_GMS_GPIO_INPUT (0x00000000)
60#define MCF_GPT_GMS_GPIO_OUTLO (0x00000020) 60#define MCF_GPT_GMS_GPIO_OUTLO (0x00000020)
61#define MCF_GPT_GMS_GPIO_OUTHI (0x00000030) 61#define MCF_GPT_GMS_GPIO_OUTHI (0x00000030)
62#define MCF_GPT_GMS_GPIO_MASK (0x00000030)
62#define MCF_GPT_GMS_TMS_DISABLE (0x00000000) 63#define MCF_GPT_GMS_TMS_DISABLE (0x00000000)
63#define MCF_GPT_GMS_TMS_INCAPT (0x00000001) 64#define MCF_GPT_GMS_TMS_INCAPT (0x00000001)
64#define MCF_GPT_GMS_TMS_OUTCAPT (0x00000002) 65#define MCF_GPT_GMS_TMS_OUTCAPT (0x00000002)
65#define MCF_GPT_GMS_TMS_PWM (0x00000003) 66#define MCF_GPT_GMS_TMS_PWM (0x00000003)
66#define MCF_GPT_GMS_TMS_GPIO (0x00000004) 67#define MCF_GPT_GMS_TMS_GPIO (0x00000004)
68#define MCF_GPT_GMS_TMS_MASK (0x00000007)
67 69
68/* Bit definitions and macros for MCF_GPT_GCIR */ 70/* Bit definitions and macros for MCF_GPT_GCIR */
69#define MCF_GPT_GCIR_CNT(x) (((x)&0x0000FFFF)<<0) 71#define MCF_GPT_GCIR_CNT(x) (((x)&0x0000FFFF)<<0)
diff --git a/arch/m68k/mac/psc.c b/arch/m68k/mac/psc.c
index ba6ccab64018..a4c3eb60706e 100644
--- a/arch/m68k/mac/psc.c
+++ b/arch/m68k/mac/psc.c
@@ -88,7 +88,7 @@ void __init psc_init(void)
88 88
89 /* 89 /*
90 * The PSC is always at the same spot, but using psc 90 * The PSC is always at the same spot, but using psc
91 * keeps things consisant with the psc_xxxx functions. 91 * keeps things consistent with the psc_xxxx functions.
92 */ 92 */
93 93
94 psc = (void *) PSC_BASE; 94 psc = (void *) PSC_BASE;
diff --git a/arch/mips/alchemy/common/power.c b/arch/mips/alchemy/common/power.c
index e5916a516e58..647e518c90bc 100644
--- a/arch/mips/alchemy/common/power.c
+++ b/arch/mips/alchemy/common/power.c
@@ -130,7 +130,7 @@ static void restore_core_regs(void)
130 au_writel(sleep_usb[1], USBD_ENABLE); 130 au_writel(sleep_usb[1], USBD_ENABLE);
131 au_sync(); 131 au_sync();
132#else 132#else
133 /* enable accces to OTG memory */ 133 /* enable access to OTG memory */
134 au_writel(au_readl(USB_MSR_BASE + 4) | (1 << 6), USB_MSR_BASE + 4); 134 au_writel(au_readl(USB_MSR_BASE + 4) | (1 << 6), USB_MSR_BASE + 4);
135 au_sync(); 135 au_sync();
136 136
diff --git a/arch/mips/alchemy/devboards/pm.c b/arch/mips/alchemy/devboards/pm.c
index 4bbd3133e451..acaf91b5e461 100644
--- a/arch/mips/alchemy/devboards/pm.c
+++ b/arch/mips/alchemy/devboards/pm.c
@@ -110,7 +110,7 @@ static void db1x_pm_end(void)
110 110
111} 111}
112 112
113static struct platform_suspend_ops db1x_pm_ops = { 113static const struct platform_suspend_ops db1x_pm_ops = {
114 .valid = suspend_valid_only_mem, 114 .valid = suspend_valid_only_mem,
115 .begin = db1x_pm_begin, 115 .begin = db1x_pm_begin,
116 .enter = db1x_pm_enter, 116 .enter = db1x_pm_enter,
diff --git a/arch/mips/dec/time.c b/arch/mips/dec/time.c
index 02f505f23c32..ea57f39e6736 100644
--- a/arch/mips/dec/time.c
+++ b/arch/mips/dec/time.c
@@ -104,7 +104,7 @@ int rtc_mips_set_mmss(unsigned long nowtime)
104 CMOS_WRITE(real_seconds, RTC_SECONDS); 104 CMOS_WRITE(real_seconds, RTC_SECONDS);
105 CMOS_WRITE(real_minutes, RTC_MINUTES); 105 CMOS_WRITE(real_minutes, RTC_MINUTES);
106 } else { 106 } else {
107 printk(KERN_WARNING 107 printk_once(KERN_NOTICE
108 "set_rtc_mmss: can't update from %d to %d\n", 108 "set_rtc_mmss: can't update from %d to %d\n",
109 cmos_minutes, real_minutes); 109 cmos_minutes, real_minutes);
110 retval = -1; 110 retval = -1;
diff --git a/arch/mips/include/asm/mach-powertv/ioremap.h b/arch/mips/include/asm/mach-powertv/ioremap.h
index 076f2eeaa575..c86ef094ec37 100644
--- a/arch/mips/include/asm/mach-powertv/ioremap.h
+++ b/arch/mips/include/asm/mach-powertv/ioremap.h
@@ -88,7 +88,7 @@ static inline dma_addr_t _dma_to_phys_offset_raw(dma_addr_t dma)
88} 88}
89 89
90/* These are not portable and should not be used in drivers. Drivers should 90/* These are not portable and should not be used in drivers. Drivers should
91 * be using ioremap() and friends to map physical addreses to virtual 91 * be using ioremap() and friends to map physical addresses to virtual
92 * addresses and dma_map*() and friends to map virtual addresses into DMA 92 * addresses and dma_map*() and friends to map virtual addresses into DMA
93 * addresses and back. 93 * addresses and back.
94 */ 94 */
diff --git a/arch/mips/include/asm/mc146818-time.h b/arch/mips/include/asm/mc146818-time.h
index 199b45733a95..4a08dbe37db8 100644
--- a/arch/mips/include/asm/mc146818-time.h
+++ b/arch/mips/include/asm/mc146818-time.h
@@ -66,7 +66,7 @@ static inline int mc146818_set_rtc_mmss(unsigned long nowtime)
66 CMOS_WRITE(real_seconds, RTC_SECONDS); 66 CMOS_WRITE(real_seconds, RTC_SECONDS);
67 CMOS_WRITE(real_minutes, RTC_MINUTES); 67 CMOS_WRITE(real_minutes, RTC_MINUTES);
68 } else { 68 } else {
69 printk(KERN_WARNING 69 printk_once(KERN_NOTICE
70 "set_rtc_mmss: can't update from %d to %d\n", 70 "set_rtc_mmss: can't update from %d to %d\n",
71 cmos_minutes, real_minutes); 71 cmos_minutes, real_minutes);
72 retval = -1; 72 retval = -1;
diff --git a/arch/mips/jz4740/board-qi_lb60.c b/arch/mips/jz4740/board-qi_lb60.c
index 5c0a3575877c..2c0e107966ad 100644
--- a/arch/mips/jz4740/board-qi_lb60.c
+++ b/arch/mips/jz4740/board-qi_lb60.c
@@ -65,7 +65,7 @@ static struct nand_ecclayout qi_lb60_ecclayout_1gb = {
65 65
66/* Early prototypes of the QI LB60 had only 1GB of NAND. 66/* Early prototypes of the QI LB60 had only 1GB of NAND.
67 * In order to support these devices aswell the partition and ecc layout is 67 * In order to support these devices aswell the partition and ecc layout is
68 * initalized depending on the NAND size */ 68 * initialized depending on the NAND size */
69static struct mtd_partition qi_lb60_partitions_1gb[] = { 69static struct mtd_partition qi_lb60_partitions_1gb[] = {
70 { 70 {
71 .name = "NAND BOOT partition", 71 .name = "NAND BOOT partition",
@@ -464,7 +464,7 @@ static int __init qi_lb60_board_setup(void)
464 board_gpio_setup(); 464 board_gpio_setup();
465 465
466 if (qi_lb60_init_platform_devices()) 466 if (qi_lb60_init_platform_devices())
467 panic("Failed to initalize platform devices\n"); 467 panic("Failed to initialize platform devices\n");
468 468
469 return 0; 469 return 0;
470} 470}
diff --git a/arch/mips/jz4740/gpio.c b/arch/mips/jz4740/gpio.c
index 38f60f35156c..88e6aeda5bf1 100644
--- a/arch/mips/jz4740/gpio.c
+++ b/arch/mips/jz4740/gpio.c
@@ -546,7 +546,7 @@ static int __init jz4740_gpio_init(void)
546 for (i = 0; i < ARRAY_SIZE(jz4740_gpio_chips); ++i) 546 for (i = 0; i < ARRAY_SIZE(jz4740_gpio_chips); ++i)
547 jz4740_gpio_chip_init(&jz4740_gpio_chips[i], i); 547 jz4740_gpio_chip_init(&jz4740_gpio_chips[i], i);
548 548
549 printk(KERN_INFO "JZ4740 GPIO initalized\n"); 549 printk(KERN_INFO "JZ4740 GPIO initialized\n");
550 550
551 return 0; 551 return 0;
552} 552}
diff --git a/arch/mips/jz4740/pm.c b/arch/mips/jz4740/pm.c
index a9994585424d..902d5b50124c 100644
--- a/arch/mips/jz4740/pm.c
+++ b/arch/mips/jz4740/pm.c
@@ -42,7 +42,7 @@ static int jz4740_pm_enter(suspend_state_t state)
42 return 0; 42 return 0;
43} 43}
44 44
45static struct platform_suspend_ops jz4740_pm_ops = { 45static const struct platform_suspend_ops jz4740_pm_ops = {
46 .valid = suspend_valid_only_mem, 46 .valid = suspend_valid_only_mem,
47 .enter = jz4740_pm_enter, 47 .enter = jz4740_pm_enter,
48}; 48};
diff --git a/arch/mips/loongson/common/pm.c b/arch/mips/loongson/common/pm.c
index 6c1fd9001712..f55e07aee071 100644
--- a/arch/mips/loongson/common/pm.c
+++ b/arch/mips/loongson/common/pm.c
@@ -147,7 +147,7 @@ static int loongson_pm_valid_state(suspend_state_t state)
147 } 147 }
148} 148}
149 149
150static struct platform_suspend_ops loongson_pm_ops = { 150static const struct platform_suspend_ops loongson_pm_ops = {
151 .valid = loongson_pm_valid_state, 151 .valid = loongson_pm_valid_state,
152 .enter = loongson_pm_enter, 152 .enter = loongson_pm_enter,
153}; 153};
diff --git a/arch/mips/mti-malta/malta-memory.c b/arch/mips/mti-malta/malta-memory.c
index b27419c84919..a96d281f9221 100644
--- a/arch/mips/mti-malta/malta-memory.c
+++ b/arch/mips/mti-malta/malta-memory.c
@@ -43,7 +43,7 @@ static struct prom_pmemblock mdesc[PROM_MAX_PMEMBLOCKS];
43static char *mtypes[3] = { 43static char *mtypes[3] = {
44 "Dont use memory", 44 "Dont use memory",
45 "YAMON PROM memory", 45 "YAMON PROM memory",
46 "Free memmory", 46 "Free memory",
47}; 47};
48#endif 48#endif
49 49
diff --git a/arch/mips/pci/pcie-octeon.c b/arch/mips/pci/pcie-octeon.c
index 385f035b24e4..0583c463e5f1 100644
--- a/arch/mips/pci/pcie-octeon.c
+++ b/arch/mips/pci/pcie-octeon.c
@@ -900,7 +900,7 @@ static int cvmx_pcie_rc_initialize(int pcie_port)
900 mem_access_subid.s.ror = 0; 900 mem_access_subid.s.ror = 0;
901 /* Disable Relaxed Ordering for Writes. */ 901 /* Disable Relaxed Ordering for Writes. */
902 mem_access_subid.s.row = 0; 902 mem_access_subid.s.row = 0;
903 /* PCIe Adddress Bits <63:34>. */ 903 /* PCIe Address Bits <63:34>. */
904 mem_access_subid.s.ba = 0; 904 mem_access_subid.s.ba = 0;
905 905
906 /* 906 /*
diff --git a/arch/mips/powertv/memory.c b/arch/mips/powertv/memory.c
index 73880ad29bc2..fb3d29660c42 100644
--- a/arch/mips/powertv/memory.c
+++ b/arch/mips/powertv/memory.c
@@ -57,7 +57,7 @@
57unsigned long ptv_memsize; 57unsigned long ptv_memsize;
58 58
59/* 59/*
60 * struct low_mem_reserved - Items in low memmory that are reserved 60 * struct low_mem_reserved - Items in low memory that are reserved
61 * @start: Physical address of item 61 * @start: Physical address of item
62 * @size: Size, in bytes, of this item 62 * @size: Size, in bytes, of this item
63 * @is_aliased: True if this is RAM aliased from another location. If false, 63 * @is_aliased: True if this is RAM aliased from another location. If false,
diff --git a/arch/mips/txx9/generic/pci.c b/arch/mips/txx9/generic/pci.c
index 9a0be810cafa..96e69a00ffc8 100644
--- a/arch/mips/txx9/generic/pci.c
+++ b/arch/mips/txx9/generic/pci.c
@@ -107,7 +107,7 @@ int txx9_pci_mem_high __initdata;
107 107
108/* 108/*
109 * allocate pci_controller and resources. 109 * allocate pci_controller and resources.
110 * mem_base, io_base: physical addresss. 0 for auto assignment. 110 * mem_base, io_base: physical address. 0 for auto assignment.
111 * mem_size and io_size means max size on auto assignment. 111 * mem_size and io_size means max size on auto assignment.
112 * pcic must be &txx9_primary_pcic or NULL. 112 * pcic must be &txx9_primary_pcic or NULL.
113 */ 113 */
diff --git a/arch/mn10300/Kconfig b/arch/mn10300/Kconfig
index 41ba38513c89..8ed41cf2b08d 100644
--- a/arch/mn10300/Kconfig
+++ b/arch/mn10300/Kconfig
@@ -203,6 +203,7 @@ endmenu
203config SMP 203config SMP
204 bool "Symmetric multi-processing support" 204 bool "Symmetric multi-processing support"
205 default y 205 default y
206 select USE_GENERIC_SMP_HELPERS
206 depends on MN10300_PROC_MN2WS0038 || MN10300_PROC_MN2WS0050 207 depends on MN10300_PROC_MN2WS0038 || MN10300_PROC_MN2WS0050
207 ---help--- 208 ---help---
208 This enables support for systems with more than one CPU. If you have 209 This enables support for systems with more than one CPU. If you have
@@ -226,11 +227,6 @@ config NR_CPUS
226 depends on SMP 227 depends on SMP
227 default "2" 228 default "2"
228 229
229config USE_GENERIC_SMP_HELPERS
230 bool
231 depends on SMP
232 default y
233
234source "kernel/Kconfig.preempt" 230source "kernel/Kconfig.preempt"
235 231
236config MN10300_CURRENT_IN_E2 232config MN10300_CURRENT_IN_E2
diff --git a/arch/mn10300/kernel/rtc.c b/arch/mn10300/kernel/rtc.c
index e9e20f9a4dd3..48d7058b3295 100644
--- a/arch/mn10300/kernel/rtc.c
+++ b/arch/mn10300/kernel/rtc.c
@@ -89,7 +89,7 @@ static int set_rtc_mmss(unsigned long nowtime)
89 CMOS_WRITE(real_seconds, RTC_SECONDS); 89 CMOS_WRITE(real_seconds, RTC_SECONDS);
90 CMOS_WRITE(real_minutes, RTC_MINUTES); 90 CMOS_WRITE(real_minutes, RTC_MINUTES);
91 } else { 91 } else {
92 printk(KERN_WARNING 92 printk_once(KERN_NOTICE
93 "set_rtc_mmss: can't update from %d to %d\n", 93 "set_rtc_mmss: can't update from %d to %d\n",
94 cmos_minutes, real_minutes); 94 cmos_minutes, real_minutes);
95 retval = -1; 95 retval = -1;
diff --git a/arch/powerpc/include/asm/8xx_immap.h b/arch/powerpc/include/asm/8xx_immap.h
index 4b0e15206006..6b6dc20b0beb 100644
--- a/arch/powerpc/include/asm/8xx_immap.h
+++ b/arch/powerpc/include/asm/8xx_immap.h
@@ -93,7 +93,7 @@ typedef struct mem_ctlr {
93} memctl8xx_t; 93} memctl8xx_t;
94 94
95/*----------------------------------------------------------------------- 95/*-----------------------------------------------------------------------
96 * BR - Memory Controler: Base Register 16-9 96 * BR - Memory Controller: Base Register 16-9
97 */ 97 */
98#define BR_BA_MSK 0xffff8000 /* Base Address Mask */ 98#define BR_BA_MSK 0xffff8000 /* Base Address Mask */
99#define BR_AT_MSK 0x00007000 /* Address Type Mask */ 99#define BR_AT_MSK 0x00007000 /* Address Type Mask */
@@ -110,7 +110,7 @@ typedef struct mem_ctlr {
110#define BR_V 0x00000001 /* Bank Valid */ 110#define BR_V 0x00000001 /* Bank Valid */
111 111
112/*----------------------------------------------------------------------- 112/*-----------------------------------------------------------------------
113 * OR - Memory Controler: Option Register 16-11 113 * OR - Memory Controller: Option Register 16-11
114 */ 114 */
115#define OR_AM_MSK 0xffff8000 /* Address Mask Mask */ 115#define OR_AM_MSK 0xffff8000 /* Address Mask Mask */
116#define OR_ATM_MSK 0x00007000 /* Address Type Mask Mask */ 116#define OR_ATM_MSK 0x00007000 /* Address Type Mask Mask */
diff --git a/arch/powerpc/kvm/book3s.c b/arch/powerpc/kvm/book3s.c
index e316847c08c0..badc983031b3 100644
--- a/arch/powerpc/kvm/book3s.c
+++ b/arch/powerpc/kvm/book3s.c
@@ -1307,12 +1307,10 @@ struct kvm_vcpu *kvmppc_core_vcpu_create(struct kvm *kvm, unsigned int id)
1307 int err = -ENOMEM; 1307 int err = -ENOMEM;
1308 unsigned long p; 1308 unsigned long p;
1309 1309
1310 vcpu_book3s = vmalloc(sizeof(struct kvmppc_vcpu_book3s)); 1310 vcpu_book3s = vzalloc(sizeof(struct kvmppc_vcpu_book3s));
1311 if (!vcpu_book3s) 1311 if (!vcpu_book3s)
1312 goto out; 1312 goto out;
1313 1313
1314 memset(vcpu_book3s, 0, sizeof(struct kvmppc_vcpu_book3s));
1315
1316 vcpu_book3s->shadow_vcpu = (struct kvmppc_book3s_shadow_vcpu *) 1314 vcpu_book3s->shadow_vcpu = (struct kvmppc_book3s_shadow_vcpu *)
1317 kzalloc(sizeof(*vcpu_book3s->shadow_vcpu), GFP_KERNEL); 1315 kzalloc(sizeof(*vcpu_book3s->shadow_vcpu), GFP_KERNEL);
1318 if (!vcpu_book3s->shadow_vcpu) 1316 if (!vcpu_book3s->shadow_vcpu)
diff --git a/arch/powerpc/kvm/powerpc.c b/arch/powerpc/kvm/powerpc.c
index 38f756f25053..99758460efde 100644
--- a/arch/powerpc/kvm/powerpc.c
+++ b/arch/powerpc/kvm/powerpc.c
@@ -145,18 +145,12 @@ void kvm_arch_check_processor_compat(void *rtn)
145 *(int *)rtn = kvmppc_core_check_processor_compat(); 145 *(int *)rtn = kvmppc_core_check_processor_compat();
146} 146}
147 147
148struct kvm *kvm_arch_create_vm(void) 148int kvm_arch_init_vm(struct kvm *kvm)
149{ 149{
150 struct kvm *kvm; 150 return 0;
151
152 kvm = kzalloc(sizeof(struct kvm), GFP_KERNEL);
153 if (!kvm)
154 return ERR_PTR(-ENOMEM);
155
156 return kvm;
157} 151}
158 152
159static void kvmppc_free_vcpus(struct kvm *kvm) 153void kvm_arch_destroy_vm(struct kvm *kvm)
160{ 154{
161 unsigned int i; 155 unsigned int i;
162 struct kvm_vcpu *vcpu; 156 struct kvm_vcpu *vcpu;
@@ -176,14 +170,6 @@ void kvm_arch_sync_events(struct kvm *kvm)
176{ 170{
177} 171}
178 172
179void kvm_arch_destroy_vm(struct kvm *kvm)
180{
181 kvmppc_free_vcpus(kvm);
182 kvm_free_physmem(kvm);
183 cleanup_srcu_struct(&kvm->srcu);
184 kfree(kvm);
185}
186
187int kvm_dev_ioctl_check_extension(long ext) 173int kvm_dev_ioctl_check_extension(long ext)
188{ 174{
189 int r; 175 int r;
diff --git a/arch/powerpc/oprofile/op_model_cell.c b/arch/powerpc/oprofile/op_model_cell.c
index 7fd90d02d8c6..c4d2b7167568 100644
--- a/arch/powerpc/oprofile/op_model_cell.c
+++ b/arch/powerpc/oprofile/op_model_cell.c
@@ -1469,7 +1469,7 @@ static int cell_global_start(struct op_counter_config *ctr)
1469 * The pm_interval register is setup to write the SPU PC value into the 1469 * The pm_interval register is setup to write the SPU PC value into the
1470 * trace buffer at the maximum rate possible. The trace buffer is configured 1470 * trace buffer at the maximum rate possible. The trace buffer is configured
1471 * to store the PCs, wrapping when it is full. The performance counter is 1471 * to store the PCs, wrapping when it is full. The performance counter is
1472 * intialized to the max hardware count minus the number of events, N, between 1472 * initialized to the max hardware count minus the number of events, N, between
1473 * samples. Once the N events have occured, a HW counter overflow occurs 1473 * samples. Once the N events have occured, a HW counter overflow occurs
1474 * causing the generation of a HW counter interrupt which also stops the 1474 * causing the generation of a HW counter interrupt which also stops the
1475 * writing of the SPU PC values to the trace buffer. Hence the last PC 1475 * writing of the SPU PC values to the trace buffer. Hence the last PC
diff --git a/arch/powerpc/platforms/52xx/lite5200_pm.c b/arch/powerpc/platforms/52xx/lite5200_pm.c
index 80234e5921f5..eda0fc2a3914 100644
--- a/arch/powerpc/platforms/52xx/lite5200_pm.c
+++ b/arch/powerpc/platforms/52xx/lite5200_pm.c
@@ -232,7 +232,7 @@ static void lite5200_pm_end(void)
232 lite5200_pm_target_state = PM_SUSPEND_ON; 232 lite5200_pm_target_state = PM_SUSPEND_ON;
233} 233}
234 234
235static struct platform_suspend_ops lite5200_pm_ops = { 235static const struct platform_suspend_ops lite5200_pm_ops = {
236 .valid = lite5200_pm_valid, 236 .valid = lite5200_pm_valid,
237 .begin = lite5200_pm_begin, 237 .begin = lite5200_pm_begin,
238 .prepare = lite5200_pm_prepare, 238 .prepare = lite5200_pm_prepare,
diff --git a/arch/powerpc/platforms/52xx/mpc52xx_pm.c b/arch/powerpc/platforms/52xx/mpc52xx_pm.c
index 568cef636275..8310e8b5b57f 100644
--- a/arch/powerpc/platforms/52xx/mpc52xx_pm.c
+++ b/arch/powerpc/platforms/52xx/mpc52xx_pm.c
@@ -186,7 +186,7 @@ void mpc52xx_pm_finish(void)
186 iounmap(mbar); 186 iounmap(mbar);
187} 187}
188 188
189static struct platform_suspend_ops mpc52xx_pm_ops = { 189static const struct platform_suspend_ops mpc52xx_pm_ops = {
190 .valid = mpc52xx_pm_valid, 190 .valid = mpc52xx_pm_valid,
191 .prepare = mpc52xx_pm_prepare, 191 .prepare = mpc52xx_pm_prepare,
192 .enter = mpc52xx_pm_enter, 192 .enter = mpc52xx_pm_enter,
diff --git a/arch/powerpc/platforms/83xx/suspend-asm.S b/arch/powerpc/platforms/83xx/suspend-asm.S
index 1930543c98d3..3d1ecd211776 100644
--- a/arch/powerpc/platforms/83xx/suspend-asm.S
+++ b/arch/powerpc/platforms/83xx/suspend-asm.S
@@ -231,7 +231,7 @@ _GLOBAL(mpc83xx_enter_deep_sleep)
231 ori r4, r4, 0x002a 231 ori r4, r4, 0x002a
232 mtspr SPRN_DBAT0L, r4 232 mtspr SPRN_DBAT0L, r4
233 lis r8, TMP_VIRT_IMMR@h 233 lis r8, TMP_VIRT_IMMR@h
234 ori r4, r8, 0x001e /* 1 MByte accessable from Kernel Space only */ 234 ori r4, r8, 0x001e /* 1 MByte accessible from Kernel Space only */
235 mtspr SPRN_DBAT0U, r4 235 mtspr SPRN_DBAT0U, r4
236 isync 236 isync
237 237
@@ -241,7 +241,7 @@ _GLOBAL(mpc83xx_enter_deep_sleep)
241 ori r4, r4, 0x002a 241 ori r4, r4, 0x002a
242 mtspr SPRN_DBAT1L, r4 242 mtspr SPRN_DBAT1L, r4
243 lis r9, (TMP_VIRT_IMMR + 0x01000000)@h 243 lis r9, (TMP_VIRT_IMMR + 0x01000000)@h
244 ori r4, r9, 0x001e /* 1 MByte accessable from Kernel Space only */ 244 ori r4, r9, 0x001e /* 1 MByte accessible from Kernel Space only */
245 mtspr SPRN_DBAT1U, r4 245 mtspr SPRN_DBAT1U, r4
246 isync 246 isync
247 247
@@ -253,7 +253,7 @@ _GLOBAL(mpc83xx_enter_deep_sleep)
253 li r4, 0x0002 253 li r4, 0x0002
254 mtspr SPRN_DBAT2L, r4 254 mtspr SPRN_DBAT2L, r4
255 lis r4, KERNELBASE@h 255 lis r4, KERNELBASE@h
256 ori r4, r4, 0x001e /* 1 MByte accessable from Kernel Space only */ 256 ori r4, r4, 0x001e /* 1 MByte accessible from Kernel Space only */
257 mtspr SPRN_DBAT2U, r4 257 mtspr SPRN_DBAT2U, r4
258 isync 258 isync
259 259
diff --git a/arch/powerpc/platforms/83xx/suspend.c b/arch/powerpc/platforms/83xx/suspend.c
index 75ae77f1af6a..fd4f2f2f19e6 100644
--- a/arch/powerpc/platforms/83xx/suspend.c
+++ b/arch/powerpc/platforms/83xx/suspend.c
@@ -311,7 +311,7 @@ static int mpc83xx_is_pci_agent(void)
311 return ret; 311 return ret;
312} 312}
313 313
314static struct platform_suspend_ops mpc83xx_suspend_ops = { 314static const struct platform_suspend_ops mpc83xx_suspend_ops = {
315 .valid = mpc83xx_suspend_valid, 315 .valid = mpc83xx_suspend_valid,
316 .begin = mpc83xx_suspend_begin, 316 .begin = mpc83xx_suspend_begin,
317 .enter = mpc83xx_suspend_enter, 317 .enter = mpc83xx_suspend_enter,
diff --git a/arch/powerpc/platforms/85xx/mpc85xx_mds.c b/arch/powerpc/platforms/85xx/mpc85xx_mds.c
index aa34cac4eb5c..747d1ee661fd 100644
--- a/arch/powerpc/platforms/85xx/mpc85xx_mds.c
+++ b/arch/powerpc/platforms/85xx/mpc85xx_mds.c
@@ -309,7 +309,7 @@ static void __init mpc85xx_mds_qe_init(void)
309 /* P1021 has pins muxed for QE and other functions. To 309 /* P1021 has pins muxed for QE and other functions. To
310 * enable QE UEC mode, we need to set bit QE0 for UCC1 310 * enable QE UEC mode, we need to set bit QE0 for UCC1
311 * in Eth mode, QE0 and QE3 for UCC5 in Eth mode, QE9 311 * in Eth mode, QE0 and QE3 for UCC5 in Eth mode, QE9
312 * and QE12 for QE MII management singals in PMUXCR 312 * and QE12 for QE MII management signals in PMUXCR
313 * register. 313 * register.
314 */ 314 */
315 setbits32(pmuxcr, MPC85xx_PMUXCR_QE0 | 315 setbits32(pmuxcr, MPC85xx_PMUXCR_QE0 |
diff --git a/arch/powerpc/platforms/ps3/device-init.c b/arch/powerpc/platforms/ps3/device-init.c
index b341018326df..6c4b5837fc8a 100644
--- a/arch/powerpc/platforms/ps3/device-init.c
+++ b/arch/powerpc/platforms/ps3/device-init.c
@@ -566,10 +566,10 @@ static int ps3_setup_dynamic_device(const struct ps3_repository_device *repo)
566 case PS3_DEV_TYPE_STOR_DISK: 566 case PS3_DEV_TYPE_STOR_DISK:
567 result = ps3_setup_storage_dev(repo, PS3_MATCH_ID_STOR_DISK); 567 result = ps3_setup_storage_dev(repo, PS3_MATCH_ID_STOR_DISK);
568 568
569 /* Some devices are not accessable from the Other OS lpar. */ 569 /* Some devices are not accessible from the Other OS lpar. */
570 if (result == -ENODEV) { 570 if (result == -ENODEV) {
571 result = 0; 571 result = 0;
572 pr_debug("%s:%u: not accessable\n", __func__, 572 pr_debug("%s:%u: not accessible\n", __func__,
573 __LINE__); 573 __LINE__);
574 } 574 }
575 575
diff --git a/arch/powerpc/platforms/ps3/interrupt.c b/arch/powerpc/platforms/ps3/interrupt.c
index 59d9712d7364..92290ff4761a 100644
--- a/arch/powerpc/platforms/ps3/interrupt.c
+++ b/arch/powerpc/platforms/ps3/interrupt.c
@@ -44,7 +44,7 @@
44 * @lock: 44 * @lock:
45 * @ipi_debug_brk_mask: 45 * @ipi_debug_brk_mask:
46 * 46 *
47 * The HV mantains per SMT thread mappings of HV outlet to HV plug on 47 * The HV maintains per SMT thread mappings of HV outlet to HV plug on
48 * behalf of the guest. These mappings are implemented as 256 bit guest 48 * behalf of the guest. These mappings are implemented as 256 bit guest
49 * supplied bitmaps indexed by plug number. The addresses of the bitmaps 49 * supplied bitmaps indexed by plug number. The addresses of the bitmaps
50 * are registered with the HV through lv1_configure_irq_state_bitmap(). 50 * are registered with the HV through lv1_configure_irq_state_bitmap().
diff --git a/arch/powerpc/platforms/pseries/hvCall_inst.c b/arch/powerpc/platforms/pseries/hvCall_inst.c
index e19ff021e711..f106662f4381 100644
--- a/arch/powerpc/platforms/pseries/hvCall_inst.c
+++ b/arch/powerpc/platforms/pseries/hvCall_inst.c
@@ -55,7 +55,7 @@ static void hc_stop(struct seq_file *m, void *p)
55static int hc_show(struct seq_file *m, void *p) 55static int hc_show(struct seq_file *m, void *p)
56{ 56{
57 unsigned long h_num = (unsigned long)p; 57 unsigned long h_num = (unsigned long)p;
58 struct hcall_stats *hs = (struct hcall_stats *)m->private; 58 struct hcall_stats *hs = m->private;
59 59
60 if (hs[h_num].num_calls) { 60 if (hs[h_num].num_calls) {
61 if (cpu_has_feature(CPU_FTR_PURR)) 61 if (cpu_has_feature(CPU_FTR_PURR))
diff --git a/arch/powerpc/platforms/pseries/suspend.c b/arch/powerpc/platforms/pseries/suspend.c
index ed72098bb4e3..a8ca289ff267 100644
--- a/arch/powerpc/platforms/pseries/suspend.c
+++ b/arch/powerpc/platforms/pseries/suspend.c
@@ -153,7 +153,7 @@ static struct sysdev_class suspend_sysdev_class = {
153 .name = "power", 153 .name = "power",
154}; 154};
155 155
156static struct platform_suspend_ops pseries_suspend_ops = { 156static const struct platform_suspend_ops pseries_suspend_ops = {
157 .valid = suspend_valid_only_mem, 157 .valid = suspend_valid_only_mem,
158 .begin = pseries_suspend_begin, 158 .begin = pseries_suspend_begin,
159 .prepare_late = pseries_prepare_late, 159 .prepare_late = pseries_prepare_late,
diff --git a/arch/powerpc/sysdev/fsl_pmc.c b/arch/powerpc/sysdev/fsl_pmc.c
index 44de8559c975..e9381bfefb21 100644
--- a/arch/powerpc/sysdev/fsl_pmc.c
+++ b/arch/powerpc/sysdev/fsl_pmc.c
@@ -53,7 +53,7 @@ static int pmc_suspend_valid(suspend_state_t state)
53 return 1; 53 return 1;
54} 54}
55 55
56static struct platform_suspend_ops pmc_suspend_ops = { 56static const struct platform_suspend_ops pmc_suspend_ops = {
57 .valid = pmc_suspend_valid, 57 .valid = pmc_suspend_valid,
58 .enter = pmc_suspend_enter, 58 .enter = pmc_suspend_enter,
59}; 59};
diff --git a/arch/powerpc/sysdev/fsl_rio.c b/arch/powerpc/sysdev/fsl_rio.c
index 9725369d432a..9f99bef2adec 100644
--- a/arch/powerpc/sysdev/fsl_rio.c
+++ b/arch/powerpc/sysdev/fsl_rio.c
@@ -973,7 +973,6 @@ fsl_rio_dbell_handler(int irq, void *dev_instance)
973 if (dsr & DOORBELL_DSR_QFI) { 973 if (dsr & DOORBELL_DSR_QFI) {
974 pr_info("RIO: doorbell queue full\n"); 974 pr_info("RIO: doorbell queue full\n");
975 out_be32(&priv->msg_regs->dsr, DOORBELL_DSR_QFI); 975 out_be32(&priv->msg_regs->dsr, DOORBELL_DSR_QFI);
976 goto out;
977 } 976 }
978 977
979 /* XXX Need to check/dispatch until queue empty */ 978 /* XXX Need to check/dispatch until queue empty */
diff --git a/arch/s390/kvm/kvm-s390.c b/arch/s390/kvm/kvm-s390.c
index 985d825494f1..bade533ba288 100644
--- a/arch/s390/kvm/kvm-s390.c
+++ b/arch/s390/kvm/kvm-s390.c
@@ -164,24 +164,18 @@ long kvm_arch_vm_ioctl(struct file *filp,
164 return r; 164 return r;
165} 165}
166 166
167struct kvm *kvm_arch_create_vm(void) 167int kvm_arch_init_vm(struct kvm *kvm)
168{ 168{
169 struct kvm *kvm;
170 int rc; 169 int rc;
171 char debug_name[16]; 170 char debug_name[16];
172 171
173 rc = s390_enable_sie(); 172 rc = s390_enable_sie();
174 if (rc) 173 if (rc)
175 goto out_nokvm; 174 goto out_err;
176
177 rc = -ENOMEM;
178 kvm = kzalloc(sizeof(struct kvm), GFP_KERNEL);
179 if (!kvm)
180 goto out_nokvm;
181 175
182 kvm->arch.sca = (struct sca_block *) get_zeroed_page(GFP_KERNEL); 176 kvm->arch.sca = (struct sca_block *) get_zeroed_page(GFP_KERNEL);
183 if (!kvm->arch.sca) 177 if (!kvm->arch.sca)
184 goto out_nosca; 178 goto out_err;
185 179
186 sprintf(debug_name, "kvm-%u", current->pid); 180 sprintf(debug_name, "kvm-%u", current->pid);
187 181
@@ -195,13 +189,11 @@ struct kvm *kvm_arch_create_vm(void)
195 debug_register_view(kvm->arch.dbf, &debug_sprintf_view); 189 debug_register_view(kvm->arch.dbf, &debug_sprintf_view);
196 VM_EVENT(kvm, 3, "%s", "vm created"); 190 VM_EVENT(kvm, 3, "%s", "vm created");
197 191
198 return kvm; 192 return 0;
199out_nodbf: 193out_nodbf:
200 free_page((unsigned long)(kvm->arch.sca)); 194 free_page((unsigned long)(kvm->arch.sca));
201out_nosca: 195out_err:
202 kfree(kvm); 196 return rc;
203out_nokvm:
204 return ERR_PTR(rc);
205} 197}
206 198
207void kvm_arch_vcpu_destroy(struct kvm_vcpu *vcpu) 199void kvm_arch_vcpu_destroy(struct kvm_vcpu *vcpu)
@@ -240,11 +232,8 @@ void kvm_arch_sync_events(struct kvm *kvm)
240void kvm_arch_destroy_vm(struct kvm *kvm) 232void kvm_arch_destroy_vm(struct kvm *kvm)
241{ 233{
242 kvm_free_vcpus(kvm); 234 kvm_free_vcpus(kvm);
243 kvm_free_physmem(kvm);
244 free_page((unsigned long)(kvm->arch.sca)); 235 free_page((unsigned long)(kvm->arch.sca));
245 debug_unregister(kvm->arch.dbf); 236 debug_unregister(kvm->arch.dbf);
246 cleanup_srcu_struct(&kvm->srcu);
247 kfree(kvm);
248} 237}
249 238
250/* Section: vcpu related */ 239/* Section: vcpu related */
diff --git a/arch/sh/boards/mach-hp6xx/pm.c b/arch/sh/boards/mach-hp6xx/pm.c
index 4499a3749d40..adc9b4bba828 100644
--- a/arch/sh/boards/mach-hp6xx/pm.c
+++ b/arch/sh/boards/mach-hp6xx/pm.c
@@ -143,7 +143,7 @@ static int hp6x0_pm_enter(suspend_state_t state)
143 return 0; 143 return 0;
144} 144}
145 145
146static struct platform_suspend_ops hp6x0_pm_ops = { 146static const struct platform_suspend_ops hp6x0_pm_ops = {
147 .enter = hp6x0_pm_enter, 147 .enter = hp6x0_pm_enter,
148 .valid = suspend_valid_only_mem, 148 .valid = suspend_valid_only_mem,
149}; 149};
diff --git a/arch/sh/boards/mach-se/7724/setup.c b/arch/sh/boards/mach-se/7724/setup.c
index 6dc7407f2cd0..527679394a25 100644
--- a/arch/sh/boards/mach-se/7724/setup.c
+++ b/arch/sh/boards/mach-se/7724/setup.c
@@ -319,6 +319,10 @@ static struct platform_device fsi_device = {
319 }, 319 },
320}; 320};
321 321
322static struct platform_device fsi_ak4642_device = {
323 .name = "sh_fsi_a_ak4642",
324};
325
322/* KEYSC in SoC (Needs SW33-2 set to ON) */ 326/* KEYSC in SoC (Needs SW33-2 set to ON) */
323static struct sh_keysc_info keysc_info = { 327static struct sh_keysc_info keysc_info = {
324 .mode = SH_KEYSC_MODE_1, 328 .mode = SH_KEYSC_MODE_1,
@@ -593,6 +597,7 @@ static struct platform_device *ms7724se_devices[] __initdata = {
593 &sh7724_usb0_host_device, 597 &sh7724_usb0_host_device,
594 &sh7724_usb1_gadget_device, 598 &sh7724_usb1_gadget_device,
595 &fsi_device, 599 &fsi_device,
600 &fsi_ak4642_device,
596 &sdhi0_cn7_device, 601 &sdhi0_cn7_device,
597 &sdhi1_cn8_device, 602 &sdhi1_cn8_device,
598 &irda_device, 603 &irda_device,
diff --git a/arch/sh/boards/mach-sh03/rtc.c b/arch/sh/boards/mach-sh03/rtc.c
index 1b200990500c..f83ac7995d0f 100644
--- a/arch/sh/boards/mach-sh03/rtc.c
+++ b/arch/sh/boards/mach-sh03/rtc.c
@@ -108,7 +108,7 @@ static int set_rtc_mmss(unsigned long nowtime)
108 __raw_writeb(real_minutes % 10, RTC_MIN1); 108 __raw_writeb(real_minutes % 10, RTC_MIN1);
109 __raw_writeb(real_minutes / 10, RTC_MIN10); 109 __raw_writeb(real_minutes / 10, RTC_MIN10);
110 } else { 110 } else {
111 printk(KERN_WARNING 111 printk_once(KERN_NOTICE
112 "set_rtc_mmss: can't update from %d to %d\n", 112 "set_rtc_mmss: can't update from %d to %d\n",
113 cmos_minutes, real_minutes); 113 cmos_minutes, real_minutes);
114 retval = -1; 114 retval = -1;
diff --git a/arch/sh/kernel/cpu/shmobile/pm.c b/arch/sh/kernel/cpu/shmobile/pm.c
index e55968712706..a6f95ae4aae7 100644
--- a/arch/sh/kernel/cpu/shmobile/pm.c
+++ b/arch/sh/kernel/cpu/shmobile/pm.c
@@ -141,7 +141,7 @@ static int sh_pm_enter(suspend_state_t state)
141 return 0; 141 return 0;
142} 142}
143 143
144static struct platform_suspend_ops sh_pm_ops = { 144static const struct platform_suspend_ops sh_pm_ops = {
145 .enter = sh_pm_enter, 145 .enter = sh_pm_enter,
146 .valid = suspend_valid_only_mem, 146 .valid = suspend_valid_only_mem,
147}; 147};
diff --git a/arch/sh/mm/cache-sh5.c b/arch/sh/mm/cache-sh5.c
index eb4cc4ec7952..d1bffbcd9d52 100644
--- a/arch/sh/mm/cache-sh5.c
+++ b/arch/sh/mm/cache-sh5.c
@@ -568,7 +568,7 @@ static void sh5_flush_dcache_page(void *page)
568} 568}
569 569
570/* 570/*
571 * Flush the range [start,end] of kernel virtual adddress space from 571 * Flush the range [start,end] of kernel virtual address space from
572 * the I-cache. The corresponding range must be purged from the 572 * the I-cache. The corresponding range must be purged from the
573 * D-cache also because the SH-5 doesn't have cache snooping between 573 * D-cache also because the SH-5 doesn't have cache snooping between
574 * the caches. The addresses will be visible through the superpage 574 * the caches. The addresses will be visible through the superpage
diff --git a/arch/sparc/kernel/traps_64.c b/arch/sparc/kernel/traps_64.c
index 42ad2ba85010..1e9770936c3b 100644
--- a/arch/sparc/kernel/traps_64.c
+++ b/arch/sparc/kernel/traps_64.c
@@ -622,7 +622,7 @@ static const char CHAFSR_PERR_msg[] =
622static const char CHAFSR_IERR_msg[] = 622static const char CHAFSR_IERR_msg[] =
623 "Internal processor error"; 623 "Internal processor error";
624static const char CHAFSR_ISAP_msg[] = 624static const char CHAFSR_ISAP_msg[] =
625 "System request parity error on incoming addresss"; 625 "System request parity error on incoming address";
626static const char CHAFSR_UCU_msg[] = 626static const char CHAFSR_UCU_msg[] =
627 "Uncorrectable E-cache ECC error for ifetch/data"; 627 "Uncorrectable E-cache ECC error for ifetch/data";
628static const char CHAFSR_UCC_msg[] = 628static const char CHAFSR_UCC_msg[] =
diff --git a/arch/um/Kconfig.um b/arch/um/Kconfig.um
index 50d6aa20c353..f8d1d0d47fe6 100644
--- a/arch/um/Kconfig.um
+++ b/arch/um/Kconfig.um
@@ -131,7 +131,7 @@ config NR_CPUS
131 131
132config HIGHMEM 132config HIGHMEM
133 bool "Highmem support (EXPERIMENTAL)" 133 bool "Highmem support (EXPERIMENTAL)"
134 depends on !64BIT && EXPERIMENTAL 134 depends on !64BIT && BROKEN
135 default n 135 default n
136 help 136 help
137 This was used to allow UML to run with big amounts of memory. 137 This was used to allow UML to run with big amounts of memory.
diff --git a/arch/um/drivers/line.c b/arch/um/drivers/line.c
index 1664cce7b0ac..050e4ddbbb65 100644
--- a/arch/um/drivers/line.c
+++ b/arch/um/drivers/line.c
@@ -821,12 +821,12 @@ void register_winch_irq(int fd, int tty_fd, int pid, struct tty_struct *tty,
821 821
822static void unregister_winch(struct tty_struct *tty) 822static void unregister_winch(struct tty_struct *tty)
823{ 823{
824 struct list_head *ele; 824 struct list_head *ele, *next;
825 struct winch *winch; 825 struct winch *winch;
826 826
827 spin_lock(&winch_handler_lock); 827 spin_lock(&winch_handler_lock);
828 828
829 list_for_each(ele, &winch_handlers) { 829 list_for_each_safe(ele, next, &winch_handlers) {
830 winch = list_entry(ele, struct winch, list); 830 winch = list_entry(ele, struct winch, list);
831 if (winch->tty == tty) { 831 if (winch->tty == tty) {
832 free_winch(winch, 1); 832 free_winch(winch, 1);
diff --git a/arch/um/drivers/mmapper_kern.c b/arch/um/drivers/mmapper_kern.c
index 8501e7d0015c..7e0619c2c2c6 100644
--- a/arch/um/drivers/mmapper_kern.c
+++ b/arch/um/drivers/mmapper_kern.c
@@ -37,13 +37,7 @@ static ssize_t mmapper_write(struct file *file, const char __user *buf,
37 if (*ppos > mmapper_size) 37 if (*ppos > mmapper_size)
38 return -EINVAL; 38 return -EINVAL;
39 39
40 if (count > mmapper_size - *ppos) 40 return simple_write_to_buffer(v_buf, mmapper_size, ppos, buf, count);
41 count = mmapper_size - *ppos;
42
43 if (copy_from_user(&v_buf[*ppos], buf, count))
44 return -EFAULT;
45
46 return count;
47} 41}
48 42
49static long mmapper_ioctl(struct file *file, unsigned int cmd, unsigned long arg) 43static long mmapper_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
@@ -137,3 +131,4 @@ module_exit(mmapper_exit);
137 131
138MODULE_AUTHOR("Greg Lonnon <glonnon@ridgerun.com>"); 132MODULE_AUTHOR("Greg Lonnon <glonnon@ridgerun.com>");
139MODULE_DESCRIPTION("DSPLinux simulator mmapper driver"); 133MODULE_DESCRIPTION("DSPLinux simulator mmapper driver");
134MODULE_LICENSE("GPL");
diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
index b6fccb07123e..36ed2e2c896b 100644
--- a/arch/x86/Kconfig
+++ b/arch/x86/Kconfig
@@ -51,6 +51,7 @@ config X86
51 select HAVE_KERNEL_GZIP 51 select HAVE_KERNEL_GZIP
52 select HAVE_KERNEL_BZIP2 52 select HAVE_KERNEL_BZIP2
53 select HAVE_KERNEL_LZMA 53 select HAVE_KERNEL_LZMA
54 select HAVE_KERNEL_XZ
54 select HAVE_KERNEL_LZO 55 select HAVE_KERNEL_LZO
55 select HAVE_HW_BREAKPOINT 56 select HAVE_HW_BREAKPOINT
56 select HAVE_MIXED_BREAKPOINTS_REGS 57 select HAVE_MIXED_BREAKPOINTS_REGS
@@ -65,6 +66,7 @@ config X86
65 select HAVE_SPARSE_IRQ 66 select HAVE_SPARSE_IRQ
66 select GENERIC_IRQ_PROBE 67 select GENERIC_IRQ_PROBE
67 select GENERIC_PENDING_IRQ if SMP 68 select GENERIC_PENDING_IRQ if SMP
69 select USE_GENERIC_SMP_HELPERS if SMP
68 70
69config INSTRUCTION_DECODER 71config INSTRUCTION_DECODER
70 def_bool (KPROBES || PERF_EVENTS) 72 def_bool (KPROBES || PERF_EVENTS)
@@ -203,10 +205,6 @@ config HAVE_INTEL_TXT
203 def_bool y 205 def_bool y
204 depends on EXPERIMENTAL && DMAR && ACPI 206 depends on EXPERIMENTAL && DMAR && ACPI
205 207
206config USE_GENERIC_SMP_HELPERS
207 def_bool y
208 depends on SMP
209
210config X86_32_SMP 208config X86_32_SMP
211 def_bool y 209 def_bool y
212 depends on X86_32 && SMP 210 depends on X86_32 && SMP
@@ -2078,11 +2076,17 @@ config OLPC_OPENFIRMWARE
2078 bool "Support for OLPC's Open Firmware" 2076 bool "Support for OLPC's Open Firmware"
2079 depends on !X86_64 && !X86_PAE 2077 depends on !X86_64 && !X86_PAE
2080 default n 2078 default n
2079 select OF
2081 help 2080 help
2082 This option adds support for the implementation of Open Firmware 2081 This option adds support for the implementation of Open Firmware
2083 that is used on the OLPC XO-1 Children's Machine. 2082 that is used on the OLPC XO-1 Children's Machine.
2084 If unsure, say N here. 2083 If unsure, say N here.
2085 2084
2085config OLPC_OPENFIRMWARE_DT
2086 bool
2087 default y if OLPC_OPENFIRMWARE && PROC_DEVICETREE
2088 select OF_PROMTREE
2089
2086endif # X86_32 2090endif # X86_32
2087 2091
2088config AMD_NB 2092config AMD_NB
diff --git a/arch/x86/boot/compressed/Makefile b/arch/x86/boot/compressed/Makefile
index 0c229551eead..09664efb9cee 100644
--- a/arch/x86/boot/compressed/Makefile
+++ b/arch/x86/boot/compressed/Makefile
@@ -4,7 +4,7 @@
4# create a compressed vmlinux image from the original vmlinux 4# create a compressed vmlinux image from the original vmlinux
5# 5#
6 6
7targets := vmlinux.lds vmlinux vmlinux.bin vmlinux.bin.gz vmlinux.bin.bz2 vmlinux.bin.lzma vmlinux.bin.lzo head_$(BITS).o misc.o string.o cmdline.o early_serial_console.o piggy.o 7targets := vmlinux.lds vmlinux vmlinux.bin vmlinux.bin.gz vmlinux.bin.bz2 vmlinux.bin.lzma vmlinux.bin.xz vmlinux.bin.lzo head_$(BITS).o misc.o string.o cmdline.o early_serial_console.o piggy.o
8 8
9KBUILD_CFLAGS := -m$(BITS) -D__KERNEL__ $(LINUX_INCLUDE) -O2 9KBUILD_CFLAGS := -m$(BITS) -D__KERNEL__ $(LINUX_INCLUDE) -O2
10KBUILD_CFLAGS += -fno-strict-aliasing -fPIC 10KBUILD_CFLAGS += -fno-strict-aliasing -fPIC
@@ -49,12 +49,15 @@ $(obj)/vmlinux.bin.bz2: $(vmlinux.bin.all-y) FORCE
49 $(call if_changed,bzip2) 49 $(call if_changed,bzip2)
50$(obj)/vmlinux.bin.lzma: $(vmlinux.bin.all-y) FORCE 50$(obj)/vmlinux.bin.lzma: $(vmlinux.bin.all-y) FORCE
51 $(call if_changed,lzma) 51 $(call if_changed,lzma)
52$(obj)/vmlinux.bin.xz: $(vmlinux.bin.all-y) FORCE
53 $(call if_changed,xzkern)
52$(obj)/vmlinux.bin.lzo: $(vmlinux.bin.all-y) FORCE 54$(obj)/vmlinux.bin.lzo: $(vmlinux.bin.all-y) FORCE
53 $(call if_changed,lzo) 55 $(call if_changed,lzo)
54 56
55suffix-$(CONFIG_KERNEL_GZIP) := gz 57suffix-$(CONFIG_KERNEL_GZIP) := gz
56suffix-$(CONFIG_KERNEL_BZIP2) := bz2 58suffix-$(CONFIG_KERNEL_BZIP2) := bz2
57suffix-$(CONFIG_KERNEL_LZMA) := lzma 59suffix-$(CONFIG_KERNEL_LZMA) := lzma
60suffix-$(CONFIG_KERNEL_XZ) := xz
58suffix-$(CONFIG_KERNEL_LZO) := lzo 61suffix-$(CONFIG_KERNEL_LZO) := lzo
59 62
60quiet_cmd_mkpiggy = MKPIGGY $@ 63quiet_cmd_mkpiggy = MKPIGGY $@
diff --git a/arch/x86/boot/compressed/misc.c b/arch/x86/boot/compressed/misc.c
index 325c05294fc4..3a19d04cebeb 100644
--- a/arch/x86/boot/compressed/misc.c
+++ b/arch/x86/boot/compressed/misc.c
@@ -139,6 +139,10 @@ static int lines, cols;
139#include "../../../../lib/decompress_unlzma.c" 139#include "../../../../lib/decompress_unlzma.c"
140#endif 140#endif
141 141
142#ifdef CONFIG_KERNEL_XZ
143#include "../../../../lib/decompress_unxz.c"
144#endif
145
142#ifdef CONFIG_KERNEL_LZO 146#ifdef CONFIG_KERNEL_LZO
143#include "../../../../lib/decompress_unlzo.c" 147#include "../../../../lib/decompress_unlzo.c"
144#endif 148#endif
diff --git a/arch/x86/boot/compressed/mkpiggy.c b/arch/x86/boot/compressed/mkpiggy.c
index 5c228129d175..646aa78ba5fd 100644
--- a/arch/x86/boot/compressed/mkpiggy.c
+++ b/arch/x86/boot/compressed/mkpiggy.c
@@ -74,7 +74,7 @@ int main(int argc, char *argv[])
74 74
75 offs = (olen > ilen) ? olen - ilen : 0; 75 offs = (olen > ilen) ? olen - ilen : 0;
76 offs += olen >> 12; /* Add 8 bytes for each 32K block */ 76 offs += olen >> 12; /* Add 8 bytes for each 32K block */
77 offs += 32*1024 + 18; /* Add 32K + 18 bytes slack */ 77 offs += 64*1024 + 128; /* Add 64K + 128 bytes slack */
78 offs = (offs+4095) & ~4095; /* Round to a 4K boundary */ 78 offs = (offs+4095) & ~4095; /* Round to a 4K boundary */
79 79
80 printf(".section \".rodata..compressed\",\"a\",@progbits\n"); 80 printf(".section \".rodata..compressed\",\"a\",@progbits\n");
diff --git a/arch/x86/crypto/aesni-intel_asm.S b/arch/x86/crypto/aesni-intel_asm.S
index ff16756a51c1..8fe2a4966b7a 100644
--- a/arch/x86/crypto/aesni-intel_asm.S
+++ b/arch/x86/crypto/aesni-intel_asm.S
@@ -9,6 +9,20 @@
9 * Vinodh Gopal <vinodh.gopal@intel.com> 9 * Vinodh Gopal <vinodh.gopal@intel.com>
10 * Kahraman Akdemir 10 * Kahraman Akdemir
11 * 11 *
12 * Added RFC4106 AES-GCM support for 128-bit keys under the AEAD
13 * interface for 64-bit kernels.
14 * Authors: Erdinc Ozturk (erdinc.ozturk@intel.com)
15 * Aidan O'Mahony (aidan.o.mahony@intel.com)
16 * Adrian Hoban <adrian.hoban@intel.com>
17 * James Guilford (james.guilford@intel.com)
18 * Gabriele Paoloni <gabriele.paoloni@intel.com>
19 * Tadeusz Struk (tadeusz.struk@intel.com)
20 * Wajdi Feghali (wajdi.k.feghali@intel.com)
21 * Copyright (c) 2010, Intel Corporation.
22 *
23 * Ported x86_64 version to x86:
24 * Author: Mathias Krause <minipli@googlemail.com>
25 *
12 * This program is free software; you can redistribute it and/or modify 26 * 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 27 * 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 28 * the Free Software Foundation; either version 2 of the License, or
@@ -18,8 +32,62 @@
18#include <linux/linkage.h> 32#include <linux/linkage.h>
19#include <asm/inst.h> 33#include <asm/inst.h>
20 34
35#ifdef __x86_64__
36.data
37POLY: .octa 0xC2000000000000000000000000000001
38TWOONE: .octa 0x00000001000000000000000000000001
39
40# order of these constants should not change.
41# more specifically, ALL_F should follow SHIFT_MASK,
42# and ZERO should follow ALL_F
43
44SHUF_MASK: .octa 0x000102030405060708090A0B0C0D0E0F
45MASK1: .octa 0x0000000000000000ffffffffffffffff
46MASK2: .octa 0xffffffffffffffff0000000000000000
47SHIFT_MASK: .octa 0x0f0e0d0c0b0a09080706050403020100
48ALL_F: .octa 0xffffffffffffffffffffffffffffffff
49ZERO: .octa 0x00000000000000000000000000000000
50ONE: .octa 0x00000000000000000000000000000001
51F_MIN_MASK: .octa 0xf1f2f3f4f5f6f7f8f9fafbfcfdfeff0
52dec: .octa 0x1
53enc: .octa 0x2
54
55
21.text 56.text
22 57
58
59#define STACK_OFFSET 8*3
60#define HashKey 16*0 // store HashKey <<1 mod poly here
61#define HashKey_2 16*1 // store HashKey^2 <<1 mod poly here
62#define HashKey_3 16*2 // store HashKey^3 <<1 mod poly here
63#define HashKey_4 16*3 // store HashKey^4 <<1 mod poly here
64#define HashKey_k 16*4 // store XOR of High 64 bits and Low 64
65 // bits of HashKey <<1 mod poly here
66 //(for Karatsuba purposes)
67#define HashKey_2_k 16*5 // store XOR of High 64 bits and Low 64
68 // bits of HashKey^2 <<1 mod poly here
69 // (for Karatsuba purposes)
70#define HashKey_3_k 16*6 // store XOR of High 64 bits and Low 64
71 // bits of HashKey^3 <<1 mod poly here
72 // (for Karatsuba purposes)
73#define HashKey_4_k 16*7 // store XOR of High 64 bits and Low 64
74 // bits of HashKey^4 <<1 mod poly here
75 // (for Karatsuba purposes)
76#define VARIABLE_OFFSET 16*8
77
78#define arg1 rdi
79#define arg2 rsi
80#define arg3 rdx
81#define arg4 rcx
82#define arg5 r8
83#define arg6 r9
84#define arg7 STACK_OFFSET+8(%r14)
85#define arg8 STACK_OFFSET+16(%r14)
86#define arg9 STACK_OFFSET+24(%r14)
87#define arg10 STACK_OFFSET+32(%r14)
88#endif
89
90
23#define STATE1 %xmm0 91#define STATE1 %xmm0
24#define STATE2 %xmm4 92#define STATE2 %xmm4
25#define STATE3 %xmm5 93#define STATE3 %xmm5
@@ -32,12 +100,16 @@
32#define IN IN1 100#define IN IN1
33#define KEY %xmm2 101#define KEY %xmm2
34#define IV %xmm3 102#define IV %xmm3
103
35#define BSWAP_MASK %xmm10 104#define BSWAP_MASK %xmm10
36#define CTR %xmm11 105#define CTR %xmm11
37#define INC %xmm12 106#define INC %xmm12
38 107
108#ifdef __x86_64__
109#define AREG %rax
39#define KEYP %rdi 110#define KEYP %rdi
40#define OUTP %rsi 111#define OUTP %rsi
112#define UKEYP OUTP
41#define INP %rdx 113#define INP %rdx
42#define LEN %rcx 114#define LEN %rcx
43#define IVP %r8 115#define IVP %r8
@@ -46,6 +118,1588 @@
46#define TKEYP T1 118#define TKEYP T1
47#define T2 %r11 119#define T2 %r11
48#define TCTR_LOW T2 120#define TCTR_LOW T2
121#else
122#define AREG %eax
123#define KEYP %edi
124#define OUTP AREG
125#define UKEYP OUTP
126#define INP %edx
127#define LEN %esi
128#define IVP %ebp
129#define KLEN %ebx
130#define T1 %ecx
131#define TKEYP T1
132#endif
133
134
135#ifdef __x86_64__
136/* GHASH_MUL MACRO to implement: Data*HashKey mod (128,127,126,121,0)
137*
138*
139* Input: A and B (128-bits each, bit-reflected)
140* Output: C = A*B*x mod poly, (i.e. >>1 )
141* To compute GH = GH*HashKey mod poly, give HK = HashKey<<1 mod poly as input
142* GH = GH * HK * x mod poly which is equivalent to GH*HashKey mod poly.
143*
144*/
145.macro GHASH_MUL GH HK TMP1 TMP2 TMP3 TMP4 TMP5
146 movdqa \GH, \TMP1
147 pshufd $78, \GH, \TMP2
148 pshufd $78, \HK, \TMP3
149 pxor \GH, \TMP2 # TMP2 = a1+a0
150 pxor \HK, \TMP3 # TMP3 = b1+b0
151 PCLMULQDQ 0x11, \HK, \TMP1 # TMP1 = a1*b1
152 PCLMULQDQ 0x00, \HK, \GH # GH = a0*b0
153 PCLMULQDQ 0x00, \TMP3, \TMP2 # TMP2 = (a0+a1)*(b1+b0)
154 pxor \GH, \TMP2
155 pxor \TMP1, \TMP2 # TMP2 = (a0*b0)+(a1*b0)
156 movdqa \TMP2, \TMP3
157 pslldq $8, \TMP3 # left shift TMP3 2 DWs
158 psrldq $8, \TMP2 # right shift TMP2 2 DWs
159 pxor \TMP3, \GH
160 pxor \TMP2, \TMP1 # TMP2:GH holds the result of GH*HK
161
162 # first phase of the reduction
163
164 movdqa \GH, \TMP2
165 movdqa \GH, \TMP3
166 movdqa \GH, \TMP4 # copy GH into TMP2,TMP3 and TMP4
167 # in in order to perform
168 # independent shifts
169 pslld $31, \TMP2 # packed right shift <<31
170 pslld $30, \TMP3 # packed right shift <<30
171 pslld $25, \TMP4 # packed right shift <<25
172 pxor \TMP3, \TMP2 # xor the shifted versions
173 pxor \TMP4, \TMP2
174 movdqa \TMP2, \TMP5
175 psrldq $4, \TMP5 # right shift TMP5 1 DW
176 pslldq $12, \TMP2 # left shift TMP2 3 DWs
177 pxor \TMP2, \GH
178
179 # second phase of the reduction
180
181 movdqa \GH,\TMP2 # copy GH into TMP2,TMP3 and TMP4
182 # in in order to perform
183 # independent shifts
184 movdqa \GH,\TMP3
185 movdqa \GH,\TMP4
186 psrld $1,\TMP2 # packed left shift >>1
187 psrld $2,\TMP3 # packed left shift >>2
188 psrld $7,\TMP4 # packed left shift >>7
189 pxor \TMP3,\TMP2 # xor the shifted versions
190 pxor \TMP4,\TMP2
191 pxor \TMP5, \TMP2
192 pxor \TMP2, \GH
193 pxor \TMP1, \GH # result is in TMP1
194.endm
195
196/*
197* if a = number of total plaintext bytes
198* b = floor(a/16)
199* num_initial_blocks = b mod 4
200* encrypt the initial num_initial_blocks blocks and apply ghash on
201* the ciphertext
202* %r10, %r11, %r12, %rax, %xmm5, %xmm6, %xmm7, %xmm8, %xmm9 registers
203* are clobbered
204* arg1, %arg2, %arg3, %r14 are used as a pointer only, not modified
205*/
206
207
208.macro INITIAL_BLOCKS_DEC num_initial_blocks TMP1 TMP2 TMP3 TMP4 TMP5 XMM0 XMM1 \
209XMM2 XMM3 XMM4 XMMDst TMP6 TMP7 i i_seq operation
210 mov arg7, %r10 # %r10 = AAD
211 mov arg8, %r12 # %r12 = aadLen
212 mov %r12, %r11
213 pxor %xmm\i, %xmm\i
214_get_AAD_loop\num_initial_blocks\operation:
215 movd (%r10), \TMP1
216 pslldq $12, \TMP1
217 psrldq $4, %xmm\i
218 pxor \TMP1, %xmm\i
219 add $4, %r10
220 sub $4, %r12
221 jne _get_AAD_loop\num_initial_blocks\operation
222 cmp $16, %r11
223 je _get_AAD_loop2_done\num_initial_blocks\operation
224 mov $16, %r12
225_get_AAD_loop2\num_initial_blocks\operation:
226 psrldq $4, %xmm\i
227 sub $4, %r12
228 cmp %r11, %r12
229 jne _get_AAD_loop2\num_initial_blocks\operation
230_get_AAD_loop2_done\num_initial_blocks\operation:
231 movdqa SHUF_MASK(%rip), %xmm14
232 PSHUFB_XMM %xmm14, %xmm\i # byte-reflect the AAD data
233
234 xor %r11, %r11 # initialise the data pointer offset as zero
235
236 # start AES for num_initial_blocks blocks
237
238 mov %arg5, %rax # %rax = *Y0
239 movdqu (%rax), \XMM0 # XMM0 = Y0
240 movdqa SHUF_MASK(%rip), %xmm14
241 PSHUFB_XMM %xmm14, \XMM0
242
243.if (\i == 5) || (\i == 6) || (\i == 7)
244.irpc index, \i_seq
245 paddd ONE(%rip), \XMM0 # INCR Y0
246 movdqa \XMM0, %xmm\index
247 movdqa SHUF_MASK(%rip), %xmm14
248 PSHUFB_XMM %xmm14, %xmm\index # perform a 16 byte swap
249
250.endr
251.irpc index, \i_seq
252 pxor 16*0(%arg1), %xmm\index
253.endr
254.irpc index, \i_seq
255 movaps 0x10(%rdi), \TMP1
256 AESENC \TMP1, %xmm\index # Round 1
257.endr
258.irpc index, \i_seq
259 movaps 0x20(%arg1), \TMP1
260 AESENC \TMP1, %xmm\index # Round 2
261.endr
262.irpc index, \i_seq
263 movaps 0x30(%arg1), \TMP1
264 AESENC \TMP1, %xmm\index # Round 2
265.endr
266.irpc index, \i_seq
267 movaps 0x40(%arg1), \TMP1
268 AESENC \TMP1, %xmm\index # Round 2
269.endr
270.irpc index, \i_seq
271 movaps 0x50(%arg1), \TMP1
272 AESENC \TMP1, %xmm\index # Round 2
273.endr
274.irpc index, \i_seq
275 movaps 0x60(%arg1), \TMP1
276 AESENC \TMP1, %xmm\index # Round 2
277.endr
278.irpc index, \i_seq
279 movaps 0x70(%arg1), \TMP1
280 AESENC \TMP1, %xmm\index # Round 2
281.endr
282.irpc index, \i_seq
283 movaps 0x80(%arg1), \TMP1
284 AESENC \TMP1, %xmm\index # Round 2
285.endr
286.irpc index, \i_seq
287 movaps 0x90(%arg1), \TMP1
288 AESENC \TMP1, %xmm\index # Round 2
289.endr
290.irpc index, \i_seq
291 movaps 0xa0(%arg1), \TMP1
292 AESENCLAST \TMP1, %xmm\index # Round 10
293.endr
294.irpc index, \i_seq
295 movdqu (%arg3 , %r11, 1), \TMP1
296 pxor \TMP1, %xmm\index
297 movdqu %xmm\index, (%arg2 , %r11, 1)
298 # write back plaintext/ciphertext for num_initial_blocks
299 add $16, %r11
300
301 movdqa \TMP1, %xmm\index
302 movdqa SHUF_MASK(%rip), %xmm14
303 PSHUFB_XMM %xmm14, %xmm\index
304
305 # prepare plaintext/ciphertext for GHASH computation
306.endr
307.endif
308 GHASH_MUL %xmm\i, \TMP3, \TMP1, \TMP2, \TMP4, \TMP5, \XMM1
309 # apply GHASH on num_initial_blocks blocks
310
311.if \i == 5
312 pxor %xmm5, %xmm6
313 GHASH_MUL %xmm6, \TMP3, \TMP1, \TMP2, \TMP4, \TMP5, \XMM1
314 pxor %xmm6, %xmm7
315 GHASH_MUL %xmm7, \TMP3, \TMP1, \TMP2, \TMP4, \TMP5, \XMM1
316 pxor %xmm7, %xmm8
317 GHASH_MUL %xmm8, \TMP3, \TMP1, \TMP2, \TMP4, \TMP5, \XMM1
318.elseif \i == 6
319 pxor %xmm6, %xmm7
320 GHASH_MUL %xmm7, \TMP3, \TMP1, \TMP2, \TMP4, \TMP5, \XMM1
321 pxor %xmm7, %xmm8
322 GHASH_MUL %xmm8, \TMP3, \TMP1, \TMP2, \TMP4, \TMP5, \XMM1
323.elseif \i == 7
324 pxor %xmm7, %xmm8
325 GHASH_MUL %xmm8, \TMP3, \TMP1, \TMP2, \TMP4, \TMP5, \XMM1
326.endif
327 cmp $64, %r13
328 jl _initial_blocks_done\num_initial_blocks\operation
329 # no need for precomputed values
330/*
331*
332* Precomputations for HashKey parallel with encryption of first 4 blocks.
333* Haskey_i_k holds XORed values of the low and high parts of the Haskey_i
334*/
335 paddd ONE(%rip), \XMM0 # INCR Y0
336 movdqa \XMM0, \XMM1
337 movdqa SHUF_MASK(%rip), %xmm14
338 PSHUFB_XMM %xmm14, \XMM1 # perform a 16 byte swap
339
340 paddd ONE(%rip), \XMM0 # INCR Y0
341 movdqa \XMM0, \XMM2
342 movdqa SHUF_MASK(%rip), %xmm14
343 PSHUFB_XMM %xmm14, \XMM2 # perform a 16 byte swap
344
345 paddd ONE(%rip), \XMM0 # INCR Y0
346 movdqa \XMM0, \XMM3
347 movdqa SHUF_MASK(%rip), %xmm14
348 PSHUFB_XMM %xmm14, \XMM3 # perform a 16 byte swap
349
350 paddd ONE(%rip), \XMM0 # INCR Y0
351 movdqa \XMM0, \XMM4
352 movdqa SHUF_MASK(%rip), %xmm14
353 PSHUFB_XMM %xmm14, \XMM4 # perform a 16 byte swap
354
355 pxor 16*0(%arg1), \XMM1
356 pxor 16*0(%arg1), \XMM2
357 pxor 16*0(%arg1), \XMM3
358 pxor 16*0(%arg1), \XMM4
359 movdqa \TMP3, \TMP5
360 pshufd $78, \TMP3, \TMP1
361 pxor \TMP3, \TMP1
362 movdqa \TMP1, HashKey_k(%rsp)
363 GHASH_MUL \TMP5, \TMP3, \TMP1, \TMP2, \TMP4, \TMP6, \TMP7
364# TMP5 = HashKey^2<<1 (mod poly)
365 movdqa \TMP5, HashKey_2(%rsp)
366# HashKey_2 = HashKey^2<<1 (mod poly)
367 pshufd $78, \TMP5, \TMP1
368 pxor \TMP5, \TMP1
369 movdqa \TMP1, HashKey_2_k(%rsp)
370.irpc index, 1234 # do 4 rounds
371 movaps 0x10*\index(%arg1), \TMP1
372 AESENC \TMP1, \XMM1
373 AESENC \TMP1, \XMM2
374 AESENC \TMP1, \XMM3
375 AESENC \TMP1, \XMM4
376.endr
377 GHASH_MUL \TMP5, \TMP3, \TMP1, \TMP2, \TMP4, \TMP6, \TMP7
378# TMP5 = HashKey^3<<1 (mod poly)
379 movdqa \TMP5, HashKey_3(%rsp)
380 pshufd $78, \TMP5, \TMP1
381 pxor \TMP5, \TMP1
382 movdqa \TMP1, HashKey_3_k(%rsp)
383.irpc index, 56789 # do next 5 rounds
384 movaps 0x10*\index(%arg1), \TMP1
385 AESENC \TMP1, \XMM1
386 AESENC \TMP1, \XMM2
387 AESENC \TMP1, \XMM3
388 AESENC \TMP1, \XMM4
389.endr
390 GHASH_MUL \TMP5, \TMP3, \TMP1, \TMP2, \TMP4, \TMP6, \TMP7
391# TMP5 = HashKey^3<<1 (mod poly)
392 movdqa \TMP5, HashKey_4(%rsp)
393 pshufd $78, \TMP5, \TMP1
394 pxor \TMP5, \TMP1
395 movdqa \TMP1, HashKey_4_k(%rsp)
396 movaps 0xa0(%arg1), \TMP2
397 AESENCLAST \TMP2, \XMM1
398 AESENCLAST \TMP2, \XMM2
399 AESENCLAST \TMP2, \XMM3
400 AESENCLAST \TMP2, \XMM4
401 movdqu 16*0(%arg3 , %r11 , 1), \TMP1
402 pxor \TMP1, \XMM1
403 movdqu \XMM1, 16*0(%arg2 , %r11 , 1)
404 movdqa \TMP1, \XMM1
405 movdqu 16*1(%arg3 , %r11 , 1), \TMP1
406 pxor \TMP1, \XMM2
407 movdqu \XMM2, 16*1(%arg2 , %r11 , 1)
408 movdqa \TMP1, \XMM2
409 movdqu 16*2(%arg3 , %r11 , 1), \TMP1
410 pxor \TMP1, \XMM3
411 movdqu \XMM3, 16*2(%arg2 , %r11 , 1)
412 movdqa \TMP1, \XMM3
413 movdqu 16*3(%arg3 , %r11 , 1), \TMP1
414 pxor \TMP1, \XMM4
415 movdqu \XMM4, 16*3(%arg2 , %r11 , 1)
416 movdqa \TMP1, \XMM4
417 add $64, %r11
418 movdqa SHUF_MASK(%rip), %xmm14
419 PSHUFB_XMM %xmm14, \XMM1 # perform a 16 byte swap
420 pxor \XMMDst, \XMM1
421# combine GHASHed value with the corresponding ciphertext
422 movdqa SHUF_MASK(%rip), %xmm14
423 PSHUFB_XMM %xmm14, \XMM2 # perform a 16 byte swap
424 movdqa SHUF_MASK(%rip), %xmm14
425 PSHUFB_XMM %xmm14, \XMM3 # perform a 16 byte swap
426 movdqa SHUF_MASK(%rip), %xmm14
427 PSHUFB_XMM %xmm14, \XMM4 # perform a 16 byte swap
428
429_initial_blocks_done\num_initial_blocks\operation:
430
431.endm
432
433
434/*
435* if a = number of total plaintext bytes
436* b = floor(a/16)
437* num_initial_blocks = b mod 4
438* encrypt the initial num_initial_blocks blocks and apply ghash on
439* the ciphertext
440* %r10, %r11, %r12, %rax, %xmm5, %xmm6, %xmm7, %xmm8, %xmm9 registers
441* are clobbered
442* arg1, %arg2, %arg3, %r14 are used as a pointer only, not modified
443*/
444
445
446.macro INITIAL_BLOCKS_ENC num_initial_blocks TMP1 TMP2 TMP3 TMP4 TMP5 XMM0 XMM1 \
447XMM2 XMM3 XMM4 XMMDst TMP6 TMP7 i i_seq operation
448 mov arg7, %r10 # %r10 = AAD
449 mov arg8, %r12 # %r12 = aadLen
450 mov %r12, %r11
451 pxor %xmm\i, %xmm\i
452_get_AAD_loop\num_initial_blocks\operation:
453 movd (%r10), \TMP1
454 pslldq $12, \TMP1
455 psrldq $4, %xmm\i
456 pxor \TMP1, %xmm\i
457 add $4, %r10
458 sub $4, %r12
459 jne _get_AAD_loop\num_initial_blocks\operation
460 cmp $16, %r11
461 je _get_AAD_loop2_done\num_initial_blocks\operation
462 mov $16, %r12
463_get_AAD_loop2\num_initial_blocks\operation:
464 psrldq $4, %xmm\i
465 sub $4, %r12
466 cmp %r11, %r12
467 jne _get_AAD_loop2\num_initial_blocks\operation
468_get_AAD_loop2_done\num_initial_blocks\operation:
469 movdqa SHUF_MASK(%rip), %xmm14
470 PSHUFB_XMM %xmm14, %xmm\i # byte-reflect the AAD data
471
472 xor %r11, %r11 # initialise the data pointer offset as zero
473
474 # start AES for num_initial_blocks blocks
475
476 mov %arg5, %rax # %rax = *Y0
477 movdqu (%rax), \XMM0 # XMM0 = Y0
478 movdqa SHUF_MASK(%rip), %xmm14
479 PSHUFB_XMM %xmm14, \XMM0
480
481.if (\i == 5) || (\i == 6) || (\i == 7)
482.irpc index, \i_seq
483 paddd ONE(%rip), \XMM0 # INCR Y0
484 movdqa \XMM0, %xmm\index
485 movdqa SHUF_MASK(%rip), %xmm14
486 PSHUFB_XMM %xmm14, %xmm\index # perform a 16 byte swap
487
488.endr
489.irpc index, \i_seq
490 pxor 16*0(%arg1), %xmm\index
491.endr
492.irpc index, \i_seq
493 movaps 0x10(%rdi), \TMP1
494 AESENC \TMP1, %xmm\index # Round 1
495.endr
496.irpc index, \i_seq
497 movaps 0x20(%arg1), \TMP1
498 AESENC \TMP1, %xmm\index # Round 2
499.endr
500.irpc index, \i_seq
501 movaps 0x30(%arg1), \TMP1
502 AESENC \TMP1, %xmm\index # Round 2
503.endr
504.irpc index, \i_seq
505 movaps 0x40(%arg1), \TMP1
506 AESENC \TMP1, %xmm\index # Round 2
507.endr
508.irpc index, \i_seq
509 movaps 0x50(%arg1), \TMP1
510 AESENC \TMP1, %xmm\index # Round 2
511.endr
512.irpc index, \i_seq
513 movaps 0x60(%arg1), \TMP1
514 AESENC \TMP1, %xmm\index # Round 2
515.endr
516.irpc index, \i_seq
517 movaps 0x70(%arg1), \TMP1
518 AESENC \TMP1, %xmm\index # Round 2
519.endr
520.irpc index, \i_seq
521 movaps 0x80(%arg1), \TMP1
522 AESENC \TMP1, %xmm\index # Round 2
523.endr
524.irpc index, \i_seq
525 movaps 0x90(%arg1), \TMP1
526 AESENC \TMP1, %xmm\index # Round 2
527.endr
528.irpc index, \i_seq
529 movaps 0xa0(%arg1), \TMP1
530 AESENCLAST \TMP1, %xmm\index # Round 10
531.endr
532.irpc index, \i_seq
533 movdqu (%arg3 , %r11, 1), \TMP1
534 pxor \TMP1, %xmm\index
535 movdqu %xmm\index, (%arg2 , %r11, 1)
536 # write back plaintext/ciphertext for num_initial_blocks
537 add $16, %r11
538
539 movdqa SHUF_MASK(%rip), %xmm14
540 PSHUFB_XMM %xmm14, %xmm\index
541
542 # prepare plaintext/ciphertext for GHASH computation
543.endr
544.endif
545 GHASH_MUL %xmm\i, \TMP3, \TMP1, \TMP2, \TMP4, \TMP5, \XMM1
546 # apply GHASH on num_initial_blocks blocks
547
548.if \i == 5
549 pxor %xmm5, %xmm6
550 GHASH_MUL %xmm6, \TMP3, \TMP1, \TMP2, \TMP4, \TMP5, \XMM1
551 pxor %xmm6, %xmm7
552 GHASH_MUL %xmm7, \TMP3, \TMP1, \TMP2, \TMP4, \TMP5, \XMM1
553 pxor %xmm7, %xmm8
554 GHASH_MUL %xmm8, \TMP3, \TMP1, \TMP2, \TMP4, \TMP5, \XMM1
555.elseif \i == 6
556 pxor %xmm6, %xmm7
557 GHASH_MUL %xmm7, \TMP3, \TMP1, \TMP2, \TMP4, \TMP5, \XMM1
558 pxor %xmm7, %xmm8
559 GHASH_MUL %xmm8, \TMP3, \TMP1, \TMP2, \TMP4, \TMP5, \XMM1
560.elseif \i == 7
561 pxor %xmm7, %xmm8
562 GHASH_MUL %xmm8, \TMP3, \TMP1, \TMP2, \TMP4, \TMP5, \XMM1
563.endif
564 cmp $64, %r13
565 jl _initial_blocks_done\num_initial_blocks\operation
566 # no need for precomputed values
567/*
568*
569* Precomputations for HashKey parallel with encryption of first 4 blocks.
570* Haskey_i_k holds XORed values of the low and high parts of the Haskey_i
571*/
572 paddd ONE(%rip), \XMM0 # INCR Y0
573 movdqa \XMM0, \XMM1
574 movdqa SHUF_MASK(%rip), %xmm14
575 PSHUFB_XMM %xmm14, \XMM1 # perform a 16 byte swap
576
577 paddd ONE(%rip), \XMM0 # INCR Y0
578 movdqa \XMM0, \XMM2
579 movdqa SHUF_MASK(%rip), %xmm14
580 PSHUFB_XMM %xmm14, \XMM2 # perform a 16 byte swap
581
582 paddd ONE(%rip), \XMM0 # INCR Y0
583 movdqa \XMM0, \XMM3
584 movdqa SHUF_MASK(%rip), %xmm14
585 PSHUFB_XMM %xmm14, \XMM3 # perform a 16 byte swap
586
587 paddd ONE(%rip), \XMM0 # INCR Y0
588 movdqa \XMM0, \XMM4
589 movdqa SHUF_MASK(%rip), %xmm14
590 PSHUFB_XMM %xmm14, \XMM4 # perform a 16 byte swap
591
592 pxor 16*0(%arg1), \XMM1
593 pxor 16*0(%arg1), \XMM2
594 pxor 16*0(%arg1), \XMM3
595 pxor 16*0(%arg1), \XMM4
596 movdqa \TMP3, \TMP5
597 pshufd $78, \TMP3, \TMP1
598 pxor \TMP3, \TMP1
599 movdqa \TMP1, HashKey_k(%rsp)
600 GHASH_MUL \TMP5, \TMP3, \TMP1, \TMP2, \TMP4, \TMP6, \TMP7
601# TMP5 = HashKey^2<<1 (mod poly)
602 movdqa \TMP5, HashKey_2(%rsp)
603# HashKey_2 = HashKey^2<<1 (mod poly)
604 pshufd $78, \TMP5, \TMP1
605 pxor \TMP5, \TMP1
606 movdqa \TMP1, HashKey_2_k(%rsp)
607.irpc index, 1234 # do 4 rounds
608 movaps 0x10*\index(%arg1), \TMP1
609 AESENC \TMP1, \XMM1
610 AESENC \TMP1, \XMM2
611 AESENC \TMP1, \XMM3
612 AESENC \TMP1, \XMM4
613.endr
614 GHASH_MUL \TMP5, \TMP3, \TMP1, \TMP2, \TMP4, \TMP6, \TMP7
615# TMP5 = HashKey^3<<1 (mod poly)
616 movdqa \TMP5, HashKey_3(%rsp)
617 pshufd $78, \TMP5, \TMP1
618 pxor \TMP5, \TMP1
619 movdqa \TMP1, HashKey_3_k(%rsp)
620.irpc index, 56789 # do next 5 rounds
621 movaps 0x10*\index(%arg1), \TMP1
622 AESENC \TMP1, \XMM1
623 AESENC \TMP1, \XMM2
624 AESENC \TMP1, \XMM3
625 AESENC \TMP1, \XMM4
626.endr
627 GHASH_MUL \TMP5, \TMP3, \TMP1, \TMP2, \TMP4, \TMP6, \TMP7
628# TMP5 = HashKey^3<<1 (mod poly)
629 movdqa \TMP5, HashKey_4(%rsp)
630 pshufd $78, \TMP5, \TMP1
631 pxor \TMP5, \TMP1
632 movdqa \TMP1, HashKey_4_k(%rsp)
633 movaps 0xa0(%arg1), \TMP2
634 AESENCLAST \TMP2, \XMM1
635 AESENCLAST \TMP2, \XMM2
636 AESENCLAST \TMP2, \XMM3
637 AESENCLAST \TMP2, \XMM4
638 movdqu 16*0(%arg3 , %r11 , 1), \TMP1
639 pxor \TMP1, \XMM1
640 movdqu 16*1(%arg3 , %r11 , 1), \TMP1
641 pxor \TMP1, \XMM2
642 movdqu 16*2(%arg3 , %r11 , 1), \TMP1
643 pxor \TMP1, \XMM3
644 movdqu 16*3(%arg3 , %r11 , 1), \TMP1
645 pxor \TMP1, \XMM4
646 movdqu \XMM1, 16*0(%arg2 , %r11 , 1)
647 movdqu \XMM2, 16*1(%arg2 , %r11 , 1)
648 movdqu \XMM3, 16*2(%arg2 , %r11 , 1)
649 movdqu \XMM4, 16*3(%arg2 , %r11 , 1)
650
651 add $64, %r11
652 movdqa SHUF_MASK(%rip), %xmm14
653 PSHUFB_XMM %xmm14, \XMM1 # perform a 16 byte swap
654 pxor \XMMDst, \XMM1
655# combine GHASHed value with the corresponding ciphertext
656 movdqa SHUF_MASK(%rip), %xmm14
657 PSHUFB_XMM %xmm14, \XMM2 # perform a 16 byte swap
658 movdqa SHUF_MASK(%rip), %xmm14
659 PSHUFB_XMM %xmm14, \XMM3 # perform a 16 byte swap
660 movdqa SHUF_MASK(%rip), %xmm14
661 PSHUFB_XMM %xmm14, \XMM4 # perform a 16 byte swap
662
663_initial_blocks_done\num_initial_blocks\operation:
664
665.endm
666
667/*
668* encrypt 4 blocks at a time
669* ghash the 4 previously encrypted ciphertext blocks
670* arg1, %arg2, %arg3 are used as pointers only, not modified
671* %r11 is the data offset value
672*/
673.macro GHASH_4_ENCRYPT_4_PARALLEL_ENC TMP1 TMP2 TMP3 TMP4 TMP5 \
674TMP6 XMM0 XMM1 XMM2 XMM3 XMM4 XMM5 XMM6 XMM7 XMM8 operation
675
676 movdqa \XMM1, \XMM5
677 movdqa \XMM2, \XMM6
678 movdqa \XMM3, \XMM7
679 movdqa \XMM4, \XMM8
680
681 movdqa SHUF_MASK(%rip), %xmm15
682 # multiply TMP5 * HashKey using karatsuba
683
684 movdqa \XMM5, \TMP4
685 pshufd $78, \XMM5, \TMP6
686 pxor \XMM5, \TMP6
687 paddd ONE(%rip), \XMM0 # INCR CNT
688 movdqa HashKey_4(%rsp), \TMP5
689 PCLMULQDQ 0x11, \TMP5, \TMP4 # TMP4 = a1*b1
690 movdqa \XMM0, \XMM1
691 paddd ONE(%rip), \XMM0 # INCR CNT
692 movdqa \XMM0, \XMM2
693 paddd ONE(%rip), \XMM0 # INCR CNT
694 movdqa \XMM0, \XMM3
695 paddd ONE(%rip), \XMM0 # INCR CNT
696 movdqa \XMM0, \XMM4
697 PSHUFB_XMM %xmm15, \XMM1 # perform a 16 byte swap
698 PCLMULQDQ 0x00, \TMP5, \XMM5 # XMM5 = a0*b0
699 PSHUFB_XMM %xmm15, \XMM2 # perform a 16 byte swap
700 PSHUFB_XMM %xmm15, \XMM3 # perform a 16 byte swap
701 PSHUFB_XMM %xmm15, \XMM4 # perform a 16 byte swap
702
703 pxor (%arg1), \XMM1
704 pxor (%arg1), \XMM2
705 pxor (%arg1), \XMM3
706 pxor (%arg1), \XMM4
707 movdqa HashKey_4_k(%rsp), \TMP5
708 PCLMULQDQ 0x00, \TMP5, \TMP6 # TMP6 = (a1+a0)*(b1+b0)
709 movaps 0x10(%arg1), \TMP1
710 AESENC \TMP1, \XMM1 # Round 1
711 AESENC \TMP1, \XMM2
712 AESENC \TMP1, \XMM3
713 AESENC \TMP1, \XMM4
714 movaps 0x20(%arg1), \TMP1
715 AESENC \TMP1, \XMM1 # Round 2
716 AESENC \TMP1, \XMM2
717 AESENC \TMP1, \XMM3
718 AESENC \TMP1, \XMM4
719 movdqa \XMM6, \TMP1
720 pshufd $78, \XMM6, \TMP2
721 pxor \XMM6, \TMP2
722 movdqa HashKey_3(%rsp), \TMP5
723 PCLMULQDQ 0x11, \TMP5, \TMP1 # TMP1 = a1 * b1
724 movaps 0x30(%arg1), \TMP3
725 AESENC \TMP3, \XMM1 # Round 3
726 AESENC \TMP3, \XMM2
727 AESENC \TMP3, \XMM3
728 AESENC \TMP3, \XMM4
729 PCLMULQDQ 0x00, \TMP5, \XMM6 # XMM6 = a0*b0
730 movaps 0x40(%arg1), \TMP3
731 AESENC \TMP3, \XMM1 # Round 4
732 AESENC \TMP3, \XMM2
733 AESENC \TMP3, \XMM3
734 AESENC \TMP3, \XMM4
735 movdqa HashKey_3_k(%rsp), \TMP5
736 PCLMULQDQ 0x00, \TMP5, \TMP2 # TMP2 = (a1+a0)*(b1+b0)
737 movaps 0x50(%arg1), \TMP3
738 AESENC \TMP3, \XMM1 # Round 5
739 AESENC \TMP3, \XMM2
740 AESENC \TMP3, \XMM3
741 AESENC \TMP3, \XMM4
742 pxor \TMP1, \TMP4
743# accumulate the results in TMP4:XMM5, TMP6 holds the middle part
744 pxor \XMM6, \XMM5
745 pxor \TMP2, \TMP6
746 movdqa \XMM7, \TMP1
747 pshufd $78, \XMM7, \TMP2
748 pxor \XMM7, \TMP2
749 movdqa HashKey_2(%rsp ), \TMP5
750
751 # Multiply TMP5 * HashKey using karatsuba
752
753 PCLMULQDQ 0x11, \TMP5, \TMP1 # TMP1 = a1*b1
754 movaps 0x60(%arg1), \TMP3
755 AESENC \TMP3, \XMM1 # Round 6
756 AESENC \TMP3, \XMM2
757 AESENC \TMP3, \XMM3
758 AESENC \TMP3, \XMM4
759 PCLMULQDQ 0x00, \TMP5, \XMM7 # XMM7 = a0*b0
760 movaps 0x70(%arg1), \TMP3
761 AESENC \TMP3, \XMM1 # Round 7
762 AESENC \TMP3, \XMM2
763 AESENC \TMP3, \XMM3
764 AESENC \TMP3, \XMM4
765 movdqa HashKey_2_k(%rsp), \TMP5
766 PCLMULQDQ 0x00, \TMP5, \TMP2 # TMP2 = (a1+a0)*(b1+b0)
767 movaps 0x80(%arg1), \TMP3
768 AESENC \TMP3, \XMM1 # Round 8
769 AESENC \TMP3, \XMM2
770 AESENC \TMP3, \XMM3
771 AESENC \TMP3, \XMM4
772 pxor \TMP1, \TMP4
773# accumulate the results in TMP4:XMM5, TMP6 holds the middle part
774 pxor \XMM7, \XMM5
775 pxor \TMP2, \TMP6
776
777 # Multiply XMM8 * HashKey
778 # XMM8 and TMP5 hold the values for the two operands
779
780 movdqa \XMM8, \TMP1
781 pshufd $78, \XMM8, \TMP2
782 pxor \XMM8, \TMP2
783 movdqa HashKey(%rsp), \TMP5
784 PCLMULQDQ 0x11, \TMP5, \TMP1 # TMP1 = a1*b1
785 movaps 0x90(%arg1), \TMP3
786 AESENC \TMP3, \XMM1 # Round 9
787 AESENC \TMP3, \XMM2
788 AESENC \TMP3, \XMM3
789 AESENC \TMP3, \XMM4
790 PCLMULQDQ 0x00, \TMP5, \XMM8 # XMM8 = a0*b0
791 movaps 0xa0(%arg1), \TMP3
792 AESENCLAST \TMP3, \XMM1 # Round 10
793 AESENCLAST \TMP3, \XMM2
794 AESENCLAST \TMP3, \XMM3
795 AESENCLAST \TMP3, \XMM4
796 movdqa HashKey_k(%rsp), \TMP5
797 PCLMULQDQ 0x00, \TMP5, \TMP2 # TMP2 = (a1+a0)*(b1+b0)
798 movdqu (%arg3,%r11,1), \TMP3
799 pxor \TMP3, \XMM1 # Ciphertext/Plaintext XOR EK
800 movdqu 16(%arg3,%r11,1), \TMP3
801 pxor \TMP3, \XMM2 # Ciphertext/Plaintext XOR EK
802 movdqu 32(%arg3,%r11,1), \TMP3
803 pxor \TMP3, \XMM3 # Ciphertext/Plaintext XOR EK
804 movdqu 48(%arg3,%r11,1), \TMP3
805 pxor \TMP3, \XMM4 # Ciphertext/Plaintext XOR EK
806 movdqu \XMM1, (%arg2,%r11,1) # Write to the ciphertext buffer
807 movdqu \XMM2, 16(%arg2,%r11,1) # Write to the ciphertext buffer
808 movdqu \XMM3, 32(%arg2,%r11,1) # Write to the ciphertext buffer
809 movdqu \XMM4, 48(%arg2,%r11,1) # Write to the ciphertext buffer
810 PSHUFB_XMM %xmm15, \XMM1 # perform a 16 byte swap
811 PSHUFB_XMM %xmm15, \XMM2 # perform a 16 byte swap
812 PSHUFB_XMM %xmm15, \XMM3 # perform a 16 byte swap
813 PSHUFB_XMM %xmm15, \XMM4 # perform a 16 byte swap
814
815 pxor \TMP4, \TMP1
816 pxor \XMM8, \XMM5
817 pxor \TMP6, \TMP2
818 pxor \TMP1, \TMP2
819 pxor \XMM5, \TMP2
820 movdqa \TMP2, \TMP3
821 pslldq $8, \TMP3 # left shift TMP3 2 DWs
822 psrldq $8, \TMP2 # right shift TMP2 2 DWs
823 pxor \TMP3, \XMM5
824 pxor \TMP2, \TMP1 # accumulate the results in TMP1:XMM5
825
826 # first phase of reduction
827
828 movdqa \XMM5, \TMP2
829 movdqa \XMM5, \TMP3
830 movdqa \XMM5, \TMP4
831# move XMM5 into TMP2, TMP3, TMP4 in order to perform shifts independently
832 pslld $31, \TMP2 # packed right shift << 31
833 pslld $30, \TMP3 # packed right shift << 30
834 pslld $25, \TMP4 # packed right shift << 25
835 pxor \TMP3, \TMP2 # xor the shifted versions
836 pxor \TMP4, \TMP2
837 movdqa \TMP2, \TMP5
838 psrldq $4, \TMP5 # right shift T5 1 DW
839 pslldq $12, \TMP2 # left shift T2 3 DWs
840 pxor \TMP2, \XMM5
841
842 # second phase of reduction
843
844 movdqa \XMM5,\TMP2 # make 3 copies of XMM5 into TMP2, TMP3, TMP4
845 movdqa \XMM5,\TMP3
846 movdqa \XMM5,\TMP4
847 psrld $1, \TMP2 # packed left shift >>1
848 psrld $2, \TMP3 # packed left shift >>2
849 psrld $7, \TMP4 # packed left shift >>7
850 pxor \TMP3,\TMP2 # xor the shifted versions
851 pxor \TMP4,\TMP2
852 pxor \TMP5, \TMP2
853 pxor \TMP2, \XMM5
854 pxor \TMP1, \XMM5 # result is in TMP1
855
856 pxor \XMM5, \XMM1
857.endm
858
859/*
860* decrypt 4 blocks at a time
861* ghash the 4 previously decrypted ciphertext blocks
862* arg1, %arg2, %arg3 are used as pointers only, not modified
863* %r11 is the data offset value
864*/
865.macro GHASH_4_ENCRYPT_4_PARALLEL_DEC TMP1 TMP2 TMP3 TMP4 TMP5 \
866TMP6 XMM0 XMM1 XMM2 XMM3 XMM4 XMM5 XMM6 XMM7 XMM8 operation
867
868 movdqa \XMM1, \XMM5
869 movdqa \XMM2, \XMM6
870 movdqa \XMM3, \XMM7
871 movdqa \XMM4, \XMM8
872
873 movdqa SHUF_MASK(%rip), %xmm15
874 # multiply TMP5 * HashKey using karatsuba
875
876 movdqa \XMM5, \TMP4
877 pshufd $78, \XMM5, \TMP6
878 pxor \XMM5, \TMP6
879 paddd ONE(%rip), \XMM0 # INCR CNT
880 movdqa HashKey_4(%rsp), \TMP5
881 PCLMULQDQ 0x11, \TMP5, \TMP4 # TMP4 = a1*b1
882 movdqa \XMM0, \XMM1
883 paddd ONE(%rip), \XMM0 # INCR CNT
884 movdqa \XMM0, \XMM2
885 paddd ONE(%rip), \XMM0 # INCR CNT
886 movdqa \XMM0, \XMM3
887 paddd ONE(%rip), \XMM0 # INCR CNT
888 movdqa \XMM0, \XMM4
889 PSHUFB_XMM %xmm15, \XMM1 # perform a 16 byte swap
890 PCLMULQDQ 0x00, \TMP5, \XMM5 # XMM5 = a0*b0
891 PSHUFB_XMM %xmm15, \XMM2 # perform a 16 byte swap
892 PSHUFB_XMM %xmm15, \XMM3 # perform a 16 byte swap
893 PSHUFB_XMM %xmm15, \XMM4 # perform a 16 byte swap
894
895 pxor (%arg1), \XMM1
896 pxor (%arg1), \XMM2
897 pxor (%arg1), \XMM3
898 pxor (%arg1), \XMM4
899 movdqa HashKey_4_k(%rsp), \TMP5
900 PCLMULQDQ 0x00, \TMP5, \TMP6 # TMP6 = (a1+a0)*(b1+b0)
901 movaps 0x10(%arg1), \TMP1
902 AESENC \TMP1, \XMM1 # Round 1
903 AESENC \TMP1, \XMM2
904 AESENC \TMP1, \XMM3
905 AESENC \TMP1, \XMM4
906 movaps 0x20(%arg1), \TMP1
907 AESENC \TMP1, \XMM1 # Round 2
908 AESENC \TMP1, \XMM2
909 AESENC \TMP1, \XMM3
910 AESENC \TMP1, \XMM4
911 movdqa \XMM6, \TMP1
912 pshufd $78, \XMM6, \TMP2
913 pxor \XMM6, \TMP2
914 movdqa HashKey_3(%rsp), \TMP5
915 PCLMULQDQ 0x11, \TMP5, \TMP1 # TMP1 = a1 * b1
916 movaps 0x30(%arg1), \TMP3
917 AESENC \TMP3, \XMM1 # Round 3
918 AESENC \TMP3, \XMM2
919 AESENC \TMP3, \XMM3
920 AESENC \TMP3, \XMM4
921 PCLMULQDQ 0x00, \TMP5, \XMM6 # XMM6 = a0*b0
922 movaps 0x40(%arg1), \TMP3
923 AESENC \TMP3, \XMM1 # Round 4
924 AESENC \TMP3, \XMM2
925 AESENC \TMP3, \XMM3
926 AESENC \TMP3, \XMM4
927 movdqa HashKey_3_k(%rsp), \TMP5
928 PCLMULQDQ 0x00, \TMP5, \TMP2 # TMP2 = (a1+a0)*(b1+b0)
929 movaps 0x50(%arg1), \TMP3
930 AESENC \TMP3, \XMM1 # Round 5
931 AESENC \TMP3, \XMM2
932 AESENC \TMP3, \XMM3
933 AESENC \TMP3, \XMM4
934 pxor \TMP1, \TMP4
935# accumulate the results in TMP4:XMM5, TMP6 holds the middle part
936 pxor \XMM6, \XMM5
937 pxor \TMP2, \TMP6
938 movdqa \XMM7, \TMP1
939 pshufd $78, \XMM7, \TMP2
940 pxor \XMM7, \TMP2
941 movdqa HashKey_2(%rsp ), \TMP5
942
943 # Multiply TMP5 * HashKey using karatsuba
944
945 PCLMULQDQ 0x11, \TMP5, \TMP1 # TMP1 = a1*b1
946 movaps 0x60(%arg1), \TMP3
947 AESENC \TMP3, \XMM1 # Round 6
948 AESENC \TMP3, \XMM2
949 AESENC \TMP3, \XMM3
950 AESENC \TMP3, \XMM4
951 PCLMULQDQ 0x00, \TMP5, \XMM7 # XMM7 = a0*b0
952 movaps 0x70(%arg1), \TMP3
953 AESENC \TMP3, \XMM1 # Round 7
954 AESENC \TMP3, \XMM2
955 AESENC \TMP3, \XMM3
956 AESENC \TMP3, \XMM4
957 movdqa HashKey_2_k(%rsp), \TMP5
958 PCLMULQDQ 0x00, \TMP5, \TMP2 # TMP2 = (a1+a0)*(b1+b0)
959 movaps 0x80(%arg1), \TMP3
960 AESENC \TMP3, \XMM1 # Round 8
961 AESENC \TMP3, \XMM2
962 AESENC \TMP3, \XMM3
963 AESENC \TMP3, \XMM4
964 pxor \TMP1, \TMP4
965# accumulate the results in TMP4:XMM5, TMP6 holds the middle part
966 pxor \XMM7, \XMM5
967 pxor \TMP2, \TMP6
968
969 # Multiply XMM8 * HashKey
970 # XMM8 and TMP5 hold the values for the two operands
971
972 movdqa \XMM8, \TMP1
973 pshufd $78, \XMM8, \TMP2
974 pxor \XMM8, \TMP2
975 movdqa HashKey(%rsp), \TMP5
976 PCLMULQDQ 0x11, \TMP5, \TMP1 # TMP1 = a1*b1
977 movaps 0x90(%arg1), \TMP3
978 AESENC \TMP3, \XMM1 # Round 9
979 AESENC \TMP3, \XMM2
980 AESENC \TMP3, \XMM3
981 AESENC \TMP3, \XMM4
982 PCLMULQDQ 0x00, \TMP5, \XMM8 # XMM8 = a0*b0
983 movaps 0xa0(%arg1), \TMP3
984 AESENCLAST \TMP3, \XMM1 # Round 10
985 AESENCLAST \TMP3, \XMM2
986 AESENCLAST \TMP3, \XMM3
987 AESENCLAST \TMP3, \XMM4
988 movdqa HashKey_k(%rsp), \TMP5
989 PCLMULQDQ 0x00, \TMP5, \TMP2 # TMP2 = (a1+a0)*(b1+b0)
990 movdqu (%arg3,%r11,1), \TMP3
991 pxor \TMP3, \XMM1 # Ciphertext/Plaintext XOR EK
992 movdqu \XMM1, (%arg2,%r11,1) # Write to plaintext buffer
993 movdqa \TMP3, \XMM1
994 movdqu 16(%arg3,%r11,1), \TMP3
995 pxor \TMP3, \XMM2 # Ciphertext/Plaintext XOR EK
996 movdqu \XMM2, 16(%arg2,%r11,1) # Write to plaintext buffer
997 movdqa \TMP3, \XMM2
998 movdqu 32(%arg3,%r11,1), \TMP3
999 pxor \TMP3, \XMM3 # Ciphertext/Plaintext XOR EK
1000 movdqu \XMM3, 32(%arg2,%r11,1) # Write to plaintext buffer
1001 movdqa \TMP3, \XMM3
1002 movdqu 48(%arg3,%r11,1), \TMP3
1003 pxor \TMP3, \XMM4 # Ciphertext/Plaintext XOR EK
1004 movdqu \XMM4, 48(%arg2,%r11,1) # Write to plaintext buffer
1005 movdqa \TMP3, \XMM4
1006 PSHUFB_XMM %xmm15, \XMM1 # perform a 16 byte swap
1007 PSHUFB_XMM %xmm15, \XMM2 # perform a 16 byte swap
1008 PSHUFB_XMM %xmm15, \XMM3 # perform a 16 byte swap
1009 PSHUFB_XMM %xmm15, \XMM4 # perform a 16 byte swap
1010
1011 pxor \TMP4, \TMP1
1012 pxor \XMM8, \XMM5
1013 pxor \TMP6, \TMP2
1014 pxor \TMP1, \TMP2
1015 pxor \XMM5, \TMP2
1016 movdqa \TMP2, \TMP3
1017 pslldq $8, \TMP3 # left shift TMP3 2 DWs
1018 psrldq $8, \TMP2 # right shift TMP2 2 DWs
1019 pxor \TMP3, \XMM5
1020 pxor \TMP2, \TMP1 # accumulate the results in TMP1:XMM5
1021
1022 # first phase of reduction
1023
1024 movdqa \XMM5, \TMP2
1025 movdqa \XMM5, \TMP3
1026 movdqa \XMM5, \TMP4
1027# move XMM5 into TMP2, TMP3, TMP4 in order to perform shifts independently
1028 pslld $31, \TMP2 # packed right shift << 31
1029 pslld $30, \TMP3 # packed right shift << 30
1030 pslld $25, \TMP4 # packed right shift << 25
1031 pxor \TMP3, \TMP2 # xor the shifted versions
1032 pxor \TMP4, \TMP2
1033 movdqa \TMP2, \TMP5
1034 psrldq $4, \TMP5 # right shift T5 1 DW
1035 pslldq $12, \TMP2 # left shift T2 3 DWs
1036 pxor \TMP2, \XMM5
1037
1038 # second phase of reduction
1039
1040 movdqa \XMM5,\TMP2 # make 3 copies of XMM5 into TMP2, TMP3, TMP4
1041 movdqa \XMM5,\TMP3
1042 movdqa \XMM5,\TMP4
1043 psrld $1, \TMP2 # packed left shift >>1
1044 psrld $2, \TMP3 # packed left shift >>2
1045 psrld $7, \TMP4 # packed left shift >>7
1046 pxor \TMP3,\TMP2 # xor the shifted versions
1047 pxor \TMP4,\TMP2
1048 pxor \TMP5, \TMP2
1049 pxor \TMP2, \XMM5
1050 pxor \TMP1, \XMM5 # result is in TMP1
1051
1052 pxor \XMM5, \XMM1
1053.endm
1054
1055/* GHASH the last 4 ciphertext blocks. */
1056.macro GHASH_LAST_4 TMP1 TMP2 TMP3 TMP4 TMP5 TMP6 \
1057TMP7 XMM1 XMM2 XMM3 XMM4 XMMDst
1058
1059 # Multiply TMP6 * HashKey (using Karatsuba)
1060
1061 movdqa \XMM1, \TMP6
1062 pshufd $78, \XMM1, \TMP2
1063 pxor \XMM1, \TMP2
1064 movdqa HashKey_4(%rsp), \TMP5
1065 PCLMULQDQ 0x11, \TMP5, \TMP6 # TMP6 = a1*b1
1066 PCLMULQDQ 0x00, \TMP5, \XMM1 # XMM1 = a0*b0
1067 movdqa HashKey_4_k(%rsp), \TMP4
1068 PCLMULQDQ 0x00, \TMP4, \TMP2 # TMP2 = (a1+a0)*(b1+b0)
1069 movdqa \XMM1, \XMMDst
1070 movdqa \TMP2, \XMM1 # result in TMP6, XMMDst, XMM1
1071
1072 # Multiply TMP1 * HashKey (using Karatsuba)
1073
1074 movdqa \XMM2, \TMP1
1075 pshufd $78, \XMM2, \TMP2
1076 pxor \XMM2, \TMP2
1077 movdqa HashKey_3(%rsp), \TMP5
1078 PCLMULQDQ 0x11, \TMP5, \TMP1 # TMP1 = a1*b1
1079 PCLMULQDQ 0x00, \TMP5, \XMM2 # XMM2 = a0*b0
1080 movdqa HashKey_3_k(%rsp), \TMP4
1081 PCLMULQDQ 0x00, \TMP4, \TMP2 # TMP2 = (a1+a0)*(b1+b0)
1082 pxor \TMP1, \TMP6
1083 pxor \XMM2, \XMMDst
1084 pxor \TMP2, \XMM1
1085# results accumulated in TMP6, XMMDst, XMM1
1086
1087 # Multiply TMP1 * HashKey (using Karatsuba)
1088
1089 movdqa \XMM3, \TMP1
1090 pshufd $78, \XMM3, \TMP2
1091 pxor \XMM3, \TMP2
1092 movdqa HashKey_2(%rsp), \TMP5
1093 PCLMULQDQ 0x11, \TMP5, \TMP1 # TMP1 = a1*b1
1094 PCLMULQDQ 0x00, \TMP5, \XMM3 # XMM3 = a0*b0
1095 movdqa HashKey_2_k(%rsp), \TMP4
1096 PCLMULQDQ 0x00, \TMP4, \TMP2 # TMP2 = (a1+a0)*(b1+b0)
1097 pxor \TMP1, \TMP6
1098 pxor \XMM3, \XMMDst
1099 pxor \TMP2, \XMM1 # results accumulated in TMP6, XMMDst, XMM1
1100
1101 # Multiply TMP1 * HashKey (using Karatsuba)
1102 movdqa \XMM4, \TMP1
1103 pshufd $78, \XMM4, \TMP2
1104 pxor \XMM4, \TMP2
1105 movdqa HashKey(%rsp), \TMP5
1106 PCLMULQDQ 0x11, \TMP5, \TMP1 # TMP1 = a1*b1
1107 PCLMULQDQ 0x00, \TMP5, \XMM4 # XMM4 = a0*b0
1108 movdqa HashKey_k(%rsp), \TMP4
1109 PCLMULQDQ 0x00, \TMP4, \TMP2 # TMP2 = (a1+a0)*(b1+b0)
1110 pxor \TMP1, \TMP6
1111 pxor \XMM4, \XMMDst
1112 pxor \XMM1, \TMP2
1113 pxor \TMP6, \TMP2
1114 pxor \XMMDst, \TMP2
1115 # middle section of the temp results combined as in karatsuba algorithm
1116 movdqa \TMP2, \TMP4
1117 pslldq $8, \TMP4 # left shift TMP4 2 DWs
1118 psrldq $8, \TMP2 # right shift TMP2 2 DWs
1119 pxor \TMP4, \XMMDst
1120 pxor \TMP2, \TMP6
1121# TMP6:XMMDst holds the result of the accumulated carry-less multiplications
1122 # first phase of the reduction
1123 movdqa \XMMDst, \TMP2
1124 movdqa \XMMDst, \TMP3
1125 movdqa \XMMDst, \TMP4
1126# move XMMDst into TMP2, TMP3, TMP4 in order to perform 3 shifts independently
1127 pslld $31, \TMP2 # packed right shifting << 31
1128 pslld $30, \TMP3 # packed right shifting << 30
1129 pslld $25, \TMP4 # packed right shifting << 25
1130 pxor \TMP3, \TMP2 # xor the shifted versions
1131 pxor \TMP4, \TMP2
1132 movdqa \TMP2, \TMP7
1133 psrldq $4, \TMP7 # right shift TMP7 1 DW
1134 pslldq $12, \TMP2 # left shift TMP2 3 DWs
1135 pxor \TMP2, \XMMDst
1136
1137 # second phase of the reduction
1138 movdqa \XMMDst, \TMP2
1139 # make 3 copies of XMMDst for doing 3 shift operations
1140 movdqa \XMMDst, \TMP3
1141 movdqa \XMMDst, \TMP4
1142 psrld $1, \TMP2 # packed left shift >> 1
1143 psrld $2, \TMP3 # packed left shift >> 2
1144 psrld $7, \TMP4 # packed left shift >> 7
1145 pxor \TMP3, \TMP2 # xor the shifted versions
1146 pxor \TMP4, \TMP2
1147 pxor \TMP7, \TMP2
1148 pxor \TMP2, \XMMDst
1149 pxor \TMP6, \XMMDst # reduced result is in XMMDst
1150.endm
1151
1152/* Encryption of a single block done*/
1153.macro ENCRYPT_SINGLE_BLOCK XMM0 TMP1
1154
1155 pxor (%arg1), \XMM0
1156 movaps 16(%arg1), \TMP1
1157 AESENC \TMP1, \XMM0
1158 movaps 32(%arg1), \TMP1
1159 AESENC \TMP1, \XMM0
1160 movaps 48(%arg1), \TMP1
1161 AESENC \TMP1, \XMM0
1162 movaps 64(%arg1), \TMP1
1163 AESENC \TMP1, \XMM0
1164 movaps 80(%arg1), \TMP1
1165 AESENC \TMP1, \XMM0
1166 movaps 96(%arg1), \TMP1
1167 AESENC \TMP1, \XMM0
1168 movaps 112(%arg1), \TMP1
1169 AESENC \TMP1, \XMM0
1170 movaps 128(%arg1), \TMP1
1171 AESENC \TMP1, \XMM0
1172 movaps 144(%arg1), \TMP1
1173 AESENC \TMP1, \XMM0
1174 movaps 160(%arg1), \TMP1
1175 AESENCLAST \TMP1, \XMM0
1176.endm
1177
1178
1179/*****************************************************************************
1180* void aesni_gcm_dec(void *aes_ctx, // AES Key schedule. Starts on a 16 byte boundary.
1181* u8 *out, // Plaintext output. Encrypt in-place is allowed.
1182* const u8 *in, // Ciphertext input
1183* u64 plaintext_len, // Length of data in bytes for decryption.
1184* u8 *iv, // Pre-counter block j0: 4 byte salt (from Security Association)
1185* // concatenated with 8 byte Initialisation Vector (from IPSec ESP Payload)
1186* // concatenated with 0x00000001. 16-byte aligned pointer.
1187* u8 *hash_subkey, // H, the Hash sub key input. Data starts on a 16-byte boundary.
1188* const u8 *aad, // Additional Authentication Data (AAD)
1189* u64 aad_len, // Length of AAD in bytes. With RFC4106 this is going to be 8 or 12 bytes
1190* u8 *auth_tag, // Authenticated Tag output. The driver will compare this to the
1191* // given authentication tag and only return the plaintext if they match.
1192* u64 auth_tag_len); // Authenticated Tag Length in bytes. Valid values are 16
1193* // (most likely), 12 or 8.
1194*
1195* Assumptions:
1196*
1197* keys:
1198* keys are pre-expanded and aligned to 16 bytes. we are using the first
1199* set of 11 keys in the data structure void *aes_ctx
1200*
1201* iv:
1202* 0 1 2 3
1203* 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
1204* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1205* | Salt (From the SA) |
1206* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1207* | Initialization Vector |
1208* | (This is the sequence number from IPSec header) |
1209* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1210* | 0x1 |
1211* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1212*
1213*
1214*
1215* AAD:
1216* AAD padded to 128 bits with 0
1217* for example, assume AAD is a u32 vector
1218*
1219* if AAD is 8 bytes:
1220* AAD[3] = {A0, A1};
1221* padded AAD in xmm register = {A1 A0 0 0}
1222*
1223* 0 1 2 3
1224* 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
1225* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1226* | SPI (A1) |
1227* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1228* | 32-bit Sequence Number (A0) |
1229* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1230* | 0x0 |
1231* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1232*
1233* AAD Format with 32-bit Sequence Number
1234*
1235* if AAD is 12 bytes:
1236* AAD[3] = {A0, A1, A2};
1237* padded AAD in xmm register = {A2 A1 A0 0}
1238*
1239* 0 1 2 3
1240* 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
1241* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1242* 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
1243* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1244* | SPI (A2) |
1245* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1246* | 64-bit Extended Sequence Number {A1,A0} |
1247* | |
1248* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1249* | 0x0 |
1250* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1251*
1252* AAD Format with 64-bit Extended Sequence Number
1253*
1254* aadLen:
1255* from the definition of the spec, aadLen can only be 8 or 12 bytes.
1256* The code supports 16 too but for other sizes, the code will fail.
1257*
1258* TLen:
1259* from the definition of the spec, TLen can only be 8, 12 or 16 bytes.
1260* For other sizes, the code will fail.
1261*
1262* poly = x^128 + x^127 + x^126 + x^121 + 1
1263*
1264*****************************************************************************/
1265
1266ENTRY(aesni_gcm_dec)
1267 push %r12
1268 push %r13
1269 push %r14
1270 mov %rsp, %r14
1271/*
1272* states of %xmm registers %xmm6:%xmm15 not saved
1273* all %xmm registers are clobbered
1274*/
1275 sub $VARIABLE_OFFSET, %rsp
1276 and $~63, %rsp # align rsp to 64 bytes
1277 mov %arg6, %r12
1278 movdqu (%r12), %xmm13 # %xmm13 = HashKey
1279 movdqa SHUF_MASK(%rip), %xmm2
1280 PSHUFB_XMM %xmm2, %xmm13
1281
1282
1283# Precompute HashKey<<1 (mod poly) from the hash key (required for GHASH)
1284
1285 movdqa %xmm13, %xmm2
1286 psllq $1, %xmm13
1287 psrlq $63, %xmm2
1288 movdqa %xmm2, %xmm1
1289 pslldq $8, %xmm2
1290 psrldq $8, %xmm1
1291 por %xmm2, %xmm13
1292
1293 # Reduction
1294
1295 pshufd $0x24, %xmm1, %xmm2
1296 pcmpeqd TWOONE(%rip), %xmm2
1297 pand POLY(%rip), %xmm2
1298 pxor %xmm2, %xmm13 # %xmm13 holds the HashKey<<1 (mod poly)
1299
1300
1301 # Decrypt first few blocks
1302
1303 movdqa %xmm13, HashKey(%rsp) # store HashKey<<1 (mod poly)
1304 mov %arg4, %r13 # save the number of bytes of plaintext/ciphertext
1305 and $-16, %r13 # %r13 = %r13 - (%r13 mod 16)
1306 mov %r13, %r12
1307 and $(3<<4), %r12
1308 jz _initial_num_blocks_is_0_decrypt
1309 cmp $(2<<4), %r12
1310 jb _initial_num_blocks_is_1_decrypt
1311 je _initial_num_blocks_is_2_decrypt
1312_initial_num_blocks_is_3_decrypt:
1313 INITIAL_BLOCKS_DEC 3, %xmm9, %xmm10, %xmm13, %xmm11, %xmm12, %xmm0, \
1314%xmm1, %xmm2, %xmm3, %xmm4, %xmm8, %xmm5, %xmm6, 5, 678, dec
1315 sub $48, %r13
1316 jmp _initial_blocks_decrypted
1317_initial_num_blocks_is_2_decrypt:
1318 INITIAL_BLOCKS_DEC 2, %xmm9, %xmm10, %xmm13, %xmm11, %xmm12, %xmm0, \
1319%xmm1, %xmm2, %xmm3, %xmm4, %xmm8, %xmm5, %xmm6, 6, 78, dec
1320 sub $32, %r13
1321 jmp _initial_blocks_decrypted
1322_initial_num_blocks_is_1_decrypt:
1323 INITIAL_BLOCKS_DEC 1, %xmm9, %xmm10, %xmm13, %xmm11, %xmm12, %xmm0, \
1324%xmm1, %xmm2, %xmm3, %xmm4, %xmm8, %xmm5, %xmm6, 7, 8, dec
1325 sub $16, %r13
1326 jmp _initial_blocks_decrypted
1327_initial_num_blocks_is_0_decrypt:
1328 INITIAL_BLOCKS_DEC 0, %xmm9, %xmm10, %xmm13, %xmm11, %xmm12, %xmm0, \
1329%xmm1, %xmm2, %xmm3, %xmm4, %xmm8, %xmm5, %xmm6, 8, 0, dec
1330_initial_blocks_decrypted:
1331 cmp $0, %r13
1332 je _zero_cipher_left_decrypt
1333 sub $64, %r13
1334 je _four_cipher_left_decrypt
1335_decrypt_by_4:
1336 GHASH_4_ENCRYPT_4_PARALLEL_DEC %xmm9, %xmm10, %xmm11, %xmm12, %xmm13, \
1337%xmm14, %xmm0, %xmm1, %xmm2, %xmm3, %xmm4, %xmm5, %xmm6, %xmm7, %xmm8, dec
1338 add $64, %r11
1339 sub $64, %r13
1340 jne _decrypt_by_4
1341_four_cipher_left_decrypt:
1342 GHASH_LAST_4 %xmm9, %xmm10, %xmm11, %xmm12, %xmm13, %xmm14, \
1343%xmm15, %xmm1, %xmm2, %xmm3, %xmm4, %xmm8
1344_zero_cipher_left_decrypt:
1345 mov %arg4, %r13
1346 and $15, %r13 # %r13 = arg4 (mod 16)
1347 je _multiple_of_16_bytes_decrypt
1348
1349 # Handle the last <16 byte block seperately
1350
1351 paddd ONE(%rip), %xmm0 # increment CNT to get Yn
1352 movdqa SHUF_MASK(%rip), %xmm10
1353 PSHUFB_XMM %xmm10, %xmm0
1354
1355 ENCRYPT_SINGLE_BLOCK %xmm0, %xmm1 # E(K, Yn)
1356 sub $16, %r11
1357 add %r13, %r11
1358 movdqu (%arg3,%r11,1), %xmm1 # recieve the last <16 byte block
1359 lea SHIFT_MASK+16(%rip), %r12
1360 sub %r13, %r12
1361# adjust the shuffle mask pointer to be able to shift 16-%r13 bytes
1362# (%r13 is the number of bytes in plaintext mod 16)
1363 movdqu (%r12), %xmm2 # get the appropriate shuffle mask
1364 PSHUFB_XMM %xmm2, %xmm1 # right shift 16-%r13 butes
1365
1366 movdqa %xmm1, %xmm2
1367 pxor %xmm1, %xmm0 # Ciphertext XOR E(K, Yn)
1368 movdqu ALL_F-SHIFT_MASK(%r12), %xmm1
1369 # get the appropriate mask to mask out top 16-%r13 bytes of %xmm0
1370 pand %xmm1, %xmm0 # mask out top 16-%r13 bytes of %xmm0
1371 pand %xmm1, %xmm2
1372 movdqa SHUF_MASK(%rip), %xmm10
1373 PSHUFB_XMM %xmm10 ,%xmm2
1374
1375 pxor %xmm2, %xmm8
1376 GHASH_MUL %xmm8, %xmm13, %xmm9, %xmm10, %xmm11, %xmm5, %xmm6
1377 # GHASH computation for the last <16 byte block
1378 sub %r13, %r11
1379 add $16, %r11
1380
1381 # output %r13 bytes
1382 MOVQ_R64_XMM %xmm0, %rax
1383 cmp $8, %r13
1384 jle _less_than_8_bytes_left_decrypt
1385 mov %rax, (%arg2 , %r11, 1)
1386 add $8, %r11
1387 psrldq $8, %xmm0
1388 MOVQ_R64_XMM %xmm0, %rax
1389 sub $8, %r13
1390_less_than_8_bytes_left_decrypt:
1391 mov %al, (%arg2, %r11, 1)
1392 add $1, %r11
1393 shr $8, %rax
1394 sub $1, %r13
1395 jne _less_than_8_bytes_left_decrypt
1396_multiple_of_16_bytes_decrypt:
1397 mov arg8, %r12 # %r13 = aadLen (number of bytes)
1398 shl $3, %r12 # convert into number of bits
1399 movd %r12d, %xmm15 # len(A) in %xmm15
1400 shl $3, %arg4 # len(C) in bits (*128)
1401 MOVQ_R64_XMM %arg4, %xmm1
1402 pslldq $8, %xmm15 # %xmm15 = len(A)||0x0000000000000000
1403 pxor %xmm1, %xmm15 # %xmm15 = len(A)||len(C)
1404 pxor %xmm15, %xmm8
1405 GHASH_MUL %xmm8, %xmm13, %xmm9, %xmm10, %xmm11, %xmm5, %xmm6
1406 # final GHASH computation
1407 movdqa SHUF_MASK(%rip), %xmm10
1408 PSHUFB_XMM %xmm10, %xmm8
1409
1410 mov %arg5, %rax # %rax = *Y0
1411 movdqu (%rax), %xmm0 # %xmm0 = Y0
1412 ENCRYPT_SINGLE_BLOCK %xmm0, %xmm1 # E(K, Y0)
1413 pxor %xmm8, %xmm0
1414_return_T_decrypt:
1415 mov arg9, %r10 # %r10 = authTag
1416 mov arg10, %r11 # %r11 = auth_tag_len
1417 cmp $16, %r11
1418 je _T_16_decrypt
1419 cmp $12, %r11
1420 je _T_12_decrypt
1421_T_8_decrypt:
1422 MOVQ_R64_XMM %xmm0, %rax
1423 mov %rax, (%r10)
1424 jmp _return_T_done_decrypt
1425_T_12_decrypt:
1426 MOVQ_R64_XMM %xmm0, %rax
1427 mov %rax, (%r10)
1428 psrldq $8, %xmm0
1429 movd %xmm0, %eax
1430 mov %eax, 8(%r10)
1431 jmp _return_T_done_decrypt
1432_T_16_decrypt:
1433 movdqu %xmm0, (%r10)
1434_return_T_done_decrypt:
1435 mov %r14, %rsp
1436 pop %r14
1437 pop %r13
1438 pop %r12
1439 ret
1440
1441
1442/*****************************************************************************
1443* void aesni_gcm_enc(void *aes_ctx, // AES Key schedule. Starts on a 16 byte boundary.
1444* u8 *out, // Ciphertext output. Encrypt in-place is allowed.
1445* const u8 *in, // Plaintext input
1446* u64 plaintext_len, // Length of data in bytes for encryption.
1447* u8 *iv, // Pre-counter block j0: 4 byte salt (from Security Association)
1448* // concatenated with 8 byte Initialisation Vector (from IPSec ESP Payload)
1449* // concatenated with 0x00000001. 16-byte aligned pointer.
1450* u8 *hash_subkey, // H, the Hash sub key input. Data starts on a 16-byte boundary.
1451* const u8 *aad, // Additional Authentication Data (AAD)
1452* u64 aad_len, // Length of AAD in bytes. With RFC4106 this is going to be 8 or 12 bytes
1453* u8 *auth_tag, // Authenticated Tag output.
1454* u64 auth_tag_len); // Authenticated Tag Length in bytes. Valid values are 16 (most likely),
1455* // 12 or 8.
1456*
1457* Assumptions:
1458*
1459* keys:
1460* keys are pre-expanded and aligned to 16 bytes. we are using the
1461* first set of 11 keys in the data structure void *aes_ctx
1462*
1463*
1464* iv:
1465* 0 1 2 3
1466* 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
1467* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1468* | Salt (From the SA) |
1469* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1470* | Initialization Vector |
1471* | (This is the sequence number from IPSec header) |
1472* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1473* | 0x1 |
1474* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1475*
1476*
1477*
1478* AAD:
1479* AAD padded to 128 bits with 0
1480* for example, assume AAD is a u32 vector
1481*
1482* if AAD is 8 bytes:
1483* AAD[3] = {A0, A1};
1484* padded AAD in xmm register = {A1 A0 0 0}
1485*
1486* 0 1 2 3
1487* 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
1488* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1489* | SPI (A1) |
1490* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1491* | 32-bit Sequence Number (A0) |
1492* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1493* | 0x0 |
1494* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1495*
1496* AAD Format with 32-bit Sequence Number
1497*
1498* if AAD is 12 bytes:
1499* AAD[3] = {A0, A1, A2};
1500* padded AAD in xmm register = {A2 A1 A0 0}
1501*
1502* 0 1 2 3
1503* 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
1504* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1505* | SPI (A2) |
1506* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1507* | 64-bit Extended Sequence Number {A1,A0} |
1508* | |
1509* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1510* | 0x0 |
1511* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1512*
1513* AAD Format with 64-bit Extended Sequence Number
1514*
1515* aadLen:
1516* from the definition of the spec, aadLen can only be 8 or 12 bytes.
1517* The code supports 16 too but for other sizes, the code will fail.
1518*
1519* TLen:
1520* from the definition of the spec, TLen can only be 8, 12 or 16 bytes.
1521* For other sizes, the code will fail.
1522*
1523* poly = x^128 + x^127 + x^126 + x^121 + 1
1524***************************************************************************/
1525ENTRY(aesni_gcm_enc)
1526 push %r12
1527 push %r13
1528 push %r14
1529 mov %rsp, %r14
1530#
1531# states of %xmm registers %xmm6:%xmm15 not saved
1532# all %xmm registers are clobbered
1533#
1534 sub $VARIABLE_OFFSET, %rsp
1535 and $~63, %rsp
1536 mov %arg6, %r12
1537 movdqu (%r12), %xmm13
1538 movdqa SHUF_MASK(%rip), %xmm2
1539 PSHUFB_XMM %xmm2, %xmm13
1540
1541
1542# precompute HashKey<<1 mod poly from the HashKey (required for GHASH)
1543
1544 movdqa %xmm13, %xmm2
1545 psllq $1, %xmm13
1546 psrlq $63, %xmm2
1547 movdqa %xmm2, %xmm1
1548 pslldq $8, %xmm2
1549 psrldq $8, %xmm1
1550 por %xmm2, %xmm13
1551
1552 # reduce HashKey<<1
1553
1554 pshufd $0x24, %xmm1, %xmm2
1555 pcmpeqd TWOONE(%rip), %xmm2
1556 pand POLY(%rip), %xmm2
1557 pxor %xmm2, %xmm13
1558 movdqa %xmm13, HashKey(%rsp)
1559 mov %arg4, %r13 # %xmm13 holds HashKey<<1 (mod poly)
1560 and $-16, %r13
1561 mov %r13, %r12
1562
1563 # Encrypt first few blocks
1564
1565 and $(3<<4), %r12
1566 jz _initial_num_blocks_is_0_encrypt
1567 cmp $(2<<4), %r12
1568 jb _initial_num_blocks_is_1_encrypt
1569 je _initial_num_blocks_is_2_encrypt
1570_initial_num_blocks_is_3_encrypt:
1571 INITIAL_BLOCKS_ENC 3, %xmm9, %xmm10, %xmm13, %xmm11, %xmm12, %xmm0, \
1572%xmm1, %xmm2, %xmm3, %xmm4, %xmm8, %xmm5, %xmm6, 5, 678, enc
1573 sub $48, %r13
1574 jmp _initial_blocks_encrypted
1575_initial_num_blocks_is_2_encrypt:
1576 INITIAL_BLOCKS_ENC 2, %xmm9, %xmm10, %xmm13, %xmm11, %xmm12, %xmm0, \
1577%xmm1, %xmm2, %xmm3, %xmm4, %xmm8, %xmm5, %xmm6, 6, 78, enc
1578 sub $32, %r13
1579 jmp _initial_blocks_encrypted
1580_initial_num_blocks_is_1_encrypt:
1581 INITIAL_BLOCKS_ENC 1, %xmm9, %xmm10, %xmm13, %xmm11, %xmm12, %xmm0, \
1582%xmm1, %xmm2, %xmm3, %xmm4, %xmm8, %xmm5, %xmm6, 7, 8, enc
1583 sub $16, %r13
1584 jmp _initial_blocks_encrypted
1585_initial_num_blocks_is_0_encrypt:
1586 INITIAL_BLOCKS_ENC 0, %xmm9, %xmm10, %xmm13, %xmm11, %xmm12, %xmm0, \
1587%xmm1, %xmm2, %xmm3, %xmm4, %xmm8, %xmm5, %xmm6, 8, 0, enc
1588_initial_blocks_encrypted:
1589
1590 # Main loop - Encrypt remaining blocks
1591
1592 cmp $0, %r13
1593 je _zero_cipher_left_encrypt
1594 sub $64, %r13
1595 je _four_cipher_left_encrypt
1596_encrypt_by_4_encrypt:
1597 GHASH_4_ENCRYPT_4_PARALLEL_ENC %xmm9, %xmm10, %xmm11, %xmm12, %xmm13, \
1598%xmm14, %xmm0, %xmm1, %xmm2, %xmm3, %xmm4, %xmm5, %xmm6, %xmm7, %xmm8, enc
1599 add $64, %r11
1600 sub $64, %r13
1601 jne _encrypt_by_4_encrypt
1602_four_cipher_left_encrypt:
1603 GHASH_LAST_4 %xmm9, %xmm10, %xmm11, %xmm12, %xmm13, %xmm14, \
1604%xmm15, %xmm1, %xmm2, %xmm3, %xmm4, %xmm8
1605_zero_cipher_left_encrypt:
1606 mov %arg4, %r13
1607 and $15, %r13 # %r13 = arg4 (mod 16)
1608 je _multiple_of_16_bytes_encrypt
1609
1610 # Handle the last <16 Byte block seperately
1611 paddd ONE(%rip), %xmm0 # INCR CNT to get Yn
1612 movdqa SHUF_MASK(%rip), %xmm10
1613 PSHUFB_XMM %xmm10, %xmm0
1614
1615 ENCRYPT_SINGLE_BLOCK %xmm0, %xmm1 # Encrypt(K, Yn)
1616 sub $16, %r11
1617 add %r13, %r11
1618 movdqu (%arg3,%r11,1), %xmm1 # receive the last <16 byte blocks
1619 lea SHIFT_MASK+16(%rip), %r12
1620 sub %r13, %r12
1621 # adjust the shuffle mask pointer to be able to shift 16-r13 bytes
1622 # (%r13 is the number of bytes in plaintext mod 16)
1623 movdqu (%r12), %xmm2 # get the appropriate shuffle mask
1624 PSHUFB_XMM %xmm2, %xmm1 # shift right 16-r13 byte
1625 pxor %xmm1, %xmm0 # Plaintext XOR Encrypt(K, Yn)
1626 movdqu ALL_F-SHIFT_MASK(%r12), %xmm1
1627 # get the appropriate mask to mask out top 16-r13 bytes of xmm0
1628 pand %xmm1, %xmm0 # mask out top 16-r13 bytes of xmm0
1629 movdqa SHUF_MASK(%rip), %xmm10
1630 PSHUFB_XMM %xmm10,%xmm0
1631
1632 pxor %xmm0, %xmm8
1633 GHASH_MUL %xmm8, %xmm13, %xmm9, %xmm10, %xmm11, %xmm5, %xmm6
1634 # GHASH computation for the last <16 byte block
1635 sub %r13, %r11
1636 add $16, %r11
1637 PSHUFB_XMM %xmm10, %xmm1
1638
1639 # shuffle xmm0 back to output as ciphertext
1640
1641 # Output %r13 bytes
1642 MOVQ_R64_XMM %xmm0, %rax
1643 cmp $8, %r13
1644 jle _less_than_8_bytes_left_encrypt
1645 mov %rax, (%arg2 , %r11, 1)
1646 add $8, %r11
1647 psrldq $8, %xmm0
1648 MOVQ_R64_XMM %xmm0, %rax
1649 sub $8, %r13
1650_less_than_8_bytes_left_encrypt:
1651 mov %al, (%arg2, %r11, 1)
1652 add $1, %r11
1653 shr $8, %rax
1654 sub $1, %r13
1655 jne _less_than_8_bytes_left_encrypt
1656_multiple_of_16_bytes_encrypt:
1657 mov arg8, %r12 # %r12 = addLen (number of bytes)
1658 shl $3, %r12
1659 movd %r12d, %xmm15 # len(A) in %xmm15
1660 shl $3, %arg4 # len(C) in bits (*128)
1661 MOVQ_R64_XMM %arg4, %xmm1
1662 pslldq $8, %xmm15 # %xmm15 = len(A)||0x0000000000000000
1663 pxor %xmm1, %xmm15 # %xmm15 = len(A)||len(C)
1664 pxor %xmm15, %xmm8
1665 GHASH_MUL %xmm8, %xmm13, %xmm9, %xmm10, %xmm11, %xmm5, %xmm6
1666 # final GHASH computation
1667 movdqa SHUF_MASK(%rip), %xmm10
1668 PSHUFB_XMM %xmm10, %xmm8 # perform a 16 byte swap
1669
1670 mov %arg5, %rax # %rax = *Y0
1671 movdqu (%rax), %xmm0 # %xmm0 = Y0
1672 ENCRYPT_SINGLE_BLOCK %xmm0, %xmm15 # Encrypt(K, Y0)
1673 pxor %xmm8, %xmm0
1674_return_T_encrypt:
1675 mov arg9, %r10 # %r10 = authTag
1676 mov arg10, %r11 # %r11 = auth_tag_len
1677 cmp $16, %r11
1678 je _T_16_encrypt
1679 cmp $12, %r11
1680 je _T_12_encrypt
1681_T_8_encrypt:
1682 MOVQ_R64_XMM %xmm0, %rax
1683 mov %rax, (%r10)
1684 jmp _return_T_done_encrypt
1685_T_12_encrypt:
1686 MOVQ_R64_XMM %xmm0, %rax
1687 mov %rax, (%r10)
1688 psrldq $8, %xmm0
1689 movd %xmm0, %eax
1690 mov %eax, 8(%r10)
1691 jmp _return_T_done_encrypt
1692_T_16_encrypt:
1693 movdqu %xmm0, (%r10)
1694_return_T_done_encrypt:
1695 mov %r14, %rsp
1696 pop %r14
1697 pop %r13
1698 pop %r12
1699 ret
1700
1701#endif
1702
49 1703
50_key_expansion_128: 1704_key_expansion_128:
51_key_expansion_256a: 1705_key_expansion_256a:
@@ -55,10 +1709,11 @@ _key_expansion_256a:
55 shufps $0b10001100, %xmm0, %xmm4 1709 shufps $0b10001100, %xmm0, %xmm4
56 pxor %xmm4, %xmm0 1710 pxor %xmm4, %xmm0
57 pxor %xmm1, %xmm0 1711 pxor %xmm1, %xmm0
58 movaps %xmm0, (%rcx) 1712 movaps %xmm0, (TKEYP)
59 add $0x10, %rcx 1713 add $0x10, TKEYP
60 ret 1714 ret
61 1715
1716.align 4
62_key_expansion_192a: 1717_key_expansion_192a:
63 pshufd $0b01010101, %xmm1, %xmm1 1718 pshufd $0b01010101, %xmm1, %xmm1
64 shufps $0b00010000, %xmm0, %xmm4 1719 shufps $0b00010000, %xmm0, %xmm4
@@ -76,12 +1731,13 @@ _key_expansion_192a:
76 1731
77 movaps %xmm0, %xmm1 1732 movaps %xmm0, %xmm1
78 shufps $0b01000100, %xmm0, %xmm6 1733 shufps $0b01000100, %xmm0, %xmm6
79 movaps %xmm6, (%rcx) 1734 movaps %xmm6, (TKEYP)
80 shufps $0b01001110, %xmm2, %xmm1 1735 shufps $0b01001110, %xmm2, %xmm1
81 movaps %xmm1, 16(%rcx) 1736 movaps %xmm1, 0x10(TKEYP)
82 add $0x20, %rcx 1737 add $0x20, TKEYP
83 ret 1738 ret
84 1739
1740.align 4
85_key_expansion_192b: 1741_key_expansion_192b:
86 pshufd $0b01010101, %xmm1, %xmm1 1742 pshufd $0b01010101, %xmm1, %xmm1
87 shufps $0b00010000, %xmm0, %xmm4 1743 shufps $0b00010000, %xmm0, %xmm4
@@ -96,10 +1752,11 @@ _key_expansion_192b:
96 pxor %xmm3, %xmm2 1752 pxor %xmm3, %xmm2
97 pxor %xmm5, %xmm2 1753 pxor %xmm5, %xmm2
98 1754
99 movaps %xmm0, (%rcx) 1755 movaps %xmm0, (TKEYP)
100 add $0x10, %rcx 1756 add $0x10, TKEYP
101 ret 1757 ret
102 1758
1759.align 4
103_key_expansion_256b: 1760_key_expansion_256b:
104 pshufd $0b10101010, %xmm1, %xmm1 1761 pshufd $0b10101010, %xmm1, %xmm1
105 shufps $0b00010000, %xmm2, %xmm4 1762 shufps $0b00010000, %xmm2, %xmm4
@@ -107,8 +1764,8 @@ _key_expansion_256b:
107 shufps $0b10001100, %xmm2, %xmm4 1764 shufps $0b10001100, %xmm2, %xmm4
108 pxor %xmm4, %xmm2 1765 pxor %xmm4, %xmm2
109 pxor %xmm1, %xmm2 1766 pxor %xmm1, %xmm2
110 movaps %xmm2, (%rcx) 1767 movaps %xmm2, (TKEYP)
111 add $0x10, %rcx 1768 add $0x10, TKEYP
112 ret 1769 ret
113 1770
114/* 1771/*
@@ -116,17 +1773,23 @@ _key_expansion_256b:
116 * unsigned int key_len) 1773 * unsigned int key_len)
117 */ 1774 */
118ENTRY(aesni_set_key) 1775ENTRY(aesni_set_key)
119 movups (%rsi), %xmm0 # user key (first 16 bytes) 1776#ifndef __x86_64__
120 movaps %xmm0, (%rdi) 1777 pushl KEYP
121 lea 0x10(%rdi), %rcx # key addr 1778 movl 8(%esp), KEYP # ctx
122 movl %edx, 480(%rdi) 1779 movl 12(%esp), UKEYP # in_key
1780 movl 16(%esp), %edx # key_len
1781#endif
1782 movups (UKEYP), %xmm0 # user key (first 16 bytes)
1783 movaps %xmm0, (KEYP)
1784 lea 0x10(KEYP), TKEYP # key addr
1785 movl %edx, 480(KEYP)
123 pxor %xmm4, %xmm4 # xmm4 is assumed 0 in _key_expansion_x 1786 pxor %xmm4, %xmm4 # xmm4 is assumed 0 in _key_expansion_x
124 cmp $24, %dl 1787 cmp $24, %dl
125 jb .Lenc_key128 1788 jb .Lenc_key128
126 je .Lenc_key192 1789 je .Lenc_key192
127 movups 0x10(%rsi), %xmm2 # other user key 1790 movups 0x10(UKEYP), %xmm2 # other user key
128 movaps %xmm2, (%rcx) 1791 movaps %xmm2, (TKEYP)
129 add $0x10, %rcx 1792 add $0x10, TKEYP
130 AESKEYGENASSIST 0x1 %xmm2 %xmm1 # round 1 1793 AESKEYGENASSIST 0x1 %xmm2 %xmm1 # round 1
131 call _key_expansion_256a 1794 call _key_expansion_256a
132 AESKEYGENASSIST 0x1 %xmm0 %xmm1 1795 AESKEYGENASSIST 0x1 %xmm0 %xmm1
@@ -155,7 +1818,7 @@ ENTRY(aesni_set_key)
155 call _key_expansion_256a 1818 call _key_expansion_256a
156 jmp .Ldec_key 1819 jmp .Ldec_key
157.Lenc_key192: 1820.Lenc_key192:
158 movq 0x10(%rsi), %xmm2 # other user key 1821 movq 0x10(UKEYP), %xmm2 # other user key
159 AESKEYGENASSIST 0x1 %xmm2 %xmm1 # round 1 1822 AESKEYGENASSIST 0x1 %xmm2 %xmm1 # round 1
160 call _key_expansion_192a 1823 call _key_expansion_192a
161 AESKEYGENASSIST 0x2 %xmm2 %xmm1 # round 2 1824 AESKEYGENASSIST 0x2 %xmm2 %xmm1 # round 2
@@ -195,33 +1858,47 @@ ENTRY(aesni_set_key)
195 AESKEYGENASSIST 0x36 %xmm0 %xmm1 # round 10 1858 AESKEYGENASSIST 0x36 %xmm0 %xmm1 # round 10
196 call _key_expansion_128 1859 call _key_expansion_128
197.Ldec_key: 1860.Ldec_key:
198 sub $0x10, %rcx 1861 sub $0x10, TKEYP
199 movaps (%rdi), %xmm0 1862 movaps (KEYP), %xmm0
200 movaps (%rcx), %xmm1 1863 movaps (TKEYP), %xmm1
201 movaps %xmm0, 240(%rcx) 1864 movaps %xmm0, 240(TKEYP)
202 movaps %xmm1, 240(%rdi) 1865 movaps %xmm1, 240(KEYP)
203 add $0x10, %rdi 1866 add $0x10, KEYP
204 lea 240-16(%rcx), %rsi 1867 lea 240-16(TKEYP), UKEYP
205.align 4 1868.align 4
206.Ldec_key_loop: 1869.Ldec_key_loop:
207 movaps (%rdi), %xmm0 1870 movaps (KEYP), %xmm0
208 AESIMC %xmm0 %xmm1 1871 AESIMC %xmm0 %xmm1
209 movaps %xmm1, (%rsi) 1872 movaps %xmm1, (UKEYP)
210 add $0x10, %rdi 1873 add $0x10, KEYP
211 sub $0x10, %rsi 1874 sub $0x10, UKEYP
212 cmp %rcx, %rdi 1875 cmp TKEYP, KEYP
213 jb .Ldec_key_loop 1876 jb .Ldec_key_loop
214 xor %rax, %rax 1877 xor AREG, AREG
1878#ifndef __x86_64__
1879 popl KEYP
1880#endif
215 ret 1881 ret
216 1882
217/* 1883/*
218 * void aesni_enc(struct crypto_aes_ctx *ctx, u8 *dst, const u8 *src) 1884 * void aesni_enc(struct crypto_aes_ctx *ctx, u8 *dst, const u8 *src)
219 */ 1885 */
220ENTRY(aesni_enc) 1886ENTRY(aesni_enc)
1887#ifndef __x86_64__
1888 pushl KEYP
1889 pushl KLEN
1890 movl 12(%esp), KEYP
1891 movl 16(%esp), OUTP
1892 movl 20(%esp), INP
1893#endif
221 movl 480(KEYP), KLEN # key length 1894 movl 480(KEYP), KLEN # key length
222 movups (INP), STATE # input 1895 movups (INP), STATE # input
223 call _aesni_enc1 1896 call _aesni_enc1
224 movups STATE, (OUTP) # output 1897 movups STATE, (OUTP) # output
1898#ifndef __x86_64__
1899 popl KLEN
1900 popl KEYP
1901#endif
225 ret 1902 ret
226 1903
227/* 1904/*
@@ -236,6 +1913,7 @@ ENTRY(aesni_enc)
236 * KEY 1913 * KEY
237 * TKEYP (T1) 1914 * TKEYP (T1)
238 */ 1915 */
1916.align 4
239_aesni_enc1: 1917_aesni_enc1:
240 movaps (KEYP), KEY # key 1918 movaps (KEYP), KEY # key
241 mov KEYP, TKEYP 1919 mov KEYP, TKEYP
@@ -298,6 +1976,7 @@ _aesni_enc1:
298 * KEY 1976 * KEY
299 * TKEYP (T1) 1977 * TKEYP (T1)
300 */ 1978 */
1979.align 4
301_aesni_enc4: 1980_aesni_enc4:
302 movaps (KEYP), KEY # key 1981 movaps (KEYP), KEY # key
303 mov KEYP, TKEYP 1982 mov KEYP, TKEYP
@@ -391,11 +2070,22 @@ _aesni_enc4:
391 * void aesni_dec (struct crypto_aes_ctx *ctx, u8 *dst, const u8 *src) 2070 * void aesni_dec (struct crypto_aes_ctx *ctx, u8 *dst, const u8 *src)
392 */ 2071 */
393ENTRY(aesni_dec) 2072ENTRY(aesni_dec)
2073#ifndef __x86_64__
2074 pushl KEYP
2075 pushl KLEN
2076 movl 12(%esp), KEYP
2077 movl 16(%esp), OUTP
2078 movl 20(%esp), INP
2079#endif
394 mov 480(KEYP), KLEN # key length 2080 mov 480(KEYP), KLEN # key length
395 add $240, KEYP 2081 add $240, KEYP
396 movups (INP), STATE # input 2082 movups (INP), STATE # input
397 call _aesni_dec1 2083 call _aesni_dec1
398 movups STATE, (OUTP) #output 2084 movups STATE, (OUTP) #output
2085#ifndef __x86_64__
2086 popl KLEN
2087 popl KEYP
2088#endif
399 ret 2089 ret
400 2090
401/* 2091/*
@@ -410,6 +2100,7 @@ ENTRY(aesni_dec)
410 * KEY 2100 * KEY
411 * TKEYP (T1) 2101 * TKEYP (T1)
412 */ 2102 */
2103.align 4
413_aesni_dec1: 2104_aesni_dec1:
414 movaps (KEYP), KEY # key 2105 movaps (KEYP), KEY # key
415 mov KEYP, TKEYP 2106 mov KEYP, TKEYP
@@ -472,6 +2163,7 @@ _aesni_dec1:
472 * KEY 2163 * KEY
473 * TKEYP (T1) 2164 * TKEYP (T1)
474 */ 2165 */
2166.align 4
475_aesni_dec4: 2167_aesni_dec4:
476 movaps (KEYP), KEY # key 2168 movaps (KEYP), KEY # key
477 mov KEYP, TKEYP 2169 mov KEYP, TKEYP
@@ -566,6 +2258,15 @@ _aesni_dec4:
566 * size_t len) 2258 * size_t len)
567 */ 2259 */
568ENTRY(aesni_ecb_enc) 2260ENTRY(aesni_ecb_enc)
2261#ifndef __x86_64__
2262 pushl LEN
2263 pushl KEYP
2264 pushl KLEN
2265 movl 16(%esp), KEYP
2266 movl 20(%esp), OUTP
2267 movl 24(%esp), INP
2268 movl 28(%esp), LEN
2269#endif
569 test LEN, LEN # check length 2270 test LEN, LEN # check length
570 jz .Lecb_enc_ret 2271 jz .Lecb_enc_ret
571 mov 480(KEYP), KLEN 2272 mov 480(KEYP), KLEN
@@ -602,6 +2303,11 @@ ENTRY(aesni_ecb_enc)
602 cmp $16, LEN 2303 cmp $16, LEN
603 jge .Lecb_enc_loop1 2304 jge .Lecb_enc_loop1
604.Lecb_enc_ret: 2305.Lecb_enc_ret:
2306#ifndef __x86_64__
2307 popl KLEN
2308 popl KEYP
2309 popl LEN
2310#endif
605 ret 2311 ret
606 2312
607/* 2313/*
@@ -609,6 +2315,15 @@ ENTRY(aesni_ecb_enc)
609 * size_t len); 2315 * size_t len);
610 */ 2316 */
611ENTRY(aesni_ecb_dec) 2317ENTRY(aesni_ecb_dec)
2318#ifndef __x86_64__
2319 pushl LEN
2320 pushl KEYP
2321 pushl KLEN
2322 movl 16(%esp), KEYP
2323 movl 20(%esp), OUTP
2324 movl 24(%esp), INP
2325 movl 28(%esp), LEN
2326#endif
612 test LEN, LEN 2327 test LEN, LEN
613 jz .Lecb_dec_ret 2328 jz .Lecb_dec_ret
614 mov 480(KEYP), KLEN 2329 mov 480(KEYP), KLEN
@@ -646,6 +2361,11 @@ ENTRY(aesni_ecb_dec)
646 cmp $16, LEN 2361 cmp $16, LEN
647 jge .Lecb_dec_loop1 2362 jge .Lecb_dec_loop1
648.Lecb_dec_ret: 2363.Lecb_dec_ret:
2364#ifndef __x86_64__
2365 popl KLEN
2366 popl KEYP
2367 popl LEN
2368#endif
649 ret 2369 ret
650 2370
651/* 2371/*
@@ -653,6 +2373,17 @@ ENTRY(aesni_ecb_dec)
653 * size_t len, u8 *iv) 2373 * size_t len, u8 *iv)
654 */ 2374 */
655ENTRY(aesni_cbc_enc) 2375ENTRY(aesni_cbc_enc)
2376#ifndef __x86_64__
2377 pushl IVP
2378 pushl LEN
2379 pushl KEYP
2380 pushl KLEN
2381 movl 20(%esp), KEYP
2382 movl 24(%esp), OUTP
2383 movl 28(%esp), INP
2384 movl 32(%esp), LEN
2385 movl 36(%esp), IVP
2386#endif
656 cmp $16, LEN 2387 cmp $16, LEN
657 jb .Lcbc_enc_ret 2388 jb .Lcbc_enc_ret
658 mov 480(KEYP), KLEN 2389 mov 480(KEYP), KLEN
@@ -670,6 +2401,12 @@ ENTRY(aesni_cbc_enc)
670 jge .Lcbc_enc_loop 2401 jge .Lcbc_enc_loop
671 movups STATE, (IVP) 2402 movups STATE, (IVP)
672.Lcbc_enc_ret: 2403.Lcbc_enc_ret:
2404#ifndef __x86_64__
2405 popl KLEN
2406 popl KEYP
2407 popl LEN
2408 popl IVP
2409#endif
673 ret 2410 ret
674 2411
675/* 2412/*
@@ -677,6 +2414,17 @@ ENTRY(aesni_cbc_enc)
677 * size_t len, u8 *iv) 2414 * size_t len, u8 *iv)
678 */ 2415 */
679ENTRY(aesni_cbc_dec) 2416ENTRY(aesni_cbc_dec)
2417#ifndef __x86_64__
2418 pushl IVP
2419 pushl LEN
2420 pushl KEYP
2421 pushl KLEN
2422 movl 20(%esp), KEYP
2423 movl 24(%esp), OUTP
2424 movl 28(%esp), INP
2425 movl 32(%esp), LEN
2426 movl 36(%esp), IVP
2427#endif
680 cmp $16, LEN 2428 cmp $16, LEN
681 jb .Lcbc_dec_just_ret 2429 jb .Lcbc_dec_just_ret
682 mov 480(KEYP), KLEN 2430 mov 480(KEYP), KLEN
@@ -690,16 +2438,30 @@ ENTRY(aesni_cbc_dec)
690 movaps IN1, STATE1 2438 movaps IN1, STATE1
691 movups 0x10(INP), IN2 2439 movups 0x10(INP), IN2
692 movaps IN2, STATE2 2440 movaps IN2, STATE2
2441#ifdef __x86_64__
693 movups 0x20(INP), IN3 2442 movups 0x20(INP), IN3
694 movaps IN3, STATE3 2443 movaps IN3, STATE3
695 movups 0x30(INP), IN4 2444 movups 0x30(INP), IN4
696 movaps IN4, STATE4 2445 movaps IN4, STATE4
2446#else
2447 movups 0x20(INP), IN1
2448 movaps IN1, STATE3
2449 movups 0x30(INP), IN2
2450 movaps IN2, STATE4
2451#endif
697 call _aesni_dec4 2452 call _aesni_dec4
698 pxor IV, STATE1 2453 pxor IV, STATE1
2454#ifdef __x86_64__
699 pxor IN1, STATE2 2455 pxor IN1, STATE2
700 pxor IN2, STATE3 2456 pxor IN2, STATE3
701 pxor IN3, STATE4 2457 pxor IN3, STATE4
702 movaps IN4, IV 2458 movaps IN4, IV
2459#else
2460 pxor (INP), STATE2
2461 pxor 0x10(INP), STATE3
2462 pxor IN1, STATE4
2463 movaps IN2, IV
2464#endif
703 movups STATE1, (OUTP) 2465 movups STATE1, (OUTP)
704 movups STATE2, 0x10(OUTP) 2466 movups STATE2, 0x10(OUTP)
705 movups STATE3, 0x20(OUTP) 2467 movups STATE3, 0x20(OUTP)
@@ -727,8 +2489,15 @@ ENTRY(aesni_cbc_dec)
727.Lcbc_dec_ret: 2489.Lcbc_dec_ret:
728 movups IV, (IVP) 2490 movups IV, (IVP)
729.Lcbc_dec_just_ret: 2491.Lcbc_dec_just_ret:
2492#ifndef __x86_64__
2493 popl KLEN
2494 popl KEYP
2495 popl LEN
2496 popl IVP
2497#endif
730 ret 2498 ret
731 2499
2500#ifdef __x86_64__
732.align 16 2501.align 16
733.Lbswap_mask: 2502.Lbswap_mask:
734 .byte 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0 2503 .byte 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0
@@ -744,6 +2513,7 @@ ENTRY(aesni_cbc_dec)
744 * INC: == 1, in little endian 2513 * INC: == 1, in little endian
745 * BSWAP_MASK == endian swapping mask 2514 * BSWAP_MASK == endian swapping mask
746 */ 2515 */
2516.align 4
747_aesni_inc_init: 2517_aesni_inc_init:
748 movaps .Lbswap_mask, BSWAP_MASK 2518 movaps .Lbswap_mask, BSWAP_MASK
749 movaps IV, CTR 2519 movaps IV, CTR
@@ -768,6 +2538,7 @@ _aesni_inc_init:
768 * CTR: == output IV, in little endian 2538 * CTR: == output IV, in little endian
769 * TCTR_LOW: == lower qword of CTR 2539 * TCTR_LOW: == lower qword of CTR
770 */ 2540 */
2541.align 4
771_aesni_inc: 2542_aesni_inc:
772 paddq INC, CTR 2543 paddq INC, CTR
773 add $1, TCTR_LOW 2544 add $1, TCTR_LOW
@@ -839,3 +2610,4 @@ ENTRY(aesni_ctr_enc)
839 movups IV, (IVP) 2610 movups IV, (IVP)
840.Lctr_enc_just_ret: 2611.Lctr_enc_just_ret:
841 ret 2612 ret
2613#endif
diff --git a/arch/x86/crypto/aesni-intel_glue.c b/arch/x86/crypto/aesni-intel_glue.c
index 2cb3dcc4490a..e1e60c7d5813 100644
--- a/arch/x86/crypto/aesni-intel_glue.c
+++ b/arch/x86/crypto/aesni-intel_glue.c
@@ -5,6 +5,14 @@
5 * Copyright (C) 2008, Intel Corp. 5 * Copyright (C) 2008, Intel Corp.
6 * Author: Huang Ying <ying.huang@intel.com> 6 * Author: Huang Ying <ying.huang@intel.com>
7 * 7 *
8 * Added RFC4106 AES-GCM support for 128-bit keys under the AEAD
9 * interface for 64-bit kernels.
10 * Authors: Adrian Hoban <adrian.hoban@intel.com>
11 * Gabriele Paoloni <gabriele.paoloni@intel.com>
12 * Tadeusz Struk (tadeusz.struk@intel.com)
13 * Aidan O'Mahony (aidan.o.mahony@intel.com)
14 * Copyright (c) 2010, Intel Corporation.
15 *
8 * This program is free software; you can redistribute it and/or modify 16 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by 17 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or 18 * the Free Software Foundation; either version 2 of the License, or
@@ -21,6 +29,10 @@
21#include <crypto/ctr.h> 29#include <crypto/ctr.h>
22#include <asm/i387.h> 30#include <asm/i387.h>
23#include <asm/aes.h> 31#include <asm/aes.h>
32#include <crypto/scatterwalk.h>
33#include <crypto/internal/aead.h>
34#include <linux/workqueue.h>
35#include <linux/spinlock.h>
24 36
25#if defined(CONFIG_CRYPTO_CTR) || defined(CONFIG_CRYPTO_CTR_MODULE) 37#if defined(CONFIG_CRYPTO_CTR) || defined(CONFIG_CRYPTO_CTR_MODULE)
26#define HAS_CTR 38#define HAS_CTR
@@ -42,8 +54,31 @@ struct async_aes_ctx {
42 struct cryptd_ablkcipher *cryptd_tfm; 54 struct cryptd_ablkcipher *cryptd_tfm;
43}; 55};
44 56
45#define AESNI_ALIGN 16 57/* This data is stored at the end of the crypto_tfm struct.
58 * It's a type of per "session" data storage location.
59 * This needs to be 16 byte aligned.
60 */
61struct aesni_rfc4106_gcm_ctx {
62 u8 hash_subkey[16];
63 struct crypto_aes_ctx aes_key_expanded;
64 u8 nonce[4];
65 struct cryptd_aead *cryptd_tfm;
66};
67
68struct aesni_gcm_set_hash_subkey_result {
69 int err;
70 struct completion completion;
71};
72
73struct aesni_hash_subkey_req_data {
74 u8 iv[16];
75 struct aesni_gcm_set_hash_subkey_result result;
76 struct scatterlist sg;
77};
78
79#define AESNI_ALIGN (16)
46#define AES_BLOCK_MASK (~(AES_BLOCK_SIZE-1)) 80#define AES_BLOCK_MASK (~(AES_BLOCK_SIZE-1))
81#define RFC4106_HASH_SUBKEY_SIZE 16
47 82
48asmlinkage int aesni_set_key(struct crypto_aes_ctx *ctx, const u8 *in_key, 83asmlinkage int aesni_set_key(struct crypto_aes_ctx *ctx, const u8 *in_key,
49 unsigned int key_len); 84 unsigned int key_len);
@@ -59,9 +94,62 @@ asmlinkage void aesni_cbc_enc(struct crypto_aes_ctx *ctx, u8 *out,
59 const u8 *in, unsigned int len, u8 *iv); 94 const u8 *in, unsigned int len, u8 *iv);
60asmlinkage void aesni_cbc_dec(struct crypto_aes_ctx *ctx, u8 *out, 95asmlinkage void aesni_cbc_dec(struct crypto_aes_ctx *ctx, u8 *out,
61 const u8 *in, unsigned int len, u8 *iv); 96 const u8 *in, unsigned int len, u8 *iv);
97#ifdef CONFIG_X86_64
62asmlinkage void aesni_ctr_enc(struct crypto_aes_ctx *ctx, u8 *out, 98asmlinkage void aesni_ctr_enc(struct crypto_aes_ctx *ctx, u8 *out,
63 const u8 *in, unsigned int len, u8 *iv); 99 const u8 *in, unsigned int len, u8 *iv);
64 100
101/* asmlinkage void aesni_gcm_enc()
102 * void *ctx, AES Key schedule. Starts on a 16 byte boundary.
103 * u8 *out, Ciphertext output. Encrypt in-place is allowed.
104 * const u8 *in, Plaintext input
105 * unsigned long plaintext_len, Length of data in bytes for encryption.
106 * u8 *iv, Pre-counter block j0: 4 byte salt (from Security Association)
107 * concatenated with 8 byte Initialisation Vector (from IPSec ESP
108 * Payload) concatenated with 0x00000001. 16-byte aligned pointer.
109 * u8 *hash_subkey, the Hash sub key input. Data starts on a 16-byte boundary.
110 * const u8 *aad, Additional Authentication Data (AAD)
111 * unsigned long aad_len, Length of AAD in bytes. With RFC4106 this
112 * is going to be 8 or 12 bytes
113 * u8 *auth_tag, Authenticated Tag output.
114 * unsigned long auth_tag_len), Authenticated Tag Length in bytes.
115 * Valid values are 16 (most likely), 12 or 8.
116 */
117asmlinkage void aesni_gcm_enc(void *ctx, u8 *out,
118 const u8 *in, unsigned long plaintext_len, u8 *iv,
119 u8 *hash_subkey, const u8 *aad, unsigned long aad_len,
120 u8 *auth_tag, unsigned long auth_tag_len);
121
122/* asmlinkage void aesni_gcm_dec()
123 * void *ctx, AES Key schedule. Starts on a 16 byte boundary.
124 * u8 *out, Plaintext output. Decrypt in-place is allowed.
125 * const u8 *in, Ciphertext input
126 * unsigned long ciphertext_len, Length of data in bytes for decryption.
127 * u8 *iv, Pre-counter block j0: 4 byte salt (from Security Association)
128 * concatenated with 8 byte Initialisation Vector (from IPSec ESP
129 * Payload) concatenated with 0x00000001. 16-byte aligned pointer.
130 * u8 *hash_subkey, the Hash sub key input. Data starts on a 16-byte boundary.
131 * const u8 *aad, Additional Authentication Data (AAD)
132 * unsigned long aad_len, Length of AAD in bytes. With RFC4106 this is going
133 * to be 8 or 12 bytes
134 * u8 *auth_tag, Authenticated Tag output.
135 * unsigned long auth_tag_len) Authenticated Tag Length in bytes.
136 * Valid values are 16 (most likely), 12 or 8.
137 */
138asmlinkage void aesni_gcm_dec(void *ctx, u8 *out,
139 const u8 *in, unsigned long ciphertext_len, u8 *iv,
140 u8 *hash_subkey, const u8 *aad, unsigned long aad_len,
141 u8 *auth_tag, unsigned long auth_tag_len);
142
143static inline struct
144aesni_rfc4106_gcm_ctx *aesni_rfc4106_gcm_ctx_get(struct crypto_aead *tfm)
145{
146 return
147 (struct aesni_rfc4106_gcm_ctx *)
148 PTR_ALIGN((u8 *)
149 crypto_tfm_ctx(crypto_aead_tfm(tfm)), AESNI_ALIGN);
150}
151#endif
152
65static inline struct crypto_aes_ctx *aes_ctx(void *raw_ctx) 153static inline struct crypto_aes_ctx *aes_ctx(void *raw_ctx)
66{ 154{
67 unsigned long addr = (unsigned long)raw_ctx; 155 unsigned long addr = (unsigned long)raw_ctx;
@@ -324,6 +412,7 @@ static struct crypto_alg blk_cbc_alg = {
324 }, 412 },
325}; 413};
326 414
415#ifdef CONFIG_X86_64
327static void ctr_crypt_final(struct crypto_aes_ctx *ctx, 416static void ctr_crypt_final(struct crypto_aes_ctx *ctx,
328 struct blkcipher_walk *walk) 417 struct blkcipher_walk *walk)
329{ 418{
@@ -389,6 +478,7 @@ static struct crypto_alg blk_ctr_alg = {
389 }, 478 },
390 }, 479 },
391}; 480};
481#endif
392 482
393static int ablk_set_key(struct crypto_ablkcipher *tfm, const u8 *key, 483static int ablk_set_key(struct crypto_ablkcipher *tfm, const u8 *key,
394 unsigned int key_len) 484 unsigned int key_len)
@@ -536,6 +626,7 @@ static struct crypto_alg ablk_cbc_alg = {
536 }, 626 },
537}; 627};
538 628
629#ifdef CONFIG_X86_64
539static int ablk_ctr_init(struct crypto_tfm *tfm) 630static int ablk_ctr_init(struct crypto_tfm *tfm)
540{ 631{
541 struct cryptd_ablkcipher *cryptd_tfm; 632 struct cryptd_ablkcipher *cryptd_tfm;
@@ -612,6 +703,7 @@ static struct crypto_alg ablk_rfc3686_ctr_alg = {
612 }, 703 },
613}; 704};
614#endif 705#endif
706#endif
615 707
616#ifdef HAS_LRW 708#ifdef HAS_LRW
617static int ablk_lrw_init(struct crypto_tfm *tfm) 709static int ablk_lrw_init(struct crypto_tfm *tfm)
@@ -730,6 +822,424 @@ static struct crypto_alg ablk_xts_alg = {
730}; 822};
731#endif 823#endif
732 824
825#ifdef CONFIG_X86_64
826static int rfc4106_init(struct crypto_tfm *tfm)
827{
828 struct cryptd_aead *cryptd_tfm;
829 struct aesni_rfc4106_gcm_ctx *ctx = (struct aesni_rfc4106_gcm_ctx *)
830 PTR_ALIGN((u8 *)crypto_tfm_ctx(tfm), AESNI_ALIGN);
831 cryptd_tfm = cryptd_alloc_aead("__driver-gcm-aes-aesni", 0, 0);
832 if (IS_ERR(cryptd_tfm))
833 return PTR_ERR(cryptd_tfm);
834 ctx->cryptd_tfm = cryptd_tfm;
835 tfm->crt_aead.reqsize = sizeof(struct aead_request)
836 + crypto_aead_reqsize(&cryptd_tfm->base);
837 return 0;
838}
839
840static void rfc4106_exit(struct crypto_tfm *tfm)
841{
842 struct aesni_rfc4106_gcm_ctx *ctx =
843 (struct aesni_rfc4106_gcm_ctx *)
844 PTR_ALIGN((u8 *)crypto_tfm_ctx(tfm), AESNI_ALIGN);
845 if (!IS_ERR(ctx->cryptd_tfm))
846 cryptd_free_aead(ctx->cryptd_tfm);
847 return;
848}
849
850static void
851rfc4106_set_hash_subkey_done(struct crypto_async_request *req, int err)
852{
853 struct aesni_gcm_set_hash_subkey_result *result = req->data;
854
855 if (err == -EINPROGRESS)
856 return;
857 result->err = err;
858 complete(&result->completion);
859}
860
861static int
862rfc4106_set_hash_subkey(u8 *hash_subkey, const u8 *key, unsigned int key_len)
863{
864 struct crypto_ablkcipher *ctr_tfm;
865 struct ablkcipher_request *req;
866 int ret = -EINVAL;
867 struct aesni_hash_subkey_req_data *req_data;
868
869 ctr_tfm = crypto_alloc_ablkcipher("ctr(aes)", 0, 0);
870 if (IS_ERR(ctr_tfm))
871 return PTR_ERR(ctr_tfm);
872
873 crypto_ablkcipher_clear_flags(ctr_tfm, ~0);
874
875 ret = crypto_ablkcipher_setkey(ctr_tfm, key, key_len);
876 if (ret) {
877 crypto_free_ablkcipher(ctr_tfm);
878 return ret;
879 }
880
881 req = ablkcipher_request_alloc(ctr_tfm, GFP_KERNEL);
882 if (!req) {
883 crypto_free_ablkcipher(ctr_tfm);
884 return -EINVAL;
885 }
886
887 req_data = kmalloc(sizeof(*req_data), GFP_KERNEL);
888 if (!req_data) {
889 crypto_free_ablkcipher(ctr_tfm);
890 return -ENOMEM;
891 }
892 memset(req_data->iv, 0, sizeof(req_data->iv));
893
894 /* Clear the data in the hash sub key container to zero.*/
895 /* We want to cipher all zeros to create the hash sub key. */
896 memset(hash_subkey, 0, RFC4106_HASH_SUBKEY_SIZE);
897
898 init_completion(&req_data->result.completion);
899 sg_init_one(&req_data->sg, hash_subkey, RFC4106_HASH_SUBKEY_SIZE);
900 ablkcipher_request_set_tfm(req, ctr_tfm);
901 ablkcipher_request_set_callback(req, CRYPTO_TFM_REQ_MAY_SLEEP |
902 CRYPTO_TFM_REQ_MAY_BACKLOG,
903 rfc4106_set_hash_subkey_done,
904 &req_data->result);
905
906 ablkcipher_request_set_crypt(req, &req_data->sg,
907 &req_data->sg, RFC4106_HASH_SUBKEY_SIZE, req_data->iv);
908
909 ret = crypto_ablkcipher_encrypt(req);
910 if (ret == -EINPROGRESS || ret == -EBUSY) {
911 ret = wait_for_completion_interruptible
912 (&req_data->result.completion);
913 if (!ret)
914 ret = req_data->result.err;
915 }
916 ablkcipher_request_free(req);
917 kfree(req_data);
918 crypto_free_ablkcipher(ctr_tfm);
919 return ret;
920}
921
922static int rfc4106_set_key(struct crypto_aead *parent, const u8 *key,
923 unsigned int key_len)
924{
925 int ret = 0;
926 struct crypto_tfm *tfm = crypto_aead_tfm(parent);
927 struct aesni_rfc4106_gcm_ctx *ctx = aesni_rfc4106_gcm_ctx_get(parent);
928 u8 *new_key_mem = NULL;
929
930 if (key_len < 4) {
931 crypto_tfm_set_flags(tfm, CRYPTO_TFM_RES_BAD_KEY_LEN);
932 return -EINVAL;
933 }
934 /*Account for 4 byte nonce at the end.*/
935 key_len -= 4;
936 if (key_len != AES_KEYSIZE_128) {
937 crypto_tfm_set_flags(tfm, CRYPTO_TFM_RES_BAD_KEY_LEN);
938 return -EINVAL;
939 }
940
941 memcpy(ctx->nonce, key + key_len, sizeof(ctx->nonce));
942 /*This must be on a 16 byte boundary!*/
943 if ((unsigned long)(&(ctx->aes_key_expanded.key_enc[0])) % AESNI_ALIGN)
944 return -EINVAL;
945
946 if ((unsigned long)key % AESNI_ALIGN) {
947 /*key is not aligned: use an auxuliar aligned pointer*/
948 new_key_mem = kmalloc(key_len+AESNI_ALIGN, GFP_KERNEL);
949 if (!new_key_mem)
950 return -ENOMEM;
951
952 new_key_mem = PTR_ALIGN(new_key_mem, AESNI_ALIGN);
953 memcpy(new_key_mem, key, key_len);
954 key = new_key_mem;
955 }
956
957 if (!irq_fpu_usable())
958 ret = crypto_aes_expand_key(&(ctx->aes_key_expanded),
959 key, key_len);
960 else {
961 kernel_fpu_begin();
962 ret = aesni_set_key(&(ctx->aes_key_expanded), key, key_len);
963 kernel_fpu_end();
964 }
965 /*This must be on a 16 byte boundary!*/
966 if ((unsigned long)(&(ctx->hash_subkey[0])) % AESNI_ALIGN) {
967 ret = -EINVAL;
968 goto exit;
969 }
970 ret = rfc4106_set_hash_subkey(ctx->hash_subkey, key, key_len);
971exit:
972 kfree(new_key_mem);
973 return ret;
974}
975
976/* This is the Integrity Check Value (aka the authentication tag length and can
977 * be 8, 12 or 16 bytes long. */
978static int rfc4106_set_authsize(struct crypto_aead *parent,
979 unsigned int authsize)
980{
981 struct aesni_rfc4106_gcm_ctx *ctx = aesni_rfc4106_gcm_ctx_get(parent);
982 struct crypto_aead *cryptd_child = cryptd_aead_child(ctx->cryptd_tfm);
983
984 switch (authsize) {
985 case 8:
986 case 12:
987 case 16:
988 break;
989 default:
990 return -EINVAL;
991 }
992 crypto_aead_crt(parent)->authsize = authsize;
993 crypto_aead_crt(cryptd_child)->authsize = authsize;
994 return 0;
995}
996
997static int rfc4106_encrypt(struct aead_request *req)
998{
999 int ret;
1000 struct crypto_aead *tfm = crypto_aead_reqtfm(req);
1001 struct aesni_rfc4106_gcm_ctx *ctx = aesni_rfc4106_gcm_ctx_get(tfm);
1002 struct crypto_aead *cryptd_child = cryptd_aead_child(ctx->cryptd_tfm);
1003
1004 if (!irq_fpu_usable()) {
1005 struct aead_request *cryptd_req =
1006 (struct aead_request *) aead_request_ctx(req);
1007 memcpy(cryptd_req, req, sizeof(*req));
1008 aead_request_set_tfm(cryptd_req, &ctx->cryptd_tfm->base);
1009 return crypto_aead_encrypt(cryptd_req);
1010 } else {
1011 kernel_fpu_begin();
1012 ret = cryptd_child->base.crt_aead.encrypt(req);
1013 kernel_fpu_end();
1014 return ret;
1015 }
1016}
1017
1018static int rfc4106_decrypt(struct aead_request *req)
1019{
1020 int ret;
1021 struct crypto_aead *tfm = crypto_aead_reqtfm(req);
1022 struct aesni_rfc4106_gcm_ctx *ctx = aesni_rfc4106_gcm_ctx_get(tfm);
1023 struct crypto_aead *cryptd_child = cryptd_aead_child(ctx->cryptd_tfm);
1024
1025 if (!irq_fpu_usable()) {
1026 struct aead_request *cryptd_req =
1027 (struct aead_request *) aead_request_ctx(req);
1028 memcpy(cryptd_req, req, sizeof(*req));
1029 aead_request_set_tfm(cryptd_req, &ctx->cryptd_tfm->base);
1030 return crypto_aead_decrypt(cryptd_req);
1031 } else {
1032 kernel_fpu_begin();
1033 ret = cryptd_child->base.crt_aead.decrypt(req);
1034 kernel_fpu_end();
1035 return ret;
1036 }
1037}
1038
1039static struct crypto_alg rfc4106_alg = {
1040 .cra_name = "rfc4106(gcm(aes))",
1041 .cra_driver_name = "rfc4106-gcm-aesni",
1042 .cra_priority = 400,
1043 .cra_flags = CRYPTO_ALG_TYPE_AEAD | CRYPTO_ALG_ASYNC,
1044 .cra_blocksize = 1,
1045 .cra_ctxsize = sizeof(struct aesni_rfc4106_gcm_ctx) + AESNI_ALIGN,
1046 .cra_alignmask = 0,
1047 .cra_type = &crypto_nivaead_type,
1048 .cra_module = THIS_MODULE,
1049 .cra_list = LIST_HEAD_INIT(rfc4106_alg.cra_list),
1050 .cra_init = rfc4106_init,
1051 .cra_exit = rfc4106_exit,
1052 .cra_u = {
1053 .aead = {
1054 .setkey = rfc4106_set_key,
1055 .setauthsize = rfc4106_set_authsize,
1056 .encrypt = rfc4106_encrypt,
1057 .decrypt = rfc4106_decrypt,
1058 .geniv = "seqiv",
1059 .ivsize = 8,
1060 .maxauthsize = 16,
1061 },
1062 },
1063};
1064
1065static int __driver_rfc4106_encrypt(struct aead_request *req)
1066{
1067 u8 one_entry_in_sg = 0;
1068 u8 *src, *dst, *assoc;
1069 __be32 counter = cpu_to_be32(1);
1070 struct crypto_aead *tfm = crypto_aead_reqtfm(req);
1071 struct aesni_rfc4106_gcm_ctx *ctx = aesni_rfc4106_gcm_ctx_get(tfm);
1072 void *aes_ctx = &(ctx->aes_key_expanded);
1073 unsigned long auth_tag_len = crypto_aead_authsize(tfm);
1074 u8 iv_tab[16+AESNI_ALIGN];
1075 u8* iv = (u8 *) PTR_ALIGN((u8 *)iv_tab, AESNI_ALIGN);
1076 struct scatter_walk src_sg_walk;
1077 struct scatter_walk assoc_sg_walk;
1078 struct scatter_walk dst_sg_walk;
1079 unsigned int i;
1080
1081 /* Assuming we are supporting rfc4106 64-bit extended */
1082 /* sequence numbers We need to have the AAD length equal */
1083 /* to 8 or 12 bytes */
1084 if (unlikely(req->assoclen != 8 && req->assoclen != 12))
1085 return -EINVAL;
1086 /* IV below built */
1087 for (i = 0; i < 4; i++)
1088 *(iv+i) = ctx->nonce[i];
1089 for (i = 0; i < 8; i++)
1090 *(iv+4+i) = req->iv[i];
1091 *((__be32 *)(iv+12)) = counter;
1092
1093 if ((sg_is_last(req->src)) && (sg_is_last(req->assoc))) {
1094 one_entry_in_sg = 1;
1095 scatterwalk_start(&src_sg_walk, req->src);
1096 scatterwalk_start(&assoc_sg_walk, req->assoc);
1097 src = scatterwalk_map(&src_sg_walk, 0);
1098 assoc = scatterwalk_map(&assoc_sg_walk, 0);
1099 dst = src;
1100 if (unlikely(req->src != req->dst)) {
1101 scatterwalk_start(&dst_sg_walk, req->dst);
1102 dst = scatterwalk_map(&dst_sg_walk, 0);
1103 }
1104
1105 } else {
1106 /* Allocate memory for src, dst, assoc */
1107 src = kmalloc(req->cryptlen + auth_tag_len + req->assoclen,
1108 GFP_ATOMIC);
1109 if (unlikely(!src))
1110 return -ENOMEM;
1111 assoc = (src + req->cryptlen + auth_tag_len);
1112 scatterwalk_map_and_copy(src, req->src, 0, req->cryptlen, 0);
1113 scatterwalk_map_and_copy(assoc, req->assoc, 0,
1114 req->assoclen, 0);
1115 dst = src;
1116 }
1117
1118 aesni_gcm_enc(aes_ctx, dst, src, (unsigned long)req->cryptlen, iv,
1119 ctx->hash_subkey, assoc, (unsigned long)req->assoclen, dst
1120 + ((unsigned long)req->cryptlen), auth_tag_len);
1121
1122 /* The authTag (aka the Integrity Check Value) needs to be written
1123 * back to the packet. */
1124 if (one_entry_in_sg) {
1125 if (unlikely(req->src != req->dst)) {
1126 scatterwalk_unmap(dst, 0);
1127 scatterwalk_done(&dst_sg_walk, 0, 0);
1128 }
1129 scatterwalk_unmap(src, 0);
1130 scatterwalk_unmap(assoc, 0);
1131 scatterwalk_done(&src_sg_walk, 0, 0);
1132 scatterwalk_done(&assoc_sg_walk, 0, 0);
1133 } else {
1134 scatterwalk_map_and_copy(dst, req->dst, 0,
1135 req->cryptlen + auth_tag_len, 1);
1136 kfree(src);
1137 }
1138 return 0;
1139}
1140
1141static int __driver_rfc4106_decrypt(struct aead_request *req)
1142{
1143 u8 one_entry_in_sg = 0;
1144 u8 *src, *dst, *assoc;
1145 unsigned long tempCipherLen = 0;
1146 __be32 counter = cpu_to_be32(1);
1147 int retval = 0;
1148 struct crypto_aead *tfm = crypto_aead_reqtfm(req);
1149 struct aesni_rfc4106_gcm_ctx *ctx = aesni_rfc4106_gcm_ctx_get(tfm);
1150 void *aes_ctx = &(ctx->aes_key_expanded);
1151 unsigned long auth_tag_len = crypto_aead_authsize(tfm);
1152 u8 iv_and_authTag[32+AESNI_ALIGN];
1153 u8 *iv = (u8 *) PTR_ALIGN((u8 *)iv_and_authTag, AESNI_ALIGN);
1154 u8 *authTag = iv + 16;
1155 struct scatter_walk src_sg_walk;
1156 struct scatter_walk assoc_sg_walk;
1157 struct scatter_walk dst_sg_walk;
1158 unsigned int i;
1159
1160 if (unlikely((req->cryptlen < auth_tag_len) ||
1161 (req->assoclen != 8 && req->assoclen != 12)))
1162 return -EINVAL;
1163 /* Assuming we are supporting rfc4106 64-bit extended */
1164 /* sequence numbers We need to have the AAD length */
1165 /* equal to 8 or 12 bytes */
1166
1167 tempCipherLen = (unsigned long)(req->cryptlen - auth_tag_len);
1168 /* IV below built */
1169 for (i = 0; i < 4; i++)
1170 *(iv+i) = ctx->nonce[i];
1171 for (i = 0; i < 8; i++)
1172 *(iv+4+i) = req->iv[i];
1173 *((__be32 *)(iv+12)) = counter;
1174
1175 if ((sg_is_last(req->src)) && (sg_is_last(req->assoc))) {
1176 one_entry_in_sg = 1;
1177 scatterwalk_start(&src_sg_walk, req->src);
1178 scatterwalk_start(&assoc_sg_walk, req->assoc);
1179 src = scatterwalk_map(&src_sg_walk, 0);
1180 assoc = scatterwalk_map(&assoc_sg_walk, 0);
1181 dst = src;
1182 if (unlikely(req->src != req->dst)) {
1183 scatterwalk_start(&dst_sg_walk, req->dst);
1184 dst = scatterwalk_map(&dst_sg_walk, 0);
1185 }
1186
1187 } else {
1188 /* Allocate memory for src, dst, assoc */
1189 src = kmalloc(req->cryptlen + req->assoclen, GFP_ATOMIC);
1190 if (!src)
1191 return -ENOMEM;
1192 assoc = (src + req->cryptlen + auth_tag_len);
1193 scatterwalk_map_and_copy(src, req->src, 0, req->cryptlen, 0);
1194 scatterwalk_map_and_copy(assoc, req->assoc, 0,
1195 req->assoclen, 0);
1196 dst = src;
1197 }
1198
1199 aesni_gcm_dec(aes_ctx, dst, src, tempCipherLen, iv,
1200 ctx->hash_subkey, assoc, (unsigned long)req->assoclen,
1201 authTag, auth_tag_len);
1202
1203 /* Compare generated tag with passed in tag. */
1204 retval = memcmp(src + tempCipherLen, authTag, auth_tag_len) ?
1205 -EBADMSG : 0;
1206
1207 if (one_entry_in_sg) {
1208 if (unlikely(req->src != req->dst)) {
1209 scatterwalk_unmap(dst, 0);
1210 scatterwalk_done(&dst_sg_walk, 0, 0);
1211 }
1212 scatterwalk_unmap(src, 0);
1213 scatterwalk_unmap(assoc, 0);
1214 scatterwalk_done(&src_sg_walk, 0, 0);
1215 scatterwalk_done(&assoc_sg_walk, 0, 0);
1216 } else {
1217 scatterwalk_map_and_copy(dst, req->dst, 0, req->cryptlen, 1);
1218 kfree(src);
1219 }
1220 return retval;
1221}
1222
1223static struct crypto_alg __rfc4106_alg = {
1224 .cra_name = "__gcm-aes-aesni",
1225 .cra_driver_name = "__driver-gcm-aes-aesni",
1226 .cra_priority = 0,
1227 .cra_flags = CRYPTO_ALG_TYPE_AEAD,
1228 .cra_blocksize = 1,
1229 .cra_ctxsize = sizeof(struct aesni_rfc4106_gcm_ctx) + AESNI_ALIGN,
1230 .cra_alignmask = 0,
1231 .cra_type = &crypto_aead_type,
1232 .cra_module = THIS_MODULE,
1233 .cra_list = LIST_HEAD_INIT(__rfc4106_alg.cra_list),
1234 .cra_u = {
1235 .aead = {
1236 .encrypt = __driver_rfc4106_encrypt,
1237 .decrypt = __driver_rfc4106_decrypt,
1238 },
1239 },
1240};
1241#endif
1242
733static int __init aesni_init(void) 1243static int __init aesni_init(void)
734{ 1244{
735 int err; 1245 int err;
@@ -738,6 +1248,7 @@ static int __init aesni_init(void)
738 printk(KERN_INFO "Intel AES-NI instructions are not detected.\n"); 1248 printk(KERN_INFO "Intel AES-NI instructions are not detected.\n");
739 return -ENODEV; 1249 return -ENODEV;
740 } 1250 }
1251
741 if ((err = crypto_register_alg(&aesni_alg))) 1252 if ((err = crypto_register_alg(&aesni_alg)))
742 goto aes_err; 1253 goto aes_err;
743 if ((err = crypto_register_alg(&__aesni_alg))) 1254 if ((err = crypto_register_alg(&__aesni_alg)))
@@ -746,18 +1257,24 @@ static int __init aesni_init(void)
746 goto blk_ecb_err; 1257 goto blk_ecb_err;
747 if ((err = crypto_register_alg(&blk_cbc_alg))) 1258 if ((err = crypto_register_alg(&blk_cbc_alg)))
748 goto blk_cbc_err; 1259 goto blk_cbc_err;
749 if ((err = crypto_register_alg(&blk_ctr_alg)))
750 goto blk_ctr_err;
751 if ((err = crypto_register_alg(&ablk_ecb_alg))) 1260 if ((err = crypto_register_alg(&ablk_ecb_alg)))
752 goto ablk_ecb_err; 1261 goto ablk_ecb_err;
753 if ((err = crypto_register_alg(&ablk_cbc_alg))) 1262 if ((err = crypto_register_alg(&ablk_cbc_alg)))
754 goto ablk_cbc_err; 1263 goto ablk_cbc_err;
1264#ifdef CONFIG_X86_64
1265 if ((err = crypto_register_alg(&blk_ctr_alg)))
1266 goto blk_ctr_err;
755 if ((err = crypto_register_alg(&ablk_ctr_alg))) 1267 if ((err = crypto_register_alg(&ablk_ctr_alg)))
756 goto ablk_ctr_err; 1268 goto ablk_ctr_err;
1269 if ((err = crypto_register_alg(&__rfc4106_alg)))
1270 goto __aead_gcm_err;
1271 if ((err = crypto_register_alg(&rfc4106_alg)))
1272 goto aead_gcm_err;
757#ifdef HAS_CTR 1273#ifdef HAS_CTR
758 if ((err = crypto_register_alg(&ablk_rfc3686_ctr_alg))) 1274 if ((err = crypto_register_alg(&ablk_rfc3686_ctr_alg)))
759 goto ablk_rfc3686_ctr_err; 1275 goto ablk_rfc3686_ctr_err;
760#endif 1276#endif
1277#endif
761#ifdef HAS_LRW 1278#ifdef HAS_LRW
762 if ((err = crypto_register_alg(&ablk_lrw_alg))) 1279 if ((err = crypto_register_alg(&ablk_lrw_alg)))
763 goto ablk_lrw_err; 1280 goto ablk_lrw_err;
@@ -770,7 +1287,6 @@ static int __init aesni_init(void)
770 if ((err = crypto_register_alg(&ablk_xts_alg))) 1287 if ((err = crypto_register_alg(&ablk_xts_alg)))
771 goto ablk_xts_err; 1288 goto ablk_xts_err;
772#endif 1289#endif
773
774 return err; 1290 return err;
775 1291
776#ifdef HAS_XTS 1292#ifdef HAS_XTS
@@ -784,18 +1300,24 @@ ablk_pcbc_err:
784 crypto_unregister_alg(&ablk_lrw_alg); 1300 crypto_unregister_alg(&ablk_lrw_alg);
785ablk_lrw_err: 1301ablk_lrw_err:
786#endif 1302#endif
1303#ifdef CONFIG_X86_64
787#ifdef HAS_CTR 1304#ifdef HAS_CTR
788 crypto_unregister_alg(&ablk_rfc3686_ctr_alg); 1305 crypto_unregister_alg(&ablk_rfc3686_ctr_alg);
789ablk_rfc3686_ctr_err: 1306ablk_rfc3686_ctr_err:
790#endif 1307#endif
1308 crypto_unregister_alg(&rfc4106_alg);
1309aead_gcm_err:
1310 crypto_unregister_alg(&__rfc4106_alg);
1311__aead_gcm_err:
791 crypto_unregister_alg(&ablk_ctr_alg); 1312 crypto_unregister_alg(&ablk_ctr_alg);
792ablk_ctr_err: 1313ablk_ctr_err:
1314 crypto_unregister_alg(&blk_ctr_alg);
1315blk_ctr_err:
1316#endif
793 crypto_unregister_alg(&ablk_cbc_alg); 1317 crypto_unregister_alg(&ablk_cbc_alg);
794ablk_cbc_err: 1318ablk_cbc_err:
795 crypto_unregister_alg(&ablk_ecb_alg); 1319 crypto_unregister_alg(&ablk_ecb_alg);
796ablk_ecb_err: 1320ablk_ecb_err:
797 crypto_unregister_alg(&blk_ctr_alg);
798blk_ctr_err:
799 crypto_unregister_alg(&blk_cbc_alg); 1321 crypto_unregister_alg(&blk_cbc_alg);
800blk_cbc_err: 1322blk_cbc_err:
801 crypto_unregister_alg(&blk_ecb_alg); 1323 crypto_unregister_alg(&blk_ecb_alg);
@@ -818,13 +1340,17 @@ static void __exit aesni_exit(void)
818#ifdef HAS_LRW 1340#ifdef HAS_LRW
819 crypto_unregister_alg(&ablk_lrw_alg); 1341 crypto_unregister_alg(&ablk_lrw_alg);
820#endif 1342#endif
1343#ifdef CONFIG_X86_64
821#ifdef HAS_CTR 1344#ifdef HAS_CTR
822 crypto_unregister_alg(&ablk_rfc3686_ctr_alg); 1345 crypto_unregister_alg(&ablk_rfc3686_ctr_alg);
823#endif 1346#endif
1347 crypto_unregister_alg(&rfc4106_alg);
1348 crypto_unregister_alg(&__rfc4106_alg);
824 crypto_unregister_alg(&ablk_ctr_alg); 1349 crypto_unregister_alg(&ablk_ctr_alg);
1350 crypto_unregister_alg(&blk_ctr_alg);
1351#endif
825 crypto_unregister_alg(&ablk_cbc_alg); 1352 crypto_unregister_alg(&ablk_cbc_alg);
826 crypto_unregister_alg(&ablk_ecb_alg); 1353 crypto_unregister_alg(&ablk_ecb_alg);
827 crypto_unregister_alg(&blk_ctr_alg);
828 crypto_unregister_alg(&blk_cbc_alg); 1354 crypto_unregister_alg(&blk_cbc_alg);
829 crypto_unregister_alg(&blk_ecb_alg); 1355 crypto_unregister_alg(&blk_ecb_alg);
830 crypto_unregister_alg(&__aesni_alg); 1356 crypto_unregister_alg(&__aesni_alg);
diff --git a/arch/x86/include/asm/boot.h b/arch/x86/include/asm/boot.h
index 3b62ab56c7a0..5e1a2eef3e7c 100644
--- a/arch/x86/include/asm/boot.h
+++ b/arch/x86/include/asm/boot.h
@@ -32,11 +32,7 @@
32#define BOOT_HEAP_SIZE 0x400000 32#define BOOT_HEAP_SIZE 0x400000
33#else /* !CONFIG_KERNEL_BZIP2 */ 33#else /* !CONFIG_KERNEL_BZIP2 */
34 34
35#ifdef CONFIG_X86_64 35#define BOOT_HEAP_SIZE 0x8000
36#define BOOT_HEAP_SIZE 0x7000
37#else
38#define BOOT_HEAP_SIZE 0x4000
39#endif
40 36
41#endif /* !CONFIG_KERNEL_BZIP2 */ 37#endif /* !CONFIG_KERNEL_BZIP2 */
42 38
diff --git a/arch/x86/include/asm/irq.h b/arch/x86/include/asm/irq.h
index ba870bb6dd8e..c704b38c57a2 100644
--- a/arch/x86/include/asm/irq.h
+++ b/arch/x86/include/asm/irq.h
@@ -10,6 +10,9 @@
10#include <asm/apicdef.h> 10#include <asm/apicdef.h>
11#include <asm/irq_vectors.h> 11#include <asm/irq_vectors.h>
12 12
13/* Even though we don't support this, supply it to appease OF */
14static inline void irq_dispose_mapping(unsigned int virq) { }
15
13static inline int irq_canonicalize(int irq) 16static inline int irq_canonicalize(int irq)
14{ 17{
15 return ((irq == 2) ? 9 : irq); 18 return ((irq == 2) ? 9 : irq);
diff --git a/arch/x86/include/asm/kvm_emulate.h b/arch/x86/include/asm/kvm_emulate.h
index b36c6b3fe144..8e37deb1eb38 100644
--- a/arch/x86/include/asm/kvm_emulate.h
+++ b/arch/x86/include/asm/kvm_emulate.h
@@ -15,6 +15,14 @@
15 15
16struct x86_emulate_ctxt; 16struct x86_emulate_ctxt;
17 17
18struct x86_exception {
19 u8 vector;
20 bool error_code_valid;
21 u16 error_code;
22 bool nested_page_fault;
23 u64 address; /* cr2 or nested page fault gpa */
24};
25
18/* 26/*
19 * x86_emulate_ops: 27 * x86_emulate_ops:
20 * 28 *
@@ -64,7 +72,8 @@ struct x86_emulate_ops {
64 * @bytes: [IN ] Number of bytes to read from memory. 72 * @bytes: [IN ] Number of bytes to read from memory.
65 */ 73 */
66 int (*read_std)(unsigned long addr, void *val, 74 int (*read_std)(unsigned long addr, void *val,
67 unsigned int bytes, struct kvm_vcpu *vcpu, u32 *error); 75 unsigned int bytes, struct kvm_vcpu *vcpu,
76 struct x86_exception *fault);
68 77
69 /* 78 /*
70 * write_std: Write bytes of standard (non-emulated/special) memory. 79 * write_std: Write bytes of standard (non-emulated/special) memory.
@@ -74,7 +83,8 @@ struct x86_emulate_ops {
74 * @bytes: [IN ] Number of bytes to write to memory. 83 * @bytes: [IN ] Number of bytes to write to memory.
75 */ 84 */
76 int (*write_std)(unsigned long addr, void *val, 85 int (*write_std)(unsigned long addr, void *val,
77 unsigned int bytes, struct kvm_vcpu *vcpu, u32 *error); 86 unsigned int bytes, struct kvm_vcpu *vcpu,
87 struct x86_exception *fault);
78 /* 88 /*
79 * fetch: Read bytes of standard (non-emulated/special) memory. 89 * fetch: Read bytes of standard (non-emulated/special) memory.
80 * Used for instruction fetch. 90 * Used for instruction fetch.
@@ -83,7 +93,8 @@ struct x86_emulate_ops {
83 * @bytes: [IN ] Number of bytes to read from memory. 93 * @bytes: [IN ] Number of bytes to read from memory.
84 */ 94 */
85 int (*fetch)(unsigned long addr, void *val, 95 int (*fetch)(unsigned long addr, void *val,
86 unsigned int bytes, struct kvm_vcpu *vcpu, u32 *error); 96 unsigned int bytes, struct kvm_vcpu *vcpu,
97 struct x86_exception *fault);
87 98
88 /* 99 /*
89 * read_emulated: Read bytes from emulated/special memory area. 100 * read_emulated: Read bytes from emulated/special memory area.
@@ -94,7 +105,7 @@ struct x86_emulate_ops {
94 int (*read_emulated)(unsigned long addr, 105 int (*read_emulated)(unsigned long addr,
95 void *val, 106 void *val,
96 unsigned int bytes, 107 unsigned int bytes,
97 unsigned int *error, 108 struct x86_exception *fault,
98 struct kvm_vcpu *vcpu); 109 struct kvm_vcpu *vcpu);
99 110
100 /* 111 /*
@@ -107,7 +118,7 @@ struct x86_emulate_ops {
107 int (*write_emulated)(unsigned long addr, 118 int (*write_emulated)(unsigned long addr,
108 const void *val, 119 const void *val,
109 unsigned int bytes, 120 unsigned int bytes,
110 unsigned int *error, 121 struct x86_exception *fault,
111 struct kvm_vcpu *vcpu); 122 struct kvm_vcpu *vcpu);
112 123
113 /* 124 /*
@@ -122,7 +133,7 @@ struct x86_emulate_ops {
122 const void *old, 133 const void *old,
123 const void *new, 134 const void *new,
124 unsigned int bytes, 135 unsigned int bytes,
125 unsigned int *error, 136 struct x86_exception *fault,
126 struct kvm_vcpu *vcpu); 137 struct kvm_vcpu *vcpu);
127 138
128 int (*pio_in_emulated)(int size, unsigned short port, void *val, 139 int (*pio_in_emulated)(int size, unsigned short port, void *val,
@@ -159,7 +170,10 @@ struct operand {
159 }; 170 };
160 union { 171 union {
161 unsigned long *reg; 172 unsigned long *reg;
162 unsigned long mem; 173 struct segmented_address {
174 ulong ea;
175 unsigned seg;
176 } mem;
163 } addr; 177 } addr;
164 union { 178 union {
165 unsigned long val; 179 unsigned long val;
@@ -226,9 +240,8 @@ struct x86_emulate_ctxt {
226 240
227 bool perm_ok; /* do not check permissions if true */ 241 bool perm_ok; /* do not check permissions if true */
228 242
229 int exception; /* exception that happens during emulation or -1 */ 243 bool have_exception;
230 u32 error_code; /* error code for exception */ 244 struct x86_exception exception;
231 bool error_code_valid;
232 245
233 /* decode cache */ 246 /* decode cache */
234 struct decode_cache decode; 247 struct decode_cache decode;
@@ -252,7 +265,7 @@ struct x86_emulate_ctxt {
252#define X86EMUL_MODE_HOST X86EMUL_MODE_PROT64 265#define X86EMUL_MODE_HOST X86EMUL_MODE_PROT64
253#endif 266#endif
254 267
255int x86_decode_insn(struct x86_emulate_ctxt *ctxt); 268int x86_decode_insn(struct x86_emulate_ctxt *ctxt, void *insn, int insn_len);
256#define EMULATION_FAILED -1 269#define EMULATION_FAILED -1
257#define EMULATION_OK 0 270#define EMULATION_OK 0
258#define EMULATION_RESTART 1 271#define EMULATION_RESTART 1
diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h
index f702f82aa1eb..aa75f21a9fba 100644
--- a/arch/x86/include/asm/kvm_host.h
+++ b/arch/x86/include/asm/kvm_host.h
@@ -83,11 +83,14 @@
83#define KVM_NR_FIXED_MTRR_REGION 88 83#define KVM_NR_FIXED_MTRR_REGION 88
84#define KVM_NR_VAR_MTRR 8 84#define KVM_NR_VAR_MTRR 8
85 85
86#define ASYNC_PF_PER_VCPU 64
87
86extern spinlock_t kvm_lock; 88extern spinlock_t kvm_lock;
87extern struct list_head vm_list; 89extern struct list_head vm_list;
88 90
89struct kvm_vcpu; 91struct kvm_vcpu;
90struct kvm; 92struct kvm;
93struct kvm_async_pf;
91 94
92enum kvm_reg { 95enum kvm_reg {
93 VCPU_REGS_RAX = 0, 96 VCPU_REGS_RAX = 0,
@@ -114,6 +117,7 @@ enum kvm_reg {
114 117
115enum kvm_reg_ex { 118enum kvm_reg_ex {
116 VCPU_EXREG_PDPTR = NR_VCPU_REGS, 119 VCPU_EXREG_PDPTR = NR_VCPU_REGS,
120 VCPU_EXREG_CR3,
117}; 121};
118 122
119enum { 123enum {
@@ -238,16 +242,18 @@ struct kvm_mmu {
238 void (*new_cr3)(struct kvm_vcpu *vcpu); 242 void (*new_cr3)(struct kvm_vcpu *vcpu);
239 void (*set_cr3)(struct kvm_vcpu *vcpu, unsigned long root); 243 void (*set_cr3)(struct kvm_vcpu *vcpu, unsigned long root);
240 unsigned long (*get_cr3)(struct kvm_vcpu *vcpu); 244 unsigned long (*get_cr3)(struct kvm_vcpu *vcpu);
241 int (*page_fault)(struct kvm_vcpu *vcpu, gva_t gva, u32 err); 245 int (*page_fault)(struct kvm_vcpu *vcpu, gva_t gva, u32 err,
242 void (*inject_page_fault)(struct kvm_vcpu *vcpu); 246 bool prefault);
247 void (*inject_page_fault)(struct kvm_vcpu *vcpu,
248 struct x86_exception *fault);
243 void (*free)(struct kvm_vcpu *vcpu); 249 void (*free)(struct kvm_vcpu *vcpu);
244 gpa_t (*gva_to_gpa)(struct kvm_vcpu *vcpu, gva_t gva, u32 access, 250 gpa_t (*gva_to_gpa)(struct kvm_vcpu *vcpu, gva_t gva, u32 access,
245 u32 *error); 251 struct x86_exception *exception);
246 gpa_t (*translate_gpa)(struct kvm_vcpu *vcpu, gpa_t gpa, u32 access); 252 gpa_t (*translate_gpa)(struct kvm_vcpu *vcpu, gpa_t gpa, u32 access);
247 void (*prefetch_page)(struct kvm_vcpu *vcpu, 253 void (*prefetch_page)(struct kvm_vcpu *vcpu,
248 struct kvm_mmu_page *page); 254 struct kvm_mmu_page *page);
249 int (*sync_page)(struct kvm_vcpu *vcpu, 255 int (*sync_page)(struct kvm_vcpu *vcpu,
250 struct kvm_mmu_page *sp, bool clear_unsync); 256 struct kvm_mmu_page *sp);
251 void (*invlpg)(struct kvm_vcpu *vcpu, gva_t gva); 257 void (*invlpg)(struct kvm_vcpu *vcpu, gva_t gva);
252 hpa_t root_hpa; 258 hpa_t root_hpa;
253 int root_level; 259 int root_level;
@@ -315,16 +321,6 @@ struct kvm_vcpu_arch {
315 */ 321 */
316 struct kvm_mmu *walk_mmu; 322 struct kvm_mmu *walk_mmu;
317 323
318 /*
319 * This struct is filled with the necessary information to propagate a
320 * page fault into the guest
321 */
322 struct {
323 u64 address;
324 unsigned error_code;
325 bool nested;
326 } fault;
327
328 /* only needed in kvm_pv_mmu_op() path, but it's hot so 324 /* only needed in kvm_pv_mmu_op() path, but it's hot so
329 * put it here to avoid allocation */ 325 * put it here to avoid allocation */
330 struct kvm_pv_mmu_op_buffer mmu_op_buffer; 326 struct kvm_pv_mmu_op_buffer mmu_op_buffer;
@@ -412,6 +408,15 @@ struct kvm_vcpu_arch {
412 u64 hv_vapic; 408 u64 hv_vapic;
413 409
414 cpumask_var_t wbinvd_dirty_mask; 410 cpumask_var_t wbinvd_dirty_mask;
411
412 struct {
413 bool halted;
414 gfn_t gfns[roundup_pow_of_two(ASYNC_PF_PER_VCPU)];
415 struct gfn_to_hva_cache data;
416 u64 msr_val;
417 u32 id;
418 bool send_user_only;
419 } apf;
415}; 420};
416 421
417struct kvm_arch { 422struct kvm_arch {
@@ -456,6 +461,10 @@ struct kvm_arch {
456 /* fields used by HYPER-V emulation */ 461 /* fields used by HYPER-V emulation */
457 u64 hv_guest_os_id; 462 u64 hv_guest_os_id;
458 u64 hv_hypercall; 463 u64 hv_hypercall;
464
465 #ifdef CONFIG_KVM_MMU_AUDIT
466 int audit_point;
467 #endif
459}; 468};
460 469
461struct kvm_vm_stat { 470struct kvm_vm_stat {
@@ -529,6 +538,7 @@ struct kvm_x86_ops {
529 struct kvm_segment *var, int seg); 538 struct kvm_segment *var, int seg);
530 void (*get_cs_db_l_bits)(struct kvm_vcpu *vcpu, int *db, int *l); 539 void (*get_cs_db_l_bits)(struct kvm_vcpu *vcpu, int *db, int *l);
531 void (*decache_cr0_guest_bits)(struct kvm_vcpu *vcpu); 540 void (*decache_cr0_guest_bits)(struct kvm_vcpu *vcpu);
541 void (*decache_cr3)(struct kvm_vcpu *vcpu);
532 void (*decache_cr4_guest_bits)(struct kvm_vcpu *vcpu); 542 void (*decache_cr4_guest_bits)(struct kvm_vcpu *vcpu);
533 void (*set_cr0)(struct kvm_vcpu *vcpu, unsigned long cr0); 543 void (*set_cr0)(struct kvm_vcpu *vcpu, unsigned long cr0);
534 void (*set_cr3)(struct kvm_vcpu *vcpu, unsigned long cr3); 544 void (*set_cr3)(struct kvm_vcpu *vcpu, unsigned long cr3);
@@ -582,9 +592,17 @@ struct kvm_x86_ops {
582 592
583 void (*write_tsc_offset)(struct kvm_vcpu *vcpu, u64 offset); 593 void (*write_tsc_offset)(struct kvm_vcpu *vcpu, u64 offset);
584 594
595 void (*get_exit_info)(struct kvm_vcpu *vcpu, u64 *info1, u64 *info2);
585 const struct trace_print_flags *exit_reasons_str; 596 const struct trace_print_flags *exit_reasons_str;
586}; 597};
587 598
599struct kvm_arch_async_pf {
600 u32 token;
601 gfn_t gfn;
602 unsigned long cr3;
603 bool direct_map;
604};
605
588extern struct kvm_x86_ops *kvm_x86_ops; 606extern struct kvm_x86_ops *kvm_x86_ops;
589 607
590int kvm_mmu_module_init(void); 608int kvm_mmu_module_init(void);
@@ -594,7 +612,6 @@ void kvm_mmu_destroy(struct kvm_vcpu *vcpu);
594int kvm_mmu_create(struct kvm_vcpu *vcpu); 612int kvm_mmu_create(struct kvm_vcpu *vcpu);
595int kvm_mmu_setup(struct kvm_vcpu *vcpu); 613int kvm_mmu_setup(struct kvm_vcpu *vcpu);
596void kvm_mmu_set_nonpresent_ptes(u64 trap_pte, u64 notrap_pte); 614void kvm_mmu_set_nonpresent_ptes(u64 trap_pte, u64 notrap_pte);
597void kvm_mmu_set_base_ptes(u64 base_pte);
598void kvm_mmu_set_mask_ptes(u64 user_mask, u64 accessed_mask, 615void kvm_mmu_set_mask_ptes(u64 user_mask, u64 accessed_mask,
599 u64 dirty_mask, u64 nx_mask, u64 x_mask); 616 u64 dirty_mask, u64 nx_mask, u64 x_mask);
600 617
@@ -623,8 +640,15 @@ enum emulation_result {
623#define EMULTYPE_NO_DECODE (1 << 0) 640#define EMULTYPE_NO_DECODE (1 << 0)
624#define EMULTYPE_TRAP_UD (1 << 1) 641#define EMULTYPE_TRAP_UD (1 << 1)
625#define EMULTYPE_SKIP (1 << 2) 642#define EMULTYPE_SKIP (1 << 2)
626int emulate_instruction(struct kvm_vcpu *vcpu, 643int x86_emulate_instruction(struct kvm_vcpu *vcpu, unsigned long cr2,
627 unsigned long cr2, u16 error_code, int emulation_type); 644 int emulation_type, void *insn, int insn_len);
645
646static inline int emulate_instruction(struct kvm_vcpu *vcpu,
647 int emulation_type)
648{
649 return x86_emulate_instruction(vcpu, 0, emulation_type, NULL, 0);
650}
651
628void realmode_lgdt(struct kvm_vcpu *vcpu, u16 size, unsigned long address); 652void realmode_lgdt(struct kvm_vcpu *vcpu, u16 size, unsigned long address);
629void realmode_lidt(struct kvm_vcpu *vcpu, u16 size, unsigned long address); 653void realmode_lidt(struct kvm_vcpu *vcpu, u16 size, unsigned long address);
630 654
@@ -650,7 +674,7 @@ int kvm_task_switch(struct kvm_vcpu *vcpu, u16 tss_selector, int reason,
650int kvm_set_cr0(struct kvm_vcpu *vcpu, unsigned long cr0); 674int kvm_set_cr0(struct kvm_vcpu *vcpu, unsigned long cr0);
651int kvm_set_cr3(struct kvm_vcpu *vcpu, unsigned long cr3); 675int kvm_set_cr3(struct kvm_vcpu *vcpu, unsigned long cr3);
652int kvm_set_cr4(struct kvm_vcpu *vcpu, unsigned long cr4); 676int kvm_set_cr4(struct kvm_vcpu *vcpu, unsigned long cr4);
653void kvm_set_cr8(struct kvm_vcpu *vcpu, unsigned long cr8); 677int kvm_set_cr8(struct kvm_vcpu *vcpu, unsigned long cr8);
654int kvm_set_dr(struct kvm_vcpu *vcpu, int dr, unsigned long val); 678int kvm_set_dr(struct kvm_vcpu *vcpu, int dr, unsigned long val);
655int kvm_get_dr(struct kvm_vcpu *vcpu, int dr, unsigned long *val); 679int kvm_get_dr(struct kvm_vcpu *vcpu, int dr, unsigned long *val);
656unsigned long kvm_get_cr8(struct kvm_vcpu *vcpu); 680unsigned long kvm_get_cr8(struct kvm_vcpu *vcpu);
@@ -668,11 +692,11 @@ void kvm_queue_exception(struct kvm_vcpu *vcpu, unsigned nr);
668void kvm_queue_exception_e(struct kvm_vcpu *vcpu, unsigned nr, u32 error_code); 692void kvm_queue_exception_e(struct kvm_vcpu *vcpu, unsigned nr, u32 error_code);
669void kvm_requeue_exception(struct kvm_vcpu *vcpu, unsigned nr); 693void kvm_requeue_exception(struct kvm_vcpu *vcpu, unsigned nr);
670void kvm_requeue_exception_e(struct kvm_vcpu *vcpu, unsigned nr, u32 error_code); 694void kvm_requeue_exception_e(struct kvm_vcpu *vcpu, unsigned nr, u32 error_code);
671void kvm_inject_page_fault(struct kvm_vcpu *vcpu); 695void kvm_inject_page_fault(struct kvm_vcpu *vcpu, struct x86_exception *fault);
672int kvm_read_guest_page_mmu(struct kvm_vcpu *vcpu, struct kvm_mmu *mmu, 696int kvm_read_guest_page_mmu(struct kvm_vcpu *vcpu, struct kvm_mmu *mmu,
673 gfn_t gfn, void *data, int offset, int len, 697 gfn_t gfn, void *data, int offset, int len,
674 u32 access); 698 u32 access);
675void kvm_propagate_fault(struct kvm_vcpu *vcpu); 699void kvm_propagate_fault(struct kvm_vcpu *vcpu, struct x86_exception *fault);
676bool kvm_require_cpl(struct kvm_vcpu *vcpu, int required_cpl); 700bool kvm_require_cpl(struct kvm_vcpu *vcpu, int required_cpl);
677 701
678int kvm_pic_set_irq(void *opaque, int irq, int level); 702int kvm_pic_set_irq(void *opaque, int irq, int level);
@@ -690,16 +714,21 @@ void __kvm_mmu_free_some_pages(struct kvm_vcpu *vcpu);
690int kvm_mmu_load(struct kvm_vcpu *vcpu); 714int kvm_mmu_load(struct kvm_vcpu *vcpu);
691void kvm_mmu_unload(struct kvm_vcpu *vcpu); 715void kvm_mmu_unload(struct kvm_vcpu *vcpu);
692void kvm_mmu_sync_roots(struct kvm_vcpu *vcpu); 716void kvm_mmu_sync_roots(struct kvm_vcpu *vcpu);
693gpa_t kvm_mmu_gva_to_gpa_read(struct kvm_vcpu *vcpu, gva_t gva, u32 *error); 717gpa_t kvm_mmu_gva_to_gpa_read(struct kvm_vcpu *vcpu, gva_t gva,
694gpa_t kvm_mmu_gva_to_gpa_fetch(struct kvm_vcpu *vcpu, gva_t gva, u32 *error); 718 struct x86_exception *exception);
695gpa_t kvm_mmu_gva_to_gpa_write(struct kvm_vcpu *vcpu, gva_t gva, u32 *error); 719gpa_t kvm_mmu_gva_to_gpa_fetch(struct kvm_vcpu *vcpu, gva_t gva,
696gpa_t kvm_mmu_gva_to_gpa_system(struct kvm_vcpu *vcpu, gva_t gva, u32 *error); 720 struct x86_exception *exception);
721gpa_t kvm_mmu_gva_to_gpa_write(struct kvm_vcpu *vcpu, gva_t gva,
722 struct x86_exception *exception);
723gpa_t kvm_mmu_gva_to_gpa_system(struct kvm_vcpu *vcpu, gva_t gva,
724 struct x86_exception *exception);
697 725
698int kvm_emulate_hypercall(struct kvm_vcpu *vcpu); 726int kvm_emulate_hypercall(struct kvm_vcpu *vcpu);
699 727
700int kvm_fix_hypercall(struct kvm_vcpu *vcpu); 728int kvm_fix_hypercall(struct kvm_vcpu *vcpu);
701 729
702int kvm_mmu_page_fault(struct kvm_vcpu *vcpu, gva_t gva, u32 error_code); 730int kvm_mmu_page_fault(struct kvm_vcpu *vcpu, gva_t gva, u32 error_code,
731 void *insn, int insn_len);
703void kvm_mmu_invlpg(struct kvm_vcpu *vcpu, gva_t gva); 732void kvm_mmu_invlpg(struct kvm_vcpu *vcpu, gva_t gva);
704 733
705void kvm_enable_tdp(void); 734void kvm_enable_tdp(void);
@@ -766,20 +795,25 @@ enum {
766#define HF_VINTR_MASK (1 << 2) 795#define HF_VINTR_MASK (1 << 2)
767#define HF_NMI_MASK (1 << 3) 796#define HF_NMI_MASK (1 << 3)
768#define HF_IRET_MASK (1 << 4) 797#define HF_IRET_MASK (1 << 4)
798#define HF_GUEST_MASK (1 << 5) /* VCPU is in guest-mode */
769 799
770/* 800/*
771 * Hardware virtualization extension instructions may fault if a 801 * Hardware virtualization extension instructions may fault if a
772 * reboot turns off virtualization while processes are running. 802 * reboot turns off virtualization while processes are running.
773 * Trap the fault and ignore the instruction if that happens. 803 * Trap the fault and ignore the instruction if that happens.
774 */ 804 */
775asmlinkage void kvm_handle_fault_on_reboot(void); 805asmlinkage void kvm_spurious_fault(void);
806extern bool kvm_rebooting;
776 807
777#define __kvm_handle_fault_on_reboot(insn) \ 808#define __kvm_handle_fault_on_reboot(insn) \
778 "666: " insn "\n\t" \ 809 "666: " insn "\n\t" \
810 "668: \n\t" \
779 ".pushsection .fixup, \"ax\" \n" \ 811 ".pushsection .fixup, \"ax\" \n" \
780 "667: \n\t" \ 812 "667: \n\t" \
813 "cmpb $0, kvm_rebooting \n\t" \
814 "jne 668b \n\t" \
781 __ASM_SIZE(push) " $666b \n\t" \ 815 __ASM_SIZE(push) " $666b \n\t" \
782 "jmp kvm_handle_fault_on_reboot \n\t" \ 816 "call kvm_spurious_fault \n\t" \
783 ".popsection \n\t" \ 817 ".popsection \n\t" \
784 ".pushsection __ex_table, \"a\" \n\t" \ 818 ".pushsection __ex_table, \"a\" \n\t" \
785 _ASM_PTR " 666b, 667b \n\t" \ 819 _ASM_PTR " 666b, 667b \n\t" \
@@ -799,4 +833,15 @@ void kvm_set_shared_msr(unsigned index, u64 val, u64 mask);
799 833
800bool kvm_is_linear_rip(struct kvm_vcpu *vcpu, unsigned long linear_rip); 834bool kvm_is_linear_rip(struct kvm_vcpu *vcpu, unsigned long linear_rip);
801 835
836void kvm_arch_async_page_not_present(struct kvm_vcpu *vcpu,
837 struct kvm_async_pf *work);
838void kvm_arch_async_page_present(struct kvm_vcpu *vcpu,
839 struct kvm_async_pf *work);
840void kvm_arch_async_page_ready(struct kvm_vcpu *vcpu,
841 struct kvm_async_pf *work);
842bool kvm_arch_can_inject_async_page_present(struct kvm_vcpu *vcpu);
843extern bool kvm_find_async_pf_gfn(struct kvm_vcpu *vcpu, gfn_t gfn);
844
845void kvm_complete_insn_gp(struct kvm_vcpu *vcpu, int err);
846
802#endif /* _ASM_X86_KVM_HOST_H */ 847#endif /* _ASM_X86_KVM_HOST_H */
diff --git a/arch/x86/include/asm/kvm_para.h b/arch/x86/include/asm/kvm_para.h
index 7b562b6184bc..a427bf77a93d 100644
--- a/arch/x86/include/asm/kvm_para.h
+++ b/arch/x86/include/asm/kvm_para.h
@@ -20,6 +20,7 @@
20 * are available. The use of 0x11 and 0x12 is deprecated 20 * are available. The use of 0x11 and 0x12 is deprecated
21 */ 21 */
22#define KVM_FEATURE_CLOCKSOURCE2 3 22#define KVM_FEATURE_CLOCKSOURCE2 3
23#define KVM_FEATURE_ASYNC_PF 4
23 24
24/* The last 8 bits are used to indicate how to interpret the flags field 25/* The last 8 bits are used to indicate how to interpret the flags field
25 * in pvclock structure. If no bits are set, all flags are ignored. 26 * in pvclock structure. If no bits are set, all flags are ignored.
@@ -32,9 +33,13 @@
32/* Custom MSRs falls in the range 0x4b564d00-0x4b564dff */ 33/* Custom MSRs falls in the range 0x4b564d00-0x4b564dff */
33#define MSR_KVM_WALL_CLOCK_NEW 0x4b564d00 34#define MSR_KVM_WALL_CLOCK_NEW 0x4b564d00
34#define MSR_KVM_SYSTEM_TIME_NEW 0x4b564d01 35#define MSR_KVM_SYSTEM_TIME_NEW 0x4b564d01
36#define MSR_KVM_ASYNC_PF_EN 0x4b564d02
35 37
36#define KVM_MAX_MMU_OP_BATCH 32 38#define KVM_MAX_MMU_OP_BATCH 32
37 39
40#define KVM_ASYNC_PF_ENABLED (1 << 0)
41#define KVM_ASYNC_PF_SEND_ALWAYS (1 << 1)
42
38/* Operations for KVM_HC_MMU_OP */ 43/* Operations for KVM_HC_MMU_OP */
39#define KVM_MMU_OP_WRITE_PTE 1 44#define KVM_MMU_OP_WRITE_PTE 1
40#define KVM_MMU_OP_FLUSH_TLB 2 45#define KVM_MMU_OP_FLUSH_TLB 2
@@ -61,10 +66,20 @@ struct kvm_mmu_op_release_pt {
61 __u64 pt_phys; 66 __u64 pt_phys;
62}; 67};
63 68
69#define KVM_PV_REASON_PAGE_NOT_PRESENT 1
70#define KVM_PV_REASON_PAGE_READY 2
71
72struct kvm_vcpu_pv_apf_data {
73 __u32 reason;
74 __u8 pad[60];
75 __u32 enabled;
76};
77
64#ifdef __KERNEL__ 78#ifdef __KERNEL__
65#include <asm/processor.h> 79#include <asm/processor.h>
66 80
67extern void kvmclock_init(void); 81extern void kvmclock_init(void);
82extern int kvm_register_clock(char *txt);
68 83
69 84
70/* This instruction is vmcall. On non-VT architectures, it will generate a 85/* This instruction is vmcall. On non-VT architectures, it will generate a
@@ -160,8 +175,17 @@ static inline unsigned int kvm_arch_para_features(void)
160 175
161#ifdef CONFIG_KVM_GUEST 176#ifdef CONFIG_KVM_GUEST
162void __init kvm_guest_init(void); 177void __init kvm_guest_init(void);
178void kvm_async_pf_task_wait(u32 token);
179void kvm_async_pf_task_wake(u32 token);
180u32 kvm_read_and_reset_pf_reason(void);
163#else 181#else
164#define kvm_guest_init() do { } while (0) 182#define kvm_guest_init() do { } while (0)
183#define kvm_async_pf_task_wait(T) do {} while(0)
184#define kvm_async_pf_task_wake(T) do {} while(0)
185static inline u32 kvm_read_and_reset_pf_reason(void)
186{
187 return 0;
188}
165#endif 189#endif
166 190
167#endif /* __KERNEL__ */ 191#endif /* __KERNEL__ */
diff --git a/arch/x86/include/asm/olpc.h b/arch/x86/include/asm/olpc.h
index 42a978c0c1b3..f482010350fb 100644
--- a/arch/x86/include/asm/olpc.h
+++ b/arch/x86/include/asm/olpc.h
@@ -107,10 +107,14 @@ extern int olpc_ec_mask_unset(uint8_t bits);
107/* GPIO assignments */ 107/* GPIO assignments */
108 108
109#define OLPC_GPIO_MIC_AC 1 109#define OLPC_GPIO_MIC_AC 1
110#define OLPC_GPIO_DCON_IRQ geode_gpio(7) 110#define OLPC_GPIO_DCON_STAT0 5
111#define OLPC_GPIO_DCON_STAT1 6
112#define OLPC_GPIO_DCON_IRQ 7
111#define OLPC_GPIO_THRM_ALRM geode_gpio(10) 113#define OLPC_GPIO_THRM_ALRM geode_gpio(10)
112#define OLPC_GPIO_SMB_CLK geode_gpio(14) 114#define OLPC_GPIO_DCON_LOAD 11
113#define OLPC_GPIO_SMB_DATA geode_gpio(15) 115#define OLPC_GPIO_DCON_BLANK 12
116#define OLPC_GPIO_SMB_CLK 14
117#define OLPC_GPIO_SMB_DATA 15
114#define OLPC_GPIO_WORKAUX geode_gpio(24) 118#define OLPC_GPIO_WORKAUX geode_gpio(24)
115#define OLPC_GPIO_LID geode_gpio(26) 119#define OLPC_GPIO_LID geode_gpio(26)
116#define OLPC_GPIO_ECSCI geode_gpio(27) 120#define OLPC_GPIO_ECSCI geode_gpio(27)
diff --git a/arch/x86/include/asm/olpc_ofw.h b/arch/x86/include/asm/olpc_ofw.h
index 2a8478140bb3..641988efe063 100644
--- a/arch/x86/include/asm/olpc_ofw.h
+++ b/arch/x86/include/asm/olpc_ofw.h
@@ -8,6 +8,8 @@
8 8
9#ifdef CONFIG_OLPC_OPENFIRMWARE 9#ifdef CONFIG_OLPC_OPENFIRMWARE
10 10
11extern bool olpc_ofw_is_installed(void);
12
11/* run an OFW command by calling into the firmware */ 13/* run an OFW command by calling into the firmware */
12#define olpc_ofw(name, args, res) \ 14#define olpc_ofw(name, args, res) \
13 __olpc_ofw((name), ARRAY_SIZE(args), args, ARRAY_SIZE(res), res) 15 __olpc_ofw((name), ARRAY_SIZE(args), args, ARRAY_SIZE(res), res)
@@ -26,10 +28,17 @@ extern bool olpc_ofw_present(void);
26 28
27#else /* !CONFIG_OLPC_OPENFIRMWARE */ 29#else /* !CONFIG_OLPC_OPENFIRMWARE */
28 30
31static inline bool olpc_ofw_is_installed(void) { return false; }
29static inline void olpc_ofw_detect(void) { } 32static inline void olpc_ofw_detect(void) { }
30static inline void setup_olpc_ofw_pgd(void) { } 33static inline void setup_olpc_ofw_pgd(void) { }
31static inline bool olpc_ofw_present(void) { return false; } 34static inline bool olpc_ofw_present(void) { return false; }
32 35
33#endif /* !CONFIG_OLPC_OPENFIRMWARE */ 36#endif /* !CONFIG_OLPC_OPENFIRMWARE */
34 37
38#ifdef CONFIG_OLPC_OPENFIRMWARE_DT
39extern void olpc_dt_build_devicetree(void);
40#else
41static inline void olpc_dt_build_devicetree(void) { }
42#endif /* CONFIG_OLPC_OPENFIRMWARE_DT */
43
35#endif /* _ASM_X86_OLPC_OFW_H */ 44#endif /* _ASM_X86_OLPC_OFW_H */
diff --git a/arch/x86/include/asm/pgalloc.h b/arch/x86/include/asm/pgalloc.h
index 271de94c3810..b4389a468fb6 100644
--- a/arch/x86/include/asm/pgalloc.h
+++ b/arch/x86/include/asm/pgalloc.h
@@ -92,7 +92,7 @@ static inline void pmd_free(struct mm_struct *mm, pmd_t *pmd)
92extern void ___pmd_free_tlb(struct mmu_gather *tlb, pmd_t *pmd); 92extern void ___pmd_free_tlb(struct mmu_gather *tlb, pmd_t *pmd);
93 93
94static inline void __pmd_free_tlb(struct mmu_gather *tlb, pmd_t *pmd, 94static inline void __pmd_free_tlb(struct mmu_gather *tlb, pmd_t *pmd,
95 unsigned long adddress) 95 unsigned long address)
96{ 96{
97 ___pmd_free_tlb(tlb, pmd); 97 ___pmd_free_tlb(tlb, pmd);
98} 98}
diff --git a/arch/x86/include/asm/processor.h b/arch/x86/include/asm/processor.h
index c6efecf85a6a..53fd1d5a1fe0 100644
--- a/arch/x86/include/asm/processor.h
+++ b/arch/x86/include/asm/processor.h
@@ -901,7 +901,7 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
901/* 901/*
902 * The below -8 is to reserve 8 bytes on top of the ring0 stack. 902 * The below -8 is to reserve 8 bytes on top of the ring0 stack.
903 * This is necessary to guarantee that the entire "struct pt_regs" 903 * This is necessary to guarantee that the entire "struct pt_regs"
904 * is accessable even if the CPU haven't stored the SS/ESP registers 904 * is accessible even if the CPU haven't stored the SS/ESP registers
905 * on the stack (interrupt gate does not save these registers 905 * on the stack (interrupt gate does not save these registers
906 * when switching to the same priv ring). 906 * when switching to the same priv ring).
907 * Therefore beware: accessing the ss/esp fields of the 907 * Therefore beware: accessing the ss/esp fields of the
diff --git a/arch/x86/include/asm/prom.h b/arch/x86/include/asm/prom.h
new file mode 100644
index 000000000000..b4ec95f07518
--- /dev/null
+++ b/arch/x86/include/asm/prom.h
@@ -0,0 +1 @@
/* dummy prom.h; here to make linux/of.h's #includes happy */
diff --git a/arch/x86/include/asm/svm.h b/arch/x86/include/asm/svm.h
index 0e831059ac5a..f2b83bc7d784 100644
--- a/arch/x86/include/asm/svm.h
+++ b/arch/x86/include/asm/svm.h
@@ -47,14 +47,13 @@ enum {
47 INTERCEPT_MONITOR, 47 INTERCEPT_MONITOR,
48 INTERCEPT_MWAIT, 48 INTERCEPT_MWAIT,
49 INTERCEPT_MWAIT_COND, 49 INTERCEPT_MWAIT_COND,
50 INTERCEPT_XSETBV,
50}; 51};
51 52
52 53
53struct __attribute__ ((__packed__)) vmcb_control_area { 54struct __attribute__ ((__packed__)) vmcb_control_area {
54 u16 intercept_cr_read; 55 u32 intercept_cr;
55 u16 intercept_cr_write; 56 u32 intercept_dr;
56 u16 intercept_dr_read;
57 u16 intercept_dr_write;
58 u32 intercept_exceptions; 57 u32 intercept_exceptions;
59 u64 intercept; 58 u64 intercept;
60 u8 reserved_1[42]; 59 u8 reserved_1[42];
@@ -81,14 +80,19 @@ struct __attribute__ ((__packed__)) vmcb_control_area {
81 u32 event_inj_err; 80 u32 event_inj_err;
82 u64 nested_cr3; 81 u64 nested_cr3;
83 u64 lbr_ctl; 82 u64 lbr_ctl;
84 u64 reserved_5; 83 u32 clean;
84 u32 reserved_5;
85 u64 next_rip; 85 u64 next_rip;
86 u8 reserved_6[816]; 86 u8 insn_len;
87 u8 insn_bytes[15];
88 u8 reserved_6[800];
87}; 89};
88 90
89 91
90#define TLB_CONTROL_DO_NOTHING 0 92#define TLB_CONTROL_DO_NOTHING 0
91#define TLB_CONTROL_FLUSH_ALL_ASID 1 93#define TLB_CONTROL_FLUSH_ALL_ASID 1
94#define TLB_CONTROL_FLUSH_ASID 3
95#define TLB_CONTROL_FLUSH_ASID_LOCAL 7
92 96
93#define V_TPR_MASK 0x0f 97#define V_TPR_MASK 0x0f
94 98
@@ -204,19 +208,31 @@ struct __attribute__ ((__packed__)) vmcb {
204#define SVM_SELECTOR_READ_MASK SVM_SELECTOR_WRITE_MASK 208#define SVM_SELECTOR_READ_MASK SVM_SELECTOR_WRITE_MASK
205#define SVM_SELECTOR_CODE_MASK (1 << 3) 209#define SVM_SELECTOR_CODE_MASK (1 << 3)
206 210
207#define INTERCEPT_CR0_MASK 1 211#define INTERCEPT_CR0_READ 0
208#define INTERCEPT_CR3_MASK (1 << 3) 212#define INTERCEPT_CR3_READ 3
209#define INTERCEPT_CR4_MASK (1 << 4) 213#define INTERCEPT_CR4_READ 4
210#define INTERCEPT_CR8_MASK (1 << 8) 214#define INTERCEPT_CR8_READ 8
211 215#define INTERCEPT_CR0_WRITE (16 + 0)
212#define INTERCEPT_DR0_MASK 1 216#define INTERCEPT_CR3_WRITE (16 + 3)
213#define INTERCEPT_DR1_MASK (1 << 1) 217#define INTERCEPT_CR4_WRITE (16 + 4)
214#define INTERCEPT_DR2_MASK (1 << 2) 218#define INTERCEPT_CR8_WRITE (16 + 8)
215#define INTERCEPT_DR3_MASK (1 << 3) 219
216#define INTERCEPT_DR4_MASK (1 << 4) 220#define INTERCEPT_DR0_READ 0
217#define INTERCEPT_DR5_MASK (1 << 5) 221#define INTERCEPT_DR1_READ 1
218#define INTERCEPT_DR6_MASK (1 << 6) 222#define INTERCEPT_DR2_READ 2
219#define INTERCEPT_DR7_MASK (1 << 7) 223#define INTERCEPT_DR3_READ 3
224#define INTERCEPT_DR4_READ 4
225#define INTERCEPT_DR5_READ 5
226#define INTERCEPT_DR6_READ 6
227#define INTERCEPT_DR7_READ 7
228#define INTERCEPT_DR0_WRITE (16 + 0)
229#define INTERCEPT_DR1_WRITE (16 + 1)
230#define INTERCEPT_DR2_WRITE (16 + 2)
231#define INTERCEPT_DR3_WRITE (16 + 3)
232#define INTERCEPT_DR4_WRITE (16 + 4)
233#define INTERCEPT_DR5_WRITE (16 + 5)
234#define INTERCEPT_DR6_WRITE (16 + 6)
235#define INTERCEPT_DR7_WRITE (16 + 7)
220 236
221#define SVM_EVTINJ_VEC_MASK 0xff 237#define SVM_EVTINJ_VEC_MASK 0xff
222 238
@@ -246,6 +262,8 @@ struct __attribute__ ((__packed__)) vmcb {
246#define SVM_EXITINFOSHIFT_TS_REASON_JMP 38 262#define SVM_EXITINFOSHIFT_TS_REASON_JMP 38
247#define SVM_EXITINFOSHIFT_TS_HAS_ERROR_CODE 44 263#define SVM_EXITINFOSHIFT_TS_HAS_ERROR_CODE 44
248 264
265#define SVM_EXITINFO_REG_MASK 0x0F
266
249#define SVM_EXIT_READ_CR0 0x000 267#define SVM_EXIT_READ_CR0 0x000
250#define SVM_EXIT_READ_CR3 0x003 268#define SVM_EXIT_READ_CR3 0x003
251#define SVM_EXIT_READ_CR4 0x004 269#define SVM_EXIT_READ_CR4 0x004
@@ -316,6 +334,7 @@ struct __attribute__ ((__packed__)) vmcb {
316#define SVM_EXIT_MONITOR 0x08a 334#define SVM_EXIT_MONITOR 0x08a
317#define SVM_EXIT_MWAIT 0x08b 335#define SVM_EXIT_MWAIT 0x08b
318#define SVM_EXIT_MWAIT_COND 0x08c 336#define SVM_EXIT_MWAIT_COND 0x08c
337#define SVM_EXIT_XSETBV 0x08d
319#define SVM_EXIT_NPF 0x400 338#define SVM_EXIT_NPF 0x400
320 339
321#define SVM_EXIT_ERR -1 340#define SVM_EXIT_ERR -1
diff --git a/arch/x86/include/asm/traps.h b/arch/x86/include/asm/traps.h
index f66cda56781d..0310da67307f 100644
--- a/arch/x86/include/asm/traps.h
+++ b/arch/x86/include/asm/traps.h
@@ -30,6 +30,7 @@ asmlinkage void segment_not_present(void);
30asmlinkage void stack_segment(void); 30asmlinkage void stack_segment(void);
31asmlinkage void general_protection(void); 31asmlinkage void general_protection(void);
32asmlinkage void page_fault(void); 32asmlinkage void page_fault(void);
33asmlinkage void async_page_fault(void);
33asmlinkage void spurious_interrupt_bug(void); 34asmlinkage void spurious_interrupt_bug(void);
34asmlinkage void coprocessor_error(void); 35asmlinkage void coprocessor_error(void);
35asmlinkage void alignment_check(void); 36asmlinkage void alignment_check(void);
diff --git a/arch/x86/include/asm/vmx.h b/arch/x86/include/asm/vmx.h
index 9f0cbd987d50..84471b810460 100644
--- a/arch/x86/include/asm/vmx.h
+++ b/arch/x86/include/asm/vmx.h
@@ -66,15 +66,23 @@
66#define PIN_BASED_NMI_EXITING 0x00000008 66#define PIN_BASED_NMI_EXITING 0x00000008
67#define PIN_BASED_VIRTUAL_NMIS 0x00000020 67#define PIN_BASED_VIRTUAL_NMIS 0x00000020
68 68
69#define VM_EXIT_SAVE_DEBUG_CONTROLS 0x00000002
69#define VM_EXIT_HOST_ADDR_SPACE_SIZE 0x00000200 70#define VM_EXIT_HOST_ADDR_SPACE_SIZE 0x00000200
71#define VM_EXIT_LOAD_IA32_PERF_GLOBAL_CTRL 0x00001000
70#define VM_EXIT_ACK_INTR_ON_EXIT 0x00008000 72#define VM_EXIT_ACK_INTR_ON_EXIT 0x00008000
71#define VM_EXIT_SAVE_IA32_PAT 0x00040000 73#define VM_EXIT_SAVE_IA32_PAT 0x00040000
72#define VM_EXIT_LOAD_IA32_PAT 0x00080000 74#define VM_EXIT_LOAD_IA32_PAT 0x00080000
75#define VM_EXIT_SAVE_IA32_EFER 0x00100000
76#define VM_EXIT_LOAD_IA32_EFER 0x00200000
77#define VM_EXIT_SAVE_VMX_PREEMPTION_TIMER 0x00400000
73 78
79#define VM_ENTRY_LOAD_DEBUG_CONTROLS 0x00000002
74#define VM_ENTRY_IA32E_MODE 0x00000200 80#define VM_ENTRY_IA32E_MODE 0x00000200
75#define VM_ENTRY_SMM 0x00000400 81#define VM_ENTRY_SMM 0x00000400
76#define VM_ENTRY_DEACT_DUAL_MONITOR 0x00000800 82#define VM_ENTRY_DEACT_DUAL_MONITOR 0x00000800
83#define VM_ENTRY_LOAD_IA32_PERF_GLOBAL_CTRL 0x00002000
77#define VM_ENTRY_LOAD_IA32_PAT 0x00004000 84#define VM_ENTRY_LOAD_IA32_PAT 0x00004000
85#define VM_ENTRY_LOAD_IA32_EFER 0x00008000
78 86
79/* VMCS Encodings */ 87/* VMCS Encodings */
80enum vmcs_field { 88enum vmcs_field {
@@ -239,6 +247,7 @@ enum vmcs_field {
239#define EXIT_REASON_TASK_SWITCH 9 247#define EXIT_REASON_TASK_SWITCH 9
240#define EXIT_REASON_CPUID 10 248#define EXIT_REASON_CPUID 10
241#define EXIT_REASON_HLT 12 249#define EXIT_REASON_HLT 12
250#define EXIT_REASON_INVD 13
242#define EXIT_REASON_INVLPG 14 251#define EXIT_REASON_INVLPG 14
243#define EXIT_REASON_RDPMC 15 252#define EXIT_REASON_RDPMC 15
244#define EXIT_REASON_RDTSC 16 253#define EXIT_REASON_RDTSC 16
@@ -296,6 +305,12 @@ enum vmcs_field {
296#define GUEST_INTR_STATE_SMI 0x00000004 305#define GUEST_INTR_STATE_SMI 0x00000004
297#define GUEST_INTR_STATE_NMI 0x00000008 306#define GUEST_INTR_STATE_NMI 0x00000008
298 307
308/* GUEST_ACTIVITY_STATE flags */
309#define GUEST_ACTIVITY_ACTIVE 0
310#define GUEST_ACTIVITY_HLT 1
311#define GUEST_ACTIVITY_SHUTDOWN 2
312#define GUEST_ACTIVITY_WAIT_SIPI 3
313
299/* 314/*
300 * Exit Qualifications for MOV for Control Register Access 315 * Exit Qualifications for MOV for Control Register Access
301 */ 316 */
diff --git a/arch/x86/kernel/amd_iommu.c b/arch/x86/kernel/amd_iommu.c
index d2fdb0826df2..57ca77787220 100644
--- a/arch/x86/kernel/amd_iommu.c
+++ b/arch/x86/kernel/amd_iommu.c
@@ -1086,7 +1086,7 @@ static int alloc_new_range(struct dma_ops_domain *dma_dom,
1086 1086
1087 dma_dom->aperture_size += APERTURE_RANGE_SIZE; 1087 dma_dom->aperture_size += APERTURE_RANGE_SIZE;
1088 1088
1089 /* Intialize the exclusion range if necessary */ 1089 /* Initialize the exclusion range if necessary */
1090 for_each_iommu(iommu) { 1090 for_each_iommu(iommu) {
1091 if (iommu->exclusion_start && 1091 if (iommu->exclusion_start &&
1092 iommu->exclusion_start >= dma_dom->aperture[index]->offset 1092 iommu->exclusion_start >= dma_dom->aperture[index]->offset
@@ -1353,7 +1353,7 @@ static void dma_ops_domain_free(struct dma_ops_domain *dom)
1353 1353
1354/* 1354/*
1355 * Allocates a new protection domain usable for the dma_ops functions. 1355 * Allocates a new protection domain usable for the dma_ops functions.
1356 * It also intializes the page table and the address allocator data 1356 * It also initializes the page table and the address allocator data
1357 * structures required for the dma_ops interface 1357 * structures required for the dma_ops interface
1358 */ 1358 */
1359static struct dma_ops_domain *dma_ops_domain_alloc(void) 1359static struct dma_ops_domain *dma_ops_domain_alloc(void)
diff --git a/arch/x86/kernel/entry_32.S b/arch/x86/kernel/entry_32.S
index 591e60104278..c8b4efad7ebb 100644
--- a/arch/x86/kernel/entry_32.S
+++ b/arch/x86/kernel/entry_32.S
@@ -1406,6 +1406,16 @@ ENTRY(general_protection)
1406 CFI_ENDPROC 1406 CFI_ENDPROC
1407END(general_protection) 1407END(general_protection)
1408 1408
1409#ifdef CONFIG_KVM_GUEST
1410ENTRY(async_page_fault)
1411 RING0_EC_FRAME
1412 pushl $do_async_page_fault
1413 CFI_ADJUST_CFA_OFFSET 4
1414 jmp error_code
1415 CFI_ENDPROC
1416END(apf_page_fault)
1417#endif
1418
1409/* 1419/*
1410 * End of kprobes section 1420 * End of kprobes section
1411 */ 1421 */
diff --git a/arch/x86/kernel/entry_64.S b/arch/x86/kernel/entry_64.S
index d3b895f375d3..aed1ffbeb0c9 100644
--- a/arch/x86/kernel/entry_64.S
+++ b/arch/x86/kernel/entry_64.S
@@ -1329,6 +1329,9 @@ errorentry xen_stack_segment do_stack_segment
1329#endif 1329#endif
1330errorentry general_protection do_general_protection 1330errorentry general_protection do_general_protection
1331errorentry page_fault do_page_fault 1331errorentry page_fault do_page_fault
1332#ifdef CONFIG_KVM_GUEST
1333errorentry async_page_fault do_async_page_fault
1334#endif
1332#ifdef CONFIG_X86_MCE 1335#ifdef CONFIG_X86_MCE
1333paranoidzeroentry machine_check *machine_check_vector(%rip) 1336paranoidzeroentry machine_check *machine_check_vector(%rip)
1334#endif 1337#endif
diff --git a/arch/x86/kernel/head_32.S b/arch/x86/kernel/head_32.S
index 9f54b209c378..fc293dc8dc35 100644
--- a/arch/x86/kernel/head_32.S
+++ b/arch/x86/kernel/head_32.S
@@ -126,7 +126,7 @@ ENTRY(startup_32)
126 movsl 126 movsl
127 movl pa(boot_params) + NEW_CL_POINTER,%esi 127 movl pa(boot_params) + NEW_CL_POINTER,%esi
128 andl %esi,%esi 128 andl %esi,%esi
129 jz 1f # No comand line 129 jz 1f # No command line
130 movl $pa(boot_command_line),%edi 130 movl $pa(boot_command_line),%edi
131 movl $(COMMAND_LINE_SIZE/4),%ecx 131 movl $(COMMAND_LINE_SIZE/4),%ecx
132 rep 132 rep
diff --git a/arch/x86/kernel/i387.c b/arch/x86/kernel/i387.c
index 58bb239a2fd7..e60c38cc0eed 100644
--- a/arch/x86/kernel/i387.c
+++ b/arch/x86/kernel/i387.c
@@ -169,6 +169,7 @@ int init_fpu(struct task_struct *tsk)
169 set_stopped_child_used_math(tsk); 169 set_stopped_child_used_math(tsk);
170 return 0; 170 return 0;
171} 171}
172EXPORT_SYMBOL_GPL(init_fpu);
172 173
173/* 174/*
174 * The xstateregs_active() routine is the same as the fpregs_active() routine, 175 * The xstateregs_active() routine is the same as the fpregs_active() routine,
diff --git a/arch/x86/kernel/irq.c b/arch/x86/kernel/irq.c
index 3a43caa3beb7..52945da52a94 100644
--- a/arch/x86/kernel/irq.c
+++ b/arch/x86/kernel/irq.c
@@ -4,6 +4,7 @@
4#include <linux/cpu.h> 4#include <linux/cpu.h>
5#include <linux/interrupt.h> 5#include <linux/interrupt.h>
6#include <linux/kernel_stat.h> 6#include <linux/kernel_stat.h>
7#include <linux/of.h>
7#include <linux/seq_file.h> 8#include <linux/seq_file.h>
8#include <linux/smp.h> 9#include <linux/smp.h>
9#include <linux/ftrace.h> 10#include <linux/ftrace.h>
@@ -275,6 +276,15 @@ void smp_x86_platform_ipi(struct pt_regs *regs)
275 276
276EXPORT_SYMBOL_GPL(vector_used_by_percpu_irq); 277EXPORT_SYMBOL_GPL(vector_used_by_percpu_irq);
277 278
279#ifdef CONFIG_OF
280unsigned int irq_create_of_mapping(struct device_node *controller,
281 const u32 *intspec, unsigned int intsize)
282{
283 return intspec[0];
284}
285EXPORT_SYMBOL_GPL(irq_create_of_mapping);
286#endif
287
278#ifdef CONFIG_HOTPLUG_CPU 288#ifdef CONFIG_HOTPLUG_CPU
279/* A cpu has been removed from cpu_online_mask. Reset irq affinities. */ 289/* A cpu has been removed from cpu_online_mask. Reset irq affinities. */
280void fixup_irqs(void) 290void fixup_irqs(void)
diff --git a/arch/x86/kernel/kvm.c b/arch/x86/kernel/kvm.c
index 63b0ec8d3d4a..8dc44662394b 100644
--- a/arch/x86/kernel/kvm.c
+++ b/arch/x86/kernel/kvm.c
@@ -27,16 +27,37 @@
27#include <linux/mm.h> 27#include <linux/mm.h>
28#include <linux/highmem.h> 28#include <linux/highmem.h>
29#include <linux/hardirq.h> 29#include <linux/hardirq.h>
30#include <linux/notifier.h>
31#include <linux/reboot.h>
32#include <linux/hash.h>
33#include <linux/sched.h>
34#include <linux/slab.h>
35#include <linux/kprobes.h>
30#include <asm/timer.h> 36#include <asm/timer.h>
37#include <asm/cpu.h>
38#include <asm/traps.h>
39#include <asm/desc.h>
40#include <asm/tlbflush.h>
31 41
32#define MMU_QUEUE_SIZE 1024 42#define MMU_QUEUE_SIZE 1024
33 43
44static int kvmapf = 1;
45
46static int parse_no_kvmapf(char *arg)
47{
48 kvmapf = 0;
49 return 0;
50}
51
52early_param("no-kvmapf", parse_no_kvmapf);
53
34struct kvm_para_state { 54struct kvm_para_state {
35 u8 mmu_queue[MMU_QUEUE_SIZE]; 55 u8 mmu_queue[MMU_QUEUE_SIZE];
36 int mmu_queue_len; 56 int mmu_queue_len;
37}; 57};
38 58
39static DEFINE_PER_CPU(struct kvm_para_state, para_state); 59static DEFINE_PER_CPU(struct kvm_para_state, para_state);
60static DEFINE_PER_CPU(struct kvm_vcpu_pv_apf_data, apf_reason) __aligned(64);
40 61
41static struct kvm_para_state *kvm_para_state(void) 62static struct kvm_para_state *kvm_para_state(void)
42{ 63{
@@ -50,6 +71,195 @@ static void kvm_io_delay(void)
50{ 71{
51} 72}
52 73
74#define KVM_TASK_SLEEP_HASHBITS 8
75#define KVM_TASK_SLEEP_HASHSIZE (1<<KVM_TASK_SLEEP_HASHBITS)
76
77struct kvm_task_sleep_node {
78 struct hlist_node link;
79 wait_queue_head_t wq;
80 u32 token;
81 int cpu;
82 bool halted;
83 struct mm_struct *mm;
84};
85
86static struct kvm_task_sleep_head {
87 spinlock_t lock;
88 struct hlist_head list;
89} async_pf_sleepers[KVM_TASK_SLEEP_HASHSIZE];
90
91static struct kvm_task_sleep_node *_find_apf_task(struct kvm_task_sleep_head *b,
92 u32 token)
93{
94 struct hlist_node *p;
95
96 hlist_for_each(p, &b->list) {
97 struct kvm_task_sleep_node *n =
98 hlist_entry(p, typeof(*n), link);
99 if (n->token == token)
100 return n;
101 }
102
103 return NULL;
104}
105
106void kvm_async_pf_task_wait(u32 token)
107{
108 u32 key = hash_32(token, KVM_TASK_SLEEP_HASHBITS);
109 struct kvm_task_sleep_head *b = &async_pf_sleepers[key];
110 struct kvm_task_sleep_node n, *e;
111 DEFINE_WAIT(wait);
112 int cpu, idle;
113
114 cpu = get_cpu();
115 idle = idle_cpu(cpu);
116 put_cpu();
117
118 spin_lock(&b->lock);
119 e = _find_apf_task(b, token);
120 if (e) {
121 /* dummy entry exist -> wake up was delivered ahead of PF */
122 hlist_del(&e->link);
123 kfree(e);
124 spin_unlock(&b->lock);
125 return;
126 }
127
128 n.token = token;
129 n.cpu = smp_processor_id();
130 n.mm = current->active_mm;
131 n.halted = idle || preempt_count() > 1;
132 atomic_inc(&n.mm->mm_count);
133 init_waitqueue_head(&n.wq);
134 hlist_add_head(&n.link, &b->list);
135 spin_unlock(&b->lock);
136
137 for (;;) {
138 if (!n.halted)
139 prepare_to_wait(&n.wq, &wait, TASK_UNINTERRUPTIBLE);
140 if (hlist_unhashed(&n.link))
141 break;
142
143 if (!n.halted) {
144 local_irq_enable();
145 schedule();
146 local_irq_disable();
147 } else {
148 /*
149 * We cannot reschedule. So halt.
150 */
151 native_safe_halt();
152 local_irq_disable();
153 }
154 }
155 if (!n.halted)
156 finish_wait(&n.wq, &wait);
157
158 return;
159}
160EXPORT_SYMBOL_GPL(kvm_async_pf_task_wait);
161
162static void apf_task_wake_one(struct kvm_task_sleep_node *n)
163{
164 hlist_del_init(&n->link);
165 if (!n->mm)
166 return;
167 mmdrop(n->mm);
168 if (n->halted)
169 smp_send_reschedule(n->cpu);
170 else if (waitqueue_active(&n->wq))
171 wake_up(&n->wq);
172}
173
174static void apf_task_wake_all(void)
175{
176 int i;
177
178 for (i = 0; i < KVM_TASK_SLEEP_HASHSIZE; i++) {
179 struct hlist_node *p, *next;
180 struct kvm_task_sleep_head *b = &async_pf_sleepers[i];
181 spin_lock(&b->lock);
182 hlist_for_each_safe(p, next, &b->list) {
183 struct kvm_task_sleep_node *n =
184 hlist_entry(p, typeof(*n), link);
185 if (n->cpu == smp_processor_id())
186 apf_task_wake_one(n);
187 }
188 spin_unlock(&b->lock);
189 }
190}
191
192void kvm_async_pf_task_wake(u32 token)
193{
194 u32 key = hash_32(token, KVM_TASK_SLEEP_HASHBITS);
195 struct kvm_task_sleep_head *b = &async_pf_sleepers[key];
196 struct kvm_task_sleep_node *n;
197
198 if (token == ~0) {
199 apf_task_wake_all();
200 return;
201 }
202
203again:
204 spin_lock(&b->lock);
205 n = _find_apf_task(b, token);
206 if (!n) {
207 /*
208 * async PF was not yet handled.
209 * Add dummy entry for the token.
210 */
211 n = kmalloc(sizeof(*n), GFP_ATOMIC);
212 if (!n) {
213 /*
214 * Allocation failed! Busy wait while other cpu
215 * handles async PF.
216 */
217 spin_unlock(&b->lock);
218 cpu_relax();
219 goto again;
220 }
221 n->token = token;
222 n->cpu = smp_processor_id();
223 n->mm = NULL;
224 init_waitqueue_head(&n->wq);
225 hlist_add_head(&n->link, &b->list);
226 } else
227 apf_task_wake_one(n);
228 spin_unlock(&b->lock);
229 return;
230}
231EXPORT_SYMBOL_GPL(kvm_async_pf_task_wake);
232
233u32 kvm_read_and_reset_pf_reason(void)
234{
235 u32 reason = 0;
236
237 if (__get_cpu_var(apf_reason).enabled) {
238 reason = __get_cpu_var(apf_reason).reason;
239 __get_cpu_var(apf_reason).reason = 0;
240 }
241
242 return reason;
243}
244EXPORT_SYMBOL_GPL(kvm_read_and_reset_pf_reason);
245
246dotraplinkage void __kprobes
247do_async_page_fault(struct pt_regs *regs, unsigned long error_code)
248{
249 switch (kvm_read_and_reset_pf_reason()) {
250 default:
251 do_page_fault(regs, error_code);
252 break;
253 case KVM_PV_REASON_PAGE_NOT_PRESENT:
254 /* page is swapped out by the host. */
255 kvm_async_pf_task_wait((u32)read_cr2());
256 break;
257 case KVM_PV_REASON_PAGE_READY:
258 kvm_async_pf_task_wake((u32)read_cr2());
259 break;
260 }
261}
262
53static void kvm_mmu_op(void *buffer, unsigned len) 263static void kvm_mmu_op(void *buffer, unsigned len)
54{ 264{
55 int r; 265 int r;
@@ -231,10 +441,117 @@ static void __init paravirt_ops_setup(void)
231#endif 441#endif
232} 442}
233 443
444void __cpuinit kvm_guest_cpu_init(void)
445{
446 if (!kvm_para_available())
447 return;
448
449 if (kvm_para_has_feature(KVM_FEATURE_ASYNC_PF) && kvmapf) {
450 u64 pa = __pa(&__get_cpu_var(apf_reason));
451
452#ifdef CONFIG_PREEMPT
453 pa |= KVM_ASYNC_PF_SEND_ALWAYS;
454#endif
455 wrmsrl(MSR_KVM_ASYNC_PF_EN, pa | KVM_ASYNC_PF_ENABLED);
456 __get_cpu_var(apf_reason).enabled = 1;
457 printk(KERN_INFO"KVM setup async PF for cpu %d\n",
458 smp_processor_id());
459 }
460}
461
462static void kvm_pv_disable_apf(void *unused)
463{
464 if (!__get_cpu_var(apf_reason).enabled)
465 return;
466
467 wrmsrl(MSR_KVM_ASYNC_PF_EN, 0);
468 __get_cpu_var(apf_reason).enabled = 0;
469
470 printk(KERN_INFO"Unregister pv shared memory for cpu %d\n",
471 smp_processor_id());
472}
473
474static int kvm_pv_reboot_notify(struct notifier_block *nb,
475 unsigned long code, void *unused)
476{
477 if (code == SYS_RESTART)
478 on_each_cpu(kvm_pv_disable_apf, NULL, 1);
479 return NOTIFY_DONE;
480}
481
482static struct notifier_block kvm_pv_reboot_nb = {
483 .notifier_call = kvm_pv_reboot_notify,
484};
485
486#ifdef CONFIG_SMP
487static void __init kvm_smp_prepare_boot_cpu(void)
488{
489#ifdef CONFIG_KVM_CLOCK
490 WARN_ON(kvm_register_clock("primary cpu clock"));
491#endif
492 kvm_guest_cpu_init();
493 native_smp_prepare_boot_cpu();
494}
495
496static void kvm_guest_cpu_online(void *dummy)
497{
498 kvm_guest_cpu_init();
499}
500
501static void kvm_guest_cpu_offline(void *dummy)
502{
503 kvm_pv_disable_apf(NULL);
504 apf_task_wake_all();
505}
506
507static int __cpuinit kvm_cpu_notify(struct notifier_block *self,
508 unsigned long action, void *hcpu)
509{
510 int cpu = (unsigned long)hcpu;
511 switch (action) {
512 case CPU_ONLINE:
513 case CPU_DOWN_FAILED:
514 case CPU_ONLINE_FROZEN:
515 smp_call_function_single(cpu, kvm_guest_cpu_online, NULL, 0);
516 break;
517 case CPU_DOWN_PREPARE:
518 case CPU_DOWN_PREPARE_FROZEN:
519 smp_call_function_single(cpu, kvm_guest_cpu_offline, NULL, 1);
520 break;
521 default:
522 break;
523 }
524 return NOTIFY_OK;
525}
526
527static struct notifier_block __cpuinitdata kvm_cpu_notifier = {
528 .notifier_call = kvm_cpu_notify,
529};
530#endif
531
532static void __init kvm_apf_trap_init(void)
533{
534 set_intr_gate(14, &async_page_fault);
535}
536
234void __init kvm_guest_init(void) 537void __init kvm_guest_init(void)
235{ 538{
539 int i;
540
236 if (!kvm_para_available()) 541 if (!kvm_para_available())
237 return; 542 return;
238 543
239 paravirt_ops_setup(); 544 paravirt_ops_setup();
545 register_reboot_notifier(&kvm_pv_reboot_nb);
546 for (i = 0; i < KVM_TASK_SLEEP_HASHSIZE; i++)
547 spin_lock_init(&async_pf_sleepers[i].lock);
548 if (kvm_para_has_feature(KVM_FEATURE_ASYNC_PF))
549 x86_init.irqs.trap_init = kvm_apf_trap_init;
550
551#ifdef CONFIG_SMP
552 smp_ops.smp_prepare_boot_cpu = kvm_smp_prepare_boot_cpu;
553 register_cpu_notifier(&kvm_cpu_notifier);
554#else
555 kvm_guest_cpu_init();
556#endif
240} 557}
diff --git a/arch/x86/kernel/kvmclock.c b/arch/x86/kernel/kvmclock.c
index ca43ce31a19c..f98d3eafe07a 100644
--- a/arch/x86/kernel/kvmclock.c
+++ b/arch/x86/kernel/kvmclock.c
@@ -125,7 +125,7 @@ static struct clocksource kvm_clock = {
125 .flags = CLOCK_SOURCE_IS_CONTINUOUS, 125 .flags = CLOCK_SOURCE_IS_CONTINUOUS,
126}; 126};
127 127
128static int kvm_register_clock(char *txt) 128int kvm_register_clock(char *txt)
129{ 129{
130 int cpu = smp_processor_id(); 130 int cpu = smp_processor_id();
131 int low, high, ret; 131 int low, high, ret;
@@ -152,14 +152,6 @@ static void __cpuinit kvm_setup_secondary_clock(void)
152} 152}
153#endif 153#endif
154 154
155#ifdef CONFIG_SMP
156static void __init kvm_smp_prepare_boot_cpu(void)
157{
158 WARN_ON(kvm_register_clock("primary cpu clock"));
159 native_smp_prepare_boot_cpu();
160}
161#endif
162
163/* 155/*
164 * After the clock is registered, the host will keep writing to the 156 * After the clock is registered, the host will keep writing to the
165 * registered memory location. If the guest happens to shutdown, this memory 157 * registered memory location. If the guest happens to shutdown, this memory
@@ -206,9 +198,6 @@ void __init kvmclock_init(void)
206 x86_cpuinit.setup_percpu_clockev = 198 x86_cpuinit.setup_percpu_clockev =
207 kvm_setup_secondary_clock; 199 kvm_setup_secondary_clock;
208#endif 200#endif
209#ifdef CONFIG_SMP
210 smp_ops.smp_prepare_boot_cpu = kvm_smp_prepare_boot_cpu;
211#endif
212 machine_ops.shutdown = kvm_shutdown; 201 machine_ops.shutdown = kvm_shutdown;
213#ifdef CONFIG_KEXEC 202#ifdef CONFIG_KEXEC
214 machine_ops.crash_shutdown = kvm_crash_shutdown; 203 machine_ops.crash_shutdown = kvm_crash_shutdown;
diff --git a/arch/x86/kernel/rtc.c b/arch/x86/kernel/rtc.c
index 1cfbbfc3ae26..6f39cab052d5 100644
--- a/arch/x86/kernel/rtc.c
+++ b/arch/x86/kernel/rtc.c
@@ -76,7 +76,7 @@ int mach_set_rtc_mmss(unsigned long nowtime)
76 CMOS_WRITE(real_seconds, RTC_SECONDS); 76 CMOS_WRITE(real_seconds, RTC_SECONDS);
77 CMOS_WRITE(real_minutes, RTC_MINUTES); 77 CMOS_WRITE(real_minutes, RTC_MINUTES);
78 } else { 78 } else {
79 printk(KERN_WARNING 79 printk_once(KERN_NOTICE
80 "set_rtc_mmss: can't update from %d to %d\n", 80 "set_rtc_mmss: can't update from %d to %d\n",
81 cmos_minutes, real_minutes); 81 cmos_minutes, real_minutes);
82 retval = -1; 82 retval = -1;
diff --git a/arch/x86/kvm/Kconfig b/arch/x86/kvm/Kconfig
index ddc131ff438f..50f63648ce1b 100644
--- a/arch/x86/kvm/Kconfig
+++ b/arch/x86/kvm/Kconfig
@@ -28,6 +28,7 @@ config KVM
28 select HAVE_KVM_IRQCHIP 28 select HAVE_KVM_IRQCHIP
29 select HAVE_KVM_EVENTFD 29 select HAVE_KVM_EVENTFD
30 select KVM_APIC_ARCHITECTURE 30 select KVM_APIC_ARCHITECTURE
31 select KVM_ASYNC_PF
31 select USER_RETURN_NOTIFIER 32 select USER_RETURN_NOTIFIER
32 select KVM_MMIO 33 select KVM_MMIO
33 ---help--- 34 ---help---
diff --git a/arch/x86/kvm/Makefile b/arch/x86/kvm/Makefile
index 31a7035c4bd9..f15501f431c8 100644
--- a/arch/x86/kvm/Makefile
+++ b/arch/x86/kvm/Makefile
@@ -1,5 +1,5 @@
1 1
2EXTRA_CFLAGS += -Ivirt/kvm -Iarch/x86/kvm 2ccflags-y += -Ivirt/kvm -Iarch/x86/kvm
3 3
4CFLAGS_x86.o := -I. 4CFLAGS_x86.o := -I.
5CFLAGS_svm.o := -I. 5CFLAGS_svm.o := -I.
@@ -9,6 +9,7 @@ kvm-y += $(addprefix ../../../virt/kvm/, kvm_main.o ioapic.o \
9 coalesced_mmio.o irq_comm.o eventfd.o \ 9 coalesced_mmio.o irq_comm.o eventfd.o \
10 assigned-dev.o) 10 assigned-dev.o)
11kvm-$(CONFIG_IOMMU_API) += $(addprefix ../../../virt/kvm/, iommu.o) 11kvm-$(CONFIG_IOMMU_API) += $(addprefix ../../../virt/kvm/, iommu.o)
12kvm-$(CONFIG_KVM_ASYNC_PF) += $(addprefix ../../../virt/kvm/, async_pf.o)
12 13
13kvm-y += x86.o mmu.o emulate.o i8259.o irq.o lapic.o \ 14kvm-y += x86.o mmu.o emulate.o i8259.o irq.o lapic.o \
14 i8254.o timer.o 15 i8254.o timer.o
diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c
index 38b6e8dafaff..caf966781d25 100644
--- a/arch/x86/kvm/emulate.c
+++ b/arch/x86/kvm/emulate.c
@@ -20,16 +20,8 @@
20 * From: xen-unstable 10676:af9809f51f81a3c43f276f00c81a52ef558afda4 20 * From: xen-unstable 10676:af9809f51f81a3c43f276f00c81a52ef558afda4
21 */ 21 */
22 22
23#ifndef __KERNEL__
24#include <stdio.h>
25#include <stdint.h>
26#include <public/xen.h>
27#define DPRINTF(_f, _a ...) printf(_f , ## _a)
28#else
29#include <linux/kvm_host.h> 23#include <linux/kvm_host.h>
30#include "kvm_cache_regs.h" 24#include "kvm_cache_regs.h"
31#define DPRINTF(x...) do {} while (0)
32#endif
33#include <linux/module.h> 25#include <linux/module.h>
34#include <asm/kvm_emulate.h> 26#include <asm/kvm_emulate.h>
35 27
@@ -418,9 +410,9 @@ address_mask(struct decode_cache *c, unsigned long reg)
418} 410}
419 411
420static inline unsigned long 412static inline unsigned long
421register_address(struct decode_cache *c, unsigned long base, unsigned long reg) 413register_address(struct decode_cache *c, unsigned long reg)
422{ 414{
423 return base + address_mask(c, reg); 415 return address_mask(c, reg);
424} 416}
425 417
426static inline void 418static inline void
@@ -452,60 +444,55 @@ static unsigned long seg_base(struct x86_emulate_ctxt *ctxt,
452 return ops->get_cached_segment_base(seg, ctxt->vcpu); 444 return ops->get_cached_segment_base(seg, ctxt->vcpu);
453} 445}
454 446
455static unsigned long seg_override_base(struct x86_emulate_ctxt *ctxt, 447static unsigned seg_override(struct x86_emulate_ctxt *ctxt,
456 struct x86_emulate_ops *ops, 448 struct x86_emulate_ops *ops,
457 struct decode_cache *c) 449 struct decode_cache *c)
458{ 450{
459 if (!c->has_seg_override) 451 if (!c->has_seg_override)
460 return 0; 452 return 0;
461 453
462 return seg_base(ctxt, ops, c->seg_override); 454 return c->seg_override;
463} 455}
464 456
465static unsigned long es_base(struct x86_emulate_ctxt *ctxt, 457static ulong linear(struct x86_emulate_ctxt *ctxt,
466 struct x86_emulate_ops *ops) 458 struct segmented_address addr)
467{ 459{
468 return seg_base(ctxt, ops, VCPU_SREG_ES); 460 struct decode_cache *c = &ctxt->decode;
469} 461 ulong la;
470
471static unsigned long ss_base(struct x86_emulate_ctxt *ctxt,
472 struct x86_emulate_ops *ops)
473{
474 return seg_base(ctxt, ops, VCPU_SREG_SS);
475}
476 462
477static void emulate_exception(struct x86_emulate_ctxt *ctxt, int vec, 463 la = seg_base(ctxt, ctxt->ops, addr.seg) + addr.ea;
478 u32 error, bool valid) 464 if (c->ad_bytes != 8)
479{ 465 la &= (u32)-1;
480 ctxt->exception = vec; 466 return la;
481 ctxt->error_code = error;
482 ctxt->error_code_valid = valid;
483} 467}
484 468
485static void emulate_gp(struct x86_emulate_ctxt *ctxt, int err) 469static int emulate_exception(struct x86_emulate_ctxt *ctxt, int vec,
470 u32 error, bool valid)
486{ 471{
487 emulate_exception(ctxt, GP_VECTOR, err, true); 472 ctxt->exception.vector = vec;
473 ctxt->exception.error_code = error;
474 ctxt->exception.error_code_valid = valid;
475 return X86EMUL_PROPAGATE_FAULT;
488} 476}
489 477
490static void emulate_pf(struct x86_emulate_ctxt *ctxt) 478static int emulate_gp(struct x86_emulate_ctxt *ctxt, int err)
491{ 479{
492 emulate_exception(ctxt, PF_VECTOR, 0, true); 480 return emulate_exception(ctxt, GP_VECTOR, err, true);
493} 481}
494 482
495static void emulate_ud(struct x86_emulate_ctxt *ctxt) 483static int emulate_ud(struct x86_emulate_ctxt *ctxt)
496{ 484{
497 emulate_exception(ctxt, UD_VECTOR, 0, false); 485 return emulate_exception(ctxt, UD_VECTOR, 0, false);
498} 486}
499 487
500static void emulate_ts(struct x86_emulate_ctxt *ctxt, int err) 488static int emulate_ts(struct x86_emulate_ctxt *ctxt, int err)
501{ 489{
502 emulate_exception(ctxt, TS_VECTOR, err, true); 490 return emulate_exception(ctxt, TS_VECTOR, err, true);
503} 491}
504 492
505static int emulate_de(struct x86_emulate_ctxt *ctxt) 493static int emulate_de(struct x86_emulate_ctxt *ctxt)
506{ 494{
507 emulate_exception(ctxt, DE_VECTOR, 0, false); 495 return emulate_exception(ctxt, DE_VECTOR, 0, false);
508 return X86EMUL_PROPAGATE_FAULT;
509} 496}
510 497
511static int do_fetch_insn_byte(struct x86_emulate_ctxt *ctxt, 498static int do_fetch_insn_byte(struct x86_emulate_ctxt *ctxt,
@@ -520,7 +507,7 @@ static int do_fetch_insn_byte(struct x86_emulate_ctxt *ctxt,
520 cur_size = fc->end - fc->start; 507 cur_size = fc->end - fc->start;
521 size = min(15UL - cur_size, PAGE_SIZE - offset_in_page(eip)); 508 size = min(15UL - cur_size, PAGE_SIZE - offset_in_page(eip));
522 rc = ops->fetch(ctxt->cs_base + eip, fc->data + cur_size, 509 rc = ops->fetch(ctxt->cs_base + eip, fc->data + cur_size,
523 size, ctxt->vcpu, NULL); 510 size, ctxt->vcpu, &ctxt->exception);
524 if (rc != X86EMUL_CONTINUE) 511 if (rc != X86EMUL_CONTINUE)
525 return rc; 512 return rc;
526 fc->end += size; 513 fc->end += size;
@@ -564,7 +551,7 @@ static void *decode_register(u8 modrm_reg, unsigned long *regs,
564 551
565static int read_descriptor(struct x86_emulate_ctxt *ctxt, 552static int read_descriptor(struct x86_emulate_ctxt *ctxt,
566 struct x86_emulate_ops *ops, 553 struct x86_emulate_ops *ops,
567 ulong addr, 554 struct segmented_address addr,
568 u16 *size, unsigned long *address, int op_bytes) 555 u16 *size, unsigned long *address, int op_bytes)
569{ 556{
570 int rc; 557 int rc;
@@ -572,10 +559,13 @@ static int read_descriptor(struct x86_emulate_ctxt *ctxt,
572 if (op_bytes == 2) 559 if (op_bytes == 2)
573 op_bytes = 3; 560 op_bytes = 3;
574 *address = 0; 561 *address = 0;
575 rc = ops->read_std(addr, (unsigned long *)size, 2, ctxt->vcpu, NULL); 562 rc = ops->read_std(linear(ctxt, addr), (unsigned long *)size, 2,
563 ctxt->vcpu, &ctxt->exception);
576 if (rc != X86EMUL_CONTINUE) 564 if (rc != X86EMUL_CONTINUE)
577 return rc; 565 return rc;
578 rc = ops->read_std(addr + 2, address, op_bytes, ctxt->vcpu, NULL); 566 addr.ea += 2;
567 rc = ops->read_std(linear(ctxt, addr), address, op_bytes,
568 ctxt->vcpu, &ctxt->exception);
579 return rc; 569 return rc;
580} 570}
581 571
@@ -768,7 +758,7 @@ static int decode_modrm(struct x86_emulate_ctxt *ctxt,
768 break; 758 break;
769 } 759 }
770 } 760 }
771 op->addr.mem = modrm_ea; 761 op->addr.mem.ea = modrm_ea;
772done: 762done:
773 return rc; 763 return rc;
774} 764}
@@ -783,13 +773,13 @@ static int decode_abs(struct x86_emulate_ctxt *ctxt,
783 op->type = OP_MEM; 773 op->type = OP_MEM;
784 switch (c->ad_bytes) { 774 switch (c->ad_bytes) {
785 case 2: 775 case 2:
786 op->addr.mem = insn_fetch(u16, 2, c->eip); 776 op->addr.mem.ea = insn_fetch(u16, 2, c->eip);
787 break; 777 break;
788 case 4: 778 case 4:
789 op->addr.mem = insn_fetch(u32, 4, c->eip); 779 op->addr.mem.ea = insn_fetch(u32, 4, c->eip);
790 break; 780 break;
791 case 8: 781 case 8:
792 op->addr.mem = insn_fetch(u64, 8, c->eip); 782 op->addr.mem.ea = insn_fetch(u64, 8, c->eip);
793 break; 783 break;
794 } 784 }
795done: 785done:
@@ -808,7 +798,7 @@ static void fetch_bit_operand(struct decode_cache *c)
808 else if (c->src.bytes == 4) 798 else if (c->src.bytes == 4)
809 sv = (s32)c->src.val & (s32)mask; 799 sv = (s32)c->src.val & (s32)mask;
810 800
811 c->dst.addr.mem += (sv >> 3); 801 c->dst.addr.mem.ea += (sv >> 3);
812 } 802 }
813 803
814 /* only subword offset */ 804 /* only subword offset */
@@ -821,7 +811,6 @@ static int read_emulated(struct x86_emulate_ctxt *ctxt,
821{ 811{
822 int rc; 812 int rc;
823 struct read_cache *mc = &ctxt->decode.mem_read; 813 struct read_cache *mc = &ctxt->decode.mem_read;
824 u32 err;
825 814
826 while (size) { 815 while (size) {
827 int n = min(size, 8u); 816 int n = min(size, 8u);
@@ -829,10 +818,8 @@ static int read_emulated(struct x86_emulate_ctxt *ctxt,
829 if (mc->pos < mc->end) 818 if (mc->pos < mc->end)
830 goto read_cached; 819 goto read_cached;
831 820
832 rc = ops->read_emulated(addr, mc->data + mc->end, n, &err, 821 rc = ops->read_emulated(addr, mc->data + mc->end, n,
833 ctxt->vcpu); 822 &ctxt->exception, ctxt->vcpu);
834 if (rc == X86EMUL_PROPAGATE_FAULT)
835 emulate_pf(ctxt);
836 if (rc != X86EMUL_CONTINUE) 823 if (rc != X86EMUL_CONTINUE)
837 return rc; 824 return rc;
838 mc->end += n; 825 mc->end += n;
@@ -907,19 +894,15 @@ static int read_segment_descriptor(struct x86_emulate_ctxt *ctxt,
907 struct desc_ptr dt; 894 struct desc_ptr dt;
908 u16 index = selector >> 3; 895 u16 index = selector >> 3;
909 int ret; 896 int ret;
910 u32 err;
911 ulong addr; 897 ulong addr;
912 898
913 get_descriptor_table_ptr(ctxt, ops, selector, &dt); 899 get_descriptor_table_ptr(ctxt, ops, selector, &dt);
914 900
915 if (dt.size < index * 8 + 7) { 901 if (dt.size < index * 8 + 7)
916 emulate_gp(ctxt, selector & 0xfffc); 902 return emulate_gp(ctxt, selector & 0xfffc);
917 return X86EMUL_PROPAGATE_FAULT;
918 }
919 addr = dt.address + index * 8; 903 addr = dt.address + index * 8;
920 ret = ops->read_std(addr, desc, sizeof *desc, ctxt->vcpu, &err); 904 ret = ops->read_std(addr, desc, sizeof *desc, ctxt->vcpu,
921 if (ret == X86EMUL_PROPAGATE_FAULT) 905 &ctxt->exception);
922 emulate_pf(ctxt);
923 906
924 return ret; 907 return ret;
925} 908}
@@ -931,21 +914,17 @@ static int write_segment_descriptor(struct x86_emulate_ctxt *ctxt,
931{ 914{
932 struct desc_ptr dt; 915 struct desc_ptr dt;
933 u16 index = selector >> 3; 916 u16 index = selector >> 3;
934 u32 err;
935 ulong addr; 917 ulong addr;
936 int ret; 918 int ret;
937 919
938 get_descriptor_table_ptr(ctxt, ops, selector, &dt); 920 get_descriptor_table_ptr(ctxt, ops, selector, &dt);
939 921
940 if (dt.size < index * 8 + 7) { 922 if (dt.size < index * 8 + 7)
941 emulate_gp(ctxt, selector & 0xfffc); 923 return emulate_gp(ctxt, selector & 0xfffc);
942 return X86EMUL_PROPAGATE_FAULT;
943 }
944 924
945 addr = dt.address + index * 8; 925 addr = dt.address + index * 8;
946 ret = ops->write_std(addr, desc, sizeof *desc, ctxt->vcpu, &err); 926 ret = ops->write_std(addr, desc, sizeof *desc, ctxt->vcpu,
947 if (ret == X86EMUL_PROPAGATE_FAULT) 927 &ctxt->exception);
948 emulate_pf(ctxt);
949 928
950 return ret; 929 return ret;
951} 930}
@@ -1092,7 +1071,6 @@ static inline int writeback(struct x86_emulate_ctxt *ctxt,
1092{ 1071{
1093 int rc; 1072 int rc;
1094 struct decode_cache *c = &ctxt->decode; 1073 struct decode_cache *c = &ctxt->decode;
1095 u32 err;
1096 1074
1097 switch (c->dst.type) { 1075 switch (c->dst.type) {
1098 case OP_REG: 1076 case OP_REG:
@@ -1101,21 +1079,19 @@ static inline int writeback(struct x86_emulate_ctxt *ctxt,
1101 case OP_MEM: 1079 case OP_MEM:
1102 if (c->lock_prefix) 1080 if (c->lock_prefix)
1103 rc = ops->cmpxchg_emulated( 1081 rc = ops->cmpxchg_emulated(
1104 c->dst.addr.mem, 1082 linear(ctxt, c->dst.addr.mem),
1105 &c->dst.orig_val, 1083 &c->dst.orig_val,
1106 &c->dst.val, 1084 &c->dst.val,
1107 c->dst.bytes, 1085 c->dst.bytes,
1108 &err, 1086 &ctxt->exception,
1109 ctxt->vcpu); 1087 ctxt->vcpu);
1110 else 1088 else
1111 rc = ops->write_emulated( 1089 rc = ops->write_emulated(
1112 c->dst.addr.mem, 1090 linear(ctxt, c->dst.addr.mem),
1113 &c->dst.val, 1091 &c->dst.val,
1114 c->dst.bytes, 1092 c->dst.bytes,
1115 &err, 1093 &ctxt->exception,
1116 ctxt->vcpu); 1094 ctxt->vcpu);
1117 if (rc == X86EMUL_PROPAGATE_FAULT)
1118 emulate_pf(ctxt);
1119 if (rc != X86EMUL_CONTINUE) 1095 if (rc != X86EMUL_CONTINUE)
1120 return rc; 1096 return rc;
1121 break; 1097 break;
@@ -1137,8 +1113,8 @@ static inline void emulate_push(struct x86_emulate_ctxt *ctxt,
1137 c->dst.bytes = c->op_bytes; 1113 c->dst.bytes = c->op_bytes;
1138 c->dst.val = c->src.val; 1114 c->dst.val = c->src.val;
1139 register_address_increment(c, &c->regs[VCPU_REGS_RSP], -c->op_bytes); 1115 register_address_increment(c, &c->regs[VCPU_REGS_RSP], -c->op_bytes);
1140 c->dst.addr.mem = register_address(c, ss_base(ctxt, ops), 1116 c->dst.addr.mem.ea = register_address(c, c->regs[VCPU_REGS_RSP]);
1141 c->regs[VCPU_REGS_RSP]); 1117 c->dst.addr.mem.seg = VCPU_SREG_SS;
1142} 1118}
1143 1119
1144static int emulate_pop(struct x86_emulate_ctxt *ctxt, 1120static int emulate_pop(struct x86_emulate_ctxt *ctxt,
@@ -1147,10 +1123,11 @@ static int emulate_pop(struct x86_emulate_ctxt *ctxt,
1147{ 1123{
1148 struct decode_cache *c = &ctxt->decode; 1124 struct decode_cache *c = &ctxt->decode;
1149 int rc; 1125 int rc;
1126 struct segmented_address addr;
1150 1127
1151 rc = read_emulated(ctxt, ops, register_address(c, ss_base(ctxt, ops), 1128 addr.ea = register_address(c, c->regs[VCPU_REGS_RSP]);
1152 c->regs[VCPU_REGS_RSP]), 1129 addr.seg = VCPU_SREG_SS;
1153 dest, len); 1130 rc = read_emulated(ctxt, ops, linear(ctxt, addr), dest, len);
1154 if (rc != X86EMUL_CONTINUE) 1131 if (rc != X86EMUL_CONTINUE)
1155 return rc; 1132 return rc;
1156 1133
@@ -1184,10 +1161,8 @@ static int emulate_popf(struct x86_emulate_ctxt *ctxt,
1184 change_mask |= EFLG_IF; 1161 change_mask |= EFLG_IF;
1185 break; 1162 break;
1186 case X86EMUL_MODE_VM86: 1163 case X86EMUL_MODE_VM86:
1187 if (iopl < 3) { 1164 if (iopl < 3)
1188 emulate_gp(ctxt, 0); 1165 return emulate_gp(ctxt, 0);
1189 return X86EMUL_PROPAGATE_FAULT;
1190 }
1191 change_mask |= EFLG_IF; 1166 change_mask |= EFLG_IF;
1192 break; 1167 break;
1193 default: /* real mode */ 1168 default: /* real mode */
@@ -1198,9 +1173,6 @@ static int emulate_popf(struct x86_emulate_ctxt *ctxt,
1198 *(unsigned long *)dest = 1173 *(unsigned long *)dest =
1199 (ctxt->eflags & ~change_mask) | (val & change_mask); 1174 (ctxt->eflags & ~change_mask) | (val & change_mask);
1200 1175
1201 if (rc == X86EMUL_PROPAGATE_FAULT)
1202 emulate_pf(ctxt);
1203
1204 return rc; 1176 return rc;
1205} 1177}
1206 1178
@@ -1287,7 +1259,6 @@ int emulate_int_real(struct x86_emulate_ctxt *ctxt,
1287 gva_t cs_addr; 1259 gva_t cs_addr;
1288 gva_t eip_addr; 1260 gva_t eip_addr;
1289 u16 cs, eip; 1261 u16 cs, eip;
1290 u32 err;
1291 1262
1292 /* TODO: Add limit checks */ 1263 /* TODO: Add limit checks */
1293 c->src.val = ctxt->eflags; 1264 c->src.val = ctxt->eflags;
@@ -1317,11 +1288,11 @@ int emulate_int_real(struct x86_emulate_ctxt *ctxt,
1317 eip_addr = dt.address + (irq << 2); 1288 eip_addr = dt.address + (irq << 2);
1318 cs_addr = dt.address + (irq << 2) + 2; 1289 cs_addr = dt.address + (irq << 2) + 2;
1319 1290
1320 rc = ops->read_std(cs_addr, &cs, 2, ctxt->vcpu, &err); 1291 rc = ops->read_std(cs_addr, &cs, 2, ctxt->vcpu, &ctxt->exception);
1321 if (rc != X86EMUL_CONTINUE) 1292 if (rc != X86EMUL_CONTINUE)
1322 return rc; 1293 return rc;
1323 1294
1324 rc = ops->read_std(eip_addr, &eip, 2, ctxt->vcpu, &err); 1295 rc = ops->read_std(eip_addr, &eip, 2, ctxt->vcpu, &ctxt->exception);
1325 if (rc != X86EMUL_CONTINUE) 1296 if (rc != X86EMUL_CONTINUE)
1326 return rc; 1297 return rc;
1327 1298
@@ -1370,10 +1341,8 @@ static int emulate_iret_real(struct x86_emulate_ctxt *ctxt,
1370 if (rc != X86EMUL_CONTINUE) 1341 if (rc != X86EMUL_CONTINUE)
1371 return rc; 1342 return rc;
1372 1343
1373 if (temp_eip & ~0xffff) { 1344 if (temp_eip & ~0xffff)
1374 emulate_gp(ctxt, 0); 1345 return emulate_gp(ctxt, 0);
1375 return X86EMUL_PROPAGATE_FAULT;
1376 }
1377 1346
1378 rc = emulate_pop(ctxt, ops, &cs, c->op_bytes); 1347 rc = emulate_pop(ctxt, ops, &cs, c->op_bytes);
1379 1348
@@ -1624,10 +1593,8 @@ emulate_syscall(struct x86_emulate_ctxt *ctxt, struct x86_emulate_ops *ops)
1624 1593
1625 /* syscall is not available in real mode */ 1594 /* syscall is not available in real mode */
1626 if (ctxt->mode == X86EMUL_MODE_REAL || 1595 if (ctxt->mode == X86EMUL_MODE_REAL ||
1627 ctxt->mode == X86EMUL_MODE_VM86) { 1596 ctxt->mode == X86EMUL_MODE_VM86)
1628 emulate_ud(ctxt); 1597 return emulate_ud(ctxt);
1629 return X86EMUL_PROPAGATE_FAULT;
1630 }
1631 1598
1632 setup_syscalls_segments(ctxt, ops, &cs, &ss); 1599 setup_syscalls_segments(ctxt, ops, &cs, &ss);
1633 1600
@@ -1678,34 +1645,26 @@ emulate_sysenter(struct x86_emulate_ctxt *ctxt, struct x86_emulate_ops *ops)
1678 u16 cs_sel, ss_sel; 1645 u16 cs_sel, ss_sel;
1679 1646
1680 /* inject #GP if in real mode */ 1647 /* inject #GP if in real mode */
1681 if (ctxt->mode == X86EMUL_MODE_REAL) { 1648 if (ctxt->mode == X86EMUL_MODE_REAL)
1682 emulate_gp(ctxt, 0); 1649 return emulate_gp(ctxt, 0);
1683 return X86EMUL_PROPAGATE_FAULT;
1684 }
1685 1650
1686 /* XXX sysenter/sysexit have not been tested in 64bit mode. 1651 /* XXX sysenter/sysexit have not been tested in 64bit mode.
1687 * Therefore, we inject an #UD. 1652 * Therefore, we inject an #UD.
1688 */ 1653 */
1689 if (ctxt->mode == X86EMUL_MODE_PROT64) { 1654 if (ctxt->mode == X86EMUL_MODE_PROT64)
1690 emulate_ud(ctxt); 1655 return emulate_ud(ctxt);
1691 return X86EMUL_PROPAGATE_FAULT;
1692 }
1693 1656
1694 setup_syscalls_segments(ctxt, ops, &cs, &ss); 1657 setup_syscalls_segments(ctxt, ops, &cs, &ss);
1695 1658
1696 ops->get_msr(ctxt->vcpu, MSR_IA32_SYSENTER_CS, &msr_data); 1659 ops->get_msr(ctxt->vcpu, MSR_IA32_SYSENTER_CS, &msr_data);
1697 switch (ctxt->mode) { 1660 switch (ctxt->mode) {
1698 case X86EMUL_MODE_PROT32: 1661 case X86EMUL_MODE_PROT32:
1699 if ((msr_data & 0xfffc) == 0x0) { 1662 if ((msr_data & 0xfffc) == 0x0)
1700 emulate_gp(ctxt, 0); 1663 return emulate_gp(ctxt, 0);
1701 return X86EMUL_PROPAGATE_FAULT;
1702 }
1703 break; 1664 break;
1704 case X86EMUL_MODE_PROT64: 1665 case X86EMUL_MODE_PROT64:
1705 if (msr_data == 0x0) { 1666 if (msr_data == 0x0)
1706 emulate_gp(ctxt, 0); 1667 return emulate_gp(ctxt, 0);
1707 return X86EMUL_PROPAGATE_FAULT;
1708 }
1709 break; 1668 break;
1710 } 1669 }
1711 1670
@@ -1745,10 +1704,8 @@ emulate_sysexit(struct x86_emulate_ctxt *ctxt, struct x86_emulate_ops *ops)
1745 1704
1746 /* inject #GP if in real mode or Virtual 8086 mode */ 1705 /* inject #GP if in real mode or Virtual 8086 mode */
1747 if (ctxt->mode == X86EMUL_MODE_REAL || 1706 if (ctxt->mode == X86EMUL_MODE_REAL ||
1748 ctxt->mode == X86EMUL_MODE_VM86) { 1707 ctxt->mode == X86EMUL_MODE_VM86)
1749 emulate_gp(ctxt, 0); 1708 return emulate_gp(ctxt, 0);
1750 return X86EMUL_PROPAGATE_FAULT;
1751 }
1752 1709
1753 setup_syscalls_segments(ctxt, ops, &cs, &ss); 1710 setup_syscalls_segments(ctxt, ops, &cs, &ss);
1754 1711
@@ -1763,18 +1720,14 @@ emulate_sysexit(struct x86_emulate_ctxt *ctxt, struct x86_emulate_ops *ops)
1763 switch (usermode) { 1720 switch (usermode) {
1764 case X86EMUL_MODE_PROT32: 1721 case X86EMUL_MODE_PROT32:
1765 cs_sel = (u16)(msr_data + 16); 1722 cs_sel = (u16)(msr_data + 16);
1766 if ((msr_data & 0xfffc) == 0x0) { 1723 if ((msr_data & 0xfffc) == 0x0)
1767 emulate_gp(ctxt, 0); 1724 return emulate_gp(ctxt, 0);
1768 return X86EMUL_PROPAGATE_FAULT;
1769 }
1770 ss_sel = (u16)(msr_data + 24); 1725 ss_sel = (u16)(msr_data + 24);
1771 break; 1726 break;
1772 case X86EMUL_MODE_PROT64: 1727 case X86EMUL_MODE_PROT64:
1773 cs_sel = (u16)(msr_data + 32); 1728 cs_sel = (u16)(msr_data + 32);
1774 if (msr_data == 0x0) { 1729 if (msr_data == 0x0)
1775 emulate_gp(ctxt, 0); 1730 return emulate_gp(ctxt, 0);
1776 return X86EMUL_PROPAGATE_FAULT;
1777 }
1778 ss_sel = cs_sel + 8; 1731 ss_sel = cs_sel + 8;
1779 cs.d = 0; 1732 cs.d = 0;
1780 cs.l = 1; 1733 cs.l = 1;
@@ -1934,33 +1887,27 @@ static int task_switch_16(struct x86_emulate_ctxt *ctxt,
1934{ 1887{
1935 struct tss_segment_16 tss_seg; 1888 struct tss_segment_16 tss_seg;
1936 int ret; 1889 int ret;
1937 u32 err, new_tss_base = get_desc_base(new_desc); 1890 u32 new_tss_base = get_desc_base(new_desc);
1938 1891
1939 ret = ops->read_std(old_tss_base, &tss_seg, sizeof tss_seg, ctxt->vcpu, 1892 ret = ops->read_std(old_tss_base, &tss_seg, sizeof tss_seg, ctxt->vcpu,
1940 &err); 1893 &ctxt->exception);
1941 if (ret == X86EMUL_PROPAGATE_FAULT) { 1894 if (ret != X86EMUL_CONTINUE)
1942 /* FIXME: need to provide precise fault address */ 1895 /* FIXME: need to provide precise fault address */
1943 emulate_pf(ctxt);
1944 return ret; 1896 return ret;
1945 }
1946 1897
1947 save_state_to_tss16(ctxt, ops, &tss_seg); 1898 save_state_to_tss16(ctxt, ops, &tss_seg);
1948 1899
1949 ret = ops->write_std(old_tss_base, &tss_seg, sizeof tss_seg, ctxt->vcpu, 1900 ret = ops->write_std(old_tss_base, &tss_seg, sizeof tss_seg, ctxt->vcpu,
1950 &err); 1901 &ctxt->exception);
1951 if (ret == X86EMUL_PROPAGATE_FAULT) { 1902 if (ret != X86EMUL_CONTINUE)
1952 /* FIXME: need to provide precise fault address */ 1903 /* FIXME: need to provide precise fault address */
1953 emulate_pf(ctxt);
1954 return ret; 1904 return ret;
1955 }
1956 1905
1957 ret = ops->read_std(new_tss_base, &tss_seg, sizeof tss_seg, ctxt->vcpu, 1906 ret = ops->read_std(new_tss_base, &tss_seg, sizeof tss_seg, ctxt->vcpu,
1958 &err); 1907 &ctxt->exception);
1959 if (ret == X86EMUL_PROPAGATE_FAULT) { 1908 if (ret != X86EMUL_CONTINUE)
1960 /* FIXME: need to provide precise fault address */ 1909 /* FIXME: need to provide precise fault address */
1961 emulate_pf(ctxt);
1962 return ret; 1910 return ret;
1963 }
1964 1911
1965 if (old_tss_sel != 0xffff) { 1912 if (old_tss_sel != 0xffff) {
1966 tss_seg.prev_task_link = old_tss_sel; 1913 tss_seg.prev_task_link = old_tss_sel;
@@ -1968,12 +1915,10 @@ static int task_switch_16(struct x86_emulate_ctxt *ctxt,
1968 ret = ops->write_std(new_tss_base, 1915 ret = ops->write_std(new_tss_base,
1969 &tss_seg.prev_task_link, 1916 &tss_seg.prev_task_link,
1970 sizeof tss_seg.prev_task_link, 1917 sizeof tss_seg.prev_task_link,
1971 ctxt->vcpu, &err); 1918 ctxt->vcpu, &ctxt->exception);
1972 if (ret == X86EMUL_PROPAGATE_FAULT) { 1919 if (ret != X86EMUL_CONTINUE)
1973 /* FIXME: need to provide precise fault address */ 1920 /* FIXME: need to provide precise fault address */
1974 emulate_pf(ctxt);
1975 return ret; 1921 return ret;
1976 }
1977 } 1922 }
1978 1923
1979 return load_state_from_tss16(ctxt, ops, &tss_seg); 1924 return load_state_from_tss16(ctxt, ops, &tss_seg);
@@ -2013,10 +1958,8 @@ static int load_state_from_tss32(struct x86_emulate_ctxt *ctxt,
2013 struct decode_cache *c = &ctxt->decode; 1958 struct decode_cache *c = &ctxt->decode;
2014 int ret; 1959 int ret;
2015 1960
2016 if (ops->set_cr(3, tss->cr3, ctxt->vcpu)) { 1961 if (ops->set_cr(3, tss->cr3, ctxt->vcpu))
2017 emulate_gp(ctxt, 0); 1962 return emulate_gp(ctxt, 0);
2018 return X86EMUL_PROPAGATE_FAULT;
2019 }
2020 c->eip = tss->eip; 1963 c->eip = tss->eip;
2021 ctxt->eflags = tss->eflags | 2; 1964 ctxt->eflags = tss->eflags | 2;
2022 c->regs[VCPU_REGS_RAX] = tss->eax; 1965 c->regs[VCPU_REGS_RAX] = tss->eax;
@@ -2076,33 +2019,27 @@ static int task_switch_32(struct x86_emulate_ctxt *ctxt,
2076{ 2019{
2077 struct tss_segment_32 tss_seg; 2020 struct tss_segment_32 tss_seg;
2078 int ret; 2021 int ret;
2079 u32 err, new_tss_base = get_desc_base(new_desc); 2022 u32 new_tss_base = get_desc_base(new_desc);
2080 2023
2081 ret = ops->read_std(old_tss_base, &tss_seg, sizeof tss_seg, ctxt->vcpu, 2024 ret = ops->read_std(old_tss_base, &tss_seg, sizeof tss_seg, ctxt->vcpu,
2082 &err); 2025 &ctxt->exception);
2083 if (ret == X86EMUL_PROPAGATE_FAULT) { 2026 if (ret != X86EMUL_CONTINUE)
2084 /* FIXME: need to provide precise fault address */ 2027 /* FIXME: need to provide precise fault address */
2085 emulate_pf(ctxt);
2086 return ret; 2028 return ret;
2087 }
2088 2029
2089 save_state_to_tss32(ctxt, ops, &tss_seg); 2030 save_state_to_tss32(ctxt, ops, &tss_seg);
2090 2031
2091 ret = ops->write_std(old_tss_base, &tss_seg, sizeof tss_seg, ctxt->vcpu, 2032 ret = ops->write_std(old_tss_base, &tss_seg, sizeof tss_seg, ctxt->vcpu,
2092 &err); 2033 &ctxt->exception);
2093 if (ret == X86EMUL_PROPAGATE_FAULT) { 2034 if (ret != X86EMUL_CONTINUE)
2094 /* FIXME: need to provide precise fault address */ 2035 /* FIXME: need to provide precise fault address */
2095 emulate_pf(ctxt);
2096 return ret; 2036 return ret;
2097 }
2098 2037
2099 ret = ops->read_std(new_tss_base, &tss_seg, sizeof tss_seg, ctxt->vcpu, 2038 ret = ops->read_std(new_tss_base, &tss_seg, sizeof tss_seg, ctxt->vcpu,
2100 &err); 2039 &ctxt->exception);
2101 if (ret == X86EMUL_PROPAGATE_FAULT) { 2040 if (ret != X86EMUL_CONTINUE)
2102 /* FIXME: need to provide precise fault address */ 2041 /* FIXME: need to provide precise fault address */
2103 emulate_pf(ctxt);
2104 return ret; 2042 return ret;
2105 }
2106 2043
2107 if (old_tss_sel != 0xffff) { 2044 if (old_tss_sel != 0xffff) {
2108 tss_seg.prev_task_link = old_tss_sel; 2045 tss_seg.prev_task_link = old_tss_sel;
@@ -2110,12 +2047,10 @@ static int task_switch_32(struct x86_emulate_ctxt *ctxt,
2110 ret = ops->write_std(new_tss_base, 2047 ret = ops->write_std(new_tss_base,
2111 &tss_seg.prev_task_link, 2048 &tss_seg.prev_task_link,
2112 sizeof tss_seg.prev_task_link, 2049 sizeof tss_seg.prev_task_link,
2113 ctxt->vcpu, &err); 2050 ctxt->vcpu, &ctxt->exception);
2114 if (ret == X86EMUL_PROPAGATE_FAULT) { 2051 if (ret != X86EMUL_CONTINUE)
2115 /* FIXME: need to provide precise fault address */ 2052 /* FIXME: need to provide precise fault address */
2116 emulate_pf(ctxt);
2117 return ret; 2053 return ret;
2118 }
2119 } 2054 }
2120 2055
2121 return load_state_from_tss32(ctxt, ops, &tss_seg); 2056 return load_state_from_tss32(ctxt, ops, &tss_seg);
@@ -2146,10 +2081,8 @@ static int emulator_do_task_switch(struct x86_emulate_ctxt *ctxt,
2146 2081
2147 if (reason != TASK_SWITCH_IRET) { 2082 if (reason != TASK_SWITCH_IRET) {
2148 if ((tss_selector & 3) > next_tss_desc.dpl || 2083 if ((tss_selector & 3) > next_tss_desc.dpl ||
2149 ops->cpl(ctxt->vcpu) > next_tss_desc.dpl) { 2084 ops->cpl(ctxt->vcpu) > next_tss_desc.dpl)
2150 emulate_gp(ctxt, 0); 2085 return emulate_gp(ctxt, 0);
2151 return X86EMUL_PROPAGATE_FAULT;
2152 }
2153 } 2086 }
2154 2087
2155 desc_limit = desc_limit_scaled(&next_tss_desc); 2088 desc_limit = desc_limit_scaled(&next_tss_desc);
@@ -2231,14 +2164,15 @@ int emulator_task_switch(struct x86_emulate_ctxt *ctxt,
2231 return (rc == X86EMUL_UNHANDLEABLE) ? -1 : 0; 2164 return (rc == X86EMUL_UNHANDLEABLE) ? -1 : 0;
2232} 2165}
2233 2166
2234static void string_addr_inc(struct x86_emulate_ctxt *ctxt, unsigned long base, 2167static void string_addr_inc(struct x86_emulate_ctxt *ctxt, unsigned seg,
2235 int reg, struct operand *op) 2168 int reg, struct operand *op)
2236{ 2169{
2237 struct decode_cache *c = &ctxt->decode; 2170 struct decode_cache *c = &ctxt->decode;
2238 int df = (ctxt->eflags & EFLG_DF) ? -1 : 1; 2171 int df = (ctxt->eflags & EFLG_DF) ? -1 : 1;
2239 2172
2240 register_address_increment(c, &c->regs[reg], df * op->bytes); 2173 register_address_increment(c, &c->regs[reg], df * op->bytes);
2241 op->addr.mem = register_address(c, base, c->regs[reg]); 2174 op->addr.mem.ea = register_address(c, c->regs[reg]);
2175 op->addr.mem.seg = seg;
2242} 2176}
2243 2177
2244static int em_push(struct x86_emulate_ctxt *ctxt) 2178static int em_push(struct x86_emulate_ctxt *ctxt)
@@ -2369,10 +2303,8 @@ static int em_rdtsc(struct x86_emulate_ctxt *ctxt)
2369 struct decode_cache *c = &ctxt->decode; 2303 struct decode_cache *c = &ctxt->decode;
2370 u64 tsc = 0; 2304 u64 tsc = 0;
2371 2305
2372 if (cpl > 0 && (ctxt->ops->get_cr(4, ctxt->vcpu) & X86_CR4_TSD)) { 2306 if (cpl > 0 && (ctxt->ops->get_cr(4, ctxt->vcpu) & X86_CR4_TSD))
2373 emulate_gp(ctxt, 0); 2307 return emulate_gp(ctxt, 0);
2374 return X86EMUL_PROPAGATE_FAULT;
2375 }
2376 ctxt->ops->get_msr(ctxt->vcpu, MSR_IA32_TSC, &tsc); 2308 ctxt->ops->get_msr(ctxt->vcpu, MSR_IA32_TSC, &tsc);
2377 c->regs[VCPU_REGS_RAX] = (u32)tsc; 2309 c->regs[VCPU_REGS_RAX] = (u32)tsc;
2378 c->regs[VCPU_REGS_RDX] = tsc >> 32; 2310 c->regs[VCPU_REGS_RDX] = tsc >> 32;
@@ -2647,7 +2579,7 @@ static int decode_imm(struct x86_emulate_ctxt *ctxt, struct operand *op,
2647 2579
2648 op->type = OP_IMM; 2580 op->type = OP_IMM;
2649 op->bytes = size; 2581 op->bytes = size;
2650 op->addr.mem = c->eip; 2582 op->addr.mem.ea = c->eip;
2651 /* NB. Immediates are sign-extended as necessary. */ 2583 /* NB. Immediates are sign-extended as necessary. */
2652 switch (op->bytes) { 2584 switch (op->bytes) {
2653 case 1: 2585 case 1:
@@ -2678,7 +2610,7 @@ done:
2678} 2610}
2679 2611
2680int 2612int
2681x86_decode_insn(struct x86_emulate_ctxt *ctxt) 2613x86_decode_insn(struct x86_emulate_ctxt *ctxt, void *insn, int insn_len)
2682{ 2614{
2683 struct x86_emulate_ops *ops = ctxt->ops; 2615 struct x86_emulate_ops *ops = ctxt->ops;
2684 struct decode_cache *c = &ctxt->decode; 2616 struct decode_cache *c = &ctxt->decode;
@@ -2689,7 +2621,10 @@ x86_decode_insn(struct x86_emulate_ctxt *ctxt)
2689 struct operand memop = { .type = OP_NONE }; 2621 struct operand memop = { .type = OP_NONE };
2690 2622
2691 c->eip = ctxt->eip; 2623 c->eip = ctxt->eip;
2692 c->fetch.start = c->fetch.end = c->eip; 2624 c->fetch.start = c->eip;
2625 c->fetch.end = c->fetch.start + insn_len;
2626 if (insn_len > 0)
2627 memcpy(c->fetch.data, insn, insn_len);
2693 ctxt->cs_base = seg_base(ctxt, ops, VCPU_SREG_CS); 2628 ctxt->cs_base = seg_base(ctxt, ops, VCPU_SREG_CS);
2694 2629
2695 switch (mode) { 2630 switch (mode) {
@@ -2803,10 +2738,8 @@ done_prefixes:
2803 c->execute = opcode.u.execute; 2738 c->execute = opcode.u.execute;
2804 2739
2805 /* Unrecognised? */ 2740 /* Unrecognised? */
2806 if (c->d == 0 || (c->d & Undefined)) { 2741 if (c->d == 0 || (c->d & Undefined))
2807 DPRINTF("Cannot emulate %02x\n", c->b);
2808 return -1; 2742 return -1;
2809 }
2810 2743
2811 if (mode == X86EMUL_MODE_PROT64 && (c->d & Stack)) 2744 if (mode == X86EMUL_MODE_PROT64 && (c->d & Stack))
2812 c->op_bytes = 8; 2745 c->op_bytes = 8;
@@ -2831,14 +2764,13 @@ done_prefixes:
2831 if (!c->has_seg_override) 2764 if (!c->has_seg_override)
2832 set_seg_override(c, VCPU_SREG_DS); 2765 set_seg_override(c, VCPU_SREG_DS);
2833 2766
2834 if (memop.type == OP_MEM && !(!c->twobyte && c->b == 0x8d)) 2767 memop.addr.mem.seg = seg_override(ctxt, ops, c);
2835 memop.addr.mem += seg_override_base(ctxt, ops, c);
2836 2768
2837 if (memop.type == OP_MEM && c->ad_bytes != 8) 2769 if (memop.type == OP_MEM && c->ad_bytes != 8)
2838 memop.addr.mem = (u32)memop.addr.mem; 2770 memop.addr.mem.ea = (u32)memop.addr.mem.ea;
2839 2771
2840 if (memop.type == OP_MEM && c->rip_relative) 2772 if (memop.type == OP_MEM && c->rip_relative)
2841 memop.addr.mem += c->eip; 2773 memop.addr.mem.ea += c->eip;
2842 2774
2843 /* 2775 /*
2844 * Decode and fetch the source operand: register, memory 2776 * Decode and fetch the source operand: register, memory
@@ -2890,14 +2822,14 @@ done_prefixes:
2890 case SrcSI: 2822 case SrcSI:
2891 c->src.type = OP_MEM; 2823 c->src.type = OP_MEM;
2892 c->src.bytes = (c->d & ByteOp) ? 1 : c->op_bytes; 2824 c->src.bytes = (c->d & ByteOp) ? 1 : c->op_bytes;
2893 c->src.addr.mem = 2825 c->src.addr.mem.ea =
2894 register_address(c, seg_override_base(ctxt, ops, c), 2826 register_address(c, c->regs[VCPU_REGS_RSI]);
2895 c->regs[VCPU_REGS_RSI]); 2827 c->src.addr.mem.seg = seg_override(ctxt, ops, c),
2896 c->src.val = 0; 2828 c->src.val = 0;
2897 break; 2829 break;
2898 case SrcImmFAddr: 2830 case SrcImmFAddr:
2899 c->src.type = OP_IMM; 2831 c->src.type = OP_IMM;
2900 c->src.addr.mem = c->eip; 2832 c->src.addr.mem.ea = c->eip;
2901 c->src.bytes = c->op_bytes + 2; 2833 c->src.bytes = c->op_bytes + 2;
2902 insn_fetch_arr(c->src.valptr, c->src.bytes, c->eip); 2834 insn_fetch_arr(c->src.valptr, c->src.bytes, c->eip);
2903 break; 2835 break;
@@ -2944,7 +2876,7 @@ done_prefixes:
2944 break; 2876 break;
2945 case DstImmUByte: 2877 case DstImmUByte:
2946 c->dst.type = OP_IMM; 2878 c->dst.type = OP_IMM;
2947 c->dst.addr.mem = c->eip; 2879 c->dst.addr.mem.ea = c->eip;
2948 c->dst.bytes = 1; 2880 c->dst.bytes = 1;
2949 c->dst.val = insn_fetch(u8, 1, c->eip); 2881 c->dst.val = insn_fetch(u8, 1, c->eip);
2950 break; 2882 break;
@@ -2969,9 +2901,9 @@ done_prefixes:
2969 case DstDI: 2901 case DstDI:
2970 c->dst.type = OP_MEM; 2902 c->dst.type = OP_MEM;
2971 c->dst.bytes = (c->d & ByteOp) ? 1 : c->op_bytes; 2903 c->dst.bytes = (c->d & ByteOp) ? 1 : c->op_bytes;
2972 c->dst.addr.mem = 2904 c->dst.addr.mem.ea =
2973 register_address(c, es_base(ctxt, ops), 2905 register_address(c, c->regs[VCPU_REGS_RDI]);
2974 c->regs[VCPU_REGS_RDI]); 2906 c->dst.addr.mem.seg = VCPU_SREG_ES;
2975 c->dst.val = 0; 2907 c->dst.val = 0;
2976 break; 2908 break;
2977 case ImplicitOps: 2909 case ImplicitOps:
@@ -3020,24 +2952,24 @@ x86_emulate_insn(struct x86_emulate_ctxt *ctxt)
3020 ctxt->decode.mem_read.pos = 0; 2952 ctxt->decode.mem_read.pos = 0;
3021 2953
3022 if (ctxt->mode == X86EMUL_MODE_PROT64 && (c->d & No64)) { 2954 if (ctxt->mode == X86EMUL_MODE_PROT64 && (c->d & No64)) {
3023 emulate_ud(ctxt); 2955 rc = emulate_ud(ctxt);
3024 goto done; 2956 goto done;
3025 } 2957 }
3026 2958
3027 /* LOCK prefix is allowed only with some instructions */ 2959 /* LOCK prefix is allowed only with some instructions */
3028 if (c->lock_prefix && (!(c->d & Lock) || c->dst.type != OP_MEM)) { 2960 if (c->lock_prefix && (!(c->d & Lock) || c->dst.type != OP_MEM)) {
3029 emulate_ud(ctxt); 2961 rc = emulate_ud(ctxt);
3030 goto done; 2962 goto done;
3031 } 2963 }
3032 2964
3033 if ((c->d & SrcMask) == SrcMemFAddr && c->src.type != OP_MEM) { 2965 if ((c->d & SrcMask) == SrcMemFAddr && c->src.type != OP_MEM) {
3034 emulate_ud(ctxt); 2966 rc = emulate_ud(ctxt);
3035 goto done; 2967 goto done;
3036 } 2968 }
3037 2969
3038 /* Privileged instruction can be executed only in CPL=0 */ 2970 /* Privileged instruction can be executed only in CPL=0 */
3039 if ((c->d & Priv) && ops->cpl(ctxt->vcpu)) { 2971 if ((c->d & Priv) && ops->cpl(ctxt->vcpu)) {
3040 emulate_gp(ctxt, 0); 2972 rc = emulate_gp(ctxt, 0);
3041 goto done; 2973 goto done;
3042 } 2974 }
3043 2975
@@ -3050,7 +2982,7 @@ x86_emulate_insn(struct x86_emulate_ctxt *ctxt)
3050 } 2982 }
3051 2983
3052 if ((c->src.type == OP_MEM) && !(c->d & NoAccess)) { 2984 if ((c->src.type == OP_MEM) && !(c->d & NoAccess)) {
3053 rc = read_emulated(ctxt, ops, c->src.addr.mem, 2985 rc = read_emulated(ctxt, ops, linear(ctxt, c->src.addr.mem),
3054 c->src.valptr, c->src.bytes); 2986 c->src.valptr, c->src.bytes);
3055 if (rc != X86EMUL_CONTINUE) 2987 if (rc != X86EMUL_CONTINUE)
3056 goto done; 2988 goto done;
@@ -3058,7 +2990,7 @@ x86_emulate_insn(struct x86_emulate_ctxt *ctxt)
3058 } 2990 }
3059 2991
3060 if (c->src2.type == OP_MEM) { 2992 if (c->src2.type == OP_MEM) {
3061 rc = read_emulated(ctxt, ops, c->src2.addr.mem, 2993 rc = read_emulated(ctxt, ops, linear(ctxt, c->src2.addr.mem),
3062 &c->src2.val, c->src2.bytes); 2994 &c->src2.val, c->src2.bytes);
3063 if (rc != X86EMUL_CONTINUE) 2995 if (rc != X86EMUL_CONTINUE)
3064 goto done; 2996 goto done;
@@ -3070,7 +3002,7 @@ x86_emulate_insn(struct x86_emulate_ctxt *ctxt)
3070 3002
3071 if ((c->dst.type == OP_MEM) && !(c->d & Mov)) { 3003 if ((c->dst.type == OP_MEM) && !(c->d & Mov)) {
3072 /* optimisation - avoid slow emulated read if Mov */ 3004 /* optimisation - avoid slow emulated read if Mov */
3073 rc = read_emulated(ctxt, ops, c->dst.addr.mem, 3005 rc = read_emulated(ctxt, ops, linear(ctxt, c->dst.addr.mem),
3074 &c->dst.val, c->dst.bytes); 3006 &c->dst.val, c->dst.bytes);
3075 if (rc != X86EMUL_CONTINUE) 3007 if (rc != X86EMUL_CONTINUE)
3076 goto done; 3008 goto done;
@@ -3215,13 +3147,13 @@ special_insn:
3215 break; 3147 break;
3216 case 0x8c: /* mov r/m, sreg */ 3148 case 0x8c: /* mov r/m, sreg */
3217 if (c->modrm_reg > VCPU_SREG_GS) { 3149 if (c->modrm_reg > VCPU_SREG_GS) {
3218 emulate_ud(ctxt); 3150 rc = emulate_ud(ctxt);
3219 goto done; 3151 goto done;
3220 } 3152 }
3221 c->dst.val = ops->get_segment_selector(c->modrm_reg, ctxt->vcpu); 3153 c->dst.val = ops->get_segment_selector(c->modrm_reg, ctxt->vcpu);
3222 break; 3154 break;
3223 case 0x8d: /* lea r16/r32, m */ 3155 case 0x8d: /* lea r16/r32, m */
3224 c->dst.val = c->src.addr.mem; 3156 c->dst.val = c->src.addr.mem.ea;
3225 break; 3157 break;
3226 case 0x8e: { /* mov seg, r/m16 */ 3158 case 0x8e: { /* mov seg, r/m16 */
3227 uint16_t sel; 3159 uint16_t sel;
@@ -3230,7 +3162,7 @@ special_insn:
3230 3162
3231 if (c->modrm_reg == VCPU_SREG_CS || 3163 if (c->modrm_reg == VCPU_SREG_CS ||
3232 c->modrm_reg > VCPU_SREG_GS) { 3164 c->modrm_reg > VCPU_SREG_GS) {
3233 emulate_ud(ctxt); 3165 rc = emulate_ud(ctxt);
3234 goto done; 3166 goto done;
3235 } 3167 }
3236 3168
@@ -3268,7 +3200,6 @@ special_insn:
3268 break; 3200 break;
3269 case 0xa6 ... 0xa7: /* cmps */ 3201 case 0xa6 ... 0xa7: /* cmps */
3270 c->dst.type = OP_NONE; /* Disable writeback. */ 3202 c->dst.type = OP_NONE; /* Disable writeback. */
3271 DPRINTF("cmps: mem1=0x%p mem2=0x%p\n", c->src.addr.mem, c->dst.addr.mem);
3272 goto cmp; 3203 goto cmp;
3273 case 0xa8 ... 0xa9: /* test ax, imm */ 3204 case 0xa8 ... 0xa9: /* test ax, imm */
3274 goto test; 3205 goto test;
@@ -3363,7 +3294,7 @@ special_insn:
3363 do_io_in: 3294 do_io_in:
3364 c->dst.bytes = min(c->dst.bytes, 4u); 3295 c->dst.bytes = min(c->dst.bytes, 4u);
3365 if (!emulator_io_permited(ctxt, ops, c->src.val, c->dst.bytes)) { 3296 if (!emulator_io_permited(ctxt, ops, c->src.val, c->dst.bytes)) {
3366 emulate_gp(ctxt, 0); 3297 rc = emulate_gp(ctxt, 0);
3367 goto done; 3298 goto done;
3368 } 3299 }
3369 if (!pio_in_emulated(ctxt, ops, c->dst.bytes, c->src.val, 3300 if (!pio_in_emulated(ctxt, ops, c->dst.bytes, c->src.val,
@@ -3377,7 +3308,7 @@ special_insn:
3377 c->src.bytes = min(c->src.bytes, 4u); 3308 c->src.bytes = min(c->src.bytes, 4u);
3378 if (!emulator_io_permited(ctxt, ops, c->dst.val, 3309 if (!emulator_io_permited(ctxt, ops, c->dst.val,
3379 c->src.bytes)) { 3310 c->src.bytes)) {
3380 emulate_gp(ctxt, 0); 3311 rc = emulate_gp(ctxt, 0);
3381 goto done; 3312 goto done;
3382 } 3313 }
3383 ops->pio_out_emulated(c->src.bytes, c->dst.val, 3314 ops->pio_out_emulated(c->src.bytes, c->dst.val,
@@ -3402,14 +3333,14 @@ special_insn:
3402 break; 3333 break;
3403 case 0xfa: /* cli */ 3334 case 0xfa: /* cli */
3404 if (emulator_bad_iopl(ctxt, ops)) { 3335 if (emulator_bad_iopl(ctxt, ops)) {
3405 emulate_gp(ctxt, 0); 3336 rc = emulate_gp(ctxt, 0);
3406 goto done; 3337 goto done;
3407 } else 3338 } else
3408 ctxt->eflags &= ~X86_EFLAGS_IF; 3339 ctxt->eflags &= ~X86_EFLAGS_IF;
3409 break; 3340 break;
3410 case 0xfb: /* sti */ 3341 case 0xfb: /* sti */
3411 if (emulator_bad_iopl(ctxt, ops)) { 3342 if (emulator_bad_iopl(ctxt, ops)) {
3412 emulate_gp(ctxt, 0); 3343 rc = emulate_gp(ctxt, 0);
3413 goto done; 3344 goto done;
3414 } else { 3345 } else {
3415 ctxt->interruptibility = KVM_X86_SHADOW_INT_STI; 3346 ctxt->interruptibility = KVM_X86_SHADOW_INT_STI;
@@ -3449,11 +3380,11 @@ writeback:
3449 c->dst.type = saved_dst_type; 3380 c->dst.type = saved_dst_type;
3450 3381
3451 if ((c->d & SrcMask) == SrcSI) 3382 if ((c->d & SrcMask) == SrcSI)
3452 string_addr_inc(ctxt, seg_override_base(ctxt, ops, c), 3383 string_addr_inc(ctxt, seg_override(ctxt, ops, c),
3453 VCPU_REGS_RSI, &c->src); 3384 VCPU_REGS_RSI, &c->src);
3454 3385
3455 if ((c->d & DstMask) == DstDI) 3386 if ((c->d & DstMask) == DstDI)
3456 string_addr_inc(ctxt, es_base(ctxt, ops), VCPU_REGS_RDI, 3387 string_addr_inc(ctxt, VCPU_SREG_ES, VCPU_REGS_RDI,
3457 &c->dst); 3388 &c->dst);
3458 3389
3459 if (c->rep_prefix && (c->d & String)) { 3390 if (c->rep_prefix && (c->d & String)) {
@@ -3482,6 +3413,8 @@ writeback:
3482 ctxt->eip = c->eip; 3413 ctxt->eip = c->eip;
3483 3414
3484done: 3415done:
3416 if (rc == X86EMUL_PROPAGATE_FAULT)
3417 ctxt->have_exception = true;
3485 return (rc == X86EMUL_UNHANDLEABLE) ? EMULATION_FAILED : EMULATION_OK; 3418 return (rc == X86EMUL_UNHANDLEABLE) ? EMULATION_FAILED : EMULATION_OK;
3486 3419
3487twobyte_insn: 3420twobyte_insn:
@@ -3544,9 +3477,11 @@ twobyte_insn:
3544 break; 3477 break;
3545 case 5: /* not defined */ 3478 case 5: /* not defined */
3546 emulate_ud(ctxt); 3479 emulate_ud(ctxt);
3480 rc = X86EMUL_PROPAGATE_FAULT;
3547 goto done; 3481 goto done;
3548 case 7: /* invlpg*/ 3482 case 7: /* invlpg*/
3549 emulate_invlpg(ctxt->vcpu, c->src.addr.mem); 3483 emulate_invlpg(ctxt->vcpu,
3484 linear(ctxt, c->src.addr.mem));
3550 /* Disable writeback. */ 3485 /* Disable writeback. */
3551 c->dst.type = OP_NONE; 3486 c->dst.type = OP_NONE;
3552 break; 3487 break;
@@ -3573,6 +3508,7 @@ twobyte_insn:
3573 case 5 ... 7: 3508 case 5 ... 7:
3574 case 9 ... 15: 3509 case 9 ... 15:
3575 emulate_ud(ctxt); 3510 emulate_ud(ctxt);
3511 rc = X86EMUL_PROPAGATE_FAULT;
3576 goto done; 3512 goto done;
3577 } 3513 }
3578 c->dst.val = ops->get_cr(c->modrm_reg, ctxt->vcpu); 3514 c->dst.val = ops->get_cr(c->modrm_reg, ctxt->vcpu);
@@ -3581,6 +3517,7 @@ twobyte_insn:
3581 if ((ops->get_cr(4, ctxt->vcpu) & X86_CR4_DE) && 3517 if ((ops->get_cr(4, ctxt->vcpu) & X86_CR4_DE) &&
3582 (c->modrm_reg == 4 || c->modrm_reg == 5)) { 3518 (c->modrm_reg == 4 || c->modrm_reg == 5)) {
3583 emulate_ud(ctxt); 3519 emulate_ud(ctxt);
3520 rc = X86EMUL_PROPAGATE_FAULT;
3584 goto done; 3521 goto done;
3585 } 3522 }
3586 ops->get_dr(c->modrm_reg, &c->dst.val, ctxt->vcpu); 3523 ops->get_dr(c->modrm_reg, &c->dst.val, ctxt->vcpu);
@@ -3588,6 +3525,7 @@ twobyte_insn:
3588 case 0x22: /* mov reg, cr */ 3525 case 0x22: /* mov reg, cr */
3589 if (ops->set_cr(c->modrm_reg, c->src.val, ctxt->vcpu)) { 3526 if (ops->set_cr(c->modrm_reg, c->src.val, ctxt->vcpu)) {
3590 emulate_gp(ctxt, 0); 3527 emulate_gp(ctxt, 0);
3528 rc = X86EMUL_PROPAGATE_FAULT;
3591 goto done; 3529 goto done;
3592 } 3530 }
3593 c->dst.type = OP_NONE; 3531 c->dst.type = OP_NONE;
@@ -3596,6 +3534,7 @@ twobyte_insn:
3596 if ((ops->get_cr(4, ctxt->vcpu) & X86_CR4_DE) && 3534 if ((ops->get_cr(4, ctxt->vcpu) & X86_CR4_DE) &&
3597 (c->modrm_reg == 4 || c->modrm_reg == 5)) { 3535 (c->modrm_reg == 4 || c->modrm_reg == 5)) {
3598 emulate_ud(ctxt); 3536 emulate_ud(ctxt);
3537 rc = X86EMUL_PROPAGATE_FAULT;
3599 goto done; 3538 goto done;
3600 } 3539 }
3601 3540
@@ -3604,6 +3543,7 @@ twobyte_insn:
3604 ~0ULL : ~0U), ctxt->vcpu) < 0) { 3543 ~0ULL : ~0U), ctxt->vcpu) < 0) {
3605 /* #UD condition is already handled by the code above */ 3544 /* #UD condition is already handled by the code above */
3606 emulate_gp(ctxt, 0); 3545 emulate_gp(ctxt, 0);
3546 rc = X86EMUL_PROPAGATE_FAULT;
3607 goto done; 3547 goto done;
3608 } 3548 }
3609 3549
@@ -3615,6 +3555,7 @@ twobyte_insn:
3615 | ((u64)c->regs[VCPU_REGS_RDX] << 32); 3555 | ((u64)c->regs[VCPU_REGS_RDX] << 32);
3616 if (ops->set_msr(ctxt->vcpu, c->regs[VCPU_REGS_RCX], msr_data)) { 3556 if (ops->set_msr(ctxt->vcpu, c->regs[VCPU_REGS_RCX], msr_data)) {
3617 emulate_gp(ctxt, 0); 3557 emulate_gp(ctxt, 0);
3558 rc = X86EMUL_PROPAGATE_FAULT;
3618 goto done; 3559 goto done;
3619 } 3560 }
3620 rc = X86EMUL_CONTINUE; 3561 rc = X86EMUL_CONTINUE;
@@ -3623,6 +3564,7 @@ twobyte_insn:
3623 /* rdmsr */ 3564 /* rdmsr */
3624 if (ops->get_msr(ctxt->vcpu, c->regs[VCPU_REGS_RCX], &msr_data)) { 3565 if (ops->get_msr(ctxt->vcpu, c->regs[VCPU_REGS_RCX], &msr_data)) {
3625 emulate_gp(ctxt, 0); 3566 emulate_gp(ctxt, 0);
3567 rc = X86EMUL_PROPAGATE_FAULT;
3626 goto done; 3568 goto done;
3627 } else { 3569 } else {
3628 c->regs[VCPU_REGS_RAX] = (u32)msr_data; 3570 c->regs[VCPU_REGS_RAX] = (u32)msr_data;
@@ -3785,6 +3727,5 @@ twobyte_insn:
3785 goto writeback; 3727 goto writeback;
3786 3728
3787cannot_emulate: 3729cannot_emulate:
3788 DPRINTF("Cannot emulate %02x\n", c->b);
3789 return -1; 3730 return -1;
3790} 3731}
diff --git a/arch/x86/kvm/kvm_cache_regs.h b/arch/x86/kvm/kvm_cache_regs.h
index 975bb45329a1..3377d53fcd36 100644
--- a/arch/x86/kvm/kvm_cache_regs.h
+++ b/arch/x86/kvm/kvm_cache_regs.h
@@ -73,6 +73,13 @@ static inline ulong kvm_read_cr4_bits(struct kvm_vcpu *vcpu, ulong mask)
73 return vcpu->arch.cr4 & mask; 73 return vcpu->arch.cr4 & mask;
74} 74}
75 75
76static inline ulong kvm_read_cr3(struct kvm_vcpu *vcpu)
77{
78 if (!test_bit(VCPU_EXREG_CR3, (ulong *)&vcpu->arch.regs_avail))
79 kvm_x86_ops->decache_cr3(vcpu);
80 return vcpu->arch.cr3;
81}
82
76static inline ulong kvm_read_cr4(struct kvm_vcpu *vcpu) 83static inline ulong kvm_read_cr4(struct kvm_vcpu *vcpu)
77{ 84{
78 return kvm_read_cr4_bits(vcpu, ~0UL); 85 return kvm_read_cr4_bits(vcpu, ~0UL);
@@ -84,4 +91,19 @@ static inline u64 kvm_read_edx_eax(struct kvm_vcpu *vcpu)
84 | ((u64)(kvm_register_read(vcpu, VCPU_REGS_RDX) & -1u) << 32); 91 | ((u64)(kvm_register_read(vcpu, VCPU_REGS_RDX) & -1u) << 32);
85} 92}
86 93
94static inline void enter_guest_mode(struct kvm_vcpu *vcpu)
95{
96 vcpu->arch.hflags |= HF_GUEST_MASK;
97}
98
99static inline void leave_guest_mode(struct kvm_vcpu *vcpu)
100{
101 vcpu->arch.hflags &= ~HF_GUEST_MASK;
102}
103
104static inline bool is_guest_mode(struct kvm_vcpu *vcpu)
105{
106 return vcpu->arch.hflags & HF_GUEST_MASK;
107}
108
87#endif 109#endif
diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
index 413f8973a855..93cf9d0d3653 100644
--- a/arch/x86/kvm/lapic.c
+++ b/arch/x86/kvm/lapic.c
@@ -277,7 +277,8 @@ static void apic_update_ppr(struct kvm_lapic *apic)
277 277
278 if (old_ppr != ppr) { 278 if (old_ppr != ppr) {
279 apic_set_reg(apic, APIC_PROCPRI, ppr); 279 apic_set_reg(apic, APIC_PROCPRI, ppr);
280 kvm_make_request(KVM_REQ_EVENT, apic->vcpu); 280 if (ppr < old_ppr)
281 kvm_make_request(KVM_REQ_EVENT, apic->vcpu);
281 } 282 }
282} 283}
283 284
diff --git a/arch/x86/kvm/mmu.c b/arch/x86/kvm/mmu.c
index fbb04aee8301..9cafbb499813 100644
--- a/arch/x86/kvm/mmu.c
+++ b/arch/x86/kvm/mmu.c
@@ -18,9 +18,11 @@
18 * 18 *
19 */ 19 */
20 20
21#include "irq.h"
21#include "mmu.h" 22#include "mmu.h"
22#include "x86.h" 23#include "x86.h"
23#include "kvm_cache_regs.h" 24#include "kvm_cache_regs.h"
25#include "x86.h"
24 26
25#include <linux/kvm_host.h> 27#include <linux/kvm_host.h>
26#include <linux/types.h> 28#include <linux/types.h>
@@ -194,7 +196,6 @@ static struct percpu_counter kvm_total_used_mmu_pages;
194 196
195static u64 __read_mostly shadow_trap_nonpresent_pte; 197static u64 __read_mostly shadow_trap_nonpresent_pte;
196static u64 __read_mostly shadow_notrap_nonpresent_pte; 198static u64 __read_mostly shadow_notrap_nonpresent_pte;
197static u64 __read_mostly shadow_base_present_pte;
198static u64 __read_mostly shadow_nx_mask; 199static u64 __read_mostly shadow_nx_mask;
199static u64 __read_mostly shadow_x_mask; /* mutual exclusive with nx_mask */ 200static u64 __read_mostly shadow_x_mask; /* mutual exclusive with nx_mask */
200static u64 __read_mostly shadow_user_mask; 201static u64 __read_mostly shadow_user_mask;
@@ -213,12 +214,6 @@ void kvm_mmu_set_nonpresent_ptes(u64 trap_pte, u64 notrap_pte)
213} 214}
214EXPORT_SYMBOL_GPL(kvm_mmu_set_nonpresent_ptes); 215EXPORT_SYMBOL_GPL(kvm_mmu_set_nonpresent_ptes);
215 216
216void kvm_mmu_set_base_ptes(u64 base_pte)
217{
218 shadow_base_present_pte = base_pte;
219}
220EXPORT_SYMBOL_GPL(kvm_mmu_set_base_ptes);
221
222void kvm_mmu_set_mask_ptes(u64 user_mask, u64 accessed_mask, 217void kvm_mmu_set_mask_ptes(u64 user_mask, u64 accessed_mask,
223 u64 dirty_mask, u64 nx_mask, u64 x_mask) 218 u64 dirty_mask, u64 nx_mask, u64 x_mask)
224{ 219{
@@ -482,46 +477,46 @@ static void kvm_mmu_page_set_gfn(struct kvm_mmu_page *sp, int index, gfn_t gfn)
482} 477}
483 478
484/* 479/*
485 * Return the pointer to the largepage write count for a given 480 * Return the pointer to the large page information for a given gfn,
486 * gfn, handling slots that are not large page aligned. 481 * handling slots that are not large page aligned.
487 */ 482 */
488static int *slot_largepage_idx(gfn_t gfn, 483static struct kvm_lpage_info *lpage_info_slot(gfn_t gfn,
489 struct kvm_memory_slot *slot, 484 struct kvm_memory_slot *slot,
490 int level) 485 int level)
491{ 486{
492 unsigned long idx; 487 unsigned long idx;
493 488
494 idx = (gfn >> KVM_HPAGE_GFN_SHIFT(level)) - 489 idx = (gfn >> KVM_HPAGE_GFN_SHIFT(level)) -
495 (slot->base_gfn >> KVM_HPAGE_GFN_SHIFT(level)); 490 (slot->base_gfn >> KVM_HPAGE_GFN_SHIFT(level));
496 return &slot->lpage_info[level - 2][idx].write_count; 491 return &slot->lpage_info[level - 2][idx];
497} 492}
498 493
499static void account_shadowed(struct kvm *kvm, gfn_t gfn) 494static void account_shadowed(struct kvm *kvm, gfn_t gfn)
500{ 495{
501 struct kvm_memory_slot *slot; 496 struct kvm_memory_slot *slot;
502 int *write_count; 497 struct kvm_lpage_info *linfo;
503 int i; 498 int i;
504 499
505 slot = gfn_to_memslot(kvm, gfn); 500 slot = gfn_to_memslot(kvm, gfn);
506 for (i = PT_DIRECTORY_LEVEL; 501 for (i = PT_DIRECTORY_LEVEL;
507 i < PT_PAGE_TABLE_LEVEL + KVM_NR_PAGE_SIZES; ++i) { 502 i < PT_PAGE_TABLE_LEVEL + KVM_NR_PAGE_SIZES; ++i) {
508 write_count = slot_largepage_idx(gfn, slot, i); 503 linfo = lpage_info_slot(gfn, slot, i);
509 *write_count += 1; 504 linfo->write_count += 1;
510 } 505 }
511} 506}
512 507
513static void unaccount_shadowed(struct kvm *kvm, gfn_t gfn) 508static void unaccount_shadowed(struct kvm *kvm, gfn_t gfn)
514{ 509{
515 struct kvm_memory_slot *slot; 510 struct kvm_memory_slot *slot;
516 int *write_count; 511 struct kvm_lpage_info *linfo;
517 int i; 512 int i;
518 513
519 slot = gfn_to_memslot(kvm, gfn); 514 slot = gfn_to_memslot(kvm, gfn);
520 for (i = PT_DIRECTORY_LEVEL; 515 for (i = PT_DIRECTORY_LEVEL;
521 i < PT_PAGE_TABLE_LEVEL + KVM_NR_PAGE_SIZES; ++i) { 516 i < PT_PAGE_TABLE_LEVEL + KVM_NR_PAGE_SIZES; ++i) {
522 write_count = slot_largepage_idx(gfn, slot, i); 517 linfo = lpage_info_slot(gfn, slot, i);
523 *write_count -= 1; 518 linfo->write_count -= 1;
524 WARN_ON(*write_count < 0); 519 WARN_ON(linfo->write_count < 0);
525 } 520 }
526} 521}
527 522
@@ -530,12 +525,12 @@ static int has_wrprotected_page(struct kvm *kvm,
530 int level) 525 int level)
531{ 526{
532 struct kvm_memory_slot *slot; 527 struct kvm_memory_slot *slot;
533 int *largepage_idx; 528 struct kvm_lpage_info *linfo;
534 529
535 slot = gfn_to_memslot(kvm, gfn); 530 slot = gfn_to_memslot(kvm, gfn);
536 if (slot) { 531 if (slot) {
537 largepage_idx = slot_largepage_idx(gfn, slot, level); 532 linfo = lpage_info_slot(gfn, slot, level);
538 return *largepage_idx; 533 return linfo->write_count;
539 } 534 }
540 535
541 return 1; 536 return 1;
@@ -590,16 +585,15 @@ static int mapping_level(struct kvm_vcpu *vcpu, gfn_t large_gfn)
590static unsigned long *gfn_to_rmap(struct kvm *kvm, gfn_t gfn, int level) 585static unsigned long *gfn_to_rmap(struct kvm *kvm, gfn_t gfn, int level)
591{ 586{
592 struct kvm_memory_slot *slot; 587 struct kvm_memory_slot *slot;
593 unsigned long idx; 588 struct kvm_lpage_info *linfo;
594 589
595 slot = gfn_to_memslot(kvm, gfn); 590 slot = gfn_to_memslot(kvm, gfn);
596 if (likely(level == PT_PAGE_TABLE_LEVEL)) 591 if (likely(level == PT_PAGE_TABLE_LEVEL))
597 return &slot->rmap[gfn - slot->base_gfn]; 592 return &slot->rmap[gfn - slot->base_gfn];
598 593
599 idx = (gfn >> KVM_HPAGE_GFN_SHIFT(level)) - 594 linfo = lpage_info_slot(gfn, slot, level);
600 (slot->base_gfn >> KVM_HPAGE_GFN_SHIFT(level));
601 595
602 return &slot->lpage_info[level - 2][idx].rmap_pde; 596 return &linfo->rmap_pde;
603} 597}
604 598
605/* 599/*
@@ -887,19 +881,16 @@ static int kvm_handle_hva(struct kvm *kvm, unsigned long hva,
887 end = start + (memslot->npages << PAGE_SHIFT); 881 end = start + (memslot->npages << PAGE_SHIFT);
888 if (hva >= start && hva < end) { 882 if (hva >= start && hva < end) {
889 gfn_t gfn_offset = (hva - start) >> PAGE_SHIFT; 883 gfn_t gfn_offset = (hva - start) >> PAGE_SHIFT;
884 gfn_t gfn = memslot->base_gfn + gfn_offset;
890 885
891 ret = handler(kvm, &memslot->rmap[gfn_offset], data); 886 ret = handler(kvm, &memslot->rmap[gfn_offset], data);
892 887
893 for (j = 0; j < KVM_NR_PAGE_SIZES - 1; ++j) { 888 for (j = 0; j < KVM_NR_PAGE_SIZES - 1; ++j) {
894 unsigned long idx; 889 struct kvm_lpage_info *linfo;
895 int sh; 890
896 891 linfo = lpage_info_slot(gfn, memslot,
897 sh = KVM_HPAGE_GFN_SHIFT(PT_DIRECTORY_LEVEL+j); 892 PT_DIRECTORY_LEVEL + j);
898 idx = ((memslot->base_gfn+gfn_offset) >> sh) - 893 ret |= handler(kvm, &linfo->rmap_pde, data);
899 (memslot->base_gfn >> sh);
900 ret |= handler(kvm,
901 &memslot->lpage_info[j][idx].rmap_pde,
902 data);
903 } 894 }
904 trace_kvm_age_page(hva, memslot, ret); 895 trace_kvm_age_page(hva, memslot, ret);
905 retval |= ret; 896 retval |= ret;
@@ -1161,7 +1152,7 @@ static void nonpaging_prefetch_page(struct kvm_vcpu *vcpu,
1161} 1152}
1162 1153
1163static int nonpaging_sync_page(struct kvm_vcpu *vcpu, 1154static int nonpaging_sync_page(struct kvm_vcpu *vcpu,
1164 struct kvm_mmu_page *sp, bool clear_unsync) 1155 struct kvm_mmu_page *sp)
1165{ 1156{
1166 return 1; 1157 return 1;
1167} 1158}
@@ -1291,7 +1282,7 @@ static int __kvm_sync_page(struct kvm_vcpu *vcpu, struct kvm_mmu_page *sp,
1291 if (clear_unsync) 1282 if (clear_unsync)
1292 kvm_unlink_unsync_page(vcpu->kvm, sp); 1283 kvm_unlink_unsync_page(vcpu->kvm, sp);
1293 1284
1294 if (vcpu->arch.mmu.sync_page(vcpu, sp, clear_unsync)) { 1285 if (vcpu->arch.mmu.sync_page(vcpu, sp)) {
1295 kvm_mmu_prepare_zap_page(vcpu->kvm, sp, invalid_list); 1286 kvm_mmu_prepare_zap_page(vcpu->kvm, sp, invalid_list);
1296 return 1; 1287 return 1;
1297 } 1288 }
@@ -1332,12 +1323,12 @@ static void kvm_sync_pages(struct kvm_vcpu *vcpu, gfn_t gfn)
1332 continue; 1323 continue;
1333 1324
1334 WARN_ON(s->role.level != PT_PAGE_TABLE_LEVEL); 1325 WARN_ON(s->role.level != PT_PAGE_TABLE_LEVEL);
1326 kvm_unlink_unsync_page(vcpu->kvm, s);
1335 if ((s->role.cr4_pae != !!is_pae(vcpu)) || 1327 if ((s->role.cr4_pae != !!is_pae(vcpu)) ||
1336 (vcpu->arch.mmu.sync_page(vcpu, s, true))) { 1328 (vcpu->arch.mmu.sync_page(vcpu, s))) {
1337 kvm_mmu_prepare_zap_page(vcpu->kvm, s, &invalid_list); 1329 kvm_mmu_prepare_zap_page(vcpu->kvm, s, &invalid_list);
1338 continue; 1330 continue;
1339 } 1331 }
1340 kvm_unlink_unsync_page(vcpu->kvm, s);
1341 flush = true; 1332 flush = true;
1342 } 1333 }
1343 1334
@@ -1963,9 +1954,9 @@ static int set_spte(struct kvm_vcpu *vcpu, u64 *sptep,
1963 unsigned pte_access, int user_fault, 1954 unsigned pte_access, int user_fault,
1964 int write_fault, int dirty, int level, 1955 int write_fault, int dirty, int level,
1965 gfn_t gfn, pfn_t pfn, bool speculative, 1956 gfn_t gfn, pfn_t pfn, bool speculative,
1966 bool can_unsync, bool reset_host_protection) 1957 bool can_unsync, bool host_writable)
1967{ 1958{
1968 u64 spte; 1959 u64 spte, entry = *sptep;
1969 int ret = 0; 1960 int ret = 0;
1970 1961
1971 /* 1962 /*
@@ -1973,7 +1964,7 @@ static int set_spte(struct kvm_vcpu *vcpu, u64 *sptep,
1973 * whether the guest actually used the pte (in order to detect 1964 * whether the guest actually used the pte (in order to detect
1974 * demand paging). 1965 * demand paging).
1975 */ 1966 */
1976 spte = shadow_base_present_pte; 1967 spte = PT_PRESENT_MASK;
1977 if (!speculative) 1968 if (!speculative)
1978 spte |= shadow_accessed_mask; 1969 spte |= shadow_accessed_mask;
1979 if (!dirty) 1970 if (!dirty)
@@ -1990,8 +1981,10 @@ static int set_spte(struct kvm_vcpu *vcpu, u64 *sptep,
1990 spte |= kvm_x86_ops->get_mt_mask(vcpu, gfn, 1981 spte |= kvm_x86_ops->get_mt_mask(vcpu, gfn,
1991 kvm_is_mmio_pfn(pfn)); 1982 kvm_is_mmio_pfn(pfn));
1992 1983
1993 if (reset_host_protection) 1984 if (host_writable)
1994 spte |= SPTE_HOST_WRITEABLE; 1985 spte |= SPTE_HOST_WRITEABLE;
1986 else
1987 pte_access &= ~ACC_WRITE_MASK;
1995 1988
1996 spte |= (u64)pfn << PAGE_SHIFT; 1989 spte |= (u64)pfn << PAGE_SHIFT;
1997 1990
@@ -2036,6 +2029,14 @@ static int set_spte(struct kvm_vcpu *vcpu, u64 *sptep,
2036 2029
2037set_pte: 2030set_pte:
2038 update_spte(sptep, spte); 2031 update_spte(sptep, spte);
2032 /*
2033 * If we overwrite a writable spte with a read-only one we
2034 * should flush remote TLBs. Otherwise rmap_write_protect
2035 * will find a read-only spte, even though the writable spte
2036 * might be cached on a CPU's TLB.
2037 */
2038 if (is_writable_pte(entry) && !is_writable_pte(*sptep))
2039 kvm_flush_remote_tlbs(vcpu->kvm);
2039done: 2040done:
2040 return ret; 2041 return ret;
2041} 2042}
@@ -2045,7 +2046,7 @@ static void mmu_set_spte(struct kvm_vcpu *vcpu, u64 *sptep,
2045 int user_fault, int write_fault, int dirty, 2046 int user_fault, int write_fault, int dirty,
2046 int *ptwrite, int level, gfn_t gfn, 2047 int *ptwrite, int level, gfn_t gfn,
2047 pfn_t pfn, bool speculative, 2048 pfn_t pfn, bool speculative,
2048 bool reset_host_protection) 2049 bool host_writable)
2049{ 2050{
2050 int was_rmapped = 0; 2051 int was_rmapped = 0;
2051 int rmap_count; 2052 int rmap_count;
@@ -2080,7 +2081,7 @@ static void mmu_set_spte(struct kvm_vcpu *vcpu, u64 *sptep,
2080 2081
2081 if (set_spte(vcpu, sptep, pte_access, user_fault, write_fault, 2082 if (set_spte(vcpu, sptep, pte_access, user_fault, write_fault,
2082 dirty, level, gfn, pfn, speculative, true, 2083 dirty, level, gfn, pfn, speculative, true,
2083 reset_host_protection)) { 2084 host_writable)) {
2084 if (write_fault) 2085 if (write_fault)
2085 *ptwrite = 1; 2086 *ptwrite = 1;
2086 kvm_mmu_flush_tlb(vcpu); 2087 kvm_mmu_flush_tlb(vcpu);
@@ -2211,7 +2212,8 @@ static void direct_pte_prefetch(struct kvm_vcpu *vcpu, u64 *sptep)
2211} 2212}
2212 2213
2213static int __direct_map(struct kvm_vcpu *vcpu, gpa_t v, int write, 2214static int __direct_map(struct kvm_vcpu *vcpu, gpa_t v, int write,
2214 int level, gfn_t gfn, pfn_t pfn) 2215 int map_writable, int level, gfn_t gfn, pfn_t pfn,
2216 bool prefault)
2215{ 2217{
2216 struct kvm_shadow_walk_iterator iterator; 2218 struct kvm_shadow_walk_iterator iterator;
2217 struct kvm_mmu_page *sp; 2219 struct kvm_mmu_page *sp;
@@ -2220,9 +2222,11 @@ static int __direct_map(struct kvm_vcpu *vcpu, gpa_t v, int write,
2220 2222
2221 for_each_shadow_entry(vcpu, (u64)gfn << PAGE_SHIFT, iterator) { 2223 for_each_shadow_entry(vcpu, (u64)gfn << PAGE_SHIFT, iterator) {
2222 if (iterator.level == level) { 2224 if (iterator.level == level) {
2223 mmu_set_spte(vcpu, iterator.sptep, ACC_ALL, ACC_ALL, 2225 unsigned pte_access = ACC_ALL;
2226
2227 mmu_set_spte(vcpu, iterator.sptep, ACC_ALL, pte_access,
2224 0, write, 1, &pt_write, 2228 0, write, 1, &pt_write,
2225 level, gfn, pfn, false, true); 2229 level, gfn, pfn, prefault, map_writable);
2226 direct_pte_prefetch(vcpu, iterator.sptep); 2230 direct_pte_prefetch(vcpu, iterator.sptep);
2227 ++vcpu->stat.pf_fixed; 2231 ++vcpu->stat.pf_fixed;
2228 break; 2232 break;
@@ -2277,12 +2281,17 @@ static int kvm_handle_bad_page(struct kvm *kvm, gfn_t gfn, pfn_t pfn)
2277 return 1; 2281 return 1;
2278} 2282}
2279 2283
2280static int nonpaging_map(struct kvm_vcpu *vcpu, gva_t v, int write, gfn_t gfn) 2284static bool try_async_pf(struct kvm_vcpu *vcpu, bool prefault, gfn_t gfn,
2285 gva_t gva, pfn_t *pfn, bool write, bool *writable);
2286
2287static int nonpaging_map(struct kvm_vcpu *vcpu, gva_t v, int write, gfn_t gfn,
2288 bool prefault)
2281{ 2289{
2282 int r; 2290 int r;
2283 int level; 2291 int level;
2284 pfn_t pfn; 2292 pfn_t pfn;
2285 unsigned long mmu_seq; 2293 unsigned long mmu_seq;
2294 bool map_writable;
2286 2295
2287 level = mapping_level(vcpu, gfn); 2296 level = mapping_level(vcpu, gfn);
2288 2297
@@ -2297,7 +2306,9 @@ static int nonpaging_map(struct kvm_vcpu *vcpu, gva_t v, int write, gfn_t gfn)
2297 2306
2298 mmu_seq = vcpu->kvm->mmu_notifier_seq; 2307 mmu_seq = vcpu->kvm->mmu_notifier_seq;
2299 smp_rmb(); 2308 smp_rmb();
2300 pfn = gfn_to_pfn(vcpu->kvm, gfn); 2309
2310 if (try_async_pf(vcpu, prefault, gfn, v, &pfn, write, &map_writable))
2311 return 0;
2301 2312
2302 /* mmio */ 2313 /* mmio */
2303 if (is_error_pfn(pfn)) 2314 if (is_error_pfn(pfn))
@@ -2307,7 +2318,8 @@ static int nonpaging_map(struct kvm_vcpu *vcpu, gva_t v, int write, gfn_t gfn)
2307 if (mmu_notifier_retry(vcpu, mmu_seq)) 2318 if (mmu_notifier_retry(vcpu, mmu_seq))
2308 goto out_unlock; 2319 goto out_unlock;
2309 kvm_mmu_free_some_pages(vcpu); 2320 kvm_mmu_free_some_pages(vcpu);
2310 r = __direct_map(vcpu, v, write, level, gfn, pfn); 2321 r = __direct_map(vcpu, v, write, map_writable, level, gfn, pfn,
2322 prefault);
2311 spin_unlock(&vcpu->kvm->mmu_lock); 2323 spin_unlock(&vcpu->kvm->mmu_lock);
2312 2324
2313 2325
@@ -2530,6 +2542,7 @@ static void mmu_sync_roots(struct kvm_vcpu *vcpu)
2530 hpa_t root = vcpu->arch.mmu.root_hpa; 2542 hpa_t root = vcpu->arch.mmu.root_hpa;
2531 sp = page_header(root); 2543 sp = page_header(root);
2532 mmu_sync_children(vcpu, sp); 2544 mmu_sync_children(vcpu, sp);
2545 trace_kvm_mmu_audit(vcpu, AUDIT_POST_SYNC);
2533 return; 2546 return;
2534 } 2547 }
2535 for (i = 0; i < 4; ++i) { 2548 for (i = 0; i < 4; ++i) {
@@ -2552,23 +2565,24 @@ void kvm_mmu_sync_roots(struct kvm_vcpu *vcpu)
2552} 2565}
2553 2566
2554static gpa_t nonpaging_gva_to_gpa(struct kvm_vcpu *vcpu, gva_t vaddr, 2567static gpa_t nonpaging_gva_to_gpa(struct kvm_vcpu *vcpu, gva_t vaddr,
2555 u32 access, u32 *error) 2568 u32 access, struct x86_exception *exception)
2556{ 2569{
2557 if (error) 2570 if (exception)
2558 *error = 0; 2571 exception->error_code = 0;
2559 return vaddr; 2572 return vaddr;
2560} 2573}
2561 2574
2562static gpa_t nonpaging_gva_to_gpa_nested(struct kvm_vcpu *vcpu, gva_t vaddr, 2575static gpa_t nonpaging_gva_to_gpa_nested(struct kvm_vcpu *vcpu, gva_t vaddr,
2563 u32 access, u32 *error) 2576 u32 access,
2577 struct x86_exception *exception)
2564{ 2578{
2565 if (error) 2579 if (exception)
2566 *error = 0; 2580 exception->error_code = 0;
2567 return vcpu->arch.nested_mmu.translate_gpa(vcpu, vaddr, access); 2581 return vcpu->arch.nested_mmu.translate_gpa(vcpu, vaddr, access);
2568} 2582}
2569 2583
2570static int nonpaging_page_fault(struct kvm_vcpu *vcpu, gva_t gva, 2584static int nonpaging_page_fault(struct kvm_vcpu *vcpu, gva_t gva,
2571 u32 error_code) 2585 u32 error_code, bool prefault)
2572{ 2586{
2573 gfn_t gfn; 2587 gfn_t gfn;
2574 int r; 2588 int r;
@@ -2584,17 +2598,67 @@ static int nonpaging_page_fault(struct kvm_vcpu *vcpu, gva_t gva,
2584 gfn = gva >> PAGE_SHIFT; 2598 gfn = gva >> PAGE_SHIFT;
2585 2599
2586 return nonpaging_map(vcpu, gva & PAGE_MASK, 2600 return nonpaging_map(vcpu, gva & PAGE_MASK,
2587 error_code & PFERR_WRITE_MASK, gfn); 2601 error_code & PFERR_WRITE_MASK, gfn, prefault);
2602}
2603
2604static int kvm_arch_setup_async_pf(struct kvm_vcpu *vcpu, gva_t gva, gfn_t gfn)
2605{
2606 struct kvm_arch_async_pf arch;
2607
2608 arch.token = (vcpu->arch.apf.id++ << 12) | vcpu->vcpu_id;
2609 arch.gfn = gfn;
2610 arch.direct_map = vcpu->arch.mmu.direct_map;
2611 arch.cr3 = vcpu->arch.mmu.get_cr3(vcpu);
2612
2613 return kvm_setup_async_pf(vcpu, gva, gfn, &arch);
2588} 2614}
2589 2615
2590static int tdp_page_fault(struct kvm_vcpu *vcpu, gva_t gpa, 2616static bool can_do_async_pf(struct kvm_vcpu *vcpu)
2591 u32 error_code) 2617{
2618 if (unlikely(!irqchip_in_kernel(vcpu->kvm) ||
2619 kvm_event_needs_reinjection(vcpu)))
2620 return false;
2621
2622 return kvm_x86_ops->interrupt_allowed(vcpu);
2623}
2624
2625static bool try_async_pf(struct kvm_vcpu *vcpu, bool prefault, gfn_t gfn,
2626 gva_t gva, pfn_t *pfn, bool write, bool *writable)
2627{
2628 bool async;
2629
2630 *pfn = gfn_to_pfn_async(vcpu->kvm, gfn, &async, write, writable);
2631
2632 if (!async)
2633 return false; /* *pfn has correct page already */
2634
2635 put_page(pfn_to_page(*pfn));
2636
2637 if (!prefault && can_do_async_pf(vcpu)) {
2638 trace_kvm_try_async_get_page(gva, gfn);
2639 if (kvm_find_async_pf_gfn(vcpu, gfn)) {
2640 trace_kvm_async_pf_doublefault(gva, gfn);
2641 kvm_make_request(KVM_REQ_APF_HALT, vcpu);
2642 return true;
2643 } else if (kvm_arch_setup_async_pf(vcpu, gva, gfn))
2644 return true;
2645 }
2646
2647 *pfn = gfn_to_pfn_prot(vcpu->kvm, gfn, write, writable);
2648
2649 return false;
2650}
2651
2652static int tdp_page_fault(struct kvm_vcpu *vcpu, gva_t gpa, u32 error_code,
2653 bool prefault)
2592{ 2654{
2593 pfn_t pfn; 2655 pfn_t pfn;
2594 int r; 2656 int r;
2595 int level; 2657 int level;
2596 gfn_t gfn = gpa >> PAGE_SHIFT; 2658 gfn_t gfn = gpa >> PAGE_SHIFT;
2597 unsigned long mmu_seq; 2659 unsigned long mmu_seq;
2660 int write = error_code & PFERR_WRITE_MASK;
2661 bool map_writable;
2598 2662
2599 ASSERT(vcpu); 2663 ASSERT(vcpu);
2600 ASSERT(VALID_PAGE(vcpu->arch.mmu.root_hpa)); 2664 ASSERT(VALID_PAGE(vcpu->arch.mmu.root_hpa));
@@ -2609,15 +2673,19 @@ static int tdp_page_fault(struct kvm_vcpu *vcpu, gva_t gpa,
2609 2673
2610 mmu_seq = vcpu->kvm->mmu_notifier_seq; 2674 mmu_seq = vcpu->kvm->mmu_notifier_seq;
2611 smp_rmb(); 2675 smp_rmb();
2612 pfn = gfn_to_pfn(vcpu->kvm, gfn); 2676
2677 if (try_async_pf(vcpu, prefault, gfn, gpa, &pfn, write, &map_writable))
2678 return 0;
2679
2680 /* mmio */
2613 if (is_error_pfn(pfn)) 2681 if (is_error_pfn(pfn))
2614 return kvm_handle_bad_page(vcpu->kvm, gfn, pfn); 2682 return kvm_handle_bad_page(vcpu->kvm, gfn, pfn);
2615 spin_lock(&vcpu->kvm->mmu_lock); 2683 spin_lock(&vcpu->kvm->mmu_lock);
2616 if (mmu_notifier_retry(vcpu, mmu_seq)) 2684 if (mmu_notifier_retry(vcpu, mmu_seq))
2617 goto out_unlock; 2685 goto out_unlock;
2618 kvm_mmu_free_some_pages(vcpu); 2686 kvm_mmu_free_some_pages(vcpu);
2619 r = __direct_map(vcpu, gpa, error_code & PFERR_WRITE_MASK, 2687 r = __direct_map(vcpu, gpa, write, map_writable,
2620 level, gfn, pfn); 2688 level, gfn, pfn, prefault);
2621 spin_unlock(&vcpu->kvm->mmu_lock); 2689 spin_unlock(&vcpu->kvm->mmu_lock);
2622 2690
2623 return r; 2691 return r;
@@ -2659,18 +2727,19 @@ void kvm_mmu_flush_tlb(struct kvm_vcpu *vcpu)
2659 2727
2660static void paging_new_cr3(struct kvm_vcpu *vcpu) 2728static void paging_new_cr3(struct kvm_vcpu *vcpu)
2661{ 2729{
2662 pgprintk("%s: cr3 %lx\n", __func__, vcpu->arch.cr3); 2730 pgprintk("%s: cr3 %lx\n", __func__, kvm_read_cr3(vcpu));
2663 mmu_free_roots(vcpu); 2731 mmu_free_roots(vcpu);
2664} 2732}
2665 2733
2666static unsigned long get_cr3(struct kvm_vcpu *vcpu) 2734static unsigned long get_cr3(struct kvm_vcpu *vcpu)
2667{ 2735{
2668 return vcpu->arch.cr3; 2736 return kvm_read_cr3(vcpu);
2669} 2737}
2670 2738
2671static void inject_page_fault(struct kvm_vcpu *vcpu) 2739static void inject_page_fault(struct kvm_vcpu *vcpu,
2740 struct x86_exception *fault)
2672{ 2741{
2673 vcpu->arch.mmu.inject_page_fault(vcpu); 2742 vcpu->arch.mmu.inject_page_fault(vcpu, fault);
2674} 2743}
2675 2744
2676static void paging_free(struct kvm_vcpu *vcpu) 2745static void paging_free(struct kvm_vcpu *vcpu)
@@ -2816,6 +2885,7 @@ static int init_kvm_tdp_mmu(struct kvm_vcpu *vcpu)
2816{ 2885{
2817 struct kvm_mmu *context = vcpu->arch.walk_mmu; 2886 struct kvm_mmu *context = vcpu->arch.walk_mmu;
2818 2887
2888 context->base_role.word = 0;
2819 context->new_cr3 = nonpaging_new_cr3; 2889 context->new_cr3 = nonpaging_new_cr3;
2820 context->page_fault = tdp_page_fault; 2890 context->page_fault = tdp_page_fault;
2821 context->free = nonpaging_free; 2891 context->free = nonpaging_free;
@@ -3008,9 +3078,6 @@ static void mmu_pte_write_new_pte(struct kvm_vcpu *vcpu,
3008 return; 3078 return;
3009 } 3079 }
3010 3080
3011 if (is_rsvd_bits_set(&vcpu->arch.mmu, *(u64 *)new, PT_PAGE_TABLE_LEVEL))
3012 return;
3013
3014 ++vcpu->kvm->stat.mmu_pte_updated; 3081 ++vcpu->kvm->stat.mmu_pte_updated;
3015 if (!sp->role.cr4_pae) 3082 if (!sp->role.cr4_pae)
3016 paging32_update_pte(vcpu, sp, spte, new); 3083 paging32_update_pte(vcpu, sp, spte, new);
@@ -3264,12 +3331,13 @@ void __kvm_mmu_free_some_pages(struct kvm_vcpu *vcpu)
3264 } 3331 }
3265} 3332}
3266 3333
3267int kvm_mmu_page_fault(struct kvm_vcpu *vcpu, gva_t cr2, u32 error_code) 3334int kvm_mmu_page_fault(struct kvm_vcpu *vcpu, gva_t cr2, u32 error_code,
3335 void *insn, int insn_len)
3268{ 3336{
3269 int r; 3337 int r;
3270 enum emulation_result er; 3338 enum emulation_result er;
3271 3339
3272 r = vcpu->arch.mmu.page_fault(vcpu, cr2, error_code); 3340 r = vcpu->arch.mmu.page_fault(vcpu, cr2, error_code, false);
3273 if (r < 0) 3341 if (r < 0)
3274 goto out; 3342 goto out;
3275 3343
@@ -3282,7 +3350,7 @@ int kvm_mmu_page_fault(struct kvm_vcpu *vcpu, gva_t cr2, u32 error_code)
3282 if (r) 3350 if (r)
3283 goto out; 3351 goto out;
3284 3352
3285 er = emulate_instruction(vcpu, cr2, error_code, 0); 3353 er = x86_emulate_instruction(vcpu, cr2, 0, insn, insn_len);
3286 3354
3287 switch (er) { 3355 switch (er) {
3288 case EMULATE_DONE: 3356 case EMULATE_DONE:
@@ -3377,11 +3445,14 @@ void kvm_mmu_slot_remove_write_access(struct kvm *kvm, int slot)
3377 if (!test_bit(slot, sp->slot_bitmap)) 3445 if (!test_bit(slot, sp->slot_bitmap))
3378 continue; 3446 continue;
3379 3447
3448 if (sp->role.level != PT_PAGE_TABLE_LEVEL)
3449 continue;
3450
3380 pt = sp->spt; 3451 pt = sp->spt;
3381 for (i = 0; i < PT64_ENT_PER_PAGE; ++i) 3452 for (i = 0; i < PT64_ENT_PER_PAGE; ++i)
3382 /* avoid RMW */ 3453 /* avoid RMW */
3383 if (is_writable_pte(pt[i])) 3454 if (is_writable_pte(pt[i]))
3384 pt[i] &= ~PT_WRITABLE_MASK; 3455 update_spte(&pt[i], pt[i] & ~PT_WRITABLE_MASK);
3385 } 3456 }
3386 kvm_flush_remote_tlbs(kvm); 3457 kvm_flush_remote_tlbs(kvm);
3387} 3458}
@@ -3463,13 +3534,6 @@ static void mmu_destroy_caches(void)
3463 kmem_cache_destroy(mmu_page_header_cache); 3534 kmem_cache_destroy(mmu_page_header_cache);
3464} 3535}
3465 3536
3466void kvm_mmu_module_exit(void)
3467{
3468 mmu_destroy_caches();
3469 percpu_counter_destroy(&kvm_total_used_mmu_pages);
3470 unregister_shrinker(&mmu_shrinker);
3471}
3472
3473int kvm_mmu_module_init(void) 3537int kvm_mmu_module_init(void)
3474{ 3538{
3475 pte_chain_cache = kmem_cache_create("kvm_pte_chain", 3539 pte_chain_cache = kmem_cache_create("kvm_pte_chain",
@@ -3566,7 +3630,7 @@ static int kvm_pv_mmu_write(struct kvm_vcpu *vcpu,
3566 3630
3567static int kvm_pv_mmu_flush_tlb(struct kvm_vcpu *vcpu) 3631static int kvm_pv_mmu_flush_tlb(struct kvm_vcpu *vcpu)
3568{ 3632{
3569 (void)kvm_set_cr3(vcpu, vcpu->arch.cr3); 3633 (void)kvm_set_cr3(vcpu, kvm_read_cr3(vcpu));
3570 return 1; 3634 return 1;
3571} 3635}
3572 3636
@@ -3662,12 +3726,6 @@ int kvm_mmu_get_spte_hierarchy(struct kvm_vcpu *vcpu, u64 addr, u64 sptes[4])
3662} 3726}
3663EXPORT_SYMBOL_GPL(kvm_mmu_get_spte_hierarchy); 3727EXPORT_SYMBOL_GPL(kvm_mmu_get_spte_hierarchy);
3664 3728
3665#ifdef CONFIG_KVM_MMU_AUDIT
3666#include "mmu_audit.c"
3667#else
3668static void mmu_audit_disable(void) { }
3669#endif
3670
3671void kvm_mmu_destroy(struct kvm_vcpu *vcpu) 3729void kvm_mmu_destroy(struct kvm_vcpu *vcpu)
3672{ 3730{
3673 ASSERT(vcpu); 3731 ASSERT(vcpu);
@@ -3675,5 +3733,18 @@ void kvm_mmu_destroy(struct kvm_vcpu *vcpu)
3675 destroy_kvm_mmu(vcpu); 3733 destroy_kvm_mmu(vcpu);
3676 free_mmu_pages(vcpu); 3734 free_mmu_pages(vcpu);
3677 mmu_free_memory_caches(vcpu); 3735 mmu_free_memory_caches(vcpu);
3736}
3737
3738#ifdef CONFIG_KVM_MMU_AUDIT
3739#include "mmu_audit.c"
3740#else
3741static void mmu_audit_disable(void) { }
3742#endif
3743
3744void kvm_mmu_module_exit(void)
3745{
3746 mmu_destroy_caches();
3747 percpu_counter_destroy(&kvm_total_used_mmu_pages);
3748 unregister_shrinker(&mmu_shrinker);
3678 mmu_audit_disable(); 3749 mmu_audit_disable();
3679} 3750}
diff --git a/arch/x86/kvm/mmu_audit.c b/arch/x86/kvm/mmu_audit.c
index ba2bcdde6221..5f6223b8bcf7 100644
--- a/arch/x86/kvm/mmu_audit.c
+++ b/arch/x86/kvm/mmu_audit.c
@@ -19,11 +19,9 @@
19 19
20#include <linux/ratelimit.h> 20#include <linux/ratelimit.h>
21 21
22static int audit_point; 22#define audit_printk(kvm, fmt, args...) \
23
24#define audit_printk(fmt, args...) \
25 printk(KERN_ERR "audit: (%s) error: " \ 23 printk(KERN_ERR "audit: (%s) error: " \
26 fmt, audit_point_name[audit_point], ##args) 24 fmt, audit_point_name[kvm->arch.audit_point], ##args)
27 25
28typedef void (*inspect_spte_fn) (struct kvm_vcpu *vcpu, u64 *sptep, int level); 26typedef void (*inspect_spte_fn) (struct kvm_vcpu *vcpu, u64 *sptep, int level);
29 27
@@ -97,18 +95,21 @@ static void audit_mappings(struct kvm_vcpu *vcpu, u64 *sptep, int level)
97 95
98 if (sp->unsync) { 96 if (sp->unsync) {
99 if (level != PT_PAGE_TABLE_LEVEL) { 97 if (level != PT_PAGE_TABLE_LEVEL) {
100 audit_printk("unsync sp: %p level = %d\n", sp, level); 98 audit_printk(vcpu->kvm, "unsync sp: %p "
99 "level = %d\n", sp, level);
101 return; 100 return;
102 } 101 }
103 102
104 if (*sptep == shadow_notrap_nonpresent_pte) { 103 if (*sptep == shadow_notrap_nonpresent_pte) {
105 audit_printk("notrap spte in unsync sp: %p\n", sp); 104 audit_printk(vcpu->kvm, "notrap spte in unsync "
105 "sp: %p\n", sp);
106 return; 106 return;
107 } 107 }
108 } 108 }
109 109
110 if (sp->role.direct && *sptep == shadow_notrap_nonpresent_pte) { 110 if (sp->role.direct && *sptep == shadow_notrap_nonpresent_pte) {
111 audit_printk("notrap spte in direct sp: %p\n", sp); 111 audit_printk(vcpu->kvm, "notrap spte in direct sp: %p\n",
112 sp);
112 return; 113 return;
113 } 114 }
114 115
@@ -125,8 +126,9 @@ static void audit_mappings(struct kvm_vcpu *vcpu, u64 *sptep, int level)
125 126
126 hpa = pfn << PAGE_SHIFT; 127 hpa = pfn << PAGE_SHIFT;
127 if ((*sptep & PT64_BASE_ADDR_MASK) != hpa) 128 if ((*sptep & PT64_BASE_ADDR_MASK) != hpa)
128 audit_printk("levels %d pfn %llx hpa %llx ent %llxn", 129 audit_printk(vcpu->kvm, "levels %d pfn %llx hpa %llx "
129 vcpu->arch.mmu.root_level, pfn, hpa, *sptep); 130 "ent %llxn", vcpu->arch.mmu.root_level, pfn,
131 hpa, *sptep);
130} 132}
131 133
132static void inspect_spte_has_rmap(struct kvm *kvm, u64 *sptep) 134static void inspect_spte_has_rmap(struct kvm *kvm, u64 *sptep)
@@ -142,8 +144,8 @@ static void inspect_spte_has_rmap(struct kvm *kvm, u64 *sptep)
142 if (!gfn_to_memslot(kvm, gfn)) { 144 if (!gfn_to_memslot(kvm, gfn)) {
143 if (!printk_ratelimit()) 145 if (!printk_ratelimit())
144 return; 146 return;
145 audit_printk("no memslot for gfn %llx\n", gfn); 147 audit_printk(kvm, "no memslot for gfn %llx\n", gfn);
146 audit_printk("index %ld of sp (gfn=%llx)\n", 148 audit_printk(kvm, "index %ld of sp (gfn=%llx)\n",
147 (long int)(sptep - rev_sp->spt), rev_sp->gfn); 149 (long int)(sptep - rev_sp->spt), rev_sp->gfn);
148 dump_stack(); 150 dump_stack();
149 return; 151 return;
@@ -153,7 +155,8 @@ static void inspect_spte_has_rmap(struct kvm *kvm, u64 *sptep)
153 if (!*rmapp) { 155 if (!*rmapp) {
154 if (!printk_ratelimit()) 156 if (!printk_ratelimit())
155 return; 157 return;
156 audit_printk("no rmap for writable spte %llx\n", *sptep); 158 audit_printk(kvm, "no rmap for writable spte %llx\n",
159 *sptep);
157 dump_stack(); 160 dump_stack();
158 } 161 }
159} 162}
@@ -168,8 +171,9 @@ static void audit_spte_after_sync(struct kvm_vcpu *vcpu, u64 *sptep, int level)
168{ 171{
169 struct kvm_mmu_page *sp = page_header(__pa(sptep)); 172 struct kvm_mmu_page *sp = page_header(__pa(sptep));
170 173
171 if (audit_point == AUDIT_POST_SYNC && sp->unsync) 174 if (vcpu->kvm->arch.audit_point == AUDIT_POST_SYNC && sp->unsync)
172 audit_printk("meet unsync sp(%p) after sync root.\n", sp); 175 audit_printk(vcpu->kvm, "meet unsync sp(%p) after sync "
176 "root.\n", sp);
173} 177}
174 178
175static void check_mappings_rmap(struct kvm *kvm, struct kvm_mmu_page *sp) 179static void check_mappings_rmap(struct kvm *kvm, struct kvm_mmu_page *sp)
@@ -202,8 +206,9 @@ static void audit_write_protection(struct kvm *kvm, struct kvm_mmu_page *sp)
202 spte = rmap_next(kvm, rmapp, NULL); 206 spte = rmap_next(kvm, rmapp, NULL);
203 while (spte) { 207 while (spte) {
204 if (is_writable_pte(*spte)) 208 if (is_writable_pte(*spte))
205 audit_printk("shadow page has writable mappings: gfn " 209 audit_printk(kvm, "shadow page has writable "
206 "%llx role %x\n", sp->gfn, sp->role.word); 210 "mappings: gfn %llx role %x\n",
211 sp->gfn, sp->role.word);
207 spte = rmap_next(kvm, rmapp, spte); 212 spte = rmap_next(kvm, rmapp, spte);
208 } 213 }
209} 214}
@@ -238,7 +243,7 @@ static void kvm_mmu_audit(void *ignore, struct kvm_vcpu *vcpu, int point)
238 if (!__ratelimit(&ratelimit_state)) 243 if (!__ratelimit(&ratelimit_state))
239 return; 244 return;
240 245
241 audit_point = point; 246 vcpu->kvm->arch.audit_point = point;
242 audit_all_active_sps(vcpu->kvm); 247 audit_all_active_sps(vcpu->kvm);
243 audit_vcpu_spte(vcpu); 248 audit_vcpu_spte(vcpu);
244} 249}
diff --git a/arch/x86/kvm/paging_tmpl.h b/arch/x86/kvm/paging_tmpl.h
index cd7a833a3b52..53210f1e94c2 100644
--- a/arch/x86/kvm/paging_tmpl.h
+++ b/arch/x86/kvm/paging_tmpl.h
@@ -72,7 +72,7 @@ struct guest_walker {
72 unsigned pt_access; 72 unsigned pt_access;
73 unsigned pte_access; 73 unsigned pte_access;
74 gfn_t gfn; 74 gfn_t gfn;
75 u32 error_code; 75 struct x86_exception fault;
76}; 76};
77 77
78static gfn_t gpte_to_gfn_lvl(pt_element_t gpte, int lvl) 78static gfn_t gpte_to_gfn_lvl(pt_element_t gpte, int lvl)
@@ -266,21 +266,23 @@ walk:
266 return 1; 266 return 1;
267 267
268error: 268error:
269 walker->error_code = 0; 269 walker->fault.vector = PF_VECTOR;
270 walker->fault.error_code_valid = true;
271 walker->fault.error_code = 0;
270 if (present) 272 if (present)
271 walker->error_code |= PFERR_PRESENT_MASK; 273 walker->fault.error_code |= PFERR_PRESENT_MASK;
272 274
273 walker->error_code |= write_fault | user_fault; 275 walker->fault.error_code |= write_fault | user_fault;
274 276
275 if (fetch_fault && mmu->nx) 277 if (fetch_fault && mmu->nx)
276 walker->error_code |= PFERR_FETCH_MASK; 278 walker->fault.error_code |= PFERR_FETCH_MASK;
277 if (rsvd_fault) 279 if (rsvd_fault)
278 walker->error_code |= PFERR_RSVD_MASK; 280 walker->fault.error_code |= PFERR_RSVD_MASK;
279 281
280 vcpu->arch.fault.address = addr; 282 walker->fault.address = addr;
281 vcpu->arch.fault.error_code = walker->error_code; 283 walker->fault.nested_page_fault = mmu != vcpu->arch.walk_mmu;
282 284
283 trace_kvm_mmu_walker_error(walker->error_code); 285 trace_kvm_mmu_walker_error(walker->fault.error_code);
284 return 0; 286 return 0;
285} 287}
286 288
@@ -299,25 +301,42 @@ static int FNAME(walk_addr_nested)(struct guest_walker *walker,
299 addr, access); 301 addr, access);
300} 302}
301 303
304static bool FNAME(prefetch_invalid_gpte)(struct kvm_vcpu *vcpu,
305 struct kvm_mmu_page *sp, u64 *spte,
306 pt_element_t gpte)
307{
308 u64 nonpresent = shadow_trap_nonpresent_pte;
309
310 if (is_rsvd_bits_set(&vcpu->arch.mmu, gpte, PT_PAGE_TABLE_LEVEL))
311 goto no_present;
312
313 if (!is_present_gpte(gpte)) {
314 if (!sp->unsync)
315 nonpresent = shadow_notrap_nonpresent_pte;
316 goto no_present;
317 }
318
319 if (!(gpte & PT_ACCESSED_MASK))
320 goto no_present;
321
322 return false;
323
324no_present:
325 drop_spte(vcpu->kvm, spte, nonpresent);
326 return true;
327}
328
302static void FNAME(update_pte)(struct kvm_vcpu *vcpu, struct kvm_mmu_page *sp, 329static void FNAME(update_pte)(struct kvm_vcpu *vcpu, struct kvm_mmu_page *sp,
303 u64 *spte, const void *pte) 330 u64 *spte, const void *pte)
304{ 331{
305 pt_element_t gpte; 332 pt_element_t gpte;
306 unsigned pte_access; 333 unsigned pte_access;
307 pfn_t pfn; 334 pfn_t pfn;
308 u64 new_spte;
309 335
310 gpte = *(const pt_element_t *)pte; 336 gpte = *(const pt_element_t *)pte;
311 if (~gpte & (PT_PRESENT_MASK | PT_ACCESSED_MASK)) { 337 if (FNAME(prefetch_invalid_gpte)(vcpu, sp, spte, gpte))
312 if (!is_present_gpte(gpte)) {
313 if (sp->unsync)
314 new_spte = shadow_trap_nonpresent_pte;
315 else
316 new_spte = shadow_notrap_nonpresent_pte;
317 __set_spte(spte, new_spte);
318 }
319 return; 338 return;
320 } 339
321 pgprintk("%s: gpte %llx spte %p\n", __func__, (u64)gpte, spte); 340 pgprintk("%s: gpte %llx spte %p\n", __func__, (u64)gpte, spte);
322 pte_access = sp->role.access & FNAME(gpte_access)(vcpu, gpte); 341 pte_access = sp->role.access & FNAME(gpte_access)(vcpu, gpte);
323 if (gpte_to_gfn(gpte) != vcpu->arch.update_pte.gfn) 342 if (gpte_to_gfn(gpte) != vcpu->arch.update_pte.gfn)
@@ -329,7 +348,7 @@ static void FNAME(update_pte)(struct kvm_vcpu *vcpu, struct kvm_mmu_page *sp,
329 return; 348 return;
330 kvm_get_pfn(pfn); 349 kvm_get_pfn(pfn);
331 /* 350 /*
332 * we call mmu_set_spte() with reset_host_protection = true beacuse that 351 * we call mmu_set_spte() with host_writable = true beacuse that
333 * vcpu->arch.update_pte.pfn was fetched from get_user_pages(write = 1). 352 * vcpu->arch.update_pte.pfn was fetched from get_user_pages(write = 1).
334 */ 353 */
335 mmu_set_spte(vcpu, spte, sp->role.access, pte_access, 0, 0, 354 mmu_set_spte(vcpu, spte, sp->role.access, pte_access, 0, 0,
@@ -364,7 +383,6 @@ static void FNAME(pte_prefetch)(struct kvm_vcpu *vcpu, struct guest_walker *gw,
364 u64 *sptep) 383 u64 *sptep)
365{ 384{
366 struct kvm_mmu_page *sp; 385 struct kvm_mmu_page *sp;
367 struct kvm_mmu *mmu = &vcpu->arch.mmu;
368 pt_element_t *gptep = gw->prefetch_ptes; 386 pt_element_t *gptep = gw->prefetch_ptes;
369 u64 *spte; 387 u64 *spte;
370 int i; 388 int i;
@@ -395,14 +413,7 @@ static void FNAME(pte_prefetch)(struct kvm_vcpu *vcpu, struct guest_walker *gw,
395 413
396 gpte = gptep[i]; 414 gpte = gptep[i];
397 415
398 if (!is_present_gpte(gpte) || 416 if (FNAME(prefetch_invalid_gpte)(vcpu, sp, spte, gpte))
399 is_rsvd_bits_set(mmu, gpte, PT_PAGE_TABLE_LEVEL)) {
400 if (!sp->unsync)
401 __set_spte(spte, shadow_notrap_nonpresent_pte);
402 continue;
403 }
404
405 if (!(gpte & PT_ACCESSED_MASK))
406 continue; 417 continue;
407 418
408 pte_access = sp->role.access & FNAME(gpte_access)(vcpu, gpte); 419 pte_access = sp->role.access & FNAME(gpte_access)(vcpu, gpte);
@@ -427,7 +438,8 @@ static void FNAME(pte_prefetch)(struct kvm_vcpu *vcpu, struct guest_walker *gw,
427static u64 *FNAME(fetch)(struct kvm_vcpu *vcpu, gva_t addr, 438static u64 *FNAME(fetch)(struct kvm_vcpu *vcpu, gva_t addr,
428 struct guest_walker *gw, 439 struct guest_walker *gw,
429 int user_fault, int write_fault, int hlevel, 440 int user_fault, int write_fault, int hlevel,
430 int *ptwrite, pfn_t pfn) 441 int *ptwrite, pfn_t pfn, bool map_writable,
442 bool prefault)
431{ 443{
432 unsigned access = gw->pt_access; 444 unsigned access = gw->pt_access;
433 struct kvm_mmu_page *sp = NULL; 445 struct kvm_mmu_page *sp = NULL;
@@ -501,7 +513,7 @@ static u64 *FNAME(fetch)(struct kvm_vcpu *vcpu, gva_t addr,
501 513
502 mmu_set_spte(vcpu, it.sptep, access, gw->pte_access & access, 514 mmu_set_spte(vcpu, it.sptep, access, gw->pte_access & access,
503 user_fault, write_fault, dirty, ptwrite, it.level, 515 user_fault, write_fault, dirty, ptwrite, it.level,
504 gw->gfn, pfn, false, true); 516 gw->gfn, pfn, prefault, map_writable);
505 FNAME(pte_prefetch)(vcpu, gw, it.sptep); 517 FNAME(pte_prefetch)(vcpu, gw, it.sptep);
506 518
507 return it.sptep; 519 return it.sptep;
@@ -527,8 +539,8 @@ out_gpte_changed:
527 * Returns: 1 if we need to emulate the instruction, 0 otherwise, or 539 * Returns: 1 if we need to emulate the instruction, 0 otherwise, or
528 * a negative value on error. 540 * a negative value on error.
529 */ 541 */
530static int FNAME(page_fault)(struct kvm_vcpu *vcpu, gva_t addr, 542static int FNAME(page_fault)(struct kvm_vcpu *vcpu, gva_t addr, u32 error_code,
531 u32 error_code) 543 bool prefault)
532{ 544{
533 int write_fault = error_code & PFERR_WRITE_MASK; 545 int write_fault = error_code & PFERR_WRITE_MASK;
534 int user_fault = error_code & PFERR_USER_MASK; 546 int user_fault = error_code & PFERR_USER_MASK;
@@ -539,6 +551,7 @@ static int FNAME(page_fault)(struct kvm_vcpu *vcpu, gva_t addr,
539 pfn_t pfn; 551 pfn_t pfn;
540 int level = PT_PAGE_TABLE_LEVEL; 552 int level = PT_PAGE_TABLE_LEVEL;
541 unsigned long mmu_seq; 553 unsigned long mmu_seq;
554 bool map_writable;
542 555
543 pgprintk("%s: addr %lx err %x\n", __func__, addr, error_code); 556 pgprintk("%s: addr %lx err %x\n", __func__, addr, error_code);
544 557
@@ -556,8 +569,11 @@ static int FNAME(page_fault)(struct kvm_vcpu *vcpu, gva_t addr,
556 */ 569 */
557 if (!r) { 570 if (!r) {
558 pgprintk("%s: guest page fault\n", __func__); 571 pgprintk("%s: guest page fault\n", __func__);
559 inject_page_fault(vcpu); 572 if (!prefault) {
560 vcpu->arch.last_pt_write_count = 0; /* reset fork detector */ 573 inject_page_fault(vcpu, &walker.fault);
574 /* reset fork detector */
575 vcpu->arch.last_pt_write_count = 0;
576 }
561 return 0; 577 return 0;
562 } 578 }
563 579
@@ -568,7 +584,10 @@ static int FNAME(page_fault)(struct kvm_vcpu *vcpu, gva_t addr,
568 584
569 mmu_seq = vcpu->kvm->mmu_notifier_seq; 585 mmu_seq = vcpu->kvm->mmu_notifier_seq;
570 smp_rmb(); 586 smp_rmb();
571 pfn = gfn_to_pfn(vcpu->kvm, walker.gfn); 587
588 if (try_async_pf(vcpu, prefault, walker.gfn, addr, &pfn, write_fault,
589 &map_writable))
590 return 0;
572 591
573 /* mmio */ 592 /* mmio */
574 if (is_error_pfn(pfn)) 593 if (is_error_pfn(pfn))
@@ -581,7 +600,7 @@ static int FNAME(page_fault)(struct kvm_vcpu *vcpu, gva_t addr,
581 trace_kvm_mmu_audit(vcpu, AUDIT_PRE_PAGE_FAULT); 600 trace_kvm_mmu_audit(vcpu, AUDIT_PRE_PAGE_FAULT);
582 kvm_mmu_free_some_pages(vcpu); 601 kvm_mmu_free_some_pages(vcpu);
583 sptep = FNAME(fetch)(vcpu, addr, &walker, user_fault, write_fault, 602 sptep = FNAME(fetch)(vcpu, addr, &walker, user_fault, write_fault,
584 level, &write_pt, pfn); 603 level, &write_pt, pfn, map_writable, prefault);
585 (void)sptep; 604 (void)sptep;
586 pgprintk("%s: shadow pte %p %llx ptwrite %d\n", __func__, 605 pgprintk("%s: shadow pte %p %llx ptwrite %d\n", __func__,
587 sptep, *sptep, write_pt); 606 sptep, *sptep, write_pt);
@@ -661,7 +680,7 @@ static void FNAME(invlpg)(struct kvm_vcpu *vcpu, gva_t gva)
661} 680}
662 681
663static gpa_t FNAME(gva_to_gpa)(struct kvm_vcpu *vcpu, gva_t vaddr, u32 access, 682static gpa_t FNAME(gva_to_gpa)(struct kvm_vcpu *vcpu, gva_t vaddr, u32 access,
664 u32 *error) 683 struct x86_exception *exception)
665{ 684{
666 struct guest_walker walker; 685 struct guest_walker walker;
667 gpa_t gpa = UNMAPPED_GVA; 686 gpa_t gpa = UNMAPPED_GVA;
@@ -672,14 +691,15 @@ static gpa_t FNAME(gva_to_gpa)(struct kvm_vcpu *vcpu, gva_t vaddr, u32 access,
672 if (r) { 691 if (r) {
673 gpa = gfn_to_gpa(walker.gfn); 692 gpa = gfn_to_gpa(walker.gfn);
674 gpa |= vaddr & ~PAGE_MASK; 693 gpa |= vaddr & ~PAGE_MASK;
675 } else if (error) 694 } else if (exception)
676 *error = walker.error_code; 695 *exception = walker.fault;
677 696
678 return gpa; 697 return gpa;
679} 698}
680 699
681static gpa_t FNAME(gva_to_gpa_nested)(struct kvm_vcpu *vcpu, gva_t vaddr, 700static gpa_t FNAME(gva_to_gpa_nested)(struct kvm_vcpu *vcpu, gva_t vaddr,
682 u32 access, u32 *error) 701 u32 access,
702 struct x86_exception *exception)
683{ 703{
684 struct guest_walker walker; 704 struct guest_walker walker;
685 gpa_t gpa = UNMAPPED_GVA; 705 gpa_t gpa = UNMAPPED_GVA;
@@ -690,8 +710,8 @@ static gpa_t FNAME(gva_to_gpa_nested)(struct kvm_vcpu *vcpu, gva_t vaddr,
690 if (r) { 710 if (r) {
691 gpa = gfn_to_gpa(walker.gfn); 711 gpa = gfn_to_gpa(walker.gfn);
692 gpa |= vaddr & ~PAGE_MASK; 712 gpa |= vaddr & ~PAGE_MASK;
693 } else if (error) 713 } else if (exception)
694 *error = walker.error_code; 714 *exception = walker.fault;
695 715
696 return gpa; 716 return gpa;
697} 717}
@@ -730,12 +750,19 @@ static void FNAME(prefetch_page)(struct kvm_vcpu *vcpu,
730 * Using the cached information from sp->gfns is safe because: 750 * Using the cached information from sp->gfns is safe because:
731 * - The spte has a reference to the struct page, so the pfn for a given gfn 751 * - The spte has a reference to the struct page, so the pfn for a given gfn
732 * can't change unless all sptes pointing to it are nuked first. 752 * can't change unless all sptes pointing to it are nuked first.
753 *
754 * Note:
755 * We should flush all tlbs if spte is dropped even though guest is
756 * responsible for it. Since if we don't, kvm_mmu_notifier_invalidate_page
757 * and kvm_mmu_notifier_invalidate_range_start detect the mapping page isn't
758 * used by guest then tlbs are not flushed, so guest is allowed to access the
759 * freed pages.
760 * And we increase kvm->tlbs_dirty to delay tlbs flush in this case.
733 */ 761 */
734static int FNAME(sync_page)(struct kvm_vcpu *vcpu, struct kvm_mmu_page *sp, 762static int FNAME(sync_page)(struct kvm_vcpu *vcpu, struct kvm_mmu_page *sp)
735 bool clear_unsync)
736{ 763{
737 int i, offset, nr_present; 764 int i, offset, nr_present;
738 bool reset_host_protection; 765 bool host_writable;
739 gpa_t first_pte_gpa; 766 gpa_t first_pte_gpa;
740 767
741 offset = nr_present = 0; 768 offset = nr_present = 0;
@@ -764,31 +791,27 @@ static int FNAME(sync_page)(struct kvm_vcpu *vcpu, struct kvm_mmu_page *sp,
764 return -EINVAL; 791 return -EINVAL;
765 792
766 gfn = gpte_to_gfn(gpte); 793 gfn = gpte_to_gfn(gpte);
767 if (is_rsvd_bits_set(&vcpu->arch.mmu, gpte, PT_PAGE_TABLE_LEVEL)
768 || gfn != sp->gfns[i] || !is_present_gpte(gpte)
769 || !(gpte & PT_ACCESSED_MASK)) {
770 u64 nonpresent;
771 794
772 if (is_present_gpte(gpte) || !clear_unsync) 795 if (FNAME(prefetch_invalid_gpte)(vcpu, sp, &sp->spt[i], gpte)) {
773 nonpresent = shadow_trap_nonpresent_pte; 796 vcpu->kvm->tlbs_dirty++;
774 else 797 continue;
775 nonpresent = shadow_notrap_nonpresent_pte; 798 }
776 drop_spte(vcpu->kvm, &sp->spt[i], nonpresent); 799
800 if (gfn != sp->gfns[i]) {
801 drop_spte(vcpu->kvm, &sp->spt[i],
802 shadow_trap_nonpresent_pte);
803 vcpu->kvm->tlbs_dirty++;
777 continue; 804 continue;
778 } 805 }
779 806
780 nr_present++; 807 nr_present++;
781 pte_access = sp->role.access & FNAME(gpte_access)(vcpu, gpte); 808 pte_access = sp->role.access & FNAME(gpte_access)(vcpu, gpte);
782 if (!(sp->spt[i] & SPTE_HOST_WRITEABLE)) { 809 host_writable = sp->spt[i] & SPTE_HOST_WRITEABLE;
783 pte_access &= ~ACC_WRITE_MASK; 810
784 reset_host_protection = 0;
785 } else {
786 reset_host_protection = 1;
787 }
788 set_spte(vcpu, &sp->spt[i], pte_access, 0, 0, 811 set_spte(vcpu, &sp->spt[i], pte_access, 0, 0,
789 is_dirty_gpte(gpte), PT_PAGE_TABLE_LEVEL, gfn, 812 is_dirty_gpte(gpte), PT_PAGE_TABLE_LEVEL, gfn,
790 spte_to_pfn(sp->spt[i]), true, false, 813 spte_to_pfn(sp->spt[i]), true, false,
791 reset_host_protection); 814 host_writable);
792 } 815 }
793 816
794 return !nr_present; 817 return !nr_present;
diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
index b81a9b7c2ca4..25bd1bc5aad2 100644
--- a/arch/x86/kvm/svm.c
+++ b/arch/x86/kvm/svm.c
@@ -31,6 +31,7 @@
31 31
32#include <asm/tlbflush.h> 32#include <asm/tlbflush.h>
33#include <asm/desc.h> 33#include <asm/desc.h>
34#include <asm/kvm_para.h>
34 35
35#include <asm/virtext.h> 36#include <asm/virtext.h>
36#include "trace.h" 37#include "trace.h"
@@ -50,6 +51,10 @@ MODULE_LICENSE("GPL");
50#define SVM_FEATURE_LBRV (1 << 1) 51#define SVM_FEATURE_LBRV (1 << 1)
51#define SVM_FEATURE_SVML (1 << 2) 52#define SVM_FEATURE_SVML (1 << 2)
52#define SVM_FEATURE_NRIP (1 << 3) 53#define SVM_FEATURE_NRIP (1 << 3)
54#define SVM_FEATURE_TSC_RATE (1 << 4)
55#define SVM_FEATURE_VMCB_CLEAN (1 << 5)
56#define SVM_FEATURE_FLUSH_ASID (1 << 6)
57#define SVM_FEATURE_DECODE_ASSIST (1 << 7)
53#define SVM_FEATURE_PAUSE_FILTER (1 << 10) 58#define SVM_FEATURE_PAUSE_FILTER (1 << 10)
54 59
55#define NESTED_EXIT_HOST 0 /* Exit handled on host level */ 60#define NESTED_EXIT_HOST 0 /* Exit handled on host level */
@@ -97,10 +102,8 @@ struct nested_state {
97 unsigned long vmexit_rax; 102 unsigned long vmexit_rax;
98 103
99 /* cache for intercepts of the guest */ 104 /* cache for intercepts of the guest */
100 u16 intercept_cr_read; 105 u32 intercept_cr;
101 u16 intercept_cr_write; 106 u32 intercept_dr;
102 u16 intercept_dr_read;
103 u16 intercept_dr_write;
104 u32 intercept_exceptions; 107 u32 intercept_exceptions;
105 u64 intercept; 108 u64 intercept;
106 109
@@ -123,7 +126,12 @@ struct vcpu_svm {
123 u64 next_rip; 126 u64 next_rip;
124 127
125 u64 host_user_msrs[NR_HOST_SAVE_USER_MSRS]; 128 u64 host_user_msrs[NR_HOST_SAVE_USER_MSRS];
126 u64 host_gs_base; 129 struct {
130 u16 fs;
131 u16 gs;
132 u16 ldt;
133 u64 gs_base;
134 } host;
127 135
128 u32 *msrpm; 136 u32 *msrpm;
129 137
@@ -133,6 +141,7 @@ struct vcpu_svm {
133 141
134 unsigned int3_injected; 142 unsigned int3_injected;
135 unsigned long int3_rip; 143 unsigned long int3_rip;
144 u32 apf_reason;
136}; 145};
137 146
138#define MSR_INVALID 0xffffffffU 147#define MSR_INVALID 0xffffffffU
@@ -180,14 +189,151 @@ static int nested_svm_vmexit(struct vcpu_svm *svm);
180static int nested_svm_check_exception(struct vcpu_svm *svm, unsigned nr, 189static int nested_svm_check_exception(struct vcpu_svm *svm, unsigned nr,
181 bool has_error_code, u32 error_code); 190 bool has_error_code, u32 error_code);
182 191
192enum {
193 VMCB_INTERCEPTS, /* Intercept vectors, TSC offset,
194 pause filter count */
195 VMCB_PERM_MAP, /* IOPM Base and MSRPM Base */
196 VMCB_ASID, /* ASID */
197 VMCB_INTR, /* int_ctl, int_vector */
198 VMCB_NPT, /* npt_en, nCR3, gPAT */
199 VMCB_CR, /* CR0, CR3, CR4, EFER */
200 VMCB_DR, /* DR6, DR7 */
201 VMCB_DT, /* GDT, IDT */
202 VMCB_SEG, /* CS, DS, SS, ES, CPL */
203 VMCB_CR2, /* CR2 only */
204 VMCB_LBR, /* DBGCTL, BR_FROM, BR_TO, LAST_EX_FROM, LAST_EX_TO */
205 VMCB_DIRTY_MAX,
206};
207
208/* TPR and CR2 are always written before VMRUN */
209#define VMCB_ALWAYS_DIRTY_MASK ((1U << VMCB_INTR) | (1U << VMCB_CR2))
210
211static inline void mark_all_dirty(struct vmcb *vmcb)
212{
213 vmcb->control.clean = 0;
214}
215
216static inline void mark_all_clean(struct vmcb *vmcb)
217{
218 vmcb->control.clean = ((1 << VMCB_DIRTY_MAX) - 1)
219 & ~VMCB_ALWAYS_DIRTY_MASK;
220}
221
222static inline void mark_dirty(struct vmcb *vmcb, int bit)
223{
224 vmcb->control.clean &= ~(1 << bit);
225}
226
183static inline struct vcpu_svm *to_svm(struct kvm_vcpu *vcpu) 227static inline struct vcpu_svm *to_svm(struct kvm_vcpu *vcpu)
184{ 228{
185 return container_of(vcpu, struct vcpu_svm, vcpu); 229 return container_of(vcpu, struct vcpu_svm, vcpu);
186} 230}
187 231
188static inline bool is_nested(struct vcpu_svm *svm) 232static void recalc_intercepts(struct vcpu_svm *svm)
233{
234 struct vmcb_control_area *c, *h;
235 struct nested_state *g;
236
237 mark_dirty(svm->vmcb, VMCB_INTERCEPTS);
238
239 if (!is_guest_mode(&svm->vcpu))
240 return;
241
242 c = &svm->vmcb->control;
243 h = &svm->nested.hsave->control;
244 g = &svm->nested;
245
246 c->intercept_cr = h->intercept_cr | g->intercept_cr;
247 c->intercept_dr = h->intercept_dr | g->intercept_dr;
248 c->intercept_exceptions = h->intercept_exceptions | g->intercept_exceptions;
249 c->intercept = h->intercept | g->intercept;
250}
251
252static inline struct vmcb *get_host_vmcb(struct vcpu_svm *svm)
253{
254 if (is_guest_mode(&svm->vcpu))
255 return svm->nested.hsave;
256 else
257 return svm->vmcb;
258}
259
260static inline void set_cr_intercept(struct vcpu_svm *svm, int bit)
261{
262 struct vmcb *vmcb = get_host_vmcb(svm);
263
264 vmcb->control.intercept_cr |= (1U << bit);
265
266 recalc_intercepts(svm);
267}
268
269static inline void clr_cr_intercept(struct vcpu_svm *svm, int bit)
270{
271 struct vmcb *vmcb = get_host_vmcb(svm);
272
273 vmcb->control.intercept_cr &= ~(1U << bit);
274
275 recalc_intercepts(svm);
276}
277
278static inline bool is_cr_intercept(struct vcpu_svm *svm, int bit)
279{
280 struct vmcb *vmcb = get_host_vmcb(svm);
281
282 return vmcb->control.intercept_cr & (1U << bit);
283}
284
285static inline void set_dr_intercept(struct vcpu_svm *svm, int bit)
286{
287 struct vmcb *vmcb = get_host_vmcb(svm);
288
289 vmcb->control.intercept_dr |= (1U << bit);
290
291 recalc_intercepts(svm);
292}
293
294static inline void clr_dr_intercept(struct vcpu_svm *svm, int bit)
295{
296 struct vmcb *vmcb = get_host_vmcb(svm);
297
298 vmcb->control.intercept_dr &= ~(1U << bit);
299
300 recalc_intercepts(svm);
301}
302
303static inline void set_exception_intercept(struct vcpu_svm *svm, int bit)
304{
305 struct vmcb *vmcb = get_host_vmcb(svm);
306
307 vmcb->control.intercept_exceptions |= (1U << bit);
308
309 recalc_intercepts(svm);
310}
311
312static inline void clr_exception_intercept(struct vcpu_svm *svm, int bit)
189{ 313{
190 return svm->nested.vmcb; 314 struct vmcb *vmcb = get_host_vmcb(svm);
315
316 vmcb->control.intercept_exceptions &= ~(1U << bit);
317
318 recalc_intercepts(svm);
319}
320
321static inline void set_intercept(struct vcpu_svm *svm, int bit)
322{
323 struct vmcb *vmcb = get_host_vmcb(svm);
324
325 vmcb->control.intercept |= (1ULL << bit);
326
327 recalc_intercepts(svm);
328}
329
330static inline void clr_intercept(struct vcpu_svm *svm, int bit)
331{
332 struct vmcb *vmcb = get_host_vmcb(svm);
333
334 vmcb->control.intercept &= ~(1ULL << bit);
335
336 recalc_intercepts(svm);
191} 337}
192 338
193static inline void enable_gif(struct vcpu_svm *svm) 339static inline void enable_gif(struct vcpu_svm *svm)
@@ -264,11 +410,6 @@ static u32 svm_msrpm_offset(u32 msr)
264 410
265#define MAX_INST_SIZE 15 411#define MAX_INST_SIZE 15
266 412
267static inline u32 svm_has(u32 feat)
268{
269 return svm_features & feat;
270}
271
272static inline void clgi(void) 413static inline void clgi(void)
273{ 414{
274 asm volatile (__ex(SVM_CLGI)); 415 asm volatile (__ex(SVM_CLGI));
@@ -284,16 +425,6 @@ static inline void invlpga(unsigned long addr, u32 asid)
284 asm volatile (__ex(SVM_INVLPGA) : : "a"(addr), "c"(asid)); 425 asm volatile (__ex(SVM_INVLPGA) : : "a"(addr), "c"(asid));
285} 426}
286 427
287static inline void force_new_asid(struct kvm_vcpu *vcpu)
288{
289 to_svm(vcpu)->asid_generation--;
290}
291
292static inline void flush_guest_tlb(struct kvm_vcpu *vcpu)
293{
294 force_new_asid(vcpu);
295}
296
297static int get_npt_level(void) 428static int get_npt_level(void)
298{ 429{
299#ifdef CONFIG_X86_64 430#ifdef CONFIG_X86_64
@@ -310,6 +441,7 @@ static void svm_set_efer(struct kvm_vcpu *vcpu, u64 efer)
310 efer &= ~EFER_LME; 441 efer &= ~EFER_LME;
311 442
312 to_svm(vcpu)->vmcb->save.efer = efer | EFER_SVME; 443 to_svm(vcpu)->vmcb->save.efer = efer | EFER_SVME;
444 mark_dirty(to_svm(vcpu)->vmcb, VMCB_CR);
313} 445}
314 446
315static int is_external_interrupt(u32 info) 447static int is_external_interrupt(u32 info)
@@ -347,7 +479,7 @@ static void skip_emulated_instruction(struct kvm_vcpu *vcpu)
347 svm->next_rip = svm->vmcb->control.next_rip; 479 svm->next_rip = svm->vmcb->control.next_rip;
348 480
349 if (!svm->next_rip) { 481 if (!svm->next_rip) {
350 if (emulate_instruction(vcpu, 0, 0, EMULTYPE_SKIP) != 482 if (emulate_instruction(vcpu, EMULTYPE_SKIP) !=
351 EMULATE_DONE) 483 EMULATE_DONE)
352 printk(KERN_DEBUG "%s: NOP\n", __func__); 484 printk(KERN_DEBUG "%s: NOP\n", __func__);
353 return; 485 return;
@@ -374,7 +506,7 @@ static void svm_queue_exception(struct kvm_vcpu *vcpu, unsigned nr,
374 nested_svm_check_exception(svm, nr, has_error_code, error_code)) 506 nested_svm_check_exception(svm, nr, has_error_code, error_code))
375 return; 507 return;
376 508
377 if (nr == BP_VECTOR && !svm_has(SVM_FEATURE_NRIP)) { 509 if (nr == BP_VECTOR && !static_cpu_has(X86_FEATURE_NRIPS)) {
378 unsigned long rip, old_rip = kvm_rip_read(&svm->vcpu); 510 unsigned long rip, old_rip = kvm_rip_read(&svm->vcpu);
379 511
380 /* 512 /*
@@ -670,7 +802,7 @@ static __init int svm_hardware_setup(void)
670 802
671 svm_features = cpuid_edx(SVM_CPUID_FUNC); 803 svm_features = cpuid_edx(SVM_CPUID_FUNC);
672 804
673 if (!svm_has(SVM_FEATURE_NPT)) 805 if (!boot_cpu_has(X86_FEATURE_NPT))
674 npt_enabled = false; 806 npt_enabled = false;
675 807
676 if (npt_enabled && !npt) { 808 if (npt_enabled && !npt) {
@@ -725,13 +857,15 @@ static void svm_write_tsc_offset(struct kvm_vcpu *vcpu, u64 offset)
725 struct vcpu_svm *svm = to_svm(vcpu); 857 struct vcpu_svm *svm = to_svm(vcpu);
726 u64 g_tsc_offset = 0; 858 u64 g_tsc_offset = 0;
727 859
728 if (is_nested(svm)) { 860 if (is_guest_mode(vcpu)) {
729 g_tsc_offset = svm->vmcb->control.tsc_offset - 861 g_tsc_offset = svm->vmcb->control.tsc_offset -
730 svm->nested.hsave->control.tsc_offset; 862 svm->nested.hsave->control.tsc_offset;
731 svm->nested.hsave->control.tsc_offset = offset; 863 svm->nested.hsave->control.tsc_offset = offset;
732 } 864 }
733 865
734 svm->vmcb->control.tsc_offset = offset + g_tsc_offset; 866 svm->vmcb->control.tsc_offset = offset + g_tsc_offset;
867
868 mark_dirty(svm->vmcb, VMCB_INTERCEPTS);
735} 869}
736 870
737static void svm_adjust_tsc_offset(struct kvm_vcpu *vcpu, s64 adjustment) 871static void svm_adjust_tsc_offset(struct kvm_vcpu *vcpu, s64 adjustment)
@@ -739,8 +873,9 @@ static void svm_adjust_tsc_offset(struct kvm_vcpu *vcpu, s64 adjustment)
739 struct vcpu_svm *svm = to_svm(vcpu); 873 struct vcpu_svm *svm = to_svm(vcpu);
740 874
741 svm->vmcb->control.tsc_offset += adjustment; 875 svm->vmcb->control.tsc_offset += adjustment;
742 if (is_nested(svm)) 876 if (is_guest_mode(vcpu))
743 svm->nested.hsave->control.tsc_offset += adjustment; 877 svm->nested.hsave->control.tsc_offset += adjustment;
878 mark_dirty(svm->vmcb, VMCB_INTERCEPTS);
744} 879}
745 880
746static void init_vmcb(struct vcpu_svm *svm) 881static void init_vmcb(struct vcpu_svm *svm)
@@ -749,62 +884,62 @@ static void init_vmcb(struct vcpu_svm *svm)
749 struct vmcb_save_area *save = &svm->vmcb->save; 884 struct vmcb_save_area *save = &svm->vmcb->save;
750 885
751 svm->vcpu.fpu_active = 1; 886 svm->vcpu.fpu_active = 1;
887 svm->vcpu.arch.hflags = 0;
752 888
753 control->intercept_cr_read = INTERCEPT_CR0_MASK | 889 set_cr_intercept(svm, INTERCEPT_CR0_READ);
754 INTERCEPT_CR3_MASK | 890 set_cr_intercept(svm, INTERCEPT_CR3_READ);
755 INTERCEPT_CR4_MASK; 891 set_cr_intercept(svm, INTERCEPT_CR4_READ);
756 892 set_cr_intercept(svm, INTERCEPT_CR0_WRITE);
757 control->intercept_cr_write = INTERCEPT_CR0_MASK | 893 set_cr_intercept(svm, INTERCEPT_CR3_WRITE);
758 INTERCEPT_CR3_MASK | 894 set_cr_intercept(svm, INTERCEPT_CR4_WRITE);
759 INTERCEPT_CR4_MASK | 895 set_cr_intercept(svm, INTERCEPT_CR8_WRITE);
760 INTERCEPT_CR8_MASK; 896
761 897 set_dr_intercept(svm, INTERCEPT_DR0_READ);
762 control->intercept_dr_read = INTERCEPT_DR0_MASK | 898 set_dr_intercept(svm, INTERCEPT_DR1_READ);
763 INTERCEPT_DR1_MASK | 899 set_dr_intercept(svm, INTERCEPT_DR2_READ);
764 INTERCEPT_DR2_MASK | 900 set_dr_intercept(svm, INTERCEPT_DR3_READ);
765 INTERCEPT_DR3_MASK | 901 set_dr_intercept(svm, INTERCEPT_DR4_READ);
766 INTERCEPT_DR4_MASK | 902 set_dr_intercept(svm, INTERCEPT_DR5_READ);
767 INTERCEPT_DR5_MASK | 903 set_dr_intercept(svm, INTERCEPT_DR6_READ);
768 INTERCEPT_DR6_MASK | 904 set_dr_intercept(svm, INTERCEPT_DR7_READ);
769 INTERCEPT_DR7_MASK; 905
770 906 set_dr_intercept(svm, INTERCEPT_DR0_WRITE);
771 control->intercept_dr_write = INTERCEPT_DR0_MASK | 907 set_dr_intercept(svm, INTERCEPT_DR1_WRITE);
772 INTERCEPT_DR1_MASK | 908 set_dr_intercept(svm, INTERCEPT_DR2_WRITE);
773 INTERCEPT_DR2_MASK | 909 set_dr_intercept(svm, INTERCEPT_DR3_WRITE);
774 INTERCEPT_DR3_MASK | 910 set_dr_intercept(svm, INTERCEPT_DR4_WRITE);
775 INTERCEPT_DR4_MASK | 911 set_dr_intercept(svm, INTERCEPT_DR5_WRITE);
776 INTERCEPT_DR5_MASK | 912 set_dr_intercept(svm, INTERCEPT_DR6_WRITE);
777 INTERCEPT_DR6_MASK | 913 set_dr_intercept(svm, INTERCEPT_DR7_WRITE);
778 INTERCEPT_DR7_MASK; 914
779 915 set_exception_intercept(svm, PF_VECTOR);
780 control->intercept_exceptions = (1 << PF_VECTOR) | 916 set_exception_intercept(svm, UD_VECTOR);
781 (1 << UD_VECTOR) | 917 set_exception_intercept(svm, MC_VECTOR);
782 (1 << MC_VECTOR); 918
783 919 set_intercept(svm, INTERCEPT_INTR);
784 920 set_intercept(svm, INTERCEPT_NMI);
785 control->intercept = (1ULL << INTERCEPT_INTR) | 921 set_intercept(svm, INTERCEPT_SMI);
786 (1ULL << INTERCEPT_NMI) | 922 set_intercept(svm, INTERCEPT_SELECTIVE_CR0);
787 (1ULL << INTERCEPT_SMI) | 923 set_intercept(svm, INTERCEPT_CPUID);
788 (1ULL << INTERCEPT_SELECTIVE_CR0) | 924 set_intercept(svm, INTERCEPT_INVD);
789 (1ULL << INTERCEPT_CPUID) | 925 set_intercept(svm, INTERCEPT_HLT);
790 (1ULL << INTERCEPT_INVD) | 926 set_intercept(svm, INTERCEPT_INVLPG);
791 (1ULL << INTERCEPT_HLT) | 927 set_intercept(svm, INTERCEPT_INVLPGA);
792 (1ULL << INTERCEPT_INVLPG) | 928 set_intercept(svm, INTERCEPT_IOIO_PROT);
793 (1ULL << INTERCEPT_INVLPGA) | 929 set_intercept(svm, INTERCEPT_MSR_PROT);
794 (1ULL << INTERCEPT_IOIO_PROT) | 930 set_intercept(svm, INTERCEPT_TASK_SWITCH);
795 (1ULL << INTERCEPT_MSR_PROT) | 931 set_intercept(svm, INTERCEPT_SHUTDOWN);
796 (1ULL << INTERCEPT_TASK_SWITCH) | 932 set_intercept(svm, INTERCEPT_VMRUN);
797 (1ULL << INTERCEPT_SHUTDOWN) | 933 set_intercept(svm, INTERCEPT_VMMCALL);
798 (1ULL << INTERCEPT_VMRUN) | 934 set_intercept(svm, INTERCEPT_VMLOAD);
799 (1ULL << INTERCEPT_VMMCALL) | 935 set_intercept(svm, INTERCEPT_VMSAVE);
800 (1ULL << INTERCEPT_VMLOAD) | 936 set_intercept(svm, INTERCEPT_STGI);
801 (1ULL << INTERCEPT_VMSAVE) | 937 set_intercept(svm, INTERCEPT_CLGI);
802 (1ULL << INTERCEPT_STGI) | 938 set_intercept(svm, INTERCEPT_SKINIT);
803 (1ULL << INTERCEPT_CLGI) | 939 set_intercept(svm, INTERCEPT_WBINVD);
804 (1ULL << INTERCEPT_SKINIT) | 940 set_intercept(svm, INTERCEPT_MONITOR);
805 (1ULL << INTERCEPT_WBINVD) | 941 set_intercept(svm, INTERCEPT_MWAIT);
806 (1ULL << INTERCEPT_MONITOR) | 942 set_intercept(svm, INTERCEPT_XSETBV);
807 (1ULL << INTERCEPT_MWAIT);
808 943
809 control->iopm_base_pa = iopm_base; 944 control->iopm_base_pa = iopm_base;
810 control->msrpm_base_pa = __pa(svm->msrpm); 945 control->msrpm_base_pa = __pa(svm->msrpm);
@@ -855,25 +990,27 @@ static void init_vmcb(struct vcpu_svm *svm)
855 if (npt_enabled) { 990 if (npt_enabled) {
856 /* Setup VMCB for Nested Paging */ 991 /* Setup VMCB for Nested Paging */
857 control->nested_ctl = 1; 992 control->nested_ctl = 1;
858 control->intercept &= ~((1ULL << INTERCEPT_TASK_SWITCH) | 993 clr_intercept(svm, INTERCEPT_TASK_SWITCH);
859 (1ULL << INTERCEPT_INVLPG)); 994 clr_intercept(svm, INTERCEPT_INVLPG);
860 control->intercept_exceptions &= ~(1 << PF_VECTOR); 995 clr_exception_intercept(svm, PF_VECTOR);
861 control->intercept_cr_read &= ~INTERCEPT_CR3_MASK; 996 clr_cr_intercept(svm, INTERCEPT_CR3_READ);
862 control->intercept_cr_write &= ~INTERCEPT_CR3_MASK; 997 clr_cr_intercept(svm, INTERCEPT_CR3_WRITE);
863 save->g_pat = 0x0007040600070406ULL; 998 save->g_pat = 0x0007040600070406ULL;
864 save->cr3 = 0; 999 save->cr3 = 0;
865 save->cr4 = 0; 1000 save->cr4 = 0;
866 } 1001 }
867 force_new_asid(&svm->vcpu); 1002 svm->asid_generation = 0;
868 1003
869 svm->nested.vmcb = 0; 1004 svm->nested.vmcb = 0;
870 svm->vcpu.arch.hflags = 0; 1005 svm->vcpu.arch.hflags = 0;
871 1006
872 if (svm_has(SVM_FEATURE_PAUSE_FILTER)) { 1007 if (boot_cpu_has(X86_FEATURE_PAUSEFILTER)) {
873 control->pause_filter_count = 3000; 1008 control->pause_filter_count = 3000;
874 control->intercept |= (1ULL << INTERCEPT_PAUSE); 1009 set_intercept(svm, INTERCEPT_PAUSE);
875 } 1010 }
876 1011
1012 mark_all_dirty(svm->vmcb);
1013
877 enable_gif(svm); 1014 enable_gif(svm);
878} 1015}
879 1016
@@ -990,8 +1127,16 @@ static void svm_vcpu_load(struct kvm_vcpu *vcpu, int cpu)
990 1127
991 if (unlikely(cpu != vcpu->cpu)) { 1128 if (unlikely(cpu != vcpu->cpu)) {
992 svm->asid_generation = 0; 1129 svm->asid_generation = 0;
1130 mark_all_dirty(svm->vmcb);
993 } 1131 }
994 1132
1133#ifdef CONFIG_X86_64
1134 rdmsrl(MSR_GS_BASE, to_svm(vcpu)->host.gs_base);
1135#endif
1136 savesegment(fs, svm->host.fs);
1137 savesegment(gs, svm->host.gs);
1138 svm->host.ldt = kvm_read_ldt();
1139
995 for (i = 0; i < NR_HOST_SAVE_USER_MSRS; i++) 1140 for (i = 0; i < NR_HOST_SAVE_USER_MSRS; i++)
996 rdmsrl(host_save_user_msrs[i], svm->host_user_msrs[i]); 1141 rdmsrl(host_save_user_msrs[i], svm->host_user_msrs[i]);
997} 1142}
@@ -1002,6 +1147,14 @@ static void svm_vcpu_put(struct kvm_vcpu *vcpu)
1002 int i; 1147 int i;
1003 1148
1004 ++vcpu->stat.host_state_reload; 1149 ++vcpu->stat.host_state_reload;
1150 kvm_load_ldt(svm->host.ldt);
1151#ifdef CONFIG_X86_64
1152 loadsegment(fs, svm->host.fs);
1153 load_gs_index(svm->host.gs);
1154 wrmsrl(MSR_KERNEL_GS_BASE, current->thread.gs);
1155#else
1156 loadsegment(gs, svm->host.gs);
1157#endif
1005 for (i = 0; i < NR_HOST_SAVE_USER_MSRS; i++) 1158 for (i = 0; i < NR_HOST_SAVE_USER_MSRS; i++)
1006 wrmsrl(host_save_user_msrs[i], svm->host_user_msrs[i]); 1159 wrmsrl(host_save_user_msrs[i], svm->host_user_msrs[i]);
1007} 1160}
@@ -1021,7 +1174,7 @@ static void svm_cache_reg(struct kvm_vcpu *vcpu, enum kvm_reg reg)
1021 switch (reg) { 1174 switch (reg) {
1022 case VCPU_EXREG_PDPTR: 1175 case VCPU_EXREG_PDPTR:
1023 BUG_ON(!npt_enabled); 1176 BUG_ON(!npt_enabled);
1024 load_pdptrs(vcpu, vcpu->arch.walk_mmu, vcpu->arch.cr3); 1177 load_pdptrs(vcpu, vcpu->arch.walk_mmu, kvm_read_cr3(vcpu));
1025 break; 1178 break;
1026 default: 1179 default:
1027 BUG(); 1180 BUG();
@@ -1030,12 +1183,12 @@ static void svm_cache_reg(struct kvm_vcpu *vcpu, enum kvm_reg reg)
1030 1183
1031static void svm_set_vintr(struct vcpu_svm *svm) 1184static void svm_set_vintr(struct vcpu_svm *svm)
1032{ 1185{
1033 svm->vmcb->control.intercept |= 1ULL << INTERCEPT_VINTR; 1186 set_intercept(svm, INTERCEPT_VINTR);
1034} 1187}
1035 1188
1036static void svm_clear_vintr(struct vcpu_svm *svm) 1189static void svm_clear_vintr(struct vcpu_svm *svm)
1037{ 1190{
1038 svm->vmcb->control.intercept &= ~(1ULL << INTERCEPT_VINTR); 1191 clr_intercept(svm, INTERCEPT_VINTR);
1039} 1192}
1040 1193
1041static struct vmcb_seg *svm_seg(struct kvm_vcpu *vcpu, int seg) 1194static struct vmcb_seg *svm_seg(struct kvm_vcpu *vcpu, int seg)
@@ -1150,6 +1303,7 @@ static void svm_set_idt(struct kvm_vcpu *vcpu, struct desc_ptr *dt)
1150 1303
1151 svm->vmcb->save.idtr.limit = dt->size; 1304 svm->vmcb->save.idtr.limit = dt->size;
1152 svm->vmcb->save.idtr.base = dt->address ; 1305 svm->vmcb->save.idtr.base = dt->address ;
1306 mark_dirty(svm->vmcb, VMCB_DT);
1153} 1307}
1154 1308
1155static void svm_get_gdt(struct kvm_vcpu *vcpu, struct desc_ptr *dt) 1309static void svm_get_gdt(struct kvm_vcpu *vcpu, struct desc_ptr *dt)
@@ -1166,19 +1320,23 @@ static void svm_set_gdt(struct kvm_vcpu *vcpu, struct desc_ptr *dt)
1166 1320
1167 svm->vmcb->save.gdtr.limit = dt->size; 1321 svm->vmcb->save.gdtr.limit = dt->size;
1168 svm->vmcb->save.gdtr.base = dt->address ; 1322 svm->vmcb->save.gdtr.base = dt->address ;
1323 mark_dirty(svm->vmcb, VMCB_DT);
1169} 1324}
1170 1325
1171static void svm_decache_cr0_guest_bits(struct kvm_vcpu *vcpu) 1326static void svm_decache_cr0_guest_bits(struct kvm_vcpu *vcpu)
1172{ 1327{
1173} 1328}
1174 1329
1330static void svm_decache_cr3(struct kvm_vcpu *vcpu)
1331{
1332}
1333
1175static void svm_decache_cr4_guest_bits(struct kvm_vcpu *vcpu) 1334static void svm_decache_cr4_guest_bits(struct kvm_vcpu *vcpu)
1176{ 1335{
1177} 1336}
1178 1337
1179static void update_cr0_intercept(struct vcpu_svm *svm) 1338static void update_cr0_intercept(struct vcpu_svm *svm)
1180{ 1339{
1181 struct vmcb *vmcb = svm->vmcb;
1182 ulong gcr0 = svm->vcpu.arch.cr0; 1340 ulong gcr0 = svm->vcpu.arch.cr0;
1183 u64 *hcr0 = &svm->vmcb->save.cr0; 1341 u64 *hcr0 = &svm->vmcb->save.cr0;
1184 1342
@@ -1188,27 +1346,14 @@ static void update_cr0_intercept(struct vcpu_svm *svm)
1188 *hcr0 = (*hcr0 & ~SVM_CR0_SELECTIVE_MASK) 1346 *hcr0 = (*hcr0 & ~SVM_CR0_SELECTIVE_MASK)
1189 | (gcr0 & SVM_CR0_SELECTIVE_MASK); 1347 | (gcr0 & SVM_CR0_SELECTIVE_MASK);
1190 1348
1349 mark_dirty(svm->vmcb, VMCB_CR);
1191 1350
1192 if (gcr0 == *hcr0 && svm->vcpu.fpu_active) { 1351 if (gcr0 == *hcr0 && svm->vcpu.fpu_active) {
1193 vmcb->control.intercept_cr_read &= ~INTERCEPT_CR0_MASK; 1352 clr_cr_intercept(svm, INTERCEPT_CR0_READ);
1194 vmcb->control.intercept_cr_write &= ~INTERCEPT_CR0_MASK; 1353 clr_cr_intercept(svm, INTERCEPT_CR0_WRITE);
1195 if (is_nested(svm)) {
1196 struct vmcb *hsave = svm->nested.hsave;
1197
1198 hsave->control.intercept_cr_read &= ~INTERCEPT_CR0_MASK;
1199 hsave->control.intercept_cr_write &= ~INTERCEPT_CR0_MASK;
1200 vmcb->control.intercept_cr_read |= svm->nested.intercept_cr_read;
1201 vmcb->control.intercept_cr_write |= svm->nested.intercept_cr_write;
1202 }
1203 } else { 1354 } else {
1204 svm->vmcb->control.intercept_cr_read |= INTERCEPT_CR0_MASK; 1355 set_cr_intercept(svm, INTERCEPT_CR0_READ);
1205 svm->vmcb->control.intercept_cr_write |= INTERCEPT_CR0_MASK; 1356 set_cr_intercept(svm, INTERCEPT_CR0_WRITE);
1206 if (is_nested(svm)) {
1207 struct vmcb *hsave = svm->nested.hsave;
1208
1209 hsave->control.intercept_cr_read |= INTERCEPT_CR0_MASK;
1210 hsave->control.intercept_cr_write |= INTERCEPT_CR0_MASK;
1211 }
1212 } 1357 }
1213} 1358}
1214 1359
@@ -1216,7 +1361,7 @@ static void svm_set_cr0(struct kvm_vcpu *vcpu, unsigned long cr0)
1216{ 1361{
1217 struct vcpu_svm *svm = to_svm(vcpu); 1362 struct vcpu_svm *svm = to_svm(vcpu);
1218 1363
1219 if (is_nested(svm)) { 1364 if (is_guest_mode(vcpu)) {
1220 /* 1365 /*
1221 * We are here because we run in nested mode, the host kvm 1366 * We are here because we run in nested mode, the host kvm
1222 * intercepts cr0 writes but the l1 hypervisor does not. 1367 * intercepts cr0 writes but the l1 hypervisor does not.
@@ -1268,6 +1413,7 @@ static void svm_set_cr0(struct kvm_vcpu *vcpu, unsigned long cr0)
1268 */ 1413 */
1269 cr0 &= ~(X86_CR0_CD | X86_CR0_NW); 1414 cr0 &= ~(X86_CR0_CD | X86_CR0_NW);
1270 svm->vmcb->save.cr0 = cr0; 1415 svm->vmcb->save.cr0 = cr0;
1416 mark_dirty(svm->vmcb, VMCB_CR);
1271 update_cr0_intercept(svm); 1417 update_cr0_intercept(svm);
1272} 1418}
1273 1419
@@ -1277,13 +1423,14 @@ static void svm_set_cr4(struct kvm_vcpu *vcpu, unsigned long cr4)
1277 unsigned long old_cr4 = to_svm(vcpu)->vmcb->save.cr4; 1423 unsigned long old_cr4 = to_svm(vcpu)->vmcb->save.cr4;
1278 1424
1279 if (npt_enabled && ((old_cr4 ^ cr4) & X86_CR4_PGE)) 1425 if (npt_enabled && ((old_cr4 ^ cr4) & X86_CR4_PGE))
1280 force_new_asid(vcpu); 1426 svm_flush_tlb(vcpu);
1281 1427
1282 vcpu->arch.cr4 = cr4; 1428 vcpu->arch.cr4 = cr4;
1283 if (!npt_enabled) 1429 if (!npt_enabled)
1284 cr4 |= X86_CR4_PAE; 1430 cr4 |= X86_CR4_PAE;
1285 cr4 |= host_cr4_mce; 1431 cr4 |= host_cr4_mce;
1286 to_svm(vcpu)->vmcb->save.cr4 = cr4; 1432 to_svm(vcpu)->vmcb->save.cr4 = cr4;
1433 mark_dirty(to_svm(vcpu)->vmcb, VMCB_CR);
1287} 1434}
1288 1435
1289static void svm_set_segment(struct kvm_vcpu *vcpu, 1436static void svm_set_segment(struct kvm_vcpu *vcpu,
@@ -1312,26 +1459,25 @@ static void svm_set_segment(struct kvm_vcpu *vcpu,
1312 = (svm->vmcb->save.cs.attrib 1459 = (svm->vmcb->save.cs.attrib
1313 >> SVM_SELECTOR_DPL_SHIFT) & 3; 1460 >> SVM_SELECTOR_DPL_SHIFT) & 3;
1314 1461
1462 mark_dirty(svm->vmcb, VMCB_SEG);
1315} 1463}
1316 1464
1317static void update_db_intercept(struct kvm_vcpu *vcpu) 1465static void update_db_intercept(struct kvm_vcpu *vcpu)
1318{ 1466{
1319 struct vcpu_svm *svm = to_svm(vcpu); 1467 struct vcpu_svm *svm = to_svm(vcpu);
1320 1468
1321 svm->vmcb->control.intercept_exceptions &= 1469 clr_exception_intercept(svm, DB_VECTOR);
1322 ~((1 << DB_VECTOR) | (1 << BP_VECTOR)); 1470 clr_exception_intercept(svm, BP_VECTOR);
1323 1471
1324 if (svm->nmi_singlestep) 1472 if (svm->nmi_singlestep)
1325 svm->vmcb->control.intercept_exceptions |= (1 << DB_VECTOR); 1473 set_exception_intercept(svm, DB_VECTOR);
1326 1474
1327 if (vcpu->guest_debug & KVM_GUESTDBG_ENABLE) { 1475 if (vcpu->guest_debug & KVM_GUESTDBG_ENABLE) {
1328 if (vcpu->guest_debug & 1476 if (vcpu->guest_debug &
1329 (KVM_GUESTDBG_SINGLESTEP | KVM_GUESTDBG_USE_HW_BP)) 1477 (KVM_GUESTDBG_SINGLESTEP | KVM_GUESTDBG_USE_HW_BP))
1330 svm->vmcb->control.intercept_exceptions |= 1478 set_exception_intercept(svm, DB_VECTOR);
1331 1 << DB_VECTOR;
1332 if (vcpu->guest_debug & KVM_GUESTDBG_USE_SW_BP) 1479 if (vcpu->guest_debug & KVM_GUESTDBG_USE_SW_BP)
1333 svm->vmcb->control.intercept_exceptions |= 1480 set_exception_intercept(svm, BP_VECTOR);
1334 1 << BP_VECTOR;
1335 } else 1481 } else
1336 vcpu->guest_debug = 0; 1482 vcpu->guest_debug = 0;
1337} 1483}
@@ -1345,21 +1491,9 @@ static void svm_guest_debug(struct kvm_vcpu *vcpu, struct kvm_guest_debug *dbg)
1345 else 1491 else
1346 svm->vmcb->save.dr7 = vcpu->arch.dr7; 1492 svm->vmcb->save.dr7 = vcpu->arch.dr7;
1347 1493
1348 update_db_intercept(vcpu); 1494 mark_dirty(svm->vmcb, VMCB_DR);
1349}
1350
1351static void load_host_msrs(struct kvm_vcpu *vcpu)
1352{
1353#ifdef CONFIG_X86_64
1354 wrmsrl(MSR_GS_BASE, to_svm(vcpu)->host_gs_base);
1355#endif
1356}
1357 1495
1358static void save_host_msrs(struct kvm_vcpu *vcpu) 1496 update_db_intercept(vcpu);
1359{
1360#ifdef CONFIG_X86_64
1361 rdmsrl(MSR_GS_BASE, to_svm(vcpu)->host_gs_base);
1362#endif
1363} 1497}
1364 1498
1365static void new_asid(struct vcpu_svm *svm, struct svm_cpu_data *sd) 1499static void new_asid(struct vcpu_svm *svm, struct svm_cpu_data *sd)
@@ -1372,6 +1506,8 @@ static void new_asid(struct vcpu_svm *svm, struct svm_cpu_data *sd)
1372 1506
1373 svm->asid_generation = sd->asid_generation; 1507 svm->asid_generation = sd->asid_generation;
1374 svm->vmcb->control.asid = sd->next_asid++; 1508 svm->vmcb->control.asid = sd->next_asid++;
1509
1510 mark_dirty(svm->vmcb, VMCB_ASID);
1375} 1511}
1376 1512
1377static void svm_set_dr7(struct kvm_vcpu *vcpu, unsigned long value) 1513static void svm_set_dr7(struct kvm_vcpu *vcpu, unsigned long value)
@@ -1379,20 +1515,40 @@ static void svm_set_dr7(struct kvm_vcpu *vcpu, unsigned long value)
1379 struct vcpu_svm *svm = to_svm(vcpu); 1515 struct vcpu_svm *svm = to_svm(vcpu);
1380 1516
1381 svm->vmcb->save.dr7 = value; 1517 svm->vmcb->save.dr7 = value;
1518 mark_dirty(svm->vmcb, VMCB_DR);
1382} 1519}
1383 1520
1384static int pf_interception(struct vcpu_svm *svm) 1521static int pf_interception(struct vcpu_svm *svm)
1385{ 1522{
1386 u64 fault_address; 1523 u64 fault_address = svm->vmcb->control.exit_info_2;
1387 u32 error_code; 1524 u32 error_code;
1525 int r = 1;
1388 1526
1389 fault_address = svm->vmcb->control.exit_info_2; 1527 switch (svm->apf_reason) {
1390 error_code = svm->vmcb->control.exit_info_1; 1528 default:
1391 1529 error_code = svm->vmcb->control.exit_info_1;
1392 trace_kvm_page_fault(fault_address, error_code); 1530
1393 if (!npt_enabled && kvm_event_needs_reinjection(&svm->vcpu)) 1531 trace_kvm_page_fault(fault_address, error_code);
1394 kvm_mmu_unprotect_page_virt(&svm->vcpu, fault_address); 1532 if (!npt_enabled && kvm_event_needs_reinjection(&svm->vcpu))
1395 return kvm_mmu_page_fault(&svm->vcpu, fault_address, error_code); 1533 kvm_mmu_unprotect_page_virt(&svm->vcpu, fault_address);
1534 r = kvm_mmu_page_fault(&svm->vcpu, fault_address, error_code,
1535 svm->vmcb->control.insn_bytes,
1536 svm->vmcb->control.insn_len);
1537 break;
1538 case KVM_PV_REASON_PAGE_NOT_PRESENT:
1539 svm->apf_reason = 0;
1540 local_irq_disable();
1541 kvm_async_pf_task_wait(fault_address);
1542 local_irq_enable();
1543 break;
1544 case KVM_PV_REASON_PAGE_READY:
1545 svm->apf_reason = 0;
1546 local_irq_disable();
1547 kvm_async_pf_task_wake(fault_address);
1548 local_irq_enable();
1549 break;
1550 }
1551 return r;
1396} 1552}
1397 1553
1398static int db_interception(struct vcpu_svm *svm) 1554static int db_interception(struct vcpu_svm *svm)
@@ -1440,7 +1596,7 @@ static int ud_interception(struct vcpu_svm *svm)
1440{ 1596{
1441 int er; 1597 int er;
1442 1598
1443 er = emulate_instruction(&svm->vcpu, 0, 0, EMULTYPE_TRAP_UD); 1599 er = emulate_instruction(&svm->vcpu, EMULTYPE_TRAP_UD);
1444 if (er != EMULATE_DONE) 1600 if (er != EMULATE_DONE)
1445 kvm_queue_exception(&svm->vcpu, UD_VECTOR); 1601 kvm_queue_exception(&svm->vcpu, UD_VECTOR);
1446 return 1; 1602 return 1;
@@ -1449,21 +1605,8 @@ static int ud_interception(struct vcpu_svm *svm)
1449static void svm_fpu_activate(struct kvm_vcpu *vcpu) 1605static void svm_fpu_activate(struct kvm_vcpu *vcpu)
1450{ 1606{
1451 struct vcpu_svm *svm = to_svm(vcpu); 1607 struct vcpu_svm *svm = to_svm(vcpu);
1452 u32 excp;
1453
1454 if (is_nested(svm)) {
1455 u32 h_excp, n_excp;
1456
1457 h_excp = svm->nested.hsave->control.intercept_exceptions;
1458 n_excp = svm->nested.intercept_exceptions;
1459 h_excp &= ~(1 << NM_VECTOR);
1460 excp = h_excp | n_excp;
1461 } else {
1462 excp = svm->vmcb->control.intercept_exceptions;
1463 excp &= ~(1 << NM_VECTOR);
1464 }
1465 1608
1466 svm->vmcb->control.intercept_exceptions = excp; 1609 clr_exception_intercept(svm, NM_VECTOR);
1467 1610
1468 svm->vcpu.fpu_active = 1; 1611 svm->vcpu.fpu_active = 1;
1469 update_cr0_intercept(svm); 1612 update_cr0_intercept(svm);
@@ -1570,7 +1713,7 @@ static int io_interception(struct vcpu_svm *svm)
1570 string = (io_info & SVM_IOIO_STR_MASK) != 0; 1713 string = (io_info & SVM_IOIO_STR_MASK) != 0;
1571 in = (io_info & SVM_IOIO_TYPE_MASK) != 0; 1714 in = (io_info & SVM_IOIO_TYPE_MASK) != 0;
1572 if (string || in) 1715 if (string || in)
1573 return emulate_instruction(vcpu, 0, 0, 0) == EMULATE_DONE; 1716 return emulate_instruction(vcpu, 0) == EMULATE_DONE;
1574 1717
1575 port = io_info >> 16; 1718 port = io_info >> 16;
1576 size = (io_info & SVM_IOIO_SIZE_MASK) >> SVM_IOIO_SIZE_SHIFT; 1719 size = (io_info & SVM_IOIO_SIZE_MASK) >> SVM_IOIO_SIZE_SHIFT;
@@ -1624,17 +1767,19 @@ static void nested_svm_set_tdp_cr3(struct kvm_vcpu *vcpu,
1624 struct vcpu_svm *svm = to_svm(vcpu); 1767 struct vcpu_svm *svm = to_svm(vcpu);
1625 1768
1626 svm->vmcb->control.nested_cr3 = root; 1769 svm->vmcb->control.nested_cr3 = root;
1627 force_new_asid(vcpu); 1770 mark_dirty(svm->vmcb, VMCB_NPT);
1771 svm_flush_tlb(vcpu);
1628} 1772}
1629 1773
1630static void nested_svm_inject_npf_exit(struct kvm_vcpu *vcpu) 1774static void nested_svm_inject_npf_exit(struct kvm_vcpu *vcpu,
1775 struct x86_exception *fault)
1631{ 1776{
1632 struct vcpu_svm *svm = to_svm(vcpu); 1777 struct vcpu_svm *svm = to_svm(vcpu);
1633 1778
1634 svm->vmcb->control.exit_code = SVM_EXIT_NPF; 1779 svm->vmcb->control.exit_code = SVM_EXIT_NPF;
1635 svm->vmcb->control.exit_code_hi = 0; 1780 svm->vmcb->control.exit_code_hi = 0;
1636 svm->vmcb->control.exit_info_1 = vcpu->arch.fault.error_code; 1781 svm->vmcb->control.exit_info_1 = fault->error_code;
1637 svm->vmcb->control.exit_info_2 = vcpu->arch.fault.address; 1782 svm->vmcb->control.exit_info_2 = fault->address;
1638 1783
1639 nested_svm_vmexit(svm); 1784 nested_svm_vmexit(svm);
1640} 1785}
@@ -1680,7 +1825,7 @@ static int nested_svm_check_exception(struct vcpu_svm *svm, unsigned nr,
1680{ 1825{
1681 int vmexit; 1826 int vmexit;
1682 1827
1683 if (!is_nested(svm)) 1828 if (!is_guest_mode(&svm->vcpu))
1684 return 0; 1829 return 0;
1685 1830
1686 svm->vmcb->control.exit_code = SVM_EXIT_EXCP_BASE + nr; 1831 svm->vmcb->control.exit_code = SVM_EXIT_EXCP_BASE + nr;
@@ -1698,7 +1843,7 @@ static int nested_svm_check_exception(struct vcpu_svm *svm, unsigned nr,
1698/* This function returns true if it is save to enable the irq window */ 1843/* This function returns true if it is save to enable the irq window */
1699static inline bool nested_svm_intr(struct vcpu_svm *svm) 1844static inline bool nested_svm_intr(struct vcpu_svm *svm)
1700{ 1845{
1701 if (!is_nested(svm)) 1846 if (!is_guest_mode(&svm->vcpu))
1702 return true; 1847 return true;
1703 1848
1704 if (!(svm->vcpu.arch.hflags & HF_VINTR_MASK)) 1849 if (!(svm->vcpu.arch.hflags & HF_VINTR_MASK))
@@ -1737,7 +1882,7 @@ static inline bool nested_svm_intr(struct vcpu_svm *svm)
1737/* This function returns true if it is save to enable the nmi window */ 1882/* This function returns true if it is save to enable the nmi window */
1738static inline bool nested_svm_nmi(struct vcpu_svm *svm) 1883static inline bool nested_svm_nmi(struct vcpu_svm *svm)
1739{ 1884{
1740 if (!is_nested(svm)) 1885 if (!is_guest_mode(&svm->vcpu))
1741 return true; 1886 return true;
1742 1887
1743 if (!(svm->nested.intercept & (1ULL << INTERCEPT_NMI))) 1888 if (!(svm->nested.intercept & (1ULL << INTERCEPT_NMI)))
@@ -1836,8 +1981,8 @@ static int nested_svm_exit_special(struct vcpu_svm *svm)
1836 return NESTED_EXIT_HOST; 1981 return NESTED_EXIT_HOST;
1837 break; 1982 break;
1838 case SVM_EXIT_EXCP_BASE + PF_VECTOR: 1983 case SVM_EXIT_EXCP_BASE + PF_VECTOR:
1839 /* When we're shadowing, trap PFs */ 1984 /* When we're shadowing, trap PFs, but not async PF */
1840 if (!npt_enabled) 1985 if (!npt_enabled && svm->apf_reason == 0)
1841 return NESTED_EXIT_HOST; 1986 return NESTED_EXIT_HOST;
1842 break; 1987 break;
1843 case SVM_EXIT_EXCP_BASE + NM_VECTOR: 1988 case SVM_EXIT_EXCP_BASE + NM_VECTOR:
@@ -1865,27 +2010,15 @@ static int nested_svm_intercept(struct vcpu_svm *svm)
1865 case SVM_EXIT_IOIO: 2010 case SVM_EXIT_IOIO:
1866 vmexit = nested_svm_intercept_ioio(svm); 2011 vmexit = nested_svm_intercept_ioio(svm);
1867 break; 2012 break;
1868 case SVM_EXIT_READ_CR0 ... SVM_EXIT_READ_CR8: { 2013 case SVM_EXIT_READ_CR0 ... SVM_EXIT_WRITE_CR8: {
1869 u32 cr_bits = 1 << (exit_code - SVM_EXIT_READ_CR0); 2014 u32 bit = 1U << (exit_code - SVM_EXIT_READ_CR0);
1870 if (svm->nested.intercept_cr_read & cr_bits) 2015 if (svm->nested.intercept_cr & bit)
1871 vmexit = NESTED_EXIT_DONE; 2016 vmexit = NESTED_EXIT_DONE;
1872 break; 2017 break;
1873 } 2018 }
1874 case SVM_EXIT_WRITE_CR0 ... SVM_EXIT_WRITE_CR8: { 2019 case SVM_EXIT_READ_DR0 ... SVM_EXIT_WRITE_DR7: {
1875 u32 cr_bits = 1 << (exit_code - SVM_EXIT_WRITE_CR0); 2020 u32 bit = 1U << (exit_code - SVM_EXIT_READ_DR0);
1876 if (svm->nested.intercept_cr_write & cr_bits) 2021 if (svm->nested.intercept_dr & bit)
1877 vmexit = NESTED_EXIT_DONE;
1878 break;
1879 }
1880 case SVM_EXIT_READ_DR0 ... SVM_EXIT_READ_DR7: {
1881 u32 dr_bits = 1 << (exit_code - SVM_EXIT_READ_DR0);
1882 if (svm->nested.intercept_dr_read & dr_bits)
1883 vmexit = NESTED_EXIT_DONE;
1884 break;
1885 }
1886 case SVM_EXIT_WRITE_DR0 ... SVM_EXIT_WRITE_DR7: {
1887 u32 dr_bits = 1 << (exit_code - SVM_EXIT_WRITE_DR0);
1888 if (svm->nested.intercept_dr_write & dr_bits)
1889 vmexit = NESTED_EXIT_DONE; 2022 vmexit = NESTED_EXIT_DONE;
1890 break; 2023 break;
1891 } 2024 }
@@ -1893,6 +2026,10 @@ static int nested_svm_intercept(struct vcpu_svm *svm)
1893 u32 excp_bits = 1 << (exit_code - SVM_EXIT_EXCP_BASE); 2026 u32 excp_bits = 1 << (exit_code - SVM_EXIT_EXCP_BASE);
1894 if (svm->nested.intercept_exceptions & excp_bits) 2027 if (svm->nested.intercept_exceptions & excp_bits)
1895 vmexit = NESTED_EXIT_DONE; 2028 vmexit = NESTED_EXIT_DONE;
2029 /* async page fault always cause vmexit */
2030 else if ((exit_code == SVM_EXIT_EXCP_BASE + PF_VECTOR) &&
2031 svm->apf_reason != 0)
2032 vmexit = NESTED_EXIT_DONE;
1896 break; 2033 break;
1897 } 2034 }
1898 case SVM_EXIT_ERR: { 2035 case SVM_EXIT_ERR: {
@@ -1926,10 +2063,8 @@ static inline void copy_vmcb_control_area(struct vmcb *dst_vmcb, struct vmcb *fr
1926 struct vmcb_control_area *dst = &dst_vmcb->control; 2063 struct vmcb_control_area *dst = &dst_vmcb->control;
1927 struct vmcb_control_area *from = &from_vmcb->control; 2064 struct vmcb_control_area *from = &from_vmcb->control;
1928 2065
1929 dst->intercept_cr_read = from->intercept_cr_read; 2066 dst->intercept_cr = from->intercept_cr;
1930 dst->intercept_cr_write = from->intercept_cr_write; 2067 dst->intercept_dr = from->intercept_dr;
1931 dst->intercept_dr_read = from->intercept_dr_read;
1932 dst->intercept_dr_write = from->intercept_dr_write;
1933 dst->intercept_exceptions = from->intercept_exceptions; 2068 dst->intercept_exceptions = from->intercept_exceptions;
1934 dst->intercept = from->intercept; 2069 dst->intercept = from->intercept;
1935 dst->iopm_base_pa = from->iopm_base_pa; 2070 dst->iopm_base_pa = from->iopm_base_pa;
@@ -1970,7 +2105,8 @@ static int nested_svm_vmexit(struct vcpu_svm *svm)
1970 if (!nested_vmcb) 2105 if (!nested_vmcb)
1971 return 1; 2106 return 1;
1972 2107
1973 /* Exit nested SVM mode */ 2108 /* Exit Guest-Mode */
2109 leave_guest_mode(&svm->vcpu);
1974 svm->nested.vmcb = 0; 2110 svm->nested.vmcb = 0;
1975 2111
1976 /* Give the current vmcb to the guest */ 2112 /* Give the current vmcb to the guest */
@@ -1984,7 +2120,7 @@ static int nested_svm_vmexit(struct vcpu_svm *svm)
1984 nested_vmcb->save.idtr = vmcb->save.idtr; 2120 nested_vmcb->save.idtr = vmcb->save.idtr;
1985 nested_vmcb->save.efer = svm->vcpu.arch.efer; 2121 nested_vmcb->save.efer = svm->vcpu.arch.efer;
1986 nested_vmcb->save.cr0 = kvm_read_cr0(&svm->vcpu); 2122 nested_vmcb->save.cr0 = kvm_read_cr0(&svm->vcpu);
1987 nested_vmcb->save.cr3 = svm->vcpu.arch.cr3; 2123 nested_vmcb->save.cr3 = kvm_read_cr3(&svm->vcpu);
1988 nested_vmcb->save.cr2 = vmcb->save.cr2; 2124 nested_vmcb->save.cr2 = vmcb->save.cr2;
1989 nested_vmcb->save.cr4 = svm->vcpu.arch.cr4; 2125 nested_vmcb->save.cr4 = svm->vcpu.arch.cr4;
1990 nested_vmcb->save.rflags = vmcb->save.rflags; 2126 nested_vmcb->save.rflags = vmcb->save.rflags;
@@ -2061,6 +2197,8 @@ static int nested_svm_vmexit(struct vcpu_svm *svm)
2061 svm->vmcb->save.cpl = 0; 2197 svm->vmcb->save.cpl = 0;
2062 svm->vmcb->control.exit_int_info = 0; 2198 svm->vmcb->control.exit_int_info = 0;
2063 2199
2200 mark_all_dirty(svm->vmcb);
2201
2064 nested_svm_unmap(page); 2202 nested_svm_unmap(page);
2065 2203
2066 nested_svm_uninit_mmu_context(&svm->vcpu); 2204 nested_svm_uninit_mmu_context(&svm->vcpu);
@@ -2148,8 +2286,8 @@ static bool nested_svm_vmrun(struct vcpu_svm *svm)
2148 nested_vmcb->control.event_inj, 2286 nested_vmcb->control.event_inj,
2149 nested_vmcb->control.nested_ctl); 2287 nested_vmcb->control.nested_ctl);
2150 2288
2151 trace_kvm_nested_intercepts(nested_vmcb->control.intercept_cr_read, 2289 trace_kvm_nested_intercepts(nested_vmcb->control.intercept_cr & 0xffff,
2152 nested_vmcb->control.intercept_cr_write, 2290 nested_vmcb->control.intercept_cr >> 16,
2153 nested_vmcb->control.intercept_exceptions, 2291 nested_vmcb->control.intercept_exceptions,
2154 nested_vmcb->control.intercept); 2292 nested_vmcb->control.intercept);
2155 2293
@@ -2177,7 +2315,7 @@ static bool nested_svm_vmrun(struct vcpu_svm *svm)
2177 if (npt_enabled) 2315 if (npt_enabled)
2178 hsave->save.cr3 = vmcb->save.cr3; 2316 hsave->save.cr3 = vmcb->save.cr3;
2179 else 2317 else
2180 hsave->save.cr3 = svm->vcpu.arch.cr3; 2318 hsave->save.cr3 = kvm_read_cr3(&svm->vcpu);
2181 2319
2182 copy_vmcb_control_area(hsave, vmcb); 2320 copy_vmcb_control_area(hsave, vmcb);
2183 2321
@@ -2229,14 +2367,12 @@ static bool nested_svm_vmrun(struct vcpu_svm *svm)
2229 svm->nested.vmcb_iopm = nested_vmcb->control.iopm_base_pa & ~0x0fffULL; 2367 svm->nested.vmcb_iopm = nested_vmcb->control.iopm_base_pa & ~0x0fffULL;
2230 2368
2231 /* cache intercepts */ 2369 /* cache intercepts */
2232 svm->nested.intercept_cr_read = nested_vmcb->control.intercept_cr_read; 2370 svm->nested.intercept_cr = nested_vmcb->control.intercept_cr;
2233 svm->nested.intercept_cr_write = nested_vmcb->control.intercept_cr_write; 2371 svm->nested.intercept_dr = nested_vmcb->control.intercept_dr;
2234 svm->nested.intercept_dr_read = nested_vmcb->control.intercept_dr_read;
2235 svm->nested.intercept_dr_write = nested_vmcb->control.intercept_dr_write;
2236 svm->nested.intercept_exceptions = nested_vmcb->control.intercept_exceptions; 2372 svm->nested.intercept_exceptions = nested_vmcb->control.intercept_exceptions;
2237 svm->nested.intercept = nested_vmcb->control.intercept; 2373 svm->nested.intercept = nested_vmcb->control.intercept;
2238 2374
2239 force_new_asid(&svm->vcpu); 2375 svm_flush_tlb(&svm->vcpu);
2240 svm->vmcb->control.int_ctl = nested_vmcb->control.int_ctl | V_INTR_MASKING_MASK; 2376 svm->vmcb->control.int_ctl = nested_vmcb->control.int_ctl | V_INTR_MASKING_MASK;
2241 if (nested_vmcb->control.int_ctl & V_INTR_MASKING_MASK) 2377 if (nested_vmcb->control.int_ctl & V_INTR_MASKING_MASK)
2242 svm->vcpu.arch.hflags |= HF_VINTR_MASK; 2378 svm->vcpu.arch.hflags |= HF_VINTR_MASK;
@@ -2245,29 +2381,12 @@ static bool nested_svm_vmrun(struct vcpu_svm *svm)
2245 2381
2246 if (svm->vcpu.arch.hflags & HF_VINTR_MASK) { 2382 if (svm->vcpu.arch.hflags & HF_VINTR_MASK) {
2247 /* We only want the cr8 intercept bits of the guest */ 2383 /* We only want the cr8 intercept bits of the guest */
2248 svm->vmcb->control.intercept_cr_read &= ~INTERCEPT_CR8_MASK; 2384 clr_cr_intercept(svm, INTERCEPT_CR8_READ);
2249 svm->vmcb->control.intercept_cr_write &= ~INTERCEPT_CR8_MASK; 2385 clr_cr_intercept(svm, INTERCEPT_CR8_WRITE);
2250 } 2386 }
2251 2387
2252 /* We don't want to see VMMCALLs from a nested guest */ 2388 /* We don't want to see VMMCALLs from a nested guest */
2253 svm->vmcb->control.intercept &= ~(1ULL << INTERCEPT_VMMCALL); 2389 clr_intercept(svm, INTERCEPT_VMMCALL);
2254
2255 /*
2256 * We don't want a nested guest to be more powerful than the guest, so
2257 * all intercepts are ORed
2258 */
2259 svm->vmcb->control.intercept_cr_read |=
2260 nested_vmcb->control.intercept_cr_read;
2261 svm->vmcb->control.intercept_cr_write |=
2262 nested_vmcb->control.intercept_cr_write;
2263 svm->vmcb->control.intercept_dr_read |=
2264 nested_vmcb->control.intercept_dr_read;
2265 svm->vmcb->control.intercept_dr_write |=
2266 nested_vmcb->control.intercept_dr_write;
2267 svm->vmcb->control.intercept_exceptions |=
2268 nested_vmcb->control.intercept_exceptions;
2269
2270 svm->vmcb->control.intercept |= nested_vmcb->control.intercept;
2271 2390
2272 svm->vmcb->control.lbr_ctl = nested_vmcb->control.lbr_ctl; 2391 svm->vmcb->control.lbr_ctl = nested_vmcb->control.lbr_ctl;
2273 svm->vmcb->control.int_vector = nested_vmcb->control.int_vector; 2392 svm->vmcb->control.int_vector = nested_vmcb->control.int_vector;
@@ -2278,11 +2397,21 @@ static bool nested_svm_vmrun(struct vcpu_svm *svm)
2278 2397
2279 nested_svm_unmap(page); 2398 nested_svm_unmap(page);
2280 2399
2281 /* nested_vmcb is our indicator if nested SVM is activated */ 2400 /* Enter Guest-Mode */
2401 enter_guest_mode(&svm->vcpu);
2402
2403 /*
2404 * Merge guest and host intercepts - must be called with vcpu in
2405 * guest-mode to take affect here
2406 */
2407 recalc_intercepts(svm);
2408
2282 svm->nested.vmcb = vmcb_gpa; 2409 svm->nested.vmcb = vmcb_gpa;
2283 2410
2284 enable_gif(svm); 2411 enable_gif(svm);
2285 2412
2413 mark_all_dirty(svm->vmcb);
2414
2286 return true; 2415 return true;
2287} 2416}
2288 2417
@@ -2400,6 +2529,8 @@ static int clgi_interception(struct vcpu_svm *svm)
2400 svm_clear_vintr(svm); 2529 svm_clear_vintr(svm);
2401 svm->vmcb->control.int_ctl &= ~V_IRQ_MASK; 2530 svm->vmcb->control.int_ctl &= ~V_IRQ_MASK;
2402 2531
2532 mark_dirty(svm->vmcb, VMCB_INTR);
2533
2403 return 1; 2534 return 1;
2404} 2535}
2405 2536
@@ -2426,6 +2557,19 @@ static int skinit_interception(struct vcpu_svm *svm)
2426 return 1; 2557 return 1;
2427} 2558}
2428 2559
2560static int xsetbv_interception(struct vcpu_svm *svm)
2561{
2562 u64 new_bv = kvm_read_edx_eax(&svm->vcpu);
2563 u32 index = kvm_register_read(&svm->vcpu, VCPU_REGS_RCX);
2564
2565 if (kvm_set_xcr(&svm->vcpu, index, new_bv) == 0) {
2566 svm->next_rip = kvm_rip_read(&svm->vcpu) + 3;
2567 skip_emulated_instruction(&svm->vcpu);
2568 }
2569
2570 return 1;
2571}
2572
2429static int invalid_op_interception(struct vcpu_svm *svm) 2573static int invalid_op_interception(struct vcpu_svm *svm)
2430{ 2574{
2431 kvm_queue_exception(&svm->vcpu, UD_VECTOR); 2575 kvm_queue_exception(&svm->vcpu, UD_VECTOR);
@@ -2507,19 +2651,92 @@ static int cpuid_interception(struct vcpu_svm *svm)
2507static int iret_interception(struct vcpu_svm *svm) 2651static int iret_interception(struct vcpu_svm *svm)
2508{ 2652{
2509 ++svm->vcpu.stat.nmi_window_exits; 2653 ++svm->vcpu.stat.nmi_window_exits;
2510 svm->vmcb->control.intercept &= ~(1ULL << INTERCEPT_IRET); 2654 clr_intercept(svm, INTERCEPT_IRET);
2511 svm->vcpu.arch.hflags |= HF_IRET_MASK; 2655 svm->vcpu.arch.hflags |= HF_IRET_MASK;
2512 return 1; 2656 return 1;
2513} 2657}
2514 2658
2515static int invlpg_interception(struct vcpu_svm *svm) 2659static int invlpg_interception(struct vcpu_svm *svm)
2516{ 2660{
2517 return emulate_instruction(&svm->vcpu, 0, 0, 0) == EMULATE_DONE; 2661 if (!static_cpu_has(X86_FEATURE_DECODEASSISTS))
2662 return emulate_instruction(&svm->vcpu, 0) == EMULATE_DONE;
2663
2664 kvm_mmu_invlpg(&svm->vcpu, svm->vmcb->control.exit_info_1);
2665 skip_emulated_instruction(&svm->vcpu);
2666 return 1;
2518} 2667}
2519 2668
2520static int emulate_on_interception(struct vcpu_svm *svm) 2669static int emulate_on_interception(struct vcpu_svm *svm)
2521{ 2670{
2522 return emulate_instruction(&svm->vcpu, 0, 0, 0) == EMULATE_DONE; 2671 return emulate_instruction(&svm->vcpu, 0) == EMULATE_DONE;
2672}
2673
2674#define CR_VALID (1ULL << 63)
2675
2676static int cr_interception(struct vcpu_svm *svm)
2677{
2678 int reg, cr;
2679 unsigned long val;
2680 int err;
2681
2682 if (!static_cpu_has(X86_FEATURE_DECODEASSISTS))
2683 return emulate_on_interception(svm);
2684
2685 if (unlikely((svm->vmcb->control.exit_info_1 & CR_VALID) == 0))
2686 return emulate_on_interception(svm);
2687
2688 reg = svm->vmcb->control.exit_info_1 & SVM_EXITINFO_REG_MASK;
2689 cr = svm->vmcb->control.exit_code - SVM_EXIT_READ_CR0;
2690
2691 err = 0;
2692 if (cr >= 16) { /* mov to cr */
2693 cr -= 16;
2694 val = kvm_register_read(&svm->vcpu, reg);
2695 switch (cr) {
2696 case 0:
2697 err = kvm_set_cr0(&svm->vcpu, val);
2698 break;
2699 case 3:
2700 err = kvm_set_cr3(&svm->vcpu, val);
2701 break;
2702 case 4:
2703 err = kvm_set_cr4(&svm->vcpu, val);
2704 break;
2705 case 8:
2706 err = kvm_set_cr8(&svm->vcpu, val);
2707 break;
2708 default:
2709 WARN(1, "unhandled write to CR%d", cr);
2710 kvm_queue_exception(&svm->vcpu, UD_VECTOR);
2711 return 1;
2712 }
2713 } else { /* mov from cr */
2714 switch (cr) {
2715 case 0:
2716 val = kvm_read_cr0(&svm->vcpu);
2717 break;
2718 case 2:
2719 val = svm->vcpu.arch.cr2;
2720 break;
2721 case 3:
2722 val = kvm_read_cr3(&svm->vcpu);
2723 break;
2724 case 4:
2725 val = kvm_read_cr4(&svm->vcpu);
2726 break;
2727 case 8:
2728 val = kvm_get_cr8(&svm->vcpu);
2729 break;
2730 default:
2731 WARN(1, "unhandled read from CR%d", cr);
2732 kvm_queue_exception(&svm->vcpu, UD_VECTOR);
2733 return 1;
2734 }
2735 kvm_register_write(&svm->vcpu, reg, val);
2736 }
2737 kvm_complete_insn_gp(&svm->vcpu, err);
2738
2739 return 1;
2523} 2740}
2524 2741
2525static int cr0_write_interception(struct vcpu_svm *svm) 2742static int cr0_write_interception(struct vcpu_svm *svm)
@@ -2527,7 +2744,7 @@ static int cr0_write_interception(struct vcpu_svm *svm)
2527 struct kvm_vcpu *vcpu = &svm->vcpu; 2744 struct kvm_vcpu *vcpu = &svm->vcpu;
2528 int r; 2745 int r;
2529 2746
2530 r = emulate_instruction(&svm->vcpu, 0, 0, 0); 2747 r = cr_interception(svm);
2531 2748
2532 if (svm->nested.vmexit_rip) { 2749 if (svm->nested.vmexit_rip) {
2533 kvm_register_write(vcpu, VCPU_REGS_RIP, svm->nested.vmexit_rip); 2750 kvm_register_write(vcpu, VCPU_REGS_RIP, svm->nested.vmexit_rip);
@@ -2536,22 +2753,47 @@ static int cr0_write_interception(struct vcpu_svm *svm)
2536 svm->nested.vmexit_rip = 0; 2753 svm->nested.vmexit_rip = 0;
2537 } 2754 }
2538 2755
2539 return r == EMULATE_DONE; 2756 return r;
2757}
2758
2759static int dr_interception(struct vcpu_svm *svm)
2760{
2761 int reg, dr;
2762 unsigned long val;
2763 int err;
2764
2765 if (!boot_cpu_has(X86_FEATURE_DECODEASSISTS))
2766 return emulate_on_interception(svm);
2767
2768 reg = svm->vmcb->control.exit_info_1 & SVM_EXITINFO_REG_MASK;
2769 dr = svm->vmcb->control.exit_code - SVM_EXIT_READ_DR0;
2770
2771 if (dr >= 16) { /* mov to DRn */
2772 val = kvm_register_read(&svm->vcpu, reg);
2773 kvm_set_dr(&svm->vcpu, dr - 16, val);
2774 } else {
2775 err = kvm_get_dr(&svm->vcpu, dr, &val);
2776 if (!err)
2777 kvm_register_write(&svm->vcpu, reg, val);
2778 }
2779
2780 return 1;
2540} 2781}
2541 2782
2542static int cr8_write_interception(struct vcpu_svm *svm) 2783static int cr8_write_interception(struct vcpu_svm *svm)
2543{ 2784{
2544 struct kvm_run *kvm_run = svm->vcpu.run; 2785 struct kvm_run *kvm_run = svm->vcpu.run;
2786 int r;
2545 2787
2546 u8 cr8_prev = kvm_get_cr8(&svm->vcpu); 2788 u8 cr8_prev = kvm_get_cr8(&svm->vcpu);
2547 /* instruction emulation calls kvm_set_cr8() */ 2789 /* instruction emulation calls kvm_set_cr8() */
2548 emulate_instruction(&svm->vcpu, 0, 0, 0); 2790 r = cr_interception(svm);
2549 if (irqchip_in_kernel(svm->vcpu.kvm)) { 2791 if (irqchip_in_kernel(svm->vcpu.kvm)) {
2550 svm->vmcb->control.intercept_cr_write &= ~INTERCEPT_CR8_MASK; 2792 clr_cr_intercept(svm, INTERCEPT_CR8_WRITE);
2551 return 1; 2793 return r;
2552 } 2794 }
2553 if (cr8_prev <= kvm_get_cr8(&svm->vcpu)) 2795 if (cr8_prev <= kvm_get_cr8(&svm->vcpu))
2554 return 1; 2796 return r;
2555 kvm_run->exit_reason = KVM_EXIT_SET_TPR; 2797 kvm_run->exit_reason = KVM_EXIT_SET_TPR;
2556 return 0; 2798 return 0;
2557} 2799}
@@ -2562,14 +2804,9 @@ static int svm_get_msr(struct kvm_vcpu *vcpu, unsigned ecx, u64 *data)
2562 2804
2563 switch (ecx) { 2805 switch (ecx) {
2564 case MSR_IA32_TSC: { 2806 case MSR_IA32_TSC: {
2565 u64 tsc_offset; 2807 struct vmcb *vmcb = get_host_vmcb(svm);
2566 2808
2567 if (is_nested(svm)) 2809 *data = vmcb->control.tsc_offset + native_read_tsc();
2568 tsc_offset = svm->nested.hsave->control.tsc_offset;
2569 else
2570 tsc_offset = svm->vmcb->control.tsc_offset;
2571
2572 *data = tsc_offset + native_read_tsc();
2573 break; 2810 break;
2574 } 2811 }
2575 case MSR_STAR: 2812 case MSR_STAR:
@@ -2714,7 +2951,7 @@ static int svm_set_msr(struct kvm_vcpu *vcpu, unsigned ecx, u64 data)
2714 svm->vmcb->save.sysenter_esp = data; 2951 svm->vmcb->save.sysenter_esp = data;
2715 break; 2952 break;
2716 case MSR_IA32_DEBUGCTLMSR: 2953 case MSR_IA32_DEBUGCTLMSR:
2717 if (!svm_has(SVM_FEATURE_LBRV)) { 2954 if (!boot_cpu_has(X86_FEATURE_LBRV)) {
2718 pr_unimpl(vcpu, "%s: MSR_IA32_DEBUGCTL 0x%llx, nop\n", 2955 pr_unimpl(vcpu, "%s: MSR_IA32_DEBUGCTL 0x%llx, nop\n",
2719 __func__, data); 2956 __func__, data);
2720 break; 2957 break;
@@ -2723,6 +2960,7 @@ static int svm_set_msr(struct kvm_vcpu *vcpu, unsigned ecx, u64 data)
2723 return 1; 2960 return 1;
2724 2961
2725 svm->vmcb->save.dbgctl = data; 2962 svm->vmcb->save.dbgctl = data;
2963 mark_dirty(svm->vmcb, VMCB_LBR);
2726 if (data & (1ULL<<0)) 2964 if (data & (1ULL<<0))
2727 svm_enable_lbrv(svm); 2965 svm_enable_lbrv(svm);
2728 else 2966 else
@@ -2775,6 +3013,7 @@ static int interrupt_window_interception(struct vcpu_svm *svm)
2775 kvm_make_request(KVM_REQ_EVENT, &svm->vcpu); 3013 kvm_make_request(KVM_REQ_EVENT, &svm->vcpu);
2776 svm_clear_vintr(svm); 3014 svm_clear_vintr(svm);
2777 svm->vmcb->control.int_ctl &= ~V_IRQ_MASK; 3015 svm->vmcb->control.int_ctl &= ~V_IRQ_MASK;
3016 mark_dirty(svm->vmcb, VMCB_INTR);
2778 /* 3017 /*
2779 * If the user space waits to inject interrupts, exit as soon as 3018 * If the user space waits to inject interrupts, exit as soon as
2780 * possible 3019 * possible
@@ -2797,31 +3036,31 @@ static int pause_interception(struct vcpu_svm *svm)
2797} 3036}
2798 3037
2799static int (*svm_exit_handlers[])(struct vcpu_svm *svm) = { 3038static int (*svm_exit_handlers[])(struct vcpu_svm *svm) = {
2800 [SVM_EXIT_READ_CR0] = emulate_on_interception, 3039 [SVM_EXIT_READ_CR0] = cr_interception,
2801 [SVM_EXIT_READ_CR3] = emulate_on_interception, 3040 [SVM_EXIT_READ_CR3] = cr_interception,
2802 [SVM_EXIT_READ_CR4] = emulate_on_interception, 3041 [SVM_EXIT_READ_CR4] = cr_interception,
2803 [SVM_EXIT_READ_CR8] = emulate_on_interception, 3042 [SVM_EXIT_READ_CR8] = cr_interception,
2804 [SVM_EXIT_CR0_SEL_WRITE] = emulate_on_interception, 3043 [SVM_EXIT_CR0_SEL_WRITE] = emulate_on_interception,
2805 [SVM_EXIT_WRITE_CR0] = cr0_write_interception, 3044 [SVM_EXIT_WRITE_CR0] = cr0_write_interception,
2806 [SVM_EXIT_WRITE_CR3] = emulate_on_interception, 3045 [SVM_EXIT_WRITE_CR3] = cr_interception,
2807 [SVM_EXIT_WRITE_CR4] = emulate_on_interception, 3046 [SVM_EXIT_WRITE_CR4] = cr_interception,
2808 [SVM_EXIT_WRITE_CR8] = cr8_write_interception, 3047 [SVM_EXIT_WRITE_CR8] = cr8_write_interception,
2809 [SVM_EXIT_READ_DR0] = emulate_on_interception, 3048 [SVM_EXIT_READ_DR0] = dr_interception,
2810 [SVM_EXIT_READ_DR1] = emulate_on_interception, 3049 [SVM_EXIT_READ_DR1] = dr_interception,
2811 [SVM_EXIT_READ_DR2] = emulate_on_interception, 3050 [SVM_EXIT_READ_DR2] = dr_interception,
2812 [SVM_EXIT_READ_DR3] = emulate_on_interception, 3051 [SVM_EXIT_READ_DR3] = dr_interception,
2813 [SVM_EXIT_READ_DR4] = emulate_on_interception, 3052 [SVM_EXIT_READ_DR4] = dr_interception,
2814 [SVM_EXIT_READ_DR5] = emulate_on_interception, 3053 [SVM_EXIT_READ_DR5] = dr_interception,
2815 [SVM_EXIT_READ_DR6] = emulate_on_interception, 3054 [SVM_EXIT_READ_DR6] = dr_interception,
2816 [SVM_EXIT_READ_DR7] = emulate_on_interception, 3055 [SVM_EXIT_READ_DR7] = dr_interception,
2817 [SVM_EXIT_WRITE_DR0] = emulate_on_interception, 3056 [SVM_EXIT_WRITE_DR0] = dr_interception,
2818 [SVM_EXIT_WRITE_DR1] = emulate_on_interception, 3057 [SVM_EXIT_WRITE_DR1] = dr_interception,
2819 [SVM_EXIT_WRITE_DR2] = emulate_on_interception, 3058 [SVM_EXIT_WRITE_DR2] = dr_interception,
2820 [SVM_EXIT_WRITE_DR3] = emulate_on_interception, 3059 [SVM_EXIT_WRITE_DR3] = dr_interception,
2821 [SVM_EXIT_WRITE_DR4] = emulate_on_interception, 3060 [SVM_EXIT_WRITE_DR4] = dr_interception,
2822 [SVM_EXIT_WRITE_DR5] = emulate_on_interception, 3061 [SVM_EXIT_WRITE_DR5] = dr_interception,
2823 [SVM_EXIT_WRITE_DR6] = emulate_on_interception, 3062 [SVM_EXIT_WRITE_DR6] = dr_interception,
2824 [SVM_EXIT_WRITE_DR7] = emulate_on_interception, 3063 [SVM_EXIT_WRITE_DR7] = dr_interception,
2825 [SVM_EXIT_EXCP_BASE + DB_VECTOR] = db_interception, 3064 [SVM_EXIT_EXCP_BASE + DB_VECTOR] = db_interception,
2826 [SVM_EXIT_EXCP_BASE + BP_VECTOR] = bp_interception, 3065 [SVM_EXIT_EXCP_BASE + BP_VECTOR] = bp_interception,
2827 [SVM_EXIT_EXCP_BASE + UD_VECTOR] = ud_interception, 3066 [SVM_EXIT_EXCP_BASE + UD_VECTOR] = ud_interception,
@@ -2854,6 +3093,7 @@ static int (*svm_exit_handlers[])(struct vcpu_svm *svm) = {
2854 [SVM_EXIT_WBINVD] = emulate_on_interception, 3093 [SVM_EXIT_WBINVD] = emulate_on_interception,
2855 [SVM_EXIT_MONITOR] = invalid_op_interception, 3094 [SVM_EXIT_MONITOR] = invalid_op_interception,
2856 [SVM_EXIT_MWAIT] = invalid_op_interception, 3095 [SVM_EXIT_MWAIT] = invalid_op_interception,
3096 [SVM_EXIT_XSETBV] = xsetbv_interception,
2857 [SVM_EXIT_NPF] = pf_interception, 3097 [SVM_EXIT_NPF] = pf_interception,
2858}; 3098};
2859 3099
@@ -2864,10 +3104,10 @@ void dump_vmcb(struct kvm_vcpu *vcpu)
2864 struct vmcb_save_area *save = &svm->vmcb->save; 3104 struct vmcb_save_area *save = &svm->vmcb->save;
2865 3105
2866 pr_err("VMCB Control Area:\n"); 3106 pr_err("VMCB Control Area:\n");
2867 pr_err("cr_read: %04x\n", control->intercept_cr_read); 3107 pr_err("cr_read: %04x\n", control->intercept_cr & 0xffff);
2868 pr_err("cr_write: %04x\n", control->intercept_cr_write); 3108 pr_err("cr_write: %04x\n", control->intercept_cr >> 16);
2869 pr_err("dr_read: %04x\n", control->intercept_dr_read); 3109 pr_err("dr_read: %04x\n", control->intercept_dr & 0xffff);
2870 pr_err("dr_write: %04x\n", control->intercept_dr_write); 3110 pr_err("dr_write: %04x\n", control->intercept_dr >> 16);
2871 pr_err("exceptions: %08x\n", control->intercept_exceptions); 3111 pr_err("exceptions: %08x\n", control->intercept_exceptions);
2872 pr_err("intercepts: %016llx\n", control->intercept); 3112 pr_err("intercepts: %016llx\n", control->intercept);
2873 pr_err("pause filter count: %d\n", control->pause_filter_count); 3113 pr_err("pause filter count: %d\n", control->pause_filter_count);
@@ -2950,15 +3190,23 @@ void dump_vmcb(struct kvm_vcpu *vcpu)
2950 3190
2951} 3191}
2952 3192
3193static void svm_get_exit_info(struct kvm_vcpu *vcpu, u64 *info1, u64 *info2)
3194{
3195 struct vmcb_control_area *control = &to_svm(vcpu)->vmcb->control;
3196
3197 *info1 = control->exit_info_1;
3198 *info2 = control->exit_info_2;
3199}
3200
2953static int handle_exit(struct kvm_vcpu *vcpu) 3201static int handle_exit(struct kvm_vcpu *vcpu)
2954{ 3202{
2955 struct vcpu_svm *svm = to_svm(vcpu); 3203 struct vcpu_svm *svm = to_svm(vcpu);
2956 struct kvm_run *kvm_run = vcpu->run; 3204 struct kvm_run *kvm_run = vcpu->run;
2957 u32 exit_code = svm->vmcb->control.exit_code; 3205 u32 exit_code = svm->vmcb->control.exit_code;
2958 3206
2959 trace_kvm_exit(exit_code, vcpu); 3207 trace_kvm_exit(exit_code, vcpu, KVM_ISA_SVM);
2960 3208
2961 if (!(svm->vmcb->control.intercept_cr_write & INTERCEPT_CR0_MASK)) 3209 if (!is_cr_intercept(svm, INTERCEPT_CR0_WRITE))
2962 vcpu->arch.cr0 = svm->vmcb->save.cr0; 3210 vcpu->arch.cr0 = svm->vmcb->save.cr0;
2963 if (npt_enabled) 3211 if (npt_enabled)
2964 vcpu->arch.cr3 = svm->vmcb->save.cr3; 3212 vcpu->arch.cr3 = svm->vmcb->save.cr3;
@@ -2970,7 +3218,7 @@ static int handle_exit(struct kvm_vcpu *vcpu)
2970 return 1; 3218 return 1;
2971 } 3219 }
2972 3220
2973 if (is_nested(svm)) { 3221 if (is_guest_mode(vcpu)) {
2974 int vmexit; 3222 int vmexit;
2975 3223
2976 trace_kvm_nested_vmexit(svm->vmcb->save.rip, exit_code, 3224 trace_kvm_nested_vmexit(svm->vmcb->save.rip, exit_code,
@@ -3033,7 +3281,6 @@ static void pre_svm_run(struct vcpu_svm *svm)
3033 3281
3034 struct svm_cpu_data *sd = per_cpu(svm_data, cpu); 3282 struct svm_cpu_data *sd = per_cpu(svm_data, cpu);
3035 3283
3036 svm->vmcb->control.tlb_ctl = TLB_CONTROL_DO_NOTHING;
3037 /* FIXME: handle wraparound of asid_generation */ 3284 /* FIXME: handle wraparound of asid_generation */
3038 if (svm->asid_generation != sd->asid_generation) 3285 if (svm->asid_generation != sd->asid_generation)
3039 new_asid(svm, sd); 3286 new_asid(svm, sd);
@@ -3045,7 +3292,7 @@ static void svm_inject_nmi(struct kvm_vcpu *vcpu)
3045 3292
3046 svm->vmcb->control.event_inj = SVM_EVTINJ_VALID | SVM_EVTINJ_TYPE_NMI; 3293 svm->vmcb->control.event_inj = SVM_EVTINJ_VALID | SVM_EVTINJ_TYPE_NMI;
3047 vcpu->arch.hflags |= HF_NMI_MASK; 3294 vcpu->arch.hflags |= HF_NMI_MASK;
3048 svm->vmcb->control.intercept |= (1ULL << INTERCEPT_IRET); 3295 set_intercept(svm, INTERCEPT_IRET);
3049 ++vcpu->stat.nmi_injections; 3296 ++vcpu->stat.nmi_injections;
3050} 3297}
3051 3298
@@ -3058,6 +3305,7 @@ static inline void svm_inject_irq(struct vcpu_svm *svm, int irq)
3058 control->int_ctl &= ~V_INTR_PRIO_MASK; 3305 control->int_ctl &= ~V_INTR_PRIO_MASK;
3059 control->int_ctl |= V_IRQ_MASK | 3306 control->int_ctl |= V_IRQ_MASK |
3060 ((/*control->int_vector >> 4*/ 0xf) << V_INTR_PRIO_SHIFT); 3307 ((/*control->int_vector >> 4*/ 0xf) << V_INTR_PRIO_SHIFT);
3308 mark_dirty(svm->vmcb, VMCB_INTR);
3061} 3309}
3062 3310
3063static void svm_set_irq(struct kvm_vcpu *vcpu) 3311static void svm_set_irq(struct kvm_vcpu *vcpu)
@@ -3077,14 +3325,14 @@ static void update_cr8_intercept(struct kvm_vcpu *vcpu, int tpr, int irr)
3077{ 3325{
3078 struct vcpu_svm *svm = to_svm(vcpu); 3326 struct vcpu_svm *svm = to_svm(vcpu);
3079 3327
3080 if (is_nested(svm) && (vcpu->arch.hflags & HF_VINTR_MASK)) 3328 if (is_guest_mode(vcpu) && (vcpu->arch.hflags & HF_VINTR_MASK))
3081 return; 3329 return;
3082 3330
3083 if (irr == -1) 3331 if (irr == -1)
3084 return; 3332 return;
3085 3333
3086 if (tpr >= irr) 3334 if (tpr >= irr)
3087 svm->vmcb->control.intercept_cr_write |= INTERCEPT_CR8_MASK; 3335 set_cr_intercept(svm, INTERCEPT_CR8_WRITE);
3088} 3336}
3089 3337
3090static int svm_nmi_allowed(struct kvm_vcpu *vcpu) 3338static int svm_nmi_allowed(struct kvm_vcpu *vcpu)
@@ -3112,10 +3360,10 @@ static void svm_set_nmi_mask(struct kvm_vcpu *vcpu, bool masked)
3112 3360
3113 if (masked) { 3361 if (masked) {
3114 svm->vcpu.arch.hflags |= HF_NMI_MASK; 3362 svm->vcpu.arch.hflags |= HF_NMI_MASK;
3115 svm->vmcb->control.intercept |= (1ULL << INTERCEPT_IRET); 3363 set_intercept(svm, INTERCEPT_IRET);
3116 } else { 3364 } else {
3117 svm->vcpu.arch.hflags &= ~HF_NMI_MASK; 3365 svm->vcpu.arch.hflags &= ~HF_NMI_MASK;
3118 svm->vmcb->control.intercept &= ~(1ULL << INTERCEPT_IRET); 3366 clr_intercept(svm, INTERCEPT_IRET);
3119 } 3367 }
3120} 3368}
3121 3369
@@ -3131,7 +3379,7 @@ static int svm_interrupt_allowed(struct kvm_vcpu *vcpu)
3131 3379
3132 ret = !!(vmcb->save.rflags & X86_EFLAGS_IF); 3380 ret = !!(vmcb->save.rflags & X86_EFLAGS_IF);
3133 3381
3134 if (is_nested(svm)) 3382 if (is_guest_mode(vcpu))
3135 return ret && !(svm->vcpu.arch.hflags & HF_VINTR_MASK); 3383 return ret && !(svm->vcpu.arch.hflags & HF_VINTR_MASK);
3136 3384
3137 return ret; 3385 return ret;
@@ -3177,7 +3425,12 @@ static int svm_set_tss_addr(struct kvm *kvm, unsigned int addr)
3177 3425
3178static void svm_flush_tlb(struct kvm_vcpu *vcpu) 3426static void svm_flush_tlb(struct kvm_vcpu *vcpu)
3179{ 3427{
3180 force_new_asid(vcpu); 3428 struct vcpu_svm *svm = to_svm(vcpu);
3429
3430 if (static_cpu_has(X86_FEATURE_FLUSHBYASID))
3431 svm->vmcb->control.tlb_ctl = TLB_CONTROL_FLUSH_ASID;
3432 else
3433 svm->asid_generation--;
3181} 3434}
3182 3435
3183static void svm_prepare_guest_switch(struct kvm_vcpu *vcpu) 3436static void svm_prepare_guest_switch(struct kvm_vcpu *vcpu)
@@ -3188,10 +3441,10 @@ static inline void sync_cr8_to_lapic(struct kvm_vcpu *vcpu)
3188{ 3441{
3189 struct vcpu_svm *svm = to_svm(vcpu); 3442 struct vcpu_svm *svm = to_svm(vcpu);
3190 3443
3191 if (is_nested(svm) && (vcpu->arch.hflags & HF_VINTR_MASK)) 3444 if (is_guest_mode(vcpu) && (vcpu->arch.hflags & HF_VINTR_MASK))
3192 return; 3445 return;
3193 3446
3194 if (!(svm->vmcb->control.intercept_cr_write & INTERCEPT_CR8_MASK)) { 3447 if (!is_cr_intercept(svm, INTERCEPT_CR8_WRITE)) {
3195 int cr8 = svm->vmcb->control.int_ctl & V_TPR_MASK; 3448 int cr8 = svm->vmcb->control.int_ctl & V_TPR_MASK;
3196 kvm_set_cr8(vcpu, cr8); 3449 kvm_set_cr8(vcpu, cr8);
3197 } 3450 }
@@ -3202,7 +3455,7 @@ static inline void sync_lapic_to_cr8(struct kvm_vcpu *vcpu)
3202 struct vcpu_svm *svm = to_svm(vcpu); 3455 struct vcpu_svm *svm = to_svm(vcpu);
3203 u64 cr8; 3456 u64 cr8;
3204 3457
3205 if (is_nested(svm) && (vcpu->arch.hflags & HF_VINTR_MASK)) 3458 if (is_guest_mode(vcpu) && (vcpu->arch.hflags & HF_VINTR_MASK))
3206 return; 3459 return;
3207 3460
3208 cr8 = kvm_get_cr8(vcpu); 3461 cr8 = kvm_get_cr8(vcpu);
@@ -3289,9 +3542,6 @@ static void svm_cancel_injection(struct kvm_vcpu *vcpu)
3289static void svm_vcpu_run(struct kvm_vcpu *vcpu) 3542static void svm_vcpu_run(struct kvm_vcpu *vcpu)
3290{ 3543{
3291 struct vcpu_svm *svm = to_svm(vcpu); 3544 struct vcpu_svm *svm = to_svm(vcpu);
3292 u16 fs_selector;
3293 u16 gs_selector;
3294 u16 ldt_selector;
3295 3545
3296 svm->vmcb->save.rax = vcpu->arch.regs[VCPU_REGS_RAX]; 3546 svm->vmcb->save.rax = vcpu->arch.regs[VCPU_REGS_RAX];
3297 svm->vmcb->save.rsp = vcpu->arch.regs[VCPU_REGS_RSP]; 3547 svm->vmcb->save.rsp = vcpu->arch.regs[VCPU_REGS_RSP];
@@ -3308,10 +3558,6 @@ static void svm_vcpu_run(struct kvm_vcpu *vcpu)
3308 3558
3309 sync_lapic_to_cr8(vcpu); 3559 sync_lapic_to_cr8(vcpu);
3310 3560
3311 save_host_msrs(vcpu);
3312 savesegment(fs, fs_selector);
3313 savesegment(gs, gs_selector);
3314 ldt_selector = kvm_read_ldt();
3315 svm->vmcb->save.cr2 = vcpu->arch.cr2; 3561 svm->vmcb->save.cr2 = vcpu->arch.cr2;
3316 3562
3317 clgi(); 3563 clgi();
@@ -3389,19 +3635,10 @@ static void svm_vcpu_run(struct kvm_vcpu *vcpu)
3389#endif 3635#endif
3390 ); 3636 );
3391 3637
3392 vcpu->arch.cr2 = svm->vmcb->save.cr2;
3393 vcpu->arch.regs[VCPU_REGS_RAX] = svm->vmcb->save.rax;
3394 vcpu->arch.regs[VCPU_REGS_RSP] = svm->vmcb->save.rsp;
3395 vcpu->arch.regs[VCPU_REGS_RIP] = svm->vmcb->save.rip;
3396
3397 load_host_msrs(vcpu);
3398 kvm_load_ldt(ldt_selector);
3399 loadsegment(fs, fs_selector);
3400#ifdef CONFIG_X86_64 3638#ifdef CONFIG_X86_64
3401 load_gs_index(gs_selector); 3639 wrmsrl(MSR_GS_BASE, svm->host.gs_base);
3402 wrmsrl(MSR_KERNEL_GS_BASE, current->thread.gs);
3403#else 3640#else
3404 loadsegment(gs, gs_selector); 3641 loadsegment(fs, svm->host.fs);
3405#endif 3642#endif
3406 3643
3407 reload_tss(vcpu); 3644 reload_tss(vcpu);
@@ -3410,10 +3647,21 @@ static void svm_vcpu_run(struct kvm_vcpu *vcpu)
3410 3647
3411 stgi(); 3648 stgi();
3412 3649
3650 vcpu->arch.cr2 = svm->vmcb->save.cr2;
3651 vcpu->arch.regs[VCPU_REGS_RAX] = svm->vmcb->save.rax;
3652 vcpu->arch.regs[VCPU_REGS_RSP] = svm->vmcb->save.rsp;
3653 vcpu->arch.regs[VCPU_REGS_RIP] = svm->vmcb->save.rip;
3654
3413 sync_cr8_to_lapic(vcpu); 3655 sync_cr8_to_lapic(vcpu);
3414 3656
3415 svm->next_rip = 0; 3657 svm->next_rip = 0;
3416 3658
3659 svm->vmcb->control.tlb_ctl = TLB_CONTROL_DO_NOTHING;
3660
3661 /* if exit due to PF check for async PF */
3662 if (svm->vmcb->control.exit_code == SVM_EXIT_EXCP_BASE + PF_VECTOR)
3663 svm->apf_reason = kvm_read_and_reset_pf_reason();
3664
3417 if (npt_enabled) { 3665 if (npt_enabled) {
3418 vcpu->arch.regs_avail &= ~(1 << VCPU_EXREG_PDPTR); 3666 vcpu->arch.regs_avail &= ~(1 << VCPU_EXREG_PDPTR);
3419 vcpu->arch.regs_dirty &= ~(1 << VCPU_EXREG_PDPTR); 3667 vcpu->arch.regs_dirty &= ~(1 << VCPU_EXREG_PDPTR);
@@ -3426,6 +3674,8 @@ static void svm_vcpu_run(struct kvm_vcpu *vcpu)
3426 if (unlikely(svm->vmcb->control.exit_code == 3674 if (unlikely(svm->vmcb->control.exit_code ==
3427 SVM_EXIT_EXCP_BASE + MC_VECTOR)) 3675 SVM_EXIT_EXCP_BASE + MC_VECTOR))
3428 svm_handle_mce(svm); 3676 svm_handle_mce(svm);
3677
3678 mark_all_clean(svm->vmcb);
3429} 3679}
3430 3680
3431#undef R 3681#undef R
@@ -3435,7 +3685,8 @@ static void svm_set_cr3(struct kvm_vcpu *vcpu, unsigned long root)
3435 struct vcpu_svm *svm = to_svm(vcpu); 3685 struct vcpu_svm *svm = to_svm(vcpu);
3436 3686
3437 svm->vmcb->save.cr3 = root; 3687 svm->vmcb->save.cr3 = root;
3438 force_new_asid(vcpu); 3688 mark_dirty(svm->vmcb, VMCB_CR);
3689 svm_flush_tlb(vcpu);
3439} 3690}
3440 3691
3441static void set_tdp_cr3(struct kvm_vcpu *vcpu, unsigned long root) 3692static void set_tdp_cr3(struct kvm_vcpu *vcpu, unsigned long root)
@@ -3443,11 +3694,13 @@ static void set_tdp_cr3(struct kvm_vcpu *vcpu, unsigned long root)
3443 struct vcpu_svm *svm = to_svm(vcpu); 3694 struct vcpu_svm *svm = to_svm(vcpu);
3444 3695
3445 svm->vmcb->control.nested_cr3 = root; 3696 svm->vmcb->control.nested_cr3 = root;
3697 mark_dirty(svm->vmcb, VMCB_NPT);
3446 3698
3447 /* Also sync guest cr3 here in case we live migrate */ 3699 /* Also sync guest cr3 here in case we live migrate */
3448 svm->vmcb->save.cr3 = vcpu->arch.cr3; 3700 svm->vmcb->save.cr3 = kvm_read_cr3(vcpu);
3701 mark_dirty(svm->vmcb, VMCB_CR);
3449 3702
3450 force_new_asid(vcpu); 3703 svm_flush_tlb(vcpu);
3451} 3704}
3452 3705
3453static int is_disabled(void) 3706static int is_disabled(void)
@@ -3494,10 +3747,6 @@ static void svm_cpuid_update(struct kvm_vcpu *vcpu)
3494static void svm_set_supported_cpuid(u32 func, struct kvm_cpuid_entry2 *entry) 3747static void svm_set_supported_cpuid(u32 func, struct kvm_cpuid_entry2 *entry)
3495{ 3748{
3496 switch (func) { 3749 switch (func) {
3497 case 0x00000001:
3498 /* Mask out xsave bit as long as it is not supported by SVM */
3499 entry->ecx &= ~(bit(X86_FEATURE_XSAVE));
3500 break;
3501 case 0x80000001: 3750 case 0x80000001:
3502 if (nested) 3751 if (nested)
3503 entry->ecx |= (1 << 2); /* Set SVM bit */ 3752 entry->ecx |= (1 << 2); /* Set SVM bit */
@@ -3511,7 +3760,7 @@ static void svm_set_supported_cpuid(u32 func, struct kvm_cpuid_entry2 *entry)
3511 additional features */ 3760 additional features */
3512 3761
3513 /* Support next_rip if host supports it */ 3762 /* Support next_rip if host supports it */
3514 if (svm_has(SVM_FEATURE_NRIP)) 3763 if (boot_cpu_has(X86_FEATURE_NRIPS))
3515 entry->edx |= SVM_FEATURE_NRIP; 3764 entry->edx |= SVM_FEATURE_NRIP;
3516 3765
3517 /* Support NPT for the guest if enabled */ 3766 /* Support NPT for the guest if enabled */
@@ -3571,6 +3820,7 @@ static const struct trace_print_flags svm_exit_reasons_str[] = {
3571 { SVM_EXIT_WBINVD, "wbinvd" }, 3820 { SVM_EXIT_WBINVD, "wbinvd" },
3572 { SVM_EXIT_MONITOR, "monitor" }, 3821 { SVM_EXIT_MONITOR, "monitor" },
3573 { SVM_EXIT_MWAIT, "mwait" }, 3822 { SVM_EXIT_MWAIT, "mwait" },
3823 { SVM_EXIT_XSETBV, "xsetbv" },
3574 { SVM_EXIT_NPF, "npf" }, 3824 { SVM_EXIT_NPF, "npf" },
3575 { -1, NULL } 3825 { -1, NULL }
3576}; 3826};
@@ -3594,9 +3844,7 @@ static void svm_fpu_deactivate(struct kvm_vcpu *vcpu)
3594{ 3844{
3595 struct vcpu_svm *svm = to_svm(vcpu); 3845 struct vcpu_svm *svm = to_svm(vcpu);
3596 3846
3597 svm->vmcb->control.intercept_exceptions |= 1 << NM_VECTOR; 3847 set_exception_intercept(svm, NM_VECTOR);
3598 if (is_nested(svm))
3599 svm->nested.hsave->control.intercept_exceptions |= 1 << NM_VECTOR;
3600 update_cr0_intercept(svm); 3848 update_cr0_intercept(svm);
3601} 3849}
3602 3850
@@ -3627,6 +3875,7 @@ static struct kvm_x86_ops svm_x86_ops = {
3627 .get_cpl = svm_get_cpl, 3875 .get_cpl = svm_get_cpl,
3628 .get_cs_db_l_bits = kvm_get_cs_db_l_bits, 3876 .get_cs_db_l_bits = kvm_get_cs_db_l_bits,
3629 .decache_cr0_guest_bits = svm_decache_cr0_guest_bits, 3877 .decache_cr0_guest_bits = svm_decache_cr0_guest_bits,
3878 .decache_cr3 = svm_decache_cr3,
3630 .decache_cr4_guest_bits = svm_decache_cr4_guest_bits, 3879 .decache_cr4_guest_bits = svm_decache_cr4_guest_bits,
3631 .set_cr0 = svm_set_cr0, 3880 .set_cr0 = svm_set_cr0,
3632 .set_cr3 = svm_set_cr3, 3881 .set_cr3 = svm_set_cr3,
@@ -3667,7 +3916,9 @@ static struct kvm_x86_ops svm_x86_ops = {
3667 .get_tdp_level = get_npt_level, 3916 .get_tdp_level = get_npt_level,
3668 .get_mt_mask = svm_get_mt_mask, 3917 .get_mt_mask = svm_get_mt_mask,
3669 3918
3919 .get_exit_info = svm_get_exit_info,
3670 .exit_reasons_str = svm_exit_reasons_str, 3920 .exit_reasons_str = svm_exit_reasons_str,
3921
3671 .get_lpage_level = svm_get_lpage_level, 3922 .get_lpage_level = svm_get_lpage_level,
3672 3923
3673 .cpuid_update = svm_cpuid_update, 3924 .cpuid_update = svm_cpuid_update,
diff --git a/arch/x86/kvm/trace.h b/arch/x86/kvm/trace.h
index a6544b8e7c0f..1357d7cf4ec8 100644
--- a/arch/x86/kvm/trace.h
+++ b/arch/x86/kvm/trace.h
@@ -178,27 +178,36 @@ TRACE_EVENT(kvm_apic,
178#define trace_kvm_apic_read(reg, val) trace_kvm_apic(0, reg, val) 178#define trace_kvm_apic_read(reg, val) trace_kvm_apic(0, reg, val)
179#define trace_kvm_apic_write(reg, val) trace_kvm_apic(1, reg, val) 179#define trace_kvm_apic_write(reg, val) trace_kvm_apic(1, reg, val)
180 180
181#define KVM_ISA_VMX 1
182#define KVM_ISA_SVM 2
183
181/* 184/*
182 * Tracepoint for kvm guest exit: 185 * Tracepoint for kvm guest exit:
183 */ 186 */
184TRACE_EVENT(kvm_exit, 187TRACE_EVENT(kvm_exit,
185 TP_PROTO(unsigned int exit_reason, struct kvm_vcpu *vcpu), 188 TP_PROTO(unsigned int exit_reason, struct kvm_vcpu *vcpu, u32 isa),
186 TP_ARGS(exit_reason, vcpu), 189 TP_ARGS(exit_reason, vcpu, isa),
187 190
188 TP_STRUCT__entry( 191 TP_STRUCT__entry(
189 __field( unsigned int, exit_reason ) 192 __field( unsigned int, exit_reason )
190 __field( unsigned long, guest_rip ) 193 __field( unsigned long, guest_rip )
194 __field( u32, isa )
195 __field( u64, info1 )
196 __field( u64, info2 )
191 ), 197 ),
192 198
193 TP_fast_assign( 199 TP_fast_assign(
194 __entry->exit_reason = exit_reason; 200 __entry->exit_reason = exit_reason;
195 __entry->guest_rip = kvm_rip_read(vcpu); 201 __entry->guest_rip = kvm_rip_read(vcpu);
202 __entry->isa = isa;
203 kvm_x86_ops->get_exit_info(vcpu, &__entry->info1,
204 &__entry->info2);
196 ), 205 ),
197 206
198 TP_printk("reason %s rip 0x%lx", 207 TP_printk("reason %s rip 0x%lx info %llx %llx",
199 ftrace_print_symbols_seq(p, __entry->exit_reason, 208 ftrace_print_symbols_seq(p, __entry->exit_reason,
200 kvm_x86_ops->exit_reasons_str), 209 kvm_x86_ops->exit_reasons_str),
201 __entry->guest_rip) 210 __entry->guest_rip, __entry->info1, __entry->info2)
202); 211);
203 212
204/* 213/*
diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
index 81fcbe9515c5..bf89ec2cfb82 100644
--- a/arch/x86/kvm/vmx.c
+++ b/arch/x86/kvm/vmx.c
@@ -69,6 +69,9 @@ module_param(emulate_invalid_guest_state, bool, S_IRUGO);
69static int __read_mostly vmm_exclusive = 1; 69static int __read_mostly vmm_exclusive = 1;
70module_param(vmm_exclusive, bool, S_IRUGO); 70module_param(vmm_exclusive, bool, S_IRUGO);
71 71
72static int __read_mostly yield_on_hlt = 1;
73module_param(yield_on_hlt, bool, S_IRUGO);
74
72#define KVM_GUEST_CR0_MASK_UNRESTRICTED_GUEST \ 75#define KVM_GUEST_CR0_MASK_UNRESTRICTED_GUEST \
73 (X86_CR0_WP | X86_CR0_NE | X86_CR0_NW | X86_CR0_CD) 76 (X86_CR0_WP | X86_CR0_NE | X86_CR0_NW | X86_CR0_CD)
74#define KVM_GUEST_CR0_MASK \ 77#define KVM_GUEST_CR0_MASK \
@@ -177,6 +180,7 @@ static int init_rmode(struct kvm *kvm);
177static u64 construct_eptp(unsigned long root_hpa); 180static u64 construct_eptp(unsigned long root_hpa);
178static void kvm_cpu_vmxon(u64 addr); 181static void kvm_cpu_vmxon(u64 addr);
179static void kvm_cpu_vmxoff(void); 182static void kvm_cpu_vmxoff(void);
183static void vmx_set_cr3(struct kvm_vcpu *vcpu, unsigned long cr3);
180 184
181static DEFINE_PER_CPU(struct vmcs *, vmxarea); 185static DEFINE_PER_CPU(struct vmcs *, vmxarea);
182static DEFINE_PER_CPU(struct vmcs *, current_vmcs); 186static DEFINE_PER_CPU(struct vmcs *, current_vmcs);
@@ -188,6 +192,8 @@ static unsigned long *vmx_io_bitmap_b;
188static unsigned long *vmx_msr_bitmap_legacy; 192static unsigned long *vmx_msr_bitmap_legacy;
189static unsigned long *vmx_msr_bitmap_longmode; 193static unsigned long *vmx_msr_bitmap_longmode;
190 194
195static bool cpu_has_load_ia32_efer;
196
191static DECLARE_BITMAP(vmx_vpid_bitmap, VMX_NR_VPIDS); 197static DECLARE_BITMAP(vmx_vpid_bitmap, VMX_NR_VPIDS);
192static DEFINE_SPINLOCK(vmx_vpid_lock); 198static DEFINE_SPINLOCK(vmx_vpid_lock);
193 199
@@ -472,7 +478,7 @@ static void vmcs_clear(struct vmcs *vmcs)
472 u8 error; 478 u8 error;
473 479
474 asm volatile (__ex(ASM_VMX_VMCLEAR_RAX) "; setna %0" 480 asm volatile (__ex(ASM_VMX_VMCLEAR_RAX) "; setna %0"
475 : "=g"(error) : "a"(&phys_addr), "m"(phys_addr) 481 : "=qm"(error) : "a"(&phys_addr), "m"(phys_addr)
476 : "cc", "memory"); 482 : "cc", "memory");
477 if (error) 483 if (error)
478 printk(KERN_ERR "kvm: vmclear fail: %p/%llx\n", 484 printk(KERN_ERR "kvm: vmclear fail: %p/%llx\n",
@@ -485,7 +491,7 @@ static void vmcs_load(struct vmcs *vmcs)
485 u8 error; 491 u8 error;
486 492
487 asm volatile (__ex(ASM_VMX_VMPTRLD_RAX) "; setna %0" 493 asm volatile (__ex(ASM_VMX_VMPTRLD_RAX) "; setna %0"
488 : "=g"(error) : "a"(&phys_addr), "m"(phys_addr) 494 : "=qm"(error) : "a"(&phys_addr), "m"(phys_addr)
489 : "cc", "memory"); 495 : "cc", "memory");
490 if (error) 496 if (error)
491 printk(KERN_ERR "kvm: vmptrld %p/%llx fail\n", 497 printk(KERN_ERR "kvm: vmptrld %p/%llx fail\n",
@@ -565,10 +571,10 @@ static inline void ept_sync_individual_addr(u64 eptp, gpa_t gpa)
565 571
566static unsigned long vmcs_readl(unsigned long field) 572static unsigned long vmcs_readl(unsigned long field)
567{ 573{
568 unsigned long value; 574 unsigned long value = 0;
569 575
570 asm volatile (__ex(ASM_VMX_VMREAD_RDX_RAX) 576 asm volatile (__ex(ASM_VMX_VMREAD_RDX_RAX)
571 : "=a"(value) : "d"(field) : "cc"); 577 : "+a"(value) : "d"(field) : "cc");
572 return value; 578 return value;
573} 579}
574 580
@@ -661,6 +667,12 @@ static void clear_atomic_switch_msr(struct vcpu_vmx *vmx, unsigned msr)
661 unsigned i; 667 unsigned i;
662 struct msr_autoload *m = &vmx->msr_autoload; 668 struct msr_autoload *m = &vmx->msr_autoload;
663 669
670 if (msr == MSR_EFER && cpu_has_load_ia32_efer) {
671 vmcs_clear_bits(VM_ENTRY_CONTROLS, VM_ENTRY_LOAD_IA32_EFER);
672 vmcs_clear_bits(VM_EXIT_CONTROLS, VM_EXIT_LOAD_IA32_EFER);
673 return;
674 }
675
664 for (i = 0; i < m->nr; ++i) 676 for (i = 0; i < m->nr; ++i)
665 if (m->guest[i].index == msr) 677 if (m->guest[i].index == msr)
666 break; 678 break;
@@ -680,6 +692,14 @@ static void add_atomic_switch_msr(struct vcpu_vmx *vmx, unsigned msr,
680 unsigned i; 692 unsigned i;
681 struct msr_autoload *m = &vmx->msr_autoload; 693 struct msr_autoload *m = &vmx->msr_autoload;
682 694
695 if (msr == MSR_EFER && cpu_has_load_ia32_efer) {
696 vmcs_write64(GUEST_IA32_EFER, guest_val);
697 vmcs_write64(HOST_IA32_EFER, host_val);
698 vmcs_set_bits(VM_ENTRY_CONTROLS, VM_ENTRY_LOAD_IA32_EFER);
699 vmcs_set_bits(VM_EXIT_CONTROLS, VM_EXIT_LOAD_IA32_EFER);
700 return;
701 }
702
683 for (i = 0; i < m->nr; ++i) 703 for (i = 0; i < m->nr; ++i)
684 if (m->guest[i].index == msr) 704 if (m->guest[i].index == msr)
685 break; 705 break;
@@ -1009,6 +1029,17 @@ static void skip_emulated_instruction(struct kvm_vcpu *vcpu)
1009 vmx_set_interrupt_shadow(vcpu, 0); 1029 vmx_set_interrupt_shadow(vcpu, 0);
1010} 1030}
1011 1031
1032static void vmx_clear_hlt(struct kvm_vcpu *vcpu)
1033{
1034 /* Ensure that we clear the HLT state in the VMCS. We don't need to
1035 * explicitly skip the instruction because if the HLT state is set, then
1036 * the instruction is already executing and RIP has already been
1037 * advanced. */
1038 if (!yield_on_hlt &&
1039 vmcs_read32(GUEST_ACTIVITY_STATE) == GUEST_ACTIVITY_HLT)
1040 vmcs_write32(GUEST_ACTIVITY_STATE, GUEST_ACTIVITY_ACTIVE);
1041}
1042
1012static void vmx_queue_exception(struct kvm_vcpu *vcpu, unsigned nr, 1043static void vmx_queue_exception(struct kvm_vcpu *vcpu, unsigned nr,
1013 bool has_error_code, u32 error_code, 1044 bool has_error_code, u32 error_code,
1014 bool reinject) 1045 bool reinject)
@@ -1035,6 +1066,7 @@ static void vmx_queue_exception(struct kvm_vcpu *vcpu, unsigned nr,
1035 intr_info |= INTR_TYPE_HARD_EXCEPTION; 1066 intr_info |= INTR_TYPE_HARD_EXCEPTION;
1036 1067
1037 vmcs_write32(VM_ENTRY_INTR_INFO_FIELD, intr_info); 1068 vmcs_write32(VM_ENTRY_INTR_INFO_FIELD, intr_info);
1069 vmx_clear_hlt(vcpu);
1038} 1070}
1039 1071
1040static bool vmx_rdtscp_supported(void) 1072static bool vmx_rdtscp_supported(void)
@@ -1305,8 +1337,11 @@ static __init int vmx_disabled_by_bios(void)
1305 && tboot_enabled()) 1337 && tboot_enabled())
1306 return 1; 1338 return 1;
1307 if (!(msr & FEATURE_CONTROL_VMXON_ENABLED_OUTSIDE_SMX) 1339 if (!(msr & FEATURE_CONTROL_VMXON_ENABLED_OUTSIDE_SMX)
1308 && !tboot_enabled()) 1340 && !tboot_enabled()) {
1341 printk(KERN_WARNING "kvm: disable TXT in the BIOS or "
1342 " activate TXT before enabling KVM\n");
1309 return 1; 1343 return 1;
1344 }
1310 } 1345 }
1311 1346
1312 return 0; 1347 return 0;
@@ -1400,6 +1435,14 @@ static __init int adjust_vmx_controls(u32 ctl_min, u32 ctl_opt,
1400 return 0; 1435 return 0;
1401} 1436}
1402 1437
1438static __init bool allow_1_setting(u32 msr, u32 ctl)
1439{
1440 u32 vmx_msr_low, vmx_msr_high;
1441
1442 rdmsr(msr, vmx_msr_low, vmx_msr_high);
1443 return vmx_msr_high & ctl;
1444}
1445
1403static __init int setup_vmcs_config(struct vmcs_config *vmcs_conf) 1446static __init int setup_vmcs_config(struct vmcs_config *vmcs_conf)
1404{ 1447{
1405 u32 vmx_msr_low, vmx_msr_high; 1448 u32 vmx_msr_low, vmx_msr_high;
@@ -1416,7 +1459,7 @@ static __init int setup_vmcs_config(struct vmcs_config *vmcs_conf)
1416 &_pin_based_exec_control) < 0) 1459 &_pin_based_exec_control) < 0)
1417 return -EIO; 1460 return -EIO;
1418 1461
1419 min = CPU_BASED_HLT_EXITING | 1462 min =
1420#ifdef CONFIG_X86_64 1463#ifdef CONFIG_X86_64
1421 CPU_BASED_CR8_LOAD_EXITING | 1464 CPU_BASED_CR8_LOAD_EXITING |
1422 CPU_BASED_CR8_STORE_EXITING | 1465 CPU_BASED_CR8_STORE_EXITING |
@@ -1429,6 +1472,10 @@ static __init int setup_vmcs_config(struct vmcs_config *vmcs_conf)
1429 CPU_BASED_MWAIT_EXITING | 1472 CPU_BASED_MWAIT_EXITING |
1430 CPU_BASED_MONITOR_EXITING | 1473 CPU_BASED_MONITOR_EXITING |
1431 CPU_BASED_INVLPG_EXITING; 1474 CPU_BASED_INVLPG_EXITING;
1475
1476 if (yield_on_hlt)
1477 min |= CPU_BASED_HLT_EXITING;
1478
1432 opt = CPU_BASED_TPR_SHADOW | 1479 opt = CPU_BASED_TPR_SHADOW |
1433 CPU_BASED_USE_MSR_BITMAPS | 1480 CPU_BASED_USE_MSR_BITMAPS |
1434 CPU_BASED_ACTIVATE_SECONDARY_CONTROLS; 1481 CPU_BASED_ACTIVATE_SECONDARY_CONTROLS;
@@ -1510,6 +1557,12 @@ static __init int setup_vmcs_config(struct vmcs_config *vmcs_conf)
1510 vmcs_conf->vmexit_ctrl = _vmexit_control; 1557 vmcs_conf->vmexit_ctrl = _vmexit_control;
1511 vmcs_conf->vmentry_ctrl = _vmentry_control; 1558 vmcs_conf->vmentry_ctrl = _vmentry_control;
1512 1559
1560 cpu_has_load_ia32_efer =
1561 allow_1_setting(MSR_IA32_VMX_ENTRY_CTLS,
1562 VM_ENTRY_LOAD_IA32_EFER)
1563 && allow_1_setting(MSR_IA32_VMX_EXIT_CTLS,
1564 VM_EXIT_LOAD_IA32_EFER);
1565
1513 return 0; 1566 return 0;
1514} 1567}
1515 1568
@@ -1683,9 +1736,13 @@ static void fix_rmode_seg(int seg, struct kvm_save_segment *save)
1683 save->limit = vmcs_read32(sf->limit); 1736 save->limit = vmcs_read32(sf->limit);
1684 save->ar = vmcs_read32(sf->ar_bytes); 1737 save->ar = vmcs_read32(sf->ar_bytes);
1685 vmcs_write16(sf->selector, save->base >> 4); 1738 vmcs_write16(sf->selector, save->base >> 4);
1686 vmcs_write32(sf->base, save->base & 0xfffff); 1739 vmcs_write32(sf->base, save->base & 0xffff0);
1687 vmcs_write32(sf->limit, 0xffff); 1740 vmcs_write32(sf->limit, 0xffff);
1688 vmcs_write32(sf->ar_bytes, 0xf3); 1741 vmcs_write32(sf->ar_bytes, 0xf3);
1742 if (save->base & 0xf)
1743 printk_once(KERN_WARNING "kvm: segment base is not paragraph"
1744 " aligned when entering protected mode (seg=%d)",
1745 seg);
1689} 1746}
1690 1747
1691static void enter_rmode(struct kvm_vcpu *vcpu) 1748static void enter_rmode(struct kvm_vcpu *vcpu)
@@ -1814,6 +1871,13 @@ static void vmx_decache_cr0_guest_bits(struct kvm_vcpu *vcpu)
1814 vcpu->arch.cr0 |= vmcs_readl(GUEST_CR0) & cr0_guest_owned_bits; 1871 vcpu->arch.cr0 |= vmcs_readl(GUEST_CR0) & cr0_guest_owned_bits;
1815} 1872}
1816 1873
1874static void vmx_decache_cr3(struct kvm_vcpu *vcpu)
1875{
1876 if (enable_ept && is_paging(vcpu))
1877 vcpu->arch.cr3 = vmcs_readl(GUEST_CR3);
1878 __set_bit(VCPU_EXREG_CR3, (ulong *)&vcpu->arch.regs_avail);
1879}
1880
1817static void vmx_decache_cr4_guest_bits(struct kvm_vcpu *vcpu) 1881static void vmx_decache_cr4_guest_bits(struct kvm_vcpu *vcpu)
1818{ 1882{
1819 ulong cr4_guest_owned_bits = vcpu->arch.cr4_guest_owned_bits; 1883 ulong cr4_guest_owned_bits = vcpu->arch.cr4_guest_owned_bits;
@@ -1857,6 +1921,7 @@ static void ept_update_paging_mode_cr0(unsigned long *hw_cr0,
1857 unsigned long cr0, 1921 unsigned long cr0,
1858 struct kvm_vcpu *vcpu) 1922 struct kvm_vcpu *vcpu)
1859{ 1923{
1924 vmx_decache_cr3(vcpu);
1860 if (!(cr0 & X86_CR0_PG)) { 1925 if (!(cr0 & X86_CR0_PG)) {
1861 /* From paging/starting to nonpaging */ 1926 /* From paging/starting to nonpaging */
1862 vmcs_write32(CPU_BASED_VM_EXEC_CONTROL, 1927 vmcs_write32(CPU_BASED_VM_EXEC_CONTROL,
@@ -1937,7 +2002,7 @@ static void vmx_set_cr3(struct kvm_vcpu *vcpu, unsigned long cr3)
1937 if (enable_ept) { 2002 if (enable_ept) {
1938 eptp = construct_eptp(cr3); 2003 eptp = construct_eptp(cr3);
1939 vmcs_write64(EPT_POINTER, eptp); 2004 vmcs_write64(EPT_POINTER, eptp);
1940 guest_cr3 = is_paging(vcpu) ? vcpu->arch.cr3 : 2005 guest_cr3 = is_paging(vcpu) ? kvm_read_cr3(vcpu) :
1941 vcpu->kvm->arch.ept_identity_map_addr; 2006 vcpu->kvm->arch.ept_identity_map_addr;
1942 ept_load_pdptrs(vcpu); 2007 ept_load_pdptrs(vcpu);
1943 } 2008 }
@@ -2725,7 +2790,7 @@ static int vmx_vcpu_reset(struct kvm_vcpu *vcpu)
2725 vmcs_writel(GUEST_IDTR_BASE, 0); 2790 vmcs_writel(GUEST_IDTR_BASE, 0);
2726 vmcs_write32(GUEST_IDTR_LIMIT, 0xffff); 2791 vmcs_write32(GUEST_IDTR_LIMIT, 0xffff);
2727 2792
2728 vmcs_write32(GUEST_ACTIVITY_STATE, 0); 2793 vmcs_write32(GUEST_ACTIVITY_STATE, GUEST_ACTIVITY_ACTIVE);
2729 vmcs_write32(GUEST_INTERRUPTIBILITY_INFO, 0); 2794 vmcs_write32(GUEST_INTERRUPTIBILITY_INFO, 0);
2730 vmcs_write32(GUEST_PENDING_DBG_EXCEPTIONS, 0); 2795 vmcs_write32(GUEST_PENDING_DBG_EXCEPTIONS, 0);
2731 2796
@@ -2787,6 +2852,10 @@ static void enable_nmi_window(struct kvm_vcpu *vcpu)
2787 return; 2852 return;
2788 } 2853 }
2789 2854
2855 if (vmcs_read32(GUEST_INTERRUPTIBILITY_INFO) & GUEST_INTR_STATE_STI) {
2856 enable_irq_window(vcpu);
2857 return;
2858 }
2790 cpu_based_vm_exec_control = vmcs_read32(CPU_BASED_VM_EXEC_CONTROL); 2859 cpu_based_vm_exec_control = vmcs_read32(CPU_BASED_VM_EXEC_CONTROL);
2791 cpu_based_vm_exec_control |= CPU_BASED_VIRTUAL_NMI_PENDING; 2860 cpu_based_vm_exec_control |= CPU_BASED_VIRTUAL_NMI_PENDING;
2792 vmcs_write32(CPU_BASED_VM_EXEC_CONTROL, cpu_based_vm_exec_control); 2861 vmcs_write32(CPU_BASED_VM_EXEC_CONTROL, cpu_based_vm_exec_control);
@@ -2814,6 +2883,7 @@ static void vmx_inject_irq(struct kvm_vcpu *vcpu)
2814 } else 2883 } else
2815 intr |= INTR_TYPE_EXT_INTR; 2884 intr |= INTR_TYPE_EXT_INTR;
2816 vmcs_write32(VM_ENTRY_INTR_INFO_FIELD, intr); 2885 vmcs_write32(VM_ENTRY_INTR_INFO_FIELD, intr);
2886 vmx_clear_hlt(vcpu);
2817} 2887}
2818 2888
2819static void vmx_inject_nmi(struct kvm_vcpu *vcpu) 2889static void vmx_inject_nmi(struct kvm_vcpu *vcpu)
@@ -2841,6 +2911,7 @@ static void vmx_inject_nmi(struct kvm_vcpu *vcpu)
2841 } 2911 }
2842 vmcs_write32(VM_ENTRY_INTR_INFO_FIELD, 2912 vmcs_write32(VM_ENTRY_INTR_INFO_FIELD,
2843 INTR_TYPE_NMI_INTR | INTR_INFO_VALID_MASK | NMI_VECTOR); 2913 INTR_TYPE_NMI_INTR | INTR_INFO_VALID_MASK | NMI_VECTOR);
2914 vmx_clear_hlt(vcpu);
2844} 2915}
2845 2916
2846static int vmx_nmi_allowed(struct kvm_vcpu *vcpu) 2917static int vmx_nmi_allowed(struct kvm_vcpu *vcpu)
@@ -2849,7 +2920,8 @@ static int vmx_nmi_allowed(struct kvm_vcpu *vcpu)
2849 return 0; 2920 return 0;
2850 2921
2851 return !(vmcs_read32(GUEST_INTERRUPTIBILITY_INFO) & 2922 return !(vmcs_read32(GUEST_INTERRUPTIBILITY_INFO) &
2852 (GUEST_INTR_STATE_MOV_SS | GUEST_INTR_STATE_NMI)); 2923 (GUEST_INTR_STATE_MOV_SS | GUEST_INTR_STATE_STI
2924 | GUEST_INTR_STATE_NMI));
2853} 2925}
2854 2926
2855static bool vmx_get_nmi_mask(struct kvm_vcpu *vcpu) 2927static bool vmx_get_nmi_mask(struct kvm_vcpu *vcpu)
@@ -2910,7 +2982,7 @@ static int handle_rmode_exception(struct kvm_vcpu *vcpu,
2910 * Cause the #SS fault with 0 error code in VM86 mode. 2982 * Cause the #SS fault with 0 error code in VM86 mode.
2911 */ 2983 */
2912 if (((vec == GP_VECTOR) || (vec == SS_VECTOR)) && err_code == 0) 2984 if (((vec == GP_VECTOR) || (vec == SS_VECTOR)) && err_code == 0)
2913 if (emulate_instruction(vcpu, 0, 0, 0) == EMULATE_DONE) 2985 if (emulate_instruction(vcpu, 0) == EMULATE_DONE)
2914 return 1; 2986 return 1;
2915 /* 2987 /*
2916 * Forward all other exceptions that are valid in real mode. 2988 * Forward all other exceptions that are valid in real mode.
@@ -3007,7 +3079,7 @@ static int handle_exception(struct kvm_vcpu *vcpu)
3007 } 3079 }
3008 3080
3009 if (is_invalid_opcode(intr_info)) { 3081 if (is_invalid_opcode(intr_info)) {
3010 er = emulate_instruction(vcpu, 0, 0, EMULTYPE_TRAP_UD); 3082 er = emulate_instruction(vcpu, EMULTYPE_TRAP_UD);
3011 if (er != EMULATE_DONE) 3083 if (er != EMULATE_DONE)
3012 kvm_queue_exception(vcpu, UD_VECTOR); 3084 kvm_queue_exception(vcpu, UD_VECTOR);
3013 return 1; 3085 return 1;
@@ -3026,7 +3098,7 @@ static int handle_exception(struct kvm_vcpu *vcpu)
3026 3098
3027 if (kvm_event_needs_reinjection(vcpu)) 3099 if (kvm_event_needs_reinjection(vcpu))
3028 kvm_mmu_unprotect_page_virt(vcpu, cr2); 3100 kvm_mmu_unprotect_page_virt(vcpu, cr2);
3029 return kvm_mmu_page_fault(vcpu, cr2, error_code); 3101 return kvm_mmu_page_fault(vcpu, cr2, error_code, NULL, 0);
3030 } 3102 }
3031 3103
3032 if (vmx->rmode.vm86_active && 3104 if (vmx->rmode.vm86_active &&
@@ -3098,7 +3170,7 @@ static int handle_io(struct kvm_vcpu *vcpu)
3098 ++vcpu->stat.io_exits; 3170 ++vcpu->stat.io_exits;
3099 3171
3100 if (string || in) 3172 if (string || in)
3101 return emulate_instruction(vcpu, 0, 0, 0) == EMULATE_DONE; 3173 return emulate_instruction(vcpu, 0) == EMULATE_DONE;
3102 3174
3103 port = exit_qualification >> 16; 3175 port = exit_qualification >> 16;
3104 size = (exit_qualification & 7) + 1; 3176 size = (exit_qualification & 7) + 1;
@@ -3118,14 +3190,6 @@ vmx_patch_hypercall(struct kvm_vcpu *vcpu, unsigned char *hypercall)
3118 hypercall[2] = 0xc1; 3190 hypercall[2] = 0xc1;
3119} 3191}
3120 3192
3121static void complete_insn_gp(struct kvm_vcpu *vcpu, int err)
3122{
3123 if (err)
3124 kvm_inject_gp(vcpu, 0);
3125 else
3126 skip_emulated_instruction(vcpu);
3127}
3128
3129static int handle_cr(struct kvm_vcpu *vcpu) 3193static int handle_cr(struct kvm_vcpu *vcpu)
3130{ 3194{
3131 unsigned long exit_qualification, val; 3195 unsigned long exit_qualification, val;
@@ -3143,21 +3207,21 @@ static int handle_cr(struct kvm_vcpu *vcpu)
3143 switch (cr) { 3207 switch (cr) {
3144 case 0: 3208 case 0:
3145 err = kvm_set_cr0(vcpu, val); 3209 err = kvm_set_cr0(vcpu, val);
3146 complete_insn_gp(vcpu, err); 3210 kvm_complete_insn_gp(vcpu, err);
3147 return 1; 3211 return 1;
3148 case 3: 3212 case 3:
3149 err = kvm_set_cr3(vcpu, val); 3213 err = kvm_set_cr3(vcpu, val);
3150 complete_insn_gp(vcpu, err); 3214 kvm_complete_insn_gp(vcpu, err);
3151 return 1; 3215 return 1;
3152 case 4: 3216 case 4:
3153 err = kvm_set_cr4(vcpu, val); 3217 err = kvm_set_cr4(vcpu, val);
3154 complete_insn_gp(vcpu, err); 3218 kvm_complete_insn_gp(vcpu, err);
3155 return 1; 3219 return 1;
3156 case 8: { 3220 case 8: {
3157 u8 cr8_prev = kvm_get_cr8(vcpu); 3221 u8 cr8_prev = kvm_get_cr8(vcpu);
3158 u8 cr8 = kvm_register_read(vcpu, reg); 3222 u8 cr8 = kvm_register_read(vcpu, reg);
3159 kvm_set_cr8(vcpu, cr8); 3223 err = kvm_set_cr8(vcpu, cr8);
3160 skip_emulated_instruction(vcpu); 3224 kvm_complete_insn_gp(vcpu, err);
3161 if (irqchip_in_kernel(vcpu->kvm)) 3225 if (irqchip_in_kernel(vcpu->kvm))
3162 return 1; 3226 return 1;
3163 if (cr8_prev <= cr8) 3227 if (cr8_prev <= cr8)
@@ -3176,8 +3240,9 @@ static int handle_cr(struct kvm_vcpu *vcpu)
3176 case 1: /*mov from cr*/ 3240 case 1: /*mov from cr*/
3177 switch (cr) { 3241 switch (cr) {
3178 case 3: 3242 case 3:
3179 kvm_register_write(vcpu, reg, vcpu->arch.cr3); 3243 val = kvm_read_cr3(vcpu);
3180 trace_kvm_cr_read(cr, vcpu->arch.cr3); 3244 kvm_register_write(vcpu, reg, val);
3245 trace_kvm_cr_read(cr, val);
3181 skip_emulated_instruction(vcpu); 3246 skip_emulated_instruction(vcpu);
3182 return 1; 3247 return 1;
3183 case 8: 3248 case 8:
@@ -3349,6 +3414,11 @@ static int handle_vmx_insn(struct kvm_vcpu *vcpu)
3349 return 1; 3414 return 1;
3350} 3415}
3351 3416
3417static int handle_invd(struct kvm_vcpu *vcpu)
3418{
3419 return emulate_instruction(vcpu, 0) == EMULATE_DONE;
3420}
3421
3352static int handle_invlpg(struct kvm_vcpu *vcpu) 3422static int handle_invlpg(struct kvm_vcpu *vcpu)
3353{ 3423{
3354 unsigned long exit_qualification = vmcs_readl(EXIT_QUALIFICATION); 3424 unsigned long exit_qualification = vmcs_readl(EXIT_QUALIFICATION);
@@ -3377,7 +3447,7 @@ static int handle_xsetbv(struct kvm_vcpu *vcpu)
3377 3447
3378static int handle_apic_access(struct kvm_vcpu *vcpu) 3448static int handle_apic_access(struct kvm_vcpu *vcpu)
3379{ 3449{
3380 return emulate_instruction(vcpu, 0, 0, 0) == EMULATE_DONE; 3450 return emulate_instruction(vcpu, 0) == EMULATE_DONE;
3381} 3451}
3382 3452
3383static int handle_task_switch(struct kvm_vcpu *vcpu) 3453static int handle_task_switch(struct kvm_vcpu *vcpu)
@@ -3476,7 +3546,7 @@ static int handle_ept_violation(struct kvm_vcpu *vcpu)
3476 3546
3477 gpa = vmcs_read64(GUEST_PHYSICAL_ADDRESS); 3547 gpa = vmcs_read64(GUEST_PHYSICAL_ADDRESS);
3478 trace_kvm_page_fault(gpa, exit_qualification); 3548 trace_kvm_page_fault(gpa, exit_qualification);
3479 return kvm_mmu_page_fault(vcpu, gpa & PAGE_MASK, 0); 3549 return kvm_mmu_page_fault(vcpu, gpa, exit_qualification & 0x3, NULL, 0);
3480} 3550}
3481 3551
3482static u64 ept_rsvd_mask(u64 spte, int level) 3552static u64 ept_rsvd_mask(u64 spte, int level)
@@ -3592,7 +3662,7 @@ static int handle_invalid_guest_state(struct kvm_vcpu *vcpu)
3592 && (kvm_get_rflags(&vmx->vcpu) & X86_EFLAGS_IF)) 3662 && (kvm_get_rflags(&vmx->vcpu) & X86_EFLAGS_IF))
3593 return handle_interrupt_window(&vmx->vcpu); 3663 return handle_interrupt_window(&vmx->vcpu);
3594 3664
3595 err = emulate_instruction(vcpu, 0, 0, 0); 3665 err = emulate_instruction(vcpu, 0);
3596 3666
3597 if (err == EMULATE_DO_MMIO) { 3667 if (err == EMULATE_DO_MMIO) {
3598 ret = 0; 3668 ret = 0;
@@ -3649,6 +3719,7 @@ static int (*kvm_vmx_exit_handlers[])(struct kvm_vcpu *vcpu) = {
3649 [EXIT_REASON_MSR_WRITE] = handle_wrmsr, 3719 [EXIT_REASON_MSR_WRITE] = handle_wrmsr,
3650 [EXIT_REASON_PENDING_INTERRUPT] = handle_interrupt_window, 3720 [EXIT_REASON_PENDING_INTERRUPT] = handle_interrupt_window,
3651 [EXIT_REASON_HLT] = handle_halt, 3721 [EXIT_REASON_HLT] = handle_halt,
3722 [EXIT_REASON_INVD] = handle_invd,
3652 [EXIT_REASON_INVLPG] = handle_invlpg, 3723 [EXIT_REASON_INVLPG] = handle_invlpg,
3653 [EXIT_REASON_VMCALL] = handle_vmcall, 3724 [EXIT_REASON_VMCALL] = handle_vmcall,
3654 [EXIT_REASON_VMCLEAR] = handle_vmx_insn, 3725 [EXIT_REASON_VMCLEAR] = handle_vmx_insn,
@@ -3676,6 +3747,12 @@ static int (*kvm_vmx_exit_handlers[])(struct kvm_vcpu *vcpu) = {
3676static const int kvm_vmx_max_exit_handlers = 3747static const int kvm_vmx_max_exit_handlers =
3677 ARRAY_SIZE(kvm_vmx_exit_handlers); 3748 ARRAY_SIZE(kvm_vmx_exit_handlers);
3678 3749
3750static void vmx_get_exit_info(struct kvm_vcpu *vcpu, u64 *info1, u64 *info2)
3751{
3752 *info1 = vmcs_readl(EXIT_QUALIFICATION);
3753 *info2 = vmcs_read32(VM_EXIT_INTR_INFO);
3754}
3755
3679/* 3756/*
3680 * The guest has exited. See if we can fix it or if we need userspace 3757 * The guest has exited. See if we can fix it or if we need userspace
3681 * assistance. 3758 * assistance.
@@ -3686,17 +3763,12 @@ static int vmx_handle_exit(struct kvm_vcpu *vcpu)
3686 u32 exit_reason = vmx->exit_reason; 3763 u32 exit_reason = vmx->exit_reason;
3687 u32 vectoring_info = vmx->idt_vectoring_info; 3764 u32 vectoring_info = vmx->idt_vectoring_info;
3688 3765
3689 trace_kvm_exit(exit_reason, vcpu); 3766 trace_kvm_exit(exit_reason, vcpu, KVM_ISA_VMX);
3690 3767
3691 /* If guest state is invalid, start emulating */ 3768 /* If guest state is invalid, start emulating */
3692 if (vmx->emulation_required && emulate_invalid_guest_state) 3769 if (vmx->emulation_required && emulate_invalid_guest_state)
3693 return handle_invalid_guest_state(vcpu); 3770 return handle_invalid_guest_state(vcpu);
3694 3771
3695 /* Access CR3 don't cause VMExit in paging mode, so we need
3696 * to sync with guest real CR3. */
3697 if (enable_ept && is_paging(vcpu))
3698 vcpu->arch.cr3 = vmcs_readl(GUEST_CR3);
3699
3700 if (exit_reason & VMX_EXIT_REASONS_FAILED_VMENTRY) { 3772 if (exit_reason & VMX_EXIT_REASONS_FAILED_VMENTRY) {
3701 vcpu->run->exit_reason = KVM_EXIT_FAIL_ENTRY; 3773 vcpu->run->exit_reason = KVM_EXIT_FAIL_ENTRY;
3702 vcpu->run->fail_entry.hardware_entry_failure_reason 3774 vcpu->run->fail_entry.hardware_entry_failure_reason
@@ -4013,7 +4085,8 @@ static void vmx_vcpu_run(struct kvm_vcpu *vcpu)
4013 ); 4085 );
4014 4086
4015 vcpu->arch.regs_avail = ~((1 << VCPU_REGS_RIP) | (1 << VCPU_REGS_RSP) 4087 vcpu->arch.regs_avail = ~((1 << VCPU_REGS_RIP) | (1 << VCPU_REGS_RSP)
4016 | (1 << VCPU_EXREG_PDPTR)); 4088 | (1 << VCPU_EXREG_PDPTR)
4089 | (1 << VCPU_EXREG_CR3));
4017 vcpu->arch.regs_dirty = 0; 4090 vcpu->arch.regs_dirty = 0;
4018 4091
4019 vmx->idt_vectoring_info = vmcs_read32(IDT_VECTORING_INFO_FIELD); 4092 vmx->idt_vectoring_info = vmcs_read32(IDT_VECTORING_INFO_FIELD);
@@ -4280,6 +4353,7 @@ static struct kvm_x86_ops vmx_x86_ops = {
4280 .get_cpl = vmx_get_cpl, 4353 .get_cpl = vmx_get_cpl,
4281 .get_cs_db_l_bits = vmx_get_cs_db_l_bits, 4354 .get_cs_db_l_bits = vmx_get_cs_db_l_bits,
4282 .decache_cr0_guest_bits = vmx_decache_cr0_guest_bits, 4355 .decache_cr0_guest_bits = vmx_decache_cr0_guest_bits,
4356 .decache_cr3 = vmx_decache_cr3,
4283 .decache_cr4_guest_bits = vmx_decache_cr4_guest_bits, 4357 .decache_cr4_guest_bits = vmx_decache_cr4_guest_bits,
4284 .set_cr0 = vmx_set_cr0, 4358 .set_cr0 = vmx_set_cr0,
4285 .set_cr3 = vmx_set_cr3, 4359 .set_cr3 = vmx_set_cr3,
@@ -4320,7 +4394,9 @@ static struct kvm_x86_ops vmx_x86_ops = {
4320 .get_tdp_level = get_ept_level, 4394 .get_tdp_level = get_ept_level,
4321 .get_mt_mask = vmx_get_mt_mask, 4395 .get_mt_mask = vmx_get_mt_mask,
4322 4396
4397 .get_exit_info = vmx_get_exit_info,
4323 .exit_reasons_str = vmx_exit_reasons_str, 4398 .exit_reasons_str = vmx_exit_reasons_str,
4399
4324 .get_lpage_level = vmx_get_lpage_level, 4400 .get_lpage_level = vmx_get_lpage_level,
4325 4401
4326 .cpuid_update = vmx_cpuid_update, 4402 .cpuid_update = vmx_cpuid_update,
@@ -4396,8 +4472,6 @@ static int __init vmx_init(void)
4396 4472
4397 if (enable_ept) { 4473 if (enable_ept) {
4398 bypass_guest_pf = 0; 4474 bypass_guest_pf = 0;
4399 kvm_mmu_set_base_ptes(VMX_EPT_READABLE_MASK |
4400 VMX_EPT_WRITABLE_MASK);
4401 kvm_mmu_set_mask_ptes(0ull, 0ull, 0ull, 0ull, 4475 kvm_mmu_set_mask_ptes(0ull, 0ull, 0ull, 0ull,
4402 VMX_EPT_EXECUTABLE_MASK); 4476 VMX_EPT_EXECUTABLE_MASK);
4403 kvm_enable_tdp(); 4477 kvm_enable_tdp();
diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index 46a368cb651e..bcc0efce85bf 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -43,6 +43,7 @@
43#include <linux/slab.h> 43#include <linux/slab.h>
44#include <linux/perf_event.h> 44#include <linux/perf_event.h>
45#include <linux/uaccess.h> 45#include <linux/uaccess.h>
46#include <linux/hash.h>
46#include <trace/events/kvm.h> 47#include <trace/events/kvm.h>
47 48
48#define CREATE_TRACE_POINTS 49#define CREATE_TRACE_POINTS
@@ -155,6 +156,13 @@ struct kvm_stats_debugfs_item debugfs_entries[] = {
155 156
156u64 __read_mostly host_xcr0; 157u64 __read_mostly host_xcr0;
157 158
159static inline void kvm_async_pf_hash_reset(struct kvm_vcpu *vcpu)
160{
161 int i;
162 for (i = 0; i < roundup_pow_of_two(ASYNC_PF_PER_VCPU); i++)
163 vcpu->arch.apf.gfns[i] = ~0;
164}
165
158static void kvm_on_user_return(struct user_return_notifier *urn) 166static void kvm_on_user_return(struct user_return_notifier *urn)
159{ 167{
160 unsigned slot; 168 unsigned slot;
@@ -326,23 +334,28 @@ void kvm_requeue_exception(struct kvm_vcpu *vcpu, unsigned nr)
326} 334}
327EXPORT_SYMBOL_GPL(kvm_requeue_exception); 335EXPORT_SYMBOL_GPL(kvm_requeue_exception);
328 336
329void kvm_inject_page_fault(struct kvm_vcpu *vcpu) 337void kvm_complete_insn_gp(struct kvm_vcpu *vcpu, int err)
330{ 338{
331 unsigned error_code = vcpu->arch.fault.error_code; 339 if (err)
340 kvm_inject_gp(vcpu, 0);
341 else
342 kvm_x86_ops->skip_emulated_instruction(vcpu);
343}
344EXPORT_SYMBOL_GPL(kvm_complete_insn_gp);
332 345
346void kvm_inject_page_fault(struct kvm_vcpu *vcpu, struct x86_exception *fault)
347{
333 ++vcpu->stat.pf_guest; 348 ++vcpu->stat.pf_guest;
334 vcpu->arch.cr2 = vcpu->arch.fault.address; 349 vcpu->arch.cr2 = fault->address;
335 kvm_queue_exception_e(vcpu, PF_VECTOR, error_code); 350 kvm_queue_exception_e(vcpu, PF_VECTOR, fault->error_code);
336} 351}
337 352
338void kvm_propagate_fault(struct kvm_vcpu *vcpu) 353void kvm_propagate_fault(struct kvm_vcpu *vcpu, struct x86_exception *fault)
339{ 354{
340 if (mmu_is_nested(vcpu) && !vcpu->arch.fault.nested) 355 if (mmu_is_nested(vcpu) && !fault->nested_page_fault)
341 vcpu->arch.nested_mmu.inject_page_fault(vcpu); 356 vcpu->arch.nested_mmu.inject_page_fault(vcpu, fault);
342 else 357 else
343 vcpu->arch.mmu.inject_page_fault(vcpu); 358 vcpu->arch.mmu.inject_page_fault(vcpu, fault);
344
345 vcpu->arch.fault.nested = false;
346} 359}
347 360
348void kvm_inject_nmi(struct kvm_vcpu *vcpu) 361void kvm_inject_nmi(struct kvm_vcpu *vcpu)
@@ -460,8 +473,8 @@ static bool pdptrs_changed(struct kvm_vcpu *vcpu)
460 (unsigned long *)&vcpu->arch.regs_avail)) 473 (unsigned long *)&vcpu->arch.regs_avail))
461 return true; 474 return true;
462 475
463 gfn = (vcpu->arch.cr3 & ~31u) >> PAGE_SHIFT; 476 gfn = (kvm_read_cr3(vcpu) & ~31u) >> PAGE_SHIFT;
464 offset = (vcpu->arch.cr3 & ~31u) & (PAGE_SIZE - 1); 477 offset = (kvm_read_cr3(vcpu) & ~31u) & (PAGE_SIZE - 1);
465 r = kvm_read_nested_guest_page(vcpu, gfn, pdpte, offset, sizeof(pdpte), 478 r = kvm_read_nested_guest_page(vcpu, gfn, pdpte, offset, sizeof(pdpte),
466 PFERR_USER_MASK | PFERR_WRITE_MASK); 479 PFERR_USER_MASK | PFERR_WRITE_MASK);
467 if (r < 0) 480 if (r < 0)
@@ -506,12 +519,15 @@ int kvm_set_cr0(struct kvm_vcpu *vcpu, unsigned long cr0)
506 } else 519 } else
507#endif 520#endif
508 if (is_pae(vcpu) && !load_pdptrs(vcpu, vcpu->arch.walk_mmu, 521 if (is_pae(vcpu) && !load_pdptrs(vcpu, vcpu->arch.walk_mmu,
509 vcpu->arch.cr3)) 522 kvm_read_cr3(vcpu)))
510 return 1; 523 return 1;
511 } 524 }
512 525
513 kvm_x86_ops->set_cr0(vcpu, cr0); 526 kvm_x86_ops->set_cr0(vcpu, cr0);
514 527
528 if ((cr0 ^ old_cr0) & X86_CR0_PG)
529 kvm_clear_async_pf_completion_queue(vcpu);
530
515 if ((cr0 ^ old_cr0) & update_bits) 531 if ((cr0 ^ old_cr0) & update_bits)
516 kvm_mmu_reset_context(vcpu); 532 kvm_mmu_reset_context(vcpu);
517 return 0; 533 return 0;
@@ -595,7 +611,8 @@ int kvm_set_cr4(struct kvm_vcpu *vcpu, unsigned long cr4)
595 return 1; 611 return 1;
596 } else if (is_paging(vcpu) && (cr4 & X86_CR4_PAE) 612 } else if (is_paging(vcpu) && (cr4 & X86_CR4_PAE)
597 && ((cr4 ^ old_cr4) & pdptr_bits) 613 && ((cr4 ^ old_cr4) & pdptr_bits)
598 && !load_pdptrs(vcpu, vcpu->arch.walk_mmu, vcpu->arch.cr3)) 614 && !load_pdptrs(vcpu, vcpu->arch.walk_mmu,
615 kvm_read_cr3(vcpu)))
599 return 1; 616 return 1;
600 617
601 if (cr4 & X86_CR4_VMXE) 618 if (cr4 & X86_CR4_VMXE)
@@ -615,7 +632,7 @@ EXPORT_SYMBOL_GPL(kvm_set_cr4);
615 632
616int kvm_set_cr3(struct kvm_vcpu *vcpu, unsigned long cr3) 633int kvm_set_cr3(struct kvm_vcpu *vcpu, unsigned long cr3)
617{ 634{
618 if (cr3 == vcpu->arch.cr3 && !pdptrs_changed(vcpu)) { 635 if (cr3 == kvm_read_cr3(vcpu) && !pdptrs_changed(vcpu)) {
619 kvm_mmu_sync_roots(vcpu); 636 kvm_mmu_sync_roots(vcpu);
620 kvm_mmu_flush_tlb(vcpu); 637 kvm_mmu_flush_tlb(vcpu);
621 return 0; 638 return 0;
@@ -650,12 +667,13 @@ int kvm_set_cr3(struct kvm_vcpu *vcpu, unsigned long cr3)
650 if (unlikely(!gfn_to_memslot(vcpu->kvm, cr3 >> PAGE_SHIFT))) 667 if (unlikely(!gfn_to_memslot(vcpu->kvm, cr3 >> PAGE_SHIFT)))
651 return 1; 668 return 1;
652 vcpu->arch.cr3 = cr3; 669 vcpu->arch.cr3 = cr3;
670 __set_bit(VCPU_EXREG_CR3, (ulong *)&vcpu->arch.regs_avail);
653 vcpu->arch.mmu.new_cr3(vcpu); 671 vcpu->arch.mmu.new_cr3(vcpu);
654 return 0; 672 return 0;
655} 673}
656EXPORT_SYMBOL_GPL(kvm_set_cr3); 674EXPORT_SYMBOL_GPL(kvm_set_cr3);
657 675
658int __kvm_set_cr8(struct kvm_vcpu *vcpu, unsigned long cr8) 676int kvm_set_cr8(struct kvm_vcpu *vcpu, unsigned long cr8)
659{ 677{
660 if (cr8 & CR8_RESERVED_BITS) 678 if (cr8 & CR8_RESERVED_BITS)
661 return 1; 679 return 1;
@@ -665,12 +683,6 @@ int __kvm_set_cr8(struct kvm_vcpu *vcpu, unsigned long cr8)
665 vcpu->arch.cr8 = cr8; 683 vcpu->arch.cr8 = cr8;
666 return 0; 684 return 0;
667} 685}
668
669void kvm_set_cr8(struct kvm_vcpu *vcpu, unsigned long cr8)
670{
671 if (__kvm_set_cr8(vcpu, cr8))
672 kvm_inject_gp(vcpu, 0);
673}
674EXPORT_SYMBOL_GPL(kvm_set_cr8); 686EXPORT_SYMBOL_GPL(kvm_set_cr8);
675 687
676unsigned long kvm_get_cr8(struct kvm_vcpu *vcpu) 688unsigned long kvm_get_cr8(struct kvm_vcpu *vcpu)
@@ -775,12 +787,12 @@ EXPORT_SYMBOL_GPL(kvm_get_dr);
775 * kvm-specific. Those are put in the beginning of the list. 787 * kvm-specific. Those are put in the beginning of the list.
776 */ 788 */
777 789
778#define KVM_SAVE_MSRS_BEGIN 7 790#define KVM_SAVE_MSRS_BEGIN 8
779static u32 msrs_to_save[] = { 791static u32 msrs_to_save[] = {
780 MSR_KVM_SYSTEM_TIME, MSR_KVM_WALL_CLOCK, 792 MSR_KVM_SYSTEM_TIME, MSR_KVM_WALL_CLOCK,
781 MSR_KVM_SYSTEM_TIME_NEW, MSR_KVM_WALL_CLOCK_NEW, 793 MSR_KVM_SYSTEM_TIME_NEW, MSR_KVM_WALL_CLOCK_NEW,
782 HV_X64_MSR_GUEST_OS_ID, HV_X64_MSR_HYPERCALL, 794 HV_X64_MSR_GUEST_OS_ID, HV_X64_MSR_HYPERCALL,
783 HV_X64_MSR_APIC_ASSIST_PAGE, 795 HV_X64_MSR_APIC_ASSIST_PAGE, MSR_KVM_ASYNC_PF_EN,
784 MSR_IA32_SYSENTER_CS, MSR_IA32_SYSENTER_ESP, MSR_IA32_SYSENTER_EIP, 796 MSR_IA32_SYSENTER_CS, MSR_IA32_SYSENTER_ESP, MSR_IA32_SYSENTER_EIP,
785 MSR_STAR, 797 MSR_STAR,
786#ifdef CONFIG_X86_64 798#ifdef CONFIG_X86_64
@@ -830,7 +842,6 @@ static int set_efer(struct kvm_vcpu *vcpu, u64 efer)
830 kvm_x86_ops->set_efer(vcpu, efer); 842 kvm_x86_ops->set_efer(vcpu, efer);
831 843
832 vcpu->arch.mmu.base_role.nxe = (efer & EFER_NX) && !tdp_enabled; 844 vcpu->arch.mmu.base_role.nxe = (efer & EFER_NX) && !tdp_enabled;
833 kvm_mmu_reset_context(vcpu);
834 845
835 /* Update reserved bits */ 846 /* Update reserved bits */
836 if ((efer ^ old_efer) & EFER_NX) 847 if ((efer ^ old_efer) & EFER_NX)
@@ -1418,6 +1429,30 @@ static int set_msr_hyperv(struct kvm_vcpu *vcpu, u32 msr, u64 data)
1418 return 0; 1429 return 0;
1419} 1430}
1420 1431
1432static int kvm_pv_enable_async_pf(struct kvm_vcpu *vcpu, u64 data)
1433{
1434 gpa_t gpa = data & ~0x3f;
1435
1436 /* Bits 2:5 are resrved, Should be zero */
1437 if (data & 0x3c)
1438 return 1;
1439
1440 vcpu->arch.apf.msr_val = data;
1441
1442 if (!(data & KVM_ASYNC_PF_ENABLED)) {
1443 kvm_clear_async_pf_completion_queue(vcpu);
1444 kvm_async_pf_hash_reset(vcpu);
1445 return 0;
1446 }
1447
1448 if (kvm_gfn_to_hva_cache_init(vcpu->kvm, &vcpu->arch.apf.data, gpa))
1449 return 1;
1450
1451 vcpu->arch.apf.send_user_only = !(data & KVM_ASYNC_PF_SEND_ALWAYS);
1452 kvm_async_pf_wakeup_all(vcpu);
1453 return 0;
1454}
1455
1421int kvm_set_msr_common(struct kvm_vcpu *vcpu, u32 msr, u64 data) 1456int kvm_set_msr_common(struct kvm_vcpu *vcpu, u32 msr, u64 data)
1422{ 1457{
1423 switch (msr) { 1458 switch (msr) {
@@ -1499,6 +1534,10 @@ int kvm_set_msr_common(struct kvm_vcpu *vcpu, u32 msr, u64 data)
1499 } 1534 }
1500 break; 1535 break;
1501 } 1536 }
1537 case MSR_KVM_ASYNC_PF_EN:
1538 if (kvm_pv_enable_async_pf(vcpu, data))
1539 return 1;
1540 break;
1502 case MSR_IA32_MCG_CTL: 1541 case MSR_IA32_MCG_CTL:
1503 case MSR_IA32_MCG_STATUS: 1542 case MSR_IA32_MCG_STATUS:
1504 case MSR_IA32_MC0_CTL ... MSR_IA32_MC0_CTL + 4 * KVM_MAX_MCE_BANKS - 1: 1543 case MSR_IA32_MC0_CTL ... MSR_IA32_MC0_CTL + 4 * KVM_MAX_MCE_BANKS - 1:
@@ -1775,6 +1814,9 @@ int kvm_get_msr_common(struct kvm_vcpu *vcpu, u32 msr, u64 *pdata)
1775 case MSR_KVM_SYSTEM_TIME_NEW: 1814 case MSR_KVM_SYSTEM_TIME_NEW:
1776 data = vcpu->arch.time; 1815 data = vcpu->arch.time;
1777 break; 1816 break;
1817 case MSR_KVM_ASYNC_PF_EN:
1818 data = vcpu->arch.apf.msr_val;
1819 break;
1778 case MSR_IA32_P5_MC_ADDR: 1820 case MSR_IA32_P5_MC_ADDR:
1779 case MSR_IA32_P5_MC_TYPE: 1821 case MSR_IA32_P5_MC_TYPE:
1780 case MSR_IA32_MCG_CAP: 1822 case MSR_IA32_MCG_CAP:
@@ -1904,6 +1946,7 @@ int kvm_dev_ioctl_check_extension(long ext)
1904 case KVM_CAP_NOP_IO_DELAY: 1946 case KVM_CAP_NOP_IO_DELAY:
1905 case KVM_CAP_MP_STATE: 1947 case KVM_CAP_MP_STATE:
1906 case KVM_CAP_SYNC_MMU: 1948 case KVM_CAP_SYNC_MMU:
1949 case KVM_CAP_USER_NMI:
1907 case KVM_CAP_REINJECT_CONTROL: 1950 case KVM_CAP_REINJECT_CONTROL:
1908 case KVM_CAP_IRQ_INJECT_STATUS: 1951 case KVM_CAP_IRQ_INJECT_STATUS:
1909 case KVM_CAP_ASSIGN_DEV_IRQ: 1952 case KVM_CAP_ASSIGN_DEV_IRQ:
@@ -1922,6 +1965,7 @@ int kvm_dev_ioctl_check_extension(long ext)
1922 case KVM_CAP_DEBUGREGS: 1965 case KVM_CAP_DEBUGREGS:
1923 case KVM_CAP_X86_ROBUST_SINGLESTEP: 1966 case KVM_CAP_X86_ROBUST_SINGLESTEP:
1924 case KVM_CAP_XSAVE: 1967 case KVM_CAP_XSAVE:
1968 case KVM_CAP_ASYNC_PF:
1925 r = 1; 1969 r = 1;
1926 break; 1970 break;
1927 case KVM_CAP_COALESCED_MMIO: 1971 case KVM_CAP_COALESCED_MMIO:
@@ -2185,6 +2229,11 @@ out:
2185 return r; 2229 return r;
2186} 2230}
2187 2231
2232static void cpuid_mask(u32 *word, int wordnum)
2233{
2234 *word &= boot_cpu_data.x86_capability[wordnum];
2235}
2236
2188static void do_cpuid_1_ent(struct kvm_cpuid_entry2 *entry, u32 function, 2237static void do_cpuid_1_ent(struct kvm_cpuid_entry2 *entry, u32 function,
2189 u32 index) 2238 u32 index)
2190{ 2239{
@@ -2259,7 +2308,9 @@ static void do_cpuid_ent(struct kvm_cpuid_entry2 *entry, u32 function,
2259 break; 2308 break;
2260 case 1: 2309 case 1:
2261 entry->edx &= kvm_supported_word0_x86_features; 2310 entry->edx &= kvm_supported_word0_x86_features;
2311 cpuid_mask(&entry->edx, 0);
2262 entry->ecx &= kvm_supported_word4_x86_features; 2312 entry->ecx &= kvm_supported_word4_x86_features;
2313 cpuid_mask(&entry->ecx, 4);
2263 /* we support x2apic emulation even if host does not support 2314 /* we support x2apic emulation even if host does not support
2264 * it since we emulate x2apic in software */ 2315 * it since we emulate x2apic in software */
2265 entry->ecx |= F(X2APIC); 2316 entry->ecx |= F(X2APIC);
@@ -2350,7 +2401,9 @@ static void do_cpuid_ent(struct kvm_cpuid_entry2 *entry, u32 function,
2350 break; 2401 break;
2351 case 0x80000001: 2402 case 0x80000001:
2352 entry->edx &= kvm_supported_word1_x86_features; 2403 entry->edx &= kvm_supported_word1_x86_features;
2404 cpuid_mask(&entry->edx, 1);
2353 entry->ecx &= kvm_supported_word6_x86_features; 2405 entry->ecx &= kvm_supported_word6_x86_features;
2406 cpuid_mask(&entry->ecx, 6);
2354 break; 2407 break;
2355 } 2408 }
2356 2409
@@ -3169,20 +3222,18 @@ int kvm_vm_ioctl_get_dirty_log(struct kvm *kvm,
3169 struct kvm_memslots *slots, *old_slots; 3222 struct kvm_memslots *slots, *old_slots;
3170 unsigned long *dirty_bitmap; 3223 unsigned long *dirty_bitmap;
3171 3224
3172 r = -ENOMEM; 3225 dirty_bitmap = memslot->dirty_bitmap_head;
3173 dirty_bitmap = vmalloc(n); 3226 if (memslot->dirty_bitmap == dirty_bitmap)
3174 if (!dirty_bitmap) 3227 dirty_bitmap += n / sizeof(long);
3175 goto out;
3176 memset(dirty_bitmap, 0, n); 3228 memset(dirty_bitmap, 0, n);
3177 3229
3178 r = -ENOMEM; 3230 r = -ENOMEM;
3179 slots = kzalloc(sizeof(struct kvm_memslots), GFP_KERNEL); 3231 slots = kzalloc(sizeof(struct kvm_memslots), GFP_KERNEL);
3180 if (!slots) { 3232 if (!slots)
3181 vfree(dirty_bitmap);
3182 goto out; 3233 goto out;
3183 }
3184 memcpy(slots, kvm->memslots, sizeof(struct kvm_memslots)); 3234 memcpy(slots, kvm->memslots, sizeof(struct kvm_memslots));
3185 slots->memslots[log->slot].dirty_bitmap = dirty_bitmap; 3235 slots->memslots[log->slot].dirty_bitmap = dirty_bitmap;
3236 slots->generation++;
3186 3237
3187 old_slots = kvm->memslots; 3238 old_slots = kvm->memslots;
3188 rcu_assign_pointer(kvm->memslots, slots); 3239 rcu_assign_pointer(kvm->memslots, slots);
@@ -3195,11 +3246,8 @@ int kvm_vm_ioctl_get_dirty_log(struct kvm *kvm,
3195 spin_unlock(&kvm->mmu_lock); 3246 spin_unlock(&kvm->mmu_lock);
3196 3247
3197 r = -EFAULT; 3248 r = -EFAULT;
3198 if (copy_to_user(log->dirty_bitmap, dirty_bitmap, n)) { 3249 if (copy_to_user(log->dirty_bitmap, dirty_bitmap, n))
3199 vfree(dirty_bitmap);
3200 goto out; 3250 goto out;
3201 }
3202 vfree(dirty_bitmap);
3203 } else { 3251 } else {
3204 r = -EFAULT; 3252 r = -EFAULT;
3205 if (clear_user(log->dirty_bitmap, n)) 3253 if (clear_user(log->dirty_bitmap, n))
@@ -3266,8 +3314,10 @@ long kvm_arch_vm_ioctl(struct file *filp,
3266 if (vpic) { 3314 if (vpic) {
3267 r = kvm_ioapic_init(kvm); 3315 r = kvm_ioapic_init(kvm);
3268 if (r) { 3316 if (r) {
3317 mutex_lock(&kvm->slots_lock);
3269 kvm_io_bus_unregister_dev(kvm, KVM_PIO_BUS, 3318 kvm_io_bus_unregister_dev(kvm, KVM_PIO_BUS,
3270 &vpic->dev); 3319 &vpic->dev);
3320 mutex_unlock(&kvm->slots_lock);
3271 kfree(vpic); 3321 kfree(vpic);
3272 goto create_irqchip_unlock; 3322 goto create_irqchip_unlock;
3273 } 3323 }
@@ -3278,10 +3328,12 @@ long kvm_arch_vm_ioctl(struct file *filp,
3278 smp_wmb(); 3328 smp_wmb();
3279 r = kvm_setup_default_irq_routing(kvm); 3329 r = kvm_setup_default_irq_routing(kvm);
3280 if (r) { 3330 if (r) {
3331 mutex_lock(&kvm->slots_lock);
3281 mutex_lock(&kvm->irq_lock); 3332 mutex_lock(&kvm->irq_lock);
3282 kvm_ioapic_destroy(kvm); 3333 kvm_ioapic_destroy(kvm);
3283 kvm_destroy_pic(kvm); 3334 kvm_destroy_pic(kvm);
3284 mutex_unlock(&kvm->irq_lock); 3335 mutex_unlock(&kvm->irq_lock);
3336 mutex_unlock(&kvm->slots_lock);
3285 } 3337 }
3286 create_irqchip_unlock: 3338 create_irqchip_unlock:
3287 mutex_unlock(&kvm->lock); 3339 mutex_unlock(&kvm->lock);
@@ -3557,63 +3609,63 @@ static gpa_t translate_gpa(struct kvm_vcpu *vcpu, gpa_t gpa, u32 access)
3557static gpa_t translate_nested_gpa(struct kvm_vcpu *vcpu, gpa_t gpa, u32 access) 3609static gpa_t translate_nested_gpa(struct kvm_vcpu *vcpu, gpa_t gpa, u32 access)
3558{ 3610{
3559 gpa_t t_gpa; 3611 gpa_t t_gpa;
3560 u32 error; 3612 struct x86_exception exception;
3561 3613
3562 BUG_ON(!mmu_is_nested(vcpu)); 3614 BUG_ON(!mmu_is_nested(vcpu));
3563 3615
3564 /* NPT walks are always user-walks */ 3616 /* NPT walks are always user-walks */
3565 access |= PFERR_USER_MASK; 3617 access |= PFERR_USER_MASK;
3566 t_gpa = vcpu->arch.mmu.gva_to_gpa(vcpu, gpa, access, &error); 3618 t_gpa = vcpu->arch.mmu.gva_to_gpa(vcpu, gpa, access, &exception);
3567 if (t_gpa == UNMAPPED_GVA)
3568 vcpu->arch.fault.nested = true;
3569 3619
3570 return t_gpa; 3620 return t_gpa;
3571} 3621}
3572 3622
3573gpa_t kvm_mmu_gva_to_gpa_read(struct kvm_vcpu *vcpu, gva_t gva, u32 *error) 3623gpa_t kvm_mmu_gva_to_gpa_read(struct kvm_vcpu *vcpu, gva_t gva,
3624 struct x86_exception *exception)
3574{ 3625{
3575 u32 access = (kvm_x86_ops->get_cpl(vcpu) == 3) ? PFERR_USER_MASK : 0; 3626 u32 access = (kvm_x86_ops->get_cpl(vcpu) == 3) ? PFERR_USER_MASK : 0;
3576 return vcpu->arch.walk_mmu->gva_to_gpa(vcpu, gva, access, error); 3627 return vcpu->arch.walk_mmu->gva_to_gpa(vcpu, gva, access, exception);
3577} 3628}
3578 3629
3579 gpa_t kvm_mmu_gva_to_gpa_fetch(struct kvm_vcpu *vcpu, gva_t gva, u32 *error) 3630 gpa_t kvm_mmu_gva_to_gpa_fetch(struct kvm_vcpu *vcpu, gva_t gva,
3631 struct x86_exception *exception)
3580{ 3632{
3581 u32 access = (kvm_x86_ops->get_cpl(vcpu) == 3) ? PFERR_USER_MASK : 0; 3633 u32 access = (kvm_x86_ops->get_cpl(vcpu) == 3) ? PFERR_USER_MASK : 0;
3582 access |= PFERR_FETCH_MASK; 3634 access |= PFERR_FETCH_MASK;
3583 return vcpu->arch.walk_mmu->gva_to_gpa(vcpu, gva, access, error); 3635 return vcpu->arch.walk_mmu->gva_to_gpa(vcpu, gva, access, exception);
3584} 3636}
3585 3637
3586gpa_t kvm_mmu_gva_to_gpa_write(struct kvm_vcpu *vcpu, gva_t gva, u32 *error) 3638gpa_t kvm_mmu_gva_to_gpa_write(struct kvm_vcpu *vcpu, gva_t gva,
3639 struct x86_exception *exception)
3587{ 3640{
3588 u32 access = (kvm_x86_ops->get_cpl(vcpu) == 3) ? PFERR_USER_MASK : 0; 3641 u32 access = (kvm_x86_ops->get_cpl(vcpu) == 3) ? PFERR_USER_MASK : 0;
3589 access |= PFERR_WRITE_MASK; 3642 access |= PFERR_WRITE_MASK;
3590 return vcpu->arch.walk_mmu->gva_to_gpa(vcpu, gva, access, error); 3643 return vcpu->arch.walk_mmu->gva_to_gpa(vcpu, gva, access, exception);
3591} 3644}
3592 3645
3593/* uses this to access any guest's mapped memory without checking CPL */ 3646/* uses this to access any guest's mapped memory without checking CPL */
3594gpa_t kvm_mmu_gva_to_gpa_system(struct kvm_vcpu *vcpu, gva_t gva, u32 *error) 3647gpa_t kvm_mmu_gva_to_gpa_system(struct kvm_vcpu *vcpu, gva_t gva,
3648 struct x86_exception *exception)
3595{ 3649{
3596 return vcpu->arch.walk_mmu->gva_to_gpa(vcpu, gva, 0, error); 3650 return vcpu->arch.walk_mmu->gva_to_gpa(vcpu, gva, 0, exception);
3597} 3651}
3598 3652
3599static int kvm_read_guest_virt_helper(gva_t addr, void *val, unsigned int bytes, 3653static int kvm_read_guest_virt_helper(gva_t addr, void *val, unsigned int bytes,
3600 struct kvm_vcpu *vcpu, u32 access, 3654 struct kvm_vcpu *vcpu, u32 access,
3601 u32 *error) 3655 struct x86_exception *exception)
3602{ 3656{
3603 void *data = val; 3657 void *data = val;
3604 int r = X86EMUL_CONTINUE; 3658 int r = X86EMUL_CONTINUE;
3605 3659
3606 while (bytes) { 3660 while (bytes) {
3607 gpa_t gpa = vcpu->arch.walk_mmu->gva_to_gpa(vcpu, addr, access, 3661 gpa_t gpa = vcpu->arch.walk_mmu->gva_to_gpa(vcpu, addr, access,
3608 error); 3662 exception);
3609 unsigned offset = addr & (PAGE_SIZE-1); 3663 unsigned offset = addr & (PAGE_SIZE-1);
3610 unsigned toread = min(bytes, (unsigned)PAGE_SIZE - offset); 3664 unsigned toread = min(bytes, (unsigned)PAGE_SIZE - offset);
3611 int ret; 3665 int ret;
3612 3666
3613 if (gpa == UNMAPPED_GVA) { 3667 if (gpa == UNMAPPED_GVA)
3614 r = X86EMUL_PROPAGATE_FAULT; 3668 return X86EMUL_PROPAGATE_FAULT;
3615 goto out;
3616 }
3617 ret = kvm_read_guest(vcpu->kvm, gpa, data, toread); 3669 ret = kvm_read_guest(vcpu->kvm, gpa, data, toread);
3618 if (ret < 0) { 3670 if (ret < 0) {
3619 r = X86EMUL_IO_NEEDED; 3671 r = X86EMUL_IO_NEEDED;
@@ -3630,31 +3682,35 @@ out:
3630 3682
3631/* used for instruction fetching */ 3683/* used for instruction fetching */
3632static int kvm_fetch_guest_virt(gva_t addr, void *val, unsigned int bytes, 3684static int kvm_fetch_guest_virt(gva_t addr, void *val, unsigned int bytes,
3633 struct kvm_vcpu *vcpu, u32 *error) 3685 struct kvm_vcpu *vcpu,
3686 struct x86_exception *exception)
3634{ 3687{
3635 u32 access = (kvm_x86_ops->get_cpl(vcpu) == 3) ? PFERR_USER_MASK : 0; 3688 u32 access = (kvm_x86_ops->get_cpl(vcpu) == 3) ? PFERR_USER_MASK : 0;
3636 return kvm_read_guest_virt_helper(addr, val, bytes, vcpu, 3689 return kvm_read_guest_virt_helper(addr, val, bytes, vcpu,
3637 access | PFERR_FETCH_MASK, error); 3690 access | PFERR_FETCH_MASK,
3691 exception);
3638} 3692}
3639 3693
3640static int kvm_read_guest_virt(gva_t addr, void *val, unsigned int bytes, 3694static int kvm_read_guest_virt(gva_t addr, void *val, unsigned int bytes,
3641 struct kvm_vcpu *vcpu, u32 *error) 3695 struct kvm_vcpu *vcpu,
3696 struct x86_exception *exception)
3642{ 3697{
3643 u32 access = (kvm_x86_ops->get_cpl(vcpu) == 3) ? PFERR_USER_MASK : 0; 3698 u32 access = (kvm_x86_ops->get_cpl(vcpu) == 3) ? PFERR_USER_MASK : 0;
3644 return kvm_read_guest_virt_helper(addr, val, bytes, vcpu, access, 3699 return kvm_read_guest_virt_helper(addr, val, bytes, vcpu, access,
3645 error); 3700 exception);
3646} 3701}
3647 3702
3648static int kvm_read_guest_virt_system(gva_t addr, void *val, unsigned int bytes, 3703static int kvm_read_guest_virt_system(gva_t addr, void *val, unsigned int bytes,
3649 struct kvm_vcpu *vcpu, u32 *error) 3704 struct kvm_vcpu *vcpu,
3705 struct x86_exception *exception)
3650{ 3706{
3651 return kvm_read_guest_virt_helper(addr, val, bytes, vcpu, 0, error); 3707 return kvm_read_guest_virt_helper(addr, val, bytes, vcpu, 0, exception);
3652} 3708}
3653 3709
3654static int kvm_write_guest_virt_system(gva_t addr, void *val, 3710static int kvm_write_guest_virt_system(gva_t addr, void *val,
3655 unsigned int bytes, 3711 unsigned int bytes,
3656 struct kvm_vcpu *vcpu, 3712 struct kvm_vcpu *vcpu,
3657 u32 *error) 3713 struct x86_exception *exception)
3658{ 3714{
3659 void *data = val; 3715 void *data = val;
3660 int r = X86EMUL_CONTINUE; 3716 int r = X86EMUL_CONTINUE;
@@ -3662,15 +3718,13 @@ static int kvm_write_guest_virt_system(gva_t addr, void *val,
3662 while (bytes) { 3718 while (bytes) {
3663 gpa_t gpa = vcpu->arch.walk_mmu->gva_to_gpa(vcpu, addr, 3719 gpa_t gpa = vcpu->arch.walk_mmu->gva_to_gpa(vcpu, addr,
3664 PFERR_WRITE_MASK, 3720 PFERR_WRITE_MASK,
3665 error); 3721 exception);
3666 unsigned offset = addr & (PAGE_SIZE-1); 3722 unsigned offset = addr & (PAGE_SIZE-1);
3667 unsigned towrite = min(bytes, (unsigned)PAGE_SIZE - offset); 3723 unsigned towrite = min(bytes, (unsigned)PAGE_SIZE - offset);
3668 int ret; 3724 int ret;
3669 3725
3670 if (gpa == UNMAPPED_GVA) { 3726 if (gpa == UNMAPPED_GVA)
3671 r = X86EMUL_PROPAGATE_FAULT; 3727 return X86EMUL_PROPAGATE_FAULT;
3672 goto out;
3673 }
3674 ret = kvm_write_guest(vcpu->kvm, gpa, data, towrite); 3728 ret = kvm_write_guest(vcpu->kvm, gpa, data, towrite);
3675 if (ret < 0) { 3729 if (ret < 0) {
3676 r = X86EMUL_IO_NEEDED; 3730 r = X86EMUL_IO_NEEDED;
@@ -3688,7 +3742,7 @@ out:
3688static int emulator_read_emulated(unsigned long addr, 3742static int emulator_read_emulated(unsigned long addr,
3689 void *val, 3743 void *val,
3690 unsigned int bytes, 3744 unsigned int bytes,
3691 unsigned int *error_code, 3745 struct x86_exception *exception,
3692 struct kvm_vcpu *vcpu) 3746 struct kvm_vcpu *vcpu)
3693{ 3747{
3694 gpa_t gpa; 3748 gpa_t gpa;
@@ -3701,7 +3755,7 @@ static int emulator_read_emulated(unsigned long addr,
3701 return X86EMUL_CONTINUE; 3755 return X86EMUL_CONTINUE;
3702 } 3756 }
3703 3757
3704 gpa = kvm_mmu_gva_to_gpa_read(vcpu, addr, error_code); 3758 gpa = kvm_mmu_gva_to_gpa_read(vcpu, addr, exception);
3705 3759
3706 if (gpa == UNMAPPED_GVA) 3760 if (gpa == UNMAPPED_GVA)
3707 return X86EMUL_PROPAGATE_FAULT; 3761 return X86EMUL_PROPAGATE_FAULT;
@@ -3710,8 +3764,8 @@ static int emulator_read_emulated(unsigned long addr,
3710 if ((gpa & PAGE_MASK) == APIC_DEFAULT_PHYS_BASE) 3764 if ((gpa & PAGE_MASK) == APIC_DEFAULT_PHYS_BASE)
3711 goto mmio; 3765 goto mmio;
3712 3766
3713 if (kvm_read_guest_virt(addr, val, bytes, vcpu, NULL) 3767 if (kvm_read_guest_virt(addr, val, bytes, vcpu, exception)
3714 == X86EMUL_CONTINUE) 3768 == X86EMUL_CONTINUE)
3715 return X86EMUL_CONTINUE; 3769 return X86EMUL_CONTINUE;
3716 3770
3717mmio: 3771mmio:
@@ -3735,7 +3789,7 @@ mmio:
3735} 3789}
3736 3790
3737int emulator_write_phys(struct kvm_vcpu *vcpu, gpa_t gpa, 3791int emulator_write_phys(struct kvm_vcpu *vcpu, gpa_t gpa,
3738 const void *val, int bytes) 3792 const void *val, int bytes)
3739{ 3793{
3740 int ret; 3794 int ret;
3741 3795
@@ -3749,12 +3803,12 @@ int emulator_write_phys(struct kvm_vcpu *vcpu, gpa_t gpa,
3749static int emulator_write_emulated_onepage(unsigned long addr, 3803static int emulator_write_emulated_onepage(unsigned long addr,
3750 const void *val, 3804 const void *val,
3751 unsigned int bytes, 3805 unsigned int bytes,
3752 unsigned int *error_code, 3806 struct x86_exception *exception,
3753 struct kvm_vcpu *vcpu) 3807 struct kvm_vcpu *vcpu)
3754{ 3808{
3755 gpa_t gpa; 3809 gpa_t gpa;
3756 3810
3757 gpa = kvm_mmu_gva_to_gpa_write(vcpu, addr, error_code); 3811 gpa = kvm_mmu_gva_to_gpa_write(vcpu, addr, exception);
3758 3812
3759 if (gpa == UNMAPPED_GVA) 3813 if (gpa == UNMAPPED_GVA)
3760 return X86EMUL_PROPAGATE_FAULT; 3814 return X86EMUL_PROPAGATE_FAULT;
@@ -3787,7 +3841,7 @@ mmio:
3787int emulator_write_emulated(unsigned long addr, 3841int emulator_write_emulated(unsigned long addr,
3788 const void *val, 3842 const void *val,
3789 unsigned int bytes, 3843 unsigned int bytes,
3790 unsigned int *error_code, 3844 struct x86_exception *exception,
3791 struct kvm_vcpu *vcpu) 3845 struct kvm_vcpu *vcpu)
3792{ 3846{
3793 /* Crossing a page boundary? */ 3847 /* Crossing a page boundary? */
@@ -3795,7 +3849,7 @@ int emulator_write_emulated(unsigned long addr,
3795 int rc, now; 3849 int rc, now;
3796 3850
3797 now = -addr & ~PAGE_MASK; 3851 now = -addr & ~PAGE_MASK;
3798 rc = emulator_write_emulated_onepage(addr, val, now, error_code, 3852 rc = emulator_write_emulated_onepage(addr, val, now, exception,
3799 vcpu); 3853 vcpu);
3800 if (rc != X86EMUL_CONTINUE) 3854 if (rc != X86EMUL_CONTINUE)
3801 return rc; 3855 return rc;
@@ -3803,7 +3857,7 @@ int emulator_write_emulated(unsigned long addr,
3803 val += now; 3857 val += now;
3804 bytes -= now; 3858 bytes -= now;
3805 } 3859 }
3806 return emulator_write_emulated_onepage(addr, val, bytes, error_code, 3860 return emulator_write_emulated_onepage(addr, val, bytes, exception,
3807 vcpu); 3861 vcpu);
3808} 3862}
3809 3863
@@ -3821,7 +3875,7 @@ static int emulator_cmpxchg_emulated(unsigned long addr,
3821 const void *old, 3875 const void *old,
3822 const void *new, 3876 const void *new,
3823 unsigned int bytes, 3877 unsigned int bytes,
3824 unsigned int *error_code, 3878 struct x86_exception *exception,
3825 struct kvm_vcpu *vcpu) 3879 struct kvm_vcpu *vcpu)
3826{ 3880{
3827 gpa_t gpa; 3881 gpa_t gpa;
@@ -3879,7 +3933,7 @@ static int emulator_cmpxchg_emulated(unsigned long addr,
3879emul_write: 3933emul_write:
3880 printk_once(KERN_WARNING "kvm: emulating exchange as write\n"); 3934 printk_once(KERN_WARNING "kvm: emulating exchange as write\n");
3881 3935
3882 return emulator_write_emulated(addr, new, bytes, error_code, vcpu); 3936 return emulator_write_emulated(addr, new, bytes, exception, vcpu);
3883} 3937}
3884 3938
3885static int kernel_pio(struct kvm_vcpu *vcpu, void *pd) 3939static int kernel_pio(struct kvm_vcpu *vcpu, void *pd)
@@ -3904,7 +3958,7 @@ static int emulator_pio_in_emulated(int size, unsigned short port, void *val,
3904 if (vcpu->arch.pio.count) 3958 if (vcpu->arch.pio.count)
3905 goto data_avail; 3959 goto data_avail;
3906 3960
3907 trace_kvm_pio(0, port, size, 1); 3961 trace_kvm_pio(0, port, size, count);
3908 3962
3909 vcpu->arch.pio.port = port; 3963 vcpu->arch.pio.port = port;
3910 vcpu->arch.pio.in = 1; 3964 vcpu->arch.pio.in = 1;
@@ -3932,7 +3986,7 @@ static int emulator_pio_out_emulated(int size, unsigned short port,
3932 const void *val, unsigned int count, 3986 const void *val, unsigned int count,
3933 struct kvm_vcpu *vcpu) 3987 struct kvm_vcpu *vcpu)
3934{ 3988{
3935 trace_kvm_pio(1, port, size, 1); 3989 trace_kvm_pio(1, port, size, count);
3936 3990
3937 vcpu->arch.pio.port = port; 3991 vcpu->arch.pio.port = port;
3938 vcpu->arch.pio.in = 0; 3992 vcpu->arch.pio.in = 0;
@@ -3973,13 +4027,15 @@ int kvm_emulate_wbinvd(struct kvm_vcpu *vcpu)
3973 return X86EMUL_CONTINUE; 4027 return X86EMUL_CONTINUE;
3974 4028
3975 if (kvm_x86_ops->has_wbinvd_exit()) { 4029 if (kvm_x86_ops->has_wbinvd_exit()) {
3976 preempt_disable(); 4030 int cpu = get_cpu();
4031
4032 cpumask_set_cpu(cpu, vcpu->arch.wbinvd_dirty_mask);
3977 smp_call_function_many(vcpu->arch.wbinvd_dirty_mask, 4033 smp_call_function_many(vcpu->arch.wbinvd_dirty_mask,
3978 wbinvd_ipi, NULL, 1); 4034 wbinvd_ipi, NULL, 1);
3979 preempt_enable(); 4035 put_cpu();
3980 cpumask_clear(vcpu->arch.wbinvd_dirty_mask); 4036 cpumask_clear(vcpu->arch.wbinvd_dirty_mask);
3981 } 4037 } else
3982 wbinvd(); 4038 wbinvd();
3983 return X86EMUL_CONTINUE; 4039 return X86EMUL_CONTINUE;
3984} 4040}
3985EXPORT_SYMBOL_GPL(kvm_emulate_wbinvd); 4041EXPORT_SYMBOL_GPL(kvm_emulate_wbinvd);
@@ -4019,7 +4075,7 @@ static unsigned long emulator_get_cr(int cr, struct kvm_vcpu *vcpu)
4019 value = vcpu->arch.cr2; 4075 value = vcpu->arch.cr2;
4020 break; 4076 break;
4021 case 3: 4077 case 3:
4022 value = vcpu->arch.cr3; 4078 value = kvm_read_cr3(vcpu);
4023 break; 4079 break;
4024 case 4: 4080 case 4:
4025 value = kvm_read_cr4(vcpu); 4081 value = kvm_read_cr4(vcpu);
@@ -4053,7 +4109,7 @@ static int emulator_set_cr(int cr, unsigned long val, struct kvm_vcpu *vcpu)
4053 res = kvm_set_cr4(vcpu, mk_cr_64(kvm_read_cr4(vcpu), val)); 4109 res = kvm_set_cr4(vcpu, mk_cr_64(kvm_read_cr4(vcpu), val));
4054 break; 4110 break;
4055 case 8: 4111 case 8:
4056 res = __kvm_set_cr8(vcpu, val & 0xfUL); 4112 res = kvm_set_cr8(vcpu, val);
4057 break; 4113 break;
4058 default: 4114 default:
4059 vcpu_printf(vcpu, "%s: unexpected cr %u\n", __func__, cr); 4115 vcpu_printf(vcpu, "%s: unexpected cr %u\n", __func__, cr);
@@ -4206,12 +4262,13 @@ static void toggle_interruptibility(struct kvm_vcpu *vcpu, u32 mask)
4206static void inject_emulated_exception(struct kvm_vcpu *vcpu) 4262static void inject_emulated_exception(struct kvm_vcpu *vcpu)
4207{ 4263{
4208 struct x86_emulate_ctxt *ctxt = &vcpu->arch.emulate_ctxt; 4264 struct x86_emulate_ctxt *ctxt = &vcpu->arch.emulate_ctxt;
4209 if (ctxt->exception == PF_VECTOR) 4265 if (ctxt->exception.vector == PF_VECTOR)
4210 kvm_propagate_fault(vcpu); 4266 kvm_propagate_fault(vcpu, &ctxt->exception);
4211 else if (ctxt->error_code_valid) 4267 else if (ctxt->exception.error_code_valid)
4212 kvm_queue_exception_e(vcpu, ctxt->exception, ctxt->error_code); 4268 kvm_queue_exception_e(vcpu, ctxt->exception.vector,
4269 ctxt->exception.error_code);
4213 else 4270 else
4214 kvm_queue_exception(vcpu, ctxt->exception); 4271 kvm_queue_exception(vcpu, ctxt->exception.vector);
4215} 4272}
4216 4273
4217static void init_emulate_ctxt(struct kvm_vcpu *vcpu) 4274static void init_emulate_ctxt(struct kvm_vcpu *vcpu)
@@ -4267,13 +4324,19 @@ EXPORT_SYMBOL_GPL(kvm_inject_realmode_interrupt);
4267 4324
4268static int handle_emulation_failure(struct kvm_vcpu *vcpu) 4325static int handle_emulation_failure(struct kvm_vcpu *vcpu)
4269{ 4326{
4327 int r = EMULATE_DONE;
4328
4270 ++vcpu->stat.insn_emulation_fail; 4329 ++vcpu->stat.insn_emulation_fail;
4271 trace_kvm_emulate_insn_failed(vcpu); 4330 trace_kvm_emulate_insn_failed(vcpu);
4272 vcpu->run->exit_reason = KVM_EXIT_INTERNAL_ERROR; 4331 if (!is_guest_mode(vcpu)) {
4273 vcpu->run->internal.suberror = KVM_INTERNAL_ERROR_EMULATION; 4332 vcpu->run->exit_reason = KVM_EXIT_INTERNAL_ERROR;
4274 vcpu->run->internal.ndata = 0; 4333 vcpu->run->internal.suberror = KVM_INTERNAL_ERROR_EMULATION;
4334 vcpu->run->internal.ndata = 0;
4335 r = EMULATE_FAIL;
4336 }
4275 kvm_queue_exception(vcpu, UD_VECTOR); 4337 kvm_queue_exception(vcpu, UD_VECTOR);
4276 return EMULATE_FAIL; 4338
4339 return r;
4277} 4340}
4278 4341
4279static bool reexecute_instruction(struct kvm_vcpu *vcpu, gva_t gva) 4342static bool reexecute_instruction(struct kvm_vcpu *vcpu, gva_t gva)
@@ -4302,10 +4365,11 @@ static bool reexecute_instruction(struct kvm_vcpu *vcpu, gva_t gva)
4302 return false; 4365 return false;
4303} 4366}
4304 4367
4305int emulate_instruction(struct kvm_vcpu *vcpu, 4368int x86_emulate_instruction(struct kvm_vcpu *vcpu,
4306 unsigned long cr2, 4369 unsigned long cr2,
4307 u16 error_code, 4370 int emulation_type,
4308 int emulation_type) 4371 void *insn,
4372 int insn_len)
4309{ 4373{
4310 int r; 4374 int r;
4311 struct decode_cache *c = &vcpu->arch.emulate_ctxt.decode; 4375 struct decode_cache *c = &vcpu->arch.emulate_ctxt.decode;
@@ -4323,10 +4387,10 @@ int emulate_instruction(struct kvm_vcpu *vcpu,
4323 if (!(emulation_type & EMULTYPE_NO_DECODE)) { 4387 if (!(emulation_type & EMULTYPE_NO_DECODE)) {
4324 init_emulate_ctxt(vcpu); 4388 init_emulate_ctxt(vcpu);
4325 vcpu->arch.emulate_ctxt.interruptibility = 0; 4389 vcpu->arch.emulate_ctxt.interruptibility = 0;
4326 vcpu->arch.emulate_ctxt.exception = -1; 4390 vcpu->arch.emulate_ctxt.have_exception = false;
4327 vcpu->arch.emulate_ctxt.perm_ok = false; 4391 vcpu->arch.emulate_ctxt.perm_ok = false;
4328 4392
4329 r = x86_decode_insn(&vcpu->arch.emulate_ctxt); 4393 r = x86_decode_insn(&vcpu->arch.emulate_ctxt, insn, insn_len);
4330 if (r == X86EMUL_PROPAGATE_FAULT) 4394 if (r == X86EMUL_PROPAGATE_FAULT)
4331 goto done; 4395 goto done;
4332 4396
@@ -4389,7 +4453,7 @@ restart:
4389 } 4453 }
4390 4454
4391done: 4455done:
4392 if (vcpu->arch.emulate_ctxt.exception >= 0) { 4456 if (vcpu->arch.emulate_ctxt.have_exception) {
4393 inject_emulated_exception(vcpu); 4457 inject_emulated_exception(vcpu);
4394 r = EMULATE_DONE; 4458 r = EMULATE_DONE;
4395 } else if (vcpu->arch.pio.count) { 4459 } else if (vcpu->arch.pio.count) {
@@ -4413,7 +4477,7 @@ done:
4413 4477
4414 return r; 4478 return r;
4415} 4479}
4416EXPORT_SYMBOL_GPL(emulate_instruction); 4480EXPORT_SYMBOL_GPL(x86_emulate_instruction);
4417 4481
4418int kvm_fast_pio_out(struct kvm_vcpu *vcpu, int size, unsigned short port) 4482int kvm_fast_pio_out(struct kvm_vcpu *vcpu, int size, unsigned short port)
4419{ 4483{
@@ -4653,7 +4717,6 @@ int kvm_arch_init(void *opaque)
4653 4717
4654 kvm_x86_ops = ops; 4718 kvm_x86_ops = ops;
4655 kvm_mmu_set_nonpresent_ptes(0ull, 0ull); 4719 kvm_mmu_set_nonpresent_ptes(0ull, 0ull);
4656 kvm_mmu_set_base_ptes(PT_PRESENT_MASK);
4657 kvm_mmu_set_mask_ptes(PT_USER_MASK, PT_ACCESSED_MASK, 4720 kvm_mmu_set_mask_ptes(PT_USER_MASK, PT_ACCESSED_MASK,
4658 PT_DIRTY_MASK, PT64_NX_MASK, 0); 4721 PT_DIRTY_MASK, PT64_NX_MASK, 0);
4659 4722
@@ -5116,6 +5179,12 @@ static int vcpu_enter_guest(struct kvm_vcpu *vcpu)
5116 vcpu->fpu_active = 0; 5179 vcpu->fpu_active = 0;
5117 kvm_x86_ops->fpu_deactivate(vcpu); 5180 kvm_x86_ops->fpu_deactivate(vcpu);
5118 } 5181 }
5182 if (kvm_check_request(KVM_REQ_APF_HALT, vcpu)) {
5183 /* Page is swapped out. Do synthetic halt */
5184 vcpu->arch.apf.halted = true;
5185 r = 1;
5186 goto out;
5187 }
5119 } 5188 }
5120 5189
5121 r = kvm_mmu_reload(vcpu); 5190 r = kvm_mmu_reload(vcpu);
@@ -5244,7 +5313,8 @@ static int __vcpu_run(struct kvm_vcpu *vcpu)
5244 5313
5245 r = 1; 5314 r = 1;
5246 while (r > 0) { 5315 while (r > 0) {
5247 if (vcpu->arch.mp_state == KVM_MP_STATE_RUNNABLE) 5316 if (vcpu->arch.mp_state == KVM_MP_STATE_RUNNABLE &&
5317 !vcpu->arch.apf.halted)
5248 r = vcpu_enter_guest(vcpu); 5318 r = vcpu_enter_guest(vcpu);
5249 else { 5319 else {
5250 srcu_read_unlock(&kvm->srcu, vcpu->srcu_idx); 5320 srcu_read_unlock(&kvm->srcu, vcpu->srcu_idx);
@@ -5257,6 +5327,7 @@ static int __vcpu_run(struct kvm_vcpu *vcpu)
5257 vcpu->arch.mp_state = 5327 vcpu->arch.mp_state =
5258 KVM_MP_STATE_RUNNABLE; 5328 KVM_MP_STATE_RUNNABLE;
5259 case KVM_MP_STATE_RUNNABLE: 5329 case KVM_MP_STATE_RUNNABLE:
5330 vcpu->arch.apf.halted = false;
5260 break; 5331 break;
5261 case KVM_MP_STATE_SIPI_RECEIVED: 5332 case KVM_MP_STATE_SIPI_RECEIVED:
5262 default: 5333 default:
@@ -5278,6 +5349,9 @@ static int __vcpu_run(struct kvm_vcpu *vcpu)
5278 vcpu->run->exit_reason = KVM_EXIT_INTR; 5349 vcpu->run->exit_reason = KVM_EXIT_INTR;
5279 ++vcpu->stat.request_irq_exits; 5350 ++vcpu->stat.request_irq_exits;
5280 } 5351 }
5352
5353 kvm_check_async_pf_completion(vcpu);
5354
5281 if (signal_pending(current)) { 5355 if (signal_pending(current)) {
5282 r = -EINTR; 5356 r = -EINTR;
5283 vcpu->run->exit_reason = KVM_EXIT_INTR; 5357 vcpu->run->exit_reason = KVM_EXIT_INTR;
@@ -5302,6 +5376,9 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run)
5302 int r; 5376 int r;
5303 sigset_t sigsaved; 5377 sigset_t sigsaved;
5304 5378
5379 if (!tsk_used_math(current) && init_fpu(current))
5380 return -ENOMEM;
5381
5305 if (vcpu->sigset_active) 5382 if (vcpu->sigset_active)
5306 sigprocmask(SIG_SETMASK, &vcpu->sigset, &sigsaved); 5383 sigprocmask(SIG_SETMASK, &vcpu->sigset, &sigsaved);
5307 5384
@@ -5313,8 +5390,12 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run)
5313 } 5390 }
5314 5391
5315 /* re-sync apic's tpr */ 5392 /* re-sync apic's tpr */
5316 if (!irqchip_in_kernel(vcpu->kvm)) 5393 if (!irqchip_in_kernel(vcpu->kvm)) {
5317 kvm_set_cr8(vcpu, kvm_run->cr8); 5394 if (kvm_set_cr8(vcpu, kvm_run->cr8) != 0) {
5395 r = -EINVAL;
5396 goto out;
5397 }
5398 }
5318 5399
5319 if (vcpu->arch.pio.count || vcpu->mmio_needed) { 5400 if (vcpu->arch.pio.count || vcpu->mmio_needed) {
5320 if (vcpu->mmio_needed) { 5401 if (vcpu->mmio_needed) {
@@ -5323,7 +5404,7 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run)
5323 vcpu->mmio_needed = 0; 5404 vcpu->mmio_needed = 0;
5324 } 5405 }
5325 vcpu->srcu_idx = srcu_read_lock(&vcpu->kvm->srcu); 5406 vcpu->srcu_idx = srcu_read_lock(&vcpu->kvm->srcu);
5326 r = emulate_instruction(vcpu, 0, 0, EMULTYPE_NO_DECODE); 5407 r = emulate_instruction(vcpu, EMULTYPE_NO_DECODE);
5327 srcu_read_unlock(&vcpu->kvm->srcu, vcpu->srcu_idx); 5408 srcu_read_unlock(&vcpu->kvm->srcu, vcpu->srcu_idx);
5328 if (r != EMULATE_DONE) { 5409 if (r != EMULATE_DONE) {
5329 r = 0; 5410 r = 0;
@@ -5436,7 +5517,7 @@ int kvm_arch_vcpu_ioctl_get_sregs(struct kvm_vcpu *vcpu,
5436 5517
5437 sregs->cr0 = kvm_read_cr0(vcpu); 5518 sregs->cr0 = kvm_read_cr0(vcpu);
5438 sregs->cr2 = vcpu->arch.cr2; 5519 sregs->cr2 = vcpu->arch.cr2;
5439 sregs->cr3 = vcpu->arch.cr3; 5520 sregs->cr3 = kvm_read_cr3(vcpu);
5440 sregs->cr4 = kvm_read_cr4(vcpu); 5521 sregs->cr4 = kvm_read_cr4(vcpu);
5441 sregs->cr8 = kvm_get_cr8(vcpu); 5522 sregs->cr8 = kvm_get_cr8(vcpu);
5442 sregs->efer = vcpu->arch.efer; 5523 sregs->efer = vcpu->arch.efer;
@@ -5504,8 +5585,9 @@ int kvm_arch_vcpu_ioctl_set_sregs(struct kvm_vcpu *vcpu,
5504 kvm_x86_ops->set_gdt(vcpu, &dt); 5585 kvm_x86_ops->set_gdt(vcpu, &dt);
5505 5586
5506 vcpu->arch.cr2 = sregs->cr2; 5587 vcpu->arch.cr2 = sregs->cr2;
5507 mmu_reset_needed |= vcpu->arch.cr3 != sregs->cr3; 5588 mmu_reset_needed |= kvm_read_cr3(vcpu) != sregs->cr3;
5508 vcpu->arch.cr3 = sregs->cr3; 5589 vcpu->arch.cr3 = sregs->cr3;
5590 __set_bit(VCPU_EXREG_CR3, (ulong *)&vcpu->arch.regs_avail);
5509 5591
5510 kvm_set_cr8(vcpu, sregs->cr8); 5592 kvm_set_cr8(vcpu, sregs->cr8);
5511 5593
@@ -5522,7 +5604,7 @@ int kvm_arch_vcpu_ioctl_set_sregs(struct kvm_vcpu *vcpu,
5522 if (sregs->cr4 & X86_CR4_OSXSAVE) 5604 if (sregs->cr4 & X86_CR4_OSXSAVE)
5523 update_cpuid(vcpu); 5605 update_cpuid(vcpu);
5524 if (!is_long_mode(vcpu) && is_pae(vcpu)) { 5606 if (!is_long_mode(vcpu) && is_pae(vcpu)) {
5525 load_pdptrs(vcpu, vcpu->arch.walk_mmu, vcpu->arch.cr3); 5607 load_pdptrs(vcpu, vcpu->arch.walk_mmu, kvm_read_cr3(vcpu));
5526 mmu_reset_needed = 1; 5608 mmu_reset_needed = 1;
5527 } 5609 }
5528 5610
@@ -5773,6 +5855,8 @@ free_vcpu:
5773 5855
5774void kvm_arch_vcpu_destroy(struct kvm_vcpu *vcpu) 5856void kvm_arch_vcpu_destroy(struct kvm_vcpu *vcpu)
5775{ 5857{
5858 vcpu->arch.apf.msr_val = 0;
5859
5776 vcpu_load(vcpu); 5860 vcpu_load(vcpu);
5777 kvm_mmu_unload(vcpu); 5861 kvm_mmu_unload(vcpu);
5778 vcpu_put(vcpu); 5862 vcpu_put(vcpu);
@@ -5792,6 +5876,11 @@ int kvm_arch_vcpu_reset(struct kvm_vcpu *vcpu)
5792 vcpu->arch.dr7 = DR7_FIXED_1; 5876 vcpu->arch.dr7 = DR7_FIXED_1;
5793 5877
5794 kvm_make_request(KVM_REQ_EVENT, vcpu); 5878 kvm_make_request(KVM_REQ_EVENT, vcpu);
5879 vcpu->arch.apf.msr_val = 0;
5880
5881 kvm_clear_async_pf_completion_queue(vcpu);
5882 kvm_async_pf_hash_reset(vcpu);
5883 vcpu->arch.apf.halted = false;
5795 5884
5796 return kvm_x86_ops->vcpu_reset(vcpu); 5885 return kvm_x86_ops->vcpu_reset(vcpu);
5797} 5886}
@@ -5881,6 +5970,8 @@ int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu)
5881 if (!zalloc_cpumask_var(&vcpu->arch.wbinvd_dirty_mask, GFP_KERNEL)) 5970 if (!zalloc_cpumask_var(&vcpu->arch.wbinvd_dirty_mask, GFP_KERNEL))
5882 goto fail_free_mce_banks; 5971 goto fail_free_mce_banks;
5883 5972
5973 kvm_async_pf_hash_reset(vcpu);
5974
5884 return 0; 5975 return 0;
5885fail_free_mce_banks: 5976fail_free_mce_banks:
5886 kfree(vcpu->arch.mce_banks); 5977 kfree(vcpu->arch.mce_banks);
@@ -5906,13 +5997,8 @@ void kvm_arch_vcpu_uninit(struct kvm_vcpu *vcpu)
5906 free_page((unsigned long)vcpu->arch.pio_data); 5997 free_page((unsigned long)vcpu->arch.pio_data);
5907} 5998}
5908 5999
5909struct kvm *kvm_arch_create_vm(void) 6000int kvm_arch_init_vm(struct kvm *kvm)
5910{ 6001{
5911 struct kvm *kvm = kzalloc(sizeof(struct kvm), GFP_KERNEL);
5912
5913 if (!kvm)
5914 return ERR_PTR(-ENOMEM);
5915
5916 INIT_LIST_HEAD(&kvm->arch.active_mmu_pages); 6002 INIT_LIST_HEAD(&kvm->arch.active_mmu_pages);
5917 INIT_LIST_HEAD(&kvm->arch.assigned_dev_head); 6003 INIT_LIST_HEAD(&kvm->arch.assigned_dev_head);
5918 6004
@@ -5921,7 +6007,7 @@ struct kvm *kvm_arch_create_vm(void)
5921 6007
5922 spin_lock_init(&kvm->arch.tsc_write_lock); 6008 spin_lock_init(&kvm->arch.tsc_write_lock);
5923 6009
5924 return kvm; 6010 return 0;
5925} 6011}
5926 6012
5927static void kvm_unload_vcpu_mmu(struct kvm_vcpu *vcpu) 6013static void kvm_unload_vcpu_mmu(struct kvm_vcpu *vcpu)
@@ -5939,8 +6025,10 @@ static void kvm_free_vcpus(struct kvm *kvm)
5939 /* 6025 /*
5940 * Unpin any mmu pages first. 6026 * Unpin any mmu pages first.
5941 */ 6027 */
5942 kvm_for_each_vcpu(i, vcpu, kvm) 6028 kvm_for_each_vcpu(i, vcpu, kvm) {
6029 kvm_clear_async_pf_completion_queue(vcpu);
5943 kvm_unload_vcpu_mmu(vcpu); 6030 kvm_unload_vcpu_mmu(vcpu);
6031 }
5944 kvm_for_each_vcpu(i, vcpu, kvm) 6032 kvm_for_each_vcpu(i, vcpu, kvm)
5945 kvm_arch_vcpu_free(vcpu); 6033 kvm_arch_vcpu_free(vcpu);
5946 6034
@@ -5964,13 +6052,10 @@ void kvm_arch_destroy_vm(struct kvm *kvm)
5964 kfree(kvm->arch.vpic); 6052 kfree(kvm->arch.vpic);
5965 kfree(kvm->arch.vioapic); 6053 kfree(kvm->arch.vioapic);
5966 kvm_free_vcpus(kvm); 6054 kvm_free_vcpus(kvm);
5967 kvm_free_physmem(kvm);
5968 if (kvm->arch.apic_access_page) 6055 if (kvm->arch.apic_access_page)
5969 put_page(kvm->arch.apic_access_page); 6056 put_page(kvm->arch.apic_access_page);
5970 if (kvm->arch.ept_identity_pagetable) 6057 if (kvm->arch.ept_identity_pagetable)
5971 put_page(kvm->arch.ept_identity_pagetable); 6058 put_page(kvm->arch.ept_identity_pagetable);
5972 cleanup_srcu_struct(&kvm->srcu);
5973 kfree(kvm);
5974} 6059}
5975 6060
5976int kvm_arch_prepare_memory_region(struct kvm *kvm, 6061int kvm_arch_prepare_memory_region(struct kvm *kvm,
@@ -6051,7 +6136,9 @@ void kvm_arch_flush_shadow(struct kvm *kvm)
6051 6136
6052int kvm_arch_vcpu_runnable(struct kvm_vcpu *vcpu) 6137int kvm_arch_vcpu_runnable(struct kvm_vcpu *vcpu)
6053{ 6138{
6054 return vcpu->arch.mp_state == KVM_MP_STATE_RUNNABLE 6139 return (vcpu->arch.mp_state == KVM_MP_STATE_RUNNABLE &&
6140 !vcpu->arch.apf.halted)
6141 || !list_empty_careful(&vcpu->async_pf.done)
6055 || vcpu->arch.mp_state == KVM_MP_STATE_SIPI_RECEIVED 6142 || vcpu->arch.mp_state == KVM_MP_STATE_SIPI_RECEIVED
6056 || vcpu->arch.nmi_pending || 6143 || vcpu->arch.nmi_pending ||
6057 (kvm_arch_interrupt_allowed(vcpu) && 6144 (kvm_arch_interrupt_allowed(vcpu) &&
@@ -6110,6 +6197,147 @@ void kvm_set_rflags(struct kvm_vcpu *vcpu, unsigned long rflags)
6110} 6197}
6111EXPORT_SYMBOL_GPL(kvm_set_rflags); 6198EXPORT_SYMBOL_GPL(kvm_set_rflags);
6112 6199
6200void kvm_arch_async_page_ready(struct kvm_vcpu *vcpu, struct kvm_async_pf *work)
6201{
6202 int r;
6203
6204 if ((vcpu->arch.mmu.direct_map != work->arch.direct_map) ||
6205 is_error_page(work->page))
6206 return;
6207
6208 r = kvm_mmu_reload(vcpu);
6209 if (unlikely(r))
6210 return;
6211
6212 if (!vcpu->arch.mmu.direct_map &&
6213 work->arch.cr3 != vcpu->arch.mmu.get_cr3(vcpu))
6214 return;
6215
6216 vcpu->arch.mmu.page_fault(vcpu, work->gva, 0, true);
6217}
6218
6219static inline u32 kvm_async_pf_hash_fn(gfn_t gfn)
6220{
6221 return hash_32(gfn & 0xffffffff, order_base_2(ASYNC_PF_PER_VCPU));
6222}
6223
6224static inline u32 kvm_async_pf_next_probe(u32 key)
6225{
6226 return (key + 1) & (roundup_pow_of_two(ASYNC_PF_PER_VCPU) - 1);
6227}
6228
6229static void kvm_add_async_pf_gfn(struct kvm_vcpu *vcpu, gfn_t gfn)
6230{
6231 u32 key = kvm_async_pf_hash_fn(gfn);
6232
6233 while (vcpu->arch.apf.gfns[key] != ~0)
6234 key = kvm_async_pf_next_probe(key);
6235
6236 vcpu->arch.apf.gfns[key] = gfn;
6237}
6238
6239static u32 kvm_async_pf_gfn_slot(struct kvm_vcpu *vcpu, gfn_t gfn)
6240{
6241 int i;
6242 u32 key = kvm_async_pf_hash_fn(gfn);
6243
6244 for (i = 0; i < roundup_pow_of_two(ASYNC_PF_PER_VCPU) &&
6245 (vcpu->arch.apf.gfns[key] != gfn &&
6246 vcpu->arch.apf.gfns[key] != ~0); i++)
6247 key = kvm_async_pf_next_probe(key);
6248
6249 return key;
6250}
6251
6252bool kvm_find_async_pf_gfn(struct kvm_vcpu *vcpu, gfn_t gfn)
6253{
6254 return vcpu->arch.apf.gfns[kvm_async_pf_gfn_slot(vcpu, gfn)] == gfn;
6255}
6256
6257static void kvm_del_async_pf_gfn(struct kvm_vcpu *vcpu, gfn_t gfn)
6258{
6259 u32 i, j, k;
6260
6261 i = j = kvm_async_pf_gfn_slot(vcpu, gfn);
6262 while (true) {
6263 vcpu->arch.apf.gfns[i] = ~0;
6264 do {
6265 j = kvm_async_pf_next_probe(j);
6266 if (vcpu->arch.apf.gfns[j] == ~0)
6267 return;
6268 k = kvm_async_pf_hash_fn(vcpu->arch.apf.gfns[j]);
6269 /*
6270 * k lies cyclically in ]i,j]
6271 * | i.k.j |
6272 * |....j i.k.| or |.k..j i...|
6273 */
6274 } while ((i <= j) ? (i < k && k <= j) : (i < k || k <= j));
6275 vcpu->arch.apf.gfns[i] = vcpu->arch.apf.gfns[j];
6276 i = j;
6277 }
6278}
6279
6280static int apf_put_user(struct kvm_vcpu *vcpu, u32 val)
6281{
6282
6283 return kvm_write_guest_cached(vcpu->kvm, &vcpu->arch.apf.data, &val,
6284 sizeof(val));
6285}
6286
6287void kvm_arch_async_page_not_present(struct kvm_vcpu *vcpu,
6288 struct kvm_async_pf *work)
6289{
6290 struct x86_exception fault;
6291
6292 trace_kvm_async_pf_not_present(work->arch.token, work->gva);
6293 kvm_add_async_pf_gfn(vcpu, work->arch.gfn);
6294
6295 if (!(vcpu->arch.apf.msr_val & KVM_ASYNC_PF_ENABLED) ||
6296 (vcpu->arch.apf.send_user_only &&
6297 kvm_x86_ops->get_cpl(vcpu) == 0))
6298 kvm_make_request(KVM_REQ_APF_HALT, vcpu);
6299 else if (!apf_put_user(vcpu, KVM_PV_REASON_PAGE_NOT_PRESENT)) {
6300 fault.vector = PF_VECTOR;
6301 fault.error_code_valid = true;
6302 fault.error_code = 0;
6303 fault.nested_page_fault = false;
6304 fault.address = work->arch.token;
6305 kvm_inject_page_fault(vcpu, &fault);
6306 }
6307}
6308
6309void kvm_arch_async_page_present(struct kvm_vcpu *vcpu,
6310 struct kvm_async_pf *work)
6311{
6312 struct x86_exception fault;
6313
6314 trace_kvm_async_pf_ready(work->arch.token, work->gva);
6315 if (is_error_page(work->page))
6316 work->arch.token = ~0; /* broadcast wakeup */
6317 else
6318 kvm_del_async_pf_gfn(vcpu, work->arch.gfn);
6319
6320 if ((vcpu->arch.apf.msr_val & KVM_ASYNC_PF_ENABLED) &&
6321 !apf_put_user(vcpu, KVM_PV_REASON_PAGE_READY)) {
6322 fault.vector = PF_VECTOR;
6323 fault.error_code_valid = true;
6324 fault.error_code = 0;
6325 fault.nested_page_fault = false;
6326 fault.address = work->arch.token;
6327 kvm_inject_page_fault(vcpu, &fault);
6328 }
6329 vcpu->arch.apf.halted = false;
6330}
6331
6332bool kvm_arch_can_inject_async_page_present(struct kvm_vcpu *vcpu)
6333{
6334 if (!(vcpu->arch.apf.msr_val & KVM_ASYNC_PF_ENABLED))
6335 return true;
6336 else
6337 return !kvm_event_needs_reinjection(vcpu) &&
6338 kvm_x86_ops->interrupt_allowed(vcpu);
6339}
6340
6113EXPORT_TRACEPOINT_SYMBOL_GPL(kvm_exit); 6341EXPORT_TRACEPOINT_SYMBOL_GPL(kvm_exit);
6114EXPORT_TRACEPOINT_SYMBOL_GPL(kvm_inj_virq); 6342EXPORT_TRACEPOINT_SYMBOL_GPL(kvm_inj_virq);
6115EXPORT_TRACEPOINT_SYMBOL_GPL(kvm_page_fault); 6343EXPORT_TRACEPOINT_SYMBOL_GPL(kvm_page_fault);
diff --git a/arch/x86/mm/init_32.c b/arch/x86/mm/init_32.c
index f89b5bb4e93f..c821074b7f0b 100644
--- a/arch/x86/mm/init_32.c
+++ b/arch/x86/mm/init_32.c
@@ -45,6 +45,7 @@
45#include <asm/bugs.h> 45#include <asm/bugs.h>
46#include <asm/tlb.h> 46#include <asm/tlb.h>
47#include <asm/tlbflush.h> 47#include <asm/tlbflush.h>
48#include <asm/olpc_ofw.h>
48#include <asm/pgalloc.h> 49#include <asm/pgalloc.h>
49#include <asm/sections.h> 50#include <asm/sections.h>
50#include <asm/paravirt.h> 51#include <asm/paravirt.h>
@@ -715,6 +716,7 @@ void __init paging_init(void)
715 /* 716 /*
716 * NOTE: at this point the bootmem allocator is fully available. 717 * NOTE: at this point the bootmem allocator is fully available.
717 */ 718 */
719 olpc_dt_build_devicetree();
718 sparse_init(); 720 sparse_init();
719 zone_sizes_init(); 721 zone_sizes_init();
720} 722}
diff --git a/arch/x86/platform/mrst/early_printk_mrst.c b/arch/x86/platform/mrst/early_printk_mrst.c
index 65df603622b2..25bfdbb5b130 100644
--- a/arch/x86/platform/mrst/early_printk_mrst.c
+++ b/arch/x86/platform/mrst/early_printk_mrst.c
@@ -103,7 +103,7 @@ struct dw_spi_reg {
103static unsigned long mrst_spi_paddr = MRST_REGBASE_SPI0; 103static unsigned long mrst_spi_paddr = MRST_REGBASE_SPI0;
104 104
105static u32 *pclk_spi0; 105static u32 *pclk_spi0;
106/* Always contains an accessable address, start with 0 */ 106/* Always contains an accessible address, start with 0 */
107static struct dw_spi_reg *pspi; 107static struct dw_spi_reg *pspi;
108 108
109static struct kmsg_dumper dw_dumper; 109static struct kmsg_dumper dw_dumper;
diff --git a/arch/x86/platform/olpc/Makefile b/arch/x86/platform/olpc/Makefile
index c31b8fcb5a86..e797428b163b 100644
--- a/arch/x86/platform/olpc/Makefile
+++ b/arch/x86/platform/olpc/Makefile
@@ -1,3 +1,4 @@
1obj-$(CONFIG_OLPC) += olpc.o 1obj-$(CONFIG_OLPC) += olpc.o
2obj-$(CONFIG_OLPC_XO1) += olpc-xo1.o 2obj-$(CONFIG_OLPC_XO1) += olpc-xo1.o
3obj-$(CONFIG_OLPC_OPENFIRMWARE) += olpc_ofw.o 3obj-$(CONFIG_OLPC_OPENFIRMWARE) += olpc_ofw.o
4obj-$(CONFIG_OLPC_OPENFIRMWARE_DT) += olpc_dt.o
diff --git a/arch/x86/platform/olpc/olpc_dt.c b/arch/x86/platform/olpc/olpc_dt.c
new file mode 100644
index 000000000000..dab874647530
--- /dev/null
+++ b/arch/x86/platform/olpc/olpc_dt.c
@@ -0,0 +1,183 @@
1/*
2 * OLPC-specific OFW device tree support code.
3 *
4 * Paul Mackerras August 1996.
5 * Copyright (C) 1996-2005 Paul Mackerras.
6 *
7 * Adapted for 64bit PowerPC by Dave Engebretsen and Peter Bergner.
8 * {engebret|bergner}@us.ibm.com
9 *
10 * Adapted for sparc by David S. Miller davem@davemloft.net
11 * Adapted for x86/OLPC by Andres Salomon <dilinger@queued.net>
12 *
13 * This program is free software; you can redistribute it and/or
14 * modify it under the terms of the GNU General Public License
15 * as published by the Free Software Foundation; either version
16 * 2 of the License, or (at your option) any later version.
17 */
18
19#include <linux/kernel.h>
20#include <linux/bootmem.h>
21#include <linux/of.h>
22#include <linux/of_pdt.h>
23#include <asm/olpc_ofw.h>
24
25static phandle __init olpc_dt_getsibling(phandle node)
26{
27 const void *args[] = { (void *)node };
28 void *res[] = { &node };
29
30 if ((s32)node == -1)
31 return 0;
32
33 if (olpc_ofw("peer", args, res) || (s32)node == -1)
34 return 0;
35
36 return node;
37}
38
39static phandle __init olpc_dt_getchild(phandle node)
40{
41 const void *args[] = { (void *)node };
42 void *res[] = { &node };
43
44 if ((s32)node == -1)
45 return 0;
46
47 if (olpc_ofw("child", args, res) || (s32)node == -1) {
48 pr_err("PROM: %s: fetching child failed!\n", __func__);
49 return 0;
50 }
51
52 return node;
53}
54
55static int __init olpc_dt_getproplen(phandle node, const char *prop)
56{
57 const void *args[] = { (void *)node, prop };
58 int len;
59 void *res[] = { &len };
60
61 if ((s32)node == -1)
62 return -1;
63
64 if (olpc_ofw("getproplen", args, res)) {
65 pr_err("PROM: %s: getproplen failed!\n", __func__);
66 return -1;
67 }
68
69 return len;
70}
71
72static int __init olpc_dt_getproperty(phandle node, const char *prop,
73 char *buf, int bufsize)
74{
75 int plen;
76
77 plen = olpc_dt_getproplen(node, prop);
78 if (plen > bufsize || plen < 1) {
79 return -1;
80 } else {
81 const void *args[] = { (void *)node, prop, buf, (void *)plen };
82 void *res[] = { &plen };
83
84 if (olpc_ofw("getprop", args, res)) {
85 pr_err("PROM: %s: getprop failed!\n", __func__);
86 return -1;
87 }
88 }
89
90 return plen;
91}
92
93static int __init olpc_dt_nextprop(phandle node, char *prev, char *buf)
94{
95 const void *args[] = { (void *)node, prev, buf };
96 int success;
97 void *res[] = { &success };
98
99 buf[0] = '\0';
100
101 if ((s32)node == -1)
102 return -1;
103
104 if (olpc_ofw("nextprop", args, res) || success != 1)
105 return -1;
106
107 return 0;
108}
109
110static int __init olpc_dt_pkg2path(phandle node, char *buf,
111 const int buflen, int *len)
112{
113 const void *args[] = { (void *)node, buf, (void *)buflen };
114 void *res[] = { len };
115
116 if ((s32)node == -1)
117 return -1;
118
119 if (olpc_ofw("package-to-path", args, res) || *len < 1)
120 return -1;
121
122 return 0;
123}
124
125static unsigned int prom_early_allocated __initdata;
126
127void * __init prom_early_alloc(unsigned long size)
128{
129 static u8 *mem;
130 static size_t free_mem;
131 void *res;
132
133 if (free_mem < size) {
134 const size_t chunk_size = max(PAGE_SIZE, size);
135
136 /*
137 * To mimimize the number of allocations, grab at least
138 * PAGE_SIZE of memory (that's an arbitrary choice that's
139 * fast enough on the platforms we care about while minimizing
140 * wasted bootmem) and hand off chunks of it to callers.
141 */
142 res = alloc_bootmem(chunk_size);
143 if (!res)
144 return NULL;
145 prom_early_allocated += chunk_size;
146 memset(res, 0, chunk_size);
147 free_mem = chunk_size;
148 mem = res;
149 }
150
151 /* allocate from the local cache */
152 free_mem -= size;
153 res = mem;
154 mem += size;
155 return res;
156}
157
158static struct of_pdt_ops prom_olpc_ops __initdata = {
159 .nextprop = olpc_dt_nextprop,
160 .getproplen = olpc_dt_getproplen,
161 .getproperty = olpc_dt_getproperty,
162 .getchild = olpc_dt_getchild,
163 .getsibling = olpc_dt_getsibling,
164 .pkg2path = olpc_dt_pkg2path,
165};
166
167void __init olpc_dt_build_devicetree(void)
168{
169 phandle root;
170
171 if (!olpc_ofw_is_installed())
172 return;
173
174 root = olpc_dt_getsibling(0);
175 if (!root) {
176 pr_err("PROM: unable to get root node from OFW!\n");
177 return;
178 }
179 of_pdt_build_devicetree(root, &prom_olpc_ops);
180
181 pr_info("PROM DT: Built device tree with %u bytes of memory.\n",
182 prom_early_allocated);
183}
diff --git a/arch/x86/platform/olpc/olpc_ofw.c b/arch/x86/platform/olpc/olpc_ofw.c
index 787320464379..e7604f62870d 100644
--- a/arch/x86/platform/olpc/olpc_ofw.c
+++ b/arch/x86/platform/olpc/olpc_ofw.c
@@ -110,3 +110,8 @@ void __init olpc_ofw_detect(void)
110 (unsigned long)olpc_ofw_cif, (-start) >> 20); 110 (unsigned long)olpc_ofw_cif, (-start) >> 20);
111 reserve_top_address(-start); 111 reserve_top_address(-start);
112} 112}
113
114bool __init olpc_ofw_is_installed(void)
115{
116 return olpc_ofw_cif != NULL;
117}
diff --git a/block/cfq-iosched.c b/block/cfq-iosched.c
index 4cd59b0d7c15..78ee4b1d4e85 100644
--- a/block/cfq-iosched.c
+++ b/block/cfq-iosched.c
@@ -1030,7 +1030,7 @@ cfq_find_alloc_cfqg(struct cfq_data *cfqd, struct cgroup *cgroup, int create)
1030 1030
1031 /* 1031 /*
1032 * Add group onto cgroup list. It might happen that bdi->dev is 1032 * Add group onto cgroup list. It might happen that bdi->dev is
1033 * not initiliazed yet. Initialize this new group without major 1033 * not initialized yet. Initialize this new group without major
1034 * and minor info and this info will be filled in once a new thread 1034 * and minor info and this info will be filled in once a new thread
1035 * comes for IO. See code above. 1035 * comes for IO. See code above.
1036 */ 1036 */
diff --git a/crypto/Kconfig b/crypto/Kconfig
index e4bac29a32e7..4b7cb0e691cd 100644
--- a/crypto/Kconfig
+++ b/crypto/Kconfig
@@ -110,7 +110,6 @@ config CRYPTO_MANAGER_DISABLE_TESTS
110 110
111config CRYPTO_GF128MUL 111config CRYPTO_GF128MUL
112 tristate "GF(2^128) multiplication functions (EXPERIMENTAL)" 112 tristate "GF(2^128) multiplication functions (EXPERIMENTAL)"
113 depends on EXPERIMENTAL
114 help 113 help
115 Efficient table driven implementation of multiplications in the 114 Efficient table driven implementation of multiplications in the
116 field GF(2^128). This is needed by some cypher modes. This 115 field GF(2^128). This is needed by some cypher modes. This
@@ -539,8 +538,9 @@ config CRYPTO_AES_X86_64
539 538
540config CRYPTO_AES_NI_INTEL 539config CRYPTO_AES_NI_INTEL
541 tristate "AES cipher algorithms (AES-NI)" 540 tristate "AES cipher algorithms (AES-NI)"
542 depends on (X86 || UML_X86) && 64BIT 541 depends on (X86 || UML_X86)
543 select CRYPTO_AES_X86_64 542 select CRYPTO_AES_X86_64 if 64BIT
543 select CRYPTO_AES_586 if !64BIT
544 select CRYPTO_CRYPTD 544 select CRYPTO_CRYPTD
545 select CRYPTO_ALGAPI 545 select CRYPTO_ALGAPI
546 select CRYPTO_FPU 546 select CRYPTO_FPU
@@ -563,9 +563,10 @@ config CRYPTO_AES_NI_INTEL
563 563
564 See <http://csrc.nist.gov/encryption/aes/> for more information. 564 See <http://csrc.nist.gov/encryption/aes/> for more information.
565 565
566 In addition to AES cipher algorithm support, the 566 In addition to AES cipher algorithm support, the acceleration
567 acceleration for some popular block cipher mode is supported 567 for some popular block cipher mode is supported too, including
568 too, including ECB, CBC, CTR, LRW, PCBC, XTS. 568 ECB, CBC, LRW, PCBC, XTS. The 64 bit version has additional
569 acceleration for CTR.
569 570
570config CRYPTO_ANUBIS 571config CRYPTO_ANUBIS
571 tristate "Anubis cipher algorithm" 572 tristate "Anubis cipher algorithm"
@@ -841,6 +842,27 @@ config CRYPTO_ANSI_CPRNG
841 ANSI X9.31 A.2.4. Note that this option must be enabled if 842 ANSI X9.31 A.2.4. Note that this option must be enabled if
842 CRYPTO_FIPS is selected 843 CRYPTO_FIPS is selected
843 844
845config CRYPTO_USER_API
846 tristate
847
848config CRYPTO_USER_API_HASH
849 tristate "User-space interface for hash algorithms"
850 depends on NET
851 select CRYPTO_HASH
852 select CRYPTO_USER_API
853 help
854 This option enables the user-spaces interface for hash
855 algorithms.
856
857config CRYPTO_USER_API_SKCIPHER
858 tristate "User-space interface for symmetric key cipher algorithms"
859 depends on NET
860 select CRYPTO_BLKCIPHER
861 select CRYPTO_USER_API
862 help
863 This option enables the user-spaces interface for symmetric
864 key cipher algorithms.
865
844source "drivers/crypto/Kconfig" 866source "drivers/crypto/Kconfig"
845 867
846endif # if CRYPTO 868endif # if CRYPTO
diff --git a/crypto/Makefile b/crypto/Makefile
index 423b7de61f93..e9a399ca69db 100644
--- a/crypto/Makefile
+++ b/crypto/Makefile
@@ -3,32 +3,32 @@
3# 3#
4 4
5obj-$(CONFIG_CRYPTO) += crypto.o 5obj-$(CONFIG_CRYPTO) += crypto.o
6crypto-objs := api.o cipher.o compress.o 6crypto-y := api.o cipher.o compress.o
7 7
8obj-$(CONFIG_CRYPTO_WORKQUEUE) += crypto_wq.o 8obj-$(CONFIG_CRYPTO_WORKQUEUE) += crypto_wq.o
9 9
10obj-$(CONFIG_CRYPTO_FIPS) += fips.o 10obj-$(CONFIG_CRYPTO_FIPS) += fips.o
11 11
12crypto_algapi-$(CONFIG_PROC_FS) += proc.o 12crypto_algapi-$(CONFIG_PROC_FS) += proc.o
13crypto_algapi-objs := algapi.o scatterwalk.o $(crypto_algapi-y) 13crypto_algapi-y := algapi.o scatterwalk.o $(crypto_algapi-y)
14obj-$(CONFIG_CRYPTO_ALGAPI2) += crypto_algapi.o 14obj-$(CONFIG_CRYPTO_ALGAPI2) += crypto_algapi.o
15 15
16obj-$(CONFIG_CRYPTO_AEAD2) += aead.o 16obj-$(CONFIG_CRYPTO_AEAD2) += aead.o
17 17
18crypto_blkcipher-objs := ablkcipher.o 18crypto_blkcipher-y := ablkcipher.o
19crypto_blkcipher-objs += blkcipher.o 19crypto_blkcipher-y += blkcipher.o
20obj-$(CONFIG_CRYPTO_BLKCIPHER2) += crypto_blkcipher.o 20obj-$(CONFIG_CRYPTO_BLKCIPHER2) += crypto_blkcipher.o
21obj-$(CONFIG_CRYPTO_BLKCIPHER2) += chainiv.o 21obj-$(CONFIG_CRYPTO_BLKCIPHER2) += chainiv.o
22obj-$(CONFIG_CRYPTO_BLKCIPHER2) += eseqiv.o 22obj-$(CONFIG_CRYPTO_BLKCIPHER2) += eseqiv.o
23obj-$(CONFIG_CRYPTO_SEQIV) += seqiv.o 23obj-$(CONFIG_CRYPTO_SEQIV) += seqiv.o
24 24
25crypto_hash-objs += ahash.o 25crypto_hash-y += ahash.o
26crypto_hash-objs += shash.o 26crypto_hash-y += shash.o
27obj-$(CONFIG_CRYPTO_HASH2) += crypto_hash.o 27obj-$(CONFIG_CRYPTO_HASH2) += crypto_hash.o
28 28
29obj-$(CONFIG_CRYPTO_PCOMP2) += pcompress.o 29obj-$(CONFIG_CRYPTO_PCOMP2) += pcompress.o
30 30
31cryptomgr-objs := algboss.o testmgr.o 31cryptomgr-y := algboss.o testmgr.o
32 32
33obj-$(CONFIG_CRYPTO_MANAGER2) += cryptomgr.o 33obj-$(CONFIG_CRYPTO_MANAGER2) += cryptomgr.o
34obj-$(CONFIG_CRYPTO_HMAC) += hmac.o 34obj-$(CONFIG_CRYPTO_HMAC) += hmac.o
@@ -85,6 +85,9 @@ obj-$(CONFIG_CRYPTO_RNG2) += krng.o
85obj-$(CONFIG_CRYPTO_ANSI_CPRNG) += ansi_cprng.o 85obj-$(CONFIG_CRYPTO_ANSI_CPRNG) += ansi_cprng.o
86obj-$(CONFIG_CRYPTO_TEST) += tcrypt.o 86obj-$(CONFIG_CRYPTO_TEST) += tcrypt.o
87obj-$(CONFIG_CRYPTO_GHASH) += ghash-generic.o 87obj-$(CONFIG_CRYPTO_GHASH) += ghash-generic.o
88obj-$(CONFIG_CRYPTO_USER_API) += af_alg.o
89obj-$(CONFIG_CRYPTO_USER_API_HASH) += algif_hash.o
90obj-$(CONFIG_CRYPTO_USER_API_SKCIPHER) += algif_skcipher.o
88 91
89# 92#
90# generic algorithms and the async_tx api 93# generic algorithms and the async_tx api
diff --git a/crypto/af_alg.c b/crypto/af_alg.c
new file mode 100644
index 000000000000..940d70cb5c25
--- /dev/null
+++ b/crypto/af_alg.c
@@ -0,0 +1,483 @@
1/*
2 * af_alg: User-space algorithm interface
3 *
4 * This file provides the user-space API for algorithms.
5 *
6 * Copyright (c) 2010 Herbert Xu <herbert@gondor.apana.org.au>
7 *
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by the Free
10 * Software Foundation; either version 2 of the License, or (at your option)
11 * any later version.
12 *
13 */
14
15#include <asm/atomic.h>
16#include <crypto/if_alg.h>
17#include <linux/crypto.h>
18#include <linux/init.h>
19#include <linux/kernel.h>
20#include <linux/list.h>
21#include <linux/module.h>
22#include <linux/net.h>
23#include <linux/rwsem.h>
24
25struct alg_type_list {
26 const struct af_alg_type *type;
27 struct list_head list;
28};
29
30static atomic_long_t alg_memory_allocated;
31
32static struct proto alg_proto = {
33 .name = "ALG",
34 .owner = THIS_MODULE,
35 .memory_allocated = &alg_memory_allocated,
36 .obj_size = sizeof(struct alg_sock),
37};
38
39static LIST_HEAD(alg_types);
40static DECLARE_RWSEM(alg_types_sem);
41
42static const struct af_alg_type *alg_get_type(const char *name)
43{
44 const struct af_alg_type *type = ERR_PTR(-ENOENT);
45 struct alg_type_list *node;
46
47 down_read(&alg_types_sem);
48 list_for_each_entry(node, &alg_types, list) {
49 if (strcmp(node->type->name, name))
50 continue;
51
52 if (try_module_get(node->type->owner))
53 type = node->type;
54 break;
55 }
56 up_read(&alg_types_sem);
57
58 return type;
59}
60
61int af_alg_register_type(const struct af_alg_type *type)
62{
63 struct alg_type_list *node;
64 int err = -EEXIST;
65
66 down_write(&alg_types_sem);
67 list_for_each_entry(node, &alg_types, list) {
68 if (!strcmp(node->type->name, type->name))
69 goto unlock;
70 }
71
72 node = kmalloc(sizeof(*node), GFP_KERNEL);
73 err = -ENOMEM;
74 if (!node)
75 goto unlock;
76
77 type->ops->owner = THIS_MODULE;
78 node->type = type;
79 list_add(&node->list, &alg_types);
80 err = 0;
81
82unlock:
83 up_write(&alg_types_sem);
84
85 return err;
86}
87EXPORT_SYMBOL_GPL(af_alg_register_type);
88
89int af_alg_unregister_type(const struct af_alg_type *type)
90{
91 struct alg_type_list *node;
92 int err = -ENOENT;
93
94 down_write(&alg_types_sem);
95 list_for_each_entry(node, &alg_types, list) {
96 if (strcmp(node->type->name, type->name))
97 continue;
98
99 list_del(&node->list);
100 kfree(node);
101 err = 0;
102 break;
103 }
104 up_write(&alg_types_sem);
105
106 return err;
107}
108EXPORT_SYMBOL_GPL(af_alg_unregister_type);
109
110static void alg_do_release(const struct af_alg_type *type, void *private)
111{
112 if (!type)
113 return;
114
115 type->release(private);
116 module_put(type->owner);
117}
118
119int af_alg_release(struct socket *sock)
120{
121 if (sock->sk)
122 sock_put(sock->sk);
123 return 0;
124}
125EXPORT_SYMBOL_GPL(af_alg_release);
126
127static int alg_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len)
128{
129 struct sock *sk = sock->sk;
130 struct alg_sock *ask = alg_sk(sk);
131 struct sockaddr_alg *sa = (void *)uaddr;
132 const struct af_alg_type *type;
133 void *private;
134
135 if (sock->state == SS_CONNECTED)
136 return -EINVAL;
137
138 if (addr_len != sizeof(*sa))
139 return -EINVAL;
140
141 sa->salg_type[sizeof(sa->salg_type) - 1] = 0;
142 sa->salg_name[sizeof(sa->salg_name) - 1] = 0;
143
144 type = alg_get_type(sa->salg_type);
145 if (IS_ERR(type) && PTR_ERR(type) == -ENOENT) {
146 request_module("algif-%s", sa->salg_type);
147 type = alg_get_type(sa->salg_type);
148 }
149
150 if (IS_ERR(type))
151 return PTR_ERR(type);
152
153 private = type->bind(sa->salg_name, sa->salg_feat, sa->salg_mask);
154 if (IS_ERR(private)) {
155 module_put(type->owner);
156 return PTR_ERR(private);
157 }
158
159 lock_sock(sk);
160
161 swap(ask->type, type);
162 swap(ask->private, private);
163
164 release_sock(sk);
165
166 alg_do_release(type, private);
167
168 return 0;
169}
170
171static int alg_setkey(struct sock *sk, char __user *ukey,
172 unsigned int keylen)
173{
174 struct alg_sock *ask = alg_sk(sk);
175 const struct af_alg_type *type = ask->type;
176 u8 *key;
177 int err;
178
179 key = sock_kmalloc(sk, keylen, GFP_KERNEL);
180 if (!key)
181 return -ENOMEM;
182
183 err = -EFAULT;
184 if (copy_from_user(key, ukey, keylen))
185 goto out;
186
187 err = type->setkey(ask->private, key, keylen);
188
189out:
190 sock_kfree_s(sk, key, keylen);
191
192 return err;
193}
194
195static int alg_setsockopt(struct socket *sock, int level, int optname,
196 char __user *optval, unsigned int optlen)
197{
198 struct sock *sk = sock->sk;
199 struct alg_sock *ask = alg_sk(sk);
200 const struct af_alg_type *type;
201 int err = -ENOPROTOOPT;
202
203 lock_sock(sk);
204 type = ask->type;
205
206 if (level != SOL_ALG || !type)
207 goto unlock;
208
209 switch (optname) {
210 case ALG_SET_KEY:
211 if (sock->state == SS_CONNECTED)
212 goto unlock;
213 if (!type->setkey)
214 goto unlock;
215
216 err = alg_setkey(sk, optval, optlen);
217 }
218
219unlock:
220 release_sock(sk);
221
222 return err;
223}
224
225int af_alg_accept(struct sock *sk, struct socket *newsock)
226{
227 struct alg_sock *ask = alg_sk(sk);
228 const struct af_alg_type *type;
229 struct sock *sk2;
230 int err;
231
232 lock_sock(sk);
233 type = ask->type;
234
235 err = -EINVAL;
236 if (!type)
237 goto unlock;
238
239 sk2 = sk_alloc(sock_net(sk), PF_ALG, GFP_KERNEL, &alg_proto);
240 err = -ENOMEM;
241 if (!sk2)
242 goto unlock;
243
244 sock_init_data(newsock, sk2);
245 sock_graft(sk2, newsock);
246
247 err = type->accept(ask->private, sk2);
248 if (err) {
249 sk_free(sk2);
250 goto unlock;
251 }
252
253 sk2->sk_family = PF_ALG;
254
255 sock_hold(sk);
256 alg_sk(sk2)->parent = sk;
257 alg_sk(sk2)->type = type;
258
259 newsock->ops = type->ops;
260 newsock->state = SS_CONNECTED;
261
262 err = 0;
263
264unlock:
265 release_sock(sk);
266
267 return err;
268}
269EXPORT_SYMBOL_GPL(af_alg_accept);
270
271static int alg_accept(struct socket *sock, struct socket *newsock, int flags)
272{
273 return af_alg_accept(sock->sk, newsock);
274}
275
276static const struct proto_ops alg_proto_ops = {
277 .family = PF_ALG,
278 .owner = THIS_MODULE,
279
280 .connect = sock_no_connect,
281 .socketpair = sock_no_socketpair,
282 .getname = sock_no_getname,
283 .ioctl = sock_no_ioctl,
284 .listen = sock_no_listen,
285 .shutdown = sock_no_shutdown,
286 .getsockopt = sock_no_getsockopt,
287 .mmap = sock_no_mmap,
288 .sendpage = sock_no_sendpage,
289 .sendmsg = sock_no_sendmsg,
290 .recvmsg = sock_no_recvmsg,
291 .poll = sock_no_poll,
292
293 .bind = alg_bind,
294 .release = af_alg_release,
295 .setsockopt = alg_setsockopt,
296 .accept = alg_accept,
297};
298
299static void alg_sock_destruct(struct sock *sk)
300{
301 struct alg_sock *ask = alg_sk(sk);
302
303 alg_do_release(ask->type, ask->private);
304}
305
306static int alg_create(struct net *net, struct socket *sock, int protocol,
307 int kern)
308{
309 struct sock *sk;
310 int err;
311
312 if (sock->type != SOCK_SEQPACKET)
313 return -ESOCKTNOSUPPORT;
314 if (protocol != 0)
315 return -EPROTONOSUPPORT;
316
317 err = -ENOMEM;
318 sk = sk_alloc(net, PF_ALG, GFP_KERNEL, &alg_proto);
319 if (!sk)
320 goto out;
321
322 sock->ops = &alg_proto_ops;
323 sock_init_data(sock, sk);
324
325 sk->sk_family = PF_ALG;
326 sk->sk_destruct = alg_sock_destruct;
327
328 return 0;
329out:
330 return err;
331}
332
333static const struct net_proto_family alg_family = {
334 .family = PF_ALG,
335 .create = alg_create,
336 .owner = THIS_MODULE,
337};
338
339int af_alg_make_sg(struct af_alg_sgl *sgl, void __user *addr, int len,
340 int write)
341{
342 unsigned long from = (unsigned long)addr;
343 unsigned long npages;
344 unsigned off;
345 int err;
346 int i;
347
348 err = -EFAULT;
349 if (!access_ok(write ? VERIFY_READ : VERIFY_WRITE, addr, len))
350 goto out;
351
352 off = from & ~PAGE_MASK;
353 npages = (off + len + PAGE_SIZE - 1) >> PAGE_SHIFT;
354 if (npages > ALG_MAX_PAGES)
355 npages = ALG_MAX_PAGES;
356
357 err = get_user_pages_fast(from, npages, write, sgl->pages);
358 if (err < 0)
359 goto out;
360
361 npages = err;
362 err = -EINVAL;
363 if (WARN_ON(npages == 0))
364 goto out;
365
366 err = 0;
367
368 sg_init_table(sgl->sg, npages);
369
370 for (i = 0; i < npages; i++) {
371 int plen = min_t(int, len, PAGE_SIZE - off);
372
373 sg_set_page(sgl->sg + i, sgl->pages[i], plen, off);
374
375 off = 0;
376 len -= plen;
377 err += plen;
378 }
379
380out:
381 return err;
382}
383EXPORT_SYMBOL_GPL(af_alg_make_sg);
384
385void af_alg_free_sg(struct af_alg_sgl *sgl)
386{
387 int i;
388
389 i = 0;
390 do {
391 put_page(sgl->pages[i]);
392 } while (!sg_is_last(sgl->sg + (i++)));
393}
394EXPORT_SYMBOL_GPL(af_alg_free_sg);
395
396int af_alg_cmsg_send(struct msghdr *msg, struct af_alg_control *con)
397{
398 struct cmsghdr *cmsg;
399
400 for (cmsg = CMSG_FIRSTHDR(msg); cmsg; cmsg = CMSG_NXTHDR(msg, cmsg)) {
401 if (!CMSG_OK(msg, cmsg))
402 return -EINVAL;
403 if (cmsg->cmsg_level != SOL_ALG)
404 continue;
405
406 switch(cmsg->cmsg_type) {
407 case ALG_SET_IV:
408 if (cmsg->cmsg_len < CMSG_LEN(sizeof(*con->iv)))
409 return -EINVAL;
410 con->iv = (void *)CMSG_DATA(cmsg);
411 if (cmsg->cmsg_len < CMSG_LEN(con->iv->ivlen +
412 sizeof(*con->iv)))
413 return -EINVAL;
414 break;
415
416 case ALG_SET_OP:
417 if (cmsg->cmsg_len < CMSG_LEN(sizeof(u32)))
418 return -EINVAL;
419 con->op = *(u32 *)CMSG_DATA(cmsg);
420 break;
421
422 default:
423 return -EINVAL;
424 }
425 }
426
427 return 0;
428}
429EXPORT_SYMBOL_GPL(af_alg_cmsg_send);
430
431int af_alg_wait_for_completion(int err, struct af_alg_completion *completion)
432{
433 switch (err) {
434 case -EINPROGRESS:
435 case -EBUSY:
436 wait_for_completion(&completion->completion);
437 INIT_COMPLETION(completion->completion);
438 err = completion->err;
439 break;
440 };
441
442 return err;
443}
444EXPORT_SYMBOL_GPL(af_alg_wait_for_completion);
445
446void af_alg_complete(struct crypto_async_request *req, int err)
447{
448 struct af_alg_completion *completion = req->data;
449
450 completion->err = err;
451 complete(&completion->completion);
452}
453EXPORT_SYMBOL_GPL(af_alg_complete);
454
455static int __init af_alg_init(void)
456{
457 int err = proto_register(&alg_proto, 0);
458
459 if (err)
460 goto out;
461
462 err = sock_register(&alg_family);
463 if (err != 0)
464 goto out_unregister_proto;
465
466out:
467 return err;
468
469out_unregister_proto:
470 proto_unregister(&alg_proto);
471 goto out;
472}
473
474static void __exit af_alg_exit(void)
475{
476 sock_unregister(PF_ALG);
477 proto_unregister(&alg_proto);
478}
479
480module_init(af_alg_init);
481module_exit(af_alg_exit);
482MODULE_LICENSE("GPL");
483MODULE_ALIAS_NETPROTO(AF_ALG);
diff --git a/crypto/algif_hash.c b/crypto/algif_hash.c
new file mode 100644
index 000000000000..62122a1a2f7a
--- /dev/null
+++ b/crypto/algif_hash.c
@@ -0,0 +1,319 @@
1/*
2 * algif_hash: User-space interface for hash algorithms
3 *
4 * This file provides the user-space API for hash algorithms.
5 *
6 * Copyright (c) 2010 Herbert Xu <herbert@gondor.apana.org.au>
7 *
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by the Free
10 * Software Foundation; either version 2 of the License, or (at your option)
11 * any later version.
12 *
13 */
14
15#include <crypto/hash.h>
16#include <crypto/if_alg.h>
17#include <linux/init.h>
18#include <linux/kernel.h>
19#include <linux/mm.h>
20#include <linux/module.h>
21#include <linux/net.h>
22#include <net/sock.h>
23
24struct hash_ctx {
25 struct af_alg_sgl sgl;
26
27 u8 *result;
28
29 struct af_alg_completion completion;
30
31 unsigned int len;
32 bool more;
33
34 struct ahash_request req;
35};
36
37static int hash_sendmsg(struct kiocb *unused, struct socket *sock,
38 struct msghdr *msg, size_t ignored)
39{
40 int limit = ALG_MAX_PAGES * PAGE_SIZE;
41 struct sock *sk = sock->sk;
42 struct alg_sock *ask = alg_sk(sk);
43 struct hash_ctx *ctx = ask->private;
44 unsigned long iovlen;
45 struct iovec *iov;
46 long copied = 0;
47 int err;
48
49 if (limit > sk->sk_sndbuf)
50 limit = sk->sk_sndbuf;
51
52 lock_sock(sk);
53 if (!ctx->more) {
54 err = crypto_ahash_init(&ctx->req);
55 if (err)
56 goto unlock;
57 }
58
59 ctx->more = 0;
60
61 for (iov = msg->msg_iov, iovlen = msg->msg_iovlen; iovlen > 0;
62 iovlen--, iov++) {
63 unsigned long seglen = iov->iov_len;
64 char __user *from = iov->iov_base;
65
66 while (seglen) {
67 int len = min_t(unsigned long, seglen, limit);
68 int newlen;
69
70 newlen = af_alg_make_sg(&ctx->sgl, from, len, 0);
71 if (newlen < 0)
72 goto unlock;
73
74 ahash_request_set_crypt(&ctx->req, ctx->sgl.sg, NULL,
75 newlen);
76
77 err = af_alg_wait_for_completion(
78 crypto_ahash_update(&ctx->req),
79 &ctx->completion);
80
81 af_alg_free_sg(&ctx->sgl);
82
83 if (err)
84 goto unlock;
85
86 seglen -= newlen;
87 from += newlen;
88 copied += newlen;
89 }
90 }
91
92 err = 0;
93
94 ctx->more = msg->msg_flags & MSG_MORE;
95 if (!ctx->more) {
96 ahash_request_set_crypt(&ctx->req, NULL, ctx->result, 0);
97 err = af_alg_wait_for_completion(crypto_ahash_final(&ctx->req),
98 &ctx->completion);
99 }
100
101unlock:
102 release_sock(sk);
103
104 return err ?: copied;
105}
106
107static ssize_t hash_sendpage(struct socket *sock, struct page *page,
108 int offset, size_t size, int flags)
109{
110 struct sock *sk = sock->sk;
111 struct alg_sock *ask = alg_sk(sk);
112 struct hash_ctx *ctx = ask->private;
113 int err;
114
115 lock_sock(sk);
116 sg_init_table(ctx->sgl.sg, 1);
117 sg_set_page(ctx->sgl.sg, page, size, offset);
118
119 ahash_request_set_crypt(&ctx->req, ctx->sgl.sg, ctx->result, size);
120
121 if (!(flags & MSG_MORE)) {
122 if (ctx->more)
123 err = crypto_ahash_finup(&ctx->req);
124 else
125 err = crypto_ahash_digest(&ctx->req);
126 } else {
127 if (!ctx->more) {
128 err = crypto_ahash_init(&ctx->req);
129 if (err)
130 goto unlock;
131 }
132
133 err = crypto_ahash_update(&ctx->req);
134 }
135
136 err = af_alg_wait_for_completion(err, &ctx->completion);
137 if (err)
138 goto unlock;
139
140 ctx->more = flags & MSG_MORE;
141
142unlock:
143 release_sock(sk);
144
145 return err ?: size;
146}
147
148static int hash_recvmsg(struct kiocb *unused, struct socket *sock,
149 struct msghdr *msg, size_t len, int flags)
150{
151 struct sock *sk = sock->sk;
152 struct alg_sock *ask = alg_sk(sk);
153 struct hash_ctx *ctx = ask->private;
154 unsigned ds = crypto_ahash_digestsize(crypto_ahash_reqtfm(&ctx->req));
155 int err;
156
157 if (len > ds)
158 len = ds;
159 else if (len < ds)
160 msg->msg_flags |= MSG_TRUNC;
161
162 lock_sock(sk);
163 if (ctx->more) {
164 ctx->more = 0;
165 ahash_request_set_crypt(&ctx->req, NULL, ctx->result, 0);
166 err = af_alg_wait_for_completion(crypto_ahash_final(&ctx->req),
167 &ctx->completion);
168 if (err)
169 goto unlock;
170 }
171
172 err = memcpy_toiovec(msg->msg_iov, ctx->result, len);
173
174unlock:
175 release_sock(sk);
176
177 return err ?: len;
178}
179
180static int hash_accept(struct socket *sock, struct socket *newsock, int flags)
181{
182 struct sock *sk = sock->sk;
183 struct alg_sock *ask = alg_sk(sk);
184 struct hash_ctx *ctx = ask->private;
185 struct ahash_request *req = &ctx->req;
186 char state[crypto_ahash_statesize(crypto_ahash_reqtfm(req))];
187 struct sock *sk2;
188 struct alg_sock *ask2;
189 struct hash_ctx *ctx2;
190 int err;
191
192 err = crypto_ahash_export(req, state);
193 if (err)
194 return err;
195
196 err = af_alg_accept(ask->parent, newsock);
197 if (err)
198 return err;
199
200 sk2 = newsock->sk;
201 ask2 = alg_sk(sk2);
202 ctx2 = ask2->private;
203 ctx2->more = 1;
204
205 err = crypto_ahash_import(&ctx2->req, state);
206 if (err) {
207 sock_orphan(sk2);
208 sock_put(sk2);
209 }
210
211 return err;
212}
213
214static struct proto_ops algif_hash_ops = {
215 .family = PF_ALG,
216
217 .connect = sock_no_connect,
218 .socketpair = sock_no_socketpair,
219 .getname = sock_no_getname,
220 .ioctl = sock_no_ioctl,
221 .listen = sock_no_listen,
222 .shutdown = sock_no_shutdown,
223 .getsockopt = sock_no_getsockopt,
224 .mmap = sock_no_mmap,
225 .bind = sock_no_bind,
226 .setsockopt = sock_no_setsockopt,
227 .poll = sock_no_poll,
228
229 .release = af_alg_release,
230 .sendmsg = hash_sendmsg,
231 .sendpage = hash_sendpage,
232 .recvmsg = hash_recvmsg,
233 .accept = hash_accept,
234};
235
236static void *hash_bind(const char *name, u32 type, u32 mask)
237{
238 return crypto_alloc_ahash(name, type, mask);
239}
240
241static void hash_release(void *private)
242{
243 crypto_free_ahash(private);
244}
245
246static int hash_setkey(void *private, const u8 *key, unsigned int keylen)
247{
248 return crypto_ahash_setkey(private, key, keylen);
249}
250
251static void hash_sock_destruct(struct sock *sk)
252{
253 struct alg_sock *ask = alg_sk(sk);
254 struct hash_ctx *ctx = ask->private;
255
256 sock_kfree_s(sk, ctx->result,
257 crypto_ahash_digestsize(crypto_ahash_reqtfm(&ctx->req)));
258 sock_kfree_s(sk, ctx, ctx->len);
259 af_alg_release_parent(sk);
260}
261
262static int hash_accept_parent(void *private, struct sock *sk)
263{
264 struct hash_ctx *ctx;
265 struct alg_sock *ask = alg_sk(sk);
266 unsigned len = sizeof(*ctx) + crypto_ahash_reqsize(private);
267 unsigned ds = crypto_ahash_digestsize(private);
268
269 ctx = sock_kmalloc(sk, len, GFP_KERNEL);
270 if (!ctx)
271 return -ENOMEM;
272
273 ctx->result = sock_kmalloc(sk, ds, GFP_KERNEL);
274 if (!ctx->result) {
275 sock_kfree_s(sk, ctx, len);
276 return -ENOMEM;
277 }
278
279 memset(ctx->result, 0, ds);
280
281 ctx->len = len;
282 ctx->more = 0;
283 af_alg_init_completion(&ctx->completion);
284
285 ask->private = ctx;
286
287 ahash_request_set_tfm(&ctx->req, private);
288 ahash_request_set_callback(&ctx->req, CRYPTO_TFM_REQ_MAY_BACKLOG,
289 af_alg_complete, &ctx->completion);
290
291 sk->sk_destruct = hash_sock_destruct;
292
293 return 0;
294}
295
296static const struct af_alg_type algif_type_hash = {
297 .bind = hash_bind,
298 .release = hash_release,
299 .setkey = hash_setkey,
300 .accept = hash_accept_parent,
301 .ops = &algif_hash_ops,
302 .name = "hash",
303 .owner = THIS_MODULE
304};
305
306static int __init algif_hash_init(void)
307{
308 return af_alg_register_type(&algif_type_hash);
309}
310
311static void __exit algif_hash_exit(void)
312{
313 int err = af_alg_unregister_type(&algif_type_hash);
314 BUG_ON(err);
315}
316
317module_init(algif_hash_init);
318module_exit(algif_hash_exit);
319MODULE_LICENSE("GPL");
diff --git a/crypto/algif_skcipher.c b/crypto/algif_skcipher.c
new file mode 100644
index 000000000000..6a6dfc062d2a
--- /dev/null
+++ b/crypto/algif_skcipher.c
@@ -0,0 +1,632 @@
1/*
2 * algif_skcipher: User-space interface for skcipher algorithms
3 *
4 * This file provides the user-space API for symmetric key ciphers.
5 *
6 * Copyright (c) 2010 Herbert Xu <herbert@gondor.apana.org.au>
7 *
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by the Free
10 * Software Foundation; either version 2 of the License, or (at your option)
11 * any later version.
12 *
13 */
14
15#include <crypto/scatterwalk.h>
16#include <crypto/skcipher.h>
17#include <crypto/if_alg.h>
18#include <linux/init.h>
19#include <linux/list.h>
20#include <linux/kernel.h>
21#include <linux/mm.h>
22#include <linux/module.h>
23#include <linux/net.h>
24#include <net/sock.h>
25
26struct skcipher_sg_list {
27 struct list_head list;
28
29 int cur;
30
31 struct scatterlist sg[0];
32};
33
34struct skcipher_ctx {
35 struct list_head tsgl;
36 struct af_alg_sgl rsgl;
37
38 void *iv;
39
40 struct af_alg_completion completion;
41
42 unsigned used;
43
44 unsigned int len;
45 bool more;
46 bool merge;
47 bool enc;
48
49 struct ablkcipher_request req;
50};
51
52#define MAX_SGL_ENTS ((PAGE_SIZE - sizeof(struct skcipher_sg_list)) / \
53 sizeof(struct scatterlist) - 1)
54
55static inline int skcipher_sndbuf(struct sock *sk)
56{
57 struct alg_sock *ask = alg_sk(sk);
58 struct skcipher_ctx *ctx = ask->private;
59
60 return max_t(int, max_t(int, sk->sk_sndbuf & PAGE_MASK, PAGE_SIZE) -
61 ctx->used, 0);
62}
63
64static inline bool skcipher_writable(struct sock *sk)
65{
66 return PAGE_SIZE <= skcipher_sndbuf(sk);
67}
68
69static int skcipher_alloc_sgl(struct sock *sk)
70{
71 struct alg_sock *ask = alg_sk(sk);
72 struct skcipher_ctx *ctx = ask->private;
73 struct skcipher_sg_list *sgl;
74 struct scatterlist *sg = NULL;
75
76 sgl = list_entry(ctx->tsgl.prev, struct skcipher_sg_list, list);
77 if (!list_empty(&ctx->tsgl))
78 sg = sgl->sg;
79
80 if (!sg || sgl->cur >= MAX_SGL_ENTS) {
81 sgl = sock_kmalloc(sk, sizeof(*sgl) +
82 sizeof(sgl->sg[0]) * (MAX_SGL_ENTS + 1),
83 GFP_KERNEL);
84 if (!sgl)
85 return -ENOMEM;
86
87 sg_init_table(sgl->sg, MAX_SGL_ENTS + 1);
88 sgl->cur = 0;
89
90 if (sg)
91 scatterwalk_sg_chain(sg, MAX_SGL_ENTS + 1, sgl->sg);
92
93 list_add_tail(&sgl->list, &ctx->tsgl);
94 }
95
96 return 0;
97}
98
99static void skcipher_pull_sgl(struct sock *sk, int used)
100{
101 struct alg_sock *ask = alg_sk(sk);
102 struct skcipher_ctx *ctx = ask->private;
103 struct skcipher_sg_list *sgl;
104 struct scatterlist *sg;
105 int i;
106
107 while (!list_empty(&ctx->tsgl)) {
108 sgl = list_first_entry(&ctx->tsgl, struct skcipher_sg_list,
109 list);
110 sg = sgl->sg;
111
112 for (i = 0; i < sgl->cur; i++) {
113 int plen = min_t(int, used, sg[i].length);
114
115 if (!sg_page(sg + i))
116 continue;
117
118 sg[i].length -= plen;
119 sg[i].offset += plen;
120
121 used -= plen;
122 ctx->used -= plen;
123
124 if (sg[i].length)
125 return;
126
127 put_page(sg_page(sg + i));
128 sg_assign_page(sg + i, NULL);
129 }
130
131 list_del(&sgl->list);
132 sock_kfree_s(sk, sgl,
133 sizeof(*sgl) + sizeof(sgl->sg[0]) *
134 (MAX_SGL_ENTS + 1));
135 }
136
137 if (!ctx->used)
138 ctx->merge = 0;
139}
140
141static void skcipher_free_sgl(struct sock *sk)
142{
143 struct alg_sock *ask = alg_sk(sk);
144 struct skcipher_ctx *ctx = ask->private;
145
146 skcipher_pull_sgl(sk, ctx->used);
147}
148
149static int skcipher_wait_for_wmem(struct sock *sk, unsigned flags)
150{
151 long timeout;
152 DEFINE_WAIT(wait);
153 int err = -ERESTARTSYS;
154
155 if (flags & MSG_DONTWAIT)
156 return -EAGAIN;
157
158 set_bit(SOCK_ASYNC_NOSPACE, &sk->sk_socket->flags);
159
160 for (;;) {
161 if (signal_pending(current))
162 break;
163 prepare_to_wait(sk_sleep(sk), &wait, TASK_INTERRUPTIBLE);
164 timeout = MAX_SCHEDULE_TIMEOUT;
165 if (sk_wait_event(sk, &timeout, skcipher_writable(sk))) {
166 err = 0;
167 break;
168 }
169 }
170 finish_wait(sk_sleep(sk), &wait);
171
172 return err;
173}
174
175static void skcipher_wmem_wakeup(struct sock *sk)
176{
177 struct socket_wq *wq;
178
179 if (!skcipher_writable(sk))
180 return;
181
182 rcu_read_lock();
183 wq = rcu_dereference(sk->sk_wq);
184 if (wq_has_sleeper(wq))
185 wake_up_interruptible_sync_poll(&wq->wait, POLLIN |
186 POLLRDNORM |
187 POLLRDBAND);
188 sk_wake_async(sk, SOCK_WAKE_WAITD, POLL_IN);
189 rcu_read_unlock();
190}
191
192static int skcipher_wait_for_data(struct sock *sk, unsigned flags)
193{
194 struct alg_sock *ask = alg_sk(sk);
195 struct skcipher_ctx *ctx = ask->private;
196 long timeout;
197 DEFINE_WAIT(wait);
198 int err = -ERESTARTSYS;
199
200 if (flags & MSG_DONTWAIT) {
201 return -EAGAIN;
202 }
203
204 set_bit(SOCK_ASYNC_WAITDATA, &sk->sk_socket->flags);
205
206 for (;;) {
207 if (signal_pending(current))
208 break;
209 prepare_to_wait(sk_sleep(sk), &wait, TASK_INTERRUPTIBLE);
210 timeout = MAX_SCHEDULE_TIMEOUT;
211 if (sk_wait_event(sk, &timeout, ctx->used)) {
212 err = 0;
213 break;
214 }
215 }
216 finish_wait(sk_sleep(sk), &wait);
217
218 clear_bit(SOCK_ASYNC_WAITDATA, &sk->sk_socket->flags);
219
220 return err;
221}
222
223static void skcipher_data_wakeup(struct sock *sk)
224{
225 struct alg_sock *ask = alg_sk(sk);
226 struct skcipher_ctx *ctx = ask->private;
227 struct socket_wq *wq;
228
229 if (!ctx->used)
230 return;
231
232 rcu_read_lock();
233 wq = rcu_dereference(sk->sk_wq);
234 if (wq_has_sleeper(wq))
235 wake_up_interruptible_sync_poll(&wq->wait, POLLOUT |
236 POLLRDNORM |
237 POLLRDBAND);
238 sk_wake_async(sk, SOCK_WAKE_SPACE, POLL_OUT);
239 rcu_read_unlock();
240}
241
242static int skcipher_sendmsg(struct kiocb *unused, struct socket *sock,
243 struct msghdr *msg, size_t size)
244{
245 struct sock *sk = sock->sk;
246 struct alg_sock *ask = alg_sk(sk);
247 struct skcipher_ctx *ctx = ask->private;
248 struct crypto_ablkcipher *tfm = crypto_ablkcipher_reqtfm(&ctx->req);
249 unsigned ivsize = crypto_ablkcipher_ivsize(tfm);
250 struct skcipher_sg_list *sgl;
251 struct af_alg_control con = {};
252 long copied = 0;
253 bool enc = 0;
254 int err;
255 int i;
256
257 if (msg->msg_controllen) {
258 err = af_alg_cmsg_send(msg, &con);
259 if (err)
260 return err;
261
262 switch (con.op) {
263 case ALG_OP_ENCRYPT:
264 enc = 1;
265 break;
266 case ALG_OP_DECRYPT:
267 enc = 0;
268 break;
269 default:
270 return -EINVAL;
271 }
272
273 if (con.iv && con.iv->ivlen != ivsize)
274 return -EINVAL;
275 }
276
277 err = -EINVAL;
278
279 lock_sock(sk);
280 if (!ctx->more && ctx->used)
281 goto unlock;
282
283 if (!ctx->used) {
284 ctx->enc = enc;
285 if (con.iv)
286 memcpy(ctx->iv, con.iv->iv, ivsize);
287 }
288
289 while (size) {
290 struct scatterlist *sg;
291 unsigned long len = size;
292 int plen;
293
294 if (ctx->merge) {
295 sgl = list_entry(ctx->tsgl.prev,
296 struct skcipher_sg_list, list);
297 sg = sgl->sg + sgl->cur - 1;
298 len = min_t(unsigned long, len,
299 PAGE_SIZE - sg->offset - sg->length);
300
301 err = memcpy_fromiovec(page_address(sg_page(sg)) +
302 sg->offset + sg->length,
303 msg->msg_iov, len);
304 if (err)
305 goto unlock;
306
307 sg->length += len;
308 ctx->merge = (sg->offset + sg->length) &
309 (PAGE_SIZE - 1);
310
311 ctx->used += len;
312 copied += len;
313 size -= len;
314 continue;
315 }
316
317 if (!skcipher_writable(sk)) {
318 err = skcipher_wait_for_wmem(sk, msg->msg_flags);
319 if (err)
320 goto unlock;
321 }
322
323 len = min_t(unsigned long, len, skcipher_sndbuf(sk));
324
325 err = skcipher_alloc_sgl(sk);
326 if (err)
327 goto unlock;
328
329 sgl = list_entry(ctx->tsgl.prev, struct skcipher_sg_list, list);
330 sg = sgl->sg;
331 do {
332 i = sgl->cur;
333 plen = min_t(int, len, PAGE_SIZE);
334
335 sg_assign_page(sg + i, alloc_page(GFP_KERNEL));
336 err = -ENOMEM;
337 if (!sg_page(sg + i))
338 goto unlock;
339
340 err = memcpy_fromiovec(page_address(sg_page(sg + i)),
341 msg->msg_iov, plen);
342 if (err) {
343 __free_page(sg_page(sg + i));
344 sg_assign_page(sg + i, NULL);
345 goto unlock;
346 }
347
348 sg[i].length = plen;
349 len -= plen;
350 ctx->used += plen;
351 copied += plen;
352 size -= plen;
353 sgl->cur++;
354 } while (len && sgl->cur < MAX_SGL_ENTS);
355
356 ctx->merge = plen & (PAGE_SIZE - 1);
357 }
358
359 err = 0;
360
361 ctx->more = msg->msg_flags & MSG_MORE;
362 if (!ctx->more && !list_empty(&ctx->tsgl))
363 sgl = list_entry(ctx->tsgl.prev, struct skcipher_sg_list, list);
364
365unlock:
366 skcipher_data_wakeup(sk);
367 release_sock(sk);
368
369 return copied ?: err;
370}
371
372static ssize_t skcipher_sendpage(struct socket *sock, struct page *page,
373 int offset, size_t size, int flags)
374{
375 struct sock *sk = sock->sk;
376 struct alg_sock *ask = alg_sk(sk);
377 struct skcipher_ctx *ctx = ask->private;
378 struct skcipher_sg_list *sgl;
379 int err = -EINVAL;
380
381 lock_sock(sk);
382 if (!ctx->more && ctx->used)
383 goto unlock;
384
385 if (!size)
386 goto done;
387
388 if (!skcipher_writable(sk)) {
389 err = skcipher_wait_for_wmem(sk, flags);
390 if (err)
391 goto unlock;
392 }
393
394 err = skcipher_alloc_sgl(sk);
395 if (err)
396 goto unlock;
397
398 ctx->merge = 0;
399 sgl = list_entry(ctx->tsgl.prev, struct skcipher_sg_list, list);
400
401 get_page(page);
402 sg_set_page(sgl->sg + sgl->cur, page, size, offset);
403 sgl->cur++;
404 ctx->used += size;
405
406done:
407 ctx->more = flags & MSG_MORE;
408 if (!ctx->more && !list_empty(&ctx->tsgl))
409 sgl = list_entry(ctx->tsgl.prev, struct skcipher_sg_list, list);
410
411unlock:
412 skcipher_data_wakeup(sk);
413 release_sock(sk);
414
415 return err ?: size;
416}
417
418static int skcipher_recvmsg(struct kiocb *unused, struct socket *sock,
419 struct msghdr *msg, size_t ignored, int flags)
420{
421 struct sock *sk = sock->sk;
422 struct alg_sock *ask = alg_sk(sk);
423 struct skcipher_ctx *ctx = ask->private;
424 unsigned bs = crypto_ablkcipher_blocksize(crypto_ablkcipher_reqtfm(
425 &ctx->req));
426 struct skcipher_sg_list *sgl;
427 struct scatterlist *sg;
428 unsigned long iovlen;
429 struct iovec *iov;
430 int err = -EAGAIN;
431 int used;
432 long copied = 0;
433
434 lock_sock(sk);
435 for (iov = msg->msg_iov, iovlen = msg->msg_iovlen; iovlen > 0;
436 iovlen--, iov++) {
437 unsigned long seglen = iov->iov_len;
438 char __user *from = iov->iov_base;
439
440 while (seglen) {
441 sgl = list_first_entry(&ctx->tsgl,
442 struct skcipher_sg_list, list);
443 sg = sgl->sg;
444
445 while (!sg->length)
446 sg++;
447
448 used = ctx->used;
449 if (!used) {
450 err = skcipher_wait_for_data(sk, flags);
451 if (err)
452 goto unlock;
453 }
454
455 used = min_t(unsigned long, used, seglen);
456
457 used = af_alg_make_sg(&ctx->rsgl, from, used, 1);
458 err = used;
459 if (err < 0)
460 goto unlock;
461
462 if (ctx->more || used < ctx->used)
463 used -= used % bs;
464
465 err = -EINVAL;
466 if (!used)
467 goto free;
468
469 ablkcipher_request_set_crypt(&ctx->req, sg,
470 ctx->rsgl.sg, used,
471 ctx->iv);
472
473 err = af_alg_wait_for_completion(
474 ctx->enc ?
475 crypto_ablkcipher_encrypt(&ctx->req) :
476 crypto_ablkcipher_decrypt(&ctx->req),
477 &ctx->completion);
478
479free:
480 af_alg_free_sg(&ctx->rsgl);
481
482 if (err)
483 goto unlock;
484
485 copied += used;
486 from += used;
487 seglen -= used;
488 skcipher_pull_sgl(sk, used);
489 }
490 }
491
492 err = 0;
493
494unlock:
495 skcipher_wmem_wakeup(sk);
496 release_sock(sk);
497
498 return copied ?: err;
499}
500
501
502static unsigned int skcipher_poll(struct file *file, struct socket *sock,
503 poll_table *wait)
504{
505 struct sock *sk = sock->sk;
506 struct alg_sock *ask = alg_sk(sk);
507 struct skcipher_ctx *ctx = ask->private;
508 unsigned int mask;
509
510 sock_poll_wait(file, sk_sleep(sk), wait);
511 mask = 0;
512
513 if (ctx->used)
514 mask |= POLLIN | POLLRDNORM;
515
516 if (skcipher_writable(sk))
517 mask |= POLLOUT | POLLWRNORM | POLLWRBAND;
518
519 return mask;
520}
521
522static struct proto_ops algif_skcipher_ops = {
523 .family = PF_ALG,
524
525 .connect = sock_no_connect,
526 .socketpair = sock_no_socketpair,
527 .getname = sock_no_getname,
528 .ioctl = sock_no_ioctl,
529 .listen = sock_no_listen,
530 .shutdown = sock_no_shutdown,
531 .getsockopt = sock_no_getsockopt,
532 .mmap = sock_no_mmap,
533 .bind = sock_no_bind,
534 .accept = sock_no_accept,
535 .setsockopt = sock_no_setsockopt,
536
537 .release = af_alg_release,
538 .sendmsg = skcipher_sendmsg,
539 .sendpage = skcipher_sendpage,
540 .recvmsg = skcipher_recvmsg,
541 .poll = skcipher_poll,
542};
543
544static void *skcipher_bind(const char *name, u32 type, u32 mask)
545{
546 return crypto_alloc_ablkcipher(name, type, mask);
547}
548
549static void skcipher_release(void *private)
550{
551 crypto_free_ablkcipher(private);
552}
553
554static int skcipher_setkey(void *private, const u8 *key, unsigned int keylen)
555{
556 return crypto_ablkcipher_setkey(private, key, keylen);
557}
558
559static void skcipher_sock_destruct(struct sock *sk)
560{
561 struct alg_sock *ask = alg_sk(sk);
562 struct skcipher_ctx *ctx = ask->private;
563 struct crypto_ablkcipher *tfm = crypto_ablkcipher_reqtfm(&ctx->req);
564
565 skcipher_free_sgl(sk);
566 sock_kfree_s(sk, ctx->iv, crypto_ablkcipher_ivsize(tfm));
567 sock_kfree_s(sk, ctx, ctx->len);
568 af_alg_release_parent(sk);
569}
570
571static int skcipher_accept_parent(void *private, struct sock *sk)
572{
573 struct skcipher_ctx *ctx;
574 struct alg_sock *ask = alg_sk(sk);
575 unsigned int len = sizeof(*ctx) + crypto_ablkcipher_reqsize(private);
576
577 ctx = sock_kmalloc(sk, len, GFP_KERNEL);
578 if (!ctx)
579 return -ENOMEM;
580
581 ctx->iv = sock_kmalloc(sk, crypto_ablkcipher_ivsize(private),
582 GFP_KERNEL);
583 if (!ctx->iv) {
584 sock_kfree_s(sk, ctx, len);
585 return -ENOMEM;
586 }
587
588 memset(ctx->iv, 0, crypto_ablkcipher_ivsize(private));
589
590 INIT_LIST_HEAD(&ctx->tsgl);
591 ctx->len = len;
592 ctx->used = 0;
593 ctx->more = 0;
594 ctx->merge = 0;
595 ctx->enc = 0;
596 af_alg_init_completion(&ctx->completion);
597
598 ask->private = ctx;
599
600 ablkcipher_request_set_tfm(&ctx->req, private);
601 ablkcipher_request_set_callback(&ctx->req, CRYPTO_TFM_REQ_MAY_BACKLOG,
602 af_alg_complete, &ctx->completion);
603
604 sk->sk_destruct = skcipher_sock_destruct;
605
606 return 0;
607}
608
609static const struct af_alg_type algif_type_skcipher = {
610 .bind = skcipher_bind,
611 .release = skcipher_release,
612 .setkey = skcipher_setkey,
613 .accept = skcipher_accept_parent,
614 .ops = &algif_skcipher_ops,
615 .name = "skcipher",
616 .owner = THIS_MODULE
617};
618
619static int __init algif_skcipher_init(void)
620{
621 return af_alg_register_type(&algif_type_skcipher);
622}
623
624static void __exit algif_skcipher_exit(void)
625{
626 int err = af_alg_unregister_type(&algif_type_skcipher);
627 BUG_ON(err);
628}
629
630module_init(algif_skcipher_init);
631module_exit(algif_skcipher_exit);
632MODULE_LICENSE("GPL");
diff --git a/crypto/authenc.c b/crypto/authenc.c
index a5a22cfcd07b..5ef7ba6b6a76 100644
--- a/crypto/authenc.c
+++ b/crypto/authenc.c
@@ -107,20 +107,6 @@ badkey:
107 goto out; 107 goto out;
108} 108}
109 109
110static void authenc_chain(struct scatterlist *head, struct scatterlist *sg,
111 int chain)
112{
113 if (chain) {
114 head->length += sg->length;
115 sg = scatterwalk_sg_next(sg);
116 }
117
118 if (sg)
119 scatterwalk_sg_chain(head, 2, sg);
120 else
121 sg_mark_end(head);
122}
123
124static void authenc_geniv_ahash_update_done(struct crypto_async_request *areq, 110static void authenc_geniv_ahash_update_done(struct crypto_async_request *areq,
125 int err) 111 int err)
126{ 112{
@@ -345,7 +331,7 @@ static int crypto_authenc_genicv(struct aead_request *req, u8 *iv,
345 if (ivsize) { 331 if (ivsize) {
346 sg_init_table(cipher, 2); 332 sg_init_table(cipher, 2);
347 sg_set_buf(cipher, iv, ivsize); 333 sg_set_buf(cipher, iv, ivsize);
348 authenc_chain(cipher, dst, vdst == iv + ivsize); 334 scatterwalk_crypto_chain(cipher, dst, vdst == iv + ivsize, 2);
349 dst = cipher; 335 dst = cipher;
350 cryptlen += ivsize; 336 cryptlen += ivsize;
351 } 337 }
@@ -354,7 +340,7 @@ static int crypto_authenc_genicv(struct aead_request *req, u8 *iv,
354 authenc_ahash_fn = crypto_authenc_ahash; 340 authenc_ahash_fn = crypto_authenc_ahash;
355 sg_init_table(asg, 2); 341 sg_init_table(asg, 2);
356 sg_set_page(asg, sg_page(assoc), assoc->length, assoc->offset); 342 sg_set_page(asg, sg_page(assoc), assoc->length, assoc->offset);
357 authenc_chain(asg, dst, 0); 343 scatterwalk_crypto_chain(asg, dst, 0, 2);
358 dst = asg; 344 dst = asg;
359 cryptlen += req->assoclen; 345 cryptlen += req->assoclen;
360 } 346 }
@@ -499,7 +485,7 @@ static int crypto_authenc_iverify(struct aead_request *req, u8 *iv,
499 if (ivsize) { 485 if (ivsize) {
500 sg_init_table(cipher, 2); 486 sg_init_table(cipher, 2);
501 sg_set_buf(cipher, iv, ivsize); 487 sg_set_buf(cipher, iv, ivsize);
502 authenc_chain(cipher, src, vsrc == iv + ivsize); 488 scatterwalk_crypto_chain(cipher, src, vsrc == iv + ivsize, 2);
503 src = cipher; 489 src = cipher;
504 cryptlen += ivsize; 490 cryptlen += ivsize;
505 } 491 }
@@ -508,7 +494,7 @@ static int crypto_authenc_iverify(struct aead_request *req, u8 *iv,
508 authenc_ahash_fn = crypto_authenc_ahash; 494 authenc_ahash_fn = crypto_authenc_ahash;
509 sg_init_table(asg, 2); 495 sg_init_table(asg, 2);
510 sg_set_page(asg, sg_page(assoc), assoc->length, assoc->offset); 496 sg_set_page(asg, sg_page(assoc), assoc->length, assoc->offset);
511 authenc_chain(asg, src, 0); 497 scatterwalk_crypto_chain(asg, src, 0, 2);
512 src = asg; 498 src = asg;
513 cryptlen += req->assoclen; 499 cryptlen += req->assoclen;
514 } 500 }
diff --git a/crypto/cast5.c b/crypto/cast5.c
index a1d2294b50ad..4a230ddec877 100644
--- a/crypto/cast5.c
+++ b/crypto/cast5.c
@@ -604,36 +604,23 @@ static void cast5_encrypt(struct crypto_tfm *tfm, u8 *outbuf, const u8 *inbuf)
604 * Rounds 3, 6, 9, 12, and 15 use f function Type 3. 604 * Rounds 3, 6, 9, 12, and 15 use f function Type 3.
605 */ 605 */
606 606
607 t = l; l = r; r = t ^ F1(r, Km[0], Kr[0]);
608 t = l; l = r; r = t ^ F2(r, Km[1], Kr[1]);
609 t = l; l = r; r = t ^ F3(r, Km[2], Kr[2]);
610 t = l; l = r; r = t ^ F1(r, Km[3], Kr[3]);
611 t = l; l = r; r = t ^ F2(r, Km[4], Kr[4]);
612 t = l; l = r; r = t ^ F3(r, Km[5], Kr[5]);
613 t = l; l = r; r = t ^ F1(r, Km[6], Kr[6]);
614 t = l; l = r; r = t ^ F2(r, Km[7], Kr[7]);
615 t = l; l = r; r = t ^ F3(r, Km[8], Kr[8]);
616 t = l; l = r; r = t ^ F1(r, Km[9], Kr[9]);
617 t = l; l = r; r = t ^ F2(r, Km[10], Kr[10]);
618 t = l; l = r; r = t ^ F3(r, Km[11], Kr[11]);
607 if (!(c->rr)) { 619 if (!(c->rr)) {
608 t = l; l = r; r = t ^ F1(r, Km[0], Kr[0]);
609 t = l; l = r; r = t ^ F2(r, Km[1], Kr[1]);
610 t = l; l = r; r = t ^ F3(r, Km[2], Kr[2]);
611 t = l; l = r; r = t ^ F1(r, Km[3], Kr[3]);
612 t = l; l = r; r = t ^ F2(r, Km[4], Kr[4]);
613 t = l; l = r; r = t ^ F3(r, Km[5], Kr[5]);
614 t = l; l = r; r = t ^ F1(r, Km[6], Kr[6]);
615 t = l; l = r; r = t ^ F2(r, Km[7], Kr[7]);
616 t = l; l = r; r = t ^ F3(r, Km[8], Kr[8]);
617 t = l; l = r; r = t ^ F1(r, Km[9], Kr[9]);
618 t = l; l = r; r = t ^ F2(r, Km[10], Kr[10]);
619 t = l; l = r; r = t ^ F3(r, Km[11], Kr[11]);
620 t = l; l = r; r = t ^ F1(r, Km[12], Kr[12]); 620 t = l; l = r; r = t ^ F1(r, Km[12], Kr[12]);
621 t = l; l = r; r = t ^ F2(r, Km[13], Kr[13]); 621 t = l; l = r; r = t ^ F2(r, Km[13], Kr[13]);
622 t = l; l = r; r = t ^ F3(r, Km[14], Kr[14]); 622 t = l; l = r; r = t ^ F3(r, Km[14], Kr[14]);
623 t = l; l = r; r = t ^ F1(r, Km[15], Kr[15]); 623 t = l; l = r; r = t ^ F1(r, Km[15], Kr[15]);
624 } else {
625 t = l; l = r; r = t ^ F1(r, Km[0], Kr[0]);
626 t = l; l = r; r = t ^ F2(r, Km[1], Kr[1]);
627 t = l; l = r; r = t ^ F3(r, Km[2], Kr[2]);
628 t = l; l = r; r = t ^ F1(r, Km[3], Kr[3]);
629 t = l; l = r; r = t ^ F2(r, Km[4], Kr[4]);
630 t = l; l = r; r = t ^ F3(r, Km[5], Kr[5]);
631 t = l; l = r; r = t ^ F1(r, Km[6], Kr[6]);
632 t = l; l = r; r = t ^ F2(r, Km[7], Kr[7]);
633 t = l; l = r; r = t ^ F3(r, Km[8], Kr[8]);
634 t = l; l = r; r = t ^ F1(r, Km[9], Kr[9]);
635 t = l; l = r; r = t ^ F2(r, Km[10], Kr[10]);
636 t = l; l = r; r = t ^ F3(r, Km[11], Kr[11]);
637 } 624 }
638 625
639 /* c1...c64 <-- (R16,L16). (Exchange final blocks L16, R16 and 626 /* c1...c64 <-- (R16,L16). (Exchange final blocks L16, R16 and
@@ -663,32 +650,19 @@ static void cast5_decrypt(struct crypto_tfm *tfm, u8 *outbuf, const u8 *inbuf)
663 t = l; l = r; r = t ^ F3(r, Km[14], Kr[14]); 650 t = l; l = r; r = t ^ F3(r, Km[14], Kr[14]);
664 t = l; l = r; r = t ^ F2(r, Km[13], Kr[13]); 651 t = l; l = r; r = t ^ F2(r, Km[13], Kr[13]);
665 t = l; l = r; r = t ^ F1(r, Km[12], Kr[12]); 652 t = l; l = r; r = t ^ F1(r, Km[12], Kr[12]);
666 t = l; l = r; r = t ^ F3(r, Km[11], Kr[11]);
667 t = l; l = r; r = t ^ F2(r, Km[10], Kr[10]);
668 t = l; l = r; r = t ^ F1(r, Km[9], Kr[9]);
669 t = l; l = r; r = t ^ F3(r, Km[8], Kr[8]);
670 t = l; l = r; r = t ^ F2(r, Km[7], Kr[7]);
671 t = l; l = r; r = t ^ F1(r, Km[6], Kr[6]);
672 t = l; l = r; r = t ^ F3(r, Km[5], Kr[5]);
673 t = l; l = r; r = t ^ F2(r, Km[4], Kr[4]);
674 t = l; l = r; r = t ^ F1(r, Km[3], Kr[3]);
675 t = l; l = r; r = t ^ F3(r, Km[2], Kr[2]);
676 t = l; l = r; r = t ^ F2(r, Km[1], Kr[1]);
677 t = l; l = r; r = t ^ F1(r, Km[0], Kr[0]);
678 } else {
679 t = l; l = r; r = t ^ F3(r, Km[11], Kr[11]);
680 t = l; l = r; r = t ^ F2(r, Km[10], Kr[10]);
681 t = l; l = r; r = t ^ F1(r, Km[9], Kr[9]);
682 t = l; l = r; r = t ^ F3(r, Km[8], Kr[8]);
683 t = l; l = r; r = t ^ F2(r, Km[7], Kr[7]);
684 t = l; l = r; r = t ^ F1(r, Km[6], Kr[6]);
685 t = l; l = r; r = t ^ F3(r, Km[5], Kr[5]);
686 t = l; l = r; r = t ^ F2(r, Km[4], Kr[4]);
687 t = l; l = r; r = t ^ F1(r, Km[3], Kr[3]);
688 t = l; l = r; r = t ^ F3(r, Km[2], Kr[2]);
689 t = l; l = r; r = t ^ F2(r, Km[1], Kr[1]);
690 t = l; l = r; r = t ^ F1(r, Km[0], Kr[0]);
691 } 653 }
654 t = l; l = r; r = t ^ F3(r, Km[11], Kr[11]);
655 t = l; l = r; r = t ^ F2(r, Km[10], Kr[10]);
656 t = l; l = r; r = t ^ F1(r, Km[9], Kr[9]);
657 t = l; l = r; r = t ^ F3(r, Km[8], Kr[8]);
658 t = l; l = r; r = t ^ F2(r, Km[7], Kr[7]);
659 t = l; l = r; r = t ^ F1(r, Km[6], Kr[6]);
660 t = l; l = r; r = t ^ F3(r, Km[5], Kr[5]);
661 t = l; l = r; r = t ^ F2(r, Km[4], Kr[4]);
662 t = l; l = r; r = t ^ F1(r, Km[3], Kr[3]);
663 t = l; l = r; r = t ^ F3(r, Km[2], Kr[2]);
664 t = l; l = r; r = t ^ F2(r, Km[1], Kr[1]);
665 t = l; l = r; r = t ^ F1(r, Km[0], Kr[0]);
692 666
693 dst[0] = cpu_to_be32(r); 667 dst[0] = cpu_to_be32(r);
694 dst[1] = cpu_to_be32(l); 668 dst[1] = cpu_to_be32(l);
diff --git a/crypto/crypto_wq.c b/crypto/crypto_wq.c
index fdcf6248f152..b980ee1af459 100644
--- a/crypto/crypto_wq.c
+++ b/crypto/crypto_wq.c
@@ -20,7 +20,8 @@ EXPORT_SYMBOL_GPL(kcrypto_wq);
20 20
21static int __init crypto_wq_init(void) 21static int __init crypto_wq_init(void)
22{ 22{
23 kcrypto_wq = create_workqueue("crypto"); 23 kcrypto_wq = alloc_workqueue("crypto",
24 WQ_MEM_RECLAIM | WQ_CPU_INTENSIVE, 1);
24 if (unlikely(!kcrypto_wq)) 25 if (unlikely(!kcrypto_wq))
25 return -ENOMEM; 26 return -ENOMEM;
26 return 0; 27 return 0;
diff --git a/crypto/deflate.c b/crypto/deflate.c
index 463dc859aa05..cbc7a33a9600 100644
--- a/crypto/deflate.c
+++ b/crypto/deflate.c
@@ -48,12 +48,11 @@ static int deflate_comp_init(struct deflate_ctx *ctx)
48 int ret = 0; 48 int ret = 0;
49 struct z_stream_s *stream = &ctx->comp_stream; 49 struct z_stream_s *stream = &ctx->comp_stream;
50 50
51 stream->workspace = vmalloc(zlib_deflate_workspacesize()); 51 stream->workspace = vzalloc(zlib_deflate_workspacesize());
52 if (!stream->workspace) { 52 if (!stream->workspace) {
53 ret = -ENOMEM; 53 ret = -ENOMEM;
54 goto out; 54 goto out;
55 } 55 }
56 memset(stream->workspace, 0, zlib_deflate_workspacesize());
57 ret = zlib_deflateInit2(stream, DEFLATE_DEF_LEVEL, Z_DEFLATED, 56 ret = zlib_deflateInit2(stream, DEFLATE_DEF_LEVEL, Z_DEFLATED,
58 -DEFLATE_DEF_WINBITS, DEFLATE_DEF_MEMLEVEL, 57 -DEFLATE_DEF_WINBITS, DEFLATE_DEF_MEMLEVEL,
59 Z_DEFAULT_STRATEGY); 58 Z_DEFAULT_STRATEGY);
diff --git a/crypto/eseqiv.c b/crypto/eseqiv.c
index 3ca3b669d5d5..42ce9f570aec 100644
--- a/crypto/eseqiv.c
+++ b/crypto/eseqiv.c
@@ -62,20 +62,6 @@ out:
62 skcipher_givcrypt_complete(req, err); 62 skcipher_givcrypt_complete(req, err);
63} 63}
64 64
65static void eseqiv_chain(struct scatterlist *head, struct scatterlist *sg,
66 int chain)
67{
68 if (chain) {
69 head->length += sg->length;
70 sg = scatterwalk_sg_next(sg);
71 }
72
73 if (sg)
74 scatterwalk_sg_chain(head, 2, sg);
75 else
76 sg_mark_end(head);
77}
78
79static int eseqiv_givencrypt(struct skcipher_givcrypt_request *req) 65static int eseqiv_givencrypt(struct skcipher_givcrypt_request *req)
80{ 66{
81 struct crypto_ablkcipher *geniv = skcipher_givcrypt_reqtfm(req); 67 struct crypto_ablkcipher *geniv = skcipher_givcrypt_reqtfm(req);
@@ -124,13 +110,13 @@ static int eseqiv_givencrypt(struct skcipher_givcrypt_request *req)
124 110
125 sg_init_table(reqctx->src, 2); 111 sg_init_table(reqctx->src, 2);
126 sg_set_buf(reqctx->src, giv, ivsize); 112 sg_set_buf(reqctx->src, giv, ivsize);
127 eseqiv_chain(reqctx->src, osrc, vsrc == giv + ivsize); 113 scatterwalk_crypto_chain(reqctx->src, osrc, vsrc == giv + ivsize, 2);
128 114
129 dst = reqctx->src; 115 dst = reqctx->src;
130 if (osrc != odst) { 116 if (osrc != odst) {
131 sg_init_table(reqctx->dst, 2); 117 sg_init_table(reqctx->dst, 2);
132 sg_set_buf(reqctx->dst, giv, ivsize); 118 sg_set_buf(reqctx->dst, giv, ivsize);
133 eseqiv_chain(reqctx->dst, odst, vdst == giv + ivsize); 119 scatterwalk_crypto_chain(reqctx->dst, odst, vdst == giv + ivsize, 2);
134 120
135 dst = reqctx->dst; 121 dst = reqctx->dst;
136 } 122 }
diff --git a/crypto/gcm.c b/crypto/gcm.c
index 2f5fbba6576c..1a252639ef91 100644
--- a/crypto/gcm.c
+++ b/crypto/gcm.c
@@ -1102,21 +1102,6 @@ static int crypto_rfc4543_setauthsize(struct crypto_aead *parent,
1102 return crypto_aead_setauthsize(ctx->child, authsize); 1102 return crypto_aead_setauthsize(ctx->child, authsize);
1103} 1103}
1104 1104
1105/* this is the same as crypto_authenc_chain */
1106static void crypto_rfc4543_chain(struct scatterlist *head,
1107 struct scatterlist *sg, int chain)
1108{
1109 if (chain) {
1110 head->length += sg->length;
1111 sg = scatterwalk_sg_next(sg);
1112 }
1113
1114 if (sg)
1115 scatterwalk_sg_chain(head, 2, sg);
1116 else
1117 sg_mark_end(head);
1118}
1119
1120static struct aead_request *crypto_rfc4543_crypt(struct aead_request *req, 1105static struct aead_request *crypto_rfc4543_crypt(struct aead_request *req,
1121 int enc) 1106 int enc)
1122{ 1107{
@@ -1154,13 +1139,13 @@ static struct aead_request *crypto_rfc4543_crypt(struct aead_request *req,
1154 1139
1155 sg_init_table(payload, 2); 1140 sg_init_table(payload, 2);
1156 sg_set_buf(payload, req->iv, 8); 1141 sg_set_buf(payload, req->iv, 8);
1157 crypto_rfc4543_chain(payload, dst, vdst == req->iv + 8); 1142 scatterwalk_crypto_chain(payload, dst, vdst == req->iv + 8, 2);
1158 assoclen += 8 + req->cryptlen - (enc ? 0 : authsize); 1143 assoclen += 8 + req->cryptlen - (enc ? 0 : authsize);
1159 1144
1160 sg_init_table(assoc, 2); 1145 sg_init_table(assoc, 2);
1161 sg_set_page(assoc, sg_page(req->assoc), req->assoc->length, 1146 sg_set_page(assoc, sg_page(req->assoc), req->assoc->length,
1162 req->assoc->offset); 1147 req->assoc->offset);
1163 crypto_rfc4543_chain(assoc, payload, 0); 1148 scatterwalk_crypto_chain(assoc, payload, 0, 2);
1164 1149
1165 aead_request_set_tfm(subreq, ctx->child); 1150 aead_request_set_tfm(subreq, ctx->child);
1166 aead_request_set_callback(subreq, req->base.flags, req->base.complete, 1151 aead_request_set_callback(subreq, req->base.flags, req->base.complete,
diff --git a/crypto/pcrypt.c b/crypto/pcrypt.c
index 75586f1f86e7..29a89dad68b6 100644
--- a/crypto/pcrypt.c
+++ b/crypto/pcrypt.c
@@ -455,7 +455,8 @@ static int pcrypt_init_padata(struct padata_pcrypt *pcrypt,
455 455
456 get_online_cpus(); 456 get_online_cpus();
457 457
458 pcrypt->wq = create_workqueue(name); 458 pcrypt->wq = alloc_workqueue(name,
459 WQ_MEM_RECLAIM | WQ_CPU_INTENSIVE, 1);
459 if (!pcrypt->wq) 460 if (!pcrypt->wq)
460 goto err; 461 goto err;
461 462
diff --git a/crypto/rmd128.c b/crypto/rmd128.c
index 1ceb6735aa53..8a0f68b7f257 100644
--- a/crypto/rmd128.c
+++ b/crypto/rmd128.c
@@ -5,7 +5,7 @@
5 * 5 *
6 * Based on the reference implementation by Antoon Bosselaers, ESAT-COSIC 6 * Based on the reference implementation by Antoon Bosselaers, ESAT-COSIC
7 * 7 *
8 * Copyright (c) 2008 Adrian-Ken Rueegsegger <rueegsegger (at) swiss-it.ch> 8 * Copyright (c) 2008 Adrian-Ken Rueegsegger <ken@codelabs.ch>
9 * 9 *
10 * This program is free software; you can redistribute it and/or modify it 10 * This program is free software; you can redistribute it and/or modify it
11 * under the terms of the GNU General Public License as published by the Free 11 * under the terms of the GNU General Public License as published by the Free
@@ -325,4 +325,5 @@ module_init(rmd128_mod_init);
325module_exit(rmd128_mod_fini); 325module_exit(rmd128_mod_fini);
326 326
327MODULE_LICENSE("GPL"); 327MODULE_LICENSE("GPL");
328MODULE_AUTHOR("Adrian-Ken Rueegsegger <ken@codelabs.ch>");
328MODULE_DESCRIPTION("RIPEMD-128 Message Digest"); 329MODULE_DESCRIPTION("RIPEMD-128 Message Digest");
diff --git a/crypto/rmd160.c b/crypto/rmd160.c
index 472261fc913f..525d7bb752cf 100644
--- a/crypto/rmd160.c
+++ b/crypto/rmd160.c
@@ -5,7 +5,7 @@
5 * 5 *
6 * Based on the reference implementation by Antoon Bosselaers, ESAT-COSIC 6 * Based on the reference implementation by Antoon Bosselaers, ESAT-COSIC
7 * 7 *
8 * Copyright (c) 2008 Adrian-Ken Rueegsegger <rueegsegger (at) swiss-it.ch> 8 * Copyright (c) 2008 Adrian-Ken Rueegsegger <ken@codelabs.ch>
9 * 9 *
10 * This program is free software; you can redistribute it and/or modify it 10 * This program is free software; you can redistribute it and/or modify it
11 * under the terms of the GNU General Public License as published by the Free 11 * under the terms of the GNU General Public License as published by the Free
@@ -369,4 +369,5 @@ module_init(rmd160_mod_init);
369module_exit(rmd160_mod_fini); 369module_exit(rmd160_mod_fini);
370 370
371MODULE_LICENSE("GPL"); 371MODULE_LICENSE("GPL");
372MODULE_AUTHOR("Adrian-Ken Rueegsegger <ken@codelabs.ch>");
372MODULE_DESCRIPTION("RIPEMD-160 Message Digest"); 373MODULE_DESCRIPTION("RIPEMD-160 Message Digest");
diff --git a/crypto/rmd256.c b/crypto/rmd256.c
index 72eafa8d2e7b..69293d9b56e0 100644
--- a/crypto/rmd256.c
+++ b/crypto/rmd256.c
@@ -5,7 +5,7 @@
5 * 5 *
6 * Based on the reference implementation by Antoon Bosselaers, ESAT-COSIC 6 * Based on the reference implementation by Antoon Bosselaers, ESAT-COSIC
7 * 7 *
8 * Copyright (c) 2008 Adrian-Ken Rueegsegger <rueegsegger (at) swiss-it.ch> 8 * Copyright (c) 2008 Adrian-Ken Rueegsegger <ken@codelabs.ch>
9 * 9 *
10 * This program is free software; you can redistribute it and/or modify it 10 * This program is free software; you can redistribute it and/or modify it
11 * under the terms of the GNU General Public License as published by the Free 11 * under the terms of the GNU General Public License as published by the Free
@@ -344,4 +344,5 @@ module_init(rmd256_mod_init);
344module_exit(rmd256_mod_fini); 344module_exit(rmd256_mod_fini);
345 345
346MODULE_LICENSE("GPL"); 346MODULE_LICENSE("GPL");
347MODULE_AUTHOR("Adrian-Ken Rueegsegger <ken@codelabs.ch>");
347MODULE_DESCRIPTION("RIPEMD-256 Message Digest"); 348MODULE_DESCRIPTION("RIPEMD-256 Message Digest");
diff --git a/crypto/rmd320.c b/crypto/rmd320.c
index 86becaba2f05..09f97dfdfbba 100644
--- a/crypto/rmd320.c
+++ b/crypto/rmd320.c
@@ -5,7 +5,7 @@
5 * 5 *
6 * Based on the reference implementation by Antoon Bosselaers, ESAT-COSIC 6 * Based on the reference implementation by Antoon Bosselaers, ESAT-COSIC
7 * 7 *
8 * Copyright (c) 2008 Adrian-Ken Rueegsegger <rueegsegger (at) swiss-it.ch> 8 * Copyright (c) 2008 Adrian-Ken Rueegsegger <ken@codelabs.ch>
9 * 9 *
10 * This program is free software; you can redistribute it and/or modify it 10 * This program is free software; you can redistribute it and/or modify it
11 * under the terms of the GNU General Public License as published by the Free 11 * under the terms of the GNU General Public License as published by the Free
@@ -393,4 +393,5 @@ module_init(rmd320_mod_init);
393module_exit(rmd320_mod_fini); 393module_exit(rmd320_mod_fini);
394 394
395MODULE_LICENSE("GPL"); 395MODULE_LICENSE("GPL");
396MODULE_AUTHOR("Adrian-Ken Rueegsegger <ken@codelabs.ch>");
396MODULE_DESCRIPTION("RIPEMD-320 Message Digest"); 397MODULE_DESCRIPTION("RIPEMD-320 Message Digest");
diff --git a/crypto/shash.c b/crypto/shash.c
index 22fd9433141f..76f74b963151 100644
--- a/crypto/shash.c
+++ b/crypto/shash.c
@@ -310,7 +310,13 @@ static int shash_async_export(struct ahash_request *req, void *out)
310 310
311static int shash_async_import(struct ahash_request *req, const void *in) 311static int shash_async_import(struct ahash_request *req, const void *in)
312{ 312{
313 return crypto_shash_import(ahash_request_ctx(req), in); 313 struct crypto_shash **ctx = crypto_ahash_ctx(crypto_ahash_reqtfm(req));
314 struct shash_desc *desc = ahash_request_ctx(req);
315
316 desc->tfm = *ctx;
317 desc->flags = req->base.flags;
318
319 return crypto_shash_import(desc, in);
314} 320}
315 321
316static void crypto_exit_shash_ops_async(struct crypto_tfm *tfm) 322static void crypto_exit_shash_ops_async(struct crypto_tfm *tfm)
diff --git a/crypto/tcrypt.c b/crypto/tcrypt.c
index 3ca68f9fc14d..9aac5e58be94 100644
--- a/crypto/tcrypt.c
+++ b/crypto/tcrypt.c
@@ -8,6 +8,13 @@
8 * Copyright (c) 2002 Jean-Francois Dive <jef@linuxbe.org> 8 * Copyright (c) 2002 Jean-Francois Dive <jef@linuxbe.org>
9 * Copyright (c) 2007 Nokia Siemens Networks 9 * Copyright (c) 2007 Nokia Siemens Networks
10 * 10 *
11 * Updated RFC4106 AES-GCM testing.
12 * Authors: Aidan O'Mahony (aidan.o.mahony@intel.com)
13 * Adrian Hoban <adrian.hoban@intel.com>
14 * Gabriele Paoloni <gabriele.paoloni@intel.com>
15 * Tadeusz Struk (tadeusz.struk@intel.com)
16 * Copyright (c) 2010, Intel Corporation.
17 *
11 * This program is free software; you can redistribute it and/or modify it 18 * This program is free software; you can redistribute it and/or modify it
12 * under the terms of the GNU General Public License as published by the Free 19 * under the terms of the GNU General Public License as published by the Free
13 * Software Foundation; either version 2 of the License, or (at your option) 20 * Software Foundation; either version 2 of the License, or (at your option)
@@ -980,6 +987,10 @@ static int do_test(int m)
980 ret += tcrypt_test("ansi_cprng"); 987 ret += tcrypt_test("ansi_cprng");
981 break; 988 break;
982 989
990 case 151:
991 ret += tcrypt_test("rfc4106(gcm(aes))");
992 break;
993
983 case 200: 994 case 200:
984 test_cipher_speed("ecb(aes)", ENCRYPT, sec, NULL, 0, 995 test_cipher_speed("ecb(aes)", ENCRYPT, sec, NULL, 0,
985 speed_template_16_24_32); 996 speed_template_16_24_32);
diff --git a/crypto/testmgr.c b/crypto/testmgr.c
index fa8c8f78c8d4..27ea9fe9476f 100644
--- a/crypto/testmgr.c
+++ b/crypto/testmgr.c
@@ -6,6 +6,13 @@
6 * Copyright (c) 2007 Nokia Siemens Networks 6 * Copyright (c) 2007 Nokia Siemens Networks
7 * Copyright (c) 2008 Herbert Xu <herbert@gondor.apana.org.au> 7 * Copyright (c) 2008 Herbert Xu <herbert@gondor.apana.org.au>
8 * 8 *
9 * Updated RFC4106 AES-GCM testing.
10 * Authors: Aidan O'Mahony (aidan.o.mahony@intel.com)
11 * Adrian Hoban <adrian.hoban@intel.com>
12 * Gabriele Paoloni <gabriele.paoloni@intel.com>
13 * Tadeusz Struk (tadeusz.struk@intel.com)
14 * Copyright (c) 2010, Intel Corporation.
15 *
9 * This program is free software; you can redistribute it and/or modify it 16 * This program is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU General Public License as published by the Free 17 * under the terms of the GNU General Public License as published by the Free
11 * Software Foundation; either version 2 of the License, or (at your option) 18 * Software Foundation; either version 2 of the License, or (at your option)
@@ -2242,6 +2249,23 @@ static const struct alg_test_desc alg_test_descs[] = {
2242 } 2249 }
2243 } 2250 }
2244 }, { 2251 }, {
2252 .alg = "rfc4106(gcm(aes))",
2253 .test = alg_test_aead,
2254 .suite = {
2255 .aead = {
2256 .enc = {
2257 .vecs = aes_gcm_rfc4106_enc_tv_template,
2258 .count = AES_GCM_4106_ENC_TEST_VECTORS
2259 },
2260 .dec = {
2261 .vecs = aes_gcm_rfc4106_dec_tv_template,
2262 .count = AES_GCM_4106_DEC_TEST_VECTORS
2263 }
2264 }
2265 }
2266 }, {
2267
2268
2245 .alg = "rfc4309(ccm(aes))", 2269 .alg = "rfc4309(ccm(aes))",
2246 .test = alg_test_aead, 2270 .test = alg_test_aead,
2247 .fips_allowed = 1, 2271 .fips_allowed = 1,
diff --git a/crypto/testmgr.h b/crypto/testmgr.h
index 74e35377fd30..834af7f2adee 100644
--- a/crypto/testmgr.h
+++ b/crypto/testmgr.h
@@ -6,6 +6,15 @@
6 * Copyright (c) 2007 Nokia Siemens Networks 6 * Copyright (c) 2007 Nokia Siemens Networks
7 * Copyright (c) 2008 Herbert Xu <herbert@gondor.apana.org.au> 7 * Copyright (c) 2008 Herbert Xu <herbert@gondor.apana.org.au>
8 * 8 *
9 * Updated RFC4106 AES-GCM testing. Some test vectors were taken from
10 * http://csrc.nist.gov/groups/ST/toolkit/BCM/documents/proposedmodes/
11 * gcm/gcm-test-vectors.tar.gz
12 * Authors: Aidan O'Mahony (aidan.o.mahony@intel.com)
13 * Adrian Hoban <adrian.hoban@intel.com>
14 * Gabriele Paoloni <gabriele.paoloni@intel.com>
15 * Tadeusz Struk (tadeusz.struk@intel.com)
16 * Copyright (c) 2010, Intel Corporation.
17 *
9 * This program is free software; you can redistribute it and/or modify it 18 * This program is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU General Public License as published by the Free 19 * under the terms of the GNU General Public License as published by the Free
11 * Software Foundation; either version 2 of the License, or (at your option) 20 * Software Foundation; either version 2 of the License, or (at your option)
@@ -2947,6 +2956,8 @@ static struct cipher_testvec cast6_dec_tv_template[] = {
2947#define AES_CTR_3686_DEC_TEST_VECTORS 6 2956#define AES_CTR_3686_DEC_TEST_VECTORS 6
2948#define AES_GCM_ENC_TEST_VECTORS 9 2957#define AES_GCM_ENC_TEST_VECTORS 9
2949#define AES_GCM_DEC_TEST_VECTORS 8 2958#define AES_GCM_DEC_TEST_VECTORS 8
2959#define AES_GCM_4106_ENC_TEST_VECTORS 7
2960#define AES_GCM_4106_DEC_TEST_VECTORS 7
2950#define AES_CCM_ENC_TEST_VECTORS 7 2961#define AES_CCM_ENC_TEST_VECTORS 7
2951#define AES_CCM_DEC_TEST_VECTORS 7 2962#define AES_CCM_DEC_TEST_VECTORS 7
2952#define AES_CCM_4309_ENC_TEST_VECTORS 7 2963#define AES_CCM_4309_ENC_TEST_VECTORS 7
@@ -5829,6 +5840,356 @@ static struct aead_testvec aes_gcm_dec_tv_template[] = {
5829 } 5840 }
5830}; 5841};
5831 5842
5843static struct aead_testvec aes_gcm_rfc4106_enc_tv_template[] = {
5844 { /* Generated using Crypto++ */
5845 .key = zeroed_string,
5846 .klen = 20,
5847 .iv = zeroed_string,
5848 .input = zeroed_string,
5849 .ilen = 16,
5850 .assoc = zeroed_string,
5851 .alen = 8,
5852 .result = "\x03\x88\xDA\xCE\x60\xB6\xA3\x92"
5853 "\xF3\x28\xC2\xB9\x71\xB2\xFE\x78"
5854 "\x97\xFE\x4C\x23\x37\x42\x01\xE0"
5855 "\x81\x9F\x8D\xC5\xD7\x41\xA0\x1B",
5856 .rlen = 32,
5857 },{
5858 .key = "\xfe\xff\xe9\x92\x86\x65\x73\x1c"
5859 "\x6d\x6a\x8f\x94\x67\x30\x83\x08"
5860 "\x00\x00\x00\x00",
5861 .klen = 20,
5862 .iv = "\x00\x00\x00\x00\x00\x00\x00\x01"
5863 "\x00\x00\x00\x00",
5864 .input = zeroed_string,
5865 .ilen = 16,
5866 .assoc = zeroed_string,
5867 .alen = 8,
5868 .result = "\xC0\x0D\x8B\x42\x0F\x8F\x34\x18"
5869 "\x88\xB1\xC5\xBC\xC5\xB6\xD6\x28"
5870 "\x6A\x9D\xDF\x11\x5E\xFE\x5E\x9D"
5871 "\x2F\x70\x44\x92\xF7\xF2\xE3\xEF",
5872 .rlen = 32,
5873
5874 }, {
5875 .key = "\xfe\xff\xe9\x92\x86\x65\x73\x1c"
5876 "\x6d\x6a\x8f\x94\x67\x30\x83\x08"
5877 "\x00\x00\x00\x00",
5878 .klen = 20,
5879 .iv = zeroed_string,
5880 .input = "\x01\x01\x01\x01\x01\x01\x01\x01"
5881 "\x01\x01\x01\x01\x01\x01\x01\x01",
5882 .ilen = 16,
5883 .assoc = zeroed_string,
5884 .alen = 8,
5885 .result = "\x4B\xB1\xB5\xE3\x25\x71\x70\xDE"
5886 "\x7F\xC9\x9C\xA5\x14\x19\xF2\xAC"
5887 "\x0B\x8F\x88\x69\x17\xE6\xB4\x3C"
5888 "\xB1\x68\xFD\x14\x52\x64\x61\xB2",
5889 .rlen = 32,
5890 }, {
5891 .key = "\xfe\xff\xe9\x92\x86\x65\x73\x1c"
5892 "\x6d\x6a\x8f\x94\x67\x30\x83\x08"
5893 "\x00\x00\x00\x00",
5894 .klen = 20,
5895 .iv = zeroed_string,
5896 .input = "\x01\x01\x01\x01\x01\x01\x01\x01"
5897 "\x01\x01\x01\x01\x01\x01\x01\x01",
5898 .ilen = 16,
5899 .assoc = "\x01\x01\x01\x01\x01\x01\x01\x01",
5900 .alen = 8,
5901 .result = "\x4B\xB1\xB5\xE3\x25\x71\x70\xDE"
5902 "\x7F\xC9\x9C\xA5\x14\x19\xF2\xAC"
5903 "\x90\x92\xB7\xE3\x5F\xA3\x9A\x63"
5904 "\x7E\xD7\x1F\xD8\xD3\x7C\x4B\xF5",
5905 .rlen = 32,
5906 }, {
5907 .key = "\xfe\xff\xe9\x92\x86\x65\x73\x1c"
5908 "\x6d\x6a\x8f\x94\x67\x30\x83\x08"
5909 "\x00\x00\x00\x00",
5910 .klen = 20,
5911 .iv = "\x00\x00\x00\x00\x00\x00\x00\x01"
5912 "\x00\x00\x00\x00",
5913 .input = "\x01\x01\x01\x01\x01\x01\x01\x01"
5914 "\x01\x01\x01\x01\x01\x01\x01\x01",
5915 .ilen = 16,
5916 .assoc = "\x01\x01\x01\x01\x01\x01\x01\x01",
5917 .alen = 8,
5918 .result = "\xC1\x0C\x8A\x43\x0E\x8E\x35\x19"
5919 "\x89\xB0\xC4\xBD\xC4\xB7\xD7\x29"
5920 "\x64\x50\xF9\x32\x13\xFB\x74\x61"
5921 "\xF4\xED\x52\xD3\xC5\x10\x55\x3C",
5922 .rlen = 32,
5923 }, {
5924 .key = "\xfe\xff\xe9\x92\x86\x65\x73\x1c"
5925 "\x6d\x6a\x8f\x94\x67\x30\x83\x08"
5926 "\x00\x00\x00\x00",
5927 .klen = 20,
5928 .iv = "\x00\x00\x00\x00\x00\x00\x00\x01"
5929 "\x00\x00\x00\x00",
5930 .input = "\x01\x01\x01\x01\x01\x01\x01\x01"
5931 "\x01\x01\x01\x01\x01\x01\x01\x01"
5932 "\x01\x01\x01\x01\x01\x01\x01\x01"
5933 "\x01\x01\x01\x01\x01\x01\x01\x01"
5934 "\x01\x01\x01\x01\x01\x01\x01\x01"
5935 "\x01\x01\x01\x01\x01\x01\x01\x01"
5936 "\x01\x01\x01\x01\x01\x01\x01\x01"
5937 "\x01\x01\x01\x01\x01\x01\x01\x01",
5938 .ilen = 64,
5939 .assoc = "\x01\x01\x01\x01\x01\x01\x01\x01",
5940 .alen = 8,
5941 .result = "\xC1\x0C\x8A\x43\x0E\x8E\x35\x19"
5942 "\x89\xB0\xC4\xBD\xC4\xB7\xD7\x29"
5943 "\x98\x14\xA1\x42\x37\x80\xFD\x90"
5944 "\x68\x12\x01\xA8\x91\x89\xB9\x83"
5945 "\x5B\x11\x77\x12\x9B\xFF\x24\x89"
5946 "\x94\x5F\x18\x12\xBA\x27\x09\x39"
5947 "\x99\x96\x76\x42\x15\x1C\xCD\xCB"
5948 "\xDC\xD3\xDA\x65\x73\xAF\x80\xCD"
5949 "\xD2\xB6\xC2\x4A\x76\xC2\x92\x85"
5950 "\xBD\xCF\x62\x98\x58\x14\xE5\xBD",
5951 .rlen = 80,
5952 }, {
5953 .key = "\x00\x01\x02\x03\x04\x05\x06\x07"
5954 "\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f"
5955 "\x00\x00\x00\x00",
5956 .klen = 20,
5957 .iv = "\x00\x00\x45\x67\x89\xab\xcd\xef"
5958 "\x00\x00\x00\x00",
5959 .input = "\xff\xff\xff\xff\xff\xff\xff\xff"
5960 "\xff\xff\xff\xff\xff\xff\xff\xff"
5961 "\xff\xff\xff\xff\xff\xff\xff\xff"
5962 "\xff\xff\xff\xff\xff\xff\xff\xff"
5963 "\xff\xff\xff\xff\xff\xff\xff\xff"
5964 "\xff\xff\xff\xff\xff\xff\xff\xff"
5965 "\xff\xff\xff\xff\xff\xff\xff\xff"
5966 "\xff\xff\xff\xff\xff\xff\xff\xff"
5967 "\xff\xff\xff\xff\xff\xff\xff\xff"
5968 "\xff\xff\xff\xff\xff\xff\xff\xff"
5969 "\xff\xff\xff\xff\xff\xff\xff\xff"
5970 "\xff\xff\xff\xff\xff\xff\xff\xff"
5971 "\xff\xff\xff\xff\xff\xff\xff\xff"
5972 "\xff\xff\xff\xff\xff\xff\xff\xff"
5973 "\xff\xff\xff\xff\xff\xff\xff\xff"
5974 "\xff\xff\xff\xff\xff\xff\xff\xff"
5975 "\xff\xff\xff\xff\xff\xff\xff\xff"
5976 "\xff\xff\xff\xff\xff\xff\xff\xff"
5977 "\xff\xff\xff\xff\xff\xff\xff\xff"
5978 "\xff\xff\xff\xff\xff\xff\xff\xff"
5979 "\xff\xff\xff\xff\xff\xff\xff\xff"
5980 "\xff\xff\xff\xff\xff\xff\xff\xff"
5981 "\xff\xff\xff\xff\xff\xff\xff\xff"
5982 "\xff\xff\xff\xff\xff\xff\xff\xff",
5983 .ilen = 192,
5984 .assoc = "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
5985 "\xaa\xaa\xaa\xaa",
5986 .alen = 12,
5987 .result = "\xC1\x76\x33\x85\xE2\x9B\x5F\xDE"
5988 "\xDE\x89\x3D\x42\xE7\xC9\x69\x8A"
5989 "\x44\x6D\xC3\x88\x46\x2E\xC2\x01"
5990 "\x5E\xF6\x0C\x39\xF0\xC4\xA5\x82"
5991 "\xCD\xE8\x31\xCC\x0A\x4C\xE4\x44"
5992 "\x41\xA9\x82\x6F\x22\xA1\x23\x1A"
5993 "\xA8\xE3\x16\xFD\x31\x5C\x27\x31"
5994 "\xF1\x7F\x01\x63\xA3\xAF\x70\xA1"
5995 "\xCF\x07\x57\x41\x67\xD0\xC4\x42"
5996 "\xDB\x18\xC6\x4C\x4C\xE0\x3D\x9F"
5997 "\x05\x07\xFB\x13\x7D\x4A\xCA\x5B"
5998 "\xF0\xBF\x64\x7E\x05\xB1\x72\xEE"
5999 "\x7C\x3B\xD4\xCD\x14\x03\xB2\x2C"
6000 "\xD3\xA9\xEE\xFA\x17\xFC\x9C\xDF"
6001 "\xC7\x75\x40\xFF\xAE\xAD\x1E\x59"
6002 "\x2F\x30\x24\xFB\xAD\x6B\x10\xFA"
6003 "\x6C\x9F\x5B\xE7\x25\xD5\xD0\x25"
6004 "\xAC\x4A\x4B\xDA\xFC\x7A\x85\x1B"
6005 "\x7E\x13\x06\x82\x08\x17\xA4\x35"
6006 "\xEC\xC5\x8D\x63\x96\x81\x0A\x8F"
6007 "\xA3\x05\x38\x95\x20\x1A\x47\x04"
6008 "\x6F\x6D\xDA\x8F\xEF\xC1\x76\x35"
6009 "\x6B\xC7\x4D\x0F\x94\x12\xCA\x3E"
6010 "\x2E\xD5\x03\x2E\x86\x7E\xAA\x3B"
6011 "\x37\x08\x1C\xCF\xBA\x5D\x71\x46"
6012 "\x80\x72\xB0\x4C\x82\x0D\x60\x3C",
6013 .rlen = 208,
6014 }
6015};
6016
6017static struct aead_testvec aes_gcm_rfc4106_dec_tv_template[] = {
6018 { /* Generated using Crypto++ */
6019 .key = zeroed_string,
6020 .klen = 20,
6021 .iv = zeroed_string,
6022 .input = "\x03\x88\xDA\xCE\x60\xB6\xA3\x92"
6023 "\xF3\x28\xC2\xB9\x71\xB2\xFE\x78"
6024 "\x97\xFE\x4C\x23\x37\x42\x01\xE0"
6025 "\x81\x9F\x8D\xC5\xD7\x41\xA0\x1B",
6026 .ilen = 32,
6027 .assoc = zeroed_string,
6028 .alen = 8,
6029 .result = zeroed_string,
6030 .rlen = 16,
6031
6032 },{
6033 .key = "\xfe\xff\xe9\x92\x86\x65\x73\x1c"
6034 "\x6d\x6a\x8f\x94\x67\x30\x83\x08"
6035 "\x00\x00\x00\x00",
6036 .klen = 20,
6037 .iv = "\x00\x00\x00\x00\x00\x00\x00\x01"
6038 "\x00\x00\x00\x00",
6039 .input = "\xC0\x0D\x8B\x42\x0F\x8F\x34\x18"
6040 "\x88\xB1\xC5\xBC\xC5\xB6\xD6\x28"
6041 "\x6A\x9D\xDF\x11\x5E\xFE\x5E\x9D"
6042 "\x2F\x70\x44\x92\xF7\xF2\xE3\xEF",
6043 .ilen = 32,
6044 .assoc = zeroed_string,
6045 .alen = 8,
6046 .result = zeroed_string,
6047 .rlen = 16,
6048 }, {
6049 .key = "\xfe\xff\xe9\x92\x86\x65\x73\x1c"
6050 "\x6d\x6a\x8f\x94\x67\x30\x83\x08"
6051 "\x00\x00\x00\x00",
6052 .klen = 20,
6053 .iv = zeroed_string,
6054 .input = "\x4B\xB1\xB5\xE3\x25\x71\x70\xDE"
6055 "\x7F\xC9\x9C\xA5\x14\x19\xF2\xAC"
6056 "\x0B\x8F\x88\x69\x17\xE6\xB4\x3C"
6057 "\xB1\x68\xFD\x14\x52\x64\x61\xB2",
6058 .ilen = 32,
6059 .assoc = zeroed_string,
6060 .alen = 8,
6061 .result = "\x01\x01\x01\x01\x01\x01\x01\x01"
6062 "\x01\x01\x01\x01\x01\x01\x01\x01",
6063 .rlen = 16,
6064 }, {
6065 .key = "\xfe\xff\xe9\x92\x86\x65\x73\x1c"
6066 "\x6d\x6a\x8f\x94\x67\x30\x83\x08"
6067 "\x00\x00\x00\x00",
6068 .klen = 20,
6069 .iv = zeroed_string,
6070 .input = "\x4B\xB1\xB5\xE3\x25\x71\x70\xDE"
6071 "\x7F\xC9\x9C\xA5\x14\x19\xF2\xAC"
6072 "\x90\x92\xB7\xE3\x5F\xA3\x9A\x63"
6073 "\x7E\xD7\x1F\xD8\xD3\x7C\x4B\xF5",
6074 .ilen = 32,
6075 .assoc = "\x01\x01\x01\x01\x01\x01\x01\x01",
6076 .alen = 8,
6077 .result = "\x01\x01\x01\x01\x01\x01\x01\x01"
6078 "\x01\x01\x01\x01\x01\x01\x01\x01",
6079 .rlen = 16,
6080
6081 }, {
6082 .key = "\xfe\xff\xe9\x92\x86\x65\x73\x1c"
6083 "\x6d\x6a\x8f\x94\x67\x30\x83\x08"
6084 "\x00\x00\x00\x00",
6085 .klen = 20,
6086 .iv = "\x00\x00\x00\x00\x00\x00\x00\x01"
6087 "\x00\x00\x00\x00",
6088 .input = "\xC1\x0C\x8A\x43\x0E\x8E\x35\x19"
6089 "\x89\xB0\xC4\xBD\xC4\xB7\xD7\x29"
6090 "\x64\x50\xF9\x32\x13\xFB\x74\x61"
6091 "\xF4\xED\x52\xD3\xC5\x10\x55\x3C",
6092 .ilen = 32,
6093 .assoc = "\x01\x01\x01\x01\x01\x01\x01\x01",
6094 .alen = 8,
6095 .result = "\x01\x01\x01\x01\x01\x01\x01\x01"
6096 "\x01\x01\x01\x01\x01\x01\x01\x01",
6097 .rlen = 16,
6098 }, {
6099 .key = "\xfe\xff\xe9\x92\x86\x65\x73\x1c"
6100 "\x6d\x6a\x8f\x94\x67\x30\x83\x08"
6101 "\x00\x00\x00\x00",
6102 .klen = 20,
6103 .iv = "\x00\x00\x00\x00\x00\x00\x00\x01"
6104 "\x00\x00\x00\x00",
6105 .input = "\xC1\x0C\x8A\x43\x0E\x8E\x35\x19"
6106 "\x89\xB0\xC4\xBD\xC4\xB7\xD7\x29"
6107 "\x98\x14\xA1\x42\x37\x80\xFD\x90"
6108 "\x68\x12\x01\xA8\x91\x89\xB9\x83"
6109 "\x5B\x11\x77\x12\x9B\xFF\x24\x89"
6110 "\x94\x5F\x18\x12\xBA\x27\x09\x39"
6111 "\x99\x96\x76\x42\x15\x1C\xCD\xCB"
6112 "\xDC\xD3\xDA\x65\x73\xAF\x80\xCD"
6113 "\xD2\xB6\xC2\x4A\x76\xC2\x92\x85"
6114 "\xBD\xCF\x62\x98\x58\x14\xE5\xBD",
6115 .ilen = 80,
6116 .assoc = "\x01\x01\x01\x01\x01\x01\x01\x01",
6117 .alen = 8,
6118 .result = "\x01\x01\x01\x01\x01\x01\x01\x01"
6119 "\x01\x01\x01\x01\x01\x01\x01\x01"
6120 "\x01\x01\x01\x01\x01\x01\x01\x01"
6121 "\x01\x01\x01\x01\x01\x01\x01\x01"
6122 "\x01\x01\x01\x01\x01\x01\x01\x01"
6123 "\x01\x01\x01\x01\x01\x01\x01\x01"
6124 "\x01\x01\x01\x01\x01\x01\x01\x01"
6125 "\x01\x01\x01\x01\x01\x01\x01\x01",
6126 .rlen = 64,
6127 }, {
6128 .key = "\x00\x01\x02\x03\x04\x05\x06\x07"
6129 "\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f"
6130 "\x00\x00\x00\x00",
6131 .klen = 20,
6132 .iv = "\x00\x00\x45\x67\x89\xab\xcd\xef"
6133 "\x00\x00\x00\x00",
6134 .input = "\xC1\x76\x33\x85\xE2\x9B\x5F\xDE"
6135 "\xDE\x89\x3D\x42\xE7\xC9\x69\x8A"
6136 "\x44\x6D\xC3\x88\x46\x2E\xC2\x01"
6137 "\x5E\xF6\x0C\x39\xF0\xC4\xA5\x82"
6138 "\xCD\xE8\x31\xCC\x0A\x4C\xE4\x44"
6139 "\x41\xA9\x82\x6F\x22\xA1\x23\x1A"
6140 "\xA8\xE3\x16\xFD\x31\x5C\x27\x31"
6141 "\xF1\x7F\x01\x63\xA3\xAF\x70\xA1"
6142 "\xCF\x07\x57\x41\x67\xD0\xC4\x42"
6143 "\xDB\x18\xC6\x4C\x4C\xE0\x3D\x9F"
6144 "\x05\x07\xFB\x13\x7D\x4A\xCA\x5B"
6145 "\xF0\xBF\x64\x7E\x05\xB1\x72\xEE"
6146 "\x7C\x3B\xD4\xCD\x14\x03\xB2\x2C"
6147 "\xD3\xA9\xEE\xFA\x17\xFC\x9C\xDF"
6148 "\xC7\x75\x40\xFF\xAE\xAD\x1E\x59"
6149 "\x2F\x30\x24\xFB\xAD\x6B\x10\xFA"
6150 "\x6C\x9F\x5B\xE7\x25\xD5\xD0\x25"
6151 "\xAC\x4A\x4B\xDA\xFC\x7A\x85\x1B"
6152 "\x7E\x13\x06\x82\x08\x17\xA4\x35"
6153 "\xEC\xC5\x8D\x63\x96\x81\x0A\x8F"
6154 "\xA3\x05\x38\x95\x20\x1A\x47\x04"
6155 "\x6F\x6D\xDA\x8F\xEF\xC1\x76\x35"
6156 "\x6B\xC7\x4D\x0F\x94\x12\xCA\x3E"
6157 "\x2E\xD5\x03\x2E\x86\x7E\xAA\x3B"
6158 "\x37\x08\x1C\xCF\xBA\x5D\x71\x46"
6159 "\x80\x72\xB0\x4C\x82\x0D\x60\x3C",
6160 .ilen = 208,
6161 .assoc = "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
6162 "\xaa\xaa\xaa\xaa",
6163 .alen = 12,
6164 .result = "\xff\xff\xff\xff\xff\xff\xff\xff"
6165 "\xff\xff\xff\xff\xff\xff\xff\xff"
6166 "\xff\xff\xff\xff\xff\xff\xff\xff"
6167 "\xff\xff\xff\xff\xff\xff\xff\xff"
6168 "\xff\xff\xff\xff\xff\xff\xff\xff"
6169 "\xff\xff\xff\xff\xff\xff\xff\xff"
6170 "\xff\xff\xff\xff\xff\xff\xff\xff"
6171 "\xff\xff\xff\xff\xff\xff\xff\xff"
6172 "\xff\xff\xff\xff\xff\xff\xff\xff"
6173 "\xff\xff\xff\xff\xff\xff\xff\xff"
6174 "\xff\xff\xff\xff\xff\xff\xff\xff"
6175 "\xff\xff\xff\xff\xff\xff\xff\xff"
6176 "\xff\xff\xff\xff\xff\xff\xff\xff"
6177 "\xff\xff\xff\xff\xff\xff\xff\xff"
6178 "\xff\xff\xff\xff\xff\xff\xff\xff"
6179 "\xff\xff\xff\xff\xff\xff\xff\xff"
6180 "\xff\xff\xff\xff\xff\xff\xff\xff"
6181 "\xff\xff\xff\xff\xff\xff\xff\xff"
6182 "\xff\xff\xff\xff\xff\xff\xff\xff"
6183 "\xff\xff\xff\xff\xff\xff\xff\xff"
6184 "\xff\xff\xff\xff\xff\xff\xff\xff"
6185 "\xff\xff\xff\xff\xff\xff\xff\xff"
6186 "\xff\xff\xff\xff\xff\xff\xff\xff"
6187 "\xff\xff\xff\xff\xff\xff\xff\xff",
6188 .rlen = 192,
6189
6190 }
6191};
6192
5832static struct aead_testvec aes_ccm_enc_tv_template[] = { 6193static struct aead_testvec aes_ccm_enc_tv_template[] = {
5833 { /* From RFC 3610 */ 6194 { /* From RFC 3610 */
5834 .key = "\xc0\xc1\xc2\xc3\xc4\xc5\xc6\xc7" 6195 .key = "\xc0\xc1\xc2\xc3\xc4\xc5\xc6\xc7"
diff --git a/crypto/zlib.c b/crypto/zlib.c
index c3015733c990..739b8fca4cea 100644
--- a/crypto/zlib.c
+++ b/crypto/zlib.c
@@ -95,11 +95,10 @@ static int zlib_compress_setup(struct crypto_pcomp *tfm, void *params,
95 zlib_comp_exit(ctx); 95 zlib_comp_exit(ctx);
96 96
97 workspacesize = zlib_deflate_workspacesize(); 97 workspacesize = zlib_deflate_workspacesize();
98 stream->workspace = vmalloc(workspacesize); 98 stream->workspace = vzalloc(workspacesize);
99 if (!stream->workspace) 99 if (!stream->workspace)
100 return -ENOMEM; 100 return -ENOMEM;
101 101
102 memset(stream->workspace, 0, workspacesize);
103 ret = zlib_deflateInit2(stream, 102 ret = zlib_deflateInit2(stream,
104 tb[ZLIB_COMP_LEVEL] 103 tb[ZLIB_COMP_LEVEL]
105 ? nla_get_u32(tb[ZLIB_COMP_LEVEL]) 104 ? nla_get_u32(tb[ZLIB_COMP_LEVEL])
diff --git a/drivers/Kconfig b/drivers/Kconfig
index 3d93b3a3d630..dd0a5b5e9bf3 100644
--- a/drivers/Kconfig
+++ b/drivers/Kconfig
@@ -88,6 +88,8 @@ source "drivers/memstick/Kconfig"
88 88
89source "drivers/leds/Kconfig" 89source "drivers/leds/Kconfig"
90 90
91source "drivers/nfc/Kconfig"
92
91source "drivers/accessibility/Kconfig" 93source "drivers/accessibility/Kconfig"
92 94
93source "drivers/infiniband/Kconfig" 95source "drivers/infiniband/Kconfig"
diff --git a/drivers/Makefile b/drivers/Makefile
index bf15ce7493d2..ef5132469f58 100644
--- a/drivers/Makefile
+++ b/drivers/Makefile
@@ -40,7 +40,7 @@ obj-$(CONFIG_FB_INTEL) += video/intelfb/
40 40
41obj-y += serial/ 41obj-y += serial/
42obj-$(CONFIG_PARPORT) += parport/ 42obj-$(CONFIG_PARPORT) += parport/
43obj-y += base/ block/ misc/ mfd/ 43obj-y += base/ block/ misc/ mfd/ nfc/
44obj-$(CONFIG_NUBUS) += nubus/ 44obj-$(CONFIG_NUBUS) += nubus/
45obj-y += macintosh/ 45obj-y += macintosh/
46obj-$(CONFIG_IDE) += ide/ 46obj-$(CONFIG_IDE) += ide/
diff --git a/drivers/acpi/acpica/acobject.h b/drivers/acpi/acpica/acobject.h
index bdbfaf22bd14..962a3ccff6fd 100644
--- a/drivers/acpi/acpica/acobject.h
+++ b/drivers/acpi/acpica/acobject.h
@@ -93,7 +93,7 @@
93 93
94#define AOPOBJ_AML_CONSTANT 0x01 /* Integer is an AML constant */ 94#define AOPOBJ_AML_CONSTANT 0x01 /* Integer is an AML constant */
95#define AOPOBJ_STATIC_POINTER 0x02 /* Data is part of an ACPI table, don't delete */ 95#define AOPOBJ_STATIC_POINTER 0x02 /* Data is part of an ACPI table, don't delete */
96#define AOPOBJ_DATA_VALID 0x04 /* Object is intialized and data is valid */ 96#define AOPOBJ_DATA_VALID 0x04 /* Object is initialized and data is valid */
97#define AOPOBJ_OBJECT_INITIALIZED 0x08 /* Region is initialized, _REG was run */ 97#define AOPOBJ_OBJECT_INITIALIZED 0x08 /* Region is initialized, _REG was run */
98#define AOPOBJ_SETUP_COMPLETE 0x10 /* Region setup is complete */ 98#define AOPOBJ_SETUP_COMPLETE 0x10 /* Region setup is complete */
99#define AOPOBJ_INVALID 0x20 /* Host OS won't allow a Region address */ 99#define AOPOBJ_INVALID 0x20 /* Host OS won't allow a Region address */
diff --git a/drivers/acpi/apei/einj.c b/drivers/acpi/apei/einj.c
index cf29df69380b..096aebfe7f32 100644
--- a/drivers/acpi/apei/einj.c
+++ b/drivers/acpi/apei/einj.c
@@ -39,7 +39,7 @@
39#define EINJ_PFX "EINJ: " 39#define EINJ_PFX "EINJ: "
40 40
41#define SPIN_UNIT 100 /* 100ns */ 41#define SPIN_UNIT 100 /* 100ns */
42/* Firmware should respond within 1 miliseconds */ 42/* Firmware should respond within 1 milliseconds */
43#define FIRMWARE_TIMEOUT (1 * NSEC_PER_MSEC) 43#define FIRMWARE_TIMEOUT (1 * NSEC_PER_MSEC)
44 44
45/* 45/*
diff --git a/drivers/acpi/apei/erst.c b/drivers/acpi/apei/erst.c
index 5850d320404c..cf6db6b7662a 100644
--- a/drivers/acpi/apei/erst.c
+++ b/drivers/acpi/apei/erst.c
@@ -53,7 +53,7 @@
53 sizeof(struct acpi_table_erst))) 53 sizeof(struct acpi_table_erst)))
54 54
55#define SPIN_UNIT 100 /* 100ns */ 55#define SPIN_UNIT 100 /* 100ns */
56/* Firmware should respond within 1 miliseconds */ 56/* Firmware should respond within 1 milliseconds */
57#define FIRMWARE_TIMEOUT (1 * NSEC_PER_MSEC) 57#define FIRMWARE_TIMEOUT (1 * NSEC_PER_MSEC)
58#define FIRMWARE_MAX_STALL 50 /* 50us */ 58#define FIRMWARE_MAX_STALL 50 /* 50us */
59 59
diff --git a/drivers/acpi/sleep.c b/drivers/acpi/sleep.c
index febb153b5a68..c423231b952b 100644
--- a/drivers/acpi/sleep.c
+++ b/drivers/acpi/sleep.c
@@ -319,7 +319,7 @@ static int acpi_suspend_state_valid(suspend_state_t pm_state)
319 } 319 }
320} 320}
321 321
322static struct platform_suspend_ops acpi_suspend_ops = { 322static const struct platform_suspend_ops acpi_suspend_ops = {
323 .valid = acpi_suspend_state_valid, 323 .valid = acpi_suspend_state_valid,
324 .begin = acpi_suspend_begin, 324 .begin = acpi_suspend_begin,
325 .prepare_late = acpi_pm_prepare, 325 .prepare_late = acpi_pm_prepare,
@@ -347,7 +347,7 @@ static int acpi_suspend_begin_old(suspend_state_t pm_state)
347 * The following callbacks are used if the pre-ACPI 2.0 suspend ordering has 347 * The following callbacks are used if the pre-ACPI 2.0 suspend ordering has
348 * been requested. 348 * been requested.
349 */ 349 */
350static struct platform_suspend_ops acpi_suspend_ops_old = { 350static const struct platform_suspend_ops acpi_suspend_ops_old = {
351 .valid = acpi_suspend_state_valid, 351 .valid = acpi_suspend_state_valid,
352 .begin = acpi_suspend_begin_old, 352 .begin = acpi_suspend_begin_old,
353 .prepare_late = acpi_pm_pre_suspend, 353 .prepare_late = acpi_pm_pre_suspend,
@@ -506,7 +506,7 @@ static void acpi_pm_thaw(void)
506 acpi_enable_all_runtime_gpes(); 506 acpi_enable_all_runtime_gpes();
507} 507}
508 508
509static struct platform_hibernation_ops acpi_hibernation_ops = { 509static const struct platform_hibernation_ops acpi_hibernation_ops = {
510 .begin = acpi_hibernation_begin, 510 .begin = acpi_hibernation_begin,
511 .end = acpi_pm_end, 511 .end = acpi_pm_end,
512 .pre_snapshot = acpi_pm_prepare, 512 .pre_snapshot = acpi_pm_prepare,
@@ -549,7 +549,7 @@ static int acpi_hibernation_begin_old(void)
549 * The following callbacks are used if the pre-ACPI 2.0 suspend ordering has 549 * The following callbacks are used if the pre-ACPI 2.0 suspend ordering has
550 * been requested. 550 * been requested.
551 */ 551 */
552static struct platform_hibernation_ops acpi_hibernation_ops_old = { 552static const struct platform_hibernation_ops acpi_hibernation_ops_old = {
553 .begin = acpi_hibernation_begin_old, 553 .begin = acpi_hibernation_begin_old,
554 .end = acpi_pm_end, 554 .end = acpi_pm_end,
555 .pre_snapshot = acpi_pm_pre_suspend, 555 .pre_snapshot = acpi_pm_pre_suspend,
diff --git a/drivers/acpi/video.c b/drivers/acpi/video.c
index 5cd0228d2daa..15a0fde4b32a 100644
--- a/drivers/acpi/video.c
+++ b/drivers/acpi/video.c
@@ -260,7 +260,7 @@ static int acpi_video_set_brightness(struct backlight_device *bd)
260 vd->brightness->levels[request_level]); 260 vd->brightness->levels[request_level]);
261} 261}
262 262
263static struct backlight_ops acpi_backlight_ops = { 263static const struct backlight_ops acpi_backlight_ops = {
264 .get_brightness = acpi_video_get_brightness, 264 .get_brightness = acpi_video_get_brightness,
265 .update_status = acpi_video_set_brightness, 265 .update_status = acpi_video_set_brightness,
266}; 266};
diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
index 0a6a943b3779..a31fe96f7de6 100644
--- a/drivers/ata/libata-core.c
+++ b/drivers/ata/libata-core.c
@@ -2240,7 +2240,7 @@ int ata_dev_configure(struct ata_device *dev)
2240 if (id[ATA_ID_CFA_KEY_MGMT] & 1) 2240 if (id[ATA_ID_CFA_KEY_MGMT] & 1)
2241 ata_dev_printk(dev, KERN_WARNING, 2241 ata_dev_printk(dev, KERN_WARNING,
2242 "supports DRM functions and may " 2242 "supports DRM functions and may "
2243 "not be fully accessable.\n"); 2243 "not be fully accessible.\n");
2244 snprintf(revbuf, 7, "CFA"); 2244 snprintf(revbuf, 7, "CFA");
2245 } else { 2245 } else {
2246 snprintf(revbuf, 7, "ATA-%d", ata_id_major_version(id)); 2246 snprintf(revbuf, 7, "ATA-%d", ata_id_major_version(id));
@@ -2248,7 +2248,7 @@ int ata_dev_configure(struct ata_device *dev)
2248 if (ata_id_has_tpm(id)) 2248 if (ata_id_has_tpm(id))
2249 ata_dev_printk(dev, KERN_WARNING, 2249 ata_dev_printk(dev, KERN_WARNING,
2250 "supports DRM functions and may " 2250 "supports DRM functions and may "
2251 "not be fully accessable.\n"); 2251 "not be fully accessible.\n");
2252 } 2252 }
2253 2253
2254 dev->n_sectors = ata_id_n_sectors(id); 2254 dev->n_sectors = ata_id_n_sectors(id);
diff --git a/drivers/ata/sata_vsc.c b/drivers/ata/sata_vsc.c
index b777176ff494..e079cf29ed5d 100644
--- a/drivers/ata/sata_vsc.c
+++ b/drivers/ata/sata_vsc.c
@@ -370,7 +370,7 @@ static int __devinit vsc_sata_init_one(struct pci_dev *pdev,
370 if (pci_resource_len(pdev, 0) == 0) 370 if (pci_resource_len(pdev, 0) == 0)
371 return -ENODEV; 371 return -ENODEV;
372 372
373 /* map IO regions and intialize host accordingly */ 373 /* map IO regions and initialize host accordingly */
374 rc = pcim_iomap_regions(pdev, 1 << VSC_MMIO_BAR, DRV_NAME); 374 rc = pcim_iomap_regions(pdev, 1 << VSC_MMIO_BAR, DRV_NAME);
375 if (rc == -EBUSY) 375 if (rc == -EBUSY)
376 pcim_pin_device(pdev); 376 pcim_pin_device(pdev);
diff --git a/drivers/atm/idt77252.h b/drivers/atm/idt77252.h
index 5042bb2dab15..f53a43ae2bbe 100644
--- a/drivers/atm/idt77252.h
+++ b/drivers/atm/idt77252.h
@@ -572,7 +572,7 @@ struct idt77252_dev
572#define SAR_STAT_TSQF 0x00001000 /* Transmit Status Queue full */ 572#define SAR_STAT_TSQF 0x00001000 /* Transmit Status Queue full */
573#define SAR_STAT_TMROF 0x00000800 /* Timer overflow */ 573#define SAR_STAT_TMROF 0x00000800 /* Timer overflow */
574#define SAR_STAT_PHYI 0x00000400 /* PHY device Interrupt flag */ 574#define SAR_STAT_PHYI 0x00000400 /* PHY device Interrupt flag */
575#define SAR_STAT_CMDBZ 0x00000200 /* ABR SAR Comand Busy Flag */ 575#define SAR_STAT_CMDBZ 0x00000200 /* ABR SAR Command Busy Flag */
576#define SAR_STAT_FBQ3A 0x00000100 /* Free Buffer Queue 3 Attention */ 576#define SAR_STAT_FBQ3A 0x00000100 /* Free Buffer Queue 3 Attention */
577#define SAR_STAT_FBQ2A 0x00000080 /* Free Buffer Queue 2 Attention */ 577#define SAR_STAT_FBQ2A 0x00000080 /* Free Buffer Queue 2 Attention */
578#define SAR_STAT_RSQF 0x00000040 /* Receive Status Queue full */ 578#define SAR_STAT_RSQF 0x00000040 /* Receive Status Queue full */
diff --git a/drivers/atm/iphase.c b/drivers/atm/iphase.c
index 729254053758..d80d51b62a1a 100644
--- a/drivers/atm/iphase.c
+++ b/drivers/atm/iphase.c
@@ -2063,7 +2063,7 @@ static int tx_init(struct atm_dev *dev)
2063 - UBR Table size is 4K 2063 - UBR Table size is 4K
2064 - UBR wait queue is 4K 2064 - UBR wait queue is 4K
2065 since the table and wait queues are contiguous, all the bytes 2065 since the table and wait queues are contiguous, all the bytes
2066 can be initialized by one memeset. 2066 can be initialized by one memeset.
2067 */ 2067 */
2068 2068
2069 vcsize_sel = 0; 2069 vcsize_sel = 0;
@@ -2089,7 +2089,7 @@ static int tx_init(struct atm_dev *dev)
2089 - ABR Table size is 2K 2089 - ABR Table size is 2K
2090 - ABR wait queue is 2K 2090 - ABR wait queue is 2K
2091 since the table and wait queues are contiguous, all the bytes 2091 since the table and wait queues are contiguous, all the bytes
2092 can be intialized by one memeset. 2092 can be initialized by one memeset.
2093 */ 2093 */
2094 i = ABR_SCHED_TABLE * iadev->memSize; 2094 i = ABR_SCHED_TABLE * iadev->memSize;
2095 writew((i >> 11) & 0xffff, iadev->seg_reg+ABR_SBPTR_BASE); 2095 writew((i >> 11) & 0xffff, iadev->seg_reg+ABR_SBPTR_BASE);
diff --git a/drivers/base/bus.c b/drivers/base/bus.c
index e243bd49764b..000e7b2006f8 100644
--- a/drivers/base/bus.c
+++ b/drivers/base/bus.c
@@ -975,7 +975,7 @@ struct klist *bus_get_device_klist(struct bus_type *bus)
975EXPORT_SYMBOL_GPL(bus_get_device_klist); 975EXPORT_SYMBOL_GPL(bus_get_device_klist);
976 976
977/* 977/*
978 * Yes, this forcably breaks the klist abstraction temporarily. It 978 * Yes, this forcibly breaks the klist abstraction temporarily. It
979 * just wants to sort the klist, not change reference counts and 979 * just wants to sort the klist, not change reference counts and
980 * take/drop locks rapidly in the process. It does all this while 980 * take/drop locks rapidly in the process. It does all this while
981 * holding the lock for the list, so objects can't otherwise be 981 * holding the lock for the list, so objects can't otherwise be
diff --git a/drivers/base/power/main.c b/drivers/base/power/main.c
index 2a52270aeb30..83404973f97a 100644
--- a/drivers/base/power/main.c
+++ b/drivers/base/power/main.c
@@ -8,7 +8,7 @@
8 * 8 *
9 * 9 *
10 * The driver model core calls device_pm_add() when a device is registered. 10 * The driver model core calls device_pm_add() when a device is registered.
11 * This will intialize the embedded device_pm_info object in the device 11 * This will initialize the embedded device_pm_info object in the device
12 * and add it to the list of power-controlled devices. sysfs entries for 12 * and add it to the list of power-controlled devices. sysfs entries for
13 * controlling device power management will also be added. 13 * controlling device power management will also be added.
14 * 14 *
diff --git a/drivers/block/rbd.c b/drivers/block/rbd.c
index 008d4a00b50d..e1e38b11f48a 100644
--- a/drivers/block/rbd.c
+++ b/drivers/block/rbd.c
@@ -1790,18 +1790,29 @@ static ssize_t rbd_add(struct bus_type *bus, const char *buf, size_t count)
1790 1790
1791 rc = rbd_bus_add_dev(rbd_dev); 1791 rc = rbd_bus_add_dev(rbd_dev);
1792 if (rc) 1792 if (rc)
1793 goto err_out_disk; 1793 goto err_out_blkdev;
1794
1794 /* set up and announce blkdev mapping */ 1795 /* set up and announce blkdev mapping */
1795 rc = rbd_init_disk(rbd_dev); 1796 rc = rbd_init_disk(rbd_dev);
1796 if (rc) 1797 if (rc)
1797 goto err_out_blkdev; 1798 goto err_out_bus;
1798 1799
1799 return count; 1800 return count;
1800 1801
1802err_out_bus:
1803 mutex_lock_nested(&ctl_mutex, SINGLE_DEPTH_NESTING);
1804 list_del_init(&rbd_dev->node);
1805 mutex_unlock(&ctl_mutex);
1806
1807 /* this will also clean up rest of rbd_dev stuff */
1808
1809 rbd_bus_del_dev(rbd_dev);
1810 kfree(options);
1811 kfree(mon_dev_name);
1812 return rc;
1813
1801err_out_blkdev: 1814err_out_blkdev:
1802 unregister_blkdev(rbd_dev->major, rbd_dev->name); 1815 unregister_blkdev(rbd_dev->major, rbd_dev->name);
1803err_out_disk:
1804 rbd_free_disk(rbd_dev);
1805err_out_client: 1816err_out_client:
1806 rbd_put_client(rbd_dev); 1817 rbd_put_client(rbd_dev);
1807 mutex_lock_nested(&ctl_mutex, SINGLE_DEPTH_NESTING); 1818 mutex_lock_nested(&ctl_mutex, SINGLE_DEPTH_NESTING);
diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig
index d4a7776f4b77..0f175a866ef0 100644
--- a/drivers/char/Kconfig
+++ b/drivers/char/Kconfig
@@ -1047,15 +1047,6 @@ config NSC_GPIO
1047 pc8736x_gpio drivers. If those drivers are built as 1047 pc8736x_gpio drivers. If those drivers are built as
1048 modules, this one will be too, named nsc_gpio 1048 modules, this one will be too, named nsc_gpio
1049 1049
1050config CS5535_GPIO
1051 tristate "AMD CS5535/CS5536 GPIO (Geode Companion Device)"
1052 depends on X86_32
1053 help
1054 Give userspace access to the GPIO pins on the AMD CS5535 and
1055 CS5536 Geode companion devices.
1056
1057 If compiled as a module, it will be called cs5535_gpio.
1058
1059config RAW_DRIVER 1050config RAW_DRIVER
1060 tristate "RAW driver (/dev/raw/rawN)" 1051 tristate "RAW driver (/dev/raw/rawN)"
1061 depends on BLOCK 1052 depends on BLOCK
diff --git a/drivers/char/Makefile b/drivers/char/Makefile
index fa0b824b7a65..1e9dffb33778 100644
--- a/drivers/char/Makefile
+++ b/drivers/char/Makefile
@@ -82,7 +82,6 @@ obj-$(CONFIG_NWFLASH) += nwflash.o
82obj-$(CONFIG_SCx200_GPIO) += scx200_gpio.o 82obj-$(CONFIG_SCx200_GPIO) += scx200_gpio.o
83obj-$(CONFIG_PC8736x_GPIO) += pc8736x_gpio.o 83obj-$(CONFIG_PC8736x_GPIO) += pc8736x_gpio.o
84obj-$(CONFIG_NSC_GPIO) += nsc_gpio.o 84obj-$(CONFIG_NSC_GPIO) += nsc_gpio.o
85obj-$(CONFIG_CS5535_GPIO) += cs5535_gpio.o
86obj-$(CONFIG_GPIO_TB0219) += tb0219.o 85obj-$(CONFIG_GPIO_TB0219) += tb0219.o
87obj-$(CONFIG_TELCLOCK) += tlclk.o 86obj-$(CONFIG_TELCLOCK) += tlclk.o
88 87
diff --git a/drivers/char/hw_random/via-rng.c b/drivers/char/hw_random/via-rng.c
index 794aacb715c1..d0387a84eec1 100644
--- a/drivers/char/hw_random/via-rng.c
+++ b/drivers/char/hw_random/via-rng.c
@@ -24,6 +24,7 @@
24 * warranty of any kind, whether express or implied. 24 * warranty of any kind, whether express or implied.
25 */ 25 */
26 26
27#include <crypto/padlock.h>
27#include <linux/module.h> 28#include <linux/module.h>
28#include <linux/kernel.h> 29#include <linux/kernel.h>
29#include <linux/hw_random.h> 30#include <linux/hw_random.h>
@@ -34,7 +35,6 @@
34#include <asm/i387.h> 35#include <asm/i387.h>
35 36
36 37
37#define PFX KBUILD_MODNAME ": "
38 38
39 39
40enum { 40enum {
@@ -81,8 +81,7 @@ static inline u32 xstore(u32 *addr, u32 edx_in)
81 ts_state = irq_ts_save(); 81 ts_state = irq_ts_save();
82 82
83 asm(".byte 0x0F,0xA7,0xC0 /* xstore %%edi (addr=%0) */" 83 asm(".byte 0x0F,0xA7,0xC0 /* xstore %%edi (addr=%0) */"
84 :"=m"(*addr), "=a"(eax_out) 84 : "=m" (*addr), "=a" (eax_out), "+d" (edx_in), "+D" (addr));
85 :"D"(addr), "d"(edx_in));
86 85
87 irq_ts_restore(ts_state); 86 irq_ts_restore(ts_state);
88 return eax_out; 87 return eax_out;
@@ -90,8 +89,10 @@ static inline u32 xstore(u32 *addr, u32 edx_in)
90 89
91static int via_rng_data_present(struct hwrng *rng, int wait) 90static int via_rng_data_present(struct hwrng *rng, int wait)
92{ 91{
92 char buf[16 + PADLOCK_ALIGNMENT - STACK_ALIGN] __attribute__
93 ((aligned(STACK_ALIGN)));
94 u32 *via_rng_datum = (u32 *)PTR_ALIGN(&buf[0], PADLOCK_ALIGNMENT);
93 u32 bytes_out; 95 u32 bytes_out;
94 u32 *via_rng_datum = (u32 *)(&rng->priv);
95 int i; 96 int i;
96 97
97 /* We choose the recommended 1-byte-per-instruction RNG rate, 98 /* We choose the recommended 1-byte-per-instruction RNG rate,
@@ -115,6 +116,7 @@ static int via_rng_data_present(struct hwrng *rng, int wait)
115 break; 116 break;
116 udelay(10); 117 udelay(10);
117 } 118 }
119 rng->priv = *via_rng_datum;
118 return bytes_out ? 1 : 0; 120 return bytes_out ? 1 : 0;
119} 121}
120 122
diff --git a/drivers/char/ramoops.c b/drivers/char/ramoops.c
index d3d63be2cd37..1a9f5f6d6ac5 100644
--- a/drivers/char/ramoops.c
+++ b/drivers/char/ramoops.c
@@ -30,7 +30,7 @@
30 30
31#define RAMOOPS_KERNMSG_HDR "====" 31#define RAMOOPS_KERNMSG_HDR "===="
32 32
33#define RECORD_SIZE 4096 33#define RECORD_SIZE 4096UL
34 34
35static ulong mem_address; 35static ulong mem_address;
36module_param(mem_address, ulong, 0400); 36module_param(mem_address, ulong, 0400);
@@ -68,11 +68,16 @@ static void ramoops_do_dump(struct kmsg_dumper *dumper,
68 char *buf, *buf_orig; 68 char *buf, *buf_orig;
69 struct timeval timestamp; 69 struct timeval timestamp;
70 70
71 if (reason != KMSG_DUMP_OOPS &&
72 reason != KMSG_DUMP_PANIC &&
73 reason != KMSG_DUMP_KEXEC)
74 return;
75
71 /* Only dump oopses if dump_oops is set */ 76 /* Only dump oopses if dump_oops is set */
72 if (reason == KMSG_DUMP_OOPS && !dump_oops) 77 if (reason == KMSG_DUMP_OOPS && !dump_oops)
73 return; 78 return;
74 79
75 buf = (char *)(cxt->virt_addr + (cxt->count * RECORD_SIZE)); 80 buf = cxt->virt_addr + (cxt->count * RECORD_SIZE);
76 buf_orig = buf; 81 buf_orig = buf;
77 82
78 memset(buf, '\0', RECORD_SIZE); 83 memset(buf, '\0', RECORD_SIZE);
@@ -83,8 +88,8 @@ static void ramoops_do_dump(struct kmsg_dumper *dumper,
83 buf += res; 88 buf += res;
84 89
85 hdr_size = buf - buf_orig; 90 hdr_size = buf - buf_orig;
86 l2_cpy = min(l2, (unsigned long)(RECORD_SIZE - hdr_size)); 91 l2_cpy = min(l2, RECORD_SIZE - hdr_size);
87 l1_cpy = min(l1, (unsigned long)(RECORD_SIZE - hdr_size) - l2_cpy); 92 l1_cpy = min(l1, RECORD_SIZE - hdr_size - l2_cpy);
88 93
89 s2_start = l2 - l2_cpy; 94 s2_start = l2 - l2_cpy;
90 s1_start = l1 - l1_cpy; 95 s1_start = l1 - l1_cpy;
diff --git a/drivers/crypto/mv_cesa.c b/drivers/crypto/mv_cesa.c
index 7d279e578df5..c99305afa58a 100644
--- a/drivers/crypto/mv_cesa.c
+++ b/drivers/crypto/mv_cesa.c
@@ -857,7 +857,7 @@ static int mv_cra_hash_init(struct crypto_tfm *tfm, const char *base_hash_name,
857 printk(KERN_WARNING MV_CESA 857 printk(KERN_WARNING MV_CESA
858 "Base driver '%s' could not be loaded!\n", 858 "Base driver '%s' could not be loaded!\n",
859 base_hash_name); 859 base_hash_name);
860 err = PTR_ERR(fallback_tfm); 860 err = PTR_ERR(base_hash);
861 goto err_bad_base; 861 goto err_bad_base;
862 } 862 }
863 } 863 }
diff --git a/drivers/crypto/n2_core.c b/drivers/crypto/n2_core.c
index 76141262ea1d..80dc094e78c6 100644
--- a/drivers/crypto/n2_core.c
+++ b/drivers/crypto/n2_core.c
@@ -1542,7 +1542,7 @@ out:
1542 return err; 1542 return err;
1543} 1543}
1544 1544
1545static void __exit n2_unregister_algs(void) 1545static void __devexit n2_unregister_algs(void)
1546{ 1546{
1547 mutex_lock(&spu_lock); 1547 mutex_lock(&spu_lock);
1548 if (!--algs_registered) 1548 if (!--algs_registered)
diff --git a/drivers/crypto/omap-aes.c b/drivers/crypto/omap-aes.c
index 799ca517c121..add2a1a72ba4 100644
--- a/drivers/crypto/omap-aes.c
+++ b/drivers/crypto/omap-aes.c
@@ -74,11 +74,9 @@
74#define FLAGS_CBC BIT(1) 74#define FLAGS_CBC BIT(1)
75#define FLAGS_GIV BIT(2) 75#define FLAGS_GIV BIT(2)
76 76
77#define FLAGS_NEW_KEY BIT(4) 77#define FLAGS_INIT BIT(4)
78#define FLAGS_NEW_IV BIT(5) 78#define FLAGS_FAST BIT(5)
79#define FLAGS_INIT BIT(6) 79#define FLAGS_BUSY BIT(6)
80#define FLAGS_FAST BIT(7)
81#define FLAGS_BUSY 8
82 80
83struct omap_aes_ctx { 81struct omap_aes_ctx {
84 struct omap_aes_dev *dd; 82 struct omap_aes_dev *dd;
@@ -98,19 +96,18 @@ struct omap_aes_reqctx {
98struct omap_aes_dev { 96struct omap_aes_dev {
99 struct list_head list; 97 struct list_head list;
100 unsigned long phys_base; 98 unsigned long phys_base;
101 void __iomem *io_base; 99 void __iomem *io_base;
102 struct clk *iclk; 100 struct clk *iclk;
103 struct omap_aes_ctx *ctx; 101 struct omap_aes_ctx *ctx;
104 struct device *dev; 102 struct device *dev;
105 unsigned long flags; 103 unsigned long flags;
104 int err;
106 105
107 u32 *iv; 106 spinlock_t lock;
108 u32 ctrl; 107 struct crypto_queue queue;
109 108
110 spinlock_t lock; 109 struct tasklet_struct done_task;
111 struct crypto_queue queue; 110 struct tasklet_struct queue_task;
112
113 struct tasklet_struct task;
114 111
115 struct ablkcipher_request *req; 112 struct ablkcipher_request *req;
116 size_t total; 113 size_t total;
@@ -179,9 +176,13 @@ static int omap_aes_wait(struct omap_aes_dev *dd, u32 offset, u32 bit)
179 176
180static int omap_aes_hw_init(struct omap_aes_dev *dd) 177static int omap_aes_hw_init(struct omap_aes_dev *dd)
181{ 178{
182 int err = 0; 179 /*
183 180 * clocks are enabled when request starts and disabled when finished.
181 * It may be long delays between requests.
182 * Device might go to off mode to save power.
183 */
184 clk_enable(dd->iclk); 184 clk_enable(dd->iclk);
185
185 if (!(dd->flags & FLAGS_INIT)) { 186 if (!(dd->flags & FLAGS_INIT)) {
186 /* is it necessary to reset before every operation? */ 187 /* is it necessary to reset before every operation? */
187 omap_aes_write_mask(dd, AES_REG_MASK, AES_REG_MASK_SOFTRESET, 188 omap_aes_write_mask(dd, AES_REG_MASK, AES_REG_MASK_SOFTRESET,
@@ -193,39 +194,26 @@ static int omap_aes_hw_init(struct omap_aes_dev *dd)
193 __asm__ __volatile__("nop"); 194 __asm__ __volatile__("nop");
194 __asm__ __volatile__("nop"); 195 __asm__ __volatile__("nop");
195 196
196 err = omap_aes_wait(dd, AES_REG_SYSSTATUS, 197 if (omap_aes_wait(dd, AES_REG_SYSSTATUS,
197 AES_REG_SYSSTATUS_RESETDONE); 198 AES_REG_SYSSTATUS_RESETDONE))
198 if (!err) 199 return -ETIMEDOUT;
199 dd->flags |= FLAGS_INIT;
200 }
201 200
202 return err; 201 dd->flags |= FLAGS_INIT;
203} 202 dd->err = 0;
203 }
204 204
205static void omap_aes_hw_cleanup(struct omap_aes_dev *dd) 205 return 0;
206{
207 clk_disable(dd->iclk);
208} 206}
209 207
210static void omap_aes_write_ctrl(struct omap_aes_dev *dd) 208static int omap_aes_write_ctrl(struct omap_aes_dev *dd)
211{ 209{
212 unsigned int key32; 210 unsigned int key32;
213 int i; 211 int i, err;
214 u32 val, mask; 212 u32 val, mask;
215 213
216 val = FLD_VAL(((dd->ctx->keylen >> 3) - 1), 4, 3); 214 err = omap_aes_hw_init(dd);
217 if (dd->flags & FLAGS_CBC) 215 if (err)
218 val |= AES_REG_CTRL_CBC; 216 return err;
219 if (dd->flags & FLAGS_ENCRYPT)
220 val |= AES_REG_CTRL_DIRECTION;
221
222 if (dd->ctrl == val && !(dd->flags & FLAGS_NEW_IV) &&
223 !(dd->ctx->flags & FLAGS_NEW_KEY))
224 goto out;
225
226 /* only need to write control registers for new settings */
227
228 dd->ctrl = val;
229 217
230 val = 0; 218 val = 0;
231 if (dd->dma_lch_out >= 0) 219 if (dd->dma_lch_out >= 0)
@@ -237,30 +225,43 @@ static void omap_aes_write_ctrl(struct omap_aes_dev *dd)
237 225
238 omap_aes_write_mask(dd, AES_REG_MASK, val, mask); 226 omap_aes_write_mask(dd, AES_REG_MASK, val, mask);
239 227
240 pr_debug("Set key\n");
241 key32 = dd->ctx->keylen / sizeof(u32); 228 key32 = dd->ctx->keylen / sizeof(u32);
242 /* set a key */ 229
230 /* it seems a key should always be set even if it has not changed */
243 for (i = 0; i < key32; i++) { 231 for (i = 0; i < key32; i++) {
244 omap_aes_write(dd, AES_REG_KEY(i), 232 omap_aes_write(dd, AES_REG_KEY(i),
245 __le32_to_cpu(dd->ctx->key[i])); 233 __le32_to_cpu(dd->ctx->key[i]));
246 } 234 }
247 dd->ctx->flags &= ~FLAGS_NEW_KEY;
248 235
249 if (dd->flags & FLAGS_NEW_IV) { 236 if ((dd->flags & FLAGS_CBC) && dd->req->info)
250 pr_debug("Set IV\n"); 237 omap_aes_write_n(dd, AES_REG_IV(0), dd->req->info, 4);
251 omap_aes_write_n(dd, AES_REG_IV(0), dd->iv, 4); 238
252 dd->flags &= ~FLAGS_NEW_IV; 239 val = FLD_VAL(((dd->ctx->keylen >> 3) - 1), 4, 3);
253 } 240 if (dd->flags & FLAGS_CBC)
241 val |= AES_REG_CTRL_CBC;
242 if (dd->flags & FLAGS_ENCRYPT)
243 val |= AES_REG_CTRL_DIRECTION;
254 244
255 mask = AES_REG_CTRL_CBC | AES_REG_CTRL_DIRECTION | 245 mask = AES_REG_CTRL_CBC | AES_REG_CTRL_DIRECTION |
256 AES_REG_CTRL_KEY_SIZE; 246 AES_REG_CTRL_KEY_SIZE;
257 247
258 omap_aes_write_mask(dd, AES_REG_CTRL, dd->ctrl, mask); 248 omap_aes_write_mask(dd, AES_REG_CTRL, val, mask);
259 249
260out: 250 /* IN */
261 /* start DMA or disable idle mode */ 251 omap_set_dma_dest_params(dd->dma_lch_in, 0, OMAP_DMA_AMODE_CONSTANT,
262 omap_aes_write_mask(dd, AES_REG_MASK, AES_REG_MASK_START, 252 dd->phys_base + AES_REG_DATA, 0, 4);
263 AES_REG_MASK_START); 253
254 omap_set_dma_dest_burst_mode(dd->dma_lch_in, OMAP_DMA_DATA_BURST_4);
255 omap_set_dma_src_burst_mode(dd->dma_lch_in, OMAP_DMA_DATA_BURST_4);
256
257 /* OUT */
258 omap_set_dma_src_params(dd->dma_lch_out, 0, OMAP_DMA_AMODE_CONSTANT,
259 dd->phys_base + AES_REG_DATA, 0, 4);
260
261 omap_set_dma_src_burst_mode(dd->dma_lch_out, OMAP_DMA_DATA_BURST_4);
262 omap_set_dma_dest_burst_mode(dd->dma_lch_out, OMAP_DMA_DATA_BURST_4);
263
264 return 0;
264} 265}
265 266
266static struct omap_aes_dev *omap_aes_find_dev(struct omap_aes_ctx *ctx) 267static struct omap_aes_dev *omap_aes_find_dev(struct omap_aes_ctx *ctx)
@@ -288,8 +289,16 @@ static void omap_aes_dma_callback(int lch, u16 ch_status, void *data)
288{ 289{
289 struct omap_aes_dev *dd = data; 290 struct omap_aes_dev *dd = data;
290 291
291 if (lch == dd->dma_lch_out) 292 if (ch_status != OMAP_DMA_BLOCK_IRQ) {
292 tasklet_schedule(&dd->task); 293 pr_err("omap-aes DMA error status: 0x%hx\n", ch_status);
294 dd->err = -EIO;
295 dd->flags &= ~FLAGS_INIT; /* request to re-initialize */
296 } else if (lch == dd->dma_lch_in) {
297 return;
298 }
299
300 /* dma_lch_out - completed */
301 tasklet_schedule(&dd->done_task);
293} 302}
294 303
295static int omap_aes_dma_init(struct omap_aes_dev *dd) 304static int omap_aes_dma_init(struct omap_aes_dev *dd)
@@ -339,18 +348,6 @@ static int omap_aes_dma_init(struct omap_aes_dev *dd)
339 goto err_dma_out; 348 goto err_dma_out;
340 } 349 }
341 350
342 omap_set_dma_dest_params(dd->dma_lch_in, 0, OMAP_DMA_AMODE_CONSTANT,
343 dd->phys_base + AES_REG_DATA, 0, 4);
344
345 omap_set_dma_dest_burst_mode(dd->dma_lch_in, OMAP_DMA_DATA_BURST_4);
346 omap_set_dma_src_burst_mode(dd->dma_lch_in, OMAP_DMA_DATA_BURST_4);
347
348 omap_set_dma_src_params(dd->dma_lch_out, 0, OMAP_DMA_AMODE_CONSTANT,
349 dd->phys_base + AES_REG_DATA, 0, 4);
350
351 omap_set_dma_src_burst_mode(dd->dma_lch_out, OMAP_DMA_DATA_BURST_4);
352 omap_set_dma_dest_burst_mode(dd->dma_lch_out, OMAP_DMA_DATA_BURST_4);
353
354 return 0; 351 return 0;
355 352
356err_dma_out: 353err_dma_out:
@@ -406,6 +403,11 @@ static int sg_copy(struct scatterlist **sg, size_t *offset, void *buf,
406 if (!count) 403 if (!count)
407 return off; 404 return off;
408 405
406 /*
407 * buflen and total are AES_BLOCK_SIZE size aligned,
408 * so count should be also aligned
409 */
410
409 sg_copy_buf(buf + off, *sg, *offset, count, out); 411 sg_copy_buf(buf + off, *sg, *offset, count, out);
410 412
411 off += count; 413 off += count;
@@ -461,7 +463,9 @@ static int omap_aes_crypt_dma(struct crypto_tfm *tfm, dma_addr_t dma_addr_in,
461 omap_start_dma(dd->dma_lch_in); 463 omap_start_dma(dd->dma_lch_in);
462 omap_start_dma(dd->dma_lch_out); 464 omap_start_dma(dd->dma_lch_out);
463 465
464 omap_aes_write_ctrl(dd); 466 /* start DMA or disable idle mode */
467 omap_aes_write_mask(dd, AES_REG_MASK, AES_REG_MASK_START,
468 AES_REG_MASK_START);
465 469
466 return 0; 470 return 0;
467} 471}
@@ -488,8 +492,10 @@ static int omap_aes_crypt_dma_start(struct omap_aes_dev *dd)
488 count = min(dd->total, sg_dma_len(dd->in_sg)); 492 count = min(dd->total, sg_dma_len(dd->in_sg));
489 count = min(count, sg_dma_len(dd->out_sg)); 493 count = min(count, sg_dma_len(dd->out_sg));
490 494
491 if (count != dd->total) 495 if (count != dd->total) {
496 pr_err("request length != buffer length\n");
492 return -EINVAL; 497 return -EINVAL;
498 }
493 499
494 pr_debug("fast\n"); 500 pr_debug("fast\n");
495 501
@@ -525,23 +531,25 @@ static int omap_aes_crypt_dma_start(struct omap_aes_dev *dd)
525 531
526 dd->total -= count; 532 dd->total -= count;
527 533
528 err = omap_aes_hw_init(dd);
529
530 err = omap_aes_crypt_dma(tfm, addr_in, addr_out, count); 534 err = omap_aes_crypt_dma(tfm, addr_in, addr_out, count);
535 if (err) {
536 dma_unmap_sg(dd->dev, dd->in_sg, 1, DMA_TO_DEVICE);
537 dma_unmap_sg(dd->dev, dd->out_sg, 1, DMA_TO_DEVICE);
538 }
531 539
532 return err; 540 return err;
533} 541}
534 542
535static void omap_aes_finish_req(struct omap_aes_dev *dd, int err) 543static void omap_aes_finish_req(struct omap_aes_dev *dd, int err)
536{ 544{
537 struct omap_aes_ctx *ctx; 545 struct ablkcipher_request *req = dd->req;
538 546
539 pr_debug("err: %d\n", err); 547 pr_debug("err: %d\n", err);
540 548
541 ctx = crypto_ablkcipher_ctx(crypto_ablkcipher_reqtfm(dd->req)); 549 clk_disable(dd->iclk);
550 dd->flags &= ~FLAGS_BUSY;
542 551
543 if (!dd->total) 552 req->base.complete(&req->base, err);
544 dd->req->base.complete(&dd->req->base, err);
545} 553}
546 554
547static int omap_aes_crypt_dma_stop(struct omap_aes_dev *dd) 555static int omap_aes_crypt_dma_stop(struct omap_aes_dev *dd)
@@ -553,8 +561,6 @@ static int omap_aes_crypt_dma_stop(struct omap_aes_dev *dd)
553 561
554 omap_aes_write_mask(dd, AES_REG_MASK, 0, AES_REG_MASK_START); 562 omap_aes_write_mask(dd, AES_REG_MASK, 0, AES_REG_MASK_START);
555 563
556 omap_aes_hw_cleanup(dd);
557
558 omap_stop_dma(dd->dma_lch_in); 564 omap_stop_dma(dd->dma_lch_in);
559 omap_stop_dma(dd->dma_lch_out); 565 omap_stop_dma(dd->dma_lch_out);
560 566
@@ -574,40 +580,39 @@ static int omap_aes_crypt_dma_stop(struct omap_aes_dev *dd)
574 } 580 }
575 } 581 }
576 582
577 if (err || !dd->total)
578 omap_aes_finish_req(dd, err);
579
580 return err; 583 return err;
581} 584}
582 585
583static int omap_aes_handle_req(struct omap_aes_dev *dd) 586static int omap_aes_handle_queue(struct omap_aes_dev *dd,
587 struct ablkcipher_request *req)
584{ 588{
585 struct crypto_async_request *async_req, *backlog; 589 struct crypto_async_request *async_req, *backlog;
586 struct omap_aes_ctx *ctx; 590 struct omap_aes_ctx *ctx;
587 struct omap_aes_reqctx *rctx; 591 struct omap_aes_reqctx *rctx;
588 struct ablkcipher_request *req;
589 unsigned long flags; 592 unsigned long flags;
590 593 int err, ret = 0;
591 if (dd->total)
592 goto start;
593 594
594 spin_lock_irqsave(&dd->lock, flags); 595 spin_lock_irqsave(&dd->lock, flags);
596 if (req)
597 ret = ablkcipher_enqueue_request(&dd->queue, req);
598 if (dd->flags & FLAGS_BUSY) {
599 spin_unlock_irqrestore(&dd->lock, flags);
600 return ret;
601 }
595 backlog = crypto_get_backlog(&dd->queue); 602 backlog = crypto_get_backlog(&dd->queue);
596 async_req = crypto_dequeue_request(&dd->queue); 603 async_req = crypto_dequeue_request(&dd->queue);
597 if (!async_req) 604 if (async_req)
598 clear_bit(FLAGS_BUSY, &dd->flags); 605 dd->flags |= FLAGS_BUSY;
599 spin_unlock_irqrestore(&dd->lock, flags); 606 spin_unlock_irqrestore(&dd->lock, flags);
600 607
601 if (!async_req) 608 if (!async_req)
602 return 0; 609 return ret;
603 610
604 if (backlog) 611 if (backlog)
605 backlog->complete(backlog, -EINPROGRESS); 612 backlog->complete(backlog, -EINPROGRESS);
606 613
607 req = ablkcipher_request_cast(async_req); 614 req = ablkcipher_request_cast(async_req);
608 615
609 pr_debug("get new req\n");
610
611 /* assign new request to device */ 616 /* assign new request to device */
612 dd->req = req; 617 dd->req = req;
613 dd->total = req->nbytes; 618 dd->total = req->nbytes;
@@ -621,27 +626,22 @@ static int omap_aes_handle_req(struct omap_aes_dev *dd)
621 rctx->mode &= FLAGS_MODE_MASK; 626 rctx->mode &= FLAGS_MODE_MASK;
622 dd->flags = (dd->flags & ~FLAGS_MODE_MASK) | rctx->mode; 627 dd->flags = (dd->flags & ~FLAGS_MODE_MASK) | rctx->mode;
623 628
624 dd->iv = req->info; 629 dd->ctx = ctx;
625 if ((dd->flags & FLAGS_CBC) && dd->iv)
626 dd->flags |= FLAGS_NEW_IV;
627 else
628 dd->flags &= ~FLAGS_NEW_IV;
629
630 ctx->dd = dd; 630 ctx->dd = dd;
631 if (dd->ctx != ctx) {
632 /* assign new context to device */
633 dd->ctx = ctx;
634 ctx->flags |= FLAGS_NEW_KEY;
635 }
636 631
637 if (!IS_ALIGNED(req->nbytes, AES_BLOCK_SIZE)) 632 err = omap_aes_write_ctrl(dd);
638 pr_err("request size is not exact amount of AES blocks\n"); 633 if (!err)
634 err = omap_aes_crypt_dma_start(dd);
635 if (err) {
636 /* aes_task will not finish it, so do it here */
637 omap_aes_finish_req(dd, err);
638 tasklet_schedule(&dd->queue_task);
639 }
639 640
640start: 641 return ret; /* return ret, which is enqueue return value */
641 return omap_aes_crypt_dma_start(dd);
642} 642}
643 643
644static void omap_aes_task(unsigned long data) 644static void omap_aes_done_task(unsigned long data)
645{ 645{
646 struct omap_aes_dev *dd = (struct omap_aes_dev *)data; 646 struct omap_aes_dev *dd = (struct omap_aes_dev *)data;
647 int err; 647 int err;
@@ -650,40 +650,50 @@ static void omap_aes_task(unsigned long data)
650 650
651 err = omap_aes_crypt_dma_stop(dd); 651 err = omap_aes_crypt_dma_stop(dd);
652 652
653 err = omap_aes_handle_req(dd); 653 err = dd->err ? : err;
654
655 if (dd->total && !err) {
656 err = omap_aes_crypt_dma_start(dd);
657 if (!err)
658 return; /* DMA started. Not fininishing. */
659 }
660
661 omap_aes_finish_req(dd, err);
662 omap_aes_handle_queue(dd, NULL);
654 663
655 pr_debug("exit\n"); 664 pr_debug("exit\n");
656} 665}
657 666
667static void omap_aes_queue_task(unsigned long data)
668{
669 struct omap_aes_dev *dd = (struct omap_aes_dev *)data;
670
671 omap_aes_handle_queue(dd, NULL);
672}
673
658static int omap_aes_crypt(struct ablkcipher_request *req, unsigned long mode) 674static int omap_aes_crypt(struct ablkcipher_request *req, unsigned long mode)
659{ 675{
660 struct omap_aes_ctx *ctx = crypto_ablkcipher_ctx( 676 struct omap_aes_ctx *ctx = crypto_ablkcipher_ctx(
661 crypto_ablkcipher_reqtfm(req)); 677 crypto_ablkcipher_reqtfm(req));
662 struct omap_aes_reqctx *rctx = ablkcipher_request_ctx(req); 678 struct omap_aes_reqctx *rctx = ablkcipher_request_ctx(req);
663 struct omap_aes_dev *dd; 679 struct omap_aes_dev *dd;
664 unsigned long flags;
665 int err;
666 680
667 pr_debug("nbytes: %d, enc: %d, cbc: %d\n", req->nbytes, 681 pr_debug("nbytes: %d, enc: %d, cbc: %d\n", req->nbytes,
668 !!(mode & FLAGS_ENCRYPT), 682 !!(mode & FLAGS_ENCRYPT),
669 !!(mode & FLAGS_CBC)); 683 !!(mode & FLAGS_CBC));
670 684
685 if (!IS_ALIGNED(req->nbytes, AES_BLOCK_SIZE)) {
686 pr_err("request size is not exact amount of AES blocks\n");
687 return -EINVAL;
688 }
689
671 dd = omap_aes_find_dev(ctx); 690 dd = omap_aes_find_dev(ctx);
672 if (!dd) 691 if (!dd)
673 return -ENODEV; 692 return -ENODEV;
674 693
675 rctx->mode = mode; 694 rctx->mode = mode;
676 695
677 spin_lock_irqsave(&dd->lock, flags); 696 return omap_aes_handle_queue(dd, req);
678 err = ablkcipher_enqueue_request(&dd->queue, req);
679 spin_unlock_irqrestore(&dd->lock, flags);
680
681 if (!test_and_set_bit(FLAGS_BUSY, &dd->flags))
682 omap_aes_handle_req(dd);
683
684 pr_debug("exit\n");
685
686 return err;
687} 697}
688 698
689/* ********************** ALG API ************************************ */ 699/* ********************** ALG API ************************************ */
@@ -701,7 +711,6 @@ static int omap_aes_setkey(struct crypto_ablkcipher *tfm, const u8 *key,
701 711
702 memcpy(ctx->key, key, keylen); 712 memcpy(ctx->key, key, keylen);
703 ctx->keylen = keylen; 713 ctx->keylen = keylen;
704 ctx->flags |= FLAGS_NEW_KEY;
705 714
706 return 0; 715 return 0;
707} 716}
@@ -750,7 +759,7 @@ static struct crypto_alg algs[] = {
750 .cra_flags = CRYPTO_ALG_TYPE_ABLKCIPHER | CRYPTO_ALG_ASYNC, 759 .cra_flags = CRYPTO_ALG_TYPE_ABLKCIPHER | CRYPTO_ALG_ASYNC,
751 .cra_blocksize = AES_BLOCK_SIZE, 760 .cra_blocksize = AES_BLOCK_SIZE,
752 .cra_ctxsize = sizeof(struct omap_aes_ctx), 761 .cra_ctxsize = sizeof(struct omap_aes_ctx),
753 .cra_alignmask = 0, 762 .cra_alignmask = 0,
754 .cra_type = &crypto_ablkcipher_type, 763 .cra_type = &crypto_ablkcipher_type,
755 .cra_module = THIS_MODULE, 764 .cra_module = THIS_MODULE,
756 .cra_init = omap_aes_cra_init, 765 .cra_init = omap_aes_cra_init,
@@ -770,7 +779,7 @@ static struct crypto_alg algs[] = {
770 .cra_flags = CRYPTO_ALG_TYPE_ABLKCIPHER | CRYPTO_ALG_ASYNC, 779 .cra_flags = CRYPTO_ALG_TYPE_ABLKCIPHER | CRYPTO_ALG_ASYNC,
771 .cra_blocksize = AES_BLOCK_SIZE, 780 .cra_blocksize = AES_BLOCK_SIZE,
772 .cra_ctxsize = sizeof(struct omap_aes_ctx), 781 .cra_ctxsize = sizeof(struct omap_aes_ctx),
773 .cra_alignmask = 0, 782 .cra_alignmask = 0,
774 .cra_type = &crypto_ablkcipher_type, 783 .cra_type = &crypto_ablkcipher_type,
775 .cra_module = THIS_MODULE, 784 .cra_module = THIS_MODULE,
776 .cra_init = omap_aes_cra_init, 785 .cra_init = omap_aes_cra_init,
@@ -849,7 +858,8 @@ static int omap_aes_probe(struct platform_device *pdev)
849 (reg & AES_REG_REV_MAJOR) >> 4, reg & AES_REG_REV_MINOR); 858 (reg & AES_REG_REV_MAJOR) >> 4, reg & AES_REG_REV_MINOR);
850 clk_disable(dd->iclk); 859 clk_disable(dd->iclk);
851 860
852 tasklet_init(&dd->task, omap_aes_task, (unsigned long)dd); 861 tasklet_init(&dd->done_task, omap_aes_done_task, (unsigned long)dd);
862 tasklet_init(&dd->queue_task, omap_aes_queue_task, (unsigned long)dd);
853 863
854 err = omap_aes_dma_init(dd); 864 err = omap_aes_dma_init(dd);
855 if (err) 865 if (err)
@@ -876,7 +886,8 @@ err_algs:
876 crypto_unregister_alg(&algs[j]); 886 crypto_unregister_alg(&algs[j]);
877 omap_aes_dma_cleanup(dd); 887 omap_aes_dma_cleanup(dd);
878err_dma: 888err_dma:
879 tasklet_kill(&dd->task); 889 tasklet_kill(&dd->done_task);
890 tasklet_kill(&dd->queue_task);
880 iounmap(dd->io_base); 891 iounmap(dd->io_base);
881err_io: 892err_io:
882 clk_put(dd->iclk); 893 clk_put(dd->iclk);
@@ -903,7 +914,8 @@ static int omap_aes_remove(struct platform_device *pdev)
903 for (i = 0; i < ARRAY_SIZE(algs); i++) 914 for (i = 0; i < ARRAY_SIZE(algs); i++)
904 crypto_unregister_alg(&algs[i]); 915 crypto_unregister_alg(&algs[i]);
905 916
906 tasklet_kill(&dd->task); 917 tasklet_kill(&dd->done_task);
918 tasklet_kill(&dd->queue_task);
907 omap_aes_dma_cleanup(dd); 919 omap_aes_dma_cleanup(dd);
908 iounmap(dd->io_base); 920 iounmap(dd->io_base);
909 clk_put(dd->iclk); 921 clk_put(dd->iclk);
diff --git a/drivers/crypto/omap-sham.c b/drivers/crypto/omap-sham.c
index a081c7c7d03f..2e71123516e0 100644
--- a/drivers/crypto/omap-sham.c
+++ b/drivers/crypto/omap-sham.c
@@ -72,10 +72,9 @@
72 72
73#define DEFAULT_TIMEOUT_INTERVAL HZ 73#define DEFAULT_TIMEOUT_INTERVAL HZ
74 74
75#define FLAGS_FIRST 0x0001
76#define FLAGS_FINUP 0x0002 75#define FLAGS_FINUP 0x0002
77#define FLAGS_FINAL 0x0004 76#define FLAGS_FINAL 0x0004
78#define FLAGS_FAST 0x0008 77#define FLAGS_SG 0x0008
79#define FLAGS_SHA1 0x0010 78#define FLAGS_SHA1 0x0010
80#define FLAGS_DMA_ACTIVE 0x0020 79#define FLAGS_DMA_ACTIVE 0x0020
81#define FLAGS_OUTPUT_READY 0x0040 80#define FLAGS_OUTPUT_READY 0x0040
@@ -83,13 +82,17 @@
83#define FLAGS_INIT 0x0100 82#define FLAGS_INIT 0x0100
84#define FLAGS_CPU 0x0200 83#define FLAGS_CPU 0x0200
85#define FLAGS_HMAC 0x0400 84#define FLAGS_HMAC 0x0400
86 85#define FLAGS_ERROR 0x0800
87/* 3rd byte */ 86#define FLAGS_BUSY 0x1000
88#define FLAGS_BUSY 16
89 87
90#define OP_UPDATE 1 88#define OP_UPDATE 1
91#define OP_FINAL 2 89#define OP_FINAL 2
92 90
91#define OMAP_ALIGN_MASK (sizeof(u32)-1)
92#define OMAP_ALIGNED __attribute__((aligned(sizeof(u32))))
93
94#define BUFLEN PAGE_SIZE
95
93struct omap_sham_dev; 96struct omap_sham_dev;
94 97
95struct omap_sham_reqctx { 98struct omap_sham_reqctx {
@@ -97,8 +100,8 @@ struct omap_sham_reqctx {
97 unsigned long flags; 100 unsigned long flags;
98 unsigned long op; 101 unsigned long op;
99 102
103 u8 digest[SHA1_DIGEST_SIZE] OMAP_ALIGNED;
100 size_t digcnt; 104 size_t digcnt;
101 u8 *buffer;
102 size_t bufcnt; 105 size_t bufcnt;
103 size_t buflen; 106 size_t buflen;
104 dma_addr_t dma_addr; 107 dma_addr_t dma_addr;
@@ -107,6 +110,8 @@ struct omap_sham_reqctx {
107 struct scatterlist *sg; 110 struct scatterlist *sg;
108 unsigned int offset; /* offset in current sg */ 111 unsigned int offset; /* offset in current sg */
109 unsigned int total; /* total request */ 112 unsigned int total; /* total request */
113
114 u8 buffer[0] OMAP_ALIGNED;
110}; 115};
111 116
112struct omap_sham_hmac_ctx { 117struct omap_sham_hmac_ctx {
@@ -136,6 +141,7 @@ struct omap_sham_dev {
136 int irq; 141 int irq;
137 struct clk *iclk; 142 struct clk *iclk;
138 spinlock_t lock; 143 spinlock_t lock;
144 int err;
139 int dma; 145 int dma;
140 int dma_lch; 146 int dma_lch;
141 struct tasklet_struct done_task; 147 struct tasklet_struct done_task;
@@ -194,53 +200,68 @@ static inline int omap_sham_wait(struct omap_sham_dev *dd, u32 offset, u32 bit)
194static void omap_sham_copy_hash(struct ahash_request *req, int out) 200static void omap_sham_copy_hash(struct ahash_request *req, int out)
195{ 201{
196 struct omap_sham_reqctx *ctx = ahash_request_ctx(req); 202 struct omap_sham_reqctx *ctx = ahash_request_ctx(req);
203 u32 *hash = (u32 *)ctx->digest;
204 int i;
205
206 /* MD5 is almost unused. So copy sha1 size to reduce code */
207 for (i = 0; i < SHA1_DIGEST_SIZE / sizeof(u32); i++) {
208 if (out)
209 hash[i] = omap_sham_read(ctx->dd,
210 SHA_REG_DIGEST(i));
211 else
212 omap_sham_write(ctx->dd,
213 SHA_REG_DIGEST(i), hash[i]);
214 }
215}
216
217static void omap_sham_copy_ready_hash(struct ahash_request *req)
218{
219 struct omap_sham_reqctx *ctx = ahash_request_ctx(req);
220 u32 *in = (u32 *)ctx->digest;
197 u32 *hash = (u32 *)req->result; 221 u32 *hash = (u32 *)req->result;
198 int i; 222 int i;
199 223
224 if (!hash)
225 return;
226
200 if (likely(ctx->flags & FLAGS_SHA1)) { 227 if (likely(ctx->flags & FLAGS_SHA1)) {
201 /* SHA1 results are in big endian */ 228 /* SHA1 results are in big endian */
202 for (i = 0; i < SHA1_DIGEST_SIZE / sizeof(u32); i++) 229 for (i = 0; i < SHA1_DIGEST_SIZE / sizeof(u32); i++)
203 if (out) 230 hash[i] = be32_to_cpu(in[i]);
204 hash[i] = be32_to_cpu(omap_sham_read(ctx->dd,
205 SHA_REG_DIGEST(i)));
206 else
207 omap_sham_write(ctx->dd, SHA_REG_DIGEST(i),
208 cpu_to_be32(hash[i]));
209 } else { 231 } else {
210 /* MD5 results are in little endian */ 232 /* MD5 results are in little endian */
211 for (i = 0; i < MD5_DIGEST_SIZE / sizeof(u32); i++) 233 for (i = 0; i < MD5_DIGEST_SIZE / sizeof(u32); i++)
212 if (out) 234 hash[i] = le32_to_cpu(in[i]);
213 hash[i] = le32_to_cpu(omap_sham_read(ctx->dd,
214 SHA_REG_DIGEST(i)));
215 else
216 omap_sham_write(ctx->dd, SHA_REG_DIGEST(i),
217 cpu_to_le32(hash[i]));
218 } 235 }
219} 236}
220 237
221static int omap_sham_write_ctrl(struct omap_sham_dev *dd, size_t length, 238static int omap_sham_hw_init(struct omap_sham_dev *dd)
222 int final, int dma)
223{ 239{
224 struct omap_sham_reqctx *ctx = ahash_request_ctx(dd->req); 240 clk_enable(dd->iclk);
225 u32 val = length << 5, mask;
226 241
227 if (unlikely(!ctx->digcnt)) { 242 if (!(dd->flags & FLAGS_INIT)) {
243 omap_sham_write_mask(dd, SHA_REG_MASK,
244 SHA_REG_MASK_SOFTRESET, SHA_REG_MASK_SOFTRESET);
228 245
229 clk_enable(dd->iclk); 246 if (omap_sham_wait(dd, SHA_REG_SYSSTATUS,
247 SHA_REG_SYSSTATUS_RESETDONE))
248 return -ETIMEDOUT;
230 249
231 if (!(dd->flags & FLAGS_INIT)) { 250 dd->flags |= FLAGS_INIT;
232 omap_sham_write_mask(dd, SHA_REG_MASK, 251 dd->err = 0;
233 SHA_REG_MASK_SOFTRESET, SHA_REG_MASK_SOFTRESET); 252 }
234 253
235 if (omap_sham_wait(dd, SHA_REG_SYSSTATUS, 254 return 0;
236 SHA_REG_SYSSTATUS_RESETDONE)) 255}
237 return -ETIMEDOUT;
238 256
239 dd->flags |= FLAGS_INIT; 257static void omap_sham_write_ctrl(struct omap_sham_dev *dd, size_t length,
240 } 258 int final, int dma)
241 } else { 259{
260 struct omap_sham_reqctx *ctx = ahash_request_ctx(dd->req);
261 u32 val = length << 5, mask;
262
263 if (likely(ctx->digcnt))
242 omap_sham_write(dd, SHA_REG_DIGCNT, ctx->digcnt); 264 omap_sham_write(dd, SHA_REG_DIGCNT, ctx->digcnt);
243 }
244 265
245 omap_sham_write_mask(dd, SHA_REG_MASK, 266 omap_sham_write_mask(dd, SHA_REG_MASK,
246 SHA_REG_MASK_IT_EN | (dma ? SHA_REG_MASK_DMA_EN : 0), 267 SHA_REG_MASK_IT_EN | (dma ? SHA_REG_MASK_DMA_EN : 0),
@@ -260,29 +281,26 @@ static int omap_sham_write_ctrl(struct omap_sham_dev *dd, size_t length,
260 SHA_REG_CTRL_ALGO | SHA_REG_CTRL_LENGTH; 281 SHA_REG_CTRL_ALGO | SHA_REG_CTRL_LENGTH;
261 282
262 omap_sham_write_mask(dd, SHA_REG_CTRL, val, mask); 283 omap_sham_write_mask(dd, SHA_REG_CTRL, val, mask);
263
264 return 0;
265} 284}
266 285
267static int omap_sham_xmit_cpu(struct omap_sham_dev *dd, const u8 *buf, 286static int omap_sham_xmit_cpu(struct omap_sham_dev *dd, const u8 *buf,
268 size_t length, int final) 287 size_t length, int final)
269{ 288{
270 struct omap_sham_reqctx *ctx = ahash_request_ctx(dd->req); 289 struct omap_sham_reqctx *ctx = ahash_request_ctx(dd->req);
271 int err, count, len32; 290 int count, len32;
272 const u32 *buffer = (const u32 *)buf; 291 const u32 *buffer = (const u32 *)buf;
273 292
274 dev_dbg(dd->dev, "xmit_cpu: digcnt: %d, length: %d, final: %d\n", 293 dev_dbg(dd->dev, "xmit_cpu: digcnt: %d, length: %d, final: %d\n",
275 ctx->digcnt, length, final); 294 ctx->digcnt, length, final);
276 295
277 err = omap_sham_write_ctrl(dd, length, final, 0); 296 omap_sham_write_ctrl(dd, length, final, 0);
278 if (err) 297
279 return err; 298 /* should be non-zero before next lines to disable clocks later */
299 ctx->digcnt += length;
280 300
281 if (omap_sham_wait(dd, SHA_REG_CTRL, SHA_REG_CTRL_INPUT_READY)) 301 if (omap_sham_wait(dd, SHA_REG_CTRL, SHA_REG_CTRL_INPUT_READY))
282 return -ETIMEDOUT; 302 return -ETIMEDOUT;
283 303
284 ctx->digcnt += length;
285
286 if (final) 304 if (final)
287 ctx->flags |= FLAGS_FINAL; /* catch last interrupt */ 305 ctx->flags |= FLAGS_FINAL; /* catch last interrupt */
288 306
@@ -298,16 +316,11 @@ static int omap_sham_xmit_dma(struct omap_sham_dev *dd, dma_addr_t dma_addr,
298 size_t length, int final) 316 size_t length, int final)
299{ 317{
300 struct omap_sham_reqctx *ctx = ahash_request_ctx(dd->req); 318 struct omap_sham_reqctx *ctx = ahash_request_ctx(dd->req);
301 int err, len32; 319 int len32;
302 320
303 dev_dbg(dd->dev, "xmit_dma: digcnt: %d, length: %d, final: %d\n", 321 dev_dbg(dd->dev, "xmit_dma: digcnt: %d, length: %d, final: %d\n",
304 ctx->digcnt, length, final); 322 ctx->digcnt, length, final);
305 323
306 /* flush cache entries related to our page */
307 if (dma_addr == ctx->dma_addr)
308 dma_sync_single_for_device(dd->dev, dma_addr, length,
309 DMA_TO_DEVICE);
310
311 len32 = DIV_ROUND_UP(length, sizeof(u32)); 324 len32 = DIV_ROUND_UP(length, sizeof(u32));
312 325
313 omap_set_dma_transfer_params(dd->dma_lch, OMAP_DMA_DATA_TYPE_S32, len32, 326 omap_set_dma_transfer_params(dd->dma_lch, OMAP_DMA_DATA_TYPE_S32, len32,
@@ -317,9 +330,7 @@ static int omap_sham_xmit_dma(struct omap_sham_dev *dd, dma_addr_t dma_addr,
317 omap_set_dma_src_params(dd->dma_lch, 0, OMAP_DMA_AMODE_POST_INC, 330 omap_set_dma_src_params(dd->dma_lch, 0, OMAP_DMA_AMODE_POST_INC,
318 dma_addr, 0, 0); 331 dma_addr, 0, 0);
319 332
320 err = omap_sham_write_ctrl(dd, length, final, 1); 333 omap_sham_write_ctrl(dd, length, final, 1);
321 if (err)
322 return err;
323 334
324 ctx->digcnt += length; 335 ctx->digcnt += length;
325 336
@@ -371,15 +382,29 @@ static size_t omap_sham_append_sg(struct omap_sham_reqctx *ctx)
371 return 0; 382 return 0;
372} 383}
373 384
385static int omap_sham_xmit_dma_map(struct omap_sham_dev *dd,
386 struct omap_sham_reqctx *ctx,
387 size_t length, int final)
388{
389 ctx->dma_addr = dma_map_single(dd->dev, ctx->buffer, ctx->buflen,
390 DMA_TO_DEVICE);
391 if (dma_mapping_error(dd->dev, ctx->dma_addr)) {
392 dev_err(dd->dev, "dma %u bytes error\n", ctx->buflen);
393 return -EINVAL;
394 }
395
396 ctx->flags &= ~FLAGS_SG;
397
398 /* next call does not fail... so no unmap in the case of error */
399 return omap_sham_xmit_dma(dd, ctx->dma_addr, length, final);
400}
401
374static int omap_sham_update_dma_slow(struct omap_sham_dev *dd) 402static int omap_sham_update_dma_slow(struct omap_sham_dev *dd)
375{ 403{
376 struct omap_sham_reqctx *ctx = ahash_request_ctx(dd->req); 404 struct omap_sham_reqctx *ctx = ahash_request_ctx(dd->req);
377 unsigned int final; 405 unsigned int final;
378 size_t count; 406 size_t count;
379 407
380 if (!ctx->total)
381 return 0;
382
383 omap_sham_append_sg(ctx); 408 omap_sham_append_sg(ctx);
384 409
385 final = (ctx->flags & FLAGS_FINUP) && !ctx->total; 410 final = (ctx->flags & FLAGS_FINUP) && !ctx->total;
@@ -390,30 +415,68 @@ static int omap_sham_update_dma_slow(struct omap_sham_dev *dd)
390 if (final || (ctx->bufcnt == ctx->buflen && ctx->total)) { 415 if (final || (ctx->bufcnt == ctx->buflen && ctx->total)) {
391 count = ctx->bufcnt; 416 count = ctx->bufcnt;
392 ctx->bufcnt = 0; 417 ctx->bufcnt = 0;
393 return omap_sham_xmit_dma(dd, ctx->dma_addr, count, final); 418 return omap_sham_xmit_dma_map(dd, ctx, count, final);
394 } 419 }
395 420
396 return 0; 421 return 0;
397} 422}
398 423
399static int omap_sham_update_dma_fast(struct omap_sham_dev *dd) 424/* Start address alignment */
425#define SG_AA(sg) (IS_ALIGNED(sg->offset, sizeof(u32)))
426/* SHA1 block size alignment */
427#define SG_SA(sg) (IS_ALIGNED(sg->length, SHA1_MD5_BLOCK_SIZE))
428
429static int omap_sham_update_dma_start(struct omap_sham_dev *dd)
400{ 430{
401 struct omap_sham_reqctx *ctx = ahash_request_ctx(dd->req); 431 struct omap_sham_reqctx *ctx = ahash_request_ctx(dd->req);
402 unsigned int length; 432 unsigned int length, final, tail;
433 struct scatterlist *sg;
403 434
404 ctx->flags |= FLAGS_FAST; 435 if (!ctx->total)
436 return 0;
437
438 if (ctx->bufcnt || ctx->offset)
439 return omap_sham_update_dma_slow(dd);
440
441 dev_dbg(dd->dev, "fast: digcnt: %d, bufcnt: %u, total: %u\n",
442 ctx->digcnt, ctx->bufcnt, ctx->total);
443
444 sg = ctx->sg;
405 445
406 length = min(ctx->total, sg_dma_len(ctx->sg)); 446 if (!SG_AA(sg))
407 ctx->total = length; 447 return omap_sham_update_dma_slow(dd);
448
449 if (!sg_is_last(sg) && !SG_SA(sg))
450 /* size is not SHA1_BLOCK_SIZE aligned */
451 return omap_sham_update_dma_slow(dd);
452
453 length = min(ctx->total, sg->length);
454
455 if (sg_is_last(sg)) {
456 if (!(ctx->flags & FLAGS_FINUP)) {
457 /* not last sg must be SHA1_MD5_BLOCK_SIZE aligned */
458 tail = length & (SHA1_MD5_BLOCK_SIZE - 1);
459 /* without finup() we need one block to close hash */
460 if (!tail)
461 tail = SHA1_MD5_BLOCK_SIZE;
462 length -= tail;
463 }
464 }
408 465
409 if (!dma_map_sg(dd->dev, ctx->sg, 1, DMA_TO_DEVICE)) { 466 if (!dma_map_sg(dd->dev, ctx->sg, 1, DMA_TO_DEVICE)) {
410 dev_err(dd->dev, "dma_map_sg error\n"); 467 dev_err(dd->dev, "dma_map_sg error\n");
411 return -EINVAL; 468 return -EINVAL;
412 } 469 }
413 470
471 ctx->flags |= FLAGS_SG;
472
414 ctx->total -= length; 473 ctx->total -= length;
474 ctx->offset = length; /* offset where to start slow */
415 475
416 return omap_sham_xmit_dma(dd, sg_dma_address(ctx->sg), length, 1); 476 final = (ctx->flags & FLAGS_FINUP) && !ctx->total;
477
478 /* next call does not fail... so no unmap in the case of error */
479 return omap_sham_xmit_dma(dd, sg_dma_address(ctx->sg), length, final);
417} 480}
418 481
419static int omap_sham_update_cpu(struct omap_sham_dev *dd) 482static int omap_sham_update_cpu(struct omap_sham_dev *dd)
@@ -433,8 +496,17 @@ static int omap_sham_update_dma_stop(struct omap_sham_dev *dd)
433 struct omap_sham_reqctx *ctx = ahash_request_ctx(dd->req); 496 struct omap_sham_reqctx *ctx = ahash_request_ctx(dd->req);
434 497
435 omap_stop_dma(dd->dma_lch); 498 omap_stop_dma(dd->dma_lch);
436 if (ctx->flags & FLAGS_FAST) 499 if (ctx->flags & FLAGS_SG) {
437 dma_unmap_sg(dd->dev, ctx->sg, 1, DMA_TO_DEVICE); 500 dma_unmap_sg(dd->dev, ctx->sg, 1, DMA_TO_DEVICE);
501 if (ctx->sg->length == ctx->offset) {
502 ctx->sg = sg_next(ctx->sg);
503 if (ctx->sg)
504 ctx->offset = 0;
505 }
506 } else {
507 dma_unmap_single(dd->dev, ctx->dma_addr, ctx->buflen,
508 DMA_TO_DEVICE);
509 }
438 510
439 return 0; 511 return 0;
440} 512}
@@ -454,14 +526,7 @@ static void omap_sham_cleanup(struct ahash_request *req)
454 spin_unlock_irqrestore(&dd->lock, flags); 526 spin_unlock_irqrestore(&dd->lock, flags);
455 527
456 if (ctx->digcnt) 528 if (ctx->digcnt)
457 clk_disable(dd->iclk); 529 omap_sham_copy_ready_hash(req);
458
459 if (ctx->dma_addr)
460 dma_unmap_single(dd->dev, ctx->dma_addr, ctx->buflen,
461 DMA_TO_DEVICE);
462
463 if (ctx->buffer)
464 free_page((unsigned long)ctx->buffer);
465 530
466 dev_dbg(dd->dev, "digcnt: %d, bufcnt: %d\n", ctx->digcnt, ctx->bufcnt); 531 dev_dbg(dd->dev, "digcnt: %d, bufcnt: %d\n", ctx->digcnt, ctx->bufcnt);
467} 532}
@@ -489,8 +554,6 @@ static int omap_sham_init(struct ahash_request *req)
489 554
490 ctx->flags = 0; 555 ctx->flags = 0;
491 556
492 ctx->flags |= FLAGS_FIRST;
493
494 dev_dbg(dd->dev, "init: digest size: %d\n", 557 dev_dbg(dd->dev, "init: digest size: %d\n",
495 crypto_ahash_digestsize(tfm)); 558 crypto_ahash_digestsize(tfm));
496 559
@@ -499,21 +562,7 @@ static int omap_sham_init(struct ahash_request *req)
499 562
500 ctx->bufcnt = 0; 563 ctx->bufcnt = 0;
501 ctx->digcnt = 0; 564 ctx->digcnt = 0;
502 565 ctx->buflen = BUFLEN;
503 ctx->buflen = PAGE_SIZE;
504 ctx->buffer = (void *)__get_free_page(
505 (req->base.flags & CRYPTO_TFM_REQ_MAY_SLEEP) ?
506 GFP_KERNEL : GFP_ATOMIC);
507 if (!ctx->buffer)
508 return -ENOMEM;
509
510 ctx->dma_addr = dma_map_single(dd->dev, ctx->buffer, ctx->buflen,
511 DMA_TO_DEVICE);
512 if (dma_mapping_error(dd->dev, ctx->dma_addr)) {
513 dev_err(dd->dev, "dma %u bytes error\n", ctx->buflen);
514 free_page((unsigned long)ctx->buffer);
515 return -EINVAL;
516 }
517 566
518 if (tctx->flags & FLAGS_HMAC) { 567 if (tctx->flags & FLAGS_HMAC) {
519 struct omap_sham_hmac_ctx *bctx = tctx->base; 568 struct omap_sham_hmac_ctx *bctx = tctx->base;
@@ -538,10 +587,8 @@ static int omap_sham_update_req(struct omap_sham_dev *dd)
538 587
539 if (ctx->flags & FLAGS_CPU) 588 if (ctx->flags & FLAGS_CPU)
540 err = omap_sham_update_cpu(dd); 589 err = omap_sham_update_cpu(dd);
541 else if (ctx->flags & FLAGS_FAST)
542 err = omap_sham_update_dma_fast(dd);
543 else 590 else
544 err = omap_sham_update_dma_slow(dd); 591 err = omap_sham_update_dma_start(dd);
545 592
546 /* wait for dma completion before can take more data */ 593 /* wait for dma completion before can take more data */
547 dev_dbg(dd->dev, "update: err: %d, digcnt: %d\n", err, ctx->digcnt); 594 dev_dbg(dd->dev, "update: err: %d, digcnt: %d\n", err, ctx->digcnt);
@@ -560,15 +607,12 @@ static int omap_sham_final_req(struct omap_sham_dev *dd)
560 use_dma = 0; 607 use_dma = 0;
561 608
562 if (use_dma) 609 if (use_dma)
563 err = omap_sham_xmit_dma(dd, ctx->dma_addr, ctx->bufcnt, 1); 610 err = omap_sham_xmit_dma_map(dd, ctx, ctx->bufcnt, 1);
564 else 611 else
565 err = omap_sham_xmit_cpu(dd, ctx->buffer, ctx->bufcnt, 1); 612 err = omap_sham_xmit_cpu(dd, ctx->buffer, ctx->bufcnt, 1);
566 613
567 ctx->bufcnt = 0; 614 ctx->bufcnt = 0;
568 615
569 if (err != -EINPROGRESS)
570 omap_sham_cleanup(req);
571
572 dev_dbg(dd->dev, "final_req: err: %d\n", err); 616 dev_dbg(dd->dev, "final_req: err: %d\n", err);
573 617
574 return err; 618 return err;
@@ -576,6 +620,7 @@ static int omap_sham_final_req(struct omap_sham_dev *dd)
576 620
577static int omap_sham_finish_req_hmac(struct ahash_request *req) 621static int omap_sham_finish_req_hmac(struct ahash_request *req)
578{ 622{
623 struct omap_sham_reqctx *ctx = ahash_request_ctx(req);
579 struct omap_sham_ctx *tctx = crypto_tfm_ctx(req->base.tfm); 624 struct omap_sham_ctx *tctx = crypto_tfm_ctx(req->base.tfm);
580 struct omap_sham_hmac_ctx *bctx = tctx->base; 625 struct omap_sham_hmac_ctx *bctx = tctx->base;
581 int bs = crypto_shash_blocksize(bctx->shash); 626 int bs = crypto_shash_blocksize(bctx->shash);
@@ -590,48 +635,56 @@ static int omap_sham_finish_req_hmac(struct ahash_request *req)
590 635
591 return crypto_shash_init(&desc.shash) ?: 636 return crypto_shash_init(&desc.shash) ?:
592 crypto_shash_update(&desc.shash, bctx->opad, bs) ?: 637 crypto_shash_update(&desc.shash, bctx->opad, bs) ?:
593 crypto_shash_finup(&desc.shash, req->result, ds, req->result); 638 crypto_shash_finup(&desc.shash, ctx->digest, ds, ctx->digest);
594} 639}
595 640
596static void omap_sham_finish_req(struct ahash_request *req, int err) 641static void omap_sham_finish_req(struct ahash_request *req, int err)
597{ 642{
598 struct omap_sham_reqctx *ctx = ahash_request_ctx(req); 643 struct omap_sham_reqctx *ctx = ahash_request_ctx(req);
644 struct omap_sham_dev *dd = ctx->dd;
599 645
600 if (!err) { 646 if (!err) {
601 omap_sham_copy_hash(ctx->dd->req, 1); 647 omap_sham_copy_hash(ctx->dd->req, 1);
602 if (ctx->flags & FLAGS_HMAC) 648 if (ctx->flags & FLAGS_HMAC)
603 err = omap_sham_finish_req_hmac(req); 649 err = omap_sham_finish_req_hmac(req);
650 } else {
651 ctx->flags |= FLAGS_ERROR;
604 } 652 }
605 653
606 if (ctx->flags & FLAGS_FINAL) 654 if ((ctx->flags & FLAGS_FINAL) || err)
607 omap_sham_cleanup(req); 655 omap_sham_cleanup(req);
608 656
609 clear_bit(FLAGS_BUSY, &ctx->dd->flags); 657 clk_disable(dd->iclk);
658 dd->flags &= ~FLAGS_BUSY;
610 659
611 if (req->base.complete) 660 if (req->base.complete)
612 req->base.complete(&req->base, err); 661 req->base.complete(&req->base, err);
613} 662}
614 663
615static int omap_sham_handle_queue(struct omap_sham_dev *dd) 664static int omap_sham_handle_queue(struct omap_sham_dev *dd,
665 struct ahash_request *req)
616{ 666{
617 struct crypto_async_request *async_req, *backlog; 667 struct crypto_async_request *async_req, *backlog;
618 struct omap_sham_reqctx *ctx; 668 struct omap_sham_reqctx *ctx;
619 struct ahash_request *req, *prev_req; 669 struct ahash_request *prev_req;
620 unsigned long flags; 670 unsigned long flags;
621 int err = 0; 671 int err = 0, ret = 0;
622
623 if (test_and_set_bit(FLAGS_BUSY, &dd->flags))
624 return 0;
625 672
626 spin_lock_irqsave(&dd->lock, flags); 673 spin_lock_irqsave(&dd->lock, flags);
674 if (req)
675 ret = ahash_enqueue_request(&dd->queue, req);
676 if (dd->flags & FLAGS_BUSY) {
677 spin_unlock_irqrestore(&dd->lock, flags);
678 return ret;
679 }
627 backlog = crypto_get_backlog(&dd->queue); 680 backlog = crypto_get_backlog(&dd->queue);
628 async_req = crypto_dequeue_request(&dd->queue); 681 async_req = crypto_dequeue_request(&dd->queue);
629 if (!async_req) 682 if (async_req)
630 clear_bit(FLAGS_BUSY, &dd->flags); 683 dd->flags |= FLAGS_BUSY;
631 spin_unlock_irqrestore(&dd->lock, flags); 684 spin_unlock_irqrestore(&dd->lock, flags);
632 685
633 if (!async_req) 686 if (!async_req)
634 return 0; 687 return ret;
635 688
636 if (backlog) 689 if (backlog)
637 backlog->complete(backlog, -EINPROGRESS); 690 backlog->complete(backlog, -EINPROGRESS);
@@ -646,7 +699,22 @@ static int omap_sham_handle_queue(struct omap_sham_dev *dd)
646 dev_dbg(dd->dev, "handling new req, op: %lu, nbytes: %d\n", 699 dev_dbg(dd->dev, "handling new req, op: %lu, nbytes: %d\n",
647 ctx->op, req->nbytes); 700 ctx->op, req->nbytes);
648 701
649 if (req != prev_req && ctx->digcnt) 702
703 err = omap_sham_hw_init(dd);
704 if (err)
705 goto err1;
706
707 omap_set_dma_dest_params(dd->dma_lch, 0,
708 OMAP_DMA_AMODE_CONSTANT,
709 dd->phys_base + SHA_REG_DIN(0), 0, 16);
710
711 omap_set_dma_dest_burst_mode(dd->dma_lch,
712 OMAP_DMA_DATA_BURST_16);
713
714 omap_set_dma_src_burst_mode(dd->dma_lch,
715 OMAP_DMA_DATA_BURST_4);
716
717 if (ctx->digcnt)
650 /* request has changed - restore hash */ 718 /* request has changed - restore hash */
651 omap_sham_copy_hash(req, 0); 719 omap_sham_copy_hash(req, 0);
652 720
@@ -658,7 +726,7 @@ static int omap_sham_handle_queue(struct omap_sham_dev *dd)
658 } else if (ctx->op == OP_FINAL) { 726 } else if (ctx->op == OP_FINAL) {
659 err = omap_sham_final_req(dd); 727 err = omap_sham_final_req(dd);
660 } 728 }
661 729err1:
662 if (err != -EINPROGRESS) { 730 if (err != -EINPROGRESS) {
663 /* done_task will not finish it, so do it here */ 731 /* done_task will not finish it, so do it here */
664 omap_sham_finish_req(req, err); 732 omap_sham_finish_req(req, err);
@@ -667,7 +735,7 @@ static int omap_sham_handle_queue(struct omap_sham_dev *dd)
667 735
668 dev_dbg(dd->dev, "exit, err: %d\n", err); 736 dev_dbg(dd->dev, "exit, err: %d\n", err);
669 737
670 return err; 738 return ret;
671} 739}
672 740
673static int omap_sham_enqueue(struct ahash_request *req, unsigned int op) 741static int omap_sham_enqueue(struct ahash_request *req, unsigned int op)
@@ -675,18 +743,10 @@ static int omap_sham_enqueue(struct ahash_request *req, unsigned int op)
675 struct omap_sham_reqctx *ctx = ahash_request_ctx(req); 743 struct omap_sham_reqctx *ctx = ahash_request_ctx(req);
676 struct omap_sham_ctx *tctx = crypto_tfm_ctx(req->base.tfm); 744 struct omap_sham_ctx *tctx = crypto_tfm_ctx(req->base.tfm);
677 struct omap_sham_dev *dd = tctx->dd; 745 struct omap_sham_dev *dd = tctx->dd;
678 unsigned long flags;
679 int err;
680 746
681 ctx->op = op; 747 ctx->op = op;
682 748
683 spin_lock_irqsave(&dd->lock, flags); 749 return omap_sham_handle_queue(dd, req);
684 err = ahash_enqueue_request(&dd->queue, req);
685 spin_unlock_irqrestore(&dd->lock, flags);
686
687 omap_sham_handle_queue(dd);
688
689 return err;
690} 750}
691 751
692static int omap_sham_update(struct ahash_request *req) 752static int omap_sham_update(struct ahash_request *req)
@@ -709,21 +769,13 @@ static int omap_sham_update(struct ahash_request *req)
709 */ 769 */
710 omap_sham_append_sg(ctx); 770 omap_sham_append_sg(ctx);
711 return 0; 771 return 0;
712 } else if (ctx->bufcnt + ctx->total <= 64) { 772 } else if (ctx->bufcnt + ctx->total <= SHA1_MD5_BLOCK_SIZE) {
773 /*
774 * faster to use CPU for short transfers
775 */
713 ctx->flags |= FLAGS_CPU; 776 ctx->flags |= FLAGS_CPU;
714 } else if (!ctx->bufcnt && sg_is_last(ctx->sg)) {
715 /* may be can use faster functions */
716 int aligned = IS_ALIGNED((u32)ctx->sg->offset,
717 sizeof(u32));
718
719 if (aligned && (ctx->flags & FLAGS_FIRST))
720 /* digest: first and final */
721 ctx->flags |= FLAGS_FAST;
722
723 ctx->flags &= ~FLAGS_FIRST;
724 } 777 }
725 } else if (ctx->bufcnt + ctx->total <= ctx->buflen) { 778 } else if (ctx->bufcnt + ctx->total < ctx->buflen) {
726 /* if not finaup -> not fast */
727 omap_sham_append_sg(ctx); 779 omap_sham_append_sg(ctx);
728 return 0; 780 return 0;
729 } 781 }
@@ -761,12 +813,14 @@ static int omap_sham_final(struct ahash_request *req)
761 813
762 ctx->flags |= FLAGS_FINUP; 814 ctx->flags |= FLAGS_FINUP;
763 815
764 /* OMAP HW accel works only with buffers >= 9 */ 816 if (!(ctx->flags & FLAGS_ERROR)) {
765 /* HMAC is always >= 9 because of ipad */ 817 /* OMAP HW accel works only with buffers >= 9 */
766 if ((ctx->digcnt + ctx->bufcnt) < 9) 818 /* HMAC is always >= 9 because of ipad */
767 err = omap_sham_final_shash(req); 819 if ((ctx->digcnt + ctx->bufcnt) < 9)
768 else if (ctx->bufcnt) 820 err = omap_sham_final_shash(req);
769 return omap_sham_enqueue(req, OP_FINAL); 821 else if (ctx->bufcnt)
822 return omap_sham_enqueue(req, OP_FINAL);
823 }
770 824
771 omap_sham_cleanup(req); 825 omap_sham_cleanup(req);
772 826
@@ -836,6 +890,8 @@ static int omap_sham_cra_init_alg(struct crypto_tfm *tfm, const char *alg_base)
836 struct omap_sham_ctx *tctx = crypto_tfm_ctx(tfm); 890 struct omap_sham_ctx *tctx = crypto_tfm_ctx(tfm);
837 const char *alg_name = crypto_tfm_alg_name(tfm); 891 const char *alg_name = crypto_tfm_alg_name(tfm);
838 892
893 pr_info("enter\n");
894
839 /* Allocate a fallback and abort if it failed. */ 895 /* Allocate a fallback and abort if it failed. */
840 tctx->fallback = crypto_alloc_shash(alg_name, 0, 896 tctx->fallback = crypto_alloc_shash(alg_name, 0,
841 CRYPTO_ALG_NEED_FALLBACK); 897 CRYPTO_ALG_NEED_FALLBACK);
@@ -846,7 +902,7 @@ static int omap_sham_cra_init_alg(struct crypto_tfm *tfm, const char *alg_base)
846 } 902 }
847 903
848 crypto_ahash_set_reqsize(__crypto_ahash_cast(tfm), 904 crypto_ahash_set_reqsize(__crypto_ahash_cast(tfm),
849 sizeof(struct omap_sham_reqctx)); 905 sizeof(struct omap_sham_reqctx) + BUFLEN);
850 906
851 if (alg_base) { 907 if (alg_base) {
852 struct omap_sham_hmac_ctx *bctx = tctx->base; 908 struct omap_sham_hmac_ctx *bctx = tctx->base;
@@ -932,7 +988,7 @@ static struct ahash_alg algs[] = {
932 CRYPTO_ALG_NEED_FALLBACK, 988 CRYPTO_ALG_NEED_FALLBACK,
933 .cra_blocksize = SHA1_BLOCK_SIZE, 989 .cra_blocksize = SHA1_BLOCK_SIZE,
934 .cra_ctxsize = sizeof(struct omap_sham_ctx), 990 .cra_ctxsize = sizeof(struct omap_sham_ctx),
935 .cra_alignmask = 0, 991 .cra_alignmask = OMAP_ALIGN_MASK,
936 .cra_module = THIS_MODULE, 992 .cra_module = THIS_MODULE,
937 .cra_init = omap_sham_cra_init, 993 .cra_init = omap_sham_cra_init,
938 .cra_exit = omap_sham_cra_exit, 994 .cra_exit = omap_sham_cra_exit,
@@ -956,7 +1012,7 @@ static struct ahash_alg algs[] = {
956 .cra_blocksize = SHA1_BLOCK_SIZE, 1012 .cra_blocksize = SHA1_BLOCK_SIZE,
957 .cra_ctxsize = sizeof(struct omap_sham_ctx) + 1013 .cra_ctxsize = sizeof(struct omap_sham_ctx) +
958 sizeof(struct omap_sham_hmac_ctx), 1014 sizeof(struct omap_sham_hmac_ctx),
959 .cra_alignmask = 0, 1015 .cra_alignmask = OMAP_ALIGN_MASK,
960 .cra_module = THIS_MODULE, 1016 .cra_module = THIS_MODULE,
961 .cra_init = omap_sham_cra_sha1_init, 1017 .cra_init = omap_sham_cra_sha1_init,
962 .cra_exit = omap_sham_cra_exit, 1018 .cra_exit = omap_sham_cra_exit,
@@ -980,7 +1036,7 @@ static struct ahash_alg algs[] = {
980 .cra_blocksize = SHA1_BLOCK_SIZE, 1036 .cra_blocksize = SHA1_BLOCK_SIZE,
981 .cra_ctxsize = sizeof(struct omap_sham_ctx) + 1037 .cra_ctxsize = sizeof(struct omap_sham_ctx) +
982 sizeof(struct omap_sham_hmac_ctx), 1038 sizeof(struct omap_sham_hmac_ctx),
983 .cra_alignmask = 0, 1039 .cra_alignmask = OMAP_ALIGN_MASK,
984 .cra_module = THIS_MODULE, 1040 .cra_module = THIS_MODULE,
985 .cra_init = omap_sham_cra_md5_init, 1041 .cra_init = omap_sham_cra_md5_init,
986 .cra_exit = omap_sham_cra_exit, 1042 .cra_exit = omap_sham_cra_exit,
@@ -993,7 +1049,7 @@ static void omap_sham_done_task(unsigned long data)
993 struct omap_sham_dev *dd = (struct omap_sham_dev *)data; 1049 struct omap_sham_dev *dd = (struct omap_sham_dev *)data;
994 struct ahash_request *req = dd->req; 1050 struct ahash_request *req = dd->req;
995 struct omap_sham_reqctx *ctx = ahash_request_ctx(req); 1051 struct omap_sham_reqctx *ctx = ahash_request_ctx(req);
996 int ready = 1; 1052 int ready = 0, err = 0;
997 1053
998 if (ctx->flags & FLAGS_OUTPUT_READY) { 1054 if (ctx->flags & FLAGS_OUTPUT_READY) {
999 ctx->flags &= ~FLAGS_OUTPUT_READY; 1055 ctx->flags &= ~FLAGS_OUTPUT_READY;
@@ -1003,15 +1059,18 @@ static void omap_sham_done_task(unsigned long data)
1003 if (dd->flags & FLAGS_DMA_ACTIVE) { 1059 if (dd->flags & FLAGS_DMA_ACTIVE) {
1004 dd->flags &= ~FLAGS_DMA_ACTIVE; 1060 dd->flags &= ~FLAGS_DMA_ACTIVE;
1005 omap_sham_update_dma_stop(dd); 1061 omap_sham_update_dma_stop(dd);
1006 omap_sham_update_dma_slow(dd); 1062 if (!dd->err)
1063 err = omap_sham_update_dma_start(dd);
1007 } 1064 }
1008 1065
1009 if (ready && !(dd->flags & FLAGS_DMA_ACTIVE)) { 1066 err = dd->err ? : err;
1010 dev_dbg(dd->dev, "update done\n"); 1067
1068 if (err != -EINPROGRESS && (ready || err)) {
1069 dev_dbg(dd->dev, "update done: err: %d\n", err);
1011 /* finish curent request */ 1070 /* finish curent request */
1012 omap_sham_finish_req(req, 0); 1071 omap_sham_finish_req(req, err);
1013 /* start new request */ 1072 /* start new request */
1014 omap_sham_handle_queue(dd); 1073 omap_sham_handle_queue(dd, NULL);
1015 } 1074 }
1016} 1075}
1017 1076
@@ -1019,7 +1078,7 @@ static void omap_sham_queue_task(unsigned long data)
1019{ 1078{
1020 struct omap_sham_dev *dd = (struct omap_sham_dev *)data; 1079 struct omap_sham_dev *dd = (struct omap_sham_dev *)data;
1021 1080
1022 omap_sham_handle_queue(dd); 1081 omap_sham_handle_queue(dd, NULL);
1023} 1082}
1024 1083
1025static irqreturn_t omap_sham_irq(int irq, void *dev_id) 1084static irqreturn_t omap_sham_irq(int irq, void *dev_id)
@@ -1041,6 +1100,7 @@ static irqreturn_t omap_sham_irq(int irq, void *dev_id)
1041 omap_sham_read(dd, SHA_REG_CTRL); 1100 omap_sham_read(dd, SHA_REG_CTRL);
1042 1101
1043 ctx->flags |= FLAGS_OUTPUT_READY; 1102 ctx->flags |= FLAGS_OUTPUT_READY;
1103 dd->err = 0;
1044 tasklet_schedule(&dd->done_task); 1104 tasklet_schedule(&dd->done_task);
1045 1105
1046 return IRQ_HANDLED; 1106 return IRQ_HANDLED;
@@ -1050,8 +1110,13 @@ static void omap_sham_dma_callback(int lch, u16 ch_status, void *data)
1050{ 1110{
1051 struct omap_sham_dev *dd = data; 1111 struct omap_sham_dev *dd = data;
1052 1112
1053 if (likely(lch == dd->dma_lch)) 1113 if (ch_status != OMAP_DMA_BLOCK_IRQ) {
1054 tasklet_schedule(&dd->done_task); 1114 pr_err("omap-sham DMA error status: 0x%hx\n", ch_status);
1115 dd->err = -EIO;
1116 dd->flags &= ~FLAGS_INIT; /* request to re-initialize */
1117 }
1118
1119 tasklet_schedule(&dd->done_task);
1055} 1120}
1056 1121
1057static int omap_sham_dma_init(struct omap_sham_dev *dd) 1122static int omap_sham_dma_init(struct omap_sham_dev *dd)
@@ -1066,15 +1131,6 @@ static int omap_sham_dma_init(struct omap_sham_dev *dd)
1066 dev_err(dd->dev, "Unable to request DMA channel\n"); 1131 dev_err(dd->dev, "Unable to request DMA channel\n");
1067 return err; 1132 return err;
1068 } 1133 }
1069 omap_set_dma_dest_params(dd->dma_lch, 0,
1070 OMAP_DMA_AMODE_CONSTANT,
1071 dd->phys_base + SHA_REG_DIN(0), 0, 16);
1072
1073 omap_set_dma_dest_burst_mode(dd->dma_lch,
1074 OMAP_DMA_DATA_BURST_16);
1075
1076 omap_set_dma_src_burst_mode(dd->dma_lch,
1077 OMAP_DMA_DATA_BURST_4);
1078 1134
1079 return 0; 1135 return 0;
1080} 1136}
diff --git a/drivers/crypto/padlock-aes.c b/drivers/crypto/padlock-aes.c
index 8a515baa38f7..db33d300aa23 100644
--- a/drivers/crypto/padlock-aes.c
+++ b/drivers/crypto/padlock-aes.c
@@ -9,6 +9,7 @@
9 9
10#include <crypto/algapi.h> 10#include <crypto/algapi.h>
11#include <crypto/aes.h> 11#include <crypto/aes.h>
12#include <crypto/padlock.h>
12#include <linux/module.h> 13#include <linux/module.h>
13#include <linux/init.h> 14#include <linux/init.h>
14#include <linux/types.h> 15#include <linux/types.h>
@@ -21,7 +22,6 @@
21#include <asm/byteorder.h> 22#include <asm/byteorder.h>
22#include <asm/processor.h> 23#include <asm/processor.h>
23#include <asm/i387.h> 24#include <asm/i387.h>
24#include "padlock.h"
25 25
26/* 26/*
27 * Number of data blocks actually fetched for each xcrypt insn. 27 * Number of data blocks actually fetched for each xcrypt insn.
diff --git a/drivers/crypto/padlock-sha.c b/drivers/crypto/padlock-sha.c
index d3a27e0119bc..adf075b6b9a8 100644
--- a/drivers/crypto/padlock-sha.c
+++ b/drivers/crypto/padlock-sha.c
@@ -13,6 +13,7 @@
13 */ 13 */
14 14
15#include <crypto/internal/hash.h> 15#include <crypto/internal/hash.h>
16#include <crypto/padlock.h>
16#include <crypto/sha.h> 17#include <crypto/sha.h>
17#include <linux/err.h> 18#include <linux/err.h>
18#include <linux/module.h> 19#include <linux/module.h>
@@ -22,13 +23,6 @@
22#include <linux/kernel.h> 23#include <linux/kernel.h>
23#include <linux/scatterlist.h> 24#include <linux/scatterlist.h>
24#include <asm/i387.h> 25#include <asm/i387.h>
25#include "padlock.h"
26
27#ifdef CONFIG_64BIT
28#define STACK_ALIGN 16
29#else
30#define STACK_ALIGN 4
31#endif
32 26
33struct padlock_sha_desc { 27struct padlock_sha_desc {
34 struct shash_desc fallback; 28 struct shash_desc fallback;
diff --git a/drivers/dca/dca-core.c b/drivers/dca/dca-core.c
index b98c67664ae7..c461eda62411 100644
--- a/drivers/dca/dca-core.c
+++ b/drivers/dca/dca-core.c
@@ -110,8 +110,6 @@ static void unregister_dca_providers(void)
110 110
111 /* at this point only one domain in the list is expected */ 111 /* at this point only one domain in the list is expected */
112 domain = list_first_entry(&dca_domains, struct dca_domain, node); 112 domain = list_first_entry(&dca_domains, struct dca_domain, node);
113 if (!domain)
114 return;
115 113
116 list_for_each_entry_safe(dca, _dca, &domain->dca_providers, node) { 114 list_for_each_entry_safe(dca, _dca, &domain->dca_providers, node) {
117 list_del(&dca->node); 115 list_del(&dca->node);
diff --git a/drivers/dma/intel_mid_dma.c b/drivers/dma/intel_mid_dma.c
index 3109bd94bc4f..78266382797e 100644
--- a/drivers/dma/intel_mid_dma.c
+++ b/drivers/dma/intel_mid_dma.c
@@ -1060,8 +1060,8 @@ static irqreturn_t intel_mid_dma_interrupt2(int irq, void *data)
1060 * mid_setup_dma - Setup the DMA controller 1060 * mid_setup_dma - Setup the DMA controller
1061 * @pdev: Controller PCI device structure 1061 * @pdev: Controller PCI device structure
1062 * 1062 *
1063 * Initilize the DMA controller, channels, registers with DMA engine, 1063 * Initialize the DMA controller, channels, registers with DMA engine,
1064 * ISR. Initilize DMA controller channels. 1064 * ISR. Initialize DMA controller channels.
1065 */ 1065 */
1066static int mid_setup_dma(struct pci_dev *pdev) 1066static int mid_setup_dma(struct pci_dev *pdev)
1067{ 1067{
@@ -1217,7 +1217,7 @@ static void middma_shutdown(struct pci_dev *pdev)
1217 * @pdev: Controller PCI device structure 1217 * @pdev: Controller PCI device structure
1218 * @id: pci device id structure 1218 * @id: pci device id structure
1219 * 1219 *
1220 * Initilize the PCI device, map BARs, query driver data. 1220 * Initialize the PCI device, map BARs, query driver data.
1221 * Call setup_dma to complete contoller and chan initilzation 1221 * Call setup_dma to complete contoller and chan initilzation
1222 */ 1222 */
1223static int __devinit intel_mid_dma_probe(struct pci_dev *pdev, 1223static int __devinit intel_mid_dma_probe(struct pci_dev *pdev,
diff --git a/drivers/edac/amd8131_edac.h b/drivers/edac/amd8131_edac.h
index 60e0d1c72dee..6f8b07131ec4 100644
--- a/drivers/edac/amd8131_edac.h
+++ b/drivers/edac/amd8131_edac.h
@@ -99,7 +99,7 @@ struct amd8131_dev_info {
99 99
100/* 100/*
101 * AMD8131 chipset has two pairs of PCIX Bridge and related IOAPIC 101 * AMD8131 chipset has two pairs of PCIX Bridge and related IOAPIC
102 * Controler, and ATCA-6101 has two AMD8131 chipsets, so there are 102 * Controller, and ATCA-6101 has two AMD8131 chipsets, so there are
103 * four PCIX Bridges on ATCA-6101 altogether. 103 * four PCIX Bridges on ATCA-6101 altogether.
104 * 104 *
105 * These PCIX Bridges share the same PCI Device ID and are all of 105 * These PCIX Bridges share the same PCI Device ID and are all of
diff --git a/drivers/edac/cell_edac.c b/drivers/edac/cell_edac.c
index c973004c002c..db1df59ae2b6 100644
--- a/drivers/edac/cell_edac.c
+++ b/drivers/edac/cell_edac.c
@@ -47,7 +47,7 @@ static void cell_edac_count_ce(struct mem_ctl_info *mci, int chan, u64 ar)
47 offset = address & ~PAGE_MASK; 47 offset = address & ~PAGE_MASK;
48 syndrome = (ar & 0x000000001fe00000ul) >> 21; 48 syndrome = (ar & 0x000000001fe00000ul) >> 21;
49 49
50 /* TODO: Decoding of the error addresss */ 50 /* TODO: Decoding of the error address */
51 edac_mc_handle_ce(mci, csrow->first_page + pfn, offset, 51 edac_mc_handle_ce(mci, csrow->first_page + pfn, offset,
52 syndrome, 0, chan, ""); 52 syndrome, 0, chan, "");
53} 53}
@@ -68,7 +68,7 @@ static void cell_edac_count_ue(struct mem_ctl_info *mci, int chan, u64 ar)
68 pfn = address >> PAGE_SHIFT; 68 pfn = address >> PAGE_SHIFT;
69 offset = address & ~PAGE_MASK; 69 offset = address & ~PAGE_MASK;
70 70
71 /* TODO: Decoding of the error addresss */ 71 /* TODO: Decoding of the error address */
72 edac_mc_handle_ue(mci, csrow->first_page + pfn, offset, 0, ""); 72 edac_mc_handle_ue(mci, csrow->first_page + pfn, offset, 0, "");
73} 73}
74 74
diff --git a/drivers/edac/edac_core.h b/drivers/edac/edac_core.h
index ff1eb7bb26c6..3d965347a673 100644
--- a/drivers/edac/edac_core.h
+++ b/drivers/edac/edac_core.h
@@ -259,7 +259,7 @@ enum scrub_type {
259 * for single channel are 64 bits, for dual channel 128 259 * for single channel are 64 bits, for dual channel 128
260 * bits. 260 * bits.
261 * 261 *
262 * Single-Ranked stick: A Single-ranked stick has 1 chip-select row of memmory. 262 * Single-Ranked stick: A Single-ranked stick has 1 chip-select row of memory.
263 * Motherboards commonly drive two chip-select pins to 263 * Motherboards commonly drive two chip-select pins to
264 * a memory stick. A single-ranked stick, will occupy 264 * a memory stick. A single-ranked stick, will occupy
265 * only one of those rows. The other will be unused. 265 * only one of those rows. The other will be unused.
diff --git a/drivers/edac/i7core_edac.c b/drivers/edac/i7core_edac.c
index 362861c15779..81154ab296b6 100644
--- a/drivers/edac/i7core_edac.c
+++ b/drivers/edac/i7core_edac.c
@@ -1,6 +1,6 @@
1/* Intel i7 core/Nehalem Memory Controller kernel module 1/* Intel i7 core/Nehalem Memory Controller kernel module
2 * 2 *
3 * This driver supports yhe memory controllers found on the Intel 3 * This driver supports the memory controllers found on the Intel
4 * processor families i7core, i7core 7xx/8xx, i5core, Xeon 35xx, 4 * processor families i7core, i7core 7xx/8xx, i5core, Xeon 35xx,
5 * Xeon 55xx and Xeon 56xx also known as Nehalem, Nehalem-EP, Lynnfield 5 * Xeon 55xx and Xeon 56xx also known as Nehalem, Nehalem-EP, Lynnfield
6 * and Westmere-EP. 6 * and Westmere-EP.
@@ -1271,7 +1271,7 @@ static void __init i7core_xeon_pci_fixup(const struct pci_id_table *table)
1271 int i; 1271 int i;
1272 1272
1273 /* 1273 /*
1274 * On Xeon 55xx, the Intel Quckpath Arch Generic Non-core pci buses 1274 * On Xeon 55xx, the Intel Quick Path Arch Generic Non-core pci buses
1275 * aren't announced by acpi. So, we need to use a legacy scan probing 1275 * aren't announced by acpi. So, we need to use a legacy scan probing
1276 * to detect them 1276 * to detect them
1277 */ 1277 */
@@ -1864,7 +1864,7 @@ static int i7core_mce_check_error(void *priv, struct mce *mce)
1864 if (mce->mcgstatus & 1) 1864 if (mce->mcgstatus & 1)
1865 i7core_check_error(mci); 1865 i7core_check_error(mci);
1866 1866
1867 /* Advice mcelog that the error were handled */ 1867 /* Advise mcelog that the errors were handled */
1868 return 1; 1868 return 1;
1869} 1869}
1870 1870
diff --git a/drivers/edac/ppc4xx_edac.c b/drivers/edac/ppc4xx_edac.c
index 070cea41b661..b9f0c20df1aa 100644
--- a/drivers/edac/ppc4xx_edac.c
+++ b/drivers/edac/ppc4xx_edac.c
@@ -873,7 +873,7 @@ ppc4xx_edac_get_mtype(u32 mcopt1)
873} 873}
874 874
875/** 875/**
876 * ppc4xx_edac_init_csrows - intialize driver instance rows 876 * ppc4xx_edac_init_csrows - initialize driver instance rows
877 * @mci: A pointer to the EDAC memory controller instance 877 * @mci: A pointer to the EDAC memory controller instance
878 * associated with the ibm,sdram-4xx-ddr2 controller for which 878 * associated with the ibm,sdram-4xx-ddr2 controller for which
879 * the csrows (i.e. banks/ranks) are being initialized. 879 * the csrows (i.e. banks/ranks) are being initialized.
@@ -881,7 +881,7 @@ ppc4xx_edac_get_mtype(u32 mcopt1)
881 * currently set for the controller, from which bank width 881 * currently set for the controller, from which bank width
882 * and memory typ information is derived. 882 * and memory typ information is derived.
883 * 883 *
884 * This routine intializes the virtual "chip select rows" associated 884 * This routine initializes the virtual "chip select rows" associated
885 * with the EDAC memory controller instance. An ibm,sdram-4xx-ddr2 885 * with the EDAC memory controller instance. An ibm,sdram-4xx-ddr2
886 * controller bank/rank is mapped to a row. 886 * controller bank/rank is mapped to a row.
887 * 887 *
@@ -992,7 +992,7 @@ ppc4xx_edac_init_csrows(struct mem_ctl_info *mci, u32 mcopt1)
992} 992}
993 993
994/** 994/**
995 * ppc4xx_edac_mc_init - intialize driver instance 995 * ppc4xx_edac_mc_init - initialize driver instance
996 * @mci: A pointer to the EDAC memory controller instance being 996 * @mci: A pointer to the EDAC memory controller instance being
997 * initialized. 997 * initialized.
998 * @op: A pointer to the OpenFirmware device tree node associated 998 * @op: A pointer to the OpenFirmware device tree node associated
diff --git a/drivers/gpio/Kconfig b/drivers/gpio/Kconfig
index 082495bb08a7..664660e56335 100644
--- a/drivers/gpio/Kconfig
+++ b/drivers/gpio/Kconfig
@@ -118,7 +118,7 @@ config GPIO_SCH
118 118
119config GPIO_VX855 119config GPIO_VX855
120 tristate "VIA VX855/VX875 GPIO" 120 tristate "VIA VX855/VX875 GPIO"
121 depends on GPIOLIB 121 depends on GPIOLIB && MFD_SUPPORT && PCI
122 select MFD_CORE 122 select MFD_CORE
123 select MFD_VX855 123 select MFD_VX855
124 help 124 help
@@ -295,7 +295,7 @@ comment "PCI GPIO expanders:"
295 295
296config GPIO_CS5535 296config GPIO_CS5535
297 tristate "AMD CS5535/CS5536 GPIO support" 297 tristate "AMD CS5535/CS5536 GPIO support"
298 depends on PCI && !CS5535_GPIO 298 depends on PCI && X86 && !CS5535_GPIO
299 help 299 help
300 The AMD CS5535 and CS5536 southbridges support 28 GPIO pins that 300 The AMD CS5535 and CS5536 southbridges support 28 GPIO pins that
301 can be used for quite a number of things. The CS5535/6 is found on 301 can be used for quite a number of things. The CS5535/6 is found on
@@ -333,6 +333,15 @@ config GPIO_PCH
333 which is an IOH(Input/Output Hub) for x86 embedded processor. 333 which is an IOH(Input/Output Hub) for x86 embedded processor.
334 This driver can access PCH GPIO device. 334 This driver can access PCH GPIO device.
335 335
336config GPIO_ML_IOH
337 tristate "OKI SEMICONDUCTOR ML7213 IOH GPIO support"
338 depends on PCI
339 help
340 ML7213 is companion chip for Intel Atom E6xx series.
341 This driver can be used for OKI SEMICONDUCTOR ML7213 IOH(Input/Output
342 Hub) which is for IVI(In-Vehicle Infotainment) use.
343 This driver can access the IOH's GPIO device.
344
336config GPIO_TIMBERDALE 345config GPIO_TIMBERDALE
337 bool "Support for timberdale GPIO IP" 346 bool "Support for timberdale GPIO IP"
338 depends on MFD_TIMBERDALE && GPIOLIB && HAS_IOMEM 347 depends on MFD_TIMBERDALE && GPIOLIB && HAS_IOMEM
@@ -342,6 +351,7 @@ config GPIO_TIMBERDALE
342config GPIO_RDC321X 351config GPIO_RDC321X
343 tristate "RDC R-321x GPIO support" 352 tristate "RDC R-321x GPIO support"
344 depends on PCI && GPIOLIB 353 depends on PCI && GPIOLIB
354 select MFD_SUPPORT
345 select MFD_CORE 355 select MFD_CORE
346 select MFD_RDC321X 356 select MFD_RDC321X
347 help 357 help
diff --git a/drivers/gpio/Makefile b/drivers/gpio/Makefile
index 39bfd7a37650..3351cf87b0ed 100644
--- a/drivers/gpio/Makefile
+++ b/drivers/gpio/Makefile
@@ -41,3 +41,4 @@ obj-$(CONFIG_GPIO_RDC321X) += rdc321x-gpio.o
41obj-$(CONFIG_GPIO_JANZ_TTL) += janz-ttl.o 41obj-$(CONFIG_GPIO_JANZ_TTL) += janz-ttl.o
42obj-$(CONFIG_GPIO_SX150X) += sx150x.o 42obj-$(CONFIG_GPIO_SX150X) += sx150x.o
43obj-$(CONFIG_GPIO_VX855) += vx855_gpio.o 43obj-$(CONFIG_GPIO_VX855) += vx855_gpio.o
44obj-$(CONFIG_GPIO_ML_IOH) += ml_ioh_gpio.o
diff --git a/drivers/gpio/adp5588-gpio.c b/drivers/gpio/adp5588-gpio.c
index 0871f78af593..33fc685cb385 100644
--- a/drivers/gpio/adp5588-gpio.c
+++ b/drivers/gpio/adp5588-gpio.c
@@ -146,9 +146,10 @@ static int adp5588_gpio_to_irq(struct gpio_chip *chip, unsigned off)
146 return dev->irq_base + off; 146 return dev->irq_base + off;
147} 147}
148 148
149static void adp5588_irq_bus_lock(unsigned int irq) 149static void adp5588_irq_bus_lock(struct irq_data *d)
150{ 150{
151 struct adp5588_gpio *dev = get_irq_chip_data(irq); 151 struct adp5588_gpio *dev = irq_data_get_irq_chip_data(d);
152
152 mutex_lock(&dev->irq_lock); 153 mutex_lock(&dev->irq_lock);
153} 154}
154 155
@@ -160,9 +161,9 @@ static void adp5588_irq_bus_lock(unsigned int irq)
160 * and unlocks the bus. 161 * and unlocks the bus.
161 */ 162 */
162 163
163static void adp5588_irq_bus_sync_unlock(unsigned int irq) 164static void adp5588_irq_bus_sync_unlock(struct irq_data *d)
164{ 165{
165 struct adp5588_gpio *dev = get_irq_chip_data(irq); 166 struct adp5588_gpio *dev = irq_data_get_irq_chip_data(d);
166 int i; 167 int i;
167 168
168 for (i = 0; i <= ADP5588_BANK(ADP5588_MAXGPIO); i++) 169 for (i = 0; i <= ADP5588_BANK(ADP5588_MAXGPIO); i++)
@@ -175,31 +176,31 @@ static void adp5588_irq_bus_sync_unlock(unsigned int irq)
175 mutex_unlock(&dev->irq_lock); 176 mutex_unlock(&dev->irq_lock);
176} 177}
177 178
178static void adp5588_irq_mask(unsigned int irq) 179static void adp5588_irq_mask(struct irq_data *d)
179{ 180{
180 struct adp5588_gpio *dev = get_irq_chip_data(irq); 181 struct adp5588_gpio *dev = irq_data_get_irq_chip_data(d);
181 unsigned gpio = irq - dev->irq_base; 182 unsigned gpio = d->irq - dev->irq_base;
182 183
183 dev->irq_mask[ADP5588_BANK(gpio)] &= ~ADP5588_BIT(gpio); 184 dev->irq_mask[ADP5588_BANK(gpio)] &= ~ADP5588_BIT(gpio);
184} 185}
185 186
186static void adp5588_irq_unmask(unsigned int irq) 187static void adp5588_irq_unmask(struct irq_data *d)
187{ 188{
188 struct adp5588_gpio *dev = get_irq_chip_data(irq); 189 struct adp5588_gpio *dev = irq_data_get_irq_chip_data(d);
189 unsigned gpio = irq - dev->irq_base; 190 unsigned gpio = d->irq - dev->irq_base;
190 191
191 dev->irq_mask[ADP5588_BANK(gpio)] |= ADP5588_BIT(gpio); 192 dev->irq_mask[ADP5588_BANK(gpio)] |= ADP5588_BIT(gpio);
192} 193}
193 194
194static int adp5588_irq_set_type(unsigned int irq, unsigned int type) 195static int adp5588_irq_set_type(struct irq_data *d, unsigned int type)
195{ 196{
196 struct adp5588_gpio *dev = get_irq_chip_data(irq); 197 struct adp5588_gpio *dev = irq_data_get_irq_chip_data(d);
197 uint16_t gpio = irq - dev->irq_base; 198 uint16_t gpio = d->irq - dev->irq_base;
198 unsigned bank, bit; 199 unsigned bank, bit;
199 200
200 if ((type & IRQ_TYPE_EDGE_BOTH)) { 201 if ((type & IRQ_TYPE_EDGE_BOTH)) {
201 dev_err(&dev->client->dev, "irq %d: unsupported type %d\n", 202 dev_err(&dev->client->dev, "irq %d: unsupported type %d\n",
202 irq, type); 203 d->irq, type);
203 return -EINVAL; 204 return -EINVAL;
204 } 205 }
205 206
@@ -222,11 +223,11 @@ static int adp5588_irq_set_type(unsigned int irq, unsigned int type)
222 223
223static struct irq_chip adp5588_irq_chip = { 224static struct irq_chip adp5588_irq_chip = {
224 .name = "adp5588", 225 .name = "adp5588",
225 .mask = adp5588_irq_mask, 226 .irq_mask = adp5588_irq_mask,
226 .unmask = adp5588_irq_unmask, 227 .irq_unmask = adp5588_irq_unmask,
227 .bus_lock = adp5588_irq_bus_lock, 228 .irq_bus_lock = adp5588_irq_bus_lock,
228 .bus_sync_unlock = adp5588_irq_bus_sync_unlock, 229 .irq_bus_sync_unlock = adp5588_irq_bus_sync_unlock,
229 .set_type = adp5588_irq_set_type, 230 .irq_set_type = adp5588_irq_set_type,
230}; 231};
231 232
232static int adp5588_gpio_read_intstat(struct i2c_client *client, u8 *buf) 233static int adp5588_gpio_read_intstat(struct i2c_client *client, u8 *buf)
diff --git a/drivers/gpio/cs5535-gpio.c b/drivers/gpio/cs5535-gpio.c
index d3e55a0ae92b..815d98b2c1ba 100644
--- a/drivers/gpio/cs5535-gpio.c
+++ b/drivers/gpio/cs5535-gpio.c
@@ -15,6 +15,7 @@
15#include <linux/gpio.h> 15#include <linux/gpio.h>
16#include <linux/io.h> 16#include <linux/io.h>
17#include <linux/cs5535.h> 17#include <linux/cs5535.h>
18#include <asm/msr.h>
18 19
19#define DRV_NAME "cs5535-gpio" 20#define DRV_NAME "cs5535-gpio"
20#define GPIO_BAR 1 21#define GPIO_BAR 1
@@ -144,6 +145,57 @@ int cs5535_gpio_isset(unsigned offset, unsigned int reg)
144} 145}
145EXPORT_SYMBOL_GPL(cs5535_gpio_isset); 146EXPORT_SYMBOL_GPL(cs5535_gpio_isset);
146 147
148int cs5535_gpio_set_irq(unsigned group, unsigned irq)
149{
150 uint32_t lo, hi;
151
152 if (group > 7 || irq > 15)
153 return -EINVAL;
154
155 rdmsr(MSR_PIC_ZSEL_HIGH, lo, hi);
156
157 lo &= ~(0xF << (group * 4));
158 lo |= (irq & 0xF) << (group * 4);
159
160 wrmsr(MSR_PIC_ZSEL_HIGH, lo, hi);
161 return 0;
162}
163EXPORT_SYMBOL_GPL(cs5535_gpio_set_irq);
164
165void cs5535_gpio_setup_event(unsigned offset, int pair, int pme)
166{
167 struct cs5535_gpio_chip *chip = &cs5535_gpio_chip;
168 uint32_t shift = (offset % 8) * 4;
169 unsigned long flags;
170 uint32_t val;
171
172 if (offset >= 24)
173 offset = GPIO_MAP_W;
174 else if (offset >= 16)
175 offset = GPIO_MAP_Z;
176 else if (offset >= 8)
177 offset = GPIO_MAP_Y;
178 else
179 offset = GPIO_MAP_X;
180
181 spin_lock_irqsave(&chip->lock, flags);
182 val = inl(chip->base + offset);
183
184 /* Clear whatever was there before */
185 val &= ~(0xF << shift);
186
187 /* Set the new value */
188 val |= ((pair & 7) << shift);
189
190 /* Set the PME bit if this is a PME event */
191 if (pme)
192 val |= (1 << (shift + 3));
193
194 outl(val, chip->base + offset);
195 spin_unlock_irqrestore(&chip->lock, flags);
196}
197EXPORT_SYMBOL_GPL(cs5535_gpio_setup_event);
198
147/* 199/*
148 * Generic gpio_chip API support. 200 * Generic gpio_chip API support.
149 */ 201 */
diff --git a/drivers/gpio/langwell_gpio.c b/drivers/gpio/langwell_gpio.c
index 64db9dc3a275..d81cc748e77f 100644
--- a/drivers/gpio/langwell_gpio.c
+++ b/drivers/gpio/langwell_gpio.c
@@ -134,10 +134,10 @@ static int lnw_gpio_to_irq(struct gpio_chip *chip, unsigned offset)
134 return lnw->irq_base + offset; 134 return lnw->irq_base + offset;
135} 135}
136 136
137static int lnw_irq_type(unsigned irq, unsigned type) 137static int lnw_irq_type(struct irq_data *d, unsigned type)
138{ 138{
139 struct lnw_gpio *lnw = get_irq_chip_data(irq); 139 struct lnw_gpio *lnw = irq_data_get_irq_chip_data(d);
140 u32 gpio = irq - lnw->irq_base; 140 u32 gpio = d->irq - lnw->irq_base;
141 unsigned long flags; 141 unsigned long flags;
142 u32 value; 142 u32 value;
143 void __iomem *grer = gpio_reg(&lnw->chip, gpio, GRER); 143 void __iomem *grer = gpio_reg(&lnw->chip, gpio, GRER);
@@ -162,19 +162,19 @@ static int lnw_irq_type(unsigned irq, unsigned type)
162 return 0; 162 return 0;
163} 163}
164 164
165static void lnw_irq_unmask(unsigned irq) 165static void lnw_irq_unmask(struct irq_data *d)
166{ 166{
167} 167}
168 168
169static void lnw_irq_mask(unsigned irq) 169static void lnw_irq_mask(struct irq_data *d)
170{ 170{
171} 171}
172 172
173static struct irq_chip lnw_irqchip = { 173static struct irq_chip lnw_irqchip = {
174 .name = "LNW-GPIO", 174 .name = "LNW-GPIO",
175 .mask = lnw_irq_mask, 175 .irq_mask = lnw_irq_mask,
176 .unmask = lnw_irq_unmask, 176 .irq_unmask = lnw_irq_unmask,
177 .set_type = lnw_irq_type, 177 .irq_set_type = lnw_irq_type,
178}; 178};
179 179
180static DEFINE_PCI_DEVICE_TABLE(lnw_gpio_ids) = { /* pin number */ 180static DEFINE_PCI_DEVICE_TABLE(lnw_gpio_ids) = { /* pin number */
diff --git a/drivers/gpio/max732x.c b/drivers/gpio/max732x.c
index 9cad60f9e962..9e1d01f0071a 100644
--- a/drivers/gpio/max732x.c
+++ b/drivers/gpio/max732x.c
@@ -327,40 +327,40 @@ static int max732x_gpio_to_irq(struct gpio_chip *gc, unsigned off)
327 return chip->irq_base + off; 327 return chip->irq_base + off;
328} 328}
329 329
330static void max732x_irq_mask(unsigned int irq) 330static void max732x_irq_mask(struct irq_data *d)
331{ 331{
332 struct max732x_chip *chip = get_irq_chip_data(irq); 332 struct max732x_chip *chip = irq_data_get_irq_chip_data(d);
333 333
334 chip->irq_mask_cur &= ~(1 << (irq - chip->irq_base)); 334 chip->irq_mask_cur &= ~(1 << (d->irq - chip->irq_base));
335} 335}
336 336
337static void max732x_irq_unmask(unsigned int irq) 337static void max732x_irq_unmask(struct irq_data *d)
338{ 338{
339 struct max732x_chip *chip = get_irq_chip_data(irq); 339 struct max732x_chip *chip = irq_data_get_irq_chip_data(d);
340 340
341 chip->irq_mask_cur |= 1 << (irq - chip->irq_base); 341 chip->irq_mask_cur |= 1 << (d->irq - chip->irq_base);
342} 342}
343 343
344static void max732x_irq_bus_lock(unsigned int irq) 344static void max732x_irq_bus_lock(struct irq_data *d)
345{ 345{
346 struct max732x_chip *chip = get_irq_chip_data(irq); 346 struct max732x_chip *chip = irq_data_get_irq_chip_data(d);
347 347
348 mutex_lock(&chip->irq_lock); 348 mutex_lock(&chip->irq_lock);
349 chip->irq_mask_cur = chip->irq_mask; 349 chip->irq_mask_cur = chip->irq_mask;
350} 350}
351 351
352static void max732x_irq_bus_sync_unlock(unsigned int irq) 352static void max732x_irq_bus_sync_unlock(struct irq_data *d)
353{ 353{
354 struct max732x_chip *chip = get_irq_chip_data(irq); 354 struct max732x_chip *chip = irq_data_get_irq_chip_data(d);
355 355
356 max732x_irq_update_mask(chip); 356 max732x_irq_update_mask(chip);
357 mutex_unlock(&chip->irq_lock); 357 mutex_unlock(&chip->irq_lock);
358} 358}
359 359
360static int max732x_irq_set_type(unsigned int irq, unsigned int type) 360static int max732x_irq_set_type(struct irq_data *d, unsigned int type)
361{ 361{
362 struct max732x_chip *chip = get_irq_chip_data(irq); 362 struct max732x_chip *chip = irq_data_get_irq_chip_data(d);
363 uint16_t off = irq - chip->irq_base; 363 uint16_t off = d->irq - chip->irq_base;
364 uint16_t mask = 1 << off; 364 uint16_t mask = 1 << off;
365 365
366 if (!(mask & chip->dir_input)) { 366 if (!(mask & chip->dir_input)) {
@@ -371,7 +371,7 @@ static int max732x_irq_set_type(unsigned int irq, unsigned int type)
371 371
372 if (!(type & IRQ_TYPE_EDGE_BOTH)) { 372 if (!(type & IRQ_TYPE_EDGE_BOTH)) {
373 dev_err(&chip->client->dev, "irq %d: unsupported type %d\n", 373 dev_err(&chip->client->dev, "irq %d: unsupported type %d\n",
374 irq, type); 374 d->irq, type);
375 return -EINVAL; 375 return -EINVAL;
376 } 376 }
377 377
@@ -390,11 +390,11 @@ static int max732x_irq_set_type(unsigned int irq, unsigned int type)
390 390
391static struct irq_chip max732x_irq_chip = { 391static struct irq_chip max732x_irq_chip = {
392 .name = "max732x", 392 .name = "max732x",
393 .mask = max732x_irq_mask, 393 .irq_mask = max732x_irq_mask,
394 .unmask = max732x_irq_unmask, 394 .irq_unmask = max732x_irq_unmask,
395 .bus_lock = max732x_irq_bus_lock, 395 .irq_bus_lock = max732x_irq_bus_lock,
396 .bus_sync_unlock = max732x_irq_bus_sync_unlock, 396 .irq_bus_sync_unlock = max732x_irq_bus_sync_unlock,
397 .set_type = max732x_irq_set_type, 397 .irq_set_type = max732x_irq_set_type,
398}; 398};
399 399
400static uint8_t max732x_irq_pending(struct max732x_chip *chip) 400static uint8_t max732x_irq_pending(struct max732x_chip *chip)
diff --git a/drivers/gpio/ml_ioh_gpio.c b/drivers/gpio/ml_ioh_gpio.c
new file mode 100644
index 000000000000..cead8e6ff345
--- /dev/null
+++ b/drivers/gpio/ml_ioh_gpio.c
@@ -0,0 +1,352 @@
1/*
2 * Copyright (C) 2010 OKI SEMICONDUCTOR Co., LTD.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; version 2 of the License.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
16 */
17#include <linux/kernel.h>
18#include <linux/pci.h>
19#include <linux/gpio.h>
20
21#define PCI_VENDOR_ID_ROHM 0x10DB
22
23struct ioh_reg_comn {
24 u32 ien;
25 u32 istatus;
26 u32 idisp;
27 u32 iclr;
28 u32 imask;
29 u32 imaskclr;
30 u32 po;
31 u32 pi;
32 u32 pm;
33 u32 im_0;
34 u32 im_1;
35 u32 reserved;
36};
37
38struct ioh_regs {
39 struct ioh_reg_comn regs[8];
40 u32 reserve1[16];
41 u32 ioh_sel_reg[4];
42 u32 reserve2[11];
43 u32 srst;
44};
45
46/**
47 * struct ioh_gpio_reg_data - The register store data.
48 * @po_reg: To store contents of PO register.
49 * @pm_reg: To store contents of PM register.
50 */
51struct ioh_gpio_reg_data {
52 u32 po_reg;
53 u32 pm_reg;
54};
55
56/**
57 * struct ioh_gpio - GPIO private data structure.
58 * @base: PCI base address of Memory mapped I/O register.
59 * @reg: Memory mapped IOH GPIO register list.
60 * @dev: Pointer to device structure.
61 * @gpio: Data for GPIO infrastructure.
62 * @ioh_gpio_reg: Memory mapped Register data is saved here
63 * when suspend.
64 * @ch: Indicate GPIO channel
65 */
66struct ioh_gpio {
67 void __iomem *base;
68 struct ioh_regs __iomem *reg;
69 struct device *dev;
70 struct gpio_chip gpio;
71 struct ioh_gpio_reg_data ioh_gpio_reg;
72 struct mutex lock;
73 int ch;
74};
75
76static const int num_ports[] = {6, 12, 16, 16, 15, 16, 16, 12};
77
78static void ioh_gpio_set(struct gpio_chip *gpio, unsigned nr, int val)
79{
80 u32 reg_val;
81 struct ioh_gpio *chip = container_of(gpio, struct ioh_gpio, gpio);
82
83 mutex_lock(&chip->lock);
84 reg_val = ioread32(&chip->reg->regs[chip->ch].po);
85 if (val)
86 reg_val |= (1 << nr);
87 else
88 reg_val &= ~(1 << nr);
89
90 iowrite32(reg_val, &chip->reg->regs[chip->ch].po);
91 mutex_unlock(&chip->lock);
92}
93
94static int ioh_gpio_get(struct gpio_chip *gpio, unsigned nr)
95{
96 struct ioh_gpio *chip = container_of(gpio, struct ioh_gpio, gpio);
97
98 return ioread32(&chip->reg->regs[chip->ch].pi) & (1 << nr);
99}
100
101static int ioh_gpio_direction_output(struct gpio_chip *gpio, unsigned nr,
102 int val)
103{
104 struct ioh_gpio *chip = container_of(gpio, struct ioh_gpio, gpio);
105 u32 pm;
106 u32 reg_val;
107
108 mutex_lock(&chip->lock);
109 pm = ioread32(&chip->reg->regs[chip->ch].pm) &
110 ((1 << num_ports[chip->ch]) - 1);
111 pm |= (1 << nr);
112 iowrite32(pm, &chip->reg->regs[chip->ch].pm);
113
114 reg_val = ioread32(&chip->reg->regs[chip->ch].po);
115 if (val)
116 reg_val |= (1 << nr);
117 else
118 reg_val &= ~(1 << nr);
119
120 mutex_unlock(&chip->lock);
121
122 return 0;
123}
124
125static int ioh_gpio_direction_input(struct gpio_chip *gpio, unsigned nr)
126{
127 struct ioh_gpio *chip = container_of(gpio, struct ioh_gpio, gpio);
128 u32 pm;
129
130 mutex_lock(&chip->lock);
131 pm = ioread32(&chip->reg->regs[chip->ch].pm) &
132 ((1 << num_ports[chip->ch]) - 1);
133 pm &= ~(1 << nr);
134 iowrite32(pm, &chip->reg->regs[chip->ch].pm);
135 mutex_unlock(&chip->lock);
136
137 return 0;
138}
139
140/*
141 * Save register configuration and disable interrupts.
142 */
143static void ioh_gpio_save_reg_conf(struct ioh_gpio *chip)
144{
145 chip->ioh_gpio_reg.po_reg = ioread32(&chip->reg->regs[chip->ch].po);
146 chip->ioh_gpio_reg.pm_reg = ioread32(&chip->reg->regs[chip->ch].pm);
147}
148
149/*
150 * This function restores the register configuration of the GPIO device.
151 */
152static void ioh_gpio_restore_reg_conf(struct ioh_gpio *chip)
153{
154 /* to store contents of PO register */
155 iowrite32(chip->ioh_gpio_reg.po_reg, &chip->reg->regs[chip->ch].po);
156 /* to store contents of PM register */
157 iowrite32(chip->ioh_gpio_reg.pm_reg, &chip->reg->regs[chip->ch].pm);
158}
159
160static void ioh_gpio_setup(struct ioh_gpio *chip, int num_port)
161{
162 struct gpio_chip *gpio = &chip->gpio;
163
164 gpio->label = dev_name(chip->dev);
165 gpio->owner = THIS_MODULE;
166 gpio->direction_input = ioh_gpio_direction_input;
167 gpio->get = ioh_gpio_get;
168 gpio->direction_output = ioh_gpio_direction_output;
169 gpio->set = ioh_gpio_set;
170 gpio->dbg_show = NULL;
171 gpio->base = -1;
172 gpio->ngpio = num_port;
173 gpio->can_sleep = 0;
174}
175
176static int __devinit ioh_gpio_probe(struct pci_dev *pdev,
177 const struct pci_device_id *id)
178{
179 int ret;
180 int i;
181 struct ioh_gpio *chip;
182 void __iomem *base;
183 void __iomem *chip_save;
184
185 ret = pci_enable_device(pdev);
186 if (ret) {
187 dev_err(&pdev->dev, "%s : pci_enable_device failed", __func__);
188 goto err_pci_enable;
189 }
190
191 ret = pci_request_regions(pdev, KBUILD_MODNAME);
192 if (ret) {
193 dev_err(&pdev->dev, "pci_request_regions failed-%d", ret);
194 goto err_request_regions;
195 }
196
197 base = pci_iomap(pdev, 1, 0);
198 if (base == 0) {
199 dev_err(&pdev->dev, "%s : pci_iomap failed", __func__);
200 ret = -ENOMEM;
201 goto err_iomap;
202 }
203
204 chip_save = kzalloc(sizeof(*chip) * 8, GFP_KERNEL);
205 if (chip_save == NULL) {
206 dev_err(&pdev->dev, "%s : kzalloc failed", __func__);
207 ret = -ENOMEM;
208 goto err_kzalloc;
209 }
210
211 chip = chip_save;
212 for (i = 0; i < 8; i++, chip++) {
213 chip->dev = &pdev->dev;
214 chip->base = base;
215 chip->reg = chip->base;
216 chip->ch = i;
217 mutex_init(&chip->lock);
218 ioh_gpio_setup(chip, num_ports[i]);
219 ret = gpiochip_add(&chip->gpio);
220 if (ret) {
221 dev_err(&pdev->dev, "IOH gpio: Failed to register GPIO\n");
222 goto err_gpiochip_add;
223 }
224 }
225
226 chip = chip_save;
227 pci_set_drvdata(pdev, chip);
228
229 return 0;
230
231err_gpiochip_add:
232 for (; i != 0; i--) {
233 chip--;
234 ret = gpiochip_remove(&chip->gpio);
235 if (ret)
236 dev_err(&pdev->dev, "Failed gpiochip_remove(%d)\n", i);
237 }
238 kfree(chip_save);
239
240err_kzalloc:
241 pci_iounmap(pdev, base);
242
243err_iomap:
244 pci_release_regions(pdev);
245
246err_request_regions:
247 pci_disable_device(pdev);
248
249err_pci_enable:
250
251 dev_err(&pdev->dev, "%s Failed returns %d\n", __func__, ret);
252 return ret;
253}
254
255static void __devexit ioh_gpio_remove(struct pci_dev *pdev)
256{
257 int err;
258 int i;
259 struct ioh_gpio *chip = pci_get_drvdata(pdev);
260 void __iomem *chip_save;
261
262 chip_save = chip;
263 for (i = 0; i < 8; i++, chip++) {
264 err = gpiochip_remove(&chip->gpio);
265 if (err)
266 dev_err(&pdev->dev, "Failed gpiochip_remove\n");
267 }
268
269 chip = chip_save;
270 pci_iounmap(pdev, chip->base);
271 pci_release_regions(pdev);
272 pci_disable_device(pdev);
273 kfree(chip);
274}
275
276#ifdef CONFIG_PM
277static int ioh_gpio_suspend(struct pci_dev *pdev, pm_message_t state)
278{
279 s32 ret;
280 struct ioh_gpio *chip = pci_get_drvdata(pdev);
281
282 ioh_gpio_save_reg_conf(chip);
283 ioh_gpio_restore_reg_conf(chip);
284
285 ret = pci_save_state(pdev);
286 if (ret) {
287 dev_err(&pdev->dev, "pci_save_state Failed-%d\n", ret);
288 return ret;
289 }
290 pci_disable_device(pdev);
291 pci_set_power_state(pdev, PCI_D0);
292 ret = pci_enable_wake(pdev, PCI_D0, 1);
293 if (ret)
294 dev_err(&pdev->dev, "pci_enable_wake Failed -%d\n", ret);
295
296 return 0;
297}
298
299static int ioh_gpio_resume(struct pci_dev *pdev)
300{
301 s32 ret;
302 struct ioh_gpio *chip = pci_get_drvdata(pdev);
303
304 ret = pci_enable_wake(pdev, PCI_D0, 0);
305
306 pci_set_power_state(pdev, PCI_D0);
307 ret = pci_enable_device(pdev);
308 if (ret) {
309 dev_err(&pdev->dev, "pci_enable_device Failed-%d ", ret);
310 return ret;
311 }
312 pci_restore_state(pdev);
313
314 iowrite32(0x01, &chip->reg->srst);
315 iowrite32(0x00, &chip->reg->srst);
316 ioh_gpio_restore_reg_conf(chip);
317
318 return 0;
319}
320#else
321#define ioh_gpio_suspend NULL
322#define ioh_gpio_resume NULL
323#endif
324
325static DEFINE_PCI_DEVICE_TABLE(ioh_gpio_pcidev_id) = {
326 { PCI_DEVICE(PCI_VENDOR_ID_ROHM, 0x802E) },
327 { 0, }
328};
329
330static struct pci_driver ioh_gpio_driver = {
331 .name = "ml_ioh_gpio",
332 .id_table = ioh_gpio_pcidev_id,
333 .probe = ioh_gpio_probe,
334 .remove = __devexit_p(ioh_gpio_remove),
335 .suspend = ioh_gpio_suspend,
336 .resume = ioh_gpio_resume
337};
338
339static int __init ioh_gpio_pci_init(void)
340{
341 return pci_register_driver(&ioh_gpio_driver);
342}
343module_init(ioh_gpio_pci_init);
344
345static void __exit ioh_gpio_pci_exit(void)
346{
347 pci_unregister_driver(&ioh_gpio_driver);
348}
349module_exit(ioh_gpio_pci_exit);
350
351MODULE_DESCRIPTION("OKI SEMICONDUCTOR ML-IOH series GPIO Driver");
352MODULE_LICENSE("GPL");
diff --git a/drivers/gpio/pca953x.c b/drivers/gpio/pca953x.c
index 501866662e05..a261972f603d 100644
--- a/drivers/gpio/pca953x.c
+++ b/drivers/gpio/pca953x.c
@@ -228,30 +228,30 @@ static int pca953x_gpio_to_irq(struct gpio_chip *gc, unsigned off)
228 return chip->irq_base + off; 228 return chip->irq_base + off;
229} 229}
230 230
231static void pca953x_irq_mask(unsigned int irq) 231static void pca953x_irq_mask(struct irq_data *d)
232{ 232{
233 struct pca953x_chip *chip = get_irq_chip_data(irq); 233 struct pca953x_chip *chip = irq_data_get_irq_chip_data(d);
234 234
235 chip->irq_mask &= ~(1 << (irq - chip->irq_base)); 235 chip->irq_mask &= ~(1 << (d->irq - chip->irq_base));
236} 236}
237 237
238static void pca953x_irq_unmask(unsigned int irq) 238static void pca953x_irq_unmask(struct irq_data *d)
239{ 239{
240 struct pca953x_chip *chip = get_irq_chip_data(irq); 240 struct pca953x_chip *chip = irq_data_get_irq_chip_data(d);
241 241
242 chip->irq_mask |= 1 << (irq - chip->irq_base); 242 chip->irq_mask |= 1 << (d->irq - chip->irq_base);
243} 243}
244 244
245static void pca953x_irq_bus_lock(unsigned int irq) 245static void pca953x_irq_bus_lock(struct irq_data *d)
246{ 246{
247 struct pca953x_chip *chip = get_irq_chip_data(irq); 247 struct pca953x_chip *chip = irq_data_get_irq_chip_data(d);
248 248
249 mutex_lock(&chip->irq_lock); 249 mutex_lock(&chip->irq_lock);
250} 250}
251 251
252static void pca953x_irq_bus_sync_unlock(unsigned int irq) 252static void pca953x_irq_bus_sync_unlock(struct irq_data *d)
253{ 253{
254 struct pca953x_chip *chip = get_irq_chip_data(irq); 254 struct pca953x_chip *chip = irq_data_get_irq_chip_data(d);
255 uint16_t new_irqs; 255 uint16_t new_irqs;
256 uint16_t level; 256 uint16_t level;
257 257
@@ -268,15 +268,15 @@ static void pca953x_irq_bus_sync_unlock(unsigned int irq)
268 mutex_unlock(&chip->irq_lock); 268 mutex_unlock(&chip->irq_lock);
269} 269}
270 270
271static int pca953x_irq_set_type(unsigned int irq, unsigned int type) 271static int pca953x_irq_set_type(struct irq_data *d, unsigned int type)
272{ 272{
273 struct pca953x_chip *chip = get_irq_chip_data(irq); 273 struct pca953x_chip *chip = irq_data_get_irq_chip_data(d);
274 uint16_t level = irq - chip->irq_base; 274 uint16_t level = d->irq - chip->irq_base;
275 uint16_t mask = 1 << level; 275 uint16_t mask = 1 << level;
276 276
277 if (!(type & IRQ_TYPE_EDGE_BOTH)) { 277 if (!(type & IRQ_TYPE_EDGE_BOTH)) {
278 dev_err(&chip->client->dev, "irq %d: unsupported type %d\n", 278 dev_err(&chip->client->dev, "irq %d: unsupported type %d\n",
279 irq, type); 279 d->irq, type);
280 return -EINVAL; 280 return -EINVAL;
281 } 281 }
282 282
@@ -295,11 +295,11 @@ static int pca953x_irq_set_type(unsigned int irq, unsigned int type)
295 295
296static struct irq_chip pca953x_irq_chip = { 296static struct irq_chip pca953x_irq_chip = {
297 .name = "pca953x", 297 .name = "pca953x",
298 .mask = pca953x_irq_mask, 298 .irq_mask = pca953x_irq_mask,
299 .unmask = pca953x_irq_unmask, 299 .irq_unmask = pca953x_irq_unmask,
300 .bus_lock = pca953x_irq_bus_lock, 300 .irq_bus_lock = pca953x_irq_bus_lock,
301 .bus_sync_unlock = pca953x_irq_bus_sync_unlock, 301 .irq_bus_sync_unlock = pca953x_irq_bus_sync_unlock,
302 .set_type = pca953x_irq_set_type, 302 .irq_set_type = pca953x_irq_set_type,
303}; 303};
304 304
305static uint16_t pca953x_irq_pending(struct pca953x_chip *chip) 305static uint16_t pca953x_irq_pending(struct pca953x_chip *chip)
diff --git a/drivers/gpio/pl061.c b/drivers/gpio/pl061.c
index 5005990f751f..2975d22daffe 100644
--- a/drivers/gpio/pl061.c
+++ b/drivers/gpio/pl061.c
@@ -129,10 +129,10 @@ static int pl061_to_irq(struct gpio_chip *gc, unsigned offset)
129/* 129/*
130 * PL061 GPIO IRQ 130 * PL061 GPIO IRQ
131 */ 131 */
132static void pl061_irq_disable(unsigned irq) 132static void pl061_irq_disable(struct irq_data *d)
133{ 133{
134 struct pl061_gpio *chip = get_irq_chip_data(irq); 134 struct pl061_gpio *chip = irq_data_get_irq_chip_data(d);
135 int offset = irq - chip->irq_base; 135 int offset = d->irq - chip->irq_base;
136 unsigned long flags; 136 unsigned long flags;
137 u8 gpioie; 137 u8 gpioie;
138 138
@@ -143,10 +143,10 @@ static void pl061_irq_disable(unsigned irq)
143 spin_unlock_irqrestore(&chip->irq_lock, flags); 143 spin_unlock_irqrestore(&chip->irq_lock, flags);
144} 144}
145 145
146static void pl061_irq_enable(unsigned irq) 146static void pl061_irq_enable(struct irq_data *d)
147{ 147{
148 struct pl061_gpio *chip = get_irq_chip_data(irq); 148 struct pl061_gpio *chip = irq_data_get_irq_chip_data(d);
149 int offset = irq - chip->irq_base; 149 int offset = d->irq - chip->irq_base;
150 unsigned long flags; 150 unsigned long flags;
151 u8 gpioie; 151 u8 gpioie;
152 152
@@ -157,10 +157,10 @@ static void pl061_irq_enable(unsigned irq)
157 spin_unlock_irqrestore(&chip->irq_lock, flags); 157 spin_unlock_irqrestore(&chip->irq_lock, flags);
158} 158}
159 159
160static int pl061_irq_type(unsigned irq, unsigned trigger) 160static int pl061_irq_type(struct irq_data *d, unsigned trigger)
161{ 161{
162 struct pl061_gpio *chip = get_irq_chip_data(irq); 162 struct pl061_gpio *chip = irq_data_get_irq_chip_data(d);
163 int offset = irq - chip->irq_base; 163 int offset = d->irq - chip->irq_base;
164 unsigned long flags; 164 unsigned long flags;
165 u8 gpiois, gpioibe, gpioiev; 165 u8 gpiois, gpioibe, gpioiev;
166 166
@@ -203,9 +203,9 @@ static int pl061_irq_type(unsigned irq, unsigned trigger)
203 203
204static struct irq_chip pl061_irqchip = { 204static struct irq_chip pl061_irqchip = {
205 .name = "GPIO", 205 .name = "GPIO",
206 .enable = pl061_irq_enable, 206 .irq_enable = pl061_irq_enable,
207 .disable = pl061_irq_disable, 207 .irq_disable = pl061_irq_disable,
208 .set_type = pl061_irq_type, 208 .irq_set_type = pl061_irq_type,
209}; 209};
210 210
211static void pl061_irq_handler(unsigned irq, struct irq_desc *desc) 211static void pl061_irq_handler(unsigned irq, struct irq_desc *desc)
@@ -214,7 +214,7 @@ static void pl061_irq_handler(unsigned irq, struct irq_desc *desc)
214 struct list_head *ptr; 214 struct list_head *ptr;
215 struct pl061_gpio *chip; 215 struct pl061_gpio *chip;
216 216
217 desc->chip->ack(irq); 217 desc->irq_data.chip->irq_ack(&desc->irq_data);
218 list_for_each(ptr, chip_list) { 218 list_for_each(ptr, chip_list) {
219 unsigned long pending; 219 unsigned long pending;
220 int offset; 220 int offset;
@@ -229,7 +229,7 @@ static void pl061_irq_handler(unsigned irq, struct irq_desc *desc)
229 for_each_set_bit(offset, &pending, PL061_GPIO_NR) 229 for_each_set_bit(offset, &pending, PL061_GPIO_NR)
230 generic_handle_irq(pl061_to_irq(&chip->gc, offset)); 230 generic_handle_irq(pl061_to_irq(&chip->gc, offset));
231 } 231 }
232 desc->chip->unmask(irq); 232 desc->irq_data.chip->irq_unmask(&desc->irq_data);
233} 233}
234 234
235static int pl061_probe(struct amba_device *dev, struct amba_id *id) 235static int pl061_probe(struct amba_device *dev, struct amba_id *id)
diff --git a/drivers/gpio/stmpe-gpio.c b/drivers/gpio/stmpe-gpio.c
index 7c9e6a052c45..eb2901f8ab5e 100644
--- a/drivers/gpio/stmpe-gpio.c
+++ b/drivers/gpio/stmpe-gpio.c
@@ -122,10 +122,10 @@ static struct gpio_chip template_chip = {
122 .can_sleep = 1, 122 .can_sleep = 1,
123}; 123};
124 124
125static int stmpe_gpio_irq_set_type(unsigned int irq, unsigned int type) 125static int stmpe_gpio_irq_set_type(struct irq_data *d, unsigned int type)
126{ 126{
127 struct stmpe_gpio *stmpe_gpio = get_irq_chip_data(irq); 127 struct stmpe_gpio *stmpe_gpio = irq_data_get_irq_chip_data(d);
128 int offset = irq - stmpe_gpio->irq_base; 128 int offset = d->irq - stmpe_gpio->irq_base;
129 int regoffset = offset / 8; 129 int regoffset = offset / 8;
130 int mask = 1 << (offset % 8); 130 int mask = 1 << (offset % 8);
131 131
@@ -145,16 +145,16 @@ static int stmpe_gpio_irq_set_type(unsigned int irq, unsigned int type)
145 return 0; 145 return 0;
146} 146}
147 147
148static void stmpe_gpio_irq_lock(unsigned int irq) 148static void stmpe_gpio_irq_lock(struct irq_data *d)
149{ 149{
150 struct stmpe_gpio *stmpe_gpio = get_irq_chip_data(irq); 150 struct stmpe_gpio *stmpe_gpio = irq_data_get_irq_chip_data(d);
151 151
152 mutex_lock(&stmpe_gpio->irq_lock); 152 mutex_lock(&stmpe_gpio->irq_lock);
153} 153}
154 154
155static void stmpe_gpio_irq_sync_unlock(unsigned int irq) 155static void stmpe_gpio_irq_sync_unlock(struct irq_data *d)
156{ 156{
157 struct stmpe_gpio *stmpe_gpio = get_irq_chip_data(irq); 157 struct stmpe_gpio *stmpe_gpio = irq_data_get_irq_chip_data(d);
158 struct stmpe *stmpe = stmpe_gpio->stmpe; 158 struct stmpe *stmpe = stmpe_gpio->stmpe;
159 int num_banks = DIV_ROUND_UP(stmpe->num_gpios, 8); 159 int num_banks = DIV_ROUND_UP(stmpe->num_gpios, 8);
160 static const u8 regmap[] = { 160 static const u8 regmap[] = {
@@ -180,20 +180,20 @@ static void stmpe_gpio_irq_sync_unlock(unsigned int irq)
180 mutex_unlock(&stmpe_gpio->irq_lock); 180 mutex_unlock(&stmpe_gpio->irq_lock);
181} 181}
182 182
183static void stmpe_gpio_irq_mask(unsigned int irq) 183static void stmpe_gpio_irq_mask(struct irq_data *d)
184{ 184{
185 struct stmpe_gpio *stmpe_gpio = get_irq_chip_data(irq); 185 struct stmpe_gpio *stmpe_gpio = irq_data_get_irq_chip_data(d);
186 int offset = irq - stmpe_gpio->irq_base; 186 int offset = d->irq - stmpe_gpio->irq_base;
187 int regoffset = offset / 8; 187 int regoffset = offset / 8;
188 int mask = 1 << (offset % 8); 188 int mask = 1 << (offset % 8);
189 189
190 stmpe_gpio->regs[REG_IE][regoffset] &= ~mask; 190 stmpe_gpio->regs[REG_IE][regoffset] &= ~mask;
191} 191}
192 192
193static void stmpe_gpio_irq_unmask(unsigned int irq) 193static void stmpe_gpio_irq_unmask(struct irq_data *d)
194{ 194{
195 struct stmpe_gpio *stmpe_gpio = get_irq_chip_data(irq); 195 struct stmpe_gpio *stmpe_gpio = irq_data_get_irq_chip_data(d);
196 int offset = irq - stmpe_gpio->irq_base; 196 int offset = d->irq - stmpe_gpio->irq_base;
197 int regoffset = offset / 8; 197 int regoffset = offset / 8;
198 int mask = 1 << (offset % 8); 198 int mask = 1 << (offset % 8);
199 199
@@ -202,11 +202,11 @@ static void stmpe_gpio_irq_unmask(unsigned int irq)
202 202
203static struct irq_chip stmpe_gpio_irq_chip = { 203static struct irq_chip stmpe_gpio_irq_chip = {
204 .name = "stmpe-gpio", 204 .name = "stmpe-gpio",
205 .bus_lock = stmpe_gpio_irq_lock, 205 .irq_bus_lock = stmpe_gpio_irq_lock,
206 .bus_sync_unlock = stmpe_gpio_irq_sync_unlock, 206 .irq_bus_sync_unlock = stmpe_gpio_irq_sync_unlock,
207 .mask = stmpe_gpio_irq_mask, 207 .irq_mask = stmpe_gpio_irq_mask,
208 .unmask = stmpe_gpio_irq_unmask, 208 .irq_unmask = stmpe_gpio_irq_unmask,
209 .set_type = stmpe_gpio_irq_set_type, 209 .irq_set_type = stmpe_gpio_irq_set_type,
210}; 210};
211 211
212static irqreturn_t stmpe_gpio_irq(int irq, void *dev) 212static irqreturn_t stmpe_gpio_irq(int irq, void *dev)
diff --git a/drivers/gpio/sx150x.c b/drivers/gpio/sx150x.c
index 823559ab0e24..e60be0015c9b 100644
--- a/drivers/gpio/sx150x.c
+++ b/drivers/gpio/sx150x.c
@@ -304,36 +304,36 @@ static int sx150x_gpio_to_irq(struct gpio_chip *gc, unsigned offset)
304 return chip->irq_base + offset; 304 return chip->irq_base + offset;
305} 305}
306 306
307static void sx150x_irq_mask(unsigned int irq) 307static void sx150x_irq_mask(struct irq_data *d)
308{ 308{
309 struct irq_chip *ic = get_irq_chip(irq); 309 struct irq_chip *ic = irq_data_get_irq_chip(d);
310 struct sx150x_chip *chip; 310 struct sx150x_chip *chip;
311 unsigned n; 311 unsigned n;
312 312
313 chip = container_of(ic, struct sx150x_chip, irq_chip); 313 chip = container_of(ic, struct sx150x_chip, irq_chip);
314 n = irq - chip->irq_base; 314 n = d->irq - chip->irq_base;
315 315
316 sx150x_write_cfg(chip, n, 1, chip->dev_cfg->reg_irq_mask, 1); 316 sx150x_write_cfg(chip, n, 1, chip->dev_cfg->reg_irq_mask, 1);
317 sx150x_write_cfg(chip, n, 2, chip->dev_cfg->reg_sense, 0); 317 sx150x_write_cfg(chip, n, 2, chip->dev_cfg->reg_sense, 0);
318} 318}
319 319
320static void sx150x_irq_unmask(unsigned int irq) 320static void sx150x_irq_unmask(struct irq_data *d)
321{ 321{
322 struct irq_chip *ic = get_irq_chip(irq); 322 struct irq_chip *ic = irq_data_get_irq_chip(d);
323 struct sx150x_chip *chip; 323 struct sx150x_chip *chip;
324 unsigned n; 324 unsigned n;
325 325
326 chip = container_of(ic, struct sx150x_chip, irq_chip); 326 chip = container_of(ic, struct sx150x_chip, irq_chip);
327 n = irq - chip->irq_base; 327 n = d->irq - chip->irq_base;
328 328
329 sx150x_write_cfg(chip, n, 1, chip->dev_cfg->reg_irq_mask, 0); 329 sx150x_write_cfg(chip, n, 1, chip->dev_cfg->reg_irq_mask, 0);
330 sx150x_write_cfg(chip, n, 2, chip->dev_cfg->reg_sense, 330 sx150x_write_cfg(chip, n, 2, chip->dev_cfg->reg_sense,
331 chip->irq_sense >> (n * 2)); 331 chip->irq_sense >> (n * 2));
332} 332}
333 333
334static int sx150x_irq_set_type(unsigned int irq, unsigned int flow_type) 334static int sx150x_irq_set_type(struct irq_data *d, unsigned int flow_type)
335{ 335{
336 struct irq_chip *ic = get_irq_chip(irq); 336 struct irq_chip *ic = irq_data_get_irq_chip(d);
337 struct sx150x_chip *chip; 337 struct sx150x_chip *chip;
338 unsigned n, val = 0; 338 unsigned n, val = 0;
339 339
@@ -341,7 +341,7 @@ static int sx150x_irq_set_type(unsigned int irq, unsigned int flow_type)
341 return -EINVAL; 341 return -EINVAL;
342 342
343 chip = container_of(ic, struct sx150x_chip, irq_chip); 343 chip = container_of(ic, struct sx150x_chip, irq_chip);
344 n = irq - chip->irq_base; 344 n = d->irq - chip->irq_base;
345 345
346 if (flow_type & IRQ_TYPE_EDGE_RISING) 346 if (flow_type & IRQ_TYPE_EDGE_RISING)
347 val |= 0x1; 347 val |= 0x1;
@@ -386,9 +386,9 @@ static irqreturn_t sx150x_irq_thread_fn(int irq, void *dev_id)
386 return (nhandled > 0 ? IRQ_HANDLED : IRQ_NONE); 386 return (nhandled > 0 ? IRQ_HANDLED : IRQ_NONE);
387} 387}
388 388
389static void sx150x_irq_bus_lock(unsigned int irq) 389static void sx150x_irq_bus_lock(struct irq_data *d)
390{ 390{
391 struct irq_chip *ic = get_irq_chip(irq); 391 struct irq_chip *ic = irq_data_get_irq_chip(d);
392 struct sx150x_chip *chip; 392 struct sx150x_chip *chip;
393 393
394 chip = container_of(ic, struct sx150x_chip, irq_chip); 394 chip = container_of(ic, struct sx150x_chip, irq_chip);
@@ -396,9 +396,9 @@ static void sx150x_irq_bus_lock(unsigned int irq)
396 mutex_lock(&chip->lock); 396 mutex_lock(&chip->lock);
397} 397}
398 398
399static void sx150x_irq_bus_sync_unlock(unsigned int irq) 399static void sx150x_irq_bus_sync_unlock(struct irq_data *d)
400{ 400{
401 struct irq_chip *ic = get_irq_chip(irq); 401 struct irq_chip *ic = irq_data_get_irq_chip(d);
402 struct sx150x_chip *chip; 402 struct sx150x_chip *chip;
403 unsigned n; 403 unsigned n;
404 404
@@ -437,16 +437,16 @@ static void sx150x_init_chip(struct sx150x_chip *chip,
437 if (pdata->oscio_is_gpo) 437 if (pdata->oscio_is_gpo)
438 ++chip->gpio_chip.ngpio; 438 ++chip->gpio_chip.ngpio;
439 439
440 chip->irq_chip.name = client->name; 440 chip->irq_chip.name = client->name;
441 chip->irq_chip.mask = sx150x_irq_mask; 441 chip->irq_chip.irq_mask = sx150x_irq_mask;
442 chip->irq_chip.unmask = sx150x_irq_unmask; 442 chip->irq_chip.irq_unmask = sx150x_irq_unmask;
443 chip->irq_chip.set_type = sx150x_irq_set_type; 443 chip->irq_chip.irq_set_type = sx150x_irq_set_type;
444 chip->irq_chip.bus_lock = sx150x_irq_bus_lock; 444 chip->irq_chip.irq_bus_lock = sx150x_irq_bus_lock;
445 chip->irq_chip.bus_sync_unlock = sx150x_irq_bus_sync_unlock; 445 chip->irq_chip.irq_bus_sync_unlock = sx150x_irq_bus_sync_unlock;
446 chip->irq_summary = -1; 446 chip->irq_summary = -1;
447 chip->irq_base = -1; 447 chip->irq_base = -1;
448 chip->irq_sense = 0; 448 chip->irq_sense = 0;
449 chip->irq_set_type_pending = 0; 449 chip->irq_set_type_pending = 0;
450} 450}
451 451
452static int sx150x_init_io(struct sx150x_chip *chip, u8 base, u16 cfg) 452static int sx150x_init_io(struct sx150x_chip *chip, u8 base, u16 cfg)
diff --git a/drivers/gpio/tc3589x-gpio.c b/drivers/gpio/tc3589x-gpio.c
index 180d584454fb..27200af1a595 100644
--- a/drivers/gpio/tc3589x-gpio.c
+++ b/drivers/gpio/tc3589x-gpio.c
@@ -110,10 +110,10 @@ static struct gpio_chip template_chip = {
110 .can_sleep = 1, 110 .can_sleep = 1,
111}; 111};
112 112
113static int tc3589x_gpio_irq_set_type(unsigned int irq, unsigned int type) 113static int tc3589x_gpio_irq_set_type(struct irq_data *d, unsigned int type)
114{ 114{
115 struct tc3589x_gpio *tc3589x_gpio = get_irq_chip_data(irq); 115 struct tc3589x_gpio *tc3589x_gpio = irq_data_get_irq_chip_data(d);
116 int offset = irq - tc3589x_gpio->irq_base; 116 int offset = d->irq - tc3589x_gpio->irq_base;
117 int regoffset = offset / 8; 117 int regoffset = offset / 8;
118 int mask = 1 << (offset % 8); 118 int mask = 1 << (offset % 8);
119 119
@@ -137,16 +137,16 @@ static int tc3589x_gpio_irq_set_type(unsigned int irq, unsigned int type)
137 return 0; 137 return 0;
138} 138}
139 139
140static void tc3589x_gpio_irq_lock(unsigned int irq) 140static void tc3589x_gpio_irq_lock(struct irq_data *d)
141{ 141{
142 struct tc3589x_gpio *tc3589x_gpio = get_irq_chip_data(irq); 142 struct tc3589x_gpio *tc3589x_gpio = irq_data_get_irq_chip_data(d);
143 143
144 mutex_lock(&tc3589x_gpio->irq_lock); 144 mutex_lock(&tc3589x_gpio->irq_lock);
145} 145}
146 146
147static void tc3589x_gpio_irq_sync_unlock(unsigned int irq) 147static void tc3589x_gpio_irq_sync_unlock(struct irq_data *d)
148{ 148{
149 struct tc3589x_gpio *tc3589x_gpio = get_irq_chip_data(irq); 149 struct tc3589x_gpio *tc3589x_gpio = irq_data_get_irq_chip_data(d);
150 struct tc3589x *tc3589x = tc3589x_gpio->tc3589x; 150 struct tc3589x *tc3589x = tc3589x_gpio->tc3589x;
151 static const u8 regmap[] = { 151 static const u8 regmap[] = {
152 [REG_IBE] = TC3589x_GPIOIBE0, 152 [REG_IBE] = TC3589x_GPIOIBE0,
@@ -172,20 +172,20 @@ static void tc3589x_gpio_irq_sync_unlock(unsigned int irq)
172 mutex_unlock(&tc3589x_gpio->irq_lock); 172 mutex_unlock(&tc3589x_gpio->irq_lock);
173} 173}
174 174
175static void tc3589x_gpio_irq_mask(unsigned int irq) 175static void tc3589x_gpio_irq_mask(struct irq_data *d)
176{ 176{
177 struct tc3589x_gpio *tc3589x_gpio = get_irq_chip_data(irq); 177 struct tc3589x_gpio *tc3589x_gpio = irq_data_get_irq_chip_data(d);
178 int offset = irq - tc3589x_gpio->irq_base; 178 int offset = d->irq - tc3589x_gpio->irq_base;
179 int regoffset = offset / 8; 179 int regoffset = offset / 8;
180 int mask = 1 << (offset % 8); 180 int mask = 1 << (offset % 8);
181 181
182 tc3589x_gpio->regs[REG_IE][regoffset] &= ~mask; 182 tc3589x_gpio->regs[REG_IE][regoffset] &= ~mask;
183} 183}
184 184
185static void tc3589x_gpio_irq_unmask(unsigned int irq) 185static void tc3589x_gpio_irq_unmask(struct irq_data *d)
186{ 186{
187 struct tc3589x_gpio *tc3589x_gpio = get_irq_chip_data(irq); 187 struct tc3589x_gpio *tc3589x_gpio = irq_data_get_irq_chip_data(d);
188 int offset = irq - tc3589x_gpio->irq_base; 188 int offset = d->irq - tc3589x_gpio->irq_base;
189 int regoffset = offset / 8; 189 int regoffset = offset / 8;
190 int mask = 1 << (offset % 8); 190 int mask = 1 << (offset % 8);
191 191
@@ -194,11 +194,11 @@ static void tc3589x_gpio_irq_unmask(unsigned int irq)
194 194
195static struct irq_chip tc3589x_gpio_irq_chip = { 195static struct irq_chip tc3589x_gpio_irq_chip = {
196 .name = "tc3589x-gpio", 196 .name = "tc3589x-gpio",
197 .bus_lock = tc3589x_gpio_irq_lock, 197 .irq_bus_lock = tc3589x_gpio_irq_lock,
198 .bus_sync_unlock = tc3589x_gpio_irq_sync_unlock, 198 .irq_bus_sync_unlock = tc3589x_gpio_irq_sync_unlock,
199 .mask = tc3589x_gpio_irq_mask, 199 .irq_mask = tc3589x_gpio_irq_mask,
200 .unmask = tc3589x_gpio_irq_unmask, 200 .irq_unmask = tc3589x_gpio_irq_unmask,
201 .set_type = tc3589x_gpio_irq_set_type, 201 .irq_set_type = tc3589x_gpio_irq_set_type,
202}; 202};
203 203
204static irqreturn_t tc3589x_gpio_irq(int irq, void *dev) 204static irqreturn_t tc3589x_gpio_irq(int irq, void *dev)
diff --git a/drivers/gpio/timbgpio.c b/drivers/gpio/timbgpio.c
index 45293662e950..349131eb1ce0 100644
--- a/drivers/gpio/timbgpio.c
+++ b/drivers/gpio/timbgpio.c
@@ -109,10 +109,10 @@ static int timbgpio_to_irq(struct gpio_chip *gpio, unsigned offset)
109/* 109/*
110 * GPIO IRQ 110 * GPIO IRQ
111 */ 111 */
112static void timbgpio_irq_disable(unsigned irq) 112static void timbgpio_irq_disable(struct irq_data *d)
113{ 113{
114 struct timbgpio *tgpio = get_irq_chip_data(irq); 114 struct timbgpio *tgpio = irq_data_get_irq_chip_data(d);
115 int offset = irq - tgpio->irq_base; 115 int offset = d->irq - tgpio->irq_base;
116 unsigned long flags; 116 unsigned long flags;
117 117
118 spin_lock_irqsave(&tgpio->lock, flags); 118 spin_lock_irqsave(&tgpio->lock, flags);
@@ -121,10 +121,10 @@ static void timbgpio_irq_disable(unsigned irq)
121 spin_unlock_irqrestore(&tgpio->lock, flags); 121 spin_unlock_irqrestore(&tgpio->lock, flags);
122} 122}
123 123
124static void timbgpio_irq_enable(unsigned irq) 124static void timbgpio_irq_enable(struct irq_data *d)
125{ 125{
126 struct timbgpio *tgpio = get_irq_chip_data(irq); 126 struct timbgpio *tgpio = irq_data_get_irq_chip_data(d);
127 int offset = irq - tgpio->irq_base; 127 int offset = d->irq - tgpio->irq_base;
128 unsigned long flags; 128 unsigned long flags;
129 129
130 spin_lock_irqsave(&tgpio->lock, flags); 130 spin_lock_irqsave(&tgpio->lock, flags);
@@ -133,10 +133,10 @@ static void timbgpio_irq_enable(unsigned irq)
133 spin_unlock_irqrestore(&tgpio->lock, flags); 133 spin_unlock_irqrestore(&tgpio->lock, flags);
134} 134}
135 135
136static int timbgpio_irq_type(unsigned irq, unsigned trigger) 136static int timbgpio_irq_type(struct irq_data *d, unsigned trigger)
137{ 137{
138 struct timbgpio *tgpio = get_irq_chip_data(irq); 138 struct timbgpio *tgpio = irq_data_get_irq_chip_data(d);
139 int offset = irq - tgpio->irq_base; 139 int offset = d->irq - tgpio->irq_base;
140 unsigned long flags; 140 unsigned long flags;
141 u32 lvr, flr, bflr = 0; 141 u32 lvr, flr, bflr = 0;
142 u32 ver; 142 u32 ver;
@@ -193,13 +193,13 @@ out:
193 return ret; 193 return ret;
194} 194}
195 195
196static void timbgpio_irq(unsigned int irq, struct irq_desc *desc) 196static void timbgpio_irq(struct irq_data *d, struct irq_desc *desc)
197{ 197{
198 struct timbgpio *tgpio = get_irq_data(irq); 198 struct timbgpio *tgpio = irq_data_get_irq_data(d);
199 unsigned long ipr; 199 unsigned long ipr;
200 int offset; 200 int offset;
201 201
202 desc->chip->ack(irq); 202 desc->irq_data.chip->ack(irq_get_irq_data(d));
203 ipr = ioread32(tgpio->membase + TGPIO_IPR); 203 ipr = ioread32(tgpio->membase + TGPIO_IPR);
204 iowrite32(ipr, tgpio->membase + TGPIO_ICR); 204 iowrite32(ipr, tgpio->membase + TGPIO_ICR);
205 205
@@ -217,9 +217,9 @@ static void timbgpio_irq(unsigned int irq, struct irq_desc *desc)
217 217
218static struct irq_chip timbgpio_irqchip = { 218static struct irq_chip timbgpio_irqchip = {
219 .name = "GPIO", 219 .name = "GPIO",
220 .enable = timbgpio_irq_enable, 220 .irq_enable = timbgpio_irq_enable,
221 .disable = timbgpio_irq_disable, 221 .irq_disable = timbgpio_irq_disable,
222 .set_type = timbgpio_irq_type, 222 .irq_set_type = timbgpio_irq_type,
223}; 223};
224 224
225static int __devinit timbgpio_probe(struct platform_device *pdev) 225static int __devinit timbgpio_probe(struct platform_device *pdev)
diff --git a/drivers/gpio/vr41xx_giu.c b/drivers/gpio/vr41xx_giu.c
index b16c9a8c03f5..cffa3bd7ad3b 100644
--- a/drivers/gpio/vr41xx_giu.c
+++ b/drivers/gpio/vr41xx_giu.c
@@ -111,69 +111,69 @@ static inline u16 giu_clear(u16 offset, u16 clear)
111 return data; 111 return data;
112} 112}
113 113
114static void ack_giuint_low(unsigned int irq) 114static void ack_giuint_low(struct irq_data *d)
115{ 115{
116 giu_write(GIUINTSTATL, 1 << GPIO_PIN_OF_IRQ(irq)); 116 giu_write(GIUINTSTATL, 1 << GPIO_PIN_OF_IRQ(d->irq));
117} 117}
118 118
119static void mask_giuint_low(unsigned int irq) 119static void mask_giuint_low(struct irq_data *d)
120{ 120{
121 giu_clear(GIUINTENL, 1 << GPIO_PIN_OF_IRQ(irq)); 121 giu_clear(GIUINTENL, 1 << GPIO_PIN_OF_IRQ(d->irq));
122} 122}
123 123
124static void mask_ack_giuint_low(unsigned int irq) 124static void mask_ack_giuint_low(struct irq_data *d)
125{ 125{
126 unsigned int pin; 126 unsigned int pin;
127 127
128 pin = GPIO_PIN_OF_IRQ(irq); 128 pin = GPIO_PIN_OF_IRQ(d->irq);
129 giu_clear(GIUINTENL, 1 << pin); 129 giu_clear(GIUINTENL, 1 << pin);
130 giu_write(GIUINTSTATL, 1 << pin); 130 giu_write(GIUINTSTATL, 1 << pin);
131} 131}
132 132
133static void unmask_giuint_low(unsigned int irq) 133static void unmask_giuint_low(struct irq_data *d)
134{ 134{
135 giu_set(GIUINTENL, 1 << GPIO_PIN_OF_IRQ(irq)); 135 giu_set(GIUINTENL, 1 << GPIO_PIN_OF_IRQ(d->irq));
136} 136}
137 137
138static struct irq_chip giuint_low_irq_chip = { 138static struct irq_chip giuint_low_irq_chip = {
139 .name = "GIUINTL", 139 .name = "GIUINTL",
140 .ack = ack_giuint_low, 140 .irq_ack = ack_giuint_low,
141 .mask = mask_giuint_low, 141 .irq_mask = mask_giuint_low,
142 .mask_ack = mask_ack_giuint_low, 142 .irq_mask_ack = mask_ack_giuint_low,
143 .unmask = unmask_giuint_low, 143 .irq_unmask = unmask_giuint_low,
144}; 144};
145 145
146static void ack_giuint_high(unsigned int irq) 146static void ack_giuint_high(struct irq_data *d)
147{ 147{
148 giu_write(GIUINTSTATH, 148 giu_write(GIUINTSTATH,
149 1 << (GPIO_PIN_OF_IRQ(irq) - GIUINT_HIGH_OFFSET)); 149 1 << (GPIO_PIN_OF_IRQ(d->irq) - GIUINT_HIGH_OFFSET));
150} 150}
151 151
152static void mask_giuint_high(unsigned int irq) 152static void mask_giuint_high(struct irq_data *d)
153{ 153{
154 giu_clear(GIUINTENH, 1 << (GPIO_PIN_OF_IRQ(irq) - GIUINT_HIGH_OFFSET)); 154 giu_clear(GIUINTENH, 1 << (GPIO_PIN_OF_IRQ(d->irq) - GIUINT_HIGH_OFFSET));
155} 155}
156 156
157static void mask_ack_giuint_high(unsigned int irq) 157static void mask_ack_giuint_high(struct irq_data *d)
158{ 158{
159 unsigned int pin; 159 unsigned int pin;
160 160
161 pin = GPIO_PIN_OF_IRQ(irq) - GIUINT_HIGH_OFFSET; 161 pin = GPIO_PIN_OF_IRQ(d->irq) - GIUINT_HIGH_OFFSET;
162 giu_clear(GIUINTENH, 1 << pin); 162 giu_clear(GIUINTENH, 1 << pin);
163 giu_write(GIUINTSTATH, 1 << pin); 163 giu_write(GIUINTSTATH, 1 << pin);
164} 164}
165 165
166static void unmask_giuint_high(unsigned int irq) 166static void unmask_giuint_high(struct irq_data *d)
167{ 167{
168 giu_set(GIUINTENH, 1 << (GPIO_PIN_OF_IRQ(irq) - GIUINT_HIGH_OFFSET)); 168 giu_set(GIUINTENH, 1 << (GPIO_PIN_OF_IRQ(d->irq) - GIUINT_HIGH_OFFSET));
169} 169}
170 170
171static struct irq_chip giuint_high_irq_chip = { 171static struct irq_chip giuint_high_irq_chip = {
172 .name = "GIUINTH", 172 .name = "GIUINTH",
173 .ack = ack_giuint_high, 173 .irq_ack = ack_giuint_high,
174 .mask = mask_giuint_high, 174 .irq_mask = mask_giuint_high,
175 .mask_ack = mask_ack_giuint_high, 175 .irq_mask_ack = mask_ack_giuint_high,
176 .unmask = unmask_giuint_high, 176 .irq_unmask = unmask_giuint_high,
177}; 177};
178 178
179static int giu_get_irq(unsigned int irq) 179static int giu_get_irq(unsigned int irq)
diff --git a/drivers/gpio/wm8994-gpio.c b/drivers/gpio/wm8994-gpio.c
index 618398e4ed8e..c822baacd8fc 100644
--- a/drivers/gpio/wm8994-gpio.c
+++ b/drivers/gpio/wm8994-gpio.c
@@ -35,6 +35,29 @@ static inline struct wm8994_gpio *to_wm8994_gpio(struct gpio_chip *chip)
35 return container_of(chip, struct wm8994_gpio, gpio_chip); 35 return container_of(chip, struct wm8994_gpio, gpio_chip);
36} 36}
37 37
38static int wm8994_gpio_request(struct gpio_chip *chip, unsigned offset)
39{
40 struct wm8994_gpio *wm8994_gpio = to_wm8994_gpio(chip);
41 struct wm8994 *wm8994 = wm8994_gpio->wm8994;
42
43 switch (wm8994->type) {
44 case WM8958:
45 switch (offset) {
46 case 1:
47 case 2:
48 case 3:
49 case 4:
50 case 6:
51 return -EINVAL;
52 }
53 break;
54 default:
55 break;
56 }
57
58 return 0;
59}
60
38static int wm8994_gpio_direction_in(struct gpio_chip *chip, unsigned offset) 61static int wm8994_gpio_direction_in(struct gpio_chip *chip, unsigned offset)
39{ 62{
40 struct wm8994_gpio *wm8994_gpio = to_wm8994_gpio(chip); 63 struct wm8994_gpio *wm8994_gpio = to_wm8994_gpio(chip);
@@ -136,6 +159,7 @@ static void wm8994_gpio_dbg_show(struct seq_file *s, struct gpio_chip *chip)
136static struct gpio_chip template_chip = { 159static struct gpio_chip template_chip = {
137 .label = "wm8994", 160 .label = "wm8994",
138 .owner = THIS_MODULE, 161 .owner = THIS_MODULE,
162 .request = wm8994_gpio_request,
139 .direction_input = wm8994_gpio_direction_in, 163 .direction_input = wm8994_gpio_direction_in,
140 .get = wm8994_gpio_get, 164 .get = wm8994_gpio_get,
141 .direction_output = wm8994_gpio_direction_out, 165 .direction_output = wm8994_gpio_direction_out,
diff --git a/drivers/gpu/drm/nouveau/nouveau_backlight.c b/drivers/gpu/drm/nouveau/nouveau_backlight.c
index b14c81110575..d3a9c6e02477 100644
--- a/drivers/gpu/drm/nouveau/nouveau_backlight.c
+++ b/drivers/gpu/drm/nouveau/nouveau_backlight.c
@@ -59,7 +59,7 @@ static int nv40_set_intensity(struct backlight_device *bd)
59 return 0; 59 return 0;
60} 60}
61 61
62static struct backlight_ops nv40_bl_ops = { 62static const struct backlight_ops nv40_bl_ops = {
63 .options = BL_CORE_SUSPENDRESUME, 63 .options = BL_CORE_SUSPENDRESUME,
64 .get_brightness = nv40_get_intensity, 64 .get_brightness = nv40_get_intensity,
65 .update_status = nv40_set_intensity, 65 .update_status = nv40_set_intensity,
@@ -82,7 +82,7 @@ static int nv50_set_intensity(struct backlight_device *bd)
82 return 0; 82 return 0;
83} 83}
84 84
85static struct backlight_ops nv50_bl_ops = { 85static const struct backlight_ops nv50_bl_ops = {
86 .options = BL_CORE_SUSPENDRESUME, 86 .options = BL_CORE_SUSPENDRESUME,
87 .get_brightness = nv50_get_intensity, 87 .get_brightness = nv50_get_intensity,
88 .update_status = nv50_set_intensity, 88 .update_status = nv50_set_intensity,
diff --git a/drivers/gpu/drm/nouveau/nouveau_bios.c b/drivers/gpu/drm/nouveau/nouveau_bios.c
index d3046559bf05..2aef5cd3acf5 100644
--- a/drivers/gpu/drm/nouveau/nouveau_bios.c
+++ b/drivers/gpu/drm/nouveau/nouveau_bios.c
@@ -1927,7 +1927,7 @@ init_ltime(struct nvbios *bios, uint16_t offset, struct init_exec *iexec)
1927 * offset (8 bit): opcode 1927 * offset (8 bit): opcode
1928 * offset + 1 (16 bit): time 1928 * offset + 1 (16 bit): time
1929 * 1929 *
1930 * Sleep for "time" miliseconds. 1930 * Sleep for "time" milliseconds.
1931 */ 1931 */
1932 1932
1933 unsigned time = ROM16(bios->data[offset + 1]); 1933 unsigned time = ROM16(bios->data[offset + 1]);
@@ -1935,7 +1935,7 @@ init_ltime(struct nvbios *bios, uint16_t offset, struct init_exec *iexec)
1935 if (!iexec->execute) 1935 if (!iexec->execute)
1936 return 3; 1936 return 3;
1937 1937
1938 BIOSLOG(bios, "0x%04X: Sleeping for 0x%04X miliseconds\n", 1938 BIOSLOG(bios, "0x%04X: Sleeping for 0x%04X milliseconds\n",
1939 offset, time); 1939 offset, time);
1940 1940
1941 msleep(time); 1941 msleep(time);
diff --git a/drivers/gpu/drm/radeon/atombios.h b/drivers/gpu/drm/radeon/atombios.h
index 58a0cd02c0a2..04b269d14a59 100644
--- a/drivers/gpu/drm/radeon/atombios.h
+++ b/drivers/gpu/drm/radeon/atombios.h
@@ -1629,7 +1629,7 @@ typedef struct _GET_ENGINE_CLOCK_PARAMETERS
1629typedef struct _READ_EDID_FROM_HW_I2C_DATA_PARAMETERS 1629typedef struct _READ_EDID_FROM_HW_I2C_DATA_PARAMETERS
1630{ 1630{
1631 USHORT usPrescale; //Ratio between Engine clock and I2C clock 1631 USHORT usPrescale; //Ratio between Engine clock and I2C clock
1632 USHORT usVRAMAddress; //Adress in Frame Buffer where to pace raw EDID 1632 USHORT usVRAMAddress; //Address in Frame Buffer where to pace raw EDID
1633 USHORT usStatus; //When use output: lower byte EDID checksum, high byte hardware status 1633 USHORT usStatus; //When use output: lower byte EDID checksum, high byte hardware status
1634 //WHen use input: lower byte as 'byte to read':currently limited to 128byte or 1byte 1634 //WHen use input: lower byte as 'byte to read':currently limited to 128byte or 1byte
1635 UCHAR ucSlaveAddr; //Read from which slave 1635 UCHAR ucSlaveAddr; //Read from which slave
diff --git a/drivers/hid/Kconfig b/drivers/hid/Kconfig
index ffbc278647bf..24cca2f69dfc 100644
--- a/drivers/hid/Kconfig
+++ b/drivers/hid/Kconfig
@@ -295,6 +295,23 @@ config HID_MONTEREY
295 ---help--- 295 ---help---
296 Support for Monterey Genius KB29E. 296 Support for Monterey Genius KB29E.
297 297
298config HID_MULTITOUCH
299 tristate "HID Multitouch panels"
300 depends on USB_HID
301 ---help---
302 Generic support for HID multitouch panels.
303
304 Say Y here if you have one of the following devices:
305 - Cypress TrueTouch panels
306 - Hanvon dual touch panels
307 - Pixcir dual touch panels
308 - 'Sensing Win7-TwoFinger' panel by GeneralTouch
309
310 If unsure, say N.
311
312 To compile this driver as a module, choose M here: the
313 module will be called hid-multitouch.
314
298config HID_NTRIG 315config HID_NTRIG
299 tristate "N-Trig touch screen" 316 tristate "N-Trig touch screen"
300 depends on USB_HID 317 depends on USB_HID
diff --git a/drivers/hid/Makefile b/drivers/hid/Makefile
index 6eae9a90b8dd..6efc2a0370ad 100644
--- a/drivers/hid/Makefile
+++ b/drivers/hid/Makefile
@@ -47,6 +47,7 @@ obj-$(CONFIG_HID_MAGICMOUSE) += hid-magicmouse.o
47obj-$(CONFIG_HID_MICROSOFT) += hid-microsoft.o 47obj-$(CONFIG_HID_MICROSOFT) += hid-microsoft.o
48obj-$(CONFIG_HID_MONTEREY) += hid-monterey.o 48obj-$(CONFIG_HID_MONTEREY) += hid-monterey.o
49obj-$(CONFIG_HID_MOSART) += hid-mosart.o 49obj-$(CONFIG_HID_MOSART) += hid-mosart.o
50obj-$(CONFIG_HID_MULTITOUCH) += hid-multitouch.o
50obj-$(CONFIG_HID_NTRIG) += hid-ntrig.o 51obj-$(CONFIG_HID_NTRIG) += hid-ntrig.o
51obj-$(CONFIG_HID_ORTEK) += hid-ortek.o 52obj-$(CONFIG_HID_ORTEK) += hid-ortek.o
52obj-$(CONFIG_HID_PRODIKEYS) += hid-prodikeys.o 53obj-$(CONFIG_HID_PRODIKEYS) += hid-prodikeys.o
diff --git a/drivers/hid/hid-cando.c b/drivers/hid/hid-cando.c
index 375b50929a50..1ea066c55201 100644
--- a/drivers/hid/hid-cando.c
+++ b/drivers/hid/hid-cando.c
@@ -236,6 +236,8 @@ static const struct hid_device_id cando_devices[] = {
236 { HID_USB_DEVICE(USB_VENDOR_ID_CANDO, 236 { HID_USB_DEVICE(USB_VENDOR_ID_CANDO,
237 USB_DEVICE_ID_CANDO_MULTI_TOUCH) }, 237 USB_DEVICE_ID_CANDO_MULTI_TOUCH) },
238 { HID_USB_DEVICE(USB_VENDOR_ID_CANDO, 238 { HID_USB_DEVICE(USB_VENDOR_ID_CANDO,
239 USB_DEVICE_ID_CANDO_MULTI_TOUCH_10_1) },
240 { HID_USB_DEVICE(USB_VENDOR_ID_CANDO,
239 USB_DEVICE_ID_CANDO_MULTI_TOUCH_11_6) }, 241 USB_DEVICE_ID_CANDO_MULTI_TOUCH_11_6) },
240 { HID_USB_DEVICE(USB_VENDOR_ID_CANDO, 242 { HID_USB_DEVICE(USB_VENDOR_ID_CANDO,
241 USB_DEVICE_ID_CANDO_MULTI_TOUCH_15_6) }, 243 USB_DEVICE_ID_CANDO_MULTI_TOUCH_15_6) },
diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
index 261168607c91..d678cf3d33d5 100644
--- a/drivers/hid/hid-core.c
+++ b/drivers/hid/hid-core.c
@@ -1312,7 +1312,9 @@ static const struct hid_device_id hid_have_special_driver[] = {
1312 { HID_USB_DEVICE(USB_VENDOR_ID_BELKIN, USB_DEVICE_ID_FLIP_KVM) }, 1312 { HID_USB_DEVICE(USB_VENDOR_ID_BELKIN, USB_DEVICE_ID_FLIP_KVM) },
1313 { HID_USB_DEVICE(USB_VENDOR_ID_BTC, USB_DEVICE_ID_BTC_EMPREX_REMOTE) }, 1313 { HID_USB_DEVICE(USB_VENDOR_ID_BTC, USB_DEVICE_ID_BTC_EMPREX_REMOTE) },
1314 { HID_USB_DEVICE(USB_VENDOR_ID_BTC, USB_DEVICE_ID_BTC_EMPREX_REMOTE_2) }, 1314 { HID_USB_DEVICE(USB_VENDOR_ID_BTC, USB_DEVICE_ID_BTC_EMPREX_REMOTE_2) },
1315 { HID_USB_DEVICE(USB_VENDOR_ID_CANDO, USB_DEVICE_ID_CANDO_PIXCIR_MULTI_TOUCH) },
1315 { HID_USB_DEVICE(USB_VENDOR_ID_CANDO, USB_DEVICE_ID_CANDO_MULTI_TOUCH) }, 1316 { HID_USB_DEVICE(USB_VENDOR_ID_CANDO, USB_DEVICE_ID_CANDO_MULTI_TOUCH) },
1317 { HID_USB_DEVICE(USB_VENDOR_ID_CANDO, USB_DEVICE_ID_CANDO_MULTI_TOUCH_10_1) },
1316 { HID_USB_DEVICE(USB_VENDOR_ID_CANDO, USB_DEVICE_ID_CANDO_MULTI_TOUCH_11_6) }, 1318 { HID_USB_DEVICE(USB_VENDOR_ID_CANDO, USB_DEVICE_ID_CANDO_MULTI_TOUCH_11_6) },
1317 { HID_USB_DEVICE(USB_VENDOR_ID_CANDO, USB_DEVICE_ID_CANDO_MULTI_TOUCH_15_6) }, 1319 { HID_USB_DEVICE(USB_VENDOR_ID_CANDO, USB_DEVICE_ID_CANDO_MULTI_TOUCH_15_6) },
1318 { HID_USB_DEVICE(USB_VENDOR_ID_CHERRY, USB_DEVICE_ID_CHERRY_CYMOTION) }, 1320 { HID_USB_DEVICE(USB_VENDOR_ID_CHERRY, USB_DEVICE_ID_CHERRY_CYMOTION) },
@@ -1324,6 +1326,7 @@ static const struct hid_device_id hid_have_special_driver[] = {
1324 { HID_USB_DEVICE(USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_BARCODE_2) }, 1326 { HID_USB_DEVICE(USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_BARCODE_2) },
1325 { HID_USB_DEVICE(USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_BARCODE_3) }, 1327 { HID_USB_DEVICE(USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_BARCODE_3) },
1326 { HID_USB_DEVICE(USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_MOUSE) }, 1328 { HID_USB_DEVICE(USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_MOUSE) },
1329 { HID_USB_DEVICE(USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_TRUETOUCH) },
1327 { HID_USB_DEVICE(USB_VENDOR_ID_DRAGONRISE, 0x0006) }, 1330 { HID_USB_DEVICE(USB_VENDOR_ID_DRAGONRISE, 0x0006) },
1328 { HID_USB_DEVICE(USB_VENDOR_ID_DWAV, USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH) }, 1331 { HID_USB_DEVICE(USB_VENDOR_ID_DWAV, USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH) },
1329 { HID_USB_DEVICE(USB_VENDOR_ID_DWAV, USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH1) }, 1332 { HID_USB_DEVICE(USB_VENDOR_ID_DWAV, USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH1) },
@@ -1335,11 +1338,13 @@ static const struct hid_device_id hid_have_special_driver[] = {
1335 { HID_USB_DEVICE(USB_VENDOR_ID_EZKEY, USB_DEVICE_ID_BTC_8193) }, 1338 { HID_USB_DEVICE(USB_VENDOR_ID_EZKEY, USB_DEVICE_ID_BTC_8193) },
1336 { HID_USB_DEVICE(USB_VENDOR_ID_GAMERON, USB_DEVICE_ID_GAMERON_DUAL_PSX_ADAPTOR) }, 1339 { HID_USB_DEVICE(USB_VENDOR_ID_GAMERON, USB_DEVICE_ID_GAMERON_DUAL_PSX_ADAPTOR) },
1337 { HID_USB_DEVICE(USB_VENDOR_ID_GAMERON, USB_DEVICE_ID_GAMERON_DUAL_PCS_ADAPTOR) }, 1340 { HID_USB_DEVICE(USB_VENDOR_ID_GAMERON, USB_DEVICE_ID_GAMERON_DUAL_PCS_ADAPTOR) },
1341 { HID_USB_DEVICE(USB_VENDOR_ID_GENERAL_TOUCH, USB_DEVICE_ID_GENERAL_TOUCH_WIN7_TWOFINGERS) },
1338 { HID_USB_DEVICE(USB_VENDOR_ID_GREENASIA, 0x0003) }, 1342 { HID_USB_DEVICE(USB_VENDOR_ID_GREENASIA, 0x0003) },
1339 { HID_USB_DEVICE(USB_VENDOR_ID_GREENASIA, 0x0012) }, 1343 { HID_USB_DEVICE(USB_VENDOR_ID_GREENASIA, 0x0012) },
1340 { HID_USB_DEVICE(USB_VENDOR_ID_GYRATION, USB_DEVICE_ID_GYRATION_REMOTE) }, 1344 { HID_USB_DEVICE(USB_VENDOR_ID_GYRATION, USB_DEVICE_ID_GYRATION_REMOTE) },
1341 { HID_USB_DEVICE(USB_VENDOR_ID_GYRATION, USB_DEVICE_ID_GYRATION_REMOTE_2) }, 1345 { HID_USB_DEVICE(USB_VENDOR_ID_GYRATION, USB_DEVICE_ID_GYRATION_REMOTE_2) },
1342 { HID_USB_DEVICE(USB_VENDOR_ID_GYRATION, USB_DEVICE_ID_GYRATION_REMOTE_3) }, 1346 { HID_USB_DEVICE(USB_VENDOR_ID_GYRATION, USB_DEVICE_ID_GYRATION_REMOTE_3) },
1347 { HID_USB_DEVICE(USB_VENDOR_ID_HANVON, USB_DEVICE_ID_HANVON_MULTITOUCH) },
1343 { HID_USB_DEVICE(USB_VENDOR_ID_KENSINGTON, USB_DEVICE_ID_KS_SLIMBLADE) }, 1348 { HID_USB_DEVICE(USB_VENDOR_ID_KENSINGTON, USB_DEVICE_ID_KS_SLIMBLADE) },
1344 { HID_USB_DEVICE(USB_VENDOR_ID_KYE, USB_DEVICE_ID_KYE_ERGO_525V) }, 1349 { HID_USB_DEVICE(USB_VENDOR_ID_KYE, USB_DEVICE_ID_KYE_ERGO_525V) },
1345 { HID_USB_DEVICE(USB_VENDOR_ID_LABTEC, USB_DEVICE_ID_LABTEC_WIRELESS_KEYBOARD) }, 1350 { HID_USB_DEVICE(USB_VENDOR_ID_LABTEC, USB_DEVICE_ID_LABTEC_WIRELESS_KEYBOARD) },
@@ -1422,6 +1427,7 @@ static const struct hid_device_id hid_have_special_driver[] = {
1422 { HID_USB_DEVICE(USB_VENDOR_ID_TOPSEED, USB_DEVICE_ID_TOPSEED_CYBERLINK) }, 1427 { HID_USB_DEVICE(USB_VENDOR_ID_TOPSEED, USB_DEVICE_ID_TOPSEED_CYBERLINK) },
1423 { HID_USB_DEVICE(USB_VENDOR_ID_TOPSEED2, USB_DEVICE_ID_TOPSEED2_RF_COMBO) }, 1428 { HID_USB_DEVICE(USB_VENDOR_ID_TOPSEED2, USB_DEVICE_ID_TOPSEED2_RF_COMBO) },
1424 { HID_USB_DEVICE(USB_VENDOR_ID_TWINHAN, USB_DEVICE_ID_TWINHAN_IR_REMOTE) }, 1429 { HID_USB_DEVICE(USB_VENDOR_ID_TWINHAN, USB_DEVICE_ID_TWINHAN_IR_REMOTE) },
1430 { HID_USB_DEVICE(USB_VENDOR_ID_TURBOX, USB_DEVICE_ID_TURBOX_TOUCHSCREEN_MOSART) },
1425 { HID_USB_DEVICE(USB_VENDOR_ID_UCLOGIC, USB_DEVICE_ID_UCLOGIC_TABLET_PF1209) }, 1431 { HID_USB_DEVICE(USB_VENDOR_ID_UCLOGIC, USB_DEVICE_ID_UCLOGIC_TABLET_PF1209) },
1426 { HID_USB_DEVICE(USB_VENDOR_ID_UCLOGIC, USB_DEVICE_ID_UCLOGIC_TABLET_WP4030U) }, 1432 { HID_USB_DEVICE(USB_VENDOR_ID_UCLOGIC, USB_DEVICE_ID_UCLOGIC_TABLET_WP4030U) },
1427 { HID_USB_DEVICE(USB_VENDOR_ID_UCLOGIC, USB_DEVICE_ID_UCLOGIC_TABLET_WP5540U) }, 1433 { HID_USB_DEVICE(USB_VENDOR_ID_UCLOGIC, USB_DEVICE_ID_UCLOGIC_TABLET_WP5540U) },
@@ -1640,7 +1646,6 @@ static const struct hid_device_id hid_ignore_list[] = {
1640 { HID_USB_DEVICE(USB_VENDOR_ID_ESSENTIAL_REALITY, USB_DEVICE_ID_ESSENTIAL_REALITY_P5) }, 1646 { HID_USB_DEVICE(USB_VENDOR_ID_ESSENTIAL_REALITY, USB_DEVICE_ID_ESSENTIAL_REALITY_P5) },
1641 { HID_USB_DEVICE(USB_VENDOR_ID_ETT, USB_DEVICE_ID_TC5UH) }, 1647 { HID_USB_DEVICE(USB_VENDOR_ID_ETT, USB_DEVICE_ID_TC5UH) },
1642 { HID_USB_DEVICE(USB_VENDOR_ID_ETT, USB_DEVICE_ID_TC4UM) }, 1648 { HID_USB_DEVICE(USB_VENDOR_ID_ETT, USB_DEVICE_ID_TC4UM) },
1643 { HID_USB_DEVICE(USB_VENDOR_ID_GENERAL_TOUCH, 0x0001) },
1644 { HID_USB_DEVICE(USB_VENDOR_ID_GENERAL_TOUCH, 0x0002) }, 1649 { HID_USB_DEVICE(USB_VENDOR_ID_GENERAL_TOUCH, 0x0002) },
1645 { HID_USB_DEVICE(USB_VENDOR_ID_GENERAL_TOUCH, 0x0003) }, 1650 { HID_USB_DEVICE(USB_VENDOR_ID_GENERAL_TOUCH, 0x0003) },
1646 { HID_USB_DEVICE(USB_VENDOR_ID_GENERAL_TOUCH, 0x0004) }, 1651 { HID_USB_DEVICE(USB_VENDOR_ID_GENERAL_TOUCH, 0x0004) },
diff --git a/drivers/hid/hid-ids.h b/drivers/hid/hid-ids.h
index f65cace77729..92a0d61a7379 100644
--- a/drivers/hid/hid-ids.h
+++ b/drivers/hid/hid-ids.h
@@ -140,7 +140,9 @@
140#define USB_DEVICE_ID_BTC_EMPREX_REMOTE_2 0x5577 140#define USB_DEVICE_ID_BTC_EMPREX_REMOTE_2 0x5577
141 141
142#define USB_VENDOR_ID_CANDO 0x2087 142#define USB_VENDOR_ID_CANDO 0x2087
143#define USB_DEVICE_ID_CANDO_PIXCIR_MULTI_TOUCH 0x0703
143#define USB_DEVICE_ID_CANDO_MULTI_TOUCH 0x0a01 144#define USB_DEVICE_ID_CANDO_MULTI_TOUCH 0x0a01
145#define USB_DEVICE_ID_CANDO_MULTI_TOUCH_10_1 0x0a02
144#define USB_DEVICE_ID_CANDO_MULTI_TOUCH_11_6 0x0b03 146#define USB_DEVICE_ID_CANDO_MULTI_TOUCH_11_6 0x0b03
145#define USB_DEVICE_ID_CANDO_MULTI_TOUCH_15_6 0x0f01 147#define USB_DEVICE_ID_CANDO_MULTI_TOUCH_15_6 0x0f01
146 148
@@ -186,6 +188,7 @@
186#define USB_DEVICE_ID_CYPRESS_BARCODE_1 0xde61 188#define USB_DEVICE_ID_CYPRESS_BARCODE_1 0xde61
187#define USB_DEVICE_ID_CYPRESS_BARCODE_2 0xde64 189#define USB_DEVICE_ID_CYPRESS_BARCODE_2 0xde64
188#define USB_DEVICE_ID_CYPRESS_BARCODE_3 0xbca1 190#define USB_DEVICE_ID_CYPRESS_BARCODE_3 0xbca1
191#define USB_DEVICE_ID_CYPRESS_TRUETOUCH 0xc001
189 192
190#define USB_VENDOR_ID_DEALEXTREAME 0x10c5 193#define USB_VENDOR_ID_DEALEXTREAME 0x10c5
191#define USB_DEVICE_ID_DEALEXTREAME_RADIO_SI4701 0x819a 194#define USB_DEVICE_ID_DEALEXTREAME_RADIO_SI4701 0x819a
@@ -236,6 +239,7 @@
236#define USB_DEVICE_ID_GAMERON_DUAL_PCS_ADAPTOR 0x0002 239#define USB_DEVICE_ID_GAMERON_DUAL_PCS_ADAPTOR 0x0002
237 240
238#define USB_VENDOR_ID_GENERAL_TOUCH 0x0dfc 241#define USB_VENDOR_ID_GENERAL_TOUCH 0x0dfc
242#define USB_DEVICE_ID_GENERAL_TOUCH_WIN7_TWOFINGERS 0x0001
239 243
240#define USB_VENDOR_ID_GLAB 0x06c2 244#define USB_VENDOR_ID_GLAB 0x06c2
241#define USB_DEVICE_ID_4_PHIDGETSERVO_30 0x0038 245#define USB_DEVICE_ID_4_PHIDGETSERVO_30 0x0038
@@ -318,6 +322,9 @@
318#define USB_DEVICE_ID_HANWANG_TABLET_FIRST 0x5000 322#define USB_DEVICE_ID_HANWANG_TABLET_FIRST 0x5000
319#define USB_DEVICE_ID_HANWANG_TABLET_LAST 0x8fff 323#define USB_DEVICE_ID_HANWANG_TABLET_LAST 0x8fff
320 324
325#define USB_VENDOR_ID_HANVON 0x20b3
326#define USB_DEVICE_ID_HANVON_MULTITOUCH 0x0a18
327
321#define USB_VENDOR_ID_HAPP 0x078b 328#define USB_VENDOR_ID_HAPP 0x078b
322#define USB_DEVICE_ID_UGCI_DRIVING 0x0010 329#define USB_DEVICE_ID_UGCI_DRIVING 0x0010
323#define USB_DEVICE_ID_UGCI_FLYING 0x0020 330#define USB_DEVICE_ID_UGCI_FLYING 0x0020
diff --git a/drivers/hid/hid-input.c b/drivers/hid/hid-input.c
index e60fdb88101f..7f552bfad32c 100644
--- a/drivers/hid/hid-input.c
+++ b/drivers/hid/hid-input.c
@@ -290,6 +290,14 @@ static void hidinput_configure_usage(struct hid_input *hidinput, struct hid_fiel
290 goto ignore; 290 goto ignore;
291 } 291 }
292 292
293 if (field->report_type == HID_FEATURE_REPORT) {
294 if (device->driver->feature_mapping) {
295 device->driver->feature_mapping(device, hidinput, field,
296 usage);
297 }
298 goto ignore;
299 }
300
293 if (device->driver->input_mapping) { 301 if (device->driver->input_mapping) {
294 int ret = device->driver->input_mapping(device, hidinput, field, 302 int ret = device->driver->input_mapping(device, hidinput, field,
295 usage, &bit, &max); 303 usage, &bit, &max);
@@ -839,7 +847,6 @@ int hidinput_connect(struct hid_device *hid, unsigned int force)
839 struct hid_input *hidinput = NULL; 847 struct hid_input *hidinput = NULL;
840 struct input_dev *input_dev; 848 struct input_dev *input_dev;
841 int i, j, k; 849 int i, j, k;
842 int max_report_type = HID_OUTPUT_REPORT;
843 850
844 INIT_LIST_HEAD(&hid->inputs); 851 INIT_LIST_HEAD(&hid->inputs);
845 852
@@ -856,10 +863,11 @@ int hidinput_connect(struct hid_device *hid, unsigned int force)
856 return -1; 863 return -1;
857 } 864 }
858 865
859 if (hid->quirks & HID_QUIRK_SKIP_OUTPUT_REPORTS) 866 for (k = HID_INPUT_REPORT; k <= HID_FEATURE_REPORT; k++) {
860 max_report_type = HID_INPUT_REPORT; 867 if (k == HID_OUTPUT_REPORT &&
868 hid->quirks & HID_QUIRK_SKIP_OUTPUT_REPORTS)
869 continue;
861 870
862 for (k = HID_INPUT_REPORT; k <= max_report_type; k++)
863 list_for_each_entry(report, &hid->report_enum[k].report_list, list) { 871 list_for_each_entry(report, &hid->report_enum[k].report_list, list) {
864 872
865 if (!report->maxfield) 873 if (!report->maxfield)
@@ -912,6 +920,7 @@ int hidinput_connect(struct hid_device *hid, unsigned int force)
912 hidinput = NULL; 920 hidinput = NULL;
913 } 921 }
914 } 922 }
923 }
915 924
916 if (hidinput && input_register_device(hidinput->input)) 925 if (hidinput && input_register_device(hidinput->input))
917 goto out_cleanup; 926 goto out_cleanup;
diff --git a/drivers/hid/hid-mosart.c b/drivers/hid/hid-mosart.c
index 9fb050ce6f04..aed7ffe36283 100644
--- a/drivers/hid/hid-mosart.c
+++ b/drivers/hid/hid-mosart.c
@@ -257,6 +257,7 @@ static void mosart_remove(struct hid_device *hdev)
257static const struct hid_device_id mosart_devices[] = { 257static const struct hid_device_id mosart_devices[] = {
258 { HID_USB_DEVICE(USB_VENDOR_ID_ASUS, USB_DEVICE_ID_ASUS_T91MT) }, 258 { HID_USB_DEVICE(USB_VENDOR_ID_ASUS, USB_DEVICE_ID_ASUS_T91MT) },
259 { HID_USB_DEVICE(USB_VENDOR_ID_ASUS, USB_DEVICE_ID_ASUSTEK_MULTITOUCH_YFO) }, 259 { HID_USB_DEVICE(USB_VENDOR_ID_ASUS, USB_DEVICE_ID_ASUSTEK_MULTITOUCH_YFO) },
260 { HID_USB_DEVICE(USB_VENDOR_ID_TURBOX, USB_DEVICE_ID_TURBOX_TOUCHSCREEN_MOSART) },
260 { } 261 { }
261}; 262};
262MODULE_DEVICE_TABLE(hid, mosart_devices); 263MODULE_DEVICE_TABLE(hid, mosart_devices);
diff --git a/drivers/hid/hid-multitouch.c b/drivers/hid/hid-multitouch.c
new file mode 100644
index 000000000000..07d3183fdde5
--- /dev/null
+++ b/drivers/hid/hid-multitouch.c
@@ -0,0 +1,516 @@
1/*
2 * HID driver for multitouch panels
3 *
4 * Copyright (c) 2010-2011 Stephane Chatty <chatty@enac.fr>
5 * Copyright (c) 2010-2011 Benjamin Tissoires <benjamin.tissoires@gmail.com>
6 * Copyright (c) 2010-2011 Ecole Nationale de l'Aviation Civile, France
7 *
8 */
9
10/*
11 * This program is free software; you can redistribute it and/or modify it
12 * under the terms of the GNU General Public License as published by the Free
13 * Software Foundation; either version 2 of the License, or (at your option)
14 * any later version.
15 */
16
17#include <linux/device.h>
18#include <linux/hid.h>
19#include <linux/module.h>
20#include <linux/slab.h>
21#include <linux/usb.h>
22#include <linux/input/mt.h>
23#include "usbhid/usbhid.h"
24
25
26MODULE_AUTHOR("Stephane Chatty <chatty@enac.fr>");
27MODULE_DESCRIPTION("HID multitouch panels");
28MODULE_LICENSE("GPL");
29
30#include "hid-ids.h"
31
32/* quirks to control the device */
33#define MT_QUIRK_NOT_SEEN_MEANS_UP (1 << 0)
34#define MT_QUIRK_SLOT_IS_CONTACTID (1 << 1)
35#define MT_QUIRK_CYPRESS (1 << 2)
36#define MT_QUIRK_SLOT_IS_CONTACTNUMBER (1 << 3)
37#define MT_QUIRK_VALID_IS_INRANGE (1 << 4)
38#define MT_QUIRK_VALID_IS_CONFIDENCE (1 << 5)
39
40struct mt_slot {
41 __s32 x, y, p, w, h;
42 __s32 contactid; /* the device ContactID assigned to this slot */
43 bool touch_state; /* is the touch valid? */
44 bool seen_in_this_frame;/* has this slot been updated */
45};
46
47struct mt_device {
48 struct mt_slot curdata; /* placeholder of incoming data */
49 struct mt_class *mtclass; /* our mt device class */
50 unsigned last_field_index; /* last field index of the report */
51 unsigned last_slot_field; /* the last field of a slot */
52 __s8 inputmode; /* InputMode HID feature, -1 if non-existent */
53 __u8 num_received; /* how many contacts we received */
54 __u8 num_expected; /* expected last contact index */
55 bool curvalid; /* is the current contact valid? */
56 struct mt_slot slots[0]; /* first slot */
57};
58
59struct mt_class {
60 __s32 name; /* MT_CLS */
61 __s32 quirks;
62 __s32 sn_move; /* Signal/noise ratio for move events */
63 __s32 sn_pressure; /* Signal/noise ratio for pressure events */
64 __u8 maxcontacts;
65};
66
67/* classes of device behavior */
68#define MT_CLS_DEFAULT 1
69#define MT_CLS_DUAL1 2
70#define MT_CLS_DUAL2 3
71#define MT_CLS_CYPRESS 4
72
73/*
74 * these device-dependent functions determine what slot corresponds
75 * to a valid contact that was just read.
76 */
77
78static int cypress_compute_slot(struct mt_device *td)
79{
80 if (td->curdata.contactid != 0 || td->num_received == 0)
81 return td->curdata.contactid;
82 else
83 return -1;
84}
85
86static int find_slot_from_contactid(struct mt_device *td)
87{
88 int i;
89 for (i = 0; i < td->mtclass->maxcontacts; ++i) {
90 if (td->slots[i].contactid == td->curdata.contactid &&
91 td->slots[i].touch_state)
92 return i;
93 }
94 for (i = 0; i < td->mtclass->maxcontacts; ++i) {
95 if (!td->slots[i].seen_in_this_frame &&
96 !td->slots[i].touch_state)
97 return i;
98 }
99 /* should not occurs. If this happens that means
100 * that the device sent more touches that it says
101 * in the report descriptor. It is ignored then. */
102 return -1;
103}
104
105struct mt_class mt_classes[] = {
106 { .name = MT_CLS_DEFAULT,
107 .quirks = MT_QUIRK_VALID_IS_INRANGE,
108 .maxcontacts = 10 },
109 { .name = MT_CLS_DUAL1,
110 .quirks = MT_QUIRK_VALID_IS_INRANGE |
111 MT_QUIRK_SLOT_IS_CONTACTID,
112 .maxcontacts = 2 },
113 { .name = MT_CLS_DUAL2,
114 .quirks = MT_QUIRK_VALID_IS_INRANGE |
115 MT_QUIRK_SLOT_IS_CONTACTNUMBER,
116 .maxcontacts = 2 },
117 { .name = MT_CLS_CYPRESS,
118 .quirks = MT_QUIRK_NOT_SEEN_MEANS_UP |
119 MT_QUIRK_CYPRESS,
120 .maxcontacts = 10 },
121
122 { }
123};
124
125static void mt_feature_mapping(struct hid_device *hdev, struct hid_input *hi,
126 struct hid_field *field, struct hid_usage *usage)
127{
128 if (usage->hid == HID_DG_INPUTMODE) {
129 struct mt_device *td = hid_get_drvdata(hdev);
130 td->inputmode = field->report->id;
131 }
132}
133
134static void set_abs(struct input_dev *input, unsigned int code,
135 struct hid_field *field, int snratio)
136{
137 int fmin = field->logical_minimum;
138 int fmax = field->logical_maximum;
139 int fuzz = snratio ? (fmax - fmin) / snratio : 0;
140 input_set_abs_params(input, code, fmin, fmax, fuzz, 0);
141}
142
143static int mt_input_mapping(struct hid_device *hdev, struct hid_input *hi,
144 struct hid_field *field, struct hid_usage *usage,
145 unsigned long **bit, int *max)
146{
147 struct mt_device *td = hid_get_drvdata(hdev);
148 struct mt_class *cls = td->mtclass;
149 switch (usage->hid & HID_USAGE_PAGE) {
150
151 case HID_UP_GENDESK:
152 switch (usage->hid) {
153 case HID_GD_X:
154 hid_map_usage(hi, usage, bit, max,
155 EV_ABS, ABS_MT_POSITION_X);
156 set_abs(hi->input, ABS_MT_POSITION_X, field,
157 cls->sn_move);
158 /* touchscreen emulation */
159 set_abs(hi->input, ABS_X, field, cls->sn_move);
160 td->last_slot_field = usage->hid;
161 return 1;
162 case HID_GD_Y:
163 hid_map_usage(hi, usage, bit, max,
164 EV_ABS, ABS_MT_POSITION_Y);
165 set_abs(hi->input, ABS_MT_POSITION_Y, field,
166 cls->sn_move);
167 /* touchscreen emulation */
168 set_abs(hi->input, ABS_Y, field, cls->sn_move);
169 td->last_slot_field = usage->hid;
170 return 1;
171 }
172 return 0;
173
174 case HID_UP_DIGITIZER:
175 switch (usage->hid) {
176 case HID_DG_INRANGE:
177 td->last_slot_field = usage->hid;
178 return 1;
179 case HID_DG_CONFIDENCE:
180 td->last_slot_field = usage->hid;
181 return 1;
182 case HID_DG_TIPSWITCH:
183 hid_map_usage(hi, usage, bit, max, EV_KEY, BTN_TOUCH);
184 input_set_capability(hi->input, EV_KEY, BTN_TOUCH);
185 td->last_slot_field = usage->hid;
186 return 1;
187 case HID_DG_CONTACTID:
188 input_mt_init_slots(hi->input,
189 td->mtclass->maxcontacts);
190 td->last_slot_field = usage->hid;
191 return 1;
192 case HID_DG_WIDTH:
193 hid_map_usage(hi, usage, bit, max,
194 EV_ABS, ABS_MT_TOUCH_MAJOR);
195 td->last_slot_field = usage->hid;
196 return 1;
197 case HID_DG_HEIGHT:
198 hid_map_usage(hi, usage, bit, max,
199 EV_ABS, ABS_MT_TOUCH_MINOR);
200 field->logical_maximum = 1;
201 field->logical_minimum = 0;
202 set_abs(hi->input, ABS_MT_ORIENTATION, field, 0);
203 td->last_slot_field = usage->hid;
204 return 1;
205 case HID_DG_TIPPRESSURE:
206 hid_map_usage(hi, usage, bit, max,
207 EV_ABS, ABS_MT_PRESSURE);
208 set_abs(hi->input, ABS_MT_PRESSURE, field,
209 cls->sn_pressure);
210 /* touchscreen emulation */
211 set_abs(hi->input, ABS_PRESSURE, field,
212 cls->sn_pressure);
213 td->last_slot_field = usage->hid;
214 return 1;
215 case HID_DG_CONTACTCOUNT:
216 td->last_field_index = field->report->maxfield - 1;
217 return 1;
218 case HID_DG_CONTACTMAX:
219 /* we don't set td->last_slot_field as contactcount and
220 * contact max are global to the report */
221 return -1;
222 }
223 /* let hid-input decide for the others */
224 return 0;
225
226 case 0xff000000:
227 /* we do not want to map these: no input-oriented meaning */
228 return -1;
229 }
230
231 return 0;
232}
233
234static int mt_input_mapped(struct hid_device *hdev, struct hid_input *hi,
235 struct hid_field *field, struct hid_usage *usage,
236 unsigned long **bit, int *max)
237{
238 if (usage->type == EV_KEY || usage->type == EV_ABS)
239 set_bit(usage->type, hi->input->evbit);
240
241 return -1;
242}
243
244static int mt_compute_slot(struct mt_device *td)
245{
246 __s32 quirks = td->mtclass->quirks;
247
248 if (quirks & MT_QUIRK_SLOT_IS_CONTACTID)
249 return td->curdata.contactid;
250
251 if (quirks & MT_QUIRK_CYPRESS)
252 return cypress_compute_slot(td);
253
254 if (quirks & MT_QUIRK_SLOT_IS_CONTACTNUMBER)
255 return td->num_received;
256
257 return find_slot_from_contactid(td);
258}
259
260/*
261 * this function is called when a whole contact has been processed,
262 * so that it can assign it to a slot and store the data there
263 */
264static void mt_complete_slot(struct mt_device *td)
265{
266 td->curdata.seen_in_this_frame = true;
267 if (td->curvalid) {
268 int slotnum = mt_compute_slot(td);
269
270 if (slotnum >= 0 && slotnum < td->mtclass->maxcontacts)
271 td->slots[slotnum] = td->curdata;
272 }
273 td->num_received++;
274}
275
276
277/*
278 * this function is called when a whole packet has been received and processed,
279 * so that it can decide what to send to the input layer.
280 */
281static void mt_emit_event(struct mt_device *td, struct input_dev *input)
282{
283 int i;
284
285 for (i = 0; i < td->mtclass->maxcontacts; ++i) {
286 struct mt_slot *s = &(td->slots[i]);
287 if ((td->mtclass->quirks & MT_QUIRK_NOT_SEEN_MEANS_UP) &&
288 !s->seen_in_this_frame) {
289 s->touch_state = false;
290 }
291
292 input_mt_slot(input, i);
293 input_mt_report_slot_state(input, MT_TOOL_FINGER,
294 s->touch_state);
295 if (s->touch_state) {
296 input_event(input, EV_ABS, ABS_MT_POSITION_X, s->x);
297 input_event(input, EV_ABS, ABS_MT_POSITION_Y, s->y);
298 input_event(input, EV_ABS, ABS_MT_PRESSURE, s->p);
299 input_event(input, EV_ABS, ABS_MT_TOUCH_MAJOR, s->w);
300 input_event(input, EV_ABS, ABS_MT_TOUCH_MINOR, s->h);
301 }
302 s->seen_in_this_frame = false;
303
304 }
305
306 input_mt_report_pointer_emulation(input, true);
307 input_sync(input);
308 td->num_received = 0;
309}
310
311
312
313static int mt_event(struct hid_device *hid, struct hid_field *field,
314 struct hid_usage *usage, __s32 value)
315{
316 struct mt_device *td = hid_get_drvdata(hid);
317 __s32 quirks = td->mtclass->quirks;
318
319 if (hid->claimed & HID_CLAIMED_INPUT) {
320 switch (usage->hid) {
321 case HID_DG_INRANGE:
322 if (quirks & MT_QUIRK_VALID_IS_INRANGE)
323 td->curvalid = value;
324 break;
325 case HID_DG_TIPSWITCH:
326 if (quirks & MT_QUIRK_NOT_SEEN_MEANS_UP)
327 td->curvalid = value;
328 td->curdata.touch_state = value;
329 break;
330 case HID_DG_CONFIDENCE:
331 if (quirks & MT_QUIRK_VALID_IS_CONFIDENCE)
332 td->curvalid = value;
333 break;
334 case HID_DG_CONTACTID:
335 td->curdata.contactid = value;
336 break;
337 case HID_DG_TIPPRESSURE:
338 td->curdata.p = value;
339 break;
340 case HID_GD_X:
341 td->curdata.x = value;
342 break;
343 case HID_GD_Y:
344 td->curdata.y = value;
345 break;
346 case HID_DG_WIDTH:
347 td->curdata.w = value;
348 break;
349 case HID_DG_HEIGHT:
350 td->curdata.h = value;
351 break;
352 case HID_DG_CONTACTCOUNT:
353 /*
354 * Includes multi-packet support where subsequent
355 * packets are sent with zero contactcount.
356 */
357 if (value)
358 td->num_expected = value;
359 break;
360
361 default:
362 /* fallback to the generic hidinput handling */
363 return 0;
364 }
365
366 if (usage->hid == td->last_slot_field)
367 mt_complete_slot(td);
368
369 if (field->index == td->last_field_index
370 && td->num_received >= td->num_expected)
371 mt_emit_event(td, field->hidinput->input);
372
373 }
374
375 /* we have handled the hidinput part, now remains hiddev */
376 if (hid->claimed & HID_CLAIMED_HIDDEV && hid->hiddev_hid_event)
377 hid->hiddev_hid_event(hid, field, usage, value);
378
379 return 1;
380}
381
382static void mt_set_input_mode(struct hid_device *hdev)
383{
384 struct mt_device *td = hid_get_drvdata(hdev);
385 struct hid_report *r;
386 struct hid_report_enum *re;
387
388 if (td->inputmode < 0)
389 return;
390
391 re = &(hdev->report_enum[HID_FEATURE_REPORT]);
392 r = re->report_id_hash[td->inputmode];
393 if (r) {
394 r->field[0]->value[0] = 0x02;
395 usbhid_submit_report(hdev, r, USB_DIR_OUT);
396 }
397}
398
399static int mt_probe(struct hid_device *hdev, const struct hid_device_id *id)
400{
401 int ret, i;
402 struct mt_device *td;
403 struct mt_class *mtclass = mt_classes; /* MT_CLS_DEFAULT */
404
405 for (i = 0; mt_classes[i].name ; i++) {
406 if (id->driver_data == mt_classes[i].name) {
407 mtclass = &(mt_classes[i]);
408 break;
409 }
410 }
411
412 /* This allows the driver to correctly support devices
413 * that emit events over several HID messages.
414 */
415 hdev->quirks |= HID_QUIRK_NO_INPUT_SYNC;
416
417 td = kzalloc(sizeof(struct mt_device) +
418 mtclass->maxcontacts * sizeof(struct mt_slot),
419 GFP_KERNEL);
420 if (!td) {
421 dev_err(&hdev->dev, "cannot allocate multitouch data\n");
422 return -ENOMEM;
423 }
424 td->mtclass = mtclass;
425 td->inputmode = -1;
426 hid_set_drvdata(hdev, td);
427
428 ret = hid_parse(hdev);
429 if (ret != 0)
430 goto fail;
431
432 ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT);
433 if (ret)
434 goto fail;
435
436 mt_set_input_mode(hdev);
437
438 return 0;
439
440fail:
441 kfree(td);
442 return ret;
443}
444
445#ifdef CONFIG_PM
446static int mt_reset_resume(struct hid_device *hdev)
447{
448 mt_set_input_mode(hdev);
449 return 0;
450}
451#endif
452
453static void mt_remove(struct hid_device *hdev)
454{
455 struct mt_device *td = hid_get_drvdata(hdev);
456 hid_hw_stop(hdev);
457 kfree(td);
458 hid_set_drvdata(hdev, NULL);
459}
460
461static const struct hid_device_id mt_devices[] = {
462
463 /* Cypress panel */
464 { .driver_data = MT_CLS_CYPRESS,
465 HID_USB_DEVICE(USB_VENDOR_ID_CYPRESS,
466 USB_DEVICE_ID_CYPRESS_TRUETOUCH) },
467
468 /* GeneralTouch panel */
469 { .driver_data = MT_CLS_DUAL2,
470 HID_USB_DEVICE(USB_VENDOR_ID_GENERAL_TOUCH,
471 USB_DEVICE_ID_GENERAL_TOUCH_WIN7_TWOFINGERS) },
472
473 /* PixCir-based panels */
474 { .driver_data = MT_CLS_DUAL1,
475 HID_USB_DEVICE(USB_VENDOR_ID_HANVON,
476 USB_DEVICE_ID_HANVON_MULTITOUCH) },
477 { .driver_data = MT_CLS_DUAL1,
478 HID_USB_DEVICE(USB_VENDOR_ID_CANDO,
479 USB_DEVICE_ID_CANDO_PIXCIR_MULTI_TOUCH) },
480
481 { }
482};
483MODULE_DEVICE_TABLE(hid, mt_devices);
484
485static const struct hid_usage_id mt_grabbed_usages[] = {
486 { HID_ANY_ID, HID_ANY_ID, HID_ANY_ID },
487 { HID_ANY_ID - 1, HID_ANY_ID - 1, HID_ANY_ID - 1}
488};
489
490static struct hid_driver mt_driver = {
491 .name = "hid-multitouch",
492 .id_table = mt_devices,
493 .probe = mt_probe,
494 .remove = mt_remove,
495 .input_mapping = mt_input_mapping,
496 .input_mapped = mt_input_mapped,
497 .feature_mapping = mt_feature_mapping,
498 .usage_table = mt_grabbed_usages,
499 .event = mt_event,
500#ifdef CONFIG_PM
501 .reset_resume = mt_reset_resume,
502#endif
503};
504
505static int __init mt_init(void)
506{
507 return hid_register_driver(&mt_driver);
508}
509
510static void __exit mt_exit(void)
511{
512 hid_unregister_driver(&mt_driver);
513}
514
515module_init(mt_init);
516module_exit(mt_exit);
diff --git a/drivers/hid/usbhid/hid-quirks.c b/drivers/hid/usbhid/hid-quirks.c
index 76b9a149c7df..9a94b643ccde 100644
--- a/drivers/hid/usbhid/hid-quirks.c
+++ b/drivers/hid/usbhid/hid-quirks.c
@@ -35,7 +35,6 @@ static const struct hid_blacklist {
35 { USB_VENDOR_ID_CHIC, USB_DEVICE_ID_CHIC_GAMEPAD, HID_QUIRK_BADPAD }, 35 { USB_VENDOR_ID_CHIC, USB_DEVICE_ID_CHIC_GAMEPAD, HID_QUIRK_BADPAD },
36 { USB_VENDOR_ID_DWAV, USB_DEVICE_ID_EGALAX_TOUCHCONTROLLER, HID_QUIRK_MULTI_INPUT | HID_QUIRK_NOGET }, 36 { USB_VENDOR_ID_DWAV, USB_DEVICE_ID_EGALAX_TOUCHCONTROLLER, HID_QUIRK_MULTI_INPUT | HID_QUIRK_NOGET },
37 { USB_VENDOR_ID_MOJO, USB_DEVICE_ID_RETRO_ADAPTER, HID_QUIRK_MULTI_INPUT }, 37 { USB_VENDOR_ID_MOJO, USB_DEVICE_ID_RETRO_ADAPTER, HID_QUIRK_MULTI_INPUT },
38 { USB_VENDOR_ID_TURBOX, USB_DEVICE_ID_TURBOX_TOUCHSCREEN_MOSART, HID_QUIRK_MULTI_INPUT },
39 { USB_VENDOR_ID_HAPP, USB_DEVICE_ID_UGCI_DRIVING, HID_QUIRK_BADPAD | HID_QUIRK_MULTI_INPUT }, 38 { USB_VENDOR_ID_HAPP, USB_DEVICE_ID_UGCI_DRIVING, HID_QUIRK_BADPAD | HID_QUIRK_MULTI_INPUT },
40 { USB_VENDOR_ID_HAPP, USB_DEVICE_ID_UGCI_FLYING, HID_QUIRK_BADPAD | HID_QUIRK_MULTI_INPUT }, 39 { USB_VENDOR_ID_HAPP, USB_DEVICE_ID_UGCI_FLYING, HID_QUIRK_BADPAD | HID_QUIRK_MULTI_INPUT },
41 { USB_VENDOR_ID_HAPP, USB_DEVICE_ID_UGCI_FIGHTING, HID_QUIRK_BADPAD | HID_QUIRK_MULTI_INPUT }, 40 { USB_VENDOR_ID_HAPP, USB_DEVICE_ID_UGCI_FIGHTING, HID_QUIRK_BADPAD | HID_QUIRK_MULTI_INPUT },
diff --git a/drivers/hwmon/Kconfig b/drivers/hwmon/Kconfig
index bdc13d28b1ea..35f00dae3676 100644
--- a/drivers/hwmon/Kconfig
+++ b/drivers/hwmon/Kconfig
@@ -809,10 +809,10 @@ config SENSORS_DME1737
809 will be called dme1737. 809 will be called dme1737.
810 810
811config SENSORS_EMC1403 811config SENSORS_EMC1403
812 tristate "SMSC EMC1403 thermal sensor" 812 tristate "SMSC EMC1403/23 thermal sensor"
813 depends on I2C 813 depends on I2C
814 help 814 help
815 If you say yes here you get support for the SMSC EMC1403 815 If you say yes here you get support for the SMSC EMC1403/23
816 temperature monitoring chip. 816 temperature monitoring chip.
817 817
818 Threshold values can be configured using sysfs. 818 Threshold values can be configured using sysfs.
diff --git a/drivers/hwmon/adm9240.c b/drivers/hwmon/adm9240.c
index 0727ad250793..9e234b981b83 100644
--- a/drivers/hwmon/adm9240.c
+++ b/drivers/hwmon/adm9240.c
@@ -20,7 +20,7 @@
20 * Alarms 16-bit map of active alarms 20 * Alarms 16-bit map of active alarms
21 * Analog Out 0..1250 mV output 21 * Analog Out 0..1250 mV output
22 * 22 *
23 * Chassis Intrusion: clear CI latch with 'echo 1 > chassis_clear' 23 * Chassis Intrusion: clear CI latch with 'echo 0 > intrusion0_alarm'
24 * 24 *
25 * Test hardware: Intel SE440BX-2 desktop motherboard --Grant 25 * Test hardware: Intel SE440BX-2 desktop motherboard --Grant
26 * 26 *
@@ -476,13 +476,16 @@ static ssize_t set_aout(struct device *dev,
476static DEVICE_ATTR(aout_output, S_IRUGO | S_IWUSR, show_aout, set_aout); 476static DEVICE_ATTR(aout_output, S_IRUGO | S_IWUSR, show_aout, set_aout);
477 477
478/* chassis_clear */ 478/* chassis_clear */
479static ssize_t chassis_clear(struct device *dev, 479static ssize_t chassis_clear_legacy(struct device *dev,
480 struct device_attribute *attr, 480 struct device_attribute *attr,
481 const char *buf, size_t count) 481 const char *buf, size_t count)
482{ 482{
483 struct i2c_client *client = to_i2c_client(dev); 483 struct i2c_client *client = to_i2c_client(dev);
484 unsigned long val = simple_strtol(buf, NULL, 10); 484 unsigned long val = simple_strtol(buf, NULL, 10);
485 485
486 dev_warn(dev, "Attribute chassis_clear is deprecated, "
487 "use intrusion0_alarm instead\n");
488
486 if (val == 1) { 489 if (val == 1) {
487 i2c_smbus_write_byte_data(client, 490 i2c_smbus_write_byte_data(client,
488 ADM9240_REG_CHASSIS_CLEAR, 0x80); 491 ADM9240_REG_CHASSIS_CLEAR, 0x80);
@@ -490,7 +493,29 @@ static ssize_t chassis_clear(struct device *dev,
490 } 493 }
491 return count; 494 return count;
492} 495}
493static DEVICE_ATTR(chassis_clear, S_IWUSR, NULL, chassis_clear); 496static DEVICE_ATTR(chassis_clear, S_IWUSR, NULL, chassis_clear_legacy);
497
498static ssize_t chassis_clear(struct device *dev,
499 struct device_attribute *attr,
500 const char *buf, size_t count)
501{
502 struct i2c_client *client = to_i2c_client(dev);
503 struct adm9240_data *data = i2c_get_clientdata(client);
504 unsigned long val;
505
506 if (strict_strtoul(buf, 10, &val) || val != 0)
507 return -EINVAL;
508
509 mutex_lock(&data->update_lock);
510 i2c_smbus_write_byte_data(client, ADM9240_REG_CHASSIS_CLEAR, 0x80);
511 data->valid = 0; /* Force cache refresh */
512 mutex_unlock(&data->update_lock);
513 dev_dbg(&client->dev, "chassis intrusion latch cleared\n");
514
515 return count;
516}
517static SENSOR_DEVICE_ATTR(intrusion0_alarm, S_IRUGO | S_IWUSR, show_alarm,
518 chassis_clear, 12);
494 519
495static struct attribute *adm9240_attributes[] = { 520static struct attribute *adm9240_attributes[] = {
496 &sensor_dev_attr_in0_input.dev_attr.attr, 521 &sensor_dev_attr_in0_input.dev_attr.attr,
@@ -532,6 +557,7 @@ static struct attribute *adm9240_attributes[] = {
532 &dev_attr_alarms.attr, 557 &dev_attr_alarms.attr,
533 &dev_attr_aout_output.attr, 558 &dev_attr_aout_output.attr,
534 &dev_attr_chassis_clear.attr, 559 &dev_attr_chassis_clear.attr,
560 &sensor_dev_attr_intrusion0_alarm.dev_attr.attr,
535 &dev_attr_cpu0_vid.attr, 561 &dev_attr_cpu0_vid.attr,
536 NULL 562 NULL
537}; 563};
diff --git a/drivers/hwmon/ads7828.c b/drivers/hwmon/ads7828.c
index aac85f3aed50..c42c5a69a664 100644
--- a/drivers/hwmon/ads7828.c
+++ b/drivers/hwmon/ads7828.c
@@ -4,7 +4,7 @@
4 4
5 This driver is based on the lm75 and other lm_sensors/hwmon drivers 5 This driver is based on the lm75 and other lm_sensors/hwmon drivers
6 6
7 Written by Steve Hardy <steve@linuxrealtime.co.uk> 7 Written by Steve Hardy <shardy@redhat.com>
8 8
9 Datasheet available at: http://focus.ti.com/lit/ds/symlink/ads7828.pdf 9 Datasheet available at: http://focus.ti.com/lit/ds/symlink/ads7828.pdf
10 10
@@ -271,7 +271,7 @@ static void __exit sensors_ads7828_exit(void)
271 i2c_del_driver(&ads7828_driver); 271 i2c_del_driver(&ads7828_driver);
272} 272}
273 273
274MODULE_AUTHOR("Steve Hardy <steve@linuxrealtime.co.uk>"); 274MODULE_AUTHOR("Steve Hardy <shardy@redhat.com>");
275MODULE_DESCRIPTION("ADS7828 driver"); 275MODULE_DESCRIPTION("ADS7828 driver");
276MODULE_LICENSE("GPL"); 276MODULE_LICENSE("GPL");
277 277
diff --git a/drivers/hwmon/dme1737.c b/drivers/hwmon/dme1737.c
index e9a610bfd0cc..d9c592713919 100644
--- a/drivers/hwmon/dme1737.c
+++ b/drivers/hwmon/dme1737.c
@@ -77,12 +77,14 @@ enum chips { dme1737, sch5027, sch311x, sch5127 };
77 * in4 +12V 77 * in4 +12V
78 * in5 VTR (+3.3V stby) 78 * in5 VTR (+3.3V stby)
79 * in6 Vbat 79 * in6 Vbat
80 * in7 Vtrip (sch5127 only)
80 * 81 *
81 * --------------------------------------------------------------------- */ 82 * --------------------------------------------------------------------- */
82 83
83/* Voltages (in) numbered 0-6 (ix) */ 84/* Voltages (in) numbered 0-7 (ix) */
84#define DME1737_REG_IN(ix) ((ix) < 5 ? 0x20 + (ix) \ 85#define DME1737_REG_IN(ix) ((ix) < 5 ? 0x20 + (ix) : \
85 : 0x94 + (ix)) 86 (ix) < 7 ? 0x94 + (ix) : \
87 0x1f)
86#define DME1737_REG_IN_MIN(ix) ((ix) < 5 ? 0x44 + (ix) * 2 \ 88#define DME1737_REG_IN_MIN(ix) ((ix) < 5 ? 0x44 + (ix) * 2 \
87 : 0x91 + (ix) * 2) 89 : 0x91 + (ix) * 2)
88#define DME1737_REG_IN_MAX(ix) ((ix) < 5 ? 0x45 + (ix) * 2 \ 90#define DME1737_REG_IN_MAX(ix) ((ix) < 5 ? 0x45 + (ix) * 2 \
@@ -101,10 +103,11 @@ enum chips { dme1737, sch5027, sch311x, sch5127 };
101 * IN_TEMP_LSB(1) = [temp3, temp1] 103 * IN_TEMP_LSB(1) = [temp3, temp1]
102 * IN_TEMP_LSB(2) = [in4, temp2] 104 * IN_TEMP_LSB(2) = [in4, temp2]
103 * IN_TEMP_LSB(3) = [in3, in0] 105 * IN_TEMP_LSB(3) = [in3, in0]
104 * IN_TEMP_LSB(4) = [in2, in1] */ 106 * IN_TEMP_LSB(4) = [in2, in1]
107 * IN_TEMP_LSB(5) = [res, in7] */
105#define DME1737_REG_IN_TEMP_LSB(ix) (0x84 + (ix)) 108#define DME1737_REG_IN_TEMP_LSB(ix) (0x84 + (ix))
106static const u8 DME1737_REG_IN_LSB[] = {3, 4, 4, 3, 2, 0, 0}; 109static const u8 DME1737_REG_IN_LSB[] = {3, 4, 4, 3, 2, 0, 0, 5};
107static const u8 DME1737_REG_IN_LSB_SHL[] = {4, 4, 0, 0, 0, 0, 4}; 110static const u8 DME1737_REG_IN_LSB_SHL[] = {4, 4, 0, 0, 0, 0, 4, 4};
108static const u8 DME1737_REG_TEMP_LSB[] = {1, 2, 1}; 111static const u8 DME1737_REG_TEMP_LSB[] = {1, 2, 1};
109static const u8 DME1737_REG_TEMP_LSB_SHL[] = {4, 4, 0}; 112static const u8 DME1737_REG_TEMP_LSB_SHL[] = {4, 4, 0};
110 113
@@ -145,7 +148,7 @@ static const u8 DME1737_REG_TEMP_LSB_SHL[] = {4, 4, 0};
145#define DME1737_REG_ALARM1 0x41 148#define DME1737_REG_ALARM1 0x41
146#define DME1737_REG_ALARM2 0x42 149#define DME1737_REG_ALARM2 0x42
147#define DME1737_REG_ALARM3 0x83 150#define DME1737_REG_ALARM3 0x83
148static const u8 DME1737_BIT_ALARM_IN[] = {0, 1, 2, 3, 8, 16, 17}; 151static const u8 DME1737_BIT_ALARM_IN[] = {0, 1, 2, 3, 8, 16, 17, 18};
149static const u8 DME1737_BIT_ALARM_TEMP[] = {4, 5, 6}; 152static const u8 DME1737_BIT_ALARM_TEMP[] = {4, 5, 6};
150static const u8 DME1737_BIT_ALARM_FAN[] = {10, 11, 12, 13, 22, 23}; 153static const u8 DME1737_BIT_ALARM_FAN[] = {10, 11, 12, 13, 22, 23};
151 154
@@ -190,6 +193,7 @@ static const u8 DME1737_BIT_ALARM_FAN[] = {10, 11, 12, 13, 22, 23};
190#define HAS_PWM_MIN (1 << 4) /* bit 4 */ 193#define HAS_PWM_MIN (1 << 4) /* bit 4 */
191#define HAS_FAN(ix) (1 << ((ix) + 5)) /* bits 5-10 */ 194#define HAS_FAN(ix) (1 << ((ix) + 5)) /* bits 5-10 */
192#define HAS_PWM(ix) (1 << ((ix) + 11)) /* bits 11-16 */ 195#define HAS_PWM(ix) (1 << ((ix) + 11)) /* bits 11-16 */
196#define HAS_IN7 (1 << 17) /* bit 17 */
193 197
194/* --------------------------------------------------------------------- 198/* ---------------------------------------------------------------------
195 * Data structures and manipulation thereof 199 * Data structures and manipulation thereof
@@ -213,9 +217,9 @@ struct dme1737_data {
213 u32 has_features; 217 u32 has_features;
214 218
215 /* Register values */ 219 /* Register values */
216 u16 in[7]; 220 u16 in[8];
217 u8 in_min[7]; 221 u8 in_min[8];
218 u8 in_max[7]; 222 u8 in_max[8];
219 s16 temp[3]; 223 s16 temp[3];
220 s8 temp_min[3]; 224 s8 temp_min[3];
221 s8 temp_max[3]; 225 s8 temp_max[3];
@@ -247,7 +251,7 @@ static const int IN_NOMINAL_SCH311x[] = {2500, 1500, 3300, 5000, 12000, 3300,
247static const int IN_NOMINAL_SCH5027[] = {5000, 2250, 3300, 1125, 1125, 3300, 251static const int IN_NOMINAL_SCH5027[] = {5000, 2250, 3300, 1125, 1125, 3300,
248 3300}; 252 3300};
249static const int IN_NOMINAL_SCH5127[] = {2500, 2250, 3300, 1125, 1125, 3300, 253static const int IN_NOMINAL_SCH5127[] = {2500, 2250, 3300, 1125, 1125, 3300,
250 3300}; 254 3300, 1500};
251#define IN_NOMINAL(type) ((type) == sch311x ? IN_NOMINAL_SCH311x : \ 255#define IN_NOMINAL(type) ((type) == sch311x ? IN_NOMINAL_SCH311x : \
252 (type) == sch5027 ? IN_NOMINAL_SCH5027 : \ 256 (type) == sch5027 ? IN_NOMINAL_SCH5027 : \
253 (type) == sch5127 ? IN_NOMINAL_SCH5127 : \ 257 (type) == sch5127 ? IN_NOMINAL_SCH5127 : \
@@ -580,7 +584,7 @@ static struct dme1737_data *dme1737_update_device(struct device *dev)
580{ 584{
581 struct dme1737_data *data = dev_get_drvdata(dev); 585 struct dme1737_data *data = dev_get_drvdata(dev);
582 int ix; 586 int ix;
583 u8 lsb[5]; 587 u8 lsb[6];
584 588
585 mutex_lock(&data->update_lock); 589 mutex_lock(&data->update_lock);
586 590
@@ -603,6 +607,9 @@ static struct dme1737_data *dme1737_update_device(struct device *dev)
603 /* Voltage inputs are stored as 16 bit values even 607 /* Voltage inputs are stored as 16 bit values even
604 * though they have only 12 bits resolution. This is 608 * though they have only 12 bits resolution. This is
605 * to make it consistent with the temp inputs. */ 609 * to make it consistent with the temp inputs. */
610 if (ix == 7 && !(data->has_features & HAS_IN7)) {
611 continue;
612 }
606 data->in[ix] = dme1737_read(data, 613 data->in[ix] = dme1737_read(data,
607 DME1737_REG_IN(ix)) << 8; 614 DME1737_REG_IN(ix)) << 8;
608 data->in_min[ix] = dme1737_read(data, 615 data->in_min[ix] = dme1737_read(data,
@@ -635,10 +642,16 @@ static struct dme1737_data *dme1737_update_device(struct device *dev)
635 * which the registers are read (MSB first, then LSB) is 642 * which the registers are read (MSB first, then LSB) is
636 * important! */ 643 * important! */
637 for (ix = 0; ix < ARRAY_SIZE(lsb); ix++) { 644 for (ix = 0; ix < ARRAY_SIZE(lsb); ix++) {
645 if (ix == 5 && !(data->has_features & HAS_IN7)) {
646 continue;
647 }
638 lsb[ix] = dme1737_read(data, 648 lsb[ix] = dme1737_read(data,
639 DME1737_REG_IN_TEMP_LSB(ix)); 649 DME1737_REG_IN_TEMP_LSB(ix));
640 } 650 }
641 for (ix = 0; ix < ARRAY_SIZE(data->in); ix++) { 651 for (ix = 0; ix < ARRAY_SIZE(data->in); ix++) {
652 if (ix == 7 && !(data->has_features & HAS_IN7)) {
653 continue;
654 }
642 data->in[ix] |= (lsb[DME1737_REG_IN_LSB[ix]] << 655 data->in[ix] |= (lsb[DME1737_REG_IN_LSB[ix]] <<
643 DME1737_REG_IN_LSB_SHL[ix]) & 0xf0; 656 DME1737_REG_IN_LSB_SHL[ix]) & 0xf0;
644 } 657 }
@@ -762,7 +775,7 @@ static struct dme1737_data *dme1737_update_device(struct device *dev)
762 775
763/* --------------------------------------------------------------------- 776/* ---------------------------------------------------------------------
764 * Voltage sysfs attributes 777 * Voltage sysfs attributes
765 * ix = [0-5] 778 * ix = [0-7]
766 * --------------------------------------------------------------------- */ 779 * --------------------------------------------------------------------- */
767 780
768#define SYS_IN_INPUT 0 781#define SYS_IN_INPUT 0
@@ -1439,7 +1452,7 @@ static ssize_t show_name(struct device *dev, struct device_attribute *attr,
1439 * Sysfs device attribute defines and structs 1452 * Sysfs device attribute defines and structs
1440 * --------------------------------------------------------------------- */ 1453 * --------------------------------------------------------------------- */
1441 1454
1442/* Voltages 0-6 */ 1455/* Voltages 0-7 */
1443 1456
1444#define SENSOR_DEVICE_ATTR_IN(ix) \ 1457#define SENSOR_DEVICE_ATTR_IN(ix) \
1445static SENSOR_DEVICE_ATTR_2(in##ix##_input, S_IRUGO, \ 1458static SENSOR_DEVICE_ATTR_2(in##ix##_input, S_IRUGO, \
@@ -1458,6 +1471,7 @@ SENSOR_DEVICE_ATTR_IN(3);
1458SENSOR_DEVICE_ATTR_IN(4); 1471SENSOR_DEVICE_ATTR_IN(4);
1459SENSOR_DEVICE_ATTR_IN(5); 1472SENSOR_DEVICE_ATTR_IN(5);
1460SENSOR_DEVICE_ATTR_IN(6); 1473SENSOR_DEVICE_ATTR_IN(6);
1474SENSOR_DEVICE_ATTR_IN(7);
1461 1475
1462/* Temperatures 1-3 */ 1476/* Temperatures 1-3 */
1463 1477
@@ -1576,7 +1590,7 @@ static DEVICE_ATTR(name, S_IRUGO, show_name, NULL); /* for ISA devices */
1576 * created unconditionally. The attributes that need modification of their 1590 * created unconditionally. The attributes that need modification of their
1577 * permissions are created read-only and write permissions are added or removed 1591 * permissions are created read-only and write permissions are added or removed
1578 * on the fly when required */ 1592 * on the fly when required */
1579static struct attribute *dme1737_attr[] ={ 1593static struct attribute *dme1737_attr[] = {
1580 /* Voltages */ 1594 /* Voltages */
1581 &sensor_dev_attr_in0_input.dev_attr.attr, 1595 &sensor_dev_attr_in0_input.dev_attr.attr,
1582 &sensor_dev_attr_in0_min.dev_attr.attr, 1596 &sensor_dev_attr_in0_min.dev_attr.attr,
@@ -1681,7 +1695,7 @@ static const struct attribute_group dme1737_zone3_group = {
1681}; 1695};
1682 1696
1683 1697
1684/* The following struct holds temp zone hysteresis related attributes, which 1698/* The following struct holds temp zone hysteresis related attributes, which
1685 * are not available in all chips. The following chips support them: 1699 * are not available in all chips. The following chips support them:
1686 * DME1737, SCH311x */ 1700 * DME1737, SCH311x */
1687static struct attribute *dme1737_zone_hyst_attr[] = { 1701static struct attribute *dme1737_zone_hyst_attr[] = {
@@ -1695,6 +1709,21 @@ static const struct attribute_group dme1737_zone_hyst_group = {
1695 .attrs = dme1737_zone_hyst_attr, 1709 .attrs = dme1737_zone_hyst_attr,
1696}; 1710};
1697 1711
1712/* The following struct holds voltage in7 related attributes, which
1713 * are not available in all chips. The following chips support them:
1714 * SCH5127 */
1715static struct attribute *dme1737_in7_attr[] = {
1716 &sensor_dev_attr_in7_input.dev_attr.attr,
1717 &sensor_dev_attr_in7_min.dev_attr.attr,
1718 &sensor_dev_attr_in7_max.dev_attr.attr,
1719 &sensor_dev_attr_in7_alarm.dev_attr.attr,
1720 NULL
1721};
1722
1723static const struct attribute_group dme1737_in7_group = {
1724 .attrs = dme1737_in7_attr,
1725};
1726
1698/* The following structs hold the PWM attributes, some of which are optional. 1727/* The following structs hold the PWM attributes, some of which are optional.
1699 * Their creation depends on the chip configuration which is determined during 1728 * Their creation depends on the chip configuration which is determined during
1700 * module load. */ 1729 * module load. */
@@ -1986,6 +2015,9 @@ static void dme1737_remove_files(struct device *dev)
1986 if (data->has_features & HAS_ZONE_HYST) { 2015 if (data->has_features & HAS_ZONE_HYST) {
1987 sysfs_remove_group(&dev->kobj, &dme1737_zone_hyst_group); 2016 sysfs_remove_group(&dev->kobj, &dme1737_zone_hyst_group);
1988 } 2017 }
2018 if (data->has_features & HAS_IN7) {
2019 sysfs_remove_group(&dev->kobj, &dme1737_in7_group);
2020 }
1989 sysfs_remove_group(&dev->kobj, &dme1737_group); 2021 sysfs_remove_group(&dev->kobj, &dme1737_group);
1990 2022
1991 if (!data->client) { 2023 if (!data->client) {
@@ -1999,43 +2031,58 @@ static int dme1737_create_files(struct device *dev)
1999 int err, ix; 2031 int err, ix;
2000 2032
2001 /* Create a name attribute for ISA devices */ 2033 /* Create a name attribute for ISA devices */
2002 if (!data->client && 2034 if (!data->client) {
2003 (err = sysfs_create_file(&dev->kobj, &dev_attr_name.attr))) { 2035 err = sysfs_create_file(&dev->kobj, &dev_attr_name.attr);
2004 goto exit; 2036 if (err) {
2037 goto exit;
2038 }
2005 } 2039 }
2006 2040
2007 /* Create standard sysfs attributes */ 2041 /* Create standard sysfs attributes */
2008 if ((err = sysfs_create_group(&dev->kobj, &dme1737_group))) { 2042 err = sysfs_create_group(&dev->kobj, &dme1737_group);
2043 if (err) {
2009 goto exit_remove; 2044 goto exit_remove;
2010 } 2045 }
2011 2046
2012 /* Create chip-dependent sysfs attributes */ 2047 /* Create chip-dependent sysfs attributes */
2013 if ((data->has_features & HAS_TEMP_OFFSET) && 2048 if (data->has_features & HAS_TEMP_OFFSET) {
2014 (err = sysfs_create_group(&dev->kobj, 2049 err = sysfs_create_group(&dev->kobj,
2015 &dme1737_temp_offset_group))) { 2050 &dme1737_temp_offset_group);
2016 goto exit_remove; 2051 if (err) {
2052 goto exit_remove;
2053 }
2017 } 2054 }
2018 if ((data->has_features & HAS_VID) && 2055 if (data->has_features & HAS_VID) {
2019 (err = sysfs_create_group(&dev->kobj, 2056 err = sysfs_create_group(&dev->kobj, &dme1737_vid_group);
2020 &dme1737_vid_group))) { 2057 if (err) {
2021 goto exit_remove; 2058 goto exit_remove;
2059 }
2022 } 2060 }
2023 if ((data->has_features & HAS_ZONE3) && 2061 if (data->has_features & HAS_ZONE3) {
2024 (err = sysfs_create_group(&dev->kobj, 2062 err = sysfs_create_group(&dev->kobj, &dme1737_zone3_group);
2025 &dme1737_zone3_group))) { 2063 if (err) {
2026 goto exit_remove; 2064 goto exit_remove;
2065 }
2027 } 2066 }
2028 if ((data->has_features & HAS_ZONE_HYST) && 2067 if (data->has_features & HAS_ZONE_HYST) {
2029 (err = sysfs_create_group(&dev->kobj, 2068 err = sysfs_create_group(&dev->kobj, &dme1737_zone_hyst_group);
2030 &dme1737_zone_hyst_group))) { 2069 if (err) {
2031 goto exit_remove; 2070 goto exit_remove;
2071 }
2072 }
2073 if (data->has_features & HAS_IN7) {
2074 err = sysfs_create_group(&dev->kobj, &dme1737_in7_group);
2075 if (err) {
2076 goto exit_remove;
2077 }
2032 } 2078 }
2033 2079
2034 /* Create fan sysfs attributes */ 2080 /* Create fan sysfs attributes */
2035 for (ix = 0; ix < ARRAY_SIZE(dme1737_fan_group); ix++) { 2081 for (ix = 0; ix < ARRAY_SIZE(dme1737_fan_group); ix++) {
2036 if (data->has_features & HAS_FAN(ix)) { 2082 if (data->has_features & HAS_FAN(ix)) {
2037 if ((err = sysfs_create_group(&dev->kobj, 2083 err = sysfs_create_group(&dev->kobj,
2038 &dme1737_fan_group[ix]))) { 2084 &dme1737_fan_group[ix]);
2085 if (err) {
2039 goto exit_remove; 2086 goto exit_remove;
2040 } 2087 }
2041 } 2088 }
@@ -2044,14 +2091,17 @@ static int dme1737_create_files(struct device *dev)
2044 /* Create PWM sysfs attributes */ 2091 /* Create PWM sysfs attributes */
2045 for (ix = 0; ix < ARRAY_SIZE(dme1737_pwm_group); ix++) { 2092 for (ix = 0; ix < ARRAY_SIZE(dme1737_pwm_group); ix++) {
2046 if (data->has_features & HAS_PWM(ix)) { 2093 if (data->has_features & HAS_PWM(ix)) {
2047 if ((err = sysfs_create_group(&dev->kobj, 2094 err = sysfs_create_group(&dev->kobj,
2048 &dme1737_pwm_group[ix]))) { 2095 &dme1737_pwm_group[ix]);
2096 if (err) {
2049 goto exit_remove; 2097 goto exit_remove;
2050 } 2098 }
2051 if ((data->has_features & HAS_PWM_MIN) && ix < 3 && 2099 if ((data->has_features & HAS_PWM_MIN) && (ix < 3)) {
2052 (err = sysfs_create_file(&dev->kobj, 2100 err = sysfs_create_file(&dev->kobj,
2053 dme1737_auto_pwm_min_attr[ix]))) { 2101 dme1737_auto_pwm_min_attr[ix]);
2054 goto exit_remove; 2102 if (err) {
2103 goto exit_remove;
2104 }
2055 } 2105 }
2056 } 2106 }
2057 } 2107 }
@@ -2188,7 +2238,7 @@ static int dme1737_init_device(struct device *dev)
2188 data->has_features |= HAS_ZONE3; 2238 data->has_features |= HAS_ZONE3;
2189 break; 2239 break;
2190 case sch5127: 2240 case sch5127:
2191 data->has_features |= HAS_FAN(2) | HAS_PWM(2); 2241 data->has_features |= HAS_FAN(2) | HAS_PWM(2) | HAS_IN7;
2192 break; 2242 break;
2193 default: 2243 default:
2194 break; 2244 break;
@@ -2281,8 +2331,9 @@ static int dme1737_i2c_get_features(int sio_cip, struct dme1737_data *data)
2281 dme1737_sio_outb(sio_cip, 0x07, 0x0a); 2331 dme1737_sio_outb(sio_cip, 0x07, 0x0a);
2282 2332
2283 /* Get the base address of the runtime registers */ 2333 /* Get the base address of the runtime registers */
2284 if (!(addr = (dme1737_sio_inb(sio_cip, 0x60) << 8) | 2334 addr = (dme1737_sio_inb(sio_cip, 0x60) << 8) |
2285 dme1737_sio_inb(sio_cip, 0x61))) { 2335 dme1737_sio_inb(sio_cip, 0x61);
2336 if (!addr) {
2286 err = -ENODEV; 2337 err = -ENODEV;
2287 goto exit; 2338 goto exit;
2288 } 2339 }
@@ -2363,13 +2414,15 @@ static int dme1737_i2c_probe(struct i2c_client *client,
2363 mutex_init(&data->update_lock); 2414 mutex_init(&data->update_lock);
2364 2415
2365 /* Initialize the DME1737 chip */ 2416 /* Initialize the DME1737 chip */
2366 if ((err = dme1737_init_device(dev))) { 2417 err = dme1737_init_device(dev);
2418 if (err) {
2367 dev_err(dev, "Failed to initialize device.\n"); 2419 dev_err(dev, "Failed to initialize device.\n");
2368 goto exit_kfree; 2420 goto exit_kfree;
2369 } 2421 }
2370 2422
2371 /* Create sysfs files */ 2423 /* Create sysfs files */
2372 if ((err = dme1737_create_files(dev))) { 2424 err = dme1737_create_files(dev);
2425 if (err) {
2373 dev_err(dev, "Failed to create sysfs files.\n"); 2426 dev_err(dev, "Failed to create sysfs files.\n");
2374 goto exit_kfree; 2427 goto exit_kfree;
2375 } 2428 }
@@ -2446,8 +2499,9 @@ static int __init dme1737_isa_detect(int sio_cip, unsigned short *addr)
2446 dme1737_sio_outb(sio_cip, 0x07, 0x0a); 2499 dme1737_sio_outb(sio_cip, 0x07, 0x0a);
2447 2500
2448 /* Get the base address of the runtime registers */ 2501 /* Get the base address of the runtime registers */
2449 if (!(base_addr = (dme1737_sio_inb(sio_cip, 0x60) << 8) | 2502 base_addr = (dme1737_sio_inb(sio_cip, 0x60) << 8) |
2450 dme1737_sio_inb(sio_cip, 0x61))) { 2503 dme1737_sio_inb(sio_cip, 0x61);
2504 if (!base_addr) {
2451 pr_err("Base address not set\n"); 2505 pr_err("Base address not set\n");
2452 err = -ENODEV; 2506 err = -ENODEV;
2453 goto exit; 2507 goto exit;
@@ -2476,18 +2530,21 @@ static int __init dme1737_isa_device_add(unsigned short addr)
2476 if (err) 2530 if (err)
2477 goto exit; 2531 goto exit;
2478 2532
2479 if (!(pdev = platform_device_alloc("dme1737", addr))) { 2533 pdev = platform_device_alloc("dme1737", addr);
2534 if (!pdev) {
2480 pr_err("Failed to allocate device\n"); 2535 pr_err("Failed to allocate device\n");
2481 err = -ENOMEM; 2536 err = -ENOMEM;
2482 goto exit; 2537 goto exit;
2483 } 2538 }
2484 2539
2485 if ((err = platform_device_add_resources(pdev, &res, 1))) { 2540 err = platform_device_add_resources(pdev, &res, 1);
2541 if (err) {
2486 pr_err("Failed to add device resource (err = %d)\n", err); 2542 pr_err("Failed to add device resource (err = %d)\n", err);
2487 goto exit_device_put; 2543 goto exit_device_put;
2488 } 2544 }
2489 2545
2490 if ((err = platform_device_add(pdev))) { 2546 err = platform_device_add(pdev);
2547 if (err) {
2491 pr_err("Failed to add device (err = %d)\n", err); 2548 pr_err("Failed to add device (err = %d)\n", err);
2492 goto exit_device_put; 2549 goto exit_device_put;
2493 } 2550 }
@@ -2514,11 +2571,12 @@ static int __devinit dme1737_isa_probe(struct platform_device *pdev)
2514 dev_err(dev, "Failed to request region 0x%04x-0x%04x.\n", 2571 dev_err(dev, "Failed to request region 0x%04x-0x%04x.\n",
2515 (unsigned short)res->start, 2572 (unsigned short)res->start,
2516 (unsigned short)res->start + DME1737_EXTENT - 1); 2573 (unsigned short)res->start + DME1737_EXTENT - 1);
2517 err = -EBUSY; 2574 err = -EBUSY;
2518 goto exit; 2575 goto exit;
2519 } 2576 }
2520 2577
2521 if (!(data = kzalloc(sizeof(struct dme1737_data), GFP_KERNEL))) { 2578 data = kzalloc(sizeof(struct dme1737_data), GFP_KERNEL);
2579 if (!data) {
2522 err = -ENOMEM; 2580 err = -ENOMEM;
2523 goto exit_release_region; 2581 goto exit_release_region;
2524 } 2582 }
@@ -2565,13 +2623,15 @@ static int __devinit dme1737_isa_probe(struct platform_device *pdev)
2565 data->type == sch5127 ? "SCH5127" : "SCH311x", data->addr); 2623 data->type == sch5127 ? "SCH5127" : "SCH311x", data->addr);
2566 2624
2567 /* Initialize the chip */ 2625 /* Initialize the chip */
2568 if ((err = dme1737_init_device(dev))) { 2626 err = dme1737_init_device(dev);
2627 if (err) {
2569 dev_err(dev, "Failed to initialize device.\n"); 2628 dev_err(dev, "Failed to initialize device.\n");
2570 goto exit_kfree; 2629 goto exit_kfree;
2571 } 2630 }
2572 2631
2573 /* Create sysfs files */ 2632 /* Create sysfs files */
2574 if ((err = dme1737_create_files(dev))) { 2633 err = dme1737_create_files(dev);
2634 if (err) {
2575 dev_err(dev, "Failed to create sysfs files.\n"); 2635 dev_err(dev, "Failed to create sysfs files.\n");
2576 goto exit_kfree; 2636 goto exit_kfree;
2577 } 2637 }
@@ -2628,7 +2688,8 @@ static int __init dme1737_init(void)
2628 int err; 2688 int err;
2629 unsigned short addr; 2689 unsigned short addr;
2630 2690
2631 if ((err = i2c_add_driver(&dme1737_i2c_driver))) { 2691 err = i2c_add_driver(&dme1737_i2c_driver);
2692 if (err) {
2632 goto exit; 2693 goto exit;
2633 } 2694 }
2634 2695
@@ -2641,12 +2702,14 @@ static int __init dme1737_init(void)
2641 return 0; 2702 return 0;
2642 } 2703 }
2643 2704
2644 if ((err = platform_driver_register(&dme1737_isa_driver))) { 2705 err = platform_driver_register(&dme1737_isa_driver);
2706 if (err) {
2645 goto exit_del_i2c_driver; 2707 goto exit_del_i2c_driver;
2646 } 2708 }
2647 2709
2648 /* Sets global pdev as a side effect */ 2710 /* Sets global pdev as a side effect */
2649 if ((err = dme1737_isa_device_add(addr))) { 2711 err = dme1737_isa_device_add(addr);
2712 if (err) {
2650 goto exit_del_isa_driver; 2713 goto exit_del_isa_driver;
2651 } 2714 }
2652 2715
diff --git a/drivers/hwmon/emc1403.c b/drivers/hwmon/emc1403.c
index 8dee3f38fdfb..5dea9faa1656 100644
--- a/drivers/hwmon/emc1403.c
+++ b/drivers/hwmon/emc1403.c
@@ -269,23 +269,30 @@ static int emc1403_detect(struct i2c_client *client,
269 struct i2c_board_info *info) 269 struct i2c_board_info *info)
270{ 270{
271 int id; 271 int id;
272 /* Check if thermal chip is SMSC and EMC1403 */ 272 /* Check if thermal chip is SMSC and EMC1403 or EMC1423 */
273 273
274 id = i2c_smbus_read_byte_data(client, THERMAL_SMSC_ID_REG); 274 id = i2c_smbus_read_byte_data(client, THERMAL_SMSC_ID_REG);
275 if (id != 0x5d) 275 if (id != 0x5d)
276 return -ENODEV; 276 return -ENODEV;
277 277
278 id = i2c_smbus_read_byte_data(client, THERMAL_PID_REG);
279 switch (id) {
280 case 0x21:
281 strlcpy(info->type, "emc1403", I2C_NAME_SIZE);
282 break;
283 case 0x23:
284 strlcpy(info->type, "emc1423", I2C_NAME_SIZE);
285 break;
278 /* Note: 0x25 is the 1404 which is very similar and this 286 /* Note: 0x25 is the 1404 which is very similar and this
279 driver could be extended */ 287 driver could be extended */
280 id = i2c_smbus_read_byte_data(client, THERMAL_PID_REG); 288 default:
281 if (id != 0x21)
282 return -ENODEV; 289 return -ENODEV;
290 }
283 291
284 id = i2c_smbus_read_byte_data(client, THERMAL_REVISION_REG); 292 id = i2c_smbus_read_byte_data(client, THERMAL_REVISION_REG);
285 if (id != 0x01) 293 if (id != 0x01)
286 return -ENODEV; 294 return -ENODEV;
287 295
288 strlcpy(info->type, "emc1403", I2C_NAME_SIZE);
289 return 0; 296 return 0;
290} 297}
291 298
@@ -342,6 +349,7 @@ static const unsigned short emc1403_address_list[] = {
342 349
343static const struct i2c_device_id emc1403_idtable[] = { 350static const struct i2c_device_id emc1403_idtable[] = {
344 { "emc1403", 0 }, 351 { "emc1403", 0 },
352 { "emc1423", 0 },
345 { } 353 { }
346}; 354};
347MODULE_DEVICE_TABLE(i2c, emc1403_idtable); 355MODULE_DEVICE_TABLE(i2c, emc1403_idtable);
diff --git a/drivers/hwmon/fschmd.c b/drivers/hwmon/fschmd.c
index d4d4ca65d371..aa6d8b686f82 100644
--- a/drivers/hwmon/fschmd.c
+++ b/drivers/hwmon/fschmd.c
@@ -49,7 +49,6 @@
49#include <linux/kref.h> 49#include <linux/kref.h>
50 50
51/* Addresses to scan */ 51/* Addresses to scan */
52static DEFINE_MUTEX(watchdog_mutex);
53static const unsigned short normal_i2c[] = { 0x73, I2C_CLIENT_END }; 52static const unsigned short normal_i2c[] = { 0x73, I2C_CLIENT_END };
54 53
55/* Insmod parameters */ 54/* Insmod parameters */
@@ -850,7 +849,7 @@ static ssize_t watchdog_write(struct file *filp, const char __user *buf,
850 849
851static long watchdog_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) 850static long watchdog_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
852{ 851{
853 static struct watchdog_info ident = { 852 struct watchdog_info ident = {
854 .options = WDIOF_KEEPALIVEPING | WDIOF_SETTIMEOUT | 853 .options = WDIOF_KEEPALIVEPING | WDIOF_SETTIMEOUT |
855 WDIOF_CARDRESET, 854 WDIOF_CARDRESET,
856 .identity = "FSC watchdog" 855 .identity = "FSC watchdog"
@@ -858,7 +857,6 @@ static long watchdog_ioctl(struct file *filp, unsigned int cmd, unsigned long ar
858 int i, ret = 0; 857 int i, ret = 0;
859 struct fschmd_data *data = filp->private_data; 858 struct fschmd_data *data = filp->private_data;
860 859
861 mutex_lock(&watchdog_mutex);
862 switch (cmd) { 860 switch (cmd) {
863 case WDIOC_GETSUPPORT: 861 case WDIOC_GETSUPPORT:
864 ident.firmware_version = data->revision; 862 ident.firmware_version = data->revision;
@@ -915,7 +913,6 @@ static long watchdog_ioctl(struct file *filp, unsigned int cmd, unsigned long ar
915 default: 913 default:
916 ret = -ENOTTY; 914 ret = -ENOTTY;
917 } 915 }
918 mutex_unlock(&watchdog_mutex);
919 return ret; 916 return ret;
920} 917}
921 918
diff --git a/drivers/hwmon/it87.c b/drivers/hwmon/it87.c
index a428a9264195..316b64823f7b 100644
--- a/drivers/hwmon/it87.c
+++ b/drivers/hwmon/it87.c
@@ -38,6 +38,8 @@
38 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 38 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
39 */ 39 */
40 40
41#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
42
41#include <linux/module.h> 43#include <linux/module.h>
42#include <linux/init.h> 44#include <linux/init.h>
43#include <linux/slab.h> 45#include <linux/slab.h>
@@ -1570,26 +1572,25 @@ static int __init it87_find(unsigned short *address,
1570 case 0xffff: /* No device at all */ 1572 case 0xffff: /* No device at all */
1571 goto exit; 1573 goto exit;
1572 default: 1574 default:
1573 pr_debug(DRVNAME ": Unsupported chip (DEVID=0x%x)\n", 1575 pr_debug("Unsupported chip (DEVID=0x%x)\n", chip_type);
1574 chip_type);
1575 goto exit; 1576 goto exit;
1576 } 1577 }
1577 1578
1578 superio_select(PME); 1579 superio_select(PME);
1579 if (!(superio_inb(IT87_ACT_REG) & 0x01)) { 1580 if (!(superio_inb(IT87_ACT_REG) & 0x01)) {
1580 pr_info("it87: Device not activated, skipping\n"); 1581 pr_info("Device not activated, skipping\n");
1581 goto exit; 1582 goto exit;
1582 } 1583 }
1583 1584
1584 *address = superio_inw(IT87_BASE_REG) & ~(IT87_EXTENT - 1); 1585 *address = superio_inw(IT87_BASE_REG) & ~(IT87_EXTENT - 1);
1585 if (*address == 0) { 1586 if (*address == 0) {
1586 pr_info("it87: Base address not set, skipping\n"); 1587 pr_info("Base address not set, skipping\n");
1587 goto exit; 1588 goto exit;
1588 } 1589 }
1589 1590
1590 err = 0; 1591 err = 0;
1591 sio_data->revision = superio_inb(DEVREV) & 0x0f; 1592 sio_data->revision = superio_inb(DEVREV) & 0x0f;
1592 pr_info("it87: Found IT%04xF chip at 0x%x, revision %d\n", 1593 pr_info("Found IT%04xF chip at 0x%x, revision %d\n",
1593 chip_type, *address, sio_data->revision); 1594 chip_type, *address, sio_data->revision);
1594 1595
1595 /* in8 (Vbat) is always internal */ 1596 /* in8 (Vbat) is always internal */
@@ -1615,7 +1616,7 @@ static int __init it87_find(unsigned short *address,
1615 } else { 1616 } else {
1616 /* We need at least 4 VID pins */ 1617 /* We need at least 4 VID pins */
1617 if (reg & 0x0f) { 1618 if (reg & 0x0f) {
1618 pr_info("it87: VID is disabled (pins used for GPIO)\n"); 1619 pr_info("VID is disabled (pins used for GPIO)\n");
1619 sio_data->skip_vid = 1; 1620 sio_data->skip_vid = 1;
1620 } 1621 }
1621 } 1622 }
@@ -1651,7 +1652,7 @@ static int __init it87_find(unsigned short *address,
1651 if (sio_data->type == it8720 && !(reg & (1 << 1))) { 1652 if (sio_data->type == it8720 && !(reg & (1 << 1))) {
1652 reg |= (1 << 1); 1653 reg |= (1 << 1);
1653 superio_outb(IT87_SIO_PINX2_REG, reg); 1654 superio_outb(IT87_SIO_PINX2_REG, reg);
1654 pr_notice("it87: Routing internal VCCH to in7\n"); 1655 pr_notice("Routing internal VCCH to in7\n");
1655 } 1656 }
1656 if (reg & (1 << 0)) 1657 if (reg & (1 << 0))
1657 sio_data->internal |= (1 << 0); 1658 sio_data->internal |= (1 << 0);
@@ -1661,7 +1662,7 @@ static int __init it87_find(unsigned short *address,
1661 sio_data->beep_pin = superio_inb(IT87_SIO_BEEP_PIN_REG) & 0x3f; 1662 sio_data->beep_pin = superio_inb(IT87_SIO_BEEP_PIN_REG) & 0x3f;
1662 } 1663 }
1663 if (sio_data->beep_pin) 1664 if (sio_data->beep_pin)
1664 pr_info("it87: Beeping is supported\n"); 1665 pr_info("Beeping is supported\n");
1665 1666
1666 /* Disable specific features based on DMI strings */ 1667 /* Disable specific features based on DMI strings */
1667 board_vendor = dmi_get_system_info(DMI_BOARD_VENDOR); 1668 board_vendor = dmi_get_system_info(DMI_BOARD_VENDOR);
@@ -1675,8 +1676,7 @@ static int __init it87_find(unsigned short *address,
1675 the PWM2 duty cycle, so we disable it. 1676 the PWM2 duty cycle, so we disable it.
1676 I use the board name string as the trigger in case 1677 I use the board name string as the trigger in case
1677 the same board is ever used in other systems. */ 1678 the same board is ever used in other systems. */
1678 pr_info("it87: Disabling pwm2 due to " 1679 pr_info("Disabling pwm2 due to hardware constraints\n");
1679 "hardware constraints\n");
1680 sio_data->skip_pwm = (1 << 1); 1680 sio_data->skip_pwm = (1 << 1);
1681 } 1681 }
1682 } 1682 }
@@ -2189,28 +2189,26 @@ static int __init it87_device_add(unsigned short address,
2189 pdev = platform_device_alloc(DRVNAME, address); 2189 pdev = platform_device_alloc(DRVNAME, address);
2190 if (!pdev) { 2190 if (!pdev) {
2191 err = -ENOMEM; 2191 err = -ENOMEM;
2192 printk(KERN_ERR DRVNAME ": Device allocation failed\n"); 2192 pr_err("Device allocation failed\n");
2193 goto exit; 2193 goto exit;
2194 } 2194 }
2195 2195
2196 err = platform_device_add_resources(pdev, &res, 1); 2196 err = platform_device_add_resources(pdev, &res, 1);
2197 if (err) { 2197 if (err) {
2198 printk(KERN_ERR DRVNAME ": Device resource addition failed " 2198 pr_err("Device resource addition failed (%d)\n", err);
2199 "(%d)\n", err);
2200 goto exit_device_put; 2199 goto exit_device_put;
2201 } 2200 }
2202 2201
2203 err = platform_device_add_data(pdev, sio_data, 2202 err = platform_device_add_data(pdev, sio_data,
2204 sizeof(struct it87_sio_data)); 2203 sizeof(struct it87_sio_data));
2205 if (err) { 2204 if (err) {
2206 printk(KERN_ERR DRVNAME ": Platform data allocation failed\n"); 2205 pr_err("Platform data allocation failed\n");
2207 goto exit_device_put; 2206 goto exit_device_put;
2208 } 2207 }
2209 2208
2210 err = platform_device_add(pdev); 2209 err = platform_device_add(pdev);
2211 if (err) { 2210 if (err) {
2212 printk(KERN_ERR DRVNAME ": Device addition failed (%d)\n", 2211 pr_err("Device addition failed (%d)\n", err);
2213 err);
2214 goto exit_device_put; 2212 goto exit_device_put;
2215 } 2213 }
2216 2214
diff --git a/drivers/hwmon/lm78.c b/drivers/hwmon/lm78.c
index 72ff2c4e757d..4cb24eafe318 100644
--- a/drivers/hwmon/lm78.c
+++ b/drivers/hwmon/lm78.c
@@ -19,6 +19,8 @@
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20*/ 20*/
21 21
22#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
23
22#include <linux/module.h> 24#include <linux/module.h>
23#include <linux/init.h> 25#include <linux/init.h>
24#include <linux/slab.h> 26#include <linux/slab.h>
@@ -858,7 +860,7 @@ static int __init lm78_isa_found(unsigned short address)
858 * individually for the probing phase. */ 860 * individually for the probing phase. */
859 for (port = address; port < address + LM78_EXTENT; port++) { 861 for (port = address; port < address + LM78_EXTENT; port++) {
860 if (!request_region(port, 1, "lm78")) { 862 if (!request_region(port, 1, "lm78")) {
861 pr_debug("lm78: Failed to request port 0x%x\n", port); 863 pr_debug("Failed to request port 0x%x\n", port);
862 goto release; 864 goto release;
863 } 865 }
864 } 866 }
@@ -920,7 +922,7 @@ static int __init lm78_isa_found(unsigned short address)
920 found = 1; 922 found = 1;
921 923
922 if (found) 924 if (found)
923 pr_info("lm78: Found an %s chip at %#x\n", 925 pr_info("Found an %s chip at %#x\n",
924 val & 0x80 ? "LM79" : "LM78", (int)address); 926 val & 0x80 ? "LM79" : "LM78", (int)address);
925 927
926 release: 928 release:
@@ -942,21 +944,19 @@ static int __init lm78_isa_device_add(unsigned short address)
942 pdev = platform_device_alloc("lm78", address); 944 pdev = platform_device_alloc("lm78", address);
943 if (!pdev) { 945 if (!pdev) {
944 err = -ENOMEM; 946 err = -ENOMEM;
945 printk(KERN_ERR "lm78: Device allocation failed\n"); 947 pr_err("Device allocation failed\n");
946 goto exit; 948 goto exit;
947 } 949 }
948 950
949 err = platform_device_add_resources(pdev, &res, 1); 951 err = platform_device_add_resources(pdev, &res, 1);
950 if (err) { 952 if (err) {
951 printk(KERN_ERR "lm78: Device resource addition failed " 953 pr_err("Device resource addition failed (%d)\n", err);
952 "(%d)\n", err);
953 goto exit_device_put; 954 goto exit_device_put;
954 } 955 }
955 956
956 err = platform_device_add(pdev); 957 err = platform_device_add(pdev);
957 if (err) { 958 if (err) {
958 printk(KERN_ERR "lm78: Device addition failed (%d)\n", 959 pr_err("Device addition failed (%d)\n", err);
959 err);
960 goto exit_device_put; 960 goto exit_device_put;
961 } 961 }
962 962
diff --git a/drivers/hwmon/pc87360.c b/drivers/hwmon/pc87360.c
index 68e69a49633c..3d99b8854d7c 100644
--- a/drivers/hwmon/pc87360.c
+++ b/drivers/hwmon/pc87360.c
@@ -33,6 +33,8 @@
33 * the standard Super-I/O addresses is used (0x2E/0x2F or 0x4E/0x4F). 33 * the standard Super-I/O addresses is used (0x2E/0x2F or 0x4E/0x4F).
34 */ 34 */
35 35
36#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
37
36#include <linux/module.h> 38#include <linux/module.h>
37#include <linux/init.h> 39#include <linux/init.h>
38#include <linux/slab.h> 40#include <linux/slab.h>
@@ -1031,16 +1033,15 @@ static int __init pc87360_find(int sioaddr, u8 *devid, unsigned short *addresses
1031 1033
1032 val = superio_inb(sioaddr, ACT); 1034 val = superio_inb(sioaddr, ACT);
1033 if (!(val & 0x01)) { 1035 if (!(val & 0x01)) {
1034 printk(KERN_INFO "pc87360: Device 0x%02x not " 1036 pr_info("Device 0x%02x not activated\n", logdev[i]);
1035 "activated\n", logdev[i]);
1036 continue; 1037 continue;
1037 } 1038 }
1038 1039
1039 val = (superio_inb(sioaddr, BASE) << 8) 1040 val = (superio_inb(sioaddr, BASE) << 8)
1040 | superio_inb(sioaddr, BASE + 1); 1041 | superio_inb(sioaddr, BASE + 1);
1041 if (!val) { 1042 if (!val) {
1042 printk(KERN_INFO "pc87360: Base address not set for " 1043 pr_info("Base address not set for device 0x%02x\n",
1043 "device 0x%02x\n", logdev[i]); 1044 logdev[i]);
1044 continue; 1045 continue;
1045 } 1046 }
1046 1047
@@ -1050,17 +1051,15 @@ static int __init pc87360_find(int sioaddr, u8 *devid, unsigned short *addresses
1050 confreg[0] = superio_inb(sioaddr, 0xF0); 1051 confreg[0] = superio_inb(sioaddr, 0xF0);
1051 confreg[1] = superio_inb(sioaddr, 0xF1); 1052 confreg[1] = superio_inb(sioaddr, 0xF1);
1052 1053
1053#ifdef DEBUG 1054 pr_debug("Fan %d: mon=%d ctrl=%d inv=%d\n", 1,
1054 printk(KERN_DEBUG "pc87360: Fan 1: mon=%d " 1055 (confreg[0] >> 2) & 1, (confreg[0] >> 3) & 1,
1055 "ctrl=%d inv=%d\n", (confreg[0]>>2)&1, 1056 (confreg[0] >> 4) & 1);
1056 (confreg[0]>>3)&1, (confreg[0]>>4)&1); 1057 pr_debug("Fan %d: mon=%d ctrl=%d inv=%d\n", 2,
1057 printk(KERN_DEBUG "pc87360: Fan 2: mon=%d " 1058 (confreg[0] >> 5) & 1, (confreg[0] >> 6) & 1,
1058 "ctrl=%d inv=%d\n", (confreg[0]>>5)&1, 1059 (confreg[0] >> 7) & 1);
1059 (confreg[0]>>6)&1, (confreg[0]>>7)&1); 1060 pr_debug("Fan %d: mon=%d ctrl=%d inv=%d\n", 3,
1060 printk(KERN_DEBUG "pc87360: Fan 3: mon=%d " 1061 confreg[1] & 1, (confreg[1] >> 1) & 1,
1061 "ctrl=%d inv=%d\n", confreg[1]&1, 1062 (confreg[1] >> 2) & 1);
1062 (confreg[1]>>1)&1, (confreg[1]>>2)&1);
1063#endif
1064 } else if (i==1) { /* Voltages */ 1063 } else if (i==1) { /* Voltages */
1065 /* Are we using thermistors? */ 1064 /* Are we using thermistors? */
1066 if (*devid == 0xE9) { /* PC87366 */ 1065 if (*devid == 0xE9) { /* PC87366 */
@@ -1071,14 +1070,12 @@ static int __init pc87360_find(int sioaddr, u8 *devid, unsigned short *addresses
1071 confreg[3] = superio_inb(sioaddr, 0x25); 1070 confreg[3] = superio_inb(sioaddr, 0x25);
1072 1071
1073 if (confreg[2] & 0x40) { 1072 if (confreg[2] & 0x40) {
1074 printk(KERN_INFO "pc87360: Using " 1073 pr_info("Using thermistors for "
1075 "thermistors for temperature " 1074 "temperature monitoring\n");
1076 "monitoring\n");
1077 } 1075 }
1078 if (confreg[3] & 0xE0) { 1076 if (confreg[3] & 0xE0) {
1079 printk(KERN_INFO "pc87360: VID " 1077 pr_info("VID inputs routed (mode %u)\n",
1080 "inputs routed (mode %u)\n", 1078 confreg[3] >> 5);
1081 confreg[3] >> 5);
1082 } 1079 }
1083 } 1080 }
1084 } 1081 }
@@ -1616,7 +1613,7 @@ static int __init pc87360_device_add(unsigned short address)
1616 pdev = platform_device_alloc("pc87360", address); 1613 pdev = platform_device_alloc("pc87360", address);
1617 if (!pdev) { 1614 if (!pdev) {
1618 err = -ENOMEM; 1615 err = -ENOMEM;
1619 printk(KERN_ERR "pc87360: Device allocation failed\n"); 1616 pr_err("Device allocation failed\n");
1620 goto exit; 1617 goto exit;
1621 } 1618 }
1622 1619
@@ -1639,15 +1636,13 @@ static int __init pc87360_device_add(unsigned short address)
1639 1636
1640 err = platform_device_add_resources(pdev, res, res_count); 1637 err = platform_device_add_resources(pdev, res, res_count);
1641 if (err) { 1638 if (err) {
1642 printk(KERN_ERR "pc87360: Device resources addition failed " 1639 pr_err("Device resources addition failed (%d)\n", err);
1643 "(%d)\n", err);
1644 goto exit_device_put; 1640 goto exit_device_put;
1645 } 1641 }
1646 1642
1647 err = platform_device_add(pdev); 1643 err = platform_device_add(pdev);
1648 if (err) { 1644 if (err) {
1649 printk(KERN_ERR "pc87360: Device addition failed (%d)\n", 1645 pr_err("Device addition failed (%d)\n", err);
1650 err);
1651 goto exit_device_put; 1646 goto exit_device_put;
1652 } 1647 }
1653 1648
@@ -1666,8 +1661,7 @@ static int __init pc87360_init(void)
1666 1661
1667 if (pc87360_find(0x2e, &devid, extra_isa) 1662 if (pc87360_find(0x2e, &devid, extra_isa)
1668 && pc87360_find(0x4e, &devid, extra_isa)) { 1663 && pc87360_find(0x4e, &devid, extra_isa)) {
1669 printk(KERN_WARNING "pc87360: PC8736x not detected, " 1664 pr_warn("PC8736x not detected, module not inserted\n");
1670 "module not inserted.\n");
1671 return -ENODEV; 1665 return -ENODEV;
1672 } 1666 }
1673 1667
@@ -1680,8 +1674,7 @@ static int __init pc87360_init(void)
1680 } 1674 }
1681 1675
1682 if (address == 0x0000) { 1676 if (address == 0x0000) {
1683 printk(KERN_WARNING "pc87360: No active logical device, " 1677 pr_warn("No active logical device, module not inserted\n");
1684 "module not inserted.\n");
1685 return -ENODEV; 1678 return -ENODEV;
1686 } 1679 }
1687 1680
diff --git a/drivers/hwmon/pc87427.c b/drivers/hwmon/pc87427.c
index 9ec4daaf6ca6..8da2181630b1 100644
--- a/drivers/hwmon/pc87427.c
+++ b/drivers/hwmon/pc87427.c
@@ -22,6 +22,8 @@
22 * mode, and voltages aren't supported at all. 22 * mode, and voltages aren't supported at all.
23 */ 23 */
24 24
25#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
26
25#include <linux/module.h> 27#include <linux/module.h>
26#include <linux/init.h> 28#include <linux/init.h>
27#include <linux/slab.h> 29#include <linux/slab.h>
@@ -1077,7 +1079,7 @@ static int __devinit pc87427_probe(struct platform_device *pdev)
1077 data = kzalloc(sizeof(struct pc87427_data), GFP_KERNEL); 1079 data = kzalloc(sizeof(struct pc87427_data), GFP_KERNEL);
1078 if (!data) { 1080 if (!data) {
1079 err = -ENOMEM; 1081 err = -ENOMEM;
1080 printk(KERN_ERR DRVNAME ": Out of memory\n"); 1082 pr_err("Out of memory\n");
1081 goto exit; 1083 goto exit;
1082 } 1084 }
1083 1085
@@ -1196,28 +1198,26 @@ static int __init pc87427_device_add(const struct pc87427_sio_data *sio_data)
1196 pdev = platform_device_alloc(DRVNAME, res[0].start); 1198 pdev = platform_device_alloc(DRVNAME, res[0].start);
1197 if (!pdev) { 1199 if (!pdev) {
1198 err = -ENOMEM; 1200 err = -ENOMEM;
1199 printk(KERN_ERR DRVNAME ": Device allocation failed\n"); 1201 pr_err("Device allocation failed\n");
1200 goto exit; 1202 goto exit;
1201 } 1203 }
1202 1204
1203 err = platform_device_add_resources(pdev, res, res_count); 1205 err = platform_device_add_resources(pdev, res, res_count);
1204 if (err) { 1206 if (err) {
1205 printk(KERN_ERR DRVNAME ": Device resource addition failed " 1207 pr_err("Device resource addition failed (%d)\n", err);
1206 "(%d)\n", err);
1207 goto exit_device_put; 1208 goto exit_device_put;
1208 } 1209 }
1209 1210
1210 err = platform_device_add_data(pdev, sio_data, 1211 err = platform_device_add_data(pdev, sio_data,
1211 sizeof(struct pc87427_sio_data)); 1212 sizeof(struct pc87427_sio_data));
1212 if (err) { 1213 if (err) {
1213 printk(KERN_ERR DRVNAME ": Platform data allocation failed\n"); 1214 pr_err("Platform data allocation failed\n");
1214 goto exit_device_put; 1215 goto exit_device_put;
1215 } 1216 }
1216 1217
1217 err = platform_device_add(pdev); 1218 err = platform_device_add(pdev);
1218 if (err) { 1219 if (err) {
1219 printk(KERN_ERR DRVNAME ": Device addition failed (%d)\n", 1220 pr_err("Device addition failed (%d)\n", err);
1220 err);
1221 goto exit_device_put; 1221 goto exit_device_put;
1222 } 1222 }
1223 1223
@@ -1249,23 +1249,23 @@ static int __init pc87427_find(int sioaddr, struct pc87427_sio_data *sio_data)
1249 1249
1250 val = superio_inb(sioaddr, SIOREG_ACT); 1250 val = superio_inb(sioaddr, SIOREG_ACT);
1251 if (!(val & 0x01)) { 1251 if (!(val & 0x01)) {
1252 printk(KERN_INFO DRVNAME ": Logical device 0x%02x " 1252 pr_info("Logical device 0x%02x not activated\n",
1253 "not activated\n", logdev[i]); 1253 logdev[i]);
1254 continue; 1254 continue;
1255 } 1255 }
1256 1256
1257 val = superio_inb(sioaddr, SIOREG_MAP); 1257 val = superio_inb(sioaddr, SIOREG_MAP);
1258 if (val & 0x01) { 1258 if (val & 0x01) {
1259 printk(KERN_WARNING DRVNAME ": Logical device 0x%02x " 1259 pr_warn("Logical device 0x%02x is memory-mapped, "
1260 "is memory-mapped, can't use\n", logdev[i]); 1260 "can't use\n", logdev[i]);
1261 continue; 1261 continue;
1262 } 1262 }
1263 1263
1264 val = (superio_inb(sioaddr, SIOREG_IOBASE) << 8) 1264 val = (superio_inb(sioaddr, SIOREG_IOBASE) << 8)
1265 | superio_inb(sioaddr, SIOREG_IOBASE + 1); 1265 | superio_inb(sioaddr, SIOREG_IOBASE + 1);
1266 if (!val) { 1266 if (!val) {
1267 printk(KERN_INFO DRVNAME ": I/O base address not set " 1267 pr_info("I/O base address not set for logical device "
1268 "for logical device 0x%02x\n", logdev[i]); 1268 "0x%02x\n", logdev[i]);
1269 continue; 1269 continue;
1270 } 1270 }
1271 sio_data->address[i] = val; 1271 sio_data->address[i] = val;
diff --git a/drivers/hwmon/via686a.c b/drivers/hwmon/via686a.c
index 13e8d218e495..25e91665a0a2 100644
--- a/drivers/hwmon/via686a.c
+++ b/drivers/hwmon/via686a.c
@@ -689,6 +689,13 @@ static int __devexit via686a_remove(struct platform_device *pdev)
689 return 0; 689 return 0;
690} 690}
691 691
692static void via686a_update_fan_div(struct via686a_data *data)
693{
694 int reg = via686a_read_value(data, VIA686A_REG_FANDIV);
695 data->fan_div[0] = (reg >> 4) & 0x03;
696 data->fan_div[1] = reg >> 6;
697}
698
692static void __devinit via686a_init_device(struct via686a_data *data) 699static void __devinit via686a_init_device(struct via686a_data *data)
693{ 700{
694 u8 reg; 701 u8 reg;
@@ -702,6 +709,9 @@ static void __devinit via686a_init_device(struct via686a_data *data)
702 via686a_write_value(data, VIA686A_REG_TEMP_MODE, 709 via686a_write_value(data, VIA686A_REG_TEMP_MODE,
703 (reg & ~VIA686A_TEMP_MODE_MASK) 710 (reg & ~VIA686A_TEMP_MODE_MASK)
704 | VIA686A_TEMP_MODE_CONTINUOUS); 711 | VIA686A_TEMP_MODE_CONTINUOUS);
712
713 /* Pre-read fan clock divisor values */
714 via686a_update_fan_div(data);
705} 715}
706 716
707static struct via686a_data *via686a_update_device(struct device *dev) 717static struct via686a_data *via686a_update_device(struct device *dev)
@@ -753,9 +763,7 @@ static struct via686a_data *via686a_update_device(struct device *dev)
753 (via686a_read_value(data, VIA686A_REG_TEMP_LOW23) & 763 (via686a_read_value(data, VIA686A_REG_TEMP_LOW23) &
754 0xc0) >> 6; 764 0xc0) >> 6;
755 765
756 i = via686a_read_value(data, VIA686A_REG_FANDIV); 766 via686a_update_fan_div(data);
757 data->fan_div[0] = (i >> 4) & 0x03;
758 data->fan_div[1] = i >> 6;
759 data->alarms = 767 data->alarms =
760 via686a_read_value(data, 768 via686a_read_value(data,
761 VIA686A_REG_ALARM1) | 769 VIA686A_REG_ALARM1) |
diff --git a/drivers/hwmon/w83781d.c b/drivers/hwmon/w83781d.c
index c84b9b4e6960..eed43a008be1 100644
--- a/drivers/hwmon/w83781d.c
+++ b/drivers/hwmon/w83781d.c
@@ -33,6 +33,8 @@
33 33
34*/ 34*/
35 35
36#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
37
36#include <linux/module.h> 38#include <linux/module.h>
37#include <linux/init.h> 39#include <linux/init.h>
38#include <linux/slab.h> 40#include <linux/slab.h>
@@ -1798,8 +1800,7 @@ w83781d_isa_found(unsigned short address)
1798 * individually for the probing phase. */ 1800 * individually for the probing phase. */
1799 for (port = address; port < address + W83781D_EXTENT; port++) { 1801 for (port = address; port < address + W83781D_EXTENT; port++) {
1800 if (!request_region(port, 1, "w83781d")) { 1802 if (!request_region(port, 1, "w83781d")) {
1801 pr_debug("w83781d: Failed to request port 0x%x\n", 1803 pr_debug("Failed to request port 0x%x\n", port);
1802 port);
1803 goto release; 1804 goto release;
1804 } 1805 }
1805 } 1806 }
@@ -1811,7 +1812,7 @@ w83781d_isa_found(unsigned short address)
1811 if (inb_p(address + 2) != val 1812 if (inb_p(address + 2) != val
1812 || inb_p(address + 3) != val 1813 || inb_p(address + 3) != val
1813 || inb_p(address + 7) != val) { 1814 || inb_p(address + 7) != val) {
1814 pr_debug("w83781d: Detection failed at step 1\n"); 1815 pr_debug("Detection failed at step %d\n", 1);
1815 goto release; 1816 goto release;
1816 } 1817 }
1817#undef REALLY_SLOW_IO 1818#undef REALLY_SLOW_IO
@@ -1820,14 +1821,14 @@ w83781d_isa_found(unsigned short address)
1820 MSB (busy flag) should be clear initially, set after the write. */ 1821 MSB (busy flag) should be clear initially, set after the write. */
1821 save = inb_p(address + W83781D_ADDR_REG_OFFSET); 1822 save = inb_p(address + W83781D_ADDR_REG_OFFSET);
1822 if (save & 0x80) { 1823 if (save & 0x80) {
1823 pr_debug("w83781d: Detection failed at step 2\n"); 1824 pr_debug("Detection failed at step %d\n", 2);
1824 goto release; 1825 goto release;
1825 } 1826 }
1826 val = ~save & 0x7f; 1827 val = ~save & 0x7f;
1827 outb_p(val, address + W83781D_ADDR_REG_OFFSET); 1828 outb_p(val, address + W83781D_ADDR_REG_OFFSET);
1828 if (inb_p(address + W83781D_ADDR_REG_OFFSET) != (val | 0x80)) { 1829 if (inb_p(address + W83781D_ADDR_REG_OFFSET) != (val | 0x80)) {
1829 outb_p(save, address + W83781D_ADDR_REG_OFFSET); 1830 outb_p(save, address + W83781D_ADDR_REG_OFFSET);
1830 pr_debug("w83781d: Detection failed at step 3\n"); 1831 pr_debug("Detection failed at step %d\n", 3);
1831 goto release; 1832 goto release;
1832 } 1833 }
1833 1834
@@ -1835,7 +1836,7 @@ w83781d_isa_found(unsigned short address)
1835 outb_p(W83781D_REG_CONFIG, address + W83781D_ADDR_REG_OFFSET); 1836 outb_p(W83781D_REG_CONFIG, address + W83781D_ADDR_REG_OFFSET);
1836 val = inb_p(address + W83781D_DATA_REG_OFFSET); 1837 val = inb_p(address + W83781D_DATA_REG_OFFSET);
1837 if (val & 0x80) { 1838 if (val & 0x80) {
1838 pr_debug("w83781d: Detection failed at step 4\n"); 1839 pr_debug("Detection failed at step %d\n", 4);
1839 goto release; 1840 goto release;
1840 } 1841 }
1841 outb_p(W83781D_REG_BANK, address + W83781D_ADDR_REG_OFFSET); 1842 outb_p(W83781D_REG_BANK, address + W83781D_ADDR_REG_OFFSET);
@@ -1844,19 +1845,19 @@ w83781d_isa_found(unsigned short address)
1844 val = inb_p(address + W83781D_DATA_REG_OFFSET); 1845 val = inb_p(address + W83781D_DATA_REG_OFFSET);
1845 if ((!(save & 0x80) && (val != 0xa3)) 1846 if ((!(save & 0x80) && (val != 0xa3))
1846 || ((save & 0x80) && (val != 0x5c))) { 1847 || ((save & 0x80) && (val != 0x5c))) {
1847 pr_debug("w83781d: Detection failed at step 5\n"); 1848 pr_debug("Detection failed at step %d\n", 5);
1848 goto release; 1849 goto release;
1849 } 1850 }
1850 outb_p(W83781D_REG_I2C_ADDR, address + W83781D_ADDR_REG_OFFSET); 1851 outb_p(W83781D_REG_I2C_ADDR, address + W83781D_ADDR_REG_OFFSET);
1851 val = inb_p(address + W83781D_DATA_REG_OFFSET); 1852 val = inb_p(address + W83781D_DATA_REG_OFFSET);
1852 if (val < 0x03 || val > 0x77) { /* Not a valid I2C address */ 1853 if (val < 0x03 || val > 0x77) { /* Not a valid I2C address */
1853 pr_debug("w83781d: Detection failed at step 6\n"); 1854 pr_debug("Detection failed at step %d\n", 6);
1854 goto release; 1855 goto release;
1855 } 1856 }
1856 1857
1857 /* The busy flag should be clear again */ 1858 /* The busy flag should be clear again */
1858 if (inb_p(address + W83781D_ADDR_REG_OFFSET) & 0x80) { 1859 if (inb_p(address + W83781D_ADDR_REG_OFFSET) & 0x80) {
1859 pr_debug("w83781d: Detection failed at step 7\n"); 1860 pr_debug("Detection failed at step %d\n", 7);
1860 goto release; 1861 goto release;
1861 } 1862 }
1862 1863
@@ -1871,7 +1872,7 @@ w83781d_isa_found(unsigned short address)
1871 found = 1; 1872 found = 1;
1872 1873
1873 if (found) 1874 if (found)
1874 pr_info("w83781d: Found a %s chip at %#x\n", 1875 pr_info("Found a %s chip at %#x\n",
1875 val == 0x30 ? "W83782D" : "W83781D", (int)address); 1876 val == 0x30 ? "W83782D" : "W83781D", (int)address);
1876 1877
1877 release: 1878 release:
@@ -1894,21 +1895,19 @@ w83781d_isa_device_add(unsigned short address)
1894 pdev = platform_device_alloc("w83781d", address); 1895 pdev = platform_device_alloc("w83781d", address);
1895 if (!pdev) { 1896 if (!pdev) {
1896 err = -ENOMEM; 1897 err = -ENOMEM;
1897 printk(KERN_ERR "w83781d: Device allocation failed\n"); 1898 pr_err("Device allocation failed\n");
1898 goto exit; 1899 goto exit;
1899 } 1900 }
1900 1901
1901 err = platform_device_add_resources(pdev, &res, 1); 1902 err = platform_device_add_resources(pdev, &res, 1);
1902 if (err) { 1903 if (err) {
1903 printk(KERN_ERR "w83781d: Device resource addition failed " 1904 pr_err("Device resource addition failed (%d)\n", err);
1904 "(%d)\n", err);
1905 goto exit_device_put; 1905 goto exit_device_put;
1906 } 1906 }
1907 1907
1908 err = platform_device_add(pdev); 1908 err = platform_device_add(pdev);
1909 if (err) { 1909 if (err) {
1910 printk(KERN_ERR "w83781d: Device addition failed (%d)\n", 1910 pr_err("Device addition failed (%d)\n", err);
1911 err);
1912 goto exit_device_put; 1911 goto exit_device_put;
1913 } 1912 }
1914 1913
diff --git a/drivers/hwmon/w83792d.c b/drivers/hwmon/w83792d.c
index 679718e6b017..63841f8cec07 100644
--- a/drivers/hwmon/w83792d.c
+++ b/drivers/hwmon/w83792d.c
@@ -691,7 +691,7 @@ store_pwm_mode(struct device *dev, struct device_attribute *attr,
691} 691}
692 692
693static ssize_t 693static ssize_t
694show_regs_chassis(struct device *dev, struct device_attribute *attr, 694show_chassis(struct device *dev, struct device_attribute *attr,
695 char *buf) 695 char *buf)
696{ 696{
697 struct w83792d_data *data = w83792d_update_device(dev); 697 struct w83792d_data *data = w83792d_update_device(dev);
@@ -699,6 +699,16 @@ show_regs_chassis(struct device *dev, struct device_attribute *attr,
699} 699}
700 700
701static ssize_t 701static ssize_t
702show_regs_chassis(struct device *dev, struct device_attribute *attr,
703 char *buf)
704{
705 dev_warn(dev,
706 "Attribute %s is deprecated, use intrusion0_alarm instead\n",
707 "chassis");
708 return show_chassis(dev, attr, buf);
709}
710
711static ssize_t
702show_chassis_clear(struct device *dev, struct device_attribute *attr, char *buf) 712show_chassis_clear(struct device *dev, struct device_attribute *attr, char *buf)
703{ 713{
704 struct w83792d_data *data = w83792d_update_device(dev); 714 struct w83792d_data *data = w83792d_update_device(dev);
@@ -706,7 +716,7 @@ show_chassis_clear(struct device *dev, struct device_attribute *attr, char *buf)
706} 716}
707 717
708static ssize_t 718static ssize_t
709store_chassis_clear(struct device *dev, struct device_attribute *attr, 719store_chassis_clear_legacy(struct device *dev, struct device_attribute *attr,
710 const char *buf, size_t count) 720 const char *buf, size_t count)
711{ 721{
712 struct i2c_client *client = to_i2c_client(dev); 722 struct i2c_client *client = to_i2c_client(dev);
@@ -714,6 +724,10 @@ store_chassis_clear(struct device *dev, struct device_attribute *attr,
714 u32 val; 724 u32 val;
715 u8 temp1 = 0, temp2 = 0; 725 u8 temp1 = 0, temp2 = 0;
716 726
727 dev_warn(dev,
728 "Attribute %s is deprecated, use intrusion0_alarm instead\n",
729 "chassis_clear");
730
717 val = simple_strtoul(buf, NULL, 10); 731 val = simple_strtoul(buf, NULL, 10);
718 mutex_lock(&data->update_lock); 732 mutex_lock(&data->update_lock);
719 data->chassis_clear = SENSORS_LIMIT(val, 0 ,1); 733 data->chassis_clear = SENSORS_LIMIT(val, 0 ,1);
@@ -726,6 +740,27 @@ store_chassis_clear(struct device *dev, struct device_attribute *attr,
726 return count; 740 return count;
727} 741}
728 742
743static ssize_t
744store_chassis_clear(struct device *dev, struct device_attribute *attr,
745 const char *buf, size_t count)
746{
747 struct i2c_client *client = to_i2c_client(dev);
748 struct w83792d_data *data = i2c_get_clientdata(client);
749 unsigned long val;
750 u8 reg;
751
752 if (strict_strtoul(buf, 10, &val) || val != 0)
753 return -EINVAL;
754
755 mutex_lock(&data->update_lock);
756 reg = w83792d_read_value(client, W83792D_REG_CHASSIS_CLR);
757 w83792d_write_value(client, W83792D_REG_CHASSIS_CLR, reg | 0x80);
758 data->valid = 0; /* Force cache refresh */
759 mutex_unlock(&data->update_lock);
760
761 return count;
762}
763
729/* For Smart Fan I / Thermal Cruise */ 764/* For Smart Fan I / Thermal Cruise */
730static ssize_t 765static ssize_t
731show_thermal_cruise(struct device *dev, struct device_attribute *attr, 766show_thermal_cruise(struct device *dev, struct device_attribute *attr,
@@ -1012,7 +1047,9 @@ static SENSOR_DEVICE_ATTR(fan5_alarm, S_IRUGO, show_alarm, NULL, 22);
1012static SENSOR_DEVICE_ATTR(fan6_alarm, S_IRUGO, show_alarm, NULL, 23); 1047static SENSOR_DEVICE_ATTR(fan6_alarm, S_IRUGO, show_alarm, NULL, 23);
1013static DEVICE_ATTR(chassis, S_IRUGO, show_regs_chassis, NULL); 1048static DEVICE_ATTR(chassis, S_IRUGO, show_regs_chassis, NULL);
1014static DEVICE_ATTR(chassis_clear, S_IRUGO | S_IWUSR, 1049static DEVICE_ATTR(chassis_clear, S_IRUGO | S_IWUSR,
1015 show_chassis_clear, store_chassis_clear); 1050 show_chassis_clear, store_chassis_clear_legacy);
1051static DEVICE_ATTR(intrusion0_alarm, S_IRUGO | S_IWUSR,
1052 show_chassis, store_chassis_clear);
1016static SENSOR_DEVICE_ATTR(pwm1, S_IWUSR | S_IRUGO, show_pwm, store_pwm, 0); 1053static SENSOR_DEVICE_ATTR(pwm1, S_IWUSR | S_IRUGO, show_pwm, store_pwm, 0);
1017static SENSOR_DEVICE_ATTR(pwm2, S_IWUSR | S_IRUGO, show_pwm, store_pwm, 1); 1054static SENSOR_DEVICE_ATTR(pwm2, S_IWUSR | S_IRUGO, show_pwm, store_pwm, 1);
1018static SENSOR_DEVICE_ATTR(pwm3, S_IWUSR | S_IRUGO, show_pwm, store_pwm, 2); 1055static SENSOR_DEVICE_ATTR(pwm3, S_IWUSR | S_IRUGO, show_pwm, store_pwm, 2);
@@ -1214,6 +1251,7 @@ static struct attribute *w83792d_attributes[] = {
1214 &dev_attr_alarms.attr, 1251 &dev_attr_alarms.attr,
1215 &dev_attr_chassis.attr, 1252 &dev_attr_chassis.attr,
1216 &dev_attr_chassis_clear.attr, 1253 &dev_attr_chassis_clear.attr,
1254 &dev_attr_intrusion0_alarm.attr,
1217 &sensor_dev_attr_tolerance1.dev_attr.attr, 1255 &sensor_dev_attr_tolerance1.dev_attr.attr,
1218 &sensor_dev_attr_thermal_cruise1.dev_attr.attr, 1256 &sensor_dev_attr_thermal_cruise1.dev_attr.attr,
1219 &sensor_dev_attr_tolerance2.dev_attr.attr, 1257 &sensor_dev_attr_tolerance2.dev_attr.attr,
diff --git a/drivers/hwmon/w83793.c b/drivers/hwmon/w83793.c
index 8e540ada47d2..e3bdedfb5347 100644
--- a/drivers/hwmon/w83793.c
+++ b/drivers/hwmon/w83793.c
@@ -51,7 +51,6 @@
51#define WATCHDOG_TIMEOUT 2 /* 2 minute default timeout */ 51#define WATCHDOG_TIMEOUT 2 /* 2 minute default timeout */
52 52
53/* Addresses to scan */ 53/* Addresses to scan */
54static DEFINE_MUTEX(watchdog_mutex);
55static const unsigned short normal_i2c[] = { 0x2c, 0x2d, 0x2e, 0x2f, 54static const unsigned short normal_i2c[] = { 0x2c, 0x2d, 0x2e, 0x2f,
56 I2C_CLIENT_END }; 55 I2C_CLIENT_END };
57 56
@@ -421,14 +420,17 @@ store_beep_enable(struct device *dev, struct device_attribute *attr,
421 420
422/* Write any value to clear chassis alarm */ 421/* Write any value to clear chassis alarm */
423static ssize_t 422static ssize_t
424store_chassis_clear(struct device *dev, 423store_chassis_clear_legacy(struct device *dev,
425 struct device_attribute *attr, const char *buf, 424 struct device_attribute *attr, const char *buf,
426 size_t count) 425 size_t count)
427{ 426{
428 struct i2c_client *client = to_i2c_client(dev); 427 struct i2c_client *client = to_i2c_client(dev);
429 struct w83793_data *data = i2c_get_clientdata(client); 428 struct w83793_data *data = i2c_get_clientdata(client);
430 u8 val; 429 u8 val;
431 430
431 dev_warn(dev, "Attribute chassis is deprecated, "
432 "use intrusion0_alarm instead\n");
433
432 mutex_lock(&data->update_lock); 434 mutex_lock(&data->update_lock);
433 val = w83793_read_value(client, W83793_REG_CLR_CHASSIS); 435 val = w83793_read_value(client, W83793_REG_CLR_CHASSIS);
434 val |= 0x80; 436 val |= 0x80;
@@ -437,6 +439,28 @@ store_chassis_clear(struct device *dev,
437 return count; 439 return count;
438} 440}
439 441
442/* Write 0 to clear chassis alarm */
443static ssize_t
444store_chassis_clear(struct device *dev,
445 struct device_attribute *attr, const char *buf,
446 size_t count)
447{
448 struct i2c_client *client = to_i2c_client(dev);
449 struct w83793_data *data = i2c_get_clientdata(client);
450 unsigned long val;
451 u8 reg;
452
453 if (strict_strtoul(buf, 10, &val) || val != 0)
454 return -EINVAL;
455
456 mutex_lock(&data->update_lock);
457 reg = w83793_read_value(client, W83793_REG_CLR_CHASSIS);
458 w83793_write_value(client, W83793_REG_CLR_CHASSIS, reg | 0x80);
459 data->valid = 0; /* Force cache refresh */
460 mutex_unlock(&data->update_lock);
461 return count;
462}
463
440#define FAN_INPUT 0 464#define FAN_INPUT 0
441#define FAN_MIN 1 465#define FAN_MIN 1
442static ssize_t 466static ssize_t
@@ -1102,6 +1126,8 @@ static DEVICE_ATTR(vrm, S_IWUSR | S_IRUGO, show_vrm, store_vrm);
1102 1126
1103static struct sensor_device_attribute_2 sda_single_files[] = { 1127static struct sensor_device_attribute_2 sda_single_files[] = {
1104 SENSOR_ATTR_2(chassis, S_IWUSR | S_IRUGO, show_alarm_beep, 1128 SENSOR_ATTR_2(chassis, S_IWUSR | S_IRUGO, show_alarm_beep,
1129 store_chassis_clear_legacy, ALARM_STATUS, 30),
1130 SENSOR_ATTR_2(intrusion0_alarm, S_IWUSR | S_IRUGO, show_alarm_beep,
1105 store_chassis_clear, ALARM_STATUS, 30), 1131 store_chassis_clear, ALARM_STATUS, 30),
1106 SENSOR_ATTR_2(beep_enable, S_IWUSR | S_IRUGO, show_beep_enable, 1132 SENSOR_ATTR_2(beep_enable, S_IWUSR | S_IRUGO, show_beep_enable,
1107 store_beep_enable, NOT_USED, NOT_USED), 1133 store_beep_enable, NOT_USED, NOT_USED),
@@ -1323,7 +1349,7 @@ static ssize_t watchdog_write(struct file *filp, const char __user *buf,
1323static long watchdog_ioctl(struct file *filp, unsigned int cmd, 1349static long watchdog_ioctl(struct file *filp, unsigned int cmd,
1324 unsigned long arg) 1350 unsigned long arg)
1325{ 1351{
1326 static struct watchdog_info ident = { 1352 struct watchdog_info ident = {
1327 .options = WDIOF_KEEPALIVEPING | 1353 .options = WDIOF_KEEPALIVEPING |
1328 WDIOF_SETTIMEOUT | 1354 WDIOF_SETTIMEOUT |
1329 WDIOF_CARDRESET, 1355 WDIOF_CARDRESET,
@@ -1333,7 +1359,6 @@ static long watchdog_ioctl(struct file *filp, unsigned int cmd,
1333 int val, ret = 0; 1359 int val, ret = 0;
1334 struct w83793_data *data = filp->private_data; 1360 struct w83793_data *data = filp->private_data;
1335 1361
1336 mutex_lock(&watchdog_mutex);
1337 switch (cmd) { 1362 switch (cmd) {
1338 case WDIOC_GETSUPPORT: 1363 case WDIOC_GETSUPPORT:
1339 if (!nowayout) 1364 if (!nowayout)
@@ -1387,7 +1412,6 @@ static long watchdog_ioctl(struct file *filp, unsigned int cmd,
1387 default: 1412 default:
1388 ret = -ENOTTY; 1413 ret = -ENOTTY;
1389 } 1414 }
1390 mutex_unlock(&watchdog_mutex);
1391 return ret; 1415 return ret;
1392} 1416}
1393 1417
diff --git a/drivers/hwmon/w83795.c b/drivers/hwmon/w83795.c
index cdbc7448491e..845232d7f611 100644
--- a/drivers/hwmon/w83795.c
+++ b/drivers/hwmon/w83795.c
@@ -458,6 +458,7 @@ static void w83795_update_limits(struct i2c_client *client)
458{ 458{
459 struct w83795_data *data = i2c_get_clientdata(client); 459 struct w83795_data *data = i2c_get_clientdata(client);
460 int i, limit; 460 int i, limit;
461 u8 lsb;
461 462
462 /* Read the voltage limits */ 463 /* Read the voltage limits */
463 for (i = 0; i < ARRAY_SIZE(data->in); i++) { 464 for (i = 0; i < ARRAY_SIZE(data->in); i++) {
@@ -479,9 +480,8 @@ static void w83795_update_limits(struct i2c_client *client)
479 } 480 }
480 481
481 /* Read the fan limits */ 482 /* Read the fan limits */
483 lsb = 0; /* Silent false gcc warning */
482 for (i = 0; i < ARRAY_SIZE(data->fan); i++) { 484 for (i = 0; i < ARRAY_SIZE(data->fan); i++) {
483 u8 lsb;
484
485 /* Each register contains LSB for 2 fans, but we want to 485 /* Each register contains LSB for 2 fans, but we want to
486 * read it only once to save time */ 486 * read it only once to save time */
487 if ((i & 1) == 0 && (data->has_fan & (3 << i))) 487 if ((i & 1) == 0 && (data->has_fan & (3 << i)))
diff --git a/drivers/i2c/busses/i2c-nomadik.c b/drivers/i2c/busses/i2c-nomadik.c
index c9fffd0389fe..2bd3469b3071 100644
--- a/drivers/i2c/busses/i2c-nomadik.c
+++ b/drivers/i2c/busses/i2c-nomadik.c
@@ -434,7 +434,7 @@ static int read_i2c(struct nmk_i2c_dev *dev)
434 } 434 }
435 435
436 if (timeout == 0) { 436 if (timeout == 0) {
437 /* controler has timedout, re-init the h/w */ 437 /* controller has timedout, re-init the h/w */
438 dev_err(&dev->pdev->dev, "controller timed out, re-init h/w\n"); 438 dev_err(&dev->pdev->dev, "controller timed out, re-init h/w\n");
439 (void) init_hw(dev); 439 (void) init_hw(dev);
440 status = -ETIMEDOUT; 440 status = -ETIMEDOUT;
@@ -498,7 +498,7 @@ static int write_i2c(struct nmk_i2c_dev *dev)
498 } 498 }
499 499
500 if (timeout == 0) { 500 if (timeout == 0) {
501 /* controler has timedout, re-init the h/w */ 501 /* controller has timedout, re-init the h/w */
502 dev_err(&dev->pdev->dev, "controller timed out, re-init h/w\n"); 502 dev_err(&dev->pdev->dev, "controller timed out, re-init h/w\n");
503 (void) init_hw(dev); 503 (void) init_hw(dev);
504 status = -ETIMEDOUT; 504 status = -ETIMEDOUT;
diff --git a/drivers/infiniband/hw/cxgb3/cxio_wr.h b/drivers/infiniband/hw/cxgb3/cxio_wr.h
index 4bb997aa39d0..83d2e19d31ae 100644
--- a/drivers/infiniband/hw/cxgb3/cxio_wr.h
+++ b/drivers/infiniband/hw/cxgb3/cxio_wr.h
@@ -689,7 +689,7 @@ struct t3_swrq {
689 * A T3 WQ implements both the SQ and RQ. 689 * A T3 WQ implements both the SQ and RQ.
690 */ 690 */
691struct t3_wq { 691struct t3_wq {
692 union t3_wr *queue; /* DMA accessable memory */ 692 union t3_wr *queue; /* DMA accessible memory */
693 dma_addr_t dma_addr; /* DMA address for HW */ 693 dma_addr_t dma_addr; /* DMA address for HW */
694 DEFINE_DMA_UNMAP_ADDR(mapping); /* unmap kruft */ 694 DEFINE_DMA_UNMAP_ADDR(mapping); /* unmap kruft */
695 u32 error; /* 1 once we go to ERROR */ 695 u32 error; /* 1 once we go to ERROR */
diff --git a/drivers/infiniband/hw/cxgb4/iw_cxgb4.h b/drivers/infiniband/hw/cxgb4/iw_cxgb4.h
index cc600c2dd0b3..2fe19ec9ba60 100644
--- a/drivers/infiniband/hw/cxgb4/iw_cxgb4.h
+++ b/drivers/infiniband/hw/cxgb4/iw_cxgb4.h
@@ -46,7 +46,6 @@
46#include <linux/timer.h> 46#include <linux/timer.h>
47#include <linux/io.h> 47#include <linux/io.h>
48#include <linux/kfifo.h> 48#include <linux/kfifo.h>
49#include <linux/mutex.h>
50 49
51#include <asm/byteorder.h> 50#include <asm/byteorder.h>
52 51
diff --git a/drivers/infiniband/hw/qib/qib_iba7322.c b/drivers/infiniband/hw/qib/qib_iba7322.c
index dbbb0e85afe4..abd409d592ef 100644
--- a/drivers/infiniband/hw/qib/qib_iba7322.c
+++ b/drivers/infiniband/hw/qib/qib_iba7322.c
@@ -332,7 +332,7 @@ MODULE_PARM_DESC(txselect, \
332#define krp_serdesctrl KREG_IBPORT_IDX(IBSerdesCtrl) 332#define krp_serdesctrl KREG_IBPORT_IDX(IBSerdesCtrl)
333 333
334/* 334/*
335 * Per-context kernel registers. Acess only with qib_read_kreg_ctxt() 335 * Per-context kernel registers. Access only with qib_read_kreg_ctxt()
336 * or qib_write_kreg_ctxt() 336 * or qib_write_kreg_ctxt()
337 */ 337 */
338#define krc_rcvhdraddr KREG_IDX(RcvHdrAddr0) 338#define krc_rcvhdraddr KREG_IDX(RcvHdrAddr0)
diff --git a/drivers/input/joystick/Kconfig b/drivers/input/joystick/Kconfig
index 5b596165b571..56eb471b5576 100644
--- a/drivers/input/joystick/Kconfig
+++ b/drivers/input/joystick/Kconfig
@@ -255,6 +255,16 @@ config JOYSTICK_AMIGA
255 To compile this driver as a module, choose M here: the 255 To compile this driver as a module, choose M here: the
256 module will be called amijoy. 256 module will be called amijoy.
257 257
258config JOYSTICK_AS5011
259 tristate "Austria Microsystem AS5011 joystick"
260 depends on I2C
261 help
262 Say Y here if you have an AS5011 digital joystick connected to your
263 system.
264
265 To compile this driver as a module, choose M here: the
266 module will be called as5011.
267
258config JOYSTICK_JOYDUMP 268config JOYSTICK_JOYDUMP
259 tristate "Gameport data dumper" 269 tristate "Gameport data dumper"
260 select GAMEPORT 270 select GAMEPORT
diff --git a/drivers/input/joystick/Makefile b/drivers/input/joystick/Makefile
index f3a8cbe2abb6..92dc0de9dfed 100644
--- a/drivers/input/joystick/Makefile
+++ b/drivers/input/joystick/Makefile
@@ -7,6 +7,7 @@
7obj-$(CONFIG_JOYSTICK_A3D) += a3d.o 7obj-$(CONFIG_JOYSTICK_A3D) += a3d.o
8obj-$(CONFIG_JOYSTICK_ADI) += adi.o 8obj-$(CONFIG_JOYSTICK_ADI) += adi.o
9obj-$(CONFIG_JOYSTICK_AMIGA) += amijoy.o 9obj-$(CONFIG_JOYSTICK_AMIGA) += amijoy.o
10obj-$(CONFIG_JOYSTICK_AS5011) += as5011.o
10obj-$(CONFIG_JOYSTICK_ANALOG) += analog.o 11obj-$(CONFIG_JOYSTICK_ANALOG) += analog.o
11obj-$(CONFIG_JOYSTICK_COBRA) += cobra.o 12obj-$(CONFIG_JOYSTICK_COBRA) += cobra.o
12obj-$(CONFIG_JOYSTICK_DB9) += db9.o 13obj-$(CONFIG_JOYSTICK_DB9) += db9.o
diff --git a/drivers/input/joystick/as5011.c b/drivers/input/joystick/as5011.c
new file mode 100644
index 000000000000..f6732b57ca07
--- /dev/null
+++ b/drivers/input/joystick/as5011.c
@@ -0,0 +1,367 @@
1/*
2 * Copyright (c) 2010, 2011 Fabien Marteau <fabien.marteau@armadeus.com>
3 * Sponsored by ARMadeus Systems
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 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 *
19 * Driver for Austria Microsystems joysticks AS5011
20 *
21 * TODO:
22 * - Power on the chip when open() and power down when close()
23 * - Manage power mode
24 */
25
26#include <linux/i2c.h>
27#include <linux/interrupt.h>
28#include <linux/input.h>
29#include <linux/gpio.h>
30#include <linux/delay.h>
31#include <linux/input/as5011.h>
32#include <linux/slab.h>
33
34#define DRIVER_DESC "Driver for Austria Microsystems AS5011 joystick"
35#define MODULE_DEVICE_ALIAS "as5011"
36
37MODULE_AUTHOR("Fabien Marteau <fabien.marteau@armadeus.com>");
38MODULE_DESCRIPTION(DRIVER_DESC);
39MODULE_LICENSE("GPL");
40
41/* registers */
42#define AS5011_CTRL1 0x76
43#define AS5011_CTRL2 0x75
44#define AS5011_XP 0x43
45#define AS5011_XN 0x44
46#define AS5011_YP 0x53
47#define AS5011_YN 0x54
48#define AS5011_X_REG 0x41
49#define AS5011_Y_REG 0x42
50#define AS5011_X_RES_INT 0x51
51#define AS5011_Y_RES_INT 0x52
52
53/* CTRL1 bits */
54#define AS5011_CTRL1_LP_PULSED 0x80
55#define AS5011_CTRL1_LP_ACTIVE 0x40
56#define AS5011_CTRL1_LP_CONTINUE 0x20
57#define AS5011_CTRL1_INT_WUP_EN 0x10
58#define AS5011_CTRL1_INT_ACT_EN 0x08
59#define AS5011_CTRL1_EXT_CLK_EN 0x04
60#define AS5011_CTRL1_SOFT_RST 0x02
61#define AS5011_CTRL1_DATA_VALID 0x01
62
63/* CTRL2 bits */
64#define AS5011_CTRL2_EXT_SAMPLE_EN 0x08
65#define AS5011_CTRL2_RC_BIAS_ON 0x04
66#define AS5011_CTRL2_INV_SPINNING 0x02
67
68#define AS5011_MAX_AXIS 80
69#define AS5011_MIN_AXIS (-80)
70#define AS5011_FUZZ 8
71#define AS5011_FLAT 40
72
73struct as5011_device {
74 struct input_dev *input_dev;
75 struct i2c_client *i2c_client;
76 unsigned int button_gpio;
77 unsigned int button_irq;
78 unsigned int axis_irq;
79};
80
81static int as5011_i2c_write(struct i2c_client *client,
82 uint8_t aregaddr,
83 uint8_t avalue)
84{
85 uint8_t data[2] = { aregaddr, avalue };
86 struct i2c_msg msg = {
87 client->addr, I2C_M_IGNORE_NAK, 2, (uint8_t *)data
88 };
89 int error;
90
91 error = i2c_transfer(client->adapter, &msg, 1);
92 return error < 0 ? error : 0;
93}
94
95static int as5011_i2c_read(struct i2c_client *client,
96 uint8_t aregaddr, signed char *value)
97{
98 uint8_t data[2] = { aregaddr };
99 struct i2c_msg msg_set[2] = {
100 { client->addr, I2C_M_REV_DIR_ADDR, 1, (uint8_t *)data },
101 { client->addr, I2C_M_RD | I2C_M_NOSTART, 1, (uint8_t *)data }
102 };
103 int error;
104
105 error = i2c_transfer(client->adapter, msg_set, 2);
106 if (error < 0)
107 return error;
108
109 *value = data[0] & 0x80 ? -1 * (1 + ~data[0]) : data[0];
110 return 0;
111}
112
113static irqreturn_t as5011_button_interrupt(int irq, void *dev_id)
114{
115 struct as5011_device *as5011 = dev_id;
116 int val = gpio_get_value_cansleep(as5011->button_gpio);
117
118 input_report_key(as5011->input_dev, BTN_JOYSTICK, !val);
119 input_sync(as5011->input_dev);
120
121 return IRQ_HANDLED;
122}
123
124static irqreturn_t as5011_axis_interrupt(int irq, void *dev_id)
125{
126 struct as5011_device *as5011 = dev_id;
127 int error;
128 signed char x, y;
129
130 error = as5011_i2c_read(as5011->i2c_client, AS5011_X_RES_INT, &x);
131 if (error < 0)
132 goto out;
133
134 error = as5011_i2c_read(as5011->i2c_client, AS5011_Y_RES_INT, &y);
135 if (error < 0)
136 goto out;
137
138 input_report_abs(as5011->input_dev, ABS_X, x);
139 input_report_abs(as5011->input_dev, ABS_Y, y);
140 input_sync(as5011->input_dev);
141
142out:
143 return IRQ_HANDLED;
144}
145
146static int __devinit as5011_configure_chip(struct as5011_device *as5011,
147 const struct as5011_platform_data *plat_dat)
148{
149 struct i2c_client *client = as5011->i2c_client;
150 int error;
151 signed char value;
152
153 /* chip soft reset */
154 error = as5011_i2c_write(client, AS5011_CTRL1,
155 AS5011_CTRL1_SOFT_RST);
156 if (error < 0) {
157 dev_err(&client->dev, "Soft reset failed\n");
158 return error;
159 }
160
161 mdelay(10);
162
163 error = as5011_i2c_write(client, AS5011_CTRL1,
164 AS5011_CTRL1_LP_PULSED |
165 AS5011_CTRL1_LP_ACTIVE |
166 AS5011_CTRL1_INT_ACT_EN);
167 if (error < 0) {
168 dev_err(&client->dev, "Power config failed\n");
169 return error;
170 }
171
172 error = as5011_i2c_write(client, AS5011_CTRL2,
173 AS5011_CTRL2_INV_SPINNING);
174 if (error < 0) {
175 dev_err(&client->dev, "Can't invert spinning\n");
176 return error;
177 }
178
179 /* write threshold */
180 error = as5011_i2c_write(client, AS5011_XP, plat_dat->xp);
181 if (error < 0) {
182 dev_err(&client->dev, "Can't write threshold\n");
183 return error;
184 }
185
186 error = as5011_i2c_write(client, AS5011_XN, plat_dat->xn);
187 if (error < 0) {
188 dev_err(&client->dev, "Can't write threshold\n");
189 return error;
190 }
191
192 error = as5011_i2c_write(client, AS5011_YP, plat_dat->yp);
193 if (error < 0) {
194 dev_err(&client->dev, "Can't write threshold\n");
195 return error;
196 }
197
198 error = as5011_i2c_write(client, AS5011_YN, plat_dat->yn);
199 if (error < 0) {
200 dev_err(&client->dev, "Can't write threshold\n");
201 return error;
202 }
203
204 /* to free irq gpio in chip */
205 error = as5011_i2c_read(client, AS5011_X_RES_INT, &value);
206 if (error < 0) {
207 dev_err(&client->dev, "Can't read i2c X resolution value\n");
208 return error;
209 }
210
211 return 0;
212}
213
214static int __devinit as5011_probe(struct i2c_client *client,
215 const struct i2c_device_id *id)
216{
217 const struct as5011_platform_data *plat_data;
218 struct as5011_device *as5011;
219 struct input_dev *input_dev;
220 int irq;
221 int error;
222
223 plat_data = client->dev.platform_data;
224 if (!plat_data)
225 return -EINVAL;
226
227 if (!plat_data->axis_irq) {
228 dev_err(&client->dev, "No axis IRQ?\n");
229 return -EINVAL;
230 }
231
232 if (!i2c_check_functionality(client->adapter,
233 I2C_FUNC_PROTOCOL_MANGLING)) {
234 dev_err(&client->dev,
235 "need i2c bus that supports protocol mangling\n");
236 return -ENODEV;
237 }
238
239 as5011 = kmalloc(sizeof(struct as5011_device), GFP_KERNEL);
240 input_dev = input_allocate_device();
241 if (!as5011 || !input_dev) {
242 dev_err(&client->dev,
243 "Can't allocate memory for device structure\n");
244 error = -ENOMEM;
245 goto err_free_mem;
246 }
247
248 as5011->i2c_client = client;
249 as5011->input_dev = input_dev;
250 as5011->button_gpio = plat_data->button_gpio;
251 as5011->axis_irq = plat_data->axis_irq;
252
253 input_dev->name = "Austria Microsystem as5011 joystick";
254 input_dev->id.bustype = BUS_I2C;
255 input_dev->dev.parent = &client->dev;
256
257 __set_bit(EV_KEY, input_dev->evbit);
258 __set_bit(EV_ABS, input_dev->evbit);
259 __set_bit(BTN_JOYSTICK, input_dev->keybit);
260
261 input_set_abs_params(input_dev, ABS_X,
262 AS5011_MIN_AXIS, AS5011_MAX_AXIS, AS5011_FUZZ, AS5011_FLAT);
263 input_set_abs_params(as5011->input_dev, ABS_Y,
264 AS5011_MIN_AXIS, AS5011_MAX_AXIS, AS5011_FUZZ, AS5011_FLAT);
265
266 error = gpio_request(as5011->button_gpio, "AS5011 button");
267 if (error < 0) {
268 dev_err(&client->dev, "Failed to request button gpio\n");
269 goto err_free_mem;
270 }
271
272 irq = gpio_to_irq(as5011->button_gpio);
273 if (irq < 0) {
274 dev_err(&client->dev,
275 "Failed to get irq number for button gpio\n");
276 goto err_free_button_gpio;
277 }
278
279 as5011->button_irq = irq;
280
281 error = request_threaded_irq(as5011->button_irq,
282 NULL, as5011_button_interrupt,
283 IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING,
284 "as5011_button", as5011);
285 if (error < 0) {
286 dev_err(&client->dev,
287 "Can't allocate button irq %d\n", as5011->button_irq);
288 goto err_free_button_gpio;
289 }
290
291 error = as5011_configure_chip(as5011, plat_data);
292 if (error)
293 goto err_free_button_irq;
294
295 error = request_threaded_irq(as5011->axis_irq, NULL,
296 as5011_axis_interrupt,
297 plat_data->axis_irqflags,
298 "as5011_joystick", as5011);
299 if (error) {
300 dev_err(&client->dev,
301 "Can't allocate axis irq %d\n", plat_data->axis_irq);
302 goto err_free_button_irq;
303 }
304
305 error = input_register_device(as5011->input_dev);
306 if (error) {
307 dev_err(&client->dev, "Failed to register input device\n");
308 goto err_free_axis_irq;
309 }
310
311 i2c_set_clientdata(client, as5011);
312
313 return 0;
314
315err_free_axis_irq:
316 free_irq(as5011->axis_irq, as5011);
317err_free_button_irq:
318 free_irq(as5011->button_irq, as5011);
319err_free_button_gpio:
320 gpio_free(as5011->button_gpio);
321err_free_mem:
322 input_free_device(input_dev);
323 kfree(as5011);
324
325 return error;
326}
327
328static int __devexit as5011_remove(struct i2c_client *client)
329{
330 struct as5011_device *as5011 = i2c_get_clientdata(client);
331
332 free_irq(as5011->axis_irq, as5011);
333 free_irq(as5011->button_irq, as5011);
334 gpio_free(as5011->button_gpio);
335
336 input_unregister_device(as5011->input_dev);
337 kfree(as5011);
338
339 return 0;
340}
341
342static const struct i2c_device_id as5011_id[] = {
343 { MODULE_DEVICE_ALIAS, 0 },
344 { }
345};
346MODULE_DEVICE_TABLE(i2c, as5011_id);
347
348static struct i2c_driver as5011_driver = {
349 .driver = {
350 .name = "as5011",
351 },
352 .probe = as5011_probe,
353 .remove = __devexit_p(as5011_remove),
354 .id_table = as5011_id,
355};
356
357static int __init as5011_init(void)
358{
359 return i2c_add_driver(&as5011_driver);
360}
361module_init(as5011_init);
362
363static void __exit as5011_exit(void)
364{
365 i2c_del_driver(&as5011_driver);
366}
367module_exit(as5011_exit);
diff --git a/drivers/input/keyboard/Kconfig b/drivers/input/keyboard/Kconfig
index f829998fabe6..7b3c0b8fa432 100644
--- a/drivers/input/keyboard/Kconfig
+++ b/drivers/input/keyboard/Kconfig
@@ -12,18 +12,6 @@ menuconfig INPUT_KEYBOARD
12 12
13if INPUT_KEYBOARD 13if INPUT_KEYBOARD
14 14
15config KEYBOARD_AAED2000
16 tristate "AAED-2000 keyboard"
17 depends on MACH_AAED2000
18 select INPUT_POLLDEV
19 default y
20 help
21 Say Y here to enable the keyboard on the Agilent AAED-2000
22 development board.
23
24 To compile this driver as a module, choose M here: the
25 module will be called aaed2000_kbd.
26
27config KEYBOARD_ADP5520 15config KEYBOARD_ADP5520
28 tristate "Keypad Support for ADP5520 PMIC" 16 tristate "Keypad Support for ADP5520 PMIC"
29 depends on PMIC_ADP5520 17 depends on PMIC_ADP5520
diff --git a/drivers/input/keyboard/Makefile b/drivers/input/keyboard/Makefile
index 8933e9ca938d..4e5571b72cda 100644
--- a/drivers/input/keyboard/Makefile
+++ b/drivers/input/keyboard/Makefile
@@ -4,7 +4,6 @@
4 4
5# Each configuration option enables a list of files. 5# Each configuration option enables a list of files.
6 6
7obj-$(CONFIG_KEYBOARD_AAED2000) += aaed2000_kbd.o
8obj-$(CONFIG_KEYBOARD_ADP5520) += adp5520-keys.o 7obj-$(CONFIG_KEYBOARD_ADP5520) += adp5520-keys.o
9obj-$(CONFIG_KEYBOARD_ADP5588) += adp5588-keys.o 8obj-$(CONFIG_KEYBOARD_ADP5588) += adp5588-keys.o
10obj-$(CONFIG_KEYBOARD_AMIGA) += amikbd.o 9obj-$(CONFIG_KEYBOARD_AMIGA) += amikbd.o
diff --git a/drivers/input/keyboard/aaed2000_kbd.c b/drivers/input/keyboard/aaed2000_kbd.c
deleted file mode 100644
index 18222a689a03..000000000000
--- a/drivers/input/keyboard/aaed2000_kbd.c
+++ /dev/null
@@ -1,186 +0,0 @@
1/*
2 * Keyboard driver for the AAED-2000 dev board
3 *
4 * Copyright (c) 2006 Nicolas Bellido Y Ortega
5 *
6 * Based on corgikbd.c
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation.
11 *
12 */
13
14#include <linux/delay.h>
15#include <linux/platform_device.h>
16#include <linux/init.h>
17#include <linux/input-polldev.h>
18#include <linux/interrupt.h>
19#include <linux/jiffies.h>
20#include <linux/module.h>
21#include <linux/slab.h>
22
23#include <mach/hardware.h>
24#include <mach/aaed2000.h>
25
26#define KB_ROWS 12
27#define KB_COLS 8
28#define KB_ROWMASK(r) (1 << (r))
29#define SCANCODE(r,c) (((c) * KB_ROWS) + (r))
30#define NR_SCANCODES (KB_COLS * KB_ROWS)
31
32#define SCAN_INTERVAL (50) /* ms */
33#define KB_ACTIVATE_DELAY (20) /* us */
34
35static unsigned char aaedkbd_keycode[NR_SCANCODES] = {
36 KEY_9, KEY_0, KEY_MINUS, KEY_EQUAL, KEY_BACKSPACE, 0, KEY_SPACE, KEY_KP6, 0, KEY_KPDOT, 0, 0,
37 KEY_K, KEY_M, KEY_O, KEY_DOT, KEY_SLASH, 0, KEY_F, 0, 0, 0, KEY_LEFTSHIFT, 0,
38 KEY_I, KEY_P, KEY_LEFTBRACE, KEY_RIGHTBRACE, KEY_BACKSLASH, 0, 0, 0, 0, 0, KEY_RIGHTSHIFT, 0,
39 KEY_8, KEY_L, KEY_SEMICOLON, KEY_APOSTROPHE, KEY_ENTER, 0, 0, 0, 0, 0, 0, 0,
40 KEY_J, KEY_H, KEY_B, KEY_KP8, KEY_KP4, 0, KEY_C, KEY_D, KEY_S, KEY_A, 0, KEY_CAPSLOCK,
41 KEY_Y, KEY_U, KEY_N, KEY_T, 0, 0, KEY_R, KEY_E, KEY_W, KEY_Q, 0, KEY_TAB,
42 KEY_7, KEY_6, KEY_G, 0, KEY_5, 0, KEY_4, KEY_3, KEY_2, KEY_1, 0, KEY_GRAVE,
43 0, 0, KEY_COMMA, 0, KEY_KP2, 0, KEY_V, KEY_LEFTALT, KEY_X, KEY_Z, 0, KEY_LEFTCTRL
44};
45
46struct aaedkbd {
47 unsigned char keycode[ARRAY_SIZE(aaedkbd_keycode)];
48 struct input_polled_dev *poll_dev;
49 int kbdscan_state[KB_COLS];
50 int kbdscan_count[KB_COLS];
51};
52
53#define KBDSCAN_STABLE_COUNT 2
54
55static void aaedkbd_report_col(struct aaedkbd *aaedkbd,
56 unsigned int col, unsigned int rowd)
57{
58 unsigned int scancode, pressed;
59 unsigned int row;
60
61 for (row = 0; row < KB_ROWS; row++) {
62 scancode = SCANCODE(row, col);
63 pressed = rowd & KB_ROWMASK(row);
64
65 input_report_key(aaedkbd->poll_dev->input,
66 aaedkbd->keycode[scancode], pressed);
67 }
68}
69
70/* Scan the hardware keyboard and push any changes up through the input layer */
71static void aaedkbd_poll(struct input_polled_dev *dev)
72{
73 struct aaedkbd *aaedkbd = dev->private;
74 unsigned int col, rowd;
75
76 col = 0;
77 do {
78 AAEC_GPIO_KSCAN = col + 8;
79 udelay(KB_ACTIVATE_DELAY);
80 rowd = AAED_EXT_GPIO & AAED_EGPIO_KBD_SCAN;
81
82 if (rowd != aaedkbd->kbdscan_state[col]) {
83 aaedkbd->kbdscan_count[col] = 0;
84 aaedkbd->kbdscan_state[col] = rowd;
85 } else if (++aaedkbd->kbdscan_count[col] >= KBDSCAN_STABLE_COUNT) {
86 aaedkbd_report_col(aaedkbd, col, rowd);
87 col++;
88 }
89 } while (col < KB_COLS);
90
91 AAEC_GPIO_KSCAN = 0x07;
92 input_sync(dev->input);
93}
94
95static int __devinit aaedkbd_probe(struct platform_device *pdev)
96{
97 struct aaedkbd *aaedkbd;
98 struct input_polled_dev *poll_dev;
99 struct input_dev *input_dev;
100 int i;
101 int error;
102
103 aaedkbd = kzalloc(sizeof(struct aaedkbd), GFP_KERNEL);
104 poll_dev = input_allocate_polled_device();
105 if (!aaedkbd || !poll_dev) {
106 error = -ENOMEM;
107 goto fail;
108 }
109
110 platform_set_drvdata(pdev, aaedkbd);
111
112 aaedkbd->poll_dev = poll_dev;
113 memcpy(aaedkbd->keycode, aaedkbd_keycode, sizeof(aaedkbd->keycode));
114
115 poll_dev->private = aaedkbd;
116 poll_dev->poll = aaedkbd_poll;
117 poll_dev->poll_interval = SCAN_INTERVAL;
118
119 input_dev = poll_dev->input;
120 input_dev->name = "AAED-2000 Keyboard";
121 input_dev->phys = "aaedkbd/input0";
122 input_dev->id.bustype = BUS_HOST;
123 input_dev->id.vendor = 0x0001;
124 input_dev->id.product = 0x0001;
125 input_dev->id.version = 0x0100;
126 input_dev->dev.parent = &pdev->dev;
127
128 input_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_REP);
129 input_dev->keycode = aaedkbd->keycode;
130 input_dev->keycodesize = sizeof(unsigned char);
131 input_dev->keycodemax = ARRAY_SIZE(aaedkbd_keycode);
132
133 for (i = 0; i < ARRAY_SIZE(aaedkbd_keycode); i++)
134 set_bit(aaedkbd->keycode[i], input_dev->keybit);
135 clear_bit(0, input_dev->keybit);
136
137 error = input_register_polled_device(aaedkbd->poll_dev);
138 if (error)
139 goto fail;
140
141 return 0;
142
143 fail: kfree(aaedkbd);
144 input_free_polled_device(poll_dev);
145 return error;
146}
147
148static int __devexit aaedkbd_remove(struct platform_device *pdev)
149{
150 struct aaedkbd *aaedkbd = platform_get_drvdata(pdev);
151
152 input_unregister_polled_device(aaedkbd->poll_dev);
153 input_free_polled_device(aaedkbd->poll_dev);
154 kfree(aaedkbd);
155
156 return 0;
157}
158
159/* work with hotplug and coldplug */
160MODULE_ALIAS("platform:aaed2000-keyboard");
161
162static struct platform_driver aaedkbd_driver = {
163 .probe = aaedkbd_probe,
164 .remove = __devexit_p(aaedkbd_remove),
165 .driver = {
166 .name = "aaed2000-keyboard",
167 .owner = THIS_MODULE,
168 },
169};
170
171static int __init aaedkbd_init(void)
172{
173 return platform_driver_register(&aaedkbd_driver);
174}
175
176static void __exit aaedkbd_exit(void)
177{
178 platform_driver_unregister(&aaedkbd_driver);
179}
180
181module_init(aaedkbd_init);
182module_exit(aaedkbd_exit);
183
184MODULE_AUTHOR("Nicolas Bellido Y Ortega");
185MODULE_DESCRIPTION("AAED-2000 Keyboard Driver");
186MODULE_LICENSE("GPL v2");
diff --git a/drivers/input/serio/Kconfig b/drivers/input/serio/Kconfig
index bcb1fdedb595..307eef77a172 100644
--- a/drivers/input/serio/Kconfig
+++ b/drivers/input/serio/Kconfig
@@ -229,7 +229,7 @@ config SERIO_PS2MULT
229 tristate "TQC PS/2 multiplexer" 229 tristate "TQC PS/2 multiplexer"
230 help 230 help
231 Say Y here if you have the PS/2 line multiplexer like the one 231 Say Y here if you have the PS/2 line multiplexer like the one
232 present on TQC boads. 232 present on TQC boards.
233 233
234 To compile this driver as a module, choose M here: the 234 To compile this driver as a module, choose M here: the
235 module will be called ps2mult. 235 module will be called ps2mult.
diff --git a/drivers/input/serio/i8042-x86ia64io.h b/drivers/input/serio/i8042-x86ia64io.h
index 5ae0fc4578fe..bb9f5d31f0d0 100644
--- a/drivers/input/serio/i8042-x86ia64io.h
+++ b/drivers/input/serio/i8042-x86ia64io.h
@@ -424,6 +424,13 @@ static const struct dmi_system_id __initconst i8042_dmi_nomux_table[] = {
424 DMI_MATCH(DMI_PRODUCT_VERSION, "0100"), 424 DMI_MATCH(DMI_PRODUCT_VERSION, "0100"),
425 }, 425 },
426 }, 426 },
427 {
428 /* Dell Vostro V13 */
429 .matches = {
430 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
431 DMI_MATCH(DMI_PRODUCT_NAME, "Vostro V13"),
432 },
433 },
427 { } 434 { }
428}; 435};
429 436
@@ -545,6 +552,17 @@ static const struct dmi_system_id __initconst i8042_dmi_laptop_table[] = {
545}; 552};
546#endif 553#endif
547 554
555static const struct dmi_system_id __initconst i8042_dmi_notimeout_table[] = {
556 {
557 /* Dell Vostro V13 */
558 .matches = {
559 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
560 DMI_MATCH(DMI_PRODUCT_NAME, "Vostro V13"),
561 },
562 },
563 { }
564};
565
548/* 566/*
549 * Some Wistron based laptops need us to explicitly enable the 'Dritek 567 * Some Wistron based laptops need us to explicitly enable the 'Dritek
550 * keyboard extension' to make their extra keys start generating scancodes. 568 * keyboard extension' to make their extra keys start generating scancodes.
@@ -896,6 +914,9 @@ static int __init i8042_platform_init(void)
896 if (dmi_check_system(i8042_dmi_nomux_table)) 914 if (dmi_check_system(i8042_dmi_nomux_table))
897 i8042_nomux = true; 915 i8042_nomux = true;
898 916
917 if (dmi_check_system(i8042_dmi_notimeout_table))
918 i8042_notimeout = true;
919
899 if (dmi_check_system(i8042_dmi_dritek_table)) 920 if (dmi_check_system(i8042_dmi_dritek_table))
900 i8042_dritek = true; 921 i8042_dritek = true;
901#endif /* CONFIG_X86 */ 922#endif /* CONFIG_X86 */
diff --git a/drivers/input/serio/i8042.c b/drivers/input/serio/i8042.c
index c04ff00a3663..ac4c93689ab9 100644
--- a/drivers/input/serio/i8042.c
+++ b/drivers/input/serio/i8042.c
@@ -63,6 +63,10 @@ static bool i8042_noloop;
63module_param_named(noloop, i8042_noloop, bool, 0); 63module_param_named(noloop, i8042_noloop, bool, 0);
64MODULE_PARM_DESC(noloop, "Disable the AUX Loopback command while probing for the AUX port"); 64MODULE_PARM_DESC(noloop, "Disable the AUX Loopback command while probing for the AUX port");
65 65
66static bool i8042_notimeout;
67module_param_named(notimeout, i8042_notimeout, bool, 0);
68MODULE_PARM_DESC(notimeout, "Ignore timeouts signalled by i8042");
69
66#ifdef CONFIG_X86 70#ifdef CONFIG_X86
67static bool i8042_dritek; 71static bool i8042_dritek;
68module_param_named(dritek, i8042_dritek, bool, 0); 72module_param_named(dritek, i8042_dritek, bool, 0);
@@ -504,7 +508,7 @@ static irqreturn_t i8042_interrupt(int irq, void *dev_id)
504 } else { 508 } else {
505 509
506 dfl = ((str & I8042_STR_PARITY) ? SERIO_PARITY : 0) | 510 dfl = ((str & I8042_STR_PARITY) ? SERIO_PARITY : 0) |
507 ((str & I8042_STR_TIMEOUT) ? SERIO_TIMEOUT : 0); 511 ((str & I8042_STR_TIMEOUT && !i8042_notimeout) ? SERIO_TIMEOUT : 0);
508 512
509 port_no = (str & I8042_STR_AUXDATA) ? 513 port_no = (str & I8042_STR_AUXDATA) ?
510 I8042_AUX_PORT_NO : I8042_KBD_PORT_NO; 514 I8042_AUX_PORT_NO : I8042_KBD_PORT_NO;
diff --git a/drivers/input/touchscreen/Kconfig b/drivers/input/touchscreen/Kconfig
index 07ac77d393a4..0c9f4b158ff0 100644
--- a/drivers/input/touchscreen/Kconfig
+++ b/drivers/input/touchscreen/Kconfig
@@ -610,7 +610,7 @@ config TOUCHSCREEN_USB_ZYTRONIC
610 610
611config TOUCHSCREEN_USB_ETT_TC45USB 611config TOUCHSCREEN_USB_ETT_TC45USB
612 default y 612 default y
613 bool "ET&T USB series TC4UM/TC5UH touchscreen controler support" if EMBEDDED 613 bool "ET&T USB series TC4UM/TC5UH touchscreen controller support" if EMBEDDED
614 depends on TOUCHSCREEN_USB_COMPOSITE 614 depends on TOUCHSCREEN_USB_COMPOSITE
615 615
616config TOUCHSCREEN_USB_NEXIO 616config TOUCHSCREEN_USB_NEXIO
diff --git a/drivers/input/touchscreen/ad7879-i2c.c b/drivers/input/touchscreen/ad7879-i2c.c
index d82a38ee9a3e..4e4e58cec6c8 100644
--- a/drivers/input/touchscreen/ad7879-i2c.c
+++ b/drivers/input/touchscreen/ad7879-i2c.c
@@ -10,14 +10,16 @@
10#include <linux/i2c.h> 10#include <linux/i2c.h>
11#include <linux/module.h> 11#include <linux/module.h>
12#include <linux/types.h> 12#include <linux/types.h>
13#include <linux/pm.h>
13 14
14#include "ad7879.h" 15#include "ad7879.h"
15 16
16#define AD7879_DEVID 0x79 /* AD7879-1/AD7889-1 */ 17#define AD7879_DEVID 0x79 /* AD7879-1/AD7889-1 */
17 18
18#ifdef CONFIG_PM 19#ifdef CONFIG_PM
19static int ad7879_i2c_suspend(struct i2c_client *client, pm_message_t message) 20static int ad7879_i2c_suspend(struct device *dev)
20{ 21{
22 struct i2c_client *client = to_i2c_client(dev);
21 struct ad7879 *ts = i2c_get_clientdata(client); 23 struct ad7879 *ts = i2c_get_clientdata(client);
22 24
23 ad7879_suspend(ts); 25 ad7879_suspend(ts);
@@ -25,17 +27,17 @@ static int ad7879_i2c_suspend(struct i2c_client *client, pm_message_t message)
25 return 0; 27 return 0;
26} 28}
27 29
28static int ad7879_i2c_resume(struct i2c_client *client) 30static int ad7879_i2c_resume(struct device *dev)
29{ 31{
32 struct i2c_client *client = to_i2c_client(dev);
30 struct ad7879 *ts = i2c_get_clientdata(client); 33 struct ad7879 *ts = i2c_get_clientdata(client);
31 34
32 ad7879_resume(ts); 35 ad7879_resume(ts);
33 36
34 return 0; 37 return 0;
35} 38}
36#else 39
37# define ad7879_i2c_suspend NULL 40static SIMPLE_DEV_PM_OPS(ad7879_i2c_pm, ad7879_i2c_suspend, ad7879_i2c_resume);
38# define ad7879_i2c_resume NULL
39#endif 41#endif
40 42
41/* All registers are word-sized. 43/* All registers are word-sized.
@@ -117,11 +119,12 @@ static struct i2c_driver ad7879_i2c_driver = {
117 .driver = { 119 .driver = {
118 .name = "ad7879", 120 .name = "ad7879",
119 .owner = THIS_MODULE, 121 .owner = THIS_MODULE,
122#ifdef CONFIG_PM
123 .pm = &ad7879_i2c_pm,
124#endif
120 }, 125 },
121 .probe = ad7879_i2c_probe, 126 .probe = ad7879_i2c_probe,
122 .remove = __devexit_p(ad7879_i2c_remove), 127 .remove = __devexit_p(ad7879_i2c_remove),
123 .suspend = ad7879_i2c_suspend,
124 .resume = ad7879_i2c_resume,
125 .id_table = ad7879_id, 128 .id_table = ad7879_id,
126}; 129};
127 130
diff --git a/drivers/input/touchscreen/cy8ctmg110_ts.c b/drivers/input/touchscreen/cy8ctmg110_ts.c
index d0c3a7229adf..a93c5c26ab3f 100644
--- a/drivers/input/touchscreen/cy8ctmg110_ts.c
+++ b/drivers/input/touchscreen/cy8ctmg110_ts.c
@@ -280,8 +280,9 @@ err_free_mem:
280} 280}
281 281
282#ifdef CONFIG_PM 282#ifdef CONFIG_PM
283static int cy8ctmg110_suspend(struct i2c_client *client, pm_message_t mesg) 283static int cy8ctmg110_suspend(struct device *dev)
284{ 284{
285 struct i2c_client *client = to_i2c_client(dev);
285 struct cy8ctmg110 *ts = i2c_get_clientdata(client); 286 struct cy8ctmg110 *ts = i2c_get_clientdata(client);
286 287
287 if (device_may_wakeup(&client->dev)) 288 if (device_may_wakeup(&client->dev))
@@ -293,8 +294,9 @@ static int cy8ctmg110_suspend(struct i2c_client *client, pm_message_t mesg)
293 return 0; 294 return 0;
294} 295}
295 296
296static int cy8ctmg110_resume(struct i2c_client *client) 297static int cy8ctmg110_resume(struct device *dev)
297{ 298{
299 struct i2c_client *client = to_i2c_client(dev);
298 struct cy8ctmg110 *ts = i2c_get_clientdata(client); 300 struct cy8ctmg110 *ts = i2c_get_clientdata(client);
299 301
300 if (device_may_wakeup(&client->dev)) 302 if (device_may_wakeup(&client->dev))
@@ -305,6 +307,8 @@ static int cy8ctmg110_resume(struct i2c_client *client)
305 } 307 }
306 return 0; 308 return 0;
307} 309}
310
311static SIMPLE_DEV_PM_OPS(cy8ctmg110_pm, cy8ctmg110_suspend, cy8ctmg110_resume);
308#endif 312#endif
309 313
310static int __devexit cy8ctmg110_remove(struct i2c_client *client) 314static int __devexit cy8ctmg110_remove(struct i2c_client *client)
@@ -335,14 +339,13 @@ static struct i2c_driver cy8ctmg110_driver = {
335 .driver = { 339 .driver = {
336 .owner = THIS_MODULE, 340 .owner = THIS_MODULE,
337 .name = CY8CTMG110_DRIVER_NAME, 341 .name = CY8CTMG110_DRIVER_NAME,
342#ifdef CONFIG_PM
343 .pm = &cy8ctmg110_pm,
344#endif
338 }, 345 },
339 .id_table = cy8ctmg110_idtable, 346 .id_table = cy8ctmg110_idtable,
340 .probe = cy8ctmg110_probe, 347 .probe = cy8ctmg110_probe,
341 .remove = __devexit_p(cy8ctmg110_remove), 348 .remove = __devexit_p(cy8ctmg110_remove),
342#ifdef CONFIG_PM
343 .suspend = cy8ctmg110_suspend,
344 .resume = cy8ctmg110_resume,
345#endif
346}; 349};
347 350
348static int __init cy8ctmg110_init(void) 351static int __init cy8ctmg110_init(void)
diff --git a/drivers/input/touchscreen/eeti_ts.c b/drivers/input/touchscreen/eeti_ts.c
index 7a3a916f84a8..7f8f538a9806 100644
--- a/drivers/input/touchscreen/eeti_ts.c
+++ b/drivers/input/touchscreen/eeti_ts.c
@@ -261,8 +261,9 @@ static int __devexit eeti_ts_remove(struct i2c_client *client)
261} 261}
262 262
263#ifdef CONFIG_PM 263#ifdef CONFIG_PM
264static int eeti_ts_suspend(struct i2c_client *client, pm_message_t mesg) 264static int eeti_ts_suspend(struct device *dev)
265{ 265{
266 struct i2c_client *client = to_i2c_client(dev);
266 struct eeti_ts_priv *priv = i2c_get_clientdata(client); 267 struct eeti_ts_priv *priv = i2c_get_clientdata(client);
267 struct input_dev *input_dev = priv->input; 268 struct input_dev *input_dev = priv->input;
268 269
@@ -279,8 +280,9 @@ static int eeti_ts_suspend(struct i2c_client *client, pm_message_t mesg)
279 return 0; 280 return 0;
280} 281}
281 282
282static int eeti_ts_resume(struct i2c_client *client) 283static int eeti_ts_resume(struct device *dev)
283{ 284{
285 struct i2c_client *client = to_i2c_client(dev);
284 struct eeti_ts_priv *priv = i2c_get_clientdata(client); 286 struct eeti_ts_priv *priv = i2c_get_clientdata(client);
285 struct input_dev *input_dev = priv->input; 287 struct input_dev *input_dev = priv->input;
286 288
@@ -296,9 +298,8 @@ static int eeti_ts_resume(struct i2c_client *client)
296 298
297 return 0; 299 return 0;
298} 300}
299#else 301
300#define eeti_ts_suspend NULL 302static SIMPLE_DEV_PM_OPS(eeti_ts_pm, eeti_ts_suspend, eeti_ts_resume);
301#define eeti_ts_resume NULL
302#endif 303#endif
303 304
304static const struct i2c_device_id eeti_ts_id[] = { 305static const struct i2c_device_id eeti_ts_id[] = {
@@ -310,11 +311,12 @@ MODULE_DEVICE_TABLE(i2c, eeti_ts_id);
310static struct i2c_driver eeti_ts_driver = { 311static struct i2c_driver eeti_ts_driver = {
311 .driver = { 312 .driver = {
312 .name = "eeti_ts", 313 .name = "eeti_ts",
314#ifdef CONFIG_PM
315 .pm = &eeti_ts_pm,
316#endif
313 }, 317 },
314 .probe = eeti_ts_probe, 318 .probe = eeti_ts_probe,
315 .remove = __devexit_p(eeti_ts_remove), 319 .remove = __devexit_p(eeti_ts_remove),
316 .suspend = eeti_ts_suspend,
317 .resume = eeti_ts_resume,
318 .id_table = eeti_ts_id, 320 .id_table = eeti_ts_id,
319}; 321};
320 322
diff --git a/drivers/input/touchscreen/mcs5000_ts.c b/drivers/input/touchscreen/mcs5000_ts.c
index 6ee9940aaf5b..2d84c80ceb66 100644
--- a/drivers/input/touchscreen/mcs5000_ts.c
+++ b/drivers/input/touchscreen/mcs5000_ts.c
@@ -261,25 +261,27 @@ static int __devexit mcs5000_ts_remove(struct i2c_client *client)
261} 261}
262 262
263#ifdef CONFIG_PM 263#ifdef CONFIG_PM
264static int mcs5000_ts_suspend(struct i2c_client *client, pm_message_t mesg) 264static int mcs5000_ts_suspend(struct device *dev)
265{ 265{
266 struct i2c_client *client = to_i2c_client(dev);
267
266 /* Touch sleep mode */ 268 /* Touch sleep mode */
267 i2c_smbus_write_byte_data(client, MCS5000_TS_OP_MODE, OP_MODE_SLEEP); 269 i2c_smbus_write_byte_data(client, MCS5000_TS_OP_MODE, OP_MODE_SLEEP);
268 270
269 return 0; 271 return 0;
270} 272}
271 273
272static int mcs5000_ts_resume(struct i2c_client *client) 274static int mcs5000_ts_resume(struct device *dev)
273{ 275{
276 struct i2c_client *client = to_i2c_client(dev);
274 struct mcs5000_ts_data *data = i2c_get_clientdata(client); 277 struct mcs5000_ts_data *data = i2c_get_clientdata(client);
275 278
276 mcs5000_ts_phys_init(data); 279 mcs5000_ts_phys_init(data);
277 280
278 return 0; 281 return 0;
279} 282}
280#else 283
281#define mcs5000_ts_suspend NULL 284static SIMPLE_DEV_PM_OPS(mcs5000_ts_pm, mcs5000_ts_suspend, mcs5000_ts_resume);
282#define mcs5000_ts_resume NULL
283#endif 285#endif
284 286
285static const struct i2c_device_id mcs5000_ts_id[] = { 287static const struct i2c_device_id mcs5000_ts_id[] = {
@@ -291,10 +293,11 @@ MODULE_DEVICE_TABLE(i2c, mcs5000_ts_id);
291static struct i2c_driver mcs5000_ts_driver = { 293static struct i2c_driver mcs5000_ts_driver = {
292 .probe = mcs5000_ts_probe, 294 .probe = mcs5000_ts_probe,
293 .remove = __devexit_p(mcs5000_ts_remove), 295 .remove = __devexit_p(mcs5000_ts_remove),
294 .suspend = mcs5000_ts_suspend,
295 .resume = mcs5000_ts_resume,
296 .driver = { 296 .driver = {
297 .name = "mcs5000_ts", 297 .name = "mcs5000_ts",
298#ifdef CONFIG_PM
299 .pm = &mcs5000_ts_pm,
300#endif
298 }, 301 },
299 .id_table = mcs5000_ts_id, 302 .id_table = mcs5000_ts_id,
300}; 303};
diff --git a/drivers/input/touchscreen/migor_ts.c b/drivers/input/touchscreen/migor_ts.c
index defe5dd3627c..5803bd0c1cca 100644
--- a/drivers/input/touchscreen/migor_ts.c
+++ b/drivers/input/touchscreen/migor_ts.c
@@ -23,6 +23,7 @@
23#include <linux/kernel.h> 23#include <linux/kernel.h>
24#include <linux/input.h> 24#include <linux/input.h>
25#include <linux/interrupt.h> 25#include <linux/interrupt.h>
26#include <linux/pm.h>
26#include <linux/slab.h> 27#include <linux/slab.h>
27#include <asm/io.h> 28#include <asm/io.h>
28#include <linux/i2c.h> 29#include <linux/i2c.h>
@@ -226,8 +227,9 @@ static int migor_ts_remove(struct i2c_client *client)
226 return 0; 227 return 0;
227} 228}
228 229
229static int migor_ts_suspend(struct i2c_client *client, pm_message_t mesg) 230static int migor_ts_suspend(struct device *dev)
230{ 231{
232 struct i2c_client *client = to_i2c_client(dev);
231 struct migor_ts_priv *priv = dev_get_drvdata(&client->dev); 233 struct migor_ts_priv *priv = dev_get_drvdata(&client->dev);
232 234
233 if (device_may_wakeup(&client->dev)) 235 if (device_may_wakeup(&client->dev))
@@ -236,8 +238,9 @@ static int migor_ts_suspend(struct i2c_client *client, pm_message_t mesg)
236 return 0; 238 return 0;
237} 239}
238 240
239static int migor_ts_resume(struct i2c_client *client) 241static int migor_ts_resume(struct device *dev)
240{ 242{
243 struct i2c_client *client = to_i2c_client(dev);
241 struct migor_ts_priv *priv = dev_get_drvdata(&client->dev); 244 struct migor_ts_priv *priv = dev_get_drvdata(&client->dev);
242 245
243 if (device_may_wakeup(&client->dev)) 246 if (device_may_wakeup(&client->dev))
@@ -246,6 +249,8 @@ static int migor_ts_resume(struct i2c_client *client)
246 return 0; 249 return 0;
247} 250}
248 251
252static SIMPLE_DEV_PM_OPS(migor_ts_pm, migor_ts_suspend, migor_ts_resume);
253
249static const struct i2c_device_id migor_ts_id[] = { 254static const struct i2c_device_id migor_ts_id[] = {
250 { "migor_ts", 0 }, 255 { "migor_ts", 0 },
251 { } 256 { }
@@ -255,11 +260,10 @@ MODULE_DEVICE_TABLE(i2c, migor_ts);
255static struct i2c_driver migor_ts_driver = { 260static struct i2c_driver migor_ts_driver = {
256 .driver = { 261 .driver = {
257 .name = "migor_ts", 262 .name = "migor_ts",
263 .pm = &migor_ts_pm,
258 }, 264 },
259 .probe = migor_ts_probe, 265 .probe = migor_ts_probe,
260 .remove = migor_ts_remove, 266 .remove = migor_ts_remove,
261 .suspend = migor_ts_suspend,
262 .resume = migor_ts_resume,
263 .id_table = migor_ts_id, 267 .id_table = migor_ts_id,
264}; 268};
265 269
diff --git a/drivers/input/touchscreen/wacom_w8001.c b/drivers/input/touchscreen/wacom_w8001.c
index 8ed53aded2d3..5cb8449c909d 100644
--- a/drivers/input/touchscreen/wacom_w8001.c
+++ b/drivers/input/touchscreen/wacom_w8001.c
@@ -3,6 +3,7 @@
3 * 3 *
4 * Copyright (c) 2008 Jaya Kumar 4 * Copyright (c) 2008 Jaya Kumar
5 * Copyright (c) 2010 Red Hat, Inc. 5 * Copyright (c) 2010 Red Hat, Inc.
6 * Copyright (c) 2010 - 2011 Ping Cheng, Wacom. <pingc@wacom.com>
6 * 7 *
7 * This file is subject to the terms and conditions of the GNU General Public 8 * This file is subject to the terms and conditions of the GNU General Public
8 * License. See the file COPYING in the main directory of this archive for 9 * License. See the file COPYING in the main directory of this archive for
@@ -64,11 +65,11 @@ struct w8001_coord {
64 65
65/* touch query reply packet */ 66/* touch query reply packet */
66struct w8001_touch_query { 67struct w8001_touch_query {
68 u16 x;
69 u16 y;
67 u8 panel_res; 70 u8 panel_res;
68 u8 capacity_res; 71 u8 capacity_res;
69 u8 sensor_id; 72 u8 sensor_id;
70 u16 x;
71 u16 y;
72}; 73};
73 74
74/* 75/*
@@ -87,9 +88,14 @@ struct w8001 {
87 char phys[32]; 88 char phys[32];
88 int type; 89 int type;
89 unsigned int pktlen; 90 unsigned int pktlen;
91 u16 max_touch_x;
92 u16 max_touch_y;
93 u16 max_pen_x;
94 u16 max_pen_y;
95 char name[64];
90}; 96};
91 97
92static void parse_data(u8 *data, struct w8001_coord *coord) 98static void parse_pen_data(u8 *data, struct w8001_coord *coord)
93{ 99{
94 memset(coord, 0, sizeof(*coord)); 100 memset(coord, 0, sizeof(*coord));
95 101
@@ -113,11 +119,30 @@ static void parse_data(u8 *data, struct w8001_coord *coord)
113 coord->tilt_y = data[8] & 0x7F; 119 coord->tilt_y = data[8] & 0x7F;
114} 120}
115 121
116static void parse_touch(struct w8001 *w8001) 122static void parse_single_touch(u8 *data, struct w8001_coord *coord)
123{
124 coord->x = (data[1] << 7) | data[2];
125 coord->y = (data[3] << 7) | data[4];
126 coord->tsw = data[0] & 0x01;
127}
128
129static void scale_touch_coordinates(struct w8001 *w8001,
130 unsigned int *x, unsigned int *y)
131{
132 if (w8001->max_pen_x && w8001->max_touch_x)
133 *x = *x * w8001->max_pen_x / w8001->max_touch_x;
134
135 if (w8001->max_pen_y && w8001->max_touch_y)
136 *y = *y * w8001->max_pen_y / w8001->max_touch_y;
137}
138
139static void parse_multi_touch(struct w8001 *w8001)
117{ 140{
118 struct input_dev *dev = w8001->dev; 141 struct input_dev *dev = w8001->dev;
119 unsigned char *data = w8001->data; 142 unsigned char *data = w8001->data;
143 unsigned int x, y;
120 int i; 144 int i;
145 int count = 0;
121 146
122 for (i = 0; i < 2; i++) { 147 for (i = 0; i < 2; i++) {
123 bool touch = data[0] & (1 << i); 148 bool touch = data[0] & (1 << i);
@@ -125,15 +150,29 @@ static void parse_touch(struct w8001 *w8001)
125 input_mt_slot(dev, i); 150 input_mt_slot(dev, i);
126 input_mt_report_slot_state(dev, MT_TOOL_FINGER, touch); 151 input_mt_report_slot_state(dev, MT_TOOL_FINGER, touch);
127 if (touch) { 152 if (touch) {
128 int x = (data[6 * i + 1] << 7) | (data[6 * i + 2]); 153 x = (data[6 * i + 1] << 7) | data[6 * i + 2];
129 int y = (data[6 * i + 3] << 7) | (data[6 * i + 4]); 154 y = (data[6 * i + 3] << 7) | data[6 * i + 4];
130 /* data[5,6] and [11,12] is finger capacity */ 155 /* data[5,6] and [11,12] is finger capacity */
131 156
157 /* scale to pen maximum */
158 scale_touch_coordinates(w8001, &x, &y);
159
132 input_report_abs(dev, ABS_MT_POSITION_X, x); 160 input_report_abs(dev, ABS_MT_POSITION_X, x);
133 input_report_abs(dev, ABS_MT_POSITION_Y, y); 161 input_report_abs(dev, ABS_MT_POSITION_Y, y);
162 count++;
134 } 163 }
135 } 164 }
136 165
166 /* emulate single touch events when stylus is out of proximity.
167 * This is to make single touch backward support consistent
168 * across all Wacom single touch devices.
169 */
170 if (w8001->type != BTN_TOOL_PEN &&
171 w8001->type != BTN_TOOL_RUBBER) {
172 w8001->type = count == 1 ? BTN_TOOL_FINGER : KEY_RESERVED;
173 input_mt_report_pointer_emulation(dev, true);
174 }
175
137 input_sync(dev); 176 input_sync(dev);
138} 177}
139 178
@@ -152,6 +191,15 @@ static void parse_touchquery(u8 *data, struct w8001_touch_query *query)
152 query->y = data[5] << 9; 191 query->y = data[5] << 9;
153 query->y |= data[6] << 2; 192 query->y |= data[6] << 2;
154 query->y |= (data[2] >> 3) & 0x3; 193 query->y |= (data[2] >> 3) & 0x3;
194
195 /* Early days' single-finger touch models need the following defaults */
196 if (!query->x && !query->y) {
197 query->x = 1024;
198 query->y = 1024;
199 if (query->panel_res)
200 query->x = query->y = (1 << query->panel_res);
201 query->panel_res = 10;
202 }
155} 203}
156 204
157static void report_pen_events(struct w8001 *w8001, struct w8001_coord *coord) 205static void report_pen_events(struct w8001 *w8001, struct w8001_coord *coord)
@@ -161,16 +209,15 @@ static void report_pen_events(struct w8001 *w8001, struct w8001_coord *coord)
161 /* 209 /*
162 * We have 1 bit for proximity (rdy) and 3 bits for tip, side, 210 * We have 1 bit for proximity (rdy) and 3 bits for tip, side,
163 * side2/eraser. If rdy && f2 are set, this can be either pen + side2, 211 * side2/eraser. If rdy && f2 are set, this can be either pen + side2,
164 * or eraser. assume 212 * or eraser. Assume:
165 * - if dev is already in proximity and f2 is toggled → pen + side2 213 * - if dev is already in proximity and f2 is toggled → pen + side2
166 * - if dev comes into proximity with f2 set → eraser 214 * - if dev comes into proximity with f2 set → eraser
167 * If f2 disappears after assuming eraser, fake proximity out for 215 * If f2 disappears after assuming eraser, fake proximity out for
168 * eraser and in for pen. 216 * eraser and in for pen.
169 */ 217 */
170 218
171 if (!w8001->type) { 219 switch (w8001->type) {
172 w8001->type = coord->f2 ? BTN_TOOL_RUBBER : BTN_TOOL_PEN; 220 case BTN_TOOL_RUBBER:
173 } else if (w8001->type == BTN_TOOL_RUBBER) {
174 if (!coord->f2) { 221 if (!coord->f2) {
175 input_report_abs(dev, ABS_PRESSURE, 0); 222 input_report_abs(dev, ABS_PRESSURE, 0);
176 input_report_key(dev, BTN_TOUCH, 0); 223 input_report_key(dev, BTN_TOUCH, 0);
@@ -180,8 +227,21 @@ static void report_pen_events(struct w8001 *w8001, struct w8001_coord *coord)
180 input_sync(dev); 227 input_sync(dev);
181 w8001->type = BTN_TOOL_PEN; 228 w8001->type = BTN_TOOL_PEN;
182 } 229 }
183 } else { 230 break;
231
232 case BTN_TOOL_FINGER:
233 input_report_key(dev, BTN_TOUCH, 0);
234 input_report_key(dev, BTN_TOOL_FINGER, 0);
235 input_sync(dev);
236 /* fall through */
237
238 case KEY_RESERVED:
239 w8001->type = coord->f2 ? BTN_TOOL_RUBBER : BTN_TOOL_PEN;
240 break;
241
242 default:
184 input_report_key(dev, BTN_STYLUS2, coord->f2); 243 input_report_key(dev, BTN_STYLUS2, coord->f2);
244 break;
185 } 245 }
186 246
187 input_report_abs(dev, ABS_X, coord->x); 247 input_report_abs(dev, ABS_X, coord->x);
@@ -193,7 +253,26 @@ static void report_pen_events(struct w8001 *w8001, struct w8001_coord *coord)
193 input_sync(dev); 253 input_sync(dev);
194 254
195 if (!coord->rdy) 255 if (!coord->rdy)
196 w8001->type = 0; 256 w8001->type = KEY_RESERVED;
257}
258
259static void report_single_touch(struct w8001 *w8001, struct w8001_coord *coord)
260{
261 struct input_dev *dev = w8001->dev;
262 unsigned int x = coord->x;
263 unsigned int y = coord->y;
264
265 /* scale to pen maximum */
266 scale_touch_coordinates(w8001, &x, &y);
267
268 input_report_abs(dev, ABS_X, x);
269 input_report_abs(dev, ABS_Y, y);
270 input_report_key(dev, BTN_TOUCH, coord->tsw);
271 input_report_key(dev, BTN_TOOL_FINGER, coord->tsw);
272
273 input_sync(dev);
274
275 w8001->type = coord->tsw ? BTN_TOOL_FINGER : KEY_RESERVED;
197} 276}
198 277
199static irqreturn_t w8001_interrupt(struct serio *serio, 278static irqreturn_t w8001_interrupt(struct serio *serio,
@@ -214,9 +293,18 @@ static irqreturn_t w8001_interrupt(struct serio *serio,
214 293
215 case W8001_PKTLEN_TOUCH93 - 1: 294 case W8001_PKTLEN_TOUCH93 - 1:
216 case W8001_PKTLEN_TOUCH9A - 1: 295 case W8001_PKTLEN_TOUCH9A - 1:
217 /* ignore one-finger touch packet. */ 296 tmp = w8001->data[0] & W8001_TOUCH_BYTE;
218 if (w8001->pktlen == w8001->idx) 297 if (tmp != W8001_TOUCH_BYTE)
298 break;
299
300 if (w8001->pktlen == w8001->idx) {
219 w8001->idx = 0; 301 w8001->idx = 0;
302 if (w8001->type != BTN_TOOL_PEN &&
303 w8001->type != BTN_TOOL_RUBBER) {
304 parse_single_touch(w8001->data, &coord);
305 report_single_touch(w8001, &coord);
306 }
307 }
220 break; 308 break;
221 309
222 /* Pen coordinates packet */ 310 /* Pen coordinates packet */
@@ -225,18 +313,18 @@ static irqreturn_t w8001_interrupt(struct serio *serio,
225 if (unlikely(tmp == W8001_TAB_BYTE)) 313 if (unlikely(tmp == W8001_TAB_BYTE))
226 break; 314 break;
227 315
228 tmp = (w8001->data[0] & W8001_TOUCH_BYTE); 316 tmp = w8001->data[0] & W8001_TOUCH_BYTE;
229 if (tmp == W8001_TOUCH_BYTE) 317 if (tmp == W8001_TOUCH_BYTE)
230 break; 318 break;
231 319
232 w8001->idx = 0; 320 w8001->idx = 0;
233 parse_data(w8001->data, &coord); 321 parse_pen_data(w8001->data, &coord);
234 report_pen_events(w8001, &coord); 322 report_pen_events(w8001, &coord);
235 break; 323 break;
236 324
237 /* control packet */ 325 /* control packet */
238 case W8001_PKTLEN_TPCCTL - 1: 326 case W8001_PKTLEN_TPCCTL - 1:
239 tmp = (w8001->data[0] & W8001_TOUCH_MASK); 327 tmp = w8001->data[0] & W8001_TOUCH_MASK;
240 if (tmp == W8001_TOUCH_BYTE) 328 if (tmp == W8001_TOUCH_BYTE)
241 break; 329 break;
242 330
@@ -249,7 +337,7 @@ static irqreturn_t w8001_interrupt(struct serio *serio,
249 /* 2 finger touch packet */ 337 /* 2 finger touch packet */
250 case W8001_PKTLEN_TOUCH2FG - 1: 338 case W8001_PKTLEN_TOUCH2FG - 1:
251 w8001->idx = 0; 339 w8001->idx = 0;
252 parse_touch(w8001); 340 parse_multi_touch(w8001);
253 break; 341 break;
254 } 342 }
255 343
@@ -279,6 +367,7 @@ static int w8001_setup(struct w8001 *w8001)
279{ 367{
280 struct input_dev *dev = w8001->dev; 368 struct input_dev *dev = w8001->dev;
281 struct w8001_coord coord; 369 struct w8001_coord coord;
370 struct w8001_touch_query touch;
282 int error; 371 int error;
283 372
284 error = w8001_command(w8001, W8001_CMD_STOP, false); 373 error = w8001_command(w8001, W8001_CMD_STOP, false);
@@ -287,14 +376,21 @@ static int w8001_setup(struct w8001 *w8001)
287 376
288 msleep(250); /* wait 250ms before querying the device */ 377 msleep(250); /* wait 250ms before querying the device */
289 378
379 dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS);
380 strlcat(w8001->name, "Wacom Serial", sizeof(w8001->name));
381
290 /* penabled? */ 382 /* penabled? */
291 error = w8001_command(w8001, W8001_CMD_QUERY, true); 383 error = w8001_command(w8001, W8001_CMD_QUERY, true);
292 if (!error) { 384 if (!error) {
385 __set_bit(BTN_TOUCH, dev->keybit);
293 __set_bit(BTN_TOOL_PEN, dev->keybit); 386 __set_bit(BTN_TOOL_PEN, dev->keybit);
294 __set_bit(BTN_TOOL_RUBBER, dev->keybit); 387 __set_bit(BTN_TOOL_RUBBER, dev->keybit);
295 __set_bit(BTN_STYLUS, dev->keybit); 388 __set_bit(BTN_STYLUS, dev->keybit);
296 __set_bit(BTN_STYLUS2, dev->keybit); 389 __set_bit(BTN_STYLUS2, dev->keybit);
297 parse_data(w8001->response, &coord); 390
391 parse_pen_data(w8001->response, &coord);
392 w8001->max_pen_x = coord.x;
393 w8001->max_pen_y = coord.y;
298 394
299 input_set_abs_params(dev, ABS_X, 0, coord.x, 0, 0); 395 input_set_abs_params(dev, ABS_X, 0, coord.x, 0, 0);
300 input_set_abs_params(dev, ABS_Y, 0, coord.y, 0, 0); 396 input_set_abs_params(dev, ABS_Y, 0, coord.y, 0, 0);
@@ -303,6 +399,8 @@ static int w8001_setup(struct w8001 *w8001)
303 input_set_abs_params(dev, ABS_TILT_X, 0, coord.tilt_x, 0, 0); 399 input_set_abs_params(dev, ABS_TILT_X, 0, coord.tilt_x, 0, 0);
304 input_set_abs_params(dev, ABS_TILT_Y, 0, coord.tilt_y, 0, 0); 400 input_set_abs_params(dev, ABS_TILT_Y, 0, coord.tilt_y, 0, 0);
305 } 401 }
402 w8001->id = 0x90;
403 strlcat(w8001->name, " Penabled", sizeof(w8001->name));
306 } 404 }
307 405
308 /* Touch enabled? */ 406 /* Touch enabled? */
@@ -313,24 +411,38 @@ static int w8001_setup(struct w8001 *w8001)
313 * second byte is empty, which indicates touch is not supported. 411 * second byte is empty, which indicates touch is not supported.
314 */ 412 */
315 if (!error && w8001->response[1]) { 413 if (!error && w8001->response[1]) {
316 struct w8001_touch_query touch; 414 __set_bit(BTN_TOUCH, dev->keybit);
415 __set_bit(BTN_TOOL_FINGER, dev->keybit);
317 416
318 parse_touchquery(w8001->response, &touch); 417 parse_touchquery(w8001->response, &touch);
418 w8001->max_touch_x = touch.x;
419 w8001->max_touch_y = touch.y;
420
421 /* scale to pen maximum */
422 if (w8001->max_pen_x && w8001->max_pen_y) {
423 touch.x = w8001->max_pen_x;
424 touch.y = w8001->max_pen_y;
425 }
319 426
320 input_set_abs_params(dev, ABS_X, 0, touch.x, 0, 0); 427 input_set_abs_params(dev, ABS_X, 0, touch.x, 0, 0);
321 input_set_abs_params(dev, ABS_Y, 0, touch.y, 0, 0); 428 input_set_abs_params(dev, ABS_Y, 0, touch.y, 0, 0);
322 __set_bit(BTN_TOOL_FINGER, dev->keybit);
323 429
324 switch (touch.sensor_id) { 430 switch (touch.sensor_id) {
325 case 0: 431 case 0:
326 case 2: 432 case 2:
327 w8001->pktlen = W8001_PKTLEN_TOUCH93; 433 w8001->pktlen = W8001_PKTLEN_TOUCH93;
434 w8001->id = 0x93;
435 strlcat(w8001->name, " 1FG", sizeof(w8001->name));
328 break; 436 break;
437
329 case 1: 438 case 1:
330 case 3: 439 case 3:
331 case 4: 440 case 4:
332 w8001->pktlen = W8001_PKTLEN_TOUCH9A; 441 w8001->pktlen = W8001_PKTLEN_TOUCH9A;
442 strlcat(w8001->name, " 1FG", sizeof(w8001->name));
443 w8001->id = 0x9a;
333 break; 444 break;
445
334 case 5: 446 case 5:
335 w8001->pktlen = W8001_PKTLEN_TOUCH2FG; 447 w8001->pktlen = W8001_PKTLEN_TOUCH2FG;
336 448
@@ -341,10 +453,18 @@ static int w8001_setup(struct w8001 *w8001)
341 0, touch.y, 0, 0); 453 0, touch.y, 0, 0);
342 input_set_abs_params(dev, ABS_MT_TOOL_TYPE, 454 input_set_abs_params(dev, ABS_MT_TOOL_TYPE,
343 0, MT_TOOL_MAX, 0, 0); 455 0, MT_TOOL_MAX, 0, 0);
456
457 strlcat(w8001->name, " 2FG", sizeof(w8001->name));
458 if (w8001->max_pen_x && w8001->max_pen_y)
459 w8001->id = 0xE3;
460 else
461 w8001->id = 0xE2;
344 break; 462 break;
345 } 463 }
346 } 464 }
347 465
466 strlcat(w8001->name, " Touchscreen", sizeof(w8001->name));
467
348 return w8001_command(w8001, W8001_CMD_START, false); 468 return w8001_command(w8001, W8001_CMD_START, false);
349} 469}
350 470
@@ -384,22 +504,10 @@ static int w8001_connect(struct serio *serio, struct serio_driver *drv)
384 } 504 }
385 505
386 w8001->serio = serio; 506 w8001->serio = serio;
387 w8001->id = serio->id.id;
388 w8001->dev = input_dev; 507 w8001->dev = input_dev;
389 init_completion(&w8001->cmd_done); 508 init_completion(&w8001->cmd_done);
390 snprintf(w8001->phys, sizeof(w8001->phys), "%s/input0", serio->phys); 509 snprintf(w8001->phys, sizeof(w8001->phys), "%s/input0", serio->phys);
391 510
392 input_dev->name = "Wacom W8001 Penabled Serial TouchScreen";
393 input_dev->phys = w8001->phys;
394 input_dev->id.bustype = BUS_RS232;
395 input_dev->id.vendor = SERIO_W8001;
396 input_dev->id.product = w8001->id;
397 input_dev->id.version = 0x0100;
398 input_dev->dev.parent = &serio->dev;
399
400 input_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS);
401 __set_bit(BTN_TOUCH, input_dev->keybit);
402
403 serio_set_drvdata(serio, w8001); 511 serio_set_drvdata(serio, w8001);
404 err = serio_open(serio, drv); 512 err = serio_open(serio, drv);
405 if (err) 513 if (err)
@@ -409,6 +517,14 @@ static int w8001_connect(struct serio *serio, struct serio_driver *drv)
409 if (err) 517 if (err)
410 goto fail3; 518 goto fail3;
411 519
520 input_dev->name = w8001->name;
521 input_dev->phys = w8001->phys;
522 input_dev->id.product = w8001->id;
523 input_dev->id.bustype = BUS_RS232;
524 input_dev->id.vendor = 0x056a;
525 input_dev->id.version = 0x0100;
526 input_dev->dev.parent = &serio->dev;
527
412 err = input_register_device(w8001->dev); 528 err = input_register_device(w8001->dev);
413 if (err) 529 if (err)
414 goto fail3; 530 goto fail3;
diff --git a/drivers/isdn/gigaset/bas-gigaset.c b/drivers/isdn/gigaset/bas-gigaset.c
index 178942a2ee61..8a3c5cfc4fea 100644
--- a/drivers/isdn/gigaset/bas-gigaset.c
+++ b/drivers/isdn/gigaset/bas-gigaset.c
@@ -2318,7 +2318,7 @@ static int gigaset_probe(struct usb_interface *interface,
2318 __func__, le16_to_cpu(udev->descriptor.idVendor), 2318 __func__, le16_to_cpu(udev->descriptor.idVendor),
2319 le16_to_cpu(udev->descriptor.idProduct)); 2319 le16_to_cpu(udev->descriptor.idProduct));
2320 2320
2321 /* allocate memory for our device state and intialize it */ 2321 /* allocate memory for our device state and initialize it */
2322 cs = gigaset_initcs(driver, BAS_CHANNELS, 0, 0, cidmode, 2322 cs = gigaset_initcs(driver, BAS_CHANNELS, 0, 0, cidmode,
2323 GIGASET_MODULENAME); 2323 GIGASET_MODULENAME);
2324 if (!cs) 2324 if (!cs)
@@ -2576,7 +2576,7 @@ static int __init bas_gigaset_init(void)
2576{ 2576{
2577 int result; 2577 int result;
2578 2578
2579 /* allocate memory for our driver state and intialize it */ 2579 /* allocate memory for our driver state and initialize it */
2580 driver = gigaset_initdriver(GIGASET_MINOR, GIGASET_MINORS, 2580 driver = gigaset_initdriver(GIGASET_MINOR, GIGASET_MINORS,
2581 GIGASET_MODULENAME, GIGASET_DEVNAME, 2581 GIGASET_MODULENAME, GIGASET_DEVNAME,
2582 &gigops, THIS_MODULE); 2582 &gigops, THIS_MODULE);
diff --git a/drivers/isdn/gigaset/ser-gigaset.c b/drivers/isdn/gigaset/ser-gigaset.c
index d151dcbf770d..0ef09d0eb96b 100644
--- a/drivers/isdn/gigaset/ser-gigaset.c
+++ b/drivers/isdn/gigaset/ser-gigaset.c
@@ -513,7 +513,7 @@ gigaset_tty_open(struct tty_struct *tty)
513 return -ENODEV; 513 return -ENODEV;
514 } 514 }
515 515
516 /* allocate memory for our device state and intialize it */ 516 /* allocate memory for our device state and initialize it */
517 cs = gigaset_initcs(driver, 1, 1, 0, cidmode, GIGASET_MODULENAME); 517 cs = gigaset_initcs(driver, 1, 1, 0, cidmode, GIGASET_MODULENAME);
518 if (!cs) 518 if (!cs)
519 goto error; 519 goto error;
@@ -771,7 +771,7 @@ static int __init ser_gigaset_init(void)
771 return rc; 771 return rc;
772 } 772 }
773 773
774 /* allocate memory for our driver state and intialize it */ 774 /* allocate memory for our driver state and initialize it */
775 driver = gigaset_initdriver(GIGASET_MINOR, GIGASET_MINORS, 775 driver = gigaset_initdriver(GIGASET_MINOR, GIGASET_MINORS,
776 GIGASET_MODULENAME, GIGASET_DEVNAME, 776 GIGASET_MODULENAME, GIGASET_DEVNAME,
777 &ops, THIS_MODULE); 777 &ops, THIS_MODULE);
diff --git a/drivers/isdn/gigaset/usb-gigaset.c b/drivers/isdn/gigaset/usb-gigaset.c
index 4a66338f4e7d..5e3300d8a2a5 100644
--- a/drivers/isdn/gigaset/usb-gigaset.c
+++ b/drivers/isdn/gigaset/usb-gigaset.c
@@ -695,7 +695,7 @@ static int gigaset_probe(struct usb_interface *interface,
695 695
696 dev_info(&udev->dev, "%s: Device matched ... !\n", __func__); 696 dev_info(&udev->dev, "%s: Device matched ... !\n", __func__);
697 697
698 /* allocate memory for our device state and intialize it */ 698 /* allocate memory for our device state and initialize it */
699 cs = gigaset_initcs(driver, 1, 1, 0, cidmode, GIGASET_MODULENAME); 699 cs = gigaset_initcs(driver, 1, 1, 0, cidmode, GIGASET_MODULENAME);
700 if (!cs) 700 if (!cs)
701 return -ENODEV; 701 return -ENODEV;
@@ -894,7 +894,7 @@ static int __init usb_gigaset_init(void)
894{ 894{
895 int result; 895 int result;
896 896
897 /* allocate memory for our driver state and intialize it */ 897 /* allocate memory for our driver state and initialize it */
898 driver = gigaset_initdriver(GIGASET_MINOR, GIGASET_MINORS, 898 driver = gigaset_initdriver(GIGASET_MINOR, GIGASET_MINORS,
899 GIGASET_MODULENAME, GIGASET_DEVNAME, 899 GIGASET_MODULENAME, GIGASET_DEVNAME,
900 &ops, THIS_MODULE); 900 &ops, THIS_MODULE);
diff --git a/drivers/isdn/hardware/mISDN/ipac.h b/drivers/isdn/hardware/mISDN/ipac.h
index 74a6ccf9065c..8121e046b739 100644
--- a/drivers/isdn/hardware/mISDN/ipac.h
+++ b/drivers/isdn/hardware/mISDN/ipac.h
@@ -29,7 +29,7 @@ struct isac_hw {
29 u32 type; 29 u32 type;
30 u32 off; /* offset to isac regs */ 30 u32 off; /* offset to isac regs */
31 char *name; 31 char *name;
32 spinlock_t *hwlock; /* lock HW acccess */ 32 spinlock_t *hwlock; /* lock HW access */
33 read_reg_func *read_reg; 33 read_reg_func *read_reg;
34 write_reg_func *write_reg; 34 write_reg_func *write_reg;
35 fifo_func *read_fifo; 35 fifo_func *read_fifo;
@@ -70,7 +70,7 @@ struct ipac_hw {
70 struct hscx_hw hscx[2]; 70 struct hscx_hw hscx[2];
71 char *name; 71 char *name;
72 void *hw; 72 void *hw;
73 spinlock_t *hwlock; /* lock HW acccess */ 73 spinlock_t *hwlock; /* lock HW access */
74 struct module *owner; 74 struct module *owner;
75 u32 type; 75 u32 type;
76 read_reg_func *read_reg; 76 read_reg_func *read_reg;
diff --git a/drivers/isdn/hardware/mISDN/isar.h b/drivers/isdn/hardware/mISDN/isar.h
index 4a134acd44d0..9962bdf699c7 100644
--- a/drivers/isdn/hardware/mISDN/isar.h
+++ b/drivers/isdn/hardware/mISDN/isar.h
@@ -44,7 +44,7 @@ struct isar_ch {
44struct isar_hw { 44struct isar_hw {
45 struct isar_ch ch[2]; 45 struct isar_ch ch[2];
46 void *hw; 46 void *hw;
47 spinlock_t *hwlock; /* lock HW acccess */ 47 spinlock_t *hwlock; /* lock HW access */
48 char *name; 48 char *name;
49 struct module *owner; 49 struct module *owner;
50 read_reg_func *read_reg; 50 read_reg_func *read_reg;
diff --git a/drivers/isdn/mISDN/dsp_cmx.c b/drivers/isdn/mISDN/dsp_cmx.c
index 76d9e673b4e1..309bacf1fadc 100644
--- a/drivers/isdn/mISDN/dsp_cmx.c
+++ b/drivers/isdn/mISDN/dsp_cmx.c
@@ -112,7 +112,7 @@
112 * Disable rx-data: 112 * Disable rx-data:
113 * If cmx is realized in hardware, rx data will be disabled if requested by 113 * If cmx is realized in hardware, rx data will be disabled if requested by
114 * the upper layer. If dtmf decoding is done by software and enabled, rx data 114 * the upper layer. If dtmf decoding is done by software and enabled, rx data
115 * will not be diabled but blocked to the upper layer. 115 * will not be disabled but blocked to the upper layer.
116 * 116 *
117 * HFC conference engine: 117 * HFC conference engine:
118 * If it is possible to realize all features using hardware, hardware will be 118 * If it is possible to realize all features using hardware, hardware will be
diff --git a/drivers/leds/leds-lp5521.c b/drivers/leds/leds-lp5521.c
index 33facd0c45d1..80a3ae3c00b9 100644
--- a/drivers/leds/leds-lp5521.c
+++ b/drivers/leds/leds-lp5521.c
@@ -98,7 +98,6 @@
98#define LP5521_EXT_CLK_USED 0x08 98#define LP5521_EXT_CLK_USED 0x08
99 99
100struct lp5521_engine { 100struct lp5521_engine {
101 const struct attribute_group *attributes;
102 int id; 101 int id;
103 u8 mode; 102 u8 mode;
104 u8 prog_page; 103 u8 prog_page;
@@ -225,25 +224,22 @@ static int lp5521_set_led_current(struct lp5521_chip *chip, int led, u8 curr)
225 curr); 224 curr);
226} 225}
227 226
228static void lp5521_init_engine(struct lp5521_chip *chip, 227static void lp5521_init_engine(struct lp5521_chip *chip)
229 const struct attribute_group *attr_group)
230{ 228{
231 int i; 229 int i;
232 for (i = 0; i < ARRAY_SIZE(chip->engines); i++) { 230 for (i = 0; i < ARRAY_SIZE(chip->engines); i++) {
233 chip->engines[i].id = i + 1; 231 chip->engines[i].id = i + 1;
234 chip->engines[i].engine_mask = LP5521_ENG_MASK_BASE >> (i * 2); 232 chip->engines[i].engine_mask = LP5521_ENG_MASK_BASE >> (i * 2);
235 chip->engines[i].prog_page = i; 233 chip->engines[i].prog_page = i;
236 chip->engines[i].attributes = &attr_group[i];
237 } 234 }
238} 235}
239 236
240static int lp5521_configure(struct i2c_client *client, 237static int lp5521_configure(struct i2c_client *client)
241 const struct attribute_group *attr_group)
242{ 238{
243 struct lp5521_chip *chip = i2c_get_clientdata(client); 239 struct lp5521_chip *chip = i2c_get_clientdata(client);
244 int ret; 240 int ret;
245 241
246 lp5521_init_engine(chip, attr_group); 242 lp5521_init_engine(chip);
247 243
248 /* Set all PWMs to direct control mode */ 244 /* Set all PWMs to direct control mode */
249 ret = lp5521_write(client, LP5521_REG_OP_MODE, 0x3F); 245 ret = lp5521_write(client, LP5521_REG_OP_MODE, 0x3F);
@@ -329,9 +325,6 @@ static int lp5521_detect(struct i2c_client *client)
329/* Set engine mode and create appropriate sysfs attributes, if required. */ 325/* Set engine mode and create appropriate sysfs attributes, if required. */
330static int lp5521_set_mode(struct lp5521_engine *engine, u8 mode) 326static int lp5521_set_mode(struct lp5521_engine *engine, u8 mode)
331{ 327{
332 struct lp5521_chip *chip = engine_to_lp5521(engine);
333 struct i2c_client *client = chip->client;
334 struct device *dev = &client->dev;
335 int ret = 0; 328 int ret = 0;
336 329
337 /* if in that mode already do nothing, except for run */ 330 /* if in that mode already do nothing, except for run */
@@ -343,18 +336,10 @@ static int lp5521_set_mode(struct lp5521_engine *engine, u8 mode)
343 } else if (mode == LP5521_CMD_LOAD) { 336 } else if (mode == LP5521_CMD_LOAD) {
344 lp5521_set_engine_mode(engine, LP5521_CMD_DISABLED); 337 lp5521_set_engine_mode(engine, LP5521_CMD_DISABLED);
345 lp5521_set_engine_mode(engine, LP5521_CMD_LOAD); 338 lp5521_set_engine_mode(engine, LP5521_CMD_LOAD);
346
347 ret = sysfs_create_group(&dev->kobj, engine->attributes);
348 if (ret)
349 return ret;
350 } else if (mode == LP5521_CMD_DISABLED) { 339 } else if (mode == LP5521_CMD_DISABLED) {
351 lp5521_set_engine_mode(engine, LP5521_CMD_DISABLED); 340 lp5521_set_engine_mode(engine, LP5521_CMD_DISABLED);
352 } 341 }
353 342
354 /* remove load attribute from sysfs if not in load mode */
355 if (engine->mode == LP5521_CMD_LOAD && mode != LP5521_CMD_LOAD)
356 sysfs_remove_group(&dev->kobj, engine->attributes);
357
358 engine->mode = mode; 343 engine->mode = mode;
359 344
360 return ret; 345 return ret;
@@ -373,6 +358,8 @@ static int lp5521_do_store_load(struct lp5521_engine *engine,
373 while ((offset < len - 1) && (i < LP5521_PROGRAM_LENGTH)) { 358 while ((offset < len - 1) && (i < LP5521_PROGRAM_LENGTH)) {
374 /* separate sscanfs because length is working only for %s */ 359 /* separate sscanfs because length is working only for %s */
375 ret = sscanf(buf + offset, "%2s%n ", c, &nrchars); 360 ret = sscanf(buf + offset, "%2s%n ", c, &nrchars);
361 if (ret != 2)
362 goto fail;
376 ret = sscanf(c, "%2x", &cmd); 363 ret = sscanf(c, "%2x", &cmd);
377 if (ret != 1) 364 if (ret != 1)
378 goto fail; 365 goto fail;
@@ -387,7 +374,10 @@ static int lp5521_do_store_load(struct lp5521_engine *engine,
387 goto fail; 374 goto fail;
388 375
389 mutex_lock(&chip->lock); 376 mutex_lock(&chip->lock);
390 ret = lp5521_load_program(engine, pattern); 377 if (engine->mode == LP5521_CMD_LOAD)
378 ret = lp5521_load_program(engine, pattern);
379 else
380 ret = -EINVAL;
391 mutex_unlock(&chip->lock); 381 mutex_unlock(&chip->lock);
392 382
393 if (ret) { 383 if (ret) {
@@ -574,20 +564,8 @@ static struct attribute *lp5521_attributes[] = {
574 &dev_attr_engine2_mode.attr, 564 &dev_attr_engine2_mode.attr,
575 &dev_attr_engine3_mode.attr, 565 &dev_attr_engine3_mode.attr,
576 &dev_attr_selftest.attr, 566 &dev_attr_selftest.attr,
577 NULL
578};
579
580static struct attribute *lp5521_engine1_attributes[] = {
581 &dev_attr_engine1_load.attr, 567 &dev_attr_engine1_load.attr,
582 NULL
583};
584
585static struct attribute *lp5521_engine2_attributes[] = {
586 &dev_attr_engine2_load.attr, 568 &dev_attr_engine2_load.attr,
587 NULL
588};
589
590static struct attribute *lp5521_engine3_attributes[] = {
591 &dev_attr_engine3_load.attr, 569 &dev_attr_engine3_load.attr,
592 NULL 570 NULL
593}; 571};
@@ -596,12 +574,6 @@ static const struct attribute_group lp5521_group = {
596 .attrs = lp5521_attributes, 574 .attrs = lp5521_attributes,
597}; 575};
598 576
599static const struct attribute_group lp5521_engine_group[] = {
600 {.attrs = lp5521_engine1_attributes },
601 {.attrs = lp5521_engine2_attributes },
602 {.attrs = lp5521_engine3_attributes },
603};
604
605static int lp5521_register_sysfs(struct i2c_client *client) 577static int lp5521_register_sysfs(struct i2c_client *client)
606{ 578{
607 struct device *dev = &client->dev; 579 struct device *dev = &client->dev;
@@ -616,12 +588,6 @@ static void lp5521_unregister_sysfs(struct i2c_client *client)
616 588
617 sysfs_remove_group(&dev->kobj, &lp5521_group); 589 sysfs_remove_group(&dev->kobj, &lp5521_group);
618 590
619 for (i = 0; i < ARRAY_SIZE(chip->engines); i++) {
620 if (chip->engines[i].mode == LP5521_CMD_LOAD)
621 sysfs_remove_group(&dev->kobj,
622 chip->engines[i].attributes);
623 }
624
625 for (i = 0; i < chip->num_leds; i++) 591 for (i = 0; i < chip->num_leds; i++)
626 sysfs_remove_group(&chip->leds[i].cdev.dev->kobj, 592 sysfs_remove_group(&chip->leds[i].cdev.dev->kobj,
627 &lp5521_led_attribute_group); 593 &lp5521_led_attribute_group);
@@ -651,7 +617,8 @@ static int __init lp5521_init_led(struct lp5521_led *led,
651 return -EINVAL; 617 return -EINVAL;
652 } 618 }
653 619
654 snprintf(name, sizeof(name), "%s:channel%d", client->name, chan); 620 snprintf(name, sizeof(name), "%s:channel%d",
621 pdata->label ?: client->name, chan);
655 led->cdev.brightness_set = lp5521_set_brightness; 622 led->cdev.brightness_set = lp5521_set_brightness;
656 led->cdev.name = name; 623 led->cdev.name = name;
657 res = led_classdev_register(dev, &led->cdev); 624 res = led_classdev_register(dev, &led->cdev);
@@ -723,7 +690,7 @@ static int lp5521_probe(struct i2c_client *client,
723 690
724 dev_info(&client->dev, "%s programmable led chip found\n", id->name); 691 dev_info(&client->dev, "%s programmable led chip found\n", id->name);
725 692
726 ret = lp5521_configure(client, lp5521_engine_group); 693 ret = lp5521_configure(client);
727 if (ret < 0) { 694 if (ret < 0) {
728 dev_err(&client->dev, "error configuring chip\n"); 695 dev_err(&client->dev, "error configuring chip\n");
729 goto fail2; 696 goto fail2;
diff --git a/drivers/leds/leds-lp5523.c b/drivers/leds/leds-lp5523.c
index 0cc4ead2fd8b..d0c4068ecddd 100644
--- a/drivers/leds/leds-lp5523.c
+++ b/drivers/leds/leds-lp5523.c
@@ -105,7 +105,6 @@
105#define SHIFT_MASK(id) (((id) - 1) * 2) 105#define SHIFT_MASK(id) (((id) - 1) * 2)
106 106
107struct lp5523_engine { 107struct lp5523_engine {
108 const struct attribute_group *attributes;
109 int id; 108 int id;
110 u8 mode; 109 u8 mode;
111 u8 prog_page; 110 u8 prog_page;
@@ -403,14 +402,23 @@ static ssize_t store_engine_leds(struct device *dev,
403 struct i2c_client *client = to_i2c_client(dev); 402 struct i2c_client *client = to_i2c_client(dev);
404 struct lp5523_chip *chip = i2c_get_clientdata(client); 403 struct lp5523_chip *chip = i2c_get_clientdata(client);
405 u16 mux = 0; 404 u16 mux = 0;
405 ssize_t ret;
406 406
407 if (lp5523_mux_parse(buf, &mux, len)) 407 if (lp5523_mux_parse(buf, &mux, len))
408 return -EINVAL; 408 return -EINVAL;
409 409
410 mutex_lock(&chip->lock);
411 ret = -EINVAL;
412 if (chip->engines[nr - 1].mode != LP5523_CMD_LOAD)
413 goto leave;
414
410 if (lp5523_load_mux(&chip->engines[nr - 1], mux)) 415 if (lp5523_load_mux(&chip->engines[nr - 1], mux))
411 return -EINVAL; 416 goto leave;
412 417
413 return len; 418 ret = len;
419leave:
420 mutex_unlock(&chip->lock);
421 return ret;
414} 422}
415 423
416#define store_leds(nr) \ 424#define store_leds(nr) \
@@ -556,7 +564,11 @@ static int lp5523_do_store_load(struct lp5523_engine *engine,
556 564
557 mutex_lock(&chip->lock); 565 mutex_lock(&chip->lock);
558 566
559 ret = lp5523_load_program(engine, pattern); 567 if (engine->mode == LP5523_CMD_LOAD)
568 ret = lp5523_load_program(engine, pattern);
569 else
570 ret = -EINVAL;
571
560 mutex_unlock(&chip->lock); 572 mutex_unlock(&chip->lock);
561 573
562 if (ret) { 574 if (ret) {
@@ -737,37 +749,18 @@ static struct attribute *lp5523_attributes[] = {
737 &dev_attr_engine2_mode.attr, 749 &dev_attr_engine2_mode.attr,
738 &dev_attr_engine3_mode.attr, 750 &dev_attr_engine3_mode.attr,
739 &dev_attr_selftest.attr, 751 &dev_attr_selftest.attr,
740 NULL
741};
742
743static struct attribute *lp5523_engine1_attributes[] = {
744 &dev_attr_engine1_load.attr, 752 &dev_attr_engine1_load.attr,
745 &dev_attr_engine1_leds.attr, 753 &dev_attr_engine1_leds.attr,
746 NULL
747};
748
749static struct attribute *lp5523_engine2_attributes[] = {
750 &dev_attr_engine2_load.attr, 754 &dev_attr_engine2_load.attr,
751 &dev_attr_engine2_leds.attr, 755 &dev_attr_engine2_leds.attr,
752 NULL
753};
754
755static struct attribute *lp5523_engine3_attributes[] = {
756 &dev_attr_engine3_load.attr, 756 &dev_attr_engine3_load.attr,
757 &dev_attr_engine3_leds.attr, 757 &dev_attr_engine3_leds.attr,
758 NULL
759}; 758};
760 759
761static const struct attribute_group lp5523_group = { 760static const struct attribute_group lp5523_group = {
762 .attrs = lp5523_attributes, 761 .attrs = lp5523_attributes,
763}; 762};
764 763
765static const struct attribute_group lp5523_engine_group[] = {
766 {.attrs = lp5523_engine1_attributes },
767 {.attrs = lp5523_engine2_attributes },
768 {.attrs = lp5523_engine3_attributes },
769};
770
771static int lp5523_register_sysfs(struct i2c_client *client) 764static int lp5523_register_sysfs(struct i2c_client *client)
772{ 765{
773 struct device *dev = &client->dev; 766 struct device *dev = &client->dev;
@@ -788,10 +781,6 @@ static void lp5523_unregister_sysfs(struct i2c_client *client)
788 781
789 sysfs_remove_group(&dev->kobj, &lp5523_group); 782 sysfs_remove_group(&dev->kobj, &lp5523_group);
790 783
791 for (i = 0; i < ARRAY_SIZE(chip->engines); i++)
792 if (chip->engines[i].mode == LP5523_CMD_LOAD)
793 sysfs_remove_group(&dev->kobj, &lp5523_engine_group[i]);
794
795 for (i = 0; i < chip->num_leds; i++) 784 for (i = 0; i < chip->num_leds; i++)
796 sysfs_remove_group(&chip->leds[i].cdev.dev->kobj, 785 sysfs_remove_group(&chip->leds[i].cdev.dev->kobj,
797 &lp5523_led_attribute_group); 786 &lp5523_led_attribute_group);
@@ -802,10 +791,6 @@ static void lp5523_unregister_sysfs(struct i2c_client *client)
802/*--------------------------------------------------------------*/ 791/*--------------------------------------------------------------*/
803static int lp5523_set_mode(struct lp5523_engine *engine, u8 mode) 792static int lp5523_set_mode(struct lp5523_engine *engine, u8 mode)
804{ 793{
805 /* engine to chip */
806 struct lp5523_chip *chip = engine_to_lp5523(engine);
807 struct i2c_client *client = chip->client;
808 struct device *dev = &client->dev;
809 int ret = 0; 794 int ret = 0;
810 795
811 /* if in that mode already do nothing, except for run */ 796 /* if in that mode already do nothing, except for run */
@@ -817,18 +802,10 @@ static int lp5523_set_mode(struct lp5523_engine *engine, u8 mode)
817 } else if (mode == LP5523_CMD_LOAD) { 802 } else if (mode == LP5523_CMD_LOAD) {
818 lp5523_set_engine_mode(engine, LP5523_CMD_DISABLED); 803 lp5523_set_engine_mode(engine, LP5523_CMD_DISABLED);
819 lp5523_set_engine_mode(engine, LP5523_CMD_LOAD); 804 lp5523_set_engine_mode(engine, LP5523_CMD_LOAD);
820
821 ret = sysfs_create_group(&dev->kobj, engine->attributes);
822 if (ret)
823 return ret;
824 } else if (mode == LP5523_CMD_DISABLED) { 805 } else if (mode == LP5523_CMD_DISABLED) {
825 lp5523_set_engine_mode(engine, LP5523_CMD_DISABLED); 806 lp5523_set_engine_mode(engine, LP5523_CMD_DISABLED);
826 } 807 }
827 808
828 /* remove load attribute from sysfs if not in load mode */
829 if (engine->mode == LP5523_CMD_LOAD && mode != LP5523_CMD_LOAD)
830 sysfs_remove_group(&dev->kobj, engine->attributes);
831
832 engine->mode = mode; 809 engine->mode = mode;
833 810
834 return ret; 811 return ret;
@@ -845,7 +822,6 @@ static int __init lp5523_init_engine(struct lp5523_engine *engine, int id)
845 engine->engine_mask = LP5523_ENG_MASK_BASE >> SHIFT_MASK(id); 822 engine->engine_mask = LP5523_ENG_MASK_BASE >> SHIFT_MASK(id);
846 engine->prog_page = id - 1; 823 engine->prog_page = id - 1;
847 engine->mux_page = id + 2; 824 engine->mux_page = id + 2;
848 engine->attributes = &lp5523_engine_group[id - 1];
849 825
850 return 0; 826 return 0;
851} 827}
@@ -870,7 +846,8 @@ static int __init lp5523_init_led(struct lp5523_led *led, struct device *dev,
870 return -EINVAL; 846 return -EINVAL;
871 } 847 }
872 848
873 snprintf(name, 32, "lp5523:channel%d", chan); 849 snprintf(name, sizeof(name), "%s:channel%d",
850 pdata->label ?: "lp5523", chan);
874 851
875 led->cdev.name = name; 852 led->cdev.name = name;
876 led->cdev.brightness_set = lp5523_set_brightness; 853 led->cdev.brightness_set = lp5523_set_brightness;
diff --git a/drivers/leds/leds-pca9532.c b/drivers/leds/leds-pca9532.c
index 43d08756d823..afac338d5025 100644
--- a/drivers/leds/leds-pca9532.c
+++ b/drivers/leds/leds-pca9532.c
@@ -200,6 +200,32 @@ static void pca9532_led_work(struct work_struct *work)
200 pca9532_setled(led); 200 pca9532_setled(led);
201} 201}
202 202
203static void pca9532_destroy_devices(struct pca9532_data *data, int n_devs)
204{
205 int i = n_devs;
206
207 if (!data)
208 return;
209
210 while (--i >= 0) {
211 switch (data->leds[i].type) {
212 case PCA9532_TYPE_NONE:
213 break;
214 case PCA9532_TYPE_LED:
215 led_classdev_unregister(&data->leds[i].ldev);
216 cancel_work_sync(&data->leds[i].work);
217 break;
218 case PCA9532_TYPE_N2100_BEEP:
219 if (data->idev != NULL) {
220 input_unregister_device(data->idev);
221 cancel_work_sync(&data->work);
222 data->idev = NULL;
223 }
224 break;
225 }
226 }
227}
228
203static int pca9532_configure(struct i2c_client *client, 229static int pca9532_configure(struct i2c_client *client,
204 struct pca9532_data *data, struct pca9532_platform_data *pdata) 230 struct pca9532_data *data, struct pca9532_platform_data *pdata)
205{ 231{
@@ -274,25 +300,7 @@ static int pca9532_configure(struct i2c_client *client,
274 return 0; 300 return 0;
275 301
276exit: 302exit:
277 if (i > 0) 303 pca9532_destroy_devices(data, i);
278 for (i = i - 1; i >= 0; i--)
279 switch (data->leds[i].type) {
280 case PCA9532_TYPE_NONE:
281 break;
282 case PCA9532_TYPE_LED:
283 led_classdev_unregister(&data->leds[i].ldev);
284 cancel_work_sync(&data->leds[i].work);
285 break;
286 case PCA9532_TYPE_N2100_BEEP:
287 if (data->idev != NULL) {
288 input_unregister_device(data->idev);
289 input_free_device(data->idev);
290 cancel_work_sync(&data->work);
291 data->idev = NULL;
292 }
293 break;
294 }
295
296 return err; 304 return err;
297} 305}
298 306
@@ -329,25 +337,7 @@ static int pca9532_probe(struct i2c_client *client,
329static int pca9532_remove(struct i2c_client *client) 337static int pca9532_remove(struct i2c_client *client)
330{ 338{
331 struct pca9532_data *data = i2c_get_clientdata(client); 339 struct pca9532_data *data = i2c_get_clientdata(client);
332 int i; 340 pca9532_destroy_devices(data, 16);
333 for (i = 0; i < 16; i++)
334 switch (data->leds[i].type) {
335 case PCA9532_TYPE_NONE:
336 break;
337 case PCA9532_TYPE_LED:
338 led_classdev_unregister(&data->leds[i].ldev);
339 cancel_work_sync(&data->leds[i].work);
340 break;
341 case PCA9532_TYPE_N2100_BEEP:
342 if (data->idev != NULL) {
343 input_unregister_device(data->idev);
344 input_free_device(data->idev);
345 cancel_work_sync(&data->work);
346 data->idev = NULL;
347 }
348 break;
349 }
350
351 kfree(data); 341 kfree(data);
352 return 0; 342 return 0;
353} 343}
diff --git a/drivers/leds/ledtrig-backlight.c b/drivers/leds/ledtrig-backlight.c
index f948e57bd9b8..2b513a2ad7de 100644
--- a/drivers/leds/ledtrig-backlight.c
+++ b/drivers/leds/ledtrig-backlight.c
@@ -26,6 +26,7 @@ struct bl_trig_notifier {
26 int brightness; 26 int brightness;
27 int old_status; 27 int old_status;
28 struct notifier_block notifier; 28 struct notifier_block notifier;
29 unsigned invert;
29}; 30};
30 31
31static int fb_notifier_callback(struct notifier_block *p, 32static int fb_notifier_callback(struct notifier_block *p,
@@ -36,23 +37,64 @@ static int fb_notifier_callback(struct notifier_block *p,
36 struct led_classdev *led = n->led; 37 struct led_classdev *led = n->led;
37 struct fb_event *fb_event = data; 38 struct fb_event *fb_event = data;
38 int *blank = fb_event->data; 39 int *blank = fb_event->data;
40 int new_status = *blank ? BLANK : UNBLANK;
39 41
40 switch (event) { 42 switch (event) {
41 case FB_EVENT_BLANK : 43 case FB_EVENT_BLANK :
42 if (*blank && n->old_status == UNBLANK) { 44 if (new_status == n->old_status)
45 break;
46
47 if ((n->old_status == UNBLANK) ^ n->invert) {
43 n->brightness = led->brightness; 48 n->brightness = led->brightness;
44 led_set_brightness(led, LED_OFF); 49 led_set_brightness(led, LED_OFF);
45 n->old_status = BLANK; 50 } else {
46 } else if (!*blank && n->old_status == BLANK) {
47 led_set_brightness(led, n->brightness); 51 led_set_brightness(led, n->brightness);
48 n->old_status = UNBLANK;
49 } 52 }
53
54 n->old_status = new_status;
55
50 break; 56 break;
51 } 57 }
52 58
53 return 0; 59 return 0;
54} 60}
55 61
62static ssize_t bl_trig_invert_show(struct device *dev,
63 struct device_attribute *attr, char *buf)
64{
65 struct led_classdev *led = dev_get_drvdata(dev);
66 struct bl_trig_notifier *n = led->trigger_data;
67
68 return sprintf(buf, "%u\n", n->invert);
69}
70
71static ssize_t bl_trig_invert_store(struct device *dev,
72 struct device_attribute *attr, const char *buf, size_t num)
73{
74 struct led_classdev *led = dev_get_drvdata(dev);
75 struct bl_trig_notifier *n = led->trigger_data;
76 unsigned long invert;
77 int ret;
78
79 ret = strict_strtoul(buf, 10, &invert);
80 if (ret < 0)
81 return ret;
82
83 if (invert > 1)
84 return -EINVAL;
85
86 n->invert = invert;
87
88 /* After inverting, we need to update the LED. */
89 if ((n->old_status == BLANK) ^ n->invert)
90 led_set_brightness(led, LED_OFF);
91 else
92 led_set_brightness(led, n->brightness);
93
94 return num;
95}
96static DEVICE_ATTR(inverted, 0644, bl_trig_invert_show, bl_trig_invert_store);
97
56static void bl_trig_activate(struct led_classdev *led) 98static void bl_trig_activate(struct led_classdev *led)
57{ 99{
58 int ret; 100 int ret;
@@ -66,6 +108,10 @@ static void bl_trig_activate(struct led_classdev *led)
66 return; 108 return;
67 } 109 }
68 110
111 ret = device_create_file(led->dev, &dev_attr_inverted);
112 if (ret)
113 goto err_invert;
114
69 n->led = led; 115 n->led = led;
70 n->brightness = led->brightness; 116 n->brightness = led->brightness;
71 n->old_status = UNBLANK; 117 n->old_status = UNBLANK;
@@ -74,6 +120,12 @@ static void bl_trig_activate(struct led_classdev *led)
74 ret = fb_register_client(&n->notifier); 120 ret = fb_register_client(&n->notifier);
75 if (ret) 121 if (ret)
76 dev_err(led->dev, "unable to register backlight trigger\n"); 122 dev_err(led->dev, "unable to register backlight trigger\n");
123
124 return;
125
126err_invert:
127 led->trigger_data = NULL;
128 kfree(n);
77} 129}
78 130
79static void bl_trig_deactivate(struct led_classdev *led) 131static void bl_trig_deactivate(struct led_classdev *led)
@@ -82,6 +134,7 @@ static void bl_trig_deactivate(struct led_classdev *led)
82 (struct bl_trig_notifier *) led->trigger_data; 134 (struct bl_trig_notifier *) led->trigger_data;
83 135
84 if (n) { 136 if (n) {
137 device_remove_file(led->dev, &dev_attr_inverted);
85 fb_unregister_client(&n->notifier); 138 fb_unregister_client(&n->notifier);
86 kfree(n); 139 kfree(n);
87 } 140 }
diff --git a/drivers/macintosh/via-pmu-backlight.c b/drivers/macintosh/via-pmu-backlight.c
index 1cec02f6c431..ade1e656bfb2 100644
--- a/drivers/macintosh/via-pmu-backlight.c
+++ b/drivers/macintosh/via-pmu-backlight.c
@@ -15,7 +15,7 @@
15 15
16#define MAX_PMU_LEVEL 0xFF 16#define MAX_PMU_LEVEL 0xFF
17 17
18static struct backlight_ops pmu_backlight_data; 18static const struct backlight_ops pmu_backlight_data;
19static DEFINE_SPINLOCK(pmu_backlight_lock); 19static DEFINE_SPINLOCK(pmu_backlight_lock);
20static int sleeping, uses_pmu_bl; 20static int sleeping, uses_pmu_bl;
21static u8 bl_curve[FB_BACKLIGHT_LEVELS]; 21static u8 bl_curve[FB_BACKLIGHT_LEVELS];
@@ -115,7 +115,7 @@ static int pmu_backlight_get_brightness(struct backlight_device *bd)
115 return bd->props.brightness; 115 return bd->props.brightness;
116} 116}
117 117
118static struct backlight_ops pmu_backlight_data = { 118static const struct backlight_ops pmu_backlight_data = {
119 .get_brightness = pmu_backlight_get_brightness, 119 .get_brightness = pmu_backlight_get_brightness,
120 .update_status = pmu_backlight_update_status, 120 .update_status = pmu_backlight_update_status,
121 121
diff --git a/drivers/macintosh/via-pmu.c b/drivers/macintosh/via-pmu.c
index cd29c8248386..8b021eb0d48c 100644
--- a/drivers/macintosh/via-pmu.c
+++ b/drivers/macintosh/via-pmu.c
@@ -2257,7 +2257,7 @@ static int pmu_sleep_valid(suspend_state_t state)
2257 && (pmac_call_feature(PMAC_FTR_SLEEP_STATE, NULL, 0, -1) >= 0); 2257 && (pmac_call_feature(PMAC_FTR_SLEEP_STATE, NULL, 0, -1) >= 0);
2258} 2258}
2259 2259
2260static struct platform_suspend_ops pmu_pm_ops = { 2260static const struct platform_suspend_ops pmu_pm_ops = {
2261 .enter = powerbook_sleep, 2261 .enter = powerbook_sleep,
2262 .valid = pmu_sleep_valid, 2262 .valid = pmu_sleep_valid,
2263}; 2263};
diff --git a/drivers/media/video/cx18/cx23418.h b/drivers/media/video/cx18/cx23418.h
index 2c00980acfcb..7e40035028d2 100644
--- a/drivers/media/video/cx18/cx23418.h
+++ b/drivers/media/video/cx18/cx23418.h
@@ -177,7 +177,7 @@
177 IN[0] - Task handle. 177 IN[0] - Task handle.
178 IN[1] - luma type: 0 = disable, 1 = 1D horizontal only, 2 = 1D vertical only, 178 IN[1] - luma type: 0 = disable, 1 = 1D horizontal only, 2 = 1D vertical only,
179 3 = 2D H/V separable, 4 = 2D symmetric non-separable 179 3 = 2D H/V separable, 4 = 2D symmetric non-separable
180 IN[2] - chroma type: 0 - diable, 1 = 1D horizontal 180 IN[2] - chroma type: 0 - disable, 1 = 1D horizontal
181 ReturnCode - One of the ERR_CAPTURE_... */ 181 ReturnCode - One of the ERR_CAPTURE_... */
182#define CX18_CPU_SET_SPATIAL_FILTER_TYPE (CPU_CMD_MASK_CAPTURE | 0x000C) 182#define CX18_CPU_SET_SPATIAL_FILTER_TYPE (CPU_CMD_MASK_CAPTURE | 0x000C)
183 183
diff --git a/drivers/media/video/cx25840/cx25840-ir.c b/drivers/media/video/cx25840/cx25840-ir.c
index 627926f6bde8..7eb79af28aa3 100644
--- a/drivers/media/video/cx25840/cx25840-ir.c
+++ b/drivers/media/video/cx25840/cx25840-ir.c
@@ -261,7 +261,7 @@ static u16 ns_to_pulse_width_count(u32 ns, u16 divider)
261 u32 rem; 261 u32 rem;
262 262
263 /* 263 /*
264 * The 2 lsb's of the pulse width timer count are not accessable, hence 264 * The 2 lsb's of the pulse width timer count are not accessible, hence
265 * the (1 << 2) 265 * the (1 << 2)
266 */ 266 */
267 n = ((u64) ns) * CX25840_IR_REFCLK_FREQ / 1000000; /* millicycles */ 267 n = ((u64) ns) * CX25840_IR_REFCLK_FREQ / 1000000; /* millicycles */
diff --git a/drivers/media/video/davinci/vpif.h b/drivers/media/video/davinci/vpif.h
index 188841b476e0..ebd5c4338ebb 100644
--- a/drivers/media/video/davinci/vpif.h
+++ b/drivers/media/video/davinci/vpif.h
@@ -33,7 +33,7 @@ extern spinlock_t vpif_lock;
33#define regr(reg) readl((reg) + vpif_base) 33#define regr(reg) readl((reg) + vpif_base)
34#define regw(value, reg) writel(value, (reg + vpif_base)) 34#define regw(value, reg) writel(value, (reg + vpif_base))
35 35
36/* Register Addresss Offsets */ 36/* Register Address Offsets */
37#define VPIF_PID (0x0000) 37#define VPIF_PID (0x0000)
38#define VPIF_CH0_CTRL (0x0004) 38#define VPIF_CH0_CTRL (0x0004)
39#define VPIF_CH1_CTRL (0x0008) 39#define VPIF_CH1_CTRL (0x0008)
diff --git a/drivers/media/video/davinci/vpss.c b/drivers/media/video/davinci/vpss.c
index 7918680917d0..3e5cf27ec2b2 100644
--- a/drivers/media/video/davinci/vpss.c
+++ b/drivers/media/video/davinci/vpss.c
@@ -85,7 +85,7 @@ enum vpss_platform_type {
85/* 85/*
86 * vpss operations. Depends on platform. Not all functions are available 86 * vpss operations. Depends on platform. Not all functions are available
87 * on all platforms. The api, first check if a functio is available before 87 * on all platforms. The api, first check if a functio is available before
88 * invoking it. In the probe, the function ptrs are intialized based on 88 * invoking it. In the probe, the function ptrs are initialized based on
89 * vpss name. vpss name can be "dm355_vpss", "dm644x_vpss" etc. 89 * vpss name. vpss name can be "dm355_vpss", "dm644x_vpss" etc.
90 */ 90 */
91struct vpss_hw_ops { 91struct vpss_hw_ops {
diff --git a/drivers/media/video/omap/omap_vout.c b/drivers/media/video/omap/omap_vout.c
index 83de97ad971e..029a4babfd61 100644
--- a/drivers/media/video/omap/omap_vout.c
+++ b/drivers/media/video/omap/omap_vout.c
@@ -1286,7 +1286,7 @@ static int omap_vout_release(struct file *file)
1286 videobuf_mmap_free(q); 1286 videobuf_mmap_free(q);
1287 1287
1288 /* Even if apply changes fails we should continue 1288 /* Even if apply changes fails we should continue
1289 freeing allocated memeory */ 1289 freeing allocated memory */
1290 if (vout->streaming) { 1290 if (vout->streaming) {
1291 u32 mask = 0; 1291 u32 mask = 0;
1292 1292
diff --git a/drivers/media/video/saa7164/saa7164-core.c b/drivers/media/video/saa7164/saa7164-core.c
index d6bf3f82cc34..58af67f2278b 100644
--- a/drivers/media/video/saa7164/saa7164-core.c
+++ b/drivers/media/video/saa7164/saa7164-core.c
@@ -655,8 +655,8 @@ static irqreturn_t saa7164_irq(int irq, void *dev_id)
655 goto out; 655 goto out;
656 } 656 }
657 657
658 /* Check that the hardware is accessable. If the status bytes are 658 /* Check that the hardware is accessible. If the status bytes are
659 * 0xFF then the device is not accessable, the the IRQ belongs 659 * 0xFF then the device is not accessible, the the IRQ belongs
660 * to another driver. 660 * to another driver.
661 * 4 x u32 interrupt registers. 661 * 4 x u32 interrupt registers.
662 */ 662 */
diff --git a/drivers/media/video/sn9c102/sn9c102_sensor.h b/drivers/media/video/sn9c102/sn9c102_sensor.h
index 494957b10bac..7f38549715b6 100644
--- a/drivers/media/video/sn9c102/sn9c102_sensor.h
+++ b/drivers/media/video/sn9c102/sn9c102_sensor.h
@@ -147,7 +147,7 @@ enum sn9c102_i2c_interface {
147 147
148struct sn9c102_sensor { 148struct sn9c102_sensor {
149 char name[32], /* sensor name */ 149 char name[32], /* sensor name */
150 maintainer[64]; /* name of the mantainer <email> */ 150 maintainer[64]; /* name of the maintainer <email> */
151 151
152 enum sn9c102_bridge supported_bridge; /* supported SN9C1xx bridges */ 152 enum sn9c102_bridge supported_bridge; /* supported SN9C1xx bridges */
153 153
diff --git a/drivers/media/video/tvp7002.c b/drivers/media/video/tvp7002.c
index e63b40f5a706..c799e4eb6fcd 100644
--- a/drivers/media/video/tvp7002.c
+++ b/drivers/media/video/tvp7002.c
@@ -789,7 +789,7 @@ static int tvp7002_query_dv_preset(struct v4l2_subdev *sd,
789 * Get the value of a TVP7002 decoder device register. 789 * Get the value of a TVP7002 decoder device register.
790 * Returns zero when successful, -EINVAL if register read fails or 790 * Returns zero when successful, -EINVAL if register read fails or
791 * access to I2C client fails, -EPERM if the call is not allowed 791 * access to I2C client fails, -EPERM if the call is not allowed
792 * by diabled CAP_SYS_ADMIN. 792 * by disabled CAP_SYS_ADMIN.
793 */ 793 */
794static int tvp7002_g_register(struct v4l2_subdev *sd, 794static int tvp7002_g_register(struct v4l2_subdev *sd,
795 struct v4l2_dbg_register *reg) 795 struct v4l2_dbg_register *reg)
diff --git a/drivers/media/video/via-camera.c b/drivers/media/video/via-camera.c
index e25aca5759fb..2f973cd56408 100644
--- a/drivers/media/video/via-camera.c
+++ b/drivers/media/video/via-camera.c
@@ -13,14 +13,12 @@
13#include <linux/pci.h> 13#include <linux/pci.h>
14#include <linux/gpio.h> 14#include <linux/gpio.h>
15#include <linux/interrupt.h> 15#include <linux/interrupt.h>
16#include <linux/pci.h>
17#include <linux/platform_device.h> 16#include <linux/platform_device.h>
18#include <linux/videodev2.h> 17#include <linux/videodev2.h>
19#include <media/v4l2-device.h> 18#include <media/v4l2-device.h>
20#include <media/v4l2-ioctl.h> 19#include <media/v4l2-ioctl.h>
21#include <media/v4l2-chip-ident.h> 20#include <media/v4l2-chip-ident.h>
22#include <media/videobuf-dma-sg.h> 21#include <media/videobuf-dma-sg.h>
23#include <linux/device.h>
24#include <linux/delay.h> 22#include <linux/delay.h>
25#include <linux/dma-mapping.h> 23#include <linux/dma-mapping.h>
26#include <linux/pm_qos_params.h> 24#include <linux/pm_qos_params.h>
diff --git a/drivers/memstick/core/memstick.c b/drivers/memstick/core/memstick.c
index c00fe8253c51..e9a3eab7b0cf 100644
--- a/drivers/memstick/core/memstick.c
+++ b/drivers/memstick/core/memstick.c
@@ -465,6 +465,7 @@ static void memstick_check(struct work_struct *work)
465 if (!host->card) { 465 if (!host->card) {
466 host->card = card; 466 host->card = card;
467 if (device_register(&card->dev)) { 467 if (device_register(&card->dev)) {
468 put_device(&card->dev);
468 kfree(host->card); 469 kfree(host->card);
469 host->card = NULL; 470 host->card = NULL;
470 } 471 }
@@ -510,14 +511,18 @@ int memstick_add_host(struct memstick_host *host)
510{ 511{
511 int rc; 512 int rc;
512 513
513 if (!idr_pre_get(&memstick_host_idr, GFP_KERNEL)) 514 while (1) {
514 return -ENOMEM; 515 if (!idr_pre_get(&memstick_host_idr, GFP_KERNEL))
516 return -ENOMEM;
515 517
516 spin_lock(&memstick_host_lock); 518 spin_lock(&memstick_host_lock);
517 rc = idr_get_new(&memstick_host_idr, host, &host->id); 519 rc = idr_get_new(&memstick_host_idr, host, &host->id);
518 spin_unlock(&memstick_host_lock); 520 spin_unlock(&memstick_host_lock);
519 if (rc) 521 if (!rc)
520 return rc; 522 break;
523 else if (rc != -EAGAIN)
524 return rc;
525 }
521 526
522 dev_set_name(&host->dev, "memstick%u", host->id); 527 dev_set_name(&host->dev, "memstick%u", host->id);
523 528
diff --git a/drivers/memstick/core/mspro_block.c b/drivers/memstick/core/mspro_block.c
index 02362eccc588..57b42bfc7d23 100644
--- a/drivers/memstick/core/mspro_block.c
+++ b/drivers/memstick/core/mspro_block.c
@@ -23,7 +23,6 @@
23 23
24#define DRIVER_NAME "mspro_block" 24#define DRIVER_NAME "mspro_block"
25 25
26static DEFINE_MUTEX(mspro_block_mutex);
27static int major; 26static int major;
28module_param(major, int, 0644); 27module_param(major, int, 0644);
29 28
@@ -160,6 +159,13 @@ struct mspro_block_data {
160 int (*mrq_handler)(struct memstick_dev *card, 159 int (*mrq_handler)(struct memstick_dev *card,
161 struct memstick_request **mrq); 160 struct memstick_request **mrq);
162 161
162
163 /* Default request setup function for data access method preferred by
164 * this host instance.
165 */
166 void (*setup_transfer)(struct memstick_dev *card,
167 u64 offset, size_t length);
168
163 struct attribute_group attr_group; 169 struct attribute_group attr_group;
164 170
165 struct scatterlist req_sg[MSPRO_BLOCK_MAX_SEGS]; 171 struct scatterlist req_sg[MSPRO_BLOCK_MAX_SEGS];
@@ -181,7 +187,6 @@ static int mspro_block_bd_open(struct block_device *bdev, fmode_t mode)
181 struct mspro_block_data *msb = disk->private_data; 187 struct mspro_block_data *msb = disk->private_data;
182 int rc = -ENXIO; 188 int rc = -ENXIO;
183 189
184 mutex_lock(&mspro_block_mutex);
185 mutex_lock(&mspro_block_disk_lock); 190 mutex_lock(&mspro_block_disk_lock);
186 191
187 if (msb && msb->card) { 192 if (msb && msb->card) {
@@ -193,7 +198,6 @@ static int mspro_block_bd_open(struct block_device *bdev, fmode_t mode)
193 } 198 }
194 199
195 mutex_unlock(&mspro_block_disk_lock); 200 mutex_unlock(&mspro_block_disk_lock);
196 mutex_unlock(&mspro_block_mutex);
197 201
198 return rc; 202 return rc;
199} 203}
@@ -225,11 +229,7 @@ static int mspro_block_disk_release(struct gendisk *disk)
225 229
226static int mspro_block_bd_release(struct gendisk *disk, fmode_t mode) 230static int mspro_block_bd_release(struct gendisk *disk, fmode_t mode)
227{ 231{
228 int ret; 232 return mspro_block_disk_release(disk);
229 mutex_lock(&mspro_block_mutex);
230 ret = mspro_block_disk_release(disk);
231 mutex_unlock(&mspro_block_mutex);
232 return ret;
233} 233}
234 234
235static int mspro_block_bd_getgeo(struct block_device *bdev, 235static int mspro_block_bd_getgeo(struct block_device *bdev,
@@ -663,14 +663,43 @@ has_int_reg:
663 } 663 }
664} 664}
665 665
666/*** Transfer setup functions for different access methods. ***/
667
668/** Setup data transfer request for SET_CMD TPC with arguments in card
669 * registers.
670 *
671 * @card Current media instance
672 * @offset Target data offset in bytes
673 * @length Required transfer length in bytes.
674 */
675static void h_mspro_block_setup_cmd(struct memstick_dev *card, u64 offset,
676 size_t length)
677{
678 struct mspro_block_data *msb = memstick_get_drvdata(card);
679 struct mspro_param_register param = {
680 .system = msb->system,
681 .data_count = cpu_to_be16((uint16_t)(length / msb->page_size)),
682 /* ISO C90 warning precludes direct initialization for now. */
683 .data_address = 0,
684 .tpc_param = 0
685 };
686
687 do_div(offset, msb->page_size);
688 param.data_address = cpu_to_be32((uint32_t)offset);
689
690 card->next_request = h_mspro_block_req_init;
691 msb->mrq_handler = h_mspro_block_transfer_data;
692 memstick_init_req(&card->current_mrq, MS_TPC_WRITE_REG,
693 &param, sizeof(param));
694}
695
666/*** Data transfer ***/ 696/*** Data transfer ***/
667 697
668static int mspro_block_issue_req(struct memstick_dev *card, int chunk) 698static int mspro_block_issue_req(struct memstick_dev *card, int chunk)
669{ 699{
670 struct mspro_block_data *msb = memstick_get_drvdata(card); 700 struct mspro_block_data *msb = memstick_get_drvdata(card);
671 sector_t t_sec; 701 u64 t_off;
672 unsigned int count; 702 unsigned int count;
673 struct mspro_param_register param;
674 703
675try_again: 704try_again:
676 while (chunk) { 705 while (chunk) {
@@ -685,30 +714,17 @@ try_again:
685 continue; 714 continue;
686 } 715 }
687 716
688 t_sec = blk_rq_pos(msb->block_req) << 9; 717 t_off = blk_rq_pos(msb->block_req);
689 sector_div(t_sec, msb->page_size); 718 t_off <<= 9;
690
691 count = blk_rq_bytes(msb->block_req); 719 count = blk_rq_bytes(msb->block_req);
692 count /= msb->page_size;
693 720
694 param.system = msb->system; 721 msb->setup_transfer(card, t_off, count);
695 param.data_count = cpu_to_be16(count);
696 param.data_address = cpu_to_be32((uint32_t)t_sec);
697 param.tpc_param = 0;
698 722
699 msb->data_dir = rq_data_dir(msb->block_req); 723 msb->data_dir = rq_data_dir(msb->block_req);
700 msb->transfer_cmd = msb->data_dir == READ 724 msb->transfer_cmd = msb->data_dir == READ
701 ? MSPRO_CMD_READ_DATA 725 ? MSPRO_CMD_READ_DATA
702 : MSPRO_CMD_WRITE_DATA; 726 : MSPRO_CMD_WRITE_DATA;
703 727
704 dev_dbg(&card->dev, "data transfer: cmd %x, "
705 "lba %x, count %x\n", msb->transfer_cmd,
706 be32_to_cpu(param.data_address), count);
707
708 card->next_request = h_mspro_block_req_init;
709 msb->mrq_handler = h_mspro_block_transfer_data;
710 memstick_init_req(&card->current_mrq, MS_TPC_WRITE_REG,
711 &param, sizeof(param));
712 memstick_new_req(card->host); 728 memstick_new_req(card->host);
713 return 0; 729 return 0;
714 } 730 }
@@ -963,18 +979,16 @@ try_again:
963static int mspro_block_read_attributes(struct memstick_dev *card) 979static int mspro_block_read_attributes(struct memstick_dev *card)
964{ 980{
965 struct mspro_block_data *msb = memstick_get_drvdata(card); 981 struct mspro_block_data *msb = memstick_get_drvdata(card);
966 struct mspro_param_register param = {
967 .system = msb->system,
968 .data_count = cpu_to_be16(1),
969 .data_address = 0,
970 .tpc_param = 0
971 };
972 struct mspro_attribute *attr = NULL; 982 struct mspro_attribute *attr = NULL;
973 struct mspro_sys_attr *s_attr = NULL; 983 struct mspro_sys_attr *s_attr = NULL;
974 unsigned char *buffer = NULL; 984 unsigned char *buffer = NULL;
975 int cnt, rc, attr_count; 985 int cnt, rc, attr_count;
976 unsigned int addr; 986 /* While normally physical device offsets, represented here by
977 unsigned short page_count; 987 * attr_offset and attr_len will be of large numeric types, we can be
988 * sure, that attributes are close enough to the beginning of the
989 * device, to save ourselves some trouble.
990 */
991 unsigned int addr, attr_offset = 0, attr_len = msb->page_size;
978 992
979 attr = kmalloc(msb->page_size, GFP_KERNEL); 993 attr = kmalloc(msb->page_size, GFP_KERNEL);
980 if (!attr) 994 if (!attr)
@@ -987,10 +1001,8 @@ static int mspro_block_read_attributes(struct memstick_dev *card)
987 msb->data_dir = READ; 1001 msb->data_dir = READ;
988 msb->transfer_cmd = MSPRO_CMD_READ_ATRB; 1002 msb->transfer_cmd = MSPRO_CMD_READ_ATRB;
989 1003
990 card->next_request = h_mspro_block_req_init; 1004 msb->setup_transfer(card, attr_offset, attr_len);
991 msb->mrq_handler = h_mspro_block_transfer_data; 1005
992 memstick_init_req(&card->current_mrq, MS_TPC_WRITE_REG, &param,
993 sizeof(param));
994 memstick_new_req(card->host); 1006 memstick_new_req(card->host);
995 wait_for_completion(&card->mrq_complete); 1007 wait_for_completion(&card->mrq_complete);
996 if (card->current_mrq.error) { 1008 if (card->current_mrq.error) {
@@ -1021,13 +1033,12 @@ static int mspro_block_read_attributes(struct memstick_dev *card)
1021 } 1033 }
1022 msb->attr_group.name = "media_attributes"; 1034 msb->attr_group.name = "media_attributes";
1023 1035
1024 buffer = kmalloc(msb->page_size, GFP_KERNEL); 1036 buffer = kmalloc(attr_len, GFP_KERNEL);
1025 if (!buffer) { 1037 if (!buffer) {
1026 rc = -ENOMEM; 1038 rc = -ENOMEM;
1027 goto out_free_attr; 1039 goto out_free_attr;
1028 } 1040 }
1029 memcpy(buffer, (char *)attr, msb->page_size); 1041 memcpy(buffer, (char *)attr, attr_len);
1030 page_count = 1;
1031 1042
1032 for (cnt = 0; cnt < attr_count; ++cnt) { 1043 for (cnt = 0; cnt < attr_count; ++cnt) {
1033 s_attr = kzalloc(sizeof(struct mspro_sys_attr), GFP_KERNEL); 1044 s_attr = kzalloc(sizeof(struct mspro_sys_attr), GFP_KERNEL);
@@ -1038,9 +1049,10 @@ static int mspro_block_read_attributes(struct memstick_dev *card)
1038 1049
1039 msb->attr_group.attrs[cnt] = &s_attr->dev_attr.attr; 1050 msb->attr_group.attrs[cnt] = &s_attr->dev_attr.attr;
1040 addr = be32_to_cpu(attr->entries[cnt].address); 1051 addr = be32_to_cpu(attr->entries[cnt].address);
1041 rc = be32_to_cpu(attr->entries[cnt].size); 1052 s_attr->size = be32_to_cpu(attr->entries[cnt].size);
1042 dev_dbg(&card->dev, "adding attribute %d: id %x, address %x, " 1053 dev_dbg(&card->dev, "adding attribute %d: id %x, address %x, "
1043 "size %x\n", cnt, attr->entries[cnt].id, addr, rc); 1054 "size %zx\n", cnt, attr->entries[cnt].id, addr,
1055 s_attr->size);
1044 s_attr->id = attr->entries[cnt].id; 1056 s_attr->id = attr->entries[cnt].id;
1045 if (mspro_block_attr_name(s_attr->id)) 1057 if (mspro_block_attr_name(s_attr->id))
1046 snprintf(s_attr->name, sizeof(s_attr->name), "%s", 1058 snprintf(s_attr->name, sizeof(s_attr->name), "%s",
@@ -1054,57 +1066,47 @@ static int mspro_block_read_attributes(struct memstick_dev *card)
1054 s_attr->dev_attr.attr.mode = S_IRUGO; 1066 s_attr->dev_attr.attr.mode = S_IRUGO;
1055 s_attr->dev_attr.show = mspro_block_attr_show(s_attr->id); 1067 s_attr->dev_attr.show = mspro_block_attr_show(s_attr->id);
1056 1068
1057 if (!rc) 1069 if (!s_attr->size)
1058 continue; 1070 continue;
1059 1071
1060 s_attr->size = rc; 1072 s_attr->data = kmalloc(s_attr->size, GFP_KERNEL);
1061 s_attr->data = kmalloc(rc, GFP_KERNEL);
1062 if (!s_attr->data) { 1073 if (!s_attr->data) {
1063 rc = -ENOMEM; 1074 rc = -ENOMEM;
1064 goto out_free_buffer; 1075 goto out_free_buffer;
1065 } 1076 }
1066 1077
1067 if (((addr / msb->page_size) 1078 if (((addr / msb->page_size) == (attr_offset / msb->page_size))
1068 == be32_to_cpu(param.data_address)) 1079 && (((addr + s_attr->size - 1) / msb->page_size)
1069 && (((addr + rc - 1) / msb->page_size) 1080 == (attr_offset / msb->page_size))) {
1070 == be32_to_cpu(param.data_address))) {
1071 memcpy(s_attr->data, buffer + addr % msb->page_size, 1081 memcpy(s_attr->data, buffer + addr % msb->page_size,
1072 rc); 1082 s_attr->size);
1073 continue; 1083 continue;
1074 } 1084 }
1075 1085
1076 if (page_count <= (rc / msb->page_size)) { 1086 attr_offset = (addr / msb->page_size) * msb->page_size;
1087
1088 if ((attr_offset + attr_len) < (addr + s_attr->size)) {
1077 kfree(buffer); 1089 kfree(buffer);
1078 page_count = (rc / msb->page_size) + 1; 1090 attr_len = (((addr + s_attr->size) / msb->page_size)
1079 buffer = kmalloc(page_count * msb->page_size, 1091 + 1 ) * msb->page_size - attr_offset;
1080 GFP_KERNEL); 1092 buffer = kmalloc(attr_len, GFP_KERNEL);
1081 if (!buffer) { 1093 if (!buffer) {
1082 rc = -ENOMEM; 1094 rc = -ENOMEM;
1083 goto out_free_attr; 1095 goto out_free_attr;
1084 } 1096 }
1085 } 1097 }
1086 1098
1087 param.system = msb->system; 1099 sg_init_one(&msb->req_sg[0], buffer, attr_len);
1088 param.data_count = cpu_to_be16((rc / msb->page_size) + 1);
1089 param.data_address = cpu_to_be32(addr / msb->page_size);
1090 param.tpc_param = 0;
1091
1092 sg_init_one(&msb->req_sg[0], buffer,
1093 be16_to_cpu(param.data_count) * msb->page_size);
1094 msb->seg_count = 1; 1100 msb->seg_count = 1;
1095 msb->current_seg = 0; 1101 msb->current_seg = 0;
1096 msb->current_page = 0; 1102 msb->current_page = 0;
1097 msb->data_dir = READ; 1103 msb->data_dir = READ;
1098 msb->transfer_cmd = MSPRO_CMD_READ_ATRB; 1104 msb->transfer_cmd = MSPRO_CMD_READ_ATRB;
1099 1105
1100 dev_dbg(&card->dev, "reading attribute pages %x, %x\n", 1106 dev_dbg(&card->dev, "reading attribute range %x, %x\n",
1101 be32_to_cpu(param.data_address), 1107 attr_offset, attr_len);
1102 be16_to_cpu(param.data_count));
1103 1108
1104 card->next_request = h_mspro_block_req_init; 1109 msb->setup_transfer(card, attr_offset, attr_len);
1105 msb->mrq_handler = h_mspro_block_transfer_data;
1106 memstick_init_req(&card->current_mrq, MS_TPC_WRITE_REG,
1107 (char *)&param, sizeof(param));
1108 memstick_new_req(card->host); 1110 memstick_new_req(card->host);
1109 wait_for_completion(&card->mrq_complete); 1111 wait_for_completion(&card->mrq_complete);
1110 if (card->current_mrq.error) { 1112 if (card->current_mrq.error) {
@@ -1112,7 +1114,8 @@ static int mspro_block_read_attributes(struct memstick_dev *card)
1112 goto out_free_buffer; 1114 goto out_free_buffer;
1113 } 1115 }
1114 1116
1115 memcpy(s_attr->data, buffer + addr % msb->page_size, rc); 1117 memcpy(s_attr->data, buffer + addr % msb->page_size,
1118 s_attr->size);
1116 } 1119 }
1117 1120
1118 rc = 0; 1121 rc = 0;
@@ -1130,6 +1133,8 @@ static int mspro_block_init_card(struct memstick_dev *card)
1130 int rc = 0; 1133 int rc = 0;
1131 1134
1132 msb->system = MEMSTICK_SYS_SERIAL; 1135 msb->system = MEMSTICK_SYS_SERIAL;
1136 msb->setup_transfer = h_mspro_block_setup_cmd;
1137
1133 card->reg_addr.r_offset = offsetof(struct mspro_register, status); 1138 card->reg_addr.r_offset = offsetof(struct mspro_register, status);
1134 card->reg_addr.r_length = sizeof(struct ms_status_register); 1139 card->reg_addr.r_length = sizeof(struct ms_status_register);
1135 card->reg_addr.w_offset = offsetof(struct mspro_register, param); 1140 card->reg_addr.w_offset = offsetof(struct mspro_register, param);
@@ -1206,10 +1211,12 @@ static int mspro_block_init_disk(struct memstick_dev *card)
1206 1211
1207 msb->page_size = be16_to_cpu(sys_info->unit_size); 1212 msb->page_size = be16_to_cpu(sys_info->unit_size);
1208 1213
1209 if (!idr_pre_get(&mspro_block_disk_idr, GFP_KERNEL)) 1214 mutex_lock(&mspro_block_disk_lock);
1215 if (!idr_pre_get(&mspro_block_disk_idr, GFP_KERNEL)) {
1216 mutex_unlock(&mspro_block_disk_lock);
1210 return -ENOMEM; 1217 return -ENOMEM;
1218 }
1211 1219
1212 mutex_lock(&mspro_block_disk_lock);
1213 rc = idr_get_new(&mspro_block_disk_idr, card, &disk_id); 1220 rc = idr_get_new(&mspro_block_disk_idr, card, &disk_id);
1214 mutex_unlock(&mspro_block_disk_lock); 1221 mutex_unlock(&mspro_block_disk_lock);
1215 1222
diff --git a/drivers/memstick/host/jmb38x_ms.c b/drivers/memstick/host/jmb38x_ms.c
index f2b894cd8b02..d89d925caecf 100644
--- a/drivers/memstick/host/jmb38x_ms.c
+++ b/drivers/memstick/host/jmb38x_ms.c
@@ -61,6 +61,7 @@ struct jmb38x_ms_host {
61 struct memstick_request *req; 61 struct memstick_request *req;
62 unsigned char cmd_flags; 62 unsigned char cmd_flags;
63 unsigned char io_pos; 63 unsigned char io_pos;
64 unsigned char ifmode;
64 unsigned int io_word[2]; 65 unsigned int io_word[2];
65}; 66};
66 67
@@ -136,15 +137,14 @@ struct jmb38x_ms {
136#define PAD_PU_PD_ON_MS_SOCK0 0x5f8f0000 137#define PAD_PU_PD_ON_MS_SOCK0 0x5f8f0000
137#define PAD_PU_PD_ON_MS_SOCK1 0x0f0f0000 138#define PAD_PU_PD_ON_MS_SOCK1 0x0f0f0000
138 139
140#define CLOCK_CONTROL_BY_MMIO 0x00000008
139#define CLOCK_CONTROL_40MHZ 0x00000001 141#define CLOCK_CONTROL_40MHZ 0x00000001
140#define CLOCK_CONTROL_50MHZ 0x0000000a 142#define CLOCK_CONTROL_50MHZ 0x00000002
141#define CLOCK_CONTROL_60MHZ 0x00000008 143#define CLOCK_CONTROL_60MHZ 0x00000010
142#define CLOCK_CONTROL_62_5MHZ 0x0000000c 144#define CLOCK_CONTROL_62_5MHZ 0x00000004
143#define CLOCK_CONTROL_OFF 0x00000000 145#define CLOCK_CONTROL_OFF 0x00000000
144 146
145#define PCI_CTL_CLOCK_DLY_ADDR 0x000000b0 147#define PCI_CTL_CLOCK_DLY_ADDR 0x000000b0
146#define PCI_CTL_CLOCK_DLY_MASK_A 0x00000f00
147#define PCI_CTL_CLOCK_DLY_MASK_B 0x0000f000
148 148
149enum { 149enum {
150 CMD_READY = 0x01, 150 CMD_READY = 0x01,
@@ -390,8 +390,13 @@ static int jmb38x_ms_issue_cmd(struct memstick_host *msh)
390 390
391 if (host->req->data_dir == READ) 391 if (host->req->data_dir == READ)
392 cmd |= TPC_DIR; 392 cmd |= TPC_DIR;
393 if (host->req->need_card_int) 393
394 cmd |= TPC_WAIT_INT; 394 if (host->req->need_card_int) {
395 if (host->ifmode == MEMSTICK_SERIAL)
396 cmd |= TPC_GET_INT;
397 else
398 cmd |= TPC_WAIT_INT;
399 }
395 400
396 data = host->req->data; 401 data = host->req->data;
397 402
@@ -529,7 +534,10 @@ static irqreturn_t jmb38x_ms_isr(int irq, void *dev_id)
529 if (irq_status & INT_STATUS_ANY_ERR) { 534 if (irq_status & INT_STATUS_ANY_ERR) {
530 if (irq_status & INT_STATUS_CRC_ERR) 535 if (irq_status & INT_STATUS_CRC_ERR)
531 host->req->error = -EILSEQ; 536 host->req->error = -EILSEQ;
532 else 537 else if (irq_status & INT_STATUS_TPC_ERR) {
538 dev_dbg(&host->chip->pdev->dev, "TPC_ERR\n");
539 jmb38x_ms_complete_cmd(msh, 0);
540 } else
533 host->req->error = -ETIME; 541 host->req->error = -ETIME;
534 } else { 542 } else {
535 if (host->cmd_flags & DMA_DATA) { 543 if (host->cmd_flags & DMA_DATA) {
@@ -644,7 +652,6 @@ static int jmb38x_ms_reset(struct jmb38x_ms_host *host)
644 ndelay(20); 652 ndelay(20);
645 } 653 }
646 dev_dbg(&host->chip->pdev->dev, "reset_req timeout\n"); 654 dev_dbg(&host->chip->pdev->dev, "reset_req timeout\n");
647 /* return -EIO; */
648 655
649reset_next: 656reset_next:
650 writel(HOST_CONTROL_RESET | HOST_CONTROL_CLOCK_EN 657 writel(HOST_CONTROL_RESET | HOST_CONTROL_CLOCK_EN
@@ -675,7 +682,7 @@ static int jmb38x_ms_set_param(struct memstick_host *msh,
675{ 682{
676 struct jmb38x_ms_host *host = memstick_priv(msh); 683 struct jmb38x_ms_host *host = memstick_priv(msh);
677 unsigned int host_ctl = readl(host->addr + HOST_CONTROL); 684 unsigned int host_ctl = readl(host->addr + HOST_CONTROL);
678 unsigned int clock_ctl = CLOCK_CONTROL_40MHZ, clock_delay = 0; 685 unsigned int clock_ctl = CLOCK_CONTROL_BY_MMIO, clock_delay = 0;
679 int rc = 0; 686 int rc = 0;
680 687
681 switch (param) { 688 switch (param) {
@@ -687,9 +694,7 @@ static int jmb38x_ms_set_param(struct memstick_host *msh,
687 694
688 host_ctl = 7; 695 host_ctl = 7;
689 host_ctl |= HOST_CONTROL_POWER_EN 696 host_ctl |= HOST_CONTROL_POWER_EN
690 | HOST_CONTROL_CLOCK_EN 697 | HOST_CONTROL_CLOCK_EN;
691 | HOST_CONTROL_HW_OC_P
692 | HOST_CONTROL_TDELAY_EN;
693 writel(host_ctl, host->addr + HOST_CONTROL); 698 writel(host_ctl, host->addr + HOST_CONTROL);
694 699
695 writel(host->id ? PAD_PU_PD_ON_MS_SOCK1 700 writel(host->id ? PAD_PU_PD_ON_MS_SOCK1
@@ -712,46 +717,88 @@ static int jmb38x_ms_set_param(struct memstick_host *msh,
712 return -EINVAL; 717 return -EINVAL;
713 break; 718 break;
714 case MEMSTICK_INTERFACE: 719 case MEMSTICK_INTERFACE:
720 dev_dbg(&host->chip->pdev->dev,
721 "Set Host Interface Mode to %d\n", value);
722 host_ctl &= ~(HOST_CONTROL_FAST_CLK | HOST_CONTROL_REI |
723 HOST_CONTROL_REO);
724 host_ctl |= HOST_CONTROL_TDELAY_EN | HOST_CONTROL_HW_OC_P;
715 host_ctl &= ~(3 << HOST_CONTROL_IF_SHIFT); 725 host_ctl &= ~(3 << HOST_CONTROL_IF_SHIFT);
716 pci_read_config_dword(host->chip->pdev,
717 PCI_CTL_CLOCK_DLY_ADDR,
718 &clock_delay);
719 clock_delay &= host->id ? ~PCI_CTL_CLOCK_DLY_MASK_B
720 : ~PCI_CTL_CLOCK_DLY_MASK_A;
721 726
722 if (value == MEMSTICK_SERIAL) { 727 if (value == MEMSTICK_SERIAL) {
723 host_ctl &= ~HOST_CONTROL_FAST_CLK;
724 host_ctl &= ~HOST_CONTROL_REO;
725 host_ctl |= HOST_CONTROL_IF_SERIAL 728 host_ctl |= HOST_CONTROL_IF_SERIAL
726 << HOST_CONTROL_IF_SHIFT; 729 << HOST_CONTROL_IF_SHIFT;
727 host_ctl |= HOST_CONTROL_REI; 730 host_ctl |= HOST_CONTROL_REI;
728 clock_ctl = CLOCK_CONTROL_40MHZ; 731 clock_ctl |= CLOCK_CONTROL_40MHZ;
732 clock_delay = 0;
729 } else if (value == MEMSTICK_PAR4) { 733 } else if (value == MEMSTICK_PAR4) {
730 host_ctl |= HOST_CONTROL_FAST_CLK | HOST_CONTROL_REO; 734 host_ctl |= HOST_CONTROL_FAST_CLK;
731 host_ctl |= HOST_CONTROL_IF_PAR4 735 host_ctl |= HOST_CONTROL_IF_PAR4
732 << HOST_CONTROL_IF_SHIFT; 736 << HOST_CONTROL_IF_SHIFT;
733 host_ctl &= ~HOST_CONTROL_REI; 737 host_ctl |= HOST_CONTROL_REO;
734 clock_ctl = CLOCK_CONTROL_40MHZ; 738 clock_ctl |= CLOCK_CONTROL_40MHZ;
735 clock_delay |= host->id ? (4 << 12) : (4 << 8); 739 clock_delay = 4;
736 } else if (value == MEMSTICK_PAR8) { 740 } else if (value == MEMSTICK_PAR8) {
737 host_ctl |= HOST_CONTROL_FAST_CLK; 741 host_ctl |= HOST_CONTROL_FAST_CLK;
738 host_ctl |= HOST_CONTROL_IF_PAR8 742 host_ctl |= HOST_CONTROL_IF_PAR8
739 << HOST_CONTROL_IF_SHIFT; 743 << HOST_CONTROL_IF_SHIFT;
740 host_ctl &= ~(HOST_CONTROL_REI | HOST_CONTROL_REO); 744 clock_ctl |= CLOCK_CONTROL_50MHZ;
741 clock_ctl = CLOCK_CONTROL_50MHZ; 745 clock_delay = 0;
742 } else 746 } else
743 return -EINVAL; 747 return -EINVAL;
744 748
745 writel(host_ctl, host->addr + HOST_CONTROL); 749 writel(host_ctl, host->addr + HOST_CONTROL);
750 writel(CLOCK_CONTROL_OFF, host->addr + CLOCK_CONTROL);
746 writel(clock_ctl, host->addr + CLOCK_CONTROL); 751 writel(clock_ctl, host->addr + CLOCK_CONTROL);
747 pci_write_config_dword(host->chip->pdev, 752 pci_write_config_byte(host->chip->pdev,
748 PCI_CTL_CLOCK_DLY_ADDR, 753 PCI_CTL_CLOCK_DLY_ADDR + 1,
749 clock_delay); 754 clock_delay);
755 host->ifmode = value;
750 break; 756 break;
751 }; 757 };
752 return 0; 758 return 0;
753} 759}
754 760
761#define PCI_PMOS0_CONTROL 0xae
762#define PMOS0_ENABLE 0x01
763#define PMOS0_OVERCURRENT_LEVEL_2_4V 0x06
764#define PMOS0_EN_OVERCURRENT_DEBOUNCE 0x40
765#define PMOS0_SW_LED_POLARITY_ENABLE 0x80
766#define PMOS0_ACTIVE_BITS (PMOS0_ENABLE | PMOS0_EN_OVERCURRENT_DEBOUNCE | \
767 PMOS0_OVERCURRENT_LEVEL_2_4V)
768#define PCI_PMOS1_CONTROL 0xbd
769#define PMOS1_ACTIVE_BITS 0x4a
770#define PCI_CLOCK_CTL 0xb9
771
772static int jmb38x_ms_pmos(struct pci_dev *pdev, int flag)
773{
774 unsigned char val;
775
776 pci_read_config_byte(pdev, PCI_PMOS0_CONTROL, &val);
777 if (flag)
778 val |= PMOS0_ACTIVE_BITS;
779 else
780 val &= ~PMOS0_ACTIVE_BITS;
781 pci_write_config_byte(pdev, PCI_PMOS0_CONTROL, val);
782 dev_dbg(&pdev->dev, "JMB38x: set PMOS0 val 0x%x\n", val);
783
784 if (pci_resource_flags(pdev, 1)) {
785 pci_read_config_byte(pdev, PCI_PMOS1_CONTROL, &val);
786 if (flag)
787 val |= PMOS1_ACTIVE_BITS;
788 else
789 val &= ~PMOS1_ACTIVE_BITS;
790 pci_write_config_byte(pdev, PCI_PMOS1_CONTROL, val);
791 dev_dbg(&pdev->dev, "JMB38x: set PMOS1 val 0x%x\n", val);
792 }
793
794 pci_read_config_byte(pdev, PCI_CLOCK_CTL, &val);
795 pci_write_config_byte(pdev, PCI_CLOCK_CTL, val & ~0x0f);
796 pci_write_config_byte(pdev, PCI_CLOCK_CTL, val | 0x01);
797 dev_dbg(&pdev->dev, "Clock Control by PCI config is disabled!\n");
798
799 return 0;
800}
801
755#ifdef CONFIG_PM 802#ifdef CONFIG_PM
756 803
757static int jmb38x_ms_suspend(struct pci_dev *dev, pm_message_t state) 804static int jmb38x_ms_suspend(struct pci_dev *dev, pm_message_t state)
@@ -784,8 +831,7 @@ static int jmb38x_ms_resume(struct pci_dev *dev)
784 return rc; 831 return rc;
785 pci_set_master(dev); 832 pci_set_master(dev);
786 833
787 pci_read_config_dword(dev, 0xac, &rc); 834 jmb38x_ms_pmos(dev, 1);
788 pci_write_config_dword(dev, 0xac, rc | 0x00470000);
789 835
790 for (rc = 0; rc < jm->host_cnt; ++rc) { 836 for (rc = 0; rc < jm->host_cnt; ++rc) {
791 if (!jm->hosts[rc]) 837 if (!jm->hosts[rc])
@@ -894,8 +940,7 @@ static int jmb38x_ms_probe(struct pci_dev *pdev,
894 goto err_out; 940 goto err_out;
895 } 941 }
896 942
897 pci_read_config_dword(pdev, 0xac, &rc); 943 jmb38x_ms_pmos(pdev, 1);
898 pci_write_config_dword(pdev, 0xac, rc | 0x00470000);
899 944
900 cnt = jmb38x_ms_count_slots(pdev); 945 cnt = jmb38x_ms_count_slots(pdev);
901 if (!cnt) { 946 if (!cnt) {
@@ -976,6 +1021,8 @@ static void jmb38x_ms_remove(struct pci_dev *dev)
976 jmb38x_ms_free_host(jm->hosts[cnt]); 1021 jmb38x_ms_free_host(jm->hosts[cnt]);
977 } 1022 }
978 1023
1024 jmb38x_ms_pmos(dev, 0);
1025
979 pci_set_drvdata(dev, NULL); 1026 pci_set_drvdata(dev, NULL);
980 pci_release_regions(dev); 1027 pci_release_regions(dev);
981 pci_disable_device(dev); 1028 pci_disable_device(dev);
@@ -983,8 +1030,9 @@ static void jmb38x_ms_remove(struct pci_dev *dev)
983} 1030}
984 1031
985static struct pci_device_id jmb38x_ms_id_tbl [] = { 1032static struct pci_device_id jmb38x_ms_id_tbl [] = {
986 { PCI_VENDOR_ID_JMICRON, PCI_DEVICE_ID_JMICRON_JMB38X_MS, PCI_ANY_ID, 1033 { PCI_VDEVICE(JMICRON, PCI_DEVICE_ID_JMICRON_JMB38X_MS) },
987 PCI_ANY_ID, 0, 0, 0 }, 1034 { PCI_VDEVICE(JMICRON, PCI_DEVICE_ID_JMICRON_JMB385_MS) },
1035 { PCI_VDEVICE(JMICRON, PCI_DEVICE_ID_JMICRON_JMB390_MS) },
988 { } 1036 { }
989}; 1037};
990 1038
diff --git a/drivers/message/fusion/lsi/mpi_log_sas.h b/drivers/message/fusion/lsi/mpi_log_sas.h
index 691620dbedd2..8b04810df469 100644
--- a/drivers/message/fusion/lsi/mpi_log_sas.h
+++ b/drivers/message/fusion/lsi/mpi_log_sas.h
@@ -268,7 +268,7 @@
268 268
269/* Compatibility Error : IR Disabled */ 269/* Compatibility Error : IR Disabled */
270#define IR_LOGINFO_COMPAT_ERROR_RAID_DISABLED (0x00010030) 270#define IR_LOGINFO_COMPAT_ERROR_RAID_DISABLED (0x00010030)
271/* Compatibility Error : Inquiry Comand failed */ 271/* Compatibility Error : Inquiry Command failed */
272#define IR_LOGINFO_COMPAT_ERROR_INQUIRY_FAILED (0x00010031) 272#define IR_LOGINFO_COMPAT_ERROR_INQUIRY_FAILED (0x00010031)
273/* Compatibility Error : Device not direct access device */ 273/* Compatibility Error : Device not direct access device */
274#define IR_LOGINFO_COMPAT_ERROR_NOT_DIRECT_ACCESS (0x00010032) 274#define IR_LOGINFO_COMPAT_ERROR_NOT_DIRECT_ACCESS (0x00010032)
diff --git a/drivers/message/fusion/mptbase.c b/drivers/message/fusion/mptbase.c
index 3e57b61ca446..3358c0af3466 100644
--- a/drivers/message/fusion/mptbase.c
+++ b/drivers/message/fusion/mptbase.c
@@ -7977,7 +7977,7 @@ mpt_spi_log_info(MPT_ADAPTER *ioc, u32 log_info)
7977 NULL, /* 2Eh */ 7977 NULL, /* 2Eh */
7978 NULL, /* 2Fh */ 7978 NULL, /* 2Fh */
7979 "Compatibility Error: IR Disabled", /* 30h */ 7979 "Compatibility Error: IR Disabled", /* 30h */
7980 "Compatibility Error: Inquiry Comand Failed", /* 31h */ 7980 "Compatibility Error: Inquiry Command Failed", /* 31h */
7981 "Compatibility Error: Device not Direct Access " 7981 "Compatibility Error: Device not Direct Access "
7982 "Device ", /* 32h */ 7982 "Device ", /* 32h */
7983 "Compatibility Error: Removable Device Found", /* 33h */ 7983 "Compatibility Error: Removable Device Found", /* 33h */
diff --git a/drivers/message/fusion/mptsas.c b/drivers/message/fusion/mptsas.c
index d48c2c6058e1..8aefb1829fcd 100644
--- a/drivers/message/fusion/mptsas.c
+++ b/drivers/message/fusion/mptsas.c
@@ -1146,7 +1146,7 @@ mptsas_target_reset_queue(MPT_ADAPTER *ioc,
1146 * 1146 *
1147 * This function will delete scheduled target reset from the list and 1147 * This function will delete scheduled target reset from the list and
1148 * try to send next target reset. This will be called from completion 1148 * try to send next target reset. This will be called from completion
1149 * context of any Task managment command. 1149 * context of any Task management command.
1150 */ 1150 */
1151 1151
1152void 1152void
diff --git a/drivers/message/i2o/i2o_block.c b/drivers/message/i2o/i2o_block.c
index f87a9d405a5e..ae7cad185898 100644
--- a/drivers/message/i2o/i2o_block.c
+++ b/drivers/message/i2o/i2o_block.c
@@ -309,7 +309,7 @@ static inline void i2o_block_request_free(struct i2o_block_request *ireq)
309 * @ireq: I2O block request 309 * @ireq: I2O block request
310 * @mptr: message body pointer 310 * @mptr: message body pointer
311 * 311 *
312 * Builds the SG list and map it to be accessable by the controller. 312 * Builds the SG list and map it to be accessible by the controller.
313 * 313 *
314 * Returns 0 on failure or 1 on success. 314 * Returns 0 on failure or 1 on success.
315 */ 315 */
diff --git a/drivers/mfd/wm8994-core.c b/drivers/mfd/wm8994-core.c
index b3b2aaf89dbe..8d221ba5e38d 100644
--- a/drivers/mfd/wm8994-core.c
+++ b/drivers/mfd/wm8994-core.c
@@ -218,6 +218,18 @@ static const char *wm8994_main_supplies[] = {
218 "SPKVDD2", 218 "SPKVDD2",
219}; 219};
220 220
221static const char *wm8958_main_supplies[] = {
222 "DBVDD1",
223 "DBVDD2",
224 "DBVDD3",
225 "DCVDD",
226 "AVDD1",
227 "AVDD2",
228 "CPVDD",
229 "SPKVDD1",
230 "SPKVDD2",
231};
232
221#ifdef CONFIG_PM 233#ifdef CONFIG_PM
222static int wm8994_device_suspend(struct device *dev) 234static int wm8994_device_suspend(struct device *dev)
223{ 235{
@@ -239,7 +251,7 @@ static int wm8994_device_suspend(struct device *dev)
239 if (ret < 0) 251 if (ret < 0)
240 dev_err(dev, "Failed to save LDO registers: %d\n", ret); 252 dev_err(dev, "Failed to save LDO registers: %d\n", ret);
241 253
242 ret = regulator_bulk_disable(ARRAY_SIZE(wm8994_main_supplies), 254 ret = regulator_bulk_disable(wm8994->num_supplies,
243 wm8994->supplies); 255 wm8994->supplies);
244 if (ret != 0) { 256 if (ret != 0) {
245 dev_err(dev, "Failed to disable supplies: %d\n", ret); 257 dev_err(dev, "Failed to disable supplies: %d\n", ret);
@@ -254,7 +266,7 @@ static int wm8994_device_resume(struct device *dev)
254 struct wm8994 *wm8994 = dev_get_drvdata(dev); 266 struct wm8994 *wm8994 = dev_get_drvdata(dev);
255 int ret; 267 int ret;
256 268
257 ret = regulator_bulk_enable(ARRAY_SIZE(wm8994_main_supplies), 269 ret = regulator_bulk_enable(wm8994->num_supplies,
258 wm8994->supplies); 270 wm8994->supplies);
259 if (ret != 0) { 271 if (ret != 0) {
260 dev_err(dev, "Failed to enable supplies: %d\n", ret); 272 dev_err(dev, "Failed to enable supplies: %d\n", ret);
@@ -305,9 +317,10 @@ static int wm8994_ldo_in_use(struct wm8994_pdata *pdata, int ldo)
305/* 317/*
306 * Instantiate the generic non-control parts of the device. 318 * Instantiate the generic non-control parts of the device.
307 */ 319 */
308static int wm8994_device_init(struct wm8994 *wm8994, unsigned long id, int irq) 320static int wm8994_device_init(struct wm8994 *wm8994, int irq)
309{ 321{
310 struct wm8994_pdata *pdata = wm8994->dev->platform_data; 322 struct wm8994_pdata *pdata = wm8994->dev->platform_data;
323 const char *devname;
311 int ret, i; 324 int ret, i;
312 325
313 mutex_init(&wm8994->io_lock); 326 mutex_init(&wm8994->io_lock);
@@ -323,25 +336,48 @@ static int wm8994_device_init(struct wm8994 *wm8994, unsigned long id, int irq)
323 goto err; 336 goto err;
324 } 337 }
325 338
339 switch (wm8994->type) {
340 case WM8994:
341 wm8994->num_supplies = ARRAY_SIZE(wm8994_main_supplies);
342 break;
343 case WM8958:
344 wm8994->num_supplies = ARRAY_SIZE(wm8958_main_supplies);
345 break;
346 default:
347 BUG();
348 return -EINVAL;
349 }
350
326 wm8994->supplies = kzalloc(sizeof(struct regulator_bulk_data) * 351 wm8994->supplies = kzalloc(sizeof(struct regulator_bulk_data) *
327 ARRAY_SIZE(wm8994_main_supplies), 352 wm8994->num_supplies,
328 GFP_KERNEL); 353 GFP_KERNEL);
329 if (!wm8994->supplies) { 354 if (!wm8994->supplies) {
330 ret = -ENOMEM; 355 ret = -ENOMEM;
331 goto err; 356 goto err;
332 } 357 }
333 358
334 for (i = 0; i < ARRAY_SIZE(wm8994_main_supplies); i++) 359 switch (wm8994->type) {
335 wm8994->supplies[i].supply = wm8994_main_supplies[i]; 360 case WM8994:
336 361 for (i = 0; i < ARRAY_SIZE(wm8994_main_supplies); i++)
337 ret = regulator_bulk_get(wm8994->dev, ARRAY_SIZE(wm8994_main_supplies), 362 wm8994->supplies[i].supply = wm8994_main_supplies[i];
363 break;
364 case WM8958:
365 for (i = 0; i < ARRAY_SIZE(wm8958_main_supplies); i++)
366 wm8994->supplies[i].supply = wm8958_main_supplies[i];
367 break;
368 default:
369 BUG();
370 return -EINVAL;
371 }
372
373 ret = regulator_bulk_get(wm8994->dev, wm8994->num_supplies,
338 wm8994->supplies); 374 wm8994->supplies);
339 if (ret != 0) { 375 if (ret != 0) {
340 dev_err(wm8994->dev, "Failed to get supplies: %d\n", ret); 376 dev_err(wm8994->dev, "Failed to get supplies: %d\n", ret);
341 goto err_supplies; 377 goto err_supplies;
342 } 378 }
343 379
344 ret = regulator_bulk_enable(ARRAY_SIZE(wm8994_main_supplies), 380 ret = regulator_bulk_enable(wm8994->num_supplies,
345 wm8994->supplies); 381 wm8994->supplies);
346 if (ret != 0) { 382 if (ret != 0) {
347 dev_err(wm8994->dev, "Failed to enable supplies: %d\n", ret); 383 dev_err(wm8994->dev, "Failed to enable supplies: %d\n", ret);
@@ -353,7 +389,22 @@ static int wm8994_device_init(struct wm8994 *wm8994, unsigned long id, int irq)
353 dev_err(wm8994->dev, "Failed to read ID register\n"); 389 dev_err(wm8994->dev, "Failed to read ID register\n");
354 goto err_enable; 390 goto err_enable;
355 } 391 }
356 if (ret != 0x8994) { 392 switch (ret) {
393 case 0x8994:
394 devname = "WM8994";
395 if (wm8994->type != WM8994)
396 dev_warn(wm8994->dev, "Device registered as type %d\n",
397 wm8994->type);
398 wm8994->type = WM8994;
399 break;
400 case 0x8958:
401 devname = "WM8958";
402 if (wm8994->type != WM8958)
403 dev_warn(wm8994->dev, "Device registered as type %d\n",
404 wm8994->type);
405 wm8994->type = WM8958;
406 break;
407 default:
357 dev_err(wm8994->dev, "Device is not a WM8994, ID is %x\n", 408 dev_err(wm8994->dev, "Device is not a WM8994, ID is %x\n",
358 ret); 409 ret);
359 ret = -EINVAL; 410 ret = -EINVAL;
@@ -370,14 +421,16 @@ static int wm8994_device_init(struct wm8994 *wm8994, unsigned long id, int irq)
370 switch (ret) { 421 switch (ret) {
371 case 0: 422 case 0:
372 case 1: 423 case 1:
373 dev_warn(wm8994->dev, "revision %c not fully supported\n", 424 if (wm8994->type == WM8994)
374 'A' + ret); 425 dev_warn(wm8994->dev,
426 "revision %c not fully supported\n",
427 'A' + ret);
375 break; 428 break;
376 default: 429 default:
377 dev_info(wm8994->dev, "revision %c\n", 'A' + ret);
378 break; 430 break;
379 } 431 }
380 432
433 dev_info(wm8994->dev, "%s revision %c\n", devname, 'A' + ret);
381 434
382 if (pdata) { 435 if (pdata) {
383 wm8994->irq_base = pdata->irq_base; 436 wm8994->irq_base = pdata->irq_base;
@@ -423,10 +476,10 @@ static int wm8994_device_init(struct wm8994 *wm8994, unsigned long id, int irq)
423err_irq: 476err_irq:
424 wm8994_irq_exit(wm8994); 477 wm8994_irq_exit(wm8994);
425err_enable: 478err_enable:
426 regulator_bulk_disable(ARRAY_SIZE(wm8994_main_supplies), 479 regulator_bulk_disable(wm8994->num_supplies,
427 wm8994->supplies); 480 wm8994->supplies);
428err_get: 481err_get:
429 regulator_bulk_free(ARRAY_SIZE(wm8994_main_supplies), wm8994->supplies); 482 regulator_bulk_free(wm8994->num_supplies, wm8994->supplies);
430err_supplies: 483err_supplies:
431 kfree(wm8994->supplies); 484 kfree(wm8994->supplies);
432err: 485err:
@@ -439,9 +492,9 @@ static void wm8994_device_exit(struct wm8994 *wm8994)
439{ 492{
440 mfd_remove_devices(wm8994->dev); 493 mfd_remove_devices(wm8994->dev);
441 wm8994_irq_exit(wm8994); 494 wm8994_irq_exit(wm8994);
442 regulator_bulk_disable(ARRAY_SIZE(wm8994_main_supplies), 495 regulator_bulk_disable(wm8994->num_supplies,
443 wm8994->supplies); 496 wm8994->supplies);
444 regulator_bulk_free(ARRAY_SIZE(wm8994_main_supplies), wm8994->supplies); 497 regulator_bulk_free(wm8994->num_supplies, wm8994->supplies);
445 kfree(wm8994->supplies); 498 kfree(wm8994->supplies);
446 kfree(wm8994); 499 kfree(wm8994);
447} 500}
@@ -506,8 +559,9 @@ static int wm8994_i2c_probe(struct i2c_client *i2c,
506 wm8994->read_dev = wm8994_i2c_read_device; 559 wm8994->read_dev = wm8994_i2c_read_device;
507 wm8994->write_dev = wm8994_i2c_write_device; 560 wm8994->write_dev = wm8994_i2c_write_device;
508 wm8994->irq = i2c->irq; 561 wm8994->irq = i2c->irq;
562 wm8994->type = id->driver_data;
509 563
510 return wm8994_device_init(wm8994, id->driver_data, i2c->irq); 564 return wm8994_device_init(wm8994, i2c->irq);
511} 565}
512 566
513static int wm8994_i2c_remove(struct i2c_client *i2c) 567static int wm8994_i2c_remove(struct i2c_client *i2c)
@@ -535,7 +589,8 @@ static int wm8994_i2c_resume(struct i2c_client *i2c)
535#endif 589#endif
536 590
537static const struct i2c_device_id wm8994_i2c_id[] = { 591static const struct i2c_device_id wm8994_i2c_id[] = {
538 { "wm8994", 0 }, 592 { "wm8994", WM8994 },
593 { "wm8958", WM8958 },
539 { } 594 { }
540}; 595};
541MODULE_DEVICE_TABLE(i2c, wm8994_i2c_id); 596MODULE_DEVICE_TABLE(i2c, wm8994_i2c_id);
diff --git a/drivers/misc/Kconfig b/drivers/misc/Kconfig
index 4d073f1e4502..1e1a4be8eb6c 100644
--- a/drivers/misc/Kconfig
+++ b/drivers/misc/Kconfig
@@ -402,7 +402,7 @@ config TI_DAC7512
402 DAC7512 16-bit digital-to-analog converter. 402 DAC7512 16-bit digital-to-analog converter.
403 403
404 This driver can also be built as a module. If so, the module 404 This driver can also be built as a module. If so, the module
405 will be calles ti_dac7512. 405 will be called ti_dac7512.
406 406
407config VMWARE_BALLOON 407config VMWARE_BALLOON
408 tristate "VMware Balloon Driver" 408 tristate "VMware Balloon Driver"
diff --git a/drivers/misc/arm-charlcd.c b/drivers/misc/arm-charlcd.c
index 9e3879ef58f2..fe8616a8d287 100644
--- a/drivers/misc/arm-charlcd.c
+++ b/drivers/misc/arm-charlcd.c
@@ -313,7 +313,7 @@ static int __init charlcd_probe(struct platform_device *pdev)
313 INIT_DELAYED_WORK(&lcd->init_work, charlcd_init_work); 313 INIT_DELAYED_WORK(&lcd->init_work, charlcd_init_work);
314 schedule_delayed_work(&lcd->init_work, 0); 314 schedule_delayed_work(&lcd->init_work, 0);
315 315
316 dev_info(&pdev->dev, "initalized ARM character LCD at %08x\n", 316 dev_info(&pdev->dev, "initialized ARM character LCD at %08x\n",
317 lcd->phybase); 317 lcd->phybase);
318 318
319 return 0; 319 return 0;
diff --git a/drivers/misc/vmw_balloon.c b/drivers/misc/vmw_balloon.c
index 2a1e804a71aa..4d2ea8e80140 100644
--- a/drivers/misc/vmw_balloon.c
+++ b/drivers/misc/vmw_balloon.c
@@ -45,7 +45,7 @@
45 45
46MODULE_AUTHOR("VMware, Inc."); 46MODULE_AUTHOR("VMware, Inc.");
47MODULE_DESCRIPTION("VMware Memory Control (Balloon) Driver"); 47MODULE_DESCRIPTION("VMware Memory Control (Balloon) Driver");
48MODULE_VERSION("1.2.1.1-k"); 48MODULE_VERSION("1.2.1.2-k");
49MODULE_ALIAS("dmi:*:svnVMware*:*"); 49MODULE_ALIAS("dmi:*:svnVMware*:*");
50MODULE_ALIAS("vmware_vmmemctl"); 50MODULE_ALIAS("vmware_vmmemctl");
51MODULE_LICENSE("GPL"); 51MODULE_LICENSE("GPL");
@@ -315,7 +315,8 @@ static bool vmballoon_send_get_target(struct vmballoon *b, u32 *new_target)
315 * fear that guest will need it. Host may reject some pages, we need to 315 * fear that guest will need it. Host may reject some pages, we need to
316 * check the return value and maybe submit a different page. 316 * check the return value and maybe submit a different page.
317 */ 317 */
318static bool vmballoon_send_lock_page(struct vmballoon *b, unsigned long pfn) 318static bool vmballoon_send_lock_page(struct vmballoon *b, unsigned long pfn,
319 unsigned int *hv_status)
319{ 320{
320 unsigned long status, dummy; 321 unsigned long status, dummy;
321 u32 pfn32; 322 u32 pfn32;
@@ -326,7 +327,7 @@ static bool vmballoon_send_lock_page(struct vmballoon *b, unsigned long pfn)
326 327
327 STATS_INC(b->stats.lock); 328 STATS_INC(b->stats.lock);
328 329
329 status = VMWARE_BALLOON_CMD(LOCK, pfn, dummy); 330 *hv_status = status = VMWARE_BALLOON_CMD(LOCK, pfn, dummy);
330 if (vmballoon_check_status(b, status)) 331 if (vmballoon_check_status(b, status))
331 return true; 332 return true;
332 333
@@ -410,6 +411,7 @@ static int vmballoon_reserve_page(struct vmballoon *b, bool can_sleep)
410{ 411{
411 struct page *page; 412 struct page *page;
412 gfp_t flags; 413 gfp_t flags;
414 unsigned int hv_status;
413 bool locked = false; 415 bool locked = false;
414 416
415 do { 417 do {
@@ -429,11 +431,12 @@ static int vmballoon_reserve_page(struct vmballoon *b, bool can_sleep)
429 } 431 }
430 432
431 /* inform monitor */ 433 /* inform monitor */
432 locked = vmballoon_send_lock_page(b, page_to_pfn(page)); 434 locked = vmballoon_send_lock_page(b, page_to_pfn(page), &hv_status);
433 if (!locked) { 435 if (!locked) {
434 STATS_INC(b->stats.refused_alloc); 436 STATS_INC(b->stats.refused_alloc);
435 437
436 if (b->reset_required) { 438 if (hv_status == VMW_BALLOON_ERROR_RESET ||
439 hv_status == VMW_BALLOON_ERROR_PPN_NOTNEEDED) {
437 __free_page(page); 440 __free_page(page);
438 return -EIO; 441 return -EIO;
439 } 442 }
diff --git a/drivers/mmc/card/block.c b/drivers/mmc/card/block.c
index 217f82037fc1..bfc8a8ae55df 100644
--- a/drivers/mmc/card/block.c
+++ b/drivers/mmc/card/block.c
@@ -257,7 +257,7 @@ static u32 get_card_status(struct mmc_card *card, struct request *req)
257 cmd.flags = MMC_RSP_SPI_R2 | MMC_RSP_R1 | MMC_CMD_AC; 257 cmd.flags = MMC_RSP_SPI_R2 | MMC_RSP_R1 | MMC_CMD_AC;
258 err = mmc_wait_for_cmd(card->host, &cmd, 0); 258 err = mmc_wait_for_cmd(card->host, &cmd, 0);
259 if (err) 259 if (err)
260 printk(KERN_ERR "%s: error %d sending status comand", 260 printk(KERN_ERR "%s: error %d sending status command",
261 req->rq_disk->disk_name, err); 261 req->rq_disk->disk_name, err);
262 return cmd.resp[0]; 262 return cmd.resp[0];
263} 263}
diff --git a/drivers/mmc/host/Kconfig b/drivers/mmc/host/Kconfig
index c22a4c039988..afe8c6fa166a 100644
--- a/drivers/mmc/host/Kconfig
+++ b/drivers/mmc/host/Kconfig
@@ -501,7 +501,7 @@ config MMC_SH_MMCIF
501 tristate "SuperH Internal MMCIF support" 501 tristate "SuperH Internal MMCIF support"
502 depends on MMC_BLOCK && (SUPERH || ARCH_SHMOBILE) 502 depends on MMC_BLOCK && (SUPERH || ARCH_SHMOBILE)
503 help 503 help
504 This selects the MMC Host Interface controler (MMCIF). 504 This selects the MMC Host Interface controller (MMCIF).
505 505
506 This driver supports MMCIF in sh7724/sh7757/sh7372. 506 This driver supports MMCIF in sh7724/sh7757/sh7372.
507 507
diff --git a/drivers/mmc/host/au1xmmc.c b/drivers/mmc/host/au1xmmc.c
index 41e5a60493ad..ef72e874ca36 100644
--- a/drivers/mmc/host/au1xmmc.c
+++ b/drivers/mmc/host/au1xmmc.c
@@ -192,7 +192,7 @@ static inline void SEND_STOP(struct au1xmmc_host *host)
192 au_writel(config2 | SD_CONFIG2_DF, HOST_CONFIG2(host)); 192 au_writel(config2 | SD_CONFIG2_DF, HOST_CONFIG2(host));
193 au_sync(); 193 au_sync();
194 194
195 /* Send the stop commmand */ 195 /* Send the stop command */
196 au_writel(STOP_CMD, HOST_CMD(host)); 196 au_writel(STOP_CMD, HOST_CMD(host));
197} 197}
198 198
diff --git a/drivers/mmc/host/sdricoh_cs.c b/drivers/mmc/host/sdricoh_cs.c
index f472c2714eb8..bbc298fd2a15 100644
--- a/drivers/mmc/host/sdricoh_cs.c
+++ b/drivers/mmc/host/sdricoh_cs.c
@@ -446,7 +446,7 @@ static int sdricoh_init_mmc(struct pci_dev *pci_dev,
446 mmc->max_seg_size = 1024 * 512; 446 mmc->max_seg_size = 1024 * 512;
447 mmc->max_blk_size = 512; 447 mmc->max_blk_size = 512;
448 448
449 /* reset the controler */ 449 /* reset the controller */
450 if (sdricoh_reset(host)) { 450 if (sdricoh_reset(host)) {
451 dev_dbg(dev, "could not reset\n"); 451 dev_dbg(dev, "could not reset\n");
452 result = -EIO; 452 result = -EIO;
@@ -478,7 +478,7 @@ static int sdricoh_pcmcia_probe(struct pcmcia_device *pcmcia_dev)
478 dev_info(&pcmcia_dev->dev, "Searching MMC controller for pcmcia device" 478 dev_info(&pcmcia_dev->dev, "Searching MMC controller for pcmcia device"
479 " %s %s ...\n", pcmcia_dev->prod_id[0], pcmcia_dev->prod_id[1]); 479 " %s %s ...\n", pcmcia_dev->prod_id[0], pcmcia_dev->prod_id[1]);
480 480
481 /* search pci cardbus bridge that contains the mmc controler */ 481 /* search pci cardbus bridge that contains the mmc controller */
482 /* the io region is already claimed by yenta_socket... */ 482 /* the io region is already claimed by yenta_socket... */
483 while ((pci_dev = 483 while ((pci_dev =
484 pci_get_device(PCI_VENDOR_ID_RICOH, PCI_DEVICE_ID_RICOH_RL5C476, 484 pci_get_device(PCI_VENDOR_ID_RICOH, PCI_DEVICE_ID_RICOH_RL5C476,
diff --git a/drivers/mtd/mtdchar.c b/drivers/mtd/mtdchar.c
index f511dd15fd31..ee4bb3330bdf 100644
--- a/drivers/mtd/mtdchar.c
+++ b/drivers/mtd/mtdchar.c
@@ -1134,7 +1134,7 @@ static const struct file_operations mtd_fops = {
1134static struct dentry *mtd_inodefs_mount(struct file_system_type *fs_type, 1134static struct dentry *mtd_inodefs_mount(struct file_system_type *fs_type,
1135 int flags, const char *dev_name, void *data) 1135 int flags, const char *dev_name, void *data)
1136{ 1136{
1137 return mount_pseudo(fs_type, "mtd_inode:", NULL, MTD_INODE_FS_MAGIC); 1137 return mount_pseudo(fs_type, "mtd_inode:", NULL, NULL, MTD_INODE_FS_MAGIC);
1138} 1138}
1139 1139
1140static struct file_system_type mtd_inodefs_type = { 1140static struct file_system_type mtd_inodefs_type = {
diff --git a/drivers/mtd/mtdoops.c b/drivers/mtd/mtdoops.c
index 1ee72f3f0512..c948150079be 100644
--- a/drivers/mtd/mtdoops.c
+++ b/drivers/mtd/mtdoops.c
@@ -307,6 +307,11 @@ static void mtdoops_do_dump(struct kmsg_dumper *dumper,
307 unsigned long l1_cpy, l2_cpy; 307 unsigned long l1_cpy, l2_cpy;
308 char *dst; 308 char *dst;
309 309
310 if (reason != KMSG_DUMP_OOPS &&
311 reason != KMSG_DUMP_PANIC &&
312 reason != KMSG_DUMP_KEXEC)
313 return;
314
310 /* Only dump oopses if dump_oops is set */ 315 /* Only dump oopses if dump_oops is set */
311 if (reason == KMSG_DUMP_OOPS && !dump_oops) 316 if (reason == KMSG_DUMP_OOPS && !dump_oops)
312 return; 317 return;
diff --git a/drivers/mtd/nand/nand_base.c b/drivers/mtd/nand/nand_base.c
index 1f75a1b1f7c3..31bf376b82a0 100644
--- a/drivers/mtd/nand/nand_base.c
+++ b/drivers/mtd/nand/nand_base.c
@@ -821,7 +821,7 @@ retry:
821 * 821 *
822 * Wait for command done. This is a helper function for nand_wait used when 822 * Wait for command done. This is a helper function for nand_wait used when
823 * we are in interrupt context. May happen when in panic and trying to write 823 * we are in interrupt context. May happen when in panic and trying to write
824 * an oops trough mtdoops. 824 * an oops through mtdoops.
825 */ 825 */
826static void panic_nand_wait(struct mtd_info *mtd, struct nand_chip *chip, 826static void panic_nand_wait(struct mtd_info *mtd, struct nand_chip *chip,
827 unsigned long timeo) 827 unsigned long timeo)
diff --git a/drivers/net/bnx2x/bnx2x.h b/drivers/net/bnx2x/bnx2x.h
index 6a858a29db56..a6cd335c9436 100644
--- a/drivers/net/bnx2x/bnx2x.h
+++ b/drivers/net/bnx2x/bnx2x.h
@@ -1415,12 +1415,12 @@ struct bnx2x_func_init_params {
1415 else 1415 else
1416 1416
1417/* skip rx queue 1417/* skip rx queue
1418 * if FCOE l2 support is diabled and this is the fcoe L2 queue 1418 * if FCOE l2 support is disabled and this is the fcoe L2 queue
1419 */ 1419 */
1420#define skip_rx_queue(bp, idx) (NO_FCOE(bp) && IS_FCOE_IDX(idx)) 1420#define skip_rx_queue(bp, idx) (NO_FCOE(bp) && IS_FCOE_IDX(idx))
1421 1421
1422/* skip tx queue 1422/* skip tx queue
1423 * if FCOE l2 support is diabled and this is the fcoe L2 queue 1423 * if FCOE l2 support is disabled and this is the fcoe L2 queue
1424 */ 1424 */
1425#define skip_tx_queue(bp, idx) (NO_FCOE(bp) && IS_FCOE_IDX(idx)) 1425#define skip_tx_queue(bp, idx) (NO_FCOE(bp) && IS_FCOE_IDX(idx))
1426 1426
diff --git a/drivers/net/bnx2x/bnx2x_main.c b/drivers/net/bnx2x/bnx2x_main.c
index 84e1af4d65e1..8cdcf5b39d1e 100644
--- a/drivers/net/bnx2x/bnx2x_main.c
+++ b/drivers/net/bnx2x/bnx2x_main.c
@@ -5037,7 +5037,7 @@ static int bnx2x_init_hw_common(struct bnx2x *bp, u32 load_code)
5037 memset(&ilt_cli, 0, sizeof(struct ilt_client_info)); 5037 memset(&ilt_cli, 0, sizeof(struct ilt_client_info));
5038 memset(&ilt, 0, sizeof(struct bnx2x_ilt)); 5038 memset(&ilt, 0, sizeof(struct bnx2x_ilt));
5039 5039
5040 /* initalize dummy TM client */ 5040 /* initialize dummy TM client */
5041 ilt_cli.start = 0; 5041 ilt_cli.start = 0;
5042 ilt_cli.end = ILT_NUM_PAGE_ENTRIES - 1; 5042 ilt_cli.end = ILT_NUM_PAGE_ENTRIES - 1;
5043 ilt_cli.client_num = ILT_CLIENT_TM; 5043 ilt_cli.client_num = ILT_CLIENT_TM;
diff --git a/drivers/net/bnx2x/bnx2x_reg.h b/drivers/net/bnx2x/bnx2x_reg.h
index 38ef7ca9f21d..c939683e3d61 100644
--- a/drivers/net/bnx2x/bnx2x_reg.h
+++ b/drivers/net/bnx2x/bnx2x_reg.h
@@ -1633,7 +1633,7 @@
1633 (~misc_registers_sw_timer_cfg_4.sw_timer_cfg_4[1] ) is set */ 1633 (~misc_registers_sw_timer_cfg_4.sw_timer_cfg_4[1] ) is set */
1634#define MISC_REG_SW_TIMER_RELOAD_VAL_4 0xa2fc 1634#define MISC_REG_SW_TIMER_RELOAD_VAL_4 0xa2fc
1635/* [RW 32] the value of the counter for sw timers1-8. there are 8 addresses 1635/* [RW 32] the value of the counter for sw timers1-8. there are 8 addresses
1636 in this register. addres 0 - timer 1; address 1 - timer 2, ... address 7 - 1636 in this register. address 0 - timer 1; address 1 - timer 2, ... address 7 -
1637 timer 8 */ 1637 timer 8 */
1638#define MISC_REG_SW_TIMER_VAL 0xa5c0 1638#define MISC_REG_SW_TIMER_VAL 0xa5c0
1639/* [RW 1] Set by the MCP to remember if one or more of the drivers is/are 1639/* [RW 1] Set by the MCP to remember if one or more of the drivers is/are
diff --git a/drivers/net/bonding/bond_3ad.c b/drivers/net/bonding/bond_3ad.c
index 48cf24ff4e6f..171782e2bb39 100644
--- a/drivers/net/bonding/bond_3ad.c
+++ b/drivers/net/bonding/bond_3ad.c
@@ -840,7 +840,7 @@ static int ad_lacpdu_send(struct port *port)
840 lacpdu_header = (struct lacpdu_header *)skb_put(skb, length); 840 lacpdu_header = (struct lacpdu_header *)skb_put(skb, length);
841 841
842 memcpy(lacpdu_header->hdr.h_dest, lacpdu_mcast_addr, ETH_ALEN); 842 memcpy(lacpdu_header->hdr.h_dest, lacpdu_mcast_addr, ETH_ALEN);
843 /* Note: source addres is set to be the member's PERMANENT address, 843 /* Note: source address is set to be the member's PERMANENT address,
844 because we use it to identify loopback lacpdus in receive. */ 844 because we use it to identify loopback lacpdus in receive. */
845 memcpy(lacpdu_header->hdr.h_source, slave->perm_hwaddr, ETH_ALEN); 845 memcpy(lacpdu_header->hdr.h_source, slave->perm_hwaddr, ETH_ALEN);
846 lacpdu_header->hdr.h_proto = PKT_TYPE_LACPDU; 846 lacpdu_header->hdr.h_proto = PKT_TYPE_LACPDU;
@@ -881,7 +881,7 @@ static int ad_marker_send(struct port *port, struct bond_marker *marker)
881 marker_header = (struct bond_marker_header *)skb_put(skb, length); 881 marker_header = (struct bond_marker_header *)skb_put(skb, length);
882 882
883 memcpy(marker_header->hdr.h_dest, lacpdu_mcast_addr, ETH_ALEN); 883 memcpy(marker_header->hdr.h_dest, lacpdu_mcast_addr, ETH_ALEN);
884 /* Note: source addres is set to be the member's PERMANENT address, 884 /* Note: source address is set to be the member's PERMANENT address,
885 because we use it to identify loopback MARKERs in receive. */ 885 because we use it to identify loopback MARKERs in receive. */
886 memcpy(marker_header->hdr.h_source, slave->perm_hwaddr, ETH_ALEN); 886 memcpy(marker_header->hdr.h_source, slave->perm_hwaddr, ETH_ALEN);
887 marker_header->hdr.h_proto = PKT_TYPE_LACPDU; 887 marker_header->hdr.h_proto = PKT_TYPE_LACPDU;
@@ -1916,7 +1916,7 @@ int bond_3ad_bind_slave(struct slave *slave)
1916 return -1; 1916 return -1;
1917 } 1917 }
1918 1918
1919 //check that the slave has not been intialized yet. 1919 //check that the slave has not been initialized yet.
1920 if (SLAVE_AD_INFO(slave).port.slave != slave) { 1920 if (SLAVE_AD_INFO(slave).port.slave != slave) {
1921 1921
1922 // port initialization 1922 // port initialization
diff --git a/drivers/net/chelsio/subr.c b/drivers/net/chelsio/subr.c
index 63ebf76d2390..8a43c7e19701 100644
--- a/drivers/net/chelsio/subr.c
+++ b/drivers/net/chelsio/subr.c
@@ -556,7 +556,7 @@ struct chelsio_vpd_t {
556#define EEPROM_MAX_POLL 4 556#define EEPROM_MAX_POLL 4
557 557
558/* 558/*
559 * Read SEEPROM. A zero is written to the flag register when the addres is 559 * Read SEEPROM. A zero is written to the flag register when the address is
560 * written to the Control register. The hardware device will set the flag to a 560 * written to the Control register. The hardware device will set the flag to a
561 * one when 4B have been transferred to the Data register. 561 * one when 4B have been transferred to the Data register.
562 */ 562 */
diff --git a/drivers/net/cxgb3/mc5.c b/drivers/net/cxgb3/mc5.c
index a8766fb2f9ab..e13b7fe9d082 100644
--- a/drivers/net/cxgb3/mc5.c
+++ b/drivers/net/cxgb3/mc5.c
@@ -318,7 +318,7 @@ static void mc5_dbgi_mode_disable(const struct mc5 *mc5)
318 318
319/* 319/*
320 * Initialization that requires the OS and protocol layers to already 320 * Initialization that requires the OS and protocol layers to already
321 * be intialized goes here. 321 * be initialized goes here.
322 */ 322 */
323int t3_mc5_init(struct mc5 *mc5, unsigned int nservers, unsigned int nfilters, 323int t3_mc5_init(struct mc5 *mc5, unsigned int nservers, unsigned int nfilters,
324 unsigned int nroutes) 324 unsigned int nroutes)
diff --git a/drivers/net/cxgb3/t3_hw.c b/drivers/net/cxgb3/t3_hw.c
index ec8579a0a808..d55db6b38e7b 100644
--- a/drivers/net/cxgb3/t3_hw.c
+++ b/drivers/net/cxgb3/t3_hw.c
@@ -607,7 +607,7 @@ struct t3_vpd {
607 * 607 *
608 * Read a 32-bit word from a location in VPD EEPROM using the card's PCI 608 * Read a 32-bit word from a location in VPD EEPROM using the card's PCI
609 * VPD ROM capability. A zero is written to the flag bit when the 609 * VPD ROM capability. A zero is written to the flag bit when the
610 * addres is written to the control register. The hardware device will 610 * address is written to the control register. The hardware device will
611 * set the flag to 1 when 4 bytes have been read into the data register. 611 * set the flag to 1 when 4 bytes have been read into the data register.
612 */ 612 */
613int t3_seeprom_read(struct adapter *adapter, u32 addr, __le32 *data) 613int t3_seeprom_read(struct adapter *adapter, u32 addr, __le32 *data)
diff --git a/drivers/net/e1000/e1000_hw.h b/drivers/net/e1000/e1000_hw.h
index f5514a0d5be6..196eeda2dd6c 100644
--- a/drivers/net/e1000/e1000_hw.h
+++ b/drivers/net/e1000/e1000_hw.h
@@ -41,7 +41,7 @@ struct e1000_hw;
41struct e1000_hw_stats; 41struct e1000_hw_stats;
42 42
43/* Enumerated types specific to the e1000 hardware */ 43/* Enumerated types specific to the e1000 hardware */
44/* Media Access Controlers */ 44/* Media Access Controllers */
45typedef enum { 45typedef enum {
46 e1000_undefined = 0, 46 e1000_undefined = 0,
47 e1000_82542_rev2_0, 47 e1000_82542_rev2_0,
diff --git a/drivers/net/e1000/e1000_main.c b/drivers/net/e1000/e1000_main.c
index 4ff88a683f61..de69c54301c1 100644
--- a/drivers/net/e1000/e1000_main.c
+++ b/drivers/net/e1000/e1000_main.c
@@ -2233,7 +2233,7 @@ static void e1000_set_rx_mode(struct net_device *netdev)
2233 * addresses take precedence to avoid disabling unicast filtering 2233 * addresses take precedence to avoid disabling unicast filtering
2234 * when possible. 2234 * when possible.
2235 * 2235 *
2236 * RAR 0 is used for the station MAC adddress 2236 * RAR 0 is used for the station MAC address
2237 * if there are not 14 addresses, go ahead and clear the filters 2237 * if there are not 14 addresses, go ahead and clear the filters
2238 */ 2238 */
2239 i = 1; 2239 i = 1;
diff --git a/drivers/net/e1000e/82571.c b/drivers/net/e1000e/82571.c
index cb6c7b1c1fb8..1397da118f0d 100644
--- a/drivers/net/e1000e/82571.c
+++ b/drivers/net/e1000e/82571.c
@@ -328,7 +328,7 @@ static s32 e1000_init_mac_params_82571(struct e1000_adapter *adapter)
328 328
329 /* 329 /*
330 * Ensure that the inter-port SWSM.SMBI lock bit is clear before 330 * Ensure that the inter-port SWSM.SMBI lock bit is clear before
331 * first NVM or PHY acess. This should be done for single-port 331 * first NVM or PHY access. This should be done for single-port
332 * devices, and for one port only on dual-port devices so that 332 * devices, and for one port only on dual-port devices so that
333 * for those devices we can still use the SMBI lock to synchronize 333 * for those devices we can still use the SMBI lock to synchronize
334 * inter-port accesses to the PHY & NVM. 334 * inter-port accesses to the PHY & NVM.
diff --git a/drivers/net/e1000e/ich8lan.c b/drivers/net/e1000e/ich8lan.c
index 5328a2927731..5bb65b7382db 100644
--- a/drivers/net/e1000e/ich8lan.c
+++ b/drivers/net/e1000e/ich8lan.c
@@ -321,7 +321,7 @@ static s32 e1000_init_phy_params_pchlan(struct e1000_hw *hw)
321 } 321 }
322 322
323 /* 323 /*
324 * Reset the PHY before any acccess to it. Doing so, ensures that 324 * Reset the PHY before any access to it. Doing so, ensures that
325 * the PHY is in a known good state before we read/write PHY registers. 325 * the PHY is in a known good state before we read/write PHY registers.
326 * The generic reset is sufficient here, because we haven't determined 326 * The generic reset is sufficient here, because we haven't determined
327 * the PHY type yet. 327 * the PHY type yet.
diff --git a/drivers/net/e1000e/phy.c b/drivers/net/e1000e/phy.c
index a640f1c369ae..00f89e8a9fa0 100644
--- a/drivers/net/e1000e/phy.c
+++ b/drivers/net/e1000e/phy.c
@@ -2986,7 +2986,7 @@ s32 e1000_write_phy_reg_hv_locked(struct e1000_hw *hw, u32 offset, u16 data)
2986} 2986}
2987 2987
2988/** 2988/**
2989 * e1000_get_phy_addr_for_hv_page - Get PHY adrress based on page 2989 * e1000_get_phy_addr_for_hv_page - Get PHY address based on page
2990 * @page: page to be accessed 2990 * @page: page to be accessed
2991 **/ 2991 **/
2992static u32 e1000_get_phy_addr_for_hv_page(u32 page) 2992static u32 e1000_get_phy_addr_for_hv_page(u32 page)
diff --git a/drivers/net/eepro.c b/drivers/net/eepro.c
index 4fa8d2a4aef3..eb35951a2442 100644
--- a/drivers/net/eepro.c
+++ b/drivers/net/eepro.c
@@ -1761,7 +1761,7 @@ module_param_array(io, int, NULL, 0);
1761module_param_array(irq, int, NULL, 0); 1761module_param_array(irq, int, NULL, 0);
1762module_param_array(mem, int, NULL, 0); 1762module_param_array(mem, int, NULL, 0);
1763module_param(autodetect, int, 0); 1763module_param(autodetect, int, 0);
1764MODULE_PARM_DESC(io, "EtherExpress Pro/10 I/O base addres(es)"); 1764MODULE_PARM_DESC(io, "EtherExpress Pro/10 I/O base address(es)");
1765MODULE_PARM_DESC(irq, "EtherExpress Pro/10 IRQ number(s)"); 1765MODULE_PARM_DESC(irq, "EtherExpress Pro/10 IRQ number(s)");
1766MODULE_PARM_DESC(mem, "EtherExpress Pro/10 Rx buffer size(es) in kB (3-29)"); 1766MODULE_PARM_DESC(mem, "EtherExpress Pro/10 Rx buffer size(es) in kB (3-29)");
1767MODULE_PARM_DESC(autodetect, "EtherExpress Pro/10 force board(s) detection (0-1)"); 1767MODULE_PARM_DESC(autodetect, "EtherExpress Pro/10 force board(s) detection (0-1)");
diff --git a/drivers/net/irda/donauboe.h b/drivers/net/irda/donauboe.h
index 4dc39e5f0156..77fcf4459161 100644
--- a/drivers/net/irda/donauboe.h
+++ b/drivers/net/irda/donauboe.h
@@ -30,7 +30,7 @@
30 * or the type-DO IR port. 30 * or the type-DO IR port.
31 * 31 *
32 * IrDA chip set list from Toshiba Computer Engineering Corp. 32 * IrDA chip set list from Toshiba Computer Engineering Corp.
33 * model method maker controler Version 33 * model method maker controller Version
34 * Portege 320CT FIR,SIR Toshiba Oboe(Triangle) 34 * Portege 320CT FIR,SIR Toshiba Oboe(Triangle)
35 * Portege 3010CT FIR,SIR Toshiba Oboe(Sydney) 35 * Portege 3010CT FIR,SIR Toshiba Oboe(Sydney)
36 * Portege 3015CT FIR,SIR Toshiba Oboe(Sydney) 36 * Portege 3015CT FIR,SIR Toshiba Oboe(Sydney)
diff --git a/drivers/net/ixgbe/ixgbe_82599.c b/drivers/net/ixgbe/ixgbe_82599.c
index 8d316d9cd29d..a21f5817685b 100644
--- a/drivers/net/ixgbe/ixgbe_82599.c
+++ b/drivers/net/ixgbe/ixgbe_82599.c
@@ -1079,7 +1079,7 @@ s32 ixgbe_init_fdir_signature_82599(struct ixgbe_hw *hw, u32 pballoc)
1079 1079
1080 /* 1080 /*
1081 * The defaults in the HW for RX PB 1-7 are not zero and so should be 1081 * The defaults in the HW for RX PB 1-7 are not zero and so should be
1082 * intialized to zero for non DCB mode otherwise actual total RX PB 1082 * initialized to zero for non DCB mode otherwise actual total RX PB
1083 * would be bigger than programmed and filter space would run into 1083 * would be bigger than programmed and filter space would run into
1084 * the PB 0 region. 1084 * the PB 0 region.
1085 */ 1085 */
@@ -1167,7 +1167,7 @@ s32 ixgbe_init_fdir_perfect_82599(struct ixgbe_hw *hw, u32 pballoc)
1167 1167
1168 /* 1168 /*
1169 * The defaults in the HW for RX PB 1-7 are not zero and so should be 1169 * The defaults in the HW for RX PB 1-7 are not zero and so should be
1170 * intialized to zero for non DCB mode otherwise actual total RX PB 1170 * initialized to zero for non DCB mode otherwise actual total RX PB
1171 * would be bigger than programmed and filter space would run into 1171 * would be bigger than programmed and filter space would run into
1172 * the PB 0 region. 1172 * the PB 0 region.
1173 */ 1173 */
diff --git a/drivers/net/ll_temac_main.c b/drivers/net/ll_temac_main.c
index 183765cb7f25..f35554d11441 100644
--- a/drivers/net/ll_temac_main.c
+++ b/drivers/net/ll_temac_main.c
@@ -238,7 +238,7 @@ static int temac_dma_bd_init(struct net_device *ndev)
238 goto out; 238 goto out;
239 } 239 }
240 /* allocate the tx and rx ring buffer descriptors. */ 240 /* allocate the tx and rx ring buffer descriptors. */
241 /* returns a virtual addres and a physical address. */ 241 /* returns a virtual address and a physical address. */
242 lp->tx_bd_v = dma_alloc_coherent(ndev->dev.parent, 242 lp->tx_bd_v = dma_alloc_coherent(ndev->dev.parent,
243 sizeof(*lp->tx_bd_v) * TX_BD_NUM, 243 sizeof(*lp->tx_bd_v) * TX_BD_NUM,
244 &lp->tx_bd_p, GFP_KERNEL); 244 &lp->tx_bd_p, GFP_KERNEL);
diff --git a/drivers/net/sis900.c b/drivers/net/sis900.c
index 581836867098..5976d1d51df1 100644
--- a/drivers/net/sis900.c
+++ b/drivers/net/sis900.c
@@ -36,7 +36,7 @@
36 Rev 1.07.06 Nov. 7 2000 Jeff Garzik <jgarzik@pobox.com> some bug fix and cleaning 36 Rev 1.07.06 Nov. 7 2000 Jeff Garzik <jgarzik@pobox.com> some bug fix and cleaning
37 Rev 1.07.05 Nov. 6 2000 metapirat<metapirat@gmx.de> contribute media type select by ifconfig 37 Rev 1.07.05 Nov. 6 2000 metapirat<metapirat@gmx.de> contribute media type select by ifconfig
38 Rev 1.07.04 Sep. 6 2000 Lei-Chun Chang added ICS1893 PHY support 38 Rev 1.07.04 Sep. 6 2000 Lei-Chun Chang added ICS1893 PHY support
39 Rev 1.07.03 Aug. 24 2000 Lei-Chun Chang (lcchang@sis.com.tw) modified 630E eqaulizer workaround rule 39 Rev 1.07.03 Aug. 24 2000 Lei-Chun Chang (lcchang@sis.com.tw) modified 630E equalizer workaround rule
40 Rev 1.07.01 Aug. 08 2000 Ollie Lho minor update for SiS 630E and SiS 630E A1 40 Rev 1.07.01 Aug. 08 2000 Ollie Lho minor update for SiS 630E and SiS 630E A1
41 Rev 1.07 Mar. 07 2000 Ollie Lho bug fix in Rx buffer ring 41 Rev 1.07 Mar. 07 2000 Ollie Lho bug fix in Rx buffer ring
42 Rev 1.06.04 Feb. 11 2000 Jeff Garzik <jgarzik@pobox.com> softnet and init for kernel 2.4 42 Rev 1.06.04 Feb. 11 2000 Jeff Garzik <jgarzik@pobox.com> softnet and init for kernel 2.4
diff --git a/drivers/net/tehuti.c b/drivers/net/tehuti.c
index 296000bf5a25..3397618d4d96 100644
--- a/drivers/net/tehuti.c
+++ b/drivers/net/tehuti.c
@@ -12,7 +12,7 @@
12/* 12/*
13 * RX HW/SW interaction overview 13 * RX HW/SW interaction overview
14 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 14 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
15 * There are 2 types of RX communication channels betwean driver and NIC. 15 * There are 2 types of RX communication channels between driver and NIC.
16 * 1) RX Free Fifo - RXF - holds descriptors of empty buffers to accept incoming 16 * 1) RX Free Fifo - RXF - holds descriptors of empty buffers to accept incoming
17 * traffic. This Fifo is filled by SW and is readen by HW. Each descriptor holds 17 * traffic. This Fifo is filled by SW and is readen by HW. Each descriptor holds
18 * info about buffer's location, size and ID. An ID field is used to identify a 18 * info about buffer's location, size and ID. An ID field is used to identify a
@@ -821,7 +821,7 @@ static void bdx_setmulti(struct net_device *ndev)
821 } 821 }
822 822
823 /* use PMF to accept first MAC_MCST_NUM (15) addresses */ 823 /* use PMF to accept first MAC_MCST_NUM (15) addresses */
824 /* TBD: sort addreses and write them in ascending order 824 /* TBD: sort addresses and write them in ascending order
825 * into RX_MAC_MCST regs. we skip this phase now and accept ALL 825 * into RX_MAC_MCST regs. we skip this phase now and accept ALL
826 * multicast frames throu IMF */ 826 * multicast frames throu IMF */
827 /* accept the rest of addresses throu IMF */ 827 /* accept the rest of addresses throu IMF */
@@ -1346,7 +1346,7 @@ static void print_rxfd(struct rxf_desc *rxfd)
1346/* 1346/*
1347 * TX HW/SW interaction overview 1347 * TX HW/SW interaction overview
1348 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 1348 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1349 * There are 2 types of TX communication channels betwean driver and NIC. 1349 * There are 2 types of TX communication channels between driver and NIC.
1350 * 1) TX Free Fifo - TXF - holds ack descriptors for sent packets 1350 * 1) TX Free Fifo - TXF - holds ack descriptors for sent packets
1351 * 2) TX Data Fifo - TXD - holds descriptors of full buffers. 1351 * 2) TX Data Fifo - TXD - holds descriptors of full buffers.
1352 * 1352 *
diff --git a/drivers/net/tun.c b/drivers/net/tun.c
index 7599c457abd1..b100bd50a0d7 100644
--- a/drivers/net/tun.c
+++ b/drivers/net/tun.c
@@ -1309,7 +1309,7 @@ static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
1309 break; 1309 break;
1310 1310
1311 case SIOCGIFHWADDR: 1311 case SIOCGIFHWADDR:
1312 /* Get hw addres */ 1312 /* Get hw address */
1313 memcpy(ifr.ifr_hwaddr.sa_data, tun->dev->dev_addr, ETH_ALEN); 1313 memcpy(ifr.ifr_hwaddr.sa_data, tun->dev->dev_addr, ETH_ALEN);
1314 ifr.ifr_hwaddr.sa_family = tun->dev->type; 1314 ifr.ifr_hwaddr.sa_family = tun->dev->type;
1315 if (copy_to_user(argp, &ifr, ifreq_len)) 1315 if (copy_to_user(argp, &ifr, ifreq_len))
diff --git a/drivers/net/via-velocity.c b/drivers/net/via-velocity.c
index cab96ad49e60..09cac704fdd7 100644
--- a/drivers/net/via-velocity.c
+++ b/drivers/net/via-velocity.c
@@ -898,7 +898,7 @@ static int velocity_set_media_mode(struct velocity_info *vptr, u32 mii_status)
898 set_mii_flow_control(vptr); 898 set_mii_flow_control(vptr);
899 899
900 /* 900 /*
901 Check if new status is consisent with current status 901 Check if new status is consistent with current status
902 if (((mii_status & curr_status) & VELOCITY_AUTONEG_ENABLE) || 902 if (((mii_status & curr_status) & VELOCITY_AUTONEG_ENABLE) ||
903 (mii_status==curr_status)) { 903 (mii_status==curr_status)) {
904 vptr->mii_status=mii_check_media_mode(vptr->mac_regs); 904 vptr->mii_status=mii_check_media_mode(vptr->mac_regs);
diff --git a/drivers/net/vxge/vxge-traffic.h b/drivers/net/vxge/vxge-traffic.h
index 8c3103fb6442..d48486d6afa1 100644
--- a/drivers/net/vxge/vxge-traffic.h
+++ b/drivers/net/vxge/vxge-traffic.h
@@ -1695,7 +1695,7 @@ struct vxge_hw_device_stats_sw_err {
1695 * struct vxge_hw_device_stats - Contains HW per-device statistics, 1695 * struct vxge_hw_device_stats - Contains HW per-device statistics,
1696 * including hw. 1696 * including hw.
1697 * @devh: HW device handle. 1697 * @devh: HW device handle.
1698 * @dma_addr: DMA addres of the %hw_info. Given to device to fill-in the stats. 1698 * @dma_addr: DMA address of the %hw_info. Given to device to fill-in the stats.
1699 * @hw_info_dmah: DMA handle used to map hw statistics onto the device memory 1699 * @hw_info_dmah: DMA handle used to map hw statistics onto the device memory
1700 * space. 1700 * space.
1701 * @hw_info_dma_acch: One more DMA handle used subsequently to free the 1701 * @hw_info_dma_acch: One more DMA handle used subsequently to free the
diff --git a/drivers/net/wan/dscc4.c b/drivers/net/wan/dscc4.c
index 34cff6ce6d27..4578e5b4b411 100644
--- a/drivers/net/wan/dscc4.c
+++ b/drivers/net/wan/dscc4.c
@@ -125,7 +125,7 @@ static u32 dscc4_pci_config_store[16];
125/* Module parameters */ 125/* Module parameters */
126 126
127MODULE_AUTHOR("Maintainer: Francois Romieu <romieu@cogenit.fr>"); 127MODULE_AUTHOR("Maintainer: Francois Romieu <romieu@cogenit.fr>");
128MODULE_DESCRIPTION("Siemens PEB20534 PCI Controler"); 128MODULE_DESCRIPTION("Siemens PEB20534 PCI Controller");
129MODULE_LICENSE("GPL"); 129MODULE_LICENSE("GPL");
130module_param(debug, int, 0); 130module_param(debug, int, 0);
131MODULE_PARM_DESC(debug,"Enable/disable extra messages"); 131MODULE_PARM_DESC(debug,"Enable/disable extra messages");
diff --git a/drivers/net/wimax/i2400m/driver.c b/drivers/net/wimax/i2400m/driver.c
index f0603327aafa..65bc334ed57b 100644
--- a/drivers/net/wimax/i2400m/driver.c
+++ b/drivers/net/wimax/i2400m/driver.c
@@ -232,7 +232,7 @@ int i2400m_check_mac_addr(struct i2400m *i2400m)
232 result); 232 result);
233 goto error; 233 goto error;
234 } 234 }
235 /* Extract MAC addresss */ 235 /* Extract MAC address */
236 ddi = (void *) skb->data; 236 ddi = (void *) skb->data;
237 BUILD_BUG_ON(ETH_ALEN != sizeof(ddi->mac_address)); 237 BUILD_BUG_ON(ETH_ALEN != sizeof(ddi->mac_address));
238 d_printf(2, dev, "GET DEVICE INFO: mac addr %pM\n", 238 d_printf(2, dev, "GET DEVICE INFO: mac addr %pM\n",
diff --git a/drivers/net/wimax/i2400m/i2400m.h b/drivers/net/wimax/i2400m/i2400m.h
index 17ecaa41a807..030cbfd31704 100644
--- a/drivers/net/wimax/i2400m/i2400m.h
+++ b/drivers/net/wimax/i2400m/i2400m.h
@@ -186,7 +186,7 @@ enum {
186 * struct i2400m_poke_table - Hardware poke table for the Intel 2400m 186 * struct i2400m_poke_table - Hardware poke table for the Intel 2400m
187 * 187 *
188 * This structure will be used to create a device specific poke table 188 * This structure will be used to create a device specific poke table
189 * to put the device in a consistant state at boot time. 189 * to put the device in a consistent state at boot time.
190 * 190 *
191 * @address: The device address to poke 191 * @address: The device address to poke
192 * 192 *
@@ -703,7 +703,7 @@ enum i2400m_bm_cmd_flags {
703 * @I2400M_BRI_MAC_REINIT: We need to reinitialize the boot 703 * @I2400M_BRI_MAC_REINIT: We need to reinitialize the boot
704 * rom after reading the MAC address. This is quite a dirty hack, 704 * rom after reading the MAC address. This is quite a dirty hack,
705 * if you ask me -- the device requires the bootrom to be 705 * if you ask me -- the device requires the bootrom to be
706 * intialized after reading the MAC address. 706 * initialized after reading the MAC address.
707 */ 707 */
708enum i2400m_bri { 708enum i2400m_bri {
709 I2400M_BRI_SOFT = 1 << 1, 709 I2400M_BRI_SOFT = 1 << 1,
diff --git a/drivers/net/wireless/ath/ath5k/reg.h b/drivers/net/wireless/ath/ath5k/reg.h
index 7ad05d401ab5..fd14b9103951 100644
--- a/drivers/net/wireless/ath/ath5k/reg.h
+++ b/drivers/net/wireless/ath/ath5k/reg.h
@@ -1064,7 +1064,7 @@
1064/* 1064/*
1065 * EEPROM command register 1065 * EEPROM command register
1066 */ 1066 */
1067#define AR5K_EEPROM_CMD 0x6008 /* Register Addres */ 1067#define AR5K_EEPROM_CMD 0x6008 /* Register Address */
1068#define AR5K_EEPROM_CMD_READ 0x00000001 /* EEPROM read */ 1068#define AR5K_EEPROM_CMD_READ 0x00000001 /* EEPROM read */
1069#define AR5K_EEPROM_CMD_WRITE 0x00000002 /* EEPROM write */ 1069#define AR5K_EEPROM_CMD_WRITE 0x00000002 /* EEPROM write */
1070#define AR5K_EEPROM_CMD_RESET 0x00000004 /* EEPROM reset */ 1070#define AR5K_EEPROM_CMD_RESET 0x00000004 /* EEPROM reset */
@@ -1084,7 +1084,7 @@
1084/* 1084/*
1085 * EEPROM config register 1085 * EEPROM config register
1086 */ 1086 */
1087#define AR5K_EEPROM_CFG 0x6010 /* Register Addres */ 1087#define AR5K_EEPROM_CFG 0x6010 /* Register Address */
1088#define AR5K_EEPROM_CFG_SIZE 0x00000003 /* Size determination override */ 1088#define AR5K_EEPROM_CFG_SIZE 0x00000003 /* Size determination override */
1089#define AR5K_EEPROM_CFG_SIZE_AUTO 0 1089#define AR5K_EEPROM_CFG_SIZE_AUTO 0
1090#define AR5K_EEPROM_CFG_SIZE_4KBIT 1 1090#define AR5K_EEPROM_CFG_SIZE_4KBIT 1
@@ -1126,7 +1126,7 @@
1126 * Second station id register (Upper 16 bits of MAC address + PCU settings) 1126 * Second station id register (Upper 16 bits of MAC address + PCU settings)
1127 */ 1127 */
1128#define AR5K_STA_ID1 0x8004 /* Register Address */ 1128#define AR5K_STA_ID1 0x8004 /* Register Address */
1129#define AR5K_STA_ID1_ADDR_U16 0x0000ffff /* Upper 16 bits of MAC addres */ 1129#define AR5K_STA_ID1_ADDR_U16 0x0000ffff /* Upper 16 bits of MAC address */
1130#define AR5K_STA_ID1_AP 0x00010000 /* Set AP mode */ 1130#define AR5K_STA_ID1_AP 0x00010000 /* Set AP mode */
1131#define AR5K_STA_ID1_ADHOC 0x00020000 /* Set Ad-Hoc mode */ 1131#define AR5K_STA_ID1_ADHOC 0x00020000 /* Set Ad-Hoc mode */
1132#define AR5K_STA_ID1_PWR_SV 0x00040000 /* Power save reporting */ 1132#define AR5K_STA_ID1_PWR_SV 0x00040000 /* Power save reporting */
diff --git a/drivers/net/wireless/b43/phy_g.c b/drivers/net/wireless/b43/phy_g.c
index 0dc33b65e86b..be4828167012 100644
--- a/drivers/net/wireless/b43/phy_g.c
+++ b/drivers/net/wireless/b43/phy_g.c
@@ -1919,7 +1919,7 @@ static void b43_hardware_pctl_init_gphy(struct b43_wldev *dev)
1919 b43_hf_write(dev, b43_hf_read(dev) | B43_HF_HWPCTL); 1919 b43_hf_write(dev, b43_hf_read(dev) | B43_HF_HWPCTL);
1920} 1920}
1921 1921
1922/* Intialize B/G PHY power control */ 1922/* Initialize B/G PHY power control */
1923static void b43_phy_init_pctl(struct b43_wldev *dev) 1923static void b43_phy_init_pctl(struct b43_wldev *dev)
1924{ 1924{
1925 struct ssb_bus *bus = dev->dev->bus; 1925 struct ssb_bus *bus = dev->dev->bus;
diff --git a/drivers/net/wireless/b43legacy/phy.c b/drivers/net/wireless/b43legacy/phy.c
index 35033dd342ce..28e477d01587 100644
--- a/drivers/net/wireless/b43legacy/phy.c
+++ b/drivers/net/wireless/b43legacy/phy.c
@@ -153,7 +153,7 @@ void b43legacy_phy_calibrate(struct b43legacy_wldev *dev)
153 phy->calibrated = 1; 153 phy->calibrated = 1;
154} 154}
155 155
156/* intialize B PHY power control 156/* initialize B PHY power control
157 * as described in http://bcm-specs.sipsolutions.net/InitPowerControl 157 * as described in http://bcm-specs.sipsolutions.net/InitPowerControl
158 */ 158 */
159static void b43legacy_phy_init_pctl(struct b43legacy_wldev *dev) 159static void b43legacy_phy_init_pctl(struct b43legacy_wldev *dev)
diff --git a/drivers/net/wireless/iwlwifi/iwl-agn-ict.c b/drivers/net/wireless/iwlwifi/iwl-agn-ict.c
index a5dbfea1bfad..b5cb3be0eb4b 100644
--- a/drivers/net/wireless/iwlwifi/iwl-agn-ict.c
+++ b/drivers/net/wireless/iwlwifi/iwl-agn-ict.c
@@ -197,7 +197,7 @@ static irqreturn_t iwl_isr(int irq, void *data)
197 197
198 none: 198 none:
199 /* re-enable interrupts here since we don't have anything to service. */ 199 /* re-enable interrupts here since we don't have anything to service. */
200 /* only Re-enable if diabled by irq and no schedules tasklet. */ 200 /* only Re-enable if disabled by irq and no schedules tasklet. */
201 if (test_bit(STATUS_INT_ENABLED, &priv->status) && !priv->_agn.inta) 201 if (test_bit(STATUS_INT_ENABLED, &priv->status) && !priv->_agn.inta)
202 iwl_enable_interrupts(priv); 202 iwl_enable_interrupts(priv);
203 203
diff --git a/drivers/net/wireless/iwlwifi/iwl-agn.c b/drivers/net/wireless/iwlwifi/iwl-agn.c
index f13a83a7e62b..36335b1b54d4 100644
--- a/drivers/net/wireless/iwlwifi/iwl-agn.c
+++ b/drivers/net/wireless/iwlwifi/iwl-agn.c
@@ -1154,7 +1154,7 @@ static void iwl_irq_tasklet_legacy(struct iwl_priv *priv)
1154 } 1154 }
1155 1155
1156 /* Re-enable all interrupts */ 1156 /* Re-enable all interrupts */
1157 /* only Re-enable if diabled by irq */ 1157 /* only Re-enable if disabled by irq */
1158 if (test_bit(STATUS_INT_ENABLED, &priv->status)) 1158 if (test_bit(STATUS_INT_ENABLED, &priv->status))
1159 iwl_enable_interrupts(priv); 1159 iwl_enable_interrupts(priv);
1160 1160
@@ -1368,7 +1368,7 @@ static void iwl_irq_tasklet(struct iwl_priv *priv)
1368 } 1368 }
1369 1369
1370 /* Re-enable all interrupts */ 1370 /* Re-enable all interrupts */
1371 /* only Re-enable if diabled by irq */ 1371 /* only Re-enable if disabled by irq */
1372 if (test_bit(STATUS_INT_ENABLED, &priv->status)) 1372 if (test_bit(STATUS_INT_ENABLED, &priv->status))
1373 iwl_enable_interrupts(priv); 1373 iwl_enable_interrupts(priv);
1374} 1374}
diff --git a/drivers/net/wireless/iwlwifi/iwl-legacy.c b/drivers/net/wireless/iwlwifi/iwl-legacy.c
index a08b4e56e6b1..bb1a742a98a0 100644
--- a/drivers/net/wireless/iwlwifi/iwl-legacy.c
+++ b/drivers/net/wireless/iwlwifi/iwl-legacy.c
@@ -619,7 +619,7 @@ unplugged:
619 619
620none: 620none:
621 /* re-enable interrupts here since we don't have anything to service. */ 621 /* re-enable interrupts here since we don't have anything to service. */
622 /* only Re-enable if diabled by irq */ 622 /* only Re-enable if disabled by irq */
623 if (test_bit(STATUS_INT_ENABLED, &priv->status)) 623 if (test_bit(STATUS_INT_ENABLED, &priv->status))
624 iwl_enable_interrupts(priv); 624 iwl_enable_interrupts(priv);
625 spin_unlock_irqrestore(&priv->lock, flags); 625 spin_unlock_irqrestore(&priv->lock, flags);
diff --git a/drivers/net/wireless/iwlwifi/iwl-sta.c b/drivers/net/wireless/iwlwifi/iwl-sta.c
index 4776323b1eba..49493d176515 100644
--- a/drivers/net/wireless/iwlwifi/iwl-sta.c
+++ b/drivers/net/wireless/iwlwifi/iwl-sta.c
@@ -107,7 +107,7 @@ static int iwl_process_add_sta_resp(struct iwl_priv *priv,
107 /* 107 /*
108 * XXX: The MAC address in the command buffer is often changed from 108 * XXX: The MAC address in the command buffer is often changed from
109 * the original sent to the device. That is, the MAC address 109 * the original sent to the device. That is, the MAC address
110 * written to the command buffer often is not the same MAC adress 110 * written to the command buffer often is not the same MAC address
111 * read from the command buffer when the command returns. This 111 * read from the command buffer when the command returns. This
112 * issue has not yet been resolved and this debugging is left to 112 * issue has not yet been resolved and this debugging is left to
113 * observe the problem. 113 * observe the problem.
diff --git a/drivers/net/wireless/prism54/islpci_dev.c b/drivers/net/wireless/prism54/islpci_dev.c
index 2c8cc954d1b6..ec2c75d77cea 100644
--- a/drivers/net/wireless/prism54/islpci_dev.c
+++ b/drivers/net/wireless/prism54/islpci_dev.c
@@ -630,7 +630,7 @@ islpci_alloc_memory(islpci_private *priv)
630 printk(KERN_DEBUG "islpci_alloc_memory\n"); 630 printk(KERN_DEBUG "islpci_alloc_memory\n");
631#endif 631#endif
632 632
633 /* remap the PCI device base address to accessable */ 633 /* remap the PCI device base address to accessible */
634 if (!(priv->device_base = 634 if (!(priv->device_base =
635 ioremap(pci_resource_start(priv->pdev, 0), 635 ioremap(pci_resource_start(priv->pdev, 0),
636 ISL38XX_PCI_MEM_SIZE))) { 636 ISL38XX_PCI_MEM_SIZE))) {
@@ -709,7 +709,7 @@ islpci_alloc_memory(islpci_private *priv)
709 PCI_DMA_FROMDEVICE); 709 PCI_DMA_FROMDEVICE);
710 if (!priv->pci_map_rx_address[counter]) { 710 if (!priv->pci_map_rx_address[counter]) {
711 /* error mapping the buffer to device 711 /* error mapping the buffer to device
712 accessable memory address */ 712 accessible memory address */
713 printk(KERN_ERR "failed to map skb DMA'able\n"); 713 printk(KERN_ERR "failed to map skb DMA'able\n");
714 goto out_free; 714 goto out_free;
715 } 715 }
@@ -773,7 +773,7 @@ islpci_free_memory(islpci_private *priv)
773 priv->data_low_rx[counter] = NULL; 773 priv->data_low_rx[counter] = NULL;
774 } 774 }
775 775
776 /* Free the acces control list and the WPA list */ 776 /* Free the access control list and the WPA list */
777 prism54_acl_clean(&priv->acl); 777 prism54_acl_clean(&priv->acl);
778 prism54_wpa_bss_ie_clean(priv); 778 prism54_wpa_bss_ie_clean(priv);
779 mgt_clean(priv); 779 mgt_clean(priv);
diff --git a/drivers/net/wireless/prism54/islpci_eth.c b/drivers/net/wireless/prism54/islpci_eth.c
index 2fc52bc2d7dd..d44f8e20cce0 100644
--- a/drivers/net/wireless/prism54/islpci_eth.c
+++ b/drivers/net/wireless/prism54/islpci_eth.c
@@ -450,7 +450,7 @@ islpci_eth_receive(islpci_private *priv)
450 MAX_FRAGMENT_SIZE_RX + 2, 450 MAX_FRAGMENT_SIZE_RX + 2,
451 PCI_DMA_FROMDEVICE); 451 PCI_DMA_FROMDEVICE);
452 if (unlikely(!priv->pci_map_rx_address[index])) { 452 if (unlikely(!priv->pci_map_rx_address[index])) {
453 /* error mapping the buffer to device accessable memory address */ 453 /* error mapping the buffer to device accessible memory address */
454 DEBUG(SHOW_ERROR_MESSAGES, 454 DEBUG(SHOW_ERROR_MESSAGES,
455 "Error mapping DMA address\n"); 455 "Error mapping DMA address\n");
456 456
diff --git a/drivers/net/wireless/rt2x00/rt2x00mac.c b/drivers/net/wireless/rt2x00/rt2x00mac.c
index 658542d2efe1..f3da051df39e 100644
--- a/drivers/net/wireless/rt2x00/rt2x00mac.c
+++ b/drivers/net/wireless/rt2x00/rt2x00mac.c
@@ -273,7 +273,7 @@ int rt2x00mac_add_interface(struct ieee80211_hw *hw,
273 intf->beacon = entry; 273 intf->beacon = entry;
274 274
275 /* 275 /*
276 * The MAC adddress must be configured after the device 276 * The MAC address must be configured after the device
277 * has been initialized. Otherwise the device can reset 277 * has been initialized. Otherwise the device can reset
278 * the MAC registers. 278 * the MAC registers.
279 * The BSSID address must only be configured in AP mode, 279 * The BSSID address must only be configured in AP mode,
diff --git a/drivers/net/wireless/wl1251/acx.h b/drivers/net/wireless/wl1251/acx.h
index e54b21a4f8b1..efcc3aaca14f 100644
--- a/drivers/net/wireless/wl1251/acx.h
+++ b/drivers/net/wireless/wl1251/acx.h
@@ -1272,10 +1272,10 @@ struct wl1251_acx_tid_cfg {
1272/* OBSOLETE */ 1272/* OBSOLETE */
1273#define WL1251_ACX_INTR_WAKE_ON_HOST BIT(6) 1273#define WL1251_ACX_INTR_WAKE_ON_HOST BIT(6)
1274 1274
1275/* Trace meassge on MBOX #A */ 1275/* Trace message on MBOX #A */
1276#define WL1251_ACX_INTR_TRACE_A BIT(7) 1276#define WL1251_ACX_INTR_TRACE_A BIT(7)
1277 1277
1278/* Trace meassge on MBOX #B */ 1278/* Trace message on MBOX #B */
1279#define WL1251_ACX_INTR_TRACE_B BIT(8) 1279#define WL1251_ACX_INTR_TRACE_B BIT(8)
1280 1280
1281/* Command processing completion */ 1281/* Command processing completion */
diff --git a/drivers/net/wireless/wl1251/wl1251.h b/drivers/net/wireless/wl1251/wl1251.h
index 13fbeeccf609..c0ce2c8b43b8 100644
--- a/drivers/net/wireless/wl1251/wl1251.h
+++ b/drivers/net/wireless/wl1251/wl1251.h
@@ -419,7 +419,7 @@ void wl1251_disable_interrupts(struct wl1251 *wl);
419#define WL1251_FW_NAME "wl1251-fw.bin" 419#define WL1251_FW_NAME "wl1251-fw.bin"
420#define WL1251_NVS_NAME "wl1251-nvs.bin" 420#define WL1251_NVS_NAME "wl1251-nvs.bin"
421 421
422#define WL1251_POWER_ON_SLEEP 10 /* in miliseconds */ 422#define WL1251_POWER_ON_SLEEP 10 /* in milliseconds */
423 423
424#define WL1251_PART_DOWN_MEM_START 0x0 424#define WL1251_PART_DOWN_MEM_START 0x0
425#define WL1251_PART_DOWN_MEM_SIZE 0x16800 425#define WL1251_PART_DOWN_MEM_SIZE 0x16800
diff --git a/drivers/net/wireless/wl12xx/acx.h b/drivers/net/wireless/wl12xx/acx.h
index 9cbc3f40c8dd..7bd8e4db4a71 100644
--- a/drivers/net/wireless/wl12xx/acx.h
+++ b/drivers/net/wireless/wl12xx/acx.h
@@ -47,9 +47,9 @@
47#define WL1271_ACX_INTR_HW_AVAILABLE BIT(5) 47#define WL1271_ACX_INTR_HW_AVAILABLE BIT(5)
48/* The MISC bit is used for aggregation of RX, TxComplete and TX rate update */ 48/* The MISC bit is used for aggregation of RX, TxComplete and TX rate update */
49#define WL1271_ACX_INTR_DATA BIT(6) 49#define WL1271_ACX_INTR_DATA BIT(6)
50/* Trace meassge on MBOX #A */ 50/* Trace message on MBOX #A */
51#define WL1271_ACX_INTR_TRACE_A BIT(7) 51#define WL1271_ACX_INTR_TRACE_A BIT(7)
52/* Trace meassge on MBOX #B */ 52/* Trace message on MBOX #B */
53#define WL1271_ACX_INTR_TRACE_B BIT(8) 53#define WL1271_ACX_INTR_TRACE_B BIT(8)
54 54
55#define WL1271_ACX_INTR_ALL 0xFFFFFFFF 55#define WL1271_ACX_INTR_ALL 0xFFFFFFFF
diff --git a/drivers/net/wireless/wl12xx/wl12xx.h b/drivers/net/wireless/wl12xx/wl12xx.h
index ce3d31f98c55..9050dd9b62d2 100644
--- a/drivers/net/wireless/wl12xx/wl12xx.h
+++ b/drivers/net/wireless/wl12xx/wl12xx.h
@@ -416,8 +416,8 @@ int wl1271_plt_stop(struct wl1271 *wl);
416 416
417/* WL1271 needs a 200ms sleep after power on, and a 20ms sleep before power 417/* WL1271 needs a 200ms sleep after power on, and a 20ms sleep before power
418 on in case is has been shut down shortly before */ 418 on in case is has been shut down shortly before */
419#define WL1271_PRE_POWER_ON_SLEEP 20 /* in miliseconds */ 419#define WL1271_PRE_POWER_ON_SLEEP 20 /* in milliseconds */
420#define WL1271_POWER_ON_SLEEP 200 /* in miliseconds */ 420#define WL1271_POWER_ON_SLEEP 200 /* in milliseconds */
421 421
422/* Macros to handle wl1271.sta_rate_set */ 422/* Macros to handle wl1271.sta_rate_set */
423#define HW_BG_RATES_MASK 0xffff 423#define HW_BG_RATES_MASK 0xffff
diff --git a/drivers/net/wireless/wl3501_cs.c b/drivers/net/wireless/wl3501_cs.c
index ee82df62e646..3e5befe4d03b 100644
--- a/drivers/net/wireless/wl3501_cs.c
+++ b/drivers/net/wireless/wl3501_cs.c
@@ -192,7 +192,7 @@ static inline void wl3501_switch_page(struct wl3501_card *this, u8 page)
192} 192}
193 193
194/* 194/*
195 * Get Ethernet MAC addresss. 195 * Get Ethernet MAC address.
196 * 196 *
197 * WARNING: We switch to FPAGE0 and switc back again. 197 * WARNING: We switch to FPAGE0 and switc back again.
198 * Making sure there is no other WL function beening called by ISR. 198 * Making sure there is no other WL function beening called by ISR.
diff --git a/drivers/nfc/Kconfig b/drivers/nfc/Kconfig
new file mode 100644
index 000000000000..ffedfd492754
--- /dev/null
+++ b/drivers/nfc/Kconfig
@@ -0,0 +1,30 @@
1#
2# Near Field Communication (NFC) devices
3#
4
5menuconfig NFC_DEVICES
6 bool "NFC devices"
7 default n
8 ---help---
9 You'll have to say Y if your computer contains an NFC device that
10 you want to use under Linux.
11
12 You can say N here if you don't have any Near Field Communication
13 devices connected to your computer.
14
15if NFC_DEVICES
16
17config PN544_NFC
18 tristate "PN544 NFC driver"
19 depends on I2C
20 select CRC_CCITT
21 default n
22 ---help---
23 Say yes if you want PN544 Near Field Communication driver.
24 This is for i2c connected version. If unsure, say N here.
25
26 To compile this driver as a module, choose m here. The module will
27 be called pn544.
28
29
30endif # NFC_DEVICES
diff --git a/drivers/nfc/Makefile b/drivers/nfc/Makefile
new file mode 100644
index 000000000000..a4efb164ec49
--- /dev/null
+++ b/drivers/nfc/Makefile
@@ -0,0 +1,5 @@
1#
2# Makefile for nfc devices
3#
4
5obj-$(CONFIG_PN544_NFC) += pn544.o
diff --git a/drivers/nfc/pn544.c b/drivers/nfc/pn544.c
new file mode 100644
index 000000000000..401c44b6eadb
--- /dev/null
+++ b/drivers/nfc/pn544.c
@@ -0,0 +1,891 @@
1/*
2 * Driver for the PN544 NFC chip.
3 *
4 * Copyright (C) Nokia Corporation
5 *
6 * Author: Jari Vanhala <ext-jari.vanhala@nokia.com>
7 * Contact: Matti Aaltonen <matti.j.aaltonen@nokia.com>
8 *
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * version 2 as published by the Free Software Foundation.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 */
22
23#include <linux/completion.h>
24#include <linux/crc-ccitt.h>
25#include <linux/delay.h>
26#include <linux/interrupt.h>
27#include <linux/kernel.h>
28#include <linux/miscdevice.h>
29#include <linux/module.h>
30#include <linux/mutex.h>
31#include <linux/nfc/pn544.h>
32#include <linux/poll.h>
33#include <linux/regulator/consumer.h>
34#include <linux/serial_core.h> /* for TCGETS */
35#include <linux/slab.h>
36
37#define DRIVER_CARD "PN544 NFC"
38#define DRIVER_DESC "NFC driver for PN544"
39
40static struct i2c_device_id pn544_id_table[] = {
41 { PN544_DRIVER_NAME, 0 },
42 { }
43};
44MODULE_DEVICE_TABLE(i2c, pn544_id_table);
45
46#define HCI_MODE 0
47#define FW_MODE 1
48
49enum pn544_state {
50 PN544_ST_COLD,
51 PN544_ST_FW_READY,
52 PN544_ST_READY,
53};
54
55enum pn544_irq {
56 PN544_NONE,
57 PN544_INT,
58};
59
60struct pn544_info {
61 struct miscdevice miscdev;
62 struct i2c_client *i2c_dev;
63 struct regulator_bulk_data regs[2];
64
65 enum pn544_state state;
66 wait_queue_head_t read_wait;
67 loff_t read_offset;
68 enum pn544_irq read_irq;
69 struct mutex read_mutex; /* Serialize read_irq access */
70 struct mutex mutex; /* Serialize info struct access */
71 u8 *buf;
72 unsigned int buflen;
73};
74
75static const char reg_vdd_io[] = "Vdd_IO";
76static const char reg_vbat[] = "VBat";
77
78/* sysfs interface */
79static ssize_t pn544_test(struct device *dev,
80 struct device_attribute *attr, char *buf)
81{
82 struct pn544_info *info = dev_get_drvdata(dev);
83 struct i2c_client *client = info->i2c_dev;
84 struct pn544_nfc_platform_data *pdata = client->dev.platform_data;
85
86 return snprintf(buf, PAGE_SIZE, "%d\n", pdata->test());
87}
88
89static int pn544_enable(struct pn544_info *info, int mode)
90{
91 struct pn544_nfc_platform_data *pdata;
92 struct i2c_client *client = info->i2c_dev;
93
94 int r;
95
96 r = regulator_bulk_enable(ARRAY_SIZE(info->regs), info->regs);
97 if (r < 0)
98 return r;
99
100 pdata = client->dev.platform_data;
101 info->read_irq = PN544_NONE;
102 if (pdata->enable)
103 pdata->enable(mode);
104
105 if (mode) {
106 info->state = PN544_ST_FW_READY;
107 dev_dbg(&client->dev, "now in FW-mode\n");
108 } else {
109 info->state = PN544_ST_READY;
110 dev_dbg(&client->dev, "now in HCI-mode\n");
111 }
112
113 usleep_range(10000, 15000);
114
115 return 0;
116}
117
118static void pn544_disable(struct pn544_info *info)
119{
120 struct pn544_nfc_platform_data *pdata;
121 struct i2c_client *client = info->i2c_dev;
122
123 pdata = client->dev.platform_data;
124 if (pdata->disable)
125 pdata->disable();
126
127 info->state = PN544_ST_COLD;
128
129 dev_dbg(&client->dev, "Now in OFF-mode\n");
130
131 msleep(PN544_RESETVEN_TIME);
132
133 info->read_irq = PN544_NONE;
134 regulator_bulk_disable(ARRAY_SIZE(info->regs), info->regs);
135}
136
137static int check_crc(u8 *buf, int buflen)
138{
139 u8 len;
140 u16 crc;
141
142 len = buf[0] + 1;
143 if (len < 4 || len != buflen || len > PN544_MSG_MAX_SIZE) {
144 pr_err(PN544_DRIVER_NAME
145 ": CRC; corrupt packet len %u (%d)\n", len, buflen);
146 print_hex_dump(KERN_DEBUG, "crc: ", DUMP_PREFIX_NONE,
147 16, 2, buf, buflen, false);
148 return -EPERM;
149 }
150 crc = crc_ccitt(0xffff, buf, len - 2);
151 crc = ~crc;
152
153 if (buf[len-2] != (crc & 0xff) || buf[len-1] != (crc >> 8)) {
154 pr_err(PN544_DRIVER_NAME ": CRC error 0x%x != 0x%x 0x%x\n",
155 crc, buf[len-1], buf[len-2]);
156
157 print_hex_dump(KERN_DEBUG, "crc: ", DUMP_PREFIX_NONE,
158 16, 2, buf, buflen, false);
159 return -EPERM;
160 }
161 return 0;
162}
163
164static int pn544_i2c_write(struct i2c_client *client, u8 *buf, int len)
165{
166 int r;
167
168 if (len < 4 || len != (buf[0] + 1)) {
169 dev_err(&client->dev, "%s: Illegal message length: %d\n",
170 __func__, len);
171 return -EINVAL;
172 }
173
174 if (check_crc(buf, len))
175 return -EINVAL;
176
177 usleep_range(3000, 6000);
178
179 r = i2c_master_send(client, buf, len);
180 dev_dbg(&client->dev, "send: %d\n", r);
181
182 if (r == -EREMOTEIO) { /* Retry, chip was in standby */
183 usleep_range(6000, 10000);
184 r = i2c_master_send(client, buf, len);
185 dev_dbg(&client->dev, "send2: %d\n", r);
186 }
187
188 if (r != len)
189 return -EREMOTEIO;
190
191 return r;
192}
193
194static int pn544_i2c_read(struct i2c_client *client, u8 *buf, int buflen)
195{
196 int r;
197 u8 len;
198
199 /*
200 * You could read a packet in one go, but then you'd need to read
201 * max size and rest would be 0xff fill, so we do split reads.
202 */
203 r = i2c_master_recv(client, &len, 1);
204 dev_dbg(&client->dev, "recv1: %d\n", r);
205
206 if (r != 1)
207 return -EREMOTEIO;
208
209 if (len < PN544_LLC_HCI_OVERHEAD)
210 len = PN544_LLC_HCI_OVERHEAD;
211 else if (len > (PN544_MSG_MAX_SIZE - 1))
212 len = PN544_MSG_MAX_SIZE - 1;
213
214 if (1 + len > buflen) /* len+(data+crc16) */
215 return -EMSGSIZE;
216
217 buf[0] = len;
218
219 r = i2c_master_recv(client, buf + 1, len);
220 dev_dbg(&client->dev, "recv2: %d\n", r);
221
222 if (r != len)
223 return -EREMOTEIO;
224
225 usleep_range(3000, 6000);
226
227 return r + 1;
228}
229
230static int pn544_fw_write(struct i2c_client *client, u8 *buf, int len)
231{
232 int r;
233
234 dev_dbg(&client->dev, "%s\n", __func__);
235
236 if (len < PN544_FW_HEADER_SIZE ||
237 (PN544_FW_HEADER_SIZE + (buf[1] << 8) + buf[2]) != len)
238 return -EINVAL;
239
240 r = i2c_master_send(client, buf, len);
241 dev_dbg(&client->dev, "fw send: %d\n", r);
242
243 if (r == -EREMOTEIO) { /* Retry, chip was in standby */
244 usleep_range(6000, 10000);
245 r = i2c_master_send(client, buf, len);
246 dev_dbg(&client->dev, "fw send2: %d\n", r);
247 }
248
249 if (r != len)
250 return -EREMOTEIO;
251
252 return r;
253}
254
255static int pn544_fw_read(struct i2c_client *client, u8 *buf, int buflen)
256{
257 int r, len;
258
259 if (buflen < PN544_FW_HEADER_SIZE)
260 return -EINVAL;
261
262 r = i2c_master_recv(client, buf, PN544_FW_HEADER_SIZE);
263 dev_dbg(&client->dev, "FW recv1: %d\n", r);
264
265 if (r < 0)
266 return r;
267
268 if (r < PN544_FW_HEADER_SIZE)
269 return -EINVAL;
270
271 len = (buf[1] << 8) + buf[2];
272 if (len == 0) /* just header, no additional data */
273 return r;
274
275 if (len > buflen - PN544_FW_HEADER_SIZE)
276 return -EMSGSIZE;
277
278 r = i2c_master_recv(client, buf + PN544_FW_HEADER_SIZE, len);
279 dev_dbg(&client->dev, "fw recv2: %d\n", r);
280
281 if (r != len)
282 return -EINVAL;
283
284 return r + PN544_FW_HEADER_SIZE;
285}
286
287static irqreturn_t pn544_irq_thread_fn(int irq, void *dev_id)
288{
289 struct pn544_info *info = dev_id;
290 struct i2c_client *client = info->i2c_dev;
291
292 BUG_ON(!info);
293 BUG_ON(irq != info->i2c_dev->irq);
294
295 dev_dbg(&client->dev, "IRQ\n");
296
297 mutex_lock(&info->read_mutex);
298 info->read_irq = PN544_INT;
299 mutex_unlock(&info->read_mutex);
300
301 wake_up_interruptible(&info->read_wait);
302
303 return IRQ_HANDLED;
304}
305
306static enum pn544_irq pn544_irq_state(struct pn544_info *info)
307{
308 enum pn544_irq irq;
309
310 mutex_lock(&info->read_mutex);
311 irq = info->read_irq;
312 mutex_unlock(&info->read_mutex);
313 /*
314 * XXX: should we check GPIO-line status directly?
315 * return pdata->irq_status() ? PN544_INT : PN544_NONE;
316 */
317
318 return irq;
319}
320
321static ssize_t pn544_read(struct file *file, char __user *buf,
322 size_t count, loff_t *offset)
323{
324 struct pn544_info *info = container_of(file->private_data,
325 struct pn544_info, miscdev);
326 struct i2c_client *client = info->i2c_dev;
327 enum pn544_irq irq;
328 size_t len;
329 int r = 0;
330
331 dev_dbg(&client->dev, "%s: info: %p, count: %zu\n", __func__,
332 info, count);
333
334 mutex_lock(&info->mutex);
335
336 if (info->state == PN544_ST_COLD) {
337 r = -ENODEV;
338 goto out;
339 }
340
341 irq = pn544_irq_state(info);
342 if (irq == PN544_NONE) {
343 if (file->f_flags & O_NONBLOCK) {
344 r = -EAGAIN;
345 goto out;
346 }
347
348 if (wait_event_interruptible(info->read_wait,
349 (info->read_irq == PN544_INT))) {
350 r = -ERESTARTSYS;
351 goto out;
352 }
353 }
354
355 if (info->state == PN544_ST_FW_READY) {
356 len = min(count, info->buflen);
357
358 mutex_lock(&info->read_mutex);
359 r = pn544_fw_read(info->i2c_dev, info->buf, len);
360 info->read_irq = PN544_NONE;
361 mutex_unlock(&info->read_mutex);
362
363 if (r < 0) {
364 dev_err(&info->i2c_dev->dev, "FW read failed: %d\n", r);
365 goto out;
366 }
367
368 print_hex_dump(KERN_DEBUG, "FW read: ", DUMP_PREFIX_NONE,
369 16, 2, info->buf, r, false);
370
371 *offset += r;
372 if (copy_to_user(buf, info->buf, r)) {
373 r = -EFAULT;
374 goto out;
375 }
376 } else {
377 len = min(count, info->buflen);
378
379 mutex_lock(&info->read_mutex);
380 r = pn544_i2c_read(info->i2c_dev, info->buf, len);
381 info->read_irq = PN544_NONE;
382 mutex_unlock(&info->read_mutex);
383
384 if (r < 0) {
385 dev_err(&info->i2c_dev->dev, "read failed (%d)\n", r);
386 goto out;
387 }
388 print_hex_dump(KERN_DEBUG, "read: ", DUMP_PREFIX_NONE,
389 16, 2, info->buf, r, false);
390
391 *offset += r;
392 if (copy_to_user(buf, info->buf, r)) {
393 r = -EFAULT;
394 goto out;
395 }
396 }
397
398out:
399 mutex_unlock(&info->mutex);
400
401 return r;
402}
403
404static unsigned int pn544_poll(struct file *file, poll_table *wait)
405{
406 struct pn544_info *info = container_of(file->private_data,
407 struct pn544_info, miscdev);
408 struct i2c_client *client = info->i2c_dev;
409 int r = 0;
410
411 dev_dbg(&client->dev, "%s: info: %p\n", __func__, info);
412
413 mutex_lock(&info->mutex);
414
415 if (info->state == PN544_ST_COLD) {
416 r = -ENODEV;
417 goto out;
418 }
419
420 poll_wait(file, &info->read_wait, wait);
421
422 if (pn544_irq_state(info) == PN544_INT) {
423 r = POLLIN | POLLRDNORM;
424 goto out;
425 }
426out:
427 mutex_unlock(&info->mutex);
428
429 return r;
430}
431
432static ssize_t pn544_write(struct file *file, const char __user *buf,
433 size_t count, loff_t *ppos)
434{
435 struct pn544_info *info = container_of(file->private_data,
436 struct pn544_info, miscdev);
437 struct i2c_client *client = info->i2c_dev;
438 ssize_t len;
439 int r;
440
441 dev_dbg(&client->dev, "%s: info: %p, count %zu\n", __func__,
442 info, count);
443
444 mutex_lock(&info->mutex);
445
446 if (info->state == PN544_ST_COLD) {
447 r = -ENODEV;
448 goto out;
449 }
450
451 /*
452 * XXX: should we detect rset-writes and clean possible
453 * read_irq state
454 */
455 if (info->state == PN544_ST_FW_READY) {
456 size_t fw_len;
457
458 if (count < PN544_FW_HEADER_SIZE) {
459 r = -EINVAL;
460 goto out;
461 }
462
463 len = min(count, info->buflen);
464 if (copy_from_user(info->buf, buf, len)) {
465 r = -EFAULT;
466 goto out;
467 }
468
469 print_hex_dump(KERN_DEBUG, "FW write: ", DUMP_PREFIX_NONE,
470 16, 2, info->buf, len, false);
471
472 fw_len = PN544_FW_HEADER_SIZE + (info->buf[1] << 8) +
473 info->buf[2];
474
475 if (len > fw_len) /* 1 msg at a time */
476 len = fw_len;
477
478 r = pn544_fw_write(info->i2c_dev, info->buf, len);
479 } else {
480 if (count < PN544_LLC_MIN_SIZE) {
481 r = -EINVAL;
482 goto out;
483 }
484
485 len = min(count, info->buflen);
486 if (copy_from_user(info->buf, buf, len)) {
487 r = -EFAULT;
488 goto out;
489 }
490
491 print_hex_dump(KERN_DEBUG, "write: ", DUMP_PREFIX_NONE,
492 16, 2, info->buf, len, false);
493
494 if (len > (info->buf[0] + 1)) /* 1 msg at a time */
495 len = info->buf[0] + 1;
496
497 r = pn544_i2c_write(info->i2c_dev, info->buf, len);
498 }
499out:
500 mutex_unlock(&info->mutex);
501
502 return r;
503
504}
505
506static long pn544_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
507{
508 struct pn544_info *info = container_of(file->private_data,
509 struct pn544_info, miscdev);
510 struct i2c_client *client = info->i2c_dev;
511 struct pn544_nfc_platform_data *pdata;
512 unsigned int val;
513 int r = 0;
514
515 dev_dbg(&client->dev, "%s: info: %p, cmd: 0x%x\n", __func__, info, cmd);
516
517 mutex_lock(&info->mutex);
518
519 if (info->state == PN544_ST_COLD) {
520 r = -ENODEV;
521 goto out;
522 }
523
524 pdata = info->i2c_dev->dev.platform_data;
525 switch (cmd) {
526 case PN544_GET_FW_MODE:
527 dev_dbg(&client->dev, "%s: PN544_GET_FW_MODE\n", __func__);
528
529 val = (info->state == PN544_ST_FW_READY);
530 if (copy_to_user((void __user *)arg, &val, sizeof(val))) {
531 r = -EFAULT;
532 goto out;
533 }
534
535 break;
536
537 case PN544_SET_FW_MODE:
538 dev_dbg(&client->dev, "%s: PN544_SET_FW_MODE\n", __func__);
539
540 if (copy_from_user(&val, (void __user *)arg, sizeof(val))) {
541 r = -EFAULT;
542 goto out;
543 }
544
545 if (val) {
546 if (info->state == PN544_ST_FW_READY)
547 break;
548
549 pn544_disable(info);
550 r = pn544_enable(info, FW_MODE);
551 if (r < 0)
552 goto out;
553 } else {
554 if (info->state == PN544_ST_READY)
555 break;
556 pn544_disable(info);
557 r = pn544_enable(info, HCI_MODE);
558 if (r < 0)
559 goto out;
560 }
561 file->f_pos = info->read_offset;
562 break;
563
564 case TCGETS:
565 dev_dbg(&client->dev, "%s: TCGETS\n", __func__);
566
567 r = -ENOIOCTLCMD;
568 break;
569
570 default:
571 dev_err(&client->dev, "Unknown ioctl 0x%x\n", cmd);
572 r = -ENOIOCTLCMD;
573 break;
574 }
575
576out:
577 mutex_unlock(&info->mutex);
578
579 return r;
580}
581
582static int pn544_open(struct inode *inode, struct file *file)
583{
584 struct pn544_info *info = container_of(file->private_data,
585 struct pn544_info, miscdev);
586 struct i2c_client *client = info->i2c_dev;
587 int r = 0;
588
589 dev_dbg(&client->dev, "%s: info: %p, client %p\n", __func__,
590 info, info->i2c_dev);
591
592 mutex_lock(&info->mutex);
593
594 /*
595 * Only 1 at a time.
596 * XXX: maybe user (counter) would work better
597 */
598 if (info->state != PN544_ST_COLD) {
599 r = -EBUSY;
600 goto out;
601 }
602
603 file->f_pos = info->read_offset;
604 r = pn544_enable(info, HCI_MODE);
605
606out:
607 mutex_unlock(&info->mutex);
608 return r;
609}
610
611static int pn544_close(struct inode *inode, struct file *file)
612{
613 struct pn544_info *info = container_of(file->private_data,
614 struct pn544_info, miscdev);
615 struct i2c_client *client = info->i2c_dev;
616
617 dev_dbg(&client->dev, "%s: info: %p, client %p\n",
618 __func__, info, info->i2c_dev);
619
620 mutex_lock(&info->mutex);
621 pn544_disable(info);
622 mutex_unlock(&info->mutex);
623
624 return 0;
625}
626
627static const struct file_operations pn544_fops = {
628 .owner = THIS_MODULE,
629 .llseek = no_llseek,
630 .read = pn544_read,
631 .write = pn544_write,
632 .poll = pn544_poll,
633 .open = pn544_open,
634 .release = pn544_close,
635 .unlocked_ioctl = pn544_ioctl,
636};
637
638#ifdef CONFIG_PM
639static int pn544_suspend(struct device *dev)
640{
641 struct i2c_client *client = to_i2c_client(dev);
642 struct pn544_info *info;
643 int r = 0;
644
645 dev_info(&client->dev, "***\n%s: client %p\n***\n", __func__, client);
646
647 info = i2c_get_clientdata(client);
648 dev_info(&client->dev, "%s: info: %p, client %p\n", __func__,
649 info, client);
650
651 mutex_lock(&info->mutex);
652
653 switch (info->state) {
654 case PN544_ST_FW_READY:
655 /* Do not suspend while upgrading FW, please! */
656 r = -EPERM;
657 break;
658
659 case PN544_ST_READY:
660 /*
661 * CHECK: Device should be in standby-mode. No way to check?
662 * Allowing low power mode for the regulator is potentially
663 * dangerous if pn544 does not go to suspension.
664 */
665 break;
666
667 case PN544_ST_COLD:
668 break;
669 };
670
671 mutex_unlock(&info->mutex);
672 return r;
673}
674
675static int pn544_resume(struct device *dev)
676{
677 struct i2c_client *client = to_i2c_client(dev);
678 struct pn544_info *info = i2c_get_clientdata(client);
679 int r = 0;
680
681 dev_dbg(&client->dev, "%s: info: %p, client %p\n", __func__,
682 info, client);
683
684 mutex_lock(&info->mutex);
685
686 switch (info->state) {
687 case PN544_ST_READY:
688 /*
689 * CHECK: If regulator low power mode is allowed in
690 * pn544_suspend, we should go back to normal mode
691 * here.
692 */
693 break;
694
695 case PN544_ST_COLD:
696 break;
697
698 case PN544_ST_FW_READY:
699 break;
700 };
701
702 mutex_unlock(&info->mutex);
703
704 return r;
705}
706
707static SIMPLE_DEV_PM_OPS(pn544_pm_ops, pn544_suspend, pn544_resume);
708#endif
709
710static struct device_attribute pn544_attr =
711 __ATTR(nfc_test, S_IRUGO, pn544_test, NULL);
712
713static int __devinit pn544_probe(struct i2c_client *client,
714 const struct i2c_device_id *id)
715{
716 struct pn544_info *info;
717 struct pn544_nfc_platform_data *pdata;
718 int r = 0;
719
720 dev_dbg(&client->dev, "%s\n", __func__);
721 dev_dbg(&client->dev, "IRQ: %d\n", client->irq);
722
723 /* private data allocation */
724 info = kzalloc(sizeof(struct pn544_info), GFP_KERNEL);
725 if (!info) {
726 dev_err(&client->dev,
727 "Cannot allocate memory for pn544_info.\n");
728 r = -ENOMEM;
729 goto err_info_alloc;
730 }
731
732 info->buflen = max(PN544_MSG_MAX_SIZE, PN544_MAX_I2C_TRANSFER);
733 info->buf = kzalloc(info->buflen, GFP_KERNEL);
734 if (!info->buf) {
735 dev_err(&client->dev,
736 "Cannot allocate memory for pn544_info->buf.\n");
737 r = -ENOMEM;
738 goto err_buf_alloc;
739 }
740
741 info->regs[0].supply = reg_vdd_io;
742 info->regs[1].supply = reg_vbat;
743 r = regulator_bulk_get(&client->dev, ARRAY_SIZE(info->regs),
744 info->regs);
745 if (r < 0)
746 goto err_kmalloc;
747
748 info->i2c_dev = client;
749 info->state = PN544_ST_COLD;
750 info->read_irq = PN544_NONE;
751 mutex_init(&info->read_mutex);
752 mutex_init(&info->mutex);
753 init_waitqueue_head(&info->read_wait);
754 i2c_set_clientdata(client, info);
755 pdata = client->dev.platform_data;
756 if (!pdata) {
757 dev_err(&client->dev, "No platform data\n");
758 r = -EINVAL;
759 goto err_reg;
760 }
761
762 if (!pdata->request_resources) {
763 dev_err(&client->dev, "request_resources() missing\n");
764 r = -EINVAL;
765 goto err_reg;
766 }
767
768 r = pdata->request_resources(client);
769 if (r) {
770 dev_err(&client->dev, "Cannot get platform resources\n");
771 goto err_reg;
772 }
773
774 r = request_threaded_irq(client->irq, NULL, pn544_irq_thread_fn,
775 IRQF_TRIGGER_RISING, PN544_DRIVER_NAME,
776 info);
777 if (r < 0) {
778 dev_err(&client->dev, "Unable to register IRQ handler\n");
779 goto err_res;
780 }
781
782 /* If we don't have the test we don't need the sysfs file */
783 if (pdata->test) {
784 r = device_create_file(&client->dev, &pn544_attr);
785 if (r) {
786 dev_err(&client->dev,
787 "sysfs registration failed, error %d\n", r);
788 goto err_irq;
789 }
790 }
791
792 info->miscdev.minor = MISC_DYNAMIC_MINOR;
793 info->miscdev.name = PN544_DRIVER_NAME;
794 info->miscdev.fops = &pn544_fops;
795 info->miscdev.parent = &client->dev;
796 r = misc_register(&info->miscdev);
797 if (r < 0) {
798 dev_err(&client->dev, "Device registration failed\n");
799 goto err_sysfs;
800 }
801
802 dev_dbg(&client->dev, "%s: info: %p, pdata %p, client %p\n",
803 __func__, info, pdata, client);
804
805 return 0;
806
807err_sysfs:
808 if (pdata->test)
809 device_remove_file(&client->dev, &pn544_attr);
810err_irq:
811 free_irq(client->irq, info);
812err_res:
813 if (pdata->free_resources)
814 pdata->free_resources();
815err_reg:
816 regulator_bulk_free(ARRAY_SIZE(info->regs), info->regs);
817err_kmalloc:
818 kfree(info->buf);
819err_buf_alloc:
820 kfree(info);
821err_info_alloc:
822 return r;
823}
824
825static __devexit int pn544_remove(struct i2c_client *client)
826{
827 struct pn544_info *info = i2c_get_clientdata(client);
828 struct pn544_nfc_platform_data *pdata = client->dev.platform_data;
829
830 dev_dbg(&client->dev, "%s\n", __func__);
831
832 misc_deregister(&info->miscdev);
833 if (pdata->test)
834 device_remove_file(&client->dev, &pn544_attr);
835
836 if (info->state != PN544_ST_COLD) {
837 if (pdata->disable)
838 pdata->disable();
839
840 info->read_irq = PN544_NONE;
841 }
842
843 free_irq(client->irq, info);
844 if (pdata->free_resources)
845 pdata->free_resources();
846
847 regulator_bulk_free(ARRAY_SIZE(info->regs), info->regs);
848 kfree(info->buf);
849 kfree(info);
850
851 return 0;
852}
853
854static struct i2c_driver pn544_driver = {
855 .driver = {
856 .name = PN544_DRIVER_NAME,
857#ifdef CONFIG_PM
858 .pm = &pn544_pm_ops,
859#endif
860 },
861 .probe = pn544_probe,
862 .id_table = pn544_id_table,
863 .remove = __devexit_p(pn544_remove),
864};
865
866static int __init pn544_init(void)
867{
868 int r;
869
870 pr_debug(DRIVER_DESC ": %s\n", __func__);
871
872 r = i2c_add_driver(&pn544_driver);
873 if (r) {
874 pr_err(PN544_DRIVER_NAME ": driver registration failed\n");
875 return r;
876 }
877
878 return 0;
879}
880
881static void __exit pn544_exit(void)
882{
883 i2c_del_driver(&pn544_driver);
884 pr_info(DRIVER_DESC ", Exiting.\n");
885}
886
887module_init(pn544_init);
888module_exit(pn544_exit);
889
890MODULE_LICENSE("GPL");
891MODULE_DESCRIPTION(DRIVER_DESC);
diff --git a/drivers/pcmcia/m32r_cfc.h b/drivers/pcmcia/m32r_cfc.h
index 8146e3bee2e8..f558e1adf954 100644
--- a/drivers/pcmcia/m32r_cfc.h
+++ b/drivers/pcmcia/m32r_cfc.h
@@ -9,7 +9,7 @@
9#endif 9#endif
10 10
11/* 11/*
12 * M32R PC Card Controler 12 * M32R PC Card Controller
13 */ 13 */
14#define M32R_PCC0_BASE 0x00ef7000 14#define M32R_PCC0_BASE 0x00ef7000
15#define M32R_PCC1_BASE 0x00ef7020 15#define M32R_PCC1_BASE 0x00ef7020
diff --git a/drivers/pcmcia/m32r_pcc.h b/drivers/pcmcia/m32r_pcc.h
index e4fffe417ba9..f95c58563bc8 100644
--- a/drivers/pcmcia/m32r_pcc.h
+++ b/drivers/pcmcia/m32r_pcc.h
@@ -5,7 +5,7 @@
5#define M32R_MAX_PCC 2 5#define M32R_MAX_PCC 2
6 6
7/* 7/*
8 * M32R PC Card Controler 8 * M32R PC Card Controller
9 */ 9 */
10#define M32R_PCC0_BASE 0x00ef7000 10#define M32R_PCC0_BASE 0x00ef7000
11#define M32R_PCC1_BASE 0x00ef7020 11#define M32R_PCC1_BASE 0x00ef7020
diff --git a/drivers/pcmcia/m8xx_pcmcia.c b/drivers/pcmcia/m8xx_pcmcia.c
index 99d4f23cb435..0db482771fb5 100644
--- a/drivers/pcmcia/m8xx_pcmcia.c
+++ b/drivers/pcmcia/m8xx_pcmcia.c
@@ -1198,7 +1198,7 @@ static int __init m8xx_probe(struct platform_device *ofdev,
1198 out_be32(M8XX_PGCRX(1), 1198 out_be32(M8XX_PGCRX(1),
1199 M8XX_PGCRX_CXOE | (mk_int_int_mask(hwirq) << 16)); 1199 M8XX_PGCRX_CXOE | (mk_int_int_mask(hwirq) << 16));
1200 1200
1201 /* intialize the fixed memory windows */ 1201 /* initialize the fixed memory windows */
1202 1202
1203 for (i = 0; i < PCMCIA_SOCKETS_NO; i++) { 1203 for (i = 0; i < PCMCIA_SOCKETS_NO; i++) {
1204 for (m = 0; m < PCMCIA_MEM_WIN_NO; m++) { 1204 for (m = 0; m < PCMCIA_MEM_WIN_NO; m++) {
diff --git a/drivers/platform/x86/acer-wmi.c b/drivers/platform/x86/acer-wmi.c
index ee40d681edd0..c5c4b8c32eb8 100644
--- a/drivers/platform/x86/acer-wmi.c
+++ b/drivers/platform/x86/acer-wmi.c
@@ -1021,7 +1021,7 @@ static int update_bl_status(struct backlight_device *bd)
1021 return 0; 1021 return 0;
1022} 1022}
1023 1023
1024static struct backlight_ops acer_bl_ops = { 1024static const struct backlight_ops acer_bl_ops = {
1025 .get_brightness = read_brightness, 1025 .get_brightness = read_brightness,
1026 .update_status = update_bl_status, 1026 .update_status = update_bl_status,
1027}; 1027};
diff --git a/drivers/platform/x86/asus-laptop.c b/drivers/platform/x86/asus-laptop.c
index d235f44fd7a3..f3aa6a7fdab6 100644
--- a/drivers/platform/x86/asus-laptop.c
+++ b/drivers/platform/x86/asus-laptop.c
@@ -640,7 +640,7 @@ static int update_bl_status(struct backlight_device *bd)
640 return asus_lcd_set(asus, value); 640 return asus_lcd_set(asus, value);
641} 641}
642 642
643static struct backlight_ops asusbl_ops = { 643static const struct backlight_ops asusbl_ops = {
644 .get_brightness = asus_read_brightness, 644 .get_brightness = asus_read_brightness,
645 .update_status = update_bl_status, 645 .update_status = update_bl_status,
646}; 646};
diff --git a/drivers/platform/x86/asus_acpi.c b/drivers/platform/x86/asus_acpi.c
index ca05aefd03bf..4633fd8532cc 100644
--- a/drivers/platform/x86/asus_acpi.c
+++ b/drivers/platform/x86/asus_acpi.c
@@ -1467,7 +1467,7 @@ static int asus_hotk_remove(struct acpi_device *device, int type)
1467 return 0; 1467 return 0;
1468} 1468}
1469 1469
1470static struct backlight_ops asus_backlight_data = { 1470static const struct backlight_ops asus_backlight_data = {
1471 .get_brightness = read_brightness, 1471 .get_brightness = read_brightness,
1472 .update_status = set_brightness_status, 1472 .update_status = set_brightness_status,
1473}; 1473};
diff --git a/drivers/platform/x86/dell-laptop.c b/drivers/platform/x86/dell-laptop.c
index cf8a89a0d8f5..34657f96b5a5 100644
--- a/drivers/platform/x86/dell-laptop.c
+++ b/drivers/platform/x86/dell-laptop.c
@@ -546,7 +546,7 @@ out:
546 return buffer->output[1]; 546 return buffer->output[1];
547} 547}
548 548
549static struct backlight_ops dell_ops = { 549static const struct backlight_ops dell_ops = {
550 .get_brightness = dell_get_intensity, 550 .get_brightness = dell_get_intensity,
551 .update_status = dell_send_intensity, 551 .update_status = dell_send_intensity,
552}; 552};
diff --git a/drivers/platform/x86/eeepc-laptop.c b/drivers/platform/x86/eeepc-laptop.c
index e9fc530e7dc2..49d9ad708f89 100644
--- a/drivers/platform/x86/eeepc-laptop.c
+++ b/drivers/platform/x86/eeepc-laptop.c
@@ -1126,7 +1126,7 @@ static int update_bl_status(struct backlight_device *bd)
1126 return set_brightness(bd, bd->props.brightness); 1126 return set_brightness(bd, bd->props.brightness);
1127} 1127}
1128 1128
1129static struct backlight_ops eeepcbl_ops = { 1129static const struct backlight_ops eeepcbl_ops = {
1130 .get_brightness = read_brightness, 1130 .get_brightness = read_brightness,
1131 .update_status = update_bl_status, 1131 .update_status = update_bl_status,
1132}; 1132};
diff --git a/drivers/platform/x86/fujitsu-laptop.c b/drivers/platform/x86/fujitsu-laptop.c
index ad88b2ec34a1..19e92b2a7f7e 100644
--- a/drivers/platform/x86/fujitsu-laptop.c
+++ b/drivers/platform/x86/fujitsu-laptop.c
@@ -437,7 +437,7 @@ static int bl_update_status(struct backlight_device *b)
437 return ret; 437 return ret;
438} 438}
439 439
440static struct backlight_ops fujitsubl_ops = { 440static const struct backlight_ops fujitsubl_ops = {
441 .get_brightness = bl_get_brightness, 441 .get_brightness = bl_get_brightness,
442 .update_status = bl_update_status, 442 .update_status = bl_update_status,
443}; 443};
diff --git a/drivers/platform/x86/sony-laptop.c b/drivers/platform/x86/sony-laptop.c
index b4a95bb2f232..5e83370b0812 100644
--- a/drivers/platform/x86/sony-laptop.c
+++ b/drivers/platform/x86/sony-laptop.c
@@ -858,7 +858,7 @@ static int sony_backlight_get_brightness(struct backlight_device *bd)
858} 858}
859 859
860static struct backlight_device *sony_backlight_device; 860static struct backlight_device *sony_backlight_device;
861static struct backlight_ops sony_backlight_ops = { 861static const struct backlight_ops sony_backlight_ops = {
862 .update_status = sony_backlight_update_status, 862 .update_status = sony_backlight_update_status,
863 .get_brightness = sony_backlight_get_brightness, 863 .get_brightness = sony_backlight_get_brightness,
864}; 864};
diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c
index a974ca383cb9..dd599585c6a9 100644
--- a/drivers/platform/x86/thinkpad_acpi.c
+++ b/drivers/platform/x86/thinkpad_acpi.c
@@ -6110,7 +6110,7 @@ static void tpacpi_brightness_notify_change(void)
6110 BACKLIGHT_UPDATE_HOTKEY); 6110 BACKLIGHT_UPDATE_HOTKEY);
6111} 6111}
6112 6112
6113static struct backlight_ops ibm_backlight_data = { 6113static const struct backlight_ops ibm_backlight_data = {
6114 .get_brightness = brightness_get, 6114 .get_brightness = brightness_get,
6115 .update_status = brightness_update_status, 6115 .update_status = brightness_update_status,
6116}; 6116};
@@ -7194,7 +7194,7 @@ static struct ibm_struct volume_driver_data = {
7194 * TPACPI_FAN_WR_ACPI_FANS (X31/X40/X41) 7194 * TPACPI_FAN_WR_ACPI_FANS (X31/X40/X41)
7195 * 7195 *
7196 * FIRMWARE BUG: on some models, EC 0x2f might not be initialized at 7196 * FIRMWARE BUG: on some models, EC 0x2f might not be initialized at
7197 * boot. Apparently the EC does not intialize it, so unless ACPI DSDT 7197 * boot. Apparently the EC does not initialize it, so unless ACPI DSDT
7198 * does so, its initial value is meaningless (0x07). 7198 * does so, its initial value is meaningless (0x07).
7199 * 7199 *
7200 * For firmware bugs, refer to: 7200 * For firmware bugs, refer to:
diff --git a/drivers/platform/x86/toshiba_acpi.c b/drivers/platform/x86/toshiba_acpi.c
index 4276da7291b8..209cced786c6 100644
--- a/drivers/platform/x86/toshiba_acpi.c
+++ b/drivers/platform/x86/toshiba_acpi.c
@@ -841,7 +841,7 @@ static void remove_toshiba_proc_entries(void)
841 remove_proc_entry("version", toshiba_proc_dir); 841 remove_proc_entry("version", toshiba_proc_dir);
842} 842}
843 843
844static struct backlight_ops toshiba_backlight_data = { 844static const struct backlight_ops toshiba_backlight_data = {
845 .get_brightness = get_lcd, 845 .get_brightness = get_lcd,
846 .update_status = set_lcd_status, 846 .update_status = set_lcd_status,
847}; 847};
diff --git a/drivers/power/s3c_adc_battery.c b/drivers/power/s3c_adc_battery.c
index fe16b482e912..4a8ae3935b3b 100644
--- a/drivers/power/s3c_adc_battery.c
+++ b/drivers/power/s3c_adc_battery.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * iPAQ h1930/h1940/rx1950 battery controler driver 2 * iPAQ h1930/h1940/rx1950 battery controller driver
3 * Copyright (c) Vasily Khoruzhick 3 * Copyright (c) Vasily Khoruzhick
4 * Based on h1940_battery.c by Arnaud Patard 4 * Based on h1940_battery.c by Arnaud Patard
5 * 5 *
@@ -427,5 +427,5 @@ static void __exit s3c_adc_bat_exit(void)
427module_exit(s3c_adc_bat_exit); 427module_exit(s3c_adc_bat_exit);
428 428
429MODULE_AUTHOR("Vasily Khoruzhick <anarsoul@gmail.com>"); 429MODULE_AUTHOR("Vasily Khoruzhick <anarsoul@gmail.com>");
430MODULE_DESCRIPTION("iPAQ H1930/H1940/RX1950 battery controler driver"); 430MODULE_DESCRIPTION("iPAQ H1930/H1940/RX1950 battery controller driver");
431MODULE_LICENSE("GPL"); 431MODULE_LICENSE("GPL");
diff --git a/drivers/pps/Kconfig b/drivers/pps/Kconfig
index 1afe4e03440f..f0d3376b58ba 100644
--- a/drivers/pps/Kconfig
+++ b/drivers/pps/Kconfig
@@ -30,6 +30,17 @@ config PPS_DEBUG
30 messages to the system log. Select this if you are having a 30 messages to the system log. Select this if you are having a
31 problem with PPS support and want to see more of what is going on. 31 problem with PPS support and want to see more of what is going on.
32 32
33config NTP_PPS
34 bool "PPS kernel consumer support"
35 depends on PPS && !NO_HZ
36 help
37 This option adds support for direct in-kernel time
38 syncronization using an external PPS signal.
39
40 It doesn't work on tickless systems at the moment.
41
33source drivers/pps/clients/Kconfig 42source drivers/pps/clients/Kconfig
34 43
44source drivers/pps/generators/Kconfig
45
35endmenu 46endmenu
diff --git a/drivers/pps/Makefile b/drivers/pps/Makefile
index 98960ddd3188..4483eaadaddd 100644
--- a/drivers/pps/Makefile
+++ b/drivers/pps/Makefile
@@ -3,7 +3,8 @@
3# 3#
4 4
5pps_core-y := pps.o kapi.o sysfs.o 5pps_core-y := pps.o kapi.o sysfs.o
6pps_core-$(CONFIG_NTP_PPS) += kc.o
6obj-$(CONFIG_PPS) := pps_core.o 7obj-$(CONFIG_PPS) := pps_core.o
7obj-y += clients/ 8obj-y += clients/ generators/
8 9
9ccflags-$(CONFIG_PPS_DEBUG) := -DDEBUG 10ccflags-$(CONFIG_PPS_DEBUG) := -DDEBUG
diff --git a/drivers/pps/clients/Kconfig b/drivers/pps/clients/Kconfig
index 4e801bd7254f..8520a7f4dd62 100644
--- a/drivers/pps/clients/Kconfig
+++ b/drivers/pps/clients/Kconfig
@@ -22,4 +22,11 @@ config PPS_CLIENT_LDISC
22 If you say yes here you get support for a PPS source connected 22 If you say yes here you get support for a PPS source connected
23 with the CD (Carrier Detect) pin of your serial port. 23 with the CD (Carrier Detect) pin of your serial port.
24 24
25config PPS_CLIENT_PARPORT
26 tristate "Parallel port PPS client"
27 depends on PPS && PARPORT
28 help
29 If you say yes here you get support for a PPS source connected
30 with the interrupt pin of your parallel port.
31
25endif 32endif
diff --git a/drivers/pps/clients/Makefile b/drivers/pps/clients/Makefile
index 812c9b19b430..42517da07049 100644
--- a/drivers/pps/clients/Makefile
+++ b/drivers/pps/clients/Makefile
@@ -4,6 +4,7 @@
4 4
5obj-$(CONFIG_PPS_CLIENT_KTIMER) += pps-ktimer.o 5obj-$(CONFIG_PPS_CLIENT_KTIMER) += pps-ktimer.o
6obj-$(CONFIG_PPS_CLIENT_LDISC) += pps-ldisc.o 6obj-$(CONFIG_PPS_CLIENT_LDISC) += pps-ldisc.o
7obj-$(CONFIG_PPS_CLIENT_PARPORT) += pps_parport.o
7 8
8ifeq ($(CONFIG_PPS_DEBUG),y) 9ifeq ($(CONFIG_PPS_DEBUG),y)
9EXTRA_CFLAGS += -DDEBUG 10EXTRA_CFLAGS += -DDEBUG
diff --git a/drivers/pps/clients/pps-ktimer.c b/drivers/pps/clients/pps-ktimer.c
index e7ef5b8186d0..2728469d3884 100644
--- a/drivers/pps/clients/pps-ktimer.c
+++ b/drivers/pps/clients/pps-ktimer.c
@@ -19,6 +19,7 @@
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 */ 20 */
21 21
22#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
22 23
23#include <linux/kernel.h> 24#include <linux/kernel.h>
24#include <linux/module.h> 25#include <linux/module.h>
@@ -31,7 +32,7 @@
31 * Global variables 32 * Global variables
32 */ 33 */
33 34
34static int source; 35static struct pps_device *pps;
35static struct timer_list ktimer; 36static struct timer_list ktimer;
36 37
37/* 38/*
@@ -40,19 +41,14 @@ static struct timer_list ktimer;
40 41
41static void pps_ktimer_event(unsigned long ptr) 42static void pps_ktimer_event(unsigned long ptr)
42{ 43{
43 struct timespec __ts; 44 struct pps_event_time ts;
44 struct pps_ktime ts;
45 45
46 /* First of all we get the time stamp... */ 46 /* First of all we get the time stamp... */
47 getnstimeofday(&__ts); 47 pps_get_ts(&ts);
48 48
49 pr_info("PPS event at %lu\n", jiffies); 49 dev_info(pps->dev, "PPS event at %lu\n", jiffies);
50 50
51 /* ... and translate it to PPS time data struct */ 51 pps_event(pps, &ts, PPS_CAPTUREASSERT, NULL);
52 ts.sec = __ts.tv_sec;
53 ts.nsec = __ts.tv_nsec;
54
55 pps_event(source, &ts, PPS_CAPTUREASSERT, NULL);
56 52
57 mod_timer(&ktimer, jiffies + HZ); 53 mod_timer(&ktimer, jiffies + HZ);
58} 54}
@@ -61,12 +57,11 @@ static void pps_ktimer_event(unsigned long ptr)
61 * The echo function 57 * The echo function
62 */ 58 */
63 59
64static void pps_ktimer_echo(int source, int event, void *data) 60static void pps_ktimer_echo(struct pps_device *pps, int event, void *data)
65{ 61{
66 pr_info("echo %s %s for source %d\n", 62 dev_info(pps->dev, "echo %s %s\n",
67 event & PPS_CAPTUREASSERT ? "assert" : "", 63 event & PPS_CAPTUREASSERT ? "assert" : "",
68 event & PPS_CAPTURECLEAR ? "clear" : "", 64 event & PPS_CAPTURECLEAR ? "clear" : "");
69 source);
70} 65}
71 66
72/* 67/*
@@ -89,30 +84,27 @@ static struct pps_source_info pps_ktimer_info = {
89 84
90static void __exit pps_ktimer_exit(void) 85static void __exit pps_ktimer_exit(void)
91{ 86{
92 del_timer_sync(&ktimer); 87 dev_info(pps->dev, "ktimer PPS source unregistered\n");
93 pps_unregister_source(source);
94 88
95 pr_info("ktimer PPS source unregistered\n"); 89 del_timer_sync(&ktimer);
90 pps_unregister_source(pps);
96} 91}
97 92
98static int __init pps_ktimer_init(void) 93static int __init pps_ktimer_init(void)
99{ 94{
100 int ret; 95 pps = pps_register_source(&pps_ktimer_info,
101
102 ret = pps_register_source(&pps_ktimer_info,
103 PPS_CAPTUREASSERT | PPS_OFFSETASSERT); 96 PPS_CAPTUREASSERT | PPS_OFFSETASSERT);
104 if (ret < 0) { 97 if (pps == NULL) {
105 printk(KERN_ERR "cannot register ktimer source\n"); 98 pr_err("cannot register PPS source\n");
106 return ret; 99 return -ENOMEM;
107 } 100 }
108 source = ret;
109 101
110 setup_timer(&ktimer, pps_ktimer_event, 0); 102 setup_timer(&ktimer, pps_ktimer_event, 0);
111 mod_timer(&ktimer, jiffies + HZ); 103 mod_timer(&ktimer, jiffies + HZ);
112 104
113 pr_info("ktimer PPS source registered at %d\n", source); 105 dev_info(pps->dev, "ktimer PPS source registered\n");
114 106
115 return 0; 107 return 0;
116} 108}
117 109
118module_init(pps_ktimer_init); 110module_init(pps_ktimer_init);
diff --git a/drivers/pps/clients/pps-ldisc.c b/drivers/pps/clients/pps-ldisc.c
index 8e1932d29fd4..79451f2dea6a 100644
--- a/drivers/pps/clients/pps-ldisc.c
+++ b/drivers/pps/clients/pps-ldisc.c
@@ -19,6 +19,8 @@
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 */ 20 */
21 21
22#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
23
22#include <linux/module.h> 24#include <linux/module.h>
23#include <linux/serial_core.h> 25#include <linux/serial_core.h>
24#include <linux/tty.h> 26#include <linux/tty.h>
@@ -27,30 +29,18 @@
27#define PPS_TTY_MAGIC 0x0001 29#define PPS_TTY_MAGIC 0x0001
28 30
29static void pps_tty_dcd_change(struct tty_struct *tty, unsigned int status, 31static void pps_tty_dcd_change(struct tty_struct *tty, unsigned int status,
30 struct timespec *ts) 32 struct pps_event_time *ts)
31{ 33{
32 int id = (long)tty->disc_data; 34 struct pps_device *pps = (struct pps_device *)tty->disc_data;
33 struct timespec __ts; 35
34 struct pps_ktime pps_ts; 36 BUG_ON(pps == NULL);
35
36 /* First of all we get the time stamp... */
37 getnstimeofday(&__ts);
38
39 /* Does caller give us a timestamp? */
40 if (ts) { /* Yes. Let's use it! */
41 pps_ts.sec = ts->tv_sec;
42 pps_ts.nsec = ts->tv_nsec;
43 } else { /* No. Do it ourself! */
44 pps_ts.sec = __ts.tv_sec;
45 pps_ts.nsec = __ts.tv_nsec;
46 }
47 37
48 /* Now do the PPS event report */ 38 /* Now do the PPS event report */
49 pps_event(id, &pps_ts, status ? PPS_CAPTUREASSERT : PPS_CAPTURECLEAR, 39 pps_event(pps, ts, status ? PPS_CAPTUREASSERT :
50 NULL); 40 PPS_CAPTURECLEAR, NULL);
51 41
52 pr_debug("PPS %s at %lu on source #%d\n", 42 dev_dbg(pps->dev, "PPS %s at %lu\n",
53 status ? "assert" : "clear", jiffies, id); 43 status ? "assert" : "clear", jiffies);
54} 44}
55 45
56static int (*alias_n_tty_open)(struct tty_struct *tty); 46static int (*alias_n_tty_open)(struct tty_struct *tty);
@@ -60,6 +50,7 @@ static int pps_tty_open(struct tty_struct *tty)
60 struct pps_source_info info; 50 struct pps_source_info info;
61 struct tty_driver *drv = tty->driver; 51 struct tty_driver *drv = tty->driver;
62 int index = tty->index + drv->name_base; 52 int index = tty->index + drv->name_base;
53 struct pps_device *pps;
63 int ret; 54 int ret;
64 55
65 info.owner = THIS_MODULE; 56 info.owner = THIS_MODULE;
@@ -70,34 +61,42 @@ static int pps_tty_open(struct tty_struct *tty)
70 PPS_OFFSETASSERT | PPS_OFFSETCLEAR | \ 61 PPS_OFFSETASSERT | PPS_OFFSETCLEAR | \
71 PPS_CANWAIT | PPS_TSFMT_TSPEC; 62 PPS_CANWAIT | PPS_TSFMT_TSPEC;
72 63
73 ret = pps_register_source(&info, PPS_CAPTUREBOTH | \ 64 pps = pps_register_source(&info, PPS_CAPTUREBOTH | \
74 PPS_OFFSETASSERT | PPS_OFFSETCLEAR); 65 PPS_OFFSETASSERT | PPS_OFFSETCLEAR);
75 if (ret < 0) { 66 if (pps == NULL) {
76 pr_err("cannot register PPS source \"%s\"\n", info.path); 67 pr_err("cannot register PPS source \"%s\"\n", info.path);
77 return ret; 68 return -ENOMEM;
78 } 69 }
79 tty->disc_data = (void *)(long)ret; 70 tty->disc_data = pps;
80 71
81 /* Should open N_TTY ldisc too */ 72 /* Should open N_TTY ldisc too */
82 ret = alias_n_tty_open(tty); 73 ret = alias_n_tty_open(tty);
83 if (ret < 0) 74 if (ret < 0) {
84 pps_unregister_source((long)tty->disc_data); 75 pr_err("cannot open tty ldisc \"%s\"\n", info.path);
76 goto err_unregister;
77 }
85 78
86 pr_info("PPS source #%d \"%s\" added\n", ret, info.path); 79 dev_info(pps->dev, "source \"%s\" added\n", info.path);
87 80
88 return 0; 81 return 0;
82
83err_unregister:
84 tty->disc_data = NULL;
85 pps_unregister_source(pps);
86 return ret;
89} 87}
90 88
91static void (*alias_n_tty_close)(struct tty_struct *tty); 89static void (*alias_n_tty_close)(struct tty_struct *tty);
92 90
93static void pps_tty_close(struct tty_struct *tty) 91static void pps_tty_close(struct tty_struct *tty)
94{ 92{
95 int id = (long)tty->disc_data; 93 struct pps_device *pps = (struct pps_device *)tty->disc_data;
96 94
97 pps_unregister_source(id);
98 alias_n_tty_close(tty); 95 alias_n_tty_close(tty);
99 96
100 pr_info("PPS source #%d removed\n", id); 97 tty->disc_data = NULL;
98 dev_info(pps->dev, "removed\n");
99 pps_unregister_source(pps);
101} 100}
102 101
103static struct tty_ldisc_ops pps_ldisc_ops; 102static struct tty_ldisc_ops pps_ldisc_ops;
diff --git a/drivers/pps/clients/pps_parport.c b/drivers/pps/clients/pps_parport.c
new file mode 100644
index 000000000000..32221efd9ca9
--- /dev/null
+++ b/drivers/pps/clients/pps_parport.c
@@ -0,0 +1,258 @@
1/*
2 * pps_parport.c -- kernel parallel port PPS client
3 *
4 *
5 * Copyright (C) 2009 Alexander Gordeev <lasaine@lvk.cs.msu.su>
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
23/*
24 * TODO:
25 * implement echo over SEL pin
26 */
27
28#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
29
30#include <linux/kernel.h>
31#include <linux/module.h>
32#include <linux/init.h>
33#include <linux/irqnr.h>
34#include <linux/time.h>
35#include <linux/parport.h>
36#include <linux/pps_kernel.h>
37
38#define DRVDESC "parallel port PPS client"
39
40/* module parameters */
41
42#define CLEAR_WAIT_MAX 100
43#define CLEAR_WAIT_MAX_ERRORS 5
44
45static unsigned int clear_wait = 100;
46MODULE_PARM_DESC(clear_wait,
47 "Maximum number of port reads when polling for signal clear,"
48 " zero turns clear edge capture off entirely");
49module_param(clear_wait, uint, 0);
50
51
52/* internal per port structure */
53struct pps_client_pp {
54 struct pardevice *pardev; /* parport device */
55 struct pps_device *pps; /* PPS device */
56 unsigned int cw; /* port clear timeout */
57 unsigned int cw_err; /* number of timeouts */
58};
59
60static inline int signal_is_set(struct parport *port)
61{
62 return (port->ops->read_status(port) & PARPORT_STATUS_ACK) != 0;
63}
64
65/* parport interrupt handler */
66static void parport_irq(void *handle)
67{
68 struct pps_event_time ts_assert, ts_clear;
69 struct pps_client_pp *dev = handle;
70 struct parport *port = dev->pardev->port;
71 unsigned int i;
72 unsigned long flags;
73
74 /* first of all we get the time stamp... */
75 pps_get_ts(&ts_assert);
76
77 if (dev->cw == 0)
78 /* clear edge capture disabled */
79 goto out_assert;
80
81 /* try capture the clear edge */
82
83 /* We have to disable interrupts here. The idea is to prevent
84 * other interrupts on the same processor to introduce random
85 * lags while polling the port. Reading from IO port is known
86 * to take approximately 1us while other interrupt handlers can
87 * take much more potentially.
88 *
89 * Interrupts won't be disabled for a long time because the
90 * number of polls is limited by clear_wait parameter which is
91 * kept rather low. So it should never be an issue.
92 */
93 local_irq_save(flags);
94 /* check the signal (no signal means the pulse is lost this time) */
95 if (!signal_is_set(port)) {
96 local_irq_restore(flags);
97 dev_err(dev->pps->dev, "lost the signal\n");
98 goto out_assert;
99 }
100
101 /* poll the port until the signal is unset */
102 for (i = dev->cw; i; i--)
103 if (!signal_is_set(port)) {
104 pps_get_ts(&ts_clear);
105 local_irq_restore(flags);
106 dev->cw_err = 0;
107 goto out_both;
108 }
109 local_irq_restore(flags);
110
111 /* timeout */
112 dev->cw_err++;
113 if (dev->cw_err >= CLEAR_WAIT_MAX_ERRORS) {
114 dev_err(dev->pps->dev, "disabled clear edge capture after %d"
115 " timeouts\n", dev->cw_err);
116 dev->cw = 0;
117 dev->cw_err = 0;
118 }
119
120out_assert:
121 /* fire assert event */
122 pps_event(dev->pps, &ts_assert,
123 PPS_CAPTUREASSERT, NULL);
124 return;
125
126out_both:
127 /* fire assert event */
128 pps_event(dev->pps, &ts_assert,
129 PPS_CAPTUREASSERT, NULL);
130 /* fire clear event */
131 pps_event(dev->pps, &ts_clear,
132 PPS_CAPTURECLEAR, NULL);
133 return;
134}
135
136/* the PPS echo function */
137static void pps_echo(struct pps_device *pps, int event, void *data)
138{
139 dev_info(pps->dev, "echo %s %s\n",
140 event & PPS_CAPTUREASSERT ? "assert" : "",
141 event & PPS_CAPTURECLEAR ? "clear" : "");
142}
143
144static void parport_attach(struct parport *port)
145{
146 struct pps_client_pp *device;
147 struct pps_source_info info = {
148 .name = KBUILD_MODNAME,
149 .path = "",
150 .mode = PPS_CAPTUREBOTH | \
151 PPS_OFFSETASSERT | PPS_OFFSETCLEAR | \
152 PPS_ECHOASSERT | PPS_ECHOCLEAR | \
153 PPS_CANWAIT | PPS_TSFMT_TSPEC,
154 .echo = pps_echo,
155 .owner = THIS_MODULE,
156 .dev = NULL
157 };
158
159 device = kzalloc(sizeof(struct pps_client_pp), GFP_KERNEL);
160 if (!device) {
161 pr_err("memory allocation failed, not attaching\n");
162 return;
163 }
164
165 device->pardev = parport_register_device(port, KBUILD_MODNAME,
166 NULL, NULL, parport_irq, 0, device);
167 if (!device->pardev) {
168 pr_err("couldn't register with %s\n", port->name);
169 goto err_free;
170 }
171
172 if (parport_claim_or_block(device->pardev) < 0) {
173 pr_err("couldn't claim %s\n", port->name);
174 goto err_unregister_dev;
175 }
176
177 device->pps = pps_register_source(&info,
178 PPS_CAPTUREBOTH | PPS_OFFSETASSERT | PPS_OFFSETCLEAR);
179 if (device->pps == NULL) {
180 pr_err("couldn't register PPS source\n");
181 goto err_release_dev;
182 }
183
184 device->cw = clear_wait;
185
186 port->ops->enable_irq(port);
187
188 pr_info("attached to %s\n", port->name);
189
190 return;
191
192err_release_dev:
193 parport_release(device->pardev);
194err_unregister_dev:
195 parport_unregister_device(device->pardev);
196err_free:
197 kfree(device);
198}
199
200static void parport_detach(struct parport *port)
201{
202 struct pardevice *pardev = port->cad;
203 struct pps_client_pp *device;
204
205 /* FIXME: oooh, this is ugly! */
206 if (strcmp(pardev->name, KBUILD_MODNAME))
207 /* not our port */
208 return;
209
210 device = pardev->private;
211
212 port->ops->disable_irq(port);
213 pps_unregister_source(device->pps);
214 parport_release(pardev);
215 parport_unregister_device(pardev);
216 kfree(device);
217}
218
219static struct parport_driver pps_parport_driver = {
220 .name = KBUILD_MODNAME,
221 .attach = parport_attach,
222 .detach = parport_detach,
223};
224
225/* module staff */
226
227static int __init pps_parport_init(void)
228{
229 int ret;
230
231 pr_info(DRVDESC "\n");
232
233 if (clear_wait > CLEAR_WAIT_MAX) {
234 pr_err("clear_wait value should be not greater"
235 " then %d\n", CLEAR_WAIT_MAX);
236 return -EINVAL;
237 }
238
239 ret = parport_register_driver(&pps_parport_driver);
240 if (ret) {
241 pr_err("unable to register with parport\n");
242 return ret;
243 }
244
245 return 0;
246}
247
248static void __exit pps_parport_exit(void)
249{
250 parport_unregister_driver(&pps_parport_driver);
251}
252
253module_init(pps_parport_init);
254module_exit(pps_parport_exit);
255
256MODULE_AUTHOR("Alexander Gordeev <lasaine@lvk.cs.msu.su>");
257MODULE_DESCRIPTION(DRVDESC);
258MODULE_LICENSE("GPL");
diff --git a/drivers/pps/generators/Kconfig b/drivers/pps/generators/Kconfig
new file mode 100644
index 000000000000..f3a73dd77660
--- /dev/null
+++ b/drivers/pps/generators/Kconfig
@@ -0,0 +1,13 @@
1#
2# PPS generators configuration
3#
4
5comment "PPS generators support"
6
7config PPS_GENERATOR_PARPORT
8 tristate "Parallel port PPS signal generator"
9 depends on PARPORT
10 help
11 If you say yes here you get support for a PPS signal generator which
12 utilizes STROBE pin of a parallel port to send PPS signals. It uses
13 parport abstraction layer and hrtimers to precisely control the signal.
diff --git a/drivers/pps/generators/Makefile b/drivers/pps/generators/Makefile
new file mode 100644
index 000000000000..303304a6b8ec
--- /dev/null
+++ b/drivers/pps/generators/Makefile
@@ -0,0 +1,9 @@
1#
2# Makefile for PPS generators.
3#
4
5obj-$(CONFIG_PPS_GENERATOR_PARPORT) += pps_gen_parport.o
6
7ifeq ($(CONFIG_PPS_DEBUG),y)
8EXTRA_CFLAGS += -DDEBUG
9endif
diff --git a/drivers/pps/generators/pps_gen_parport.c b/drivers/pps/generators/pps_gen_parport.c
new file mode 100644
index 000000000000..5c32f8dacf56
--- /dev/null
+++ b/drivers/pps/generators/pps_gen_parport.c
@@ -0,0 +1,282 @@
1/*
2 * pps_gen_parport.c -- kernel parallel port PPS signal generator
3 *
4 *
5 * Copyright (C) 2009 Alexander Gordeev <lasaine@lvk.cs.msu.su>
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
23/*
24 * TODO:
25 * fix issues when realtime clock is adjusted in a leap
26 */
27
28#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
29
30#include <linux/kernel.h>
31#include <linux/module.h>
32#include <linux/init.h>
33#include <linux/time.h>
34#include <linux/hrtimer.h>
35#include <linux/parport.h>
36
37#define DRVDESC "parallel port PPS signal generator"
38
39#define SIGNAL 0
40#define NO_SIGNAL PARPORT_CONTROL_STROBE
41
42/* module parameters */
43
44#define SEND_DELAY_MAX 100000
45
46static unsigned int send_delay = 30000;
47MODULE_PARM_DESC(delay,
48 "Delay between setting and dropping the signal (ns)");
49module_param_named(delay, send_delay, uint, 0);
50
51
52#define SAFETY_INTERVAL 3000 /* set the hrtimer earlier for safety (ns) */
53
54/* internal per port structure */
55struct pps_generator_pp {
56 struct pardevice *pardev; /* parport device */
57 struct hrtimer timer;
58 long port_write_time; /* calibrated port write time (ns) */
59};
60
61static struct pps_generator_pp device = {
62 .pardev = NULL,
63};
64
65static int attached;
66
67/* calibrated time between a hrtimer event and the reaction */
68static long hrtimer_error = SAFETY_INTERVAL;
69
70/* the kernel hrtimer event */
71static enum hrtimer_restart hrtimer_event(struct hrtimer *timer)
72{
73 struct timespec expire_time, ts1, ts2, ts3, dts;
74 struct pps_generator_pp *dev;
75 struct parport *port;
76 long lim, delta;
77 unsigned long flags;
78
79 /* We have to disable interrupts here. The idea is to prevent
80 * other interrupts on the same processor to introduce random
81 * lags while polling the clock. getnstimeofday() takes <1us on
82 * most machines while other interrupt handlers can take much
83 * more potentially.
84 *
85 * NB: approx time with blocked interrupts =
86 * send_delay + 3 * SAFETY_INTERVAL
87 */
88 local_irq_save(flags);
89
90 /* first of all we get the time stamp... */
91 getnstimeofday(&ts1);
92 expire_time = ktime_to_timespec(hrtimer_get_softexpires(timer));
93 dev = container_of(timer, struct pps_generator_pp, timer);
94 lim = NSEC_PER_SEC - send_delay - dev->port_write_time;
95
96 /* check if we are late */
97 if (expire_time.tv_sec != ts1.tv_sec || ts1.tv_nsec > lim) {
98 local_irq_restore(flags);
99 pr_err("we are late this time %ld.%09ld\n",
100 ts1.tv_sec, ts1.tv_nsec);
101 goto done;
102 }
103
104 /* busy loop until the time is right for an assert edge */
105 do {
106 getnstimeofday(&ts2);
107 } while (expire_time.tv_sec == ts2.tv_sec && ts2.tv_nsec < lim);
108
109 /* set the signal */
110 port = dev->pardev->port;
111 port->ops->write_control(port, SIGNAL);
112
113 /* busy loop until the time is right for a clear edge */
114 lim = NSEC_PER_SEC - dev->port_write_time;
115 do {
116 getnstimeofday(&ts2);
117 } while (expire_time.tv_sec == ts2.tv_sec && ts2.tv_nsec < lim);
118
119 /* unset the signal */
120 port->ops->write_control(port, NO_SIGNAL);
121
122 getnstimeofday(&ts3);
123
124 local_irq_restore(flags);
125
126 /* update calibrated port write time */
127 dts = timespec_sub(ts3, ts2);
128 dev->port_write_time =
129 (dev->port_write_time + timespec_to_ns(&dts)) >> 1;
130
131done:
132 /* update calibrated hrtimer error */
133 dts = timespec_sub(ts1, expire_time);
134 delta = timespec_to_ns(&dts);
135 /* If the new error value is bigger then the old, use the new
136 * value, if not then slowly move towards the new value. This
137 * way it should be safe in bad conditions and efficient in
138 * good conditions.
139 */
140 if (delta >= hrtimer_error)
141 hrtimer_error = delta;
142 else
143 hrtimer_error = (3 * hrtimer_error + delta) >> 2;
144
145 /* update the hrtimer expire time */
146 hrtimer_set_expires(timer,
147 ktime_set(expire_time.tv_sec + 1,
148 NSEC_PER_SEC - (send_delay +
149 dev->port_write_time + SAFETY_INTERVAL +
150 2 * hrtimer_error)));
151
152 return HRTIMER_RESTART;
153}
154
155/* calibrate port write time */
156#define PORT_NTESTS_SHIFT 5
157static void calibrate_port(struct pps_generator_pp *dev)
158{
159 struct parport *port = dev->pardev->port;
160 int i;
161 long acc = 0;
162
163 for (i = 0; i < (1 << PORT_NTESTS_SHIFT); i++) {
164 struct timespec a, b;
165 unsigned long irq_flags;
166
167 local_irq_save(irq_flags);
168 getnstimeofday(&a);
169 port->ops->write_control(port, NO_SIGNAL);
170 getnstimeofday(&b);
171 local_irq_restore(irq_flags);
172
173 b = timespec_sub(b, a);
174 acc += timespec_to_ns(&b);
175 }
176
177 dev->port_write_time = acc >> PORT_NTESTS_SHIFT;
178 pr_info("port write takes %ldns\n", dev->port_write_time);
179}
180
181static inline ktime_t next_intr_time(struct pps_generator_pp *dev)
182{
183 struct timespec ts;
184
185 getnstimeofday(&ts);
186
187 return ktime_set(ts.tv_sec +
188 ((ts.tv_nsec > 990 * NSEC_PER_MSEC) ? 1 : 0),
189 NSEC_PER_SEC - (send_delay +
190 dev->port_write_time + 3 * SAFETY_INTERVAL));
191}
192
193static void parport_attach(struct parport *port)
194{
195 if (attached) {
196 /* we already have a port */
197 return;
198 }
199
200 device.pardev = parport_register_device(port, KBUILD_MODNAME,
201 NULL, NULL, NULL, 0, &device);
202 if (!device.pardev) {
203 pr_err("couldn't register with %s\n", port->name);
204 return;
205 }
206
207 if (parport_claim_or_block(device.pardev) < 0) {
208 pr_err("couldn't claim %s\n", port->name);
209 goto err_unregister_dev;
210 }
211
212 pr_info("attached to %s\n", port->name);
213 attached = 1;
214
215 calibrate_port(&device);
216
217 hrtimer_init(&device.timer, CLOCK_REALTIME, HRTIMER_MODE_ABS);
218 device.timer.function = hrtimer_event;
219#ifdef CONFIG_PREEMPT_RT
220 /* hrtimer interrupt will run in the interrupt context with this */
221 device.timer.irqsafe = 1;
222#endif
223
224 hrtimer_start(&device.timer, next_intr_time(&device), HRTIMER_MODE_ABS);
225
226 return;
227
228err_unregister_dev:
229 parport_unregister_device(device.pardev);
230}
231
232static void parport_detach(struct parport *port)
233{
234 if (port->cad != device.pardev)
235 return; /* not our port */
236
237 hrtimer_cancel(&device.timer);
238 parport_release(device.pardev);
239 parport_unregister_device(device.pardev);
240}
241
242static struct parport_driver pps_gen_parport_driver = {
243 .name = KBUILD_MODNAME,
244 .attach = parport_attach,
245 .detach = parport_detach,
246};
247
248/* module staff */
249
250static int __init pps_gen_parport_init(void)
251{
252 int ret;
253
254 pr_info(DRVDESC "\n");
255
256 if (send_delay > SEND_DELAY_MAX) {
257 pr_err("delay value should be not greater"
258 " then %d\n", SEND_DELAY_MAX);
259 return -EINVAL;
260 }
261
262 ret = parport_register_driver(&pps_gen_parport_driver);
263 if (ret) {
264 pr_err("unable to register with parport\n");
265 return ret;
266 }
267
268 return 0;
269}
270
271static void __exit pps_gen_parport_exit(void)
272{
273 parport_unregister_driver(&pps_gen_parport_driver);
274 pr_info("hrtimer avg error is %ldns\n", hrtimer_error);
275}
276
277module_init(pps_gen_parport_init);
278module_exit(pps_gen_parport_exit);
279
280MODULE_AUTHOR("Alexander Gordeev <lasaine@lvk.cs.msu.su>");
281MODULE_DESCRIPTION(DRVDESC);
282MODULE_LICENSE("GPL");
diff --git a/drivers/pps/kapi.c b/drivers/pps/kapi.c
index 1aa02db3ff4e..cba1b43f7519 100644
--- a/drivers/pps/kapi.c
+++ b/drivers/pps/kapi.c
@@ -19,24 +19,20 @@
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 */ 20 */
21 21
22#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
22 23
23#include <linux/kernel.h> 24#include <linux/kernel.h>
24#include <linux/module.h> 25#include <linux/module.h>
25#include <linux/init.h> 26#include <linux/init.h>
26#include <linux/sched.h> 27#include <linux/sched.h>
27#include <linux/time.h> 28#include <linux/time.h>
29#include <linux/timex.h>
28#include <linux/spinlock.h> 30#include <linux/spinlock.h>
29#include <linux/idr.h>
30#include <linux/fs.h> 31#include <linux/fs.h>
31#include <linux/pps_kernel.h> 32#include <linux/pps_kernel.h>
32#include <linux/slab.h> 33#include <linux/slab.h>
33 34
34/* 35#include "kc.h"
35 * Global variables
36 */
37
38DEFINE_SPINLOCK(pps_idr_lock);
39DEFINE_IDR(pps_idr);
40 36
41/* 37/*
42 * Local functions 38 * Local functions
@@ -60,60 +56,6 @@ static void pps_add_offset(struct pps_ktime *ts, struct pps_ktime *offset)
60 * Exported functions 56 * Exported functions
61 */ 57 */
62 58
63/* pps_get_source - find a PPS source
64 * @source: the PPS source ID.
65 *
66 * This function is used to find an already registered PPS source into the
67 * system.
68 *
69 * The function returns NULL if found nothing, otherwise it returns a pointer
70 * to the PPS source data struct (the refcounter is incremented by 1).
71 */
72
73struct pps_device *pps_get_source(int source)
74{
75 struct pps_device *pps;
76 unsigned long flags;
77
78 spin_lock_irqsave(&pps_idr_lock, flags);
79
80 pps = idr_find(&pps_idr, source);
81 if (pps != NULL)
82 atomic_inc(&pps->usage);
83
84 spin_unlock_irqrestore(&pps_idr_lock, flags);
85
86 return pps;
87}
88
89/* pps_put_source - free the PPS source data
90 * @pps: a pointer to the PPS source.
91 *
92 * This function is used to free a PPS data struct if its refcount is 0.
93 */
94
95void pps_put_source(struct pps_device *pps)
96{
97 unsigned long flags;
98
99 spin_lock_irqsave(&pps_idr_lock, flags);
100 BUG_ON(atomic_read(&pps->usage) == 0);
101
102 if (!atomic_dec_and_test(&pps->usage)) {
103 pps = NULL;
104 goto exit;
105 }
106
107 /* No more reference to the PPS source. We can safely remove the
108 * PPS data struct.
109 */
110 idr_remove(&pps_idr, pps->id);
111
112exit:
113 spin_unlock_irqrestore(&pps_idr_lock, flags);
114 kfree(pps);
115}
116
117/* pps_register_source - add a PPS source in the system 59/* pps_register_source - add a PPS source in the system
118 * @info: the PPS info struct 60 * @info: the PPS info struct
119 * @default_params: the default PPS parameters of the new source 61 * @default_params: the default PPS parameters of the new source
@@ -122,31 +64,31 @@ exit:
122 * source is described by info's fields and it will have, as default PPS 64 * source is described by info's fields and it will have, as default PPS
123 * parameters, the ones specified into default_params. 65 * parameters, the ones specified into default_params.
124 * 66 *
125 * The function returns, in case of success, the PPS source ID. 67 * The function returns, in case of success, the PPS device. Otherwise NULL.
126 */ 68 */
127 69
128int pps_register_source(struct pps_source_info *info, int default_params) 70struct pps_device *pps_register_source(struct pps_source_info *info,
71 int default_params)
129{ 72{
130 struct pps_device *pps; 73 struct pps_device *pps;
131 int id;
132 int err; 74 int err;
133 75
134 /* Sanity checks */ 76 /* Sanity checks */
135 if ((info->mode & default_params) != default_params) { 77 if ((info->mode & default_params) != default_params) {
136 printk(KERN_ERR "pps: %s: unsupported default parameters\n", 78 pr_err("%s: unsupported default parameters\n",
137 info->name); 79 info->name);
138 err = -EINVAL; 80 err = -EINVAL;
139 goto pps_register_source_exit; 81 goto pps_register_source_exit;
140 } 82 }
141 if ((info->mode & (PPS_ECHOASSERT | PPS_ECHOCLEAR)) != 0 && 83 if ((info->mode & (PPS_ECHOASSERT | PPS_ECHOCLEAR)) != 0 &&
142 info->echo == NULL) { 84 info->echo == NULL) {
143 printk(KERN_ERR "pps: %s: echo function is not defined\n", 85 pr_err("%s: echo function is not defined\n",
144 info->name); 86 info->name);
145 err = -EINVAL; 87 err = -EINVAL;
146 goto pps_register_source_exit; 88 goto pps_register_source_exit;
147 } 89 }
148 if ((info->mode & (PPS_TSFMT_TSPEC | PPS_TSFMT_NTPFP)) == 0) { 90 if ((info->mode & (PPS_TSFMT_TSPEC | PPS_TSFMT_NTPFP)) == 0) {
149 printk(KERN_ERR "pps: %s: unspecified time format\n", 91 pr_err("%s: unspecified time format\n",
150 info->name); 92 info->name);
151 err = -EINVAL; 93 err = -EINVAL;
152 goto pps_register_source_exit; 94 goto pps_register_source_exit;
@@ -168,94 +110,48 @@ int pps_register_source(struct pps_source_info *info, int default_params)
168 110
169 init_waitqueue_head(&pps->queue); 111 init_waitqueue_head(&pps->queue);
170 spin_lock_init(&pps->lock); 112 spin_lock_init(&pps->lock);
171 atomic_set(&pps->usage, 1);
172
173 /* Get new ID for the new PPS source */
174 if (idr_pre_get(&pps_idr, GFP_KERNEL) == 0) {
175 err = -ENOMEM;
176 goto kfree_pps;
177 }
178
179 spin_lock_irq(&pps_idr_lock);
180
181 /* Now really allocate the PPS source.
182 * After idr_get_new() calling the new source will be freely available
183 * into the kernel.
184 */
185 err = idr_get_new(&pps_idr, pps, &id);
186 if (err < 0) {
187 spin_unlock_irq(&pps_idr_lock);
188 goto kfree_pps;
189 }
190
191 id = id & MAX_ID_MASK;
192 if (id >= PPS_MAX_SOURCES) {
193 spin_unlock_irq(&pps_idr_lock);
194
195 printk(KERN_ERR "pps: %s: too many PPS sources in the system\n",
196 info->name);
197 err = -EBUSY;
198 goto free_idr;
199 }
200 pps->id = id;
201
202 spin_unlock_irq(&pps_idr_lock);
203 113
204 /* Create the char device */ 114 /* Create the char device */
205 err = pps_register_cdev(pps); 115 err = pps_register_cdev(pps);
206 if (err < 0) { 116 if (err < 0) {
207 printk(KERN_ERR "pps: %s: unable to create char device\n", 117 pr_err("%s: unable to create char device\n",
208 info->name); 118 info->name);
209 goto free_idr; 119 goto kfree_pps;
210 } 120 }
211 121
212 pr_info("new PPS source %s at ID %d\n", info->name, id); 122 dev_info(pps->dev, "new PPS source %s\n", info->name);
213 123
214 return id; 124 return pps;
215
216free_idr:
217 spin_lock_irq(&pps_idr_lock);
218 idr_remove(&pps_idr, id);
219 spin_unlock_irq(&pps_idr_lock);
220 125
221kfree_pps: 126kfree_pps:
222 kfree(pps); 127 kfree(pps);
223 128
224pps_register_source_exit: 129pps_register_source_exit:
225 printk(KERN_ERR "pps: %s: unable to register source\n", info->name); 130 pr_err("%s: unable to register source\n", info->name);
226 131
227 return err; 132 return NULL;
228} 133}
229EXPORT_SYMBOL(pps_register_source); 134EXPORT_SYMBOL(pps_register_source);
230 135
231/* pps_unregister_source - remove a PPS source from the system 136/* pps_unregister_source - remove a PPS source from the system
232 * @source: the PPS source ID 137 * @pps: the PPS source
233 * 138 *
234 * This function is used to remove a previously registered PPS source from 139 * This function is used to remove a previously registered PPS source from
235 * the system. 140 * the system.
236 */ 141 */
237 142
238void pps_unregister_source(int source) 143void pps_unregister_source(struct pps_device *pps)
239{ 144{
240 struct pps_device *pps; 145 pps_kc_remove(pps);
241
242 spin_lock_irq(&pps_idr_lock);
243 pps = idr_find(&pps_idr, source);
244
245 if (!pps) {
246 BUG();
247 spin_unlock_irq(&pps_idr_lock);
248 return;
249 }
250 spin_unlock_irq(&pps_idr_lock);
251
252 pps_unregister_cdev(pps); 146 pps_unregister_cdev(pps);
253 pps_put_source(pps); 147
148 /* don't have to kfree(pps) here because it will be done on
149 * device destruction */
254} 150}
255EXPORT_SYMBOL(pps_unregister_source); 151EXPORT_SYMBOL(pps_unregister_source);
256 152
257/* pps_event - register a PPS event into the system 153/* pps_event - register a PPS event into the system
258 * @source: the PPS source ID 154 * @pps: the PPS device
259 * @ts: the event timestamp 155 * @ts: the event timestamp
260 * @event: the event type 156 * @event: the event type
261 * @data: userdef pointer 157 * @data: userdef pointer
@@ -263,78 +159,72 @@ EXPORT_SYMBOL(pps_unregister_source);
263 * This function is used by each PPS client in order to register a new 159 * This function is used by each PPS client in order to register a new
264 * PPS event into the system (it's usually called inside an IRQ handler). 160 * PPS event into the system (it's usually called inside an IRQ handler).
265 * 161 *
266 * If an echo function is associated with the PPS source it will be called 162 * If an echo function is associated with the PPS device it will be called
267 * as: 163 * as:
268 * pps->info.echo(source, event, data); 164 * pps->info.echo(pps, event, data);
269 */ 165 */
270 166void pps_event(struct pps_device *pps, struct pps_event_time *ts, int event,
271void pps_event(int source, struct pps_ktime *ts, int event, void *data) 167 void *data)
272{ 168{
273 struct pps_device *pps;
274 unsigned long flags; 169 unsigned long flags;
275 int captured = 0; 170 int captured = 0;
171 struct pps_ktime ts_real;
276 172
277 if ((event & (PPS_CAPTUREASSERT | PPS_CAPTURECLEAR)) == 0) { 173 /* check event type */
278 printk(KERN_ERR "pps: unknown event (%x) for source %d\n", 174 BUG_ON((event & (PPS_CAPTUREASSERT | PPS_CAPTURECLEAR)) == 0);
279 event, source);
280 return;
281 }
282 175
283 pps = pps_get_source(source); 176 dev_dbg(pps->dev, "PPS event at %ld.%09ld\n",
284 if (!pps) 177 ts->ts_real.tv_sec, ts->ts_real.tv_nsec);
285 return;
286 178
287 pr_debug("PPS event on source %d at %llu.%06u\n", 179 timespec_to_pps_ktime(&ts_real, ts->ts_real);
288 pps->id, (unsigned long long) ts->sec, ts->nsec);
289 180
290 spin_lock_irqsave(&pps->lock, flags); 181 spin_lock_irqsave(&pps->lock, flags);
291 182
292 /* Must call the echo function? */ 183 /* Must call the echo function? */
293 if ((pps->params.mode & (PPS_ECHOASSERT | PPS_ECHOCLEAR))) 184 if ((pps->params.mode & (PPS_ECHOASSERT | PPS_ECHOCLEAR)))
294 pps->info.echo(source, event, data); 185 pps->info.echo(pps, event, data);
295 186
296 /* Check the event */ 187 /* Check the event */
297 pps->current_mode = pps->params.mode; 188 pps->current_mode = pps->params.mode;
298 if ((event & PPS_CAPTUREASSERT) & 189 if (event & pps->params.mode & PPS_CAPTUREASSERT) {
299 (pps->params.mode & PPS_CAPTUREASSERT)) {
300 /* We have to add an offset? */ 190 /* We have to add an offset? */
301 if (pps->params.mode & PPS_OFFSETASSERT) 191 if (pps->params.mode & PPS_OFFSETASSERT)
302 pps_add_offset(ts, &pps->params.assert_off_tu); 192 pps_add_offset(&ts_real,
193 &pps->params.assert_off_tu);
303 194
304 /* Save the time stamp */ 195 /* Save the time stamp */
305 pps->assert_tu = *ts; 196 pps->assert_tu = ts_real;
306 pps->assert_sequence++; 197 pps->assert_sequence++;
307 pr_debug("capture assert seq #%u for source %d\n", 198 dev_dbg(pps->dev, "capture assert seq #%u\n",
308 pps->assert_sequence, source); 199 pps->assert_sequence);
309 200
310 captured = ~0; 201 captured = ~0;
311 } 202 }
312 if ((event & PPS_CAPTURECLEAR) & 203 if (event & pps->params.mode & PPS_CAPTURECLEAR) {
313 (pps->params.mode & PPS_CAPTURECLEAR)) {
314 /* We have to add an offset? */ 204 /* We have to add an offset? */
315 if (pps->params.mode & PPS_OFFSETCLEAR) 205 if (pps->params.mode & PPS_OFFSETCLEAR)
316 pps_add_offset(ts, &pps->params.clear_off_tu); 206 pps_add_offset(&ts_real,
207 &pps->params.clear_off_tu);
317 208
318 /* Save the time stamp */ 209 /* Save the time stamp */
319 pps->clear_tu = *ts; 210 pps->clear_tu = ts_real;
320 pps->clear_sequence++; 211 pps->clear_sequence++;
321 pr_debug("capture clear seq #%u for source %d\n", 212 dev_dbg(pps->dev, "capture clear seq #%u\n",
322 pps->clear_sequence, source); 213 pps->clear_sequence);
323 214
324 captured = ~0; 215 captured = ~0;
325 } 216 }
326 217
327 /* Wake up iif captured somthing */ 218 pps_kc_event(pps, ts, event);
219
220 /* Wake up if captured something */
328 if (captured) { 221 if (captured) {
329 pps->go = ~0; 222 pps->last_ev++;
330 wake_up_interruptible(&pps->queue); 223 wake_up_interruptible_all(&pps->queue);
331 224
332 kill_fasync(&pps->async_queue, SIGIO, POLL_IN); 225 kill_fasync(&pps->async_queue, SIGIO, POLL_IN);
333 } 226 }
334 227
335 spin_unlock_irqrestore(&pps->lock, flags); 228 spin_unlock_irqrestore(&pps->lock, flags);
336
337 /* Now we can release the PPS source for (possible) deregistration */
338 pps_put_source(pps);
339} 229}
340EXPORT_SYMBOL(pps_event); 230EXPORT_SYMBOL(pps_event);
diff --git a/drivers/pps/kc.c b/drivers/pps/kc.c
new file mode 100644
index 000000000000..079e930b1938
--- /dev/null
+++ b/drivers/pps/kc.c
@@ -0,0 +1,122 @@
1/*
2 * PPS kernel consumer API
3 *
4 * Copyright (C) 2009-2010 Alexander Gordeev <lasaine@lvk.cs.msu.su>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 */
20
21#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
22
23#include <linux/kernel.h>
24#include <linux/module.h>
25#include <linux/device.h>
26#include <linux/init.h>
27#include <linux/spinlock.h>
28#include <linux/pps_kernel.h>
29
30#include "kc.h"
31
32/*
33 * Global variables
34 */
35
36/* state variables to bind kernel consumer */
37DEFINE_SPINLOCK(pps_kc_hardpps_lock);
38/* PPS API (RFC 2783): current source and mode for kernel consumer */
39struct pps_device *pps_kc_hardpps_dev; /* unique pointer to device */
40int pps_kc_hardpps_mode; /* mode bits for kernel consumer */
41
42/* pps_kc_bind - control PPS kernel consumer binding
43 * @pps: the PPS source
44 * @bind_args: kernel consumer bind parameters
45 *
46 * This function is used to bind or unbind PPS kernel consumer according to
47 * supplied parameters. Should not be called in interrupt context.
48 */
49int pps_kc_bind(struct pps_device *pps, struct pps_bind_args *bind_args)
50{
51 /* Check if another consumer is already bound */
52 spin_lock_irq(&pps_kc_hardpps_lock);
53
54 if (bind_args->edge == 0)
55 if (pps_kc_hardpps_dev == pps) {
56 pps_kc_hardpps_mode = 0;
57 pps_kc_hardpps_dev = NULL;
58 spin_unlock_irq(&pps_kc_hardpps_lock);
59 dev_info(pps->dev, "unbound kernel"
60 " consumer\n");
61 } else {
62 spin_unlock_irq(&pps_kc_hardpps_lock);
63 dev_err(pps->dev, "selected kernel consumer"
64 " is not bound\n");
65 return -EINVAL;
66 }
67 else
68 if (pps_kc_hardpps_dev == NULL ||
69 pps_kc_hardpps_dev == pps) {
70 pps_kc_hardpps_mode = bind_args->edge;
71 pps_kc_hardpps_dev = pps;
72 spin_unlock_irq(&pps_kc_hardpps_lock);
73 dev_info(pps->dev, "bound kernel consumer: "
74 "edge=0x%x\n", bind_args->edge);
75 } else {
76 spin_unlock_irq(&pps_kc_hardpps_lock);
77 dev_err(pps->dev, "another kernel consumer"
78 " is already bound\n");
79 return -EINVAL;
80 }
81
82 return 0;
83}
84
85/* pps_kc_remove - unbind kernel consumer on PPS source removal
86 * @pps: the PPS source
87 *
88 * This function is used to disable kernel consumer on PPS source removal
89 * if this source was bound to PPS kernel consumer. Can be called on any
90 * source safely. Should not be called in interrupt context.
91 */
92void pps_kc_remove(struct pps_device *pps)
93{
94 spin_lock_irq(&pps_kc_hardpps_lock);
95 if (pps == pps_kc_hardpps_dev) {
96 pps_kc_hardpps_mode = 0;
97 pps_kc_hardpps_dev = NULL;
98 spin_unlock_irq(&pps_kc_hardpps_lock);
99 dev_info(pps->dev, "unbound kernel consumer"
100 " on device removal\n");
101 } else
102 spin_unlock_irq(&pps_kc_hardpps_lock);
103}
104
105/* pps_kc_event - call hardpps() on PPS event
106 * @pps: the PPS source
107 * @ts: PPS event timestamp
108 * @event: PPS event edge
109 *
110 * This function calls hardpps() when an event from bound PPS source occurs.
111 */
112void pps_kc_event(struct pps_device *pps, struct pps_event_time *ts,
113 int event)
114{
115 unsigned long flags;
116
117 /* Pass some events to kernel consumer if activated */
118 spin_lock_irqsave(&pps_kc_hardpps_lock, flags);
119 if (pps == pps_kc_hardpps_dev && event & pps_kc_hardpps_mode)
120 hardpps(&ts->ts_real, &ts->ts_raw);
121 spin_unlock_irqrestore(&pps_kc_hardpps_lock, flags);
122}
diff --git a/drivers/pps/kc.h b/drivers/pps/kc.h
new file mode 100644
index 000000000000..d296fcd0a175
--- /dev/null
+++ b/drivers/pps/kc.h
@@ -0,0 +1,46 @@
1/*
2 * PPS kernel consumer API header
3 *
4 * Copyright (C) 2009-2010 Alexander Gordeev <lasaine@lvk.cs.msu.su>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 */
20
21#ifndef LINUX_PPS_KC_H
22#define LINUX_PPS_KC_H
23
24#include <linux/errno.h>
25#include <linux/pps_kernel.h>
26
27#ifdef CONFIG_NTP_PPS
28
29extern int pps_kc_bind(struct pps_device *pps,
30 struct pps_bind_args *bind_args);
31extern void pps_kc_remove(struct pps_device *pps);
32extern void pps_kc_event(struct pps_device *pps,
33 struct pps_event_time *ts, int event);
34
35
36#else /* CONFIG_NTP_PPS */
37
38static inline int pps_kc_bind(struct pps_device *pps,
39 struct pps_bind_args *bind_args) { return -EOPNOTSUPP; }
40static inline void pps_kc_remove(struct pps_device *pps) {}
41static inline void pps_kc_event(struct pps_device *pps,
42 struct pps_event_time *ts, int event) {}
43
44#endif /* CONFIG_NTP_PPS */
45
46#endif /* LINUX_PPS_KC_H */
diff --git a/drivers/pps/pps.c b/drivers/pps/pps.c
index ca5183bdad85..2baadd21b7a6 100644
--- a/drivers/pps/pps.c
+++ b/drivers/pps/pps.c
@@ -19,6 +19,7 @@
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 */ 20 */
21 21
22#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
22 23
23#include <linux/kernel.h> 24#include <linux/kernel.h>
24#include <linux/module.h> 25#include <linux/module.h>
@@ -26,9 +27,13 @@
26#include <linux/sched.h> 27#include <linux/sched.h>
27#include <linux/uaccess.h> 28#include <linux/uaccess.h>
28#include <linux/idr.h> 29#include <linux/idr.h>
30#include <linux/mutex.h>
29#include <linux/cdev.h> 31#include <linux/cdev.h>
30#include <linux/poll.h> 32#include <linux/poll.h>
31#include <linux/pps_kernel.h> 33#include <linux/pps_kernel.h>
34#include <linux/slab.h>
35
36#include "kc.h"
32 37
33/* 38/*
34 * Local variables 39 * Local variables
@@ -37,6 +42,9 @@
37static dev_t pps_devt; 42static dev_t pps_devt;
38static struct class *pps_class; 43static struct class *pps_class;
39 44
45static DEFINE_MUTEX(pps_idr_lock);
46static DEFINE_IDR(pps_idr);
47
40/* 48/*
41 * Char device methods 49 * Char device methods
42 */ 50 */
@@ -61,15 +69,13 @@ static long pps_cdev_ioctl(struct file *file,
61{ 69{
62 struct pps_device *pps = file->private_data; 70 struct pps_device *pps = file->private_data;
63 struct pps_kparams params; 71 struct pps_kparams params;
64 struct pps_fdata fdata;
65 unsigned long ticks;
66 void __user *uarg = (void __user *) arg; 72 void __user *uarg = (void __user *) arg;
67 int __user *iuarg = (int __user *) arg; 73 int __user *iuarg = (int __user *) arg;
68 int err; 74 int err;
69 75
70 switch (cmd) { 76 switch (cmd) {
71 case PPS_GETPARAMS: 77 case PPS_GETPARAMS:
72 pr_debug("PPS_GETPARAMS: source %d\n", pps->id); 78 dev_dbg(pps->dev, "PPS_GETPARAMS\n");
73 79
74 spin_lock_irq(&pps->lock); 80 spin_lock_irq(&pps->lock);
75 81
@@ -85,7 +91,7 @@ static long pps_cdev_ioctl(struct file *file,
85 break; 91 break;
86 92
87 case PPS_SETPARAMS: 93 case PPS_SETPARAMS:
88 pr_debug("PPS_SETPARAMS: source %d\n", pps->id); 94 dev_dbg(pps->dev, "PPS_SETPARAMS\n");
89 95
90 /* Check the capabilities */ 96 /* Check the capabilities */
91 if (!capable(CAP_SYS_TIME)) 97 if (!capable(CAP_SYS_TIME))
@@ -95,14 +101,14 @@ static long pps_cdev_ioctl(struct file *file,
95 if (err) 101 if (err)
96 return -EFAULT; 102 return -EFAULT;
97 if (!(params.mode & (PPS_CAPTUREASSERT | PPS_CAPTURECLEAR))) { 103 if (!(params.mode & (PPS_CAPTUREASSERT | PPS_CAPTURECLEAR))) {
98 pr_debug("capture mode unspecified (%x)\n", 104 dev_dbg(pps->dev, "capture mode unspecified (%x)\n",
99 params.mode); 105 params.mode);
100 return -EINVAL; 106 return -EINVAL;
101 } 107 }
102 108
103 /* Check for supported capabilities */ 109 /* Check for supported capabilities */
104 if ((params.mode & ~pps->info.mode) != 0) { 110 if ((params.mode & ~pps->info.mode) != 0) {
105 pr_debug("unsupported capabilities (%x)\n", 111 dev_dbg(pps->dev, "unsupported capabilities (%x)\n",
106 params.mode); 112 params.mode);
107 return -EINVAL; 113 return -EINVAL;
108 } 114 }
@@ -115,7 +121,7 @@ static long pps_cdev_ioctl(struct file *file,
115 /* Restore the read only parameters */ 121 /* Restore the read only parameters */
116 if ((params.mode & (PPS_TSFMT_TSPEC | PPS_TSFMT_NTPFP)) == 0) { 122 if ((params.mode & (PPS_TSFMT_TSPEC | PPS_TSFMT_NTPFP)) == 0) {
117 /* section 3.3 of RFC 2783 interpreted */ 123 /* section 3.3 of RFC 2783 interpreted */
118 pr_debug("time format unspecified (%x)\n", 124 dev_dbg(pps->dev, "time format unspecified (%x)\n",
119 params.mode); 125 params.mode);
120 pps->params.mode |= PPS_TSFMT_TSPEC; 126 pps->params.mode |= PPS_TSFMT_TSPEC;
121 } 127 }
@@ -128,7 +134,7 @@ static long pps_cdev_ioctl(struct file *file,
128 break; 134 break;
129 135
130 case PPS_GETCAP: 136 case PPS_GETCAP:
131 pr_debug("PPS_GETCAP: source %d\n", pps->id); 137 dev_dbg(pps->dev, "PPS_GETCAP\n");
132 138
133 err = put_user(pps->info.mode, iuarg); 139 err = put_user(pps->info.mode, iuarg);
134 if (err) 140 if (err)
@@ -136,20 +142,26 @@ static long pps_cdev_ioctl(struct file *file,
136 142
137 break; 143 break;
138 144
139 case PPS_FETCH: 145 case PPS_FETCH: {
140 pr_debug("PPS_FETCH: source %d\n", pps->id); 146 struct pps_fdata fdata;
147 unsigned int ev;
148
149 dev_dbg(pps->dev, "PPS_FETCH\n");
141 150
142 err = copy_from_user(&fdata, uarg, sizeof(struct pps_fdata)); 151 err = copy_from_user(&fdata, uarg, sizeof(struct pps_fdata));
143 if (err) 152 if (err)
144 return -EFAULT; 153 return -EFAULT;
145 154
146 pps->go = 0; 155 ev = pps->last_ev;
147 156
148 /* Manage the timeout */ 157 /* Manage the timeout */
149 if (fdata.timeout.flags & PPS_TIME_INVALID) 158 if (fdata.timeout.flags & PPS_TIME_INVALID)
150 err = wait_event_interruptible(pps->queue, pps->go); 159 err = wait_event_interruptible(pps->queue,
160 ev != pps->last_ev);
151 else { 161 else {
152 pr_debug("timeout %lld.%09d\n", 162 unsigned long ticks;
163
164 dev_dbg(pps->dev, "timeout %lld.%09d\n",
153 (long long) fdata.timeout.sec, 165 (long long) fdata.timeout.sec,
154 fdata.timeout.nsec); 166 fdata.timeout.nsec);
155 ticks = fdata.timeout.sec * HZ; 167 ticks = fdata.timeout.sec * HZ;
@@ -157,7 +169,9 @@ static long pps_cdev_ioctl(struct file *file,
157 169
158 if (ticks != 0) { 170 if (ticks != 0) {
159 err = wait_event_interruptible_timeout( 171 err = wait_event_interruptible_timeout(
160 pps->queue, pps->go, ticks); 172 pps->queue,
173 ev != pps->last_ev,
174 ticks);
161 if (err == 0) 175 if (err == 0)
162 return -ETIMEDOUT; 176 return -ETIMEDOUT;
163 } 177 }
@@ -165,7 +179,7 @@ static long pps_cdev_ioctl(struct file *file,
165 179
166 /* Check for pending signals */ 180 /* Check for pending signals */
167 if (err == -ERESTARTSYS) { 181 if (err == -ERESTARTSYS) {
168 pr_debug("pending signal caught\n"); 182 dev_dbg(pps->dev, "pending signal caught\n");
169 return -EINTR; 183 return -EINTR;
170 } 184 }
171 185
@@ -185,10 +199,44 @@ static long pps_cdev_ioctl(struct file *file,
185 return -EFAULT; 199 return -EFAULT;
186 200
187 break; 201 break;
202 }
203 case PPS_KC_BIND: {
204 struct pps_bind_args bind_args;
205
206 dev_dbg(pps->dev, "PPS_KC_BIND\n");
207
208 /* Check the capabilities */
209 if (!capable(CAP_SYS_TIME))
210 return -EPERM;
211
212 if (copy_from_user(&bind_args, uarg,
213 sizeof(struct pps_bind_args)))
214 return -EFAULT;
188 215
216 /* Check for supported capabilities */
217 if ((bind_args.edge & ~pps->info.mode) != 0) {
218 dev_err(pps->dev, "unsupported capabilities (%x)\n",
219 bind_args.edge);
220 return -EINVAL;
221 }
222
223 /* Validate parameters roughly */
224 if (bind_args.tsformat != PPS_TSFMT_TSPEC ||
225 (bind_args.edge & ~PPS_CAPTUREBOTH) != 0 ||
226 bind_args.consumer != PPS_KC_HARDPPS) {
227 dev_err(pps->dev, "invalid kernel consumer bind"
228 " parameters (%x)\n", bind_args.edge);
229 return -EINVAL;
230 }
231
232 err = pps_kc_bind(pps, &bind_args);
233 if (err < 0)
234 return err;
235
236 break;
237 }
189 default: 238 default:
190 return -ENOTTY; 239 return -ENOTTY;
191 break;
192 } 240 }
193 241
194 return 0; 242 return 0;
@@ -198,12 +246,6 @@ static int pps_cdev_open(struct inode *inode, struct file *file)
198{ 246{
199 struct pps_device *pps = container_of(inode->i_cdev, 247 struct pps_device *pps = container_of(inode->i_cdev,
200 struct pps_device, cdev); 248 struct pps_device, cdev);
201 int found;
202
203 found = pps_get_source(pps->id) != 0;
204 if (!found)
205 return -ENODEV;
206
207 file->private_data = pps; 249 file->private_data = pps;
208 250
209 return 0; 251 return 0;
@@ -211,11 +253,6 @@ static int pps_cdev_open(struct inode *inode, struct file *file)
211 253
212static int pps_cdev_release(struct inode *inode, struct file *file) 254static int pps_cdev_release(struct inode *inode, struct file *file)
213{ 255{
214 struct pps_device *pps = file->private_data;
215
216 /* Free the PPS source and wake up (possible) deregistration */
217 pps_put_source(pps);
218
219 return 0; 256 return 0;
220} 257}
221 258
@@ -233,25 +270,67 @@ static const struct file_operations pps_cdev_fops = {
233 .release = pps_cdev_release, 270 .release = pps_cdev_release,
234}; 271};
235 272
273static void pps_device_destruct(struct device *dev)
274{
275 struct pps_device *pps = dev_get_drvdata(dev);
276
277 /* release id here to protect others from using it while it's
278 * still in use */
279 mutex_lock(&pps_idr_lock);
280 idr_remove(&pps_idr, pps->id);
281 mutex_unlock(&pps_idr_lock);
282
283 kfree(dev);
284 kfree(pps);
285}
286
236int pps_register_cdev(struct pps_device *pps) 287int pps_register_cdev(struct pps_device *pps)
237{ 288{
238 int err; 289 int err;
290 dev_t devt;
291
292 mutex_lock(&pps_idr_lock);
293 /* Get new ID for the new PPS source */
294 if (idr_pre_get(&pps_idr, GFP_KERNEL) == 0) {
295 mutex_unlock(&pps_idr_lock);
296 return -ENOMEM;
297 }
298
299 /* Now really allocate the PPS source.
300 * After idr_get_new() calling the new source will be freely available
301 * into the kernel.
302 */
303 err = idr_get_new(&pps_idr, pps, &pps->id);
304 mutex_unlock(&pps_idr_lock);
305
306 if (err < 0)
307 return err;
308
309 pps->id &= MAX_ID_MASK;
310 if (pps->id >= PPS_MAX_SOURCES) {
311 pr_err("%s: too many PPS sources in the system\n",
312 pps->info.name);
313 err = -EBUSY;
314 goto free_idr;
315 }
316
317 devt = MKDEV(MAJOR(pps_devt), pps->id);
239 318
240 pps->devno = MKDEV(MAJOR(pps_devt), pps->id);
241 cdev_init(&pps->cdev, &pps_cdev_fops); 319 cdev_init(&pps->cdev, &pps_cdev_fops);
242 pps->cdev.owner = pps->info.owner; 320 pps->cdev.owner = pps->info.owner;
243 321
244 err = cdev_add(&pps->cdev, pps->devno, 1); 322 err = cdev_add(&pps->cdev, devt, 1);
245 if (err) { 323 if (err) {
246 printk(KERN_ERR "pps: %s: failed to add char device %d:%d\n", 324 pr_err("%s: failed to add char device %d:%d\n",
247 pps->info.name, MAJOR(pps_devt), pps->id); 325 pps->info.name, MAJOR(pps_devt), pps->id);
248 return err; 326 goto free_idr;
249 } 327 }
250 pps->dev = device_create(pps_class, pps->info.dev, pps->devno, NULL, 328 pps->dev = device_create(pps_class, pps->info.dev, devt, pps,
251 "pps%d", pps->id); 329 "pps%d", pps->id);
252 if (IS_ERR(pps->dev)) 330 if (IS_ERR(pps->dev))
253 goto del_cdev; 331 goto del_cdev;
254 dev_set_drvdata(pps->dev, pps); 332
333 pps->dev->release = pps_device_destruct;
255 334
256 pr_debug("source %s got cdev (%d:%d)\n", pps->info.name, 335 pr_debug("source %s got cdev (%d:%d)\n", pps->info.name,
257 MAJOR(pps_devt), pps->id); 336 MAJOR(pps_devt), pps->id);
@@ -261,12 +340,17 @@ int pps_register_cdev(struct pps_device *pps)
261del_cdev: 340del_cdev:
262 cdev_del(&pps->cdev); 341 cdev_del(&pps->cdev);
263 342
343free_idr:
344 mutex_lock(&pps_idr_lock);
345 idr_remove(&pps_idr, pps->id);
346 mutex_unlock(&pps_idr_lock);
347
264 return err; 348 return err;
265} 349}
266 350
267void pps_unregister_cdev(struct pps_device *pps) 351void pps_unregister_cdev(struct pps_device *pps)
268{ 352{
269 device_destroy(pps_class, pps->devno); 353 device_destroy(pps_class, pps->dev->devt);
270 cdev_del(&pps->cdev); 354 cdev_del(&pps->cdev);
271} 355}
272 356
@@ -286,14 +370,14 @@ static int __init pps_init(void)
286 370
287 pps_class = class_create(THIS_MODULE, "pps"); 371 pps_class = class_create(THIS_MODULE, "pps");
288 if (!pps_class) { 372 if (!pps_class) {
289 printk(KERN_ERR "pps: failed to allocate class\n"); 373 pr_err("failed to allocate class\n");
290 return -ENOMEM; 374 return -ENOMEM;
291 } 375 }
292 pps_class->dev_attrs = pps_attrs; 376 pps_class->dev_attrs = pps_attrs;
293 377
294 err = alloc_chrdev_region(&pps_devt, 0, PPS_MAX_SOURCES, "pps"); 378 err = alloc_chrdev_region(&pps_devt, 0, PPS_MAX_SOURCES, "pps");
295 if (err < 0) { 379 if (err < 0) {
296 printk(KERN_ERR "pps: failed to allocate char device region\n"); 380 pr_err("failed to allocate char device region\n");
297 goto remove_class; 381 goto remove_class;
298 } 382 }
299 383
diff --git a/drivers/rapidio/rio-scan.c b/drivers/rapidio/rio-scan.c
index 1eb82c4c712e..467e82bd0929 100644
--- a/drivers/rapidio/rio-scan.c
+++ b/drivers/rapidio/rio-scan.c
@@ -46,7 +46,6 @@ static void rio_init_em(struct rio_dev *rdev);
46DEFINE_SPINLOCK(rio_global_list_lock); 46DEFINE_SPINLOCK(rio_global_list_lock);
47 47
48static int next_destid = 0; 48static int next_destid = 0;
49static int next_switchid = 0;
50static int next_net = 0; 49static int next_net = 0;
51static int next_comptag = 1; 50static int next_comptag = 1;
52 51
@@ -378,12 +377,30 @@ static struct rio_dev __devinit *rio_setup_device(struct rio_net *net,
378 struct rio_dev *rdev; 377 struct rio_dev *rdev;
379 struct rio_switch *rswitch = NULL; 378 struct rio_switch *rswitch = NULL;
380 int result, rdid; 379 int result, rdid;
380 size_t size;
381 u32 swpinfo = 0;
381 382
382 rdev = kzalloc(sizeof(struct rio_dev), GFP_KERNEL); 383 size = sizeof(struct rio_dev);
384 if (rio_mport_read_config_32(port, destid, hopcount,
385 RIO_PEF_CAR, &result))
386 return NULL;
387
388 if (result & (RIO_PEF_SWITCH | RIO_PEF_MULTIPORT)) {
389 rio_mport_read_config_32(port, destid, hopcount,
390 RIO_SWP_INFO_CAR, &swpinfo);
391 if (result & RIO_PEF_SWITCH) {
392 size += (RIO_GET_TOTAL_PORTS(swpinfo) *
393 sizeof(rswitch->nextdev[0])) + sizeof(*rswitch);
394 }
395 }
396
397 rdev = kzalloc(size, GFP_KERNEL);
383 if (!rdev) 398 if (!rdev)
384 return NULL; 399 return NULL;
385 400
386 rdev->net = net; 401 rdev->net = net;
402 rdev->pef = result;
403 rdev->swpinfo = swpinfo;
387 rio_mport_read_config_32(port, destid, hopcount, RIO_DEV_ID_CAR, 404 rio_mport_read_config_32(port, destid, hopcount, RIO_DEV_ID_CAR,
388 &result); 405 &result);
389 rdev->did = result >> 16; 406 rdev->did = result >> 16;
@@ -397,8 +414,6 @@ static struct rio_dev __devinit *rio_setup_device(struct rio_net *net,
397 rio_mport_read_config_32(port, destid, hopcount, RIO_ASM_INFO_CAR, 414 rio_mport_read_config_32(port, destid, hopcount, RIO_ASM_INFO_CAR,
398 &result); 415 &result);
399 rdev->asm_rev = result >> 16; 416 rdev->asm_rev = result >> 16;
400 rio_mport_read_config_32(port, destid, hopcount, RIO_PEF_CAR,
401 &rdev->pef);
402 if (rdev->pef & RIO_PEF_EXT_FEATURES) { 417 if (rdev->pef & RIO_PEF_EXT_FEATURES) {
403 rdev->efptr = result & 0xffff; 418 rdev->efptr = result & 0xffff;
404 rdev->phys_efptr = rio_mport_get_physefb(port, 0, destid, 419 rdev->phys_efptr = rio_mport_get_physefb(port, 0, destid,
@@ -408,11 +423,6 @@ static struct rio_dev __devinit *rio_setup_device(struct rio_net *net,
408 hopcount, RIO_EFB_ERR_MGMNT); 423 hopcount, RIO_EFB_ERR_MGMNT);
409 } 424 }
410 425
411 if (rdev->pef & (RIO_PEF_SWITCH | RIO_PEF_MULTIPORT)) {
412 rio_mport_read_config_32(port, destid, hopcount,
413 RIO_SWP_INFO_CAR, &rdev->swpinfo);
414 }
415
416 rio_mport_read_config_32(port, destid, hopcount, RIO_SRC_OPS_CAR, 426 rio_mport_read_config_32(port, destid, hopcount, RIO_SRC_OPS_CAR,
417 &rdev->src_ops); 427 &rdev->src_ops);
418 rio_mport_read_config_32(port, destid, hopcount, RIO_DST_OPS_CAR, 428 rio_mport_read_config_32(port, destid, hopcount, RIO_DST_OPS_CAR,
@@ -427,6 +437,10 @@ static struct rio_dev __devinit *rio_setup_device(struct rio_net *net,
427 rio_mport_write_config_32(port, destid, hopcount, 437 rio_mport_write_config_32(port, destid, hopcount,
428 RIO_COMPONENT_TAG_CSR, next_comptag); 438 RIO_COMPONENT_TAG_CSR, next_comptag);
429 rdev->comp_tag = next_comptag++; 439 rdev->comp_tag = next_comptag++;
440 } else {
441 rio_mport_read_config_32(port, destid, hopcount,
442 RIO_COMPONENT_TAG_CSR,
443 &rdev->comp_tag);
430 } 444 }
431 445
432 if (rio_device_has_destid(port, rdev->src_ops, rdev->dst_ops)) { 446 if (rio_device_has_destid(port, rdev->src_ops, rdev->dst_ops)) {
@@ -437,21 +451,20 @@ static struct rio_dev __devinit *rio_setup_device(struct rio_net *net,
437 next_destid++; 451 next_destid++;
438 } else 452 } else
439 rdev->destid = rio_get_device_id(port, destid, hopcount); 453 rdev->destid = rio_get_device_id(port, destid, hopcount);
440 } else 454
441 /* Switch device has an associated destID */ 455 rdev->hopcount = 0xff;
442 rdev->destid = RIO_INVALID_DESTID; 456 } else {
457 /* Switch device has an associated destID which
458 * will be adjusted later
459 */
460 rdev->destid = destid;
461 rdev->hopcount = hopcount;
462 }
443 463
444 /* If a PE has both switch and other functions, show it as a switch */ 464 /* If a PE has both switch and other functions, show it as a switch */
445 if (rio_is_switch(rdev)) { 465 if (rio_is_switch(rdev)) {
446 rswitch = kzalloc(sizeof(*rswitch) + 466 rswitch = rdev->rswitch;
447 RIO_GET_TOTAL_PORTS(rdev->swpinfo) * 467 rswitch->switchid = rdev->comp_tag & RIO_CTAG_UDEVID;
448 sizeof(rswitch->nextdev[0]),
449 GFP_KERNEL);
450 if (!rswitch)
451 goto cleanup;
452 rswitch->switchid = next_switchid;
453 rswitch->hopcount = hopcount;
454 rswitch->destid = destid;
455 rswitch->port_ok = 0; 468 rswitch->port_ok = 0;
456 rswitch->route_table = kzalloc(sizeof(u8)* 469 rswitch->route_table = kzalloc(sizeof(u8)*
457 RIO_MAX_ROUTE_ENTRIES(port->sys_size), 470 RIO_MAX_ROUTE_ENTRIES(port->sys_size),
@@ -462,15 +475,13 @@ static struct rio_dev __devinit *rio_setup_device(struct rio_net *net,
462 for (rdid = 0; rdid < RIO_MAX_ROUTE_ENTRIES(port->sys_size); 475 for (rdid = 0; rdid < RIO_MAX_ROUTE_ENTRIES(port->sys_size);
463 rdid++) 476 rdid++)
464 rswitch->route_table[rdid] = RIO_INVALID_ROUTE; 477 rswitch->route_table[rdid] = RIO_INVALID_ROUTE;
465 rdev->rswitch = rswitch;
466 rswitch->rdev = rdev;
467 dev_set_name(&rdev->dev, "%02x:s:%04x", rdev->net->id, 478 dev_set_name(&rdev->dev, "%02x:s:%04x", rdev->net->id,
468 rdev->rswitch->switchid); 479 rswitch->switchid);
469 rio_switch_init(rdev, do_enum); 480 rio_switch_init(rdev, do_enum);
470 481
471 if (do_enum && rdev->rswitch->clr_table) 482 if (do_enum && rswitch->clr_table)
472 rdev->rswitch->clr_table(port, destid, hopcount, 483 rswitch->clr_table(port, destid, hopcount,
473 RIO_GLOBAL_TABLE); 484 RIO_GLOBAL_TABLE);
474 485
475 list_add_tail(&rswitch->node, &rio_switches); 486 list_add_tail(&rswitch->node, &rio_switches);
476 487
@@ -506,10 +517,9 @@ static struct rio_dev __devinit *rio_setup_device(struct rio_net *net,
506 return rdev; 517 return rdev;
507 518
508cleanup: 519cleanup:
509 if (rswitch) { 520 if (rswitch->route_table)
510 kfree(rswitch->route_table); 521 kfree(rswitch->route_table);
511 kfree(rswitch); 522
512 }
513 kfree(rdev); 523 kfree(rdev);
514 return NULL; 524 return NULL;
515} 525}
@@ -632,8 +642,7 @@ rio_unlock_device(struct rio_mport *port, u16 destid, u8 hopcount)
632 642
633/** 643/**
634 * rio_route_add_entry- Add a route entry to a switch routing table 644 * rio_route_add_entry- Add a route entry to a switch routing table
635 * @mport: Master port to send transaction 645 * @rdev: RIO device
636 * @rswitch: Switch device
637 * @table: Routing table ID 646 * @table: Routing table ID
638 * @route_destid: Destination ID to be routed 647 * @route_destid: Destination ID to be routed
639 * @route_port: Port number to be routed 648 * @route_port: Port number to be routed
@@ -647,31 +656,31 @@ rio_unlock_device(struct rio_mport *port, u16 destid, u8 hopcount)
647 * on failure. 656 * on failure.
648 */ 657 */
649static int 658static int
650rio_route_add_entry(struct rio_mport *mport, struct rio_switch *rswitch, 659rio_route_add_entry(struct rio_dev *rdev,
651 u16 table, u16 route_destid, u8 route_port, int lock) 660 u16 table, u16 route_destid, u8 route_port, int lock)
652{ 661{
653 int rc; 662 int rc;
654 663
655 if (lock) { 664 if (lock) {
656 rc = rio_lock_device(mport, rswitch->destid, 665 rc = rio_lock_device(rdev->net->hport, rdev->destid,
657 rswitch->hopcount, 1000); 666 rdev->hopcount, 1000);
658 if (rc) 667 if (rc)
659 return rc; 668 return rc;
660 } 669 }
661 670
662 rc = rswitch->add_entry(mport, rswitch->destid, 671 rc = rdev->rswitch->add_entry(rdev->net->hport, rdev->destid,
663 rswitch->hopcount, table, 672 rdev->hopcount, table,
664 route_destid, route_port); 673 route_destid, route_port);
665 if (lock) 674 if (lock)
666 rio_unlock_device(mport, rswitch->destid, rswitch->hopcount); 675 rio_unlock_device(rdev->net->hport, rdev->destid,
676 rdev->hopcount);
667 677
668 return rc; 678 return rc;
669} 679}
670 680
671/** 681/**
672 * rio_route_get_entry- Read a route entry in a switch routing table 682 * rio_route_get_entry- Read a route entry in a switch routing table
673 * @mport: Master port to send transaction 683 * @rdev: RIO device
674 * @rswitch: Switch device
675 * @table: Routing table ID 684 * @table: Routing table ID
676 * @route_destid: Destination ID to be routed 685 * @route_destid: Destination ID to be routed
677 * @route_port: Pointer to read port number into 686 * @route_port: Pointer to read port number into
@@ -685,23 +694,24 @@ rio_route_add_entry(struct rio_mport *mport, struct rio_switch *rswitch,
685 * on failure. 694 * on failure.
686 */ 695 */
687static int 696static int
688rio_route_get_entry(struct rio_mport *mport, struct rio_switch *rswitch, u16 table, 697rio_route_get_entry(struct rio_dev *rdev, u16 table,
689 u16 route_destid, u8 *route_port, int lock) 698 u16 route_destid, u8 *route_port, int lock)
690{ 699{
691 int rc; 700 int rc;
692 701
693 if (lock) { 702 if (lock) {
694 rc = rio_lock_device(mport, rswitch->destid, 703 rc = rio_lock_device(rdev->net->hport, rdev->destid,
695 rswitch->hopcount, 1000); 704 rdev->hopcount, 1000);
696 if (rc) 705 if (rc)
697 return rc; 706 return rc;
698 } 707 }
699 708
700 rc = rswitch->get_entry(mport, rswitch->destid, 709 rc = rdev->rswitch->get_entry(rdev->net->hport, rdev->destid,
701 rswitch->hopcount, table, 710 rdev->hopcount, table,
702 route_destid, route_port); 711 route_destid, route_port);
703 if (lock) 712 if (lock)
704 rio_unlock_device(mport, rswitch->destid, rswitch->hopcount); 713 rio_unlock_device(rdev->net->hport, rdev->destid,
714 rdev->hopcount);
705 715
706 return rc; 716 return rc;
707} 717}
@@ -809,16 +819,15 @@ static int __devinit rio_enum_peer(struct rio_net *net, struct rio_mport *port,
809 return -1; 819 return -1;
810 820
811 if (rio_is_switch(rdev)) { 821 if (rio_is_switch(rdev)) {
812 next_switchid++;
813 sw_inport = RIO_GET_PORT_NUM(rdev->swpinfo); 822 sw_inport = RIO_GET_PORT_NUM(rdev->swpinfo);
814 rio_route_add_entry(port, rdev->rswitch, RIO_GLOBAL_TABLE, 823 rio_route_add_entry(rdev, RIO_GLOBAL_TABLE,
815 port->host_deviceid, sw_inport, 0); 824 port->host_deviceid, sw_inport, 0);
816 rdev->rswitch->route_table[port->host_deviceid] = sw_inport; 825 rdev->rswitch->route_table[port->host_deviceid] = sw_inport;
817 826
818 for (destid = 0; destid < next_destid; destid++) { 827 for (destid = 0; destid < next_destid; destid++) {
819 if (destid == port->host_deviceid) 828 if (destid == port->host_deviceid)
820 continue; 829 continue;
821 rio_route_add_entry(port, rdev->rswitch, RIO_GLOBAL_TABLE, 830 rio_route_add_entry(rdev, RIO_GLOBAL_TABLE,
822 destid, sw_inport, 0); 831 destid, sw_inport, 0);
823 rdev->rswitch->route_table[destid] = sw_inport; 832 rdev->rswitch->route_table[destid] = sw_inport;
824 } 833 }
@@ -850,8 +859,7 @@ static int __devinit rio_enum_peer(struct rio_net *net, struct rio_mport *port,
850 "RIO: scanning device on port %d\n", 859 "RIO: scanning device on port %d\n",
851 port_num); 860 port_num);
852 rdev->rswitch->port_ok |= (1 << port_num); 861 rdev->rswitch->port_ok |= (1 << port_num);
853 rio_route_add_entry(port, rdev->rswitch, 862 rio_route_add_entry(rdev, RIO_GLOBAL_TABLE,
854 RIO_GLOBAL_TABLE,
855 RIO_ANY_DESTID(port->sys_size), 863 RIO_ANY_DESTID(port->sys_size),
856 port_num, 0); 864 port_num, 0);
857 865
@@ -865,7 +873,7 @@ static int __devinit rio_enum_peer(struct rio_net *net, struct rio_mport *port,
865 destid < next_destid; destid++) { 873 destid < next_destid; destid++) {
866 if (destid == port->host_deviceid) 874 if (destid == port->host_deviceid)
867 continue; 875 continue;
868 rio_route_add_entry(port, rdev->rswitch, 876 rio_route_add_entry(rdev,
869 RIO_GLOBAL_TABLE, 877 RIO_GLOBAL_TABLE,
870 destid, 878 destid,
871 port_num, 879 port_num,
@@ -904,7 +912,7 @@ static int __devinit rio_enum_peer(struct rio_net *net, struct rio_mport *port,
904 next_destid++; 912 next_destid++;
905 } 913 }
906 914
907 rdev->rswitch->destid = sw_destid; 915 rdev->destid = sw_destid;
908 } else 916 } else
909 pr_debug("RIO: found %s (vid %4.4x did %4.4x)\n", 917 pr_debug("RIO: found %s (vid %4.4x did %4.4x)\n",
910 rio_name(rdev), rdev->vid, rdev->did); 918 rio_name(rdev), rdev->vid, rdev->did);
@@ -941,7 +949,7 @@ static int rio_enum_complete(struct rio_mport *port)
941 */ 949 */
942static int __devinit 950static int __devinit
943rio_disc_peer(struct rio_net *net, struct rio_mport *port, u16 destid, 951rio_disc_peer(struct rio_net *net, struct rio_mport *port, u16 destid,
944 u8 hopcount) 952 u8 hopcount, struct rio_dev *prev, int prev_port)
945{ 953{
946 u8 port_num, route_port; 954 u8 port_num, route_port;
947 struct rio_dev *rdev; 955 struct rio_dev *rdev;
@@ -951,14 +959,15 @@ rio_disc_peer(struct rio_net *net, struct rio_mport *port, u16 destid,
951 if ((rdev = rio_setup_device(net, port, destid, hopcount, 0))) { 959 if ((rdev = rio_setup_device(net, port, destid, hopcount, 0))) {
952 /* Add device to the global and bus/net specific list. */ 960 /* Add device to the global and bus/net specific list. */
953 list_add_tail(&rdev->net_list, &net->devices); 961 list_add_tail(&rdev->net_list, &net->devices);
962 rdev->prev = prev;
963 if (prev && rio_is_switch(prev))
964 prev->rswitch->nextdev[prev_port] = rdev;
954 } else 965 } else
955 return -1; 966 return -1;
956 967
957 if (rio_is_switch(rdev)) { 968 if (rio_is_switch(rdev)) {
958 next_switchid++;
959
960 /* Associated destid is how we accessed this switch */ 969 /* Associated destid is how we accessed this switch */
961 rdev->rswitch->destid = destid; 970 rdev->destid = destid;
962 971
963 pr_debug( 972 pr_debug(
964 "RIO: found %s (vid %4.4x did %4.4x) with %d ports\n", 973 "RIO: found %s (vid %4.4x did %4.4x) with %d ports\n",
@@ -981,7 +990,7 @@ rio_disc_peer(struct rio_net *net, struct rio_mport *port, u16 destid,
981 for (ndestid = 0; 990 for (ndestid = 0;
982 ndestid < RIO_ANY_DESTID(port->sys_size); 991 ndestid < RIO_ANY_DESTID(port->sys_size);
983 ndestid++) { 992 ndestid++) {
984 rio_route_get_entry(port, rdev->rswitch, 993 rio_route_get_entry(rdev,
985 RIO_GLOBAL_TABLE, 994 RIO_GLOBAL_TABLE,
986 ndestid, 995 ndestid,
987 &route_port, 0); 996 &route_port, 0);
@@ -992,8 +1001,8 @@ rio_disc_peer(struct rio_net *net, struct rio_mport *port, u16 destid,
992 if (ndestid == RIO_ANY_DESTID(port->sys_size)) 1001 if (ndestid == RIO_ANY_DESTID(port->sys_size))
993 continue; 1002 continue;
994 rio_unlock_device(port, destid, hopcount); 1003 rio_unlock_device(port, destid, hopcount);
995 if (rio_disc_peer 1004 if (rio_disc_peer(net, port, ndestid,
996 (net, port, ndestid, hopcount + 1) < 0) 1005 hopcount + 1, rdev, port_num) < 0)
997 return -1; 1006 return -1;
998 } 1007 }
999 } 1008 }
@@ -1069,14 +1078,14 @@ static struct rio_net __devinit *rio_alloc_net(struct rio_mport *port)
1069 */ 1078 */
1070static void rio_update_route_tables(struct rio_mport *port) 1079static void rio_update_route_tables(struct rio_mport *port)
1071{ 1080{
1072 struct rio_dev *rdev; 1081 struct rio_dev *rdev, *swrdev;
1073 struct rio_switch *rswitch; 1082 struct rio_switch *rswitch;
1074 u8 sport; 1083 u8 sport;
1075 u16 destid; 1084 u16 destid;
1076 1085
1077 list_for_each_entry(rdev, &rio_devices, global_list) { 1086 list_for_each_entry(rdev, &rio_devices, global_list) {
1078 1087
1079 destid = (rio_is_switch(rdev))?rdev->rswitch->destid:rdev->destid; 1088 destid = rdev->destid;
1080 1089
1081 list_for_each_entry(rswitch, &rio_switches, node) { 1090 list_for_each_entry(rswitch, &rio_switches, node) {
1082 1091
@@ -1084,14 +1093,16 @@ static void rio_update_route_tables(struct rio_mport *port)
1084 continue; 1093 continue;
1085 1094
1086 if (RIO_INVALID_ROUTE == rswitch->route_table[destid]) { 1095 if (RIO_INVALID_ROUTE == rswitch->route_table[destid]) {
1096 swrdev = sw_to_rio_dev(rswitch);
1097
1087 /* Skip if destid ends in empty switch*/ 1098 /* Skip if destid ends in empty switch*/
1088 if (rswitch->destid == destid) 1099 if (swrdev->destid == destid)
1089 continue; 1100 continue;
1090 1101
1091 sport = RIO_GET_PORT_NUM(rswitch->rdev->swpinfo); 1102 sport = RIO_GET_PORT_NUM(swrdev->swpinfo);
1092 1103
1093 if (rswitch->add_entry) { 1104 if (rswitch->add_entry) {
1094 rio_route_add_entry(port, rswitch, 1105 rio_route_add_entry(swrdev,
1095 RIO_GLOBAL_TABLE, destid, 1106 RIO_GLOBAL_TABLE, destid,
1096 sport, 0); 1107 sport, 0);
1097 rswitch->route_table[destid] = sport; 1108 rswitch->route_table[destid] = sport;
@@ -1203,21 +1214,20 @@ static void rio_build_route_tables(void)
1203 1214
1204 list_for_each_entry(rdev, &rio_devices, global_list) 1215 list_for_each_entry(rdev, &rio_devices, global_list)
1205 if (rio_is_switch(rdev)) { 1216 if (rio_is_switch(rdev)) {
1206 rio_lock_device(rdev->net->hport, rdev->rswitch->destid, 1217 rio_lock_device(rdev->net->hport, rdev->destid,
1207 rdev->rswitch->hopcount, 1000); 1218 rdev->hopcount, 1000);
1208 for (i = 0; 1219 for (i = 0;
1209 i < RIO_MAX_ROUTE_ENTRIES(rdev->net->hport->sys_size); 1220 i < RIO_MAX_ROUTE_ENTRIES(rdev->net->hport->sys_size);
1210 i++) { 1221 i++) {
1211 if (rio_route_get_entry 1222 if (rio_route_get_entry(rdev,
1212 (rdev->net->hport, rdev->rswitch, 1223 RIO_GLOBAL_TABLE, i, &sport, 0) < 0)
1213 RIO_GLOBAL_TABLE, i, &sport, 0) < 0)
1214 continue; 1224 continue;
1215 rdev->rswitch->route_table[i] = sport; 1225 rdev->rswitch->route_table[i] = sport;
1216 } 1226 }
1217 1227
1218 rio_unlock_device(rdev->net->hport, 1228 rio_unlock_device(rdev->net->hport,
1219 rdev->rswitch->destid, 1229 rdev->destid,
1220 rdev->rswitch->hopcount); 1230 rdev->hopcount);
1221 } 1231 }
1222} 1232}
1223 1233
@@ -1284,7 +1294,7 @@ int __devinit rio_disc_mport(struct rio_mport *mport)
1284 mport->host_deviceid); 1294 mport->host_deviceid);
1285 1295
1286 if (rio_disc_peer(net, mport, RIO_ANY_DESTID(mport->sys_size), 1296 if (rio_disc_peer(net, mport, RIO_ANY_DESTID(mport->sys_size),
1287 0) < 0) { 1297 0, NULL, 0) < 0) {
1288 printk(KERN_INFO 1298 printk(KERN_INFO
1289 "RIO: master port %d device has failed discovery\n", 1299 "RIO: master port %d device has failed discovery\n",
1290 mport->id); 1300 mport->id);
diff --git a/drivers/rapidio/rio-sysfs.c b/drivers/rapidio/rio-sysfs.c
index 137ed93ee33f..76b41853a877 100644
--- a/drivers/rapidio/rio-sysfs.c
+++ b/drivers/rapidio/rio-sysfs.c
@@ -217,7 +217,7 @@ int rio_create_sysfs_dev_files(struct rio_dev *rdev)
217 217
218 err = device_create_bin_file(&rdev->dev, &rio_config_attr); 218 err = device_create_bin_file(&rdev->dev, &rio_config_attr);
219 219
220 if (!err && rdev->rswitch) { 220 if (!err && (rdev->pef & RIO_PEF_SWITCH)) {
221 err = device_create_file(&rdev->dev, &dev_attr_routes); 221 err = device_create_file(&rdev->dev, &dev_attr_routes);
222 if (!err && rdev->rswitch->sw_sysfs) 222 if (!err && rdev->rswitch->sw_sysfs)
223 err = rdev->rswitch->sw_sysfs(rdev, RIO_SW_SYSFS_CREATE); 223 err = rdev->rswitch->sw_sysfs(rdev, RIO_SW_SYSFS_CREATE);
@@ -239,7 +239,7 @@ int rio_create_sysfs_dev_files(struct rio_dev *rdev)
239void rio_remove_sysfs_dev_files(struct rio_dev *rdev) 239void rio_remove_sysfs_dev_files(struct rio_dev *rdev)
240{ 240{
241 device_remove_bin_file(&rdev->dev, &rio_config_attr); 241 device_remove_bin_file(&rdev->dev, &rio_config_attr);
242 if (rdev->rswitch) { 242 if (rdev->pef & RIO_PEF_SWITCH) {
243 device_remove_file(&rdev->dev, &dev_attr_routes); 243 device_remove_file(&rdev->dev, &dev_attr_routes);
244 if (rdev->rswitch->sw_sysfs) 244 if (rdev->rswitch->sw_sysfs)
245 rdev->rswitch->sw_sysfs(rdev, RIO_SW_SYSFS_REMOVE); 245 rdev->rswitch->sw_sysfs(rdev, RIO_SW_SYSFS_REMOVE);
diff --git a/drivers/rapidio/rio.c b/drivers/rapidio/rio.c
index 7b5080c45569..cc2a3b74d0f0 100644
--- a/drivers/rapidio/rio.c
+++ b/drivers/rapidio/rio.c
@@ -471,16 +471,9 @@ exit:
471 */ 471 */
472int rio_set_port_lockout(struct rio_dev *rdev, u32 pnum, int lock) 472int rio_set_port_lockout(struct rio_dev *rdev, u32 pnum, int lock)
473{ 473{
474 u8 hopcount = 0xff;
475 u16 destid = rdev->destid;
476 u32 regval; 474 u32 regval;
477 475
478 if (rdev->rswitch) { 476 rio_read_config_32(rdev,
479 destid = rdev->rswitch->destid;
480 hopcount = rdev->rswitch->hopcount;
481 }
482
483 rio_mport_read_config_32(rdev->net->hport, destid, hopcount,
484 rdev->phys_efptr + RIO_PORT_N_CTL_CSR(pnum), 477 rdev->phys_efptr + RIO_PORT_N_CTL_CSR(pnum),
485 &regval); 478 &regval);
486 if (lock) 479 if (lock)
@@ -488,7 +481,7 @@ int rio_set_port_lockout(struct rio_dev *rdev, u32 pnum, int lock)
488 else 481 else
489 regval &= ~RIO_PORT_N_CTL_LOCKOUT; 482 regval &= ~RIO_PORT_N_CTL_LOCKOUT;
490 483
491 rio_mport_write_config_32(rdev->net->hport, destid, hopcount, 484 rio_write_config_32(rdev,
492 rdev->phys_efptr + RIO_PORT_N_CTL_CSR(pnum), 485 rdev->phys_efptr + RIO_PORT_N_CTL_CSR(pnum),
493 regval); 486 regval);
494 return 0; 487 return 0;
@@ -507,7 +500,7 @@ static int
507rio_chk_dev_route(struct rio_dev *rdev, struct rio_dev **nrdev, int *npnum) 500rio_chk_dev_route(struct rio_dev *rdev, struct rio_dev **nrdev, int *npnum)
508{ 501{
509 u32 result; 502 u32 result;
510 int p_port, dstid, rc = -EIO; 503 int p_port, rc = -EIO;
511 struct rio_dev *prev = NULL; 504 struct rio_dev *prev = NULL;
512 505
513 /* Find switch with failed RIO link */ 506 /* Find switch with failed RIO link */
@@ -522,9 +515,7 @@ rio_chk_dev_route(struct rio_dev *rdev, struct rio_dev **nrdev, int *npnum)
522 if (prev == NULL) 515 if (prev == NULL)
523 goto err_out; 516 goto err_out;
524 517
525 dstid = (rdev->pef & RIO_PEF_SWITCH) ? 518 p_port = prev->rswitch->route_table[rdev->destid];
526 rdev->rswitch->destid : rdev->destid;
527 p_port = prev->rswitch->route_table[dstid];
528 519
529 if (p_port != RIO_INVALID_ROUTE) { 520 if (p_port != RIO_INVALID_ROUTE) {
530 pr_debug("RIO: link failed on [%s]-P%d\n", 521 pr_debug("RIO: link failed on [%s]-P%d\n",
@@ -567,15 +558,8 @@ rio_mport_chk_dev_access(struct rio_mport *mport, u16 destid, u8 hopcount)
567 */ 558 */
568static int rio_chk_dev_access(struct rio_dev *rdev) 559static int rio_chk_dev_access(struct rio_dev *rdev)
569{ 560{
570 u8 hopcount = 0xff; 561 return rio_mport_chk_dev_access(rdev->net->hport,
571 u16 destid = rdev->destid; 562 rdev->destid, rdev->hopcount);
572
573 if (rdev->rswitch) {
574 destid = rdev->rswitch->destid;
575 hopcount = rdev->rswitch->hopcount;
576 }
577
578 return rio_mport_chk_dev_access(rdev->net->hport, destid, hopcount);
579} 563}
580 564
581/** 565/**
@@ -588,23 +572,20 @@ static int rio_chk_dev_access(struct rio_dev *rdev)
588static int 572static int
589rio_get_input_status(struct rio_dev *rdev, int pnum, u32 *lnkresp) 573rio_get_input_status(struct rio_dev *rdev, int pnum, u32 *lnkresp)
590{ 574{
591 struct rio_mport *mport = rdev->net->hport;
592 u16 destid = rdev->rswitch->destid;
593 u8 hopcount = rdev->rswitch->hopcount;
594 u32 regval; 575 u32 regval;
595 int checkcount; 576 int checkcount;
596 577
597 if (lnkresp) { 578 if (lnkresp) {
598 /* Read from link maintenance response register 579 /* Read from link maintenance response register
599 * to clear valid bit */ 580 * to clear valid bit */
600 rio_mport_read_config_32(mport, destid, hopcount, 581 rio_read_config_32(rdev,
601 rdev->phys_efptr + RIO_PORT_N_MNT_RSP_CSR(pnum), 582 rdev->phys_efptr + RIO_PORT_N_MNT_RSP_CSR(pnum),
602 &regval); 583 &regval);
603 udelay(50); 584 udelay(50);
604 } 585 }
605 586
606 /* Issue Input-status command */ 587 /* Issue Input-status command */
607 rio_mport_write_config_32(mport, destid, hopcount, 588 rio_write_config_32(rdev,
608 rdev->phys_efptr + RIO_PORT_N_MNT_REQ_CSR(pnum), 589 rdev->phys_efptr + RIO_PORT_N_MNT_REQ_CSR(pnum),
609 RIO_MNT_REQ_CMD_IS); 590 RIO_MNT_REQ_CMD_IS);
610 591
@@ -615,7 +596,7 @@ rio_get_input_status(struct rio_dev *rdev, int pnum, u32 *lnkresp)
615 checkcount = 3; 596 checkcount = 3;
616 while (checkcount--) { 597 while (checkcount--) {
617 udelay(50); 598 udelay(50);
618 rio_mport_read_config_32(mport, destid, hopcount, 599 rio_read_config_32(rdev,
619 rdev->phys_efptr + RIO_PORT_N_MNT_RSP_CSR(pnum), 600 rdev->phys_efptr + RIO_PORT_N_MNT_RSP_CSR(pnum),
620 &regval); 601 &regval);
621 if (regval & RIO_PORT_N_MNT_RSP_RVAL) { 602 if (regval & RIO_PORT_N_MNT_RSP_RVAL) {
@@ -635,15 +616,12 @@ rio_get_input_status(struct rio_dev *rdev, int pnum, u32 *lnkresp)
635 */ 616 */
636static int rio_clr_err_stopped(struct rio_dev *rdev, u32 pnum, u32 err_status) 617static int rio_clr_err_stopped(struct rio_dev *rdev, u32 pnum, u32 err_status)
637{ 618{
638 struct rio_mport *mport = rdev->net->hport;
639 u16 destid = rdev->rswitch->destid;
640 u8 hopcount = rdev->rswitch->hopcount;
641 struct rio_dev *nextdev = rdev->rswitch->nextdev[pnum]; 619 struct rio_dev *nextdev = rdev->rswitch->nextdev[pnum];
642 u32 regval; 620 u32 regval;
643 u32 far_ackid, far_linkstat, near_ackid; 621 u32 far_ackid, far_linkstat, near_ackid;
644 622
645 if (err_status == 0) 623 if (err_status == 0)
646 rio_mport_read_config_32(mport, destid, hopcount, 624 rio_read_config_32(rdev,
647 rdev->phys_efptr + RIO_PORT_N_ERR_STS_CSR(pnum), 625 rdev->phys_efptr + RIO_PORT_N_ERR_STS_CSR(pnum),
648 &err_status); 626 &err_status);
649 627
@@ -661,7 +639,7 @@ static int rio_clr_err_stopped(struct rio_dev *rdev, u32 pnum, u32 err_status)
661 pnum, regval); 639 pnum, regval);
662 far_ackid = (regval & RIO_PORT_N_MNT_RSP_ASTAT) >> 5; 640 far_ackid = (regval & RIO_PORT_N_MNT_RSP_ASTAT) >> 5;
663 far_linkstat = regval & RIO_PORT_N_MNT_RSP_LSTAT; 641 far_linkstat = regval & RIO_PORT_N_MNT_RSP_LSTAT;
664 rio_mport_read_config_32(mport, destid, hopcount, 642 rio_read_config_32(rdev,
665 rdev->phys_efptr + RIO_PORT_N_ACK_STS_CSR(pnum), 643 rdev->phys_efptr + RIO_PORT_N_ACK_STS_CSR(pnum),
666 &regval); 644 &regval);
667 pr_debug("RIO_EM: SP%d_ACK_STS_CSR=0x%08x\n", pnum, regval); 645 pr_debug("RIO_EM: SP%d_ACK_STS_CSR=0x%08x\n", pnum, regval);
@@ -679,9 +657,8 @@ static int rio_clr_err_stopped(struct rio_dev *rdev, u32 pnum, u32 err_status)
679 /* Align near outstanding/outbound ackIDs with 657 /* Align near outstanding/outbound ackIDs with
680 * far inbound. 658 * far inbound.
681 */ 659 */
682 rio_mport_write_config_32(mport, destid, 660 rio_write_config_32(rdev,
683 hopcount, rdev->phys_efptr + 661 rdev->phys_efptr + RIO_PORT_N_ACK_STS_CSR(pnum),
684 RIO_PORT_N_ACK_STS_CSR(pnum),
685 (near_ackid << 24) | 662 (near_ackid << 24) |
686 (far_ackid << 8) | far_ackid); 663 (far_ackid << 8) | far_ackid);
687 /* Align far outstanding/outbound ackIDs with 664 /* Align far outstanding/outbound ackIDs with
@@ -698,7 +675,7 @@ static int rio_clr_err_stopped(struct rio_dev *rdev, u32 pnum, u32 err_status)
698 pr_debug("RIO_EM: Invalid nextdev pointer (NULL)\n"); 675 pr_debug("RIO_EM: Invalid nextdev pointer (NULL)\n");
699 } 676 }
700rd_err: 677rd_err:
701 rio_mport_read_config_32(mport, destid, hopcount, 678 rio_read_config_32(rdev,
702 rdev->phys_efptr + RIO_PORT_N_ERR_STS_CSR(pnum), 679 rdev->phys_efptr + RIO_PORT_N_ERR_STS_CSR(pnum),
703 &err_status); 680 &err_status);
704 pr_debug("RIO_EM: SP%d_ERR_STS_CSR=0x%08x\n", pnum, err_status); 681 pr_debug("RIO_EM: SP%d_ERR_STS_CSR=0x%08x\n", pnum, err_status);
@@ -710,7 +687,7 @@ rd_err:
710 RIO_GET_PORT_NUM(nextdev->swpinfo), NULL); 687 RIO_GET_PORT_NUM(nextdev->swpinfo), NULL);
711 udelay(50); 688 udelay(50);
712 689
713 rio_mport_read_config_32(mport, destid, hopcount, 690 rio_read_config_32(rdev,
714 rdev->phys_efptr + RIO_PORT_N_ERR_STS_CSR(pnum), 691 rdev->phys_efptr + RIO_PORT_N_ERR_STS_CSR(pnum),
715 &err_status); 692 &err_status);
716 pr_debug("RIO_EM: SP%d_ERR_STS_CSR=0x%08x\n", pnum, err_status); 693 pr_debug("RIO_EM: SP%d_ERR_STS_CSR=0x%08x\n", pnum, err_status);
@@ -730,13 +707,10 @@ rd_err:
730int rio_inb_pwrite_handler(union rio_pw_msg *pw_msg) 707int rio_inb_pwrite_handler(union rio_pw_msg *pw_msg)
731{ 708{
732 struct rio_dev *rdev; 709 struct rio_dev *rdev;
733 struct rio_mport *mport;
734 u8 hopcount;
735 u16 destid;
736 u32 err_status, em_perrdet, em_ltlerrdet; 710 u32 err_status, em_perrdet, em_ltlerrdet;
737 int rc, portnum; 711 int rc, portnum;
738 712
739 rdev = rio_get_comptag(pw_msg->em.comptag, NULL); 713 rdev = rio_get_comptag((pw_msg->em.comptag & RIO_CTAG_UDEVID), NULL);
740 if (rdev == NULL) { 714 if (rdev == NULL) {
741 /* Device removed or enumeration error */ 715 /* Device removed or enumeration error */
742 pr_debug("RIO: %s No matching device for CTag 0x%08x\n", 716 pr_debug("RIO: %s No matching device for CTag 0x%08x\n",
@@ -800,17 +774,13 @@ int rio_inb_pwrite_handler(union rio_pw_msg *pw_msg)
800 return 0; 774 return 0;
801 } 775 }
802 776
803 mport = rdev->net->hport;
804 destid = rdev->rswitch->destid;
805 hopcount = rdev->rswitch->hopcount;
806
807 /* 777 /*
808 * Process the port-write notification from switch 778 * Process the port-write notification from switch
809 */ 779 */
810 if (rdev->rswitch->em_handle) 780 if (rdev->rswitch->em_handle)
811 rdev->rswitch->em_handle(rdev, portnum); 781 rdev->rswitch->em_handle(rdev, portnum);
812 782
813 rio_mport_read_config_32(mport, destid, hopcount, 783 rio_read_config_32(rdev,
814 rdev->phys_efptr + RIO_PORT_N_ERR_STS_CSR(portnum), 784 rdev->phys_efptr + RIO_PORT_N_ERR_STS_CSR(portnum),
815 &err_status); 785 &err_status);
816 pr_debug("RIO_PW: SP%d_ERR_STS_CSR=0x%08x\n", portnum, err_status); 786 pr_debug("RIO_PW: SP%d_ERR_STS_CSR=0x%08x\n", portnum, err_status);
@@ -840,7 +810,7 @@ int rio_inb_pwrite_handler(union rio_pw_msg *pw_msg)
840 rdev->rswitch->port_ok &= ~(1 << portnum); 810 rdev->rswitch->port_ok &= ~(1 << portnum);
841 rio_set_port_lockout(rdev, portnum, 1); 811 rio_set_port_lockout(rdev, portnum, 1);
842 812
843 rio_mport_write_config_32(mport, destid, hopcount, 813 rio_write_config_32(rdev,
844 rdev->phys_efptr + 814 rdev->phys_efptr +
845 RIO_PORT_N_ACK_STS_CSR(portnum), 815 RIO_PORT_N_ACK_STS_CSR(portnum),
846 RIO_PORT_N_ACK_CLEAR); 816 RIO_PORT_N_ACK_CLEAR);
@@ -851,28 +821,28 @@ int rio_inb_pwrite_handler(union rio_pw_msg *pw_msg)
851 } 821 }
852 } 822 }
853 823
854 rio_mport_read_config_32(mport, destid, hopcount, 824 rio_read_config_32(rdev,
855 rdev->em_efptr + RIO_EM_PN_ERR_DETECT(portnum), &em_perrdet); 825 rdev->em_efptr + RIO_EM_PN_ERR_DETECT(portnum), &em_perrdet);
856 if (em_perrdet) { 826 if (em_perrdet) {
857 pr_debug("RIO_PW: RIO_EM_P%d_ERR_DETECT=0x%08x\n", 827 pr_debug("RIO_PW: RIO_EM_P%d_ERR_DETECT=0x%08x\n",
858 portnum, em_perrdet); 828 portnum, em_perrdet);
859 /* Clear EM Port N Error Detect CSR */ 829 /* Clear EM Port N Error Detect CSR */
860 rio_mport_write_config_32(mport, destid, hopcount, 830 rio_write_config_32(rdev,
861 rdev->em_efptr + RIO_EM_PN_ERR_DETECT(portnum), 0); 831 rdev->em_efptr + RIO_EM_PN_ERR_DETECT(portnum), 0);
862 } 832 }
863 833
864 rio_mport_read_config_32(mport, destid, hopcount, 834 rio_read_config_32(rdev,
865 rdev->em_efptr + RIO_EM_LTL_ERR_DETECT, &em_ltlerrdet); 835 rdev->em_efptr + RIO_EM_LTL_ERR_DETECT, &em_ltlerrdet);
866 if (em_ltlerrdet) { 836 if (em_ltlerrdet) {
867 pr_debug("RIO_PW: RIO_EM_LTL_ERR_DETECT=0x%08x\n", 837 pr_debug("RIO_PW: RIO_EM_LTL_ERR_DETECT=0x%08x\n",
868 em_ltlerrdet); 838 em_ltlerrdet);
869 /* Clear EM L/T Layer Error Detect CSR */ 839 /* Clear EM L/T Layer Error Detect CSR */
870 rio_mport_write_config_32(mport, destid, hopcount, 840 rio_write_config_32(rdev,
871 rdev->em_efptr + RIO_EM_LTL_ERR_DETECT, 0); 841 rdev->em_efptr + RIO_EM_LTL_ERR_DETECT, 0);
872 } 842 }
873 843
874 /* Clear remaining error bits and Port-Write Pending bit */ 844 /* Clear remaining error bits and Port-Write Pending bit */
875 rio_mport_write_config_32(mport, destid, hopcount, 845 rio_write_config_32(rdev,
876 rdev->phys_efptr + RIO_PORT_N_ERR_STS_CSR(portnum), 846 rdev->phys_efptr + RIO_PORT_N_ERR_STS_CSR(portnum),
877 err_status); 847 err_status);
878 848
diff --git a/drivers/rapidio/switches/idt_gen2.c b/drivers/rapidio/switches/idt_gen2.c
index 0bb871cb5c40..095016a9dec1 100644
--- a/drivers/rapidio/switches/idt_gen2.c
+++ b/drivers/rapidio/switches/idt_gen2.c
@@ -209,9 +209,6 @@ idtg2_get_domain(struct rio_mport *mport, u16 destid, u8 hopcount,
209static int 209static int
210idtg2_em_init(struct rio_dev *rdev) 210idtg2_em_init(struct rio_dev *rdev)
211{ 211{
212 struct rio_mport *mport = rdev->net->hport;
213 u16 destid = rdev->rswitch->destid;
214 u8 hopcount = rdev->rswitch->hopcount;
215 u32 regval; 212 u32 regval;
216 int i, tmp; 213 int i, tmp;
217 214
@@ -220,29 +217,25 @@ idtg2_em_init(struct rio_dev *rdev)
220 * All standard EM configuration should be performed at upper level. 217 * All standard EM configuration should be performed at upper level.
221 */ 218 */
222 219
223 pr_debug("RIO: %s [%d:%d]\n", __func__, destid, hopcount); 220 pr_debug("RIO: %s [%d:%d]\n", __func__, rdev->destid, rdev->hopcount);
224 221
225 /* Set Port-Write info CSR: PRIO=3 and CRF=1 */ 222 /* Set Port-Write info CSR: PRIO=3 and CRF=1 */
226 rio_mport_write_config_32(mport, destid, hopcount, 223 rio_write_config_32(rdev, IDT_PW_INFO_CSR, 0x0000e000);
227 IDT_PW_INFO_CSR, 0x0000e000);
228 224
229 /* 225 /*
230 * Configure LT LAYER error reporting. 226 * Configure LT LAYER error reporting.
231 */ 227 */
232 228
233 /* Enable standard (RIO.p8) error reporting */ 229 /* Enable standard (RIO.p8) error reporting */
234 rio_mport_write_config_32(mport, destid, hopcount, 230 rio_write_config_32(rdev, IDT_LT_ERR_REPORT_EN,
235 IDT_LT_ERR_REPORT_EN,
236 REM_LTL_ERR_ILLTRAN | REM_LTL_ERR_UNSOLR | 231 REM_LTL_ERR_ILLTRAN | REM_LTL_ERR_UNSOLR |
237 REM_LTL_ERR_UNSUPTR); 232 REM_LTL_ERR_UNSUPTR);
238 233
239 /* Use Port-Writes for LT layer error reporting. 234 /* Use Port-Writes for LT layer error reporting.
240 * Enable per-port reset 235 * Enable per-port reset
241 */ 236 */
242 rio_mport_read_config_32(mport, destid, hopcount, 237 rio_read_config_32(rdev, IDT_DEV_CTRL_1, &regval);
243 IDT_DEV_CTRL_1, &regval); 238 rio_write_config_32(rdev, IDT_DEV_CTRL_1,
244 rio_mport_write_config_32(mport, destid, hopcount,
245 IDT_DEV_CTRL_1,
246 regval | IDT_DEV_CTRL_1_GENPW | IDT_DEV_CTRL_1_PRSTBEH); 239 regval | IDT_DEV_CTRL_1_GENPW | IDT_DEV_CTRL_1_PRSTBEH);
247 240
248 /* 241 /*
@@ -250,45 +243,40 @@ idtg2_em_init(struct rio_dev *rdev)
250 */ 243 */
251 244
252 /* Report all RIO.p8 errors supported by device */ 245 /* Report all RIO.p8 errors supported by device */
253 rio_mport_write_config_32(mport, destid, hopcount, 246 rio_write_config_32(rdev, IDT_PORT_ERR_REPORT_EN_BC, 0x807e8037);
254 IDT_PORT_ERR_REPORT_EN_BC, 0x807e8037);
255 247
256 /* Configure reporting of implementation specific errors/events */ 248 /* Configure reporting of implementation specific errors/events */
257 rio_mport_write_config_32(mport, destid, hopcount, 249 rio_write_config_32(rdev, IDT_PORT_ISERR_REPORT_EN_BC,
258 IDT_PORT_ISERR_REPORT_EN_BC, IDT_PORT_INIT_TX_ACQUIRED); 250 IDT_PORT_INIT_TX_ACQUIRED);
259 251
260 /* Use Port-Writes for port error reporting and enable error logging */ 252 /* Use Port-Writes for port error reporting and enable error logging */
261 tmp = RIO_GET_TOTAL_PORTS(rdev->swpinfo); 253 tmp = RIO_GET_TOTAL_PORTS(rdev->swpinfo);
262 for (i = 0; i < tmp; i++) { 254 for (i = 0; i < tmp; i++) {
263 rio_mport_read_config_32(mport, destid, hopcount, 255 rio_read_config_32(rdev, IDT_PORT_OPS(i), &regval);
264 IDT_PORT_OPS(i), &regval); 256 rio_write_config_32(rdev,
265 rio_mport_write_config_32(mport, destid, hopcount,
266 IDT_PORT_OPS(i), regval | IDT_PORT_OPS_GENPW | 257 IDT_PORT_OPS(i), regval | IDT_PORT_OPS_GENPW |
267 IDT_PORT_OPS_PL_ELOG | 258 IDT_PORT_OPS_PL_ELOG |
268 IDT_PORT_OPS_LL_ELOG | 259 IDT_PORT_OPS_LL_ELOG |
269 IDT_PORT_OPS_LT_ELOG); 260 IDT_PORT_OPS_LT_ELOG);
270 } 261 }
271 /* Overwrite error log if full */ 262 /* Overwrite error log if full */
272 rio_mport_write_config_32(mport, destid, hopcount, 263 rio_write_config_32(rdev, IDT_ERR_CAP, IDT_ERR_CAP_LOG_OVERWR);
273 IDT_ERR_CAP, IDT_ERR_CAP_LOG_OVERWR);
274 264
275 /* 265 /*
276 * Configure LANE error reporting. 266 * Configure LANE error reporting.
277 */ 267 */
278 268
279 /* Disable line error reporting */ 269 /* Disable line error reporting */
280 rio_mport_write_config_32(mport, destid, hopcount, 270 rio_write_config_32(rdev, IDT_LANE_ERR_REPORT_EN_BC, 0);
281 IDT_LANE_ERR_REPORT_EN_BC, 0);
282 271
283 /* Use Port-Writes for lane error reporting (when enabled) 272 /* Use Port-Writes for lane error reporting (when enabled)
284 * (do per-lane update because lanes may have different configuration) 273 * (do per-lane update because lanes may have different configuration)
285 */ 274 */
286 tmp = (rdev->did == RIO_DID_IDTCPS1848) ? 48 : 16; 275 tmp = (rdev->did == RIO_DID_IDTCPS1848) ? 48 : 16;
287 for (i = 0; i < tmp; i++) { 276 for (i = 0; i < tmp; i++) {
288 rio_mport_read_config_32(mport, destid, hopcount, 277 rio_read_config_32(rdev, IDT_LANE_CTRL(i), &regval);
289 IDT_LANE_CTRL(i), &regval); 278 rio_write_config_32(rdev, IDT_LANE_CTRL(i),
290 rio_mport_write_config_32(mport, destid, hopcount, 279 regval | IDT_LANE_CTRL_GENPW);
291 IDT_LANE_CTRL(i), regval | IDT_LANE_CTRL_GENPW);
292 } 280 }
293 281
294 /* 282 /*
@@ -296,41 +284,32 @@ idtg2_em_init(struct rio_dev *rdev)
296 */ 284 */
297 285
298 /* Disable JTAG and I2C Error capture */ 286 /* Disable JTAG and I2C Error capture */
299 rio_mport_write_config_32(mport, destid, hopcount, 287 rio_write_config_32(rdev, IDT_AUX_PORT_ERR_CAP_EN, 0);
300 IDT_AUX_PORT_ERR_CAP_EN, 0);
301 288
302 /* Disable JTAG and I2C Error reporting/logging */ 289 /* Disable JTAG and I2C Error reporting/logging */
303 rio_mport_write_config_32(mport, destid, hopcount, 290 rio_write_config_32(rdev, IDT_AUX_ERR_REPORT_EN, 0);
304 IDT_AUX_ERR_REPORT_EN, 0);
305 291
306 /* Disable Port-Write notification from JTAG */ 292 /* Disable Port-Write notification from JTAG */
307 rio_mport_write_config_32(mport, destid, hopcount, 293 rio_write_config_32(rdev, IDT_JTAG_CTRL, 0);
308 IDT_JTAG_CTRL, 0);
309 294
310 /* Disable Port-Write notification from I2C */ 295 /* Disable Port-Write notification from I2C */
311 rio_mport_read_config_32(mport, destid, hopcount, 296 rio_read_config_32(rdev, IDT_I2C_MCTRL, &regval);
312 IDT_I2C_MCTRL, &regval); 297 rio_write_config_32(rdev, IDT_I2C_MCTRL, regval & ~IDT_I2C_MCTRL_GENPW);
313 rio_mport_write_config_32(mport, destid, hopcount,
314 IDT_I2C_MCTRL,
315 regval & ~IDT_I2C_MCTRL_GENPW);
316 298
317 /* 299 /*
318 * Configure CFG_BLK error reporting. 300 * Configure CFG_BLK error reporting.
319 */ 301 */
320 302
321 /* Disable Configuration Block error capture */ 303 /* Disable Configuration Block error capture */
322 rio_mport_write_config_32(mport, destid, hopcount, 304 rio_write_config_32(rdev, IDT_CFGBLK_ERR_CAPTURE_EN, 0);
323 IDT_CFGBLK_ERR_CAPTURE_EN, 0);
324 305
325 /* Disable Port-Writes for Configuration Block error reporting */ 306 /* Disable Port-Writes for Configuration Block error reporting */
326 rio_mport_read_config_32(mport, destid, hopcount, 307 rio_read_config_32(rdev, IDT_CFGBLK_ERR_REPORT, &regval);
327 IDT_CFGBLK_ERR_REPORT, &regval); 308 rio_write_config_32(rdev, IDT_CFGBLK_ERR_REPORT,
328 rio_mport_write_config_32(mport, destid, hopcount, 309 regval & ~IDT_CFGBLK_ERR_REPORT_GENPW);
329 IDT_CFGBLK_ERR_REPORT,
330 regval & ~IDT_CFGBLK_ERR_REPORT_GENPW);
331 310
332 /* set TVAL = ~50us */ 311 /* set TVAL = ~50us */
333 rio_mport_write_config_32(mport, destid, hopcount, 312 rio_write_config_32(rdev,
334 rdev->phys_efptr + RIO_PORT_LINKTO_CTL_CSR, 0x8e << 8); 313 rdev->phys_efptr + RIO_PORT_LINKTO_CTL_CSR, 0x8e << 8);
335 314
336 return 0; 315 return 0;
@@ -339,18 +318,15 @@ idtg2_em_init(struct rio_dev *rdev)
339static int 318static int
340idtg2_em_handler(struct rio_dev *rdev, u8 portnum) 319idtg2_em_handler(struct rio_dev *rdev, u8 portnum)
341{ 320{
342 struct rio_mport *mport = rdev->net->hport;
343 u16 destid = rdev->rswitch->destid;
344 u8 hopcount = rdev->rswitch->hopcount;
345 u32 regval, em_perrdet, em_ltlerrdet; 321 u32 regval, em_perrdet, em_ltlerrdet;
346 322
347 rio_mport_read_config_32(mport, destid, hopcount, 323 rio_read_config_32(rdev,
348 rdev->em_efptr + RIO_EM_LTL_ERR_DETECT, &em_ltlerrdet); 324 rdev->em_efptr + RIO_EM_LTL_ERR_DETECT, &em_ltlerrdet);
349 if (em_ltlerrdet) { 325 if (em_ltlerrdet) {
350 /* Service Logical/Transport Layer Error(s) */ 326 /* Service Logical/Transport Layer Error(s) */
351 if (em_ltlerrdet & REM_LTL_ERR_IMPSPEC) { 327 if (em_ltlerrdet & REM_LTL_ERR_IMPSPEC) {
352 /* Implementation specific error reported */ 328 /* Implementation specific error reported */
353 rio_mport_read_config_32(mport, destid, hopcount, 329 rio_read_config_32(rdev,
354 IDT_ISLTL_ADDRESS_CAP, &regval); 330 IDT_ISLTL_ADDRESS_CAP, &regval);
355 331
356 pr_debug("RIO: %s Implementation Specific LTL errors" \ 332 pr_debug("RIO: %s Implementation Specific LTL errors" \
@@ -358,13 +334,12 @@ idtg2_em_handler(struct rio_dev *rdev, u8 portnum)
358 rio_name(rdev), em_ltlerrdet, regval); 334 rio_name(rdev), em_ltlerrdet, regval);
359 335
360 /* Clear implementation specific address capture CSR */ 336 /* Clear implementation specific address capture CSR */
361 rio_mport_write_config_32(mport, destid, hopcount, 337 rio_write_config_32(rdev, IDT_ISLTL_ADDRESS_CAP, 0);
362 IDT_ISLTL_ADDRESS_CAP, 0);
363 338
364 } 339 }
365 } 340 }
366 341
367 rio_mport_read_config_32(mport, destid, hopcount, 342 rio_read_config_32(rdev,
368 rdev->em_efptr + RIO_EM_PN_ERR_DETECT(portnum), &em_perrdet); 343 rdev->em_efptr + RIO_EM_PN_ERR_DETECT(portnum), &em_perrdet);
369 if (em_perrdet) { 344 if (em_perrdet) {
370 /* Service Port-Level Error(s) */ 345 /* Service Port-Level Error(s) */
@@ -372,14 +347,14 @@ idtg2_em_handler(struct rio_dev *rdev, u8 portnum)
372 /* Implementation Specific port error reported */ 347 /* Implementation Specific port error reported */
373 348
374 /* Get IS errors reported */ 349 /* Get IS errors reported */
375 rio_mport_read_config_32(mport, destid, hopcount, 350 rio_read_config_32(rdev,
376 IDT_PORT_ISERR_DET(portnum), &regval); 351 IDT_PORT_ISERR_DET(portnum), &regval);
377 352
378 pr_debug("RIO: %s Implementation Specific Port" \ 353 pr_debug("RIO: %s Implementation Specific Port" \
379 " errors 0x%x\n", rio_name(rdev), regval); 354 " errors 0x%x\n", rio_name(rdev), regval);
380 355
381 /* Clear all implementation specific events */ 356 /* Clear all implementation specific events */
382 rio_mport_write_config_32(mport, destid, hopcount, 357 rio_write_config_32(rdev,
383 IDT_PORT_ISERR_DET(portnum), 0); 358 IDT_PORT_ISERR_DET(portnum), 0);
384 } 359 }
385 } 360 }
@@ -391,14 +366,10 @@ static ssize_t
391idtg2_show_errlog(struct device *dev, struct device_attribute *attr, char *buf) 366idtg2_show_errlog(struct device *dev, struct device_attribute *attr, char *buf)
392{ 367{
393 struct rio_dev *rdev = to_rio_dev(dev); 368 struct rio_dev *rdev = to_rio_dev(dev);
394 struct rio_mport *mport = rdev->net->hport;
395 u16 destid = rdev->rswitch->destid;
396 u8 hopcount = rdev->rswitch->hopcount;
397 ssize_t len = 0; 369 ssize_t len = 0;
398 u32 regval; 370 u32 regval;
399 371
400 while (!rio_mport_read_config_32(mport, destid, hopcount, 372 while (!rio_read_config_32(rdev, IDT_ERR_RD, &regval)) {
401 IDT_ERR_RD, &regval)) {
402 if (!regval) /* 0 = end of log */ 373 if (!regval) /* 0 = end of log */
403 break; 374 break;
404 len += snprintf(buf + len, PAGE_SIZE - len, 375 len += snprintf(buf + len, PAGE_SIZE - len,
@@ -445,3 +416,5 @@ static int idtg2_switch_init(struct rio_dev *rdev, int do_enum)
445 416
446DECLARE_RIO_SWITCH_INIT(RIO_VID_IDT, RIO_DID_IDTCPS1848, idtg2_switch_init); 417DECLARE_RIO_SWITCH_INIT(RIO_VID_IDT, RIO_DID_IDTCPS1848, idtg2_switch_init);
447DECLARE_RIO_SWITCH_INIT(RIO_VID_IDT, RIO_DID_IDTCPS1616, idtg2_switch_init); 418DECLARE_RIO_SWITCH_INIT(RIO_VID_IDT, RIO_DID_IDTCPS1616, idtg2_switch_init);
419DECLARE_RIO_SWITCH_INIT(RIO_VID_IDT, RIO_DID_IDTVPS1616, idtg2_switch_init);
420DECLARE_RIO_SWITCH_INIT(RIO_VID_IDT, RIO_DID_IDTSPS1616, idtg2_switch_init);
diff --git a/drivers/rapidio/switches/idtcps.c b/drivers/rapidio/switches/idtcps.c
index fc9f6374f759..3a971077e7bf 100644
--- a/drivers/rapidio/switches/idtcps.c
+++ b/drivers/rapidio/switches/idtcps.c
@@ -117,10 +117,6 @@ idtcps_get_domain(struct rio_mport *mport, u16 destid, u8 hopcount,
117 117
118static int idtcps_switch_init(struct rio_dev *rdev, int do_enum) 118static int idtcps_switch_init(struct rio_dev *rdev, int do_enum)
119{ 119{
120 struct rio_mport *mport = rdev->net->hport;
121 u16 destid = rdev->rswitch->destid;
122 u8 hopcount = rdev->rswitch->hopcount;
123
124 pr_debug("RIO: %s for %s\n", __func__, rio_name(rdev)); 120 pr_debug("RIO: %s for %s\n", __func__, rio_name(rdev));
125 rdev->rswitch->add_entry = idtcps_route_add_entry; 121 rdev->rswitch->add_entry = idtcps_route_add_entry;
126 rdev->rswitch->get_entry = idtcps_route_get_entry; 122 rdev->rswitch->get_entry = idtcps_route_get_entry;
@@ -132,7 +128,7 @@ static int idtcps_switch_init(struct rio_dev *rdev, int do_enum)
132 128
133 if (do_enum) { 129 if (do_enum) {
134 /* set TVAL = ~50us */ 130 /* set TVAL = ~50us */
135 rio_mport_write_config_32(mport, destid, hopcount, 131 rio_write_config_32(rdev,
136 rdev->phys_efptr + RIO_PORT_LINKTO_CTL_CSR, 0x8e << 8); 132 rdev->phys_efptr + RIO_PORT_LINKTO_CTL_CSR, 0x8e << 8);
137 } 133 }
138 134
diff --git a/drivers/rapidio/switches/tsi568.c b/drivers/rapidio/switches/tsi568.c
index b9a389b9f812..3994c00aa01f 100644
--- a/drivers/rapidio/switches/tsi568.c
+++ b/drivers/rapidio/switches/tsi568.c
@@ -113,22 +113,17 @@ tsi568_route_clr_table(struct rio_mport *mport, u16 destid, u8 hopcount,
113static int 113static int
114tsi568_em_init(struct rio_dev *rdev) 114tsi568_em_init(struct rio_dev *rdev)
115{ 115{
116 struct rio_mport *mport = rdev->net->hport;
117 u16 destid = rdev->rswitch->destid;
118 u8 hopcount = rdev->rswitch->hopcount;
119 u32 regval; 116 u32 regval;
120 int portnum; 117 int portnum;
121 118
122 pr_debug("TSI568 %s [%d:%d]\n", __func__, destid, hopcount); 119 pr_debug("TSI568 %s [%d:%d]\n", __func__, rdev->destid, rdev->hopcount);
123 120
124 /* Make sure that Port-Writes are disabled (for all ports) */ 121 /* Make sure that Port-Writes are disabled (for all ports) */
125 for (portnum = 0; 122 for (portnum = 0;
126 portnum < RIO_GET_TOTAL_PORTS(rdev->swpinfo); portnum++) { 123 portnum < RIO_GET_TOTAL_PORTS(rdev->swpinfo); portnum++) {
127 rio_mport_read_config_32(mport, destid, hopcount, 124 rio_read_config_32(rdev, TSI568_SP_MODE(portnum), &regval);
128 TSI568_SP_MODE(portnum), &regval); 125 rio_write_config_32(rdev, TSI568_SP_MODE(portnum),
129 rio_mport_write_config_32(mport, destid, hopcount, 126 regval | TSI568_SP_MODE_PW_DIS);
130 TSI568_SP_MODE(portnum),
131 regval | TSI568_SP_MODE_PW_DIS);
132 } 127 }
133 128
134 return 0; 129 return 0;
diff --git a/drivers/rapidio/switches/tsi57x.c b/drivers/rapidio/switches/tsi57x.c
index 2003fb63c404..1a62934bfebc 100644
--- a/drivers/rapidio/switches/tsi57x.c
+++ b/drivers/rapidio/switches/tsi57x.c
@@ -158,48 +158,45 @@ tsi57x_get_domain(struct rio_mport *mport, u16 destid, u8 hopcount,
158static int 158static int
159tsi57x_em_init(struct rio_dev *rdev) 159tsi57x_em_init(struct rio_dev *rdev)
160{ 160{
161 struct rio_mport *mport = rdev->net->hport;
162 u16 destid = rdev->rswitch->destid;
163 u8 hopcount = rdev->rswitch->hopcount;
164 u32 regval; 161 u32 regval;
165 int portnum; 162 int portnum;
166 163
167 pr_debug("TSI578 %s [%d:%d]\n", __func__, destid, hopcount); 164 pr_debug("TSI578 %s [%d:%d]\n", __func__, rdev->destid, rdev->hopcount);
168 165
169 for (portnum = 0; 166 for (portnum = 0;
170 portnum < RIO_GET_TOTAL_PORTS(rdev->swpinfo); portnum++) { 167 portnum < RIO_GET_TOTAL_PORTS(rdev->swpinfo); portnum++) {
171 /* Make sure that Port-Writes are enabled (for all ports) */ 168 /* Make sure that Port-Writes are enabled (for all ports) */
172 rio_mport_read_config_32(mport, destid, hopcount, 169 rio_read_config_32(rdev,
173 TSI578_SP_MODE(portnum), &regval); 170 TSI578_SP_MODE(portnum), &regval);
174 rio_mport_write_config_32(mport, destid, hopcount, 171 rio_write_config_32(rdev,
175 TSI578_SP_MODE(portnum), 172 TSI578_SP_MODE(portnum),
176 regval & ~TSI578_SP_MODE_PW_DIS); 173 regval & ~TSI578_SP_MODE_PW_DIS);
177 174
178 /* Clear all pending interrupts */ 175 /* Clear all pending interrupts */
179 rio_mport_read_config_32(mport, destid, hopcount, 176 rio_read_config_32(rdev,
180 rdev->phys_efptr + 177 rdev->phys_efptr +
181 RIO_PORT_N_ERR_STS_CSR(portnum), 178 RIO_PORT_N_ERR_STS_CSR(portnum),
182 &regval); 179 &regval);
183 rio_mport_write_config_32(mport, destid, hopcount, 180 rio_write_config_32(rdev,
184 rdev->phys_efptr + 181 rdev->phys_efptr +
185 RIO_PORT_N_ERR_STS_CSR(portnum), 182 RIO_PORT_N_ERR_STS_CSR(portnum),
186 regval & 0x07120214); 183 regval & 0x07120214);
187 184
188 rio_mport_read_config_32(mport, destid, hopcount, 185 rio_read_config_32(rdev,
189 TSI578_SP_INT_STATUS(portnum), &regval); 186 TSI578_SP_INT_STATUS(portnum), &regval);
190 rio_mport_write_config_32(mport, destid, hopcount, 187 rio_write_config_32(rdev,
191 TSI578_SP_INT_STATUS(portnum), 188 TSI578_SP_INT_STATUS(portnum),
192 regval & 0x000700bd); 189 regval & 0x000700bd);
193 190
194 /* Enable all interrupts to allow ports to send a port-write */ 191 /* Enable all interrupts to allow ports to send a port-write */
195 rio_mport_read_config_32(mport, destid, hopcount, 192 rio_read_config_32(rdev,
196 TSI578_SP_CTL_INDEP(portnum), &regval); 193 TSI578_SP_CTL_INDEP(portnum), &regval);
197 rio_mport_write_config_32(mport, destid, hopcount, 194 rio_write_config_32(rdev,
198 TSI578_SP_CTL_INDEP(portnum), 195 TSI578_SP_CTL_INDEP(portnum),
199 regval | 0x000b0000); 196 regval | 0x000b0000);
200 197
201 /* Skip next (odd) port if the current port is in x4 mode */ 198 /* Skip next (odd) port if the current port is in x4 mode */
202 rio_mport_read_config_32(mport, destid, hopcount, 199 rio_read_config_32(rdev,
203 rdev->phys_efptr + RIO_PORT_N_CTL_CSR(portnum), 200 rdev->phys_efptr + RIO_PORT_N_CTL_CSR(portnum),
204 &regval); 201 &regval);
205 if ((regval & RIO_PORT_N_CTL_PWIDTH) == RIO_PORT_N_CTL_PWIDTH_4) 202 if ((regval & RIO_PORT_N_CTL_PWIDTH) == RIO_PORT_N_CTL_PWIDTH_4)
@@ -207,7 +204,7 @@ tsi57x_em_init(struct rio_dev *rdev)
207 } 204 }
208 205
209 /* set TVAL = ~50us */ 206 /* set TVAL = ~50us */
210 rio_mport_write_config_32(mport, destid, hopcount, 207 rio_write_config_32(rdev,
211 rdev->phys_efptr + RIO_PORT_LINKTO_CTL_CSR, 0x9a << 8); 208 rdev->phys_efptr + RIO_PORT_LINKTO_CTL_CSR, 0x9a << 8);
212 209
213 return 0; 210 return 0;
@@ -217,14 +214,12 @@ static int
217tsi57x_em_handler(struct rio_dev *rdev, u8 portnum) 214tsi57x_em_handler(struct rio_dev *rdev, u8 portnum)
218{ 215{
219 struct rio_mport *mport = rdev->net->hport; 216 struct rio_mport *mport = rdev->net->hport;
220 u16 destid = rdev->rswitch->destid;
221 u8 hopcount = rdev->rswitch->hopcount;
222 u32 intstat, err_status; 217 u32 intstat, err_status;
223 int sendcount, checkcount; 218 int sendcount, checkcount;
224 u8 route_port; 219 u8 route_port;
225 u32 regval; 220 u32 regval;
226 221
227 rio_mport_read_config_32(mport, destid, hopcount, 222 rio_read_config_32(rdev,
228 rdev->phys_efptr + RIO_PORT_N_ERR_STS_CSR(portnum), 223 rdev->phys_efptr + RIO_PORT_N_ERR_STS_CSR(portnum),
229 &err_status); 224 &err_status);
230 225
@@ -232,15 +227,15 @@ tsi57x_em_handler(struct rio_dev *rdev, u8 portnum)
232 (err_status & (RIO_PORT_N_ERR_STS_PW_OUT_ES | 227 (err_status & (RIO_PORT_N_ERR_STS_PW_OUT_ES |
233 RIO_PORT_N_ERR_STS_PW_INP_ES))) { 228 RIO_PORT_N_ERR_STS_PW_INP_ES))) {
234 /* Remove any queued packets by locking/unlocking port */ 229 /* Remove any queued packets by locking/unlocking port */
235 rio_mport_read_config_32(mport, destid, hopcount, 230 rio_read_config_32(rdev,
236 rdev->phys_efptr + RIO_PORT_N_CTL_CSR(portnum), 231 rdev->phys_efptr + RIO_PORT_N_CTL_CSR(portnum),
237 &regval); 232 &regval);
238 if (!(regval & RIO_PORT_N_CTL_LOCKOUT)) { 233 if (!(regval & RIO_PORT_N_CTL_LOCKOUT)) {
239 rio_mport_write_config_32(mport, destid, hopcount, 234 rio_write_config_32(rdev,
240 rdev->phys_efptr + RIO_PORT_N_CTL_CSR(portnum), 235 rdev->phys_efptr + RIO_PORT_N_CTL_CSR(portnum),
241 regval | RIO_PORT_N_CTL_LOCKOUT); 236 regval | RIO_PORT_N_CTL_LOCKOUT);
242 udelay(50); 237 udelay(50);
243 rio_mport_write_config_32(mport, destid, hopcount, 238 rio_write_config_32(rdev,
244 rdev->phys_efptr + RIO_PORT_N_CTL_CSR(portnum), 239 rdev->phys_efptr + RIO_PORT_N_CTL_CSR(portnum),
245 regval); 240 regval);
246 } 241 }
@@ -248,7 +243,7 @@ tsi57x_em_handler(struct rio_dev *rdev, u8 portnum)
248 /* Read from link maintenance response register to clear 243 /* Read from link maintenance response register to clear
249 * valid bit 244 * valid bit
250 */ 245 */
251 rio_mport_read_config_32(mport, destid, hopcount, 246 rio_read_config_32(rdev,
252 rdev->phys_efptr + RIO_PORT_N_MNT_RSP_CSR(portnum), 247 rdev->phys_efptr + RIO_PORT_N_MNT_RSP_CSR(portnum),
253 &regval); 248 &regval);
254 249
@@ -257,13 +252,12 @@ tsi57x_em_handler(struct rio_dev *rdev, u8 portnum)
257 */ 252 */
258 sendcount = 3; 253 sendcount = 3;
259 while (sendcount) { 254 while (sendcount) {
260 rio_mport_write_config_32(mport, destid, hopcount, 255 rio_write_config_32(rdev,
261 TSI578_SP_CS_TX(portnum), 0x40fc8000); 256 TSI578_SP_CS_TX(portnum), 0x40fc8000);
262 checkcount = 3; 257 checkcount = 3;
263 while (checkcount--) { 258 while (checkcount--) {
264 udelay(50); 259 udelay(50);
265 rio_mport_read_config_32( 260 rio_read_config_32(rdev,
266 mport, destid, hopcount,
267 rdev->phys_efptr + 261 rdev->phys_efptr +
268 RIO_PORT_N_MNT_RSP_CSR(portnum), 262 RIO_PORT_N_MNT_RSP_CSR(portnum),
269 &regval); 263 &regval);
@@ -277,25 +271,23 @@ tsi57x_em_handler(struct rio_dev *rdev, u8 portnum)
277 271
278exit_es: 272exit_es:
279 /* Clear implementation specific error status bits */ 273 /* Clear implementation specific error status bits */
280 rio_mport_read_config_32(mport, destid, hopcount, 274 rio_read_config_32(rdev, TSI578_SP_INT_STATUS(portnum), &intstat);
281 TSI578_SP_INT_STATUS(portnum), &intstat);
282 pr_debug("TSI578[%x:%x] SP%d_INT_STATUS=0x%08x\n", 275 pr_debug("TSI578[%x:%x] SP%d_INT_STATUS=0x%08x\n",
283 destid, hopcount, portnum, intstat); 276 rdev->destid, rdev->hopcount, portnum, intstat);
284 277
285 if (intstat & 0x10000) { 278 if (intstat & 0x10000) {
286 rio_mport_read_config_32(mport, destid, hopcount, 279 rio_read_config_32(rdev,
287 TSI578_SP_LUT_PEINF(portnum), &regval); 280 TSI578_SP_LUT_PEINF(portnum), &regval);
288 regval = (mport->sys_size) ? (regval >> 16) : (regval >> 24); 281 regval = (mport->sys_size) ? (regval >> 16) : (regval >> 24);
289 route_port = rdev->rswitch->route_table[regval]; 282 route_port = rdev->rswitch->route_table[regval];
290 pr_debug("RIO: TSI578[%s] P%d LUT Parity Error (destID=%d)\n", 283 pr_debug("RIO: TSI578[%s] P%d LUT Parity Error (destID=%d)\n",
291 rio_name(rdev), portnum, regval); 284 rio_name(rdev), portnum, regval);
292 tsi57x_route_add_entry(mport, destid, hopcount, 285 tsi57x_route_add_entry(mport, rdev->destid, rdev->hopcount,
293 RIO_GLOBAL_TABLE, regval, route_port); 286 RIO_GLOBAL_TABLE, regval, route_port);
294 } 287 }
295 288
296 rio_mport_write_config_32(mport, destid, hopcount, 289 rio_write_config_32(rdev, TSI578_SP_INT_STATUS(portnum),
297 TSI578_SP_INT_STATUS(portnum), 290 intstat & 0x000700bd);
298 intstat & 0x000700bd);
299 291
300 return 0; 292 return 0;
301} 293}
diff --git a/drivers/regulator/88pm8607.c b/drivers/regulator/88pm8607.c
index 2ce2eb71d0f5..dd6308499bd4 100644
--- a/drivers/regulator/88pm8607.c
+++ b/drivers/regulator/88pm8607.c
@@ -249,7 +249,7 @@ static int choose_voltage(struct regulator_dev *rdev, int min_uV, int max_uV)
249} 249}
250 250
251static int pm8607_set_voltage(struct regulator_dev *rdev, 251static int pm8607_set_voltage(struct regulator_dev *rdev,
252 int min_uV, int max_uV) 252 int min_uV, int max_uV, unsigned *selector)
253{ 253{
254 struct pm8607_regulator_info *info = rdev_get_drvdata(rdev); 254 struct pm8607_regulator_info *info = rdev_get_drvdata(rdev);
255 uint8_t val, mask; 255 uint8_t val, mask;
@@ -263,6 +263,7 @@ static int pm8607_set_voltage(struct regulator_dev *rdev,
263 ret = choose_voltage(rdev, min_uV, max_uV); 263 ret = choose_voltage(rdev, min_uV, max_uV);
264 if (ret < 0) 264 if (ret < 0)
265 return -EINVAL; 265 return -EINVAL;
266 *selector = ret;
266 val = (uint8_t)(ret << info->vol_shift); 267 val = (uint8_t)(ret << info->vol_shift);
267 mask = ((1 << info->vol_nbits) - 1) << info->vol_shift; 268 mask = ((1 << info->vol_nbits) - 1) << info->vol_shift;
268 269
diff --git a/drivers/regulator/Kconfig b/drivers/regulator/Kconfig
index dd30e883d4a7..e1d943619ab8 100644
--- a/drivers/regulator/Kconfig
+++ b/drivers/regulator/Kconfig
@@ -186,13 +186,25 @@ config REGULATOR_PCAP
186 This driver provides support for the voltage regulators of the 186 This driver provides support for the voltage regulators of the
187 PCAP2 PMIC. 187 PCAP2 PMIC.
188 188
189config REGULATOR_MC13XXX_CORE
190 tristate
191
189config REGULATOR_MC13783 192config REGULATOR_MC13783
190 tristate "Support regulators on Freescale MC13783 PMIC" 193 tristate "Support regulators on Freescale MC13783 PMIC"
191 depends on MFD_MC13783 194 depends on MFD_MC13783
195 select REGULATOR_MC13XXX_CORE
192 help 196 help
193 Say y here to support the regulators found on the Freescale MC13783 197 Say y here to support the regulators found on the Freescale MC13783
194 PMIC. 198 PMIC.
195 199
200config REGULATOR_MC13892
201 tristate "Support regulators on Freescale MC13892 PMIC"
202 depends on MFD_MC13XXX
203 select REGULATOR_MC13XXX_CORE
204 help
205 Say y here to support the regulators found on the Freescale MC13892
206 PMIC.
207
196config REGULATOR_AB3100 208config REGULATOR_AB3100
197 tristate "ST-Ericsson AB3100 Regulator functions" 209 tristate "ST-Ericsson AB3100 Regulator functions"
198 depends on AB3100_CORE 210 depends on AB3100_CORE
@@ -250,5 +262,15 @@ config REGULATOR_TPS6586X
250 help 262 help
251 This driver supports TPS6586X voltage regulator chips. 263 This driver supports TPS6586X voltage regulator chips.
252 264
265config REGULATOR_TPS6524X
266 tristate "TI TPS6524X Power regulators"
267 depends on SPI
268 help
269 This driver supports TPS6524X voltage regulator chips. TPS6524X
270 provides three step-down converters and two general-purpose LDO
271 voltage regulators. This device is interfaced using a customized
272 serial interface currently supported on the sequencer serial
273 port controller.
274
253endif 275endif
254 276
diff --git a/drivers/regulator/Makefile b/drivers/regulator/Makefile
index bff815736780..0b5e88c2b8d7 100644
--- a/drivers/regulator/Makefile
+++ b/drivers/regulator/Makefile
@@ -30,10 +30,13 @@ obj-$(CONFIG_REGULATOR_DA903X) += da903x.o
30obj-$(CONFIG_REGULATOR_PCF50633) += pcf50633-regulator.o 30obj-$(CONFIG_REGULATOR_PCF50633) += pcf50633-regulator.o
31obj-$(CONFIG_REGULATOR_PCAP) += pcap-regulator.o 31obj-$(CONFIG_REGULATOR_PCAP) += pcap-regulator.o
32obj-$(CONFIG_REGULATOR_MC13783) += mc13783-regulator.o 32obj-$(CONFIG_REGULATOR_MC13783) += mc13783-regulator.o
33obj-$(CONFIG_REGULATOR_MC13892) += mc13892-regulator.o
34obj-$(CONFIG_REGULATOR_MC13XXX_CORE) += mc13xxx-regulator-core.o
33obj-$(CONFIG_REGULATOR_AB3100) += ab3100.o 35obj-$(CONFIG_REGULATOR_AB3100) += ab3100.o
34 36
35obj-$(CONFIG_REGULATOR_TPS65023) += tps65023-regulator.o 37obj-$(CONFIG_REGULATOR_TPS65023) += tps65023-regulator.o
36obj-$(CONFIG_REGULATOR_TPS6507X) += tps6507x-regulator.o 38obj-$(CONFIG_REGULATOR_TPS6507X) += tps6507x-regulator.o
39obj-$(CONFIG_REGULATOR_TPS6524X) += tps6524x-regulator.o
37obj-$(CONFIG_REGULATOR_88PM8607) += 88pm8607.o 40obj-$(CONFIG_REGULATOR_88PM8607) += 88pm8607.o
38obj-$(CONFIG_REGULATOR_ISL6271A) += isl6271a-regulator.o 41obj-$(CONFIG_REGULATOR_ISL6271A) += isl6271a-regulator.o
39obj-$(CONFIG_REGULATOR_AB8500) += ab8500.o 42obj-$(CONFIG_REGULATOR_AB8500) += ab8500.o
diff --git a/drivers/regulator/ab3100.c b/drivers/regulator/ab3100.c
index b349266a43de..ed6feaf9398d 100644
--- a/drivers/regulator/ab3100.c
+++ b/drivers/regulator/ab3100.c
@@ -362,7 +362,8 @@ static int ab3100_get_best_voltage_index(struct regulator_dev *reg,
362} 362}
363 363
364static int ab3100_set_voltage_regulator(struct regulator_dev *reg, 364static int ab3100_set_voltage_regulator(struct regulator_dev *reg,
365 int min_uV, int max_uV) 365 int min_uV, int max_uV,
366 unsigned *selector)
366{ 367{
367 struct ab3100_regulator *abreg = reg->reg_data; 368 struct ab3100_regulator *abreg = reg->reg_data;
368 u8 regval; 369 u8 regval;
@@ -373,6 +374,8 @@ static int ab3100_set_voltage_regulator(struct regulator_dev *reg,
373 if (bestindex < 0) 374 if (bestindex < 0)
374 return bestindex; 375 return bestindex;
375 376
377 *selector = bestindex;
378
376 err = abx500_get_register_interruptible(abreg->dev, 0, 379 err = abx500_get_register_interruptible(abreg->dev, 0,
377 abreg->regreg, &regval); 380 abreg->regreg, &regval);
378 if (err) { 381 if (err) {
diff --git a/drivers/regulator/ab8500.c b/drivers/regulator/ab8500.c
index db6b70f20511..d9a052c53aec 100644
--- a/drivers/regulator/ab8500.c
+++ b/drivers/regulator/ab8500.c
@@ -3,18 +3,13 @@
3 * 3 *
4 * License Terms: GNU General Public License v2 4 * License Terms: GNU General Public License v2
5 * 5 *
6 * Author: Sundar Iyer <sundar.iyer@stericsson.com> for ST-Ericsson 6 * Authors: Sundar Iyer <sundar.iyer@stericsson.com> for ST-Ericsson
7 * Bengt Jonsson <bengt.g.jonsson@stericsson.com> for ST-Ericsson
7 * 8 *
8 * AB8500 peripheral regulators 9 * AB8500 peripheral regulators
9 * 10 *
10 * AB8500 supports the following regulators, 11 * AB8500 supports the following regulators:
11 * LDOs - VAUDIO, VANAMIC2/2, VDIGMIC, VINTCORE12, VTVOUT, 12 * VAUX1/2/3, VINTCORE, VTVOUT, VAUDIO, VAMIC1/2, VDMIC, VANA
12 * VAUX1/2/3, VANA
13 *
14 * for DB8500 cut 1.0 and previous versions of the silicon, all accesses
15 * to registers are through the DB8500 SPI. In cut 1.1 onwards, these
16 * accesses are through the DB8500 PRCMU I2C
17 *
18 */ 13 */
19#include <linux/init.h> 14#include <linux/init.h>
20#include <linux/kernel.h> 15#include <linux/kernel.h>
@@ -28,38 +23,37 @@
28 23
29/** 24/**
30 * struct ab8500_regulator_info - ab8500 regulator information 25 * struct ab8500_regulator_info - ab8500 regulator information
26 * @dev: device pointer
31 * @desc: regulator description 27 * @desc: regulator description
32 * @ab8500: ab8500 parent
33 * @regulator_dev: regulator device 28 * @regulator_dev: regulator device
34 * @max_uV: maximum voltage (for variable voltage supplies) 29 * @max_uV: maximum voltage (for variable voltage supplies)
35 * @min_uV: minimum voltage (for variable voltage supplies) 30 * @min_uV: minimum voltage (for variable voltage supplies)
36 * @fixed_uV: typical voltage (for fixed voltage supplies) 31 * @fixed_uV: typical voltage (for fixed voltage supplies)
37 * @update_bank: bank to control on/off 32 * @update_bank: bank to control on/off
38 * @update_reg: register to control on/off 33 * @update_reg: register to control on/off
39 * @mask: mask to enable/disable regulator 34 * @update_mask: mask to enable/disable regulator
40 * @enable: bits to enable the regulator in normal(high power) mode 35 * @update_val_enable: bits to enable the regulator in normal (high power) mode
41 * @voltage_bank: bank to control regulator voltage 36 * @voltage_bank: bank to control regulator voltage
42 * @voltage_reg: register to control regulator voltage 37 * @voltage_reg: register to control regulator voltage
43 * @voltage_mask: mask to control regulator voltage 38 * @voltage_mask: mask to control regulator voltage
44 * @supported_voltages: supported voltage table 39 * @voltages: supported voltage table
45 * @voltages_len: number of supported voltages for the regulator 40 * @voltages_len: number of supported voltages for the regulator
46 */ 41 */
47struct ab8500_regulator_info { 42struct ab8500_regulator_info {
48 struct device *dev; 43 struct device *dev;
49 struct regulator_desc desc; 44 struct regulator_desc desc;
50 struct ab8500 *ab8500;
51 struct regulator_dev *regulator; 45 struct regulator_dev *regulator;
52 int max_uV; 46 int max_uV;
53 int min_uV; 47 int min_uV;
54 int fixed_uV; 48 int fixed_uV;
55 u8 update_bank; 49 u8 update_bank;
56 u8 update_reg; 50 u8 update_reg;
57 u8 mask; 51 u8 update_mask;
58 u8 enable; 52 u8 update_val_enable;
59 u8 voltage_bank; 53 u8 voltage_bank;
60 u8 voltage_reg; 54 u8 voltage_reg;
61 u8 voltage_mask; 55 u8 voltage_mask;
62 int const *supported_voltages; 56 int const *voltages;
63 int voltages_len; 57 int voltages_len;
64}; 58};
65 59
@@ -83,6 +77,17 @@ static const int ldo_vauxn_voltages[] = {
83 3300000, 77 3300000,
84}; 78};
85 79
80static const int ldo_vaux3_voltages[] = {
81 1200000,
82 1500000,
83 1800000,
84 2100000,
85 2500000,
86 2750000,
87 2790000,
88 2910000,
89};
90
86static const int ldo_vintcore_voltages[] = { 91static const int ldo_vintcore_voltages[] = {
87 1200000, 92 1200000,
88 1225000, 93 1225000,
@@ -95,57 +100,80 @@ static const int ldo_vintcore_voltages[] = {
95 100
96static int ab8500_regulator_enable(struct regulator_dev *rdev) 101static int ab8500_regulator_enable(struct regulator_dev *rdev)
97{ 102{
98 int regulator_id, ret; 103 int ret;
99 struct ab8500_regulator_info *info = rdev_get_drvdata(rdev); 104 struct ab8500_regulator_info *info = rdev_get_drvdata(rdev);
100 105
101 regulator_id = rdev_get_id(rdev); 106 if (info == NULL) {
102 if (regulator_id >= AB8500_NUM_REGULATORS) 107 dev_err(rdev_get_dev(rdev), "regulator info null pointer\n");
103 return -EINVAL; 108 return -EINVAL;
109 }
104 110
105 ret = abx500_mask_and_set_register_interruptible(info->dev, 111 ret = abx500_mask_and_set_register_interruptible(info->dev,
106 info->update_bank, info->update_reg, info->mask, info->enable); 112 info->update_bank, info->update_reg,
113 info->update_mask, info->update_val_enable);
107 if (ret < 0) 114 if (ret < 0)
108 dev_err(rdev_get_dev(rdev), 115 dev_err(rdev_get_dev(rdev),
109 "couldn't set enable bits for regulator\n"); 116 "couldn't set enable bits for regulator\n");
117
118 dev_vdbg(rdev_get_dev(rdev),
119 "%s-enable (bank, reg, mask, value): 0x%x, 0x%x, 0x%x, 0x%x\n",
120 info->desc.name, info->update_bank, info->update_reg,
121 info->update_mask, info->update_val_enable);
122
110 return ret; 123 return ret;
111} 124}
112 125
113static int ab8500_regulator_disable(struct regulator_dev *rdev) 126static int ab8500_regulator_disable(struct regulator_dev *rdev)
114{ 127{
115 int regulator_id, ret; 128 int ret;
116 struct ab8500_regulator_info *info = rdev_get_drvdata(rdev); 129 struct ab8500_regulator_info *info = rdev_get_drvdata(rdev);
117 130
118 regulator_id = rdev_get_id(rdev); 131 if (info == NULL) {
119 if (regulator_id >= AB8500_NUM_REGULATORS) 132 dev_err(rdev_get_dev(rdev), "regulator info null pointer\n");
120 return -EINVAL; 133 return -EINVAL;
134 }
121 135
122 ret = abx500_mask_and_set_register_interruptible(info->dev, 136 ret = abx500_mask_and_set_register_interruptible(info->dev,
123 info->update_bank, info->update_reg, info->mask, 0x0); 137 info->update_bank, info->update_reg,
138 info->update_mask, 0x0);
124 if (ret < 0) 139 if (ret < 0)
125 dev_err(rdev_get_dev(rdev), 140 dev_err(rdev_get_dev(rdev),
126 "couldn't set disable bits for regulator\n"); 141 "couldn't set disable bits for regulator\n");
142
143 dev_vdbg(rdev_get_dev(rdev),
144 "%s-disable (bank, reg, mask, value): 0x%x, 0x%x, 0x%x, 0x%x\n",
145 info->desc.name, info->update_bank, info->update_reg,
146 info->update_mask, 0x0);
147
127 return ret; 148 return ret;
128} 149}
129 150
130static int ab8500_regulator_is_enabled(struct regulator_dev *rdev) 151static int ab8500_regulator_is_enabled(struct regulator_dev *rdev)
131{ 152{
132 int regulator_id, ret; 153 int ret;
133 struct ab8500_regulator_info *info = rdev_get_drvdata(rdev); 154 struct ab8500_regulator_info *info = rdev_get_drvdata(rdev);
134 u8 value; 155 u8 regval;
135 156
136 regulator_id = rdev_get_id(rdev); 157 if (info == NULL) {
137 if (regulator_id >= AB8500_NUM_REGULATORS) 158 dev_err(rdev_get_dev(rdev), "regulator info null pointer\n");
138 return -EINVAL; 159 return -EINVAL;
160 }
139 161
140 ret = abx500_get_register_interruptible(info->dev, 162 ret = abx500_get_register_interruptible(info->dev,
141 info->update_bank, info->update_reg, &value); 163 info->update_bank, info->update_reg, &regval);
142 if (ret < 0) { 164 if (ret < 0) {
143 dev_err(rdev_get_dev(rdev), 165 dev_err(rdev_get_dev(rdev),
144 "couldn't read 0x%x register\n", info->update_reg); 166 "couldn't read 0x%x register\n", info->update_reg);
145 return ret; 167 return ret;
146 } 168 }
147 169
148 if (value & info->mask) 170 dev_vdbg(rdev_get_dev(rdev),
171 "%s-is_enabled (bank, reg, mask, value): 0x%x, 0x%x, 0x%x,"
172 " 0x%x\n",
173 info->desc.name, info->update_bank, info->update_reg,
174 info->update_mask, regval);
175
176 if (regval & info->update_mask)
149 return true; 177 return true;
150 else 178 else
151 return false; 179 return false;
@@ -153,12 +181,12 @@ static int ab8500_regulator_is_enabled(struct regulator_dev *rdev)
153 181
154static int ab8500_list_voltage(struct regulator_dev *rdev, unsigned selector) 182static int ab8500_list_voltage(struct regulator_dev *rdev, unsigned selector)
155{ 183{
156 int regulator_id;
157 struct ab8500_regulator_info *info = rdev_get_drvdata(rdev); 184 struct ab8500_regulator_info *info = rdev_get_drvdata(rdev);
158 185
159 regulator_id = rdev_get_id(rdev); 186 if (info == NULL) {
160 if (regulator_id >= AB8500_NUM_REGULATORS) 187 dev_err(rdev_get_dev(rdev), "regulator info null pointer\n");
161 return -EINVAL; 188 return -EINVAL;
189 }
162 190
163 /* return the uV for the fixed regulators */ 191 /* return the uV for the fixed regulators */
164 if (info->fixed_uV) 192 if (info->fixed_uV)
@@ -167,33 +195,40 @@ static int ab8500_list_voltage(struct regulator_dev *rdev, unsigned selector)
167 if (selector >= info->voltages_len) 195 if (selector >= info->voltages_len)
168 return -EINVAL; 196 return -EINVAL;
169 197
170 return info->supported_voltages[selector]; 198 return info->voltages[selector];
171} 199}
172 200
173static int ab8500_regulator_get_voltage(struct regulator_dev *rdev) 201static int ab8500_regulator_get_voltage(struct regulator_dev *rdev)
174{ 202{
175 int regulator_id, ret; 203 int ret, val;
176 struct ab8500_regulator_info *info = rdev_get_drvdata(rdev); 204 struct ab8500_regulator_info *info = rdev_get_drvdata(rdev);
177 u8 value; 205 u8 regval;
178 206
179 regulator_id = rdev_get_id(rdev); 207 if (info == NULL) {
180 if (regulator_id >= AB8500_NUM_REGULATORS) 208 dev_err(rdev_get_dev(rdev), "regulator info null pointer\n");
181 return -EINVAL; 209 return -EINVAL;
210 }
182 211
183 ret = abx500_get_register_interruptible(info->dev, info->voltage_bank, 212 ret = abx500_get_register_interruptible(info->dev,
184 info->voltage_reg, &value); 213 info->voltage_bank, info->voltage_reg, &regval);
185 if (ret < 0) { 214 if (ret < 0) {
186 dev_err(rdev_get_dev(rdev), 215 dev_err(rdev_get_dev(rdev),
187 "couldn't read voltage reg for regulator\n"); 216 "couldn't read voltage reg for regulator\n");
188 return ret; 217 return ret;
189 } 218 }
190 219
220 dev_vdbg(rdev_get_dev(rdev),
221 "%s-get_voltage (bank, reg, mask, value): 0x%x, 0x%x, 0x%x,"
222 " 0x%x\n",
223 info->desc.name, info->voltage_bank, info->voltage_reg,
224 info->voltage_mask, regval);
225
191 /* vintcore has a different layout */ 226 /* vintcore has a different layout */
192 value &= info->voltage_mask; 227 val = regval & info->voltage_mask;
193 if (regulator_id == AB8500_LDO_INTCORE) 228 if (info->desc.id == AB8500_LDO_INTCORE)
194 ret = info->supported_voltages[value >> 0x3]; 229 ret = info->voltages[val >> 0x3];
195 else 230 else
196 ret = info->supported_voltages[value]; 231 ret = info->voltages[val];
197 232
198 return ret; 233 return ret;
199} 234}
@@ -206,8 +241,8 @@ static int ab8500_get_best_voltage_index(struct regulator_dev *rdev,
206 241
207 /* check the supported voltage */ 242 /* check the supported voltage */
208 for (i = 0; i < info->voltages_len; i++) { 243 for (i = 0; i < info->voltages_len; i++) {
209 if ((info->supported_voltages[i] >= min_uV) && 244 if ((info->voltages[i] >= min_uV) &&
210 (info->supported_voltages[i] <= max_uV)) 245 (info->voltages[i] <= max_uV))
211 return i; 246 return i;
212 } 247 }
213 248
@@ -215,14 +250,17 @@ static int ab8500_get_best_voltage_index(struct regulator_dev *rdev,
215} 250}
216 251
217static int ab8500_regulator_set_voltage(struct regulator_dev *rdev, 252static int ab8500_regulator_set_voltage(struct regulator_dev *rdev,
218 int min_uV, int max_uV) 253 int min_uV, int max_uV,
254 unsigned *selector)
219{ 255{
220 int regulator_id, ret; 256 int ret;
221 struct ab8500_regulator_info *info = rdev_get_drvdata(rdev); 257 struct ab8500_regulator_info *info = rdev_get_drvdata(rdev);
258 u8 regval;
222 259
223 regulator_id = rdev_get_id(rdev); 260 if (info == NULL) {
224 if (regulator_id >= AB8500_NUM_REGULATORS) 261 dev_err(rdev_get_dev(rdev), "regulator info null pointer\n");
225 return -EINVAL; 262 return -EINVAL;
263 }
226 264
227 /* get the appropriate voltages within the range */ 265 /* get the appropriate voltages within the range */
228 ret = ab8500_get_best_voltage_index(rdev, min_uV, max_uV); 266 ret = ab8500_get_best_voltage_index(rdev, min_uV, max_uV);
@@ -232,14 +270,23 @@ static int ab8500_regulator_set_voltage(struct regulator_dev *rdev,
232 return ret; 270 return ret;
233 } 271 }
234 272
273 *selector = ret;
274
235 /* set the registers for the request */ 275 /* set the registers for the request */
276 regval = (u8)ret;
236 ret = abx500_mask_and_set_register_interruptible(info->dev, 277 ret = abx500_mask_and_set_register_interruptible(info->dev,
237 info->voltage_bank, info->voltage_reg, 278 info->voltage_bank, info->voltage_reg,
238 info->voltage_mask, (u8)ret); 279 info->voltage_mask, regval);
239 if (ret < 0) 280 if (ret < 0)
240 dev_err(rdev_get_dev(rdev), 281 dev_err(rdev_get_dev(rdev),
241 "couldn't set voltage reg for regulator\n"); 282 "couldn't set voltage reg for regulator\n");
242 283
284 dev_vdbg(rdev_get_dev(rdev),
285 "%s-set_voltage (bank, reg, mask, value): 0x%x, 0x%x, 0x%x,"
286 " 0x%x\n",
287 info->desc.name, info->voltage_bank, info->voltage_reg,
288 info->voltage_mask, regval);
289
243 return ret; 290 return ret;
244} 291}
245 292
@@ -254,17 +301,17 @@ static struct regulator_ops ab8500_regulator_ops = {
254 301
255static int ab8500_fixed_get_voltage(struct regulator_dev *rdev) 302static int ab8500_fixed_get_voltage(struct regulator_dev *rdev)
256{ 303{
257 int regulator_id;
258 struct ab8500_regulator_info *info = rdev_get_drvdata(rdev); 304 struct ab8500_regulator_info *info = rdev_get_drvdata(rdev);
259 305
260 regulator_id = rdev_get_id(rdev); 306 if (info == NULL) {
261 if (regulator_id >= AB8500_NUM_REGULATORS) 307 dev_err(rdev_get_dev(rdev), "regulator info null pointer\n");
262 return -EINVAL; 308 return -EINVAL;
309 }
263 310
264 return info->fixed_uV; 311 return info->fixed_uV;
265} 312}
266 313
267static struct regulator_ops ab8500_ldo_fixed_ops = { 314static struct regulator_ops ab8500_regulator_fixed_ops = {
268 .enable = ab8500_regulator_enable, 315 .enable = ab8500_regulator_enable,
269 .disable = ab8500_regulator_disable, 316 .disable = ab8500_regulator_disable,
270 .is_enabled = ab8500_regulator_is_enabled, 317 .is_enabled = ab8500_regulator_is_enabled,
@@ -272,88 +319,197 @@ static struct regulator_ops ab8500_ldo_fixed_ops = {
272 .list_voltage = ab8500_list_voltage, 319 .list_voltage = ab8500_list_voltage,
273}; 320};
274 321
275#define AB8500_LDO(_id, min, max, bank, reg, reg_mask, \ 322static struct ab8500_regulator_info
276 reg_enable, volt_bank, volt_reg, volt_mask, \ 323 ab8500_regulator_info[AB8500_NUM_REGULATORS] = {
277 voltages, len_volts) \
278{ \
279 .desc = { \
280 .name = "LDO-" #_id, \
281 .ops = &ab8500_regulator_ops, \
282 .type = REGULATOR_VOLTAGE, \
283 .id = AB8500_LDO_##_id, \
284 .owner = THIS_MODULE, \
285 }, \
286 .min_uV = (min) * 1000, \
287 .max_uV = (max) * 1000, \
288 .update_bank = bank, \
289 .update_reg = reg, \
290 .mask = reg_mask, \
291 .enable = reg_enable, \
292 .voltage_bank = volt_bank, \
293 .voltage_reg = volt_reg, \
294 .voltage_mask = volt_mask, \
295 .supported_voltages = voltages, \
296 .voltages_len = len_volts, \
297 .fixed_uV = 0, \
298}
299
300#define AB8500_FIXED_LDO(_id, fixed, bank, reg, \
301 reg_mask, reg_enable) \
302{ \
303 .desc = { \
304 .name = "LDO-" #_id, \
305 .ops = &ab8500_ldo_fixed_ops, \
306 .type = REGULATOR_VOLTAGE, \
307 .id = AB8500_LDO_##_id, \
308 .owner = THIS_MODULE, \
309 }, \
310 .fixed_uV = fixed * 1000, \
311 .update_bank = bank, \
312 .update_reg = reg, \
313 .mask = reg_mask, \
314 .enable = reg_enable, \
315}
316
317static struct ab8500_regulator_info ab8500_regulator_info[] = {
318 /* 324 /*
319 * Variable Voltage LDOs 325 * Variable Voltage Regulators
320 * name, min uV, max uV, ctrl bank, ctrl reg, reg mask, enable mask, 326 * name, min mV, max mV,
321 * volt ctrl bank, volt ctrl reg, volt ctrl mask, volt table, 327 * update bank, reg, mask, enable val
322 * num supported volts 328 * volt bank, reg, mask, table, table length
323 */ 329 */
324 AB8500_LDO(AUX1, 1100, 3300, 0x04, 0x09, 0x3, 0x1, 0x04, 0x1f, 0xf, 330 [AB8500_LDO_AUX1] = {
325 ldo_vauxn_voltages, ARRAY_SIZE(ldo_vauxn_voltages)), 331 .desc = {
326 AB8500_LDO(AUX2, 1100, 3300, 0x04, 0x09, 0xc, 0x4, 0x04, 0x20, 0xf, 332 .name = "LDO-AUX1",
327 ldo_vauxn_voltages, ARRAY_SIZE(ldo_vauxn_voltages)), 333 .ops = &ab8500_regulator_ops,
328 AB8500_LDO(AUX3, 1100, 3300, 0x04, 0x0a, 0x3, 0x1, 0x04, 0x21, 0xf, 334 .type = REGULATOR_VOLTAGE,
329 ldo_vauxn_voltages, ARRAY_SIZE(ldo_vauxn_voltages)), 335 .id = AB8500_LDO_AUX1,
330 AB8500_LDO(INTCORE, 1100, 3300, 0x03, 0x80, 0x4, 0x4, 0x03, 0x80, 0x38, 336 .owner = THIS_MODULE,
331 ldo_vintcore_voltages, ARRAY_SIZE(ldo_vintcore_voltages)), 337 .n_voltages = ARRAY_SIZE(ldo_vauxn_voltages),
338 },
339 .min_uV = 1100000,
340 .max_uV = 3300000,
341 .update_bank = 0x04,
342 .update_reg = 0x09,
343 .update_mask = 0x03,
344 .update_val_enable = 0x01,
345 .voltage_bank = 0x04,
346 .voltage_reg = 0x1f,
347 .voltage_mask = 0x0f,
348 .voltages = ldo_vauxn_voltages,
349 .voltages_len = ARRAY_SIZE(ldo_vauxn_voltages),
350 },
351 [AB8500_LDO_AUX2] = {
352 .desc = {
353 .name = "LDO-AUX2",
354 .ops = &ab8500_regulator_ops,
355 .type = REGULATOR_VOLTAGE,
356 .id = AB8500_LDO_AUX2,
357 .owner = THIS_MODULE,
358 .n_voltages = ARRAY_SIZE(ldo_vauxn_voltages),
359 },
360 .min_uV = 1100000,
361 .max_uV = 3300000,
362 .update_bank = 0x04,
363 .update_reg = 0x09,
364 .update_mask = 0x0c,
365 .update_val_enable = 0x04,
366 .voltage_bank = 0x04,
367 .voltage_reg = 0x20,
368 .voltage_mask = 0x0f,
369 .voltages = ldo_vauxn_voltages,
370 .voltages_len = ARRAY_SIZE(ldo_vauxn_voltages),
371 },
372 [AB8500_LDO_AUX3] = {
373 .desc = {
374 .name = "LDO-AUX3",
375 .ops = &ab8500_regulator_ops,
376 .type = REGULATOR_VOLTAGE,
377 .id = AB8500_LDO_AUX3,
378 .owner = THIS_MODULE,
379 .n_voltages = ARRAY_SIZE(ldo_vaux3_voltages),
380 },
381 .min_uV = 1100000,
382 .max_uV = 3300000,
383 .update_bank = 0x04,
384 .update_reg = 0x0a,
385 .update_mask = 0x03,
386 .update_val_enable = 0x01,
387 .voltage_bank = 0x04,
388 .voltage_reg = 0x21,
389 .voltage_mask = 0x07,
390 .voltages = ldo_vaux3_voltages,
391 .voltages_len = ARRAY_SIZE(ldo_vaux3_voltages),
392 },
393 [AB8500_LDO_INTCORE] = {
394 .desc = {
395 .name = "LDO-INTCORE",
396 .ops = &ab8500_regulator_ops,
397 .type = REGULATOR_VOLTAGE,
398 .id = AB8500_LDO_INTCORE,
399 .owner = THIS_MODULE,
400 .n_voltages = ARRAY_SIZE(ldo_vintcore_voltages),
401 },
402 .min_uV = 1100000,
403 .max_uV = 3300000,
404 .update_bank = 0x03,
405 .update_reg = 0x80,
406 .update_mask = 0x44,
407 .update_val_enable = 0x04,
408 .voltage_bank = 0x03,
409 .voltage_reg = 0x80,
410 .voltage_mask = 0x38,
411 .voltages = ldo_vintcore_voltages,
412 .voltages_len = ARRAY_SIZE(ldo_vintcore_voltages),
413 },
332 414
333 /* 415 /*
334 * Fixed Voltage LDOs 416 * Fixed Voltage Regulators
335 * name, o/p uV, ctrl bank, ctrl reg, enable, disable 417 * name, fixed mV,
418 * update bank, reg, mask, enable val
336 */ 419 */
337 AB8500_FIXED_LDO(TVOUT, 2000, 0x03, 0x80, 0x2, 0x2), 420 [AB8500_LDO_TVOUT] = {
338 AB8500_FIXED_LDO(AUDIO, 2000, 0x03, 0x83, 0x2, 0x2), 421 .desc = {
339 AB8500_FIXED_LDO(ANAMIC1, 2050, 0x03, 0x83, 0x4, 0x4), 422 .name = "LDO-TVOUT",
340 AB8500_FIXED_LDO(ANAMIC2, 2050, 0x03, 0x83, 0x8, 0x8), 423 .ops = &ab8500_regulator_fixed_ops,
341 AB8500_FIXED_LDO(DMIC, 1800, 0x03, 0x83, 0x10, 0x10), 424 .type = REGULATOR_VOLTAGE,
342 AB8500_FIXED_LDO(ANA, 1200, 0x03, 0x83, 0xc, 0x4), 425 .id = AB8500_LDO_TVOUT,
343}; 426 .owner = THIS_MODULE,
427 .n_voltages = 1,
428 },
429 .fixed_uV = 2000000,
430 .update_bank = 0x03,
431 .update_reg = 0x80,
432 .update_mask = 0x82,
433 .update_val_enable = 0x02,
434 },
435 [AB8500_LDO_AUDIO] = {
436 .desc = {
437 .name = "LDO-AUDIO",
438 .ops = &ab8500_regulator_fixed_ops,
439 .type = REGULATOR_VOLTAGE,
440 .id = AB8500_LDO_AUDIO,
441 .owner = THIS_MODULE,
442 .n_voltages = 1,
443 },
444 .fixed_uV = 2000000,
445 .update_bank = 0x03,
446 .update_reg = 0x83,
447 .update_mask = 0x02,
448 .update_val_enable = 0x02,
449 },
450 [AB8500_LDO_ANAMIC1] = {
451 .desc = {
452 .name = "LDO-ANAMIC1",
453 .ops = &ab8500_regulator_fixed_ops,
454 .type = REGULATOR_VOLTAGE,
455 .id = AB8500_LDO_ANAMIC1,
456 .owner = THIS_MODULE,
457 .n_voltages = 1,
458 },
459 .fixed_uV = 2050000,
460 .update_bank = 0x03,
461 .update_reg = 0x83,
462 .update_mask = 0x08,
463 .update_val_enable = 0x08,
464 },
465 [AB8500_LDO_ANAMIC2] = {
466 .desc = {
467 .name = "LDO-ANAMIC2",
468 .ops = &ab8500_regulator_fixed_ops,
469 .type = REGULATOR_VOLTAGE,
470 .id = AB8500_LDO_ANAMIC2,
471 .owner = THIS_MODULE,
472 .n_voltages = 1,
473 },
474 .fixed_uV = 2050000,
475 .update_bank = 0x03,
476 .update_reg = 0x83,
477 .update_mask = 0x10,
478 .update_val_enable = 0x10,
479 },
480 [AB8500_LDO_DMIC] = {
481 .desc = {
482 .name = "LDO-DMIC",
483 .ops = &ab8500_regulator_fixed_ops,
484 .type = REGULATOR_VOLTAGE,
485 .id = AB8500_LDO_DMIC,
486 .owner = THIS_MODULE,
487 .n_voltages = 1,
488 },
489 .fixed_uV = 1800000,
490 .update_bank = 0x03,
491 .update_reg = 0x83,
492 .update_mask = 0x04,
493 .update_val_enable = 0x04,
494 },
495 [AB8500_LDO_ANA] = {
496 .desc = {
497 .name = "LDO-ANA",
498 .ops = &ab8500_regulator_fixed_ops,
499 .type = REGULATOR_VOLTAGE,
500 .id = AB8500_LDO_ANA,
501 .owner = THIS_MODULE,
502 .n_voltages = 1,
503 },
504 .fixed_uV = 1200000,
505 .update_bank = 0x04,
506 .update_reg = 0x06,
507 .update_mask = 0x0c,
508 .update_val_enable = 0x04,
509 },
344 510
345static inline struct ab8500_regulator_info *find_regulator_info(int id)
346{
347 struct ab8500_regulator_info *info;
348 int i;
349 511
350 for (i = 0; i < ARRAY_SIZE(ab8500_regulator_info); i++) { 512};
351 info = &ab8500_regulator_info[i];
352 if (info->desc.id == id)
353 return info;
354 }
355 return NULL;
356}
357 513
358static __devinit int ab8500_regulator_probe(struct platform_device *pdev) 514static __devinit int ab8500_regulator_probe(struct platform_device *pdev)
359{ 515{
@@ -366,6 +522,16 @@ static __devinit int ab8500_regulator_probe(struct platform_device *pdev)
366 return -EINVAL; 522 return -EINVAL;
367 } 523 }
368 pdata = dev_get_platdata(ab8500->dev); 524 pdata = dev_get_platdata(ab8500->dev);
525 if (!pdata) {
526 dev_err(&pdev->dev, "null pdata\n");
527 return -EINVAL;
528 }
529
530 /* make sure the platform data has the correct size */
531 if (pdata->num_regulator != ARRAY_SIZE(ab8500_regulator_info)) {
532 dev_err(&pdev->dev, "platform configuration error\n");
533 return -EINVAL;
534 }
369 535
370 /* register all regulators */ 536 /* register all regulators */
371 for (i = 0; i < ARRAY_SIZE(ab8500_regulator_info); i++) { 537 for (i = 0; i < ARRAY_SIZE(ab8500_regulator_info); i++) {
@@ -374,10 +540,22 @@ static __devinit int ab8500_regulator_probe(struct platform_device *pdev)
374 /* assign per-regulator data */ 540 /* assign per-regulator data */
375 info = &ab8500_regulator_info[i]; 541 info = &ab8500_regulator_info[i];
376 info->dev = &pdev->dev; 542 info->dev = &pdev->dev;
377 info->ab8500 = ab8500;
378 543
544 /* fix for hardware before ab8500v2.0 */
545 if (abx500_get_chip_id(info->dev) < 0x20) {
546 if (info->desc.id == AB8500_LDO_AUX3) {
547 info->desc.n_voltages =
548 ARRAY_SIZE(ldo_vauxn_voltages);
549 info->voltages = ldo_vauxn_voltages;
550 info->voltages_len =
551 ARRAY_SIZE(ldo_vauxn_voltages);
552 info->voltage_mask = 0xf;
553 }
554 }
555
556 /* register regulator with framework */
379 info->regulator = regulator_register(&info->desc, &pdev->dev, 557 info->regulator = regulator_register(&info->desc, &pdev->dev,
380 pdata->regulator[i], info); 558 &pdata->regulator[i], info);
381 if (IS_ERR(info->regulator)) { 559 if (IS_ERR(info->regulator)) {
382 err = PTR_ERR(info->regulator); 560 err = PTR_ERR(info->regulator);
383 dev_err(&pdev->dev, "failed to register regulator %s\n", 561 dev_err(&pdev->dev, "failed to register regulator %s\n",
@@ -389,6 +567,9 @@ static __devinit int ab8500_regulator_probe(struct platform_device *pdev)
389 } 567 }
390 return err; 568 return err;
391 } 569 }
570
571 dev_vdbg(rdev_get_dev(info->regulator),
572 "%s-probed\n", info->desc.name);
392 } 573 }
393 574
394 return 0; 575 return 0;
@@ -401,6 +582,10 @@ static __devexit int ab8500_regulator_remove(struct platform_device *pdev)
401 for (i = 0; i < ARRAY_SIZE(ab8500_regulator_info); i++) { 582 for (i = 0; i < ARRAY_SIZE(ab8500_regulator_info); i++) {
402 struct ab8500_regulator_info *info = NULL; 583 struct ab8500_regulator_info *info = NULL;
403 info = &ab8500_regulator_info[i]; 584 info = &ab8500_regulator_info[i];
585
586 dev_vdbg(rdev_get_dev(info->regulator),
587 "%s-remove\n", info->desc.name);
588
404 regulator_unregister(info->regulator); 589 regulator_unregister(info->regulator);
405 } 590 }
406 591
diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
index ba521f0f0fac..9fa20957847d 100644
--- a/drivers/regulator/core.c
+++ b/drivers/regulator/core.c
@@ -13,8 +13,11 @@
13 * 13 *
14 */ 14 */
15 15
16#define pr_fmt(fmt) "%s: " fmt, __func__
17
16#include <linux/kernel.h> 18#include <linux/kernel.h>
17#include <linux/init.h> 19#include <linux/init.h>
20#include <linux/debugfs.h>
18#include <linux/device.h> 21#include <linux/device.h>
19#include <linux/slab.h> 22#include <linux/slab.h>
20#include <linux/err.h> 23#include <linux/err.h>
@@ -25,16 +28,30 @@
25#include <linux/regulator/driver.h> 28#include <linux/regulator/driver.h>
26#include <linux/regulator/machine.h> 29#include <linux/regulator/machine.h>
27 30
31#define CREATE_TRACE_POINTS
32#include <trace/events/regulator.h>
33
28#include "dummy.h" 34#include "dummy.h"
29 35
30#define REGULATOR_VERSION "0.5" 36#define rdev_err(rdev, fmt, ...) \
37 pr_err("%s: " fmt, rdev_get_name(rdev), ##__VA_ARGS__)
38#define rdev_warn(rdev, fmt, ...) \
39 pr_warn("%s: " fmt, rdev_get_name(rdev), ##__VA_ARGS__)
40#define rdev_info(rdev, fmt, ...) \
41 pr_info("%s: " fmt, rdev_get_name(rdev), ##__VA_ARGS__)
42#define rdev_dbg(rdev, fmt, ...) \
43 pr_debug("%s: " fmt, rdev_get_name(rdev), ##__VA_ARGS__)
31 44
32static DEFINE_MUTEX(regulator_list_mutex); 45static DEFINE_MUTEX(regulator_list_mutex);
33static LIST_HEAD(regulator_list); 46static LIST_HEAD(regulator_list);
34static LIST_HEAD(regulator_map_list); 47static LIST_HEAD(regulator_map_list);
35static int has_full_constraints; 48static bool has_full_constraints;
36static bool board_wants_dummy_regulator; 49static bool board_wants_dummy_regulator;
37 50
51#ifdef CONFIG_DEBUG_FS
52static struct dentry *debugfs_root;
53#endif
54
38/* 55/*
39 * struct regulator_map 56 * struct regulator_map
40 * 57 *
@@ -71,6 +88,8 @@ static int _regulator_get_current_limit(struct regulator_dev *rdev);
71static unsigned int _regulator_get_mode(struct regulator_dev *rdev); 88static unsigned int _regulator_get_mode(struct regulator_dev *rdev);
72static void _notifier_call_chain(struct regulator_dev *rdev, 89static void _notifier_call_chain(struct regulator_dev *rdev,
73 unsigned long event, void *data); 90 unsigned long event, void *data);
91static int _regulator_do_set_voltage(struct regulator_dev *rdev,
92 int min_uV, int max_uV);
74 93
75static const char *rdev_get_name(struct regulator_dev *rdev) 94static const char *rdev_get_name(struct regulator_dev *rdev)
76{ 95{
@@ -111,13 +130,11 @@ static int regulator_check_voltage(struct regulator_dev *rdev,
111 BUG_ON(*min_uV > *max_uV); 130 BUG_ON(*min_uV > *max_uV);
112 131
113 if (!rdev->constraints) { 132 if (!rdev->constraints) {
114 printk(KERN_ERR "%s: no constraints for %s\n", __func__, 133 rdev_err(rdev, "no constraints\n");
115 rdev_get_name(rdev));
116 return -ENODEV; 134 return -ENODEV;
117 } 135 }
118 if (!(rdev->constraints->valid_ops_mask & REGULATOR_CHANGE_VOLTAGE)) { 136 if (!(rdev->constraints->valid_ops_mask & REGULATOR_CHANGE_VOLTAGE)) {
119 printk(KERN_ERR "%s: operation not allowed for %s\n", 137 rdev_err(rdev, "operation not allowed\n");
120 __func__, rdev_get_name(rdev));
121 return -EPERM; 138 return -EPERM;
122 } 139 }
123 140
@@ -132,6 +149,27 @@ static int regulator_check_voltage(struct regulator_dev *rdev,
132 return 0; 149 return 0;
133} 150}
134 151
152/* Make sure we select a voltage that suits the needs of all
153 * regulator consumers
154 */
155static int regulator_check_consumers(struct regulator_dev *rdev,
156 int *min_uV, int *max_uV)
157{
158 struct regulator *regulator;
159
160 list_for_each_entry(regulator, &rdev->consumer_list, list) {
161 if (*max_uV > regulator->max_uV)
162 *max_uV = regulator->max_uV;
163 if (*min_uV < regulator->min_uV)
164 *min_uV = regulator->min_uV;
165 }
166
167 if (*min_uV > *max_uV)
168 return -EINVAL;
169
170 return 0;
171}
172
135/* current constraint check */ 173/* current constraint check */
136static int regulator_check_current_limit(struct regulator_dev *rdev, 174static int regulator_check_current_limit(struct regulator_dev *rdev,
137 int *min_uA, int *max_uA) 175 int *min_uA, int *max_uA)
@@ -139,13 +177,11 @@ static int regulator_check_current_limit(struct regulator_dev *rdev,
139 BUG_ON(*min_uA > *max_uA); 177 BUG_ON(*min_uA > *max_uA);
140 178
141 if (!rdev->constraints) { 179 if (!rdev->constraints) {
142 printk(KERN_ERR "%s: no constraints for %s\n", __func__, 180 rdev_err(rdev, "no constraints\n");
143 rdev_get_name(rdev));
144 return -ENODEV; 181 return -ENODEV;
145 } 182 }
146 if (!(rdev->constraints->valid_ops_mask & REGULATOR_CHANGE_CURRENT)) { 183 if (!(rdev->constraints->valid_ops_mask & REGULATOR_CHANGE_CURRENT)) {
147 printk(KERN_ERR "%s: operation not allowed for %s\n", 184 rdev_err(rdev, "operation not allowed\n");
148 __func__, rdev_get_name(rdev));
149 return -EPERM; 185 return -EPERM;
150 } 186 }
151 187
@@ -174,18 +210,15 @@ static int regulator_check_mode(struct regulator_dev *rdev, int mode)
174 } 210 }
175 211
176 if (!rdev->constraints) { 212 if (!rdev->constraints) {
177 printk(KERN_ERR "%s: no constraints for %s\n", __func__, 213 rdev_err(rdev, "no constraints\n");
178 rdev_get_name(rdev));
179 return -ENODEV; 214 return -ENODEV;
180 } 215 }
181 if (!(rdev->constraints->valid_ops_mask & REGULATOR_CHANGE_MODE)) { 216 if (!(rdev->constraints->valid_ops_mask & REGULATOR_CHANGE_MODE)) {
182 printk(KERN_ERR "%s: operation not allowed for %s\n", 217 rdev_err(rdev, "operation not allowed\n");
183 __func__, rdev_get_name(rdev));
184 return -EPERM; 218 return -EPERM;
185 } 219 }
186 if (!(rdev->constraints->valid_modes_mask & mode)) { 220 if (!(rdev->constraints->valid_modes_mask & mode)) {
187 printk(KERN_ERR "%s: invalid mode %x for %s\n", 221 rdev_err(rdev, "invalid mode %x\n", mode);
188 __func__, mode, rdev_get_name(rdev));
189 return -EINVAL; 222 return -EINVAL;
190 } 223 }
191 return 0; 224 return 0;
@@ -195,13 +228,11 @@ static int regulator_check_mode(struct regulator_dev *rdev, int mode)
195static int regulator_check_drms(struct regulator_dev *rdev) 228static int regulator_check_drms(struct regulator_dev *rdev)
196{ 229{
197 if (!rdev->constraints) { 230 if (!rdev->constraints) {
198 printk(KERN_ERR "%s: no constraints for %s\n", __func__, 231 rdev_err(rdev, "no constraints\n");
199 rdev_get_name(rdev));
200 return -ENODEV; 232 return -ENODEV;
201 } 233 }
202 if (!(rdev->constraints->valid_ops_mask & REGULATOR_CHANGE_DRMS)) { 234 if (!(rdev->constraints->valid_ops_mask & REGULATOR_CHANGE_DRMS)) {
203 printk(KERN_ERR "%s: operation not allowed for %s\n", 235 rdev_err(rdev, "operation not allowed\n");
204 __func__, rdev_get_name(rdev));
205 return -EPERM; 236 return -EPERM;
206 } 237 }
207 return 0; 238 return 0;
@@ -553,18 +584,21 @@ static void drms_uA_update(struct regulator_dev *rdev)
553 584
554 err = regulator_check_drms(rdev); 585 err = regulator_check_drms(rdev);
555 if (err < 0 || !rdev->desc->ops->get_optimum_mode || 586 if (err < 0 || !rdev->desc->ops->get_optimum_mode ||
556 !rdev->desc->ops->get_voltage || !rdev->desc->ops->set_mode) 587 (!rdev->desc->ops->get_voltage &&
588 !rdev->desc->ops->get_voltage_sel) ||
589 !rdev->desc->ops->set_mode)
557 return; 590 return;
558 591
559 /* get output voltage */ 592 /* get output voltage */
560 output_uV = rdev->desc->ops->get_voltage(rdev); 593 output_uV = _regulator_get_voltage(rdev);
561 if (output_uV <= 0) 594 if (output_uV <= 0)
562 return; 595 return;
563 596
564 /* get input voltage */ 597 /* get input voltage */
565 if (rdev->supply && rdev->supply->desc->ops->get_voltage) 598 input_uV = 0;
566 input_uV = rdev->supply->desc->ops->get_voltage(rdev->supply); 599 if (rdev->supply)
567 else 600 input_uV = _regulator_get_voltage(rdev);
601 if (input_uV <= 0)
568 input_uV = rdev->constraints->input_uV; 602 input_uV = rdev->constraints->input_uV;
569 if (input_uV <= 0) 603 if (input_uV <= 0)
570 return; 604 return;
@@ -598,20 +632,17 @@ static int suspend_set_state(struct regulator_dev *rdev,
598 */ 632 */
599 if (!rstate->enabled && !rstate->disabled) { 633 if (!rstate->enabled && !rstate->disabled) {
600 if (can_set_state) 634 if (can_set_state)
601 printk(KERN_WARNING "%s: No configuration for %s\n", 635 rdev_warn(rdev, "No configuration\n");
602 __func__, rdev_get_name(rdev));
603 return 0; 636 return 0;
604 } 637 }
605 638
606 if (rstate->enabled && rstate->disabled) { 639 if (rstate->enabled && rstate->disabled) {
607 printk(KERN_ERR "%s: invalid configuration for %s\n", 640 rdev_err(rdev, "invalid configuration\n");
608 __func__, rdev_get_name(rdev));
609 return -EINVAL; 641 return -EINVAL;
610 } 642 }
611 643
612 if (!can_set_state) { 644 if (!can_set_state) {
613 printk(KERN_ERR "%s: no way to set suspend state\n", 645 rdev_err(rdev, "no way to set suspend state\n");
614 __func__);
615 return -EINVAL; 646 return -EINVAL;
616 } 647 }
617 648
@@ -620,15 +651,14 @@ static int suspend_set_state(struct regulator_dev *rdev,
620 else 651 else
621 ret = rdev->desc->ops->set_suspend_disable(rdev); 652 ret = rdev->desc->ops->set_suspend_disable(rdev);
622 if (ret < 0) { 653 if (ret < 0) {
623 printk(KERN_ERR "%s: failed to enabled/disable\n", __func__); 654 rdev_err(rdev, "failed to enabled/disable\n");
624 return ret; 655 return ret;
625 } 656 }
626 657
627 if (rdev->desc->ops->set_suspend_voltage && rstate->uV > 0) { 658 if (rdev->desc->ops->set_suspend_voltage && rstate->uV > 0) {
628 ret = rdev->desc->ops->set_suspend_voltage(rdev, rstate->uV); 659 ret = rdev->desc->ops->set_suspend_voltage(rdev, rstate->uV);
629 if (ret < 0) { 660 if (ret < 0) {
630 printk(KERN_ERR "%s: failed to set voltage\n", 661 rdev_err(rdev, "failed to set voltage\n");
631 __func__);
632 return ret; 662 return ret;
633 } 663 }
634 } 664 }
@@ -636,7 +666,7 @@ static int suspend_set_state(struct regulator_dev *rdev,
636 if (rdev->desc->ops->set_suspend_mode && rstate->mode > 0) { 666 if (rdev->desc->ops->set_suspend_mode && rstate->mode > 0) {
637 ret = rdev->desc->ops->set_suspend_mode(rdev, rstate->mode); 667 ret = rdev->desc->ops->set_suspend_mode(rdev, rstate->mode);
638 if (ret < 0) { 668 if (ret < 0) {
639 printk(KERN_ERR "%s: failed to set mode\n", __func__); 669 rdev_err(rdev, "failed to set mode\n");
640 return ret; 670 return ret;
641 } 671 }
642 } 672 }
@@ -714,29 +744,27 @@ static void print_constraints(struct regulator_dev *rdev)
714 if (constraints->valid_modes_mask & REGULATOR_MODE_STANDBY) 744 if (constraints->valid_modes_mask & REGULATOR_MODE_STANDBY)
715 count += sprintf(buf + count, "standby"); 745 count += sprintf(buf + count, "standby");
716 746
717 printk(KERN_INFO "regulator: %s: %s\n", rdev_get_name(rdev), buf); 747 rdev_info(rdev, "%s\n", buf);
718} 748}
719 749
720static int machine_constraints_voltage(struct regulator_dev *rdev, 750static int machine_constraints_voltage(struct regulator_dev *rdev,
721 struct regulation_constraints *constraints) 751 struct regulation_constraints *constraints)
722{ 752{
723 struct regulator_ops *ops = rdev->desc->ops; 753 struct regulator_ops *ops = rdev->desc->ops;
724 const char *name = rdev_get_name(rdev);
725 int ret; 754 int ret;
726 755
727 /* do we need to apply the constraint voltage */ 756 /* do we need to apply the constraint voltage */
728 if (rdev->constraints->apply_uV && 757 if (rdev->constraints->apply_uV &&
729 rdev->constraints->min_uV == rdev->constraints->max_uV && 758 rdev->constraints->min_uV == rdev->constraints->max_uV) {
730 ops->set_voltage) { 759 ret = _regulator_do_set_voltage(rdev,
731 ret = ops->set_voltage(rdev, 760 rdev->constraints->min_uV,
732 rdev->constraints->min_uV, rdev->constraints->max_uV); 761 rdev->constraints->max_uV);
733 if (ret < 0) { 762 if (ret < 0) {
734 printk(KERN_ERR "%s: failed to apply %duV constraint to %s\n", 763 rdev_err(rdev, "failed to apply %duV constraint\n",
735 __func__, 764 rdev->constraints->min_uV);
736 rdev->constraints->min_uV, name); 765 rdev->constraints = NULL;
737 rdev->constraints = NULL; 766 return ret;
738 return ret; 767 }
739 }
740 } 768 }
741 769
742 /* constrain machine-level voltage specs to fit 770 /* constrain machine-level voltage specs to fit
@@ -765,8 +793,7 @@ static int machine_constraints_voltage(struct regulator_dev *rdev,
765 793
766 /* else require explicit machine-level constraints */ 794 /* else require explicit machine-level constraints */
767 if (cmin <= 0 || cmax <= 0 || cmax < cmin) { 795 if (cmin <= 0 || cmax <= 0 || cmax < cmin) {
768 pr_err("%s: %s '%s' voltage constraints\n", 796 rdev_err(rdev, "invalid voltage constraints\n");
769 __func__, "invalid", name);
770 return -EINVAL; 797 return -EINVAL;
771 } 798 }
772 799
@@ -787,22 +814,19 @@ static int machine_constraints_voltage(struct regulator_dev *rdev,
787 814
788 /* final: [min_uV..max_uV] valid iff constraints valid */ 815 /* final: [min_uV..max_uV] valid iff constraints valid */
789 if (max_uV < min_uV) { 816 if (max_uV < min_uV) {
790 pr_err("%s: %s '%s' voltage constraints\n", 817 rdev_err(rdev, "unsupportable voltage constraints\n");
791 __func__, "unsupportable", name);
792 return -EINVAL; 818 return -EINVAL;
793 } 819 }
794 820
795 /* use regulator's subset of machine constraints */ 821 /* use regulator's subset of machine constraints */
796 if (constraints->min_uV < min_uV) { 822 if (constraints->min_uV < min_uV) {
797 pr_debug("%s: override '%s' %s, %d -> %d\n", 823 rdev_dbg(rdev, "override min_uV, %d -> %d\n",
798 __func__, name, "min_uV", 824 constraints->min_uV, min_uV);
799 constraints->min_uV, min_uV);
800 constraints->min_uV = min_uV; 825 constraints->min_uV = min_uV;
801 } 826 }
802 if (constraints->max_uV > max_uV) { 827 if (constraints->max_uV > max_uV) {
803 pr_debug("%s: override '%s' %s, %d -> %d\n", 828 rdev_dbg(rdev, "override max_uV, %d -> %d\n",
804 __func__, name, "max_uV", 829 constraints->max_uV, max_uV);
805 constraints->max_uV, max_uV);
806 constraints->max_uV = max_uV; 830 constraints->max_uV = max_uV;
807 } 831 }
808 } 832 }
@@ -822,26 +846,25 @@ static int machine_constraints_voltage(struct regulator_dev *rdev,
822 * set_mode. 846 * set_mode.
823 */ 847 */
824static int set_machine_constraints(struct regulator_dev *rdev, 848static int set_machine_constraints(struct regulator_dev *rdev,
825 struct regulation_constraints *constraints) 849 const struct regulation_constraints *constraints)
826{ 850{
827 int ret = 0; 851 int ret = 0;
828 const char *name;
829 struct regulator_ops *ops = rdev->desc->ops; 852 struct regulator_ops *ops = rdev->desc->ops;
830 853
831 rdev->constraints = constraints; 854 rdev->constraints = kmemdup(constraints, sizeof(*constraints),
832 855 GFP_KERNEL);
833 name = rdev_get_name(rdev); 856 if (!rdev->constraints)
857 return -ENOMEM;
834 858
835 ret = machine_constraints_voltage(rdev, constraints); 859 ret = machine_constraints_voltage(rdev, rdev->constraints);
836 if (ret != 0) 860 if (ret != 0)
837 goto out; 861 goto out;
838 862
839 /* do we need to setup our suspend state */ 863 /* do we need to setup our suspend state */
840 if (constraints->initial_state) { 864 if (constraints->initial_state) {
841 ret = suspend_prepare(rdev, constraints->initial_state); 865 ret = suspend_prepare(rdev, rdev->constraints->initial_state);
842 if (ret < 0) { 866 if (ret < 0) {
843 printk(KERN_ERR "%s: failed to set suspend state for %s\n", 867 rdev_err(rdev, "failed to set suspend state\n");
844 __func__, name);
845 rdev->constraints = NULL; 868 rdev->constraints = NULL;
846 goto out; 869 goto out;
847 } 870 }
@@ -849,17 +872,14 @@ static int set_machine_constraints(struct regulator_dev *rdev,
849 872
850 if (constraints->initial_mode) { 873 if (constraints->initial_mode) {
851 if (!ops->set_mode) { 874 if (!ops->set_mode) {
852 printk(KERN_ERR "%s: no set_mode operation for %s\n", 875 rdev_err(rdev, "no set_mode operation\n");
853 __func__, name);
854 ret = -EINVAL; 876 ret = -EINVAL;
855 goto out; 877 goto out;
856 } 878 }
857 879
858 ret = ops->set_mode(rdev, constraints->initial_mode); 880 ret = ops->set_mode(rdev, rdev->constraints->initial_mode);
859 if (ret < 0) { 881 if (ret < 0) {
860 printk(KERN_ERR 882 rdev_err(rdev, "failed to set initial mode: %d\n", ret);
861 "%s: failed to set initial mode for %s: %d\n",
862 __func__, name, ret);
863 goto out; 883 goto out;
864 } 884 }
865 } 885 }
@@ -867,11 +887,11 @@ static int set_machine_constraints(struct regulator_dev *rdev,
867 /* If the constraints say the regulator should be on at this point 887 /* If the constraints say the regulator should be on at this point
868 * and we have control then make sure it is enabled. 888 * and we have control then make sure it is enabled.
869 */ 889 */
870 if ((constraints->always_on || constraints->boot_on) && ops->enable) { 890 if ((rdev->constraints->always_on || rdev->constraints->boot_on) &&
891 ops->enable) {
871 ret = ops->enable(rdev); 892 ret = ops->enable(rdev);
872 if (ret < 0) { 893 if (ret < 0) {
873 printk(KERN_ERR "%s: failed to enable %s\n", 894 rdev_err(rdev, "failed to enable\n");
874 __func__, name);
875 rdev->constraints = NULL; 895 rdev->constraints = NULL;
876 goto out; 896 goto out;
877 } 897 }
@@ -899,9 +919,8 @@ static int set_supply(struct regulator_dev *rdev,
899 err = sysfs_create_link(&rdev->dev.kobj, &supply_rdev->dev.kobj, 919 err = sysfs_create_link(&rdev->dev.kobj, &supply_rdev->dev.kobj,
900 "supply"); 920 "supply");
901 if (err) { 921 if (err) {
902 printk(KERN_ERR 922 rdev_err(rdev, "could not add device link %s err %d\n",
903 "%s: could not add device link %s err %d\n", 923 supply_rdev->dev.kobj.name, err);
904 __func__, supply_rdev->dev.kobj.name, err);
905 goto out; 924 goto out;
906 } 925 }
907 rdev->supply = supply_rdev; 926 rdev->supply = supply_rdev;
@@ -957,10 +976,10 @@ static int set_consumer_device_supply(struct regulator_dev *rdev,
957 continue; 976 continue;
958 977
959 dev_dbg(consumer_dev, "%s/%s is '%s' supply; fail %s/%s\n", 978 dev_dbg(consumer_dev, "%s/%s is '%s' supply; fail %s/%s\n",
960 dev_name(&node->regulator->dev), 979 dev_name(&node->regulator->dev),
961 node->regulator->desc->name, 980 node->regulator->desc->name,
962 supply, 981 supply,
963 dev_name(&rdev->dev), rdev_get_name(rdev)); 982 dev_name(&rdev->dev), rdev_get_name(rdev));
964 return -EBUSY; 983 return -EBUSY;
965 } 984 }
966 985
@@ -1031,8 +1050,7 @@ static struct regulator *create_regulator(struct regulator_dev *rdev,
1031 regulator->dev_attr.show = device_requested_uA_show; 1050 regulator->dev_attr.show = device_requested_uA_show;
1032 err = device_create_file(dev, &regulator->dev_attr); 1051 err = device_create_file(dev, &regulator->dev_attr);
1033 if (err < 0) { 1052 if (err < 0) {
1034 printk(KERN_WARNING "%s: could not add regulator_dev" 1053 rdev_warn(rdev, "could not add regulator_dev requested microamps sysfs entry\n");
1035 " load sysfs\n", __func__);
1036 goto attr_name_err; 1054 goto attr_name_err;
1037 } 1055 }
1038 1056
@@ -1049,9 +1067,8 @@ static struct regulator *create_regulator(struct regulator_dev *rdev,
1049 err = sysfs_create_link(&rdev->dev.kobj, &dev->kobj, 1067 err = sysfs_create_link(&rdev->dev.kobj, &dev->kobj,
1050 buf); 1068 buf);
1051 if (err) { 1069 if (err) {
1052 printk(KERN_WARNING 1070 rdev_warn(rdev, "could not add device link %s err %d\n",
1053 "%s: could not add device link %s err %d\n", 1071 dev->kobj.name, err);
1054 __func__, dev->kobj.name, err);
1055 goto link_name_err; 1072 goto link_name_err;
1056 } 1073 }
1057 } 1074 }
@@ -1088,7 +1105,7 @@ static struct regulator *_regulator_get(struct device *dev, const char *id,
1088 int ret; 1105 int ret;
1089 1106
1090 if (id == NULL) { 1107 if (id == NULL) {
1091 printk(KERN_ERR "regulator: get() with no identifier\n"); 1108 pr_err("get() with no identifier\n");
1092 return regulator; 1109 return regulator;
1093 } 1110 }
1094 1111
@@ -1122,8 +1139,8 @@ static struct regulator *_regulator_get(struct device *dev, const char *id,
1122 * substitute in a dummy regulator so consumers can continue. 1139 * substitute in a dummy regulator so consumers can continue.
1123 */ 1140 */
1124 if (!has_full_constraints) { 1141 if (!has_full_constraints) {
1125 pr_warning("%s supply %s not found, using dummy regulator\n", 1142 pr_warn("%s supply %s not found, using dummy regulator\n",
1126 devname, id); 1143 devname, id);
1127 rdev = dummy_regulator_rdev; 1144 rdev = dummy_regulator_rdev;
1128 goto found; 1145 goto found;
1129 } 1146 }
@@ -1274,8 +1291,7 @@ static int _regulator_enable(struct regulator_dev *rdev)
1274 ret = _regulator_enable(rdev->supply); 1291 ret = _regulator_enable(rdev->supply);
1275 mutex_unlock(&rdev->supply->mutex); 1292 mutex_unlock(&rdev->supply->mutex);
1276 if (ret < 0) { 1293 if (ret < 0) {
1277 printk(KERN_ERR "%s: failed to enable %s: %d\n", 1294 rdev_err(rdev, "failed to enable: %d\n", ret);
1278 __func__, rdev_get_name(rdev), ret);
1279 return ret; 1295 return ret;
1280 } 1296 }
1281 } 1297 }
@@ -1302,13 +1318,13 @@ static int _regulator_enable(struct regulator_dev *rdev)
1302 if (ret >= 0) { 1318 if (ret >= 0) {
1303 delay = ret; 1319 delay = ret;
1304 } else { 1320 } else {
1305 printk(KERN_WARNING 1321 rdev_warn(rdev, "enable_time() failed: %d\n",
1306 "%s: enable_time() failed for %s: %d\n", 1322 ret);
1307 __func__, rdev_get_name(rdev),
1308 ret);
1309 delay = 0; 1323 delay = 0;
1310 } 1324 }
1311 1325
1326 trace_regulator_enable(rdev_get_name(rdev));
1327
1312 /* Allow the regulator to ramp; it would be useful 1328 /* Allow the regulator to ramp; it would be useful
1313 * to extend this for bulk operations so that the 1329 * to extend this for bulk operations so that the
1314 * regulators can ramp together. */ 1330 * regulators can ramp together. */
@@ -1316,6 +1332,8 @@ static int _regulator_enable(struct regulator_dev *rdev)
1316 if (ret < 0) 1332 if (ret < 0)
1317 return ret; 1333 return ret;
1318 1334
1335 trace_regulator_enable_delay(rdev_get_name(rdev));
1336
1319 if (delay >= 1000) { 1337 if (delay >= 1000) {
1320 mdelay(delay / 1000); 1338 mdelay(delay / 1000);
1321 udelay(delay % 1000); 1339 udelay(delay % 1000);
@@ -1323,9 +1341,10 @@ static int _regulator_enable(struct regulator_dev *rdev)
1323 udelay(delay); 1341 udelay(delay);
1324 } 1342 }
1325 1343
1344 trace_regulator_enable_complete(rdev_get_name(rdev));
1345
1326 } else if (ret < 0) { 1346 } else if (ret < 0) {
1327 printk(KERN_ERR "%s: is_enabled() failed for %s: %d\n", 1347 rdev_err(rdev, "is_enabled() failed: %d\n", ret);
1328 __func__, rdev_get_name(rdev), ret);
1329 return ret; 1348 return ret;
1330 } 1349 }
1331 /* Fallthrough on positive return values - already enabled */ 1350 /* Fallthrough on positive return values - already enabled */
@@ -1367,8 +1386,7 @@ static int _regulator_disable(struct regulator_dev *rdev,
1367 *supply_rdev_ptr = NULL; 1386 *supply_rdev_ptr = NULL;
1368 1387
1369 if (WARN(rdev->use_count <= 0, 1388 if (WARN(rdev->use_count <= 0,
1370 "unbalanced disables for %s\n", 1389 "unbalanced disables for %s\n", rdev_get_name(rdev)))
1371 rdev_get_name(rdev)))
1372 return -EIO; 1390 return -EIO;
1373 1391
1374 /* are we the last user and permitted to disable ? */ 1392 /* are we the last user and permitted to disable ? */
@@ -1378,13 +1396,16 @@ static int _regulator_disable(struct regulator_dev *rdev,
1378 /* we are last user */ 1396 /* we are last user */
1379 if (_regulator_can_change_status(rdev) && 1397 if (_regulator_can_change_status(rdev) &&
1380 rdev->desc->ops->disable) { 1398 rdev->desc->ops->disable) {
1399 trace_regulator_disable(rdev_get_name(rdev));
1400
1381 ret = rdev->desc->ops->disable(rdev); 1401 ret = rdev->desc->ops->disable(rdev);
1382 if (ret < 0) { 1402 if (ret < 0) {
1383 printk(KERN_ERR "%s: failed to disable %s\n", 1403 rdev_err(rdev, "failed to disable\n");
1384 __func__, rdev_get_name(rdev));
1385 return ret; 1404 return ret;
1386 } 1405 }
1387 1406
1407 trace_regulator_disable_complete(rdev_get_name(rdev));
1408
1388 _notifier_call_chain(rdev, REGULATOR_EVENT_DISABLE, 1409 _notifier_call_chain(rdev, REGULATOR_EVENT_DISABLE,
1389 NULL); 1410 NULL);
1390 } 1411 }
@@ -1451,8 +1472,7 @@ static int _regulator_force_disable(struct regulator_dev *rdev,
1451 /* ah well, who wants to live forever... */ 1472 /* ah well, who wants to live forever... */
1452 ret = rdev->desc->ops->disable(rdev); 1473 ret = rdev->desc->ops->disable(rdev);
1453 if (ret < 0) { 1474 if (ret < 0) {
1454 printk(KERN_ERR "%s: failed to force disable %s\n", 1475 rdev_err(rdev, "failed to force disable\n");
1455 __func__, rdev_get_name(rdev));
1456 return ret; 1476 return ret;
1457 } 1477 }
1458 /* notify other consumers that power has been forced off */ 1478 /* notify other consumers that power has been forced off */
@@ -1605,6 +1625,62 @@ int regulator_is_supported_voltage(struct regulator *regulator,
1605 return 0; 1625 return 0;
1606} 1626}
1607 1627
1628static int _regulator_do_set_voltage(struct regulator_dev *rdev,
1629 int min_uV, int max_uV)
1630{
1631 int ret;
1632 unsigned int selector;
1633
1634 trace_regulator_set_voltage(rdev_get_name(rdev), min_uV, max_uV);
1635
1636 if (rdev->desc->ops->set_voltage) {
1637 ret = rdev->desc->ops->set_voltage(rdev, min_uV, max_uV,
1638 &selector);
1639
1640 if (rdev->desc->ops->list_voltage)
1641 selector = rdev->desc->ops->list_voltage(rdev,
1642 selector);
1643 else
1644 selector = -1;
1645 } else if (rdev->desc->ops->set_voltage_sel) {
1646 int best_val = INT_MAX;
1647 int i;
1648
1649 selector = 0;
1650
1651 /* Find the smallest voltage that falls within the specified
1652 * range.
1653 */
1654 for (i = 0; i < rdev->desc->n_voltages; i++) {
1655 ret = rdev->desc->ops->list_voltage(rdev, i);
1656 if (ret < 0)
1657 continue;
1658
1659 if (ret < best_val && ret >= min_uV && ret <= max_uV) {
1660 best_val = ret;
1661 selector = i;
1662 }
1663 }
1664
1665 if (best_val != INT_MAX) {
1666 ret = rdev->desc->ops->set_voltage_sel(rdev, selector);
1667 selector = best_val;
1668 } else {
1669 ret = -EINVAL;
1670 }
1671 } else {
1672 ret = -EINVAL;
1673 }
1674
1675 if (ret == 0)
1676 _notifier_call_chain(rdev, REGULATOR_EVENT_VOLTAGE_CHANGE,
1677 NULL);
1678
1679 trace_regulator_set_voltage_complete(rdev_get_name(rdev), selector);
1680
1681 return ret;
1682}
1683
1608/** 1684/**
1609 * regulator_set_voltage - set regulator output voltage 1685 * regulator_set_voltage - set regulator output voltage
1610 * @regulator: regulator source 1686 * @regulator: regulator source
@@ -1626,12 +1702,20 @@ int regulator_is_supported_voltage(struct regulator *regulator,
1626int regulator_set_voltage(struct regulator *regulator, int min_uV, int max_uV) 1702int regulator_set_voltage(struct regulator *regulator, int min_uV, int max_uV)
1627{ 1703{
1628 struct regulator_dev *rdev = regulator->rdev; 1704 struct regulator_dev *rdev = regulator->rdev;
1629 int ret; 1705 int ret = 0;
1630 1706
1631 mutex_lock(&rdev->mutex); 1707 mutex_lock(&rdev->mutex);
1632 1708
1709 /* If we're setting the same range as last time the change
1710 * should be a noop (some cpufreq implementations use the same
1711 * voltage for multiple frequencies, for example).
1712 */
1713 if (regulator->min_uV == min_uV && regulator->max_uV == max_uV)
1714 goto out;
1715
1633 /* sanity check */ 1716 /* sanity check */
1634 if (!rdev->desc->ops->set_voltage) { 1717 if (!rdev->desc->ops->set_voltage &&
1718 !rdev->desc->ops->set_voltage_sel) {
1635 ret = -EINVAL; 1719 ret = -EINVAL;
1636 goto out; 1720 goto out;
1637 } 1721 }
@@ -1642,18 +1726,76 @@ int regulator_set_voltage(struct regulator *regulator, int min_uV, int max_uV)
1642 goto out; 1726 goto out;
1643 regulator->min_uV = min_uV; 1727 regulator->min_uV = min_uV;
1644 regulator->max_uV = max_uV; 1728 regulator->max_uV = max_uV;
1645 ret = rdev->desc->ops->set_voltage(rdev, min_uV, max_uV); 1729
1730 ret = regulator_check_consumers(rdev, &min_uV, &max_uV);
1731 if (ret < 0)
1732 goto out;
1733
1734 ret = _regulator_do_set_voltage(rdev, min_uV, max_uV);
1646 1735
1647out: 1736out:
1648 _notifier_call_chain(rdev, REGULATOR_EVENT_VOLTAGE_CHANGE, NULL);
1649 mutex_unlock(&rdev->mutex); 1737 mutex_unlock(&rdev->mutex);
1650 return ret; 1738 return ret;
1651} 1739}
1652EXPORT_SYMBOL_GPL(regulator_set_voltage); 1740EXPORT_SYMBOL_GPL(regulator_set_voltage);
1653 1741
1742/**
1743 * regulator_sync_voltage - re-apply last regulator output voltage
1744 * @regulator: regulator source
1745 *
1746 * Re-apply the last configured voltage. This is intended to be used
1747 * where some external control source the consumer is cooperating with
1748 * has caused the configured voltage to change.
1749 */
1750int regulator_sync_voltage(struct regulator *regulator)
1751{
1752 struct regulator_dev *rdev = regulator->rdev;
1753 int ret, min_uV, max_uV;
1754
1755 mutex_lock(&rdev->mutex);
1756
1757 if (!rdev->desc->ops->set_voltage &&
1758 !rdev->desc->ops->set_voltage_sel) {
1759 ret = -EINVAL;
1760 goto out;
1761 }
1762
1763 /* This is only going to work if we've had a voltage configured. */
1764 if (!regulator->min_uV && !regulator->max_uV) {
1765 ret = -EINVAL;
1766 goto out;
1767 }
1768
1769 min_uV = regulator->min_uV;
1770 max_uV = regulator->max_uV;
1771
1772 /* This should be a paranoia check... */
1773 ret = regulator_check_voltage(rdev, &min_uV, &max_uV);
1774 if (ret < 0)
1775 goto out;
1776
1777 ret = regulator_check_consumers(rdev, &min_uV, &max_uV);
1778 if (ret < 0)
1779 goto out;
1780
1781 ret = _regulator_do_set_voltage(rdev, min_uV, max_uV);
1782
1783out:
1784 mutex_unlock(&rdev->mutex);
1785 return ret;
1786}
1787EXPORT_SYMBOL_GPL(regulator_sync_voltage);
1788
1654static int _regulator_get_voltage(struct regulator_dev *rdev) 1789static int _regulator_get_voltage(struct regulator_dev *rdev)
1655{ 1790{
1656 /* sanity check */ 1791 int sel;
1792
1793 if (rdev->desc->ops->get_voltage_sel) {
1794 sel = rdev->desc->ops->get_voltage_sel(rdev);
1795 if (sel < 0)
1796 return sel;
1797 return rdev->desc->ops->list_voltage(rdev, sel);
1798 }
1657 if (rdev->desc->ops->get_voltage) 1799 if (rdev->desc->ops->get_voltage)
1658 return rdev->desc->ops->get_voltage(rdev); 1800 return rdev->desc->ops->get_voltage(rdev);
1659 else 1801 else
@@ -1880,21 +2022,20 @@ int regulator_set_optimum_mode(struct regulator *regulator, int uA_load)
1880 goto out; 2022 goto out;
1881 2023
1882 /* get output voltage */ 2024 /* get output voltage */
1883 output_uV = rdev->desc->ops->get_voltage(rdev); 2025 output_uV = _regulator_get_voltage(rdev);
1884 if (output_uV <= 0) { 2026 if (output_uV <= 0) {
1885 printk(KERN_ERR "%s: invalid output voltage found for %s\n", 2027 rdev_err(rdev, "invalid output voltage found\n");
1886 __func__, rdev_get_name(rdev));
1887 goto out; 2028 goto out;
1888 } 2029 }
1889 2030
1890 /* get input voltage */ 2031 /* get input voltage */
1891 if (rdev->supply && rdev->supply->desc->ops->get_voltage) 2032 input_uV = 0;
1892 input_uV = rdev->supply->desc->ops->get_voltage(rdev->supply); 2033 if (rdev->supply)
1893 else 2034 input_uV = _regulator_get_voltage(rdev->supply);
2035 if (input_uV <= 0)
1894 input_uV = rdev->constraints->input_uV; 2036 input_uV = rdev->constraints->input_uV;
1895 if (input_uV <= 0) { 2037 if (input_uV <= 0) {
1896 printk(KERN_ERR "%s: invalid input voltage found for %s\n", 2038 rdev_err(rdev, "invalid input voltage found\n");
1897 __func__, rdev_get_name(rdev));
1898 goto out; 2039 goto out;
1899 } 2040 }
1900 2041
@@ -1907,16 +2048,14 @@ int regulator_set_optimum_mode(struct regulator *regulator, int uA_load)
1907 total_uA_load); 2048 total_uA_load);
1908 ret = regulator_check_mode(rdev, mode); 2049 ret = regulator_check_mode(rdev, mode);
1909 if (ret < 0) { 2050 if (ret < 0) {
1910 printk(KERN_ERR "%s: failed to get optimum mode for %s @" 2051 rdev_err(rdev, "failed to get optimum mode @ %d uA %d -> %d uV\n",
1911 " %d uA %d -> %d uV\n", __func__, rdev_get_name(rdev), 2052 total_uA_load, input_uV, output_uV);
1912 total_uA_load, input_uV, output_uV);
1913 goto out; 2053 goto out;
1914 } 2054 }
1915 2055
1916 ret = rdev->desc->ops->set_mode(rdev, mode); 2056 ret = rdev->desc->ops->set_mode(rdev, mode);
1917 if (ret < 0) { 2057 if (ret < 0) {
1918 printk(KERN_ERR "%s: failed to set optimum mode %x for %s\n", 2058 rdev_err(rdev, "failed to set optimum mode %x\n", mode);
1919 __func__, mode, rdev_get_name(rdev));
1920 goto out; 2059 goto out;
1921 } 2060 }
1922 ret = mode; 2061 ret = mode;
@@ -2047,7 +2186,7 @@ int regulator_bulk_enable(int num_consumers,
2047 return 0; 2186 return 0;
2048 2187
2049err: 2188err:
2050 printk(KERN_ERR "Failed to enable %s: %d\n", consumers[i].supply, ret); 2189 pr_err("Failed to enable %s: %d\n", consumers[i].supply, ret);
2051 for (--i; i >= 0; --i) 2190 for (--i; i >= 0; --i)
2052 regulator_disable(consumers[i].consumer); 2191 regulator_disable(consumers[i].consumer);
2053 2192
@@ -2082,8 +2221,7 @@ int regulator_bulk_disable(int num_consumers,
2082 return 0; 2221 return 0;
2083 2222
2084err: 2223err:
2085 printk(KERN_ERR "Failed to disable %s: %d\n", consumers[i].supply, 2224 pr_err("Failed to disable %s: %d\n", consumers[i].supply, ret);
2086 ret);
2087 for (--i; i >= 0; --i) 2225 for (--i; i >= 0; --i)
2088 regulator_enable(consumers[i].consumer); 2226 regulator_enable(consumers[i].consumer);
2089 2227
@@ -2166,7 +2304,7 @@ static int add_regulator_attributes(struct regulator_dev *rdev)
2166 int status = 0; 2304 int status = 0;
2167 2305
2168 /* some attributes need specific methods to be displayed */ 2306 /* some attributes need specific methods to be displayed */
2169 if (ops->get_voltage) { 2307 if (ops->get_voltage || ops->get_voltage_sel) {
2170 status = device_create_file(dev, &dev_attr_microvolts); 2308 status = device_create_file(dev, &dev_attr_microvolts);
2171 if (status < 0) 2309 if (status < 0)
2172 return status; 2310 return status;
@@ -2207,7 +2345,7 @@ static int add_regulator_attributes(struct regulator_dev *rdev)
2207 return status; 2345 return status;
2208 2346
2209 /* constraints need specific supporting methods */ 2347 /* constraints need specific supporting methods */
2210 if (ops->set_voltage) { 2348 if (ops->set_voltage || ops->set_voltage_sel) {
2211 status = device_create_file(dev, &dev_attr_min_microvolts); 2349 status = device_create_file(dev, &dev_attr_min_microvolts);
2212 if (status < 0) 2350 if (status < 0)
2213 return status; 2351 return status;
@@ -2271,6 +2409,23 @@ static int add_regulator_attributes(struct regulator_dev *rdev)
2271 return status; 2409 return status;
2272} 2410}
2273 2411
2412static void rdev_init_debugfs(struct regulator_dev *rdev)
2413{
2414#ifdef CONFIG_DEBUG_FS
2415 rdev->debugfs = debugfs_create_dir(rdev_get_name(rdev), debugfs_root);
2416 if (IS_ERR(rdev->debugfs) || !rdev->debugfs) {
2417 rdev_warn(rdev, "Failed to create debugfs directory\n");
2418 rdev->debugfs = NULL;
2419 return;
2420 }
2421
2422 debugfs_create_u32("use_count", 0444, rdev->debugfs,
2423 &rdev->use_count);
2424 debugfs_create_u32("open_count", 0444, rdev->debugfs,
2425 &rdev->open_count);
2426#endif
2427}
2428
2274/** 2429/**
2275 * regulator_register - register regulator 2430 * regulator_register - register regulator
2276 * @regulator_desc: regulator to register 2431 * @regulator_desc: regulator to register
@@ -2282,7 +2437,7 @@ static int add_regulator_attributes(struct regulator_dev *rdev)
2282 * Returns 0 on success. 2437 * Returns 0 on success.
2283 */ 2438 */
2284struct regulator_dev *regulator_register(struct regulator_desc *regulator_desc, 2439struct regulator_dev *regulator_register(struct regulator_desc *regulator_desc,
2285 struct device *dev, struct regulator_init_data *init_data, 2440 struct device *dev, const struct regulator_init_data *init_data,
2286 void *driver_data) 2441 void *driver_data)
2287{ 2442{
2288 static atomic_t regulator_no = ATOMIC_INIT(0); 2443 static atomic_t regulator_no = ATOMIC_INIT(0);
@@ -2302,6 +2457,22 @@ struct regulator_dev *regulator_register(struct regulator_desc *regulator_desc,
2302 if (!init_data) 2457 if (!init_data)
2303 return ERR_PTR(-EINVAL); 2458 return ERR_PTR(-EINVAL);
2304 2459
2460 /* Only one of each should be implemented */
2461 WARN_ON(regulator_desc->ops->get_voltage &&
2462 regulator_desc->ops->get_voltage_sel);
2463 WARN_ON(regulator_desc->ops->set_voltage &&
2464 regulator_desc->ops->set_voltage_sel);
2465
2466 /* If we're using selectors we must implement list_voltage. */
2467 if (regulator_desc->ops->get_voltage_sel &&
2468 !regulator_desc->ops->list_voltage) {
2469 return ERR_PTR(-EINVAL);
2470 }
2471 if (regulator_desc->ops->set_voltage_sel &&
2472 !regulator_desc->ops->list_voltage) {
2473 return ERR_PTR(-EINVAL);
2474 }
2475
2305 rdev = kzalloc(sizeof(struct regulator_dev), GFP_KERNEL); 2476 rdev = kzalloc(sizeof(struct regulator_dev), GFP_KERNEL);
2306 if (rdev == NULL) 2477 if (rdev == NULL)
2307 return ERR_PTR(-ENOMEM); 2478 return ERR_PTR(-ENOMEM);
@@ -2399,6 +2570,8 @@ struct regulator_dev *regulator_register(struct regulator_desc *regulator_desc,
2399 } 2570 }
2400 2571
2401 list_add(&rdev->list, &regulator_list); 2572 list_add(&rdev->list, &regulator_list);
2573
2574 rdev_init_debugfs(rdev);
2402out: 2575out:
2403 mutex_unlock(&regulator_list_mutex); 2576 mutex_unlock(&regulator_list_mutex);
2404 return rdev; 2577 return rdev;
@@ -2431,12 +2604,16 @@ void regulator_unregister(struct regulator_dev *rdev)
2431 return; 2604 return;
2432 2605
2433 mutex_lock(&regulator_list_mutex); 2606 mutex_lock(&regulator_list_mutex);
2607#ifdef CONFIG_DEBUG_FS
2608 debugfs_remove_recursive(rdev->debugfs);
2609#endif
2434 WARN_ON(rdev->open_count); 2610 WARN_ON(rdev->open_count);
2435 unset_regulator_supplies(rdev); 2611 unset_regulator_supplies(rdev);
2436 list_del(&rdev->list); 2612 list_del(&rdev->list);
2437 if (rdev->supply) 2613 if (rdev->supply)
2438 sysfs_remove_link(&rdev->dev.kobj, "supply"); 2614 sysfs_remove_link(&rdev->dev.kobj, "supply");
2439 device_unregister(&rdev->dev); 2615 device_unregister(&rdev->dev);
2616 kfree(rdev->constraints);
2440 mutex_unlock(&regulator_list_mutex); 2617 mutex_unlock(&regulator_list_mutex);
2441} 2618}
2442EXPORT_SYMBOL_GPL(regulator_unregister); 2619EXPORT_SYMBOL_GPL(regulator_unregister);
@@ -2465,8 +2642,7 @@ int regulator_suspend_prepare(suspend_state_t state)
2465 mutex_unlock(&rdev->mutex); 2642 mutex_unlock(&rdev->mutex);
2466 2643
2467 if (ret < 0) { 2644 if (ret < 0) {
2468 printk(KERN_ERR "%s: failed to prepare %s\n", 2645 rdev_err(rdev, "failed to prepare\n");
2469 __func__, rdev_get_name(rdev));
2470 goto out; 2646 goto out;
2471 } 2647 }
2472 } 2648 }
@@ -2572,10 +2748,16 @@ static int __init regulator_init(void)
2572{ 2748{
2573 int ret; 2749 int ret;
2574 2750
2575 printk(KERN_INFO "regulator: core version %s\n", REGULATOR_VERSION);
2576
2577 ret = class_register(&regulator_class); 2751 ret = class_register(&regulator_class);
2578 2752
2753#ifdef CONFIG_DEBUG_FS
2754 debugfs_root = debugfs_create_dir("regulator", NULL);
2755 if (IS_ERR(debugfs_root) || !debugfs_root) {
2756 pr_warn("regulator: Failed to create debugfs directory\n");
2757 debugfs_root = NULL;
2758 }
2759#endif
2760
2579 regulator_dummy_init(); 2761 regulator_dummy_init();
2580 2762
2581 return ret; 2763 return ret;
@@ -2590,7 +2772,6 @@ static int __init regulator_init_complete(void)
2590 struct regulator_ops *ops; 2772 struct regulator_ops *ops;
2591 struct regulation_constraints *c; 2773 struct regulation_constraints *c;
2592 int enabled, ret; 2774 int enabled, ret;
2593 const char *name;
2594 2775
2595 mutex_lock(&regulator_list_mutex); 2776 mutex_lock(&regulator_list_mutex);
2596 2777
@@ -2602,8 +2783,6 @@ static int __init regulator_init_complete(void)
2602 ops = rdev->desc->ops; 2783 ops = rdev->desc->ops;
2603 c = rdev->constraints; 2784 c = rdev->constraints;
2604 2785
2605 name = rdev_get_name(rdev);
2606
2607 if (!ops->disable || (c && c->always_on)) 2786 if (!ops->disable || (c && c->always_on))
2608 continue; 2787 continue;
2609 2788
@@ -2624,13 +2803,10 @@ static int __init regulator_init_complete(void)
2624 if (has_full_constraints) { 2803 if (has_full_constraints) {
2625 /* We log since this may kill the system if it 2804 /* We log since this may kill the system if it
2626 * goes wrong. */ 2805 * goes wrong. */
2627 printk(KERN_INFO "%s: disabling %s\n", 2806 rdev_info(rdev, "disabling\n");
2628 __func__, name);
2629 ret = ops->disable(rdev); 2807 ret = ops->disable(rdev);
2630 if (ret != 0) { 2808 if (ret != 0) {
2631 printk(KERN_ERR 2809 rdev_err(rdev, "couldn't disable: %d\n", ret);
2632 "%s: couldn't disable %s: %d\n",
2633 __func__, name, ret);
2634 } 2810 }
2635 } else { 2811 } else {
2636 /* The intention is that in future we will 2812 /* The intention is that in future we will
@@ -2638,9 +2814,7 @@ static int __init regulator_init_complete(void)
2638 * so warn even if we aren't going to do 2814 * so warn even if we aren't going to do
2639 * anything here. 2815 * anything here.
2640 */ 2816 */
2641 printk(KERN_WARNING 2817 rdev_warn(rdev, "incomplete constraints, leaving on\n");
2642 "%s: incomplete constraints, leaving %s on\n",
2643 __func__, name);
2644 } 2818 }
2645 2819
2646unlock: 2820unlock:
diff --git a/drivers/regulator/da903x.c b/drivers/regulator/da903x.c
index f8c4661a7a81..362e08221085 100644
--- a/drivers/regulator/da903x.c
+++ b/drivers/regulator/da903x.c
@@ -107,7 +107,7 @@ static inline int check_range(struct da903x_regulator_info *info,
107 107
108/* DA9030/DA9034 common operations */ 108/* DA9030/DA9034 common operations */
109static int da903x_set_ldo_voltage(struct regulator_dev *rdev, 109static int da903x_set_ldo_voltage(struct regulator_dev *rdev,
110 int min_uV, int max_uV) 110 int min_uV, int max_uV, unsigned *selector)
111{ 111{
112 struct da903x_regulator_info *info = rdev_get_drvdata(rdev); 112 struct da903x_regulator_info *info = rdev_get_drvdata(rdev);
113 struct device *da9034_dev = to_da903x_dev(rdev); 113 struct device *da9034_dev = to_da903x_dev(rdev);
@@ -119,6 +119,7 @@ static int da903x_set_ldo_voltage(struct regulator_dev *rdev,
119 } 119 }
120 120
121 val = (min_uV - info->min_uV + info->step_uV - 1) / info->step_uV; 121 val = (min_uV - info->min_uV + info->step_uV - 1) / info->step_uV;
122 *selector = val;
122 val <<= info->vol_shift; 123 val <<= info->vol_shift;
123 mask = ((1 << info->vol_nbits) - 1) << info->vol_shift; 124 mask = ((1 << info->vol_nbits) - 1) << info->vol_shift;
124 125
@@ -187,7 +188,8 @@ static int da903x_list_voltage(struct regulator_dev *rdev, unsigned selector)
187 188
188/* DA9030 specific operations */ 189/* DA9030 specific operations */
189static int da9030_set_ldo1_15_voltage(struct regulator_dev *rdev, 190static int da9030_set_ldo1_15_voltage(struct regulator_dev *rdev,
190 int min_uV, int max_uV) 191 int min_uV, int max_uV,
192 unsigned *selector)
191{ 193{
192 struct da903x_regulator_info *info = rdev_get_drvdata(rdev); 194 struct da903x_regulator_info *info = rdev_get_drvdata(rdev);
193 struct device *da903x_dev = to_da903x_dev(rdev); 195 struct device *da903x_dev = to_da903x_dev(rdev);
@@ -200,6 +202,7 @@ static int da9030_set_ldo1_15_voltage(struct regulator_dev *rdev,
200 } 202 }
201 203
202 val = (min_uV - info->min_uV + info->step_uV - 1) / info->step_uV; 204 val = (min_uV - info->min_uV + info->step_uV - 1) / info->step_uV;
205 *selector = val;
203 val <<= info->vol_shift; 206 val <<= info->vol_shift;
204 mask = ((1 << info->vol_nbits) - 1) << info->vol_shift; 207 mask = ((1 << info->vol_nbits) - 1) << info->vol_shift;
205 val |= DA9030_LDO_UNLOCK; /* have to set UNLOCK bits */ 208 val |= DA9030_LDO_UNLOCK; /* have to set UNLOCK bits */
@@ -214,7 +217,8 @@ static int da9030_set_ldo1_15_voltage(struct regulator_dev *rdev,
214} 217}
215 218
216static int da9030_set_ldo14_voltage(struct regulator_dev *rdev, 219static int da9030_set_ldo14_voltage(struct regulator_dev *rdev,
217 int min_uV, int max_uV) 220 int min_uV, int max_uV,
221 unsigned *selector)
218{ 222{
219 struct da903x_regulator_info *info = rdev_get_drvdata(rdev); 223 struct da903x_regulator_info *info = rdev_get_drvdata(rdev);
220 struct device *da903x_dev = to_da903x_dev(rdev); 224 struct device *da903x_dev = to_da903x_dev(rdev);
@@ -234,6 +238,7 @@ static int da9030_set_ldo14_voltage(struct regulator_dev *rdev,
234 val = (min_uV - thresh + info->step_uV - 1) / info->step_uV; 238 val = (min_uV - thresh + info->step_uV - 1) / info->step_uV;
235 } 239 }
236 240
241 *selector = val;
237 val <<= info->vol_shift; 242 val <<= info->vol_shift;
238 mask = ((1 << info->vol_nbits) - 1) << info->vol_shift; 243 mask = ((1 << info->vol_nbits) - 1) << info->vol_shift;
239 244
@@ -263,7 +268,7 @@ static int da9030_get_ldo14_voltage(struct regulator_dev *rdev)
263 268
264/* DA9034 specific operations */ 269/* DA9034 specific operations */
265static int da9034_set_dvc_voltage(struct regulator_dev *rdev, 270static int da9034_set_dvc_voltage(struct regulator_dev *rdev,
266 int min_uV, int max_uV) 271 int min_uV, int max_uV, unsigned *selector)
267{ 272{
268 struct da903x_regulator_info *info = rdev_get_drvdata(rdev); 273 struct da903x_regulator_info *info = rdev_get_drvdata(rdev);
269 struct device *da9034_dev = to_da903x_dev(rdev); 274 struct device *da9034_dev = to_da903x_dev(rdev);
@@ -276,6 +281,7 @@ static int da9034_set_dvc_voltage(struct regulator_dev *rdev,
276 } 281 }
277 282
278 val = (min_uV - info->min_uV + info->step_uV - 1) / info->step_uV; 283 val = (min_uV - info->min_uV + info->step_uV - 1) / info->step_uV;
284 *selector = val;
279 val <<= info->vol_shift; 285 val <<= info->vol_shift;
280 mask = ((1 << info->vol_nbits) - 1) << info->vol_shift; 286 mask = ((1 << info->vol_nbits) - 1) << info->vol_shift;
281 287
@@ -289,7 +295,7 @@ static int da9034_set_dvc_voltage(struct regulator_dev *rdev,
289} 295}
290 296
291static int da9034_set_ldo12_voltage(struct regulator_dev *rdev, 297static int da9034_set_ldo12_voltage(struct regulator_dev *rdev,
292 int min_uV, int max_uV) 298 int min_uV, int max_uV, unsigned *selector)
293{ 299{
294 struct da903x_regulator_info *info = rdev_get_drvdata(rdev); 300 struct da903x_regulator_info *info = rdev_get_drvdata(rdev);
295 struct device *da9034_dev = to_da903x_dev(rdev); 301 struct device *da9034_dev = to_da903x_dev(rdev);
@@ -302,6 +308,7 @@ static int da9034_set_ldo12_voltage(struct regulator_dev *rdev,
302 308
303 val = (min_uV - info->min_uV + info->step_uV - 1) / info->step_uV; 309 val = (min_uV - info->min_uV + info->step_uV - 1) / info->step_uV;
304 val = (val >= 20) ? val - 12 : ((val > 7) ? 8 : val); 310 val = (val >= 20) ? val - 12 : ((val > 7) ? 8 : val);
311 *selector = val;
305 val <<= info->vol_shift; 312 val <<= info->vol_shift;
306 mask = ((1 << info->vol_nbits) - 1) << info->vol_shift; 313 mask = ((1 << info->vol_nbits) - 1) << info->vol_shift;
307 314
diff --git a/drivers/regulator/isl6271a-regulator.c b/drivers/regulator/isl6271a-regulator.c
index b8cc6389a541..e4b3592e8176 100644
--- a/drivers/regulator/isl6271a-regulator.c
+++ b/drivers/regulator/isl6271a-regulator.c
@@ -58,7 +58,9 @@ out:
58 return data; 58 return data;
59} 59}
60 60
61static int isl6271a_set_voltage(struct regulator_dev *dev, int minuV, int maxuV) 61static int isl6271a_set_voltage(struct regulator_dev *dev,
62 int minuV, int maxuV,
63 unsigned *selector)
62{ 64{
63 struct isl_pmic *pmic = rdev_get_drvdata(dev); 65 struct isl_pmic *pmic = rdev_get_drvdata(dev);
64 int vsel, err, data; 66 int vsel, err, data;
@@ -78,6 +80,8 @@ static int isl6271a_set_voltage(struct regulator_dev *dev, int minuV, int maxuV)
78 /* Convert the microvolts to data for the chip */ 80 /* Convert the microvolts to data for the chip */
79 data = (vsel - ISL6271A_VOLTAGE_MIN) / ISL6271A_VOLTAGE_STEP; 81 data = (vsel - ISL6271A_VOLTAGE_MIN) / ISL6271A_VOLTAGE_STEP;
80 82
83 *selector = data;
84
81 mutex_lock(&pmic->mtx); 85 mutex_lock(&pmic->mtx);
82 86
83 err = i2c_smbus_write_byte(pmic->client, data); 87 err = i2c_smbus_write_byte(pmic->client, data);
@@ -169,7 +173,7 @@ static int __devinit isl6271a_probe(struct i2c_client *i2c,
169 init_data, pmic); 173 init_data, pmic);
170 if (IS_ERR(pmic->rdev[i])) { 174 if (IS_ERR(pmic->rdev[i])) {
171 dev_err(&i2c->dev, "failed to register %s\n", id->name); 175 dev_err(&i2c->dev, "failed to register %s\n", id->name);
172 err = PTR_ERR(pmic->rdev); 176 err = PTR_ERR(pmic->rdev[i]);
173 goto error; 177 goto error;
174 } 178 }
175 } 179 }
diff --git a/drivers/regulator/lp3971.c b/drivers/regulator/lp3971.c
index 3bb82b624e19..0f22ef12601c 100644
--- a/drivers/regulator/lp3971.c
+++ b/drivers/regulator/lp3971.c
@@ -168,7 +168,8 @@ static int lp3971_ldo_get_voltage(struct regulator_dev *dev)
168} 168}
169 169
170static int lp3971_ldo_set_voltage(struct regulator_dev *dev, 170static int lp3971_ldo_set_voltage(struct regulator_dev *dev,
171 int min_uV, int max_uV) 171 int min_uV, int max_uV,
172 unsigned int *selector)
172{ 173{
173 struct lp3971 *lp3971 = rdev_get_drvdata(dev); 174 struct lp3971 *lp3971 = rdev_get_drvdata(dev);
174 int ldo = rdev_get_id(dev) - LP3971_LDO1; 175 int ldo = rdev_get_id(dev) - LP3971_LDO1;
@@ -187,6 +188,8 @@ static int lp3971_ldo_set_voltage(struct regulator_dev *dev,
187 if (val > LDO_VOL_MAX_IDX || vol_map[val] > max_vol) 188 if (val > LDO_VOL_MAX_IDX || vol_map[val] > max_vol)
188 return -EINVAL; 189 return -EINVAL;
189 190
191 *selector = val;
192
190 return lp3971_set_bits(lp3971, LP3971_LDO_VOL_CONTR_REG(ldo), 193 return lp3971_set_bits(lp3971, LP3971_LDO_VOL_CONTR_REG(ldo),
191 LDO_VOL_CONTR_MASK << LDO_VOL_CONTR_SHIFT(ldo), 194 LDO_VOL_CONTR_MASK << LDO_VOL_CONTR_SHIFT(ldo),
192 val << LDO_VOL_CONTR_SHIFT(ldo)); 195 val << LDO_VOL_CONTR_SHIFT(ldo));
@@ -256,7 +259,8 @@ static int lp3971_dcdc_get_voltage(struct regulator_dev *dev)
256} 259}
257 260
258static int lp3971_dcdc_set_voltage(struct regulator_dev *dev, 261static int lp3971_dcdc_set_voltage(struct regulator_dev *dev,
259 int min_uV, int max_uV) 262 int min_uV, int max_uV,
263 unsigned int *selector)
260{ 264{
261 struct lp3971 *lp3971 = rdev_get_drvdata(dev); 265 struct lp3971 *lp3971 = rdev_get_drvdata(dev);
262 int buck = rdev_get_id(dev) - LP3971_DCDC1; 266 int buck = rdev_get_id(dev) - LP3971_DCDC1;
@@ -277,6 +281,8 @@ static int lp3971_dcdc_set_voltage(struct regulator_dev *dev,
277 if (val > BUCK_TARGET_VOL_MAX_IDX || vol_map[val] > max_vol) 281 if (val > BUCK_TARGET_VOL_MAX_IDX || vol_map[val] > max_vol)
278 return -EINVAL; 282 return -EINVAL;
279 283
284 *selector = val;
285
280 ret = lp3971_set_bits(lp3971, LP3971_BUCK_TARGET_VOL1_REG(buck), 286 ret = lp3971_set_bits(lp3971, LP3971_BUCK_TARGET_VOL1_REG(buck),
281 BUCK_TARGET_VOL_MASK, val); 287 BUCK_TARGET_VOL_MASK, val);
282 if (ret) 288 if (ret)
diff --git a/drivers/regulator/lp3972.c b/drivers/regulator/lp3972.c
index e07062fd0b42..6aa1b506fb5d 100644
--- a/drivers/regulator/lp3972.c
+++ b/drivers/regulator/lp3972.c
@@ -292,7 +292,8 @@ static int lp3972_ldo_get_voltage(struct regulator_dev *dev)
292} 292}
293 293
294static int lp3972_ldo_set_voltage(struct regulator_dev *dev, 294static int lp3972_ldo_set_voltage(struct regulator_dev *dev,
295 int min_uV, int max_uV) 295 int min_uV, int max_uV,
296 unsigned int *selector)
296{ 297{
297 struct lp3972 *lp3972 = rdev_get_drvdata(dev); 298 struct lp3972 *lp3972 = rdev_get_drvdata(dev);
298 int ldo = rdev_get_id(dev) - LP3972_LDO1; 299 int ldo = rdev_get_id(dev) - LP3972_LDO1;
@@ -313,6 +314,8 @@ static int lp3972_ldo_set_voltage(struct regulator_dev *dev,
313 if (val > LP3972_LDO_VOL_MAX_IDX(ldo) || vol_map[val] > max_vol) 314 if (val > LP3972_LDO_VOL_MAX_IDX(ldo) || vol_map[val] > max_vol)
314 return -EINVAL; 315 return -EINVAL;
315 316
317 *selector = val;
318
316 shift = LP3972_LDO_VOL_CONTR_SHIFT(ldo); 319 shift = LP3972_LDO_VOL_CONTR_SHIFT(ldo);
317 ret = lp3972_set_bits(lp3972, LP3972_LDO_VOL_CONTR_REG(ldo), 320 ret = lp3972_set_bits(lp3972, LP3972_LDO_VOL_CONTR_REG(ldo),
318 LP3972_LDO_VOL_MASK(ldo) << shift, val << shift); 321 LP3972_LDO_VOL_MASK(ldo) << shift, val << shift);
@@ -416,7 +419,8 @@ static int lp3972_dcdc_get_voltage(struct regulator_dev *dev)
416} 419}
417 420
418static int lp3972_dcdc_set_voltage(struct regulator_dev *dev, 421static int lp3972_dcdc_set_voltage(struct regulator_dev *dev,
419 int min_uV, int max_uV) 422 int min_uV, int max_uV,
423 unsigned int *selector)
420{ 424{
421 struct lp3972 *lp3972 = rdev_get_drvdata(dev); 425 struct lp3972 *lp3972 = rdev_get_drvdata(dev);
422 int buck = rdev_get_id(dev) - LP3972_DCDC1; 426 int buck = rdev_get_id(dev) - LP3972_DCDC1;
@@ -438,6 +442,8 @@ static int lp3972_dcdc_set_voltage(struct regulator_dev *dev,
438 vol_map[val] > max_vol) 442 vol_map[val] > max_vol)
439 return -EINVAL; 443 return -EINVAL;
440 444
445 *selector = val;
446
441 ret = lp3972_set_bits(lp3972, LP3972_BUCK_VOL1_REG(buck), 447 ret = lp3972_set_bits(lp3972, LP3972_BUCK_VOL1_REG(buck),
442 LP3972_BUCK_VOL_MASK, val); 448 LP3972_BUCK_VOL_MASK, val);
443 if (ret) 449 if (ret)
diff --git a/drivers/regulator/max1586.c b/drivers/regulator/max1586.c
index 559cfa271a44..3f49512c5134 100644
--- a/drivers/regulator/max1586.c
+++ b/drivers/regulator/max1586.c
@@ -63,12 +63,12 @@ static int max1586_v3_calc_voltage(struct max1586_data *max1586,
63 return max1586->min_uV + (selector * range_uV / MAX1586_V3_MAX_VSEL); 63 return max1586->min_uV + (selector * range_uV / MAX1586_V3_MAX_VSEL);
64} 64}
65 65
66static int max1586_v3_set(struct regulator_dev *rdev, int min_uV, int max_uV) 66static int max1586_v3_set(struct regulator_dev *rdev, int min_uV, int max_uV,
67 unsigned *selector)
67{ 68{
68 struct max1586_data *max1586 = rdev_get_drvdata(rdev); 69 struct max1586_data *max1586 = rdev_get_drvdata(rdev);
69 struct i2c_client *client = max1586->client; 70 struct i2c_client *client = max1586->client;
70 unsigned range_uV = max1586->max_uV - max1586->min_uV; 71 unsigned range_uV = max1586->max_uV - max1586->min_uV;
71 unsigned selector;
72 u8 v3_prog; 72 u8 v3_prog;
73 73
74 if (min_uV > max1586->max_uV || max_uV < max1586->min_uV) 74 if (min_uV > max1586->max_uV || max_uV < max1586->min_uV)
@@ -76,15 +76,15 @@ static int max1586_v3_set(struct regulator_dev *rdev, int min_uV, int max_uV)
76 if (min_uV < max1586->min_uV) 76 if (min_uV < max1586->min_uV)
77 min_uV = max1586->min_uV; 77 min_uV = max1586->min_uV;
78 78
79 selector = ((min_uV - max1586->min_uV) * MAX1586_V3_MAX_VSEL + 79 *selector = ((min_uV - max1586->min_uV) * MAX1586_V3_MAX_VSEL +
80 range_uV - 1) / range_uV; 80 range_uV - 1) / range_uV;
81 if (max1586_v3_calc_voltage(max1586, selector) > max_uV) 81 if (max1586_v3_calc_voltage(max1586, *selector) > max_uV)
82 return -EINVAL; 82 return -EINVAL;
83 83
84 dev_dbg(&client->dev, "changing voltage v3 to %dmv\n", 84 dev_dbg(&client->dev, "changing voltage v3 to %dmv\n",
85 max1586_v3_calc_voltage(max1586, selector) / 1000); 85 max1586_v3_calc_voltage(max1586, *selector) / 1000);
86 86
87 v3_prog = I2C_V3_SELECT | (u8) selector; 87 v3_prog = I2C_V3_SELECT | (u8) *selector;
88 return i2c_smbus_write_byte(client, v3_prog); 88 return i2c_smbus_write_byte(client, v3_prog);
89} 89}
90 90
@@ -110,10 +110,10 @@ static int max1586_v6_calc_voltage(unsigned selector)
110 return voltages_uv[selector]; 110 return voltages_uv[selector];
111} 111}
112 112
113static int max1586_v6_set(struct regulator_dev *rdev, int min_uV, int max_uV) 113static int max1586_v6_set(struct regulator_dev *rdev, int min_uV, int max_uV,
114 unsigned int *selector)
114{ 115{
115 struct i2c_client *client = rdev_get_drvdata(rdev); 116 struct i2c_client *client = rdev_get_drvdata(rdev);
116 unsigned selector;
117 u8 v6_prog; 117 u8 v6_prog;
118 118
119 if (min_uV < MAX1586_V6_MIN_UV || min_uV > MAX1586_V6_MAX_UV) 119 if (min_uV < MAX1586_V6_MIN_UV || min_uV > MAX1586_V6_MAX_UV)
@@ -122,21 +122,21 @@ static int max1586_v6_set(struct regulator_dev *rdev, int min_uV, int max_uV)
122 return -EINVAL; 122 return -EINVAL;
123 123
124 if (min_uV < 1800000) 124 if (min_uV < 1800000)
125 selector = 0; 125 *selector = 0;
126 else if (min_uV < 2500000) 126 else if (min_uV < 2500000)
127 selector = 1; 127 *selector = 1;
128 else if (min_uV < 3000000) 128 else if (min_uV < 3000000)
129 selector = 2; 129 *selector = 2;
130 else if (min_uV >= 3000000) 130 else if (min_uV >= 3000000)
131 selector = 3; 131 *selector = 3;
132 132
133 if (max1586_v6_calc_voltage(selector) > max_uV) 133 if (max1586_v6_calc_voltage(*selector) > max_uV)
134 return -EINVAL; 134 return -EINVAL;
135 135
136 dev_dbg(&client->dev, "changing voltage v6 to %dmv\n", 136 dev_dbg(&client->dev, "changing voltage v6 to %dmv\n",
137 max1586_v6_calc_voltage(selector) / 1000); 137 max1586_v6_calc_voltage(*selector) / 1000);
138 138
139 v6_prog = I2C_V6_SELECT | (u8) selector; 139 v6_prog = I2C_V6_SELECT | (u8) *selector;
140 return i2c_smbus_write_byte(client, v6_prog); 140 return i2c_smbus_write_byte(client, v6_prog);
141} 141}
142 142
diff --git a/drivers/regulator/max8649.c b/drivers/regulator/max8649.c
index 6b60a9c0366b..30eb9e54f7ec 100644
--- a/drivers/regulator/max8649.c
+++ b/drivers/regulator/max8649.c
@@ -155,7 +155,7 @@ static int max8649_get_voltage(struct regulator_dev *rdev)
155} 155}
156 156
157static int max8649_set_voltage(struct regulator_dev *rdev, 157static int max8649_set_voltage(struct regulator_dev *rdev,
158 int min_uV, int max_uV) 158 int min_uV, int max_uV, unsigned *selector)
159{ 159{
160 struct max8649_regulator_info *info = rdev_get_drvdata(rdev); 160 struct max8649_regulator_info *info = rdev_get_drvdata(rdev);
161 unsigned char data, mask; 161 unsigned char data, mask;
@@ -168,6 +168,7 @@ static int max8649_set_voltage(struct regulator_dev *rdev,
168 data = (min_uV - MAX8649_DCDC_VMIN + MAX8649_DCDC_STEP - 1) 168 data = (min_uV - MAX8649_DCDC_VMIN + MAX8649_DCDC_STEP - 1)
169 / MAX8649_DCDC_STEP; 169 / MAX8649_DCDC_STEP;
170 mask = MAX8649_VOL_MASK; 170 mask = MAX8649_VOL_MASK;
171 *selector = data & mask;
171 172
172 return max8649_set_bits(info->i2c, info->vol_reg, mask, data); 173 return max8649_set_bits(info->i2c, info->vol_reg, mask, data);
173} 174}
diff --git a/drivers/regulator/max8660.c b/drivers/regulator/max8660.c
index c570e6eb0db2..33f5d9a492ef 100644
--- a/drivers/regulator/max8660.c
+++ b/drivers/regulator/max8660.c
@@ -141,7 +141,8 @@ static int max8660_dcdc_get(struct regulator_dev *rdev)
141 return MAX8660_DCDC_MIN_UV + selector * MAX8660_DCDC_STEP; 141 return MAX8660_DCDC_MIN_UV + selector * MAX8660_DCDC_STEP;
142} 142}
143 143
144static int max8660_dcdc_set(struct regulator_dev *rdev, int min_uV, int max_uV) 144static int max8660_dcdc_set(struct regulator_dev *rdev, int min_uV, int max_uV,
145 unsigned int *s)
145{ 146{
146 struct max8660 *max8660 = rdev_get_drvdata(rdev); 147 struct max8660 *max8660 = rdev_get_drvdata(rdev);
147 u8 reg, selector, bits; 148 u8 reg, selector, bits;
@@ -154,6 +155,7 @@ static int max8660_dcdc_set(struct regulator_dev *rdev, int min_uV, int max_uV)
154 155
155 selector = (min_uV - (MAX8660_DCDC_MIN_UV - MAX8660_DCDC_STEP + 1)) 156 selector = (min_uV - (MAX8660_DCDC_MIN_UV - MAX8660_DCDC_STEP + 1))
156 / MAX8660_DCDC_STEP; 157 / MAX8660_DCDC_STEP;
158 *s = selector;
157 159
158 ret = max8660_dcdc_list(rdev, selector); 160 ret = max8660_dcdc_list(rdev, selector);
159 if (ret < 0 || ret > max_uV) 161 if (ret < 0 || ret > max_uV)
@@ -196,7 +198,8 @@ static int max8660_ldo5_get(struct regulator_dev *rdev)
196 return MAX8660_LDO5_MIN_UV + selector * MAX8660_LDO5_STEP; 198 return MAX8660_LDO5_MIN_UV + selector * MAX8660_LDO5_STEP;
197} 199}
198 200
199static int max8660_ldo5_set(struct regulator_dev *rdev, int min_uV, int max_uV) 201static int max8660_ldo5_set(struct regulator_dev *rdev, int min_uV, int max_uV,
202 unsigned int *s)
200{ 203{
201 struct max8660 *max8660 = rdev_get_drvdata(rdev); 204 struct max8660 *max8660 = rdev_get_drvdata(rdev);
202 u8 selector; 205 u8 selector;
@@ -213,6 +216,8 @@ static int max8660_ldo5_set(struct regulator_dev *rdev, int min_uV, int max_uV)
213 if (ret < 0 || ret > max_uV) 216 if (ret < 0 || ret > max_uV)
214 return -EINVAL; 217 return -EINVAL;
215 218
219 *s = selector;
220
216 ret = max8660_write(max8660, MAX8660_MDTV2, 0, selector); 221 ret = max8660_write(max8660, MAX8660_MDTV2, 0, selector);
217 if (ret) 222 if (ret)
218 return ret; 223 return ret;
@@ -270,7 +275,8 @@ static int max8660_ldo67_get(struct regulator_dev *rdev)
270 return MAX8660_LDO67_MIN_UV + selector * MAX8660_LDO67_STEP; 275 return MAX8660_LDO67_MIN_UV + selector * MAX8660_LDO67_STEP;
271} 276}
272 277
273static int max8660_ldo67_set(struct regulator_dev *rdev, int min_uV, int max_uV) 278static int max8660_ldo67_set(struct regulator_dev *rdev, int min_uV,
279 int max_uV, unsigned int *s)
274{ 280{
275 struct max8660 *max8660 = rdev_get_drvdata(rdev); 281 struct max8660 *max8660 = rdev_get_drvdata(rdev);
276 u8 selector; 282 u8 selector;
@@ -288,6 +294,8 @@ static int max8660_ldo67_set(struct regulator_dev *rdev, int min_uV, int max_uV)
288 if (ret < 0 || ret > max_uV) 294 if (ret < 0 || ret > max_uV)
289 return -EINVAL; 295 return -EINVAL;
290 296
297 *s = selector;
298
291 if (rdev_get_id(rdev) == MAX8660_V6) 299 if (rdev_get_id(rdev) == MAX8660_V6)
292 return max8660_write(max8660, MAX8660_L12VCR, 0xf0, selector); 300 return max8660_write(max8660, MAX8660_L12VCR, 0xf0, selector);
293 else 301 else
diff --git a/drivers/regulator/max8925-regulator.c b/drivers/regulator/max8925-regulator.c
index 552cad85ae5a..8ae147549c6a 100644
--- a/drivers/regulator/max8925-regulator.c
+++ b/drivers/regulator/max8925-regulator.c
@@ -55,7 +55,7 @@ static int max8925_list_voltage(struct regulator_dev *rdev, unsigned index)
55} 55}
56 56
57static int max8925_set_voltage(struct regulator_dev *rdev, 57static int max8925_set_voltage(struct regulator_dev *rdev,
58 int min_uV, int max_uV) 58 int min_uV, int max_uV, unsigned int *selector)
59{ 59{
60 struct max8925_regulator_info *info = rdev_get_drvdata(rdev); 60 struct max8925_regulator_info *info = rdev_get_drvdata(rdev);
61 unsigned char data, mask; 61 unsigned char data, mask;
@@ -66,6 +66,7 @@ static int max8925_set_voltage(struct regulator_dev *rdev,
66 return -EINVAL; 66 return -EINVAL;
67 } 67 }
68 data = (min_uV - info->min_uV + info->step_uV - 1) / info->step_uV; 68 data = (min_uV - info->min_uV + info->step_uV - 1) / info->step_uV;
69 *selector = data;
69 data <<= info->vol_shift; 70 data <<= info->vol_shift;
70 mask = ((1 << info->vol_nbits) - 1) << info->vol_shift; 71 mask = ((1 << info->vol_nbits) - 1) << info->vol_shift;
71 72
diff --git a/drivers/regulator/max8952.c b/drivers/regulator/max8952.c
index 0d5dda4fd911..a8f4ecfb0843 100644
--- a/drivers/regulator/max8952.c
+++ b/drivers/regulator/max8952.c
@@ -133,7 +133,7 @@ static int max8952_get_voltage(struct regulator_dev *rdev)
133} 133}
134 134
135static int max8952_set_voltage(struct regulator_dev *rdev, 135static int max8952_set_voltage(struct regulator_dev *rdev,
136 int min_uV, int max_uV) 136 int min_uV, int max_uV, unsigned *selector)
137{ 137{
138 struct max8952_data *max8952 = rdev_get_drvdata(rdev); 138 struct max8952_data *max8952 = rdev_get_drvdata(rdev);
139 s8 vid = -1, i; 139 s8 vid = -1, i;
@@ -156,6 +156,7 @@ static int max8952_set_voltage(struct regulator_dev *rdev,
156 if (vid >= 0 && vid < MAX8952_NUM_DVS_MODE) { 156 if (vid >= 0 && vid < MAX8952_NUM_DVS_MODE) {
157 max8952->vid0 = (vid % 2 == 1); 157 max8952->vid0 = (vid % 2 == 1);
158 max8952->vid1 = (((vid >> 1) % 2) == 1); 158 max8952->vid1 = (((vid >> 1) % 2) == 1);
159 *selector = vid;
159 gpio_set_value(max8952->pdata->gpio_vid0, max8952->vid0); 160 gpio_set_value(max8952->pdata->gpio_vid0, max8952->vid0);
160 gpio_set_value(max8952->pdata->gpio_vid1, max8952->vid1); 161 gpio_set_value(max8952->pdata->gpio_vid1, max8952->vid1);
161 } else 162 } else
diff --git a/drivers/regulator/max8998.c b/drivers/regulator/max8998.c
index 5c20756db607..7568df6122ab 100644
--- a/drivers/regulator/max8998.c
+++ b/drivers/regulator/max8998.c
@@ -304,7 +304,7 @@ static int max8998_get_voltage(struct regulator_dev *rdev)
304} 304}
305 305
306static int max8998_set_voltage_ldo(struct regulator_dev *rdev, 306static int max8998_set_voltage_ldo(struct regulator_dev *rdev,
307 int min_uV, int max_uV) 307 int min_uV, int max_uV, unsigned *selector)
308{ 308{
309 struct max8998_data *max8998 = rdev_get_drvdata(rdev); 309 struct max8998_data *max8998 = rdev_get_drvdata(rdev);
310 struct i2c_client *i2c = max8998->iodev->i2c; 310 struct i2c_client *i2c = max8998->iodev->i2c;
@@ -331,6 +331,8 @@ static int max8998_set_voltage_ldo(struct regulator_dev *rdev,
331 if (desc->min + desc->step*i > max_vol) 331 if (desc->min + desc->step*i > max_vol)
332 return -EINVAL; 332 return -EINVAL;
333 333
334 *selector = i;
335
334 ret = max8998_get_voltage_register(rdev, &reg, &shift, &mask); 336 ret = max8998_get_voltage_register(rdev, &reg, &shift, &mask);
335 if (ret) 337 if (ret)
336 return ret; 338 return ret;
@@ -352,7 +354,7 @@ static inline void buck2_gpio_set(int gpio, int v)
352} 354}
353 355
354static int max8998_set_voltage_buck(struct regulator_dev *rdev, 356static int max8998_set_voltage_buck(struct regulator_dev *rdev,
355 int min_uV, int max_uV) 357 int min_uV, int max_uV, unsigned *selector)
356{ 358{
357 struct max8998_data *max8998 = rdev_get_drvdata(rdev); 359 struct max8998_data *max8998 = rdev_get_drvdata(rdev);
358 struct max8998_platform_data *pdata = 360 struct max8998_platform_data *pdata =
@@ -384,6 +386,8 @@ static int max8998_set_voltage_buck(struct regulator_dev *rdev,
384 if (desc->min + desc->step*i > max_vol) 386 if (desc->min + desc->step*i > max_vol)
385 return -EINVAL; 387 return -EINVAL;
386 388
389 *selector = i;
390
387 ret = max8998_get_voltage_register(rdev, &reg, &shift, &mask); 391 ret = max8998_get_voltage_register(rdev, &reg, &shift, &mask);
388 if (ret) 392 if (ret)
389 return ret; 393 return ret;
diff --git a/drivers/regulator/mc13783-regulator.c b/drivers/regulator/mc13783-regulator.c
index ecd99f59dba8..3e5d0c3b4e53 100644
--- a/drivers/regulator/mc13783-regulator.c
+++ b/drivers/regulator/mc13783-regulator.c
@@ -1,6 +1,7 @@
1/* 1/*
2 * Regulator Driver for Freescale MC13783 PMIC 2 * Regulator Driver for Freescale MC13783 PMIC
3 * 3 *
4 * Copyright 2010 Yong Shen <yong.shen@linaro.org>
4 * Copyright (C) 2008 Sascha Hauer, Pengutronix <s.hauer@pengutronix.de> 5 * Copyright (C) 2008 Sascha Hauer, Pengutronix <s.hauer@pengutronix.de>
5 * Copyright 2009 Alberto Panizzo <maramaopercheseimorto@gmail.com> 6 * Copyright 2009 Alberto Panizzo <maramaopercheseimorto@gmail.com>
6 * 7 *
@@ -17,6 +18,7 @@
17#include <linux/slab.h> 18#include <linux/slab.h>
18#include <linux/init.h> 19#include <linux/init.h>
19#include <linux/err.h> 20#include <linux/err.h>
21#include "mc13xxx.h"
20 22
21#define MC13783_REG_SWITCHERS5 29 23#define MC13783_REG_SWITCHERS5 29
22#define MC13783_REG_SWITCHERS5_SW3EN (1 << 20) 24#define MC13783_REG_SWITCHERS5_SW3EN (1 << 20)
@@ -89,154 +91,106 @@
89#define MC13783_REG_POWERMISC_PWGTSPI_M (3 << 15) 91#define MC13783_REG_POWERMISC_PWGTSPI_M (3 << 15)
90 92
91 93
92struct mc13783_regulator {
93 struct regulator_desc desc;
94 int reg;
95 int enable_bit;
96 int vsel_reg;
97 int vsel_shift;
98 int vsel_mask;
99 int const *voltages;
100};
101
102/* Voltage Values */ 94/* Voltage Values */
103static const int const mc13783_sw3_val[] = { 95static const int mc13783_sw3_val[] = {
104 5000000, 5000000, 5000000, 5500000, 96 5000000, 5000000, 5000000, 5500000,
105}; 97};
106 98
107static const int const mc13783_vaudio_val[] = { 99static const int mc13783_vaudio_val[] = {
108 2775000, 100 2775000,
109}; 101};
110 102
111static const int const mc13783_viohi_val[] = { 103static const int mc13783_viohi_val[] = {
112 2775000, 104 2775000,
113}; 105};
114 106
115static const int const mc13783_violo_val[] = { 107static const int mc13783_violo_val[] = {
116 1200000, 1300000, 1500000, 1800000, 108 1200000, 1300000, 1500000, 1800000,
117}; 109};
118 110
119static const int const mc13783_vdig_val[] = { 111static const int mc13783_vdig_val[] = {
120 1200000, 1300000, 1500000, 1800000, 112 1200000, 1300000, 1500000, 1800000,
121}; 113};
122 114
123static const int const mc13783_vgen_val[] = { 115static const int mc13783_vgen_val[] = {
124 1200000, 1300000, 1500000, 1800000, 116 1200000, 1300000, 1500000, 1800000,
125 1100000, 2000000, 2775000, 2400000, 117 1100000, 2000000, 2775000, 2400000,
126}; 118};
127 119
128static const int const mc13783_vrfdig_val[] = { 120static const int mc13783_vrfdig_val[] = {
129 1200000, 1500000, 1800000, 1875000, 121 1200000, 1500000, 1800000, 1875000,
130}; 122};
131 123
132static const int const mc13783_vrfref_val[] = { 124static const int mc13783_vrfref_val[] = {
133 2475000, 2600000, 2700000, 2775000, 125 2475000, 2600000, 2700000, 2775000,
134}; 126};
135 127
136static const int const mc13783_vrfcp_val[] = { 128static const int mc13783_vrfcp_val[] = {
137 2700000, 2775000, 129 2700000, 2775000,
138}; 130};
139 131
140static const int const mc13783_vsim_val[] = { 132static const int mc13783_vsim_val[] = {
141 1800000, 2900000, 3000000, 133 1800000, 2900000, 3000000,
142}; 134};
143 135
144static const int const mc13783_vesim_val[] = { 136static const int mc13783_vesim_val[] = {
145 1800000, 2900000, 137 1800000, 2900000,
146}; 138};
147 139
148static const int const mc13783_vcam_val[] = { 140static const int mc13783_vcam_val[] = {
149 1500000, 1800000, 2500000, 2550000, 141 1500000, 1800000, 2500000, 2550000,
150 2600000, 2750000, 2800000, 3000000, 142 2600000, 2750000, 2800000, 3000000,
151}; 143};
152 144
153static const int const mc13783_vrfbg_val[] = { 145static const int mc13783_vrfbg_val[] = {
154 1250000, 146 1250000,
155}; 147};
156 148
157static const int const mc13783_vvib_val[] = { 149static const int mc13783_vvib_val[] = {
158 1300000, 1800000, 2000000, 3000000, 150 1300000, 1800000, 2000000, 3000000,
159}; 151};
160 152
161static const int const mc13783_vmmc_val[] = { 153static const int mc13783_vmmc_val[] = {
162 1600000, 1800000, 2000000, 2600000, 154 1600000, 1800000, 2000000, 2600000,
163 2700000, 2800000, 2900000, 3000000, 155 2700000, 2800000, 2900000, 3000000,
164}; 156};
165 157
166static const int const mc13783_vrf_val[] = { 158static const int mc13783_vrf_val[] = {
167 1500000, 1875000, 2700000, 2775000, 159 1500000, 1875000, 2700000, 2775000,
168}; 160};
169 161
170static const int const mc13783_gpo_val[] = { 162static const int mc13783_gpo_val[] = {
171 3100000, 163 3100000,
172}; 164};
173 165
174static const int const mc13783_pwgtdrv_val[] = { 166static const int mc13783_pwgtdrv_val[] = {
175 5500000, 167 5500000,
176}; 168};
177 169
178static struct regulator_ops mc13783_regulator_ops;
179static struct regulator_ops mc13783_fixed_regulator_ops;
180static struct regulator_ops mc13783_gpo_regulator_ops; 170static struct regulator_ops mc13783_gpo_regulator_ops;
181 171
182#define MC13783_DEFINE(prefix, _name, _reg, _vsel_reg, _voltages) \ 172#define MC13783_DEFINE(prefix, name, reg, vsel_reg, voltages) \
183 [MC13783_ ## prefix ## _ ## _name] = { \ 173 MC13xxx_DEFINE(MC13783_REG_, name, reg, vsel_reg, voltages, \
184 .desc = { \ 174 mc13xxx_regulator_ops)
185 .name = #prefix "_" #_name, \
186 .n_voltages = ARRAY_SIZE(_voltages), \
187 .ops = &mc13783_regulator_ops, \
188 .type = REGULATOR_VOLTAGE, \
189 .id = MC13783_ ## prefix ## _ ## _name, \
190 .owner = THIS_MODULE, \
191 }, \
192 .reg = MC13783_REG_ ## _reg, \
193 .enable_bit = MC13783_REG_ ## _reg ## _ ## _name ## EN, \
194 .vsel_reg = MC13783_REG_ ## _vsel_reg, \
195 .vsel_shift = MC13783_REG_ ## _vsel_reg ## _ ## _name ## VSEL,\
196 .vsel_mask = MC13783_REG_ ## _vsel_reg ## _ ## _name ## VSEL_M,\
197 .voltages = _voltages, \
198 }
199 175
200#define MC13783_FIXED_DEFINE(prefix, _name, _reg, _voltages) \ 176#define MC13783_FIXED_DEFINE(prefix, name, reg, voltages) \
201 [MC13783_ ## prefix ## _ ## _name] = { \ 177 MC13xxx_FIXED_DEFINE(MC13783_REG_, name, reg, voltages, \
202 .desc = { \ 178 mc13xxx_fixed_regulator_ops)
203 .name = #prefix "_" #_name, \
204 .n_voltages = ARRAY_SIZE(_voltages), \
205 .ops = &mc13783_fixed_regulator_ops, \
206 .type = REGULATOR_VOLTAGE, \
207 .id = MC13783_ ## prefix ## _ ## _name, \
208 .owner = THIS_MODULE, \
209 }, \
210 .reg = MC13783_REG_ ## _reg, \
211 .enable_bit = MC13783_REG_ ## _reg ## _ ## _name ## EN, \
212 .voltages = _voltages, \
213 }
214 179
215#define MC13783_GPO_DEFINE(prefix, _name, _reg, _voltages) \ 180#define MC13783_GPO_DEFINE(prefix, name, reg, voltages) \
216 [MC13783_ ## prefix ## _ ## _name] = { \ 181 MC13xxx_GPO_DEFINE(MC13783_REG_, name, reg, voltages, \
217 .desc = { \ 182 mc13783_gpo_regulator_ops)
218 .name = #prefix "_" #_name, \
219 .n_voltages = ARRAY_SIZE(_voltages), \
220 .ops = &mc13783_gpo_regulator_ops, \
221 .type = REGULATOR_VOLTAGE, \
222 .id = MC13783_ ## prefix ## _ ## _name, \
223 .owner = THIS_MODULE, \
224 }, \
225 .reg = MC13783_REG_ ## _reg, \
226 .enable_bit = MC13783_REG_ ## _reg ## _ ## _name ## EN, \
227 .voltages = _voltages, \
228 }
229 183
230#define MC13783_DEFINE_SW(_name, _reg, _vsel_reg, _voltages) \ 184#define MC13783_DEFINE_SW(_name, _reg, _vsel_reg, _voltages) \
231 MC13783_DEFINE(SW, _name, _reg, _vsel_reg, _voltages) 185 MC13783_DEFINE(REG, _name, _reg, _vsel_reg, _voltages)
232#define MC13783_DEFINE_REGU(_name, _reg, _vsel_reg, _voltages) \ 186#define MC13783_DEFINE_REGU(_name, _reg, _vsel_reg, _voltages) \
233 MC13783_DEFINE(REGU, _name, _reg, _vsel_reg, _voltages) 187 MC13783_DEFINE(REG, _name, _reg, _vsel_reg, _voltages)
234 188
235static struct mc13783_regulator mc13783_regulators[] = { 189static struct mc13xxx_regulator mc13783_regulators[] = {
236 MC13783_DEFINE_SW(SW3, SWITCHERS5, SWITCHERS5, mc13783_sw3_val), 190 MC13783_DEFINE_SW(SW3, SWITCHERS5, SWITCHERS5, mc13783_sw3_val),
237 191
238 MC13783_FIXED_DEFINE(REGU, VAUDIO, REGULATORMODE0, mc13783_vaudio_val), 192 MC13783_FIXED_DEFINE(REG, VAUDIO, REGULATORMODE0, mc13783_vaudio_val),
239 MC13783_FIXED_DEFINE(REGU, VIOHI, REGULATORMODE0, mc13783_viohi_val), 193 MC13783_FIXED_DEFINE(REG, VIOHI, REGULATORMODE0, mc13783_viohi_val),
240 MC13783_DEFINE_REGU(VIOLO, REGULATORMODE0, REGULATORSETTING0, \ 194 MC13783_DEFINE_REGU(VIOLO, REGULATORMODE0, REGULATORSETTING0, \
241 mc13783_violo_val), 195 mc13783_violo_val),
242 MC13783_DEFINE_REGU(VDIG, REGULATORMODE0, REGULATORSETTING0, \ 196 MC13783_DEFINE_REGU(VDIG, REGULATORMODE0, REGULATORSETTING0, \
@@ -255,7 +209,7 @@ static struct mc13783_regulator mc13783_regulators[] = {
255 mc13783_vesim_val), 209 mc13783_vesim_val),
256 MC13783_DEFINE_REGU(VCAM, REGULATORMODE1, REGULATORSETTING0, \ 210 MC13783_DEFINE_REGU(VCAM, REGULATORMODE1, REGULATORSETTING0, \
257 mc13783_vcam_val), 211 mc13783_vcam_val),
258 MC13783_FIXED_DEFINE(REGU, VRFBG, REGULATORMODE1, mc13783_vrfbg_val), 212 MC13783_FIXED_DEFINE(REG, VRFBG, REGULATORMODE1, mc13783_vrfbg_val),
259 MC13783_DEFINE_REGU(VVIB, REGULATORMODE1, REGULATORSETTING1, \ 213 MC13783_DEFINE_REGU(VVIB, REGULATORMODE1, REGULATORSETTING1, \
260 mc13783_vvib_val), 214 mc13783_vvib_val),
261 MC13783_DEFINE_REGU(VRF1, REGULATORMODE1, REGULATORSETTING1, \ 215 MC13783_DEFINE_REGU(VRF1, REGULATORMODE1, REGULATORSETTING1, \
@@ -266,215 +220,24 @@ static struct mc13783_regulator mc13783_regulators[] = {
266 mc13783_vmmc_val), 220 mc13783_vmmc_val),
267 MC13783_DEFINE_REGU(VMMC2, REGULATORMODE1, REGULATORSETTING1, \ 221 MC13783_DEFINE_REGU(VMMC2, REGULATORMODE1, REGULATORSETTING1, \
268 mc13783_vmmc_val), 222 mc13783_vmmc_val),
269 MC13783_GPO_DEFINE(REGU, GPO1, POWERMISC, mc13783_gpo_val), 223 MC13783_GPO_DEFINE(REG, GPO1, POWERMISC, mc13783_gpo_val),
270 MC13783_GPO_DEFINE(REGU, GPO2, POWERMISC, mc13783_gpo_val), 224 MC13783_GPO_DEFINE(REG, GPO2, POWERMISC, mc13783_gpo_val),
271 MC13783_GPO_DEFINE(REGU, GPO3, POWERMISC, mc13783_gpo_val), 225 MC13783_GPO_DEFINE(REG, GPO3, POWERMISC, mc13783_gpo_val),
272 MC13783_GPO_DEFINE(REGU, GPO4, POWERMISC, mc13783_gpo_val), 226 MC13783_GPO_DEFINE(REG, GPO4, POWERMISC, mc13783_gpo_val),
273 MC13783_GPO_DEFINE(REGU, PWGT1SPI, POWERMISC, mc13783_pwgtdrv_val), 227 MC13783_GPO_DEFINE(REG, PWGT1SPI, POWERMISC, mc13783_pwgtdrv_val),
274 MC13783_GPO_DEFINE(REGU, PWGT2SPI, POWERMISC, mc13783_pwgtdrv_val), 228 MC13783_GPO_DEFINE(REG, PWGT2SPI, POWERMISC, mc13783_pwgtdrv_val),
275};
276
277struct mc13783_regulator_priv {
278 struct mc13783 *mc13783;
279 u32 powermisc_pwgt_state;
280 struct regulator_dev *regulators[];
281};
282
283static int mc13783_regulator_enable(struct regulator_dev *rdev)
284{
285 struct mc13783_regulator_priv *priv = rdev_get_drvdata(rdev);
286 int id = rdev_get_id(rdev);
287 int ret;
288
289 dev_dbg(rdev_get_dev(rdev), "%s id: %d\n", __func__, id);
290
291 mc13783_lock(priv->mc13783);
292 ret = mc13783_reg_rmw(priv->mc13783, mc13783_regulators[id].reg,
293 mc13783_regulators[id].enable_bit,
294 mc13783_regulators[id].enable_bit);
295 mc13783_unlock(priv->mc13783);
296
297 return ret;
298}
299
300static int mc13783_regulator_disable(struct regulator_dev *rdev)
301{
302 struct mc13783_regulator_priv *priv = rdev_get_drvdata(rdev);
303 int id = rdev_get_id(rdev);
304 int ret;
305
306 dev_dbg(rdev_get_dev(rdev), "%s id: %d\n", __func__, id);
307
308 mc13783_lock(priv->mc13783);
309 ret = mc13783_reg_rmw(priv->mc13783, mc13783_regulators[id].reg,
310 mc13783_regulators[id].enable_bit, 0);
311 mc13783_unlock(priv->mc13783);
312
313 return ret;
314}
315
316static int mc13783_regulator_is_enabled(struct regulator_dev *rdev)
317{
318 struct mc13783_regulator_priv *priv = rdev_get_drvdata(rdev);
319 int ret, id = rdev_get_id(rdev);
320 unsigned int val;
321
322 mc13783_lock(priv->mc13783);
323 ret = mc13783_reg_read(priv->mc13783, mc13783_regulators[id].reg, &val);
324 mc13783_unlock(priv->mc13783);
325
326 if (ret)
327 return ret;
328
329 return (val & mc13783_regulators[id].enable_bit) != 0;
330}
331
332static int mc13783_regulator_list_voltage(struct regulator_dev *rdev,
333 unsigned selector)
334{
335 int id = rdev_get_id(rdev);
336
337 if (selector >= mc13783_regulators[id].desc.n_voltages)
338 return -EINVAL;
339
340 return mc13783_regulators[id].voltages[selector];
341}
342
343static int mc13783_get_best_voltage_index(struct regulator_dev *rdev,
344 int min_uV, int max_uV)
345{
346 int reg_id = rdev_get_id(rdev);
347 int i;
348 int bestmatch;
349 int bestindex;
350
351 /*
352 * Locate the minimum voltage fitting the criteria on
353 * this regulator. The switchable voltages are not
354 * in strict falling order so we need to check them
355 * all for the best match.
356 */
357 bestmatch = INT_MAX;
358 bestindex = -1;
359 for (i = 0; i < mc13783_regulators[reg_id].desc.n_voltages; i++) {
360 if (mc13783_regulators[reg_id].voltages[i] >= min_uV &&
361 mc13783_regulators[reg_id].voltages[i] < bestmatch) {
362 bestmatch = mc13783_regulators[reg_id].voltages[i];
363 bestindex = i;
364 }
365 }
366
367 if (bestindex < 0 || bestmatch > max_uV) {
368 dev_warn(&rdev->dev, "no possible value for %d<=x<=%d uV\n",
369 min_uV, max_uV);
370 return -EINVAL;
371 }
372 return bestindex;
373}
374
375static int mc13783_regulator_set_voltage(struct regulator_dev *rdev,
376 int min_uV, int max_uV)
377{
378 struct mc13783_regulator_priv *priv = rdev_get_drvdata(rdev);
379 int value, id = rdev_get_id(rdev);
380 int ret;
381
382 dev_dbg(rdev_get_dev(rdev), "%s id: %d min_uV: %d max_uV: %d\n",
383 __func__, id, min_uV, max_uV);
384
385 /* Find the best index */
386 value = mc13783_get_best_voltage_index(rdev, min_uV, max_uV);
387 dev_dbg(rdev_get_dev(rdev), "%s best value: %d \n", __func__, value);
388 if (value < 0)
389 return value;
390
391 mc13783_lock(priv->mc13783);
392 ret = mc13783_reg_rmw(priv->mc13783, mc13783_regulators[id].vsel_reg,
393 mc13783_regulators[id].vsel_mask,
394 value << mc13783_regulators[id].vsel_shift);
395 mc13783_unlock(priv->mc13783);
396
397 return ret;
398}
399
400static int mc13783_regulator_get_voltage(struct regulator_dev *rdev)
401{
402 struct mc13783_regulator_priv *priv = rdev_get_drvdata(rdev);
403 int ret, id = rdev_get_id(rdev);
404 unsigned int val;
405
406 dev_dbg(rdev_get_dev(rdev), "%s id: %d\n", __func__, id);
407
408 mc13783_lock(priv->mc13783);
409 ret = mc13783_reg_read(priv->mc13783,
410 mc13783_regulators[id].vsel_reg, &val);
411 mc13783_unlock(priv->mc13783);
412
413 if (ret)
414 return ret;
415
416 val = (val & mc13783_regulators[id].vsel_mask)
417 >> mc13783_regulators[id].vsel_shift;
418
419 dev_dbg(rdev_get_dev(rdev), "%s id: %d val: %d\n", __func__, id, val);
420
421 BUG_ON(val < 0 || val > mc13783_regulators[id].desc.n_voltages);
422
423 return mc13783_regulators[id].voltages[val];
424}
425
426static struct regulator_ops mc13783_regulator_ops = {
427 .enable = mc13783_regulator_enable,
428 .disable = mc13783_regulator_disable,
429 .is_enabled = mc13783_regulator_is_enabled,
430 .list_voltage = mc13783_regulator_list_voltage,
431 .set_voltage = mc13783_regulator_set_voltage,
432 .get_voltage = mc13783_regulator_get_voltage,
433};
434
435static int mc13783_fixed_regulator_set_voltage(struct regulator_dev *rdev,
436 int min_uV, int max_uV)
437{
438 int id = rdev_get_id(rdev);
439
440 dev_dbg(rdev_get_dev(rdev), "%s id: %d min_uV: %d max_uV: %d\n",
441 __func__, id, min_uV, max_uV);
442
443 if (min_uV >= mc13783_regulators[id].voltages[0] &&
444 max_uV <= mc13783_regulators[id].voltages[0])
445 return 0;
446 else
447 return -EINVAL;
448}
449
450static int mc13783_fixed_regulator_get_voltage(struct regulator_dev *rdev)
451{
452 int id = rdev_get_id(rdev);
453
454 dev_dbg(rdev_get_dev(rdev), "%s id: %d\n", __func__, id);
455
456 return mc13783_regulators[id].voltages[0];
457}
458
459static struct regulator_ops mc13783_fixed_regulator_ops = {
460 .enable = mc13783_regulator_enable,
461 .disable = mc13783_regulator_disable,
462 .is_enabled = mc13783_regulator_is_enabled,
463 .list_voltage = mc13783_regulator_list_voltage,
464 .set_voltage = mc13783_fixed_regulator_set_voltage,
465 .get_voltage = mc13783_fixed_regulator_get_voltage,
466}; 229};
467 230
468static int mc13783_powermisc_rmw(struct mc13783_regulator_priv *priv, u32 mask, 231static int mc13783_powermisc_rmw(struct mc13xxx_regulator_priv *priv, u32 mask,
469 u32 val) 232 u32 val)
470{ 233{
471 struct mc13783 *mc13783 = priv->mc13783; 234 struct mc13xxx *mc13783 = priv->mc13xxx;
472 int ret; 235 int ret;
473 u32 valread; 236 u32 valread;
474 237
475 BUG_ON(val & ~mask); 238 BUG_ON(val & ~mask);
476 239
477 ret = mc13783_reg_read(mc13783, MC13783_REG_POWERMISC, &valread); 240 ret = mc13xxx_reg_read(mc13783, MC13783_REG_POWERMISC, &valread);
478 if (ret) 241 if (ret)
479 return ret; 242 return ret;
480 243
@@ -489,34 +252,36 @@ static int mc13783_powermisc_rmw(struct mc13783_regulator_priv *priv, u32 mask,
489 valread = (valread & ~MC13783_REG_POWERMISC_PWGTSPI_M) | 252 valread = (valread & ~MC13783_REG_POWERMISC_PWGTSPI_M) |
490 priv->powermisc_pwgt_state; 253 priv->powermisc_pwgt_state;
491 254
492 return mc13783_reg_write(mc13783, MC13783_REG_POWERMISC, valread); 255 return mc13xxx_reg_write(mc13783, MC13783_REG_POWERMISC, valread);
493} 256}
494 257
495static int mc13783_gpo_regulator_enable(struct regulator_dev *rdev) 258static int mc13783_gpo_regulator_enable(struct regulator_dev *rdev)
496{ 259{
497 struct mc13783_regulator_priv *priv = rdev_get_drvdata(rdev); 260 struct mc13xxx_regulator_priv *priv = rdev_get_drvdata(rdev);
261 struct mc13xxx_regulator *mc13xxx_regulators = priv->mc13xxx_regulators;
498 int id = rdev_get_id(rdev); 262 int id = rdev_get_id(rdev);
499 int ret; 263 int ret;
500 u32 en_val = mc13783_regulators[id].enable_bit; 264 u32 en_val = mc13xxx_regulators[id].enable_bit;
501 265
502 dev_dbg(rdev_get_dev(rdev), "%s id: %d\n", __func__, id); 266 dev_dbg(rdev_get_dev(rdev), "%s id: %d\n", __func__, id);
503 267
504 /* Power Gate enable value is 0 */ 268 /* Power Gate enable value is 0 */
505 if (id == MC13783_REGU_PWGT1SPI || 269 if (id == MC13783_REG_PWGT1SPI ||
506 id == MC13783_REGU_PWGT2SPI) 270 id == MC13783_REG_PWGT2SPI)
507 en_val = 0; 271 en_val = 0;
508 272
509 mc13783_lock(priv->mc13783); 273 mc13xxx_lock(priv->mc13xxx);
510 ret = mc13783_powermisc_rmw(priv, mc13783_regulators[id].enable_bit, 274 ret = mc13783_powermisc_rmw(priv, mc13xxx_regulators[id].enable_bit,
511 en_val); 275 en_val);
512 mc13783_unlock(priv->mc13783); 276 mc13xxx_unlock(priv->mc13xxx);
513 277
514 return ret; 278 return ret;
515} 279}
516 280
517static int mc13783_gpo_regulator_disable(struct regulator_dev *rdev) 281static int mc13783_gpo_regulator_disable(struct regulator_dev *rdev)
518{ 282{
519 struct mc13783_regulator_priv *priv = rdev_get_drvdata(rdev); 283 struct mc13xxx_regulator_priv *priv = rdev_get_drvdata(rdev);
284 struct mc13xxx_regulator *mc13xxx_regulators = priv->mc13xxx_regulators;
520 int id = rdev_get_id(rdev); 285 int id = rdev_get_id(rdev);
521 int ret; 286 int ret;
522 u32 dis_val = 0; 287 u32 dis_val = 0;
@@ -524,27 +289,28 @@ static int mc13783_gpo_regulator_disable(struct regulator_dev *rdev)
524 dev_dbg(rdev_get_dev(rdev), "%s id: %d\n", __func__, id); 289 dev_dbg(rdev_get_dev(rdev), "%s id: %d\n", __func__, id);
525 290
526 /* Power Gate disable value is 1 */ 291 /* Power Gate disable value is 1 */
527 if (id == MC13783_REGU_PWGT1SPI || 292 if (id == MC13783_REG_PWGT1SPI ||
528 id == MC13783_REGU_PWGT2SPI) 293 id == MC13783_REG_PWGT2SPI)
529 dis_val = mc13783_regulators[id].enable_bit; 294 dis_val = mc13xxx_regulators[id].enable_bit;
530 295
531 mc13783_lock(priv->mc13783); 296 mc13xxx_lock(priv->mc13xxx);
532 ret = mc13783_powermisc_rmw(priv, mc13783_regulators[id].enable_bit, 297 ret = mc13783_powermisc_rmw(priv, mc13xxx_regulators[id].enable_bit,
533 dis_val); 298 dis_val);
534 mc13783_unlock(priv->mc13783); 299 mc13xxx_unlock(priv->mc13xxx);
535 300
536 return ret; 301 return ret;
537} 302}
538 303
539static int mc13783_gpo_regulator_is_enabled(struct regulator_dev *rdev) 304static int mc13783_gpo_regulator_is_enabled(struct regulator_dev *rdev)
540{ 305{
541 struct mc13783_regulator_priv *priv = rdev_get_drvdata(rdev); 306 struct mc13xxx_regulator_priv *priv = rdev_get_drvdata(rdev);
307 struct mc13xxx_regulator *mc13xxx_regulators = priv->mc13xxx_regulators;
542 int ret, id = rdev_get_id(rdev); 308 int ret, id = rdev_get_id(rdev);
543 unsigned int val; 309 unsigned int val;
544 310
545 mc13783_lock(priv->mc13783); 311 mc13xxx_lock(priv->mc13xxx);
546 ret = mc13783_reg_read(priv->mc13783, mc13783_regulators[id].reg, &val); 312 ret = mc13xxx_reg_read(priv->mc13xxx, mc13xxx_regulators[id].reg, &val);
547 mc13783_unlock(priv->mc13783); 313 mc13xxx_unlock(priv->mc13xxx);
548 314
549 if (ret) 315 if (ret)
550 return ret; 316 return ret;
@@ -554,22 +320,22 @@ static int mc13783_gpo_regulator_is_enabled(struct regulator_dev *rdev)
554 val = (val & ~MC13783_REG_POWERMISC_PWGTSPI_M) | 320 val = (val & ~MC13783_REG_POWERMISC_PWGTSPI_M) |
555 (priv->powermisc_pwgt_state ^ MC13783_REG_POWERMISC_PWGTSPI_M); 321 (priv->powermisc_pwgt_state ^ MC13783_REG_POWERMISC_PWGTSPI_M);
556 322
557 return (val & mc13783_regulators[id].enable_bit) != 0; 323 return (val & mc13xxx_regulators[id].enable_bit) != 0;
558} 324}
559 325
560static struct regulator_ops mc13783_gpo_regulator_ops = { 326static struct regulator_ops mc13783_gpo_regulator_ops = {
561 .enable = mc13783_gpo_regulator_enable, 327 .enable = mc13783_gpo_regulator_enable,
562 .disable = mc13783_gpo_regulator_disable, 328 .disable = mc13783_gpo_regulator_disable,
563 .is_enabled = mc13783_gpo_regulator_is_enabled, 329 .is_enabled = mc13783_gpo_regulator_is_enabled,
564 .list_voltage = mc13783_regulator_list_voltage, 330 .list_voltage = mc13xxx_regulator_list_voltage,
565 .set_voltage = mc13783_fixed_regulator_set_voltage, 331 .set_voltage = mc13xxx_fixed_regulator_set_voltage,
566 .get_voltage = mc13783_fixed_regulator_get_voltage, 332 .get_voltage = mc13xxx_fixed_regulator_get_voltage,
567}; 333};
568 334
569static int __devinit mc13783_regulator_probe(struct platform_device *pdev) 335static int __devinit mc13783_regulator_probe(struct platform_device *pdev)
570{ 336{
571 struct mc13783_regulator_priv *priv; 337 struct mc13xxx_regulator_priv *priv;
572 struct mc13783 *mc13783 = dev_get_drvdata(pdev->dev.parent); 338 struct mc13xxx *mc13783 = dev_get_drvdata(pdev->dev.parent);
573 struct mc13783_regulator_platform_data *pdata = 339 struct mc13783_regulator_platform_data *pdata =
574 dev_get_platdata(&pdev->dev); 340 dev_get_platdata(&pdev->dev);
575 struct mc13783_regulator_init_data *init_data; 341 struct mc13783_regulator_init_data *init_data;
@@ -583,7 +349,8 @@ static int __devinit mc13783_regulator_probe(struct platform_device *pdev)
583 if (!priv) 349 if (!priv)
584 return -ENOMEM; 350 return -ENOMEM;
585 351
586 priv->mc13783 = mc13783; 352 priv->mc13xxx_regulators = mc13783_regulators;
353 priv->mc13xxx = mc13783;
587 354
588 for (i = 0; i < pdata->num_regulators; i++) { 355 for (i = 0; i < pdata->num_regulators; i++) {
589 init_data = &pdata->regulators[i]; 356 init_data = &pdata->regulators[i];
@@ -613,7 +380,7 @@ err:
613 380
614static int __devexit mc13783_regulator_remove(struct platform_device *pdev) 381static int __devexit mc13783_regulator_remove(struct platform_device *pdev)
615{ 382{
616 struct mc13783_regulator_priv *priv = platform_get_drvdata(pdev); 383 struct mc13xxx_regulator_priv *priv = platform_get_drvdata(pdev);
617 struct mc13783_regulator_platform_data *pdata = 384 struct mc13783_regulator_platform_data *pdata =
618 dev_get_platdata(&pdev->dev); 385 dev_get_platdata(&pdev->dev);
619 int i; 386 int i;
diff --git a/drivers/regulator/mc13892-regulator.c b/drivers/regulator/mc13892-regulator.c
new file mode 100644
index 000000000000..1b8f7398a4a8
--- /dev/null
+++ b/drivers/regulator/mc13892-regulator.c
@@ -0,0 +1,635 @@
1/*
2 * Regulator Driver for Freescale MC13892 PMIC
3 *
4 * Copyright 2010 Yong Shen <yong.shen@linaro.org>
5 *
6 * Based on draft driver from Arnaud Patard <arnaud.patard@rtp-net.org>
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/mfd/mc13892.h>
14#include <linux/regulator/machine.h>
15#include <linux/regulator/driver.h>
16#include <linux/platform_device.h>
17#include <linux/kernel.h>
18#include <linux/slab.h>
19#include <linux/init.h>
20#include <linux/err.h>
21#include "mc13xxx.h"
22
23#define MC13892_REVISION 7
24
25#define MC13892_POWERCTL0 13
26#define MC13892_POWERCTL0_USEROFFSPI 3
27#define MC13892_POWERCTL0_VCOINCELLVSEL 20
28#define MC13892_POWERCTL0_VCOINCELLVSEL_M (7<<20)
29#define MC13892_POWERCTL0_VCOINCELLEN (1<<23)
30
31#define MC13892_SWITCHERS0_SWxHI (1<<23)
32
33#define MC13892_SWITCHERS0 24
34#define MC13892_SWITCHERS0_SW1VSEL 0
35#define MC13892_SWITCHERS0_SW1VSEL_M (0x1f<<0)
36#define MC13892_SWITCHERS0_SW1HI (1<<23)
37#define MC13892_SWITCHERS0_SW1EN 0
38
39#define MC13892_SWITCHERS1 25
40#define MC13892_SWITCHERS1_SW2VSEL 0
41#define MC13892_SWITCHERS1_SW2VSEL_M (0x1f<<0)
42#define MC13892_SWITCHERS1_SW2HI (1<<23)
43#define MC13892_SWITCHERS1_SW2EN 0
44
45#define MC13892_SWITCHERS2 26
46#define MC13892_SWITCHERS2_SW3VSEL 0
47#define MC13892_SWITCHERS2_SW3VSEL_M (0x1f<<0)
48#define MC13892_SWITCHERS2_SW3HI (1<<23)
49#define MC13892_SWITCHERS2_SW3EN 0
50
51#define MC13892_SWITCHERS3 27
52#define MC13892_SWITCHERS3_SW4VSEL 0
53#define MC13892_SWITCHERS3_SW4VSEL_M (0x1f<<0)
54#define MC13892_SWITCHERS3_SW4HI (1<<23)
55#define MC13892_SWITCHERS3_SW4EN 0
56
57#define MC13892_SWITCHERS4 28
58#define MC13892_SWITCHERS4_SW1MODE 0
59#define MC13892_SWITCHERS4_SW1MODE_AUTO (8<<0)
60#define MC13892_SWITCHERS4_SW1MODE_M (0xf<<0)
61#define MC13892_SWITCHERS4_SW2MODE 10
62#define MC13892_SWITCHERS4_SW2MODE_AUTO (8<<10)
63#define MC13892_SWITCHERS4_SW2MODE_M (0xf<<10)
64
65#define MC13892_SWITCHERS5 29
66#define MC13892_SWITCHERS5_SW3MODE 0
67#define MC13892_SWITCHERS5_SW3MODE_AUTO (8<<0)
68#define MC13892_SWITCHERS5_SW3MODE_M (0xf<<0)
69#define MC13892_SWITCHERS5_SW4MODE 8
70#define MC13892_SWITCHERS5_SW4MODE_AUTO (8<<8)
71#define MC13892_SWITCHERS5_SW4MODE_M (0xf<<8)
72#define MC13892_SWITCHERS5_SWBSTEN (1<<20)
73
74#define MC13892_REGULATORSETTING0 30
75#define MC13892_REGULATORSETTING0_VGEN1VSEL 0
76#define MC13892_REGULATORSETTING0_VDIGVSEL 4
77#define MC13892_REGULATORSETTING0_VGEN2VSEL 6
78#define MC13892_REGULATORSETTING0_VPLLVSEL 9
79#define MC13892_REGULATORSETTING0_VUSB2VSEL 11
80#define MC13892_REGULATORSETTING0_VGEN3VSEL 14
81#define MC13892_REGULATORSETTING0_VCAMVSEL 16
82
83#define MC13892_REGULATORSETTING0_VGEN1VSEL_M (3<<0)
84#define MC13892_REGULATORSETTING0_VDIGVSEL_M (3<<4)
85#define MC13892_REGULATORSETTING0_VGEN2VSEL_M (7<<6)
86#define MC13892_REGULATORSETTING0_VPLLVSEL_M (3<<9)
87#define MC13892_REGULATORSETTING0_VUSB2VSEL_M (3<<11)
88#define MC13892_REGULATORSETTING0_VGEN3VSEL_M (1<<14)
89#define MC13892_REGULATORSETTING0_VCAMVSEL_M (3<<16)
90
91#define MC13892_REGULATORSETTING1 31
92#define MC13892_REGULATORSETTING1_VVIDEOVSEL 2
93#define MC13892_REGULATORSETTING1_VAUDIOVSEL 4
94#define MC13892_REGULATORSETTING1_VSDVSEL 6
95
96#define MC13892_REGULATORSETTING1_VVIDEOVSEL_M (3<<2)
97#define MC13892_REGULATORSETTING1_VAUDIOVSEL_M (3<<4)
98#define MC13892_REGULATORSETTING1_VSDVSEL_M (7<<6)
99
100#define MC13892_REGULATORMODE0 32
101#define MC13892_REGULATORMODE0_VGEN1EN (1<<0)
102#define MC13892_REGULATORMODE0_VGEN1STDBY (1<<1)
103#define MC13892_REGULATORMODE0_VGEN1MODE (1<<2)
104#define MC13892_REGULATORMODE0_VIOHIEN (1<<3)
105#define MC13892_REGULATORMODE0_VIOHISTDBY (1<<4)
106#define MC13892_REGULATORMODE0_VIOHIMODE (1<<5)
107#define MC13892_REGULATORMODE0_VDIGEN (1<<9)
108#define MC13892_REGULATORMODE0_VDIGSTDBY (1<<10)
109#define MC13892_REGULATORMODE0_VDIGMODE (1<<11)
110#define MC13892_REGULATORMODE0_VGEN2EN (1<<12)
111#define MC13892_REGULATORMODE0_VGEN2STDBY (1<<13)
112#define MC13892_REGULATORMODE0_VGEN2MODE (1<<14)
113#define MC13892_REGULATORMODE0_VPLLEN (1<<15)
114#define MC13892_REGULATORMODE0_VPLLSTDBY (1<<16)
115#define MC13892_REGULATORMODE0_VPLLMODE (1<<17)
116#define MC13892_REGULATORMODE0_VUSB2EN (1<<18)
117#define MC13892_REGULATORMODE0_VUSB2STDBY (1<<19)
118#define MC13892_REGULATORMODE0_VUSB2MODE (1<<20)
119
120#define MC13892_REGULATORMODE1 33
121#define MC13892_REGULATORMODE1_VGEN3EN (1<<0)
122#define MC13892_REGULATORMODE1_VGEN3STDBY (1<<1)
123#define MC13892_REGULATORMODE1_VGEN3MODE (1<<2)
124#define MC13892_REGULATORMODE1_VCAMEN (1<<6)
125#define MC13892_REGULATORMODE1_VCAMSTDBY (1<<7)
126#define MC13892_REGULATORMODE1_VCAMMODE (1<<8)
127#define MC13892_REGULATORMODE1_VCAMCONFIGEN (1<<9)
128#define MC13892_REGULATORMODE1_VVIDEOEN (1<<12)
129#define MC13892_REGULATORMODE1_VVIDEOSTDBY (1<<13)
130#define MC13892_REGULATORMODE1_VVIDEOMODE (1<<14)
131#define MC13892_REGULATORMODE1_VAUDIOEN (1<<15)
132#define MC13892_REGULATORMODE1_VAUDIOSTDBY (1<<16)
133#define MC13892_REGULATORMODE1_VAUDIOMODE (1<<17)
134#define MC13892_REGULATORMODE1_VSDEN (1<<18)
135#define MC13892_REGULATORMODE1_VSDSTDBY (1<<19)
136#define MC13892_REGULATORMODE1_VSDMODE (1<<20)
137
138#define MC13892_POWERMISC 34
139#define MC13892_POWERMISC_GPO1EN (1<<6)
140#define MC13892_POWERMISC_GPO2EN (1<<8)
141#define MC13892_POWERMISC_GPO3EN (1<<10)
142#define MC13892_POWERMISC_GPO4EN (1<<12)
143#define MC13892_POWERMISC_PWGT1SPIEN (1<<15)
144#define MC13892_POWERMISC_PWGT2SPIEN (1<<16)
145#define MC13892_POWERMISC_GPO4ADINEN (1<<21)
146
147#define MC13892_POWERMISC_PWGTSPI_M (3 << 15)
148
149#define MC13892_USB1 50
150#define MC13892_USB1_VUSBEN (1<<3)
151
152static const int mc13892_vcoincell[] = {
153 2500000, 2700000, 2800000, 2900000, 3000000, 3100000,
154 3200000, 3300000,
155};
156
157static const int mc13892_sw1[] = {
158 600000, 625000, 650000, 675000, 700000, 725000,
159 750000, 775000, 800000, 825000, 850000, 875000,
160 900000, 925000, 950000, 975000, 1000000, 1025000,
161 1050000, 1075000, 1100000, 1125000, 1150000, 1175000,
162 1200000, 1225000, 1250000, 1275000, 1300000, 1325000,
163 1350000, 1375000
164};
165
166static const int mc13892_sw[] = {
167 600000, 625000, 650000, 675000, 700000, 725000,
168 750000, 775000, 800000, 825000, 850000, 875000,
169 900000, 925000, 950000, 975000, 1000000, 1025000,
170 1050000, 1075000, 1100000, 1125000, 1150000, 1175000,
171 1200000, 1225000, 1250000, 1275000, 1300000, 1325000,
172 1350000, 1375000, 1400000, 1425000, 1450000, 1475000,
173 1500000, 1525000, 1550000, 1575000, 1600000, 1625000,
174 1650000, 1675000, 1700000, 1725000, 1750000, 1775000,
175 1800000, 1825000, 1850000, 1875000
176};
177
178static const int mc13892_swbst[] = {
179 5000000,
180};
181
182static const int mc13892_viohi[] = {
183 2775000,
184};
185
186static const int mc13892_vpll[] = {
187 1050000, 1250000, 1650000, 1800000,
188};
189
190static const int mc13892_vdig[] = {
191 1050000, 1250000, 1650000, 1800000,
192};
193
194static const int mc13892_vsd[] = {
195 1800000, 2000000, 2600000, 2700000,
196 2800000, 2900000, 3000000, 3150000,
197};
198
199static const int mc13892_vusb2[] = {
200 2400000, 2600000, 2700000, 2775000,
201};
202
203static const int mc13892_vvideo[] = {
204 2700000, 2775000, 2500000, 2600000,
205};
206
207static const int mc13892_vaudio[] = {
208 2300000, 2500000, 2775000, 3000000,
209};
210
211static const int mc13892_vcam[] = {
212 2500000, 2600000, 2750000, 3000000,
213};
214
215static const int mc13892_vgen1[] = {
216 1200000, 1500000, 2775000, 3150000,
217};
218
219static const int mc13892_vgen2[] = {
220 1200000, 1500000, 1600000, 1800000,
221 2700000, 2800000, 3000000, 3150000,
222};
223
224static const int mc13892_vgen3[] = {
225 1800000, 2900000,
226};
227
228static const int mc13892_vusb[] = {
229 3300000,
230};
231
232static const int mc13892_gpo[] = {
233 2750000,
234};
235
236static const int mc13892_pwgtdrv[] = {
237 5000000,
238};
239
240static struct regulator_ops mc13892_gpo_regulator_ops;
241/* sw regulators need special care due to the "hi bit" */
242static struct regulator_ops mc13892_sw_regulator_ops;
243
244
245#define MC13892_FIXED_DEFINE(name, reg, voltages) \
246 MC13xxx_FIXED_DEFINE(MC13892_, name, reg, voltages, \
247 mc13xxx_fixed_regulator_ops)
248
249#define MC13892_GPO_DEFINE(name, reg, voltages) \
250 MC13xxx_GPO_DEFINE(MC13892_, name, reg, voltages, \
251 mc13892_gpo_regulator_ops)
252
253#define MC13892_SW_DEFINE(name, reg, vsel_reg, voltages) \
254 MC13xxx_DEFINE(MC13892_, name, reg, vsel_reg, voltages, \
255 mc13892_sw_regulator_ops)
256
257#define MC13892_DEFINE_REGU(name, reg, vsel_reg, voltages) \
258 MC13xxx_DEFINE(MC13892_, name, reg, vsel_reg, voltages, \
259 mc13xxx_regulator_ops)
260
261static struct mc13xxx_regulator mc13892_regulators[] = {
262 MC13892_DEFINE_REGU(VCOINCELL, POWERCTL0, POWERCTL0, mc13892_vcoincell),
263 MC13892_SW_DEFINE(SW1, SWITCHERS0, SWITCHERS0, mc13892_sw1),
264 MC13892_SW_DEFINE(SW2, SWITCHERS1, SWITCHERS1, mc13892_sw),
265 MC13892_SW_DEFINE(SW3, SWITCHERS2, SWITCHERS2, mc13892_sw),
266 MC13892_SW_DEFINE(SW4, SWITCHERS3, SWITCHERS3, mc13892_sw),
267 MC13892_FIXED_DEFINE(SWBST, SWITCHERS5, mc13892_swbst),
268 MC13892_FIXED_DEFINE(VIOHI, REGULATORMODE0, mc13892_viohi),
269 MC13892_DEFINE_REGU(VPLL, REGULATORMODE0, REGULATORSETTING0, \
270 mc13892_vpll),
271 MC13892_DEFINE_REGU(VDIG, REGULATORMODE0, REGULATORSETTING0, \
272 mc13892_vdig),
273 MC13892_DEFINE_REGU(VSD, REGULATORMODE1, REGULATORSETTING1, \
274 mc13892_vsd),
275 MC13892_DEFINE_REGU(VUSB2, REGULATORMODE0, REGULATORSETTING0, \
276 mc13892_vusb2),
277 MC13892_DEFINE_REGU(VVIDEO, REGULATORMODE1, REGULATORSETTING1, \
278 mc13892_vvideo),
279 MC13892_DEFINE_REGU(VAUDIO, REGULATORMODE1, REGULATORSETTING1, \
280 mc13892_vaudio),
281 MC13892_DEFINE_REGU(VCAM, REGULATORMODE1, REGULATORSETTING0, \
282 mc13892_vcam),
283 MC13892_DEFINE_REGU(VGEN1, REGULATORMODE0, REGULATORSETTING0, \
284 mc13892_vgen1),
285 MC13892_DEFINE_REGU(VGEN2, REGULATORMODE0, REGULATORSETTING0, \
286 mc13892_vgen2),
287 MC13892_DEFINE_REGU(VGEN3, REGULATORMODE1, REGULATORSETTING0, \
288 mc13892_vgen3),
289 MC13892_FIXED_DEFINE(VUSB, USB1, mc13892_vusb),
290 MC13892_GPO_DEFINE(GPO1, POWERMISC, mc13892_gpo),
291 MC13892_GPO_DEFINE(GPO2, POWERMISC, mc13892_gpo),
292 MC13892_GPO_DEFINE(GPO3, POWERMISC, mc13892_gpo),
293 MC13892_GPO_DEFINE(GPO4, POWERMISC, mc13892_gpo),
294 MC13892_GPO_DEFINE(PWGT1SPI, POWERMISC, mc13892_pwgtdrv),
295 MC13892_GPO_DEFINE(PWGT2SPI, POWERMISC, mc13892_pwgtdrv),
296};
297
298static int mc13892_powermisc_rmw(struct mc13xxx_regulator_priv *priv, u32 mask,
299 u32 val)
300{
301 struct mc13xxx *mc13892 = priv->mc13xxx;
302 int ret;
303 u32 valread;
304
305 BUG_ON(val & ~mask);
306
307 ret = mc13xxx_reg_read(mc13892, MC13892_POWERMISC, &valread);
308 if (ret)
309 return ret;
310
311 /* Update the stored state for Power Gates. */
312 priv->powermisc_pwgt_state =
313 (priv->powermisc_pwgt_state & ~mask) | val;
314 priv->powermisc_pwgt_state &= MC13892_POWERMISC_PWGTSPI_M;
315
316 /* Construct the new register value */
317 valread = (valread & ~mask) | val;
318 /* Overwrite the PWGTxEN with the stored version */
319 valread = (valread & ~MC13892_POWERMISC_PWGTSPI_M) |
320 priv->powermisc_pwgt_state;
321
322 return mc13xxx_reg_write(mc13892, MC13892_POWERMISC, valread);
323}
324
325static int mc13892_gpo_regulator_enable(struct regulator_dev *rdev)
326{
327 struct mc13xxx_regulator_priv *priv = rdev_get_drvdata(rdev);
328 int id = rdev_get_id(rdev);
329 int ret;
330 u32 en_val = mc13892_regulators[id].enable_bit;
331 u32 mask = mc13892_regulators[id].enable_bit;
332
333 dev_dbg(rdev_get_dev(rdev), "%s id: %d\n", __func__, id);
334
335 /* Power Gate enable value is 0 */
336 if (id == MC13892_PWGT1SPI || id == MC13892_PWGT2SPI)
337 en_val = 0;
338
339 if (id == MC13892_GPO4)
340 mask |= MC13892_POWERMISC_GPO4ADINEN;
341
342 mc13xxx_lock(priv->mc13xxx);
343 ret = mc13892_powermisc_rmw(priv, mask, en_val);
344 mc13xxx_unlock(priv->mc13xxx);
345
346 return ret;
347}
348
349static int mc13892_gpo_regulator_disable(struct regulator_dev *rdev)
350{
351 struct mc13xxx_regulator_priv *priv = rdev_get_drvdata(rdev);
352 int id = rdev_get_id(rdev);
353 int ret;
354 u32 dis_val = 0;
355
356 dev_dbg(rdev_get_dev(rdev), "%s id: %d\n", __func__, id);
357
358 /* Power Gate disable value is 1 */
359 if (id == MC13892_PWGT1SPI || id == MC13892_PWGT2SPI)
360 dis_val = mc13892_regulators[id].enable_bit;
361
362 mc13xxx_lock(priv->mc13xxx);
363 ret = mc13892_powermisc_rmw(priv, mc13892_regulators[id].enable_bit,
364 dis_val);
365 mc13xxx_unlock(priv->mc13xxx);
366
367 return ret;
368}
369
370static int mc13892_gpo_regulator_is_enabled(struct regulator_dev *rdev)
371{
372 struct mc13xxx_regulator_priv *priv = rdev_get_drvdata(rdev);
373 int ret, id = rdev_get_id(rdev);
374 unsigned int val;
375
376 mc13xxx_lock(priv->mc13xxx);
377 ret = mc13xxx_reg_read(priv->mc13xxx, mc13892_regulators[id].reg, &val);
378 mc13xxx_unlock(priv->mc13xxx);
379
380 if (ret)
381 return ret;
382
383 /* Power Gates state is stored in powermisc_pwgt_state
384 * where the meaning of bits is negated */
385 val = (val & ~MC13892_POWERMISC_PWGTSPI_M) |
386 (priv->powermisc_pwgt_state ^ MC13892_POWERMISC_PWGTSPI_M);
387
388 return (val & mc13892_regulators[id].enable_bit) != 0;
389}
390
391
392static struct regulator_ops mc13892_gpo_regulator_ops = {
393 .enable = mc13892_gpo_regulator_enable,
394 .disable = mc13892_gpo_regulator_disable,
395 .is_enabled = mc13892_gpo_regulator_is_enabled,
396 .list_voltage = mc13xxx_regulator_list_voltage,
397 .set_voltage = mc13xxx_fixed_regulator_set_voltage,
398 .get_voltage = mc13xxx_fixed_regulator_get_voltage,
399};
400
401static int mc13892_sw_regulator_get_voltage(struct regulator_dev *rdev)
402{
403 struct mc13xxx_regulator_priv *priv = rdev_get_drvdata(rdev);
404 int ret, id = rdev_get_id(rdev);
405 unsigned int val, hi;
406
407 dev_dbg(rdev_get_dev(rdev), "%s id: %d\n", __func__, id);
408
409 mc13xxx_lock(priv->mc13xxx);
410 ret = mc13xxx_reg_read(priv->mc13xxx,
411 mc13892_regulators[id].vsel_reg, &val);
412 mc13xxx_unlock(priv->mc13xxx);
413 if (ret)
414 return ret;
415
416 hi = val & MC13892_SWITCHERS0_SWxHI;
417 val = (val & mc13892_regulators[id].vsel_mask)
418 >> mc13892_regulators[id].vsel_shift;
419
420 dev_dbg(rdev_get_dev(rdev), "%s id: %d val: %d\n", __func__, id, val);
421
422 if (hi)
423 val = (25000 * val) + 1100000;
424 else
425 val = (25000 * val) + 600000;
426
427 return val;
428}
429
430static int mc13892_sw_regulator_set_voltage(struct regulator_dev *rdev,
431 int min_uV, int max_uV, unsigned *selector)
432{
433 struct mc13xxx_regulator_priv *priv = rdev_get_drvdata(rdev);
434 int hi, value, val, mask, id = rdev_get_id(rdev);
435 int ret;
436
437 dev_dbg(rdev_get_dev(rdev), "%s id: %d min_uV: %d max_uV: %d\n",
438 __func__, id, min_uV, max_uV);
439
440 /* Find the best index */
441 value = mc13xxx_get_best_voltage_index(rdev, min_uV, max_uV);
442 dev_dbg(rdev_get_dev(rdev), "%s best value: %d\n", __func__, value);
443 if (value < 0)
444 return value;
445
446 value = mc13892_regulators[id].voltages[value];
447
448 mc13xxx_lock(priv->mc13xxx);
449 ret = mc13xxx_reg_read(priv->mc13xxx,
450 mc13892_regulators[id].vsel_reg, &val);
451 if (ret)
452 goto err;
453
454 hi = val & MC13892_SWITCHERS0_SWxHI;
455 if (value > 1375)
456 hi = 1;
457 if (value < 1100)
458 hi = 0;
459
460 if (hi) {
461 value = (value - 1100000) / 25000;
462 value |= MC13892_SWITCHERS0_SWxHI;
463 } else
464 value = (value - 600000) / 25000;
465
466 mask = mc13892_regulators[id].vsel_mask | MC13892_SWITCHERS0_SWxHI;
467 ret = mc13xxx_reg_rmw(priv->mc13xxx, mc13892_regulators[id].vsel_reg,
468 mask, value << mc13892_regulators[id].vsel_shift);
469err:
470 mc13xxx_unlock(priv->mc13xxx);
471
472 return ret;
473}
474
475static struct regulator_ops mc13892_sw_regulator_ops = {
476 .is_enabled = mc13xxx_sw_regulator_is_enabled,
477 .list_voltage = mc13xxx_regulator_list_voltage,
478 .set_voltage = mc13892_sw_regulator_set_voltage,
479 .get_voltage = mc13892_sw_regulator_get_voltage,
480};
481
482static int mc13892_vcam_set_mode(struct regulator_dev *rdev, unsigned int mode)
483{
484 unsigned int en_val = 0;
485 struct mc13xxx_regulator_priv *priv = rdev_get_drvdata(rdev);
486 int ret, id = rdev_get_id(rdev);
487
488 if (mode == REGULATOR_MODE_FAST)
489 en_val = MC13892_REGULATORMODE1_VCAMCONFIGEN;
490
491 mc13xxx_lock(priv->mc13xxx);
492 ret = mc13xxx_reg_rmw(priv->mc13xxx, mc13892_regulators[id].reg,
493 MC13892_REGULATORMODE1_VCAMCONFIGEN, en_val);
494 mc13xxx_unlock(priv->mc13xxx);
495
496 return ret;
497}
498
499static unsigned int mc13892_vcam_get_mode(struct regulator_dev *rdev)
500{
501 struct mc13xxx_regulator_priv *priv = rdev_get_drvdata(rdev);
502 int ret, id = rdev_get_id(rdev);
503 unsigned int val;
504
505 mc13xxx_lock(priv->mc13xxx);
506 ret = mc13xxx_reg_read(priv->mc13xxx, mc13892_regulators[id].reg, &val);
507 mc13xxx_unlock(priv->mc13xxx);
508
509 if (ret)
510 return ret;
511
512 if (val & MC13892_REGULATORMODE1_VCAMCONFIGEN)
513 return REGULATOR_MODE_FAST;
514
515 return REGULATOR_MODE_NORMAL;
516}
517
518
519static int __devinit mc13892_regulator_probe(struct platform_device *pdev)
520{
521 struct mc13xxx_regulator_priv *priv;
522 struct mc13xxx *mc13892 = dev_get_drvdata(pdev->dev.parent);
523 struct mc13xxx_regulator_platform_data *pdata =
524 dev_get_platdata(&pdev->dev);
525 struct mc13xxx_regulator_init_data *init_data;
526 int i, ret;
527 u32 val;
528
529 priv = kzalloc(sizeof(*priv) +
530 pdata->num_regulators * sizeof(priv->regulators[0]),
531 GFP_KERNEL);
532 if (!priv)
533 return -ENOMEM;
534
535 priv->mc13xxx_regulators = mc13892_regulators;
536 priv->mc13xxx = mc13892;
537
538 mc13xxx_lock(mc13892);
539 ret = mc13xxx_reg_read(mc13892, MC13892_REVISION, &val);
540 if (ret)
541 goto err_free;
542
543 /* enable switch auto mode */
544 if ((val & 0x0000FFFF) == 0x45d0) {
545 ret = mc13xxx_reg_rmw(mc13892, MC13892_SWITCHERS4,
546 MC13892_SWITCHERS4_SW1MODE_M |
547 MC13892_SWITCHERS4_SW2MODE_M,
548 MC13892_SWITCHERS4_SW1MODE_AUTO |
549 MC13892_SWITCHERS4_SW2MODE_AUTO);
550 if (ret)
551 goto err_free;
552
553 ret = mc13xxx_reg_rmw(mc13892, MC13892_SWITCHERS5,
554 MC13892_SWITCHERS5_SW3MODE_M |
555 MC13892_SWITCHERS5_SW4MODE_M,
556 MC13892_SWITCHERS5_SW3MODE_AUTO |
557 MC13892_SWITCHERS5_SW4MODE_AUTO);
558 if (ret)
559 goto err_free;
560 }
561 mc13xxx_unlock(mc13892);
562
563 mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
564 = mc13892_vcam_set_mode;
565 mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
566 = mc13892_vcam_get_mode;
567 for (i = 0; i < pdata->num_regulators; i++) {
568 init_data = &pdata->regulators[i];
569 priv->regulators[i] = regulator_register(
570 &mc13892_regulators[init_data->id].desc,
571 &pdev->dev, init_data->init_data, priv);
572
573 if (IS_ERR(priv->regulators[i])) {
574 dev_err(&pdev->dev, "failed to register regulator %s\n",
575 mc13892_regulators[i].desc.name);
576 ret = PTR_ERR(priv->regulators[i]);
577 goto err;
578 }
579 }
580
581 platform_set_drvdata(pdev, priv);
582
583 return 0;
584err:
585 while (--i >= 0)
586 regulator_unregister(priv->regulators[i]);
587
588err_free:
589 mc13xxx_unlock(mc13892);
590 kfree(priv);
591
592 return ret;
593}
594
595static int __devexit mc13892_regulator_remove(struct platform_device *pdev)
596{
597 struct mc13xxx_regulator_priv *priv = platform_get_drvdata(pdev);
598 struct mc13xxx_regulator_platform_data *pdata =
599 dev_get_platdata(&pdev->dev);
600 int i;
601
602 platform_set_drvdata(pdev, NULL);
603
604 for (i = 0; i < pdata->num_regulators; i++)
605 regulator_unregister(priv->regulators[i]);
606
607 kfree(priv);
608 return 0;
609}
610
611static struct platform_driver mc13892_regulator_driver = {
612 .driver = {
613 .name = "mc13892-regulator",
614 .owner = THIS_MODULE,
615 },
616 .remove = __devexit_p(mc13892_regulator_remove),
617 .probe = mc13892_regulator_probe,
618};
619
620static int __init mc13892_regulator_init(void)
621{
622 return platform_driver_register(&mc13892_regulator_driver);
623}
624subsys_initcall(mc13892_regulator_init);
625
626static void __exit mc13892_regulator_exit(void)
627{
628 platform_driver_unregister(&mc13892_regulator_driver);
629}
630module_exit(mc13892_regulator_exit);
631
632MODULE_LICENSE("GPL v2");
633MODULE_AUTHOR("Yong Shen <yong.shen@linaro.org>");
634MODULE_DESCRIPTION("Regulator Driver for Freescale MC13892 PMIC");
635MODULE_ALIAS("platform:mc13892-regulator");
diff --git a/drivers/regulator/mc13xxx-regulator-core.c b/drivers/regulator/mc13xxx-regulator-core.c
new file mode 100644
index 000000000000..f53d31b950d4
--- /dev/null
+++ b/drivers/regulator/mc13xxx-regulator-core.c
@@ -0,0 +1,241 @@
1/*
2 * Regulator Driver for Freescale MC13xxx PMIC
3 *
4 * Copyright 2010 Yong Shen <yong.shen@linaro.org>
5 *
6 * Based on mc13783 regulator driver :
7 * Copyright (C) 2008 Sascha Hauer, Pengutronix <s.hauer@pengutronix.de>
8 * Copyright 2009 Alberto Panizzo <maramaopercheseimorto@gmail.com>
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License version 2 as
12 * published by the Free Software Foundation.
13 *
14 * Regs infos taken from mc13xxx drivers from freescale and mc13xxx.pdf file
15 * from freescale
16 */
17
18#include <linux/mfd/mc13xxx.h>
19#include <linux/regulator/machine.h>
20#include <linux/regulator/driver.h>
21#include <linux/platform_device.h>
22#include <linux/kernel.h>
23#include <linux/slab.h>
24#include <linux/init.h>
25#include <linux/err.h>
26#include "mc13xxx.h"
27
28static int mc13xxx_regulator_enable(struct regulator_dev *rdev)
29{
30 struct mc13xxx_regulator_priv *priv = rdev_get_drvdata(rdev);
31 struct mc13xxx_regulator *mc13xxx_regulators = priv->mc13xxx_regulators;
32 int id = rdev_get_id(rdev);
33 int ret;
34
35 dev_dbg(rdev_get_dev(rdev), "%s id: %d\n", __func__, id);
36
37 mc13xxx_lock(priv->mc13xxx);
38 ret = mc13xxx_reg_rmw(priv->mc13xxx, mc13xxx_regulators[id].reg,
39 mc13xxx_regulators[id].enable_bit,
40 mc13xxx_regulators[id].enable_bit);
41 mc13xxx_unlock(priv->mc13xxx);
42
43 return ret;
44}
45
46static int mc13xxx_regulator_disable(struct regulator_dev *rdev)
47{
48 struct mc13xxx_regulator_priv *priv = rdev_get_drvdata(rdev);
49 struct mc13xxx_regulator *mc13xxx_regulators = priv->mc13xxx_regulators;
50 int id = rdev_get_id(rdev);
51 int ret;
52
53 dev_dbg(rdev_get_dev(rdev), "%s id: %d\n", __func__, id);
54
55 mc13xxx_lock(priv->mc13xxx);
56 ret = mc13xxx_reg_rmw(priv->mc13xxx, mc13xxx_regulators[id].reg,
57 mc13xxx_regulators[id].enable_bit, 0);
58 mc13xxx_unlock(priv->mc13xxx);
59
60 return ret;
61}
62
63static int mc13xxx_regulator_is_enabled(struct regulator_dev *rdev)
64{
65 struct mc13xxx_regulator_priv *priv = rdev_get_drvdata(rdev);
66 struct mc13xxx_regulator *mc13xxx_regulators = priv->mc13xxx_regulators;
67 int ret, id = rdev_get_id(rdev);
68 unsigned int val;
69
70 mc13xxx_lock(priv->mc13xxx);
71 ret = mc13xxx_reg_read(priv->mc13xxx, mc13xxx_regulators[id].reg, &val);
72 mc13xxx_unlock(priv->mc13xxx);
73
74 if (ret)
75 return ret;
76
77 return (val & mc13xxx_regulators[id].enable_bit) != 0;
78}
79
80int mc13xxx_regulator_list_voltage(struct regulator_dev *rdev,
81 unsigned selector)
82{
83 int id = rdev_get_id(rdev);
84 struct mc13xxx_regulator_priv *priv = rdev_get_drvdata(rdev);
85 struct mc13xxx_regulator *mc13xxx_regulators = priv->mc13xxx_regulators;
86
87 if (selector >= mc13xxx_regulators[id].desc.n_voltages)
88 return -EINVAL;
89
90 return mc13xxx_regulators[id].voltages[selector];
91}
92EXPORT_SYMBOL_GPL(mc13xxx_regulator_list_voltage);
93
94int mc13xxx_get_best_voltage_index(struct regulator_dev *rdev,
95 int min_uV, int max_uV)
96{
97 struct mc13xxx_regulator_priv *priv = rdev_get_drvdata(rdev);
98 struct mc13xxx_regulator *mc13xxx_regulators = priv->mc13xxx_regulators;
99 int reg_id = rdev_get_id(rdev);
100 int i;
101 int bestmatch;
102 int bestindex;
103
104 /*
105 * Locate the minimum voltage fitting the criteria on
106 * this regulator. The switchable voltages are not
107 * in strict falling order so we need to check them
108 * all for the best match.
109 */
110 bestmatch = INT_MAX;
111 bestindex = -1;
112 for (i = 0; i < mc13xxx_regulators[reg_id].desc.n_voltages; i++) {
113 if (mc13xxx_regulators[reg_id].voltages[i] >= min_uV &&
114 mc13xxx_regulators[reg_id].voltages[i] < bestmatch) {
115 bestmatch = mc13xxx_regulators[reg_id].voltages[i];
116 bestindex = i;
117 }
118 }
119
120 if (bestindex < 0 || bestmatch > max_uV) {
121 dev_warn(&rdev->dev, "no possible value for %d<=x<=%d uV\n",
122 min_uV, max_uV);
123 return -EINVAL;
124 }
125 return bestindex;
126}
127EXPORT_SYMBOL_GPL(mc13xxx_get_best_voltage_index);
128
129static int mc13xxx_regulator_set_voltage(struct regulator_dev *rdev, int min_uV,
130 int max_uV, unsigned *selector)
131{
132 struct mc13xxx_regulator_priv *priv = rdev_get_drvdata(rdev);
133 struct mc13xxx_regulator *mc13xxx_regulators = priv->mc13xxx_regulators;
134 int value, id = rdev_get_id(rdev);
135 int ret;
136
137 dev_dbg(rdev_get_dev(rdev), "%s id: %d min_uV: %d max_uV: %d\n",
138 __func__, id, min_uV, max_uV);
139
140 /* Find the best index */
141 value = mc13xxx_get_best_voltage_index(rdev, min_uV, max_uV);
142 dev_dbg(rdev_get_dev(rdev), "%s best value: %d\n", __func__, value);
143 if (value < 0)
144 return value;
145
146 mc13xxx_lock(priv->mc13xxx);
147 ret = mc13xxx_reg_rmw(priv->mc13xxx, mc13xxx_regulators[id].vsel_reg,
148 mc13xxx_regulators[id].vsel_mask,
149 value << mc13xxx_regulators[id].vsel_shift);
150 mc13xxx_unlock(priv->mc13xxx);
151
152 return ret;
153}
154
155static int mc13xxx_regulator_get_voltage(struct regulator_dev *rdev)
156{
157 struct mc13xxx_regulator_priv *priv = rdev_get_drvdata(rdev);
158 struct mc13xxx_regulator *mc13xxx_regulators = priv->mc13xxx_regulators;
159 int ret, id = rdev_get_id(rdev);
160 unsigned int val;
161
162 dev_dbg(rdev_get_dev(rdev), "%s id: %d\n", __func__, id);
163
164 mc13xxx_lock(priv->mc13xxx);
165 ret = mc13xxx_reg_read(priv->mc13xxx,
166 mc13xxx_regulators[id].vsel_reg, &val);
167 mc13xxx_unlock(priv->mc13xxx);
168
169 if (ret)
170 return ret;
171
172 val = (val & mc13xxx_regulators[id].vsel_mask)
173 >> mc13xxx_regulators[id].vsel_shift;
174
175 dev_dbg(rdev_get_dev(rdev), "%s id: %d val: %d\n", __func__, id, val);
176
177 BUG_ON(val < 0 || val > mc13xxx_regulators[id].desc.n_voltages);
178
179 return mc13xxx_regulators[id].voltages[val];
180}
181
182struct regulator_ops mc13xxx_regulator_ops = {
183 .enable = mc13xxx_regulator_enable,
184 .disable = mc13xxx_regulator_disable,
185 .is_enabled = mc13xxx_regulator_is_enabled,
186 .list_voltage = mc13xxx_regulator_list_voltage,
187 .set_voltage = mc13xxx_regulator_set_voltage,
188 .get_voltage = mc13xxx_regulator_get_voltage,
189};
190EXPORT_SYMBOL_GPL(mc13xxx_regulator_ops);
191
192int mc13xxx_fixed_regulator_set_voltage(struct regulator_dev *rdev, int min_uV,
193 int max_uV, unsigned *selector)
194{
195 struct mc13xxx_regulator_priv *priv = rdev_get_drvdata(rdev);
196 struct mc13xxx_regulator *mc13xxx_regulators = priv->mc13xxx_regulators;
197 int id = rdev_get_id(rdev);
198
199 dev_dbg(rdev_get_dev(rdev), "%s id: %d min_uV: %d max_uV: %d\n",
200 __func__, id, min_uV, max_uV);
201
202 if (min_uV >= mc13xxx_regulators[id].voltages[0] &&
203 max_uV <= mc13xxx_regulators[id].voltages[0])
204 return 0;
205 else
206 return -EINVAL;
207}
208EXPORT_SYMBOL_GPL(mc13xxx_fixed_regulator_set_voltage);
209
210int mc13xxx_fixed_regulator_get_voltage(struct regulator_dev *rdev)
211{
212 struct mc13xxx_regulator_priv *priv = rdev_get_drvdata(rdev);
213 struct mc13xxx_regulator *mc13xxx_regulators = priv->mc13xxx_regulators;
214 int id = rdev_get_id(rdev);
215
216 dev_dbg(rdev_get_dev(rdev), "%s id: %d\n", __func__, id);
217
218 return mc13xxx_regulators[id].voltages[0];
219}
220EXPORT_SYMBOL_GPL(mc13xxx_fixed_regulator_get_voltage);
221
222struct regulator_ops mc13xxx_fixed_regulator_ops = {
223 .enable = mc13xxx_regulator_enable,
224 .disable = mc13xxx_regulator_disable,
225 .is_enabled = mc13xxx_regulator_is_enabled,
226 .list_voltage = mc13xxx_regulator_list_voltage,
227 .set_voltage = mc13xxx_fixed_regulator_set_voltage,
228 .get_voltage = mc13xxx_fixed_regulator_get_voltage,
229};
230EXPORT_SYMBOL_GPL(mc13xxx_fixed_regulator_ops);
231
232int mc13xxx_sw_regulator_is_enabled(struct regulator_dev *rdev)
233{
234 return 1;
235}
236EXPORT_SYMBOL_GPL(mc13xxx_sw_regulator_is_enabled);
237
238MODULE_LICENSE("GPL v2");
239MODULE_AUTHOR("Yong Shen <yong.shen@linaro.org>");
240MODULE_DESCRIPTION("Regulator Driver for Freescale MC13xxx PMIC");
241MODULE_ALIAS("mc13xxx-regulator-core");
diff --git a/drivers/regulator/mc13xxx.h b/drivers/regulator/mc13xxx.h
new file mode 100644
index 000000000000..27758267e122
--- /dev/null
+++ b/drivers/regulator/mc13xxx.h
@@ -0,0 +1,101 @@
1/*
2 * mc13xxx.h - regulators for the Freescale mc13xxx PMIC
3 *
4 * Copyright (C) 2010 Yong Shen <yong.shen@linaro.org>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 */
11
12#ifndef __LINUX_REGULATOR_MC13XXX_H
13#define __LINUX_REGULATOR_MC13XXX_H
14
15#include <linux/regulator/driver.h>
16
17struct mc13xxx_regulator {
18 struct regulator_desc desc;
19 int reg;
20 int enable_bit;
21 int vsel_reg;
22 int vsel_shift;
23 int vsel_mask;
24 int hi_bit;
25 int const *voltages;
26};
27
28struct mc13xxx_regulator_priv {
29 struct mc13xxx *mc13xxx;
30 u32 powermisc_pwgt_state;
31 struct mc13xxx_regulator *mc13xxx_regulators;
32 struct regulator_dev *regulators[];
33};
34
35extern int mc13xxx_sw_regulator(struct regulator_dev *rdev);
36extern int mc13xxx_sw_regulator_is_enabled(struct regulator_dev *rdev);
37extern int mc13xxx_get_best_voltage_index(struct regulator_dev *rdev,
38 int min_uV, int max_uV);
39extern int mc13xxx_regulator_list_voltage(struct regulator_dev *rdev,
40 unsigned selector);
41extern int mc13xxx_fixed_regulator_set_voltage(struct regulator_dev *rdev,
42 int min_uV, int max_uV, unsigned *selector);
43extern int mc13xxx_fixed_regulator_get_voltage(struct regulator_dev *rdev);
44
45extern struct regulator_ops mc13xxx_regulator_ops;
46extern struct regulator_ops mc13xxx_fixed_regulator_ops;
47
48#define MC13xxx_DEFINE(prefix, _name, _reg, _vsel_reg, _voltages, _ops) \
49 [prefix ## _name] = { \
50 .desc = { \
51 .name = #prefix "_" #_name, \
52 .n_voltages = ARRAY_SIZE(_voltages), \
53 .ops = &_ops, \
54 .type = REGULATOR_VOLTAGE, \
55 .id = prefix ## _name, \
56 .owner = THIS_MODULE, \
57 }, \
58 .reg = prefix ## _reg, \
59 .enable_bit = prefix ## _reg ## _ ## _name ## EN, \
60 .vsel_reg = prefix ## _vsel_reg, \
61 .vsel_shift = prefix ## _vsel_reg ## _ ## _name ## VSEL,\
62 .vsel_mask = prefix ## _vsel_reg ## _ ## _name ## VSEL_M,\
63 .voltages = _voltages, \
64 }
65
66#define MC13xxx_FIXED_DEFINE(prefix, _name, _reg, _voltages, _ops) \
67 [prefix ## _name] = { \
68 .desc = { \
69 .name = #prefix "_" #_name, \
70 .n_voltages = ARRAY_SIZE(_voltages), \
71 .ops = &_ops, \
72 .type = REGULATOR_VOLTAGE, \
73 .id = prefix ## _name, \
74 .owner = THIS_MODULE, \
75 }, \
76 .reg = prefix ## _reg, \
77 .enable_bit = prefix ## _reg ## _ ## _name ## EN, \
78 .voltages = _voltages, \
79 }
80
81#define MC13xxx_GPO_DEFINE(prefix, _name, _reg, _voltages, _ops) \
82 [prefix ## _name] = { \
83 .desc = { \
84 .name = #prefix "_" #_name, \
85 .n_voltages = ARRAY_SIZE(_voltages), \
86 .ops = &_ops, \
87 .type = REGULATOR_VOLTAGE, \
88 .id = prefix ## _name, \
89 .owner = THIS_MODULE, \
90 }, \
91 .reg = prefix ## _reg, \
92 .enable_bit = prefix ## _reg ## _ ## _name ## EN, \
93 .voltages = _voltages, \
94 }
95
96#define MC13xxx_DEFINE_SW(_name, _reg, _vsel_reg, _voltages, ops) \
97 MC13xxx_DEFINE(SW, _name, _reg, _vsel_reg, _voltages, ops)
98#define MC13xxx_DEFINE_REGU(_name, _reg, _vsel_reg, _voltages, ops) \
99 MC13xxx_DEFINE(REGU, _name, _reg, _vsel_reg, _voltages, ops)
100
101#endif
diff --git a/drivers/regulator/pcap-regulator.c b/drivers/regulator/pcap-regulator.c
index 29d0566379ae..31f6e11a7f16 100644
--- a/drivers/regulator/pcap-regulator.c
+++ b/drivers/regulator/pcap-regulator.c
@@ -151,7 +151,8 @@ static struct pcap_regulator vreg_table[] = {
151}; 151};
152 152
153static int pcap_regulator_set_voltage(struct regulator_dev *rdev, 153static int pcap_regulator_set_voltage(struct regulator_dev *rdev,
154 int min_uV, int max_uV) 154 int min_uV, int max_uV,
155 unsigned *selector)
155{ 156{
156 struct pcap_regulator *vreg = &vreg_table[rdev_get_id(rdev)]; 157 struct pcap_regulator *vreg = &vreg_table[rdev_get_id(rdev)];
157 void *pcap = rdev_get_drvdata(rdev); 158 void *pcap = rdev_get_drvdata(rdev);
@@ -170,10 +171,12 @@ static int pcap_regulator_set_voltage(struct regulator_dev *rdev,
170 i = 0; 171 i = 0;
171 172
172 uV = vreg->voltage_table[i] * 1000; 173 uV = vreg->voltage_table[i] * 1000;
173 if (min_uV <= uV && uV <= max_uV) 174 if (min_uV <= uV && uV <= max_uV) {
175 *selector = i;
174 return ezx_pcap_set_bits(pcap, vreg->reg, 176 return ezx_pcap_set_bits(pcap, vreg->reg,
175 (vreg->n_voltages - 1) << vreg->index, 177 (vreg->n_voltages - 1) << vreg->index,
176 i << vreg->index); 178 i << vreg->index);
179 }
177 180
178 if (i == 0 && rdev_get_id(rdev) == V1) 181 if (i == 0 && rdev_get_id(rdev) == V1)
179 i = vreg->n_voltages - 1; 182 i = vreg->n_voltages - 1;
diff --git a/drivers/regulator/pcf50633-regulator.c b/drivers/regulator/pcf50633-regulator.c
index c8f41dc05b76..69a11d9dd87f 100644
--- a/drivers/regulator/pcf50633-regulator.c
+++ b/drivers/regulator/pcf50633-regulator.c
@@ -108,7 +108,8 @@ static unsigned int ldo_voltage_value(u8 bits)
108} 108}
109 109
110static int pcf50633_regulator_set_voltage(struct regulator_dev *rdev, 110static int pcf50633_regulator_set_voltage(struct regulator_dev *rdev,
111 int min_uV, int max_uV) 111 int min_uV, int max_uV,
112 unsigned *selector)
112{ 113{
113 struct pcf50633 *pcf; 114 struct pcf50633 *pcf;
114 int regulator_id, millivolts; 115 int regulator_id, millivolts;
@@ -147,6 +148,8 @@ static int pcf50633_regulator_set_voltage(struct regulator_dev *rdev,
147 return -EINVAL; 148 return -EINVAL;
148 } 149 }
149 150
151 *selector = volt_bits;
152
150 return pcf50633_reg_write(pcf, regnr, volt_bits); 153 return pcf50633_reg_write(pcf, regnr, volt_bits);
151} 154}
152 155
diff --git a/drivers/regulator/tps65023-regulator.c b/drivers/regulator/tps65023-regulator.c
index cd6d4fc9d74f..60a7ca5409e9 100644
--- a/drivers/regulator/tps65023-regulator.c
+++ b/drivers/regulator/tps65023-regulator.c
@@ -321,7 +321,8 @@ static int tps65023_dcdc_get_voltage(struct regulator_dev *dev)
321} 321}
322 322
323static int tps65023_dcdc_set_voltage(struct regulator_dev *dev, 323static int tps65023_dcdc_set_voltage(struct regulator_dev *dev,
324 int min_uV, int max_uV) 324 int min_uV, int max_uV,
325 unsigned *selector)
325{ 326{
326 struct tps_pmic *tps = rdev_get_drvdata(dev); 327 struct tps_pmic *tps = rdev_get_drvdata(dev);
327 int dcdc = rdev_get_id(dev); 328 int dcdc = rdev_get_id(dev);
@@ -346,6 +347,8 @@ static int tps65023_dcdc_set_voltage(struct regulator_dev *dev,
346 break; 347 break;
347 } 348 }
348 349
350 *selector = vsel;
351
349 /* write to the register in case we found a match */ 352 /* write to the register in case we found a match */
350 if (vsel == tps->info[dcdc]->table_len) 353 if (vsel == tps->info[dcdc]->table_len)
351 return -EINVAL; 354 return -EINVAL;
@@ -371,7 +374,7 @@ static int tps65023_ldo_get_voltage(struct regulator_dev *dev)
371} 374}
372 375
373static int tps65023_ldo_set_voltage(struct regulator_dev *dev, 376static int tps65023_ldo_set_voltage(struct regulator_dev *dev,
374 int min_uV, int max_uV) 377 int min_uV, int max_uV, unsigned *selector)
375{ 378{
376 struct tps_pmic *tps = rdev_get_drvdata(dev); 379 struct tps_pmic *tps = rdev_get_drvdata(dev);
377 int data, vsel, ldo = rdev_get_id(dev); 380 int data, vsel, ldo = rdev_get_id(dev);
@@ -396,6 +399,8 @@ static int tps65023_ldo_set_voltage(struct regulator_dev *dev,
396 if (vsel == tps->info[ldo]->table_len) 399 if (vsel == tps->info[ldo]->table_len)
397 return -EINVAL; 400 return -EINVAL;
398 401
402 *selector = vsel;
403
399 data = tps_65023_reg_read(tps, TPS65023_REG_LDO_CTRL); 404 data = tps_65023_reg_read(tps, TPS65023_REG_LDO_CTRL);
400 if (data < 0) 405 if (data < 0)
401 return data; 406 return data;
diff --git a/drivers/regulator/tps6507x-regulator.c b/drivers/regulator/tps6507x-regulator.c
index 020f5878d7ff..064755290599 100644
--- a/drivers/regulator/tps6507x-regulator.c
+++ b/drivers/regulator/tps6507x-regulator.c
@@ -369,7 +369,8 @@ static int tps6507x_pmic_dcdc_get_voltage(struct regulator_dev *dev)
369} 369}
370 370
371static int tps6507x_pmic_dcdc_set_voltage(struct regulator_dev *dev, 371static int tps6507x_pmic_dcdc_set_voltage(struct regulator_dev *dev,
372 int min_uV, int max_uV) 372 int min_uV, int max_uV,
373 unsigned *selector)
373{ 374{
374 struct tps6507x_pmic *tps = rdev_get_drvdata(dev); 375 struct tps6507x_pmic *tps = rdev_get_drvdata(dev);
375 int data, vsel, dcdc = rdev_get_id(dev); 376 int data, vsel, dcdc = rdev_get_id(dev);
@@ -415,6 +416,8 @@ static int tps6507x_pmic_dcdc_set_voltage(struct regulator_dev *dev,
415 if (vsel == tps->info[dcdc]->table_len) 416 if (vsel == tps->info[dcdc]->table_len)
416 return -EINVAL; 417 return -EINVAL;
417 418
419 *selector = vsel;
420
418 data = tps6507x_pmic_reg_read(tps, reg); 421 data = tps6507x_pmic_reg_read(tps, reg);
419 if (data < 0) 422 if (data < 0)
420 return data; 423 return data;
@@ -450,7 +453,8 @@ static int tps6507x_pmic_ldo_get_voltage(struct regulator_dev *dev)
450} 453}
451 454
452static int tps6507x_pmic_ldo_set_voltage(struct regulator_dev *dev, 455static int tps6507x_pmic_ldo_set_voltage(struct regulator_dev *dev,
453 int min_uV, int max_uV) 456 int min_uV, int max_uV,
457 unsigned *selector)
454{ 458{
455 struct tps6507x_pmic *tps = rdev_get_drvdata(dev); 459 struct tps6507x_pmic *tps = rdev_get_drvdata(dev);
456 int data, vsel, ldo = rdev_get_id(dev); 460 int data, vsel, ldo = rdev_get_id(dev);
@@ -483,6 +487,8 @@ static int tps6507x_pmic_ldo_set_voltage(struct regulator_dev *dev,
483 if (vsel == tps->info[ldo]->table_len) 487 if (vsel == tps->info[ldo]->table_len)
484 return -EINVAL; 488 return -EINVAL;
485 489
490 *selector = vsel;
491
486 data = tps6507x_pmic_reg_read(tps, reg); 492 data = tps6507x_pmic_reg_read(tps, reg);
487 if (data < 0) 493 if (data < 0)
488 return data; 494 return data;
diff --git a/drivers/regulator/tps6524x-regulator.c b/drivers/regulator/tps6524x-regulator.c
new file mode 100644
index 000000000000..176a6be5a8ce
--- /dev/null
+++ b/drivers/regulator/tps6524x-regulator.c
@@ -0,0 +1,693 @@
1/*
2 * Regulator driver for TPS6524x PMIC
3 *
4 * Copyright (C) 2010 Texas Instruments
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation version 2.
9 *
10 * This program is distributed "as is" WITHOUT ANY WARRANTY of any kind,
11 * whether express or implied; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
14 */
15
16#include <linux/kernel.h>
17#include <linux/module.h>
18#include <linux/err.h>
19#include <linux/errno.h>
20#include <linux/slab.h>
21#include <linux/spi/spi.h>
22#include <linux/regulator/driver.h>
23#include <linux/regulator/machine.h>
24
25#define REG_LDO_SET 0x0
26#define LDO_ILIM_MASK 1 /* 0 = 400-800, 1 = 900-1500 */
27#define LDO_VSEL_MASK 0x0f
28#define LDO2_ILIM_SHIFT 12
29#define LDO2_VSEL_SHIFT 4
30#define LDO1_ILIM_SHIFT 8
31#define LDO1_VSEL_SHIFT 0
32
33#define REG_BLOCK_EN 0x1
34#define BLOCK_MASK 1
35#define BLOCK_LDO1_SHIFT 0
36#define BLOCK_LDO2_SHIFT 1
37#define BLOCK_LCD_SHIFT 2
38#define BLOCK_USB_SHIFT 3
39
40#define REG_DCDC_SET 0x2
41#define DCDC_VDCDC_MASK 0x1f
42#define DCDC_VDCDC1_SHIFT 0
43#define DCDC_VDCDC2_SHIFT 5
44#define DCDC_VDCDC3_SHIFT 10
45
46#define REG_DCDC_EN 0x3
47#define DCDCDCDC_EN_MASK 0x1
48#define DCDCDCDC1_EN_SHIFT 0
49#define DCDCDCDC1_PG_MSK BIT(1)
50#define DCDCDCDC2_EN_SHIFT 2
51#define DCDCDCDC2_PG_MSK BIT(3)
52#define DCDCDCDC3_EN_SHIFT 4
53#define DCDCDCDC3_PG_MSK BIT(5)
54
55#define REG_USB 0x4
56#define USB_ILIM_SHIFT 0
57#define USB_ILIM_MASK 0x3
58#define USB_TSD_SHIFT 2
59#define USB_TSD_MASK 0x3
60#define USB_TWARN_SHIFT 4
61#define USB_TWARN_MASK 0x3
62#define USB_IWARN_SD BIT(6)
63#define USB_FAST_LOOP BIT(7)
64
65#define REG_ALARM 0x5
66#define ALARM_LDO1 BIT(0)
67#define ALARM_DCDC1 BIT(1)
68#define ALARM_DCDC2 BIT(2)
69#define ALARM_DCDC3 BIT(3)
70#define ALARM_LDO2 BIT(4)
71#define ALARM_USB_WARN BIT(5)
72#define ALARM_USB_ALARM BIT(6)
73#define ALARM_LCD BIT(9)
74#define ALARM_TEMP_WARM BIT(10)
75#define ALARM_TEMP_HOT BIT(11)
76#define ALARM_NRST BIT(14)
77#define ALARM_POWERUP BIT(15)
78
79#define REG_INT_ENABLE 0x6
80#define INT_LDO1 BIT(0)
81#define INT_DCDC1 BIT(1)
82#define INT_DCDC2 BIT(2)
83#define INT_DCDC3 BIT(3)
84#define INT_LDO2 BIT(4)
85#define INT_USB_WARN BIT(5)
86#define INT_USB_ALARM BIT(6)
87#define INT_LCD BIT(9)
88#define INT_TEMP_WARM BIT(10)
89#define INT_TEMP_HOT BIT(11)
90#define INT_GLOBAL_EN BIT(15)
91
92#define REG_INT_STATUS 0x7
93#define STATUS_LDO1 BIT(0)
94#define STATUS_DCDC1 BIT(1)
95#define STATUS_DCDC2 BIT(2)
96#define STATUS_DCDC3 BIT(3)
97#define STATUS_LDO2 BIT(4)
98#define STATUS_USB_WARN BIT(5)
99#define STATUS_USB_ALARM BIT(6)
100#define STATUS_LCD BIT(9)
101#define STATUS_TEMP_WARM BIT(10)
102#define STATUS_TEMP_HOT BIT(11)
103
104#define REG_SOFTWARE_RESET 0xb
105#define REG_WRITE_ENABLE 0xd
106#define REG_REV_ID 0xf
107
108#define N_DCDC 3
109#define N_LDO 2
110#define N_SWITCH 2
111#define N_REGULATORS (3 /* DCDC */ + \
112 2 /* LDO */ + \
113 2 /* switch */)
114
115#define FIXED_ILIMSEL BIT(0)
116#define FIXED_VOLTAGE BIT(1)
117
118#define CMD_READ(reg) ((reg) << 6)
119#define CMD_WRITE(reg) (BIT(5) | (reg) << 6)
120#define STAT_CLK BIT(3)
121#define STAT_WRITE BIT(2)
122#define STAT_INVALID BIT(1)
123#define STAT_WP BIT(0)
124
125struct field {
126 int reg;
127 int shift;
128 int mask;
129};
130
131struct supply_info {
132 const char *name;
133 int n_voltages;
134 const int *voltages;
135 int fixed_voltage;
136 int n_ilimsels;
137 const int *ilimsels;
138 int fixed_ilimsel;
139 int flags;
140 struct field enable, voltage, ilimsel;
141};
142
143struct tps6524x {
144 struct device *dev;
145 struct spi_device *spi;
146 struct mutex lock;
147 struct regulator_desc desc[N_REGULATORS];
148 struct regulator_dev *rdev[N_REGULATORS];
149};
150
151static int __read_reg(struct tps6524x *hw, int reg)
152{
153 int error = 0;
154 u16 cmd = CMD_READ(reg), in;
155 u8 status;
156 struct spi_message m;
157 struct spi_transfer t[3];
158
159 spi_message_init(&m);
160 memset(t, 0, sizeof(t));
161
162 t[0].tx_buf = &cmd;
163 t[0].len = 2;
164 t[0].bits_per_word = 12;
165 spi_message_add_tail(&t[0], &m);
166
167 t[1].rx_buf = &in;
168 t[1].len = 2;
169 t[1].bits_per_word = 16;
170 spi_message_add_tail(&t[1], &m);
171
172 t[2].rx_buf = &status;
173 t[2].len = 1;
174 t[2].bits_per_word = 4;
175 spi_message_add_tail(&t[2], &m);
176
177 error = spi_sync(hw->spi, &m);
178 if (error < 0)
179 return error;
180
181 dev_dbg(hw->dev, "read reg %d, data %x, status %x\n",
182 reg, in, status);
183
184 if (!(status & STAT_CLK) || (status & STAT_WRITE))
185 return -EIO;
186
187 if (status & STAT_INVALID)
188 return -EINVAL;
189
190 return in;
191}
192
193static int read_reg(struct tps6524x *hw, int reg)
194{
195 int ret;
196
197 mutex_lock(&hw->lock);
198 ret = __read_reg(hw, reg);
199 mutex_unlock(&hw->lock);
200
201 return ret;
202}
203
204static int __write_reg(struct tps6524x *hw, int reg, int val)
205{
206 int error = 0;
207 u16 cmd = CMD_WRITE(reg), out = val;
208 u8 status;
209 struct spi_message m;
210 struct spi_transfer t[3];
211
212 spi_message_init(&m);
213 memset(t, 0, sizeof(t));
214
215 t[0].tx_buf = &cmd;
216 t[0].len = 2;
217 t[0].bits_per_word = 12;
218 spi_message_add_tail(&t[0], &m);
219
220 t[1].tx_buf = &out;
221 t[1].len = 2;
222 t[1].bits_per_word = 16;
223 spi_message_add_tail(&t[1], &m);
224
225 t[2].rx_buf = &status;
226 t[2].len = 1;
227 t[2].bits_per_word = 4;
228 spi_message_add_tail(&t[2], &m);
229
230 error = spi_sync(hw->spi, &m);
231 if (error < 0)
232 return error;
233
234 dev_dbg(hw->dev, "wrote reg %d, data %x, status %x\n",
235 reg, out, status);
236
237 if (!(status & STAT_CLK) || !(status & STAT_WRITE))
238 return -EIO;
239
240 if (status & (STAT_INVALID | STAT_WP))
241 return -EINVAL;
242
243 return error;
244}
245
246static int __rmw_reg(struct tps6524x *hw, int reg, int mask, int val)
247{
248 int ret;
249
250 ret = __read_reg(hw, reg);
251 if (ret < 0)
252 return ret;
253
254 ret &= ~mask;
255 ret |= val;
256
257 ret = __write_reg(hw, reg, ret);
258
259 return (ret < 0) ? ret : 0;
260}
261
262static int rmw_protect(struct tps6524x *hw, int reg, int mask, int val)
263{
264 int ret;
265
266 mutex_lock(&hw->lock);
267
268 ret = __write_reg(hw, REG_WRITE_ENABLE, 1);
269 if (ret) {
270 dev_err(hw->dev, "failed to set write enable\n");
271 goto error;
272 }
273
274 ret = __rmw_reg(hw, reg, mask, val);
275 if (ret)
276 dev_err(hw->dev, "failed to rmw register %d\n", reg);
277
278 ret = __write_reg(hw, REG_WRITE_ENABLE, 0);
279 if (ret) {
280 dev_err(hw->dev, "failed to clear write enable\n");
281 goto error;
282 }
283
284error:
285 mutex_unlock(&hw->lock);
286
287 return ret;
288}
289
290static int read_field(struct tps6524x *hw, const struct field *field)
291{
292 int tmp;
293
294 tmp = read_reg(hw, field->reg);
295 if (tmp < 0)
296 return tmp;
297
298 return (tmp >> field->shift) & field->mask;
299}
300
301static int write_field(struct tps6524x *hw, const struct field *field,
302 int val)
303{
304 if (val & ~field->mask)
305 return -EOVERFLOW;
306
307 return rmw_protect(hw, field->reg,
308 field->mask << field->shift,
309 val << field->shift);
310}
311
312static const int dcdc1_voltages[] = {
313 800000, 825000, 850000, 875000,
314 900000, 925000, 950000, 975000,
315 1000000, 1025000, 1050000, 1075000,
316 1100000, 1125000, 1150000, 1175000,
317 1200000, 1225000, 1250000, 1275000,
318 1300000, 1325000, 1350000, 1375000,
319 1400000, 1425000, 1450000, 1475000,
320 1500000, 1525000, 1550000, 1575000,
321};
322
323static const int dcdc2_voltages[] = {
324 1400000, 1450000, 1500000, 1550000,
325 1600000, 1650000, 1700000, 1750000,
326 1800000, 1850000, 1900000, 1950000,
327 2000000, 2050000, 2100000, 2150000,
328 2200000, 2250000, 2300000, 2350000,
329 2400000, 2450000, 2500000, 2550000,
330 2600000, 2650000, 2700000, 2750000,
331 2800000, 2850000, 2900000, 2950000,
332};
333
334static const int dcdc3_voltages[] = {
335 2400000, 2450000, 2500000, 2550000, 2600000,
336 2650000, 2700000, 2750000, 2800000, 2850000,
337 2900000, 2950000, 3000000, 3050000, 3100000,
338 3150000, 3200000, 3250000, 3300000, 3350000,
339 3400000, 3450000, 3500000, 3550000, 3600000,
340};
341
342static const int ldo1_voltages[] = {
343 4300000, 4350000, 4400000, 4450000,
344 4500000, 4550000, 4600000, 4650000,
345 4700000, 4750000, 4800000, 4850000,
346 4900000, 4950000, 5000000, 5050000,
347};
348
349static const int ldo2_voltages[] = {
350 1100000, 1150000, 1200000, 1250000,
351 1300000, 1700000, 1750000, 1800000,
352 1850000, 1900000, 3150000, 3200000,
353 3250000, 3300000, 3350000, 3400000,
354};
355
356static const int ldo_ilimsel[] = {
357 400000, 1500000
358};
359
360static const int usb_ilimsel[] = {
361 200000, 400000, 800000, 1000000
362};
363
364#define __MK_FIELD(_reg, _mask, _shift) \
365 { .reg = (_reg), .mask = (_mask), .shift = (_shift), }
366
367static const struct supply_info supply_info[N_REGULATORS] = {
368 {
369 .name = "DCDC1",
370 .flags = FIXED_ILIMSEL,
371 .n_voltages = ARRAY_SIZE(dcdc1_voltages),
372 .voltages = dcdc1_voltages,
373 .fixed_ilimsel = 2400000,
374 .enable = __MK_FIELD(REG_DCDC_EN, DCDCDCDC_EN_MASK,
375 DCDCDCDC1_EN_SHIFT),
376 .voltage = __MK_FIELD(REG_DCDC_SET, DCDC_VDCDC_MASK,
377 DCDC_VDCDC1_SHIFT),
378 },
379 {
380 .name = "DCDC2",
381 .flags = FIXED_ILIMSEL,
382 .n_voltages = ARRAY_SIZE(dcdc2_voltages),
383 .voltages = dcdc2_voltages,
384 .fixed_ilimsel = 1200000,
385 .enable = __MK_FIELD(REG_DCDC_EN, DCDCDCDC_EN_MASK,
386 DCDCDCDC2_EN_SHIFT),
387 .voltage = __MK_FIELD(REG_DCDC_SET, DCDC_VDCDC_MASK,
388 DCDC_VDCDC2_SHIFT),
389 },
390 {
391 .name = "DCDC3",
392 .flags = FIXED_ILIMSEL,
393 .n_voltages = ARRAY_SIZE(dcdc3_voltages),
394 .voltages = dcdc3_voltages,
395 .fixed_ilimsel = 1200000,
396 .enable = __MK_FIELD(REG_DCDC_EN, DCDCDCDC_EN_MASK,
397 DCDCDCDC3_EN_SHIFT),
398 .voltage = __MK_FIELD(REG_DCDC_SET, DCDC_VDCDC_MASK,
399 DCDC_VDCDC3_SHIFT),
400 },
401 {
402 .name = "LDO1",
403 .n_voltages = ARRAY_SIZE(ldo1_voltages),
404 .voltages = ldo1_voltages,
405 .n_ilimsels = ARRAY_SIZE(ldo_ilimsel),
406 .ilimsels = ldo_ilimsel,
407 .enable = __MK_FIELD(REG_BLOCK_EN, BLOCK_MASK,
408 BLOCK_LDO1_SHIFT),
409 .voltage = __MK_FIELD(REG_LDO_SET, LDO_VSEL_MASK,
410 LDO1_VSEL_SHIFT),
411 .ilimsel = __MK_FIELD(REG_LDO_SET, LDO_ILIM_MASK,
412 LDO1_ILIM_SHIFT),
413 },
414 {
415 .name = "LDO2",
416 .n_voltages = ARRAY_SIZE(ldo2_voltages),
417 .voltages = ldo2_voltages,
418 .n_ilimsels = ARRAY_SIZE(ldo_ilimsel),
419 .ilimsels = ldo_ilimsel,
420 .enable = __MK_FIELD(REG_BLOCK_EN, BLOCK_MASK,
421 BLOCK_LDO2_SHIFT),
422 .voltage = __MK_FIELD(REG_LDO_SET, LDO_VSEL_MASK,
423 LDO2_VSEL_SHIFT),
424 .ilimsel = __MK_FIELD(REG_LDO_SET, LDO_ILIM_MASK,
425 LDO2_ILIM_SHIFT),
426 },
427 {
428 .name = "USB",
429 .flags = FIXED_VOLTAGE,
430 .fixed_voltage = 5000000,
431 .n_ilimsels = ARRAY_SIZE(usb_ilimsel),
432 .ilimsels = usb_ilimsel,
433 .enable = __MK_FIELD(REG_BLOCK_EN, BLOCK_MASK,
434 BLOCK_USB_SHIFT),
435 .ilimsel = __MK_FIELD(REG_USB, USB_ILIM_MASK,
436 USB_ILIM_SHIFT),
437 },
438 {
439 .name = "LCD",
440 .flags = FIXED_VOLTAGE | FIXED_ILIMSEL,
441 .fixed_voltage = 5000000,
442 .fixed_ilimsel = 400000,
443 .enable = __MK_FIELD(REG_BLOCK_EN, BLOCK_MASK,
444 BLOCK_LCD_SHIFT),
445 },
446};
447
448static int list_voltage(struct regulator_dev *rdev, unsigned selector)
449{
450 const struct supply_info *info;
451 struct tps6524x *hw;
452
453 hw = rdev_get_drvdata(rdev);
454 info = &supply_info[rdev_get_id(rdev)];
455
456 if (info->flags & FIXED_VOLTAGE)
457 return selector ? -EINVAL : info->fixed_voltage;
458
459 return ((selector < info->n_voltages) ?
460 info->voltages[selector] : -EINVAL);
461}
462
463static int set_voltage(struct regulator_dev *rdev, int min_uV, int max_uV,
464 unsigned *selector)
465{
466 const struct supply_info *info;
467 struct tps6524x *hw;
468 unsigned i;
469
470 hw = rdev_get_drvdata(rdev);
471 info = &supply_info[rdev_get_id(rdev)];
472
473 if (info->flags & FIXED_VOLTAGE)
474 return -EINVAL;
475
476 for (i = 0; i < info->n_voltages; i++)
477 if (min_uV <= info->voltages[i] &&
478 max_uV >= info->voltages[i])
479 break;
480
481 if (i >= info->n_voltages)
482 i = info->n_voltages - 1;
483
484 *selector = info->voltages[i];
485
486 return write_field(hw, &info->voltage, i);
487}
488
489static int get_voltage(struct regulator_dev *rdev)
490{
491 const struct supply_info *info;
492 struct tps6524x *hw;
493 int ret;
494
495 hw = rdev_get_drvdata(rdev);
496 info = &supply_info[rdev_get_id(rdev)];
497
498 if (info->flags & FIXED_VOLTAGE)
499 return info->fixed_voltage;
500
501 ret = read_field(hw, &info->voltage);
502 if (ret < 0)
503 return ret;
504 if (WARN_ON(ret >= info->n_voltages))
505 return -EIO;
506
507 return info->voltages[ret];
508}
509
510static int set_current_limit(struct regulator_dev *rdev, int min_uA,
511 int max_uA)
512{
513 const struct supply_info *info;
514 struct tps6524x *hw;
515 int i;
516
517 hw = rdev_get_drvdata(rdev);
518 info = &supply_info[rdev_get_id(rdev)];
519
520 if (info->flags & FIXED_ILIMSEL)
521 return -EINVAL;
522
523 for (i = 0; i < info->n_ilimsels; i++)
524 if (min_uA <= info->ilimsels[i] &&
525 max_uA >= info->ilimsels[i])
526 break;
527
528 if (i >= info->n_ilimsels)
529 return -EINVAL;
530
531 return write_field(hw, &info->ilimsel, i);
532}
533
534static int get_current_limit(struct regulator_dev *rdev)
535{
536 const struct supply_info *info;
537 struct tps6524x *hw;
538 int ret;
539
540 hw = rdev_get_drvdata(rdev);
541 info = &supply_info[rdev_get_id(rdev)];
542
543 if (info->flags & FIXED_ILIMSEL)
544 return info->fixed_ilimsel;
545
546 ret = read_field(hw, &info->ilimsel);
547 if (ret < 0)
548 return ret;
549 if (WARN_ON(ret >= info->n_ilimsels))
550 return -EIO;
551
552 return info->ilimsels[ret];
553}
554
555static int enable_supply(struct regulator_dev *rdev)
556{
557 const struct supply_info *info;
558 struct tps6524x *hw;
559
560 hw = rdev_get_drvdata(rdev);
561 info = &supply_info[rdev_get_id(rdev)];
562
563 return write_field(hw, &info->enable, 1);
564}
565
566static int disable_supply(struct regulator_dev *rdev)
567{
568 const struct supply_info *info;
569 struct tps6524x *hw;
570
571 hw = rdev_get_drvdata(rdev);
572 info = &supply_info[rdev_get_id(rdev)];
573
574 return write_field(hw, &info->enable, 0);
575}
576
577static int is_supply_enabled(struct regulator_dev *rdev)
578{
579 const struct supply_info *info;
580 struct tps6524x *hw;
581
582 hw = rdev_get_drvdata(rdev);
583 info = &supply_info[rdev_get_id(rdev)];
584
585 return read_field(hw, &info->enable);
586}
587
588static struct regulator_ops regulator_ops = {
589 .is_enabled = is_supply_enabled,
590 .enable = enable_supply,
591 .disable = disable_supply,
592 .get_voltage = get_voltage,
593 .set_voltage = set_voltage,
594 .list_voltage = list_voltage,
595 .set_current_limit = set_current_limit,
596 .get_current_limit = get_current_limit,
597};
598
599static int __devexit pmic_remove(struct spi_device *spi)
600{
601 struct tps6524x *hw = spi_get_drvdata(spi);
602 int i;
603
604 if (!hw)
605 return 0;
606 for (i = 0; i < N_REGULATORS; i++) {
607 if (hw->rdev[i])
608 regulator_unregister(hw->rdev[i]);
609 hw->rdev[i] = NULL;
610 }
611 spi_set_drvdata(spi, NULL);
612 kfree(hw);
613 return 0;
614}
615
616static int __devinit pmic_probe(struct spi_device *spi)
617{
618 struct tps6524x *hw;
619 struct device *dev = &spi->dev;
620 const struct supply_info *info = supply_info;
621 struct regulator_init_data *init_data;
622 int ret = 0, i;
623
624 init_data = dev->platform_data;
625 if (!init_data) {
626 dev_err(dev, "could not find regulator platform data\n");
627 return -EINVAL;
628 }
629
630 hw = kzalloc(sizeof(struct tps6524x), GFP_KERNEL);
631 if (!hw) {
632 dev_err(dev, "cannot allocate regulator private data\n");
633 return -ENOMEM;
634 }
635 spi_set_drvdata(spi, hw);
636
637 memset(hw, 0, sizeof(struct tps6524x));
638 hw->dev = dev;
639 hw->spi = spi_dev_get(spi);
640 mutex_init(&hw->lock);
641
642 for (i = 0; i < N_REGULATORS; i++, info++, init_data++) {
643 hw->desc[i].name = info->name;
644 hw->desc[i].id = i;
645 hw->desc[i].n_voltages = info->n_voltages;
646 hw->desc[i].ops = &regulator_ops;
647 hw->desc[i].type = REGULATOR_VOLTAGE;
648 hw->desc[i].owner = THIS_MODULE;
649
650 if (info->flags & FIXED_VOLTAGE)
651 hw->desc[i].n_voltages = 1;
652
653 hw->rdev[i] = regulator_register(&hw->desc[i], dev,
654 init_data, hw);
655 if (IS_ERR(hw->rdev[i])) {
656 ret = PTR_ERR(hw->rdev[i]);
657 hw->rdev[i] = NULL;
658 goto fail;
659 }
660 }
661
662 return 0;
663
664fail:
665 pmic_remove(spi);
666 return ret;
667}
668
669static struct spi_driver pmic_driver = {
670 .probe = pmic_probe,
671 .remove = __devexit_p(pmic_remove),
672 .driver = {
673 .name = "tps6524x",
674 .owner = THIS_MODULE,
675 },
676};
677
678static int __init pmic_driver_init(void)
679{
680 return spi_register_driver(&pmic_driver);
681}
682module_init(pmic_driver_init);
683
684static void __exit pmic_driver_exit(void)
685{
686 spi_unregister_driver(&pmic_driver);
687}
688module_exit(pmic_driver_exit);
689
690MODULE_DESCRIPTION("TPS6524X PMIC Driver");
691MODULE_AUTHOR("Cyril Chemparathy");
692MODULE_LICENSE("GPL");
693MODULE_ALIAS("spi:tps6524x");
diff --git a/drivers/regulator/tps6586x-regulator.c b/drivers/regulator/tps6586x-regulator.c
index 6d20b0454a1d..bb04a75a4c98 100644
--- a/drivers/regulator/tps6586x-regulator.c
+++ b/drivers/regulator/tps6586x-regulator.c
@@ -85,7 +85,8 @@ static int tps6586x_ldo_list_voltage(struct regulator_dev *rdev,
85 85
86static int __tps6586x_ldo_set_voltage(struct device *parent, 86static int __tps6586x_ldo_set_voltage(struct device *parent,
87 struct tps6586x_regulator *ri, 87 struct tps6586x_regulator *ri,
88 int min_uV, int max_uV) 88 int min_uV, int max_uV,
89 unsigned *selector)
89{ 90{
90 int val, uV; 91 int val, uV;
91 uint8_t mask; 92 uint8_t mask;
@@ -100,6 +101,8 @@ static int __tps6586x_ldo_set_voltage(struct device *parent,
100 /* use the first in-range value */ 101 /* use the first in-range value */
101 if (min_uV <= uV && uV <= max_uV) { 102 if (min_uV <= uV && uV <= max_uV) {
102 103
104 *selector = val;
105
103 val <<= ri->volt_shift; 106 val <<= ri->volt_shift;
104 mask = ((1 << ri->volt_nbits) - 1) << ri->volt_shift; 107 mask = ((1 << ri->volt_nbits) - 1) << ri->volt_shift;
105 108
@@ -111,12 +114,13 @@ static int __tps6586x_ldo_set_voltage(struct device *parent,
111} 114}
112 115
113static int tps6586x_ldo_set_voltage(struct regulator_dev *rdev, 116static int tps6586x_ldo_set_voltage(struct regulator_dev *rdev,
114 int min_uV, int max_uV) 117 int min_uV, int max_uV, unsigned *selector)
115{ 118{
116 struct tps6586x_regulator *ri = rdev_get_drvdata(rdev); 119 struct tps6586x_regulator *ri = rdev_get_drvdata(rdev);
117 struct device *parent = to_tps6586x_dev(rdev); 120 struct device *parent = to_tps6586x_dev(rdev);
118 121
119 return __tps6586x_ldo_set_voltage(parent, ri, min_uV, max_uV); 122 return __tps6586x_ldo_set_voltage(parent, ri, min_uV, max_uV,
123 selector);
120} 124}
121 125
122static int tps6586x_ldo_get_voltage(struct regulator_dev *rdev) 126static int tps6586x_ldo_get_voltage(struct regulator_dev *rdev)
@@ -140,13 +144,14 @@ static int tps6586x_ldo_get_voltage(struct regulator_dev *rdev)
140} 144}
141 145
142static int tps6586x_dvm_set_voltage(struct regulator_dev *rdev, 146static int tps6586x_dvm_set_voltage(struct regulator_dev *rdev,
143 int min_uV, int max_uV) 147 int min_uV, int max_uV, unsigned *selector)
144{ 148{
145 struct tps6586x_regulator *ri = rdev_get_drvdata(rdev); 149 struct tps6586x_regulator *ri = rdev_get_drvdata(rdev);
146 struct device *parent = to_tps6586x_dev(rdev); 150 struct device *parent = to_tps6586x_dev(rdev);
147 int ret; 151 int ret;
148 152
149 ret = __tps6586x_ldo_set_voltage(parent, ri, min_uV, max_uV); 153 ret = __tps6586x_ldo_set_voltage(parent, ri, min_uV, max_uV,
154 selector);
150 if (ret) 155 if (ret)
151 return ret; 156 return ret;
152 157
diff --git a/drivers/regulator/twl-regulator.c b/drivers/regulator/twl-regulator.c
index a57262a4fa6c..bd332cf1cc3f 100644
--- a/drivers/regulator/twl-regulator.c
+++ b/drivers/regulator/twl-regulator.c
@@ -329,7 +329,8 @@ static int twl4030ldo_list_voltage(struct regulator_dev *rdev, unsigned index)
329} 329}
330 330
331static int 331static int
332twl4030ldo_set_voltage(struct regulator_dev *rdev, int min_uV, int max_uV) 332twl4030ldo_set_voltage(struct regulator_dev *rdev, int min_uV, int max_uV,
333 unsigned *selector)
333{ 334{
334 struct twlreg_info *info = rdev_get_drvdata(rdev); 335 struct twlreg_info *info = rdev_get_drvdata(rdev);
335 int vsel; 336 int vsel;
@@ -345,9 +346,11 @@ twl4030ldo_set_voltage(struct regulator_dev *rdev, int min_uV, int max_uV)
345 /* REVISIT for VAUX2, first match may not be best/lowest */ 346 /* REVISIT for VAUX2, first match may not be best/lowest */
346 347
347 /* use the first in-range value */ 348 /* use the first in-range value */
348 if (min_uV <= uV && uV <= max_uV) 349 if (min_uV <= uV && uV <= max_uV) {
350 *selector = vsel;
349 return twlreg_write(info, TWL_MODULE_PM_RECEIVER, 351 return twlreg_write(info, TWL_MODULE_PM_RECEIVER,
350 VREG_VOLTAGE, vsel); 352 VREG_VOLTAGE, vsel);
353 }
351 } 354 }
352 355
353 return -EDOM; 356 return -EDOM;
@@ -389,7 +392,8 @@ static int twl6030ldo_list_voltage(struct regulator_dev *rdev, unsigned index)
389} 392}
390 393
391static int 394static int
392twl6030ldo_set_voltage(struct regulator_dev *rdev, int min_uV, int max_uV) 395twl6030ldo_set_voltage(struct regulator_dev *rdev, int min_uV, int max_uV,
396 unsigned *selector)
393{ 397{
394 struct twlreg_info *info = rdev_get_drvdata(rdev); 398 struct twlreg_info *info = rdev_get_drvdata(rdev);
395 int vsel; 399 int vsel;
@@ -402,6 +406,7 @@ twl6030ldo_set_voltage(struct regulator_dev *rdev, int min_uV, int max_uV)
402 * mV = 1000mv + 100mv * (vsel - 1) 406 * mV = 1000mv + 100mv * (vsel - 1)
403 */ 407 */
404 vsel = (min_uV/1000 - 1000)/100 + 1; 408 vsel = (min_uV/1000 - 1000)/100 + 1;
409 *selector = vsel;
405 return twlreg_write(info, TWL_MODULE_PM_RECEIVER, VREG_VOLTAGE, vsel); 410 return twlreg_write(info, TWL_MODULE_PM_RECEIVER, VREG_VOLTAGE, vsel);
406 411
407} 412}
diff --git a/drivers/regulator/wm831x-dcdc.c b/drivers/regulator/wm831x-dcdc.c
index dbfaf5945e48..8b0d2c4bde91 100644
--- a/drivers/regulator/wm831x-dcdc.c
+++ b/drivers/regulator/wm831x-dcdc.c
@@ -302,7 +302,7 @@ static int wm831x_buckv_set_dvs(struct regulator_dev *rdev, int state)
302} 302}
303 303
304static int wm831x_buckv_set_voltage(struct regulator_dev *rdev, 304static int wm831x_buckv_set_voltage(struct regulator_dev *rdev,
305 int min_uV, int max_uV) 305 int min_uV, int max_uV, unsigned *selector)
306{ 306{
307 struct wm831x_dcdc *dcdc = rdev_get_drvdata(rdev); 307 struct wm831x_dcdc *dcdc = rdev_get_drvdata(rdev);
308 struct wm831x *wm831x = dcdc->wm831x; 308 struct wm831x *wm831x = dcdc->wm831x;
@@ -314,6 +314,8 @@ static int wm831x_buckv_set_voltage(struct regulator_dev *rdev,
314 if (vsel < 0) 314 if (vsel < 0)
315 return vsel; 315 return vsel;
316 316
317 *selector = vsel;
318
317 /* If this value is already set then do a GPIO update if we can */ 319 /* If this value is already set then do a GPIO update if we can */
318 if (dcdc->dvs_gpio && dcdc->on_vsel == vsel) 320 if (dcdc->dvs_gpio && dcdc->on_vsel == vsel)
319 return wm831x_buckv_set_dvs(rdev, 0); 321 return wm831x_buckv_set_dvs(rdev, 0);
@@ -375,14 +377,14 @@ static int wm831x_buckv_set_suspend_voltage(struct regulator_dev *rdev,
375 return wm831x_set_bits(wm831x, reg, WM831X_DC1_SLP_VSEL_MASK, vsel); 377 return wm831x_set_bits(wm831x, reg, WM831X_DC1_SLP_VSEL_MASK, vsel);
376} 378}
377 379
378static int wm831x_buckv_get_voltage(struct regulator_dev *rdev) 380static int wm831x_buckv_get_voltage_sel(struct regulator_dev *rdev)
379{ 381{
380 struct wm831x_dcdc *dcdc = rdev_get_drvdata(rdev); 382 struct wm831x_dcdc *dcdc = rdev_get_drvdata(rdev);
381 383
382 if (dcdc->dvs_gpio && dcdc->dvs_gpio_state) 384 if (dcdc->dvs_gpio && dcdc->dvs_gpio_state)
383 return wm831x_buckv_list_voltage(rdev, dcdc->dvs_vsel); 385 return dcdc->dvs_vsel;
384 else 386 else
385 return wm831x_buckv_list_voltage(rdev, dcdc->on_vsel); 387 return dcdc->on_vsel;
386} 388}
387 389
388/* Current limit options */ 390/* Current limit options */
@@ -424,7 +426,7 @@ static int wm831x_buckv_get_current_limit(struct regulator_dev *rdev)
424 426
425static struct regulator_ops wm831x_buckv_ops = { 427static struct regulator_ops wm831x_buckv_ops = {
426 .set_voltage = wm831x_buckv_set_voltage, 428 .set_voltage = wm831x_buckv_set_voltage,
427 .get_voltage = wm831x_buckv_get_voltage, 429 .get_voltage_sel = wm831x_buckv_get_voltage_sel,
428 .list_voltage = wm831x_buckv_list_voltage, 430 .list_voltage = wm831x_buckv_list_voltage,
429 .set_suspend_voltage = wm831x_buckv_set_suspend_voltage, 431 .set_suspend_voltage = wm831x_buckv_set_suspend_voltage,
430 .set_current_limit = wm831x_buckv_set_current_limit, 432 .set_current_limit = wm831x_buckv_set_current_limit,
@@ -636,7 +638,7 @@ static int wm831x_buckp_list_voltage(struct regulator_dev *rdev,
636} 638}
637 639
638static int wm831x_buckp_set_voltage_int(struct regulator_dev *rdev, int reg, 640static int wm831x_buckp_set_voltage_int(struct regulator_dev *rdev, int reg,
639 int min_uV, int max_uV) 641 int min_uV, int max_uV, int *selector)
640{ 642{
641 struct wm831x_dcdc *dcdc = rdev_get_drvdata(rdev); 643 struct wm831x_dcdc *dcdc = rdev_get_drvdata(rdev);
642 struct wm831x *wm831x = dcdc->wm831x; 644 struct wm831x *wm831x = dcdc->wm831x;
@@ -650,16 +652,20 @@ static int wm831x_buckp_set_voltage_int(struct regulator_dev *rdev, int reg,
650 if (wm831x_buckp_list_voltage(rdev, vsel) > max_uV) 652 if (wm831x_buckp_list_voltage(rdev, vsel) > max_uV)
651 return -EINVAL; 653 return -EINVAL;
652 654
655 *selector = vsel;
656
653 return wm831x_set_bits(wm831x, reg, WM831X_DC3_ON_VSEL_MASK, vsel); 657 return wm831x_set_bits(wm831x, reg, WM831X_DC3_ON_VSEL_MASK, vsel);
654} 658}
655 659
656static int wm831x_buckp_set_voltage(struct regulator_dev *rdev, 660static int wm831x_buckp_set_voltage(struct regulator_dev *rdev,
657 int min_uV, int max_uV) 661 int min_uV, int max_uV,
662 unsigned *selector)
658{ 663{
659 struct wm831x_dcdc *dcdc = rdev_get_drvdata(rdev); 664 struct wm831x_dcdc *dcdc = rdev_get_drvdata(rdev);
660 u16 reg = dcdc->base + WM831X_DCDC_ON_CONFIG; 665 u16 reg = dcdc->base + WM831X_DCDC_ON_CONFIG;
661 666
662 return wm831x_buckp_set_voltage_int(rdev, reg, min_uV, max_uV); 667 return wm831x_buckp_set_voltage_int(rdev, reg, min_uV, max_uV,
668 selector);
663} 669}
664 670
665static int wm831x_buckp_set_suspend_voltage(struct regulator_dev *rdev, 671static int wm831x_buckp_set_suspend_voltage(struct regulator_dev *rdev,
@@ -667,11 +673,12 @@ static int wm831x_buckp_set_suspend_voltage(struct regulator_dev *rdev,
667{ 673{
668 struct wm831x_dcdc *dcdc = rdev_get_drvdata(rdev); 674 struct wm831x_dcdc *dcdc = rdev_get_drvdata(rdev);
669 u16 reg = dcdc->base + WM831X_DCDC_SLEEP_CONTROL; 675 u16 reg = dcdc->base + WM831X_DCDC_SLEEP_CONTROL;
676 unsigned selector;
670 677
671 return wm831x_buckp_set_voltage_int(rdev, reg, uV, uV); 678 return wm831x_buckp_set_voltage_int(rdev, reg, uV, uV, &selector);
672} 679}
673 680
674static int wm831x_buckp_get_voltage(struct regulator_dev *rdev) 681static int wm831x_buckp_get_voltage_sel(struct regulator_dev *rdev)
675{ 682{
676 struct wm831x_dcdc *dcdc = rdev_get_drvdata(rdev); 683 struct wm831x_dcdc *dcdc = rdev_get_drvdata(rdev);
677 struct wm831x *wm831x = dcdc->wm831x; 684 struct wm831x *wm831x = dcdc->wm831x;
@@ -682,12 +689,12 @@ static int wm831x_buckp_get_voltage(struct regulator_dev *rdev)
682 if (val < 0) 689 if (val < 0)
683 return val; 690 return val;
684 691
685 return wm831x_buckp_list_voltage(rdev, val & WM831X_DC3_ON_VSEL_MASK); 692 return val & WM831X_DC3_ON_VSEL_MASK;
686} 693}
687 694
688static struct regulator_ops wm831x_buckp_ops = { 695static struct regulator_ops wm831x_buckp_ops = {
689 .set_voltage = wm831x_buckp_set_voltage, 696 .set_voltage = wm831x_buckp_set_voltage,
690 .get_voltage = wm831x_buckp_get_voltage, 697 .get_voltage_sel = wm831x_buckp_get_voltage_sel,
691 .list_voltage = wm831x_buckp_list_voltage, 698 .list_voltage = wm831x_buckp_list_voltage,
692 .set_suspend_voltage = wm831x_buckp_set_suspend_voltage, 699 .set_suspend_voltage = wm831x_buckp_set_suspend_voltage,
693 700
diff --git a/drivers/regulator/wm831x-ldo.c b/drivers/regulator/wm831x-ldo.c
index 9edf8f692341..c94fc5b7cd5b 100644
--- a/drivers/regulator/wm831x-ldo.c
+++ b/drivers/regulator/wm831x-ldo.c
@@ -113,7 +113,8 @@ static int wm831x_gp_ldo_list_voltage(struct regulator_dev *rdev,
113} 113}
114 114
115static int wm831x_gp_ldo_set_voltage_int(struct regulator_dev *rdev, int reg, 115static int wm831x_gp_ldo_set_voltage_int(struct regulator_dev *rdev, int reg,
116 int min_uV, int max_uV) 116 int min_uV, int max_uV,
117 unsigned *selector)
117{ 118{
118 struct wm831x_ldo *ldo = rdev_get_drvdata(rdev); 119 struct wm831x_ldo *ldo = rdev_get_drvdata(rdev);
119 struct wm831x *wm831x = ldo->wm831x; 120 struct wm831x *wm831x = ldo->wm831x;
@@ -133,16 +134,20 @@ static int wm831x_gp_ldo_set_voltage_int(struct regulator_dev *rdev, int reg,
133 if (ret < min_uV || ret > max_uV) 134 if (ret < min_uV || ret > max_uV)
134 return -EINVAL; 135 return -EINVAL;
135 136
137 *selector = vsel;
138
136 return wm831x_set_bits(wm831x, reg, WM831X_LDO1_ON_VSEL_MASK, vsel); 139 return wm831x_set_bits(wm831x, reg, WM831X_LDO1_ON_VSEL_MASK, vsel);
137} 140}
138 141
139static int wm831x_gp_ldo_set_voltage(struct regulator_dev *rdev, 142static int wm831x_gp_ldo_set_voltage(struct regulator_dev *rdev,
140 int min_uV, int max_uV) 143 int min_uV, int max_uV,
144 unsigned *selector)
141{ 145{
142 struct wm831x_ldo *ldo = rdev_get_drvdata(rdev); 146 struct wm831x_ldo *ldo = rdev_get_drvdata(rdev);
143 int reg = ldo->base + WM831X_LDO_ON_CONTROL; 147 int reg = ldo->base + WM831X_LDO_ON_CONTROL;
144 148
145 return wm831x_gp_ldo_set_voltage_int(rdev, reg, min_uV, max_uV); 149 return wm831x_gp_ldo_set_voltage_int(rdev, reg, min_uV, max_uV,
150 selector);
146} 151}
147 152
148static int wm831x_gp_ldo_set_suspend_voltage(struct regulator_dev *rdev, 153static int wm831x_gp_ldo_set_suspend_voltage(struct regulator_dev *rdev,
@@ -150,11 +155,12 @@ static int wm831x_gp_ldo_set_suspend_voltage(struct regulator_dev *rdev,
150{ 155{
151 struct wm831x_ldo *ldo = rdev_get_drvdata(rdev); 156 struct wm831x_ldo *ldo = rdev_get_drvdata(rdev);
152 int reg = ldo->base + WM831X_LDO_SLEEP_CONTROL; 157 int reg = ldo->base + WM831X_LDO_SLEEP_CONTROL;
158 unsigned int selector;
153 159
154 return wm831x_gp_ldo_set_voltage_int(rdev, reg, uV, uV); 160 return wm831x_gp_ldo_set_voltage_int(rdev, reg, uV, uV, &selector);
155} 161}
156 162
157static int wm831x_gp_ldo_get_voltage(struct regulator_dev *rdev) 163static int wm831x_gp_ldo_get_voltage_sel(struct regulator_dev *rdev)
158{ 164{
159 struct wm831x_ldo *ldo = rdev_get_drvdata(rdev); 165 struct wm831x_ldo *ldo = rdev_get_drvdata(rdev);
160 struct wm831x *wm831x = ldo->wm831x; 166 struct wm831x *wm831x = ldo->wm831x;
@@ -167,7 +173,7 @@ static int wm831x_gp_ldo_get_voltage(struct regulator_dev *rdev)
167 173
168 ret &= WM831X_LDO1_ON_VSEL_MASK; 174 ret &= WM831X_LDO1_ON_VSEL_MASK;
169 175
170 return wm831x_gp_ldo_list_voltage(rdev, ret); 176 return ret;
171} 177}
172 178
173static unsigned int wm831x_gp_ldo_get_mode(struct regulator_dev *rdev) 179static unsigned int wm831x_gp_ldo_get_mode(struct regulator_dev *rdev)
@@ -287,7 +293,7 @@ static unsigned int wm831x_gp_ldo_get_optimum_mode(struct regulator_dev *rdev,
287 293
288static struct regulator_ops wm831x_gp_ldo_ops = { 294static struct regulator_ops wm831x_gp_ldo_ops = {
289 .list_voltage = wm831x_gp_ldo_list_voltage, 295 .list_voltage = wm831x_gp_ldo_list_voltage,
290 .get_voltage = wm831x_gp_ldo_get_voltage, 296 .get_voltage_sel = wm831x_gp_ldo_get_voltage_sel,
291 .set_voltage = wm831x_gp_ldo_set_voltage, 297 .set_voltage = wm831x_gp_ldo_set_voltage,
292 .set_suspend_voltage = wm831x_gp_ldo_set_suspend_voltage, 298 .set_suspend_voltage = wm831x_gp_ldo_set_suspend_voltage,
293 .get_mode = wm831x_gp_ldo_get_mode, 299 .get_mode = wm831x_gp_ldo_get_mode,
@@ -413,7 +419,8 @@ static int wm831x_aldo_list_voltage(struct regulator_dev *rdev,
413} 419}
414 420
415static int wm831x_aldo_set_voltage_int(struct regulator_dev *rdev, int reg, 421static int wm831x_aldo_set_voltage_int(struct regulator_dev *rdev, int reg,
416 int min_uV, int max_uV) 422 int min_uV, int max_uV,
423 unsigned *selector)
417{ 424{
418 struct wm831x_ldo *ldo = rdev_get_drvdata(rdev); 425 struct wm831x_ldo *ldo = rdev_get_drvdata(rdev);
419 struct wm831x *wm831x = ldo->wm831x; 426 struct wm831x *wm831x = ldo->wm831x;
@@ -433,16 +440,19 @@ static int wm831x_aldo_set_voltage_int(struct regulator_dev *rdev, int reg,
433 if (ret < min_uV || ret > max_uV) 440 if (ret < min_uV || ret > max_uV)
434 return -EINVAL; 441 return -EINVAL;
435 442
443 *selector = vsel;
444
436 return wm831x_set_bits(wm831x, reg, WM831X_LDO7_ON_VSEL_MASK, vsel); 445 return wm831x_set_bits(wm831x, reg, WM831X_LDO7_ON_VSEL_MASK, vsel);
437} 446}
438 447
439static int wm831x_aldo_set_voltage(struct regulator_dev *rdev, 448static int wm831x_aldo_set_voltage(struct regulator_dev *rdev,
440 int min_uV, int max_uV) 449 int min_uV, int max_uV, unsigned *selector)
441{ 450{
442 struct wm831x_ldo *ldo = rdev_get_drvdata(rdev); 451 struct wm831x_ldo *ldo = rdev_get_drvdata(rdev);
443 int reg = ldo->base + WM831X_LDO_ON_CONTROL; 452 int reg = ldo->base + WM831X_LDO_ON_CONTROL;
444 453
445 return wm831x_aldo_set_voltage_int(rdev, reg, min_uV, max_uV); 454 return wm831x_aldo_set_voltage_int(rdev, reg, min_uV, max_uV,
455 selector);
446} 456}
447 457
448static int wm831x_aldo_set_suspend_voltage(struct regulator_dev *rdev, 458static int wm831x_aldo_set_suspend_voltage(struct regulator_dev *rdev,
@@ -450,11 +460,12 @@ static int wm831x_aldo_set_suspend_voltage(struct regulator_dev *rdev,
450{ 460{
451 struct wm831x_ldo *ldo = rdev_get_drvdata(rdev); 461 struct wm831x_ldo *ldo = rdev_get_drvdata(rdev);
452 int reg = ldo->base + WM831X_LDO_SLEEP_CONTROL; 462 int reg = ldo->base + WM831X_LDO_SLEEP_CONTROL;
463 unsigned int selector;
453 464
454 return wm831x_aldo_set_voltage_int(rdev, reg, uV, uV); 465 return wm831x_aldo_set_voltage_int(rdev, reg, uV, uV, &selector);
455} 466}
456 467
457static int wm831x_aldo_get_voltage(struct regulator_dev *rdev) 468static int wm831x_aldo_get_voltage_sel(struct regulator_dev *rdev)
458{ 469{
459 struct wm831x_ldo *ldo = rdev_get_drvdata(rdev); 470 struct wm831x_ldo *ldo = rdev_get_drvdata(rdev);
460 struct wm831x *wm831x = ldo->wm831x; 471 struct wm831x *wm831x = ldo->wm831x;
@@ -467,7 +478,7 @@ static int wm831x_aldo_get_voltage(struct regulator_dev *rdev)
467 478
468 ret &= WM831X_LDO7_ON_VSEL_MASK; 479 ret &= WM831X_LDO7_ON_VSEL_MASK;
469 480
470 return wm831x_aldo_list_voltage(rdev, ret); 481 return ret;
471} 482}
472 483
473static unsigned int wm831x_aldo_get_mode(struct regulator_dev *rdev) 484static unsigned int wm831x_aldo_get_mode(struct regulator_dev *rdev)
@@ -548,7 +559,7 @@ static int wm831x_aldo_get_status(struct regulator_dev *rdev)
548 559
549static struct regulator_ops wm831x_aldo_ops = { 560static struct regulator_ops wm831x_aldo_ops = {
550 .list_voltage = wm831x_aldo_list_voltage, 561 .list_voltage = wm831x_aldo_list_voltage,
551 .get_voltage = wm831x_aldo_get_voltage, 562 .get_voltage_sel = wm831x_aldo_get_voltage_sel,
552 .set_voltage = wm831x_aldo_set_voltage, 563 .set_voltage = wm831x_aldo_set_voltage,
553 .set_suspend_voltage = wm831x_aldo_set_suspend_voltage, 564 .set_suspend_voltage = wm831x_aldo_set_suspend_voltage,
554 .get_mode = wm831x_aldo_get_mode, 565 .get_mode = wm831x_aldo_get_mode,
@@ -666,7 +677,8 @@ static int wm831x_alive_ldo_list_voltage(struct regulator_dev *rdev,
666 677
667static int wm831x_alive_ldo_set_voltage_int(struct regulator_dev *rdev, 678static int wm831x_alive_ldo_set_voltage_int(struct regulator_dev *rdev,
668 int reg, 679 int reg,
669 int min_uV, int max_uV) 680 int min_uV, int max_uV,
681 unsigned *selector)
670{ 682{
671 struct wm831x_ldo *ldo = rdev_get_drvdata(rdev); 683 struct wm831x_ldo *ldo = rdev_get_drvdata(rdev);
672 struct wm831x *wm831x = ldo->wm831x; 684 struct wm831x *wm831x = ldo->wm831x;
@@ -680,16 +692,20 @@ static int wm831x_alive_ldo_set_voltage_int(struct regulator_dev *rdev,
680 if (ret < min_uV || ret > max_uV) 692 if (ret < min_uV || ret > max_uV)
681 return -EINVAL; 693 return -EINVAL;
682 694
695 *selector = vsel;
696
683 return wm831x_set_bits(wm831x, reg, WM831X_LDO11_ON_VSEL_MASK, vsel); 697 return wm831x_set_bits(wm831x, reg, WM831X_LDO11_ON_VSEL_MASK, vsel);
684} 698}
685 699
686static int wm831x_alive_ldo_set_voltage(struct regulator_dev *rdev, 700static int wm831x_alive_ldo_set_voltage(struct regulator_dev *rdev,
687 int min_uV, int max_uV) 701 int min_uV, int max_uV,
702 unsigned *selector)
688{ 703{
689 struct wm831x_ldo *ldo = rdev_get_drvdata(rdev); 704 struct wm831x_ldo *ldo = rdev_get_drvdata(rdev);
690 int reg = ldo->base + WM831X_ALIVE_LDO_ON_CONTROL; 705 int reg = ldo->base + WM831X_ALIVE_LDO_ON_CONTROL;
691 706
692 return wm831x_alive_ldo_set_voltage_int(rdev, reg, min_uV, max_uV); 707 return wm831x_alive_ldo_set_voltage_int(rdev, reg, min_uV, max_uV,
708 selector);
693} 709}
694 710
695static int wm831x_alive_ldo_set_suspend_voltage(struct regulator_dev *rdev, 711static int wm831x_alive_ldo_set_suspend_voltage(struct regulator_dev *rdev,
@@ -697,11 +713,12 @@ static int wm831x_alive_ldo_set_suspend_voltage(struct regulator_dev *rdev,
697{ 713{
698 struct wm831x_ldo *ldo = rdev_get_drvdata(rdev); 714 struct wm831x_ldo *ldo = rdev_get_drvdata(rdev);
699 int reg = ldo->base + WM831X_ALIVE_LDO_SLEEP_CONTROL; 715 int reg = ldo->base + WM831X_ALIVE_LDO_SLEEP_CONTROL;
716 unsigned selector;
700 717
701 return wm831x_alive_ldo_set_voltage_int(rdev, reg, uV, uV); 718 return wm831x_alive_ldo_set_voltage_int(rdev, reg, uV, uV, &selector);
702} 719}
703 720
704static int wm831x_alive_ldo_get_voltage(struct regulator_dev *rdev) 721static int wm831x_alive_ldo_get_voltage_sel(struct regulator_dev *rdev)
705{ 722{
706 struct wm831x_ldo *ldo = rdev_get_drvdata(rdev); 723 struct wm831x_ldo *ldo = rdev_get_drvdata(rdev);
707 struct wm831x *wm831x = ldo->wm831x; 724 struct wm831x *wm831x = ldo->wm831x;
@@ -714,7 +731,7 @@ static int wm831x_alive_ldo_get_voltage(struct regulator_dev *rdev)
714 731
715 ret &= WM831X_LDO11_ON_VSEL_MASK; 732 ret &= WM831X_LDO11_ON_VSEL_MASK;
716 733
717 return wm831x_alive_ldo_list_voltage(rdev, ret); 734 return ret;
718} 735}
719 736
720static int wm831x_alive_ldo_get_status(struct regulator_dev *rdev) 737static int wm831x_alive_ldo_get_status(struct regulator_dev *rdev)
@@ -736,7 +753,7 @@ static int wm831x_alive_ldo_get_status(struct regulator_dev *rdev)
736 753
737static struct regulator_ops wm831x_alive_ldo_ops = { 754static struct regulator_ops wm831x_alive_ldo_ops = {
738 .list_voltage = wm831x_alive_ldo_list_voltage, 755 .list_voltage = wm831x_alive_ldo_list_voltage,
739 .get_voltage = wm831x_alive_ldo_get_voltage, 756 .get_voltage_sel = wm831x_alive_ldo_get_voltage_sel,
740 .set_voltage = wm831x_alive_ldo_set_voltage, 757 .set_voltage = wm831x_alive_ldo_set_voltage,
741 .set_suspend_voltage = wm831x_alive_ldo_set_suspend_voltage, 758 .set_suspend_voltage = wm831x_alive_ldo_set_suspend_voltage,
742 .get_status = wm831x_alive_ldo_get_status, 759 .get_status = wm831x_alive_ldo_get_status,
diff --git a/drivers/regulator/wm8350-regulator.c b/drivers/regulator/wm8350-regulator.c
index fe4b8a8a9dfd..1bcb22c44095 100644
--- a/drivers/regulator/wm8350-regulator.c
+++ b/drivers/regulator/wm8350-regulator.c
@@ -360,7 +360,7 @@ int wm8350_isink_set_flash(struct wm8350 *wm8350, int isink, u16 mode,
360EXPORT_SYMBOL_GPL(wm8350_isink_set_flash); 360EXPORT_SYMBOL_GPL(wm8350_isink_set_flash);
361 361
362static int wm8350_dcdc_set_voltage(struct regulator_dev *rdev, int min_uV, 362static int wm8350_dcdc_set_voltage(struct regulator_dev *rdev, int min_uV,
363 int max_uV) 363 int max_uV, unsigned *selector)
364{ 364{
365 struct wm8350 *wm8350 = rdev_get_drvdata(rdev); 365 struct wm8350 *wm8350 = rdev_get_drvdata(rdev);
366 int volt_reg, dcdc = rdev_get_id(rdev), mV, 366 int volt_reg, dcdc = rdev_get_id(rdev), mV,
@@ -397,17 +397,18 @@ static int wm8350_dcdc_set_voltage(struct regulator_dev *rdev, int min_uV,
397 return -EINVAL; 397 return -EINVAL;
398 } 398 }
399 399
400 *selector = mV;
401
400 /* all DCDCs have same mV bits */ 402 /* all DCDCs have same mV bits */
401 val = wm8350_reg_read(wm8350, volt_reg) & ~WM8350_DC1_VSEL_MASK; 403 val = wm8350_reg_read(wm8350, volt_reg) & ~WM8350_DC1_VSEL_MASK;
402 wm8350_reg_write(wm8350, volt_reg, val | mV); 404 wm8350_reg_write(wm8350, volt_reg, val | mV);
403 return 0; 405 return 0;
404} 406}
405 407
406static int wm8350_dcdc_get_voltage(struct regulator_dev *rdev) 408static int wm8350_dcdc_get_voltage_sel(struct regulator_dev *rdev)
407{ 409{
408 struct wm8350 *wm8350 = rdev_get_drvdata(rdev); 410 struct wm8350 *wm8350 = rdev_get_drvdata(rdev);
409 int volt_reg, dcdc = rdev_get_id(rdev); 411 int volt_reg, dcdc = rdev_get_id(rdev);
410 u16 val;
411 412
412 switch (dcdc) { 413 switch (dcdc) {
413 case WM8350_DCDC_1: 414 case WM8350_DCDC_1:
@@ -429,8 +430,7 @@ static int wm8350_dcdc_get_voltage(struct regulator_dev *rdev)
429 } 430 }
430 431
431 /* all DCDCs have same mV bits */ 432 /* all DCDCs have same mV bits */
432 val = wm8350_reg_read(wm8350, volt_reg) & WM8350_DC1_VSEL_MASK; 433 return wm8350_reg_read(wm8350, volt_reg) & WM8350_DC1_VSEL_MASK;
433 return wm8350_dcdc_val_to_mvolts(val) * 1000;
434} 434}
435 435
436static int wm8350_dcdc_list_voltage(struct regulator_dev *rdev, 436static int wm8350_dcdc_list_voltage(struct regulator_dev *rdev,
@@ -754,7 +754,7 @@ static int wm8350_ldo_set_suspend_disable(struct regulator_dev *rdev)
754} 754}
755 755
756static int wm8350_ldo_set_voltage(struct regulator_dev *rdev, int min_uV, 756static int wm8350_ldo_set_voltage(struct regulator_dev *rdev, int min_uV,
757 int max_uV) 757 int max_uV, unsigned *selector)
758{ 758{
759 struct wm8350 *wm8350 = rdev_get_drvdata(rdev); 759 struct wm8350 *wm8350 = rdev_get_drvdata(rdev);
760 int volt_reg, ldo = rdev_get_id(rdev), mV, min_mV = min_uV / 1000, 760 int volt_reg, ldo = rdev_get_id(rdev), mV, min_mV = min_uV / 1000,
@@ -797,17 +797,18 @@ static int wm8350_ldo_set_voltage(struct regulator_dev *rdev, int min_uV,
797 return -EINVAL; 797 return -EINVAL;
798 } 798 }
799 799
800 *selector = mV;
801
800 /* all LDOs have same mV bits */ 802 /* all LDOs have same mV bits */
801 val = wm8350_reg_read(wm8350, volt_reg) & ~WM8350_LDO1_VSEL_MASK; 803 val = wm8350_reg_read(wm8350, volt_reg) & ~WM8350_LDO1_VSEL_MASK;
802 wm8350_reg_write(wm8350, volt_reg, val | mV); 804 wm8350_reg_write(wm8350, volt_reg, val | mV);
803 return 0; 805 return 0;
804} 806}
805 807
806static int wm8350_ldo_get_voltage(struct regulator_dev *rdev) 808static int wm8350_ldo_get_voltage_sel(struct regulator_dev *rdev)
807{ 809{
808 struct wm8350 *wm8350 = rdev_get_drvdata(rdev); 810 struct wm8350 *wm8350 = rdev_get_drvdata(rdev);
809 int volt_reg, ldo = rdev_get_id(rdev); 811 int volt_reg, ldo = rdev_get_id(rdev);
810 u16 val;
811 812
812 switch (ldo) { 813 switch (ldo) {
813 case WM8350_LDO_1: 814 case WM8350_LDO_1:
@@ -827,8 +828,7 @@ static int wm8350_ldo_get_voltage(struct regulator_dev *rdev)
827 } 828 }
828 829
829 /* all LDOs have same mV bits */ 830 /* all LDOs have same mV bits */
830 val = wm8350_reg_read(wm8350, volt_reg) & WM8350_LDO1_VSEL_MASK; 831 return wm8350_reg_read(wm8350, volt_reg) & WM8350_LDO1_VSEL_MASK;
831 return wm8350_ldo_val_to_mvolts(val) * 1000;
832} 832}
833 833
834static int wm8350_ldo_list_voltage(struct regulator_dev *rdev, 834static int wm8350_ldo_list_voltage(struct regulator_dev *rdev,
@@ -1225,7 +1225,7 @@ static int wm8350_ldo_is_enabled(struct regulator_dev *rdev)
1225 1225
1226static struct regulator_ops wm8350_dcdc_ops = { 1226static struct regulator_ops wm8350_dcdc_ops = {
1227 .set_voltage = wm8350_dcdc_set_voltage, 1227 .set_voltage = wm8350_dcdc_set_voltage,
1228 .get_voltage = wm8350_dcdc_get_voltage, 1228 .get_voltage_sel = wm8350_dcdc_get_voltage_sel,
1229 .list_voltage = wm8350_dcdc_list_voltage, 1229 .list_voltage = wm8350_dcdc_list_voltage,
1230 .enable = wm8350_dcdc_enable, 1230 .enable = wm8350_dcdc_enable,
1231 .disable = wm8350_dcdc_disable, 1231 .disable = wm8350_dcdc_disable,
@@ -1249,7 +1249,7 @@ static struct regulator_ops wm8350_dcdc2_5_ops = {
1249 1249
1250static struct regulator_ops wm8350_ldo_ops = { 1250static struct regulator_ops wm8350_ldo_ops = {
1251 .set_voltage = wm8350_ldo_set_voltage, 1251 .set_voltage = wm8350_ldo_set_voltage,
1252 .get_voltage = wm8350_ldo_get_voltage, 1252 .get_voltage_sel = wm8350_ldo_get_voltage_sel,
1253 .list_voltage = wm8350_ldo_list_voltage, 1253 .list_voltage = wm8350_ldo_list_voltage,
1254 .enable = wm8350_ldo_enable, 1254 .enable = wm8350_ldo_enable,
1255 .disable = wm8350_ldo_disable, 1255 .disable = wm8350_ldo_disable,
diff --git a/drivers/regulator/wm8400-regulator.c b/drivers/regulator/wm8400-regulator.c
index 924c7eb29ee9..b42d01cef35a 100644
--- a/drivers/regulator/wm8400-regulator.c
+++ b/drivers/regulator/wm8400-regulator.c
@@ -67,7 +67,7 @@ static int wm8400_ldo_get_voltage(struct regulator_dev *dev)
67} 67}
68 68
69static int wm8400_ldo_set_voltage(struct regulator_dev *dev, 69static int wm8400_ldo_set_voltage(struct regulator_dev *dev,
70 int min_uV, int max_uV) 70 int min_uV, int max_uV, unsigned *selector)
71{ 71{
72 struct wm8400 *wm8400 = rdev_get_drvdata(dev); 72 struct wm8400 *wm8400 = rdev_get_drvdata(dev);
73 u16 val; 73 u16 val;
@@ -93,6 +93,8 @@ static int wm8400_ldo_set_voltage(struct regulator_dev *dev,
93 val += 0xf; 93 val += 0xf;
94 } 94 }
95 95
96 *selector = val;
97
96 return wm8400_set_bits(wm8400, WM8400_LDO1_CONTROL + rdev_get_id(dev), 98 return wm8400_set_bits(wm8400, WM8400_LDO1_CONTROL + rdev_get_id(dev),
97 WM8400_LDO1_VSEL_MASK, val); 99 WM8400_LDO1_VSEL_MASK, val);
98} 100}
@@ -156,7 +158,7 @@ static int wm8400_dcdc_get_voltage(struct regulator_dev *dev)
156} 158}
157 159
158static int wm8400_dcdc_set_voltage(struct regulator_dev *dev, 160static int wm8400_dcdc_set_voltage(struct regulator_dev *dev,
159 int min_uV, int max_uV) 161 int min_uV, int max_uV, unsigned *selector)
160{ 162{
161 struct wm8400 *wm8400 = rdev_get_drvdata(dev); 163 struct wm8400 *wm8400 = rdev_get_drvdata(dev);
162 u16 val; 164 u16 val;
@@ -171,6 +173,8 @@ static int wm8400_dcdc_set_voltage(struct regulator_dev *dev,
171 return -EINVAL; 173 return -EINVAL;
172 BUG_ON(850000 + (25000 * val) < min_uV); 174 BUG_ON(850000 + (25000 * val) < min_uV);
173 175
176 *selector = val;
177
174 return wm8400_set_bits(wm8400, WM8400_DCDC1_CONTROL_1 + offset, 178 return wm8400_set_bits(wm8400, WM8400_DCDC1_CONTROL_1 + offset,
175 WM8400_DC1_VSEL_MASK, val); 179 WM8400_DC1_VSEL_MASK, val);
176} 180}
diff --git a/drivers/regulator/wm8994-regulator.c b/drivers/regulator/wm8994-regulator.c
index 03713bc66e4a..35b2958d5106 100644
--- a/drivers/regulator/wm8994-regulator.c
+++ b/drivers/regulator/wm8994-regulator.c
@@ -86,7 +86,7 @@ static int wm8994_ldo1_list_voltage(struct regulator_dev *rdev,
86 return (selector * 100000) + 2400000; 86 return (selector * 100000) + 2400000;
87} 87}
88 88
89static int wm8994_ldo1_get_voltage(struct regulator_dev *rdev) 89static int wm8994_ldo1_get_voltage_sel(struct regulator_dev *rdev)
90{ 90{
91 struct wm8994_ldo *ldo = rdev_get_drvdata(rdev); 91 struct wm8994_ldo *ldo = rdev_get_drvdata(rdev);
92 int val; 92 int val;
@@ -95,13 +95,11 @@ static int wm8994_ldo1_get_voltage(struct regulator_dev *rdev)
95 if (val < 0) 95 if (val < 0)
96 return val; 96 return val;
97 97
98 val = (val & WM8994_LDO1_VSEL_MASK) >> WM8994_LDO1_VSEL_SHIFT; 98 return (val & WM8994_LDO1_VSEL_MASK) >> WM8994_LDO1_VSEL_SHIFT;
99
100 return wm8994_ldo1_list_voltage(rdev, val);
101} 99}
102 100
103static int wm8994_ldo1_set_voltage(struct regulator_dev *rdev, 101static int wm8994_ldo1_set_voltage(struct regulator_dev *rdev,
104 int min_uV, int max_uV) 102 int min_uV, int max_uV, unsigned *s)
105{ 103{
106 struct wm8994_ldo *ldo = rdev_get_drvdata(rdev); 104 struct wm8994_ldo *ldo = rdev_get_drvdata(rdev);
107 int selector, v; 105 int selector, v;
@@ -111,6 +109,7 @@ static int wm8994_ldo1_set_voltage(struct regulator_dev *rdev,
111 if (v < 0 || v > max_uV) 109 if (v < 0 || v > max_uV)
112 return -EINVAL; 110 return -EINVAL;
113 111
112 *s = selector;
114 selector <<= WM8994_LDO1_VSEL_SHIFT; 113 selector <<= WM8994_LDO1_VSEL_SHIFT;
115 114
116 return wm8994_set_bits(ldo->wm8994, WM8994_LDO_1, 115 return wm8994_set_bits(ldo->wm8994, WM8994_LDO_1,
@@ -124,20 +123,29 @@ static struct regulator_ops wm8994_ldo1_ops = {
124 .enable_time = wm8994_ldo_enable_time, 123 .enable_time = wm8994_ldo_enable_time,
125 124
126 .list_voltage = wm8994_ldo1_list_voltage, 125 .list_voltage = wm8994_ldo1_list_voltage,
127 .get_voltage = wm8994_ldo1_get_voltage, 126 .get_voltage_sel = wm8994_ldo1_get_voltage_sel,
128 .set_voltage = wm8994_ldo1_set_voltage, 127 .set_voltage = wm8994_ldo1_set_voltage,
129}; 128};
130 129
131static int wm8994_ldo2_list_voltage(struct regulator_dev *rdev, 130static int wm8994_ldo2_list_voltage(struct regulator_dev *rdev,
132 unsigned int selector) 131 unsigned int selector)
133{ 132{
133 struct wm8994_ldo *ldo = rdev_get_drvdata(rdev);
134
134 if (selector > WM8994_LDO2_MAX_SELECTOR) 135 if (selector > WM8994_LDO2_MAX_SELECTOR)
135 return -EINVAL; 136 return -EINVAL;
136 137
137 return (selector * 100000) + 900000; 138 switch (ldo->wm8994->type) {
139 case WM8994:
140 return (selector * 100000) + 900000;
141 case WM8958:
142 return (selector * 100000) + 1000000;
143 default:
144 return -EINVAL;
145 }
138} 146}
139 147
140static int wm8994_ldo2_get_voltage(struct regulator_dev *rdev) 148static int wm8994_ldo2_get_voltage_sel(struct regulator_dev *rdev)
141{ 149{
142 struct wm8994_ldo *ldo = rdev_get_drvdata(rdev); 150 struct wm8994_ldo *ldo = rdev_get_drvdata(rdev);
143 int val; 151 int val;
@@ -146,22 +154,31 @@ static int wm8994_ldo2_get_voltage(struct regulator_dev *rdev)
146 if (val < 0) 154 if (val < 0)
147 return val; 155 return val;
148 156
149 val = (val & WM8994_LDO2_VSEL_MASK) >> WM8994_LDO2_VSEL_SHIFT; 157 return (val & WM8994_LDO2_VSEL_MASK) >> WM8994_LDO2_VSEL_SHIFT;
150
151 return wm8994_ldo2_list_voltage(rdev, val);
152} 158}
153 159
154static int wm8994_ldo2_set_voltage(struct regulator_dev *rdev, 160static int wm8994_ldo2_set_voltage(struct regulator_dev *rdev,
155 int min_uV, int max_uV) 161 int min_uV, int max_uV, unsigned *s)
156{ 162{
157 struct wm8994_ldo *ldo = rdev_get_drvdata(rdev); 163 struct wm8994_ldo *ldo = rdev_get_drvdata(rdev);
158 int selector, v; 164 int selector, v;
159 165
160 selector = (min_uV - 900000) / 100000; 166 switch (ldo->wm8994->type) {
167 case WM8994:
168 selector = (min_uV - 900000) / 100000;
169 break;
170 case WM8958:
171 selector = (min_uV - 1000000) / 100000;
172 break;
173 default:
174 return -EINVAL;
175 }
176
161 v = wm8994_ldo2_list_voltage(rdev, selector); 177 v = wm8994_ldo2_list_voltage(rdev, selector);
162 if (v < 0 || v > max_uV) 178 if (v < 0 || v > max_uV)
163 return -EINVAL; 179 return -EINVAL;
164 180
181 *s = selector;
165 selector <<= WM8994_LDO2_VSEL_SHIFT; 182 selector <<= WM8994_LDO2_VSEL_SHIFT;
166 183
167 return wm8994_set_bits(ldo->wm8994, WM8994_LDO_2, 184 return wm8994_set_bits(ldo->wm8994, WM8994_LDO_2,
@@ -175,7 +192,7 @@ static struct regulator_ops wm8994_ldo2_ops = {
175 .enable_time = wm8994_ldo_enable_time, 192 .enable_time = wm8994_ldo_enable_time,
176 193
177 .list_voltage = wm8994_ldo2_list_voltage, 194 .list_voltage = wm8994_ldo2_list_voltage,
178 .get_voltage = wm8994_ldo2_get_voltage, 195 .get_voltage_sel = wm8994_ldo2_get_voltage_sel,
179 .set_voltage = wm8994_ldo2_set_voltage, 196 .set_voltage = wm8994_ldo2_set_voltage,
180}; 197};
181 198
diff --git a/drivers/rtc/rtc-cmos.c b/drivers/rtc/rtc-cmos.c
index 7e6ce626b7f1..c7ff8df347e7 100644
--- a/drivers/rtc/rtc-cmos.c
+++ b/drivers/rtc/rtc-cmos.c
@@ -36,6 +36,7 @@
36#include <linux/platform_device.h> 36#include <linux/platform_device.h>
37#include <linux/mod_devicetable.h> 37#include <linux/mod_devicetable.h>
38#include <linux/log2.h> 38#include <linux/log2.h>
39#include <linux/pm.h>
39 40
40/* this is for "generic access to PC-style RTC" using CMOS_READ/CMOS_WRITE */ 41/* this is for "generic access to PC-style RTC" using CMOS_READ/CMOS_WRITE */
41#include <asm-generic/rtc.h> 42#include <asm-generic/rtc.h>
@@ -851,7 +852,7 @@ static void __exit cmos_do_remove(struct device *dev)
851 852
852#ifdef CONFIG_PM 853#ifdef CONFIG_PM
853 854
854static int cmos_suspend(struct device *dev, pm_message_t mesg) 855static int cmos_suspend(struct device *dev)
855{ 856{
856 struct cmos_rtc *cmos = dev_get_drvdata(dev); 857 struct cmos_rtc *cmos = dev_get_drvdata(dev);
857 unsigned char tmp; 858 unsigned char tmp;
@@ -899,7 +900,7 @@ static int cmos_suspend(struct device *dev, pm_message_t mesg)
899 */ 900 */
900static inline int cmos_poweroff(struct device *dev) 901static inline int cmos_poweroff(struct device *dev)
901{ 902{
902 return cmos_suspend(dev, PMSG_HIBERNATE); 903 return cmos_suspend(dev);
903} 904}
904 905
905static int cmos_resume(struct device *dev) 906static int cmos_resume(struct device *dev)
@@ -946,9 +947,9 @@ static int cmos_resume(struct device *dev)
946 return 0; 947 return 0;
947} 948}
948 949
950static SIMPLE_DEV_PM_OPS(cmos_pm_ops, cmos_suspend, cmos_resume);
951
949#else 952#else
950#define cmos_suspend NULL
951#define cmos_resume NULL
952 953
953static inline int cmos_poweroff(struct device *dev) 954static inline int cmos_poweroff(struct device *dev)
954{ 955{
@@ -1078,7 +1079,7 @@ static void __exit cmos_pnp_remove(struct pnp_dev *pnp)
1078 1079
1079static int cmos_pnp_suspend(struct pnp_dev *pnp, pm_message_t mesg) 1080static int cmos_pnp_suspend(struct pnp_dev *pnp, pm_message_t mesg)
1080{ 1081{
1081 return cmos_suspend(&pnp->dev, mesg); 1082 return cmos_suspend(&pnp->dev);
1082} 1083}
1083 1084
1084static int cmos_pnp_resume(struct pnp_dev *pnp) 1085static int cmos_pnp_resume(struct pnp_dev *pnp)
@@ -1158,8 +1159,9 @@ static struct platform_driver cmos_platform_driver = {
1158 .shutdown = cmos_platform_shutdown, 1159 .shutdown = cmos_platform_shutdown,
1159 .driver = { 1160 .driver = {
1160 .name = (char *) driver_name, 1161 .name = (char *) driver_name,
1161 .suspend = cmos_suspend, 1162#ifdef CONFIG_PM
1162 .resume = cmos_resume, 1163 .pm = &cmos_pm_ops,
1164#endif
1163 } 1165 }
1164}; 1166};
1165 1167
diff --git a/drivers/rtc/rtc-max6902.c b/drivers/rtc/rtc-max6902.c
index 657403ebd54a..0ec3f588a255 100644
--- a/drivers/rtc/rtc-max6902.c
+++ b/drivers/rtc/rtc-max6902.c
@@ -139,12 +139,13 @@ static int __devinit max6902_probe(struct spi_device *spi)
139 if (IS_ERR(rtc)) 139 if (IS_ERR(rtc))
140 return PTR_ERR(rtc); 140 return PTR_ERR(rtc);
141 141
142 dev_set_drvdata(&spi->dev, rtc);
142 return 0; 143 return 0;
143} 144}
144 145
145static int __devexit max6902_remove(struct spi_device *spi) 146static int __devexit max6902_remove(struct spi_device *spi)
146{ 147{
147 struct rtc_device *rtc = platform_get_drvdata(spi); 148 struct rtc_device *rtc = dev_get_drvdata(&spi->dev);
148 149
149 rtc_device_unregister(rtc); 150 rtc_device_unregister(rtc);
150 return 0; 151 return 0;
diff --git a/drivers/rtc/rtc-omap.c b/drivers/rtc/rtc-omap.c
index 73377b0d65da..e72b523c79a5 100644
--- a/drivers/rtc/rtc-omap.c
+++ b/drivers/rtc/rtc-omap.c
@@ -429,13 +429,14 @@ fail1:
429fail0: 429fail0:
430 iounmap(rtc_base); 430 iounmap(rtc_base);
431fail: 431fail:
432 release_resource(mem); 432 release_mem_region(mem->start, resource_size(mem));
433 return -EIO; 433 return -EIO;
434} 434}
435 435
436static int __exit omap_rtc_remove(struct platform_device *pdev) 436static int __exit omap_rtc_remove(struct platform_device *pdev)
437{ 437{
438 struct rtc_device *rtc = platform_get_drvdata(pdev); 438 struct rtc_device *rtc = platform_get_drvdata(pdev);
439 struct resource *mem = dev_get_drvdata(&rtc->dev);
439 440
440 device_init_wakeup(&pdev->dev, 0); 441 device_init_wakeup(&pdev->dev, 0);
441 442
@@ -447,8 +448,9 @@ static int __exit omap_rtc_remove(struct platform_device *pdev)
447 if (omap_rtc_timer != omap_rtc_alarm) 448 if (omap_rtc_timer != omap_rtc_alarm)
448 free_irq(omap_rtc_alarm, rtc); 449 free_irq(omap_rtc_alarm, rtc);
449 450
450 release_resource(dev_get_drvdata(&rtc->dev));
451 rtc_device_unregister(rtc); 451 rtc_device_unregister(rtc);
452 iounmap(rtc_base);
453 release_mem_region(mem->start, resource_size(mem));
452 return 0; 454 return 0;
453} 455}
454 456
diff --git a/drivers/s390/net/lcs.c b/drivers/s390/net/lcs.c
index 09e7a053c844..30b2a820e670 100644
--- a/drivers/s390/net/lcs.c
+++ b/drivers/s390/net/lcs.c
@@ -841,7 +841,7 @@ lcs_notify_lancmd_waiters(struct lcs_card *card, struct lcs_cmd *cmd)
841} 841}
842 842
843/** 843/**
844 * Emit buffer of a lan comand. 844 * Emit buffer of a lan command.
845 */ 845 */
846static void 846static void
847lcs_lancmd_timeout(unsigned long data) 847lcs_lancmd_timeout(unsigned long data)
diff --git a/drivers/s390/scsi/zfcp_cfdc.c b/drivers/s390/scsi/zfcp_cfdc.c
index 46342fee394d..303dde09d294 100644
--- a/drivers/s390/scsi/zfcp_cfdc.c
+++ b/drivers/s390/scsi/zfcp_cfdc.c
@@ -317,7 +317,7 @@ static void zfcp_act_eval_err(struct zfcp_adapter *adapter, u32 table)
317 317
318/** 318/**
319 * zfcp_cfdc_port_denied - Process "access denied" for port 319 * zfcp_cfdc_port_denied - Process "access denied" for port
320 * @port: The port where the acces has been denied 320 * @port: The port where the access has been denied
321 * @qual: The FSF status qualifier for the access denied FSF status 321 * @qual: The FSF status qualifier for the access denied FSF status
322 */ 322 */
323void zfcp_cfdc_port_denied(struct zfcp_port *port, 323void zfcp_cfdc_port_denied(struct zfcp_port *port,
diff --git a/drivers/scsi/a100u2w.c b/drivers/scsi/a100u2w.c
index dc5ac6e528c4..a391090a17c5 100644
--- a/drivers/scsi/a100u2w.c
+++ b/drivers/scsi/a100u2w.c
@@ -416,7 +416,7 @@ static u8 orc_load_firmware(struct orc_host * host)
416 /* Go back and check they match */ 416 /* Go back and check they match */
417 417
418 outb(PRGMRST | DOWNLOAD, host->base + ORC_RISCCTL); /* Reset program count 0 */ 418 outb(PRGMRST | DOWNLOAD, host->base + ORC_RISCCTL); /* Reset program count 0 */
419 bios_addr -= 0x1000; /* Reset the BIOS adddress */ 419 bios_addr -= 0x1000; /* Reset the BIOS address */
420 for (i = 0, data32_ptr = (u8 *) & data32; /* Check the code */ 420 for (i = 0, data32_ptr = (u8 *) & data32; /* Check the code */
421 i < 0x1000; /* Firmware code size = 4K */ 421 i < 0x1000; /* Firmware code size = 4K */
422 i++, bios_addr++) { 422 i++, bios_addr++) {
diff --git a/drivers/scsi/aacraid/commsup.c b/drivers/scsi/aacraid/commsup.c
index afc9aeba5edb..060ac4bd5a14 100644
--- a/drivers/scsi/aacraid/commsup.c
+++ b/drivers/scsi/aacraid/commsup.c
@@ -91,7 +91,7 @@ void aac_fib_map_free(struct aac_dev *dev)
91 * aac_fib_setup - setup the fibs 91 * aac_fib_setup - setup the fibs
92 * @dev: Adapter to set up 92 * @dev: Adapter to set up
93 * 93 *
94 * Allocate the PCI space for the fibs, map it and then intialise the 94 * Allocate the PCI space for the fibs, map it and then initialise the
95 * fib area, the unmapped fib data and also the free list 95 * fib area, the unmapped fib data and also the free list
96 */ 96 */
97 97
diff --git a/drivers/scsi/aic7xxx_old/aic7xxx.seq b/drivers/scsi/aic7xxx_old/aic7xxx.seq
index 5997e7c3a191..1565be9ebd49 100644
--- a/drivers/scsi/aic7xxx_old/aic7xxx.seq
+++ b/drivers/scsi/aic7xxx_old/aic7xxx.seq
@@ -1178,7 +1178,7 @@ notFound:
1178/* 1178/*
1179 * Retrieve an SCB by SCBID first searching the disconnected list falling 1179 * Retrieve an SCB by SCBID first searching the disconnected list falling
1180 * back to DMA'ing the SCB down from the host. This routine assumes that 1180 * back to DMA'ing the SCB down from the host. This routine assumes that
1181 * ARG_1 is the SCBID of interrest and that SINDEX is the position in the 1181 * ARG_1 is the SCBID of interest and that SINDEX is the position in the
1182 * disconnected list to start the search from. If SINDEX is SCB_LIST_NULL, 1182 * disconnected list to start the search from. If SINDEX is SCB_LIST_NULL,
1183 * we go directly to the host for the SCB. 1183 * we go directly to the host for the SCB.
1184 */ 1184 */
diff --git a/drivers/scsi/aic94xx/aic94xx_reg_def.h b/drivers/scsi/aic94xx/aic94xx_reg_def.h
index 28aaf349c111..40273a747d29 100644
--- a/drivers/scsi/aic94xx/aic94xx_reg_def.h
+++ b/drivers/scsi/aic94xx/aic94xx_reg_def.h
@@ -1689,7 +1689,7 @@
1689#define PHY_START_CAL 0x01 1689#define PHY_START_CAL 0x01
1690 1690
1691/* 1691/*
1692 * HST_PCIX2 Registers, Addresss Range: (0x00-0xFC) 1692 * HST_PCIX2 Registers, Address Range: (0x00-0xFC)
1693 */ 1693 */
1694#define PCIX_REG_BASE_ADR 0xB8040000 1694#define PCIX_REG_BASE_ADR 0xB8040000
1695 1695
@@ -1802,7 +1802,7 @@
1802#define PCIC_TP_CTRL 0xFC 1802#define PCIC_TP_CTRL 0xFC
1803 1803
1804/* 1804/*
1805 * EXSI Registers, Addresss Range: (0x00-0xFC) 1805 * EXSI Registers, Address Range: (0x00-0xFC)
1806 */ 1806 */
1807#define EXSI_REG_BASE_ADR REG_BASE_ADDR_EXSI 1807#define EXSI_REG_BASE_ADR REG_BASE_ADDR_EXSI
1808 1808
diff --git a/drivers/scsi/aic94xx/aic94xx_scb.c b/drivers/scsi/aic94xx/aic94xx_scb.c
index c43698b1cb64..29593275201a 100644
--- a/drivers/scsi/aic94xx/aic94xx_scb.c
+++ b/drivers/scsi/aic94xx/aic94xx_scb.c
@@ -867,7 +867,7 @@ void asd_build_initiate_link_adm_task(struct asd_ascb *ascb, int phy_id,
867 * resources they have with this SCB, and then call this one at the 867 * resources they have with this SCB, and then call this one at the
868 * end of their timeout function. To do this, one should initialize 868 * end of their timeout function. To do this, one should initialize
869 * the ascb->timer.{function, data, expires} prior to calling the post 869 * the ascb->timer.{function, data, expires} prior to calling the post
870 * funcion. The timer is started by the post function. 870 * function. The timer is started by the post function.
871 */ 871 */
872void asd_ascb_timedout(unsigned long data) 872void asd_ascb_timedout(unsigned long data)
873{ 873{
diff --git a/drivers/scsi/aic94xx/aic94xx_seq.c b/drivers/scsi/aic94xx/aic94xx_seq.c
index 74374618010c..390168f62a13 100644
--- a/drivers/scsi/aic94xx/aic94xx_seq.c
+++ b/drivers/scsi/aic94xx/aic94xx_seq.c
@@ -797,7 +797,7 @@ static void asd_init_lseq_mdp(struct asd_ha_struct *asd_ha, int lseq)
797 int j; 797 int j;
798 /* Start from Page 1 of Mode 0 and 1. */ 798 /* Start from Page 1 of Mode 0 and 1. */
799 moffs = LSEQ_PAGE_SIZE + i*LSEQ_MODE_SCRATCH_SIZE; 799 moffs = LSEQ_PAGE_SIZE + i*LSEQ_MODE_SCRATCH_SIZE;
800 /* All the fields of page 1 can be intialized to 0. */ 800 /* All the fields of page 1 can be initialized to 0. */
801 for (j = 0; j < LSEQ_PAGE_SIZE; j += 4) 801 for (j = 0; j < LSEQ_PAGE_SIZE; j += 4)
802 asd_write_reg_dword(asd_ha, LmSCRATCH(lseq)+moffs+j,0); 802 asd_write_reg_dword(asd_ha, LmSCRATCH(lseq)+moffs+j,0);
803 } 803 }
@@ -938,7 +938,7 @@ static void asd_init_cseq_cio(struct asd_ha_struct *asd_ha)
938 asd_write_reg_dword(asd_ha, SCBPRO, 0); 938 asd_write_reg_dword(asd_ha, SCBPRO, 0);
939 asd_write_reg_dword(asd_ha, CSEQCON, 0); 939 asd_write_reg_dword(asd_ha, CSEQCON, 0);
940 940
941 /* Intialize CSEQ Mode 11 Interrupt Vectors. 941 /* Initialize CSEQ Mode 11 Interrupt Vectors.
942 * The addresses are 16 bit wide and in dword units. 942 * The addresses are 16 bit wide and in dword units.
943 * The values of their macros are in byte units. 943 * The values of their macros are in byte units.
944 * Thus we have to divide by 4. */ 944 * Thus we have to divide by 4. */
@@ -961,7 +961,7 @@ static void asd_init_cseq_cio(struct asd_ha_struct *asd_ha)
961 asd_write_reg_word(asd_ha, CPRGMCNT, cseq_idle_loop); 961 asd_write_reg_word(asd_ha, CPRGMCNT, cseq_idle_loop);
962 962
963 for (i = 0; i < 8; i++) { 963 for (i = 0; i < 8; i++) {
964 /* Intialize Mode n Link m Interrupt Enable. */ 964 /* Initialize Mode n Link m Interrupt Enable. */
965 asd_write_reg_dword(asd_ha, CMnINTEN(i), EN_CMnRSPMBXF); 965 asd_write_reg_dword(asd_ha, CMnINTEN(i), EN_CMnRSPMBXF);
966 /* Initialize Mode n Request Mailbox. */ 966 /* Initialize Mode n Request Mailbox. */
967 asd_write_reg_dword(asd_ha, CMnREQMBX(i), 0); 967 asd_write_reg_dword(asd_ha, CMnREQMBX(i), 0);
diff --git a/drivers/scsi/bfa/bfa_fcpim.c b/drivers/scsi/bfa/bfa_fcpim.c
index 9c410b21db6d..c0353cdca929 100644
--- a/drivers/scsi/bfa/bfa_fcpim.c
+++ b/drivers/scsi/bfa/bfa_fcpim.c
@@ -1838,7 +1838,7 @@ bfa_ioim_sm_cleanup_qfull(struct bfa_ioim_s *ioim, enum bfa_ioim_event event)
1838 1838
1839 case BFA_IOIM_SM_ABORT: 1839 case BFA_IOIM_SM_ABORT:
1840 /* 1840 /*
1841 * IO is alraedy being cleaned up implicitly 1841 * IO is already being cleaned up implicitly
1842 */ 1842 */
1843 ioim->io_cbfn = __bfa_cb_ioim_abort; 1843 ioim->io_cbfn = __bfa_cb_ioim_abort;
1844 break; 1844 break;
diff --git a/drivers/scsi/bfa/bfa_fcs_lport.c b/drivers/scsi/bfa/bfa_fcs_lport.c
index 4e2eb92ba028..43fa986bb586 100644
--- a/drivers/scsi/bfa/bfa_fcs_lport.c
+++ b/drivers/scsi/bfa/bfa_fcs_lport.c
@@ -5646,7 +5646,7 @@ bfa_cb_lps_fdisc_comp(void *bfad, void *uarg, bfa_status_t status)
5646 switch (status) { 5646 switch (status) {
5647 case BFA_STATUS_OK: 5647 case BFA_STATUS_OK:
5648 /* 5648 /*
5649 * Initialiaze the V-Port fields 5649 * Initialize the V-Port fields
5650 */ 5650 */
5651 __vport_fcid(vport) = vport->lps->lp_pid; 5651 __vport_fcid(vport) = vport->lps->lp_pid;
5652 vport->vport_stats.fdisc_accepts++; 5652 vport->vport_stats.fdisc_accepts++;
diff --git a/drivers/scsi/dc395x.c b/drivers/scsi/dc395x.c
index 8f1b5c8bf903..b0f8523e665f 100644
--- a/drivers/scsi/dc395x.c
+++ b/drivers/scsi/dc395x.c
@@ -3796,7 +3796,7 @@ static struct DeviceCtlBlk *device_alloc(struct AdapterCtlBlk *acb,
3796 * adapter_add_device - Adds the device instance to the adaptor instance. 3796 * adapter_add_device - Adds the device instance to the adaptor instance.
3797 * 3797 *
3798 * @acb: The adapter device to be updated 3798 * @acb: The adapter device to be updated
3799 * @dcb: A newly created and intialised device instance to add. 3799 * @dcb: A newly created and initialised device instance to add.
3800 **/ 3800 **/
3801static void adapter_add_device(struct AdapterCtlBlk *acb, 3801static void adapter_add_device(struct AdapterCtlBlk *acb,
3802 struct DeviceCtlBlk *dcb) 3802 struct DeviceCtlBlk *dcb)
@@ -4498,7 +4498,7 @@ static void __devinit adapter_init_chip(struct AdapterCtlBlk *acb)
4498 * init_adapter - Grab the resource for the card, setup the adapter 4498 * init_adapter - Grab the resource for the card, setup the adapter
4499 * information, set the card into a known state, create the various 4499 * information, set the card into a known state, create the various
4500 * tables etc etc. This basically gets all adapter information all up 4500 * tables etc etc. This basically gets all adapter information all up
4501 * to date, intialised and gets the chip in sync with it. 4501 * to date, initialised and gets the chip in sync with it.
4502 * 4502 *
4503 * @host: This hosts adapter structure 4503 * @host: This hosts adapter structure
4504 * @io_port: The base I/O port 4504 * @io_port: The base I/O port
@@ -4789,7 +4789,7 @@ static void banner_display(void)
4789 * that it finds in the system. The pci_dev strcuture indicates which 4789 * that it finds in the system. The pci_dev strcuture indicates which
4790 * instance we are being called from. 4790 * instance we are being called from.
4791 * 4791 *
4792 * @dev: The PCI device to intialize. 4792 * @dev: The PCI device to initialize.
4793 * @id: Looks like a pointer to the entry in our pci device table 4793 * @id: Looks like a pointer to the entry in our pci device table
4794 * that was actually matched by the PCI subsystem. 4794 * that was actually matched by the PCI subsystem.
4795 * 4795 *
@@ -4860,7 +4860,7 @@ fail:
4860 * dc395x_remove_one - Called to remove a single instance of the 4860 * dc395x_remove_one - Called to remove a single instance of the
4861 * adapter. 4861 * adapter.
4862 * 4862 *
4863 * @dev: The PCI device to intialize. 4863 * @dev: The PCI device to initialize.
4864 **/ 4864 **/
4865static void __devexit dc395x_remove_one(struct pci_dev *dev) 4865static void __devexit dc395x_remove_one(struct pci_dev *dev)
4866{ 4866{
diff --git a/drivers/scsi/libfc/fc_fcp.c b/drivers/scsi/libfc/fc_fcp.c
index cdc06cda76e5..5962d1a5a674 100644
--- a/drivers/scsi/libfc/fc_fcp.c
+++ b/drivers/scsi/libfc/fc_fcp.c
@@ -1250,7 +1250,7 @@ static void fc_lun_reset_send(unsigned long data)
1250/** 1250/**
1251 * fc_lun_reset() - Send a LUN RESET command to a device 1251 * fc_lun_reset() - Send a LUN RESET command to a device
1252 * and wait for the reply 1252 * and wait for the reply
1253 * @lport: The local port to sent the comand on 1253 * @lport: The local port to sent the command on
1254 * @fsp: The FCP packet that identifies the LUN to be reset 1254 * @fsp: The FCP packet that identifies the LUN to be reset
1255 * @id: The SCSI command ID 1255 * @id: The SCSI command ID
1256 * @lun: The LUN ID to be reset 1256 * @lun: The LUN ID to be reset
diff --git a/drivers/scsi/lpfc/lpfc_attr.c b/drivers/scsi/lpfc/lpfc_attr.c
index c06491b5862f..3512abb8a587 100644
--- a/drivers/scsi/lpfc/lpfc_attr.c
+++ b/drivers/scsi/lpfc/lpfc_attr.c
@@ -1335,7 +1335,7 @@ lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1335} 1335}
1336 1336
1337/** 1337/**
1338 * lpfc_param_init - Intializes a cfg attribute 1338 * lpfc_param_init - Initializes a cfg attribute
1339 * 1339 *
1340 * Description: 1340 * Description:
1341 * Macro that given an attr e.g. hba_queue_depth expands 1341 * Macro that given an attr e.g. hba_queue_depth expands
diff --git a/drivers/scsi/lpfc/lpfc_hbadisc.c b/drivers/scsi/lpfc/lpfc_hbadisc.c
index f9f160ab2ee9..bb015960dbc9 100644
--- a/drivers/scsi/lpfc/lpfc_hbadisc.c
+++ b/drivers/scsi/lpfc/lpfc_hbadisc.c
@@ -2852,7 +2852,7 @@ lpfc_mbx_process_link_up(struct lpfc_hba *phba, struct lpfc_mbx_read_top *la)
2852 if (unlikely(!fcf_record)) { 2852 if (unlikely(!fcf_record)) {
2853 lpfc_printf_log(phba, KERN_ERR, 2853 lpfc_printf_log(phba, KERN_ERR,
2854 LOG_MBOX | LOG_SLI, 2854 LOG_MBOX | LOG_SLI,
2855 "2554 Could not allocate memmory for " 2855 "2554 Could not allocate memory for "
2856 "fcf record\n"); 2856 "fcf record\n");
2857 rc = -ENODEV; 2857 rc = -ENODEV;
2858 goto out; 2858 goto out;
diff --git a/drivers/scsi/lpfc/lpfc_init.c b/drivers/scsi/lpfc/lpfc_init.c
index 462242dcdd0a..6d0b36aa3389 100644
--- a/drivers/scsi/lpfc/lpfc_init.c
+++ b/drivers/scsi/lpfc/lpfc_init.c
@@ -8071,7 +8071,7 @@ lpfc_pci_remove_one_s3(struct pci_dev *pdev)
8071 * the HBA. 8071 * the HBA.
8072 */ 8072 */
8073 8073
8074 /* HBA interrupt will be diabled after this call */ 8074 /* HBA interrupt will be disabled after this call */
8075 lpfc_sli_hba_down(phba); 8075 lpfc_sli_hba_down(phba);
8076 /* Stop kthread signal shall trigger work_done one more time */ 8076 /* Stop kthread signal shall trigger work_done one more time */
8077 kthread_stop(phba->worker_thread); 8077 kthread_stop(phba->worker_thread);
diff --git a/drivers/scsi/lpfc/lpfc_sli.c b/drivers/scsi/lpfc/lpfc_sli.c
index 634b2fea9c4d..a359d2b873ce 100644
--- a/drivers/scsi/lpfc/lpfc_sli.c
+++ b/drivers/scsi/lpfc/lpfc_sli.c
@@ -10172,7 +10172,7 @@ lpfc_sli4_intr_handler(int irq, void *dev_id)
10172 * lpfc_sli4_queue_free - free a queue structure and associated memory 10172 * lpfc_sli4_queue_free - free a queue structure and associated memory
10173 * @queue: The queue structure to free. 10173 * @queue: The queue structure to free.
10174 * 10174 *
10175 * This function frees a queue structure and the DMAable memeory used for 10175 * This function frees a queue structure and the DMAable memory used for
10176 * the host resident queue. This function must be called after destroying the 10176 * the host resident queue. This function must be called after destroying the
10177 * queue on the HBA. 10177 * queue on the HBA.
10178 **/ 10178 **/
diff --git a/drivers/scsi/megaraid.h b/drivers/scsi/megaraid.h
index f5644745e24e..853411911b2e 100644
--- a/drivers/scsi/megaraid.h
+++ b/drivers/scsi/megaraid.h
@@ -13,7 +13,7 @@
13 */ 13 */
14 14
15/* 15/*
16 * Comand coalescing - This feature allows the driver to be able to combine 16 * Command coalescing - This feature allows the driver to be able to combine
17 * two or more commands and issue as one command in order to boost I/O 17 * two or more commands and issue as one command in order to boost I/O
18 * performance. Useful if the nature of the I/O is sequential. It is not very 18 * performance. Useful if the nature of the I/O is sequential. It is not very
19 * useful for random natured I/Os. 19 * useful for random natured I/Os.
diff --git a/drivers/scsi/megaraid/megaraid_mm.c b/drivers/scsi/megaraid/megaraid_mm.c
index a7008c0c24f9..25506c777381 100644
--- a/drivers/scsi/megaraid/megaraid_mm.c
+++ b/drivers/scsi/megaraid/megaraid_mm.c
@@ -224,7 +224,7 @@ mraid_mm_unlocked_ioctl(struct file *filep, unsigned int cmd,
224{ 224{
225 int err; 225 int err;
226 226
227 /* inconsistant: mraid_mm_compat_ioctl doesn't take the BKL */ 227 /* inconsistent: mraid_mm_compat_ioctl doesn't take the BKL */
228 mutex_lock(&mraid_mm_mutex); 228 mutex_lock(&mraid_mm_mutex);
229 err = mraid_mm_ioctl(filep, cmd, arg); 229 err = mraid_mm_ioctl(filep, cmd, arg);
230 mutex_unlock(&mraid_mm_mutex); 230 mutex_unlock(&mraid_mm_mutex);
diff --git a/drivers/scsi/pm8001/pm8001_init.c b/drivers/scsi/pm8001/pm8001_init.c
index f8c86b28f03f..b95285f3383f 100644
--- a/drivers/scsi/pm8001/pm8001_init.c
+++ b/drivers/scsi/pm8001/pm8001_init.c
@@ -603,7 +603,7 @@ static u32 pm8001_request_irq(struct pm8001_hba_info *pm8001_ha)
603#endif 603#endif
604 604
605intx: 605intx:
606 /* intialize the INT-X interrupt */ 606 /* initialize the INT-X interrupt */
607 rc = request_irq(pdev->irq, irq_handler, IRQF_SHARED, DRV_NAME, 607 rc = request_irq(pdev->irq, irq_handler, IRQF_SHARED, DRV_NAME,
608 SHOST_TO_SAS_HA(pm8001_ha->shost)); 608 SHOST_TO_SAS_HA(pm8001_ha->shost));
609 return rc; 609 return rc;
diff --git a/drivers/scsi/scsi_netlink.c b/drivers/scsi/scsi_netlink.c
index d53e6503c6d5..a2ed201885ae 100644
--- a/drivers/scsi/scsi_netlink.c
+++ b/drivers/scsi/scsi_netlink.c
@@ -477,7 +477,7 @@ EXPORT_SYMBOL_GPL(scsi_nl_remove_driver);
477 477
478 478
479/** 479/**
480 * scsi_netlink_init - Called by SCSI subsystem to intialize 480 * scsi_netlink_init - Called by SCSI subsystem to initialize
481 * the SCSI transport netlink interface 481 * the SCSI transport netlink interface
482 * 482 *
483 **/ 483 **/
diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c
index 4c68d36f9ac2..490ce213204e 100644
--- a/drivers/scsi/scsi_sysfs.c
+++ b/drivers/scsi/scsi_sysfs.c
@@ -864,13 +864,15 @@ int scsi_sysfs_add_sdev(struct scsi_device *sdev)
864 864
865 error = device_add(&sdev->sdev_gendev); 865 error = device_add(&sdev->sdev_gendev);
866 if (error) { 866 if (error) {
867 printk(KERN_INFO "error 1\n"); 867 sdev_printk(KERN_INFO, sdev,
868 "failed to add device: %d\n", error);
868 return error; 869 return error;
869 } 870 }
870 device_enable_async_suspend(&sdev->sdev_dev); 871 device_enable_async_suspend(&sdev->sdev_dev);
871 error = device_add(&sdev->sdev_dev); 872 error = device_add(&sdev->sdev_dev);
872 if (error) { 873 if (error) {
873 printk(KERN_INFO "error 2\n"); 874 sdev_printk(KERN_INFO, sdev,
875 "failed to add class device: %d\n", error);
874 device_del(&sdev->sdev_gendev); 876 device_del(&sdev->sdev_gendev);
875 return error; 877 return error;
876 } 878 }
diff --git a/drivers/scsi/sym53c8xx_2/sym_glue.c b/drivers/scsi/sym53c8xx_2/sym_glue.c
index 6b97ded9d45d..b4543f575f46 100644
--- a/drivers/scsi/sym53c8xx_2/sym_glue.c
+++ b/drivers/scsi/sym53c8xx_2/sym_glue.c
@@ -1866,7 +1866,7 @@ static pci_ers_result_t sym2_io_slot_dump(struct pci_dev *pdev)
1866 * 1866 *
1867 * This routine is similar to sym_set_workarounds(), except 1867 * This routine is similar to sym_set_workarounds(), except
1868 * that, at this point, we already know that the device was 1868 * that, at this point, we already know that the device was
1869 * successfully intialized at least once before, and so most 1869 * successfully initialized at least once before, and so most
1870 * of the steps taken there are un-needed here. 1870 * of the steps taken there are un-needed here.
1871 */ 1871 */
1872static void sym2_reset_workarounds(struct pci_dev *pdev) 1872static void sym2_reset_workarounds(struct pci_dev *pdev)
diff --git a/drivers/spi/atmel_spi.c b/drivers/spi/atmel_spi.c
index a067046c9da2..1a478bf88c9d 100644
--- a/drivers/spi/atmel_spi.c
+++ b/drivers/spi/atmel_spi.c
@@ -341,9 +341,9 @@ static void atmel_spi_next_message(struct spi_master *master)
341/* 341/*
342 * For DMA, tx_buf/tx_dma have the same relationship as rx_buf/rx_dma: 342 * For DMA, tx_buf/tx_dma have the same relationship as rx_buf/rx_dma:
343 * - The buffer is either valid for CPU access, else NULL 343 * - The buffer is either valid for CPU access, else NULL
344 * - If the buffer is valid, so is its DMA addresss 344 * - If the buffer is valid, so is its DMA address
345 * 345 *
346 * This driver manages the dma addresss unless message->is_dma_mapped. 346 * This driver manages the dma address unless message->is_dma_mapped.
347 */ 347 */
348static int 348static int
349atmel_spi_dma_map_xfer(struct atmel_spi *as, struct spi_transfer *xfer) 349atmel_spi_dma_map_xfer(struct atmel_spi *as, struct spi_transfer *xfer)
diff --git a/drivers/spi/spidev.c b/drivers/spi/spidev.c
index 4e6245e67995..603428213d21 100644
--- a/drivers/spi/spidev.c
+++ b/drivers/spi/spidev.c
@@ -38,7 +38,7 @@
38 38
39 39
40/* 40/*
41 * This supports acccess to SPI devices using normal userspace I/O calls. 41 * This supports access to SPI devices using normal userspace I/O calls.
42 * Note that while traditional UNIX/POSIX I/O semantics are half duplex, 42 * Note that while traditional UNIX/POSIX I/O semantics are half duplex,
43 * and often mask message boundaries, full SPI support requires full duplex 43 * and often mask message boundaries, full SPI support requires full duplex
44 * transfers. There are several kinds of internal message boundaries to 44 * transfers. There are several kinds of internal message boundaries to
diff --git a/drivers/staging/Kconfig b/drivers/staging/Kconfig
index e2d586903432..5c8fcfc42c3e 100644
--- a/drivers/staging/Kconfig
+++ b/drivers/staging/Kconfig
@@ -123,6 +123,8 @@ source "drivers/staging/sep/Kconfig"
123 123
124source "drivers/staging/iio/Kconfig" 124source "drivers/staging/iio/Kconfig"
125 125
126source "drivers/staging/cs5535_gpio/Kconfig"
127
126source "drivers/staging/zram/Kconfig" 128source "drivers/staging/zram/Kconfig"
127 129
128source "drivers/staging/wlags49_h2/Kconfig" 130source "drivers/staging/wlags49_h2/Kconfig"
diff --git a/drivers/staging/Makefile b/drivers/staging/Makefile
index c7d222413c07..d53886317826 100644
--- a/drivers/staging/Makefile
+++ b/drivers/staging/Makefile
@@ -44,6 +44,7 @@ obj-$(CONFIG_VME_BUS) += vme/
44obj-$(CONFIG_MRST_RAR_HANDLER) += memrar/ 44obj-$(CONFIG_MRST_RAR_HANDLER) += memrar/
45obj-$(CONFIG_DX_SEP) += sep/ 45obj-$(CONFIG_DX_SEP) += sep/
46obj-$(CONFIG_IIO) += iio/ 46obj-$(CONFIG_IIO) += iio/
47obj-$(CONFIG_CS5535_GPIO) += cs5535_gpio/
47obj-$(CONFIG_ZRAM) += zram/ 48obj-$(CONFIG_ZRAM) += zram/
48obj-$(CONFIG_WLAGS49_H2) += wlags49_h2/ 49obj-$(CONFIG_WLAGS49_H2) += wlags49_h2/
49obj-$(CONFIG_WLAGS49_H25) += wlags49_h25/ 50obj-$(CONFIG_WLAGS49_H25) += wlags49_h25/
diff --git a/drivers/staging/cs5535_gpio/Kconfig b/drivers/staging/cs5535_gpio/Kconfig
new file mode 100644
index 000000000000..a1b3a8d2b866
--- /dev/null
+++ b/drivers/staging/cs5535_gpio/Kconfig
@@ -0,0 +1,11 @@
1config CS5535_GPIO
2 tristate "AMD CS5535/CS5536 GPIO (Geode Companion Device)"
3 depends on X86_32
4 help
5 Note: this driver is DEPRECATED. Please use the cs5535-gpio module
6 in the GPIO section instead (CONFIG_GPIO_CS5535).
7
8 Give userspace access to the GPIO pins on the AMD CS5535 and
9 CS5536 Geode companion devices.
10
11 If compiled as a module, it will be called cs5535_gpio.
diff --git a/drivers/staging/cs5535_gpio/Makefile b/drivers/staging/cs5535_gpio/Makefile
new file mode 100644
index 000000000000..d67c4b85f191
--- /dev/null
+++ b/drivers/staging/cs5535_gpio/Makefile
@@ -0,0 +1 @@
obj-$(CONFIG_CS5535_GPIO) += cs5535_gpio.o
diff --git a/drivers/staging/cs5535_gpio/TODO b/drivers/staging/cs5535_gpio/TODO
new file mode 100644
index 000000000000..98d1cd1e2363
--- /dev/null
+++ b/drivers/staging/cs5535_gpio/TODO
@@ -0,0 +1,6 @@
1This is an obsolete driver for some the CS5535 and CS5536 southbridge GPIOs.
2It has been replaced by a driver that makes use of the Linux GPIO subsystem.
3Please switch to that driver, and let dilinger@queued.net know if there's
4anything missing from the new driver.
5
6This driver is scheduled for removal in 2.6.40.
diff --git a/drivers/char/cs5535_gpio.c b/drivers/staging/cs5535_gpio/cs5535_gpio.c
index 0cf1e5fad9ab..0cf1e5fad9ab 100644
--- a/drivers/char/cs5535_gpio.c
+++ b/drivers/staging/cs5535_gpio/cs5535_gpio.c
diff --git a/drivers/staging/msm/msm_fb_bl.c b/drivers/staging/msm/msm_fb_bl.c
index 033fc9486e01..2a8077511fc0 100644
--- a/drivers/staging/msm/msm_fb_bl.c
+++ b/drivers/staging/msm/msm_fb_bl.c
@@ -42,7 +42,7 @@ static int msm_fb_bl_update_status(struct backlight_device *pbd)
42 return 0; 42 return 0;
43} 43}
44 44
45static struct backlight_ops msm_fb_bl_ops = { 45static const struct backlight_ops msm_fb_bl_ops = {
46 .get_brightness = msm_fb_bl_get_brightness, 46 .get_brightness = msm_fb_bl_get_brightness,
47 .update_status = msm_fb_bl_update_status, 47 .update_status = msm_fb_bl_update_status,
48}; 48};
diff --git a/drivers/staging/olpc_dcon/TODO b/drivers/staging/olpc_dcon/TODO
index ac2d3d023715..35f9cda7be11 100644
--- a/drivers/staging/olpc_dcon/TODO
+++ b/drivers/staging/olpc_dcon/TODO
@@ -1,6 +1,5 @@
1TODO: 1TODO:
2 - checkpatch.pl cleanups 2 - checkpatch.pl cleanups
3 - port geode gpio calls to newer cs5535 API
4 - see if vx855 gpio API can be made similar enough to cs5535 so we can 3 - see if vx855 gpio API can be made similar enough to cs5535 so we can
5 share more code 4 share more code
6 - allow simultaneous XO-1 and XO-1.5 support 5 - allow simultaneous XO-1 and XO-1.5 support
diff --git a/drivers/staging/olpc_dcon/olpc_dcon.c b/drivers/staging/olpc_dcon/olpc_dcon.c
index 4ca45ec7fd84..9f26dc9408bb 100644
--- a/drivers/staging/olpc_dcon/olpc_dcon.c
+++ b/drivers/staging/olpc_dcon/olpc_dcon.c
@@ -27,7 +27,6 @@
27#include <asm/uaccess.h> 27#include <asm/uaccess.h>
28#include <linux/ctype.h> 28#include <linux/ctype.h>
29#include <linux/reboot.h> 29#include <linux/reboot.h>
30#include <linux/gpio.h>
31#include <asm/tsc.h> 30#include <asm/tsc.h>
32#include <asm/olpc.h> 31#include <asm/olpc.h>
33 32
@@ -49,7 +48,7 @@ struct dcon_platform_data {
49 int (*init)(void); 48 int (*init)(void);
50 void (*bus_stabilize_wiggle)(void); 49 void (*bus_stabilize_wiggle)(void);
51 void (*set_dconload)(int); 50 void (*set_dconload)(int);
52 int (*read_status)(void); 51 u8 (*read_status)(void);
53}; 52};
54 53
55static struct dcon_platform_data *pdata; 54static struct dcon_platform_data *pdata;
@@ -615,7 +614,7 @@ static struct device_attribute dcon_device_files[] = {
615 __ATTR(resumeline, 0644, dcon_resumeline_show, dcon_resumeline_store), 614 __ATTR(resumeline, 0644, dcon_resumeline_show, dcon_resumeline_store),
616}; 615};
617 616
618static struct backlight_ops dcon_bl_ops = { 617static const struct backlight_ops dcon_bl_ops = {
619 .get_brightness = dconbl_get, 618 .get_brightness = dconbl_get,
620 .update_status = dconbl_set 619 .update_status = dconbl_set
621}; 620};
diff --git a/drivers/staging/olpc_dcon/olpc_dcon.h b/drivers/staging/olpc_dcon/olpc_dcon.h
index 6453ca4ba0ee..e566d213da2a 100644
--- a/drivers/staging/olpc_dcon/olpc_dcon.h
+++ b/drivers/staging/olpc_dcon/olpc_dcon.h
@@ -29,26 +29,6 @@
29#define DCON_REG_SCAN_INT 9 29#define DCON_REG_SCAN_INT 9
30#define DCON_REG_BRIGHT 10 30#define DCON_REG_BRIGHT 10
31 31
32/* GPIO registers (CS5536) */
33
34#define MSR_LBAR_GPIO 0x5140000C
35
36#define GPIOx_OUT_VAL 0x00
37#define GPIOx_OUT_EN 0x04
38#define GPIOx_IN_EN 0x20
39#define GPIOx_INV_EN 0x24
40#define GPIOx_IN_FLTR_EN 0x28
41#define GPIOx_EVNTCNT_EN 0x2C
42#define GPIOx_READ_BACK 0x30
43#define GPIOx_EVNT_EN 0x38
44#define GPIOx_NEGEDGE_EN 0x44
45#define GPIOx_NEGEDGE_STS 0x4C
46#define GPIO_FLT7_AMNT 0xD8
47#define GPIO_MAP_X 0xE0
48#define GPIO_MAP_Y 0xE4
49#define GPIO_FE7_SEL 0xF7
50
51
52/* Status values */ 32/* Status values */
53 33
54#define DCONSTAT_SCANINT 0 34#define DCONSTAT_SCANINT 0
diff --git a/drivers/staging/olpc_dcon/olpc_dcon_xo_1.c b/drivers/staging/olpc_dcon/olpc_dcon_xo_1.c
index 779fb7d7b30c..043198dc6ff7 100644
--- a/drivers/staging/olpc_dcon/olpc_dcon_xo_1.c
+++ b/drivers/staging/olpc_dcon/olpc_dcon_xo_1.c
@@ -10,54 +10,70 @@
10 * modify it under the terms of version 2 of the GNU General Public 10 * modify it under the terms of version 2 of the GNU General Public
11 * License as published by the Free Software Foundation. 11 * License as published by the Free Software Foundation.
12 */ 12 */
13 13#include <linux/cs5535.h>
14#include <linux/gpio.h>
14#include <asm/olpc.h> 15#include <asm/olpc.h>
15 16
16#include "olpc_dcon.h" 17#include "olpc_dcon.h"
17 18
18/* Base address of the GPIO registers */
19static unsigned long gpio_base;
20
21/*
22 * List of GPIOs that we care about:
23 * (in) GPIO12 -- DCONBLANK
24 * (in) GPIO[56] -- DCONSTAT[01]
25 * (out) GPIO11 -- DCONLOAD
26 */
27
28#define IN_GPIOS ((1<<5) | (1<<6) | (1<<7) | (1<<12))
29#define OUT_GPIOS (1<<11)
30
31static int dcon_init_xo_1(void) 19static int dcon_init_xo_1(void)
32{ 20{
33 unsigned long lo, hi;
34 unsigned char lob; 21 unsigned char lob;
35 22
36 rdmsr(MSR_LBAR_GPIO, lo, hi); 23 if (gpio_request(OLPC_GPIO_DCON_STAT0, "OLPC-DCON")) {
37 24 printk(KERN_ERR "olpc-dcon: failed to request STAT0 GPIO\n");
38 /* Check the mask and whether GPIO is enabled (sanity check) */ 25 return -EIO;
39 if (hi != 0x0000f001) { 26 }
40 printk(KERN_ERR "GPIO not enabled -- cannot use DCON\n"); 27 if (gpio_request(OLPC_GPIO_DCON_STAT1, "OLPC-DCON")) {
41 return -ENODEV; 28 printk(KERN_ERR "olpc-dcon: failed to request STAT1 GPIO\n");
29 goto err_gp_stat1;
30 }
31 if (gpio_request(OLPC_GPIO_DCON_IRQ, "OLPC-DCON")) {
32 printk(KERN_ERR "olpc-dcon: failed to request IRQ GPIO\n");
33 goto err_gp_irq;
34 }
35 if (gpio_request(OLPC_GPIO_DCON_LOAD, "OLPC-DCON")) {
36 printk(KERN_ERR "olpc-dcon: failed to request LOAD GPIO\n");
37 goto err_gp_load;
38 }
39 if (gpio_request(OLPC_GPIO_DCON_BLANK, "OLPC-DCON")) {
40 printk(KERN_ERR "olpc-dcon: failed to request BLANK GPIO\n");
41 goto err_gp_blank;
42 } 42 }
43
44 /* Mask off the IO base address */
45 gpio_base = lo & 0x0000ff00;
46 43
47 /* Turn off the event enable for GPIO7 just to be safe */ 44 /* Turn off the event enable for GPIO7 just to be safe */
48 outl(1 << (16+7), gpio_base + GPIOx_EVNT_EN); 45 cs5535_gpio_clear(OLPC_GPIO_DCON_IRQ, GPIO_EVENTS_ENABLE);
46
47 /*
48 * Determine the current state by reading the GPIO bit; earlier
49 * stages of the boot process have established the state.
50 *
51 * Note that we read GPIO_OUPUT_VAL rather than GPIO_READ_BACK here;
52 * this is because OFW will disable input for the pin and set a value..
53 * READ_BACK will only contain a valid value if input is enabled and
54 * then a value is set. So, future readings of the pin can use
55 * READ_BACK, but the first one cannot. Awesome, huh?
56 */
57 dcon_source = cs5535_gpio_isset(OLPC_GPIO_DCON_LOAD, GPIO_OUTPUT_VAL)
58 ? DCON_SOURCE_CPU
59 : DCON_SOURCE_DCON;
60 dcon_pending = dcon_source;
49 61
50 /* Set the directions for the GPIO pins */ 62 /* Set the directions for the GPIO pins */
51 outl(OUT_GPIOS | (IN_GPIOS << 16), gpio_base + GPIOx_OUT_EN); 63 gpio_direction_input(OLPC_GPIO_DCON_STAT0);
52 outl(IN_GPIOS | (OUT_GPIOS << 16), gpio_base + GPIOx_IN_EN); 64 gpio_direction_input(OLPC_GPIO_DCON_STAT1);
65 gpio_direction_input(OLPC_GPIO_DCON_IRQ);
66 gpio_direction_input(OLPC_GPIO_DCON_BLANK);
67 gpio_direction_output(OLPC_GPIO_DCON_LOAD,
68 dcon_source == DCON_SOURCE_CPU);
53 69
54 /* Set up the interrupt mappings */ 70 /* Set up the interrupt mappings */
55 71
56 /* Set the IRQ to pair 2 */ 72 /* Set the IRQ to pair 2 */
57 geode_gpio_event_irq(OLPC_GPIO_DCON_IRQ, 2); 73 cs5535_gpio_setup_event(OLPC_GPIO_DCON_IRQ, 2, 0);
58 74
59 /* Enable group 2 to trigger the DCON interrupt */ 75 /* Enable group 2 to trigger the DCON interrupt */
60 geode_gpio_set_irq(2, DCON_IRQ); 76 cs5535_gpio_set_irq(2, DCON_IRQ);
61 77
62 /* Select edge level for interrupt (in PIC) */ 78 /* Select edge level for interrupt (in PIC) */
63 lob = inb(0x4d0); 79 lob = inb(0x4d0);
@@ -65,52 +81,61 @@ static int dcon_init_xo_1(void)
65 outb(lob, 0x4d0); 81 outb(lob, 0x4d0);
66 82
67 /* Register the interupt handler */ 83 /* Register the interupt handler */
68 if (request_irq(DCON_IRQ, &dcon_interrupt, 0, "DCON", &dcon_driver)) 84 if (request_irq(DCON_IRQ, &dcon_interrupt, 0, "DCON", &dcon_driver)) {
69 return -EIO; 85 printk(KERN_ERR "olpc-dcon: failed to request DCON's irq\n");
86 goto err_req_irq;
87 }
70 88
71 /* Clear INV_EN for GPIO7 (DCONIRQ) */ 89 /* Clear INV_EN for GPIO7 (DCONIRQ) */
72 outl((1<<(16+7)), gpio_base + GPIOx_INV_EN); 90 cs5535_gpio_clear(OLPC_GPIO_DCON_IRQ, GPIO_INPUT_INVERT);
73 91
74 /* Enable filter for GPIO12 (DCONBLANK) */ 92 /* Enable filter for GPIO12 (DCONBLANK) */
75 outl(1<<(12), gpio_base + GPIOx_IN_FLTR_EN); 93 cs5535_gpio_set(OLPC_GPIO_DCON_BLANK, GPIO_INPUT_FILTER);
76 94
77 /* Disable filter for GPIO7 */ 95 /* Disable filter for GPIO7 */
78 outl(1<<(16+7), gpio_base + GPIOx_IN_FLTR_EN); 96 cs5535_gpio_clear(OLPC_GPIO_DCON_IRQ, GPIO_INPUT_FILTER);
79 97
80 /* Disable event counter for GPIO7 (DCONIRQ) and GPIO12 (DCONBLANK) */ 98 /* Disable event counter for GPIO7 (DCONIRQ) and GPIO12 (DCONBLANK) */
81 99 cs5535_gpio_clear(OLPC_GPIO_DCON_IRQ, GPIO_INPUT_EVENT_COUNT);
82 outl(1<<(16+7), gpio_base + GPIOx_EVNTCNT_EN); 100 cs5535_gpio_clear(OLPC_GPIO_DCON_BLANK, GPIO_INPUT_EVENT_COUNT);
83 outl(1<<(16+12), gpio_base + GPIOx_EVNTCNT_EN);
84 101
85 /* Add GPIO12 to the Filter Event Pair #7 */ 102 /* Add GPIO12 to the Filter Event Pair #7 */
86 outb(12, gpio_base + GPIO_FE7_SEL); 103 cs5535_gpio_set(OLPC_GPIO_DCON_BLANK, GPIO_FE7_SEL);
87 104
88 /* Turn off negative Edge Enable for GPIO12 */ 105 /* Turn off negative Edge Enable for GPIO12 */
89 outl(1<<(16+12), gpio_base + GPIOx_NEGEDGE_EN); 106 cs5535_gpio_clear(OLPC_GPIO_DCON_BLANK, GPIO_NEGATIVE_EDGE_EN);
90 107
91 /* Enable negative Edge Enable for GPIO7 */ 108 /* Enable negative Edge Enable for GPIO7 */
92 outl(1<<7, gpio_base + GPIOx_NEGEDGE_EN); 109 cs5535_gpio_set(OLPC_GPIO_DCON_IRQ, GPIO_NEGATIVE_EDGE_EN);
93 110
94 /* Zero the filter amount for Filter Event Pair #7 */ 111 /* Zero the filter amount for Filter Event Pair #7 */
95 outw(0, gpio_base + GPIO_FLT7_AMNT); 112 cs5535_gpio_set(0, GPIO_FLTR7_AMOUNT);
96 113
97 /* Clear the negative edge status for GPIO7 and GPIO12 */ 114 /* Clear the negative edge status for GPIO7 and GPIO12 */
98 outl((1<<7) | (1<<12), gpio_base+0x4c); 115 cs5535_gpio_set(OLPC_GPIO_DCON_IRQ, GPIO_NEGATIVE_EDGE_STS);
116 cs5535_gpio_set(OLPC_GPIO_DCON_BLANK, GPIO_NEGATIVE_EDGE_STS);
99 117
100 /* FIXME: Clear the posiitive status as well, just to be sure */ 118 /* FIXME: Clear the posiitive status as well, just to be sure */
101 outl((1<<7) | (1<<12), gpio_base+0x48); 119 cs5535_gpio_set(OLPC_GPIO_DCON_IRQ, GPIO_POSITIVE_EDGE_STS);
120 cs5535_gpio_set(OLPC_GPIO_DCON_BLANK, GPIO_POSITIVE_EDGE_STS);
102 121
103 /* Enable events for GPIO7 (DCONIRQ) and GPIO12 (DCONBLANK) */ 122 /* Enable events for GPIO7 (DCONIRQ) and GPIO12 (DCONBLANK) */
104 outl((1<<(7))|(1<<12), gpio_base + GPIOx_EVNT_EN); 123 cs5535_gpio_set(OLPC_GPIO_DCON_IRQ, GPIO_EVENTS_ENABLE);
105 124 cs5535_gpio_set(OLPC_GPIO_DCON_BLANK, GPIO_EVENTS_ENABLE);
106 /* Determine the current state by reading the GPIO bit */
107 /* Earlier stages of the boot process have established the state */
108 dcon_source = inl(gpio_base + GPIOx_OUT_VAL) & (1<<11)
109 ? DCON_SOURCE_CPU
110 : DCON_SOURCE_DCON;
111 dcon_pending = dcon_source;
112 125
113 return 0; 126 return 0;
127
128err_req_irq:
129 gpio_free(OLPC_GPIO_DCON_BLANK);
130err_gp_blank:
131 gpio_free(OLPC_GPIO_DCON_LOAD);
132err_gp_load:
133 gpio_free(OLPC_GPIO_DCON_IRQ);
134err_gp_irq:
135 gpio_free(OLPC_GPIO_DCON_STAT1);
136err_gp_stat1:
137 gpio_free(OLPC_GPIO_DCON_STAT0);
138 return -EIO;
114} 139}
115 140
116static void dcon_wiggle_xo_1(void) 141static void dcon_wiggle_xo_1(void)
@@ -128,37 +153,44 @@ static void dcon_wiggle_xo_1(void)
128 * simultaneously set AUX1 IN/OUT to GPIO14; ditto for SMB_DATA and 153 * simultaneously set AUX1 IN/OUT to GPIO14; ditto for SMB_DATA and
129 * GPIO15. 154 * GPIO15.
130 */ 155 */
131 geode_gpio_set(OLPC_GPIO_SMB_CLK|OLPC_GPIO_SMB_DATA, GPIO_OUTPUT_VAL); 156 cs5535_gpio_set(OLPC_GPIO_SMB_CLK, GPIO_OUTPUT_VAL);
132 geode_gpio_set(OLPC_GPIO_SMB_CLK|OLPC_GPIO_SMB_DATA, GPIO_OUTPUT_ENABLE); 157 cs5535_gpio_set(OLPC_GPIO_SMB_DATA, GPIO_OUTPUT_VAL);
133 geode_gpio_clear(OLPC_GPIO_SMB_CLK|OLPC_GPIO_SMB_DATA, GPIO_OUTPUT_AUX1); 158 cs5535_gpio_set(OLPC_GPIO_SMB_CLK, GPIO_OUTPUT_ENABLE);
134 geode_gpio_clear(OLPC_GPIO_SMB_CLK|OLPC_GPIO_SMB_DATA, GPIO_OUTPUT_AUX2); 159 cs5535_gpio_set(OLPC_GPIO_SMB_DATA, GPIO_OUTPUT_ENABLE);
135 geode_gpio_clear(OLPC_GPIO_SMB_CLK|OLPC_GPIO_SMB_DATA, GPIO_INPUT_AUX1); 160 cs5535_gpio_clear(OLPC_GPIO_SMB_CLK, GPIO_OUTPUT_AUX1);
161 cs5535_gpio_clear(OLPC_GPIO_SMB_DATA, GPIO_OUTPUT_AUX1);
162 cs5535_gpio_clear(OLPC_GPIO_SMB_CLK, GPIO_OUTPUT_AUX2);
163 cs5535_gpio_clear(OLPC_GPIO_SMB_DATA, GPIO_OUTPUT_AUX2);
164 cs5535_gpio_clear(OLPC_GPIO_SMB_CLK, GPIO_INPUT_AUX1);
165 cs5535_gpio_clear(OLPC_GPIO_SMB_DATA, GPIO_INPUT_AUX1);
136 166
137 for (x = 0; x < 16; x++) { 167 for (x = 0; x < 16; x++) {
138 udelay(5); 168 udelay(5);
139 geode_gpio_clear(OLPC_GPIO_SMB_CLK, GPIO_OUTPUT_VAL); 169 cs5535_gpio_clear(OLPC_GPIO_SMB_CLK, GPIO_OUTPUT_VAL);
140 udelay(5); 170 udelay(5);
141 geode_gpio_set(OLPC_GPIO_SMB_CLK, GPIO_OUTPUT_VAL); 171 cs5535_gpio_set(OLPC_GPIO_SMB_CLK, GPIO_OUTPUT_VAL);
142 } 172 }
143 udelay(5); 173 udelay(5);
144 geode_gpio_set(OLPC_GPIO_SMB_CLK|OLPC_GPIO_SMB_DATA, GPIO_OUTPUT_AUX1); 174 cs5535_gpio_set(OLPC_GPIO_SMB_CLK, GPIO_OUTPUT_AUX1);
145 geode_gpio_set(OLPC_GPIO_SMB_CLK|OLPC_GPIO_SMB_DATA, GPIO_INPUT_AUX1); 175 cs5535_gpio_set(OLPC_GPIO_SMB_DATA, GPIO_OUTPUT_AUX1);
176 cs5535_gpio_set(OLPC_GPIO_SMB_CLK, GPIO_INPUT_AUX1);
177 cs5535_gpio_set(OLPC_GPIO_SMB_DATA, GPIO_INPUT_AUX1);
146} 178}
147 179
148static void dcon_set_dconload_1(int val) 180static void dcon_set_dconload_1(int val)
149{ 181{
150 if (val) 182 gpio_set_value(OLPC_GPIO_DCON_LOAD, val);
151 outl(1<<11, gpio_base + GPIOx_OUT_VAL);
152 else
153 outl(1<<(11 + 16), gpio_base + GPIOx_OUT_VAL);
154} 183}
155 184
156static int dcon_read_status_xo_1(void) 185static u8 dcon_read_status_xo_1(void)
157{ 186{
158 int status = inl(gpio_base + GPIOx_READ_BACK) >> 5; 187 u8 status;
159 188
189 status = gpio_get_value(OLPC_GPIO_DCON_STAT0);
190 status |= gpio_get_value(OLPC_GPIO_DCON_STAT1) << 1;
191
160 /* Clear the negative edge status for GPIO7 */ 192 /* Clear the negative edge status for GPIO7 */
161 outl(1 << 7, gpio_base + GPIOx_NEGEDGE_STS); 193 cs5535_gpio_set(OLPC_GPIO_DCON_IRQ, GPIO_NEGATIVE_EDGE_STS);
162 194
163 return status; 195 return status;
164} 196}
diff --git a/drivers/staging/olpc_dcon/olpc_dcon_xo_1_5.c b/drivers/staging/olpc_dcon/olpc_dcon_xo_1_5.c
index cca6a235ef96..4f56098bb366 100644
--- a/drivers/staging/olpc_dcon/olpc_dcon_xo_1_5.c
+++ b/drivers/staging/olpc_dcon/olpc_dcon_xo_1_5.c
@@ -195,9 +195,9 @@ static void dcon_set_dconload_xo_1_5(int val)
195 } 195 }
196} 196}
197 197
198static int dcon_read_status_xo_1_5(void) 198static u8 dcon_read_status_xo_1_5(void)
199{ 199{
200 int status; 200 u8 status;
201 201
202 if (!dcon_was_irq()) 202 if (!dcon_was_irq())
203 return -1; 203 return -1;
diff --git a/drivers/staging/pohmelfs/net.c b/drivers/staging/pohmelfs/net.c
index 9279897ff161..b2e918622088 100644
--- a/drivers/staging/pohmelfs/net.c
+++ b/drivers/staging/pohmelfs/net.c
@@ -413,7 +413,7 @@ static int pohmelfs_readdir_response(struct netfs_state *st)
413 if (dentry) { 413 if (dentry) {
414 alias = d_materialise_unique(dentry, &npi->vfs_inode); 414 alias = d_materialise_unique(dentry, &npi->vfs_inode);
415 if (alias) 415 if (alias)
416 dput(dentry); 416 dput(alias);
417 } 417 }
418 418
419 dput(dentry); 419 dput(dentry);
diff --git a/drivers/staging/samsung-laptop/samsung-laptop.c b/drivers/staging/samsung-laptop/samsung-laptop.c
index ac2bf11e1119..701e8d52a9fa 100644
--- a/drivers/staging/samsung-laptop/samsung-laptop.c
+++ b/drivers/staging/samsung-laptop/samsung-laptop.c
@@ -269,7 +269,7 @@ static int update_status(struct backlight_device *bd)
269 return 0; 269 return 0;
270} 270}
271 271
272static struct backlight_ops backlight_ops = { 272static const struct backlight_ops backlight_ops = {
273 .get_brightness = get_brightness, 273 .get_brightness = get_brightness,
274 .update_status = update_status, 274 .update_status = update_status,
275}; 275};
diff --git a/drivers/staging/smbfs/dir.c b/drivers/staging/smbfs/dir.c
index dd612f50749f..87a3a9bd5842 100644
--- a/drivers/staging/smbfs/dir.c
+++ b/drivers/staging/smbfs/dir.c
@@ -403,12 +403,6 @@ smb_delete_dentry(const struct dentry *dentry)
403void 403void
404smb_new_dentry(struct dentry *dentry) 404smb_new_dentry(struct dentry *dentry)
405{ 405{
406 struct smb_sb_info *server = server_from_dentry(dentry);
407
408 if (server->mnt->flags & SMB_MOUNT_CASE)
409 d_set_d_op(dentry, &smbfs_dentry_operations_case);
410 else
411 d_set_d_op(dentry, &smbfs_dentry_operations);
412 dentry->d_time = jiffies; 406 dentry->d_time = jiffies;
413} 407}
414 408
@@ -440,7 +434,6 @@ smb_lookup(struct inode *dir, struct dentry *dentry, struct nameidata *nd)
440 struct smb_fattr finfo; 434 struct smb_fattr finfo;
441 struct inode *inode; 435 struct inode *inode;
442 int error; 436 int error;
443 struct smb_sb_info *server;
444 437
445 error = -ENAMETOOLONG; 438 error = -ENAMETOOLONG;
446 if (dentry->d_name.len > SMB_MAXNAMELEN) 439 if (dentry->d_name.len > SMB_MAXNAMELEN)
@@ -468,12 +461,6 @@ smb_lookup(struct inode *dir, struct dentry *dentry, struct nameidata *nd)
468 inode = smb_iget(dir->i_sb, &finfo); 461 inode = smb_iget(dir->i_sb, &finfo);
469 if (inode) { 462 if (inode) {
470 add_entry: 463 add_entry:
471 server = server_from_dentry(dentry);
472 if (server->mnt->flags & SMB_MOUNT_CASE)
473 d_set_d_op(dentry, &smbfs_dentry_operations_case);
474 else
475 d_set_d_op(dentry, &smbfs_dentry_operations);
476
477 d_add(dentry, inode); 464 d_add(dentry, inode);
478 smb_renew_times(dentry); 465 smb_renew_times(dentry);
479 error = 0; 466 error = 0;
diff --git a/drivers/staging/smbfs/inode.c b/drivers/staging/smbfs/inode.c
index 244319dc9702..0778589d9e9e 100644
--- a/drivers/staging/smbfs/inode.c
+++ b/drivers/staging/smbfs/inode.c
@@ -614,6 +614,10 @@ static int smb_fill_super(struct super_block *sb, void *raw_data, int silent)
614 printk(KERN_ERR "smbfs: failed to start smbiod\n"); 614 printk(KERN_ERR "smbfs: failed to start smbiod\n");
615 goto out_no_smbiod; 615 goto out_no_smbiod;
616 } 616 }
617 if (server->mnt->flags & SMB_MOUNT_CASE)
618 sb->s_d_op = &smbfs_dentry_operations_case;
619 else
620 sb->s_d_op = &smbfs_dentry_operations;
617 621
618 /* 622 /*
619 * Keep the super block locked while we get the root inode. 623 * Keep the super block locked while we get the root inode.
diff --git a/drivers/staging/smbfs/proto.h b/drivers/staging/smbfs/proto.h
index 05939a6f43e6..3883cb16a3f6 100644
--- a/drivers/staging/smbfs/proto.h
+++ b/drivers/staging/smbfs/proto.h
@@ -38,6 +38,8 @@ extern void smb_install_null_ops(struct smb_ops *ops);
38extern const struct file_operations smb_dir_operations; 38extern const struct file_operations smb_dir_operations;
39extern const struct inode_operations smb_dir_inode_operations; 39extern const struct inode_operations smb_dir_inode_operations;
40extern const struct inode_operations smb_dir_inode_operations_unix; 40extern const struct inode_operations smb_dir_inode_operations_unix;
41extern const struct dentry_operations smbfs_dentry_operations_case;
42extern const struct dentry_operations smbfs_dentry_operations;
41extern void smb_new_dentry(struct dentry *dentry); 43extern void smb_new_dentry(struct dentry *dentry);
42extern void smb_renew_times(struct dentry *dentry); 44extern void smb_renew_times(struct dentry *dentry);
43/* cache.c */ 45/* cache.c */
diff --git a/drivers/telephony/ixj.c b/drivers/telephony/ixj.c
index 0d236f4bb8c2..b00101972f20 100644
--- a/drivers/telephony/ixj.c
+++ b/drivers/telephony/ixj.c
@@ -284,12 +284,11 @@ static int samplerate = 100;
284 284
285module_param(ixjdebug, int, 0); 285module_param(ixjdebug, int, 0);
286 286
287static struct pci_device_id ixj_pci_tbl[] __devinitdata = { 287static DEFINE_PCI_DEVICE_TABLE(ixj_pci_tbl) = {
288 { PCI_VENDOR_ID_QUICKNET, PCI_DEVICE_ID_QUICKNET_XJ, 288 { PCI_VENDOR_ID_QUICKNET, PCI_DEVICE_ID_QUICKNET_XJ,
289 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, 289 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
290 { } 290 { }
291}; 291};
292
293MODULE_DEVICE_TABLE(pci, ixj_pci_tbl); 292MODULE_DEVICE_TABLE(pci, ixj_pci_tbl);
294 293
295/************************************************************************ 294/************************************************************************
@@ -6581,7 +6580,8 @@ static long do_ixj_ioctl(struct file *file_p, unsigned int cmd, unsigned long ar
6581 case IXJCTL_SET_FILTER: 6580 case IXJCTL_SET_FILTER:
6582 if (copy_from_user(&jf, argp, sizeof(jf))) 6581 if (copy_from_user(&jf, argp, sizeof(jf)))
6583 retval = -EFAULT; 6582 retval = -EFAULT;
6584 retval = ixj_init_filter(j, &jf); 6583 else
6584 retval = ixj_init_filter(j, &jf);
6585 break; 6585 break;
6586 case IXJCTL_SET_FILTER_RAW: 6586 case IXJCTL_SET_FILTER_RAW:
6587 if (copy_from_user(&jfr, argp, sizeof(jfr))) 6587 if (copy_from_user(&jfr, argp, sizeof(jfr)))
diff --git a/drivers/usb/gadget/imx_udc.c b/drivers/usb/gadget/imx_udc.c
index 1210534822d6..5408186afc35 100644
--- a/drivers/usb/gadget/imx_udc.c
+++ b/drivers/usb/gadget/imx_udc.c
@@ -1320,7 +1320,7 @@ static struct imx_udc_struct controller = {
1320}; 1320};
1321 1321
1322/******************************************************************************* 1322/*******************************************************************************
1323 * USB gadged driver functions 1323 * USB gadget driver functions
1324 ******************************************************************************* 1324 *******************************************************************************
1325 */ 1325 */
1326int usb_gadget_probe_driver(struct usb_gadget_driver *driver, 1326int usb_gadget_probe_driver(struct usb_gadget_driver *driver,
diff --git a/drivers/usb/gadget/langwell_udc.c b/drivers/usb/gadget/langwell_udc.c
index 777972454e3e..1eca8b47ce3c 100644
--- a/drivers/usb/gadget/langwell_udc.c
+++ b/drivers/usb/gadget/langwell_udc.c
@@ -3086,7 +3086,7 @@ static void langwell_udc_remove(struct pci_dev *pdev)
3086 3086
3087 kfree(dev->ep); 3087 kfree(dev->ep);
3088 3088
3089 /* diable IRQ handler */ 3089 /* disable IRQ handler */
3090 if (dev->got_irq) 3090 if (dev->got_irq)
3091 free_irq(pdev->irq, dev); 3091 free_irq(pdev->irq, dev);
3092 3092
@@ -3406,7 +3406,7 @@ static int langwell_udc_suspend(struct pci_dev *pdev, pm_message_t state)
3406 /* disable interrupt and set controller to stop state */ 3406 /* disable interrupt and set controller to stop state */
3407 langwell_udc_stop(dev); 3407 langwell_udc_stop(dev);
3408 3408
3409 /* diable IRQ handler */ 3409 /* disable IRQ handler */
3410 if (dev->got_irq) 3410 if (dev->got_irq)
3411 free_irq(pdev->irq, dev); 3411 free_irq(pdev->irq, dev);
3412 dev->got_irq = 0; 3412 dev->got_irq = 0;
diff --git a/drivers/usb/host/fhci-hcd.c b/drivers/usb/host/fhci-hcd.c
index 20092a27a1e8..12fd184226f2 100644
--- a/drivers/usb/host/fhci-hcd.c
+++ b/drivers/usb/host/fhci-hcd.c
@@ -98,13 +98,13 @@ void fhci_usb_enable_interrupt(struct fhci_usb *usb)
98 usb->intr_nesting_cnt--; 98 usb->intr_nesting_cnt--;
99} 99}
100 100
101/* diable the usb interrupt */ 101/* disable the usb interrupt */
102void fhci_usb_disable_interrupt(struct fhci_usb *usb) 102void fhci_usb_disable_interrupt(struct fhci_usb *usb)
103{ 103{
104 struct fhci_hcd *fhci = usb->fhci; 104 struct fhci_hcd *fhci = usb->fhci;
105 105
106 if (usb->intr_nesting_cnt == 0) { 106 if (usb->intr_nesting_cnt == 0) {
107 /* diable the timer interrupt */ 107 /* disable the timer interrupt */
108 disable_irq_nosync(fhci->timer->irq); 108 disable_irq_nosync(fhci->timer->irq);
109 109
110 /* disable the usb interrupt */ 110 /* disable the usb interrupt */
diff --git a/drivers/usb/host/fhci-tds.c b/drivers/usb/host/fhci-tds.c
index 7be548ca2183..38fe058fbe61 100644
--- a/drivers/usb/host/fhci-tds.c
+++ b/drivers/usb/host/fhci-tds.c
@@ -271,8 +271,8 @@ void fhci_init_ep_registers(struct fhci_usb *usb, struct endpoint *ep,
271 271
272/* 272/*
273 * Collect the submitted frames and inform the application about them 273 * Collect the submitted frames and inform the application about them
274 * It is also prepearing the TDs for new frames. If the Tx interrupts 274 * It is also preparing the TDs for new frames. If the Tx interrupts
275 * are diabled, the application should call that routine to get 275 * are disabled, the application should call that routine to get
276 * confirmation about the submitted frames. Otherwise, the routine is 276 * confirmation about the submitted frames. Otherwise, the routine is
277 * called frome the interrupt service routine during the Tx interrupt. 277 * called frome the interrupt service routine during the Tx interrupt.
278 * In that case the application is informed by calling the application 278 * In that case the application is informed by calling the application
diff --git a/drivers/usb/host/imx21-hcd.c b/drivers/usb/host/imx21-hcd.c
index e49b75a78000..f90d003f2302 100644
--- a/drivers/usb/host/imx21-hcd.c
+++ b/drivers/usb/host/imx21-hcd.c
@@ -1658,7 +1658,7 @@ static int imx21_hc_reset(struct usb_hcd *hcd)
1658 1658
1659 spin_lock_irqsave(&imx21->lock, flags); 1659 spin_lock_irqsave(&imx21->lock, flags);
1660 1660
1661 /* Reset the Host controler modules */ 1661 /* Reset the Host controller modules */
1662 writel(USBOTG_RST_RSTCTRL | USBOTG_RST_RSTRH | 1662 writel(USBOTG_RST_RSTCTRL | USBOTG_RST_RSTRH |
1663 USBOTG_RST_RSTHSIE | USBOTG_RST_RSTHC, 1663 USBOTG_RST_RSTHSIE | USBOTG_RST_RSTHC,
1664 imx21->regs + USBOTG_RST_CTRL); 1664 imx21->regs + USBOTG_RST_CTRL);
diff --git a/drivers/usb/host/oxu210hp-hcd.c b/drivers/usb/host/oxu210hp-hcd.c
index 32149be4ad8e..e0cb12b573f9 100644
--- a/drivers/usb/host/oxu210hp-hcd.c
+++ b/drivers/usb/host/oxu210hp-hcd.c
@@ -3094,7 +3094,7 @@ static int oxu_hub_status_data(struct usb_hcd *hcd, char *buf)
3094 3094
3095 /* Some boards (mostly VIA?) report bogus overcurrent indications, 3095 /* Some boards (mostly VIA?) report bogus overcurrent indications,
3096 * causing massive log spam unless we completely ignore them. It 3096 * causing massive log spam unless we completely ignore them. It
3097 * may be relevant that VIA VT8235 controlers, where PORT_POWER is 3097 * may be relevant that VIA VT8235 controllers, where PORT_POWER is
3098 * always set, seem to clear PORT_OCC and PORT_CSC when writing to 3098 * always set, seem to clear PORT_OCC and PORT_CSC when writing to
3099 * PORT_POWER; that's surprising, but maybe within-spec. 3099 * PORT_POWER; that's surprising, but maybe within-spec.
3100 */ 3100 */
diff --git a/drivers/usb/misc/adutux.c b/drivers/usb/misc/adutux.c
index 44f8b9225054..a6afd15f6a46 100644
--- a/drivers/usb/misc/adutux.c
+++ b/drivers/usb/misc/adutux.c
@@ -717,7 +717,7 @@ static int adu_probe(struct usb_interface *interface,
717 goto exit; 717 goto exit;
718 } 718 }
719 719
720 /* allocate memory for our device state and intialize it */ 720 /* allocate memory for our device state and initialize it */
721 dev = kzalloc(sizeof(struct adu_device), GFP_KERNEL); 721 dev = kzalloc(sizeof(struct adu_device), GFP_KERNEL);
722 if (dev == NULL) { 722 if (dev == NULL) {
723 dev_err(&interface->dev, "Out of memory\n"); 723 dev_err(&interface->dev, "Out of memory\n");
diff --git a/drivers/usb/misc/iowarrior.c b/drivers/usb/misc/iowarrior.c
index c9078e4e1f4d..e573e4704015 100644
--- a/drivers/usb/misc/iowarrior.c
+++ b/drivers/usb/misc/iowarrior.c
@@ -769,7 +769,7 @@ static int iowarrior_probe(struct usb_interface *interface,
769 int i; 769 int i;
770 int retval = -ENOMEM; 770 int retval = -ENOMEM;
771 771
772 /* allocate memory for our device state and intialize it */ 772 /* allocate memory for our device state and initialize it */
773 dev = kzalloc(sizeof(struct iowarrior), GFP_KERNEL); 773 dev = kzalloc(sizeof(struct iowarrior), GFP_KERNEL);
774 if (dev == NULL) { 774 if (dev == NULL) {
775 dev_err(&interface->dev, "Out of memory\n"); 775 dev_err(&interface->dev, "Out of memory\n");
diff --git a/drivers/usb/misc/ldusb.c b/drivers/usb/misc/ldusb.c
index edffef642337..eefb8275bb7e 100644
--- a/drivers/usb/misc/ldusb.c
+++ b/drivers/usb/misc/ldusb.c
@@ -642,7 +642,7 @@ static int ld_usb_probe(struct usb_interface *intf, const struct usb_device_id *
642 int i; 642 int i;
643 int retval = -ENOMEM; 643 int retval = -ENOMEM;
644 644
645 /* allocate memory for our device state and intialize it */ 645 /* allocate memory for our device state and initialize it */
646 646
647 dev = kzalloc(sizeof(*dev), GFP_KERNEL); 647 dev = kzalloc(sizeof(*dev), GFP_KERNEL);
648 if (dev == NULL) { 648 if (dev == NULL) {
diff --git a/drivers/usb/musb/musb_gadget.c b/drivers/usb/musb/musb_gadget.c
index 9b162dfaa4fb..ed58c6c8f15c 100644
--- a/drivers/usb/musb/musb_gadget.c
+++ b/drivers/usb/musb/musb_gadget.c
@@ -1684,7 +1684,7 @@ static inline void __init musb_g_init_endpoints(struct musb *musb)
1684 struct musb_hw_ep *hw_ep; 1684 struct musb_hw_ep *hw_ep;
1685 unsigned count = 0; 1685 unsigned count = 0;
1686 1686
1687 /* intialize endpoint list just once */ 1687 /* initialize endpoint list just once */
1688 INIT_LIST_HEAD(&(musb->g.ep_list)); 1688 INIT_LIST_HEAD(&(musb->g.ep_list));
1689 1689
1690 for (epnum = 0, hw_ep = musb->endpoints; 1690 for (epnum = 0, hw_ep = musb->endpoints;
@@ -1765,7 +1765,7 @@ void musb_gadget_cleanup(struct musb *musb)
1765 * 1765 *
1766 * -EINVAL something went wrong (not driver) 1766 * -EINVAL something went wrong (not driver)
1767 * -EBUSY another gadget is already using the controller 1767 * -EBUSY another gadget is already using the controller
1768 * -ENOMEM no memeory to perform the operation 1768 * -ENOMEM no memory to perform the operation
1769 * 1769 *
1770 * @param driver the gadget driver 1770 * @param driver the gadget driver
1771 * @param bind the driver's bind function 1771 * @param bind the driver's bind function
diff --git a/drivers/usb/wusbcore/wa-rpipe.c b/drivers/usb/wusbcore/wa-rpipe.c
index c7b1d8108de9..8cb9d80207fa 100644
--- a/drivers/usb/wusbcore/wa-rpipe.c
+++ b/drivers/usb/wusbcore/wa-rpipe.c
@@ -49,7 +49,7 @@
49 * 49 *
50 * USB Stack port number 4 (1 based) 50 * USB Stack port number 4 (1 based)
51 * WUSB code port index 3 (0 based) 51 * WUSB code port index 3 (0 based)
52 * USB Addresss 5 (2 based -- 0 is for default, 1 for root hub) 52 * USB Address 5 (2 based -- 0 is for default, 1 for root hub)
53 * 53 *
54 * Now, because we don't use the concept as default address exactly 54 * Now, because we don't use the concept as default address exactly
55 * like the (wired) USB code does, we need to kind of skip it. So we 55 * like the (wired) USB code does, we need to kind of skip it. So we
diff --git a/drivers/video/Kconfig b/drivers/video/Kconfig
index 55dc6fb6e909..d916ac04abab 100644
--- a/drivers/video/Kconfig
+++ b/drivers/video/Kconfig
@@ -11,6 +11,13 @@ config HAVE_FB_ATMEL
11config HAVE_FB_IMX 11config HAVE_FB_IMX
12 bool 12 bool
13 13
14config SH_MIPI_DSI
15 tristate
16 depends on (SUPERH || ARCH_SHMOBILE) && HAVE_CLK
17
18config SH_LCD_MIPI_DSI
19 bool
20
14source "drivers/char/agp/Kconfig" 21source "drivers/char/agp/Kconfig"
15 22
16source "drivers/gpu/vga/Kconfig" 23source "drivers/gpu/vga/Kconfig"
@@ -414,7 +421,7 @@ config FB_SA1100
414 Y here. 421 Y here.
415 422
416config FB_IMX 423config FB_IMX
417 tristate "Motorola i.MX LCD support" 424 tristate "Freescale i.MX LCD support"
418 depends on FB && (HAVE_FB_IMX || ARCH_MX1 || ARCH_MX2) 425 depends on FB && (HAVE_FB_IMX || ARCH_MX1 || ARCH_MX2)
419 select FB_CFB_FILLRECT 426 select FB_CFB_FILLRECT
420 select FB_CFB_COPYAREA 427 select FB_CFB_COPYAREA
@@ -1273,7 +1280,7 @@ config FB_MATROX
1273 module will be called matroxfb. 1280 module will be called matroxfb.
1274 1281
1275 You can pass several parameters to the driver at boot time or at 1282 You can pass several parameters to the driver at boot time or at
1276 module load time. The parameters look like "video=matrox:XXX", and 1283 module load time. The parameters look like "video=matroxfb:XXX", and
1277 are described in <file:Documentation/fb/matroxfb.txt>. 1284 are described in <file:Documentation/fb/matroxfb.txt>.
1278 1285
1279config FB_MATROX_MILLENIUM 1286config FB_MATROX_MILLENIUM
@@ -1990,13 +1997,6 @@ config FB_W100
1990 1997
1991 If unsure, say N. 1998 If unsure, say N.
1992 1999
1993config SH_MIPI_DSI
1994 tristate
1995 depends on (SUPERH || ARCH_SHMOBILE) && HAVE_CLK
1996
1997config SH_LCD_MIPI_DSI
1998 bool
1999
2000config FB_SH_MOBILE_LCDC 2000config FB_SH_MOBILE_LCDC
2001 tristate "SuperH Mobile LCDC framebuffer support" 2001 tristate "SuperH Mobile LCDC framebuffer support"
2002 depends on FB && (SUPERH || ARCH_SHMOBILE) && HAVE_CLK 2002 depends on FB && (SUPERH || ARCH_SHMOBILE) && HAVE_CLK
diff --git a/drivers/video/atmel_lcdfb.c b/drivers/video/atmel_lcdfb.c
index 8dce25126330..bac163450216 100644
--- a/drivers/video/atmel_lcdfb.c
+++ b/drivers/video/atmel_lcdfb.c
@@ -111,7 +111,7 @@ static int atmel_bl_get_brightness(struct backlight_device *bl)
111 return lcdc_readl(sinfo, ATMEL_LCDC_CONTRAST_VAL); 111 return lcdc_readl(sinfo, ATMEL_LCDC_CONTRAST_VAL);
112} 112}
113 113
114static struct backlight_ops atmel_lcdc_bl_ops = { 114static const struct backlight_ops atmel_lcdc_bl_ops = {
115 .update_status = atmel_bl_update_status, 115 .update_status = atmel_bl_update_status,
116 .get_brightness = atmel_bl_get_brightness, 116 .get_brightness = atmel_bl_get_brightness,
117}; 117};
diff --git a/drivers/video/aty/aty128fb.c b/drivers/video/aty/aty128fb.c
index 34a0851bcbfa..dd9de2e80580 100644
--- a/drivers/video/aty/aty128fb.c
+++ b/drivers/video/aty/aty128fb.c
@@ -1786,7 +1786,7 @@ static int aty128_bl_get_brightness(struct backlight_device *bd)
1786 return bd->props.brightness; 1786 return bd->props.brightness;
1787} 1787}
1788 1788
1789static struct backlight_ops aty128_bl_data = { 1789static const struct backlight_ops aty128_bl_data = {
1790 .get_brightness = aty128_bl_get_brightness, 1790 .get_brightness = aty128_bl_get_brightness,
1791 .update_status = aty128_bl_update_status, 1791 .update_status = aty128_bl_update_status,
1792}; 1792};
diff --git a/drivers/video/aty/atyfb_base.c b/drivers/video/aty/atyfb_base.c
index 5a3ce3ad1ec8..767ab4fb1a05 100644
--- a/drivers/video/aty/atyfb_base.c
+++ b/drivers/video/aty/atyfb_base.c
@@ -2221,7 +2221,7 @@ static int aty_bl_get_brightness(struct backlight_device *bd)
2221 return bd->props.brightness; 2221 return bd->props.brightness;
2222} 2222}
2223 2223
2224static struct backlight_ops aty_bl_data = { 2224static const struct backlight_ops aty_bl_data = {
2225 .get_brightness = aty_bl_get_brightness, 2225 .get_brightness = aty_bl_get_brightness,
2226 .update_status = aty_bl_update_status, 2226 .update_status = aty_bl_update_status,
2227}; 2227};
diff --git a/drivers/video/aty/radeon_backlight.c b/drivers/video/aty/radeon_backlight.c
index 256966e9667d..9b811ddbce83 100644
--- a/drivers/video/aty/radeon_backlight.c
+++ b/drivers/video/aty/radeon_backlight.c
@@ -128,7 +128,7 @@ static int radeon_bl_get_brightness(struct backlight_device *bd)
128 return bd->props.brightness; 128 return bd->props.brightness;
129} 129}
130 130
131static struct backlight_ops radeon_bl_data = { 131static const struct backlight_ops radeon_bl_data = {
132 .get_brightness = radeon_bl_get_brightness, 132 .get_brightness = radeon_bl_get_brightness,
133 .update_status = radeon_bl_update_status, 133 .update_status = radeon_bl_update_status,
134}; 134};
diff --git a/drivers/video/backlight/88pm860x_bl.c b/drivers/video/backlight/88pm860x_bl.c
index 38ffc3fbcbe4..c789c46e38af 100644
--- a/drivers/video/backlight/88pm860x_bl.c
+++ b/drivers/video/backlight/88pm860x_bl.c
@@ -155,7 +155,7 @@ out:
155 return -EINVAL; 155 return -EINVAL;
156} 156}
157 157
158static struct backlight_ops pm860x_backlight_ops = { 158static const struct backlight_ops pm860x_backlight_ops = {
159 .options = BL_CORE_SUSPENDRESUME, 159 .options = BL_CORE_SUSPENDRESUME,
160 .update_status = pm860x_backlight_update_status, 160 .update_status = pm860x_backlight_update_status,
161 .get_brightness = pm860x_backlight_get_brightness, 161 .get_brightness = pm860x_backlight_get_brightness,
diff --git a/drivers/video/backlight/l4f00242t03.c b/drivers/video/backlight/l4f00242t03.c
index c67801e57aaf..98ad3e5f7c85 100644
--- a/drivers/video/backlight/l4f00242t03.c
+++ b/drivers/video/backlight/l4f00242t03.c
@@ -25,7 +25,7 @@
25struct l4f00242t03_priv { 25struct l4f00242t03_priv {
26 struct spi_device *spi; 26 struct spi_device *spi;
27 struct lcd_device *ld; 27 struct lcd_device *ld;
28 int lcd_on:1; 28 int lcd_state;
29 struct regulator *io_reg; 29 struct regulator *io_reg;
30 struct regulator *core_reg; 30 struct regulator *core_reg;
31}; 31};
@@ -62,11 +62,36 @@ static void l4f00242t03_lcd_init(struct spi_device *spi)
62 regulator_enable(priv->core_reg); 62 regulator_enable(priv->core_reg);
63 } 63 }
64 64
65 l4f00242t03_reset(pdata->reset_gpio);
66
65 gpio_set_value(pdata->data_enable_gpio, 1); 67 gpio_set_value(pdata->data_enable_gpio, 1);
66 msleep(60); 68 msleep(60);
67 spi_write(spi, (const u8 *)cmd, ARRAY_SIZE(cmd) * sizeof(u16)); 69 spi_write(spi, (const u8 *)cmd, ARRAY_SIZE(cmd) * sizeof(u16));
68} 70}
69 71
72static void l4f00242t03_lcd_powerdown(struct spi_device *spi)
73{
74 struct l4f00242t03_pdata *pdata = spi->dev.platform_data;
75 struct l4f00242t03_priv *priv = dev_get_drvdata(&spi->dev);
76
77 dev_dbg(&spi->dev, "Powering down LCD\n");
78
79 gpio_set_value(pdata->data_enable_gpio, 0);
80
81 if (priv->io_reg)
82 regulator_disable(priv->io_reg);
83
84 if (priv->core_reg)
85 regulator_disable(priv->core_reg);
86}
87
88static int l4f00242t03_lcd_power_get(struct lcd_device *ld)
89{
90 struct l4f00242t03_priv *priv = lcd_get_data(ld);
91
92 return priv->lcd_state;
93}
94
70static int l4f00242t03_lcd_power_set(struct lcd_device *ld, int power) 95static int l4f00242t03_lcd_power_set(struct lcd_device *ld, int power)
71{ 96{
72 struct l4f00242t03_priv *priv = lcd_get_data(ld); 97 struct l4f00242t03_priv *priv = lcd_get_data(ld);
@@ -79,35 +104,54 @@ static int l4f00242t03_lcd_power_set(struct lcd_device *ld, int power)
79 const u16 disoff = 0x28; 104 const u16 disoff = 0x28;
80 105
81 if (power <= FB_BLANK_NORMAL) { 106 if (power <= FB_BLANK_NORMAL) {
82 if (priv->lcd_on) 107 if (priv->lcd_state <= FB_BLANK_NORMAL) {
83 return 0; 108 /* Do nothing, the LCD is running */
84 109 } else if (priv->lcd_state < FB_BLANK_POWERDOWN) {
85 dev_dbg(&spi->dev, "turning on LCD\n"); 110 dev_dbg(&spi->dev, "Resuming LCD\n");
86 111
87 spi_write(spi, (const u8 *)&slpout, sizeof(u16)); 112 spi_write(spi, (const u8 *)&slpout, sizeof(u16));
88 msleep(60); 113 msleep(60);
89 spi_write(spi, (const u8 *)&dison, sizeof(u16)); 114 spi_write(spi, (const u8 *)&dison, sizeof(u16));
90 115 } else {
91 priv->lcd_on = 1; 116 /* priv->lcd_state == FB_BLANK_POWERDOWN */
117 l4f00242t03_lcd_init(spi);
118 priv->lcd_state = FB_BLANK_VSYNC_SUSPEND;
119 l4f00242t03_lcd_power_set(priv->ld, power);
120 }
121 } else if (power < FB_BLANK_POWERDOWN) {
122 if (priv->lcd_state <= FB_BLANK_NORMAL) {
123 /* Send the display in standby */
124 dev_dbg(&spi->dev, "Standby the LCD\n");
125
126 spi_write(spi, (const u8 *)&disoff, sizeof(u16));
127 msleep(60);
128 spi_write(spi, (const u8 *)&slpin, sizeof(u16));
129 } else if (priv->lcd_state < FB_BLANK_POWERDOWN) {
130 /* Do nothing, the LCD is already in standby */
131 } else {
132 /* priv->lcd_state == FB_BLANK_POWERDOWN */
133 l4f00242t03_lcd_init(spi);
134 priv->lcd_state = FB_BLANK_UNBLANK;
135 l4f00242t03_lcd_power_set(ld, power);
136 }
92 } else { 137 } else {
93 if (!priv->lcd_on) 138 /* power == FB_BLANK_POWERDOWN */
94 return 0; 139 if (priv->lcd_state != FB_BLANK_POWERDOWN) {
95 140 /* Clear the screen before shutting down */
96 dev_dbg(&spi->dev, "turning off LCD\n"); 141 spi_write(spi, (const u8 *)&disoff, sizeof(u16));
97 142 msleep(60);
98 spi_write(spi, (const u8 *)&disoff, sizeof(u16)); 143 l4f00242t03_lcd_powerdown(spi);
99 msleep(60); 144 }
100 spi_write(spi, (const u8 *)&slpin, sizeof(u16));
101
102 priv->lcd_on = 0;
103 } 145 }
104 146
147 priv->lcd_state = power;
148
105 return 0; 149 return 0;
106} 150}
107 151
108static struct lcd_ops l4f_ops = { 152static struct lcd_ops l4f_ops = {
109 .set_power = l4f00242t03_lcd_power_set, 153 .set_power = l4f00242t03_lcd_power_set,
110 .get_power = NULL, 154 .get_power = l4f00242t03_lcd_power_get,
111}; 155};
112 156
113static int __devinit l4f00242t03_probe(struct spi_device *spi) 157static int __devinit l4f00242t03_probe(struct spi_device *spi)
@@ -185,9 +229,9 @@ static int __devinit l4f00242t03_probe(struct spi_device *spi)
185 } 229 }
186 230
187 /* Init the LCD */ 231 /* Init the LCD */
188 l4f00242t03_reset(pdata->reset_gpio);
189 l4f00242t03_lcd_init(spi); 232 l4f00242t03_lcd_init(spi);
190 l4f00242t03_lcd_power_set(priv->ld, 1); 233 priv->lcd_state = FB_BLANK_VSYNC_SUSPEND;
234 l4f00242t03_lcd_power_set(priv->ld, FB_BLANK_UNBLANK);
191 235
192 dev_info(&spi->dev, "Epson l4f00242t03 lcd probed.\n"); 236 dev_info(&spi->dev, "Epson l4f00242t03 lcd probed.\n");
193 237
@@ -214,9 +258,11 @@ static int __devexit l4f00242t03_remove(struct spi_device *spi)
214 struct l4f00242t03_priv *priv = dev_get_drvdata(&spi->dev); 258 struct l4f00242t03_priv *priv = dev_get_drvdata(&spi->dev);
215 struct l4f00242t03_pdata *pdata = priv->spi->dev.platform_data; 259 struct l4f00242t03_pdata *pdata = priv->spi->dev.platform_data;
216 260
217 l4f00242t03_lcd_power_set(priv->ld, 0); 261 l4f00242t03_lcd_power_set(priv->ld, FB_BLANK_POWERDOWN);
218 lcd_device_unregister(priv->ld); 262 lcd_device_unregister(priv->ld);
219 263
264 dev_set_drvdata(&spi->dev, NULL);
265
220 gpio_free(pdata->data_enable_gpio); 266 gpio_free(pdata->data_enable_gpio);
221 gpio_free(pdata->reset_gpio); 267 gpio_free(pdata->reset_gpio);
222 268
@@ -230,6 +276,15 @@ static int __devexit l4f00242t03_remove(struct spi_device *spi)
230 return 0; 276 return 0;
231} 277}
232 278
279static void l4f00242t03_shutdown(struct spi_device *spi)
280{
281 struct l4f00242t03_priv *priv = dev_get_drvdata(&spi->dev);
282
283 if (priv)
284 l4f00242t03_lcd_power_set(priv->ld, FB_BLANK_POWERDOWN);
285
286}
287
233static struct spi_driver l4f00242t03_driver = { 288static struct spi_driver l4f00242t03_driver = {
234 .driver = { 289 .driver = {
235 .name = "l4f00242t03", 290 .name = "l4f00242t03",
@@ -237,6 +292,7 @@ static struct spi_driver l4f00242t03_driver = {
237 }, 292 },
238 .probe = l4f00242t03_probe, 293 .probe = l4f00242t03_probe,
239 .remove = __devexit_p(l4f00242t03_remove), 294 .remove = __devexit_p(l4f00242t03_remove),
295 .shutdown = l4f00242t03_shutdown,
240}; 296};
241 297
242static __init int l4f00242t03_init(void) 298static __init int l4f00242t03_init(void)
diff --git a/drivers/video/backlight/max8925_bl.c b/drivers/video/backlight/max8925_bl.c
index b2b2c7ba1f63..209acc105cbc 100644
--- a/drivers/video/backlight/max8925_bl.c
+++ b/drivers/video/backlight/max8925_bl.c
@@ -92,7 +92,7 @@ static int max8925_backlight_get_brightness(struct backlight_device *bl)
92 return ret; 92 return ret;
93} 93}
94 94
95static struct backlight_ops max8925_backlight_ops = { 95static const struct backlight_ops max8925_backlight_ops = {
96 .options = BL_CORE_SUSPENDRESUME, 96 .options = BL_CORE_SUSPENDRESUME,
97 .update_status = max8925_backlight_update_status, 97 .update_status = max8925_backlight_update_status,
98 .get_brightness = max8925_backlight_get_brightness, 98 .get_brightness = max8925_backlight_get_brightness,
diff --git a/drivers/video/console/vgacon.c b/drivers/video/console/vgacon.c
index 915448ec75bf..c97491b8b39b 100644
--- a/drivers/video/console/vgacon.c
+++ b/drivers/video/console/vgacon.c
@@ -375,7 +375,8 @@ static const char *vgacon_startup(void)
375 u16 saved1, saved2; 375 u16 saved1, saved2;
376 volatile u16 *p; 376 volatile u16 *p;
377 377
378 if (screen_info.orig_video_isVGA == VIDEO_TYPE_VLFB) { 378 if (screen_info.orig_video_isVGA == VIDEO_TYPE_VLFB ||
379 screen_info.orig_video_isVGA == VIDEO_TYPE_EFI) {
379 no_vga: 380 no_vga:
380#ifdef CONFIG_DUMMY_CONSOLE 381#ifdef CONFIG_DUMMY_CONSOLE
381 conswitchp = &dummy_con; 382 conswitchp = &dummy_con;
diff --git a/drivers/video/imxfb.c b/drivers/video/imxfb.c
index 1ab2c2588675..69bd4a581d4a 100644
--- a/drivers/video/imxfb.c
+++ b/drivers/video/imxfb.c
@@ -974,6 +974,6 @@ static void __exit imxfb_cleanup(void)
974module_init(imxfb_init); 974module_init(imxfb_init);
975module_exit(imxfb_cleanup); 975module_exit(imxfb_cleanup);
976 976
977MODULE_DESCRIPTION("Motorola i.MX framebuffer driver"); 977MODULE_DESCRIPTION("Freescale i.MX framebuffer driver");
978MODULE_AUTHOR("Sascha Hauer, Pengutronix"); 978MODULE_AUTHOR("Sascha Hauer, Pengutronix");
979MODULE_LICENSE("GPL"); 979MODULE_LICENSE("GPL");
diff --git a/drivers/video/matrox/matroxfb_base.c b/drivers/video/matrox/matroxfb_base.c
index 052dd9f0b760..a082debe824b 100644
--- a/drivers/video/matrox/matroxfb_base.c
+++ b/drivers/video/matrox/matroxfb_base.c
@@ -1247,46 +1247,46 @@ static struct { struct fb_bitfield red, green, blue, transp; int bits_per_pixel;
1247}; 1247};
1248 1248
1249/* initialized by setup, see explanation at end of file (search for MODULE_PARM_DESC) */ 1249/* initialized by setup, see explanation at end of file (search for MODULE_PARM_DESC) */
1250static unsigned int mem; /* "matrox:mem:xxxxxM" */ 1250static unsigned int mem; /* "matroxfb:mem:xxxxxM" */
1251static int option_precise_width = 1; /* cannot be changed, option_precise_width==0 must imply noaccel */ 1251static int option_precise_width = 1; /* cannot be changed, option_precise_width==0 must imply noaccel */
1252static int inv24; /* "matrox:inv24" */ 1252static int inv24; /* "matroxfb:inv24" */
1253static int cross4MB = -1; /* "matrox:cross4MB" */ 1253static int cross4MB = -1; /* "matroxfb:cross4MB" */
1254static int disabled; /* "matrox:disabled" */ 1254static int disabled; /* "matroxfb:disabled" */
1255static int noaccel; /* "matrox:noaccel" */ 1255static int noaccel; /* "matroxfb:noaccel" */
1256static int nopan; /* "matrox:nopan" */ 1256static int nopan; /* "matroxfb:nopan" */
1257static int no_pci_retry; /* "matrox:nopciretry" */ 1257static int no_pci_retry; /* "matroxfb:nopciretry" */
1258static int novga; /* "matrox:novga" */ 1258static int novga; /* "matroxfb:novga" */
1259static int nobios; /* "matrox:nobios" */ 1259static int nobios; /* "matroxfb:nobios" */
1260static int noinit = 1; /* "matrox:init" */ 1260static int noinit = 1; /* "matroxfb:init" */
1261static int inverse; /* "matrox:inverse" */ 1261static int inverse; /* "matroxfb:inverse" */
1262static int sgram; /* "matrox:sgram" */ 1262static int sgram; /* "matroxfb:sgram" */
1263#ifdef CONFIG_MTRR 1263#ifdef CONFIG_MTRR
1264static int mtrr = 1; /* "matrox:nomtrr" */ 1264static int mtrr = 1; /* "matroxfb:nomtrr" */
1265#endif 1265#endif
1266static int grayscale; /* "matrox:grayscale" */ 1266static int grayscale; /* "matroxfb:grayscale" */
1267static int dev = -1; /* "matrox:dev:xxxxx" */ 1267static int dev = -1; /* "matroxfb:dev:xxxxx" */
1268static unsigned int vesa = ~0; /* "matrox:vesa:xxxxx" */ 1268static unsigned int vesa = ~0; /* "matroxfb:vesa:xxxxx" */
1269static int depth = -1; /* "matrox:depth:xxxxx" */ 1269static int depth = -1; /* "matroxfb:depth:xxxxx" */
1270static unsigned int xres; /* "matrox:xres:xxxxx" */ 1270static unsigned int xres; /* "matroxfb:xres:xxxxx" */
1271static unsigned int yres; /* "matrox:yres:xxxxx" */ 1271static unsigned int yres; /* "matroxfb:yres:xxxxx" */
1272static unsigned int upper = ~0; /* "matrox:upper:xxxxx" */ 1272static unsigned int upper = ~0; /* "matroxfb:upper:xxxxx" */
1273static unsigned int lower = ~0; /* "matrox:lower:xxxxx" */ 1273static unsigned int lower = ~0; /* "matroxfb:lower:xxxxx" */
1274static unsigned int vslen; /* "matrox:vslen:xxxxx" */ 1274static unsigned int vslen; /* "matroxfb:vslen:xxxxx" */
1275static unsigned int left = ~0; /* "matrox:left:xxxxx" */ 1275static unsigned int left = ~0; /* "matroxfb:left:xxxxx" */
1276static unsigned int right = ~0; /* "matrox:right:xxxxx" */ 1276static unsigned int right = ~0; /* "matroxfb:right:xxxxx" */
1277static unsigned int hslen; /* "matrox:hslen:xxxxx" */ 1277static unsigned int hslen; /* "matroxfb:hslen:xxxxx" */
1278static unsigned int pixclock; /* "matrox:pixclock:xxxxx" */ 1278static unsigned int pixclock; /* "matroxfb:pixclock:xxxxx" */
1279static int sync = -1; /* "matrox:sync:xxxxx" */ 1279static int sync = -1; /* "matroxfb:sync:xxxxx" */
1280static unsigned int fv; /* "matrox:fv:xxxxx" */ 1280static unsigned int fv; /* "matroxfb:fv:xxxxx" */
1281static unsigned int fh; /* "matrox:fh:xxxxxk" */ 1281static unsigned int fh; /* "matroxfb:fh:xxxxxk" */
1282static unsigned int maxclk; /* "matrox:maxclk:xxxxM" */ 1282static unsigned int maxclk; /* "matroxfb:maxclk:xxxxM" */
1283static int dfp; /* "matrox:dfp */ 1283static int dfp; /* "matroxfb:dfp */
1284static int dfp_type = -1; /* "matrox:dfp:xxx */ 1284static int dfp_type = -1; /* "matroxfb:dfp:xxx */
1285static int memtype = -1; /* "matrox:memtype:xxx" */ 1285static int memtype = -1; /* "matroxfb:memtype:xxx" */
1286static char outputs[8]; /* "matrox:outputs:xxx" */ 1286static char outputs[8]; /* "matroxfb:outputs:xxx" */
1287 1287
1288#ifndef MODULE 1288#ifndef MODULE
1289static char videomode[64]; /* "matrox:mode:xxxxx" or "matrox:xxxxx" */ 1289static char videomode[64]; /* "matroxfb:mode:xxxxx" or "matroxfb:xxxxx" */
1290#endif 1290#endif
1291 1291
1292static int matroxfb_getmemory(struct matrox_fb_info *minfo, 1292static int matroxfb_getmemory(struct matrox_fb_info *minfo,
diff --git a/drivers/video/modedb.c b/drivers/video/modedb.c
index d2bb365f09b3..48c3ea8652b6 100644
--- a/drivers/video/modedb.c
+++ b/drivers/video/modedb.c
@@ -32,300 +32,320 @@
32const char *fb_mode_option; 32const char *fb_mode_option;
33EXPORT_SYMBOL_GPL(fb_mode_option); 33EXPORT_SYMBOL_GPL(fb_mode_option);
34 34
35 /* 35/*
36 * Standard video mode definitions (taken from XFree86) 36 * Standard video mode definitions (taken from XFree86)
37 */ 37 */
38 38
39static const struct fb_videomode modedb[] = { 39static const struct fb_videomode modedb[] = {
40 { 40
41 /* 640x400 @ 70 Hz, 31.5 kHz hsync */ 41 /* 640x400 @ 70 Hz, 31.5 kHz hsync */
42 NULL, 70, 640, 400, 39721, 40, 24, 39, 9, 96, 2, 42 { NULL, 70, 640, 400, 39721, 40, 24, 39, 9, 96, 2, 0,
43 0, FB_VMODE_NONINTERLACED 43 FB_VMODE_NONINTERLACED },
44 }, { 44
45 /* 640x480 @ 60 Hz, 31.5 kHz hsync */ 45 /* 640x480 @ 60 Hz, 31.5 kHz hsync */
46 NULL, 60, 640, 480, 39721, 40, 24, 32, 11, 96, 2, 46 { NULL, 60, 640, 480, 39721, 40, 24, 32, 11, 96, 2, 0,
47 0, FB_VMODE_NONINTERLACED 47 FB_VMODE_NONINTERLACED },
48 }, { 48
49 /* 800x600 @ 56 Hz, 35.15 kHz hsync */ 49 /* 800x600 @ 56 Hz, 35.15 kHz hsync */
50 NULL, 56, 800, 600, 27777, 128, 24, 22, 1, 72, 2, 50 { NULL, 56, 800, 600, 27777, 128, 24, 22, 1, 72, 2, 0,
51 0, FB_VMODE_NONINTERLACED 51 FB_VMODE_NONINTERLACED },
52 }, { 52
53 /* 1024x768 @ 87 Hz interlaced, 35.5 kHz hsync */ 53 /* 1024x768 @ 87 Hz interlaced, 35.5 kHz hsync */
54 NULL, 87, 1024, 768, 22271, 56, 24, 33, 8, 160, 8, 54 { NULL, 87, 1024, 768, 22271, 56, 24, 33, 8, 160, 8, 0,
55 0, FB_VMODE_INTERLACED 55 FB_VMODE_INTERLACED },
56 }, { 56
57 /* 640x400 @ 85 Hz, 37.86 kHz hsync */ 57 /* 640x400 @ 85 Hz, 37.86 kHz hsync */
58 NULL, 85, 640, 400, 31746, 96, 32, 41, 1, 64, 3, 58 { NULL, 85, 640, 400, 31746, 96, 32, 41, 1, 64, 3,
59 FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED 59 FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED },
60 }, { 60
61 /* 640x480 @ 72 Hz, 36.5 kHz hsync */ 61 /* 640x480 @ 72 Hz, 36.5 kHz hsync */
62 NULL, 72, 640, 480, 31746, 144, 40, 30, 8, 40, 3, 62 { NULL, 72, 640, 480, 31746, 144, 40, 30, 8, 40, 3, 0,
63 0, FB_VMODE_NONINTERLACED 63 FB_VMODE_NONINTERLACED },
64 }, { 64
65 /* 640x480 @ 75 Hz, 37.50 kHz hsync */ 65 /* 640x480 @ 75 Hz, 37.50 kHz hsync */
66 NULL, 75, 640, 480, 31746, 120, 16, 16, 1, 64, 3, 66 { NULL, 75, 640, 480, 31746, 120, 16, 16, 1, 64, 3, 0,
67 0, FB_VMODE_NONINTERLACED 67 FB_VMODE_NONINTERLACED },
68 }, { 68
69 /* 800x600 @ 60 Hz, 37.8 kHz hsync */ 69 /* 800x600 @ 60 Hz, 37.8 kHz hsync */
70 NULL, 60, 800, 600, 25000, 88, 40, 23, 1, 128, 4, 70 { NULL, 60, 800, 600, 25000, 88, 40, 23, 1, 128, 4,
71 FB_SYNC_HOR_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED 71 FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
72 }, { 72 FB_VMODE_NONINTERLACED },
73
73 /* 640x480 @ 85 Hz, 43.27 kHz hsync */ 74 /* 640x480 @ 85 Hz, 43.27 kHz hsync */
74 NULL, 85, 640, 480, 27777, 80, 56, 25, 1, 56, 3, 75 { NULL, 85, 640, 480, 27777, 80, 56, 25, 1, 56, 3, 0,
75 0, FB_VMODE_NONINTERLACED 76 FB_VMODE_NONINTERLACED },
76 }, { 77
77 /* 1152x864 @ 89 Hz interlaced, 44 kHz hsync */ 78 /* 1152x864 @ 89 Hz interlaced, 44 kHz hsync */
78 NULL, 89, 1152, 864, 15384, 96, 16, 110, 1, 216, 10, 79 { NULL, 89, 1152, 864, 15384, 96, 16, 110, 1, 216, 10, 0,
79 0, FB_VMODE_INTERLACED 80 FB_VMODE_INTERLACED },
80 }, {
81 /* 800x600 @ 72 Hz, 48.0 kHz hsync */ 81 /* 800x600 @ 72 Hz, 48.0 kHz hsync */
82 NULL, 72, 800, 600, 20000, 64, 56, 23, 37, 120, 6, 82 { NULL, 72, 800, 600, 20000, 64, 56, 23, 37, 120, 6,
83 FB_SYNC_HOR_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED 83 FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
84 }, { 84 FB_VMODE_NONINTERLACED },
85
85 /* 1024x768 @ 60 Hz, 48.4 kHz hsync */ 86 /* 1024x768 @ 60 Hz, 48.4 kHz hsync */
86 NULL, 60, 1024, 768, 15384, 168, 8, 29, 3, 144, 6, 87 { NULL, 60, 1024, 768, 15384, 168, 8, 29, 3, 144, 6, 0,
87 0, FB_VMODE_NONINTERLACED 88 FB_VMODE_NONINTERLACED },
88 }, { 89
89 /* 640x480 @ 100 Hz, 53.01 kHz hsync */ 90 /* 640x480 @ 100 Hz, 53.01 kHz hsync */
90 NULL, 100, 640, 480, 21834, 96, 32, 36, 8, 96, 6, 91 { NULL, 100, 640, 480, 21834, 96, 32, 36, 8, 96, 6, 0,
91 0, FB_VMODE_NONINTERLACED 92 FB_VMODE_NONINTERLACED },
92 }, { 93
93 /* 1152x864 @ 60 Hz, 53.5 kHz hsync */ 94 /* 1152x864 @ 60 Hz, 53.5 kHz hsync */
94 NULL, 60, 1152, 864, 11123, 208, 64, 16, 4, 256, 8, 95 { NULL, 60, 1152, 864, 11123, 208, 64, 16, 4, 256, 8, 0,
95 0, FB_VMODE_NONINTERLACED 96 FB_VMODE_NONINTERLACED },
96 }, { 97
97 /* 800x600 @ 85 Hz, 55.84 kHz hsync */ 98 /* 800x600 @ 85 Hz, 55.84 kHz hsync */
98 NULL, 85, 800, 600, 16460, 160, 64, 36, 16, 64, 5, 99 { NULL, 85, 800, 600, 16460, 160, 64, 36, 16, 64, 5, 0,
99 0, FB_VMODE_NONINTERLACED 100 FB_VMODE_NONINTERLACED },
100 }, { 101
101 /* 1024x768 @ 70 Hz, 56.5 kHz hsync */ 102 /* 1024x768 @ 70 Hz, 56.5 kHz hsync */
102 NULL, 70, 1024, 768, 13333, 144, 24, 29, 3, 136, 6, 103 { NULL, 70, 1024, 768, 13333, 144, 24, 29, 3, 136, 6, 0,
103 0, FB_VMODE_NONINTERLACED 104 FB_VMODE_NONINTERLACED },
104 }, { 105
105 /* 1280x1024 @ 87 Hz interlaced, 51 kHz hsync */ 106 /* 1280x1024 @ 87 Hz interlaced, 51 kHz hsync */
106 NULL, 87, 1280, 1024, 12500, 56, 16, 128, 1, 216, 12, 107 { NULL, 87, 1280, 1024, 12500, 56, 16, 128, 1, 216, 12, 0,
107 0, FB_VMODE_INTERLACED 108 FB_VMODE_INTERLACED },
108 }, { 109
109 /* 800x600 @ 100 Hz, 64.02 kHz hsync */ 110 /* 800x600 @ 100 Hz, 64.02 kHz hsync */
110 NULL, 100, 800, 600, 14357, 160, 64, 30, 4, 64, 6, 111 { NULL, 100, 800, 600, 14357, 160, 64, 30, 4, 64, 6, 0,
111 0, FB_VMODE_NONINTERLACED 112 FB_VMODE_NONINTERLACED },
112 }, { 113
113 /* 1024x768 @ 76 Hz, 62.5 kHz hsync */ 114 /* 1024x768 @ 76 Hz, 62.5 kHz hsync */
114 NULL, 76, 1024, 768, 11764, 208, 8, 36, 16, 120, 3, 115 { NULL, 76, 1024, 768, 11764, 208, 8, 36, 16, 120, 3, 0,
115 0, FB_VMODE_NONINTERLACED 116 FB_VMODE_NONINTERLACED },
116 }, { 117
117 /* 1152x864 @ 70 Hz, 62.4 kHz hsync */ 118 /* 1152x864 @ 70 Hz, 62.4 kHz hsync */
118 NULL, 70, 1152, 864, 10869, 106, 56, 20, 1, 160, 10, 119 { NULL, 70, 1152, 864, 10869, 106, 56, 20, 1, 160, 10, 0,
119 0, FB_VMODE_NONINTERLACED 120 FB_VMODE_NONINTERLACED },
120 }, { 121
121 /* 1280x1024 @ 61 Hz, 64.2 kHz hsync */ 122 /* 1280x1024 @ 61 Hz, 64.2 kHz hsync */
122 NULL, 61, 1280, 1024, 9090, 200, 48, 26, 1, 184, 3, 123 { NULL, 61, 1280, 1024, 9090, 200, 48, 26, 1, 184, 3, 0,
123 0, FB_VMODE_NONINTERLACED 124 FB_VMODE_NONINTERLACED },
124 }, { 125
125 /* 1400x1050 @ 60Hz, 63.9 kHz hsync */ 126 /* 1400x1050 @ 60Hz, 63.9 kHz hsync */
126 NULL, 60, 1400, 1050, 9259, 136, 40, 13, 1, 112, 3, 127 { NULL, 60, 1400, 1050, 9259, 136, 40, 13, 1, 112, 3, 0,
127 0, FB_VMODE_NONINTERLACED 128 FB_VMODE_NONINTERLACED },
128 }, { 129
129 /* 1400x1050 @ 75,107 Hz, 82,392 kHz +hsync +vsync*/ 130 /* 1400x1050 @ 75,107 Hz, 82,392 kHz +hsync +vsync*/
130 NULL, 75, 1400, 1050, 7190, 120, 56, 23, 10, 112, 13, 131 { NULL, 75, 1400, 1050, 7190, 120, 56, 23, 10, 112, 13,
131 FB_SYNC_HOR_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED 132 FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
132 }, { 133 FB_VMODE_NONINTERLACED },
134
133 /* 1400x1050 @ 60 Hz, ? kHz +hsync +vsync*/ 135 /* 1400x1050 @ 60 Hz, ? kHz +hsync +vsync*/
134 NULL, 60, 1400, 1050, 9259, 128, 40, 12, 0, 112, 3, 136 { NULL, 60, 1400, 1050, 9259, 128, 40, 12, 0, 112, 3,
135 FB_SYNC_HOR_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED 137 FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
136 }, { 138 FB_VMODE_NONINTERLACED },
139
137 /* 1024x768 @ 85 Hz, 70.24 kHz hsync */ 140 /* 1024x768 @ 85 Hz, 70.24 kHz hsync */
138 NULL, 85, 1024, 768, 10111, 192, 32, 34, 14, 160, 6, 141 { NULL, 85, 1024, 768, 10111, 192, 32, 34, 14, 160, 6, 0,
139 0, FB_VMODE_NONINTERLACED 142 FB_VMODE_NONINTERLACED },
140 }, { 143
141 /* 1152x864 @ 78 Hz, 70.8 kHz hsync */ 144 /* 1152x864 @ 78 Hz, 70.8 kHz hsync */
142 NULL, 78, 1152, 864, 9090, 228, 88, 32, 0, 84, 12, 145 { NULL, 78, 1152, 864, 9090, 228, 88, 32, 0, 84, 12, 0,
143 0, FB_VMODE_NONINTERLACED 146 FB_VMODE_NONINTERLACED },
144 }, { 147
145 /* 1280x1024 @ 70 Hz, 74.59 kHz hsync */ 148 /* 1280x1024 @ 70 Hz, 74.59 kHz hsync */
146 NULL, 70, 1280, 1024, 7905, 224, 32, 28, 8, 160, 8, 149 { NULL, 70, 1280, 1024, 7905, 224, 32, 28, 8, 160, 8, 0,
147 0, FB_VMODE_NONINTERLACED 150 FB_VMODE_NONINTERLACED },
148 }, { 151
149 /* 1600x1200 @ 60Hz, 75.00 kHz hsync */ 152 /* 1600x1200 @ 60Hz, 75.00 kHz hsync */
150 NULL, 60, 1600, 1200, 6172, 304, 64, 46, 1, 192, 3, 153 { NULL, 60, 1600, 1200, 6172, 304, 64, 46, 1, 192, 3,
151 FB_SYNC_HOR_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED 154 FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
152 }, { 155 FB_VMODE_NONINTERLACED },
156
153 /* 1152x864 @ 84 Hz, 76.0 kHz hsync */ 157 /* 1152x864 @ 84 Hz, 76.0 kHz hsync */
154 NULL, 84, 1152, 864, 7407, 184, 312, 32, 0, 128, 12, 158 { NULL, 84, 1152, 864, 7407, 184, 312, 32, 0, 128, 12, 0,
155 0, FB_VMODE_NONINTERLACED 159 FB_VMODE_NONINTERLACED },
156 }, { 160
157 /* 1280x1024 @ 74 Hz, 78.85 kHz hsync */ 161 /* 1280x1024 @ 74 Hz, 78.85 kHz hsync */
158 NULL, 74, 1280, 1024, 7407, 256, 32, 34, 3, 144, 3, 162 { NULL, 74, 1280, 1024, 7407, 256, 32, 34, 3, 144, 3, 0,
159 0, FB_VMODE_NONINTERLACED 163 FB_VMODE_NONINTERLACED },
160 }, { 164
161 /* 1024x768 @ 100Hz, 80.21 kHz hsync */ 165 /* 1024x768 @ 100Hz, 80.21 kHz hsync */
162 NULL, 100, 1024, 768, 8658, 192, 32, 21, 3, 192, 10, 166 { NULL, 100, 1024, 768, 8658, 192, 32, 21, 3, 192, 10, 0,
163 0, FB_VMODE_NONINTERLACED 167 FB_VMODE_NONINTERLACED },
164 }, { 168
165 /* 1280x1024 @ 76 Hz, 81.13 kHz hsync */ 169 /* 1280x1024 @ 76 Hz, 81.13 kHz hsync */
166 NULL, 76, 1280, 1024, 7407, 248, 32, 34, 3, 104, 3, 170 { NULL, 76, 1280, 1024, 7407, 248, 32, 34, 3, 104, 3, 0,
167 0, FB_VMODE_NONINTERLACED 171 FB_VMODE_NONINTERLACED },
168 }, { 172
169 /* 1600x1200 @ 70 Hz, 87.50 kHz hsync */ 173 /* 1600x1200 @ 70 Hz, 87.50 kHz hsync */
170 NULL, 70, 1600, 1200, 5291, 304, 64, 46, 1, 192, 3, 174 { NULL, 70, 1600, 1200, 5291, 304, 64, 46, 1, 192, 3, 0,
171 0, FB_VMODE_NONINTERLACED 175 FB_VMODE_NONINTERLACED },
172 }, { 176
173 /* 1152x864 @ 100 Hz, 89.62 kHz hsync */ 177 /* 1152x864 @ 100 Hz, 89.62 kHz hsync */
174 NULL, 100, 1152, 864, 7264, 224, 32, 17, 2, 128, 19, 178 { NULL, 100, 1152, 864, 7264, 224, 32, 17, 2, 128, 19, 0,
175 0, FB_VMODE_NONINTERLACED 179 FB_VMODE_NONINTERLACED },
176 }, { 180
177 /* 1280x1024 @ 85 Hz, 91.15 kHz hsync */ 181 /* 1280x1024 @ 85 Hz, 91.15 kHz hsync */
178 NULL, 85, 1280, 1024, 6349, 224, 64, 44, 1, 160, 3, 182 { NULL, 85, 1280, 1024, 6349, 224, 64, 44, 1, 160, 3,
179 FB_SYNC_HOR_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED 183 FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
180 }, { 184 FB_VMODE_NONINTERLACED },
185
181 /* 1600x1200 @ 75 Hz, 93.75 kHz hsync */ 186 /* 1600x1200 @ 75 Hz, 93.75 kHz hsync */
182 NULL, 75, 1600, 1200, 4938, 304, 64, 46, 1, 192, 3, 187 { NULL, 75, 1600, 1200, 4938, 304, 64, 46, 1, 192, 3,
183 FB_SYNC_HOR_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED 188 FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
184 }, { 189 FB_VMODE_NONINTERLACED },
190
185 /* 1680x1050 @ 60 Hz, 65.191 kHz hsync */ 191 /* 1680x1050 @ 60 Hz, 65.191 kHz hsync */
186 NULL, 60, 1680, 1050, 6848, 280, 104, 30, 3, 176, 6, 192 { NULL, 60, 1680, 1050, 6848, 280, 104, 30, 3, 176, 6,
187 FB_SYNC_HOR_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED 193 FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
188 }, { 194 FB_VMODE_NONINTERLACED },
195
189 /* 1600x1200 @ 85 Hz, 105.77 kHz hsync */ 196 /* 1600x1200 @ 85 Hz, 105.77 kHz hsync */
190 NULL, 85, 1600, 1200, 4545, 272, 16, 37, 4, 192, 3, 197 { NULL, 85, 1600, 1200, 4545, 272, 16, 37, 4, 192, 3,
191 FB_SYNC_HOR_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED 198 FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
192 }, { 199 FB_VMODE_NONINTERLACED },
200
193 /* 1280x1024 @ 100 Hz, 107.16 kHz hsync */ 201 /* 1280x1024 @ 100 Hz, 107.16 kHz hsync */
194 NULL, 100, 1280, 1024, 5502, 256, 32, 26, 7, 128, 15, 202 { NULL, 100, 1280, 1024, 5502, 256, 32, 26, 7, 128, 15, 0,
195 0, FB_VMODE_NONINTERLACED 203 FB_VMODE_NONINTERLACED },
196 }, { 204
197 /* 1800x1440 @ 64Hz, 96.15 kHz hsync */ 205 /* 1800x1440 @ 64Hz, 96.15 kHz hsync */
198 NULL, 64, 1800, 1440, 4347, 304, 96, 46, 1, 192, 3, 206 { NULL, 64, 1800, 1440, 4347, 304, 96, 46, 1, 192, 3,
199 FB_SYNC_HOR_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED 207 FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
200 }, { 208 FB_VMODE_NONINTERLACED },
209
201 /* 1800x1440 @ 70Hz, 104.52 kHz hsync */ 210 /* 1800x1440 @ 70Hz, 104.52 kHz hsync */
202 NULL, 70, 1800, 1440, 4000, 304, 96, 46, 1, 192, 3, 211 { NULL, 70, 1800, 1440, 4000, 304, 96, 46, 1, 192, 3,
203 FB_SYNC_HOR_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED 212 FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
204 }, { 213 FB_VMODE_NONINTERLACED },
214
205 /* 512x384 @ 78 Hz, 31.50 kHz hsync */ 215 /* 512x384 @ 78 Hz, 31.50 kHz hsync */
206 NULL, 78, 512, 384, 49603, 48, 16, 16, 1, 64, 3, 216 { NULL, 78, 512, 384, 49603, 48, 16, 16, 1, 64, 3, 0,
207 0, FB_VMODE_NONINTERLACED 217 FB_VMODE_NONINTERLACED },
208 }, { 218
209 /* 512x384 @ 85 Hz, 34.38 kHz hsync */ 219 /* 512x384 @ 85 Hz, 34.38 kHz hsync */
210 NULL, 85, 512, 384, 45454, 48, 16, 16, 1, 64, 3, 220 { NULL, 85, 512, 384, 45454, 48, 16, 16, 1, 64, 3, 0,
211 0, FB_VMODE_NONINTERLACED 221 FB_VMODE_NONINTERLACED },
212 }, { 222
213 /* 320x200 @ 70 Hz, 31.5 kHz hsync, 8:5 aspect ratio */ 223 /* 320x200 @ 70 Hz, 31.5 kHz hsync, 8:5 aspect ratio */
214 NULL, 70, 320, 200, 79440, 16, 16, 20, 4, 48, 1, 224 { NULL, 70, 320, 200, 79440, 16, 16, 20, 4, 48, 1, 0,
215 0, FB_VMODE_DOUBLE 225 FB_VMODE_DOUBLE },
216 }, { 226
217 /* 320x240 @ 60 Hz, 31.5 kHz hsync, 4:3 aspect ratio */ 227 /* 320x240 @ 60 Hz, 31.5 kHz hsync, 4:3 aspect ratio */
218 NULL, 60, 320, 240, 79440, 16, 16, 16, 5, 48, 1, 228 { NULL, 60, 320, 240, 79440, 16, 16, 16, 5, 48, 1, 0,
219 0, FB_VMODE_DOUBLE 229 FB_VMODE_DOUBLE },
220 }, { 230
221 /* 320x240 @ 72 Hz, 36.5 kHz hsync */ 231 /* 320x240 @ 72 Hz, 36.5 kHz hsync */
222 NULL, 72, 320, 240, 63492, 16, 16, 16, 4, 48, 2, 232 { NULL, 72, 320, 240, 63492, 16, 16, 16, 4, 48, 2, 0,
223 0, FB_VMODE_DOUBLE 233 FB_VMODE_DOUBLE },
224 }, { 234
225 /* 400x300 @ 56 Hz, 35.2 kHz hsync, 4:3 aspect ratio */ 235 /* 400x300 @ 56 Hz, 35.2 kHz hsync, 4:3 aspect ratio */
226 NULL, 56, 400, 300, 55555, 64, 16, 10, 1, 32, 1, 236 { NULL, 56, 400, 300, 55555, 64, 16, 10, 1, 32, 1, 0,
227 0, FB_VMODE_DOUBLE 237 FB_VMODE_DOUBLE },
228 }, { 238
229 /* 400x300 @ 60 Hz, 37.8 kHz hsync */ 239 /* 400x300 @ 60 Hz, 37.8 kHz hsync */
230 NULL, 60, 400, 300, 50000, 48, 16, 11, 1, 64, 2, 240 { NULL, 60, 400, 300, 50000, 48, 16, 11, 1, 64, 2, 0,
231 0, FB_VMODE_DOUBLE 241 FB_VMODE_DOUBLE },
232 }, { 242
233 /* 400x300 @ 72 Hz, 48.0 kHz hsync */ 243 /* 400x300 @ 72 Hz, 48.0 kHz hsync */
234 NULL, 72, 400, 300, 40000, 32, 24, 11, 19, 64, 3, 244 { NULL, 72, 400, 300, 40000, 32, 24, 11, 19, 64, 3, 0,
235 0, FB_VMODE_DOUBLE 245 FB_VMODE_DOUBLE },
236 }, { 246
237 /* 480x300 @ 56 Hz, 35.2 kHz hsync, 8:5 aspect ratio */ 247 /* 480x300 @ 56 Hz, 35.2 kHz hsync, 8:5 aspect ratio */
238 NULL, 56, 480, 300, 46176, 80, 16, 10, 1, 40, 1, 248 { NULL, 56, 480, 300, 46176, 80, 16, 10, 1, 40, 1, 0,
239 0, FB_VMODE_DOUBLE 249 FB_VMODE_DOUBLE },
240 }, { 250
241 /* 480x300 @ 60 Hz, 37.8 kHz hsync */ 251 /* 480x300 @ 60 Hz, 37.8 kHz hsync */
242 NULL, 60, 480, 300, 41858, 56, 16, 11, 1, 80, 2, 252 { NULL, 60, 480, 300, 41858, 56, 16, 11, 1, 80, 2, 0,
243 0, FB_VMODE_DOUBLE 253 FB_VMODE_DOUBLE },
244 }, { 254
245 /* 480x300 @ 63 Hz, 39.6 kHz hsync */ 255 /* 480x300 @ 63 Hz, 39.6 kHz hsync */
246 NULL, 63, 480, 300, 40000, 56, 16, 11, 1, 80, 2, 256 { NULL, 63, 480, 300, 40000, 56, 16, 11, 1, 80, 2, 0,
247 0, FB_VMODE_DOUBLE 257 FB_VMODE_DOUBLE },
248 }, { 258
249 /* 480x300 @ 72 Hz, 48.0 kHz hsync */ 259 /* 480x300 @ 72 Hz, 48.0 kHz hsync */
250 NULL, 72, 480, 300, 33386, 40, 24, 11, 19, 80, 3, 260 { NULL, 72, 480, 300, 33386, 40, 24, 11, 19, 80, 3, 0,
251 0, FB_VMODE_DOUBLE 261 FB_VMODE_DOUBLE },
252 }, { 262
253 /* 1920x1200 @ 60 Hz, 74.5 Khz hsync */ 263 /* 1920x1200 @ 60 Hz, 74.5 Khz hsync */
254 NULL, 60, 1920, 1200, 5177, 128, 336, 1, 38, 208, 3, 264 { NULL, 60, 1920, 1200, 5177, 128, 336, 1, 38, 208, 3,
255 FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT, 265 FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
256 FB_VMODE_NONINTERLACED 266 FB_VMODE_NONINTERLACED },
257 }, { 267
258 /* 1152x768, 60 Hz, PowerBook G4 Titanium I and II */ 268 /* 1152x768, 60 Hz, PowerBook G4 Titanium I and II */
259 NULL, 60, 1152, 768, 14047, 158, 26, 29, 3, 136, 6, 269 { NULL, 60, 1152, 768, 14047, 158, 26, 29, 3, 136, 6,
260 FB_SYNC_HOR_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED 270 FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
261 }, { 271 FB_VMODE_NONINTERLACED },
272
262 /* 1366x768, 60 Hz, 47.403 kHz hsync, WXGA 16:9 aspect ratio */ 273 /* 1366x768, 60 Hz, 47.403 kHz hsync, WXGA 16:9 aspect ratio */
263 NULL, 60, 1366, 768, 13806, 120, 10, 14, 3, 32, 5, 274 { NULL, 60, 1366, 768, 13806, 120, 10, 14, 3, 32, 5, 0,
264 0, FB_VMODE_NONINTERLACED 275 FB_VMODE_NONINTERLACED },
265 }, { 276
266 /* 1280x800, 60 Hz, 47.403 kHz hsync, WXGA 16:10 aspect ratio */ 277 /* 1280x800, 60 Hz, 47.403 kHz hsync, WXGA 16:10 aspect ratio */
267 NULL, 60, 1280, 800, 12048, 200, 64, 24, 1, 136, 3, 278 { NULL, 60, 1280, 800, 12048, 200, 64, 24, 1, 136, 3, 0,
268 0, FB_VMODE_NONINTERLACED 279 FB_VMODE_NONINTERLACED },
269 }, { 280
270 /* 720x576i @ 50 Hz, 15.625 kHz hsync (PAL RGB) */ 281 /* 720x576i @ 50 Hz, 15.625 kHz hsync (PAL RGB) */
271 NULL, 50, 720, 576, 74074, 64, 16, 39, 5, 64, 5, 282 { NULL, 50, 720, 576, 74074, 64, 16, 39, 5, 64, 5, 0,
272 0, FB_VMODE_INTERLACED 283 FB_VMODE_INTERLACED },
273 }, { 284
274 /* 800x520i @ 50 Hz, 15.625 kHz hsync (PAL RGB) */ 285 /* 800x520i @ 50 Hz, 15.625 kHz hsync (PAL RGB) */
275 NULL, 50, 800, 520, 58823, 144, 64, 72, 28, 80, 5, 286 { NULL, 50, 800, 520, 58823, 144, 64, 72, 28, 80, 5, 0,
276 0, FB_VMODE_INTERLACED 287 FB_VMODE_INTERLACED },
277 }, { 288
278 /* 864x480 @ 60 Hz, 35.15 kHz hsync */ 289 /* 864x480 @ 60 Hz, 35.15 kHz hsync */
279 NULL, 60, 864, 480, 27777, 1, 1, 1, 1, 0, 0, 290 { NULL, 60, 864, 480, 27777, 1, 1, 1, 1, 0, 0,
280 0, FB_VMODE_NONINTERLACED 291 0, FB_VMODE_NONINTERLACED },
281 },
282}; 292};
283 293
284#ifdef CONFIG_FB_MODE_HELPERS 294#ifdef CONFIG_FB_MODE_HELPERS
285const struct fb_videomode cea_modes[64] = { 295const struct fb_videomode cea_modes[64] = {
286 /* #1: 640x480p@59.94/60Hz */ 296 /* #1: 640x480p@59.94/60Hz */
287 [1] = { 297 [1] = {
288 NULL, 60, 640, 480, 39722, 48, 16, 33, 10, 96, 2, 0, FB_VMODE_NONINTERLACED, 0, 298 NULL, 60, 640, 480, 39722, 48, 16, 33, 10, 96, 2, 0,
299 FB_VMODE_NONINTERLACED, 0,
289 }, 300 },
290 /* #3: 720x480p@59.94/60Hz */ 301 /* #3: 720x480p@59.94/60Hz */
291 [3] = { 302 [3] = {
292 NULL, 60, 720, 480, 37037, 60, 16, 30, 9, 62, 6, 0, FB_VMODE_NONINTERLACED, 0, 303 NULL, 60, 720, 480, 37037, 60, 16, 30, 9, 62, 6, 0,
304 FB_VMODE_NONINTERLACED, 0,
293 }, 305 },
294 /* #5: 1920x1080i@59.94/60Hz */ 306 /* #5: 1920x1080i@59.94/60Hz */
295 [5] = { 307 [5] = {
296 NULL, 60, 1920, 1080, 13763, 148, 88, 15, 2, 44, 5, 308 NULL, 60, 1920, 1080, 13763, 148, 88, 15, 2, 44, 5,
297 FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT, FB_VMODE_INTERLACED, 0, 309 FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
310 FB_VMODE_INTERLACED, 0,
298 }, 311 },
299 /* #7: 720(1440)x480iH@59.94/60Hz */ 312 /* #7: 720(1440)x480iH@59.94/60Hz */
300 [7] = { 313 [7] = {
301 NULL, 60, 1440, 480, 18554/*37108*/, 114, 38, 15, 4, 124, 3, 0, FB_VMODE_INTERLACED, 0, 314 NULL, 60, 1440, 480, 18554/*37108*/, 114, 38, 15, 4, 124, 3, 0,
315 FB_VMODE_INTERLACED, 0,
302 }, 316 },
303 /* #9: 720(1440)x240pH@59.94/60Hz */ 317 /* #9: 720(1440)x240pH@59.94/60Hz */
304 [9] = { 318 [9] = {
305 NULL, 60, 1440, 240, 18554, 114, 38, 16, 4, 124, 3, 0, FB_VMODE_NONINTERLACED, 0, 319 NULL, 60, 1440, 240, 18554, 114, 38, 16, 4, 124, 3, 0,
320 FB_VMODE_NONINTERLACED, 0,
306 }, 321 },
307 /* #18: 720x576pH@50Hz */ 322 /* #18: 720x576pH@50Hz */
308 [18] = { 323 [18] = {
309 NULL, 50, 720, 576, 37037, 68, 12, 39, 5, 64, 5, 0, FB_VMODE_NONINTERLACED, 0, 324 NULL, 50, 720, 576, 37037, 68, 12, 39, 5, 64, 5, 0,
325 FB_VMODE_NONINTERLACED, 0,
310 }, 326 },
311 /* #19: 1280x720p@50Hz */ 327 /* #19: 1280x720p@50Hz */
312 [19] = { 328 [19] = {
313 NULL, 50, 1280, 720, 13468, 220, 440, 20, 5, 40, 5, 329 NULL, 50, 1280, 720, 13468, 220, 440, 20, 5, 40, 5,
314 FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED, 0, 330 FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
331 FB_VMODE_NONINTERLACED, 0,
315 }, 332 },
316 /* #20: 1920x1080i@50Hz */ 333 /* #20: 1920x1080i@50Hz */
317 [20] = { 334 [20] = {
318 NULL, 50, 1920, 1080, 13480, 148, 528, 15, 5, 528, 5, 335 NULL, 50, 1920, 1080, 13480, 148, 528, 15, 5, 528, 5,
319 FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT, FB_VMODE_INTERLACED, 0, 336 FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
337 FB_VMODE_INTERLACED, 0,
320 }, 338 },
321 /* #32: 1920x1080p@23.98/24Hz */ 339 /* #32: 1920x1080p@23.98/24Hz */
322 [32] = { 340 [32] = {
323 NULL, 24, 1920, 1080, 13468, 148, 638, 36, 4, 44, 5, 341 NULL, 24, 1920, 1080, 13468, 148, 638, 36, 4, 44, 5,
324 FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED, 0, 342 FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
343 FB_VMODE_NONINTERLACED, 0,
325 }, 344 },
326 /* #35: (2880)x480p4x@59.94/60Hz */ 345 /* #35: (2880)x480p4x@59.94/60Hz */
327 [35] = { 346 [35] = {
328 NULL, 60, 2880, 480, 9250, 240, 64, 30, 9, 248, 6, 0, FB_VMODE_NONINTERLACED, 0, 347 NULL, 60, 2880, 480, 9250, 240, 64, 30, 9, 248, 6, 0,
348 FB_VMODE_NONINTERLACED, 0,
329 }, 349 },
330}; 350};
331 351
@@ -340,10 +360,10 @@ const struct fb_videomode vesa_modes[] = {
340 { NULL, 85, 721, 400, 28169, 108, 36, 42, 01, 72, 3, 360 { NULL, 85, 721, 400, 28169, 108, 36, 42, 01, 72, 3,
341 FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA }, 361 FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA },
342 /* 3 640x480-60 VESA */ 362 /* 3 640x480-60 VESA */
343 { NULL, 60, 640, 480, 39682, 48, 16, 33, 10, 96, 2, 363 { NULL, 60, 640, 480, 39682, 48, 16, 33, 10, 96, 2,
344 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA }, 364 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA },
345 /* 4 640x480-72 VESA */ 365 /* 4 640x480-72 VESA */
346 { NULL, 72, 640, 480, 31746, 128, 24, 29, 9, 40, 2, 366 { NULL, 72, 640, 480, 31746, 128, 24, 29, 9, 40, 2,
347 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA }, 367 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA },
348 /* 5 640x480-75 VESA */ 368 /* 5 640x480-75 VESA */
349 { NULL, 75, 640, 480, 31746, 120, 16, 16, 01, 64, 3, 369 { NULL, 75, 640, 480, 31746, 120, 16, 16, 01, 64, 3,
@@ -426,7 +446,7 @@ const struct fb_videomode vesa_modes[] = {
426 FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT, 446 FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
427 FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA }, 447 FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA },
428 /* 26 1600x1200-75 VESA */ 448 /* 26 1600x1200-75 VESA */
429 { NULL, 75, 1600, 1200, 4938, 304, 64, 46, 1, 192, 3, 449 { NULL, 75, 1600, 1200, 4938, 304, 64, 46, 1, 192, 3,
430 FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT, 450 FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
431 FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA }, 451 FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA },
432 /* 27 1600x1200-85 VESA */ 452 /* 27 1600x1200-85 VESA */
diff --git a/drivers/video/nuc900fb.c b/drivers/video/nuc900fb.c
index 81687ed26ba9..62498bd662fc 100644
--- a/drivers/video/nuc900fb.c
+++ b/drivers/video/nuc900fb.c
@@ -15,6 +15,7 @@
15 */ 15 */
16#include <linux/module.h> 16#include <linux/module.h>
17#include <linux/kernel.h> 17#include <linux/kernel.h>
18#include <linux/err.h>
18#include <linux/errno.h> 19#include <linux/errno.h>
19#include <linux/string.h> 20#include <linux/string.h>
20#include <linux/mm.h> 21#include <linux/mm.h>
@@ -597,9 +598,9 @@ static int __devinit nuc900fb_probe(struct platform_device *pdev)
597 } 598 }
598 599
599 fbi->clk = clk_get(&pdev->dev, NULL); 600 fbi->clk = clk_get(&pdev->dev, NULL);
600 if (!fbi->clk || IS_ERR(fbi->clk)) { 601 if (IS_ERR(fbi->clk)) {
601 printk(KERN_ERR "nuc900-lcd:failed to get lcd clock source\n"); 602 printk(KERN_ERR "nuc900-lcd:failed to get lcd clock source\n");
602 ret = -ENOENT; 603 ret = PTR_ERR(fbi->clk);
603 goto release_irq; 604 goto release_irq;
604 } 605 }
605 606
diff --git a/drivers/video/nvidia/nv_backlight.c b/drivers/video/nvidia/nv_backlight.c
index 2fb552a6f32c..6aac6d1b937b 100644
--- a/drivers/video/nvidia/nv_backlight.c
+++ b/drivers/video/nvidia/nv_backlight.c
@@ -87,7 +87,7 @@ static int nvidia_bl_get_brightness(struct backlight_device *bd)
87 return bd->props.brightness; 87 return bd->props.brightness;
88} 88}
89 89
90static struct backlight_ops nvidia_bl_ops = { 90static const struct backlight_ops nvidia_bl_ops = {
91 .get_brightness = nvidia_bl_get_brightness, 91 .get_brightness = nvidia_bl_get_brightness,
92 .update_status = nvidia_bl_update_status, 92 .update_status = nvidia_bl_update_status,
93}; 93};
diff --git a/drivers/video/omap2/displays/Kconfig b/drivers/video/omap2/displays/Kconfig
index 12327bbfdbbb..940cab394c2e 100644
--- a/drivers/video/omap2/displays/Kconfig
+++ b/drivers/video/omap2/displays/Kconfig
@@ -1,11 +1,13 @@
1menu "OMAP2/3 Display Device Drivers" 1menu "OMAP2/3 Display Device Drivers"
2 depends on OMAP2_DSS 2 depends on OMAP2_DSS
3 3
4config PANEL_GENERIC 4config PANEL_GENERIC_DPI
5 tristate "Generic Panel" 5 tristate "Generic DPI Panel"
6 help 6 help
7 Generic panel driver. 7 Generic DPI panel driver.
8 Used for DVI output for Beagle and OMAP3 SDP. 8 Supports DVI output for Beagle and OMAP3 SDP.
9 Supports LCD Panel used in TI SDP3430 and EVM boards,
10 OMAP3517 EVM boards and CM-T35.
9 11
10config PANEL_SHARP_LS037V7DW01 12config PANEL_SHARP_LS037V7DW01
11 tristate "Sharp LS037V7DW01 LCD Panel" 13 tristate "Sharp LS037V7DW01 LCD Panel"
@@ -14,11 +16,12 @@ config PANEL_SHARP_LS037V7DW01
14 help 16 help
15 LCD Panel used in TI's SDP3430 and EVM boards 17 LCD Panel used in TI's SDP3430 and EVM boards
16 18
17config PANEL_SHARP_LQ043T1DG01 19config PANEL_NEC_NL8048HL11_01B
18 tristate "Sharp LQ043T1DG01 LCD Panel" 20 tristate "NEC NL8048HL11-01B Panel"
19 depends on OMAP2_DSS 21 depends on OMAP2_DSS
20 help 22 help
21 LCD Panel used in TI's OMAP3517 EVM boards 23 This NEC NL8048HL11-01B panel is TFT LCD
24 used in the Zoom2/3/3630 sdp boards.
22 25
23config PANEL_TAAL 26config PANEL_TAAL
24 tristate "Taal DSI Panel" 27 tristate "Taal DSI Panel"
@@ -26,12 +29,6 @@ config PANEL_TAAL
26 help 29 help
27 Taal DSI command mode panel from TPO. 30 Taal DSI command mode panel from TPO.
28 31
29config PANEL_TOPPOLY_TDO35S
30 tristate "Toppoly TDO35S LCD Panel support"
31 depends on OMAP2_DSS
32 help
33 LCD Panel used in CM-T35
34
35config PANEL_TPO_TD043MTEA1 32config PANEL_TPO_TD043MTEA1
36 tristate "TPO TD043MTEA1 LCD Panel" 33 tristate "TPO TD043MTEA1 LCD Panel"
37 depends on OMAP2_DSS && SPI 34 depends on OMAP2_DSS && SPI
diff --git a/drivers/video/omap2/displays/Makefile b/drivers/video/omap2/displays/Makefile
index aa386095d7c4..861f0255ec6b 100644
--- a/drivers/video/omap2/displays/Makefile
+++ b/drivers/video/omap2/displays/Makefile
@@ -1,8 +1,7 @@
1obj-$(CONFIG_PANEL_GENERIC) += panel-generic.o 1obj-$(CONFIG_PANEL_GENERIC_DPI) += panel-generic-dpi.o
2obj-$(CONFIG_PANEL_SHARP_LS037V7DW01) += panel-sharp-ls037v7dw01.o 2obj-$(CONFIG_PANEL_SHARP_LS037V7DW01) += panel-sharp-ls037v7dw01.o
3obj-$(CONFIG_PANEL_SHARP_LQ043T1DG01) += panel-sharp-lq043t1dg01.o 3obj-$(CONFIG_PANEL_NEC_NL8048HL11_01B) += panel-nec-nl8048hl11-01b.o
4 4
5obj-$(CONFIG_PANEL_TAAL) += panel-taal.o 5obj-$(CONFIG_PANEL_TAAL) += panel-taal.o
6obj-$(CONFIG_PANEL_TOPPOLY_TDO35S) += panel-toppoly-tdo35s.o
7obj-$(CONFIG_PANEL_TPO_TD043MTEA1) += panel-tpo-td043mtea1.o 6obj-$(CONFIG_PANEL_TPO_TD043MTEA1) += panel-tpo-td043mtea1.o
8obj-$(CONFIG_PANEL_ACX565AKM) += panel-acx565akm.o 7obj-$(CONFIG_PANEL_ACX565AKM) += panel-acx565akm.o
diff --git a/drivers/video/omap2/displays/panel-generic-dpi.c b/drivers/video/omap2/displays/panel-generic-dpi.c
new file mode 100644
index 000000000000..07eb30ee59c8
--- /dev/null
+++ b/drivers/video/omap2/displays/panel-generic-dpi.c
@@ -0,0 +1,365 @@
1/*
2 * Generic DPI Panels support
3 *
4 * Copyright (C) 2010 Canonical Ltd.
5 * Author: Bryan Wu <bryan.wu@canonical.com>
6 *
7 * LCD panel driver for Sharp LQ043T1DG01
8 *
9 * Copyright (C) 2009 Texas Instruments Inc
10 * Author: Vaibhav Hiremath <hvaibhav@ti.com>
11 *
12 * LCD panel driver for Toppoly TDO35S
13 *
14 * Copyright (C) 2009 CompuLab, Ltd.
15 * Author: Mike Rapoport <mike@compulab.co.il>
16 *
17 * Copyright (C) 2008 Nokia Corporation
18 * Author: Tomi Valkeinen <tomi.valkeinen@nokia.com>
19 *
20 * This program is free software; you can redistribute it and/or modify it
21 * under the terms of the GNU General Public License version 2 as published by
22 * the Free Software Foundation.
23 *
24 * This program is distributed in the hope that it will be useful, but WITHOUT
25 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
26 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
27 * more details.
28 *
29 * You should have received a copy of the GNU General Public License along with
30 * this program. If not, see <http://www.gnu.org/licenses/>.
31 */
32
33#include <linux/module.h>
34#include <linux/delay.h>
35#include <linux/slab.h>
36
37#include <plat/panel-generic-dpi.h>
38
39struct panel_config {
40 struct omap_video_timings timings;
41
42 int acbi; /* ac-bias pin transitions per interrupt */
43 /* Unit: line clocks */
44 int acb; /* ac-bias pin frequency */
45
46 enum omap_panel_config config;
47
48 int power_on_delay;
49 int power_off_delay;
50
51 /*
52 * Used to match device to panel configuration
53 * when use generic panel driver
54 */
55 const char *name;
56};
57
58/* Panel configurations */
59static struct panel_config generic_dpi_panels[] = {
60 /* Generic Panel */
61 {
62 {
63 .x_res = 640,
64 .y_res = 480,
65
66 .pixel_clock = 23500,
67
68 .hfp = 48,
69 .hsw = 32,
70 .hbp = 80,
71
72 .vfp = 3,
73 .vsw = 4,
74 .vbp = 7,
75 },
76 .acbi = 0x0,
77 .acb = 0x0,
78 .config = OMAP_DSS_LCD_TFT,
79 .power_on_delay = 0,
80 .power_off_delay = 0,
81 .name = "generic",
82 },
83
84 /* Sharp LQ043T1DG01 */
85 {
86 {
87 .x_res = 480,
88 .y_res = 272,
89
90 .pixel_clock = 9000,
91
92 .hsw = 42,
93 .hfp = 3,
94 .hbp = 2,
95
96 .vsw = 11,
97 .vfp = 3,
98 .vbp = 2,
99 },
100 .acbi = 0x0,
101 .acb = 0x0,
102 .config = OMAP_DSS_LCD_TFT | OMAP_DSS_LCD_IVS |
103 OMAP_DSS_LCD_IHS | OMAP_DSS_LCD_IEO,
104 .power_on_delay = 50,
105 .power_off_delay = 100,
106 .name = "sharp_lq",
107 },
108
109 /* Sharp LS037V7DW01 */
110 {
111 {
112 .x_res = 480,
113 .y_res = 640,
114
115 .pixel_clock = 19200,
116
117 .hsw = 2,
118 .hfp = 1,
119 .hbp = 28,
120
121 .vsw = 1,
122 .vfp = 1,
123 .vbp = 1,
124 },
125 .acbi = 0x0,
126 .acb = 0x28,
127 .config = OMAP_DSS_LCD_TFT | OMAP_DSS_LCD_IVS |
128 OMAP_DSS_LCD_IHS,
129 .power_on_delay = 50,
130 .power_off_delay = 100,
131 .name = "sharp_ls",
132 },
133
134 /* Toppoly TDO35S */
135 {
136 {
137 .x_res = 480,
138 .y_res = 640,
139
140 .pixel_clock = 26000,
141
142 .hfp = 104,
143 .hsw = 8,
144 .hbp = 8,
145
146 .vfp = 4,
147 .vsw = 2,
148 .vbp = 2,
149 },
150 .acbi = 0x0,
151 .acb = 0x0,
152 .config = OMAP_DSS_LCD_TFT | OMAP_DSS_LCD_IVS |
153 OMAP_DSS_LCD_IHS | OMAP_DSS_LCD_IPC |
154 OMAP_DSS_LCD_ONOFF,
155 .power_on_delay = 0,
156 .power_off_delay = 0,
157 .name = "toppoly_tdo35s",
158 },
159};
160
161struct panel_drv_data {
162
163 struct omap_dss_device *dssdev;
164
165 struct panel_config *panel_config;
166};
167
168static inline struct panel_generic_dpi_data
169*get_panel_data(const struct omap_dss_device *dssdev)
170{
171 return (struct panel_generic_dpi_data *) dssdev->data;
172}
173
174static int generic_dpi_panel_power_on(struct omap_dss_device *dssdev)
175{
176 int r;
177 struct panel_generic_dpi_data *panel_data = get_panel_data(dssdev);
178 struct panel_drv_data *drv_data = dev_get_drvdata(&dssdev->dev);
179 struct panel_config *panel_config = drv_data->panel_config;
180
181 if (dssdev->state == OMAP_DSS_DISPLAY_ACTIVE)
182 return 0;
183
184 r = omapdss_dpi_display_enable(dssdev);
185 if (r)
186 goto err0;
187
188 /* wait couple of vsyncs until enabling the LCD */
189 if (panel_config->power_on_delay)
190 msleep(panel_config->power_on_delay);
191
192 if (panel_data->platform_enable) {
193 r = panel_data->platform_enable(dssdev);
194 if (r)
195 goto err1;
196 }
197
198 return 0;
199err1:
200 omapdss_dpi_display_disable(dssdev);
201err0:
202 return r;
203}
204
205static void generic_dpi_panel_power_off(struct omap_dss_device *dssdev)
206{
207 struct panel_generic_dpi_data *panel_data = get_panel_data(dssdev);
208 struct panel_drv_data *drv_data = dev_get_drvdata(&dssdev->dev);
209 struct panel_config *panel_config = drv_data->panel_config;
210
211 if (dssdev->state != OMAP_DSS_DISPLAY_ACTIVE)
212 return;
213
214 if (panel_data->platform_disable)
215 panel_data->platform_disable(dssdev);
216
217 /* wait couple of vsyncs after disabling the LCD */
218 if (panel_config->power_off_delay)
219 msleep(panel_config->power_off_delay);
220
221 omapdss_dpi_display_disable(dssdev);
222}
223
224static int generic_dpi_panel_probe(struct omap_dss_device *dssdev)
225{
226 struct panel_generic_dpi_data *panel_data = get_panel_data(dssdev);
227 struct panel_config *panel_config = NULL;
228 struct panel_drv_data *drv_data = NULL;
229 int i;
230
231 dev_dbg(&dssdev->dev, "probe\n");
232
233 if (!panel_data || !panel_data->name)
234 return -EINVAL;
235
236 for (i = 0; i < ARRAY_SIZE(generic_dpi_panels); i++) {
237 if (strcmp(panel_data->name, generic_dpi_panels[i].name) == 0) {
238 panel_config = &generic_dpi_panels[i];
239 break;
240 }
241 }
242
243 if (!panel_config)
244 return -EINVAL;
245
246 dssdev->panel.config = panel_config->config;
247 dssdev->panel.timings = panel_config->timings;
248 dssdev->panel.acb = panel_config->acb;
249 dssdev->panel.acbi = panel_config->acbi;
250
251 drv_data = kzalloc(sizeof(*drv_data), GFP_KERNEL);
252 if (!drv_data)
253 return -ENOMEM;
254
255 drv_data->dssdev = dssdev;
256 drv_data->panel_config = panel_config;
257
258 dev_set_drvdata(&dssdev->dev, drv_data);
259
260 return 0;
261}
262
263static void generic_dpi_panel_remove(struct omap_dss_device *dssdev)
264{
265 struct panel_drv_data *drv_data = dev_get_drvdata(&dssdev->dev);
266
267 dev_dbg(&dssdev->dev, "remove\n");
268
269 kfree(drv_data);
270
271 dev_set_drvdata(&dssdev->dev, NULL);
272}
273
274static int generic_dpi_panel_enable(struct omap_dss_device *dssdev)
275{
276 int r = 0;
277
278 r = generic_dpi_panel_power_on(dssdev);
279 if (r)
280 return r;
281
282 dssdev->state = OMAP_DSS_DISPLAY_ACTIVE;
283
284 return 0;
285}
286
287static void generic_dpi_panel_disable(struct omap_dss_device *dssdev)
288{
289 generic_dpi_panel_power_off(dssdev);
290
291 dssdev->state = OMAP_DSS_DISPLAY_DISABLED;
292}
293
294static int generic_dpi_panel_suspend(struct omap_dss_device *dssdev)
295{
296 generic_dpi_panel_power_off(dssdev);
297
298 dssdev->state = OMAP_DSS_DISPLAY_SUSPENDED;
299
300 return 0;
301}
302
303static int generic_dpi_panel_resume(struct omap_dss_device *dssdev)
304{
305 int r = 0;
306
307 r = generic_dpi_panel_power_on(dssdev);
308 if (r)
309 return r;
310
311 dssdev->state = OMAP_DSS_DISPLAY_ACTIVE;
312
313 return 0;
314}
315
316static void generic_dpi_panel_set_timings(struct omap_dss_device *dssdev,
317 struct omap_video_timings *timings)
318{
319 dpi_set_timings(dssdev, timings);
320}
321
322static void generic_dpi_panel_get_timings(struct omap_dss_device *dssdev,
323 struct omap_video_timings *timings)
324{
325 *timings = dssdev->panel.timings;
326}
327
328static int generic_dpi_panel_check_timings(struct omap_dss_device *dssdev,
329 struct omap_video_timings *timings)
330{
331 return dpi_check_timings(dssdev, timings);
332}
333
334static struct omap_dss_driver dpi_driver = {
335 .probe = generic_dpi_panel_probe,
336 .remove = generic_dpi_panel_remove,
337
338 .enable = generic_dpi_panel_enable,
339 .disable = generic_dpi_panel_disable,
340 .suspend = generic_dpi_panel_suspend,
341 .resume = generic_dpi_panel_resume,
342
343 .set_timings = generic_dpi_panel_set_timings,
344 .get_timings = generic_dpi_panel_get_timings,
345 .check_timings = generic_dpi_panel_check_timings,
346
347 .driver = {
348 .name = "generic_dpi_panel",
349 .owner = THIS_MODULE,
350 },
351};
352
353static int __init generic_dpi_panel_drv_init(void)
354{
355 return omap_dss_register_driver(&dpi_driver);
356}
357
358static void __exit generic_dpi_panel_drv_exit(void)
359{
360 omap_dss_unregister_driver(&dpi_driver);
361}
362
363module_init(generic_dpi_panel_drv_init);
364module_exit(generic_dpi_panel_drv_exit);
365MODULE_LICENSE("GPL");
diff --git a/drivers/video/omap2/displays/panel-generic.c b/drivers/video/omap2/displays/panel-generic.c
deleted file mode 100644
index 395a68de3990..000000000000
--- a/drivers/video/omap2/displays/panel-generic.c
+++ /dev/null
@@ -1,174 +0,0 @@
1/*
2 * Generic panel support
3 *
4 * Copyright (C) 2008 Nokia Corporation
5 * Author: Tomi Valkeinen <tomi.valkeinen@nokia.com>
6 *
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License version 2 as published by
9 * the Free Software Foundation.
10 *
11 * This program is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 * more details.
15 *
16 * You should have received a copy of the GNU General Public License along with
17 * this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#include <linux/module.h>
21#include <linux/delay.h>
22
23#include <plat/display.h>
24
25static struct omap_video_timings generic_panel_timings = {
26 /* 640 x 480 @ 60 Hz Reduced blanking VESA CVT 0.31M3-R */
27 .x_res = 640,
28 .y_res = 480,
29 .pixel_clock = 23500,
30 .hfp = 48,
31 .hsw = 32,
32 .hbp = 80,
33 .vfp = 3,
34 .vsw = 4,
35 .vbp = 7,
36};
37
38static int generic_panel_power_on(struct omap_dss_device *dssdev)
39{
40 int r;
41
42 if (dssdev->state == OMAP_DSS_DISPLAY_ACTIVE)
43 return 0;
44
45 r = omapdss_dpi_display_enable(dssdev);
46 if (r)
47 goto err0;
48
49 if (dssdev->platform_enable) {
50 r = dssdev->platform_enable(dssdev);
51 if (r)
52 goto err1;
53 }
54
55 return 0;
56err1:
57 omapdss_dpi_display_disable(dssdev);
58err0:
59 return r;
60}
61
62static void generic_panel_power_off(struct omap_dss_device *dssdev)
63{
64 if (dssdev->state != OMAP_DSS_DISPLAY_ACTIVE)
65 return;
66
67 if (dssdev->platform_disable)
68 dssdev->platform_disable(dssdev);
69
70 omapdss_dpi_display_disable(dssdev);
71}
72
73static int generic_panel_probe(struct omap_dss_device *dssdev)
74{
75 dssdev->panel.config = OMAP_DSS_LCD_TFT;
76 dssdev->panel.timings = generic_panel_timings;
77
78 return 0;
79}
80
81static void generic_panel_remove(struct omap_dss_device *dssdev)
82{
83}
84
85static int generic_panel_enable(struct omap_dss_device *dssdev)
86{
87 int r = 0;
88
89 r = generic_panel_power_on(dssdev);
90 if (r)
91 return r;
92
93 dssdev->state = OMAP_DSS_DISPLAY_ACTIVE;
94
95 return 0;
96}
97
98static void generic_panel_disable(struct omap_dss_device *dssdev)
99{
100 generic_panel_power_off(dssdev);
101
102 dssdev->state = OMAP_DSS_DISPLAY_DISABLED;
103}
104
105static int generic_panel_suspend(struct omap_dss_device *dssdev)
106{
107 generic_panel_power_off(dssdev);
108 dssdev->state = OMAP_DSS_DISPLAY_SUSPENDED;
109 return 0;
110}
111
112static int generic_panel_resume(struct omap_dss_device *dssdev)
113{
114 int r = 0;
115
116 r = generic_panel_power_on(dssdev);
117 if (r)
118 return r;
119
120 dssdev->state = OMAP_DSS_DISPLAY_ACTIVE;
121
122 return 0;
123}
124
125static void generic_panel_set_timings(struct omap_dss_device *dssdev,
126 struct omap_video_timings *timings)
127{
128 dpi_set_timings(dssdev, timings);
129}
130
131static void generic_panel_get_timings(struct omap_dss_device *dssdev,
132 struct omap_video_timings *timings)
133{
134 *timings = dssdev->panel.timings;
135}
136
137static int generic_panel_check_timings(struct omap_dss_device *dssdev,
138 struct omap_video_timings *timings)
139{
140 return dpi_check_timings(dssdev, timings);
141}
142
143static struct omap_dss_driver generic_driver = {
144 .probe = generic_panel_probe,
145 .remove = generic_panel_remove,
146
147 .enable = generic_panel_enable,
148 .disable = generic_panel_disable,
149 .suspend = generic_panel_suspend,
150 .resume = generic_panel_resume,
151
152 .set_timings = generic_panel_set_timings,
153 .get_timings = generic_panel_get_timings,
154 .check_timings = generic_panel_check_timings,
155
156 .driver = {
157 .name = "generic_panel",
158 .owner = THIS_MODULE,
159 },
160};
161
162static int __init generic_panel_drv_init(void)
163{
164 return omap_dss_register_driver(&generic_driver);
165}
166
167static void __exit generic_panel_drv_exit(void)
168{
169 omap_dss_unregister_driver(&generic_driver);
170}
171
172module_init(generic_panel_drv_init);
173module_exit(generic_panel_drv_exit);
174MODULE_LICENSE("GPL");
diff --git a/drivers/video/omap2/displays/panel-nec-nl8048hl11-01b.c b/drivers/video/omap2/displays/panel-nec-nl8048hl11-01b.c
new file mode 100644
index 000000000000..925e0fadff54
--- /dev/null
+++ b/drivers/video/omap2/displays/panel-nec-nl8048hl11-01b.c
@@ -0,0 +1,325 @@
1/*
2 * Support for NEC-nl8048hl11-01b panel driver
3 *
4 * Copyright (C) 2010 Texas Instruments Inc.
5 * Author: Erik Gilling <konkers@android.com>
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License version 2 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 with
16 * this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19#include <linux/module.h>
20#include <linux/delay.h>
21#include <linux/spi/spi.h>
22#include <linux/backlight.h>
23#include <linux/fb.h>
24
25#include <plat/display.h>
26
27#define LCD_XRES 800
28#define LCD_YRES 480
29/*
30 * NEC PIX Clock Ratings
31 * MIN:21.8MHz TYP:23.8MHz MAX:25.7MHz
32 */
33#define LCD_PIXEL_CLOCK 23800
34
35struct nec_8048_data {
36 struct backlight_device *bl;
37};
38
39static const struct {
40 unsigned char addr;
41 unsigned char dat;
42} nec_8048_init_seq[] = {
43 { 3, 0x01 }, { 0, 0x00 }, { 1, 0x01 }, { 4, 0x00 }, { 5, 0x14 },
44 { 6, 0x24 }, { 16, 0xD7 }, { 17, 0x00 }, { 18, 0x00 }, { 19, 0x55 },
45 { 20, 0x01 }, { 21, 0x70 }, { 22, 0x1E }, { 23, 0x25 }, { 24, 0x25 },
46 { 25, 0x02 }, { 26, 0x02 }, { 27, 0xA0 }, { 32, 0x2F }, { 33, 0x0F },
47 { 34, 0x0F }, { 35, 0x0F }, { 36, 0x0F }, { 37, 0x0F }, { 38, 0x0F },
48 { 39, 0x00 }, { 40, 0x02 }, { 41, 0x02 }, { 42, 0x02 }, { 43, 0x0F },
49 { 44, 0x0F }, { 45, 0x0F }, { 46, 0x0F }, { 47, 0x0F }, { 48, 0x0F },
50 { 49, 0x0F }, { 50, 0x00 }, { 51, 0x02 }, { 52, 0x02 }, { 53, 0x02 },
51 { 80, 0x0C }, { 83, 0x42 }, { 84, 0x42 }, { 85, 0x41 }, { 86, 0x14 },
52 { 89, 0x88 }, { 90, 0x01 }, { 91, 0x00 }, { 92, 0x02 }, { 93, 0x0C },
53 { 94, 0x1C }, { 95, 0x27 }, { 98, 0x49 }, { 99, 0x27 }, { 102, 0x76 },
54 { 103, 0x27 }, { 112, 0x01 }, { 113, 0x0E }, { 114, 0x02 },
55 { 115, 0x0C }, { 118, 0x0C }, { 121, 0x30 }, { 130, 0x00 },
56 { 131, 0x00 }, { 132, 0xFC }, { 134, 0x00 }, { 136, 0x00 },
57 { 138, 0x00 }, { 139, 0x00 }, { 140, 0x00 }, { 141, 0xFC },
58 { 143, 0x00 }, { 145, 0x00 }, { 147, 0x00 }, { 148, 0x00 },
59 { 149, 0x00 }, { 150, 0xFC }, { 152, 0x00 }, { 154, 0x00 },
60 { 156, 0x00 }, { 157, 0x00 }, { 2, 0x00 },
61};
62
63/*
64 * NEC NL8048HL11-01B Manual
65 * defines HFB, HSW, HBP, VFP, VSW, VBP as shown below
66 */
67
68static struct omap_video_timings nec_8048_panel_timings = {
69 /* 800 x 480 @ 60 Hz Reduced blanking VESA CVT 0.31M3-R */
70 .x_res = LCD_XRES,
71 .y_res = LCD_YRES,
72 .pixel_clock = LCD_PIXEL_CLOCK,
73 .hfp = 6,
74 .hsw = 1,
75 .hbp = 4,
76 .vfp = 3,
77 .vsw = 1,
78 .vbp = 4,
79};
80
81static int nec_8048_bl_update_status(struct backlight_device *bl)
82{
83 struct omap_dss_device *dssdev = dev_get_drvdata(&bl->dev);
84 int level;
85
86 if (!dssdev->set_backlight)
87 return -EINVAL;
88
89 if (bl->props.fb_blank == FB_BLANK_UNBLANK &&
90 bl->props.power == FB_BLANK_UNBLANK)
91 level = bl->props.brightness;
92 else
93 level = 0;
94
95 return dssdev->set_backlight(dssdev, level);
96}
97
98static int nec_8048_bl_get_brightness(struct backlight_device *bl)
99{
100 if (bl->props.fb_blank == FB_BLANK_UNBLANK &&
101 bl->props.power == FB_BLANK_UNBLANK)
102 return bl->props.brightness;
103
104 return 0;
105}
106
107static const struct backlight_ops nec_8048_bl_ops = {
108 .get_brightness = nec_8048_bl_get_brightness,
109 .update_status = nec_8048_bl_update_status,
110};
111
112static int nec_8048_panel_probe(struct omap_dss_device *dssdev)
113{
114 struct backlight_device *bl;
115 struct nec_8048_data *necd;
116 struct backlight_properties props;
117 int r;
118
119 dssdev->panel.config = OMAP_DSS_LCD_TFT | OMAP_DSS_LCD_IVS |
120 OMAP_DSS_LCD_IHS | OMAP_DSS_LCD_RF |
121 OMAP_DSS_LCD_ONOFF;
122 dssdev->panel.timings = nec_8048_panel_timings;
123
124 necd = kzalloc(sizeof(*necd), GFP_KERNEL);
125 if (!necd)
126 return -ENOMEM;
127
128 dev_set_drvdata(&dssdev->dev, necd);
129
130 memset(&props, 0, sizeof(struct backlight_properties));
131 props.max_brightness = 255;
132
133 bl = backlight_device_register("nec-8048", &dssdev->dev, dssdev,
134 &nec_8048_bl_ops, &props);
135 if (IS_ERR(bl)) {
136 r = PTR_ERR(bl);
137 kfree(necd);
138 return r;
139 }
140 necd->bl = bl;
141
142 bl->props.fb_blank = FB_BLANK_UNBLANK;
143 bl->props.power = FB_BLANK_UNBLANK;
144 bl->props.max_brightness = dssdev->max_backlight_level;
145 bl->props.brightness = dssdev->max_backlight_level;
146
147 r = nec_8048_bl_update_status(bl);
148 if (r < 0)
149 dev_err(&dssdev->dev, "failed to set lcd brightness\n");
150
151 return 0;
152}
153
154static void nec_8048_panel_remove(struct omap_dss_device *dssdev)
155{
156 struct nec_8048_data *necd = dev_get_drvdata(&dssdev->dev);
157 struct backlight_device *bl = necd->bl;
158
159 bl->props.power = FB_BLANK_POWERDOWN;
160 nec_8048_bl_update_status(bl);
161 backlight_device_unregister(bl);
162
163 kfree(necd);
164}
165
166static int nec_8048_panel_enable(struct omap_dss_device *dssdev)
167{
168 int r = 0;
169 struct nec_8048_data *necd = dev_get_drvdata(&dssdev->dev);
170 struct backlight_device *bl = necd->bl;
171
172 if (dssdev->platform_enable) {
173 r = dssdev->platform_enable(dssdev);
174 if (r)
175 return r;
176 }
177
178 r = nec_8048_bl_update_status(bl);
179 if (r < 0)
180 dev_err(&dssdev->dev, "failed to set lcd brightness\n");
181
182 r = omapdss_dpi_display_enable(dssdev);
183
184 return r;
185}
186
187static void nec_8048_panel_disable(struct omap_dss_device *dssdev)
188{
189 struct nec_8048_data *necd = dev_get_drvdata(&dssdev->dev);
190 struct backlight_device *bl = necd->bl;
191
192 omapdss_dpi_display_disable(dssdev);
193
194 bl->props.brightness = 0;
195 nec_8048_bl_update_status(bl);
196
197 if (dssdev->platform_disable)
198 dssdev->platform_disable(dssdev);
199}
200
201static int nec_8048_panel_suspend(struct omap_dss_device *dssdev)
202{
203 nec_8048_panel_disable(dssdev);
204 return 0;
205}
206
207static int nec_8048_panel_resume(struct omap_dss_device *dssdev)
208{
209 return nec_8048_panel_enable(dssdev);
210}
211
212static int nec_8048_recommended_bpp(struct omap_dss_device *dssdev)
213{
214 return 16;
215}
216
217static struct omap_dss_driver nec_8048_driver = {
218 .probe = nec_8048_panel_probe,
219 .remove = nec_8048_panel_remove,
220 .enable = nec_8048_panel_enable,
221 .disable = nec_8048_panel_disable,
222 .suspend = nec_8048_panel_suspend,
223 .resume = nec_8048_panel_resume,
224 .get_recommended_bpp = nec_8048_recommended_bpp,
225
226 .driver = {
227 .name = "NEC_8048_panel",
228 .owner = THIS_MODULE,
229 },
230};
231
232static int nec_8048_spi_send(struct spi_device *spi, unsigned char reg_addr,
233 unsigned char reg_data)
234{
235 int ret = 0;
236 unsigned int cmd = 0, data = 0;
237
238 cmd = 0x0000 | reg_addr; /* register address write */
239 data = 0x0100 | reg_data ; /* register data write */
240 data = (cmd << 16) | data;
241
242 ret = spi_write(spi, (unsigned char *)&data, 4);
243 if (ret)
244 pr_err("error in spi_write %x\n", data);
245
246 return ret;
247}
248
249static int init_nec_8048_wvga_lcd(struct spi_device *spi)
250{
251 unsigned int i;
252 /* Initialization Sequence */
253 /* nec_8048_spi_send(spi, REG, VAL) */
254 for (i = 0; i < (ARRAY_SIZE(nec_8048_init_seq) - 1); i++)
255 nec_8048_spi_send(spi, nec_8048_init_seq[i].addr,
256 nec_8048_init_seq[i].dat);
257 udelay(20);
258 nec_8048_spi_send(spi, nec_8048_init_seq[i].addr,
259 nec_8048_init_seq[i].dat);
260 return 0;
261}
262
263static int nec_8048_spi_probe(struct spi_device *spi)
264{
265 spi->mode = SPI_MODE_0;
266 spi->bits_per_word = 32;
267 spi_setup(spi);
268
269 init_nec_8048_wvga_lcd(spi);
270
271 return omap_dss_register_driver(&nec_8048_driver);
272}
273
274static int nec_8048_spi_remove(struct spi_device *spi)
275{
276 omap_dss_unregister_driver(&nec_8048_driver);
277
278 return 0;
279}
280
281static int nec_8048_spi_suspend(struct spi_device *spi, pm_message_t mesg)
282{
283 nec_8048_spi_send(spi, 2, 0x01);
284 mdelay(40);
285
286 return 0;
287}
288
289static int nec_8048_spi_resume(struct spi_device *spi)
290{
291 /* reinitialize the panel */
292 spi_setup(spi);
293 nec_8048_spi_send(spi, 2, 0x00);
294 init_nec_8048_wvga_lcd(spi);
295
296 return 0;
297}
298
299static struct spi_driver nec_8048_spi_driver = {
300 .probe = nec_8048_spi_probe,
301 .remove = __devexit_p(nec_8048_spi_remove),
302 .suspend = nec_8048_spi_suspend,
303 .resume = nec_8048_spi_resume,
304 .driver = {
305 .name = "nec_8048_spi",
306 .bus = &spi_bus_type,
307 .owner = THIS_MODULE,
308 },
309};
310
311static int __init nec_8048_lcd_init(void)
312{
313 return spi_register_driver(&nec_8048_spi_driver);
314}
315
316static void __exit nec_8048_lcd_exit(void)
317{
318 return spi_unregister_driver(&nec_8048_spi_driver);
319}
320
321module_init(nec_8048_lcd_init);
322module_exit(nec_8048_lcd_exit);
323MODULE_AUTHOR("Erik Gilling <konkers@android.com>");
324MODULE_DESCRIPTION("NEC-nl8048hl11-01b Driver");
325MODULE_LICENSE("GPL");
diff --git a/drivers/video/omap2/displays/panel-sharp-lq043t1dg01.c b/drivers/video/omap2/displays/panel-sharp-lq043t1dg01.c
deleted file mode 100644
index 0c6896cea2d0..000000000000
--- a/drivers/video/omap2/displays/panel-sharp-lq043t1dg01.c
+++ /dev/null
@@ -1,165 +0,0 @@
1/*
2 * LCD panel driver for Sharp LQ043T1DG01
3 *
4 * Copyright (C) 2009 Texas Instruments Inc
5 * Author: Vaibhav Hiremath <hvaibhav@ti.com>
6 *
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License version 2 as published by
9 * the Free Software Foundation.
10 *
11 * This program is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 * more details.
15 *
16 * You should have received a copy of the GNU General Public License along with
17 * this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#include <linux/module.h>
21#include <linux/delay.h>
22#include <linux/device.h>
23#include <linux/err.h>
24
25#include <plat/display.h>
26
27static struct omap_video_timings sharp_lq_timings = {
28 .x_res = 480,
29 .y_res = 272,
30
31 .pixel_clock = 9000,
32
33 .hsw = 42,
34 .hfp = 3,
35 .hbp = 2,
36
37 .vsw = 11,
38 .vfp = 3,
39 .vbp = 2,
40};
41
42static int sharp_lq_panel_power_on(struct omap_dss_device *dssdev)
43{
44 int r;
45
46 if (dssdev->state == OMAP_DSS_DISPLAY_ACTIVE)
47 return 0;
48
49 r = omapdss_dpi_display_enable(dssdev);
50 if (r)
51 goto err0;
52
53 /* wait couple of vsyncs until enabling the LCD */
54 msleep(50);
55
56 if (dssdev->platform_enable) {
57 r = dssdev->platform_enable(dssdev);
58 if (r)
59 goto err1;
60 }
61
62 return 0;
63err1:
64 omapdss_dpi_display_disable(dssdev);
65err0:
66 return r;
67}
68
69static void sharp_lq_panel_power_off(struct omap_dss_device *dssdev)
70{
71 if (dssdev->state != OMAP_DSS_DISPLAY_ACTIVE)
72 return;
73
74 if (dssdev->platform_disable)
75 dssdev->platform_disable(dssdev);
76
77 /* wait at least 5 vsyncs after disabling the LCD */
78 msleep(100);
79
80 omapdss_dpi_display_disable(dssdev);
81}
82
83static int sharp_lq_panel_probe(struct omap_dss_device *dssdev)
84{
85
86 dssdev->panel.config = OMAP_DSS_LCD_TFT | OMAP_DSS_LCD_IVS |
87 OMAP_DSS_LCD_IHS | OMAP_DSS_LCD_IEO;
88 dssdev->panel.acb = 0x0;
89 dssdev->panel.timings = sharp_lq_timings;
90
91 return 0;
92}
93
94static void sharp_lq_panel_remove(struct omap_dss_device *dssdev)
95{
96}
97
98static int sharp_lq_panel_enable(struct omap_dss_device *dssdev)
99{
100 int r = 0;
101
102 r = sharp_lq_panel_power_on(dssdev);
103 if (r)
104 return r;
105
106 dssdev->state = OMAP_DSS_DISPLAY_ACTIVE;
107
108 return 0;
109}
110
111static void sharp_lq_panel_disable(struct omap_dss_device *dssdev)
112{
113 sharp_lq_panel_power_off(dssdev);
114
115 dssdev->state = OMAP_DSS_DISPLAY_DISABLED;
116}
117
118static int sharp_lq_panel_suspend(struct omap_dss_device *dssdev)
119{
120 sharp_lq_panel_power_off(dssdev);
121 dssdev->state = OMAP_DSS_DISPLAY_SUSPENDED;
122 return 0;
123}
124
125static int sharp_lq_panel_resume(struct omap_dss_device *dssdev)
126{
127 int r = 0;
128
129 r = sharp_lq_panel_power_on(dssdev);
130 if (r)
131 return r;
132
133 dssdev->state = OMAP_DSS_DISPLAY_ACTIVE;
134
135 return 0;
136}
137
138static struct omap_dss_driver sharp_lq_driver = {
139 .probe = sharp_lq_panel_probe,
140 .remove = sharp_lq_panel_remove,
141
142 .enable = sharp_lq_panel_enable,
143 .disable = sharp_lq_panel_disable,
144 .suspend = sharp_lq_panel_suspend,
145 .resume = sharp_lq_panel_resume,
146
147 .driver = {
148 .name = "sharp_lq_panel",
149 .owner = THIS_MODULE,
150 },
151};
152
153static int __init sharp_lq_panel_drv_init(void)
154{
155 return omap_dss_register_driver(&sharp_lq_driver);
156}
157
158static void __exit sharp_lq_panel_drv_exit(void)
159{
160 omap_dss_unregister_driver(&sharp_lq_driver);
161}
162
163module_init(sharp_lq_panel_drv_init);
164module_exit(sharp_lq_panel_drv_exit);
165MODULE_LICENSE("GPL");
diff --git a/drivers/video/omap2/displays/panel-taal.c b/drivers/video/omap2/displays/panel-taal.c
index e1c765d11419..61026f96ad20 100644
--- a/drivers/video/omap2/displays/panel-taal.c
+++ b/drivers/video/omap2/displays/panel-taal.c
@@ -465,7 +465,7 @@ static int taal_bl_get_intensity(struct backlight_device *dev)
465 return 0; 465 return 0;
466} 466}
467 467
468static struct backlight_ops taal_bl_ops = { 468static const struct backlight_ops taal_bl_ops = {
469 .get_brightness = taal_bl_get_intensity, 469 .get_brightness = taal_bl_get_intensity,
470 .update_status = taal_bl_update_status, 470 .update_status = taal_bl_update_status,
471}; 471};
diff --git a/drivers/video/omap2/displays/panel-toppoly-tdo35s.c b/drivers/video/omap2/displays/panel-toppoly-tdo35s.c
deleted file mode 100644
index 526e906c8a6c..000000000000
--- a/drivers/video/omap2/displays/panel-toppoly-tdo35s.c
+++ /dev/null
@@ -1,164 +0,0 @@
1/*
2 * LCD panel driver for Toppoly TDO35S
3 *
4 * Copyright (C) 2009 CompuLab, Ltd.
5 * Author: Mike Rapoport <mike@compulab.co.il>
6 *
7 * Based on generic panel support
8 * Copyright (C) 2008 Nokia Corporation
9 * Author: Tomi Valkeinen <tomi.valkeinen@nokia.com>
10 *
11 * This program is free software; you can redistribute it and/or modify it
12 * under the terms of the GNU General Public License version 2 as published by
13 * the Free Software Foundation.
14 *
15 * This program is distributed in the hope that it will be useful, but WITHOUT
16 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
17 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
18 * more details.
19 *
20 * You should have received a copy of the GNU General Public License along with
21 * this program. If not, see <http://www.gnu.org/licenses/>.
22 */
23
24#include <linux/module.h>
25#include <linux/delay.h>
26
27#include <plat/display.h>
28
29static struct omap_video_timings toppoly_tdo_panel_timings = {
30 /* 640 x 480 @ 60 Hz Reduced blanking VESA CVT 0.31M3-R */
31 .x_res = 480,
32 .y_res = 640,
33
34 .pixel_clock = 26000,
35
36 .hfp = 104,
37 .hsw = 8,
38 .hbp = 8,
39
40 .vfp = 4,
41 .vsw = 2,
42 .vbp = 2,
43};
44
45static int toppoly_tdo_panel_power_on(struct omap_dss_device *dssdev)
46{
47 int r;
48
49 if (dssdev->state == OMAP_DSS_DISPLAY_ACTIVE)
50 return 0;
51
52 r = omapdss_dpi_display_enable(dssdev);
53 if (r)
54 goto err0;
55
56 if (dssdev->platform_enable) {
57 r = dssdev->platform_enable(dssdev);
58 if (r)
59 goto err1;
60 }
61
62 return 0;
63err1:
64 omapdss_dpi_display_disable(dssdev);
65err0:
66 return r;
67}
68
69static void toppoly_tdo_panel_power_off(struct omap_dss_device *dssdev)
70{
71 if (dssdev->state != OMAP_DSS_DISPLAY_ACTIVE)
72 return;
73
74 if (dssdev->platform_disable)
75 dssdev->platform_disable(dssdev);
76
77 omapdss_dpi_display_disable(dssdev);
78}
79
80static int toppoly_tdo_panel_probe(struct omap_dss_device *dssdev)
81{
82 dssdev->panel.config = OMAP_DSS_LCD_TFT |
83 OMAP_DSS_LCD_IVS |
84 OMAP_DSS_LCD_IHS |
85 OMAP_DSS_LCD_IPC |
86 OMAP_DSS_LCD_ONOFF;
87
88 dssdev->panel.timings = toppoly_tdo_panel_timings;
89
90 return 0;
91}
92
93static void toppoly_tdo_panel_remove(struct omap_dss_device *dssdev)
94{
95}
96
97static int toppoly_tdo_panel_enable(struct omap_dss_device *dssdev)
98{
99 int r = 0;
100
101 r = toppoly_tdo_panel_power_on(dssdev);
102 if (r)
103 return r;
104
105 dssdev->state = OMAP_DSS_DISPLAY_ACTIVE;
106
107 return 0;
108}
109
110static void toppoly_tdo_panel_disable(struct omap_dss_device *dssdev)
111{
112 toppoly_tdo_panel_power_off(dssdev);
113
114 dssdev->state = OMAP_DSS_DISPLAY_DISABLED;
115}
116
117static int toppoly_tdo_panel_suspend(struct omap_dss_device *dssdev)
118{
119 toppoly_tdo_panel_power_off(dssdev);
120 dssdev->state = OMAP_DSS_DISPLAY_SUSPENDED;
121 return 0;
122}
123
124static int toppoly_tdo_panel_resume(struct omap_dss_device *dssdev)
125{
126 int r = 0;
127
128 r = toppoly_tdo_panel_power_on(dssdev);
129 if (r)
130 return r;
131
132 dssdev->state = OMAP_DSS_DISPLAY_ACTIVE;
133
134 return 0;
135}
136
137static struct omap_dss_driver generic_driver = {
138 .probe = toppoly_tdo_panel_probe,
139 .remove = toppoly_tdo_panel_remove,
140
141 .enable = toppoly_tdo_panel_enable,
142 .disable = toppoly_tdo_panel_disable,
143 .suspend = toppoly_tdo_panel_suspend,
144 .resume = toppoly_tdo_panel_resume,
145
146 .driver = {
147 .name = "toppoly_tdo35s_panel",
148 .owner = THIS_MODULE,
149 },
150};
151
152static int __init toppoly_tdo_panel_drv_init(void)
153{
154 return omap_dss_register_driver(&generic_driver);
155}
156
157static void __exit toppoly_tdo_panel_drv_exit(void)
158{
159 omap_dss_unregister_driver(&generic_driver);
160}
161
162module_init(toppoly_tdo_panel_drv_init);
163module_exit(toppoly_tdo_panel_drv_exit);
164MODULE_LICENSE("GPL");
diff --git a/drivers/video/omap2/dss/dispc.c b/drivers/video/omap2/dss/dispc.c
index fa40fa59a9ac..9f8c69f16e61 100644
--- a/drivers/video/omap2/dss/dispc.c
+++ b/drivers/video/omap2/dss/dispc.c
@@ -44,34 +44,40 @@
44/* DISPC */ 44/* DISPC */
45#define DISPC_BASE 0x48050400 45#define DISPC_BASE 0x48050400
46 46
47#define DISPC_SZ_REGS SZ_1K 47#define DISPC_SZ_REGS SZ_4K
48 48
49struct dispc_reg { u16 idx; }; 49struct dispc_reg { u16 idx; };
50 50
51#define DISPC_REG(idx) ((const struct dispc_reg) { idx }) 51#define DISPC_REG(idx) ((const struct dispc_reg) { idx })
52 52
53/* DISPC common */ 53/*
54 * DISPC common registers and
55 * DISPC channel registers , ch = 0 for LCD, ch = 1 for
56 * DIGIT, and ch = 2 for LCD2
57 */
54#define DISPC_REVISION DISPC_REG(0x0000) 58#define DISPC_REVISION DISPC_REG(0x0000)
55#define DISPC_SYSCONFIG DISPC_REG(0x0010) 59#define DISPC_SYSCONFIG DISPC_REG(0x0010)
56#define DISPC_SYSSTATUS DISPC_REG(0x0014) 60#define DISPC_SYSSTATUS DISPC_REG(0x0014)
57#define DISPC_IRQSTATUS DISPC_REG(0x0018) 61#define DISPC_IRQSTATUS DISPC_REG(0x0018)
58#define DISPC_IRQENABLE DISPC_REG(0x001C) 62#define DISPC_IRQENABLE DISPC_REG(0x001C)
59#define DISPC_CONTROL DISPC_REG(0x0040) 63#define DISPC_CONTROL DISPC_REG(0x0040)
64#define DISPC_CONTROL2 DISPC_REG(0x0238)
60#define DISPC_CONFIG DISPC_REG(0x0044) 65#define DISPC_CONFIG DISPC_REG(0x0044)
66#define DISPC_CONFIG2 DISPC_REG(0x0620)
61#define DISPC_CAPABLE DISPC_REG(0x0048) 67#define DISPC_CAPABLE DISPC_REG(0x0048)
62#define DISPC_DEFAULT_COLOR0 DISPC_REG(0x004C) 68#define DISPC_DEFAULT_COLOR(ch) DISPC_REG(ch == 0 ? 0x004C : \
63#define DISPC_DEFAULT_COLOR1 DISPC_REG(0x0050) 69 (ch == 1 ? 0x0050 : 0x03AC))
64#define DISPC_TRANS_COLOR0 DISPC_REG(0x0054) 70#define DISPC_TRANS_COLOR(ch) DISPC_REG(ch == 0 ? 0x0054 : \
65#define DISPC_TRANS_COLOR1 DISPC_REG(0x0058) 71 (ch == 1 ? 0x0058 : 0x03B0))
66#define DISPC_LINE_STATUS DISPC_REG(0x005C) 72#define DISPC_LINE_STATUS DISPC_REG(0x005C)
67#define DISPC_LINE_NUMBER DISPC_REG(0x0060) 73#define DISPC_LINE_NUMBER DISPC_REG(0x0060)
68#define DISPC_TIMING_H DISPC_REG(0x0064) 74#define DISPC_TIMING_H(ch) DISPC_REG(ch != 2 ? 0x0064 : 0x0400)
69#define DISPC_TIMING_V DISPC_REG(0x0068) 75#define DISPC_TIMING_V(ch) DISPC_REG(ch != 2 ? 0x0068 : 0x0404)
70#define DISPC_POL_FREQ DISPC_REG(0x006C) 76#define DISPC_POL_FREQ(ch) DISPC_REG(ch != 2 ? 0x006C : 0x0408)
71#define DISPC_DIVISOR DISPC_REG(0x0070) 77#define DISPC_DIVISOR(ch) DISPC_REG(ch != 2 ? 0x0070 : 0x040C)
72#define DISPC_GLOBAL_ALPHA DISPC_REG(0x0074) 78#define DISPC_GLOBAL_ALPHA DISPC_REG(0x0074)
73#define DISPC_SIZE_DIG DISPC_REG(0x0078) 79#define DISPC_SIZE_DIG DISPC_REG(0x0078)
74#define DISPC_SIZE_LCD DISPC_REG(0x007C) 80#define DISPC_SIZE_LCD(ch) DISPC_REG(ch != 2 ? 0x007C : 0x03CC)
75 81
76/* DISPC GFX plane */ 82/* DISPC GFX plane */
77#define DISPC_GFX_BA0 DISPC_REG(0x0080) 83#define DISPC_GFX_BA0 DISPC_REG(0x0080)
@@ -86,13 +92,12 @@ struct dispc_reg { u16 idx; };
86#define DISPC_GFX_WINDOW_SKIP DISPC_REG(0x00B4) 92#define DISPC_GFX_WINDOW_SKIP DISPC_REG(0x00B4)
87#define DISPC_GFX_TABLE_BA DISPC_REG(0x00B8) 93#define DISPC_GFX_TABLE_BA DISPC_REG(0x00B8)
88 94
89#define DISPC_DATA_CYCLE1 DISPC_REG(0x01D4) 95#define DISPC_DATA_CYCLE1(ch) DISPC_REG(ch != 2 ? 0x01D4 : 0x03C0)
90#define DISPC_DATA_CYCLE2 DISPC_REG(0x01D8) 96#define DISPC_DATA_CYCLE2(ch) DISPC_REG(ch != 2 ? 0x01D8 : 0x03C4)
91#define DISPC_DATA_CYCLE3 DISPC_REG(0x01DC) 97#define DISPC_DATA_CYCLE3(ch) DISPC_REG(ch != 2 ? 0x01DC : 0x03C8)
92 98#define DISPC_CPR_COEF_R(ch) DISPC_REG(ch != 2 ? 0x0220 : 0x03BC)
93#define DISPC_CPR_COEF_R DISPC_REG(0x0220) 99#define DISPC_CPR_COEF_G(ch) DISPC_REG(ch != 2 ? 0x0224 : 0x03B8)
94#define DISPC_CPR_COEF_G DISPC_REG(0x0224) 100#define DISPC_CPR_COEF_B(ch) DISPC_REG(ch != 2 ? 0x0228 : 0x03B4)
95#define DISPC_CPR_COEF_B DISPC_REG(0x0228)
96 101
97#define DISPC_GFX_PRELOAD DISPC_REG(0x022C) 102#define DISPC_GFX_PRELOAD DISPC_REG(0x022C)
98 103
@@ -217,18 +222,29 @@ void dispc_save_context(void)
217 SR(IRQENABLE); 222 SR(IRQENABLE);
218 SR(CONTROL); 223 SR(CONTROL);
219 SR(CONFIG); 224 SR(CONFIG);
220 SR(DEFAULT_COLOR0); 225 SR(DEFAULT_COLOR(0));
221 SR(DEFAULT_COLOR1); 226 SR(DEFAULT_COLOR(1));
222 SR(TRANS_COLOR0); 227 SR(TRANS_COLOR(0));
223 SR(TRANS_COLOR1); 228 SR(TRANS_COLOR(1));
224 SR(LINE_NUMBER); 229 SR(LINE_NUMBER);
225 SR(TIMING_H); 230 SR(TIMING_H(0));
226 SR(TIMING_V); 231 SR(TIMING_V(0));
227 SR(POL_FREQ); 232 SR(POL_FREQ(0));
228 SR(DIVISOR); 233 SR(DIVISOR(0));
229 SR(GLOBAL_ALPHA); 234 SR(GLOBAL_ALPHA);
230 SR(SIZE_DIG); 235 SR(SIZE_DIG);
231 SR(SIZE_LCD); 236 SR(SIZE_LCD(0));
237 if (dss_has_feature(FEAT_MGR_LCD2)) {
238 SR(CONTROL2);
239 SR(DEFAULT_COLOR(2));
240 SR(TRANS_COLOR(2));
241 SR(SIZE_LCD(2));
242 SR(TIMING_H(2));
243 SR(TIMING_V(2));
244 SR(POL_FREQ(2));
245 SR(DIVISOR(2));
246 SR(CONFIG2);
247 }
232 248
233 SR(GFX_BA0); 249 SR(GFX_BA0);
234 SR(GFX_BA1); 250 SR(GFX_BA1);
@@ -241,13 +257,22 @@ void dispc_save_context(void)
241 SR(GFX_WINDOW_SKIP); 257 SR(GFX_WINDOW_SKIP);
242 SR(GFX_TABLE_BA); 258 SR(GFX_TABLE_BA);
243 259
244 SR(DATA_CYCLE1); 260 SR(DATA_CYCLE1(0));
245 SR(DATA_CYCLE2); 261 SR(DATA_CYCLE2(0));
246 SR(DATA_CYCLE3); 262 SR(DATA_CYCLE3(0));
247 263
248 SR(CPR_COEF_R); 264 SR(CPR_COEF_R(0));
249 SR(CPR_COEF_G); 265 SR(CPR_COEF_G(0));
250 SR(CPR_COEF_B); 266 SR(CPR_COEF_B(0));
267 if (dss_has_feature(FEAT_MGR_LCD2)) {
268 SR(CPR_COEF_B(2));
269 SR(CPR_COEF_G(2));
270 SR(CPR_COEF_R(2));
271
272 SR(DATA_CYCLE1(2));
273 SR(DATA_CYCLE2(2));
274 SR(DATA_CYCLE3(2));
275 }
251 276
252 SR(GFX_PRELOAD); 277 SR(GFX_PRELOAD);
253 278
@@ -356,18 +381,28 @@ void dispc_restore_context(void)
356 /*RR(IRQENABLE);*/ 381 /*RR(IRQENABLE);*/
357 /*RR(CONTROL);*/ 382 /*RR(CONTROL);*/
358 RR(CONFIG); 383 RR(CONFIG);
359 RR(DEFAULT_COLOR0); 384 RR(DEFAULT_COLOR(0));
360 RR(DEFAULT_COLOR1); 385 RR(DEFAULT_COLOR(1));
361 RR(TRANS_COLOR0); 386 RR(TRANS_COLOR(0));
362 RR(TRANS_COLOR1); 387 RR(TRANS_COLOR(1));
363 RR(LINE_NUMBER); 388 RR(LINE_NUMBER);
364 RR(TIMING_H); 389 RR(TIMING_H(0));
365 RR(TIMING_V); 390 RR(TIMING_V(0));
366 RR(POL_FREQ); 391 RR(POL_FREQ(0));
367 RR(DIVISOR); 392 RR(DIVISOR(0));
368 RR(GLOBAL_ALPHA); 393 RR(GLOBAL_ALPHA);
369 RR(SIZE_DIG); 394 RR(SIZE_DIG);
370 RR(SIZE_LCD); 395 RR(SIZE_LCD(0));
396 if (dss_has_feature(FEAT_MGR_LCD2)) {
397 RR(DEFAULT_COLOR(2));
398 RR(TRANS_COLOR(2));
399 RR(SIZE_LCD(2));
400 RR(TIMING_H(2));
401 RR(TIMING_V(2));
402 RR(POL_FREQ(2));
403 RR(DIVISOR(2));
404 RR(CONFIG2);
405 }
371 406
372 RR(GFX_BA0); 407 RR(GFX_BA0);
373 RR(GFX_BA1); 408 RR(GFX_BA1);
@@ -380,13 +415,22 @@ void dispc_restore_context(void)
380 RR(GFX_WINDOW_SKIP); 415 RR(GFX_WINDOW_SKIP);
381 RR(GFX_TABLE_BA); 416 RR(GFX_TABLE_BA);
382 417
383 RR(DATA_CYCLE1); 418 RR(DATA_CYCLE1(0));
384 RR(DATA_CYCLE2); 419 RR(DATA_CYCLE2(0));
385 RR(DATA_CYCLE3); 420 RR(DATA_CYCLE3(0));
386 421
387 RR(CPR_COEF_R); 422 RR(CPR_COEF_R(0));
388 RR(CPR_COEF_G); 423 RR(CPR_COEF_G(0));
389 RR(CPR_COEF_B); 424 RR(CPR_COEF_B(0));
425 if (dss_has_feature(FEAT_MGR_LCD2)) {
426 RR(DATA_CYCLE1(2));
427 RR(DATA_CYCLE2(2));
428 RR(DATA_CYCLE3(2));
429
430 RR(CPR_COEF_B(2));
431 RR(CPR_COEF_G(2));
432 RR(CPR_COEF_R(2));
433 }
390 434
391 RR(GFX_PRELOAD); 435 RR(GFX_PRELOAD);
392 436
@@ -490,7 +534,8 @@ void dispc_restore_context(void)
490 534
491 /* enable last, because LCD & DIGIT enable are here */ 535 /* enable last, because LCD & DIGIT enable are here */
492 RR(CONTROL); 536 RR(CONTROL);
493 537 if (dss_has_feature(FEAT_MGR_LCD2))
538 RR(CONTROL2);
494 /* clear spurious SYNC_LOST_DIGIT interrupts */ 539 /* clear spurious SYNC_LOST_DIGIT interrupts */
495 dispc_write_reg(DISPC_IRQSTATUS, DISPC_IRQ_SYNC_LOST_DIGIT); 540 dispc_write_reg(DISPC_IRQSTATUS, DISPC_IRQ_SYNC_LOST_DIGIT);
496 541
@@ -516,42 +561,63 @@ bool dispc_go_busy(enum omap_channel channel)
516{ 561{
517 int bit; 562 int bit;
518 563
519 if (channel == OMAP_DSS_CHANNEL_LCD) 564 if (channel == OMAP_DSS_CHANNEL_LCD ||
565 channel == OMAP_DSS_CHANNEL_LCD2)
520 bit = 5; /* GOLCD */ 566 bit = 5; /* GOLCD */
521 else 567 else
522 bit = 6; /* GODIGIT */ 568 bit = 6; /* GODIGIT */
523 569
524 return REG_GET(DISPC_CONTROL, bit, bit) == 1; 570 if (channel == OMAP_DSS_CHANNEL_LCD2)
571 return REG_GET(DISPC_CONTROL2, bit, bit) == 1;
572 else
573 return REG_GET(DISPC_CONTROL, bit, bit) == 1;
525} 574}
526 575
527void dispc_go(enum omap_channel channel) 576void dispc_go(enum omap_channel channel)
528{ 577{
529 int bit; 578 int bit;
579 bool enable_bit, go_bit;
530 580
531 enable_clocks(1); 581 enable_clocks(1);
532 582
533 if (channel == OMAP_DSS_CHANNEL_LCD) 583 if (channel == OMAP_DSS_CHANNEL_LCD ||
584 channel == OMAP_DSS_CHANNEL_LCD2)
534 bit = 0; /* LCDENABLE */ 585 bit = 0; /* LCDENABLE */
535 else 586 else
536 bit = 1; /* DIGITALENABLE */ 587 bit = 1; /* DIGITALENABLE */
537 588
538 /* if the channel is not enabled, we don't need GO */ 589 /* if the channel is not enabled, we don't need GO */
539 if (REG_GET(DISPC_CONTROL, bit, bit) == 0) 590 if (channel == OMAP_DSS_CHANNEL_LCD2)
591 enable_bit = REG_GET(DISPC_CONTROL2, bit, bit) == 1;
592 else
593 enable_bit = REG_GET(DISPC_CONTROL, bit, bit) == 1;
594
595 if (!enable_bit)
540 goto end; 596 goto end;
541 597
542 if (channel == OMAP_DSS_CHANNEL_LCD) 598 if (channel == OMAP_DSS_CHANNEL_LCD ||
599 channel == OMAP_DSS_CHANNEL_LCD2)
543 bit = 5; /* GOLCD */ 600 bit = 5; /* GOLCD */
544 else 601 else
545 bit = 6; /* GODIGIT */ 602 bit = 6; /* GODIGIT */
546 603
547 if (REG_GET(DISPC_CONTROL, bit, bit) == 1) { 604 if (channel == OMAP_DSS_CHANNEL_LCD2)
605 go_bit = REG_GET(DISPC_CONTROL2, bit, bit) == 1;
606 else
607 go_bit = REG_GET(DISPC_CONTROL, bit, bit) == 1;
608
609 if (go_bit) {
548 DSSERR("GO bit not down for channel %d\n", channel); 610 DSSERR("GO bit not down for channel %d\n", channel);
549 goto end; 611 goto end;
550 } 612 }
551 613
552 DSSDBG("GO %s\n", channel == OMAP_DSS_CHANNEL_LCD ? "LCD" : "DIGIT"); 614 DSSDBG("GO %s\n", channel == OMAP_DSS_CHANNEL_LCD ? "LCD" :
615 (channel == OMAP_DSS_CHANNEL_LCD2 ? "LCD2" : "DIGIT"));
553 616
554 REG_FLD_MOD(DISPC_CONTROL, 1, bit, bit); 617 if (channel == OMAP_DSS_CHANNEL_LCD2)
618 REG_FLD_MOD(DISPC_CONTROL2, 1, bit, bit);
619 else
620 REG_FLD_MOD(DISPC_CONTROL, 1, bit, bit);
555end: 621end:
556 enable_clocks(0); 622 enable_clocks(0);
557} 623}
@@ -773,13 +839,26 @@ static void _dispc_set_vid_size(enum omap_plane plane, int width, int height)
773 dispc_write_reg(vsi_reg[plane-1], val); 839 dispc_write_reg(vsi_reg[plane-1], val);
774} 840}
775 841
842static void _dispc_set_pre_mult_alpha(enum omap_plane plane, bool enable)
843{
844 if (!dss_has_feature(FEAT_PRE_MULT_ALPHA))
845 return;
846
847 if (!dss_has_feature(FEAT_GLOBAL_ALPHA_VID1) &&
848 plane == OMAP_DSS_VIDEO1)
849 return;
850
851 REG_FLD_MOD(dispc_reg_att[plane], enable ? 1 : 0, 28, 28);
852}
853
776static void _dispc_setup_global_alpha(enum omap_plane plane, u8 global_alpha) 854static void _dispc_setup_global_alpha(enum omap_plane plane, u8 global_alpha)
777{ 855{
778 if (!dss_has_feature(FEAT_GLOBAL_ALPHA)) 856 if (!dss_has_feature(FEAT_GLOBAL_ALPHA))
779 return; 857 return;
780 858
781 BUG_ON(!dss_has_feature(FEAT_GLOBAL_ALPHA_VID1) && 859 if (!dss_has_feature(FEAT_GLOBAL_ALPHA_VID1) &&
782 plane == OMAP_DSS_VIDEO1); 860 plane == OMAP_DSS_VIDEO1)
861 return;
783 862
784 if (plane == OMAP_DSS_GFX) 863 if (plane == OMAP_DSS_GFX)
785 REG_FLD_MOD(DISPC_GLOBAL_ALPHA, global_alpha, 7, 0); 864 REG_FLD_MOD(DISPC_GLOBAL_ALPHA, global_alpha, 7, 0);
@@ -851,6 +930,7 @@ static void _dispc_set_channel_out(enum omap_plane plane,
851{ 930{
852 int shift; 931 int shift;
853 u32 val; 932 u32 val;
933 int chan = 0, chan2 = 0;
854 934
855 switch (plane) { 935 switch (plane) {
856 case OMAP_DSS_GFX: 936 case OMAP_DSS_GFX:
@@ -866,7 +946,29 @@ static void _dispc_set_channel_out(enum omap_plane plane,
866 } 946 }
867 947
868 val = dispc_read_reg(dispc_reg_att[plane]); 948 val = dispc_read_reg(dispc_reg_att[plane]);
869 val = FLD_MOD(val, channel, shift, shift); 949 if (dss_has_feature(FEAT_MGR_LCD2)) {
950 switch (channel) {
951 case OMAP_DSS_CHANNEL_LCD:
952 chan = 0;
953 chan2 = 0;
954 break;
955 case OMAP_DSS_CHANNEL_DIGIT:
956 chan = 1;
957 chan2 = 0;
958 break;
959 case OMAP_DSS_CHANNEL_LCD2:
960 chan = 0;
961 chan2 = 1;
962 break;
963 default:
964 BUG();
965 }
966
967 val = FLD_MOD(val, chan, shift, shift);
968 val = FLD_MOD(val, chan2, 31, 30);
969 } else {
970 val = FLD_MOD(val, channel, shift, shift);
971 }
870 dispc_write_reg(dispc_reg_att[plane], val); 972 dispc_write_reg(dispc_reg_att[plane], val);
871} 973}
872 974
@@ -923,13 +1025,13 @@ void dispc_enable_replication(enum omap_plane plane, bool enable)
923 enable_clocks(0); 1025 enable_clocks(0);
924} 1026}
925 1027
926void dispc_set_lcd_size(u16 width, u16 height) 1028void dispc_set_lcd_size(enum omap_channel channel, u16 width, u16 height)
927{ 1029{
928 u32 val; 1030 u32 val;
929 BUG_ON((width > (1 << 11)) || (height > (1 << 11))); 1031 BUG_ON((width > (1 << 11)) || (height > (1 << 11)));
930 val = FLD_VAL(height - 1, 26, 16) | FLD_VAL(width - 1, 10, 0); 1032 val = FLD_VAL(height - 1, 26, 16) | FLD_VAL(width - 1, 10, 0);
931 enable_clocks(1); 1033 enable_clocks(1);
932 dispc_write_reg(DISPC_SIZE_LCD, val); 1034 dispc_write_reg(DISPC_SIZE_LCD(channel), val);
933 enable_clocks(0); 1035 enable_clocks(0);
934} 1036}
935 1037
@@ -1426,12 +1528,13 @@ static void calc_dma_rotation_offset(u8 rotation, bool mirror,
1426 } 1528 }
1427} 1529}
1428 1530
1429static unsigned long calc_fclk_five_taps(u16 width, u16 height, 1531static unsigned long calc_fclk_five_taps(enum omap_channel channel, u16 width,
1430 u16 out_width, u16 out_height, enum omap_color_mode color_mode) 1532 u16 height, u16 out_width, u16 out_height,
1533 enum omap_color_mode color_mode)
1431{ 1534{
1432 u32 fclk = 0; 1535 u32 fclk = 0;
1433 /* FIXME venc pclk? */ 1536 /* FIXME venc pclk? */
1434 u64 tmp, pclk = dispc_pclk_rate(); 1537 u64 tmp, pclk = dispc_pclk_rate(channel);
1435 1538
1436 if (height > out_height) { 1539 if (height > out_height) {
1437 /* FIXME get real display PPL */ 1540 /* FIXME get real display PPL */
@@ -1463,8 +1566,8 @@ static unsigned long calc_fclk_five_taps(u16 width, u16 height,
1463 return fclk; 1566 return fclk;
1464} 1567}
1465 1568
1466static unsigned long calc_fclk(u16 width, u16 height, 1569static unsigned long calc_fclk(enum omap_channel channel, u16 width,
1467 u16 out_width, u16 out_height) 1570 u16 height, u16 out_width, u16 out_height)
1468{ 1571{
1469 unsigned int hf, vf; 1572 unsigned int hf, vf;
1470 1573
@@ -1488,7 +1591,7 @@ static unsigned long calc_fclk(u16 width, u16 height,
1488 vf = 1; 1591 vf = 1;
1489 1592
1490 /* FIXME venc pclk? */ 1593 /* FIXME venc pclk? */
1491 return dispc_pclk_rate() * vf * hf; 1594 return dispc_pclk_rate(channel) * vf * hf;
1492} 1595}
1493 1596
1494void dispc_set_channel_out(enum omap_plane plane, enum omap_channel channel_out) 1597void dispc_set_channel_out(enum omap_plane plane, enum omap_channel channel_out)
@@ -1507,7 +1610,8 @@ static int _dispc_setup_plane(enum omap_plane plane,
1507 bool ilace, 1610 bool ilace,
1508 enum omap_dss_rotation_type rotation_type, 1611 enum omap_dss_rotation_type rotation_type,
1509 u8 rotation, int mirror, 1612 u8 rotation, int mirror,
1510 u8 global_alpha) 1613 u8 global_alpha, u8 pre_mult_alpha,
1614 enum omap_channel channel)
1511{ 1615{
1512 const int maxdownscale = cpu_is_omap34xx() ? 4 : 2; 1616 const int maxdownscale = cpu_is_omap34xx() ? 4 : 2;
1513 bool five_taps = 0; 1617 bool five_taps = 0;
@@ -1536,29 +1640,12 @@ static int _dispc_setup_plane(enum omap_plane plane,
1536 height, pos_y, out_height); 1640 height, pos_y, out_height);
1537 } 1641 }
1538 1642
1643 if (!dss_feat_color_mode_supported(plane, color_mode))
1644 return -EINVAL;
1645
1539 if (plane == OMAP_DSS_GFX) { 1646 if (plane == OMAP_DSS_GFX) {
1540 if (width != out_width || height != out_height) 1647 if (width != out_width || height != out_height)
1541 return -EINVAL; 1648 return -EINVAL;
1542
1543 switch (color_mode) {
1544 case OMAP_DSS_COLOR_ARGB16:
1545 case OMAP_DSS_COLOR_ARGB32:
1546 case OMAP_DSS_COLOR_RGBA32:
1547 if (!dss_has_feature(FEAT_GLOBAL_ALPHA))
1548 return -EINVAL;
1549 case OMAP_DSS_COLOR_RGBX32:
1550 if (cpu_is_omap24xx())
1551 return -EINVAL;
1552 /* fall through */
1553 case OMAP_DSS_COLOR_RGB12U:
1554 case OMAP_DSS_COLOR_RGB16:
1555 case OMAP_DSS_COLOR_RGB24P:
1556 case OMAP_DSS_COLOR_RGB24U:
1557 break;
1558
1559 default:
1560 return -EINVAL;
1561 }
1562 } else { 1649 } else {
1563 /* video plane */ 1650 /* video plane */
1564 1651
@@ -1572,42 +1659,16 @@ static int _dispc_setup_plane(enum omap_plane plane,
1572 out_height > height * 8) 1659 out_height > height * 8)
1573 return -EINVAL; 1660 return -EINVAL;
1574 1661
1575 switch (color_mode) { 1662 if (color_mode == OMAP_DSS_COLOR_YUV2 ||
1576 case OMAP_DSS_COLOR_RGBX32: 1663 color_mode == OMAP_DSS_COLOR_UYVY)
1577 case OMAP_DSS_COLOR_RGB12U:
1578 if (cpu_is_omap24xx())
1579 return -EINVAL;
1580 /* fall through */
1581 case OMAP_DSS_COLOR_RGB16:
1582 case OMAP_DSS_COLOR_RGB24P:
1583 case OMAP_DSS_COLOR_RGB24U:
1584 break;
1585
1586 case OMAP_DSS_COLOR_ARGB16:
1587 case OMAP_DSS_COLOR_ARGB32:
1588 case OMAP_DSS_COLOR_RGBA32:
1589 if (!dss_has_feature(FEAT_GLOBAL_ALPHA))
1590 return -EINVAL;
1591 if (!dss_has_feature(FEAT_GLOBAL_ALPHA_VID1) &&
1592 plane == OMAP_DSS_VIDEO1)
1593 return -EINVAL;
1594 break;
1595
1596 case OMAP_DSS_COLOR_YUV2:
1597 case OMAP_DSS_COLOR_UYVY:
1598 cconv = 1; 1664 cconv = 1;
1599 break;
1600
1601 default:
1602 return -EINVAL;
1603 }
1604 1665
1605 /* Must use 5-tap filter? */ 1666 /* Must use 5-tap filter? */
1606 five_taps = height > out_height * 2; 1667 five_taps = height > out_height * 2;
1607 1668
1608 if (!five_taps) { 1669 if (!five_taps) {
1609 fclk = calc_fclk(width, height, 1670 fclk = calc_fclk(channel, width, height, out_width,
1610 out_width, out_height); 1671 out_height);
1611 1672
1612 /* Try 5-tap filter if 3-tap fclk is too high */ 1673 /* Try 5-tap filter if 3-tap fclk is too high */
1613 if (cpu_is_omap34xx() && height > out_height && 1674 if (cpu_is_omap34xx() && height > out_height &&
@@ -1621,7 +1682,7 @@ static int _dispc_setup_plane(enum omap_plane plane,
1621 } 1682 }
1622 1683
1623 if (five_taps) 1684 if (five_taps)
1624 fclk = calc_fclk_five_taps(width, height, 1685 fclk = calc_fclk_five_taps(channel, width, height,
1625 out_width, out_height, color_mode); 1686 out_width, out_height, color_mode);
1626 1687
1627 DSSDBG("required fclk rate = %lu Hz\n", fclk); 1688 DSSDBG("required fclk rate = %lu Hz\n", fclk);
@@ -1693,8 +1754,8 @@ static int _dispc_setup_plane(enum omap_plane plane,
1693 1754
1694 _dispc_set_rotation_attrs(plane, rotation, mirror, color_mode); 1755 _dispc_set_rotation_attrs(plane, rotation, mirror, color_mode);
1695 1756
1696 if (plane != OMAP_DSS_VIDEO1) 1757 _dispc_set_pre_mult_alpha(plane, pre_mult_alpha);
1697 _dispc_setup_global_alpha(plane, global_alpha); 1758 _dispc_setup_global_alpha(plane, global_alpha);
1698 1759
1699 return 0; 1760 return 0;
1700} 1761}
@@ -1710,36 +1771,44 @@ static void dispc_disable_isr(void *data, u32 mask)
1710 complete(compl); 1771 complete(compl);
1711} 1772}
1712 1773
1713static void _enable_lcd_out(bool enable) 1774static void _enable_lcd_out(enum omap_channel channel, bool enable)
1714{ 1775{
1715 REG_FLD_MOD(DISPC_CONTROL, enable ? 1 : 0, 0, 0); 1776 if (channel == OMAP_DSS_CHANNEL_LCD2)
1777 REG_FLD_MOD(DISPC_CONTROL2, enable ? 1 : 0, 0, 0);
1778 else
1779 REG_FLD_MOD(DISPC_CONTROL, enable ? 1 : 0, 0, 0);
1716} 1780}
1717 1781
1718static void dispc_enable_lcd_out(bool enable) 1782static void dispc_enable_lcd_out(enum omap_channel channel, bool enable)
1719{ 1783{
1720 struct completion frame_done_completion; 1784 struct completion frame_done_completion;
1721 bool is_on; 1785 bool is_on;
1722 int r; 1786 int r;
1787 u32 irq;
1723 1788
1724 enable_clocks(1); 1789 enable_clocks(1);
1725 1790
1726 /* When we disable LCD output, we need to wait until frame is done. 1791 /* When we disable LCD output, we need to wait until frame is done.
1727 * Otherwise the DSS is still working, and turning off the clocks 1792 * Otherwise the DSS is still working, and turning off the clocks
1728 * prevents DSS from going to OFF mode */ 1793 * prevents DSS from going to OFF mode */
1729 is_on = REG_GET(DISPC_CONTROL, 0, 0); 1794 is_on = channel == OMAP_DSS_CHANNEL_LCD2 ?
1795 REG_GET(DISPC_CONTROL2, 0, 0) :
1796 REG_GET(DISPC_CONTROL, 0, 0);
1797
1798 irq = channel == OMAP_DSS_CHANNEL_LCD2 ? DISPC_IRQ_FRAMEDONE2 :
1799 DISPC_IRQ_FRAMEDONE;
1730 1800
1731 if (!enable && is_on) { 1801 if (!enable && is_on) {
1732 init_completion(&frame_done_completion); 1802 init_completion(&frame_done_completion);
1733 1803
1734 r = omap_dispc_register_isr(dispc_disable_isr, 1804 r = omap_dispc_register_isr(dispc_disable_isr,
1735 &frame_done_completion, 1805 &frame_done_completion, irq);
1736 DISPC_IRQ_FRAMEDONE);
1737 1806
1738 if (r) 1807 if (r)
1739 DSSERR("failed to register FRAMEDONE isr\n"); 1808 DSSERR("failed to register FRAMEDONE isr\n");
1740 } 1809 }
1741 1810
1742 _enable_lcd_out(enable); 1811 _enable_lcd_out(channel, enable);
1743 1812
1744 if (!enable && is_on) { 1813 if (!enable && is_on) {
1745 if (!wait_for_completion_timeout(&frame_done_completion, 1814 if (!wait_for_completion_timeout(&frame_done_completion,
@@ -1747,8 +1816,7 @@ static void dispc_enable_lcd_out(bool enable)
1747 DSSERR("timeout waiting for FRAME DONE\n"); 1816 DSSERR("timeout waiting for FRAME DONE\n");
1748 1817
1749 r = omap_dispc_unregister_isr(dispc_disable_isr, 1818 r = omap_dispc_unregister_isr(dispc_disable_isr,
1750 &frame_done_completion, 1819 &frame_done_completion, irq);
1751 DISPC_IRQ_FRAMEDONE);
1752 1820
1753 if (r) 1821 if (r)
1754 DSSERR("failed to unregister FRAMEDONE isr\n"); 1822 DSSERR("failed to unregister FRAMEDONE isr\n");
@@ -1818,6 +1886,8 @@ static void dispc_enable_digit_out(bool enable)
1818 unsigned long flags; 1886 unsigned long flags;
1819 spin_lock_irqsave(&dispc.irq_lock, flags); 1887 spin_lock_irqsave(&dispc.irq_lock, flags);
1820 dispc.irq_error_mask = DISPC_IRQ_MASK_ERROR; 1888 dispc.irq_error_mask = DISPC_IRQ_MASK_ERROR;
1889 if (dss_has_feature(FEAT_MGR_LCD2))
1890 dispc.irq_error_mask |= DISPC_IRQ_SYNC_LOST2;
1821 dispc_write_reg(DISPC_IRQSTATUS, DISPC_IRQ_SYNC_LOST_DIGIT); 1891 dispc_write_reg(DISPC_IRQSTATUS, DISPC_IRQ_SYNC_LOST_DIGIT);
1822 _omap_dispc_set_irqs(); 1892 _omap_dispc_set_irqs();
1823 spin_unlock_irqrestore(&dispc.irq_lock, flags); 1893 spin_unlock_irqrestore(&dispc.irq_lock, flags);
@@ -1832,14 +1902,17 @@ bool dispc_is_channel_enabled(enum omap_channel channel)
1832 return !!REG_GET(DISPC_CONTROL, 0, 0); 1902 return !!REG_GET(DISPC_CONTROL, 0, 0);
1833 else if (channel == OMAP_DSS_CHANNEL_DIGIT) 1903 else if (channel == OMAP_DSS_CHANNEL_DIGIT)
1834 return !!REG_GET(DISPC_CONTROL, 1, 1); 1904 return !!REG_GET(DISPC_CONTROL, 1, 1);
1905 else if (channel == OMAP_DSS_CHANNEL_LCD2)
1906 return !!REG_GET(DISPC_CONTROL2, 0, 0);
1835 else 1907 else
1836 BUG(); 1908 BUG();
1837} 1909}
1838 1910
1839void dispc_enable_channel(enum omap_channel channel, bool enable) 1911void dispc_enable_channel(enum omap_channel channel, bool enable)
1840{ 1912{
1841 if (channel == OMAP_DSS_CHANNEL_LCD) 1913 if (channel == OMAP_DSS_CHANNEL_LCD ||
1842 dispc_enable_lcd_out(enable); 1914 channel == OMAP_DSS_CHANNEL_LCD2)
1915 dispc_enable_lcd_out(channel, enable);
1843 else if (channel == OMAP_DSS_CHANNEL_DIGIT) 1916 else if (channel == OMAP_DSS_CHANNEL_DIGIT)
1844 dispc_enable_digit_out(enable); 1917 dispc_enable_digit_out(enable);
1845 else 1918 else
@@ -1848,6 +1921,9 @@ void dispc_enable_channel(enum omap_channel channel, bool enable)
1848 1921
1849void dispc_lcd_enable_signal_polarity(bool act_high) 1922void dispc_lcd_enable_signal_polarity(bool act_high)
1850{ 1923{
1924 if (!dss_has_feature(FEAT_LCDENABLEPOL))
1925 return;
1926
1851 enable_clocks(1); 1927 enable_clocks(1);
1852 REG_FLD_MOD(DISPC_CONTROL, act_high ? 1 : 0, 29, 29); 1928 REG_FLD_MOD(DISPC_CONTROL, act_high ? 1 : 0, 29, 29);
1853 enable_clocks(0); 1929 enable_clocks(0);
@@ -1855,6 +1931,9 @@ void dispc_lcd_enable_signal_polarity(bool act_high)
1855 1931
1856void dispc_lcd_enable_signal(bool enable) 1932void dispc_lcd_enable_signal(bool enable)
1857{ 1933{
1934 if (!dss_has_feature(FEAT_LCDENABLESIGNAL))
1935 return;
1936
1858 enable_clocks(1); 1937 enable_clocks(1);
1859 REG_FLD_MOD(DISPC_CONTROL, enable ? 1 : 0, 28, 28); 1938 REG_FLD_MOD(DISPC_CONTROL, enable ? 1 : 0, 28, 28);
1860 enable_clocks(0); 1939 enable_clocks(0);
@@ -1862,20 +1941,27 @@ void dispc_lcd_enable_signal(bool enable)
1862 1941
1863void dispc_pck_free_enable(bool enable) 1942void dispc_pck_free_enable(bool enable)
1864{ 1943{
1944 if (!dss_has_feature(FEAT_PCKFREEENABLE))
1945 return;
1946
1865 enable_clocks(1); 1947 enable_clocks(1);
1866 REG_FLD_MOD(DISPC_CONTROL, enable ? 1 : 0, 27, 27); 1948 REG_FLD_MOD(DISPC_CONTROL, enable ? 1 : 0, 27, 27);
1867 enable_clocks(0); 1949 enable_clocks(0);
1868} 1950}
1869 1951
1870void dispc_enable_fifohandcheck(bool enable) 1952void dispc_enable_fifohandcheck(enum omap_channel channel, bool enable)
1871{ 1953{
1872 enable_clocks(1); 1954 enable_clocks(1);
1873 REG_FLD_MOD(DISPC_CONFIG, enable ? 1 : 0, 16, 16); 1955 if (channel == OMAP_DSS_CHANNEL_LCD2)
1956 REG_FLD_MOD(DISPC_CONFIG2, enable ? 1 : 0, 16, 16);
1957 else
1958 REG_FLD_MOD(DISPC_CONFIG, enable ? 1 : 0, 16, 16);
1874 enable_clocks(0); 1959 enable_clocks(0);
1875} 1960}
1876 1961
1877 1962
1878void dispc_set_lcd_display_type(enum omap_lcd_display_type type) 1963void dispc_set_lcd_display_type(enum omap_channel channel,
1964 enum omap_lcd_display_type type)
1879{ 1965{
1880 int mode; 1966 int mode;
1881 1967
@@ -1894,7 +1980,10 @@ void dispc_set_lcd_display_type(enum omap_lcd_display_type type)
1894 } 1980 }
1895 1981
1896 enable_clocks(1); 1982 enable_clocks(1);
1897 REG_FLD_MOD(DISPC_CONTROL, mode, 3, 3); 1983 if (channel == OMAP_DSS_CHANNEL_LCD2)
1984 REG_FLD_MOD(DISPC_CONTROL2, mode, 3, 3);
1985 else
1986 REG_FLD_MOD(DISPC_CONTROL, mode, 3, 3);
1898 enable_clocks(0); 1987 enable_clocks(0);
1899} 1988}
1900 1989
@@ -1908,25 +1997,21 @@ void dispc_set_loadmode(enum omap_dss_load_mode mode)
1908 1997
1909void dispc_set_default_color(enum omap_channel channel, u32 color) 1998void dispc_set_default_color(enum omap_channel channel, u32 color)
1910{ 1999{
1911 const struct dispc_reg def_reg[] = { DISPC_DEFAULT_COLOR0,
1912 DISPC_DEFAULT_COLOR1 };
1913
1914 enable_clocks(1); 2000 enable_clocks(1);
1915 dispc_write_reg(def_reg[channel], color); 2001 dispc_write_reg(DISPC_DEFAULT_COLOR(channel), color);
1916 enable_clocks(0); 2002 enable_clocks(0);
1917} 2003}
1918 2004
1919u32 dispc_get_default_color(enum omap_channel channel) 2005u32 dispc_get_default_color(enum omap_channel channel)
1920{ 2006{
1921 const struct dispc_reg def_reg[] = { DISPC_DEFAULT_COLOR0,
1922 DISPC_DEFAULT_COLOR1 };
1923 u32 l; 2007 u32 l;
1924 2008
1925 BUG_ON(channel != OMAP_DSS_CHANNEL_DIGIT && 2009 BUG_ON(channel != OMAP_DSS_CHANNEL_DIGIT &&
1926 channel != OMAP_DSS_CHANNEL_LCD); 2010 channel != OMAP_DSS_CHANNEL_LCD &&
2011 channel != OMAP_DSS_CHANNEL_LCD2);
1927 2012
1928 enable_clocks(1); 2013 enable_clocks(1);
1929 l = dispc_read_reg(def_reg[channel]); 2014 l = dispc_read_reg(DISPC_DEFAULT_COLOR(channel));
1930 enable_clocks(0); 2015 enable_clocks(0);
1931 2016
1932 return l; 2017 return l;
@@ -1936,16 +2021,15 @@ void dispc_set_trans_key(enum omap_channel ch,
1936 enum omap_dss_trans_key_type type, 2021 enum omap_dss_trans_key_type type,
1937 u32 trans_key) 2022 u32 trans_key)
1938{ 2023{
1939 const struct dispc_reg tr_reg[] = {
1940 DISPC_TRANS_COLOR0, DISPC_TRANS_COLOR1 };
1941
1942 enable_clocks(1); 2024 enable_clocks(1);
1943 if (ch == OMAP_DSS_CHANNEL_LCD) 2025 if (ch == OMAP_DSS_CHANNEL_LCD)
1944 REG_FLD_MOD(DISPC_CONFIG, type, 11, 11); 2026 REG_FLD_MOD(DISPC_CONFIG, type, 11, 11);
1945 else /* OMAP_DSS_CHANNEL_DIGIT */ 2027 else if (ch == OMAP_DSS_CHANNEL_DIGIT)
1946 REG_FLD_MOD(DISPC_CONFIG, type, 13, 13); 2028 REG_FLD_MOD(DISPC_CONFIG, type, 13, 13);
2029 else /* OMAP_DSS_CHANNEL_LCD2 */
2030 REG_FLD_MOD(DISPC_CONFIG2, type, 11, 11);
1947 2031
1948 dispc_write_reg(tr_reg[ch], trans_key); 2032 dispc_write_reg(DISPC_TRANS_COLOR(ch), trans_key);
1949 enable_clocks(0); 2033 enable_clocks(0);
1950} 2034}
1951 2035
@@ -1953,21 +2037,20 @@ void dispc_get_trans_key(enum omap_channel ch,
1953 enum omap_dss_trans_key_type *type, 2037 enum omap_dss_trans_key_type *type,
1954 u32 *trans_key) 2038 u32 *trans_key)
1955{ 2039{
1956 const struct dispc_reg tr_reg[] = {
1957 DISPC_TRANS_COLOR0, DISPC_TRANS_COLOR1 };
1958
1959 enable_clocks(1); 2040 enable_clocks(1);
1960 if (type) { 2041 if (type) {
1961 if (ch == OMAP_DSS_CHANNEL_LCD) 2042 if (ch == OMAP_DSS_CHANNEL_LCD)
1962 *type = REG_GET(DISPC_CONFIG, 11, 11); 2043 *type = REG_GET(DISPC_CONFIG, 11, 11);
1963 else if (ch == OMAP_DSS_CHANNEL_DIGIT) 2044 else if (ch == OMAP_DSS_CHANNEL_DIGIT)
1964 *type = REG_GET(DISPC_CONFIG, 13, 13); 2045 *type = REG_GET(DISPC_CONFIG, 13, 13);
2046 else if (ch == OMAP_DSS_CHANNEL_LCD2)
2047 *type = REG_GET(DISPC_CONFIG2, 11, 11);
1965 else 2048 else
1966 BUG(); 2049 BUG();
1967 } 2050 }
1968 2051
1969 if (trans_key) 2052 if (trans_key)
1970 *trans_key = dispc_read_reg(tr_reg[ch]); 2053 *trans_key = dispc_read_reg(DISPC_TRANS_COLOR(ch));
1971 enable_clocks(0); 2054 enable_clocks(0);
1972} 2055}
1973 2056
@@ -1976,8 +2059,10 @@ void dispc_enable_trans_key(enum omap_channel ch, bool enable)
1976 enable_clocks(1); 2059 enable_clocks(1);
1977 if (ch == OMAP_DSS_CHANNEL_LCD) 2060 if (ch == OMAP_DSS_CHANNEL_LCD)
1978 REG_FLD_MOD(DISPC_CONFIG, enable, 10, 10); 2061 REG_FLD_MOD(DISPC_CONFIG, enable, 10, 10);
1979 else /* OMAP_DSS_CHANNEL_DIGIT */ 2062 else if (ch == OMAP_DSS_CHANNEL_DIGIT)
1980 REG_FLD_MOD(DISPC_CONFIG, enable, 12, 12); 2063 REG_FLD_MOD(DISPC_CONFIG, enable, 12, 12);
2064 else /* OMAP_DSS_CHANNEL_LCD2 */
2065 REG_FLD_MOD(DISPC_CONFIG2, enable, 10, 10);
1981 enable_clocks(0); 2066 enable_clocks(0);
1982} 2067}
1983void dispc_enable_alpha_blending(enum omap_channel ch, bool enable) 2068void dispc_enable_alpha_blending(enum omap_channel ch, bool enable)
@@ -1988,8 +2073,10 @@ void dispc_enable_alpha_blending(enum omap_channel ch, bool enable)
1988 enable_clocks(1); 2073 enable_clocks(1);
1989 if (ch == OMAP_DSS_CHANNEL_LCD) 2074 if (ch == OMAP_DSS_CHANNEL_LCD)
1990 REG_FLD_MOD(DISPC_CONFIG, enable, 18, 18); 2075 REG_FLD_MOD(DISPC_CONFIG, enable, 18, 18);
1991 else /* OMAP_DSS_CHANNEL_DIGIT */ 2076 else if (ch == OMAP_DSS_CHANNEL_DIGIT)
1992 REG_FLD_MOD(DISPC_CONFIG, enable, 19, 19); 2077 REG_FLD_MOD(DISPC_CONFIG, enable, 19, 19);
2078 else /* OMAP_DSS_CHANNEL_LCD2 */
2079 REG_FLD_MOD(DISPC_CONFIG2, enable, 18, 18);
1993 enable_clocks(0); 2080 enable_clocks(0);
1994} 2081}
1995bool dispc_alpha_blending_enabled(enum omap_channel ch) 2082bool dispc_alpha_blending_enabled(enum omap_channel ch)
@@ -2003,13 +2090,14 @@ bool dispc_alpha_blending_enabled(enum omap_channel ch)
2003 if (ch == OMAP_DSS_CHANNEL_LCD) 2090 if (ch == OMAP_DSS_CHANNEL_LCD)
2004 enabled = REG_GET(DISPC_CONFIG, 18, 18); 2091 enabled = REG_GET(DISPC_CONFIG, 18, 18);
2005 else if (ch == OMAP_DSS_CHANNEL_DIGIT) 2092 else if (ch == OMAP_DSS_CHANNEL_DIGIT)
2006 enabled = REG_GET(DISPC_CONFIG, 18, 18); 2093 enabled = REG_GET(DISPC_CONFIG, 19, 19);
2094 else if (ch == OMAP_DSS_CHANNEL_LCD2)
2095 enabled = REG_GET(DISPC_CONFIG2, 18, 18);
2007 else 2096 else
2008 BUG(); 2097 BUG();
2009 enable_clocks(0); 2098 enable_clocks(0);
2010 2099
2011 return enabled; 2100 return enabled;
2012
2013} 2101}
2014 2102
2015 2103
@@ -2022,6 +2110,8 @@ bool dispc_trans_key_enabled(enum omap_channel ch)
2022 enabled = REG_GET(DISPC_CONFIG, 10, 10); 2110 enabled = REG_GET(DISPC_CONFIG, 10, 10);
2023 else if (ch == OMAP_DSS_CHANNEL_DIGIT) 2111 else if (ch == OMAP_DSS_CHANNEL_DIGIT)
2024 enabled = REG_GET(DISPC_CONFIG, 12, 12); 2112 enabled = REG_GET(DISPC_CONFIG, 12, 12);
2113 else if (ch == OMAP_DSS_CHANNEL_LCD2)
2114 enabled = REG_GET(DISPC_CONFIG2, 10, 10);
2025 else 2115 else
2026 BUG(); 2116 BUG();
2027 enable_clocks(0); 2117 enable_clocks(0);
@@ -2030,7 +2120,7 @@ bool dispc_trans_key_enabled(enum omap_channel ch)
2030} 2120}
2031 2121
2032 2122
2033void dispc_set_tft_data_lines(u8 data_lines) 2123void dispc_set_tft_data_lines(enum omap_channel channel, u8 data_lines)
2034{ 2124{
2035 int code; 2125 int code;
2036 2126
@@ -2053,11 +2143,15 @@ void dispc_set_tft_data_lines(u8 data_lines)
2053 } 2143 }
2054 2144
2055 enable_clocks(1); 2145 enable_clocks(1);
2056 REG_FLD_MOD(DISPC_CONTROL, code, 9, 8); 2146 if (channel == OMAP_DSS_CHANNEL_LCD2)
2147 REG_FLD_MOD(DISPC_CONTROL2, code, 9, 8);
2148 else
2149 REG_FLD_MOD(DISPC_CONTROL, code, 9, 8);
2057 enable_clocks(0); 2150 enable_clocks(0);
2058} 2151}
2059 2152
2060void dispc_set_parallel_interface_mode(enum omap_parallel_interface_mode mode) 2153void dispc_set_parallel_interface_mode(enum omap_channel channel,
2154 enum omap_parallel_interface_mode mode)
2061{ 2155{
2062 u32 l; 2156 u32 l;
2063 int stallmode; 2157 int stallmode;
@@ -2087,13 +2181,17 @@ void dispc_set_parallel_interface_mode(enum omap_parallel_interface_mode mode)
2087 2181
2088 enable_clocks(1); 2182 enable_clocks(1);
2089 2183
2090 l = dispc_read_reg(DISPC_CONTROL); 2184 if (channel == OMAP_DSS_CHANNEL_LCD2) {
2091 2185 l = dispc_read_reg(DISPC_CONTROL2);
2092 l = FLD_MOD(l, stallmode, 11, 11); 2186 l = FLD_MOD(l, stallmode, 11, 11);
2093 l = FLD_MOD(l, gpout0, 15, 15); 2187 dispc_write_reg(DISPC_CONTROL2, l);
2094 l = FLD_MOD(l, gpout1, 16, 16); 2188 } else {
2095 2189 l = dispc_read_reg(DISPC_CONTROL);
2096 dispc_write_reg(DISPC_CONTROL, l); 2190 l = FLD_MOD(l, stallmode, 11, 11);
2191 l = FLD_MOD(l, gpout0, 15, 15);
2192 l = FLD_MOD(l, gpout1, 16, 16);
2193 dispc_write_reg(DISPC_CONTROL, l);
2194 }
2097 2195
2098 enable_clocks(0); 2196 enable_clocks(0);
2099} 2197}
@@ -2129,8 +2227,8 @@ bool dispc_lcd_timings_ok(struct omap_video_timings *timings)
2129 timings->vfp, timings->vbp); 2227 timings->vfp, timings->vbp);
2130} 2228}
2131 2229
2132static void _dispc_set_lcd_timings(int hsw, int hfp, int hbp, 2230static void _dispc_set_lcd_timings(enum omap_channel channel, int hsw,
2133 int vsw, int vfp, int vbp) 2231 int hfp, int hbp, int vsw, int vfp, int vbp)
2134{ 2232{
2135 u32 timing_h, timing_v; 2233 u32 timing_h, timing_v;
2136 2234
@@ -2149,13 +2247,14 @@ static void _dispc_set_lcd_timings(int hsw, int hfp, int hbp,
2149 } 2247 }
2150 2248
2151 enable_clocks(1); 2249 enable_clocks(1);
2152 dispc_write_reg(DISPC_TIMING_H, timing_h); 2250 dispc_write_reg(DISPC_TIMING_H(channel), timing_h);
2153 dispc_write_reg(DISPC_TIMING_V, timing_v); 2251 dispc_write_reg(DISPC_TIMING_V(channel), timing_v);
2154 enable_clocks(0); 2252 enable_clocks(0);
2155} 2253}
2156 2254
2157/* change name to mode? */ 2255/* change name to mode? */
2158void dispc_set_lcd_timings(struct omap_video_timings *timings) 2256void dispc_set_lcd_timings(enum omap_channel channel,
2257 struct omap_video_timings *timings)
2159{ 2258{
2160 unsigned xtot, ytot; 2259 unsigned xtot, ytot;
2161 unsigned long ht, vt; 2260 unsigned long ht, vt;
@@ -2165,10 +2264,11 @@ void dispc_set_lcd_timings(struct omap_video_timings *timings)
2165 timings->vfp, timings->vbp)) 2264 timings->vfp, timings->vbp))
2166 BUG(); 2265 BUG();
2167 2266
2168 _dispc_set_lcd_timings(timings->hsw, timings->hfp, timings->hbp, 2267 _dispc_set_lcd_timings(channel, timings->hsw, timings->hfp,
2169 timings->vsw, timings->vfp, timings->vbp); 2268 timings->hbp, timings->vsw, timings->vfp,
2269 timings->vbp);
2170 2270
2171 dispc_set_lcd_size(timings->x_res, timings->y_res); 2271 dispc_set_lcd_size(channel, timings->x_res, timings->y_res);
2172 2272
2173 xtot = timings->x_res + timings->hfp + timings->hsw + timings->hbp; 2273 xtot = timings->x_res + timings->hfp + timings->hsw + timings->hbp;
2174 ytot = timings->y_res + timings->vfp + timings->vsw + timings->vbp; 2274 ytot = timings->y_res + timings->vfp + timings->vsw + timings->vbp;
@@ -2176,7 +2276,8 @@ void dispc_set_lcd_timings(struct omap_video_timings *timings)
2176 ht = (timings->pixel_clock * 1000) / xtot; 2276 ht = (timings->pixel_clock * 1000) / xtot;
2177 vt = (timings->pixel_clock * 1000) / xtot / ytot; 2277 vt = (timings->pixel_clock * 1000) / xtot / ytot;
2178 2278
2179 DSSDBG("xres %u yres %u\n", timings->x_res, timings->y_res); 2279 DSSDBG("channel %d xres %u yres %u\n", channel, timings->x_res,
2280 timings->y_res);
2180 DSSDBG("pck %u\n", timings->pixel_clock); 2281 DSSDBG("pck %u\n", timings->pixel_clock);
2181 DSSDBG("hsw %d hfp %d hbp %d vsw %d vfp %d vbp %d\n", 2282 DSSDBG("hsw %d hfp %d hbp %d vsw %d vfp %d vbp %d\n",
2182 timings->hsw, timings->hfp, timings->hbp, 2283 timings->hsw, timings->hfp, timings->hbp,
@@ -2185,21 +2286,23 @@ void dispc_set_lcd_timings(struct omap_video_timings *timings)
2185 DSSDBG("hsync %luHz, vsync %luHz\n", ht, vt); 2286 DSSDBG("hsync %luHz, vsync %luHz\n", ht, vt);
2186} 2287}
2187 2288
2188static void dispc_set_lcd_divisor(u16 lck_div, u16 pck_div) 2289static void dispc_set_lcd_divisor(enum omap_channel channel, u16 lck_div,
2290 u16 pck_div)
2189{ 2291{
2190 BUG_ON(lck_div < 1); 2292 BUG_ON(lck_div < 1);
2191 BUG_ON(pck_div < 2); 2293 BUG_ON(pck_div < 2);
2192 2294
2193 enable_clocks(1); 2295 enable_clocks(1);
2194 dispc_write_reg(DISPC_DIVISOR, 2296 dispc_write_reg(DISPC_DIVISOR(channel),
2195 FLD_VAL(lck_div, 23, 16) | FLD_VAL(pck_div, 7, 0)); 2297 FLD_VAL(lck_div, 23, 16) | FLD_VAL(pck_div, 7, 0));
2196 enable_clocks(0); 2298 enable_clocks(0);
2197} 2299}
2198 2300
2199static void dispc_get_lcd_divisor(int *lck_div, int *pck_div) 2301static void dispc_get_lcd_divisor(enum omap_channel channel, int *lck_div,
2302 int *pck_div)
2200{ 2303{
2201 u32 l; 2304 u32 l;
2202 l = dispc_read_reg(DISPC_DIVISOR); 2305 l = dispc_read_reg(DISPC_DIVISOR(channel));
2203 *lck_div = FLD_GET(l, 23, 16); 2306 *lck_div = FLD_GET(l, 23, 16);
2204 *pck_div = FLD_GET(l, 7, 0); 2307 *pck_div = FLD_GET(l, 7, 0);
2205} 2308}
@@ -2219,13 +2322,13 @@ unsigned long dispc_fclk_rate(void)
2219 return r; 2322 return r;
2220} 2323}
2221 2324
2222unsigned long dispc_lclk_rate(void) 2325unsigned long dispc_lclk_rate(enum omap_channel channel)
2223{ 2326{
2224 int lcd; 2327 int lcd;
2225 unsigned long r; 2328 unsigned long r;
2226 u32 l; 2329 u32 l;
2227 2330
2228 l = dispc_read_reg(DISPC_DIVISOR); 2331 l = dispc_read_reg(DISPC_DIVISOR(channel));
2229 2332
2230 lcd = FLD_GET(l, 23, 16); 2333 lcd = FLD_GET(l, 23, 16);
2231 2334
@@ -2234,13 +2337,13 @@ unsigned long dispc_lclk_rate(void)
2234 return r / lcd; 2337 return r / lcd;
2235} 2338}
2236 2339
2237unsigned long dispc_pclk_rate(void) 2340unsigned long dispc_pclk_rate(enum omap_channel channel)
2238{ 2341{
2239 int lcd, pcd; 2342 int lcd, pcd;
2240 unsigned long r; 2343 unsigned long r;
2241 u32 l; 2344 u32 l;
2242 2345
2243 l = dispc_read_reg(DISPC_DIVISOR); 2346 l = dispc_read_reg(DISPC_DIVISOR(channel));
2244 2347
2245 lcd = FLD_GET(l, 23, 16); 2348 lcd = FLD_GET(l, 23, 16);
2246 pcd = FLD_GET(l, 7, 0); 2349 pcd = FLD_GET(l, 7, 0);
@@ -2256,8 +2359,6 @@ void dispc_dump_clocks(struct seq_file *s)
2256 2359
2257 enable_clocks(1); 2360 enable_clocks(1);
2258 2361
2259 dispc_get_lcd_divisor(&lcd, &pcd);
2260
2261 seq_printf(s, "- DISPC -\n"); 2362 seq_printf(s, "- DISPC -\n");
2262 2363
2263 seq_printf(s, "dispc fclk source = %s\n", 2364 seq_printf(s, "dispc fclk source = %s\n",
@@ -2265,9 +2366,25 @@ void dispc_dump_clocks(struct seq_file *s)
2265 "dss1_alwon_fclk" : "dsi1_pll_fclk"); 2366 "dss1_alwon_fclk" : "dsi1_pll_fclk");
2266 2367
2267 seq_printf(s, "fck\t\t%-16lu\n", dispc_fclk_rate()); 2368 seq_printf(s, "fck\t\t%-16lu\n", dispc_fclk_rate());
2268 seq_printf(s, "lck\t\t%-16lulck div\t%u\n", dispc_lclk_rate(), lcd);
2269 seq_printf(s, "pck\t\t%-16lupck div\t%u\n", dispc_pclk_rate(), pcd);
2270 2369
2370 seq_printf(s, "- LCD1 -\n");
2371
2372 dispc_get_lcd_divisor(OMAP_DSS_CHANNEL_LCD, &lcd, &pcd);
2373
2374 seq_printf(s, "lck\t\t%-16lulck div\t%u\n",
2375 dispc_lclk_rate(OMAP_DSS_CHANNEL_LCD), lcd);
2376 seq_printf(s, "pck\t\t%-16lupck div\t%u\n",
2377 dispc_pclk_rate(OMAP_DSS_CHANNEL_LCD), pcd);
2378 if (dss_has_feature(FEAT_MGR_LCD2)) {
2379 seq_printf(s, "- LCD2 -\n");
2380
2381 dispc_get_lcd_divisor(OMAP_DSS_CHANNEL_LCD2, &lcd, &pcd);
2382
2383 seq_printf(s, "lck\t\t%-16lulck div\t%u\n",
2384 dispc_lclk_rate(OMAP_DSS_CHANNEL_LCD2), lcd);
2385 seq_printf(s, "pck\t\t%-16lupck div\t%u\n",
2386 dispc_pclk_rate(OMAP_DSS_CHANNEL_LCD2), pcd);
2387 }
2271 enable_clocks(0); 2388 enable_clocks(0);
2272} 2389}
2273 2390
@@ -2309,6 +2426,12 @@ void dispc_dump_irqs(struct seq_file *s)
2309 PIS(SYNC_LOST); 2426 PIS(SYNC_LOST);
2310 PIS(SYNC_LOST_DIGIT); 2427 PIS(SYNC_LOST_DIGIT);
2311 PIS(WAKEUP); 2428 PIS(WAKEUP);
2429 if (dss_has_feature(FEAT_MGR_LCD2)) {
2430 PIS(FRAMEDONE2);
2431 PIS(VSYNC2);
2432 PIS(ACBIAS_COUNT_STAT2);
2433 PIS(SYNC_LOST2);
2434 }
2312#undef PIS 2435#undef PIS
2313} 2436}
2314#endif 2437#endif
@@ -2327,19 +2450,30 @@ void dispc_dump_regs(struct seq_file *s)
2327 DUMPREG(DISPC_CONTROL); 2450 DUMPREG(DISPC_CONTROL);
2328 DUMPREG(DISPC_CONFIG); 2451 DUMPREG(DISPC_CONFIG);
2329 DUMPREG(DISPC_CAPABLE); 2452 DUMPREG(DISPC_CAPABLE);
2330 DUMPREG(DISPC_DEFAULT_COLOR0); 2453 DUMPREG(DISPC_DEFAULT_COLOR(0));
2331 DUMPREG(DISPC_DEFAULT_COLOR1); 2454 DUMPREG(DISPC_DEFAULT_COLOR(1));
2332 DUMPREG(DISPC_TRANS_COLOR0); 2455 DUMPREG(DISPC_TRANS_COLOR(0));
2333 DUMPREG(DISPC_TRANS_COLOR1); 2456 DUMPREG(DISPC_TRANS_COLOR(1));
2334 DUMPREG(DISPC_LINE_STATUS); 2457 DUMPREG(DISPC_LINE_STATUS);
2335 DUMPREG(DISPC_LINE_NUMBER); 2458 DUMPREG(DISPC_LINE_NUMBER);
2336 DUMPREG(DISPC_TIMING_H); 2459 DUMPREG(DISPC_TIMING_H(0));
2337 DUMPREG(DISPC_TIMING_V); 2460 DUMPREG(DISPC_TIMING_V(0));
2338 DUMPREG(DISPC_POL_FREQ); 2461 DUMPREG(DISPC_POL_FREQ(0));
2339 DUMPREG(DISPC_DIVISOR); 2462 DUMPREG(DISPC_DIVISOR(0));
2340 DUMPREG(DISPC_GLOBAL_ALPHA); 2463 DUMPREG(DISPC_GLOBAL_ALPHA);
2341 DUMPREG(DISPC_SIZE_DIG); 2464 DUMPREG(DISPC_SIZE_DIG);
2342 DUMPREG(DISPC_SIZE_LCD); 2465 DUMPREG(DISPC_SIZE_LCD(0));
2466 if (dss_has_feature(FEAT_MGR_LCD2)) {
2467 DUMPREG(DISPC_CONTROL2);
2468 DUMPREG(DISPC_CONFIG2);
2469 DUMPREG(DISPC_DEFAULT_COLOR(2));
2470 DUMPREG(DISPC_TRANS_COLOR(2));
2471 DUMPREG(DISPC_TIMING_H(2));
2472 DUMPREG(DISPC_TIMING_V(2));
2473 DUMPREG(DISPC_POL_FREQ(2));
2474 DUMPREG(DISPC_DIVISOR(2));
2475 DUMPREG(DISPC_SIZE_LCD(2));
2476 }
2343 2477
2344 DUMPREG(DISPC_GFX_BA0); 2478 DUMPREG(DISPC_GFX_BA0);
2345 DUMPREG(DISPC_GFX_BA1); 2479 DUMPREG(DISPC_GFX_BA1);
@@ -2353,13 +2487,22 @@ void dispc_dump_regs(struct seq_file *s)
2353 DUMPREG(DISPC_GFX_WINDOW_SKIP); 2487 DUMPREG(DISPC_GFX_WINDOW_SKIP);
2354 DUMPREG(DISPC_GFX_TABLE_BA); 2488 DUMPREG(DISPC_GFX_TABLE_BA);
2355 2489
2356 DUMPREG(DISPC_DATA_CYCLE1); 2490 DUMPREG(DISPC_DATA_CYCLE1(0));
2357 DUMPREG(DISPC_DATA_CYCLE2); 2491 DUMPREG(DISPC_DATA_CYCLE2(0));
2358 DUMPREG(DISPC_DATA_CYCLE3); 2492 DUMPREG(DISPC_DATA_CYCLE3(0));
2359 2493
2360 DUMPREG(DISPC_CPR_COEF_R); 2494 DUMPREG(DISPC_CPR_COEF_R(0));
2361 DUMPREG(DISPC_CPR_COEF_G); 2495 DUMPREG(DISPC_CPR_COEF_G(0));
2362 DUMPREG(DISPC_CPR_COEF_B); 2496 DUMPREG(DISPC_CPR_COEF_B(0));
2497 if (dss_has_feature(FEAT_MGR_LCD2)) {
2498 DUMPREG(DISPC_DATA_CYCLE1(2));
2499 DUMPREG(DISPC_DATA_CYCLE2(2));
2500 DUMPREG(DISPC_DATA_CYCLE3(2));
2501
2502 DUMPREG(DISPC_CPR_COEF_R(2));
2503 DUMPREG(DISPC_CPR_COEF_G(2));
2504 DUMPREG(DISPC_CPR_COEF_B(2));
2505 }
2363 2506
2364 DUMPREG(DISPC_GFX_PRELOAD); 2507 DUMPREG(DISPC_GFX_PRELOAD);
2365 2508
@@ -2458,8 +2601,8 @@ void dispc_dump_regs(struct seq_file *s)
2458#undef DUMPREG 2601#undef DUMPREG
2459} 2602}
2460 2603
2461static void _dispc_set_pol_freq(bool onoff, bool rf, bool ieo, bool ipc, 2604static void _dispc_set_pol_freq(enum omap_channel channel, bool onoff, bool rf,
2462 bool ihs, bool ivs, u8 acbi, u8 acb) 2605 bool ieo, bool ipc, bool ihs, bool ivs, u8 acbi, u8 acb)
2463{ 2606{
2464 u32 l = 0; 2607 u32 l = 0;
2465 2608
@@ -2476,13 +2619,14 @@ static void _dispc_set_pol_freq(bool onoff, bool rf, bool ieo, bool ipc,
2476 l |= FLD_VAL(acb, 7, 0); 2619 l |= FLD_VAL(acb, 7, 0);
2477 2620
2478 enable_clocks(1); 2621 enable_clocks(1);
2479 dispc_write_reg(DISPC_POL_FREQ, l); 2622 dispc_write_reg(DISPC_POL_FREQ(channel), l);
2480 enable_clocks(0); 2623 enable_clocks(0);
2481} 2624}
2482 2625
2483void dispc_set_pol_freq(enum omap_panel_config config, u8 acbi, u8 acb) 2626void dispc_set_pol_freq(enum omap_channel channel,
2627 enum omap_panel_config config, u8 acbi, u8 acb)
2484{ 2628{
2485 _dispc_set_pol_freq((config & OMAP_DSS_LCD_ONOFF) != 0, 2629 _dispc_set_pol_freq(channel, (config & OMAP_DSS_LCD_ONOFF) != 0,
2486 (config & OMAP_DSS_LCD_RF) != 0, 2630 (config & OMAP_DSS_LCD_RF) != 0,
2487 (config & OMAP_DSS_LCD_IEO) != 0, 2631 (config & OMAP_DSS_LCD_IEO) != 0,
2488 (config & OMAP_DSS_LCD_IPC) != 0, 2632 (config & OMAP_DSS_LCD_IPC) != 0,
@@ -2551,24 +2695,26 @@ int dispc_calc_clock_rates(unsigned long dispc_fclk_rate,
2551 return 0; 2695 return 0;
2552} 2696}
2553 2697
2554int dispc_set_clock_div(struct dispc_clock_info *cinfo) 2698int dispc_set_clock_div(enum omap_channel channel,
2699 struct dispc_clock_info *cinfo)
2555{ 2700{
2556 DSSDBG("lck = %lu (%u)\n", cinfo->lck, cinfo->lck_div); 2701 DSSDBG("lck = %lu (%u)\n", cinfo->lck, cinfo->lck_div);
2557 DSSDBG("pck = %lu (%u)\n", cinfo->pck, cinfo->pck_div); 2702 DSSDBG("pck = %lu (%u)\n", cinfo->pck, cinfo->pck_div);
2558 2703
2559 dispc_set_lcd_divisor(cinfo->lck_div, cinfo->pck_div); 2704 dispc_set_lcd_divisor(channel, cinfo->lck_div, cinfo->pck_div);
2560 2705
2561 return 0; 2706 return 0;
2562} 2707}
2563 2708
2564int dispc_get_clock_div(struct dispc_clock_info *cinfo) 2709int dispc_get_clock_div(enum omap_channel channel,
2710 struct dispc_clock_info *cinfo)
2565{ 2711{
2566 unsigned long fck; 2712 unsigned long fck;
2567 2713
2568 fck = dispc_fclk_rate(); 2714 fck = dispc_fclk_rate();
2569 2715
2570 cinfo->lck_div = REG_GET(DISPC_DIVISOR, 23, 16); 2716 cinfo->lck_div = REG_GET(DISPC_DIVISOR(channel), 23, 16);
2571 cinfo->pck_div = REG_GET(DISPC_DIVISOR, 7, 0); 2717 cinfo->pck_div = REG_GET(DISPC_DIVISOR(channel), 7, 0);
2572 2718
2573 cinfo->lck = fck / cinfo->lck_div; 2719 cinfo->lck = fck / cinfo->lck_div;
2574 cinfo->pck = cinfo->lck / cinfo->pck_div; 2720 cinfo->pck = cinfo->lck / cinfo->pck_div;
@@ -2708,6 +2854,8 @@ static void print_irq_status(u32 status)
2708 PIS(VID2_FIFO_UNDERFLOW); 2854 PIS(VID2_FIFO_UNDERFLOW);
2709 PIS(SYNC_LOST); 2855 PIS(SYNC_LOST);
2710 PIS(SYNC_LOST_DIGIT); 2856 PIS(SYNC_LOST_DIGIT);
2857 if (dss_has_feature(FEAT_MGR_LCD2))
2858 PIS(SYNC_LOST2);
2711#undef PIS 2859#undef PIS
2712 2860
2713 printk("\n"); 2861 printk("\n");
@@ -2926,6 +3074,45 @@ static void dispc_error_worker(struct work_struct *work)
2926 } 3074 }
2927 } 3075 }
2928 3076
3077 if (errors & DISPC_IRQ_SYNC_LOST2) {
3078 struct omap_overlay_manager *manager = NULL;
3079 bool enable = false;
3080
3081 DSSERR("SYNC_LOST for LCD2, disabling LCD2\n");
3082
3083 for (i = 0; i < omap_dss_get_num_overlay_managers(); ++i) {
3084 struct omap_overlay_manager *mgr;
3085 mgr = omap_dss_get_overlay_manager(i);
3086
3087 if (mgr->id == OMAP_DSS_CHANNEL_LCD2) {
3088 manager = mgr;
3089 enable = mgr->device->state ==
3090 OMAP_DSS_DISPLAY_ACTIVE;
3091 mgr->device->driver->disable(mgr->device);
3092 break;
3093 }
3094 }
3095
3096 if (manager) {
3097 struct omap_dss_device *dssdev = manager->device;
3098 for (i = 0; i < omap_dss_get_num_overlays(); ++i) {
3099 struct omap_overlay *ovl;
3100 ovl = omap_dss_get_overlay(i);
3101
3102 if (!(ovl->caps & OMAP_DSS_OVL_CAP_DISPC))
3103 continue;
3104
3105 if (ovl->id != 0 && ovl->manager == manager)
3106 dispc_enable_plane(ovl->id, 0);
3107 }
3108
3109 dispc_go(manager->id);
3110 mdelay(50);
3111 if (enable)
3112 dssdev->driver->enable(dssdev);
3113 }
3114 }
3115
2929 if (errors & DISPC_IRQ_OCP_ERR) { 3116 if (errors & DISPC_IRQ_OCP_ERR) {
2930 DSSERR("OCP_ERR\n"); 3117 DSSERR("OCP_ERR\n");
2931 for (i = 0; i < omap_dss_get_num_overlay_managers(); ++i) { 3118 for (i = 0; i < omap_dss_get_num_overlay_managers(); ++i) {
@@ -3033,6 +3220,8 @@ static void _omap_dispc_initialize_irq(void)
3033 memset(dispc.registered_isr, 0, sizeof(dispc.registered_isr)); 3220 memset(dispc.registered_isr, 0, sizeof(dispc.registered_isr));
3034 3221
3035 dispc.irq_error_mask = DISPC_IRQ_MASK_ERROR; 3222 dispc.irq_error_mask = DISPC_IRQ_MASK_ERROR;
3223 if (dss_has_feature(FEAT_MGR_LCD2))
3224 dispc.irq_error_mask |= DISPC_IRQ_SYNC_LOST2;
3036 3225
3037 /* there's SYNC_LOST_DIGIT waiting after enabling the DSS, 3226 /* there's SYNC_LOST_DIGIT waiting after enabling the DSS,
3038 * so clear it */ 3227 * so clear it */
@@ -3065,7 +3254,8 @@ static void _omap_dispc_initial_config(void)
3065 dispc_write_reg(DISPC_SYSCONFIG, l); 3254 dispc_write_reg(DISPC_SYSCONFIG, l);
3066 3255
3067 /* FUNCGATED */ 3256 /* FUNCGATED */
3068 REG_FLD_MOD(DISPC_CONFIG, 1, 9, 9); 3257 if (dss_has_feature(FEAT_FUNCGATED))
3258 REG_FLD_MOD(DISPC_CONFIG, 1, 9, 9);
3069 3259
3070 /* L3 firewall setting: enable access to OCM RAM */ 3260 /* L3 firewall setting: enable access to OCM RAM */
3071 /* XXX this should be somewhere in plat-omap */ 3261 /* XXX this should be somewhere in plat-omap */
@@ -3139,17 +3329,18 @@ int dispc_setup_plane(enum omap_plane plane,
3139 enum omap_color_mode color_mode, 3329 enum omap_color_mode color_mode,
3140 bool ilace, 3330 bool ilace,
3141 enum omap_dss_rotation_type rotation_type, 3331 enum omap_dss_rotation_type rotation_type,
3142 u8 rotation, bool mirror, u8 global_alpha) 3332 u8 rotation, bool mirror, u8 global_alpha,
3333 u8 pre_mult_alpha, enum omap_channel channel)
3143{ 3334{
3144 int r = 0; 3335 int r = 0;
3145 3336
3146 DSSDBG("dispc_setup_plane %d, pa %x, sw %d, %d,%d, %dx%d -> " 3337 DSSDBG("dispc_setup_plane %d, pa %x, sw %d, %d,%d, %dx%d -> "
3147 "%dx%d, ilace %d, cmode %x, rot %d, mir %d\n", 3338 "%dx%d, ilace %d, cmode %x, rot %d, mir %d chan %d\n",
3148 plane, paddr, screen_width, pos_x, pos_y, 3339 plane, paddr, screen_width, pos_x, pos_y,
3149 width, height, 3340 width, height,
3150 out_width, out_height, 3341 out_width, out_height,
3151 ilace, color_mode, 3342 ilace, color_mode,
3152 rotation, mirror); 3343 rotation, mirror, channel);
3153 3344
3154 enable_clocks(1); 3345 enable_clocks(1);
3155 3346
@@ -3161,7 +3352,8 @@ int dispc_setup_plane(enum omap_plane plane,
3161 color_mode, ilace, 3352 color_mode, ilace,
3162 rotation_type, 3353 rotation_type,
3163 rotation, mirror, 3354 rotation, mirror,
3164 global_alpha); 3355 global_alpha,
3356 pre_mult_alpha, channel);
3165 3357
3166 enable_clocks(0); 3358 enable_clocks(0);
3167 3359
diff --git a/drivers/video/omap2/dss/dpi.c b/drivers/video/omap2/dss/dpi.c
index 960e977a8bf0..75fb0a515430 100644
--- a/drivers/video/omap2/dss/dpi.c
+++ b/drivers/video/omap2/dss/dpi.c
@@ -40,8 +40,9 @@ static struct {
40} dpi; 40} dpi;
41 41
42#ifdef CONFIG_OMAP2_DSS_USE_DSI_PLL 42#ifdef CONFIG_OMAP2_DSS_USE_DSI_PLL
43static int dpi_set_dsi_clk(bool is_tft, unsigned long pck_req, 43static int dpi_set_dsi_clk(struct omap_dss_device *dssdev, bool is_tft,
44 unsigned long *fck, int *lck_div, int *pck_div) 44 unsigned long pck_req, unsigned long *fck, int *lck_div,
45 int *pck_div)
45{ 46{
46 struct dsi_clock_info dsi_cinfo; 47 struct dsi_clock_info dsi_cinfo;
47 struct dispc_clock_info dispc_cinfo; 48 struct dispc_clock_info dispc_cinfo;
@@ -58,7 +59,7 @@ static int dpi_set_dsi_clk(bool is_tft, unsigned long pck_req,
58 59
59 dss_select_dispc_clk_source(DSS_SRC_DSI1_PLL_FCLK); 60 dss_select_dispc_clk_source(DSS_SRC_DSI1_PLL_FCLK);
60 61
61 r = dispc_set_clock_div(&dispc_cinfo); 62 r = dispc_set_clock_div(dssdev->manager->id, &dispc_cinfo);
62 if (r) 63 if (r)
63 return r; 64 return r;
64 65
@@ -69,8 +70,9 @@ static int dpi_set_dsi_clk(bool is_tft, unsigned long pck_req,
69 return 0; 70 return 0;
70} 71}
71#else 72#else
72static int dpi_set_dispc_clk(bool is_tft, unsigned long pck_req, 73static int dpi_set_dispc_clk(struct omap_dss_device *dssdev, bool is_tft,
73 unsigned long *fck, int *lck_div, int *pck_div) 74 unsigned long pck_req, unsigned long *fck, int *lck_div,
75 int *pck_div)
74{ 76{
75 struct dss_clock_info dss_cinfo; 77 struct dss_clock_info dss_cinfo;
76 struct dispc_clock_info dispc_cinfo; 78 struct dispc_clock_info dispc_cinfo;
@@ -84,7 +86,7 @@ static int dpi_set_dispc_clk(bool is_tft, unsigned long pck_req,
84 if (r) 86 if (r)
85 return r; 87 return r;
86 88
87 r = dispc_set_clock_div(&dispc_cinfo); 89 r = dispc_set_clock_div(dssdev->manager->id, &dispc_cinfo);
88 if (r) 90 if (r)
89 return r; 91 return r;
90 92
@@ -107,17 +109,17 @@ static int dpi_set_mode(struct omap_dss_device *dssdev)
107 109
108 dss_clk_enable(DSS_CLK_ICK | DSS_CLK_FCK1); 110 dss_clk_enable(DSS_CLK_ICK | DSS_CLK_FCK1);
109 111
110 dispc_set_pol_freq(dssdev->panel.config, dssdev->panel.acbi, 112 dispc_set_pol_freq(dssdev->manager->id, dssdev->panel.config,
111 dssdev->panel.acb); 113 dssdev->panel.acbi, dssdev->panel.acb);
112 114
113 is_tft = (dssdev->panel.config & OMAP_DSS_LCD_TFT) != 0; 115 is_tft = (dssdev->panel.config & OMAP_DSS_LCD_TFT) != 0;
114 116
115#ifdef CONFIG_OMAP2_DSS_USE_DSI_PLL 117#ifdef CONFIG_OMAP2_DSS_USE_DSI_PLL
116 r = dpi_set_dsi_clk(is_tft, t->pixel_clock * 1000, 118 r = dpi_set_dsi_clk(dssdev, is_tft, t->pixel_clock * 1000, &fck,
117 &fck, &lck_div, &pck_div); 119 &lck_div, &pck_div);
118#else 120#else
119 r = dpi_set_dispc_clk(is_tft, t->pixel_clock * 1000, 121 r = dpi_set_dispc_clk(dssdev, is_tft, t->pixel_clock * 1000, &fck,
120 &fck, &lck_div, &pck_div); 122 &lck_div, &pck_div);
121#endif 123#endif
122 if (r) 124 if (r)
123 goto err0; 125 goto err0;
@@ -132,7 +134,7 @@ static int dpi_set_mode(struct omap_dss_device *dssdev)
132 t->pixel_clock = pck; 134 t->pixel_clock = pck;
133 } 135 }
134 136
135 dispc_set_lcd_timings(t); 137 dispc_set_lcd_timings(dssdev->manager->id, t);
136 138
137err0: 139err0:
138 dss_clk_disable(DSS_CLK_ICK | DSS_CLK_FCK1); 140 dss_clk_disable(DSS_CLK_ICK | DSS_CLK_FCK1);
@@ -145,10 +147,12 @@ static int dpi_basic_init(struct omap_dss_device *dssdev)
145 147
146 is_tft = (dssdev->panel.config & OMAP_DSS_LCD_TFT) != 0; 148 is_tft = (dssdev->panel.config & OMAP_DSS_LCD_TFT) != 0;
147 149
148 dispc_set_parallel_interface_mode(OMAP_DSS_PARALLELMODE_BYPASS); 150 dispc_set_parallel_interface_mode(dssdev->manager->id,
149 dispc_set_lcd_display_type(is_tft ? OMAP_DSS_LCD_DISPLAY_TFT : 151 OMAP_DSS_PARALLELMODE_BYPASS);
150 OMAP_DSS_LCD_DISPLAY_STN); 152 dispc_set_lcd_display_type(dssdev->manager->id, is_tft ?
151 dispc_set_tft_data_lines(dssdev->phy.dpi.data_lines); 153 OMAP_DSS_LCD_DISPLAY_TFT : OMAP_DSS_LCD_DISPLAY_STN);
154 dispc_set_tft_data_lines(dssdev->manager->id,
155 dssdev->phy.dpi.data_lines);
152 156
153 return 0; 157 return 0;
154} 158}
@@ -234,7 +238,7 @@ void dpi_set_timings(struct omap_dss_device *dssdev,
234 dssdev->panel.timings = *timings; 238 dssdev->panel.timings = *timings;
235 if (dssdev->state == OMAP_DSS_DISPLAY_ACTIVE) { 239 if (dssdev->state == OMAP_DSS_DISPLAY_ACTIVE) {
236 dpi_set_mode(dssdev); 240 dpi_set_mode(dssdev);
237 dispc_go(OMAP_DSS_CHANNEL_LCD); 241 dispc_go(dssdev->manager->id);
238 } 242 }
239} 243}
240EXPORT_SYMBOL(dpi_set_timings); 244EXPORT_SYMBOL(dpi_set_timings);
diff --git a/drivers/video/omap2/dss/dsi.c b/drivers/video/omap2/dss/dsi.c
index aa4f7a5fae29..ddf3a0560822 100644
--- a/drivers/video/omap2/dss/dsi.c
+++ b/drivers/video/omap2/dss/dsi.c
@@ -792,7 +792,8 @@ static int dsi_pll_power(enum dsi_pll_power_state state)
792} 792}
793 793
794/* calculate clock rates using dividers in cinfo */ 794/* calculate clock rates using dividers in cinfo */
795static int dsi_calc_clock_rates(struct dsi_clock_info *cinfo) 795static int dsi_calc_clock_rates(struct omap_dss_device *dssdev,
796 struct dsi_clock_info *cinfo)
796{ 797{
797 if (cinfo->regn == 0 || cinfo->regn > REGN_MAX) 798 if (cinfo->regn == 0 || cinfo->regn > REGN_MAX)
798 return -EINVAL; 799 return -EINVAL;
@@ -812,7 +813,7 @@ static int dsi_calc_clock_rates(struct dsi_clock_info *cinfo)
812 * with DSS2_FCK source also */ 813 * with DSS2_FCK source also */
813 cinfo->highfreq = 0; 814 cinfo->highfreq = 0;
814 } else { 815 } else {
815 cinfo->clkin = dispc_pclk_rate(); 816 cinfo->clkin = dispc_pclk_rate(dssdev->manager->id);
816 817
817 if (cinfo->clkin < 32000000) 818 if (cinfo->clkin < 32000000)
818 cinfo->highfreq = 0; 819 cinfo->highfreq = 0;
@@ -1206,8 +1207,8 @@ void dsi_dump_clocks(struct seq_file *s)
1206 1207
1207 seq_printf(s, "VP_CLK\t\t%lu\n" 1208 seq_printf(s, "VP_CLK\t\t%lu\n"
1208 "VP_PCLK\t\t%lu\n", 1209 "VP_PCLK\t\t%lu\n",
1209 dispc_lclk_rate(), 1210 dispc_lclk_rate(OMAP_DSS_CHANNEL_LCD),
1210 dispc_pclk_rate()); 1211 dispc_pclk_rate(OMAP_DSS_CHANNEL_LCD));
1211 1212
1212 enable_clocks(0); 1213 enable_clocks(0);
1213} 1214}
@@ -2888,7 +2889,7 @@ int omap_dsi_prepare_update(struct omap_dss_device *dssdev,
2888 if (dssdev->manager->caps & OMAP_DSS_OVL_MGR_CAP_DISPC) { 2889 if (dssdev->manager->caps & OMAP_DSS_OVL_MGR_CAP_DISPC) {
2889 dss_setup_partial_planes(dssdev, x, y, w, h, 2890 dss_setup_partial_planes(dssdev, x, y, w, h,
2890 enlarge_update_area); 2891 enlarge_update_area);
2891 dispc_set_lcd_size(*w, *h); 2892 dispc_set_lcd_size(dssdev->manager->id, *w, *h);
2892 } 2893 }
2893 2894
2894 return 0; 2895 return 0;
@@ -2947,12 +2948,14 @@ static int dsi_display_init_dispc(struct omap_dss_device *dssdev)
2947 return r; 2948 return r;
2948 } 2949 }
2949 2950
2950 dispc_set_lcd_display_type(OMAP_DSS_LCD_DISPLAY_TFT); 2951 dispc_set_lcd_display_type(dssdev->manager->id,
2952 OMAP_DSS_LCD_DISPLAY_TFT);
2951 2953
2952 dispc_set_parallel_interface_mode(OMAP_DSS_PARALLELMODE_DSI); 2954 dispc_set_parallel_interface_mode(dssdev->manager->id,
2953 dispc_enable_fifohandcheck(1); 2955 OMAP_DSS_PARALLELMODE_DSI);
2956 dispc_enable_fifohandcheck(dssdev->manager->id, 1);
2954 2957
2955 dispc_set_tft_data_lines(dssdev->ctrl.pixel_size); 2958 dispc_set_tft_data_lines(dssdev->manager->id, dssdev->ctrl.pixel_size);
2956 2959
2957 { 2960 {
2958 struct omap_video_timings timings = { 2961 struct omap_video_timings timings = {
@@ -2964,7 +2967,7 @@ static int dsi_display_init_dispc(struct omap_dss_device *dssdev)
2964 .vbp = 0, 2967 .vbp = 0,
2965 }; 2968 };
2966 2969
2967 dispc_set_lcd_timings(&timings); 2970 dispc_set_lcd_timings(dssdev->manager->id, &timings);
2968 } 2971 }
2969 2972
2970 return 0; 2973 return 0;
@@ -2987,7 +2990,7 @@ static int dsi_configure_dsi_clocks(struct omap_dss_device *dssdev)
2987 cinfo.regm = dssdev->phy.dsi.div.regm; 2990 cinfo.regm = dssdev->phy.dsi.div.regm;
2988 cinfo.regm3 = dssdev->phy.dsi.div.regm3; 2991 cinfo.regm3 = dssdev->phy.dsi.div.regm3;
2989 cinfo.regm4 = dssdev->phy.dsi.div.regm4; 2992 cinfo.regm4 = dssdev->phy.dsi.div.regm4;
2990 r = dsi_calc_clock_rates(&cinfo); 2993 r = dsi_calc_clock_rates(dssdev, &cinfo);
2991 if (r) { 2994 if (r) {
2992 DSSERR("Failed to calc dsi clocks\n"); 2995 DSSERR("Failed to calc dsi clocks\n");
2993 return r; 2996 return r;
@@ -3019,7 +3022,7 @@ static int dsi_configure_dispc_clocks(struct omap_dss_device *dssdev)
3019 return r; 3022 return r;
3020 } 3023 }
3021 3024
3022 r = dispc_set_clock_div(&dispc_cinfo); 3025 r = dispc_set_clock_div(dssdev->manager->id, &dispc_cinfo);
3023 if (r) { 3026 if (r) {
3024 DSSERR("Failed to set dispc clocks\n"); 3027 DSSERR("Failed to set dispc clocks\n");
3025 return r; 3028 return r;
diff --git a/drivers/video/omap2/dss/dss.h b/drivers/video/omap2/dss/dss.h
index 5c7940d5f282..b394951120ac 100644
--- a/drivers/video/omap2/dss/dss.h
+++ b/drivers/video/omap2/dss/dss.h
@@ -333,9 +333,9 @@ void dispc_disable_sidle(void);
333void dispc_lcd_enable_signal_polarity(bool act_high); 333void dispc_lcd_enable_signal_polarity(bool act_high);
334void dispc_lcd_enable_signal(bool enable); 334void dispc_lcd_enable_signal(bool enable);
335void dispc_pck_free_enable(bool enable); 335void dispc_pck_free_enable(bool enable);
336void dispc_enable_fifohandcheck(bool enable); 336void dispc_enable_fifohandcheck(enum omap_channel channel, bool enable);
337 337
338void dispc_set_lcd_size(u16 width, u16 height); 338void dispc_set_lcd_size(enum omap_channel channel, u16 width, u16 height);
339void dispc_set_digit_size(u16 width, u16 height); 339void dispc_set_digit_size(u16 width, u16 height);
340u32 dispc_get_plane_fifo_size(enum omap_plane plane); 340u32 dispc_get_plane_fifo_size(enum omap_plane plane);
341void dispc_setup_plane_fifo(enum omap_plane plane, u32 low, u32 high); 341void dispc_setup_plane_fifo(enum omap_plane plane, u32 low, u32 high);
@@ -359,7 +359,8 @@ int dispc_setup_plane(enum omap_plane plane,
359 bool ilace, 359 bool ilace,
360 enum omap_dss_rotation_type rotation_type, 360 enum omap_dss_rotation_type rotation_type,
361 u8 rotation, bool mirror, 361 u8 rotation, bool mirror,
362 u8 global_alpha); 362 u8 global_alpha, u8 pre_mult_alpha,
363 enum omap_channel channel);
363 364
364bool dispc_go_busy(enum omap_channel channel); 365bool dispc_go_busy(enum omap_channel channel);
365void dispc_go(enum omap_channel channel); 366void dispc_go(enum omap_channel channel);
@@ -368,9 +369,11 @@ bool dispc_is_channel_enabled(enum omap_channel channel);
368int dispc_enable_plane(enum omap_plane plane, bool enable); 369int dispc_enable_plane(enum omap_plane plane, bool enable);
369void dispc_enable_replication(enum omap_plane plane, bool enable); 370void dispc_enable_replication(enum omap_plane plane, bool enable);
370 371
371void dispc_set_parallel_interface_mode(enum omap_parallel_interface_mode mode); 372void dispc_set_parallel_interface_mode(enum omap_channel channel,
372void dispc_set_tft_data_lines(u8 data_lines); 373 enum omap_parallel_interface_mode mode);
373void dispc_set_lcd_display_type(enum omap_lcd_display_type type); 374void dispc_set_tft_data_lines(enum omap_channel channel, u8 data_lines);
375void dispc_set_lcd_display_type(enum omap_channel channel,
376 enum omap_lcd_display_type type);
374void dispc_set_loadmode(enum omap_dss_load_mode mode); 377void dispc_set_loadmode(enum omap_dss_load_mode mode);
375 378
376void dispc_set_default_color(enum omap_channel channel, u32 color); 379void dispc_set_default_color(enum omap_channel channel, u32 color);
@@ -387,17 +390,21 @@ bool dispc_trans_key_enabled(enum omap_channel ch);
387bool dispc_alpha_blending_enabled(enum omap_channel ch); 390bool dispc_alpha_blending_enabled(enum omap_channel ch);
388 391
389bool dispc_lcd_timings_ok(struct omap_video_timings *timings); 392bool dispc_lcd_timings_ok(struct omap_video_timings *timings);
390void dispc_set_lcd_timings(struct omap_video_timings *timings); 393void dispc_set_lcd_timings(enum omap_channel channel,
394 struct omap_video_timings *timings);
391unsigned long dispc_fclk_rate(void); 395unsigned long dispc_fclk_rate(void);
392unsigned long dispc_lclk_rate(void); 396unsigned long dispc_lclk_rate(enum omap_channel channel);
393unsigned long dispc_pclk_rate(void); 397unsigned long dispc_pclk_rate(enum omap_channel channel);
394void dispc_set_pol_freq(enum omap_panel_config config, u8 acbi, u8 acb); 398void dispc_set_pol_freq(enum omap_channel channel,
399 enum omap_panel_config config, u8 acbi, u8 acb);
395void dispc_find_clk_divs(bool is_tft, unsigned long req_pck, unsigned long fck, 400void dispc_find_clk_divs(bool is_tft, unsigned long req_pck, unsigned long fck,
396 struct dispc_clock_info *cinfo); 401 struct dispc_clock_info *cinfo);
397int dispc_calc_clock_rates(unsigned long dispc_fclk_rate, 402int dispc_calc_clock_rates(unsigned long dispc_fclk_rate,
398 struct dispc_clock_info *cinfo); 403 struct dispc_clock_info *cinfo);
399int dispc_set_clock_div(struct dispc_clock_info *cinfo); 404int dispc_set_clock_div(enum omap_channel channel,
400int dispc_get_clock_div(struct dispc_clock_info *cinfo); 405 struct dispc_clock_info *cinfo);
406int dispc_get_clock_div(enum omap_channel channel,
407 struct dispc_clock_info *cinfo);
401 408
402 409
403/* VENC */ 410/* VENC */
@@ -424,8 +431,8 @@ void rfbi_dump_regs(struct seq_file *s);
424 431
425int rfbi_configure(int rfbi_module, int bpp, int lines); 432int rfbi_configure(int rfbi_module, int bpp, int lines);
426void rfbi_enable_rfbi(bool enable); 433void rfbi_enable_rfbi(bool enable);
427void rfbi_transfer_area(u16 width, u16 height, 434void rfbi_transfer_area(struct omap_dss_device *dssdev, u16 width,
428 void (callback)(void *data), void *data); 435 u16 height, void (callback)(void *data), void *data);
429void rfbi_set_timings(int rfbi_module, struct rfbi_timings *t); 436void rfbi_set_timings(int rfbi_module, struct rfbi_timings *t);
430unsigned long rfbi_get_max_tx_rate(void); 437unsigned long rfbi_get_max_tx_rate(void);
431int rfbi_init_display(struct omap_dss_device *display); 438int rfbi_init_display(struct omap_dss_device *display);
diff --git a/drivers/video/omap2/dss/dss_features.c b/drivers/video/omap2/dss/dss_features.c
index 867f68de125f..cf3ef696e141 100644
--- a/drivers/video/omap2/dss/dss_features.c
+++ b/drivers/video/omap2/dss/dss_features.c
@@ -82,6 +82,18 @@ static const enum omap_display_type omap3_dss_supported_displays[] = {
82 OMAP_DISPLAY_TYPE_VENC, 82 OMAP_DISPLAY_TYPE_VENC,
83}; 83};
84 84
85static const enum omap_display_type omap4_dss_supported_displays[] = {
86 /* OMAP_DSS_CHANNEL_LCD */
87 OMAP_DISPLAY_TYPE_DBI | OMAP_DISPLAY_TYPE_DSI,
88
89 /* OMAP_DSS_CHANNEL_DIGIT */
90 OMAP_DISPLAY_TYPE_VENC,
91
92 /* OMAP_DSS_CHANNEL_LCD2 */
93 OMAP_DISPLAY_TYPE_DPI | OMAP_DISPLAY_TYPE_DBI |
94 OMAP_DISPLAY_TYPE_DSI,
95};
96
85static const enum omap_color_mode omap2_dss_supported_color_modes[] = { 97static const enum omap_color_mode omap2_dss_supported_color_modes[] = {
86 /* OMAP_DSS_GFX */ 98 /* OMAP_DSS_GFX */
87 OMAP_DSS_COLOR_CLUT1 | OMAP_DSS_COLOR_CLUT2 | 99 OMAP_DSS_COLOR_CLUT1 | OMAP_DSS_COLOR_CLUT2 |
@@ -127,6 +139,10 @@ static struct omap_dss_features omap2_dss_features = {
127 .reg_fields = omap2_dss_reg_fields, 139 .reg_fields = omap2_dss_reg_fields,
128 .num_reg_fields = ARRAY_SIZE(omap2_dss_reg_fields), 140 .num_reg_fields = ARRAY_SIZE(omap2_dss_reg_fields),
129 141
142 .has_feature =
143 FEAT_LCDENABLEPOL | FEAT_LCDENABLESIGNAL |
144 FEAT_PCKFREEENABLE | FEAT_FUNCGATED,
145
130 .num_mgrs = 2, 146 .num_mgrs = 2,
131 .num_ovls = 3, 147 .num_ovls = 3,
132 .supported_displays = omap2_dss_supported_displays, 148 .supported_displays = omap2_dss_supported_displays,
@@ -134,11 +150,29 @@ static struct omap_dss_features omap2_dss_features = {
134}; 150};
135 151
136/* OMAP3 DSS Features */ 152/* OMAP3 DSS Features */
137static struct omap_dss_features omap3_dss_features = { 153static struct omap_dss_features omap3430_dss_features = {
154 .reg_fields = omap3_dss_reg_fields,
155 .num_reg_fields = ARRAY_SIZE(omap3_dss_reg_fields),
156
157 .has_feature =
158 FEAT_GLOBAL_ALPHA | FEAT_LCDENABLEPOL |
159 FEAT_LCDENABLESIGNAL | FEAT_PCKFREEENABLE |
160 FEAT_FUNCGATED,
161
162 .num_mgrs = 2,
163 .num_ovls = 3,
164 .supported_displays = omap3_dss_supported_displays,
165 .supported_color_modes = omap3_dss_supported_color_modes,
166};
167
168static struct omap_dss_features omap3630_dss_features = {
138 .reg_fields = omap3_dss_reg_fields, 169 .reg_fields = omap3_dss_reg_fields,
139 .num_reg_fields = ARRAY_SIZE(omap3_dss_reg_fields), 170 .num_reg_fields = ARRAY_SIZE(omap3_dss_reg_fields),
140 171
141 .has_feature = FEAT_GLOBAL_ALPHA, 172 .has_feature =
173 FEAT_GLOBAL_ALPHA | FEAT_LCDENABLEPOL |
174 FEAT_LCDENABLESIGNAL | FEAT_PCKFREEENABLE |
175 FEAT_PRE_MULT_ALPHA | FEAT_FUNCGATED,
142 176
143 .num_mgrs = 2, 177 .num_mgrs = 2,
144 .num_ovls = 3, 178 .num_ovls = 3,
@@ -146,6 +180,21 @@ static struct omap_dss_features omap3_dss_features = {
146 .supported_color_modes = omap3_dss_supported_color_modes, 180 .supported_color_modes = omap3_dss_supported_color_modes,
147}; 181};
148 182
183/* OMAP4 DSS Features */
184static struct omap_dss_features omap4_dss_features = {
185 .reg_fields = omap3_dss_reg_fields,
186 .num_reg_fields = ARRAY_SIZE(omap3_dss_reg_fields),
187
188 .has_feature =
189 FEAT_GLOBAL_ALPHA | FEAT_PRE_MULT_ALPHA |
190 FEAT_MGR_LCD2,
191
192 .num_mgrs = 3,
193 .num_ovls = 3,
194 .supported_displays = omap4_dss_supported_displays,
195 .supported_color_modes = omap3_dss_supported_color_modes,
196};
197
149/* Functions returning values related to a DSS feature */ 198/* Functions returning values related to a DSS feature */
150int dss_feat_get_num_mgrs(void) 199int dss_feat_get_num_mgrs(void)
151{ 200{
@@ -167,6 +216,13 @@ enum omap_color_mode dss_feat_get_supported_color_modes(enum omap_plane plane)
167 return omap_current_dss_features->supported_color_modes[plane]; 216 return omap_current_dss_features->supported_color_modes[plane];
168} 217}
169 218
219bool dss_feat_color_mode_supported(enum omap_plane plane,
220 enum omap_color_mode color_mode)
221{
222 return omap_current_dss_features->supported_color_modes[plane] &
223 color_mode;
224}
225
170/* DSS has_feature check */ 226/* DSS has_feature check */
171bool dss_has_feature(enum dss_feat_id id) 227bool dss_has_feature(enum dss_feat_id id)
172{ 228{
@@ -186,6 +242,10 @@ void dss_features_init(void)
186{ 242{
187 if (cpu_is_omap24xx()) 243 if (cpu_is_omap24xx())
188 omap_current_dss_features = &omap2_dss_features; 244 omap_current_dss_features = &omap2_dss_features;
245 else if (cpu_is_omap3630())
246 omap_current_dss_features = &omap3630_dss_features;
247 else if (cpu_is_omap34xx())
248 omap_current_dss_features = &omap3430_dss_features;
189 else 249 else
190 omap_current_dss_features = &omap3_dss_features; 250 omap_current_dss_features = &omap4_dss_features;
191} 251}
diff --git a/drivers/video/omap2/dss/dss_features.h b/drivers/video/omap2/dss/dss_features.h
index cb231eaa9b31..b9c70be92588 100644
--- a/drivers/video/omap2/dss/dss_features.h
+++ b/drivers/video/omap2/dss/dss_features.h
@@ -20,13 +20,19 @@
20#ifndef __OMAP2_DSS_FEATURES_H 20#ifndef __OMAP2_DSS_FEATURES_H
21#define __OMAP2_DSS_FEATURES_H 21#define __OMAP2_DSS_FEATURES_H
22 22
23#define MAX_DSS_MANAGERS 2 23#define MAX_DSS_MANAGERS 3
24#define MAX_DSS_OVERLAYS 3 24#define MAX_DSS_OVERLAYS 3
25 25
26/* DSS has feature id */ 26/* DSS has feature id */
27enum dss_feat_id { 27enum dss_feat_id {
28 FEAT_GLOBAL_ALPHA = 1 << 0, 28 FEAT_GLOBAL_ALPHA = 1 << 0,
29 FEAT_GLOBAL_ALPHA_VID1 = 1 << 1, 29 FEAT_GLOBAL_ALPHA_VID1 = 1 << 1,
30 FEAT_PRE_MULT_ALPHA = 1 << 2,
31 FEAT_LCDENABLEPOL = 1 << 3,
32 FEAT_LCDENABLESIGNAL = 1 << 4,
33 FEAT_PCKFREEENABLE = 1 << 5,
34 FEAT_FUNCGATED = 1 << 6,
35 FEAT_MGR_LCD2 = 1 << 7,
30}; 36};
31 37
32/* DSS register field id */ 38/* DSS register field id */
@@ -43,6 +49,8 @@ int dss_feat_get_num_mgrs(void);
43int dss_feat_get_num_ovls(void); 49int dss_feat_get_num_ovls(void);
44enum omap_display_type dss_feat_get_supported_displays(enum omap_channel channel); 50enum omap_display_type dss_feat_get_supported_displays(enum omap_channel channel);
45enum omap_color_mode dss_feat_get_supported_color_modes(enum omap_plane plane); 51enum omap_color_mode dss_feat_get_supported_color_modes(enum omap_plane plane);
52bool dss_feat_color_mode_supported(enum omap_plane plane,
53 enum omap_color_mode color_mode);
46 54
47bool dss_has_feature(enum dss_feat_id id); 55bool dss_has_feature(enum dss_feat_id id);
48void dss_feat_get_reg_field(enum dss_feat_reg_field id, u8 *start, u8 *end); 56void dss_feat_get_reg_field(enum dss_feat_reg_field id, u8 *start, u8 *end);
diff --git a/drivers/video/omap2/dss/manager.c b/drivers/video/omap2/dss/manager.c
index 545e9b9a4d92..172d4e697309 100644
--- a/drivers/video/omap2/dss/manager.c
+++ b/drivers/video/omap2/dss/manager.c
@@ -406,6 +406,7 @@ struct overlay_cache_data {
406 u16 out_width; /* if 0, out_width == width */ 406 u16 out_width; /* if 0, out_width == width */
407 u16 out_height; /* if 0, out_height == height */ 407 u16 out_height; /* if 0, out_height == height */
408 u8 global_alpha; 408 u8 global_alpha;
409 u8 pre_mult_alpha;
409 410
410 enum omap_channel channel; 411 enum omap_channel channel;
411 bool replication; 412 bool replication;
@@ -512,11 +513,14 @@ static int dss_mgr_wait_for_vsync(struct omap_overlay_manager *mgr)
512 unsigned long timeout = msecs_to_jiffies(500); 513 unsigned long timeout = msecs_to_jiffies(500);
513 u32 irq; 514 u32 irq;
514 515
515 if (mgr->device->type == OMAP_DISPLAY_TYPE_VENC) 516 if (mgr->device->type == OMAP_DISPLAY_TYPE_VENC) {
516 irq = DISPC_IRQ_EVSYNC_ODD; 517 irq = DISPC_IRQ_EVSYNC_ODD;
517 else 518 } else {
518 irq = DISPC_IRQ_VSYNC; 519 if (mgr->id == OMAP_DSS_CHANNEL_LCD)
519 520 irq = DISPC_IRQ_VSYNC;
521 else
522 irq = DISPC_IRQ_VSYNC2;
523 }
520 return omap_dispc_wait_for_irq_interruptible_timeout(irq, timeout); 524 return omap_dispc_wait_for_irq_interruptible_timeout(irq, timeout);
521} 525}
522 526
@@ -524,7 +528,6 @@ static int dss_mgr_wait_for_go(struct omap_overlay_manager *mgr)
524{ 528{
525 unsigned long timeout = msecs_to_jiffies(500); 529 unsigned long timeout = msecs_to_jiffies(500);
526 struct manager_cache_data *mc; 530 struct manager_cache_data *mc;
527 enum omap_channel channel;
528 u32 irq; 531 u32 irq;
529 int r; 532 int r;
530 int i; 533 int i;
@@ -535,7 +538,6 @@ static int dss_mgr_wait_for_go(struct omap_overlay_manager *mgr)
535 538
536 if (dssdev->type == OMAP_DISPLAY_TYPE_VENC) { 539 if (dssdev->type == OMAP_DISPLAY_TYPE_VENC) {
537 irq = DISPC_IRQ_EVSYNC_ODD | DISPC_IRQ_EVSYNC_EVEN; 540 irq = DISPC_IRQ_EVSYNC_ODD | DISPC_IRQ_EVSYNC_EVEN;
538 channel = OMAP_DSS_CHANNEL_DIGIT;
539 } else { 541 } else {
540 if (dssdev->caps & OMAP_DSS_DISPLAY_CAP_MANUAL_UPDATE) { 542 if (dssdev->caps & OMAP_DSS_DISPLAY_CAP_MANUAL_UPDATE) {
541 enum omap_dss_update_mode mode; 543 enum omap_dss_update_mode mode;
@@ -543,11 +545,14 @@ static int dss_mgr_wait_for_go(struct omap_overlay_manager *mgr)
543 if (mode != OMAP_DSS_UPDATE_AUTO) 545 if (mode != OMAP_DSS_UPDATE_AUTO)
544 return 0; 546 return 0;
545 547
546 irq = DISPC_IRQ_FRAMEDONE; 548 irq = (dssdev->manager->id == OMAP_DSS_CHANNEL_LCD) ?
549 DISPC_IRQ_FRAMEDONE
550 : DISPC_IRQ_FRAMEDONE2;
547 } else { 551 } else {
548 irq = DISPC_IRQ_VSYNC; 552 irq = (dssdev->manager->id == OMAP_DSS_CHANNEL_LCD) ?
553 DISPC_IRQ_VSYNC
554 : DISPC_IRQ_VSYNC2;
549 } 555 }
550 channel = OMAP_DSS_CHANNEL_LCD;
551 } 556 }
552 557
553 mc = &dss_cache.manager_cache[mgr->id]; 558 mc = &dss_cache.manager_cache[mgr->id];
@@ -594,7 +599,6 @@ static int dss_mgr_wait_for_go(struct omap_overlay_manager *mgr)
594int dss_mgr_wait_for_go_ovl(struct omap_overlay *ovl) 599int dss_mgr_wait_for_go_ovl(struct omap_overlay *ovl)
595{ 600{
596 unsigned long timeout = msecs_to_jiffies(500); 601 unsigned long timeout = msecs_to_jiffies(500);
597 enum omap_channel channel;
598 struct overlay_cache_data *oc; 602 struct overlay_cache_data *oc;
599 struct omap_dss_device *dssdev; 603 struct omap_dss_device *dssdev;
600 u32 irq; 604 u32 irq;
@@ -611,7 +615,6 @@ int dss_mgr_wait_for_go_ovl(struct omap_overlay *ovl)
611 615
612 if (dssdev->type == OMAP_DISPLAY_TYPE_VENC) { 616 if (dssdev->type == OMAP_DISPLAY_TYPE_VENC) {
613 irq = DISPC_IRQ_EVSYNC_ODD | DISPC_IRQ_EVSYNC_EVEN; 617 irq = DISPC_IRQ_EVSYNC_ODD | DISPC_IRQ_EVSYNC_EVEN;
614 channel = OMAP_DSS_CHANNEL_DIGIT;
615 } else { 618 } else {
616 if (dssdev->caps & OMAP_DSS_DISPLAY_CAP_MANUAL_UPDATE) { 619 if (dssdev->caps & OMAP_DSS_DISPLAY_CAP_MANUAL_UPDATE) {
617 enum omap_dss_update_mode mode; 620 enum omap_dss_update_mode mode;
@@ -619,11 +622,14 @@ int dss_mgr_wait_for_go_ovl(struct omap_overlay *ovl)
619 if (mode != OMAP_DSS_UPDATE_AUTO) 622 if (mode != OMAP_DSS_UPDATE_AUTO)
620 return 0; 623 return 0;
621 624
622 irq = DISPC_IRQ_FRAMEDONE; 625 irq = (dssdev->manager->id == OMAP_DSS_CHANNEL_LCD) ?
626 DISPC_IRQ_FRAMEDONE
627 : DISPC_IRQ_FRAMEDONE2;
623 } else { 628 } else {
624 irq = DISPC_IRQ_VSYNC; 629 irq = (dssdev->manager->id == OMAP_DSS_CHANNEL_LCD) ?
630 DISPC_IRQ_VSYNC
631 : DISPC_IRQ_VSYNC2;
625 } 632 }
626 channel = OMAP_DSS_CHANNEL_LCD;
627 } 633 }
628 634
629 oc = &dss_cache.overlay_cache[ovl->id]; 635 oc = &dss_cache.overlay_cache[ovl->id];
@@ -842,7 +848,9 @@ static int configure_overlay(enum omap_plane plane)
842 c->rotation_type, 848 c->rotation_type,
843 c->rotation, 849 c->rotation,
844 c->mirror, 850 c->mirror,
845 c->global_alpha); 851 c->global_alpha,
852 c->pre_mult_alpha,
853 c->channel);
846 854
847 if (r) { 855 if (r) {
848 /* this shouldn't happen */ 856 /* this shouldn't happen */
@@ -894,10 +902,10 @@ static int configure_dispc(void)
894 r = 0; 902 r = 0;
895 busy = false; 903 busy = false;
896 904
897 mgr_busy[0] = dispc_go_busy(0); 905 for (i = 0; i < num_mgrs; i++) {
898 mgr_busy[1] = dispc_go_busy(1); 906 mgr_busy[i] = dispc_go_busy(i);
899 mgr_go[0] = false; 907 mgr_go[i] = false;
900 mgr_go[1] = false; 908 }
901 909
902 /* Commit overlay settings */ 910 /* Commit overlay settings */
903 for (i = 0; i < num_ovls; ++i) { 911 for (i = 0; i < num_ovls; ++i) {
@@ -1156,9 +1164,10 @@ static void dss_apply_irq_handler(void *data, u32 mask)
1156 const int num_mgrs = dss_feat_get_num_mgrs(); 1164 const int num_mgrs = dss_feat_get_num_mgrs();
1157 int i, r; 1165 int i, r;
1158 bool mgr_busy[MAX_DSS_MANAGERS]; 1166 bool mgr_busy[MAX_DSS_MANAGERS];
1167 u32 irq_mask;
1159 1168
1160 mgr_busy[0] = dispc_go_busy(0); 1169 for (i = 0; i < num_mgrs; i++)
1161 mgr_busy[1] = dispc_go_busy(1); 1170 mgr_busy[i] = dispc_go_busy(i);
1162 1171
1163 spin_lock(&dss_cache.lock); 1172 spin_lock(&dss_cache.lock);
1164 1173
@@ -1179,8 +1188,8 @@ static void dss_apply_irq_handler(void *data, u32 mask)
1179 goto end; 1188 goto end;
1180 1189
1181 /* re-read busy flags */ 1190 /* re-read busy flags */
1182 mgr_busy[0] = dispc_go_busy(0); 1191 for (i = 0; i < num_mgrs; i++)
1183 mgr_busy[1] = dispc_go_busy(1); 1192 mgr_busy[i] = dispc_go_busy(i);
1184 1193
1185 /* keep running as long as there are busy managers, so that 1194 /* keep running as long as there are busy managers, so that
1186 * we can collect overlay-applied information */ 1195 * we can collect overlay-applied information */
@@ -1189,9 +1198,12 @@ static void dss_apply_irq_handler(void *data, u32 mask)
1189 goto end; 1198 goto end;
1190 } 1199 }
1191 1200
1192 omap_dispc_unregister_isr(dss_apply_irq_handler, NULL, 1201 irq_mask = DISPC_IRQ_VSYNC | DISPC_IRQ_EVSYNC_ODD |
1193 DISPC_IRQ_VSYNC | DISPC_IRQ_EVSYNC_ODD | 1202 DISPC_IRQ_EVSYNC_EVEN;
1194 DISPC_IRQ_EVSYNC_EVEN); 1203 if (dss_has_feature(FEAT_MGR_LCD2))
1204 irq_mask |= DISPC_IRQ_VSYNC2;
1205
1206 omap_dispc_unregister_isr(dss_apply_irq_handler, NULL, irq_mask);
1195 dss_cache.irq_enabled = false; 1207 dss_cache.irq_enabled = false;
1196 1208
1197end: 1209end:
@@ -1265,6 +1277,7 @@ static int omap_dss_mgr_apply(struct omap_overlay_manager *mgr)
1265 oc->out_width = ovl->info.out_width; 1277 oc->out_width = ovl->info.out_width;
1266 oc->out_height = ovl->info.out_height; 1278 oc->out_height = ovl->info.out_height;
1267 oc->global_alpha = ovl->info.global_alpha; 1279 oc->global_alpha = ovl->info.global_alpha;
1280 oc->pre_mult_alpha = ovl->info.pre_mult_alpha;
1268 1281
1269 oc->replication = 1282 oc->replication =
1270 dss_use_replication(dssdev, ovl->info.color_mode); 1283 dss_use_replication(dssdev, ovl->info.color_mode);
@@ -1383,9 +1396,14 @@ static int omap_dss_mgr_apply(struct omap_overlay_manager *mgr)
1383 r = 0; 1396 r = 0;
1384 dss_clk_enable(DSS_CLK_ICK | DSS_CLK_FCK1); 1397 dss_clk_enable(DSS_CLK_ICK | DSS_CLK_FCK1);
1385 if (!dss_cache.irq_enabled) { 1398 if (!dss_cache.irq_enabled) {
1386 r = omap_dispc_register_isr(dss_apply_irq_handler, NULL, 1399 u32 mask;
1387 DISPC_IRQ_VSYNC | DISPC_IRQ_EVSYNC_ODD | 1400
1388 DISPC_IRQ_EVSYNC_EVEN); 1401 mask = DISPC_IRQ_VSYNC | DISPC_IRQ_EVSYNC_ODD |
1402 DISPC_IRQ_EVSYNC_EVEN;
1403 if (dss_has_feature(FEAT_MGR_LCD2))
1404 mask |= DISPC_IRQ_VSYNC2;
1405
1406 r = omap_dispc_register_isr(dss_apply_irq_handler, NULL, mask);
1389 dss_cache.irq_enabled = true; 1407 dss_cache.irq_enabled = true;
1390 } 1408 }
1391 configure_dispc(); 1409 configure_dispc();
@@ -1477,6 +1495,10 @@ int dss_init_overlay_managers(struct platform_device *pdev)
1477 mgr->name = "tv"; 1495 mgr->name = "tv";
1478 mgr->id = OMAP_DSS_CHANNEL_DIGIT; 1496 mgr->id = OMAP_DSS_CHANNEL_DIGIT;
1479 break; 1497 break;
1498 case 2:
1499 mgr->name = "lcd2";
1500 mgr->id = OMAP_DSS_CHANNEL_LCD2;
1501 break;
1480 } 1502 }
1481 1503
1482 mgr->set_device = &omap_dss_set_device; 1504 mgr->set_device = &omap_dss_set_device;
diff --git a/drivers/video/omap2/dss/overlay.c b/drivers/video/omap2/dss/overlay.c
index 75642c22cac7..456efef03c20 100644
--- a/drivers/video/omap2/dss/overlay.c
+++ b/drivers/video/omap2/dss/overlay.c
@@ -257,6 +257,43 @@ static ssize_t overlay_global_alpha_store(struct omap_overlay *ovl,
257 return size; 257 return size;
258} 258}
259 259
260static ssize_t overlay_pre_mult_alpha_show(struct omap_overlay *ovl,
261 char *buf)
262{
263 return snprintf(buf, PAGE_SIZE, "%d\n",
264 ovl->info.pre_mult_alpha);
265}
266
267static ssize_t overlay_pre_mult_alpha_store(struct omap_overlay *ovl,
268 const char *buf, size_t size)
269{
270 int r;
271 struct omap_overlay_info info;
272
273 ovl->get_overlay_info(ovl, &info);
274
275 /* only GFX and Video2 plane support pre alpha multiplied
276 * set zero for Video1 plane
277 */
278 if (!dss_has_feature(FEAT_GLOBAL_ALPHA_VID1) &&
279 ovl->id == OMAP_DSS_VIDEO1)
280 info.pre_mult_alpha = 0;
281 else
282 info.pre_mult_alpha = simple_strtoul(buf, NULL, 10);
283
284 r = ovl->set_overlay_info(ovl, &info);
285 if (r)
286 return r;
287
288 if (ovl->manager) {
289 r = ovl->manager->apply(ovl->manager);
290 if (r)
291 return r;
292 }
293
294 return size;
295}
296
260struct overlay_attribute { 297struct overlay_attribute {
261 struct attribute attr; 298 struct attribute attr;
262 ssize_t (*show)(struct omap_overlay *, char *); 299 ssize_t (*show)(struct omap_overlay *, char *);
@@ -280,6 +317,9 @@ static OVERLAY_ATTR(enabled, S_IRUGO|S_IWUSR,
280 overlay_enabled_show, overlay_enabled_store); 317 overlay_enabled_show, overlay_enabled_store);
281static OVERLAY_ATTR(global_alpha, S_IRUGO|S_IWUSR, 318static OVERLAY_ATTR(global_alpha, S_IRUGO|S_IWUSR,
282 overlay_global_alpha_show, overlay_global_alpha_store); 319 overlay_global_alpha_show, overlay_global_alpha_store);
320static OVERLAY_ATTR(pre_mult_alpha, S_IRUGO|S_IWUSR,
321 overlay_pre_mult_alpha_show,
322 overlay_pre_mult_alpha_store);
283 323
284static struct attribute *overlay_sysfs_attrs[] = { 324static struct attribute *overlay_sysfs_attrs[] = {
285 &overlay_attr_name.attr, 325 &overlay_attr_name.attr,
@@ -290,6 +330,7 @@ static struct attribute *overlay_sysfs_attrs[] = {
290 &overlay_attr_output_size.attr, 330 &overlay_attr_output_size.attr,
291 &overlay_attr_enabled.attr, 331 &overlay_attr_enabled.attr,
292 &overlay_attr_global_alpha.attr, 332 &overlay_attr_global_alpha.attr,
333 &overlay_attr_pre_mult_alpha.attr,
293 NULL 334 NULL
294}; 335};
295 336
@@ -623,12 +664,22 @@ void dss_recheck_connections(struct omap_dss_device *dssdev, bool force)
623 int i; 664 int i;
624 struct omap_overlay_manager *lcd_mgr; 665 struct omap_overlay_manager *lcd_mgr;
625 struct omap_overlay_manager *tv_mgr; 666 struct omap_overlay_manager *tv_mgr;
667 struct omap_overlay_manager *lcd2_mgr = NULL;
626 struct omap_overlay_manager *mgr = NULL; 668 struct omap_overlay_manager *mgr = NULL;
627 669
628 lcd_mgr = omap_dss_get_overlay_manager(OMAP_DSS_OVL_MGR_LCD); 670 lcd_mgr = omap_dss_get_overlay_manager(OMAP_DSS_OVL_MGR_LCD);
629 tv_mgr = omap_dss_get_overlay_manager(OMAP_DSS_OVL_MGR_TV); 671 tv_mgr = omap_dss_get_overlay_manager(OMAP_DSS_OVL_MGR_TV);
630 672 if (dss_has_feature(FEAT_MGR_LCD2))
631 if (dssdev->type != OMAP_DISPLAY_TYPE_VENC) { 673 lcd2_mgr = omap_dss_get_overlay_manager(OMAP_DSS_OVL_MGR_LCD2);
674
675 if (dssdev->channel == OMAP_DSS_CHANNEL_LCD2) {
676 if (!lcd2_mgr->device || force) {
677 if (lcd2_mgr->device)
678 lcd2_mgr->unset_device(lcd2_mgr);
679 lcd2_mgr->set_device(lcd2_mgr, dssdev);
680 mgr = lcd2_mgr;
681 }
682 } else if (dssdev->type != OMAP_DISPLAY_TYPE_VENC) {
632 if (!lcd_mgr->device || force) { 683 if (!lcd_mgr->device || force) {
633 if (lcd_mgr->device) 684 if (lcd_mgr->device)
634 lcd_mgr->unset_device(lcd_mgr); 685 lcd_mgr->unset_device(lcd_mgr);
diff --git a/drivers/video/omap2/dss/rfbi.c b/drivers/video/omap2/dss/rfbi.c
index bbe62464e92d..10a2ffe02882 100644
--- a/drivers/video/omap2/dss/rfbi.c
+++ b/drivers/video/omap2/dss/rfbi.c
@@ -301,8 +301,8 @@ void omap_rfbi_write_pixels(const void __iomem *buf, int scr_width,
301} 301}
302EXPORT_SYMBOL(omap_rfbi_write_pixels); 302EXPORT_SYMBOL(omap_rfbi_write_pixels);
303 303
304void rfbi_transfer_area(u16 width, u16 height, 304void rfbi_transfer_area(struct omap_dss_device *dssdev, u16 width,
305 void (callback)(void *data), void *data) 305 u16 height, void (*callback)(void *data), void *data)
306{ 306{
307 u32 l; 307 u32 l;
308 308
@@ -311,9 +311,9 @@ void rfbi_transfer_area(u16 width, u16 height,
311 311
312 DSSDBG("rfbi_transfer_area %dx%d\n", width, height); 312 DSSDBG("rfbi_transfer_area %dx%d\n", width, height);
313 313
314 dispc_set_lcd_size(width, height); 314 dispc_set_lcd_size(dssdev->manager->id, width, height);
315 315
316 dispc_enable_channel(OMAP_DSS_CHANNEL_LCD, true); 316 dispc_enable_channel(dssdev->manager->id, true);
317 317
318 rfbi.framedone_callback = callback; 318 rfbi.framedone_callback = callback;
319 rfbi.framedone_callback_data = data; 319 rfbi.framedone_callback_data = data;
@@ -887,7 +887,7 @@ int omap_rfbi_prepare_update(struct omap_dss_device *dssdev,
887 887
888 if (dssdev->manager->caps & OMAP_DSS_OVL_MGR_CAP_DISPC) { 888 if (dssdev->manager->caps & OMAP_DSS_OVL_MGR_CAP_DISPC) {
889 dss_setup_partial_planes(dssdev, x, y, w, h, true); 889 dss_setup_partial_planes(dssdev, x, y, w, h, true);
890 dispc_set_lcd_size(*w, *h); 890 dispc_set_lcd_size(dssdev->manager->id, *w, *h);
891 } 891 }
892 892
893 return 0; 893 return 0;
@@ -899,7 +899,7 @@ int omap_rfbi_update(struct omap_dss_device *dssdev,
899 void (*callback)(void *), void *data) 899 void (*callback)(void *), void *data)
900{ 900{
901 if (dssdev->manager->caps & OMAP_DSS_OVL_MGR_CAP_DISPC) { 901 if (dssdev->manager->caps & OMAP_DSS_OVL_MGR_CAP_DISPC) {
902 rfbi_transfer_area(w, h, callback, data); 902 rfbi_transfer_area(dssdev, w, h, callback, data);
903 } else { 903 } else {
904 struct omap_overlay *ovl; 904 struct omap_overlay *ovl;
905 void __iomem *addr; 905 void __iomem *addr;
@@ -1018,11 +1018,13 @@ int omapdss_rfbi_display_enable(struct omap_dss_device *dssdev)
1018 goto err1; 1018 goto err1;
1019 } 1019 }
1020 1020
1021 dispc_set_lcd_display_type(OMAP_DSS_LCD_DISPLAY_TFT); 1021 dispc_set_lcd_display_type(dssdev->manager->id,
1022 OMAP_DSS_LCD_DISPLAY_TFT);
1022 1023
1023 dispc_set_parallel_interface_mode(OMAP_DSS_PARALLELMODE_RFBI); 1024 dispc_set_parallel_interface_mode(dssdev->manager->id,
1025 OMAP_DSS_PARALLELMODE_RFBI);
1024 1026
1025 dispc_set_tft_data_lines(dssdev->ctrl.pixel_size); 1027 dispc_set_tft_data_lines(dssdev->manager->id, dssdev->ctrl.pixel_size);
1026 1028
1027 rfbi_configure(dssdev->phy.rfbi.channel, 1029 rfbi_configure(dssdev->phy.rfbi.channel,
1028 dssdev->ctrl.pixel_size, 1030 dssdev->ctrl.pixel_size,
diff --git a/drivers/video/omap2/dss/sdi.c b/drivers/video/omap2/dss/sdi.c
index ee07a3cc22ef..b64adf7dfc88 100644
--- a/drivers/video/omap2/dss/sdi.c
+++ b/drivers/video/omap2/dss/sdi.c
@@ -35,12 +35,16 @@ static struct {
35 struct regulator *vdds_sdi_reg; 35 struct regulator *vdds_sdi_reg;
36} sdi; 36} sdi;
37 37
38static void sdi_basic_init(void) 38static void sdi_basic_init(struct omap_dss_device *dssdev)
39
39{ 40{
40 dispc_set_parallel_interface_mode(OMAP_DSS_PARALLELMODE_BYPASS); 41 dispc_set_parallel_interface_mode(dssdev->manager->id,
42 OMAP_DSS_PARALLELMODE_BYPASS);
43
44 dispc_set_lcd_display_type(dssdev->manager->id,
45 OMAP_DSS_LCD_DISPLAY_TFT);
41 46
42 dispc_set_lcd_display_type(OMAP_DSS_LCD_DISPLAY_TFT); 47 dispc_set_tft_data_lines(dssdev->manager->id, 24);
43 dispc_set_tft_data_lines(24);
44 dispc_lcd_enable_signal_polarity(1); 48 dispc_lcd_enable_signal_polarity(1);
45} 49}
46 50
@@ -68,20 +72,20 @@ int omapdss_sdi_display_enable(struct omap_dss_device *dssdev)
68 if (!sdi.skip_init) 72 if (!sdi.skip_init)
69 dss_clk_enable(DSS_CLK_ICK | DSS_CLK_FCK1); 73 dss_clk_enable(DSS_CLK_ICK | DSS_CLK_FCK1);
70 74
71 sdi_basic_init(); 75 sdi_basic_init(dssdev);
72 76
73 /* 15.5.9.1.2 */ 77 /* 15.5.9.1.2 */
74 dssdev->panel.config |= OMAP_DSS_LCD_RF | OMAP_DSS_LCD_ONOFF; 78 dssdev->panel.config |= OMAP_DSS_LCD_RF | OMAP_DSS_LCD_ONOFF;
75 79
76 dispc_set_pol_freq(dssdev->panel.config, dssdev->panel.acbi, 80 dispc_set_pol_freq(dssdev->manager->id, dssdev->panel.config,
77 dssdev->panel.acb); 81 dssdev->panel.acbi, dssdev->panel.acb);
78 82
79 if (!sdi.skip_init) { 83 if (!sdi.skip_init) {
80 r = dss_calc_clock_div(1, t->pixel_clock * 1000, 84 r = dss_calc_clock_div(1, t->pixel_clock * 1000,
81 &dss_cinfo, &dispc_cinfo); 85 &dss_cinfo, &dispc_cinfo);
82 } else { 86 } else {
83 r = dss_get_clock_div(&dss_cinfo); 87 r = dss_get_clock_div(&dss_cinfo);
84 r = dispc_get_clock_div(&dispc_cinfo); 88 r = dispc_get_clock_div(dssdev->manager->id, &dispc_cinfo);
85 } 89 }
86 90
87 if (r) 91 if (r)
@@ -102,13 +106,13 @@ int omapdss_sdi_display_enable(struct omap_dss_device *dssdev)
102 } 106 }
103 107
104 108
105 dispc_set_lcd_timings(t); 109 dispc_set_lcd_timings(dssdev->manager->id, t);
106 110
107 r = dss_set_clock_div(&dss_cinfo); 111 r = dss_set_clock_div(&dss_cinfo);
108 if (r) 112 if (r)
109 goto err2; 113 goto err2;
110 114
111 r = dispc_set_clock_div(&dispc_cinfo); 115 r = dispc_set_clock_div(dssdev->manager->id, &dispc_cinfo);
112 if (r) 116 if (r)
113 goto err2; 117 goto err2;
114 118
diff --git a/drivers/video/omap2/omapfb/omapfb-main.c b/drivers/video/omap2/omapfb/omapfb-main.c
index 6a704f176c22..4fdab8e9c496 100644
--- a/drivers/video/omap2/omapfb/omapfb-main.c
+++ b/drivers/video/omap2/omapfb/omapfb-main.c
@@ -2132,8 +2132,9 @@ static int omapfb_parse_def_modes(struct omapfb2_device *fbdev)
2132 char *str, *options, *this_opt; 2132 char *str, *options, *this_opt;
2133 int r = 0; 2133 int r = 0;
2134 2134
2135 str = kmalloc(strlen(def_mode) + 1, GFP_KERNEL); 2135 str = kstrdup(def_mode, GFP_KERNEL);
2136 strcpy(str, def_mode); 2136 if (!str)
2137 return -ENOMEM;
2137 options = str; 2138 options = str;
2138 2139
2139 while (!r && (this_opt = strsep(&options, ",")) != NULL) { 2140 while (!r && (this_opt = strsep(&options, ",")) != NULL) {
diff --git a/drivers/video/riva/fbdev.c b/drivers/video/riva/fbdev.c
index 618f36bec10d..da388186d617 100644
--- a/drivers/video/riva/fbdev.c
+++ b/drivers/video/riva/fbdev.c
@@ -331,7 +331,7 @@ static int riva_bl_get_brightness(struct backlight_device *bd)
331 return bd->props.brightness; 331 return bd->props.brightness;
332} 332}
333 333
334static struct backlight_ops riva_bl_ops = { 334static const struct backlight_ops riva_bl_ops = {
335 .get_brightness = riva_bl_get_brightness, 335 .get_brightness = riva_bl_get_brightness,
336 .update_status = riva_bl_update_status, 336 .update_status = riva_bl_update_status,
337}; 337};
diff --git a/drivers/video/s3c2410fb.c b/drivers/video/s3c2410fb.c
index 46b430978bcc..61c819e35f7f 100644
--- a/drivers/video/s3c2410fb.c
+++ b/drivers/video/s3c2410fb.c
@@ -13,6 +13,7 @@
13 13
14#include <linux/module.h> 14#include <linux/module.h>
15#include <linux/kernel.h> 15#include <linux/kernel.h>
16#include <linux/err.h>
16#include <linux/errno.h> 17#include <linux/errno.h>
17#include <linux/string.h> 18#include <linux/string.h>
18#include <linux/mm.h> 19#include <linux/mm.h>
@@ -918,9 +919,9 @@ static int __devinit s3c24xxfb_probe(struct platform_device *pdev,
918 } 919 }
919 920
920 info->clk = clk_get(NULL, "lcd"); 921 info->clk = clk_get(NULL, "lcd");
921 if (!info->clk || IS_ERR(info->clk)) { 922 if (IS_ERR(info->clk)) {
922 printk(KERN_ERR "failed to get lcd clock source\n"); 923 printk(KERN_ERR "failed to get lcd clock source\n");
923 ret = -ENOENT; 924 ret = PTR_ERR(info->clk);
924 goto release_irq; 925 goto release_irq;
925 } 926 }
926 927
diff --git a/drivers/video/sh_mobile_hdmi.c b/drivers/video/sh_mobile_hdmi.c
index 8c59cc8c5a9c..74d9f546a2e8 100644
--- a/drivers/video/sh_mobile_hdmi.c
+++ b/drivers/video/sh_mobile_hdmi.c
@@ -22,6 +22,7 @@
22#include <linux/slab.h> 22#include <linux/slab.h>
23#include <linux/types.h> 23#include <linux/types.h>
24#include <linux/workqueue.h> 24#include <linux/workqueue.h>
25#include <sound/soc.h>
25#include <sound/soc-dapm.h> 26#include <sound/soc-dapm.h>
26#include <sound/initval.h> 27#include <sound/initval.h>
27 28
@@ -221,6 +222,7 @@ struct sh_hdmi {
221 struct delayed_work edid_work; 222 struct delayed_work edid_work;
222 struct fb_var_screeninfo var; 223 struct fb_var_screeninfo var;
223 struct fb_monspecs monspec; 224 struct fb_monspecs monspec;
225 struct notifier_block notifier;
224}; 226};
225 227
226static void hdmi_write(struct sh_hdmi *hdmi, u8 data, u8 reg) 228static void hdmi_write(struct sh_hdmi *hdmi, u8 data, u8 reg)
@@ -737,7 +739,7 @@ static int sh_hdmi_read_edid(struct sh_hdmi *hdmi, unsigned long *hdmi_rate,
737 struct fb_modelist *modelist = NULL; 739 struct fb_modelist *modelist = NULL;
738 unsigned int f_width = 0, f_height = 0, f_refresh = 0; 740 unsigned int f_width = 0, f_height = 0, f_refresh = 0;
739 unsigned long found_rate_error = ULONG_MAX; /* silly compiler... */ 741 unsigned long found_rate_error = ULONG_MAX; /* silly compiler... */
740 bool exact_match = false; 742 bool scanning = false, preferred_bad = false;
741 u8 edid[128]; 743 u8 edid[128];
742 char *forced; 744 char *forced;
743 int i; 745 int i;
@@ -800,6 +802,9 @@ static int sh_hdmi_read_edid(struct sh_hdmi *hdmi, unsigned long *hdmi_rate,
800 if (i < 2) { 802 if (i < 2) {
801 f_width = 0; 803 f_width = 0;
802 f_height = 0; 804 f_height = 0;
805 } else {
806 /* The user wants us to use the EDID data */
807 scanning = true;
803 } 808 }
804 dev_dbg(hdmi->dev, "Forced mode %ux%u@%uHz\n", 809 dev_dbg(hdmi->dev, "Forced mode %ux%u@%uHz\n",
805 f_width, f_height, f_refresh); 810 f_width, f_height, f_refresh);
@@ -807,37 +812,56 @@ static int sh_hdmi_read_edid(struct sh_hdmi *hdmi, unsigned long *hdmi_rate,
807 812
808 /* Walk monitor modes to find the best or the exact match */ 813 /* Walk monitor modes to find the best or the exact match */
809 for (i = 0, mode = hdmi->monspec.modedb; 814 for (i = 0, mode = hdmi->monspec.modedb;
810 f_width && f_height && i < hdmi->monspec.modedb_len && !exact_match; 815 i < hdmi->monspec.modedb_len && scanning;
811 i++, mode++) { 816 i++, mode++) {
812 unsigned long rate_error; 817 unsigned long rate_error;
813 818
814 /* No interest in unmatching modes */ 819 if (!f_width && !f_height) {
815 if (f_width != mode->xres || f_height != mode->yres) 820 /*
821 * A parameter string "video=sh_mobile_lcdc:0x0" means
822 * use the preferred EDID mode. If it is rejected by
823 * .fb_check_var(), keep looking, until an acceptable
824 * one is found.
825 */
826 if ((mode->flag & FB_MODE_IS_FIRST) || preferred_bad)
827 scanning = false;
828 else
829 continue;
830 } else if (f_width != mode->xres || f_height != mode->yres) {
831 /* No interest in unmatching modes */
816 continue; 832 continue;
833 }
817 834
818 rate_error = sh_hdmi_rate_error(hdmi, mode, hdmi_rate, parent_rate); 835 rate_error = sh_hdmi_rate_error(hdmi, mode, hdmi_rate, parent_rate);
819 836
820 if (f_refresh == mode->refresh || (!f_refresh && !rate_error)) 837 if (scanning) {
821 /* 838 if (f_refresh == mode->refresh || (!f_refresh && !rate_error))
822 * Exact match if either the refresh rate matches or it 839 /*
823 * hasn't been specified and we've found a mode, for 840 * Exact match if either the refresh rate
824 * which we can configure the clock precisely 841 * matches or it hasn't been specified and we've
825 */ 842 * found a mode, for which we can configure the
826 exact_match = true; 843 * clock precisely
827 else if (found && found_rate_error <= rate_error) 844 */
828 /* 845 scanning = false;
829 * We otherwise search for the closest matching clock 846 else if (found && found_rate_error <= rate_error)
830 * rate - either if no refresh rate has been specified 847 /*
831 * or we cannot find an exactly matching one 848 * We otherwise search for the closest matching
832 */ 849 * clock rate - either if no refresh rate has
833 continue; 850 * been specified or we cannot find an exactly
851 * matching one
852 */
853 continue;
854 }
834 855
835 /* Check if supported: sufficient fb memory, supported clock-rate */ 856 /* Check if supported: sufficient fb memory, supported clock-rate */
836 fb_videomode_to_var(var, mode); 857 fb_videomode_to_var(var, mode);
837 858
859 var->bits_per_pixel = info->var.bits_per_pixel;
860
838 if (info && info->fbops->fb_check_var && 861 if (info && info->fbops->fb_check_var &&
839 info->fbops->fb_check_var(var, info)) { 862 info->fbops->fb_check_var(var, info)) {
840 exact_match = false; 863 scanning = true;
864 preferred_bad = true;
841 continue; 865 continue;
842 } 866 }
843 867
@@ -855,9 +879,9 @@ static int sh_hdmi_read_edid(struct sh_hdmi *hdmi, unsigned long *hdmi_rate,
855 * driver, and passing ->info with HDMI platform data. 879 * driver, and passing ->info with HDMI platform data.
856 */ 880 */
857 if (info && !found) { 881 if (info && !found) {
858 modelist = hdmi->info->modelist.next && 882 modelist = info->modelist.next &&
859 !list_empty(&hdmi->info->modelist) ? 883 !list_empty(&info->modelist) ?
860 list_entry(hdmi->info->modelist.next, 884 list_entry(info->modelist.next,
861 struct fb_modelist, list) : 885 struct fb_modelist, list) :
862 NULL; 886 NULL;
863 887
@@ -1100,6 +1124,7 @@ static void sh_hdmi_edid_work_fn(struct work_struct *work)
1100 mutex_lock(&hdmi->mutex); 1124 mutex_lock(&hdmi->mutex);
1101 1125
1102 if (hdmi->hp_state == HDMI_HOTPLUG_CONNECTED) { 1126 if (hdmi->hp_state == HDMI_HOTPLUG_CONNECTED) {
1127 struct fb_info *info = hdmi->info;
1103 unsigned long parent_rate = 0, hdmi_rate; 1128 unsigned long parent_rate = 0, hdmi_rate;
1104 1129
1105 /* A device has been plugged in */ 1130 /* A device has been plugged in */
@@ -1121,22 +1146,21 @@ static void sh_hdmi_edid_work_fn(struct work_struct *work)
1121 /* Switched to another (d) power-save mode */ 1146 /* Switched to another (d) power-save mode */
1122 msleep(10); 1147 msleep(10);
1123 1148
1124 if (!hdmi->info) 1149 if (!info)
1125 goto out; 1150 goto out;
1126 1151
1127 ch = hdmi->info->par; 1152 ch = info->par;
1128 1153
1129 acquire_console_sem(); 1154 acquire_console_sem();
1130 1155
1131 /* HDMI plug in */ 1156 /* HDMI plug in */
1132 if (!sh_hdmi_must_reconfigure(hdmi) && 1157 if (!sh_hdmi_must_reconfigure(hdmi) &&
1133 hdmi->info->state == FBINFO_STATE_RUNNING) { 1158 info->state == FBINFO_STATE_RUNNING) {
1134 /* 1159 /*
1135 * First activation with the default monitor - just turn 1160 * First activation with the default monitor - just turn
1136 * on, if we run a resume here, the logo disappears 1161 * on, if we run a resume here, the logo disappears
1137 */ 1162 */
1138 if (lock_fb_info(hdmi->info)) { 1163 if (lock_fb_info(info)) {
1139 struct fb_info *info = hdmi->info;
1140 info->var.width = hdmi->var.width; 1164 info->var.width = hdmi->var.width;
1141 info->var.height = hdmi->var.height; 1165 info->var.height = hdmi->var.height;
1142 sh_hdmi_display_on(hdmi, info); 1166 sh_hdmi_display_on(hdmi, info);
@@ -1144,7 +1168,7 @@ static void sh_hdmi_edid_work_fn(struct work_struct *work)
1144 } 1168 }
1145 } else { 1169 } else {
1146 /* New monitor or have to wake up */ 1170 /* New monitor or have to wake up */
1147 fb_set_suspend(hdmi->info, 0); 1171 fb_set_suspend(info, 0);
1148 } 1172 }
1149 1173
1150 release_console_sem(); 1174 release_console_sem();
@@ -1175,13 +1199,6 @@ out:
1175} 1199}
1176 1200
1177static int sh_hdmi_notify(struct notifier_block *nb, 1201static int sh_hdmi_notify(struct notifier_block *nb,
1178 unsigned long action, void *data);
1179
1180static struct notifier_block sh_hdmi_notifier = {
1181 .notifier_call = sh_hdmi_notify,
1182};
1183
1184static int sh_hdmi_notify(struct notifier_block *nb,
1185 unsigned long action, void *data) 1202 unsigned long action, void *data)
1186{ 1203{
1187 struct fb_event *event = data; 1204 struct fb_event *event = data;
@@ -1190,7 +1207,7 @@ static int sh_hdmi_notify(struct notifier_block *nb,
1190 struct sh_mobile_lcdc_board_cfg *board_cfg = &ch->cfg.board_cfg; 1207 struct sh_mobile_lcdc_board_cfg *board_cfg = &ch->cfg.board_cfg;
1191 struct sh_hdmi *hdmi = board_cfg->board_data; 1208 struct sh_hdmi *hdmi = board_cfg->board_data;
1192 1209
1193 if (nb != &sh_hdmi_notifier || !hdmi || hdmi->info != info) 1210 if (!hdmi || nb != &hdmi->notifier || hdmi->info != info)
1194 return NOTIFY_DONE; 1211 return NOTIFY_DONE;
1195 1212
1196 switch(action) { 1213 switch(action) {
@@ -1209,11 +1226,11 @@ static int sh_hdmi_notify(struct notifier_block *nb,
1209 * temporarily, synchronise with the work queue and re-acquire 1226 * temporarily, synchronise with the work queue and re-acquire
1210 * the info->lock. 1227 * the info->lock.
1211 */ 1228 */
1212 unlock_fb_info(hdmi->info); 1229 unlock_fb_info(info);
1213 mutex_lock(&hdmi->mutex); 1230 mutex_lock(&hdmi->mutex);
1214 hdmi->info = NULL; 1231 hdmi->info = NULL;
1215 mutex_unlock(&hdmi->mutex); 1232 mutex_unlock(&hdmi->mutex);
1216 lock_fb_info(hdmi->info); 1233 lock_fb_info(info);
1217 return NOTIFY_OK; 1234 return NOTIFY_OK;
1218 } 1235 }
1219 return NOTIFY_DONE; 1236 return NOTIFY_DONE;
@@ -1311,6 +1328,9 @@ static int __init sh_hdmi_probe(struct platform_device *pdev)
1311 goto ecodec; 1328 goto ecodec;
1312 } 1329 }
1313 1330
1331 hdmi->notifier.notifier_call = sh_hdmi_notify;
1332 fb_register_client(&hdmi->notifier);
1333
1314 return 0; 1334 return 0;
1315 1335
1316ecodec: 1336ecodec:
@@ -1341,6 +1361,8 @@ static int __exit sh_hdmi_remove(struct platform_device *pdev)
1341 1361
1342 snd_soc_unregister_codec(&pdev->dev); 1362 snd_soc_unregister_codec(&pdev->dev);
1343 1363
1364 fb_unregister_client(&hdmi->notifier);
1365
1344 board_cfg->display_on = NULL; 1366 board_cfg->display_on = NULL;
1345 board_cfg->display_off = NULL; 1367 board_cfg->display_off = NULL;
1346 board_cfg->board_data = NULL; 1368 board_cfg->board_data = NULL;
diff --git a/drivers/video/sstfb.c b/drivers/video/sstfb.c
index dee64c3b1e67..2ab704118c44 100644
--- a/drivers/video/sstfb.c
+++ b/drivers/video/sstfb.c
@@ -536,7 +536,7 @@ static int sstfb_set_par(struct fb_info *info)
536 fbiinit2 = sst_read(FBIINIT2); 536 fbiinit2 = sst_read(FBIINIT2);
537 fbiinit3 = sst_read(FBIINIT3); 537 fbiinit3 = sst_read(FBIINIT3);
538 538
539 /* everything is reset. we enable fbiinit2/3 remap : dac acces ok */ 539 /* everything is reset. we enable fbiinit2/3 remap : dac access ok */
540 pci_write_config_dword(sst_dev, PCI_INIT_ENABLE, 540 pci_write_config_dword(sst_dev, PCI_INIT_ENABLE,
541 PCI_EN_INIT_WR | PCI_REMAP_DAC ); 541 PCI_EN_INIT_WR | PCI_REMAP_DAC );
542 542
diff --git a/drivers/video/vt8500lcdfb.c b/drivers/video/vt8500lcdfb.c
index 7617f12e4fd7..0e120d67eb65 100644
--- a/drivers/video/vt8500lcdfb.c
+++ b/drivers/video/vt8500lcdfb.c
@@ -215,6 +215,33 @@ static int vt8500lcd_pan_display(struct fb_var_screeninfo *var,
215 return 0; 215 return 0;
216} 216}
217 217
218/*
219 * vt8500lcd_blank():
220 * Blank the display by setting all palette values to zero. Note,
221 * True Color modes do not really use the palette, so this will not
222 * blank the display in all modes.
223 */
224static int vt8500lcd_blank(int blank, struct fb_info *info)
225{
226 int i;
227
228 switch (blank) {
229 case FB_BLANK_POWERDOWN:
230 case FB_BLANK_VSYNC_SUSPEND:
231 case FB_BLANK_HSYNC_SUSPEND:
232 case FB_BLANK_NORMAL:
233 if (info->fix.visual == FB_VISUAL_PSEUDOCOLOR ||
234 info->fix.visual == FB_VISUAL_STATIC_PSEUDOCOLOR)
235 for (i = 0; i < 256; i++)
236 vt8500lcd_setcolreg(i, 0, 0, 0, 0, info);
237 case FB_BLANK_UNBLANK:
238 if (info->fix.visual == FB_VISUAL_PSEUDOCOLOR ||
239 info->fix.visual == FB_VISUAL_STATIC_PSEUDOCOLOR)
240 fb_set_cmap(&info->cmap, info);
241 }
242 return 0;
243}
244
218static struct fb_ops vt8500lcd_ops = { 245static struct fb_ops vt8500lcd_ops = {
219 .owner = THIS_MODULE, 246 .owner = THIS_MODULE,
220 .fb_set_par = vt8500lcd_set_par, 247 .fb_set_par = vt8500lcd_set_par,
@@ -225,6 +252,7 @@ static struct fb_ops vt8500lcd_ops = {
225 .fb_sync = wmt_ge_sync, 252 .fb_sync = wmt_ge_sync,
226 .fb_ioctl = vt8500lcd_ioctl, 253 .fb_ioctl = vt8500lcd_ioctl,
227 .fb_pan_display = vt8500lcd_pan_display, 254 .fb_pan_display = vt8500lcd_pan_display,
255 .fb_blank = vt8500lcd_blank,
228}; 256};
229 257
230static irqreturn_t vt8500lcd_handle_irq(int irq, void *dev_id) 258static irqreturn_t vt8500lcd_handle_irq(int irq, void *dev_id)
diff --git a/drivers/w1/slaves/Kconfig b/drivers/w1/slaves/Kconfig
index 1f51366417b9..f0c909625bd1 100644
--- a/drivers/w1/slaves/Kconfig
+++ b/drivers/w1/slaves/Kconfig
@@ -16,6 +16,17 @@ config W1_SLAVE_SMEM
16 Say Y here if you want to connect 1-wire 16 Say Y here if you want to connect 1-wire
17 simple 64bit memory rom(ds2401/ds2411/ds1990*) to your wire. 17 simple 64bit memory rom(ds2401/ds2411/ds1990*) to your wire.
18 18
19config W1_SLAVE_DS2423
20 tristate "Counter 1-wire device (DS2423)"
21 select CRC16
22 help
23 If you enable this you can read the counter values available
24 in the DS2423 chipset from the w1_slave file under the
25 sys file system.
26
27 Say Y here if you want to use a 1-wire
28 counter family device (DS2423).
29
19config W1_SLAVE_DS2431 30config W1_SLAVE_DS2431
20 tristate "1kb EEPROM family support (DS2431)" 31 tristate "1kb EEPROM family support (DS2431)"
21 help 32 help
diff --git a/drivers/w1/slaves/Makefile b/drivers/w1/slaves/Makefile
index f1f51f19b129..3c76350a24f7 100644
--- a/drivers/w1/slaves/Makefile
+++ b/drivers/w1/slaves/Makefile
@@ -4,6 +4,7 @@
4 4
5obj-$(CONFIG_W1_SLAVE_THERM) += w1_therm.o 5obj-$(CONFIG_W1_SLAVE_THERM) += w1_therm.o
6obj-$(CONFIG_W1_SLAVE_SMEM) += w1_smem.o 6obj-$(CONFIG_W1_SLAVE_SMEM) += w1_smem.o
7obj-$(CONFIG_W1_SLAVE_DS2423) += w1_ds2423.o
7obj-$(CONFIG_W1_SLAVE_DS2431) += w1_ds2431.o 8obj-$(CONFIG_W1_SLAVE_DS2431) += w1_ds2431.o
8obj-$(CONFIG_W1_SLAVE_DS2433) += w1_ds2433.o 9obj-$(CONFIG_W1_SLAVE_DS2433) += w1_ds2433.o
9obj-$(CONFIG_W1_SLAVE_DS2760) += w1_ds2760.o 10obj-$(CONFIG_W1_SLAVE_DS2760) += w1_ds2760.o
diff --git a/drivers/w1/slaves/w1_ds2423.c b/drivers/w1/slaves/w1_ds2423.c
new file mode 100644
index 000000000000..7a7dbe5026f1
--- /dev/null
+++ b/drivers/w1/slaves/w1_ds2423.c
@@ -0,0 +1,166 @@
1/*
2 * w1_ds2423.c
3 *
4 * Copyright (c) 2010 Mika Laitio <lamikr@pilppa.org>
5 *
6 * This driver will read and write the value of 4 counters to w1_slave file in
7 * sys filesystem.
8 * Inspired by the w1_therm and w1_ds2431 drivers.
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the therms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 */
24
25#include <linux/kernel.h>
26#include <linux/module.h>
27#include <linux/moduleparam.h>
28#include <linux/device.h>
29#include <linux/types.h>
30#include <linux/delay.h>
31#include <linux/crc16.h>
32
33#include "../w1.h"
34#include "../w1_int.h"
35#include "../w1_family.h"
36
37#define CRC16_VALID 0xb001
38#define CRC16_INIT 0
39
40#define COUNTER_COUNT 4
41#define READ_BYTE_COUNT 42
42
43static ssize_t w1_counter_read(struct device *device,
44 struct device_attribute *attr, char *buf);
45
46static struct device_attribute w1_counter_attr =
47 __ATTR(w1_slave, S_IRUGO, w1_counter_read, NULL);
48
49static ssize_t w1_counter_read(struct device *device,
50 struct device_attribute *attr, char *out_buf)
51{
52 struct w1_slave *sl = dev_to_w1_slave(device);
53 struct w1_master *dev = sl->master;
54 u8 rbuf[COUNTER_COUNT * READ_BYTE_COUNT];
55 u8 wrbuf[3];
56 int rom_addr;
57 int read_byte_count;
58 int result;
59 ssize_t c;
60 int ii;
61 int p;
62 int crc;
63
64 c = PAGE_SIZE;
65 rom_addr = (12 << 5) + 31;
66 wrbuf[0] = 0xA5;
67 wrbuf[1] = rom_addr & 0xFF;
68 wrbuf[2] = rom_addr >> 8;
69 mutex_lock(&dev->mutex);
70 if (!w1_reset_select_slave(sl)) {
71 w1_write_block(dev, wrbuf, 3);
72 read_byte_count = 0;
73 for (p = 0; p < 4; p++) {
74 /*
75 * 1 byte for first bytes in ram page read
76 * 4 bytes for counter
77 * 4 bytes for zero bits
78 * 2 bytes for crc
79 * 31 remaining bytes from the ram page
80 */
81 read_byte_count += w1_read_block(dev,
82 rbuf + (p * READ_BYTE_COUNT), READ_BYTE_COUNT);
83 for (ii = 0; ii < READ_BYTE_COUNT; ++ii)
84 c -= snprintf(out_buf + PAGE_SIZE - c,
85 c, "%02x ",
86 rbuf[(p * READ_BYTE_COUNT) + ii]);
87 if (read_byte_count != (p + 1) * READ_BYTE_COUNT) {
88 dev_warn(device,
89 "w1_counter_read() returned %u bytes "
90 "instead of %d bytes wanted.\n",
91 read_byte_count,
92 READ_BYTE_COUNT);
93 c -= snprintf(out_buf + PAGE_SIZE - c,
94 c, "crc=NO\n");
95 } else {
96 if (p == 0) {
97 crc = crc16(CRC16_INIT, wrbuf, 3);
98 crc = crc16(crc, rbuf, 11);
99 } else {
100 /*
101 * DS2423 calculates crc from all bytes
102 * read after the previous crc bytes.
103 */
104 crc = crc16(CRC16_INIT,
105 (rbuf + 11) +
106 ((p - 1) * READ_BYTE_COUNT),
107 READ_BYTE_COUNT);
108 }
109 if (crc == CRC16_VALID) {
110 result = 0;
111 for (ii = 4; ii > 0; ii--) {
112 result <<= 8;
113 result |= rbuf[(p *
114 READ_BYTE_COUNT) + ii];
115 }
116 c -= snprintf(out_buf + PAGE_SIZE - c,
117 c, "crc=YES c=%d\n", result);
118 } else {
119 c -= snprintf(out_buf + PAGE_SIZE - c,
120 c, "crc=NO\n");
121 }
122 }
123 }
124 } else {
125 c -= snprintf(out_buf + PAGE_SIZE - c, c, "Connection error");
126 }
127 mutex_unlock(&dev->mutex);
128 return PAGE_SIZE - c;
129}
130
131static int w1_f1d_add_slave(struct w1_slave *sl)
132{
133 return device_create_file(&sl->dev, &w1_counter_attr);
134}
135
136static void w1_f1d_remove_slave(struct w1_slave *sl)
137{
138 device_remove_file(&sl->dev, &w1_counter_attr);
139}
140
141static struct w1_family_ops w1_f1d_fops = {
142 .add_slave = w1_f1d_add_slave,
143 .remove_slave = w1_f1d_remove_slave,
144};
145
146static struct w1_family w1_family_1d = {
147 .fid = W1_COUNTER_DS2423,
148 .fops = &w1_f1d_fops,
149};
150
151static int __init w1_f1d_init(void)
152{
153 return w1_register_family(&w1_family_1d);
154}
155
156static void __exit w1_f1d_exit(void)
157{
158 w1_unregister_family(&w1_family_1d);
159}
160
161module_init(w1_f1d_init);
162module_exit(w1_f1d_exit);
163
164MODULE_LICENSE("GPL");
165MODULE_AUTHOR("Mika Laitio <lamikr@pilppa.org>");
166MODULE_DESCRIPTION("w1 family 1d driver for DS2423, 4 counters and 4kb ram");
diff --git a/drivers/w1/w1_family.h b/drivers/w1/w1_family.h
index 3ca1b9298f21..f3b636d7cafe 100644
--- a/drivers/w1/w1_family.h
+++ b/drivers/w1/w1_family.h
@@ -30,6 +30,7 @@
30#define W1_FAMILY_SMEM_01 0x01 30#define W1_FAMILY_SMEM_01 0x01
31#define W1_FAMILY_SMEM_81 0x81 31#define W1_FAMILY_SMEM_81 0x81
32#define W1_THERM_DS18S20 0x10 32#define W1_THERM_DS18S20 0x10
33#define W1_COUNTER_DS2423 0x1D
33#define W1_THERM_DS1822 0x22 34#define W1_THERM_DS1822 0x22
34#define W1_EEPROM_DS2433 0x23 35#define W1_EEPROM_DS2433 0x23
35#define W1_THERM_DS18B20 0x28 36#define W1_THERM_DS18B20 0x28
diff --git a/drivers/watchdog/Kconfig b/drivers/watchdog/Kconfig
index a5ad77ef4266..2e2400e7322e 100644
--- a/drivers/watchdog/Kconfig
+++ b/drivers/watchdog/Kconfig
@@ -409,15 +409,26 @@ config ALIM7101_WDT
409 Most people will say N. 409 Most people will say N.
410 410
411config F71808E_WDT 411config F71808E_WDT
412 tristate "Fintek F71808E, F71882FG and F71889FG Watchdog" 412 tristate "Fintek F71808E, F71862FG, F71869, F71882FG and F71889FG Watchdog"
413 depends on X86 && EXPERIMENTAL 413 depends on X86 && EXPERIMENTAL
414 help 414 help
415 This is the driver for the hardware watchdog on the Fintek 415 This is the driver for the hardware watchdog on the Fintek
416 F71808E, F71882FG and F71889FG Super I/O controllers. 416 F71808E, F71862FG, F71869, F71882FG and F71889FG Super I/O controllers.
417 417
418 You can compile this driver directly into the kernel, or use 418 You can compile this driver directly into the kernel, or use
419 it as a module. The module will be called f71808e_wdt. 419 it as a module. The module will be called f71808e_wdt.
420 420
421config SP5100_TCO
422 tristate "AMD/ATI SP5100 TCO Timer/Watchdog"
423 depends on X86 && PCI
424 ---help---
425 Hardware watchdog driver for the AMD/ATI SP5100 chipset. The TCO
426 (Total Cost of Ownership) timer is a watchdog timer that will reboot
427 the machine after its expiration. The expiration time can be
428 configured with the "heartbeat" parameter.
429
430 To compile this driver as a module, choose M here: the
431 module will be called sp5100_tco.
421 432
422config GEODE_WDT 433config GEODE_WDT
423 tristate "AMD Geode CS5535/CS5536 Watchdog" 434 tristate "AMD Geode CS5535/CS5536 Watchdog"
@@ -631,6 +642,24 @@ config PC87413_WDT
631 642
632 Most people will say N. 643 Most people will say N.
633 644
645config NV_TCO
646 tristate "nVidia TCO Timer/Watchdog"
647 depends on X86 && PCI
648 ---help---
649 Hardware driver for the TCO timer built into the nVidia Hub family
650 (such as the MCP51). The TCO (Total Cost of Ownership) timer is a
651 watchdog timer that will reboot the machine after its second
652 expiration. The expiration time can be configured with the
653 "heartbeat" parameter.
654
655 On some motherboards the driver may fail to reset the chipset's
656 NO_REBOOT flag which prevents the watchdog from rebooting the
657 machine. If this is the case you will get a kernel message like
658 "failed to reset NO_REBOOT flag, reboot disabled by hardware".
659
660 To compile this driver as a module, choose M here: the
661 module will be called nv_tco.
662
634config RDC321X_WDT 663config RDC321X_WDT
635 tristate "RDC R-321x SoC watchdog" 664 tristate "RDC R-321x SoC watchdog"
636 depends on X86_RDC321X 665 depends on X86_RDC321X
@@ -722,14 +751,15 @@ config SMSC37B787_WDT
722 Most people will say N. 751 Most people will say N.
723 752
724config W83627HF_WDT 753config W83627HF_WDT
725 tristate "W83627HF Watchdog Timer" 754 tristate "W83627HF/W83627DHG Watchdog Timer"
726 depends on X86 755 depends on X86
727 ---help--- 756 ---help---
728 This is the driver for the hardware watchdog on the W83627HF chipset 757 This is the driver for the hardware watchdog on the W83627HF chipset
729 as used in Advantech PC-9578 and Tyan S2721-533 motherboards 758 as used in Advantech PC-9578 and Tyan S2721-533 motherboards
730 (and likely others). This watchdog simply watches your kernel to 759 (and likely others). The driver also supports the W83627DHG chip.
731 make sure it doesn't freeze, and if it does, it reboots your computer 760 This watchdog simply watches your kernel to make sure it doesn't
732 after a certain amount of time. 761 freeze, and if it does, it reboots your computer after a certain
762 amount of time.
733 763
734 To compile this driver as a module, choose M here: the 764 To compile this driver as a module, choose M here: the
735 module will be called w83627hf_wdt. 765 module will be called w83627hf_wdt.
@@ -832,10 +862,22 @@ config SBC_EPX_C3_WATCHDOG
832 862
833# M68K Architecture 863# M68K Architecture
834 864
835# M68KNOMMU Architecture 865config M548x_WATCHDOG
866 tristate "MCF548x watchdog support"
867 depends on M548x
868 help
869 To compile this driver as a module, choose M here: the
870 module will be called m548x_wdt.
836 871
837# MIPS Architecture 872# MIPS Architecture
838 873
874config ATH79_WDT
875 tristate "Atheros AR71XX/AR724X/AR913X hardware watchdog"
876 depends on ATH79
877 help
878 Hardware driver for the built-in watchdog timer on the Atheros
879 AR71XX/AR724X/AR913X SoCs.
880
839config BCM47XX_WDT 881config BCM47XX_WDT
840 tristate "Broadcom BCM47xx Watchdog Timer" 882 tristate "Broadcom BCM47xx Watchdog Timer"
841 depends on BCM47XX 883 depends on BCM47XX
diff --git a/drivers/watchdog/Makefile b/drivers/watchdog/Makefile
index 4b0ef386229d..dd776651917c 100644
--- a/drivers/watchdog/Makefile
+++ b/drivers/watchdog/Makefile
@@ -68,6 +68,7 @@ obj-$(CONFIG_ADVANTECH_WDT) += advantechwdt.o
68obj-$(CONFIG_ALIM1535_WDT) += alim1535_wdt.o 68obj-$(CONFIG_ALIM1535_WDT) += alim1535_wdt.o
69obj-$(CONFIG_ALIM7101_WDT) += alim7101_wdt.o 69obj-$(CONFIG_ALIM7101_WDT) += alim7101_wdt.o
70obj-$(CONFIG_F71808E_WDT) += f71808e_wdt.o 70obj-$(CONFIG_F71808E_WDT) += f71808e_wdt.o
71obj-$(CONFIG_SP5100_TCO) += sp5100_tco.o
71obj-$(CONFIG_GEODE_WDT) += geodewdt.o 72obj-$(CONFIG_GEODE_WDT) += geodewdt.o
72obj-$(CONFIG_SC520_WDT) += sc520_wdt.o 73obj-$(CONFIG_SC520_WDT) += sc520_wdt.o
73obj-$(CONFIG_SBC_FITPC2_WATCHDOG) += sbc_fitpc2_wdt.o 74obj-$(CONFIG_SBC_FITPC2_WATCHDOG) += sbc_fitpc2_wdt.o
@@ -86,6 +87,7 @@ obj-$(CONFIG_HP_WATCHDOG) += hpwdt.o
86obj-$(CONFIG_SC1200_WDT) += sc1200wdt.o 87obj-$(CONFIG_SC1200_WDT) += sc1200wdt.o
87obj-$(CONFIG_SCx200_WDT) += scx200_wdt.o 88obj-$(CONFIG_SCx200_WDT) += scx200_wdt.o
88obj-$(CONFIG_PC87413_WDT) += pc87413_wdt.o 89obj-$(CONFIG_PC87413_WDT) += pc87413_wdt.o
90obj-$(CONFIG_NV_TCO) += nv_tco.o
89obj-$(CONFIG_RDC321X_WDT) += rdc321x_wdt.o 91obj-$(CONFIG_RDC321X_WDT) += rdc321x_wdt.o
90obj-$(CONFIG_60XX_WDT) += sbc60xxwdt.o 92obj-$(CONFIG_60XX_WDT) += sbc60xxwdt.o
91obj-$(CONFIG_SBC8360_WDT) += sbc8360.o 93obj-$(CONFIG_SBC8360_WDT) += sbc8360.o
@@ -104,10 +106,10 @@ obj-$(CONFIG_SBC_EPX_C3_WATCHDOG) += sbc_epx_c3.o
104# M32R Architecture 106# M32R Architecture
105 107
106# M68K Architecture 108# M68K Architecture
107 109obj-$(CONFIG_M548x_WATCHDOG) += m548x_wdt.o
108# M68KNOMMU Architecture
109 110
110# MIPS Architecture 111# MIPS Architecture
112obj-$(CONFIG_ATH79_WDT) += ath79_wdt.o
111obj-$(CONFIG_BCM47XX_WDT) += bcm47xx_wdt.o 113obj-$(CONFIG_BCM47XX_WDT) += bcm47xx_wdt.o
112obj-$(CONFIG_BCM63XX_WDT) += bcm63xx_wdt.o 114obj-$(CONFIG_BCM63XX_WDT) += bcm63xx_wdt.o
113obj-$(CONFIG_RC32434_WDT) += rc32434_wdt.o 115obj-$(CONFIG_RC32434_WDT) += rc32434_wdt.o
diff --git a/drivers/watchdog/alim1535_wdt.c b/drivers/watchdog/alim1535_wdt.c
index 1e9caea8ff8a..fa4d36033552 100644
--- a/drivers/watchdog/alim1535_wdt.c
+++ b/drivers/watchdog/alim1535_wdt.c
@@ -301,7 +301,7 @@ static int ali_notify_sys(struct notifier_block *this,
301 * want to register another driver on the same PCI id. 301 * want to register another driver on the same PCI id.
302 */ 302 */
303 303
304static struct pci_device_id ali_pci_tbl[] = { 304static struct pci_device_id ali_pci_tbl[] __used = {
305 { PCI_VENDOR_ID_AL, 0x1533, PCI_ANY_ID, PCI_ANY_ID,}, 305 { PCI_VENDOR_ID_AL, 0x1533, PCI_ANY_ID, PCI_ANY_ID,},
306 { PCI_VENDOR_ID_AL, 0x1535, PCI_ANY_ID, PCI_ANY_ID,}, 306 { PCI_VENDOR_ID_AL, 0x1535, PCI_ANY_ID, PCI_ANY_ID,},
307 { 0, }, 307 { 0, },
diff --git a/drivers/watchdog/alim7101_wdt.c b/drivers/watchdog/alim7101_wdt.c
index d8d4da9a483d..4b7a2b4138ed 100644
--- a/drivers/watchdog/alim7101_wdt.c
+++ b/drivers/watchdog/alim7101_wdt.c
@@ -430,7 +430,7 @@ err_out:
430module_init(alim7101_wdt_init); 430module_init(alim7101_wdt_init);
431module_exit(alim7101_wdt_unload); 431module_exit(alim7101_wdt_unload);
432 432
433static struct pci_device_id alim7101_pci_tbl[] __devinitdata = { 433static struct pci_device_id alim7101_pci_tbl[] __devinitdata __used = {
434 { PCI_DEVICE(PCI_VENDOR_ID_AL, PCI_DEVICE_ID_AL_M1533) }, 434 { PCI_DEVICE(PCI_VENDOR_ID_AL, PCI_DEVICE_ID_AL_M1533) },
435 { PCI_DEVICE(PCI_VENDOR_ID_AL, PCI_DEVICE_ID_AL_M7101) }, 435 { PCI_DEVICE(PCI_VENDOR_ID_AL, PCI_DEVICE_ID_AL_M7101) },
436 { } 436 { }
diff --git a/drivers/watchdog/ath79_wdt.c b/drivers/watchdog/ath79_wdt.c
new file mode 100644
index 000000000000..725c84bfdd76
--- /dev/null
+++ b/drivers/watchdog/ath79_wdt.c
@@ -0,0 +1,305 @@
1/*
2 * Atheros AR71XX/AR724X/AR913X built-in hardware watchdog timer.
3 *
4 * Copyright (C) 2008-2011 Gabor Juhos <juhosg@openwrt.org>
5 * Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
6 *
7 * This driver was based on: drivers/watchdog/ixp4xx_wdt.c
8 * Author: Deepak Saxena <dsaxena@plexity.net>
9 * Copyright 2004 (c) MontaVista, Software, Inc.
10 *
11 * which again was based on sa1100 driver,
12 * Copyright (C) 2000 Oleg Drokin <green@crimea.edu>
13 *
14 * This program is free software; you can redistribute it and/or modify it
15 * under the terms of the GNU General Public License version 2 as published
16 * by the Free Software Foundation.
17 *
18 */
19
20#include <linux/bitops.h>
21#include <linux/errno.h>
22#include <linux/fs.h>
23#include <linux/init.h>
24#include <linux/kernel.h>
25#include <linux/miscdevice.h>
26#include <linux/module.h>
27#include <linux/moduleparam.h>
28#include <linux/platform_device.h>
29#include <linux/types.h>
30#include <linux/watchdog.h>
31#include <linux/clk.h>
32#include <linux/err.h>
33
34#include <asm/mach-ath79/ath79.h>
35#include <asm/mach-ath79/ar71xx_regs.h>
36
37#define DRIVER_NAME "ath79-wdt"
38
39#define WDT_TIMEOUT 15 /* seconds */
40
41#define WDOG_CTRL_LAST_RESET BIT(31)
42#define WDOG_CTRL_ACTION_MASK 3
43#define WDOG_CTRL_ACTION_NONE 0 /* no action */
44#define WDOG_CTRL_ACTION_GPI 1 /* general purpose interrupt */
45#define WDOG_CTRL_ACTION_NMI 2 /* NMI */
46#define WDOG_CTRL_ACTION_FCR 3 /* full chip reset */
47
48static int nowayout = WATCHDOG_NOWAYOUT;
49module_param(nowayout, int, 0);
50MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started "
51 "(default=" __MODULE_STRING(WATCHDOG_NOWAYOUT) ")");
52
53static int timeout = WDT_TIMEOUT;
54module_param(timeout, int, 0);
55MODULE_PARM_DESC(timeout, "Watchdog timeout in seconds "
56 "(default=" __MODULE_STRING(WDT_TIMEOUT) "s)");
57
58static unsigned long wdt_flags;
59
60#define WDT_FLAGS_BUSY 0
61#define WDT_FLAGS_EXPECT_CLOSE 1
62
63static struct clk *wdt_clk;
64static unsigned long wdt_freq;
65static int boot_status;
66static int max_timeout;
67
68static inline void ath79_wdt_keepalive(void)
69{
70 ath79_reset_wr(AR71XX_RESET_REG_WDOG, wdt_freq * timeout);
71}
72
73static inline void ath79_wdt_enable(void)
74{
75 ath79_wdt_keepalive();
76 ath79_reset_wr(AR71XX_RESET_REG_WDOG_CTRL, WDOG_CTRL_ACTION_FCR);
77}
78
79static inline void ath79_wdt_disable(void)
80{
81 ath79_reset_wr(AR71XX_RESET_REG_WDOG_CTRL, WDOG_CTRL_ACTION_NONE);
82}
83
84static int ath79_wdt_set_timeout(int val)
85{
86 if (val < 1 || val > max_timeout)
87 return -EINVAL;
88
89 timeout = val;
90 ath79_wdt_keepalive();
91
92 return 0;
93}
94
95static int ath79_wdt_open(struct inode *inode, struct file *file)
96{
97 if (test_and_set_bit(WDT_FLAGS_BUSY, &wdt_flags))
98 return -EBUSY;
99
100 clear_bit(WDT_FLAGS_EXPECT_CLOSE, &wdt_flags);
101 ath79_wdt_enable();
102
103 return nonseekable_open(inode, file);
104}
105
106static int ath79_wdt_release(struct inode *inode, struct file *file)
107{
108 if (test_bit(WDT_FLAGS_EXPECT_CLOSE, &wdt_flags))
109 ath79_wdt_disable();
110 else {
111 pr_crit(DRIVER_NAME ": device closed unexpectedly, "
112 "watchdog timer will not stop!\n");
113 ath79_wdt_keepalive();
114 }
115
116 clear_bit(WDT_FLAGS_BUSY, &wdt_flags);
117 clear_bit(WDT_FLAGS_EXPECT_CLOSE, &wdt_flags);
118
119 return 0;
120}
121
122static ssize_t ath79_wdt_write(struct file *file, const char *data,
123 size_t len, loff_t *ppos)
124{
125 if (len) {
126 if (!nowayout) {
127 size_t i;
128
129 clear_bit(WDT_FLAGS_EXPECT_CLOSE, &wdt_flags);
130
131 for (i = 0; i != len; i++) {
132 char c;
133
134 if (get_user(c, data + i))
135 return -EFAULT;
136
137 if (c == 'V')
138 set_bit(WDT_FLAGS_EXPECT_CLOSE,
139 &wdt_flags);
140 }
141 }
142
143 ath79_wdt_keepalive();
144 }
145
146 return len;
147}
148
149static const struct watchdog_info ath79_wdt_info = {
150 .options = WDIOF_SETTIMEOUT | WDIOF_KEEPALIVEPING |
151 WDIOF_MAGICCLOSE | WDIOF_CARDRESET,
152 .firmware_version = 0,
153 .identity = "ATH79 watchdog",
154};
155
156static long ath79_wdt_ioctl(struct file *file, unsigned int cmd,
157 unsigned long arg)
158{
159 void __user *argp = (void __user *)arg;
160 int __user *p = argp;
161 int err;
162 int t;
163
164 switch (cmd) {
165 case WDIOC_GETSUPPORT:
166 err = copy_to_user(argp, &ath79_wdt_info,
167 sizeof(ath79_wdt_info)) ? -EFAULT : 0;
168 break;
169
170 case WDIOC_GETSTATUS:
171 err = put_user(0, p);
172 break;
173
174 case WDIOC_GETBOOTSTATUS:
175 err = put_user(boot_status, p);
176 break;
177
178 case WDIOC_KEEPALIVE:
179 ath79_wdt_keepalive();
180 err = 0;
181 break;
182
183 case WDIOC_SETTIMEOUT:
184 err = get_user(t, p);
185 if (err)
186 break;
187
188 err = ath79_wdt_set_timeout(t);
189 if (err)
190 break;
191
192 /* fallthrough */
193 case WDIOC_GETTIMEOUT:
194 err = put_user(timeout, p);
195 break;
196
197 default:
198 err = -ENOTTY;
199 break;
200 }
201
202 return err;
203}
204
205static const struct file_operations ath79_wdt_fops = {
206 .owner = THIS_MODULE,
207 .llseek = no_llseek,
208 .write = ath79_wdt_write,
209 .unlocked_ioctl = ath79_wdt_ioctl,
210 .open = ath79_wdt_open,
211 .release = ath79_wdt_release,
212};
213
214static struct miscdevice ath79_wdt_miscdev = {
215 .minor = WATCHDOG_MINOR,
216 .name = "watchdog",
217 .fops = &ath79_wdt_fops,
218};
219
220static int __devinit ath79_wdt_probe(struct platform_device *pdev)
221{
222 u32 ctrl;
223 int err;
224
225 wdt_clk = clk_get(&pdev->dev, "wdt");
226 if (IS_ERR(wdt_clk))
227 return PTR_ERR(wdt_clk);
228
229 err = clk_enable(wdt_clk);
230 if (err)
231 goto err_clk_put;
232
233 wdt_freq = clk_get_rate(wdt_clk);
234 if (!wdt_freq) {
235 err = -EINVAL;
236 goto err_clk_disable;
237 }
238
239 max_timeout = (0xfffffffful / wdt_freq);
240 if (timeout < 1 || timeout > max_timeout) {
241 timeout = max_timeout;
242 dev_info(&pdev->dev,
243 "timeout value must be 0 < timeout < %d, using %d\n",
244 max_timeout, timeout);
245 }
246
247 ctrl = ath79_reset_rr(AR71XX_RESET_REG_WDOG_CTRL);
248 boot_status = (ctrl & WDOG_CTRL_LAST_RESET) ? WDIOF_CARDRESET : 0;
249
250 err = misc_register(&ath79_wdt_miscdev);
251 if (err) {
252 dev_err(&pdev->dev,
253 "unable to register misc device, err=%d\n", err);
254 goto err_clk_disable;
255 }
256
257 return 0;
258
259err_clk_disable:
260 clk_disable(wdt_clk);
261err_clk_put:
262 clk_put(wdt_clk);
263 return err;
264}
265
266static int __devexit ath79_wdt_remove(struct platform_device *pdev)
267{
268 misc_deregister(&ath79_wdt_miscdev);
269 clk_disable(wdt_clk);
270 clk_put(wdt_clk);
271 return 0;
272}
273
274static void ath97_wdt_shutdown(struct platform_device *pdev)
275{
276 ath79_wdt_disable();
277}
278
279static struct platform_driver ath79_wdt_driver = {
280 .remove = __devexit_p(ath79_wdt_remove),
281 .shutdown = ath97_wdt_shutdown,
282 .driver = {
283 .name = DRIVER_NAME,
284 .owner = THIS_MODULE,
285 },
286};
287
288static int __init ath79_wdt_init(void)
289{
290 return platform_driver_probe(&ath79_wdt_driver, ath79_wdt_probe);
291}
292module_init(ath79_wdt_init);
293
294static void __exit ath79_wdt_exit(void)
295{
296 platform_driver_unregister(&ath79_wdt_driver);
297}
298module_exit(ath79_wdt_exit);
299
300MODULE_DESCRIPTION("Atheros AR71XX/AR724X/AR913X hardware watchdog driver");
301MODULE_AUTHOR("Gabor Juhos <juhosg@openwrt.org");
302MODULE_AUTHOR("Imre Kaloz <kaloz@openwrt.org");
303MODULE_LICENSE("GPL v2");
304MODULE_ALIAS("platform:" DRIVER_NAME);
305MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
diff --git a/drivers/watchdog/booke_wdt.c b/drivers/watchdog/booke_wdt.c
index d11ffb091b0d..7e7ec9c35b6a 100644
--- a/drivers/watchdog/booke_wdt.c
+++ b/drivers/watchdog/booke_wdt.c
@@ -85,6 +85,22 @@ static unsigned int sec_to_period(unsigned int secs)
85 return 0; 85 return 0;
86} 86}
87 87
88static void __booke_wdt_set(void *data)
89{
90 u32 val;
91
92 val = mfspr(SPRN_TCR);
93 val &= ~WDTP_MASK;
94 val |= WDTP(booke_wdt_period);
95
96 mtspr(SPRN_TCR, val);
97}
98
99static void booke_wdt_set(void)
100{
101 on_each_cpu(__booke_wdt_set, NULL, 0);
102}
103
88static void __booke_wdt_ping(void *data) 104static void __booke_wdt_ping(void *data)
89{ 105{
90 mtspr(SPRN_TSR, TSR_ENW|TSR_WIS); 106 mtspr(SPRN_TSR, TSR_ENW|TSR_WIS);
@@ -181,8 +197,7 @@ static long booke_wdt_ioctl(struct file *file,
181#else 197#else
182 booke_wdt_period = tmp; 198 booke_wdt_period = tmp;
183#endif 199#endif
184 mtspr(SPRN_TCR, (mfspr(SPRN_TCR) & ~WDTP_MASK) | 200 booke_wdt_set();
185 WDTP(booke_wdt_period));
186 return 0; 201 return 0;
187 case WDIOC_GETTIMEOUT: 202 case WDIOC_GETTIMEOUT:
188 return put_user(booke_wdt_period, p); 203 return put_user(booke_wdt_period, p);
@@ -193,8 +208,15 @@ static long booke_wdt_ioctl(struct file *file,
193 return 0; 208 return 0;
194} 209}
195 210
211/* wdt_is_active stores wether or not the /dev/watchdog device is opened */
212static unsigned long wdt_is_active;
213
196static int booke_wdt_open(struct inode *inode, struct file *file) 214static int booke_wdt_open(struct inode *inode, struct file *file)
197{ 215{
216 /* /dev/watchdog can only be opened once */
217 if (test_and_set_bit(0, &wdt_is_active))
218 return -EBUSY;
219
198 spin_lock(&booke_wdt_lock); 220 spin_lock(&booke_wdt_lock);
199 if (booke_wdt_enabled == 0) { 221 if (booke_wdt_enabled == 0) {
200 booke_wdt_enabled = 1; 222 booke_wdt_enabled = 1;
@@ -210,8 +232,17 @@ static int booke_wdt_open(struct inode *inode, struct file *file)
210 232
211static int booke_wdt_release(struct inode *inode, struct file *file) 233static int booke_wdt_release(struct inode *inode, struct file *file)
212{ 234{
235#ifndef CONFIG_WATCHDOG_NOWAYOUT
236 /* Normally, the watchdog is disabled when /dev/watchdog is closed, but
237 * if CONFIG_WATCHDOG_NOWAYOUT is defined, then it means that the
238 * watchdog should remain enabled. So we disable it only if
239 * CONFIG_WATCHDOG_NOWAYOUT is not defined.
240 */
213 on_each_cpu(__booke_wdt_disable, NULL, 0); 241 on_each_cpu(__booke_wdt_disable, NULL, 0);
214 booke_wdt_enabled = 0; 242 booke_wdt_enabled = 0;
243#endif
244
245 clear_bit(0, &wdt_is_active);
215 246
216 return 0; 247 return 0;
217} 248}
diff --git a/drivers/watchdog/f71808e_wdt.c b/drivers/watchdog/f71808e_wdt.c
index 65e579635dba..d4d8d1fdccc4 100644
--- a/drivers/watchdog/f71808e_wdt.c
+++ b/drivers/watchdog/f71808e_wdt.c
@@ -42,18 +42,21 @@
42#define SIO_REG_DEVID 0x20 /* Device ID (2 bytes) */ 42#define SIO_REG_DEVID 0x20 /* Device ID (2 bytes) */
43#define SIO_REG_DEVREV 0x22 /* Device revision */ 43#define SIO_REG_DEVREV 0x22 /* Device revision */
44#define SIO_REG_MANID 0x23 /* Fintek ID (2 bytes) */ 44#define SIO_REG_MANID 0x23 /* Fintek ID (2 bytes) */
45#define SIO_REG_ROM_ADDR_SEL 0x27 /* ROM address select */
46#define SIO_REG_MFUNCT1 0x29 /* Multi function select 1 */
47#define SIO_REG_MFUNCT2 0x2a /* Multi function select 2 */
48#define SIO_REG_MFUNCT3 0x2b /* Multi function select 3 */
45#define SIO_REG_ENABLE 0x30 /* Logical device enable */ 49#define SIO_REG_ENABLE 0x30 /* Logical device enable */
46#define SIO_REG_ADDR 0x60 /* Logical device address (2 bytes) */ 50#define SIO_REG_ADDR 0x60 /* Logical device address (2 bytes) */
47 51
48#define SIO_FINTEK_ID 0x1934 /* Manufacturers ID */ 52#define SIO_FINTEK_ID 0x1934 /* Manufacturers ID */
49#define SIO_F71808_ID 0x0901 /* Chipset ID */ 53#define SIO_F71808_ID 0x0901 /* Chipset ID */
50#define SIO_F71858_ID 0x0507 /* Chipset ID */ 54#define SIO_F71858_ID 0x0507 /* Chipset ID */
51#define SIO_F71862_ID 0x0601 /* Chipset ID */ 55#define SIO_F71862_ID 0x0601 /* Chipset ID */
56#define SIO_F71869_ID 0x0814 /* Chipset ID */
52#define SIO_F71882_ID 0x0541 /* Chipset ID */ 57#define SIO_F71882_ID 0x0541 /* Chipset ID */
53#define SIO_F71889_ID 0x0723 /* Chipset ID */ 58#define SIO_F71889_ID 0x0723 /* Chipset ID */
54 59
55#define F71882FG_REG_START 0x01
56
57#define F71808FG_REG_WDO_CONF 0xf0 60#define F71808FG_REG_WDO_CONF 0xf0
58#define F71808FG_REG_WDT_CONF 0xf5 61#define F71808FG_REG_WDT_CONF 0xf5
59#define F71808FG_REG_WD_TIME 0xf6 62#define F71808FG_REG_WD_TIME 0xf6
@@ -70,13 +73,15 @@
70#define WATCHDOG_MAX_TIMEOUT (60 * 255) 73#define WATCHDOG_MAX_TIMEOUT (60 * 255)
71#define WATCHDOG_PULSE_WIDTH 125 /* 125 ms, default pulse width for 74#define WATCHDOG_PULSE_WIDTH 125 /* 125 ms, default pulse width for
72 watchdog signal */ 75 watchdog signal */
76#define WATCHDOG_F71862FG_PIN 63 /* default watchdog reset output
77 pin number 63 */
73 78
74static unsigned short force_id; 79static unsigned short force_id;
75module_param(force_id, ushort, 0); 80module_param(force_id, ushort, 0);
76MODULE_PARM_DESC(force_id, "Override the detected device ID"); 81MODULE_PARM_DESC(force_id, "Override the detected device ID");
77 82
78static const int max_timeout = WATCHDOG_MAX_TIMEOUT; 83static const int max_timeout = WATCHDOG_MAX_TIMEOUT;
79static int timeout = 60; /* default timeout in seconds */ 84static int timeout = WATCHDOG_TIMEOUT; /* default timeout in seconds */
80module_param(timeout, int, 0); 85module_param(timeout, int, 0);
81MODULE_PARM_DESC(timeout, 86MODULE_PARM_DESC(timeout,
82 "Watchdog timeout in seconds. 1<= timeout <=" 87 "Watchdog timeout in seconds. 1<= timeout <="
@@ -89,6 +94,12 @@ MODULE_PARM_DESC(pulse_width,
89 "Watchdog signal pulse width. 0(=level), 1 ms, 25 ms, 125 ms or 5000 ms" 94 "Watchdog signal pulse width. 0(=level), 1 ms, 25 ms, 125 ms or 5000 ms"
90 " (default=" __MODULE_STRING(WATCHDOG_PULSE_WIDTH) ")"); 95 " (default=" __MODULE_STRING(WATCHDOG_PULSE_WIDTH) ")");
91 96
97static unsigned int f71862fg_pin = WATCHDOG_F71862FG_PIN;
98module_param(f71862fg_pin, uint, 0);
99MODULE_PARM_DESC(f71862fg_pin,
100 "Watchdog f71862fg reset output pin configuration. Choose pin 56 or 63"
101 " (default=" __MODULE_STRING(WATCHDOG_F71862FG_PIN)")");
102
92static int nowayout = WATCHDOG_NOWAYOUT; 103static int nowayout = WATCHDOG_NOWAYOUT;
93module_param(nowayout, bool, 0444); 104module_param(nowayout, bool, 0444);
94MODULE_PARM_DESC(nowayout, "Disable watchdog shutdown on close"); 105MODULE_PARM_DESC(nowayout, "Disable watchdog shutdown on close");
@@ -98,12 +109,13 @@ module_param(start_withtimeout, uint, 0);
98MODULE_PARM_DESC(start_withtimeout, "Start watchdog timer on module load with" 109MODULE_PARM_DESC(start_withtimeout, "Start watchdog timer on module load with"
99 " given initial timeout. Zero (default) disables this feature."); 110 " given initial timeout. Zero (default) disables this feature.");
100 111
101enum chips { f71808fg, f71858fg, f71862fg, f71882fg, f71889fg }; 112enum chips { f71808fg, f71858fg, f71862fg, f71869, f71882fg, f71889fg };
102 113
103static const char *f71808e_names[] = { 114static const char *f71808e_names[] = {
104 "f71808fg", 115 "f71808fg",
105 "f71858fg", 116 "f71858fg",
106 "f71862fg", 117 "f71862fg",
118 "f71869",
107 "f71882fg", 119 "f71882fg",
108 "f71889fg", 120 "f71889fg",
109}; 121};
@@ -282,6 +294,28 @@ exit_unlock:
282 return err; 294 return err;
283} 295}
284 296
297static int f71862fg_pin_configure(unsigned short ioaddr)
298{
299 /* When ioaddr is non-zero the calling function has to take care of
300 mutex handling and superio preparation! */
301
302 if (f71862fg_pin == 63) {
303 if (ioaddr) {
304 /* SPI must be disabled first to use this pin! */
305 superio_clear_bit(ioaddr, SIO_REG_ROM_ADDR_SEL, 6);
306 superio_set_bit(ioaddr, SIO_REG_MFUNCT3, 4);
307 }
308 } else if (f71862fg_pin == 56) {
309 if (ioaddr)
310 superio_set_bit(ioaddr, SIO_REG_MFUNCT1, 1);
311 } else {
312 printk(KERN_ERR DRVNAME ": Invalid argument f71862fg_pin=%d\n",
313 f71862fg_pin);
314 return -EINVAL;
315 }
316 return 0;
317}
318
285static int watchdog_start(void) 319static int watchdog_start(void)
286{ 320{
287 /* Make sure we don't die as soon as the watchdog is enabled below */ 321 /* Make sure we don't die as soon as the watchdog is enabled below */
@@ -299,19 +333,30 @@ static int watchdog_start(void)
299 switch (watchdog.type) { 333 switch (watchdog.type) {
300 case f71808fg: 334 case f71808fg:
301 /* Set pin 21 to GPIO23/WDTRST#, then to WDTRST# */ 335 /* Set pin 21 to GPIO23/WDTRST#, then to WDTRST# */
302 superio_clear_bit(watchdog.sioaddr, 0x2a, 3); 336 superio_clear_bit(watchdog.sioaddr, SIO_REG_MFUNCT2, 3);
303 superio_clear_bit(watchdog.sioaddr, 0x2b, 3); 337 superio_clear_bit(watchdog.sioaddr, SIO_REG_MFUNCT3, 3);
338 break;
339
340 case f71862fg:
341 err = f71862fg_pin_configure(watchdog.sioaddr);
342 if (err)
343 goto exit_superio;
344 break;
345
346 case f71869:
347 /* GPIO14 --> WDTRST# */
348 superio_clear_bit(watchdog.sioaddr, SIO_REG_MFUNCT1, 4);
304 break; 349 break;
305 350
306 case f71882fg: 351 case f71882fg:
307 /* Set pin 56 to WDTRST# */ 352 /* Set pin 56 to WDTRST# */
308 superio_set_bit(watchdog.sioaddr, 0x29, 1); 353 superio_set_bit(watchdog.sioaddr, SIO_REG_MFUNCT1, 1);
309 break; 354 break;
310 355
311 case f71889fg: 356 case f71889fg:
312 /* set pin 40 to WDTRST# */ 357 /* set pin 40 to WDTRST# */
313 superio_outb(watchdog.sioaddr, 0x2b, 358 superio_outb(watchdog.sioaddr, SIO_REG_MFUNCT3,
314 superio_inb(watchdog.sioaddr, 0x2b) & 0xcf); 359 superio_inb(watchdog.sioaddr, SIO_REG_MFUNCT3) & 0xcf);
315 break; 360 break;
316 361
317 default: 362 default:
@@ -711,16 +756,19 @@ static int __init f71808e_find(int sioaddr)
711 case SIO_F71808_ID: 756 case SIO_F71808_ID:
712 watchdog.type = f71808fg; 757 watchdog.type = f71808fg;
713 break; 758 break;
759 case SIO_F71862_ID:
760 watchdog.type = f71862fg;
761 err = f71862fg_pin_configure(0); /* validate module parameter */
762 break;
763 case SIO_F71869_ID:
764 watchdog.type = f71869;
765 break;
714 case SIO_F71882_ID: 766 case SIO_F71882_ID:
715 watchdog.type = f71882fg; 767 watchdog.type = f71882fg;
716 break; 768 break;
717 case SIO_F71889_ID: 769 case SIO_F71889_ID:
718 watchdog.type = f71889fg; 770 watchdog.type = f71889fg;
719 break; 771 break;
720 case SIO_F71862_ID:
721 /* These have a watchdog, though it isn't implemented (yet). */
722 err = -ENOSYS;
723 goto exit;
724 case SIO_F71858_ID: 772 case SIO_F71858_ID:
725 /* Confirmed (by datasheet) not to have a watchdog. */ 773 /* Confirmed (by datasheet) not to have a watchdog. */
726 err = -ENODEV; 774 err = -ENODEV;
diff --git a/drivers/watchdog/iTCO_wdt.c b/drivers/watchdog/iTCO_wdt.c
index b8838d2c67a6..2c6c2b4ad8bf 100644
--- a/drivers/watchdog/iTCO_wdt.c
+++ b/drivers/watchdog/iTCO_wdt.c
@@ -1,7 +1,7 @@
1/* 1/*
2 * intel TCO Watchdog Driver 2 * intel TCO Watchdog Driver
3 * 3 *
4 * (c) Copyright 2006-2009 Wim Van Sebroeck <wim@iguana.be>. 4 * (c) Copyright 2006-2010 Wim Van Sebroeck <wim@iguana.be>.
5 * 5 *
6 * This program is free software; you can redistribute it and/or 6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License 7 * modify it under the terms of the GNU General Public License
@@ -26,13 +26,15 @@
26 * document number 301473-002, 301474-026: 82801F (ICH6) 26 * document number 301473-002, 301474-026: 82801F (ICH6)
27 * document number 313082-001, 313075-006: 631xESB, 632xESB 27 * document number 313082-001, 313075-006: 631xESB, 632xESB
28 * document number 307013-003, 307014-024: 82801G (ICH7) 28 * document number 307013-003, 307014-024: 82801G (ICH7)
29 * document number 322896-001, 322897-001: NM10
29 * document number 313056-003, 313057-017: 82801H (ICH8) 30 * document number 313056-003, 313057-017: 82801H (ICH8)
30 * document number 316972-004, 316973-012: 82801I (ICH9) 31 * document number 316972-004, 316973-012: 82801I (ICH9)
31 * document number 319973-002, 319974-002: 82801J (ICH10) 32 * document number 319973-002, 319974-002: 82801J (ICH10)
32 * document number 322169-001, 322170-003: 5 Series, 3400 Series (PCH) 33 * document number 322169-001, 322170-003: 5 Series, 3400 Series (PCH)
33 * document number 320066-003, 320257-008: EP80597 (IICH) 34 * document number 320066-003, 320257-008: EP80597 (IICH)
34 * document number TBD : Cougar Point (CPT) 35 * document number 324645-001, 324646-001: Cougar Point (CPT)
35 * document number TBD : Patsburg (PBG) 36 * document number TBD : Patsburg (PBG)
37 * document number TBD : DH89xxCC
36 */ 38 */
37 39
38/* 40/*
@@ -85,6 +87,7 @@ enum iTCO_chipsets {
85 TCO_ICH7DH, /* ICH7DH */ 87 TCO_ICH7DH, /* ICH7DH */
86 TCO_ICH7M, /* ICH7-M & ICH7-U */ 88 TCO_ICH7M, /* ICH7-M & ICH7-U */
87 TCO_ICH7MDH, /* ICH7-M DH */ 89 TCO_ICH7MDH, /* ICH7-M DH */
90 TCO_NM10, /* NM10 */
88 TCO_ICH8, /* ICH8 & ICH8R */ 91 TCO_ICH8, /* ICH8 & ICH8R */
89 TCO_ICH8DH, /* ICH8DH */ 92 TCO_ICH8DH, /* ICH8DH */
90 TCO_ICH8DO, /* ICH8DO */ 93 TCO_ICH8DO, /* ICH8DO */
@@ -149,6 +152,7 @@ enum iTCO_chipsets {
149 TCO_CPT31, /* Cougar Point */ 152 TCO_CPT31, /* Cougar Point */
150 TCO_PBG1, /* Patsburg */ 153 TCO_PBG1, /* Patsburg */
151 TCO_PBG2, /* Patsburg */ 154 TCO_PBG2, /* Patsburg */
155 TCO_DH89XXCC, /* DH89xxCC */
152}; 156};
153 157
154static struct { 158static struct {
@@ -174,6 +178,7 @@ static struct {
174 {"ICH7DH", 2}, 178 {"ICH7DH", 2},
175 {"ICH7-M or ICH7-U", 2}, 179 {"ICH7-M or ICH7-U", 2},
176 {"ICH7-M DH", 2}, 180 {"ICH7-M DH", 2},
181 {"NM10", 2},
177 {"ICH8 or ICH8R", 2}, 182 {"ICH8 or ICH8R", 2},
178 {"ICH8DH", 2}, 183 {"ICH8DH", 2},
179 {"ICH8DO", 2}, 184 {"ICH8DO", 2},
@@ -238,6 +243,7 @@ static struct {
238 {"Cougar Point", 2}, 243 {"Cougar Point", 2},
239 {"Patsburg", 2}, 244 {"Patsburg", 2},
240 {"Patsburg", 2}, 245 {"Patsburg", 2},
246 {"DH89xxCC", 2},
241 {NULL, 0} 247 {NULL, 0}
242}; 248};
243 249
@@ -291,6 +297,7 @@ static struct pci_device_id iTCO_wdt_pci_tbl[] = {
291 { ITCO_PCI_DEVICE(PCI_DEVICE_ID_INTEL_ICH7_30, TCO_ICH7DH)}, 297 { ITCO_PCI_DEVICE(PCI_DEVICE_ID_INTEL_ICH7_30, TCO_ICH7DH)},
292 { ITCO_PCI_DEVICE(PCI_DEVICE_ID_INTEL_ICH7_1, TCO_ICH7M)}, 298 { ITCO_PCI_DEVICE(PCI_DEVICE_ID_INTEL_ICH7_1, TCO_ICH7M)},
293 { ITCO_PCI_DEVICE(PCI_DEVICE_ID_INTEL_ICH7_31, TCO_ICH7MDH)}, 299 { ITCO_PCI_DEVICE(PCI_DEVICE_ID_INTEL_ICH7_31, TCO_ICH7MDH)},
300 { ITCO_PCI_DEVICE(0x27bc, TCO_NM10)},
294 { ITCO_PCI_DEVICE(PCI_DEVICE_ID_INTEL_ICH8_0, TCO_ICH8)}, 301 { ITCO_PCI_DEVICE(PCI_DEVICE_ID_INTEL_ICH8_0, TCO_ICH8)},
295 { ITCO_PCI_DEVICE(PCI_DEVICE_ID_INTEL_ICH8_2, TCO_ICH8DH)}, 302 { ITCO_PCI_DEVICE(PCI_DEVICE_ID_INTEL_ICH8_2, TCO_ICH8DH)},
296 { ITCO_PCI_DEVICE(PCI_DEVICE_ID_INTEL_ICH8_3, TCO_ICH8DO)}, 303 { ITCO_PCI_DEVICE(PCI_DEVICE_ID_INTEL_ICH8_3, TCO_ICH8DO)},
@@ -355,6 +362,7 @@ static struct pci_device_id iTCO_wdt_pci_tbl[] = {
355 { ITCO_PCI_DEVICE(0x1c5f, TCO_CPT31)}, 362 { ITCO_PCI_DEVICE(0x1c5f, TCO_CPT31)},
356 { ITCO_PCI_DEVICE(0x1d40, TCO_PBG1)}, 363 { ITCO_PCI_DEVICE(0x1d40, TCO_PBG1)},
357 { ITCO_PCI_DEVICE(0x1d41, TCO_PBG2)}, 364 { ITCO_PCI_DEVICE(0x1d41, TCO_PBG2)},
365 { ITCO_PCI_DEVICE(0x2310, TCO_DH89XXCC)},
358 { 0, }, /* End of list */ 366 { 0, }, /* End of list */
359}; 367};
360MODULE_DEVICE_TABLE(pci, iTCO_wdt_pci_tbl); 368MODULE_DEVICE_TABLE(pci, iTCO_wdt_pci_tbl);
diff --git a/drivers/watchdog/ks8695_wdt.c b/drivers/watchdog/ks8695_wdt.c
index 2852bb2e3fd9..811471903e8a 100644
--- a/drivers/watchdog/ks8695_wdt.c
+++ b/drivers/watchdog/ks8695_wdt.c
@@ -21,7 +21,7 @@
21#include <linux/watchdog.h> 21#include <linux/watchdog.h>
22#include <linux/io.h> 22#include <linux/io.h>
23#include <linux/uaccess.h> 23#include <linux/uaccess.h>
24#include <mach/timex.h> 24#include <mach/hardware.h>
25#include <mach/regs-timer.h> 25#include <mach/regs-timer.h>
26 26
27#define WDT_DEFAULT_TIME 5 /* seconds */ 27#define WDT_DEFAULT_TIME 5 /* seconds */
diff --git a/drivers/watchdog/m548x_wdt.c b/drivers/watchdog/m548x_wdt.c
new file mode 100644
index 000000000000..cabbcfe1c847
--- /dev/null
+++ b/drivers/watchdog/m548x_wdt.c
@@ -0,0 +1,227 @@
1/*
2 * drivers/watchdog/m548x_wdt.c
3 *
4 * Watchdog driver for ColdFire MCF548x processors
5 * Copyright 2010 (c) Philippe De Muyter <phdm@macqel.be>
6 *
7 * Adapted from the IXP4xx watchdog driver, which carries these notices:
8 *
9 * Author: Deepak Saxena <dsaxena@plexity.net>
10 *
11 * Copyright 2004 (c) MontaVista, Software, Inc.
12 * Based on sa1100 driver, Copyright (C) 2000 Oleg Drokin <green@crimea.edu>
13 *
14 * This file is licensed under the terms of the GNU General Public
15 * License version 2. This program is licensed "as is" without any
16 * warranty of any kind, whether express or implied.
17 */
18
19#include <linux/module.h>
20#include <linux/moduleparam.h>
21#include <linux/types.h>
22#include <linux/kernel.h>
23#include <linux/fs.h>
24#include <linux/miscdevice.h>
25#include <linux/watchdog.h>
26#include <linux/init.h>
27#include <linux/bitops.h>
28#include <linux/ioport.h>
29#include <linux/uaccess.h>
30
31#include <asm/coldfire.h>
32#include <asm/m548xsim.h>
33#include <asm/m548xgpt.h>
34
35static int nowayout = WATCHDOG_NOWAYOUT;
36static unsigned int heartbeat = 30; /* (secs) Default is 0.5 minute */
37static unsigned long wdt_status;
38
39#define WDT_IN_USE 0
40#define WDT_OK_TO_CLOSE 1
41
42static void wdt_enable(void)
43{
44 unsigned int gms0;
45
46 /* preserve GPIO usage, if any */
47 gms0 = __raw_readl(MCF_MBAR + MCF_GPT_GMS0);
48 if (gms0 & MCF_GPT_GMS_TMS_GPIO)
49 gms0 &= (MCF_GPT_GMS_TMS_GPIO | MCF_GPT_GMS_GPIO_MASK
50 | MCF_GPT_GMS_OD);
51 else
52 gms0 = MCF_GPT_GMS_TMS_GPIO | MCF_GPT_GMS_OD;
53 __raw_writel(gms0, MCF_MBAR + MCF_GPT_GMS0);
54 __raw_writel(MCF_GPT_GCIR_PRE(heartbeat*(MCF_BUSCLK/0xffff)) |
55 MCF_GPT_GCIR_CNT(0xffff), MCF_MBAR + MCF_GPT_GCIR0);
56 gms0 |= MCF_GPT_GMS_OCPW(0xA5) | MCF_GPT_GMS_WDEN | MCF_GPT_GMS_CE;
57 __raw_writel(gms0, MCF_MBAR + MCF_GPT_GMS0);
58}
59
60static void wdt_disable(void)
61{
62 unsigned int gms0;
63
64 /* disable watchdog */
65 gms0 = __raw_readl(MCF_MBAR + MCF_GPT_GMS0);
66 gms0 &= ~(MCF_GPT_GMS_WDEN | MCF_GPT_GMS_CE);
67 __raw_writel(gms0, MCF_MBAR + MCF_GPT_GMS0);
68}
69
70static void wdt_keepalive(void)
71{
72 unsigned int gms0;
73
74 gms0 = __raw_readl(MCF_MBAR + MCF_GPT_GMS0);
75 gms0 |= MCF_GPT_GMS_OCPW(0xA5);
76 __raw_writel(gms0, MCF_MBAR + MCF_GPT_GMS0);
77}
78
79static int m548x_wdt_open(struct inode *inode, struct file *file)
80{
81 if (test_and_set_bit(WDT_IN_USE, &wdt_status))
82 return -EBUSY;
83
84 clear_bit(WDT_OK_TO_CLOSE, &wdt_status);
85 wdt_enable();
86 return nonseekable_open(inode, file);
87}
88
89static ssize_t m548x_wdt_write(struct file *file, const char *data,
90 size_t len, loff_t *ppos)
91{
92 if (len) {
93 if (!nowayout) {
94 size_t i;
95
96 clear_bit(WDT_OK_TO_CLOSE, &wdt_status);
97
98 for (i = 0; i != len; i++) {
99 char c;
100
101 if (get_user(c, data + i))
102 return -EFAULT;
103 if (c == 'V')
104 set_bit(WDT_OK_TO_CLOSE, &wdt_status);
105 }
106 }
107 wdt_keepalive();
108 }
109 return len;
110}
111
112static const struct watchdog_info ident = {
113 .options = WDIOF_MAGICCLOSE | WDIOF_SETTIMEOUT |
114 WDIOF_KEEPALIVEPING,
115 .identity = "Coldfire M548x Watchdog",
116};
117
118static long m548x_wdt_ioctl(struct file *file, unsigned int cmd,
119 unsigned long arg)
120{
121 int ret = -ENOTTY;
122 int time;
123
124 switch (cmd) {
125 case WDIOC_GETSUPPORT:
126 ret = copy_to_user((struct watchdog_info *)arg, &ident,
127 sizeof(ident)) ? -EFAULT : 0;
128 break;
129
130 case WDIOC_GETSTATUS:
131 ret = put_user(0, (int *)arg);
132 break;
133
134 case WDIOC_GETBOOTSTATUS:
135 ret = put_user(0, (int *)arg);
136 break;
137
138 case WDIOC_KEEPALIVE:
139 wdt_keepalive();
140 ret = 0;
141 break;
142
143 case WDIOC_SETTIMEOUT:
144 ret = get_user(time, (int *)arg);
145 if (ret)
146 break;
147
148 if (time <= 0 || time > 30) {
149 ret = -EINVAL;
150 break;
151 }
152
153 heartbeat = time;
154 wdt_enable();
155 /* Fall through */
156
157 case WDIOC_GETTIMEOUT:
158 ret = put_user(heartbeat, (int *)arg);
159 break;
160 }
161 return ret;
162}
163
164static int m548x_wdt_release(struct inode *inode, struct file *file)
165{
166 if (test_bit(WDT_OK_TO_CLOSE, &wdt_status))
167 wdt_disable();
168 else {
169 printk(KERN_CRIT "WATCHDOG: Device closed unexpectedly - "
170 "timer will not stop\n");
171 wdt_keepalive();
172 }
173 clear_bit(WDT_IN_USE, &wdt_status);
174 clear_bit(WDT_OK_TO_CLOSE, &wdt_status);
175
176 return 0;
177}
178
179
180static const struct file_operations m548x_wdt_fops = {
181 .owner = THIS_MODULE,
182 .llseek = no_llseek,
183 .write = m548x_wdt_write,
184 .unlocked_ioctl = m548x_wdt_ioctl,
185 .open = m548x_wdt_open,
186 .release = m548x_wdt_release,
187};
188
189static struct miscdevice m548x_wdt_miscdev = {
190 .minor = WATCHDOG_MINOR,
191 .name = "watchdog",
192 .fops = &m548x_wdt_fops,
193};
194
195static int __init m548x_wdt_init(void)
196{
197 if (!request_mem_region(MCF_MBAR + MCF_GPT_GCIR0, 4,
198 "Coldfire M548x Watchdog")) {
199 printk(KERN_WARNING
200 "Coldfire M548x Watchdog : I/O region busy\n");
201 return -EBUSY;
202 }
203 printk(KERN_INFO "ColdFire watchdog driver is loaded.\n");
204
205 return misc_register(&m548x_wdt_miscdev);
206}
207
208static void __exit m548x_wdt_exit(void)
209{
210 misc_deregister(&m548x_wdt_miscdev);
211 release_mem_region(MCF_MBAR + MCF_GPT_GCIR0, 4);
212}
213
214module_init(m548x_wdt_init);
215module_exit(m548x_wdt_exit);
216
217MODULE_AUTHOR("Philippe De Muyter <phdm@macqel.be>");
218MODULE_DESCRIPTION("Coldfire M548x Watchdog");
219
220module_param(heartbeat, int, 0);
221MODULE_PARM_DESC(heartbeat, "Watchdog heartbeat in seconds (default 30s)");
222
223module_param(nowayout, int, 0);
224MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started");
225
226MODULE_LICENSE("GPL");
227MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
diff --git a/drivers/watchdog/nv_tco.c b/drivers/watchdog/nv_tco.c
new file mode 100644
index 000000000000..1a50aa7079bf
--- /dev/null
+++ b/drivers/watchdog/nv_tco.c
@@ -0,0 +1,512 @@
1/*
2 * nv_tco 0.01: TCO timer driver for NV chipsets
3 *
4 * (c) Copyright 2005 Google Inc., All Rights Reserved.
5 *
6 * Based off i8xx_tco.c:
7 * (c) Copyright 2000 kernel concepts <nils@kernelconcepts.de>, All Rights
8 * Reserved.
9 * http://www.kernelconcepts.de
10 *
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License
13 * as published by the Free Software Foundation; either version
14 * 2 of the License, or (at your option) any later version.
15 *
16 * TCO timer driver for NV chipsets
17 * based on softdog.c by Alan Cox <alan@redhat.com>
18 */
19
20/*
21 * Includes, defines, variables, module parameters, ...
22 */
23
24#include <linux/module.h>
25#include <linux/moduleparam.h>
26#include <linux/types.h>
27#include <linux/miscdevice.h>
28#include <linux/watchdog.h>
29#include <linux/init.h>
30#include <linux/fs.h>
31#include <linux/pci.h>
32#include <linux/ioport.h>
33#include <linux/jiffies.h>
34#include <linux/platform_device.h>
35#include <linux/uaccess.h>
36#include <linux/io.h>
37
38#include "nv_tco.h"
39
40/* Module and version information */
41#define TCO_VERSION "0.01"
42#define TCO_MODULE_NAME "NV_TCO"
43#define TCO_DRIVER_NAME TCO_MODULE_NAME ", v" TCO_VERSION
44#define PFX TCO_MODULE_NAME ": "
45
46/* internal variables */
47static unsigned int tcobase;
48static DEFINE_SPINLOCK(tco_lock); /* Guards the hardware */
49static unsigned long timer_alive;
50static char tco_expect_close;
51static struct pci_dev *tco_pci;
52
53/* the watchdog platform device */
54static struct platform_device *nv_tco_platform_device;
55
56/* module parameters */
57#define WATCHDOG_HEARTBEAT 30 /* 30 sec default heartbeat (2<heartbeat<39) */
58static int heartbeat = WATCHDOG_HEARTBEAT; /* in seconds */
59module_param(heartbeat, int, 0);
60MODULE_PARM_DESC(heartbeat, "Watchdog heartbeat in seconds. (2<heartbeat<39, "
61 "default=" __MODULE_STRING(WATCHDOG_HEARTBEAT) ")");
62
63static int nowayout = WATCHDOG_NOWAYOUT;
64module_param(nowayout, int, 0);
65MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started"
66 " (default=" __MODULE_STRING(WATCHDOG_NOWAYOUT) ")");
67
68/*
69 * Some TCO specific functions
70 */
71static inline unsigned char seconds_to_ticks(int seconds)
72{
73 /* the internal timer is stored as ticks which decrement
74 * every 0.6 seconds */
75 return (seconds * 10) / 6;
76}
77
78static void tco_timer_start(void)
79{
80 u32 val;
81 unsigned long flags;
82
83 spin_lock_irqsave(&tco_lock, flags);
84 val = inl(TCO_CNT(tcobase));
85 val &= ~TCO_CNT_TCOHALT;
86 outl(val, TCO_CNT(tcobase));
87 spin_unlock_irqrestore(&tco_lock, flags);
88}
89
90static void tco_timer_stop(void)
91{
92 u32 val;
93 unsigned long flags;
94
95 spin_lock_irqsave(&tco_lock, flags);
96 val = inl(TCO_CNT(tcobase));
97 val |= TCO_CNT_TCOHALT;
98 outl(val, TCO_CNT(tcobase));
99 spin_unlock_irqrestore(&tco_lock, flags);
100}
101
102static void tco_timer_keepalive(void)
103{
104 unsigned long flags;
105
106 spin_lock_irqsave(&tco_lock, flags);
107 outb(0x01, TCO_RLD(tcobase));
108 spin_unlock_irqrestore(&tco_lock, flags);
109}
110
111static int tco_timer_set_heartbeat(int t)
112{
113 int ret = 0;
114 unsigned char tmrval;
115 unsigned long flags;
116 u8 val;
117
118 /*
119 * note seconds_to_ticks(t) > t, so if t > 0x3f, so is
120 * tmrval=seconds_to_ticks(t). Check that the count in seconds isn't
121 * out of range on it's own (to avoid overflow in tmrval).
122 */
123 if (t < 0 || t > 0x3f)
124 return -EINVAL;
125 tmrval = seconds_to_ticks(t);
126
127 /* "Values of 0h-3h are ignored and should not be attempted" */
128 if (tmrval > 0x3f || tmrval < 0x04)
129 return -EINVAL;
130
131 /* Write new heartbeat to watchdog */
132 spin_lock_irqsave(&tco_lock, flags);
133 val = inb(TCO_TMR(tcobase));
134 val &= 0xc0;
135 val |= tmrval;
136 outb(val, TCO_TMR(tcobase));
137 val = inb(TCO_TMR(tcobase));
138
139 if ((val & 0x3f) != tmrval)
140 ret = -EINVAL;
141 spin_unlock_irqrestore(&tco_lock, flags);
142
143 if (ret)
144 return ret;
145
146 heartbeat = t;
147 return 0;
148}
149
150/*
151 * /dev/watchdog handling
152 */
153
154static int nv_tco_open(struct inode *inode, struct file *file)
155{
156 /* /dev/watchdog can only be opened once */
157 if (test_and_set_bit(0, &timer_alive))
158 return -EBUSY;
159
160 /* Reload and activate timer */
161 tco_timer_keepalive();
162 tco_timer_start();
163 return nonseekable_open(inode, file);
164}
165
166static int nv_tco_release(struct inode *inode, struct file *file)
167{
168 /* Shut off the timer */
169 if (tco_expect_close == 42) {
170 tco_timer_stop();
171 } else {
172 printk(KERN_CRIT PFX "Unexpected close, not stopping "
173 "watchdog!\n");
174 tco_timer_keepalive();
175 }
176 clear_bit(0, &timer_alive);
177 tco_expect_close = 0;
178 return 0;
179}
180
181static ssize_t nv_tco_write(struct file *file, const char __user *data,
182 size_t len, loff_t *ppos)
183{
184 /* See if we got the magic character 'V' and reload the timer */
185 if (len) {
186 if (!nowayout) {
187 size_t i;
188
189 /*
190 * note: just in case someone wrote the magic character
191 * five months ago...
192 */
193 tco_expect_close = 0;
194
195 /*
196 * scan to see whether or not we got the magic
197 * character
198 */
199 for (i = 0; i != len; i++) {
200 char c;
201 if (get_user(c, data + i))
202 return -EFAULT;
203 if (c == 'V')
204 tco_expect_close = 42;
205 }
206 }
207
208 /* someone wrote to us, we should reload the timer */
209 tco_timer_keepalive();
210 }
211 return len;
212}
213
214static long nv_tco_ioctl(struct file *file, unsigned int cmd,
215 unsigned long arg)
216{
217 int new_options, retval = -EINVAL;
218 int new_heartbeat;
219 void __user *argp = (void __user *)arg;
220 int __user *p = argp;
221 static const struct watchdog_info ident = {
222 .options = WDIOF_SETTIMEOUT |
223 WDIOF_KEEPALIVEPING |
224 WDIOF_MAGICCLOSE,
225 .firmware_version = 0,
226 .identity = TCO_MODULE_NAME,
227 };
228
229 switch (cmd) {
230 case WDIOC_GETSUPPORT:
231 return copy_to_user(argp, &ident, sizeof(ident)) ? -EFAULT : 0;
232 case WDIOC_GETSTATUS:
233 case WDIOC_GETBOOTSTATUS:
234 return put_user(0, p);
235 case WDIOC_SETOPTIONS:
236 if (get_user(new_options, p))
237 return -EFAULT;
238 if (new_options & WDIOS_DISABLECARD) {
239 tco_timer_stop();
240 retval = 0;
241 }
242 if (new_options & WDIOS_ENABLECARD) {
243 tco_timer_keepalive();
244 tco_timer_start();
245 retval = 0;
246 }
247 return retval;
248 case WDIOC_KEEPALIVE:
249 tco_timer_keepalive();
250 return 0;
251 case WDIOC_SETTIMEOUT:
252 if (get_user(new_heartbeat, p))
253 return -EFAULT;
254 if (tco_timer_set_heartbeat(new_heartbeat))
255 return -EINVAL;
256 tco_timer_keepalive();
257 /* Fall through */
258 case WDIOC_GETTIMEOUT:
259 return put_user(heartbeat, p);
260 default:
261 return -ENOTTY;
262 }
263}
264
265/*
266 * Kernel Interfaces
267 */
268
269static const struct file_operations nv_tco_fops = {
270 .owner = THIS_MODULE,
271 .llseek = no_llseek,
272 .write = nv_tco_write,
273 .unlocked_ioctl = nv_tco_ioctl,
274 .open = nv_tco_open,
275 .release = nv_tco_release,
276};
277
278static struct miscdevice nv_tco_miscdev = {
279 .minor = WATCHDOG_MINOR,
280 .name = "watchdog",
281 .fops = &nv_tco_fops,
282};
283
284/*
285 * Data for PCI driver interface
286 *
287 * This data only exists for exporting the supported
288 * PCI ids via MODULE_DEVICE_TABLE. We do not actually
289 * register a pci_driver, because someone else might one day
290 * want to register another driver on the same PCI id.
291 */
292static struct pci_device_id tco_pci_tbl[] = {
293 { PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE_MCP51_SMBUS,
294 PCI_ANY_ID, PCI_ANY_ID, },
295 { PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE_MCP55_SMBUS,
296 PCI_ANY_ID, PCI_ANY_ID, },
297 { 0, }, /* End of list */
298};
299MODULE_DEVICE_TABLE(pci, tco_pci_tbl);
300
301/*
302 * Init & exit routines
303 */
304
305static unsigned char __init nv_tco_getdevice(void)
306{
307 struct pci_dev *dev = NULL;
308 u32 val;
309
310 /* Find the PCI device */
311 for_each_pci_dev(dev) {
312 if (pci_match_id(tco_pci_tbl, dev) != NULL) {
313 tco_pci = dev;
314 break;
315 }
316 }
317
318 if (!tco_pci)
319 return 0;
320
321 /* Find the base io port */
322 pci_read_config_dword(tco_pci, 0x64, &val);
323 val &= 0xffff;
324 if (val == 0x0001 || val == 0x0000) {
325 /* Something is wrong here, bar isn't setup */
326 printk(KERN_ERR PFX "failed to get tcobase address\n");
327 return 0;
328 }
329 val &= 0xff00;
330 tcobase = val + 0x40;
331
332 if (!request_region(tcobase, 0x10, "NV TCO")) {
333 printk(KERN_ERR PFX "I/O address 0x%04x already in use\n",
334 tcobase);
335 return 0;
336 }
337
338 /* Set a reasonable heartbeat before we stop the timer */
339 tco_timer_set_heartbeat(30);
340
341 /*
342 * Stop the TCO before we change anything so we don't race with
343 * a zeroed timer.
344 */
345 tco_timer_keepalive();
346 tco_timer_stop();
347
348 /* Disable SMI caused by TCO */
349 if (!request_region(MCP51_SMI_EN(tcobase), 4, "NV TCO")) {
350 printk(KERN_ERR PFX "I/O address 0x%04x already in use\n",
351 MCP51_SMI_EN(tcobase));
352 goto out;
353 }
354 val = inl(MCP51_SMI_EN(tcobase));
355 val &= ~MCP51_SMI_EN_TCO;
356 outl(val, MCP51_SMI_EN(tcobase));
357 val = inl(MCP51_SMI_EN(tcobase));
358 release_region(MCP51_SMI_EN(tcobase), 4);
359 if (val & MCP51_SMI_EN_TCO) {
360 printk(KERN_ERR PFX "Could not disable SMI caused by TCO\n");
361 goto out;
362 }
363
364 /* Check chipset's NO_REBOOT bit */
365 pci_read_config_dword(tco_pci, MCP51_SMBUS_SETUP_B, &val);
366 val |= MCP51_SMBUS_SETUP_B_TCO_REBOOT;
367 pci_write_config_dword(tco_pci, MCP51_SMBUS_SETUP_B, val);
368 pci_read_config_dword(tco_pci, MCP51_SMBUS_SETUP_B, &val);
369 if (!(val & MCP51_SMBUS_SETUP_B_TCO_REBOOT)) {
370 printk(KERN_ERR PFX "failed to reset NO_REBOOT flag, reboot "
371 "disabled by hardware\n");
372 goto out;
373 }
374
375 return 1;
376out:
377 release_region(tcobase, 0x10);
378 return 0;
379}
380
381static int __devinit nv_tco_init(struct platform_device *dev)
382{
383 int ret;
384
385 /* Check whether or not the hardware watchdog is there */
386 if (!nv_tco_getdevice())
387 return -ENODEV;
388
389 /* Check to see if last reboot was due to watchdog timeout */
390 printk(KERN_INFO PFX "Watchdog reboot %sdetected.\n",
391 inl(TCO_STS(tcobase)) & TCO_STS_TCO2TO_STS ? "" : "not ");
392
393 /* Clear out the old status */
394 outl(TCO_STS_RESET, TCO_STS(tcobase));
395
396 /*
397 * Check that the heartbeat value is within it's range.
398 * If not, reset to the default.
399 */
400 if (tco_timer_set_heartbeat(heartbeat)) {
401 heartbeat = WATCHDOG_HEARTBEAT;
402 tco_timer_set_heartbeat(heartbeat);
403 printk(KERN_INFO PFX "heartbeat value must be 2<heartbeat<39, "
404 "using %d\n", heartbeat);
405 }
406
407 ret = misc_register(&nv_tco_miscdev);
408 if (ret != 0) {
409 printk(KERN_ERR PFX "cannot register miscdev on minor=%d "
410 "(err=%d)\n", WATCHDOG_MINOR, ret);
411 goto unreg_region;
412 }
413
414 clear_bit(0, &timer_alive);
415
416 tco_timer_stop();
417
418 printk(KERN_INFO PFX "initialized (0x%04x). heartbeat=%d sec "
419 "(nowayout=%d)\n", tcobase, heartbeat, nowayout);
420
421 return 0;
422
423unreg_region:
424 release_region(tcobase, 0x10);
425 return ret;
426}
427
428static void __devexit nv_tco_cleanup(void)
429{
430 u32 val;
431
432 /* Stop the timer before we leave */
433 if (!nowayout)
434 tco_timer_stop();
435
436 /* Set the NO_REBOOT bit to prevent later reboots, just for sure */
437 pci_read_config_dword(tco_pci, MCP51_SMBUS_SETUP_B, &val);
438 val &= ~MCP51_SMBUS_SETUP_B_TCO_REBOOT;
439 pci_write_config_dword(tco_pci, MCP51_SMBUS_SETUP_B, val);
440 pci_read_config_dword(tco_pci, MCP51_SMBUS_SETUP_B, &val);
441 if (val & MCP51_SMBUS_SETUP_B_TCO_REBOOT) {
442 printk(KERN_CRIT PFX "Couldn't unset REBOOT bit. Machine may "
443 "soon reset\n");
444 }
445
446 /* Deregister */
447 misc_deregister(&nv_tco_miscdev);
448 release_region(tcobase, 0x10);
449}
450
451static int __devexit nv_tco_remove(struct platform_device *dev)
452{
453 if (tcobase)
454 nv_tco_cleanup();
455
456 return 0;
457}
458
459static void nv_tco_shutdown(struct platform_device *dev)
460{
461 tco_timer_stop();
462}
463
464static struct platform_driver nv_tco_driver = {
465 .probe = nv_tco_init,
466 .remove = __devexit_p(nv_tco_remove),
467 .shutdown = nv_tco_shutdown,
468 .driver = {
469 .owner = THIS_MODULE,
470 .name = TCO_MODULE_NAME,
471 },
472};
473
474static int __init nv_tco_init_module(void)
475{
476 int err;
477
478 printk(KERN_INFO PFX "NV TCO WatchDog Timer Driver v%s\n",
479 TCO_VERSION);
480
481 err = platform_driver_register(&nv_tco_driver);
482 if (err)
483 return err;
484
485 nv_tco_platform_device = platform_device_register_simple(
486 TCO_MODULE_NAME, -1, NULL, 0);
487 if (IS_ERR(nv_tco_platform_device)) {
488 err = PTR_ERR(nv_tco_platform_device);
489 goto unreg_platform_driver;
490 }
491
492 return 0;
493
494unreg_platform_driver:
495 platform_driver_unregister(&nv_tco_driver);
496 return err;
497}
498
499static void __exit nv_tco_cleanup_module(void)
500{
501 platform_device_unregister(nv_tco_platform_device);
502 platform_driver_unregister(&nv_tco_driver);
503 printk(KERN_INFO PFX "NV TCO Watchdog Module Unloaded.\n");
504}
505
506module_init(nv_tco_init_module);
507module_exit(nv_tco_cleanup_module);
508
509MODULE_AUTHOR("Mike Waychison");
510MODULE_DESCRIPTION("TCO timer driver for NV chipsets");
511MODULE_LICENSE("GPL");
512MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
diff --git a/drivers/watchdog/nv_tco.h b/drivers/watchdog/nv_tco.h
new file mode 100644
index 000000000000..c2d1d04e055b
--- /dev/null
+++ b/drivers/watchdog/nv_tco.h
@@ -0,0 +1,64 @@
1/*
2 * nv_tco: TCO timer driver for nVidia chipsets.
3 *
4 * (c) Copyright 2005 Google Inc., All Rights Reserved.
5 *
6 * Supported Chipsets:
7 * - MCP51/MCP55
8 *
9 * (c) Copyright 2000 kernel concepts <nils@kernelconcepts.de>, All Rights
10 * Reserved.
11 * http://www.kernelconcepts.de
12 *
13 * This program is free software; you can redistribute it and/or
14 * modify it under the terms of the GNU General Public License
15 * as published by the Free Software Foundation; either version
16 * 2 of the License, or (at your option) any later version.
17 *
18 * Neither kernel concepts nor Nils Faerber admit liability nor provide
19 * warranty for any of this software. This material is provided
20 * "AS-IS" and at no charge.
21 *
22 * (c) Copyright 2000 kernel concepts <nils@kernelconcepts.de>
23 * developed for
24 * Jentro AG, Haar/Munich (Germany)
25 *
26 * TCO timer driver for NV chipsets
27 * based on softdog.c by Alan Cox <alan@redhat.com>
28 */
29
30/*
31 * Some address definitions for the TCO
32 */
33
34#define TCO_RLD(base) ((base) + 0x00) /* TCO Timer Reload and Current Value */
35#define TCO_TMR(base) ((base) + 0x01) /* TCO Timer Initial Value */
36
37#define TCO_STS(base) ((base) + 0x04) /* TCO Status Register */
38/*
39 * TCO Boot Status bit: set on TCO reset, reset by software or standby
40 * power-good (survives reboots), unfortunately this bit is never
41 * set.
42 */
43# define TCO_STS_BOOT_STS (1 << 9)
44/*
45 * first and 2nd timeout status bits, these also survive a warm boot,
46 * and they work, so we use them.
47 */
48# define TCO_STS_TCO_INT_STS (1 << 1)
49# define TCO_STS_TCO2TO_STS (1 << 10)
50# define TCO_STS_RESET (TCO_STS_BOOT_STS | TCO_STS_TCO2TO_STS | \
51 TCO_STS_TCO_INT_STS)
52
53#define TCO_CNT(base) ((base) + 0x08) /* TCO Control Register */
54# define TCO_CNT_TCOHALT (1 << 12)
55
56#define MCP51_SMBUS_SETUP_B 0xe8
57# define MCP51_SMBUS_SETUP_B_TCO_REBOOT (1 << 25)
58
59/*
60 * The SMI_EN register is at the base io address + 0x04,
61 * while TCOBASE is + 0x40.
62 */
63#define MCP51_SMI_EN(base) ((base) - 0x40 + 0x04)
64# define MCP51_SMI_EN_TCO ((1 << 4) | (1 << 5))
diff --git a/drivers/watchdog/sp5100_tco.c b/drivers/watchdog/sp5100_tco.c
new file mode 100644
index 000000000000..808372883e88
--- /dev/null
+++ b/drivers/watchdog/sp5100_tco.c
@@ -0,0 +1,480 @@
1/*
2 * sp5100_tco : TCO timer driver for sp5100 chipsets
3 *
4 * (c) Copyright 2009 Google Inc., All Rights Reserved.
5 *
6 * Based on i8xx_tco.c:
7 * (c) Copyright 2000 kernel concepts <nils@kernelconcepts.de>, All Rights
8 * Reserved.
9 * http://www.kernelconcepts.de
10 *
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License
13 * as published by the Free Software Foundation; either version
14 * 2 of the License, or (at your option) any later version.
15 *
16 * See AMD Publication 43009 "AMD SB700/710/750 Register Reference Guide"
17 */
18
19/*
20 * Includes, defines, variables, module parameters, ...
21 */
22
23#include <linux/module.h>
24#include <linux/moduleparam.h>
25#include <linux/types.h>
26#include <linux/miscdevice.h>
27#include <linux/watchdog.h>
28#include <linux/init.h>
29#include <linux/fs.h>
30#include <linux/pci.h>
31#include <linux/ioport.h>
32#include <linux/platform_device.h>
33#include <linux/uaccess.h>
34#include <linux/io.h>
35
36#include "sp5100_tco.h"
37
38/* Module and version information */
39#define TCO_VERSION "0.01"
40#define TCO_MODULE_NAME "SP5100 TCO timer"
41#define TCO_DRIVER_NAME TCO_MODULE_NAME ", v" TCO_VERSION
42#define PFX TCO_MODULE_NAME ": "
43
44/* internal variables */
45static void __iomem *tcobase;
46static unsigned int pm_iobase;
47static DEFINE_SPINLOCK(tco_lock); /* Guards the hardware */
48static unsigned long timer_alive;
49static char tco_expect_close;
50static struct pci_dev *sp5100_tco_pci;
51
52/* the watchdog platform device */
53static struct platform_device *sp5100_tco_platform_device;
54
55/* module parameters */
56
57#define WATCHDOG_HEARTBEAT 60 /* 60 sec default heartbeat. */
58static int heartbeat = WATCHDOG_HEARTBEAT; /* in seconds */
59module_param(heartbeat, int, 0);
60MODULE_PARM_DESC(heartbeat, "Watchdog heartbeat in seconds. (default="
61 __MODULE_STRING(WATCHDOG_HEARTBEAT) ")");
62
63static int nowayout = WATCHDOG_NOWAYOUT;
64module_param(nowayout, int, 0);
65MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started"
66 " (default=" __MODULE_STRING(WATCHDOG_NOWAYOUT) ")");
67
68/*
69 * Some TCO specific functions
70 */
71static void tco_timer_start(void)
72{
73 u32 val;
74 unsigned long flags;
75
76 spin_lock_irqsave(&tco_lock, flags);
77 val = readl(SP5100_WDT_CONTROL(tcobase));
78 val |= SP5100_WDT_START_STOP_BIT;
79 writel(val, SP5100_WDT_CONTROL(tcobase));
80 spin_unlock_irqrestore(&tco_lock, flags);
81}
82
83static void tco_timer_stop(void)
84{
85 u32 val;
86 unsigned long flags;
87
88 spin_lock_irqsave(&tco_lock, flags);
89 val = readl(SP5100_WDT_CONTROL(tcobase));
90 val &= ~SP5100_WDT_START_STOP_BIT;
91 writel(val, SP5100_WDT_CONTROL(tcobase));
92 spin_unlock_irqrestore(&tco_lock, flags);
93}
94
95static void tco_timer_keepalive(void)
96{
97 u32 val;
98 unsigned long flags;
99
100 spin_lock_irqsave(&tco_lock, flags);
101 val = readl(SP5100_WDT_CONTROL(tcobase));
102 val |= SP5100_WDT_TRIGGER_BIT;
103 writel(val, SP5100_WDT_CONTROL(tcobase));
104 spin_unlock_irqrestore(&tco_lock, flags);
105}
106
107static int tco_timer_set_heartbeat(int t)
108{
109 unsigned long flags;
110
111 if (t < 0 || t > 0xffff)
112 return -EINVAL;
113
114 /* Write new heartbeat to watchdog */
115 spin_lock_irqsave(&tco_lock, flags);
116 writel(t, SP5100_WDT_COUNT(tcobase));
117 spin_unlock_irqrestore(&tco_lock, flags);
118
119 heartbeat = t;
120 return 0;
121}
122
123/*
124 * /dev/watchdog handling
125 */
126
127static int sp5100_tco_open(struct inode *inode, struct file *file)
128{
129 /* /dev/watchdog can only be opened once */
130 if (test_and_set_bit(0, &timer_alive))
131 return -EBUSY;
132
133 /* Reload and activate timer */
134 tco_timer_start();
135 tco_timer_keepalive();
136 return nonseekable_open(inode, file);
137}
138
139static int sp5100_tco_release(struct inode *inode, struct file *file)
140{
141 /* Shut off the timer. */
142 if (tco_expect_close == 42) {
143 tco_timer_stop();
144 } else {
145 printk(KERN_CRIT PFX
146 "Unexpected close, not stopping watchdog!\n");
147 tco_timer_keepalive();
148 }
149 clear_bit(0, &timer_alive);
150 tco_expect_close = 0;
151 return 0;
152}
153
154static ssize_t sp5100_tco_write(struct file *file, const char __user *data,
155 size_t len, loff_t *ppos)
156{
157 /* See if we got the magic character 'V' and reload the timer */
158 if (len) {
159 if (!nowayout) {
160 size_t i;
161
162 /* note: just in case someone wrote the magic character
163 * five months ago... */
164 tco_expect_close = 0;
165
166 /* scan to see whether or not we got the magic character
167 */
168 for (i = 0; i != len; i++) {
169 char c;
170 if (get_user(c, data + i))
171 return -EFAULT;
172 if (c == 'V')
173 tco_expect_close = 42;
174 }
175 }
176
177 /* someone wrote to us, we should reload the timer */
178 tco_timer_keepalive();
179 }
180 return len;
181}
182
183static long sp5100_tco_ioctl(struct file *file, unsigned int cmd,
184 unsigned long arg)
185{
186 int new_options, retval = -EINVAL;
187 int new_heartbeat;
188 void __user *argp = (void __user *)arg;
189 int __user *p = argp;
190 static const struct watchdog_info ident = {
191 .options = WDIOF_SETTIMEOUT |
192 WDIOF_KEEPALIVEPING |
193 WDIOF_MAGICCLOSE,
194 .firmware_version = 0,
195 .identity = TCO_MODULE_NAME,
196 };
197
198 switch (cmd) {
199 case WDIOC_GETSUPPORT:
200 return copy_to_user(argp, &ident,
201 sizeof(ident)) ? -EFAULT : 0;
202 case WDIOC_GETSTATUS:
203 case WDIOC_GETBOOTSTATUS:
204 return put_user(0, p);
205 case WDIOC_SETOPTIONS:
206 if (get_user(new_options, p))
207 return -EFAULT;
208 if (new_options & WDIOS_DISABLECARD) {
209 tco_timer_stop();
210 retval = 0;
211 }
212 if (new_options & WDIOS_ENABLECARD) {
213 tco_timer_start();
214 tco_timer_keepalive();
215 retval = 0;
216 }
217 return retval;
218 case WDIOC_KEEPALIVE:
219 tco_timer_keepalive();
220 return 0;
221 case WDIOC_SETTIMEOUT:
222 if (get_user(new_heartbeat, p))
223 return -EFAULT;
224 if (tco_timer_set_heartbeat(new_heartbeat))
225 return -EINVAL;
226 tco_timer_keepalive();
227 /* Fall through */
228 case WDIOC_GETTIMEOUT:
229 return put_user(heartbeat, p);
230 default:
231 return -ENOTTY;
232 }
233}
234
235/*
236 * Kernel Interfaces
237 */
238
239static const struct file_operations sp5100_tco_fops = {
240 .owner = THIS_MODULE,
241 .llseek = no_llseek,
242 .write = sp5100_tco_write,
243 .unlocked_ioctl = sp5100_tco_ioctl,
244 .open = sp5100_tco_open,
245 .release = sp5100_tco_release,
246};
247
248static struct miscdevice sp5100_tco_miscdev = {
249 .minor = WATCHDOG_MINOR,
250 .name = "watchdog",
251 .fops = &sp5100_tco_fops,
252};
253
254/*
255 * Data for PCI driver interface
256 *
257 * This data only exists for exporting the supported
258 * PCI ids via MODULE_DEVICE_TABLE. We do not actually
259 * register a pci_driver, because someone else might
260 * want to register another driver on the same PCI id.
261 */
262static struct pci_device_id sp5100_tco_pci_tbl[] = {
263 { PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_SBX00_SMBUS, PCI_ANY_ID,
264 PCI_ANY_ID, },
265 { 0, }, /* End of list */
266};
267MODULE_DEVICE_TABLE(pci, sp5100_tco_pci_tbl);
268
269/*
270 * Init & exit routines
271 */
272
273static unsigned char __devinit sp5100_tco_setupdevice(void)
274{
275 struct pci_dev *dev = NULL;
276 u32 val;
277
278 /* Match the PCI device */
279 for_each_pci_dev(dev) {
280 if (pci_match_id(sp5100_tco_pci_tbl, dev) != NULL) {
281 sp5100_tco_pci = dev;
282 break;
283 }
284 }
285
286 if (!sp5100_tco_pci)
287 return 0;
288
289 /* Request the IO ports used by this driver */
290 pm_iobase = SP5100_IO_PM_INDEX_REG;
291 if (!request_region(pm_iobase, SP5100_PM_IOPORTS_SIZE, "SP5100 TCO")) {
292 printk(KERN_ERR PFX "I/O address 0x%04x already in use\n",
293 pm_iobase);
294 goto exit;
295 }
296
297 /* Find the watchdog base address. */
298 outb(SP5100_PM_WATCHDOG_BASE3, SP5100_IO_PM_INDEX_REG);
299 val = inb(SP5100_IO_PM_DATA_REG);
300 outb(SP5100_PM_WATCHDOG_BASE2, SP5100_IO_PM_INDEX_REG);
301 val = val << 8 | inb(SP5100_IO_PM_DATA_REG);
302 outb(SP5100_PM_WATCHDOG_BASE1, SP5100_IO_PM_INDEX_REG);
303 val = val << 8 | inb(SP5100_IO_PM_DATA_REG);
304 outb(SP5100_PM_WATCHDOG_BASE0, SP5100_IO_PM_INDEX_REG);
305 /* Low three bits of BASE0 are reserved. */
306 val = val << 8 | (inb(SP5100_IO_PM_DATA_REG) & 0xf8);
307
308 tcobase = ioremap(val, SP5100_WDT_MEM_MAP_SIZE);
309 if (tcobase == 0) {
310 printk(KERN_ERR PFX "failed to get tcobase address\n");
311 goto unreg_region;
312 }
313
314 /* Enable watchdog decode bit */
315 pci_read_config_dword(sp5100_tco_pci,
316 SP5100_PCI_WATCHDOG_MISC_REG,
317 &val);
318
319 val |= SP5100_PCI_WATCHDOG_DECODE_EN;
320
321 pci_write_config_dword(sp5100_tco_pci,
322 SP5100_PCI_WATCHDOG_MISC_REG,
323 val);
324
325 /* Enable Watchdog timer and set the resolution to 1 sec. */
326 outb(SP5100_PM_WATCHDOG_CONTROL, SP5100_IO_PM_INDEX_REG);
327 val = inb(SP5100_IO_PM_DATA_REG);
328 val |= SP5100_PM_WATCHDOG_SECOND_RES;
329 val &= ~SP5100_PM_WATCHDOG_DISABLE;
330 outb(val, SP5100_IO_PM_DATA_REG);
331
332 /* Check that the watchdog action is set to reset the system. */
333 val = readl(SP5100_WDT_CONTROL(tcobase));
334 val &= ~SP5100_PM_WATCHDOG_ACTION_RESET;
335 writel(val, SP5100_WDT_CONTROL(tcobase));
336
337 /* Set a reasonable heartbeat before we stop the timer */
338 tco_timer_set_heartbeat(heartbeat);
339
340 /*
341 * Stop the TCO before we change anything so we don't race with
342 * a zeroed timer.
343 */
344 tco_timer_stop();
345
346 /* Done */
347 return 1;
348
349 iounmap(tcobase);
350unreg_region:
351 release_region(pm_iobase, SP5100_PM_IOPORTS_SIZE);
352exit:
353 return 0;
354}
355
356static int __devinit sp5100_tco_init(struct platform_device *dev)
357{
358 int ret;
359 u32 val;
360
361 /* Check whether or not the hardware watchdog is there. If found, then
362 * set it up.
363 */
364 if (!sp5100_tco_setupdevice())
365 return -ENODEV;
366
367 /* Check to see if last reboot was due to watchdog timeout */
368 printk(KERN_INFO PFX "Watchdog reboot %sdetected.\n",
369 readl(SP5100_WDT_CONTROL(tcobase)) & SP5100_PM_WATCHDOG_FIRED ?
370 "" : "not ");
371
372 /* Clear out the old status */
373 val = readl(SP5100_WDT_CONTROL(tcobase));
374 val &= ~SP5100_PM_WATCHDOG_FIRED;
375 writel(val, SP5100_WDT_CONTROL(tcobase));
376
377 /*
378 * Check that the heartbeat value is within it's range.
379 * If not, reset to the default.
380 */
381 if (tco_timer_set_heartbeat(heartbeat)) {
382 heartbeat = WATCHDOG_HEARTBEAT;
383 tco_timer_set_heartbeat(heartbeat);
384 }
385
386 ret = misc_register(&sp5100_tco_miscdev);
387 if (ret != 0) {
388 printk(KERN_ERR PFX "cannot register miscdev on minor="
389 "%d (err=%d)\n",
390 WATCHDOG_MINOR, ret);
391 goto exit;
392 }
393
394 clear_bit(0, &timer_alive);
395
396 printk(KERN_INFO PFX "initialized (0x%p). heartbeat=%d sec"
397 " (nowayout=%d)\n",
398 tcobase, heartbeat, nowayout);
399
400 return 0;
401
402exit:
403 iounmap(tcobase);
404 release_region(pm_iobase, SP5100_PM_IOPORTS_SIZE);
405 return ret;
406}
407
408static void __devexit sp5100_tco_cleanup(void)
409{
410 /* Stop the timer before we leave */
411 if (!nowayout)
412 tco_timer_stop();
413
414 /* Deregister */
415 misc_deregister(&sp5100_tco_miscdev);
416 iounmap(tcobase);
417 release_region(pm_iobase, SP5100_PM_IOPORTS_SIZE);
418}
419
420static int __devexit sp5100_tco_remove(struct platform_device *dev)
421{
422 if (tcobase)
423 sp5100_tco_cleanup();
424 return 0;
425}
426
427static void sp5100_tco_shutdown(struct platform_device *dev)
428{
429 tco_timer_stop();
430}
431
432static struct platform_driver sp5100_tco_driver = {
433 .probe = sp5100_tco_init,
434 .remove = __devexit_p(sp5100_tco_remove),
435 .shutdown = sp5100_tco_shutdown,
436 .driver = {
437 .owner = THIS_MODULE,
438 .name = TCO_MODULE_NAME,
439 },
440};
441
442static int __init sp5100_tco_init_module(void)
443{
444 int err;
445
446 printk(KERN_INFO PFX "SP5100 TCO WatchDog Timer Driver v%s\n",
447 TCO_VERSION);
448
449 err = platform_driver_register(&sp5100_tco_driver);
450 if (err)
451 return err;
452
453 sp5100_tco_platform_device = platform_device_register_simple(
454 TCO_MODULE_NAME, -1, NULL, 0);
455 if (IS_ERR(sp5100_tco_platform_device)) {
456 err = PTR_ERR(sp5100_tco_platform_device);
457 goto unreg_platform_driver;
458 }
459
460 return 0;
461
462unreg_platform_driver:
463 platform_driver_unregister(&sp5100_tco_driver);
464 return err;
465}
466
467static void __exit sp5100_tco_cleanup_module(void)
468{
469 platform_device_unregister(sp5100_tco_platform_device);
470 platform_driver_unregister(&sp5100_tco_driver);
471 printk(KERN_INFO PFX "SP5100 TCO Watchdog Module Unloaded.\n");
472}
473
474module_init(sp5100_tco_init_module);
475module_exit(sp5100_tco_cleanup_module);
476
477MODULE_AUTHOR("Priyanka Gupta");
478MODULE_DESCRIPTION("TCO timer driver for SP5100 chipset");
479MODULE_LICENSE("GPL");
480MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
diff --git a/drivers/watchdog/sp5100_tco.h b/drivers/watchdog/sp5100_tco.h
new file mode 100644
index 000000000000..a5a16cc90a34
--- /dev/null
+++ b/drivers/watchdog/sp5100_tco.h
@@ -0,0 +1,41 @@
1/*
2 * sp5100_tco: TCO timer driver for sp5100 chipsets.
3 *
4 * (c) Copyright 2009 Google Inc., All Rights Reserved.
5 *
6 * TCO timer driver for sp5100 chipsets
7 */
8
9/*
10 * Some address definitions for the Watchdog
11 */
12
13#define SP5100_WDT_MEM_MAP_SIZE 0x08
14#define SP5100_WDT_CONTROL(base) ((base) + 0x00) /* Watchdog Control */
15#define SP5100_WDT_COUNT(base) ((base) + 0x04) /* Watchdog Count */
16
17#define SP5100_WDT_START_STOP_BIT 1
18#define SP5100_WDT_TRIGGER_BIT (1 << 7)
19
20#define SP5100_PCI_WATCHDOG_MISC_REG 0x41
21#define SP5100_PCI_WATCHDOG_DECODE_EN (1 << 3)
22
23#define SP5100_PM_IOPORTS_SIZE 0x02
24
25/* These two IO registers are hardcoded and there doesn't seem to be a way to
26 * read them from a register.
27 */
28#define SP5100_IO_PM_INDEX_REG 0xCD6
29#define SP5100_IO_PM_DATA_REG 0xCD7
30
31#define SP5100_PM_WATCHDOG_CONTROL 0x69
32#define SP5100_PM_WATCHDOG_BASE0 0x6C
33#define SP5100_PM_WATCHDOG_BASE1 0x6D
34#define SP5100_PM_WATCHDOG_BASE2 0x6E
35#define SP5100_PM_WATCHDOG_BASE3 0x6F
36
37#define SP5100_PM_WATCHDOG_FIRED (1 << 1)
38#define SP5100_PM_WATCHDOG_ACTION_RESET (1 << 2)
39
40#define SP5100_PM_WATCHDOG_DISABLE 1
41#define SP5100_PM_WATCHDOG_SECOND_RES (3 << 1)
diff --git a/drivers/watchdog/w83627hf_wdt.c b/drivers/watchdog/w83627hf_wdt.c
index 0f5288df0091..e5c91d4404ed 100644
--- a/drivers/watchdog/w83627hf_wdt.c
+++ b/drivers/watchdog/w83627hf_wdt.c
@@ -42,7 +42,7 @@
42 42
43#include <asm/system.h> 43#include <asm/system.h>
44 44
45#define WATCHDOG_NAME "w83627hf/thf/hg WDT" 45#define WATCHDOG_NAME "w83627hf/thf/hg/dhg WDT"
46#define PFX WATCHDOG_NAME ": " 46#define PFX WATCHDOG_NAME ": "
47#define WATCHDOG_TIMEOUT 60 /* 60 sec default timeout */ 47#define WATCHDOG_TIMEOUT 60 /* 60 sec default timeout */
48 48
@@ -89,7 +89,7 @@ static void w83627hf_select_wd_register(void)
89 c = ((inb_p(WDT_EFDR) & 0xf7) | 0x04); /* select WDT0 */ 89 c = ((inb_p(WDT_EFDR) & 0xf7) | 0x04); /* select WDT0 */
90 outb_p(0x2b, WDT_EFER); 90 outb_p(0x2b, WDT_EFER);
91 outb_p(c, WDT_EFDR); /* set GPIO3 to WDT0 */ 91 outb_p(c, WDT_EFDR); /* set GPIO3 to WDT0 */
92 } else if (c == 0x88) { /* W83627EHF */ 92 } else if (c == 0x88 || c == 0xa0) { /* W83627EHF / W83627DHG */
93 outb_p(0x2d, WDT_EFER); /* select GPIO5 */ 93 outb_p(0x2d, WDT_EFER); /* select GPIO5 */
94 c = inb_p(WDT_EFDR) & ~0x01; /* PIN77 -> WDT0# */ 94 c = inb_p(WDT_EFDR) & ~0x01; /* PIN77 -> WDT0# */
95 outb_p(0x2d, WDT_EFER); 95 outb_p(0x2d, WDT_EFER);
@@ -129,6 +129,8 @@ static void w83627hf_init(void)
129 t = inb_p(WDT_EFDR); /* read CRF5 */ 129 t = inb_p(WDT_EFDR); /* read CRF5 */
130 t &= ~0x0C; /* set second mode & disable keyboard 130 t &= ~0x0C; /* set second mode & disable keyboard
131 turning off watchdog */ 131 turning off watchdog */
132 t |= 0x02; /* enable the WDTO# output low pulse
133 to the KBRST# pin (PIN60) */
132 outb_p(t, WDT_EFDR); /* Write back to CRF5 */ 134 outb_p(t, WDT_EFDR); /* Write back to CRF5 */
133 135
134 outb_p(0xF7, WDT_EFER); /* Select CRF7 */ 136 outb_p(0xF7, WDT_EFER); /* Select CRF7 */
@@ -321,7 +323,7 @@ static int __init wdt_init(void)
321{ 323{
322 int ret; 324 int ret;
323 325
324 printk(KERN_INFO "WDT driver for the Winbond(TM) W83627HF/THF/HG Super I/O chip initialising.\n"); 326 printk(KERN_INFO "WDT driver for the Winbond(TM) W83627HF/THF/HG/DHG Super I/O chip initialising.\n");
325 327
326 if (wdt_set_heartbeat(timeout)) { 328 if (wdt_set_heartbeat(timeout)) {
327 wdt_set_heartbeat(WATCHDOG_TIMEOUT); 329 wdt_set_heartbeat(WATCHDOG_TIMEOUT);
diff --git a/firmware/ihex2fw.c b/firmware/ihex2fw.c
index ba0cf0b601bb..cf38e159131a 100644
--- a/firmware/ihex2fw.c
+++ b/firmware/ihex2fw.c
@@ -124,8 +124,7 @@ int main(int argc, char **argv)
124 if (process_ihex(data, st.st_size)) 124 if (process_ihex(data, st.st_size))
125 return 1; 125 return 1;
126 126
127 output_records(outfd); 127 return output_records(outfd);
128 return 0;
129} 128}
130 129
131static int process_ihex(uint8_t *data, ssize_t size) 130static int process_ihex(uint8_t *data, ssize_t size)
@@ -269,11 +268,13 @@ static int output_records(int outfd)
269 268
270 p->addr = htonl(p->addr); 269 p->addr = htonl(p->addr);
271 p->len = htons(p->len); 270 p->len = htons(p->len);
272 write(outfd, &p->addr, writelen); 271 if (write(outfd, &p->addr, writelen) != writelen)
272 return 1;
273 p = p->next; 273 p = p->next;
274 } 274 }
275 /* EOF record is zero length, since we don't bother to represent 275 /* EOF record is zero length, since we don't bother to represent
276 the type field in the binary version */ 276 the type field in the binary version */
277 write(outfd, zeroes, 6); 277 if (write(outfd, zeroes, 6) != 6)
278 return 1;
278 return 0; 279 return 0;
279} 280}
diff --git a/fs/9p/v9fs_vfs.h b/fs/9p/v9fs_vfs.h
index bab0eac873f4..b789f8e597ec 100644
--- a/fs/9p/v9fs_vfs.h
+++ b/fs/9p/v9fs_vfs.h
@@ -59,7 +59,6 @@ void v9fs_stat2inode_dotl(struct p9_stat_dotl *, struct inode *);
59int v9fs_dir_release(struct inode *inode, struct file *filp); 59int v9fs_dir_release(struct inode *inode, struct file *filp);
60int v9fs_file_open(struct inode *inode, struct file *file); 60int v9fs_file_open(struct inode *inode, struct file *file);
61void v9fs_inode2stat(struct inode *inode, struct p9_wstat *stat); 61void v9fs_inode2stat(struct inode *inode, struct p9_wstat *stat);
62void v9fs_dentry_release(struct dentry *);
63int v9fs_uflags2omode(int uflags, int extended); 62int v9fs_uflags2omode(int uflags, int extended);
64 63
65ssize_t v9fs_file_readn(struct file *, char *, char __user *, u32, u64); 64ssize_t v9fs_file_readn(struct file *, char *, char __user *, u32, u64);
diff --git a/fs/9p/vfs_dentry.c b/fs/9p/vfs_dentry.c
index 466d2a4fc5cb..233b7d4ffe5e 100644
--- a/fs/9p/vfs_dentry.c
+++ b/fs/9p/vfs_dentry.c
@@ -86,7 +86,7 @@ static int v9fs_cached_dentry_delete(const struct dentry *dentry)
86 * 86 *
87 */ 87 */
88 88
89void v9fs_dentry_release(struct dentry *dentry) 89static void v9fs_dentry_release(struct dentry *dentry)
90{ 90{
91 struct v9fs_dentry *dent; 91 struct v9fs_dentry *dent;
92 struct p9_fid *temp, *current_fid; 92 struct p9_fid *temp, *current_fid;
diff --git a/fs/9p/vfs_inode.c b/fs/9p/vfs_inode.c
index 5076eeb95502..b76a40bdf4c2 100644
--- a/fs/9p/vfs_inode.c
+++ b/fs/9p/vfs_inode.c
@@ -699,11 +699,6 @@ struct dentry *v9fs_vfs_lookup(struct inode *dir, struct dentry *dentry,
699 goto error_iput; 699 goto error_iput;
700 700
701inst_out: 701inst_out:
702 if (v9ses->cache)
703 d_set_d_op(dentry, &v9fs_cached_dentry_operations);
704 else
705 d_set_d_op(dentry, &v9fs_dentry_operations);
706
707 d_add(dentry, inode); 702 d_add(dentry, inode);
708 return NULL; 703 return NULL;
709 704
diff --git a/fs/9p/vfs_super.c b/fs/9p/vfs_super.c
index c55c614500ad..dbaabe3b8131 100644
--- a/fs/9p/vfs_super.c
+++ b/fs/9p/vfs_super.c
@@ -141,6 +141,11 @@ static struct dentry *v9fs_mount(struct file_system_type *fs_type, int flags,
141 } 141 }
142 v9fs_fill_super(sb, v9ses, flags, data); 142 v9fs_fill_super(sb, v9ses, flags, data);
143 143
144 if (v9ses->cache)
145 sb->s_d_op = &v9fs_cached_dentry_operations;
146 else
147 sb->s_d_op = &v9fs_dentry_operations;
148
144 inode = v9fs_get_inode(sb, S_IFDIR | mode); 149 inode = v9fs_get_inode(sb, S_IFDIR | mode);
145 if (IS_ERR(inode)) { 150 if (IS_ERR(inode)) {
146 retval = PTR_ERR(inode); 151 retval = PTR_ERR(inode);
@@ -217,9 +222,6 @@ static void v9fs_kill_super(struct super_block *s)
217 222
218 P9_DPRINTK(P9_DEBUG_VFS, " %p\n", s); 223 P9_DPRINTK(P9_DEBUG_VFS, " %p\n", s);
219 224
220 if (s->s_root)
221 v9fs_dentry_release(s->s_root); /* clunk root */
222
223 kill_anon_super(s); 225 kill_anon_super(s);
224 226
225 v9fs_session_cancel(v9ses); 227 v9fs_session_cancel(v9ses);
diff --git a/fs/adfs/dir.c b/fs/adfs/dir.c
index bf7693c384f9..3b4a764ed780 100644
--- a/fs/adfs/dir.c
+++ b/fs/adfs/dir.c
@@ -276,7 +276,6 @@ adfs_lookup(struct inode *dir, struct dentry *dentry, struct nameidata *nd)
276 struct object_info obj; 276 struct object_info obj;
277 int error; 277 int error;
278 278
279 d_set_d_op(dentry, &adfs_dentry_operations);
280 lock_kernel(); 279 lock_kernel();
281 error = adfs_dir_lookup_byname(dir, &dentry->d_name, &obj); 280 error = adfs_dir_lookup_byname(dir, &dentry->d_name, &obj);
282 if (error == 0) { 281 if (error == 0) {
diff --git a/fs/adfs/super.c b/fs/adfs/super.c
index a4041b52fbca..2d7954049fbe 100644
--- a/fs/adfs/super.c
+++ b/fs/adfs/super.c
@@ -473,6 +473,7 @@ static int adfs_fill_super(struct super_block *sb, void *data, int silent)
473 asb->s_namelen = ADFS_F_NAME_LEN; 473 asb->s_namelen = ADFS_F_NAME_LEN;
474 } 474 }
475 475
476 sb->s_d_op = &adfs_dentry_operations;
476 root = adfs_iget(sb, &root_obj); 477 root = adfs_iget(sb, &root_obj);
477 sb->s_root = d_alloc_root(root); 478 sb->s_root = d_alloc_root(root);
478 if (!sb->s_root) { 479 if (!sb->s_root) {
@@ -483,8 +484,7 @@ static int adfs_fill_super(struct super_block *sb, void *data, int silent)
483 kfree(asb->s_map); 484 kfree(asb->s_map);
484 adfs_error(sb, "get root inode failed\n"); 485 adfs_error(sb, "get root inode failed\n");
485 goto error; 486 goto error;
486 } else 487 }
487 d_set_d_op(sb->s_root, &adfs_dentry_operations);
488 unlock_kernel(); 488 unlock_kernel();
489 return 0; 489 return 0;
490 490
diff --git a/fs/affs/affs.h b/fs/affs/affs.h
index a8cbdeb34025..0e95f73a7023 100644
--- a/fs/affs/affs.h
+++ b/fs/affs/affs.h
@@ -201,6 +201,7 @@ extern const struct address_space_operations affs_aops;
201extern const struct address_space_operations affs_aops_ofs; 201extern const struct address_space_operations affs_aops_ofs;
202 202
203extern const struct dentry_operations affs_dentry_operations; 203extern const struct dentry_operations affs_dentry_operations;
204extern const struct dentry_operations affs_intl_dentry_operations;
204 205
205static inline void 206static inline void
206affs_set_blocksize(struct super_block *sb, int size) 207affs_set_blocksize(struct super_block *sb, int size)
diff --git a/fs/affs/namei.c b/fs/affs/namei.c
index 944a4042fb65..e3e9efc1fdd8 100644
--- a/fs/affs/namei.c
+++ b/fs/affs/namei.c
@@ -32,7 +32,7 @@ const struct dentry_operations affs_dentry_operations = {
32 .d_compare = affs_compare_dentry, 32 .d_compare = affs_compare_dentry,
33}; 33};
34 34
35static const struct dentry_operations affs_intl_dentry_operations = { 35const struct dentry_operations affs_intl_dentry_operations = {
36 .d_hash = affs_intl_hash_dentry, 36 .d_hash = affs_intl_hash_dentry,
37 .d_compare = affs_intl_compare_dentry, 37 .d_compare = affs_intl_compare_dentry,
38}; 38};
@@ -240,7 +240,6 @@ affs_lookup(struct inode *dir, struct dentry *dentry, struct nameidata *nd)
240 if (IS_ERR(inode)) 240 if (IS_ERR(inode))
241 return ERR_CAST(inode); 241 return ERR_CAST(inode);
242 } 242 }
243 d_set_d_op(dentry, AFFS_SB(sb)->s_flags & SF_INTL ? &affs_intl_dentry_operations : &affs_dentry_operations);
244 d_add(dentry, inode); 243 d_add(dentry, inode);
245 return NULL; 244 return NULL;
246} 245}
diff --git a/fs/affs/super.c b/fs/affs/super.c
index d39081bbe7ce..b31507d0f9b9 100644
--- a/fs/affs/super.c
+++ b/fs/affs/super.c
@@ -477,12 +477,16 @@ got_root:
477 goto out_error_noinode; 477 goto out_error_noinode;
478 } 478 }
479 479
480 if (AFFS_SB(sb)->s_flags & SF_INTL)
481 sb->s_d_op = &affs_intl_dentry_operations;
482 else
483 sb->s_d_op = &affs_dentry_operations;
484
480 sb->s_root = d_alloc_root(root_inode); 485 sb->s_root = d_alloc_root(root_inode);
481 if (!sb->s_root) { 486 if (!sb->s_root) {
482 printk(KERN_ERR "AFFS: Get root inode failed\n"); 487 printk(KERN_ERR "AFFS: Get root inode failed\n");
483 goto out_error; 488 goto out_error;
484 } 489 }
485 d_set_d_op(sb->s_root, &affs_dentry_operations);
486 490
487 pr_debug("AFFS: s_flags=%lX\n",sb->s_flags); 491 pr_debug("AFFS: s_flags=%lX\n",sb->s_flags);
488 return 0; 492 return 0;
diff --git a/fs/afs/dir.c b/fs/afs/dir.c
index 34a3263d60a4..e6a4ab980e31 100644
--- a/fs/afs/dir.c
+++ b/fs/afs/dir.c
@@ -62,7 +62,7 @@ const struct inode_operations afs_dir_inode_operations = {
62 .setattr = afs_setattr, 62 .setattr = afs_setattr,
63}; 63};
64 64
65static const struct dentry_operations afs_fs_dentry_operations = { 65const struct dentry_operations afs_fs_dentry_operations = {
66 .d_revalidate = afs_d_revalidate, 66 .d_revalidate = afs_d_revalidate,
67 .d_delete = afs_d_delete, 67 .d_delete = afs_d_delete,
68 .d_release = afs_d_release, 68 .d_release = afs_d_release,
@@ -582,8 +582,6 @@ static struct dentry *afs_lookup(struct inode *dir, struct dentry *dentry,
582 } 582 }
583 583
584success: 584success:
585 d_set_d_op(dentry, &afs_fs_dentry_operations);
586
587 d_add(dentry, inode); 585 d_add(dentry, inode);
588 _leave(" = 0 { vn=%u u=%u } -> { ino=%lu v=%llu }", 586 _leave(" = 0 { vn=%u u=%u } -> { ino=%lu v=%llu }",
589 fid.vnode, 587 fid.vnode,
diff --git a/fs/afs/internal.h b/fs/afs/internal.h
index 6d4bc1c8ff60..ab6db5abaf53 100644
--- a/fs/afs/internal.h
+++ b/fs/afs/internal.h
@@ -486,6 +486,7 @@ extern bool afs_cm_incoming_call(struct afs_call *);
486 * dir.c 486 * dir.c
487 */ 487 */
488extern const struct inode_operations afs_dir_inode_operations; 488extern const struct inode_operations afs_dir_inode_operations;
489extern const struct dentry_operations afs_fs_dentry_operations;
489extern const struct file_operations afs_dir_file_operations; 490extern const struct file_operations afs_dir_file_operations;
490 491
491/* 492/*
diff --git a/fs/afs/super.c b/fs/afs/super.c
index f901a9d7c111..fb240e8766d6 100644
--- a/fs/afs/super.c
+++ b/fs/afs/super.c
@@ -336,6 +336,7 @@ static int afs_fill_super(struct super_block *sb, void *data)
336 if (!root) 336 if (!root)
337 goto error; 337 goto error;
338 338
339 sb->s_d_op = &afs_fs_dentry_operations;
339 sb->s_root = root; 340 sb->s_root = root;
340 341
341 _leave(" = 0"); 342 _leave(" = 0");
diff --git a/fs/aio.c b/fs/aio.c
index 8c8f6c5b6d79..5e00f15c54aa 100644
--- a/fs/aio.c
+++ b/fs/aio.c
@@ -798,29 +798,12 @@ static void aio_queue_work(struct kioctx * ctx)
798 queue_delayed_work(aio_wq, &ctx->wq, timeout); 798 queue_delayed_work(aio_wq, &ctx->wq, timeout);
799} 799}
800 800
801
802/*
803 * aio_run_iocbs:
804 * Process all pending retries queued on the ioctx
805 * run list.
806 * Assumes it is operating within the aio issuer's mm
807 * context.
808 */
809static inline void aio_run_iocbs(struct kioctx *ctx)
810{
811 int requeue;
812
813 spin_lock_irq(&ctx->ctx_lock);
814
815 requeue = __aio_run_iocbs(ctx);
816 spin_unlock_irq(&ctx->ctx_lock);
817 if (requeue)
818 aio_queue_work(ctx);
819}
820
821/* 801/*
822 * just like aio_run_iocbs, but keeps running them until 802 * aio_run_all_iocbs:
823 * the list stays empty 803 * Process all pending retries queued on the ioctx
804 * run list, and keep running them until the list
805 * stays empty.
806 * Assumes it is operating within the aio issuer's mm context.
824 */ 807 */
825static inline void aio_run_all_iocbs(struct kioctx *ctx) 808static inline void aio_run_all_iocbs(struct kioctx *ctx)
826{ 809{
@@ -1839,7 +1822,7 @@ SYSCALL_DEFINE5(io_getevents, aio_context_t, ctx_id,
1839 long ret = -EINVAL; 1822 long ret = -EINVAL;
1840 1823
1841 if (likely(ioctx)) { 1824 if (likely(ioctx)) {
1842 if (likely(min_nr <= nr && min_nr >= 0 && nr >= 0)) 1825 if (likely(min_nr <= nr && min_nr >= 0))
1843 ret = read_events(ioctx, min_nr, nr, events, timeout); 1826 ret = read_events(ioctx, min_nr, nr, events, timeout);
1844 put_ioctx(ioctx); 1827 put_ioctx(ioctx);
1845 } 1828 }
diff --git a/fs/anon_inodes.c b/fs/anon_inodes.c
index 5fd38112a6ca..cbe57f3c4d89 100644
--- a/fs/anon_inodes.c
+++ b/fs/anon_inodes.c
@@ -26,12 +26,6 @@ static struct vfsmount *anon_inode_mnt __read_mostly;
26static struct inode *anon_inode_inode; 26static struct inode *anon_inode_inode;
27static const struct file_operations anon_inode_fops; 27static const struct file_operations anon_inode_fops;
28 28
29static struct dentry *anon_inodefs_mount(struct file_system_type *fs_type,
30 int flags, const char *dev_name, void *data)
31{
32 return mount_pseudo(fs_type, "anon_inode:", NULL, ANON_INODE_FS_MAGIC);
33}
34
35/* 29/*
36 * anon_inodefs_dname() is called from d_path(). 30 * anon_inodefs_dname() is called from d_path().
37 */ 31 */
@@ -41,14 +35,22 @@ static char *anon_inodefs_dname(struct dentry *dentry, char *buffer, int buflen)
41 dentry->d_name.name); 35 dentry->d_name.name);
42} 36}
43 37
38static const struct dentry_operations anon_inodefs_dentry_operations = {
39 .d_dname = anon_inodefs_dname,
40};
41
42static struct dentry *anon_inodefs_mount(struct file_system_type *fs_type,
43 int flags, const char *dev_name, void *data)
44{
45 return mount_pseudo(fs_type, "anon_inode:", NULL,
46 &anon_inodefs_dentry_operations, ANON_INODE_FS_MAGIC);
47}
48
44static struct file_system_type anon_inode_fs_type = { 49static struct file_system_type anon_inode_fs_type = {
45 .name = "anon_inodefs", 50 .name = "anon_inodefs",
46 .mount = anon_inodefs_mount, 51 .mount = anon_inodefs_mount,
47 .kill_sb = kill_anon_super, 52 .kill_sb = kill_anon_super,
48}; 53};
49static const struct dentry_operations anon_inodefs_dentry_operations = {
50 .d_dname = anon_inodefs_dname,
51};
52 54
53/* 55/*
54 * nop .set_page_dirty method so that people can use .page_mkwrite on 56 * nop .set_page_dirty method so that people can use .page_mkwrite on
@@ -64,9 +66,9 @@ static const struct address_space_operations anon_aops = {
64}; 66};
65 67
66/** 68/**
67 * anon_inode_getfd - creates a new file instance by hooking it up to an 69 * anon_inode_getfile - creates a new file instance by hooking it up to an
68 * anonymous inode, and a dentry that describe the "class" 70 * anonymous inode, and a dentry that describe the "class"
69 * of the file 71 * of the file
70 * 72 *
71 * @name: [in] name of the "class" of the new file 73 * @name: [in] name of the "class" of the new file
72 * @fops: [in] file operations for the new file 74 * @fops: [in] file operations for the new file
@@ -113,7 +115,6 @@ struct file *anon_inode_getfile(const char *name,
113 */ 115 */
114 ihold(anon_inode_inode); 116 ihold(anon_inode_inode);
115 117
116 d_set_d_op(path.dentry, &anon_inodefs_dentry_operations);
117 d_instantiate(path.dentry, anon_inode_inode); 118 d_instantiate(path.dentry, anon_inode_inode);
118 119
119 error = -ENFILE; 120 error = -ENFILE;
diff --git a/fs/befs/endian.h b/fs/befs/endian.h
index 6cb84d896d05..27223878ba9f 100644
--- a/fs/befs/endian.h
+++ b/fs/befs/endian.h
@@ -102,22 +102,22 @@ cpu_to_fsrun(const struct super_block *sb, befs_block_run n)
102} 102}
103 103
104static inline befs_data_stream 104static inline befs_data_stream
105fsds_to_cpu(const struct super_block *sb, befs_disk_data_stream n) 105fsds_to_cpu(const struct super_block *sb, const befs_disk_data_stream *n)
106{ 106{
107 befs_data_stream data; 107 befs_data_stream data;
108 int i; 108 int i;
109 109
110 for (i = 0; i < BEFS_NUM_DIRECT_BLOCKS; ++i) 110 for (i = 0; i < BEFS_NUM_DIRECT_BLOCKS; ++i)
111 data.direct[i] = fsrun_to_cpu(sb, n.direct[i]); 111 data.direct[i] = fsrun_to_cpu(sb, n->direct[i]);
112 112
113 data.max_direct_range = fs64_to_cpu(sb, n.max_direct_range); 113 data.max_direct_range = fs64_to_cpu(sb, n->max_direct_range);
114 data.indirect = fsrun_to_cpu(sb, n.indirect); 114 data.indirect = fsrun_to_cpu(sb, n->indirect);
115 data.max_indirect_range = fs64_to_cpu(sb, n.max_indirect_range); 115 data.max_indirect_range = fs64_to_cpu(sb, n->max_indirect_range);
116 data.double_indirect = fsrun_to_cpu(sb, n.double_indirect); 116 data.double_indirect = fsrun_to_cpu(sb, n->double_indirect);
117 data.max_double_indirect_range = fs64_to_cpu(sb, 117 data.max_double_indirect_range = fs64_to_cpu(sb,
118 n. 118 n->
119 max_double_indirect_range); 119 max_double_indirect_range);
120 data.size = fs64_to_cpu(sb, n.size); 120 data.size = fs64_to_cpu(sb, n->size);
121 121
122 return data; 122 return data;
123} 123}
diff --git a/fs/befs/linuxvfs.c b/fs/befs/linuxvfs.c
index de93581b79a2..b1d0c794747b 100644
--- a/fs/befs/linuxvfs.c
+++ b/fs/befs/linuxvfs.c
@@ -390,7 +390,7 @@ static struct inode *befs_iget(struct super_block *sb, unsigned long ino)
390 int num_blks; 390 int num_blks;
391 391
392 befs_ino->i_data.ds = 392 befs_ino->i_data.ds =
393 fsds_to_cpu(sb, raw_inode->data.datastream); 393 fsds_to_cpu(sb, &raw_inode->data.datastream);
394 394
395 num_blks = befs_count_blocks(sb, &befs_ino->i_data.ds); 395 num_blks = befs_count_blocks(sb, &befs_ino->i_data.ds);
396 inode->i_blocks = 396 inode->i_blocks =
diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c
index 6884e198e0c7..d5b640ba6cb1 100644
--- a/fs/binfmt_elf.c
+++ b/fs/binfmt_elf.c
@@ -66,12 +66,11 @@ static int elf_core_dump(struct coredump_params *cprm);
66#define ELF_PAGEALIGN(_v) (((_v) + ELF_MIN_ALIGN - 1) & ~(ELF_MIN_ALIGN - 1)) 66#define ELF_PAGEALIGN(_v) (((_v) + ELF_MIN_ALIGN - 1) & ~(ELF_MIN_ALIGN - 1))
67 67
68static struct linux_binfmt elf_format = { 68static struct linux_binfmt elf_format = {
69 .module = THIS_MODULE, 69 .module = THIS_MODULE,
70 .load_binary = load_elf_binary, 70 .load_binary = load_elf_binary,
71 .load_shlib = load_elf_library, 71 .load_shlib = load_elf_library,
72 .core_dump = elf_core_dump, 72 .core_dump = elf_core_dump,
73 .min_coredump = ELF_EXEC_PAGESIZE, 73 .min_coredump = ELF_EXEC_PAGESIZE,
74 .hasvdso = 1
75}; 74};
76 75
77#define BAD_ADDR(x) ((unsigned long)(x) >= TASK_SIZE) 76#define BAD_ADDR(x) ((unsigned long)(x) >= TASK_SIZE)
@@ -316,8 +315,6 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
316 return 0; 315 return 0;
317} 316}
318 317
319#ifndef elf_map
320
321static unsigned long elf_map(struct file *filep, unsigned long addr, 318static unsigned long elf_map(struct file *filep, unsigned long addr,
322 struct elf_phdr *eppnt, int prot, int type, 319 struct elf_phdr *eppnt, int prot, int type,
323 unsigned long total_size) 320 unsigned long total_size)
@@ -354,8 +351,6 @@ static unsigned long elf_map(struct file *filep, unsigned long addr,
354 return(map_addr); 351 return(map_addr);
355} 352}
356 353
357#endif /* !elf_map */
358
359static unsigned long total_mapping_size(struct elf_phdr *cmds, int nr) 354static unsigned long total_mapping_size(struct elf_phdr *cmds, int nr)
360{ 355{
361 int i, first_idx = -1, last_idx = -1; 356 int i, first_idx = -1, last_idx = -1;
@@ -421,7 +416,7 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
421 goto out; 416 goto out;
422 417
423 retval = kernel_read(interpreter, interp_elf_ex->e_phoff, 418 retval = kernel_read(interpreter, interp_elf_ex->e_phoff,
424 (char *)elf_phdata,size); 419 (char *)elf_phdata, size);
425 error = -EIO; 420 error = -EIO;
426 if (retval != size) { 421 if (retval != size) {
427 if (retval < 0) 422 if (retval < 0)
@@ -601,7 +596,7 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
601 goto out; 596 goto out;
602 if (!elf_check_arch(&loc->elf_ex)) 597 if (!elf_check_arch(&loc->elf_ex))
603 goto out; 598 goto out;
604 if (!bprm->file->f_op||!bprm->file->f_op->mmap) 599 if (!bprm->file->f_op || !bprm->file->f_op->mmap)
605 goto out; 600 goto out;
606 601
607 /* Now read in all of the header information */ 602 /* Now read in all of the header information */
@@ -761,8 +756,8 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
761 /* There was a PT_LOAD segment with p_memsz > p_filesz 756 /* There was a PT_LOAD segment with p_memsz > p_filesz
762 before this one. Map anonymous pages, if needed, 757 before this one. Map anonymous pages, if needed,
763 and clear the area. */ 758 and clear the area. */
764 retval = set_brk (elf_bss + load_bias, 759 retval = set_brk(elf_bss + load_bias,
765 elf_brk + load_bias); 760 elf_brk + load_bias);
766 if (retval) { 761 if (retval) {
767 send_sig(SIGKILL, current, 0); 762 send_sig(SIGKILL, current, 0);
768 goto out_free_dentry; 763 goto out_free_dentry;
diff --git a/fs/block_dev.c b/fs/block_dev.c
index 771f23527010..88da70355aa3 100644
--- a/fs/block_dev.c
+++ b/fs/block_dev.c
@@ -473,7 +473,7 @@ static const struct super_operations bdev_sops = {
473static struct dentry *bd_mount(struct file_system_type *fs_type, 473static struct dentry *bd_mount(struct file_system_type *fs_type,
474 int flags, const char *dev_name, void *data) 474 int flags, const char *dev_name, void *data)
475{ 475{
476 return mount_pseudo(fs_type, "bdev:", &bdev_sops, 0x62646576); 476 return mount_pseudo(fs_type, "bdev:", &bdev_sops, NULL, 0x62646576);
477} 477}
478 478
479static struct file_system_type bd_type = { 479static struct file_system_type bd_type = {
diff --git a/fs/btrfs/export.c b/fs/btrfs/export.c
index 0ccf9a8afcdf..9786963b07e5 100644
--- a/fs/btrfs/export.c
+++ b/fs/btrfs/export.c
@@ -65,7 +65,6 @@ static struct dentry *btrfs_get_dentry(struct super_block *sb, u64 objectid,
65{ 65{
66 struct btrfs_fs_info *fs_info = btrfs_sb(sb)->fs_info; 66 struct btrfs_fs_info *fs_info = btrfs_sb(sb)->fs_info;
67 struct btrfs_root *root; 67 struct btrfs_root *root;
68 struct dentry *dentry;
69 struct inode *inode; 68 struct inode *inode;
70 struct btrfs_key key; 69 struct btrfs_key key;
71 int index; 70 int index;
@@ -108,10 +107,7 @@ static struct dentry *btrfs_get_dentry(struct super_block *sb, u64 objectid,
108 return ERR_PTR(-ESTALE); 107 return ERR_PTR(-ESTALE);
109 } 108 }
110 109
111 dentry = d_obtain_alias(inode); 110 return d_obtain_alias(inode);
112 if (!IS_ERR(dentry))
113 d_set_d_op(dentry, &btrfs_dentry_operations);
114 return dentry;
115fail: 111fail:
116 srcu_read_unlock(&fs_info->subvol_srcu, index); 112 srcu_read_unlock(&fs_info->subvol_srcu, index);
117 return ERR_PTR(err); 113 return ERR_PTR(err);
@@ -166,7 +162,6 @@ static struct dentry *btrfs_fh_to_dentry(struct super_block *sb, struct fid *fh,
166static struct dentry *btrfs_get_parent(struct dentry *child) 162static struct dentry *btrfs_get_parent(struct dentry *child)
167{ 163{
168 struct inode *dir = child->d_inode; 164 struct inode *dir = child->d_inode;
169 struct dentry *dentry;
170 struct btrfs_root *root = BTRFS_I(dir)->root; 165 struct btrfs_root *root = BTRFS_I(dir)->root;
171 struct btrfs_path *path; 166 struct btrfs_path *path;
172 struct extent_buffer *leaf; 167 struct extent_buffer *leaf;
@@ -223,10 +218,7 @@ static struct dentry *btrfs_get_parent(struct dentry *child)
223 218
224 key.type = BTRFS_INODE_ITEM_KEY; 219 key.type = BTRFS_INODE_ITEM_KEY;
225 key.offset = 0; 220 key.offset = 0;
226 dentry = d_obtain_alias(btrfs_iget(root->fs_info->sb, &key, root, NULL)); 221 return d_obtain_alias(btrfs_iget(root->fs_info->sb, &key, root, NULL));
227 if (!IS_ERR(dentry))
228 d_set_d_op(dentry, &btrfs_dentry_operations);
229 return dentry;
230fail: 222fail:
231 btrfs_free_path(path); 223 btrfs_free_path(path);
232 return ERR_PTR(ret); 224 return ERR_PTR(ret);
diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
index a0ff46a47895..a3798a3aa0d2 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
@@ -4084,8 +4084,6 @@ struct inode *btrfs_lookup_dentry(struct inode *dir, struct dentry *dentry)
4084 int index; 4084 int index;
4085 int ret; 4085 int ret;
4086 4086
4087 d_set_d_op(dentry, &btrfs_dentry_operations);
4088
4089 if (dentry->d_name.len > BTRFS_NAME_LEN) 4087 if (dentry->d_name.len > BTRFS_NAME_LEN)
4090 return ERR_PTR(-ENAMETOOLONG); 4088 return ERR_PTR(-ENAMETOOLONG);
4091 4089
@@ -7117,6 +7115,10 @@ static long btrfs_fallocate(struct inode *inode, int mode,
7117 alloc_start = offset & ~mask; 7115 alloc_start = offset & ~mask;
7118 alloc_end = (offset + len + mask) & ~mask; 7116 alloc_end = (offset + len + mask) & ~mask;
7119 7117
7118 /* We only support the FALLOC_FL_KEEP_SIZE mode */
7119 if (mode && (mode != FALLOC_FL_KEEP_SIZE))
7120 return -EOPNOTSUPP;
7121
7120 /* 7122 /*
7121 * wait for ordered IO before we have any locks. We'll loop again 7123 * wait for ordered IO before we have any locks. We'll loop again
7122 * below with the locks held. 7124 * below with the locks held.
diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c
index 883c6fa1367e..22acdaa78ce1 100644
--- a/fs/btrfs/super.c
+++ b/fs/btrfs/super.c
@@ -460,6 +460,7 @@ static int btrfs_fill_super(struct super_block *sb,
460 sb->s_maxbytes = MAX_LFS_FILESIZE; 460 sb->s_maxbytes = MAX_LFS_FILESIZE;
461 sb->s_magic = BTRFS_SUPER_MAGIC; 461 sb->s_magic = BTRFS_SUPER_MAGIC;
462 sb->s_op = &btrfs_super_ops; 462 sb->s_op = &btrfs_super_ops;
463 sb->s_d_op = &btrfs_dentry_operations;
463 sb->s_export_op = &btrfs_export_ops; 464 sb->s_export_op = &btrfs_export_ops;
464 sb->s_xattr = btrfs_xattr_handlers; 465 sb->s_xattr = btrfs_xattr_handlers;
465 sb->s_time_gran = 1; 466 sb->s_time_gran = 1;
diff --git a/fs/ceph/Makefile b/fs/ceph/Makefile
index 9e6c4f2e8ff1..bd352125e829 100644
--- a/fs/ceph/Makefile
+++ b/fs/ceph/Makefile
@@ -2,31 +2,10 @@
2# Makefile for CEPH filesystem. 2# Makefile for CEPH filesystem.
3# 3#
4 4
5ifneq ($(KERNELRELEASE),)
6
7obj-$(CONFIG_CEPH_FS) += ceph.o 5obj-$(CONFIG_CEPH_FS) += ceph.o
8 6
9ceph-objs := super.o inode.o dir.o file.o locks.o addr.o ioctl.o \ 7ceph-y := super.o inode.o dir.o file.o locks.o addr.o ioctl.o \
10 export.o caps.o snap.o xattr.o \ 8 export.o caps.o snap.o xattr.o \
11 mds_client.o mdsmap.o strings.o ceph_frag.o \ 9 mds_client.o mdsmap.o strings.o ceph_frag.o \
12 debugfs.o 10 debugfs.o
13 11
14else
15#Otherwise we were called directly from the command
16# line; invoke the kernel build system.
17
18KERNELDIR ?= /lib/modules/$(shell uname -r)/build
19PWD := $(shell pwd)
20
21default: all
22
23all:
24 $(MAKE) -C $(KERNELDIR) M=$(PWD) CONFIG_CEPH_FS=m modules
25
26modules_install:
27 $(MAKE) -C $(KERNELDIR) M=$(PWD) CONFIG_CEPH_FS=m modules_install
28
29clean:
30 $(MAKE) -C $(KERNELDIR) M=$(PWD) clean
31
32endif
diff --git a/fs/ceph/debugfs.c b/fs/ceph/debugfs.c
index 7ae1b3d55b58..08f65faac112 100644
--- a/fs/ceph/debugfs.c
+++ b/fs/ceph/debugfs.c
@@ -60,10 +60,13 @@ static int mdsc_show(struct seq_file *s, void *p)
60 for (rp = rb_first(&mdsc->request_tree); rp; rp = rb_next(rp)) { 60 for (rp = rb_first(&mdsc->request_tree); rp; rp = rb_next(rp)) {
61 req = rb_entry(rp, struct ceph_mds_request, r_node); 61 req = rb_entry(rp, struct ceph_mds_request, r_node);
62 62
63 if (req->r_request) 63 if (req->r_request && req->r_session)
64 seq_printf(s, "%lld\tmds%d\t", req->r_tid, req->r_mds); 64 seq_printf(s, "%lld\tmds%d\t", req->r_tid,
65 else 65 req->r_session->s_mds);
66 else if (!req->r_request)
66 seq_printf(s, "%lld\t(no request)\t", req->r_tid); 67 seq_printf(s, "%lld\t(no request)\t", req->r_tid);
68 else
69 seq_printf(s, "%lld\t(no session)\t", req->r_tid);
67 70
68 seq_printf(s, "%s", ceph_mds_op_name(req->r_op)); 71 seq_printf(s, "%s", ceph_mds_op_name(req->r_op));
69 72
diff --git a/fs/ceph/dir.c b/fs/ceph/dir.c
index fa7ca04ee816..0bc68de8edd7 100644
--- a/fs/ceph/dir.c
+++ b/fs/ceph/dir.c
@@ -1224,6 +1224,26 @@ void ceph_dentry_lru_del(struct dentry *dn)
1224 } 1224 }
1225} 1225}
1226 1226
1227/*
1228 * Return name hash for a given dentry. This is dependent on
1229 * the parent directory's hash function.
1230 */
1231unsigned ceph_dentry_hash(struct dentry *dn)
1232{
1233 struct inode *dir = dn->d_parent->d_inode;
1234 struct ceph_inode_info *dci = ceph_inode(dir);
1235
1236 switch (dci->i_dir_layout.dl_dir_hash) {
1237 case 0: /* for backward compat */
1238 case CEPH_STR_HASH_LINUX:
1239 return dn->d_name.hash;
1240
1241 default:
1242 return ceph_str_hash(dci->i_dir_layout.dl_dir_hash,
1243 dn->d_name.name, dn->d_name.len);
1244 }
1245}
1246
1227const struct file_operations ceph_dir_fops = { 1247const struct file_operations ceph_dir_fops = {
1228 .read = ceph_read_dir, 1248 .read = ceph_read_dir,
1229 .readdir = ceph_readdir, 1249 .readdir = ceph_readdir,
diff --git a/fs/ceph/export.c b/fs/ceph/export.c
index 2297d9426992..e41056174bf8 100644
--- a/fs/ceph/export.c
+++ b/fs/ceph/export.c
@@ -59,7 +59,7 @@ static int ceph_encode_fh(struct dentry *dentry, u32 *rawfh, int *max_len,
59 dout("encode_fh %p connectable\n", dentry); 59 dout("encode_fh %p connectable\n", dentry);
60 cfh->ino = ceph_ino(dentry->d_inode); 60 cfh->ino = ceph_ino(dentry->d_inode);
61 cfh->parent_ino = ceph_ino(parent->d_inode); 61 cfh->parent_ino = ceph_ino(parent->d_inode);
62 cfh->parent_name_hash = parent->d_name.hash; 62 cfh->parent_name_hash = ceph_dentry_hash(parent);
63 *max_len = connected_handle_length; 63 *max_len = connected_handle_length;
64 type = 2; 64 type = 2;
65 } else if (*max_len >= handle_length) { 65 } else if (*max_len >= handle_length) {
diff --git a/fs/ceph/inode.c b/fs/ceph/inode.c
index e61de4f7b99d..e835eff551e3 100644
--- a/fs/ceph/inode.c
+++ b/fs/ceph/inode.c
@@ -297,6 +297,8 @@ struct inode *ceph_alloc_inode(struct super_block *sb)
297 ci->i_release_count = 0; 297 ci->i_release_count = 0;
298 ci->i_symlink = NULL; 298 ci->i_symlink = NULL;
299 299
300 memset(&ci->i_dir_layout, 0, sizeof(ci->i_dir_layout));
301
300 ci->i_fragtree = RB_ROOT; 302 ci->i_fragtree = RB_ROOT;
301 mutex_init(&ci->i_fragtree_mutex); 303 mutex_init(&ci->i_fragtree_mutex);
302 304
@@ -689,6 +691,8 @@ static int fill_inode(struct inode *inode,
689 inode->i_op = &ceph_dir_iops; 691 inode->i_op = &ceph_dir_iops;
690 inode->i_fop = &ceph_dir_fops; 692 inode->i_fop = &ceph_dir_fops;
691 693
694 ci->i_dir_layout = iinfo->dir_layout;
695
692 ci->i_files = le64_to_cpu(info->files); 696 ci->i_files = le64_to_cpu(info->files);
693 ci->i_subdirs = le64_to_cpu(info->subdirs); 697 ci->i_subdirs = le64_to_cpu(info->subdirs);
694 ci->i_rbytes = le64_to_cpu(info->rbytes); 698 ci->i_rbytes = le64_to_cpu(info->rbytes);
diff --git a/fs/ceph/mds_client.c b/fs/ceph/mds_client.c
index a50fca1e03be..1e30d194a8e3 100644
--- a/fs/ceph/mds_client.c
+++ b/fs/ceph/mds_client.c
@@ -60,7 +60,8 @@ static const struct ceph_connection_operations mds_con_ops;
60 * parse individual inode info 60 * parse individual inode info
61 */ 61 */
62static int parse_reply_info_in(void **p, void *end, 62static int parse_reply_info_in(void **p, void *end,
63 struct ceph_mds_reply_info_in *info) 63 struct ceph_mds_reply_info_in *info,
64 int features)
64{ 65{
65 int err = -EIO; 66 int err = -EIO;
66 67
@@ -74,6 +75,12 @@ static int parse_reply_info_in(void **p, void *end,
74 info->symlink = *p; 75 info->symlink = *p;
75 *p += info->symlink_len; 76 *p += info->symlink_len;
76 77
78 if (features & CEPH_FEATURE_DIRLAYOUTHASH)
79 ceph_decode_copy_safe(p, end, &info->dir_layout,
80 sizeof(info->dir_layout), bad);
81 else
82 memset(&info->dir_layout, 0, sizeof(info->dir_layout));
83
77 ceph_decode_32_safe(p, end, info->xattr_len, bad); 84 ceph_decode_32_safe(p, end, info->xattr_len, bad);
78 ceph_decode_need(p, end, info->xattr_len, bad); 85 ceph_decode_need(p, end, info->xattr_len, bad);
79 info->xattr_data = *p; 86 info->xattr_data = *p;
@@ -88,12 +95,13 @@ bad:
88 * target inode. 95 * target inode.
89 */ 96 */
90static int parse_reply_info_trace(void **p, void *end, 97static int parse_reply_info_trace(void **p, void *end,
91 struct ceph_mds_reply_info_parsed *info) 98 struct ceph_mds_reply_info_parsed *info,
99 int features)
92{ 100{
93 int err; 101 int err;
94 102
95 if (info->head->is_dentry) { 103 if (info->head->is_dentry) {
96 err = parse_reply_info_in(p, end, &info->diri); 104 err = parse_reply_info_in(p, end, &info->diri, features);
97 if (err < 0) 105 if (err < 0)
98 goto out_bad; 106 goto out_bad;
99 107
@@ -114,7 +122,7 @@ static int parse_reply_info_trace(void **p, void *end,
114 } 122 }
115 123
116 if (info->head->is_target) { 124 if (info->head->is_target) {
117 err = parse_reply_info_in(p, end, &info->targeti); 125 err = parse_reply_info_in(p, end, &info->targeti, features);
118 if (err < 0) 126 if (err < 0)
119 goto out_bad; 127 goto out_bad;
120 } 128 }
@@ -134,7 +142,8 @@ out_bad:
134 * parse readdir results 142 * parse readdir results
135 */ 143 */
136static int parse_reply_info_dir(void **p, void *end, 144static int parse_reply_info_dir(void **p, void *end,
137 struct ceph_mds_reply_info_parsed *info) 145 struct ceph_mds_reply_info_parsed *info,
146 int features)
138{ 147{
139 u32 num, i = 0; 148 u32 num, i = 0;
140 int err; 149 int err;
@@ -182,7 +191,7 @@ static int parse_reply_info_dir(void **p, void *end,
182 *p += sizeof(struct ceph_mds_reply_lease); 191 *p += sizeof(struct ceph_mds_reply_lease);
183 192
184 /* inode */ 193 /* inode */
185 err = parse_reply_info_in(p, end, &info->dir_in[i]); 194 err = parse_reply_info_in(p, end, &info->dir_in[i], features);
186 if (err < 0) 195 if (err < 0)
187 goto out_bad; 196 goto out_bad;
188 i++; 197 i++;
@@ -205,7 +214,8 @@ out_bad:
205 * parse fcntl F_GETLK results 214 * parse fcntl F_GETLK results
206 */ 215 */
207static int parse_reply_info_filelock(void **p, void *end, 216static int parse_reply_info_filelock(void **p, void *end,
208 struct ceph_mds_reply_info_parsed *info) 217 struct ceph_mds_reply_info_parsed *info,
218 int features)
209{ 219{
210 if (*p + sizeof(*info->filelock_reply) > end) 220 if (*p + sizeof(*info->filelock_reply) > end)
211 goto bad; 221 goto bad;
@@ -225,19 +235,21 @@ bad:
225 * parse extra results 235 * parse extra results
226 */ 236 */
227static int parse_reply_info_extra(void **p, void *end, 237static int parse_reply_info_extra(void **p, void *end,
228 struct ceph_mds_reply_info_parsed *info) 238 struct ceph_mds_reply_info_parsed *info,
239 int features)
229{ 240{
230 if (info->head->op == CEPH_MDS_OP_GETFILELOCK) 241 if (info->head->op == CEPH_MDS_OP_GETFILELOCK)
231 return parse_reply_info_filelock(p, end, info); 242 return parse_reply_info_filelock(p, end, info, features);
232 else 243 else
233 return parse_reply_info_dir(p, end, info); 244 return parse_reply_info_dir(p, end, info, features);
234} 245}
235 246
236/* 247/*
237 * parse entire mds reply 248 * parse entire mds reply
238 */ 249 */
239static int parse_reply_info(struct ceph_msg *msg, 250static int parse_reply_info(struct ceph_msg *msg,
240 struct ceph_mds_reply_info_parsed *info) 251 struct ceph_mds_reply_info_parsed *info,
252 int features)
241{ 253{
242 void *p, *end; 254 void *p, *end;
243 u32 len; 255 u32 len;
@@ -250,7 +262,7 @@ static int parse_reply_info(struct ceph_msg *msg,
250 /* trace */ 262 /* trace */
251 ceph_decode_32_safe(&p, end, len, bad); 263 ceph_decode_32_safe(&p, end, len, bad);
252 if (len > 0) { 264 if (len > 0) {
253 err = parse_reply_info_trace(&p, p+len, info); 265 err = parse_reply_info_trace(&p, p+len, info, features);
254 if (err < 0) 266 if (err < 0)
255 goto out_bad; 267 goto out_bad;
256 } 268 }
@@ -258,7 +270,7 @@ static int parse_reply_info(struct ceph_msg *msg,
258 /* extra */ 270 /* extra */
259 ceph_decode_32_safe(&p, end, len, bad); 271 ceph_decode_32_safe(&p, end, len, bad);
260 if (len > 0) { 272 if (len > 0) {
261 err = parse_reply_info_extra(&p, p+len, info); 273 err = parse_reply_info_extra(&p, p+len, info, features);
262 if (err < 0) 274 if (err < 0)
263 goto out_bad; 275 goto out_bad;
264 } 276 }
@@ -654,7 +666,7 @@ static int __choose_mds(struct ceph_mds_client *mdsc,
654 } else { 666 } else {
655 /* dir + name */ 667 /* dir + name */
656 inode = dir; 668 inode = dir;
657 hash = req->r_dentry->d_name.hash; 669 hash = ceph_dentry_hash(req->r_dentry);
658 is_hash = true; 670 is_hash = true;
659 } 671 }
660 } 672 }
@@ -1693,7 +1705,6 @@ static int __prepare_send_request(struct ceph_mds_client *mdsc,
1693 struct ceph_msg *msg; 1705 struct ceph_msg *msg;
1694 int flags = 0; 1706 int flags = 0;
1695 1707
1696 req->r_mds = mds;
1697 req->r_attempts++; 1708 req->r_attempts++;
1698 if (req->r_inode) { 1709 if (req->r_inode) {
1699 struct ceph_cap *cap = 1710 struct ceph_cap *cap =
@@ -1780,6 +1791,8 @@ static int __do_request(struct ceph_mds_client *mdsc,
1780 goto finish; 1791 goto finish;
1781 } 1792 }
1782 1793
1794 put_request_session(req);
1795
1783 mds = __choose_mds(mdsc, req); 1796 mds = __choose_mds(mdsc, req);
1784 if (mds < 0 || 1797 if (mds < 0 ||
1785 ceph_mdsmap_get_state(mdsc->mdsmap, mds) < CEPH_MDS_STATE_ACTIVE) { 1798 ceph_mdsmap_get_state(mdsc->mdsmap, mds) < CEPH_MDS_STATE_ACTIVE) {
@@ -1797,6 +1810,8 @@ static int __do_request(struct ceph_mds_client *mdsc,
1797 goto finish; 1810 goto finish;
1798 } 1811 }
1799 } 1812 }
1813 req->r_session = get_session(session);
1814
1800 dout("do_request mds%d session %p state %s\n", mds, session, 1815 dout("do_request mds%d session %p state %s\n", mds, session,
1801 session_state_name(session->s_state)); 1816 session_state_name(session->s_state));
1802 if (session->s_state != CEPH_MDS_SESSION_OPEN && 1817 if (session->s_state != CEPH_MDS_SESSION_OPEN &&
@@ -1809,7 +1824,6 @@ static int __do_request(struct ceph_mds_client *mdsc,
1809 } 1824 }
1810 1825
1811 /* send request */ 1826 /* send request */
1812 req->r_session = get_session(session);
1813 req->r_resend_mds = -1; /* forget any previous mds hint */ 1827 req->r_resend_mds = -1; /* forget any previous mds hint */
1814 1828
1815 if (req->r_request_started == 0) /* note request start time */ 1829 if (req->r_request_started == 0) /* note request start time */
@@ -1863,7 +1877,6 @@ static void kick_requests(struct ceph_mds_client *mdsc, int mds)
1863 if (req->r_session && 1877 if (req->r_session &&
1864 req->r_session->s_mds == mds) { 1878 req->r_session->s_mds == mds) {
1865 dout(" kicking tid %llu\n", req->r_tid); 1879 dout(" kicking tid %llu\n", req->r_tid);
1866 put_request_session(req);
1867 __do_request(mdsc, req); 1880 __do_request(mdsc, req);
1868 } 1881 }
1869 } 1882 }
@@ -2056,8 +2069,11 @@ static void handle_reply(struct ceph_mds_session *session, struct ceph_msg *msg)
2056 goto out; 2069 goto out;
2057 } else { 2070 } else {
2058 struct ceph_inode_info *ci = ceph_inode(req->r_inode); 2071 struct ceph_inode_info *ci = ceph_inode(req->r_inode);
2059 struct ceph_cap *cap = 2072 struct ceph_cap *cap = NULL;
2060 ceph_get_cap_for_mds(ci, req->r_mds);; 2073
2074 if (req->r_session)
2075 cap = ceph_get_cap_for_mds(ci,
2076 req->r_session->s_mds);
2061 2077
2062 dout("already using auth"); 2078 dout("already using auth");
2063 if ((!cap || cap != ci->i_auth_cap) || 2079 if ((!cap || cap != ci->i_auth_cap) ||
@@ -2101,7 +2117,7 @@ static void handle_reply(struct ceph_mds_session *session, struct ceph_msg *msg)
2101 2117
2102 dout("handle_reply tid %lld result %d\n", tid, result); 2118 dout("handle_reply tid %lld result %d\n", tid, result);
2103 rinfo = &req->r_reply_info; 2119 rinfo = &req->r_reply_info;
2104 err = parse_reply_info(msg, rinfo); 2120 err = parse_reply_info(msg, rinfo, session->s_con.peer_features);
2105 mutex_unlock(&mdsc->mutex); 2121 mutex_unlock(&mdsc->mutex);
2106 2122
2107 mutex_lock(&session->s_mutex); 2123 mutex_lock(&session->s_mutex);
diff --git a/fs/ceph/mds_client.h b/fs/ceph/mds_client.h
index aabe563b54db..4e3a9cc0bba6 100644
--- a/fs/ceph/mds_client.h
+++ b/fs/ceph/mds_client.h
@@ -35,6 +35,7 @@ struct ceph_cap;
35 */ 35 */
36struct ceph_mds_reply_info_in { 36struct ceph_mds_reply_info_in {
37 struct ceph_mds_reply_inode *in; 37 struct ceph_mds_reply_inode *in;
38 struct ceph_dir_layout dir_layout;
38 u32 symlink_len; 39 u32 symlink_len;
39 char *symlink; 40 char *symlink;
40 u32 xattr_len; 41 u32 xattr_len;
@@ -165,7 +166,6 @@ struct ceph_mds_request {
165 struct ceph_mds_client *r_mdsc; 166 struct ceph_mds_client *r_mdsc;
166 167
167 int r_op; /* mds op code */ 168 int r_op; /* mds op code */
168 int r_mds;
169 169
170 /* operation on what? */ 170 /* operation on what? */
171 struct inode *r_inode; /* arg1 */ 171 struct inode *r_inode; /* arg1 */
diff --git a/fs/ceph/super.c b/fs/ceph/super.c
index 08b460ae0539..bf6f0f34082a 100644
--- a/fs/ceph/super.c
+++ b/fs/ceph/super.c
@@ -428,7 +428,8 @@ struct ceph_fs_client *create_fs_client(struct ceph_mount_options *fsopt,
428 goto fail; 428 goto fail;
429 } 429 }
430 fsc->client->extra_mon_dispatch = extra_mon_dispatch; 430 fsc->client->extra_mon_dispatch = extra_mon_dispatch;
431 fsc->client->supported_features |= CEPH_FEATURE_FLOCK; 431 fsc->client->supported_features |= CEPH_FEATURE_FLOCK |
432 CEPH_FEATURE_DIRLAYOUTHASH;
432 fsc->client->monc.want_mdsmap = 1; 433 fsc->client->monc.want_mdsmap = 1;
433 434
434 fsc->mount_options = fsopt; 435 fsc->mount_options = fsopt;
@@ -443,13 +444,17 @@ struct ceph_fs_client *create_fs_client(struct ceph_mount_options *fsopt,
443 goto fail_client; 444 goto fail_client;
444 445
445 err = -ENOMEM; 446 err = -ENOMEM;
446 fsc->wb_wq = create_workqueue("ceph-writeback"); 447 /*
448 * The number of concurrent works can be high but they don't need
449 * to be processed in parallel, limit concurrency.
450 */
451 fsc->wb_wq = alloc_workqueue("ceph-writeback", 0, 1);
447 if (fsc->wb_wq == NULL) 452 if (fsc->wb_wq == NULL)
448 goto fail_bdi; 453 goto fail_bdi;
449 fsc->pg_inv_wq = create_singlethread_workqueue("ceph-pg-invalid"); 454 fsc->pg_inv_wq = alloc_workqueue("ceph-pg-invalid", 0, 1);
450 if (fsc->pg_inv_wq == NULL) 455 if (fsc->pg_inv_wq == NULL)
451 goto fail_wb_wq; 456 goto fail_wb_wq;
452 fsc->trunc_wq = create_singlethread_workqueue("ceph-trunc"); 457 fsc->trunc_wq = alloc_workqueue("ceph-trunc", 0, 1);
453 if (fsc->trunc_wq == NULL) 458 if (fsc->trunc_wq == NULL)
454 goto fail_pg_inv_wq; 459 goto fail_pg_inv_wq;
455 460
diff --git a/fs/ceph/super.h b/fs/ceph/super.h
index 4553d8829edb..20b907d76ae2 100644
--- a/fs/ceph/super.h
+++ b/fs/ceph/super.h
@@ -239,6 +239,7 @@ struct ceph_inode_info {
239 unsigned i_ceph_flags; 239 unsigned i_ceph_flags;
240 unsigned long i_release_count; 240 unsigned long i_release_count;
241 241
242 struct ceph_dir_layout i_dir_layout;
242 struct ceph_file_layout i_layout; 243 struct ceph_file_layout i_layout;
243 char *i_symlink; 244 char *i_symlink;
244 245
@@ -768,6 +769,7 @@ extern void ceph_dentry_lru_add(struct dentry *dn);
768extern void ceph_dentry_lru_touch(struct dentry *dn); 769extern void ceph_dentry_lru_touch(struct dentry *dn);
769extern void ceph_dentry_lru_del(struct dentry *dn); 770extern void ceph_dentry_lru_del(struct dentry *dn);
770extern void ceph_invalidate_dentry_lease(struct dentry *dentry); 771extern void ceph_invalidate_dentry_lease(struct dentry *dentry);
772extern unsigned ceph_dentry_hash(struct dentry *dn);
771 773
772/* 774/*
773 * our d_ops vary depending on whether the inode is live, 775 * our d_ops vary depending on whether the inode is live,
diff --git a/fs/char_dev.c b/fs/char_dev.c
index e5b9df993b93..6e99b9ddd4e9 100644
--- a/fs/char_dev.c
+++ b/fs/char_dev.c
@@ -417,18 +417,6 @@ static int chrdev_open(struct inode *inode, struct file *filp)
417 return ret; 417 return ret;
418} 418}
419 419
420int cdev_index(struct inode *inode)
421{
422 int idx;
423 struct kobject *kobj;
424
425 kobj = kobj_lookup(cdev_map, inode->i_rdev, &idx);
426 if (!kobj)
427 return -1;
428 kobject_put(kobj);
429 return idx;
430}
431
432void cd_forget(struct inode *inode) 420void cd_forget(struct inode *inode)
433{ 421{
434 spin_lock(&cdev_lock); 422 spin_lock(&cdev_lock);
@@ -582,7 +570,6 @@ EXPORT_SYMBOL(cdev_init);
582EXPORT_SYMBOL(cdev_alloc); 570EXPORT_SYMBOL(cdev_alloc);
583EXPORT_SYMBOL(cdev_del); 571EXPORT_SYMBOL(cdev_del);
584EXPORT_SYMBOL(cdev_add); 572EXPORT_SYMBOL(cdev_add);
585EXPORT_SYMBOL(cdev_index);
586EXPORT_SYMBOL(__register_chrdev); 573EXPORT_SYMBOL(__register_chrdev);
587EXPORT_SYMBOL(__unregister_chrdev); 574EXPORT_SYMBOL(__unregister_chrdev);
588EXPORT_SYMBOL(directly_mappable_cdev_bdi); 575EXPORT_SYMBOL(directly_mappable_cdev_bdi);
diff --git a/fs/cifs/cifsfs.c b/fs/cifs/cifsfs.c
index 5e7075d5f139..d9f652a522a6 100644
--- a/fs/cifs/cifsfs.c
+++ b/fs/cifs/cifsfs.c
@@ -174,6 +174,12 @@ cifs_read_super(struct super_block *sb, void *data,
174 goto out_no_root; 174 goto out_no_root;
175 } 175 }
176 176
177 /* do that *after* d_alloc_root() - we want NULL ->d_op for root here */
178 if (cifs_sb_master_tcon(cifs_sb)->nocase)
179 sb->s_d_op = &cifs_ci_dentry_ops;
180 else
181 sb->s_d_op = &cifs_dentry_ops;
182
177#ifdef CONFIG_CIFS_EXPERIMENTAL 183#ifdef CONFIG_CIFS_EXPERIMENTAL
178 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_SERVER_INUM) { 184 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_SERVER_INUM) {
179 cFYI(1, "export ops supported"); 185 cFYI(1, "export ops supported");
diff --git a/fs/cifs/dir.c b/fs/cifs/dir.c
index 2e773825835e..1e95dd635632 100644
--- a/fs/cifs/dir.c
+++ b/fs/cifs/dir.c
@@ -130,17 +130,6 @@ cifs_bp_rename_retry:
130 return full_path; 130 return full_path;
131} 131}
132 132
133static void setup_cifs_dentry(struct cifsTconInfo *tcon,
134 struct dentry *direntry,
135 struct inode *newinode)
136{
137 if (tcon->nocase)
138 d_set_d_op(direntry, &cifs_ci_dentry_ops);
139 else
140 d_set_d_op(direntry, &cifs_dentry_ops);
141 d_instantiate(direntry, newinode);
142}
143
144/* Inode operations in similar order to how they appear in Linux file fs.h */ 133/* Inode operations in similar order to how they appear in Linux file fs.h */
145 134
146int 135int
@@ -327,7 +316,7 @@ cifs_create_get_file_info:
327 316
328cifs_create_set_dentry: 317cifs_create_set_dentry:
329 if (rc == 0) 318 if (rc == 0)
330 setup_cifs_dentry(tcon, direntry, newinode); 319 d_instantiate(direntry, newinode);
331 else 320 else
332 cFYI(1, "Create worked, get_inode_info failed rc = %d", rc); 321 cFYI(1, "Create worked, get_inode_info failed rc = %d", rc);
333 322
@@ -418,10 +407,6 @@ int cifs_mknod(struct inode *inode, struct dentry *direntry, int mode,
418 407
419 rc = cifs_get_inode_info_unix(&newinode, full_path, 408 rc = cifs_get_inode_info_unix(&newinode, full_path,
420 inode->i_sb, xid); 409 inode->i_sb, xid);
421 if (pTcon->nocase)
422 d_set_d_op(direntry, &cifs_ci_dentry_ops);
423 else
424 d_set_d_op(direntry, &cifs_dentry_ops);
425 410
426 if (rc == 0) 411 if (rc == 0)
427 d_instantiate(direntry, newinode); 412 d_instantiate(direntry, newinode);
@@ -601,10 +586,6 @@ cifs_lookup(struct inode *parent_dir_inode, struct dentry *direntry,
601 parent_dir_inode->i_sb, xid, NULL); 586 parent_dir_inode->i_sb, xid, NULL);
602 587
603 if ((rc == 0) && (newInode != NULL)) { 588 if ((rc == 0) && (newInode != NULL)) {
604 if (pTcon->nocase)
605 d_set_d_op(direntry, &cifs_ci_dentry_ops);
606 else
607 d_set_d_op(direntry, &cifs_dentry_ops);
608 d_add(direntry, newInode); 589 d_add(direntry, newInode);
609 if (posix_open) { 590 if (posix_open) {
610 filp = lookup_instantiate_filp(nd, direntry, 591 filp = lookup_instantiate_filp(nd, direntry,
@@ -631,10 +612,6 @@ cifs_lookup(struct inode *parent_dir_inode, struct dentry *direntry,
631 } else if (rc == -ENOENT) { 612 } else if (rc == -ENOENT) {
632 rc = 0; 613 rc = 0;
633 direntry->d_time = jiffies; 614 direntry->d_time = jiffies;
634 if (pTcon->nocase)
635 d_set_d_op(direntry, &cifs_ci_dentry_ops);
636 else
637 d_set_d_op(direntry, &cifs_dentry_ops);
638 d_add(direntry, NULL); 615 d_add(direntry, NULL);
639 /* if it was once a directory (but how can we tell?) we could do 616 /* if it was once a directory (but how can we tell?) we could do
640 shrink_dcache_parent(direntry); */ 617 shrink_dcache_parent(direntry); */
diff --git a/fs/cifs/inode.c b/fs/cifs/inode.c
index 0c7e36910e31..b06b60620240 100644
--- a/fs/cifs/inode.c
+++ b/fs/cifs/inode.c
@@ -1324,10 +1324,6 @@ int cifs_mkdir(struct inode *inode, struct dentry *direntry, int mode)
1324/*BB check (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_SET_UID ) to see if need 1324/*BB check (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_SET_UID ) to see if need
1325 to set uid/gid */ 1325 to set uid/gid */
1326 inc_nlink(inode); 1326 inc_nlink(inode);
1327 if (pTcon->nocase)
1328 d_set_d_op(direntry, &cifs_ci_dentry_ops);
1329 else
1330 d_set_d_op(direntry, &cifs_dentry_ops);
1331 1327
1332 cifs_unix_basic_to_fattr(&fattr, pInfo, cifs_sb); 1328 cifs_unix_basic_to_fattr(&fattr, pInfo, cifs_sb);
1333 cifs_fill_uniqueid(inode->i_sb, &fattr); 1329 cifs_fill_uniqueid(inode->i_sb, &fattr);
@@ -1368,10 +1364,6 @@ mkdir_get_info:
1368 rc = cifs_get_inode_info(&newinode, full_path, NULL, 1364 rc = cifs_get_inode_info(&newinode, full_path, NULL,
1369 inode->i_sb, xid, NULL); 1365 inode->i_sb, xid, NULL);
1370 1366
1371 if (pTcon->nocase)
1372 d_set_d_op(direntry, &cifs_ci_dentry_ops);
1373 else
1374 d_set_d_op(direntry, &cifs_dentry_ops);
1375 d_instantiate(direntry, newinode); 1367 d_instantiate(direntry, newinode);
1376 /* setting nlink not necessary except in cases where we 1368 /* setting nlink not necessary except in cases where we
1377 * failed to get it from the server or was set bogus */ 1369 * failed to get it from the server or was set bogus */
diff --git a/fs/cifs/link.c b/fs/cifs/link.c
index fe2f6a93c49e..306769de2fb5 100644
--- a/fs/cifs/link.c
+++ b/fs/cifs/link.c
@@ -524,10 +524,6 @@ cifs_symlink(struct inode *inode, struct dentry *direntry, const char *symname)
524 cFYI(1, "Create symlink ok, getinodeinfo fail rc = %d", 524 cFYI(1, "Create symlink ok, getinodeinfo fail rc = %d",
525 rc); 525 rc);
526 } else { 526 } else {
527 if (pTcon->nocase)
528 d_set_d_op(direntry, &cifs_ci_dentry_ops);
529 else
530 d_set_d_op(direntry, &cifs_dentry_ops);
531 d_instantiate(direntry, newinode); 527 d_instantiate(direntry, newinode);
532 } 528 }
533 } 529 }
diff --git a/fs/cifs/readdir.c b/fs/cifs/readdir.c
index 76b1b37c9e6b..7f25cc3d2256 100644
--- a/fs/cifs/readdir.c
+++ b/fs/cifs/readdir.c
@@ -102,11 +102,6 @@ cifs_readdir_lookup(struct dentry *parent, struct qstr *name,
102 return NULL; 102 return NULL;
103 } 103 }
104 104
105 if (cifs_sb_master_tcon(CIFS_SB(sb))->nocase)
106 d_set_d_op(dentry, &cifs_ci_dentry_ops);
107 else
108 d_set_d_op(dentry, &cifs_dentry_ops);
109
110 alias = d_materialise_unique(dentry, inode); 105 alias = d_materialise_unique(dentry, inode);
111 if (alias != NULL) { 106 if (alias != NULL) {
112 dput(dentry); 107 dput(dentry);
diff --git a/fs/coda/cache.c b/fs/coda/cache.c
index 5525e1c660fd..690157876184 100644
--- a/fs/coda/cache.c
+++ b/fs/coda/cache.c
@@ -20,10 +20,9 @@
20#include <linux/spinlock.h> 20#include <linux/spinlock.h>
21 21
22#include <linux/coda.h> 22#include <linux/coda.h>
23#include <linux/coda_linux.h>
24#include <linux/coda_psdev.h> 23#include <linux/coda_psdev.h>
25#include <linux/coda_fs_i.h> 24#include "coda_linux.h"
26#include <linux/coda_cache.h> 25#include "coda_cache.h"
27 26
28static atomic_t permission_epoch = ATOMIC_INIT(0); 27static atomic_t permission_epoch = ATOMIC_INIT(0);
29 28
diff --git a/fs/coda/cnode.c b/fs/coda/cnode.c
index 602240569c89..6475877b0763 100644
--- a/fs/coda/cnode.c
+++ b/fs/coda/cnode.c
@@ -7,9 +7,8 @@
7#include <linux/time.h> 7#include <linux/time.h>
8 8
9#include <linux/coda.h> 9#include <linux/coda.h>
10#include <linux/coda_linux.h>
11#include <linux/coda_fs_i.h>
12#include <linux/coda_psdev.h> 10#include <linux/coda_psdev.h>
11#include "coda_linux.h"
13 12
14static inline int coda_fideq(struct CodaFid *fid1, struct CodaFid *fid2) 13static inline int coda_fideq(struct CodaFid *fid1, struct CodaFid *fid2)
15{ 14{
diff --git a/include/linux/coda_cache.h b/fs/coda/coda_cache.h
index c910b5eb1ceb..c910b5eb1ceb 100644
--- a/include/linux/coda_cache.h
+++ b/fs/coda/coda_cache.h
diff --git a/include/linux/coda_fs_i.h b/fs/coda/coda_fs_i.h
index e35071b1de0e..e35071b1de0e 100644
--- a/include/linux/coda_fs_i.h
+++ b/fs/coda/coda_fs_i.h
diff --git a/fs/coda/coda_linux.c b/fs/coda/coda_linux.c
index bf4a3fd3c8e3..2bdbcc11b373 100644
--- a/fs/coda/coda_linux.c
+++ b/fs/coda/coda_linux.c
@@ -17,9 +17,8 @@
17#include <linux/string.h> 17#include <linux/string.h>
18 18
19#include <linux/coda.h> 19#include <linux/coda.h>
20#include <linux/coda_linux.h>
21#include <linux/coda_psdev.h> 20#include <linux/coda_psdev.h>
22#include <linux/coda_fs_i.h> 21#include "coda_linux.h"
23 22
24/* initialize the debugging variables */ 23/* initialize the debugging variables */
25int coda_fake_statfs; 24int coda_fake_statfs;
diff --git a/include/linux/coda_linux.h b/fs/coda/coda_linux.h
index 4ccc59c1ea82..9b0c5323890b 100644
--- a/include/linux/coda_linux.h
+++ b/fs/coda/coda_linux.h
@@ -20,13 +20,15 @@
20#include <linux/wait.h> 20#include <linux/wait.h>
21#include <linux/types.h> 21#include <linux/types.h>
22#include <linux/fs.h> 22#include <linux/fs.h>
23#include <linux/coda_fs_i.h> 23#include "coda_fs_i.h"
24 24
25/* operations */ 25/* operations */
26extern const struct inode_operations coda_dir_inode_operations; 26extern const struct inode_operations coda_dir_inode_operations;
27extern const struct inode_operations coda_file_inode_operations; 27extern const struct inode_operations coda_file_inode_operations;
28extern const struct inode_operations coda_ioctl_inode_operations; 28extern const struct inode_operations coda_ioctl_inode_operations;
29 29
30extern const struct dentry_operations coda_dentry_operations;
31
30extern const struct address_space_operations coda_file_aops; 32extern const struct address_space_operations coda_file_aops;
31extern const struct address_space_operations coda_symlink_aops; 33extern const struct address_space_operations coda_symlink_aops;
32 34
diff --git a/fs/coda/dir.c b/fs/coda/dir.c
index 29badd91360f..2b8dae4d121e 100644
--- a/fs/coda/dir.c
+++ b/fs/coda/dir.c
@@ -23,10 +23,9 @@
23#include <asm/uaccess.h> 23#include <asm/uaccess.h>
24 24
25#include <linux/coda.h> 25#include <linux/coda.h>
26#include <linux/coda_linux.h>
27#include <linux/coda_psdev.h> 26#include <linux/coda_psdev.h>
28#include <linux/coda_fs_i.h> 27#include "coda_linux.h"
29#include <linux/coda_cache.h> 28#include "coda_cache.h"
30 29
31#include "coda_int.h" 30#include "coda_int.h"
32 31
@@ -61,7 +60,7 @@ static int coda_return_EIO(void)
61} 60}
62#define CODA_EIO_ERROR ((void *) (coda_return_EIO)) 61#define CODA_EIO_ERROR ((void *) (coda_return_EIO))
63 62
64static const struct dentry_operations coda_dentry_operations = 63const struct dentry_operations coda_dentry_operations =
65{ 64{
66 .d_revalidate = coda_dentry_revalidate, 65 .d_revalidate = coda_dentry_revalidate,
67 .d_delete = coda_dentry_delete, 66 .d_delete = coda_dentry_delete,
@@ -126,8 +125,6 @@ static struct dentry *coda_lookup(struct inode *dir, struct dentry *entry, struc
126 return ERR_PTR(error); 125 return ERR_PTR(error);
127 126
128exit: 127exit:
129 d_set_d_op(entry, &coda_dentry_operations);
130
131 if (inode && (type & CODA_NOCACHE)) 128 if (inode && (type & CODA_NOCACHE))
132 coda_flag_inode(inode, C_VATTR | C_PURGE); 129 coda_flag_inode(inode, C_VATTR | C_PURGE);
133 130
diff --git a/fs/coda/file.c b/fs/coda/file.c
index c8b50ba4366a..0433057be330 100644
--- a/fs/coda/file.c
+++ b/fs/coda/file.c
@@ -21,10 +21,9 @@
21#include <asm/uaccess.h> 21#include <asm/uaccess.h>
22 22
23#include <linux/coda.h> 23#include <linux/coda.h>
24#include <linux/coda_linux.h>
25#include <linux/coda_fs_i.h>
26#include <linux/coda_psdev.h> 24#include <linux/coda_psdev.h>
27 25
26#include "coda_linux.h"
28#include "coda_int.h" 27#include "coda_int.h"
29 28
30static ssize_t 29static ssize_t
diff --git a/fs/coda/inode.c b/fs/coda/inode.c
index 50dc7d189f56..871b27715465 100644
--- a/fs/coda/inode.c
+++ b/fs/coda/inode.c
@@ -28,10 +28,9 @@
28#include <linux/vmalloc.h> 28#include <linux/vmalloc.h>
29 29
30#include <linux/coda.h> 30#include <linux/coda.h>
31#include <linux/coda_linux.h>
32#include <linux/coda_psdev.h> 31#include <linux/coda_psdev.h>
33#include <linux/coda_fs_i.h> 32#include "coda_linux.h"
34#include <linux/coda_cache.h> 33#include "coda_cache.h"
35 34
36#include "coda_int.h" 35#include "coda_int.h"
37 36
@@ -45,7 +44,7 @@ static struct kmem_cache * coda_inode_cachep;
45static struct inode *coda_alloc_inode(struct super_block *sb) 44static struct inode *coda_alloc_inode(struct super_block *sb)
46{ 45{
47 struct coda_inode_info *ei; 46 struct coda_inode_info *ei;
48 ei = (struct coda_inode_info *)kmem_cache_alloc(coda_inode_cachep, GFP_KERNEL); 47 ei = kmem_cache_alloc(coda_inode_cachep, GFP_KERNEL);
49 if (!ei) 48 if (!ei)
50 return NULL; 49 return NULL;
51 memset(&ei->c_fid, 0, sizeof(struct CodaFid)); 50 memset(&ei->c_fid, 0, sizeof(struct CodaFid));
@@ -193,6 +192,7 @@ static int coda_fill_super(struct super_block *sb, void *data, int silent)
193 sb->s_blocksize_bits = 12; 192 sb->s_blocksize_bits = 12;
194 sb->s_magic = CODA_SUPER_MAGIC; 193 sb->s_magic = CODA_SUPER_MAGIC;
195 sb->s_op = &coda_super_operations; 194 sb->s_op = &coda_super_operations;
195 sb->s_d_op = &coda_dentry_operations;
196 sb->s_bdi = &vc->bdi; 196 sb->s_bdi = &vc->bdi;
197 197
198 /* get root fid from Venus: this needs the root inode */ 198 /* get root fid from Venus: this needs the root inode */
diff --git a/fs/coda/pioctl.c b/fs/coda/pioctl.c
index 741f0bd03918..6cbb3afb36dc 100644
--- a/fs/coda/pioctl.c
+++ b/fs/coda/pioctl.c
@@ -19,10 +19,10 @@
19#include <asm/uaccess.h> 19#include <asm/uaccess.h>
20 20
21#include <linux/coda.h> 21#include <linux/coda.h>
22#include <linux/coda_linux.h>
23#include <linux/coda_fs_i.h>
24#include <linux/coda_psdev.h> 22#include <linux/coda_psdev.h>
25 23
24#include "coda_linux.h"
25
26/* pioctl ops */ 26/* pioctl ops */
27static int coda_ioctl_permission(struct inode *inode, int mask, unsigned int flags); 27static int coda_ioctl_permission(struct inode *inode, int mask, unsigned int flags);
28static long coda_pioctl(struct file *filp, unsigned int cmd, 28static long coda_pioctl(struct file *filp, unsigned int cmd,
diff --git a/fs/coda/psdev.c b/fs/coda/psdev.c
index 62647a8595e4..8f616e0e252c 100644
--- a/fs/coda/psdev.c
+++ b/fs/coda/psdev.c
@@ -43,10 +43,10 @@
43#include <asm/uaccess.h> 43#include <asm/uaccess.h>
44 44
45#include <linux/coda.h> 45#include <linux/coda.h>
46#include <linux/coda_linux.h>
47#include <linux/coda_fs_i.h>
48#include <linux/coda_psdev.h> 46#include <linux/coda_psdev.h>
49 47
48#include "coda_linux.h"
49
50#include "coda_int.h" 50#include "coda_int.h"
51 51
52/* statistics */ 52/* statistics */
diff --git a/fs/coda/symlink.c b/fs/coda/symlink.c
index af78f007a2b0..ab94ef63caef 100644
--- a/fs/coda/symlink.c
+++ b/fs/coda/symlink.c
@@ -16,9 +16,9 @@
16#include <linux/pagemap.h> 16#include <linux/pagemap.h>
17 17
18#include <linux/coda.h> 18#include <linux/coda.h>
19#include <linux/coda_linux.h>
20#include <linux/coda_psdev.h> 19#include <linux/coda_psdev.h>
21#include <linux/coda_fs_i.h> 20
21#include "coda_linux.h"
22 22
23static int coda_symlink_filler(struct file *file, struct page *page) 23static int coda_symlink_filler(struct file *file, struct page *page)
24{ 24{
diff --git a/fs/coda/upcall.c b/fs/coda/upcall.c
index c3563cab9758..9727e0c52579 100644
--- a/fs/coda/upcall.c
+++ b/fs/coda/upcall.c
@@ -33,10 +33,9 @@
33#include <linux/vfs.h> 33#include <linux/vfs.h>
34 34
35#include <linux/coda.h> 35#include <linux/coda.h>
36#include <linux/coda_linux.h>
37#include <linux/coda_psdev.h> 36#include <linux/coda_psdev.h>
38#include <linux/coda_fs_i.h> 37#include "coda_linux.h"
39#include <linux/coda_cache.h> 38#include "coda_cache.h"
40 39
41#include "coda_int.h" 40#include "coda_int.h"
42 41
diff --git a/fs/configfs/configfs_internal.h b/fs/configfs/configfs_internal.h
index 026cf68553a4..82bda8fdfc1c 100644
--- a/fs/configfs/configfs_internal.h
+++ b/fs/configfs/configfs_internal.h
@@ -90,6 +90,7 @@ extern const struct file_operations configfs_file_operations;
90extern const struct file_operations bin_fops; 90extern const struct file_operations bin_fops;
91extern const struct inode_operations configfs_dir_inode_operations; 91extern const struct inode_operations configfs_dir_inode_operations;
92extern const struct inode_operations configfs_symlink_inode_operations; 92extern const struct inode_operations configfs_symlink_inode_operations;
93extern const struct dentry_operations configfs_dentry_ops;
93 94
94extern int configfs_symlink(struct inode *dir, struct dentry *dentry, 95extern int configfs_symlink(struct inode *dir, struct dentry *dentry,
95 const char *symname); 96 const char *symname);
diff --git a/fs/configfs/dir.c b/fs/configfs/dir.c
index 36637a8c1ed3..90ff3cb10de3 100644
--- a/fs/configfs/dir.c
+++ b/fs/configfs/dir.c
@@ -72,7 +72,7 @@ static int configfs_d_delete(const struct dentry *dentry)
72 return 1; 72 return 1;
73} 73}
74 74
75static const struct dentry_operations configfs_dentry_ops = { 75const struct dentry_operations configfs_dentry_ops = {
76 .d_iput = configfs_d_iput, 76 .d_iput = configfs_d_iput,
77 /* simple_delete_dentry() isn't exported */ 77 /* simple_delete_dentry() isn't exported */
78 .d_delete = configfs_d_delete, 78 .d_delete = configfs_d_delete,
@@ -442,7 +442,6 @@ static int configfs_attach_attr(struct configfs_dirent * sd, struct dentry * den
442 return error; 442 return error;
443 } 443 }
444 444
445 d_set_d_op(dentry, &configfs_dentry_ops);
446 d_rehash(dentry); 445 d_rehash(dentry);
447 446
448 return 0; 447 return 0;
@@ -489,7 +488,6 @@ static struct dentry * configfs_lookup(struct inode *dir,
489 */ 488 */
490 if (dentry->d_name.len > NAME_MAX) 489 if (dentry->d_name.len > NAME_MAX)
491 return ERR_PTR(-ENAMETOOLONG); 490 return ERR_PTR(-ENAMETOOLONG);
492 d_set_d_op(dentry, &configfs_dentry_ops);
493 d_add(dentry, NULL); 491 d_add(dentry, NULL);
494 return NULL; 492 return NULL;
495 } 493 }
@@ -683,7 +681,6 @@ static int create_default_group(struct config_group *parent_group,
683 ret = -ENOMEM; 681 ret = -ENOMEM;
684 child = d_alloc(parent, &name); 682 child = d_alloc(parent, &name);
685 if (child) { 683 if (child) {
686 d_set_d_op(child, &configfs_dentry_ops);
687 d_add(child, NULL); 684 d_add(child, NULL);
688 685
689 ret = configfs_attach_group(&parent_group->cg_item, 686 ret = configfs_attach_group(&parent_group->cg_item,
@@ -1681,7 +1678,6 @@ int configfs_register_subsystem(struct configfs_subsystem *subsys)
1681 err = -ENOMEM; 1678 err = -ENOMEM;
1682 dentry = d_alloc(configfs_sb->s_root, &name); 1679 dentry = d_alloc(configfs_sb->s_root, &name);
1683 if (dentry) { 1680 if (dentry) {
1684 d_set_d_op(dentry, &configfs_dentry_ops);
1685 d_add(dentry, NULL); 1681 d_add(dentry, NULL);
1686 1682
1687 err = configfs_attach_group(sd->s_element, &group->cg_item, 1683 err = configfs_attach_group(sd->s_element, &group->cg_item,
diff --git a/fs/configfs/mount.c b/fs/configfs/mount.c
index 7d3607febe1c..ecc62178beda 100644
--- a/fs/configfs/mount.c
+++ b/fs/configfs/mount.c
@@ -101,6 +101,7 @@ static int configfs_fill_super(struct super_block *sb, void *data, int silent)
101 configfs_root_group.cg_item.ci_dentry = root; 101 configfs_root_group.cg_item.ci_dentry = root;
102 root->d_fsdata = &configfs_root; 102 root->d_fsdata = &configfs_root;
103 sb->s_root = root; 103 sb->s_root = root;
104 sb->s_d_op = &configfs_dentry_ops; /* the rest get that */
104 return 0; 105 return 0;
105} 106}
106 107
diff --git a/fs/cramfs/inode.c b/fs/cramfs/inode.c
index 32fd5fe9ca0e..e141939080f0 100644
--- a/fs/cramfs/inode.c
+++ b/fs/cramfs/inode.c
@@ -34,57 +34,81 @@ static const struct address_space_operations cramfs_aops;
34static DEFINE_MUTEX(read_mutex); 34static DEFINE_MUTEX(read_mutex);
35 35
36 36
37/* These two macros may change in future, to provide better st_ino 37/* These macros may change in future, to provide better st_ino semantics. */
38 semantics. */
39#define CRAMINO(x) (((x)->offset && (x)->size)?(x)->offset<<2:1)
40#define OFFSET(x) ((x)->i_ino) 38#define OFFSET(x) ((x)->i_ino)
41 39
42static void setup_inode(struct inode *inode, struct cramfs_inode * cramfs_inode) 40static unsigned long cramino(struct cramfs_inode *cino, unsigned int offset)
43{ 41{
42 if (!cino->offset)
43 return offset + 1;
44 if (!cino->size)
45 return offset + 1;
46
47 /*
48 * The file mode test fixes buggy mkcramfs implementations where
49 * cramfs_inode->offset is set to a non zero value for entries
50 * which did not contain data, like devices node and fifos.
51 */
52 switch (cino->mode & S_IFMT) {
53 case S_IFREG:
54 case S_IFDIR:
55 case S_IFLNK:
56 return cino->offset << 2;
57 default:
58 break;
59 }
60 return offset + 1;
61}
62
63static struct inode *get_cramfs_inode(struct super_block *sb,
64 struct cramfs_inode *cramfs_inode, unsigned int offset)
65{
66 struct inode *inode;
44 static struct timespec zerotime; 67 static struct timespec zerotime;
68
69 inode = iget_locked(sb, cramino(cramfs_inode, offset));
70 if (!inode)
71 return ERR_PTR(-ENOMEM);
72 if (!(inode->i_state & I_NEW))
73 return inode;
74
75 switch (cramfs_inode->mode & S_IFMT) {
76 case S_IFREG:
77 inode->i_fop = &generic_ro_fops;
78 inode->i_data.a_ops = &cramfs_aops;
79 break;
80 case S_IFDIR:
81 inode->i_op = &cramfs_dir_inode_operations;
82 inode->i_fop = &cramfs_directory_operations;
83 break;
84 case S_IFLNK:
85 inode->i_op = &page_symlink_inode_operations;
86 inode->i_data.a_ops = &cramfs_aops;
87 break;
88 default:
89 init_special_inode(inode, cramfs_inode->mode,
90 old_decode_dev(cramfs_inode->size));
91 }
92
45 inode->i_mode = cramfs_inode->mode; 93 inode->i_mode = cramfs_inode->mode;
46 inode->i_uid = cramfs_inode->uid; 94 inode->i_uid = cramfs_inode->uid;
47 inode->i_size = cramfs_inode->size;
48 inode->i_blocks = (cramfs_inode->size - 1) / 512 + 1;
49 inode->i_gid = cramfs_inode->gid; 95 inode->i_gid = cramfs_inode->gid;
96
97 /* if the lower 2 bits are zero, the inode contains data */
98 if (!(inode->i_ino & 3)) {
99 inode->i_size = cramfs_inode->size;
100 inode->i_blocks = (cramfs_inode->size - 1) / 512 + 1;
101 }
102
50 /* Struct copy intentional */ 103 /* Struct copy intentional */
51 inode->i_mtime = inode->i_atime = inode->i_ctime = zerotime; 104 inode->i_mtime = inode->i_atime = inode->i_ctime = zerotime;
52 /* inode->i_nlink is left 1 - arguably wrong for directories, 105 /* inode->i_nlink is left 1 - arguably wrong for directories,
53 but it's the best we can do without reading the directory 106 but it's the best we can do without reading the directory
54 contents. 1 yields the right result in GNU find, even 107 contents. 1 yields the right result in GNU find, even
55 without -noleaf option. */ 108 without -noleaf option. */
56 if (S_ISREG(inode->i_mode)) {
57 inode->i_fop = &generic_ro_fops;
58 inode->i_data.a_ops = &cramfs_aops;
59 } else if (S_ISDIR(inode->i_mode)) {
60 inode->i_op = &cramfs_dir_inode_operations;
61 inode->i_fop = &cramfs_directory_operations;
62 } else if (S_ISLNK(inode->i_mode)) {
63 inode->i_op = &page_symlink_inode_operations;
64 inode->i_data.a_ops = &cramfs_aops;
65 } else {
66 init_special_inode(inode, inode->i_mode,
67 old_decode_dev(cramfs_inode->size));
68 }
69}
70 109
71static struct inode *get_cramfs_inode(struct super_block *sb, 110 unlock_new_inode(inode);
72 struct cramfs_inode * cramfs_inode) 111
73{
74 struct inode *inode;
75 if (CRAMINO(cramfs_inode) == 1) {
76 inode = new_inode(sb);
77 if (inode) {
78 inode->i_ino = 1;
79 setup_inode(inode, cramfs_inode);
80 }
81 } else {
82 inode = iget_locked(sb, CRAMINO(cramfs_inode));
83 if (inode && (inode->i_state & I_NEW)) {
84 setup_inode(inode, cramfs_inode);
85 unlock_new_inode(inode);
86 }
87 }
88 return inode; 112 return inode;
89} 113}
90 114
@@ -265,6 +289,9 @@ static int cramfs_fill_super(struct super_block *sb, void *data, int silent)
265 printk(KERN_ERR "cramfs: root is not a directory\n"); 289 printk(KERN_ERR "cramfs: root is not a directory\n");
266 goto out; 290 goto out;
267 } 291 }
292 /* correct strange, hard-coded permissions of mkcramfs */
293 super.root.mode |= (S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
294
268 root_offset = super.root.offset << 2; 295 root_offset = super.root.offset << 2;
269 if (super.flags & CRAMFS_FLAG_FSID_VERSION_2) { 296 if (super.flags & CRAMFS_FLAG_FSID_VERSION_2) {
270 sbi->size=super.size; 297 sbi->size=super.size;
@@ -289,7 +316,7 @@ static int cramfs_fill_super(struct super_block *sb, void *data, int silent)
289 316
290 /* Set it all up.. */ 317 /* Set it all up.. */
291 sb->s_op = &cramfs_ops; 318 sb->s_op = &cramfs_ops;
292 root = get_cramfs_inode(sb, &super.root); 319 root = get_cramfs_inode(sb, &super.root, 0);
293 if (!root) 320 if (!root)
294 goto out; 321 goto out;
295 sb->s_root = d_alloc_root(root); 322 sb->s_root = d_alloc_root(root);
@@ -365,7 +392,7 @@ static int cramfs_readdir(struct file *filp, void *dirent, filldir_t filldir)
365 */ 392 */
366 namelen = de->namelen << 2; 393 namelen = de->namelen << 2;
367 memcpy(buf, name, namelen); 394 memcpy(buf, name, namelen);
368 ino = CRAMINO(de); 395 ino = cramino(de, OFFSET(inode) + offset);
369 mode = de->mode; 396 mode = de->mode;
370 mutex_unlock(&read_mutex); 397 mutex_unlock(&read_mutex);
371 nextoffset = offset + sizeof(*de) + namelen; 398 nextoffset = offset + sizeof(*de) + namelen;
@@ -404,8 +431,9 @@ static struct dentry * cramfs_lookup(struct inode *dir, struct dentry *dentry, s
404 struct cramfs_inode *de; 431 struct cramfs_inode *de;
405 char *name; 432 char *name;
406 int namelen, retval; 433 int namelen, retval;
434 int dir_off = OFFSET(dir) + offset;
407 435
408 de = cramfs_read(dir->i_sb, OFFSET(dir) + offset, sizeof(*de)+CRAMFS_MAXPATHLEN); 436 de = cramfs_read(dir->i_sb, dir_off, sizeof(*de)+CRAMFS_MAXPATHLEN);
409 name = (char *)(de+1); 437 name = (char *)(de+1);
410 438
411 /* Try to take advantage of sorted directories */ 439 /* Try to take advantage of sorted directories */
@@ -436,7 +464,7 @@ static struct dentry * cramfs_lookup(struct inode *dir, struct dentry *dentry, s
436 if (!retval) { 464 if (!retval) {
437 struct cramfs_inode entry = *de; 465 struct cramfs_inode entry = *de;
438 mutex_unlock(&read_mutex); 466 mutex_unlock(&read_mutex);
439 d_add(dentry, get_cramfs_inode(dir->i_sb, &entry)); 467 d_add(dentry, get_cramfs_inode(dir->i_sb, &entry, dir_off));
440 return NULL; 468 return NULL;
441 } 469 }
442 /* else (retval < 0) */ 470 /* else (retval < 0) */
diff --git a/fs/dcache.c b/fs/dcache.c
index 5699d4c027cb..0c6d5c549d84 100644
--- a/fs/dcache.c
+++ b/fs/dcache.c
@@ -1320,6 +1320,7 @@ struct dentry *d_alloc(struct dentry * parent, const struct qstr *name)
1320 __dget_dlock(parent); 1320 __dget_dlock(parent);
1321 dentry->d_parent = parent; 1321 dentry->d_parent = parent;
1322 dentry->d_sb = parent->d_sb; 1322 dentry->d_sb = parent->d_sb;
1323 d_set_d_op(dentry, dentry->d_sb->s_d_op);
1323 list_add(&dentry->d_u.d_child, &parent->d_subdirs); 1324 list_add(&dentry->d_u.d_child, &parent->d_subdirs);
1324 spin_unlock(&parent->d_lock); 1325 spin_unlock(&parent->d_lock);
1325 } 1326 }
@@ -1335,6 +1336,7 @@ struct dentry *d_alloc_pseudo(struct super_block *sb, const struct qstr *name)
1335 struct dentry *dentry = d_alloc(NULL, name); 1336 struct dentry *dentry = d_alloc(NULL, name);
1336 if (dentry) { 1337 if (dentry) {
1337 dentry->d_sb = sb; 1338 dentry->d_sb = sb;
1339 d_set_d_op(dentry, dentry->d_sb->s_d_op);
1338 dentry->d_parent = dentry; 1340 dentry->d_parent = dentry;
1339 dentry->d_flags |= DCACHE_DISCONNECTED; 1341 dentry->d_flags |= DCACHE_DISCONNECTED;
1340 } 1342 }
@@ -1507,6 +1509,7 @@ struct dentry * d_alloc_root(struct inode * root_inode)
1507 res = d_alloc(NULL, &name); 1509 res = d_alloc(NULL, &name);
1508 if (res) { 1510 if (res) {
1509 res->d_sb = root_inode->i_sb; 1511 res->d_sb = root_inode->i_sb;
1512 d_set_d_op(res, res->d_sb->s_d_op);
1510 res->d_parent = res; 1513 res->d_parent = res;
1511 d_instantiate(res, root_inode); 1514 d_instantiate(res, root_inode);
1512 } 1515 }
@@ -1567,6 +1570,7 @@ struct dentry *d_obtain_alias(struct inode *inode)
1567 /* attach a disconnected dentry */ 1570 /* attach a disconnected dentry */
1568 spin_lock(&tmp->d_lock); 1571 spin_lock(&tmp->d_lock);
1569 tmp->d_sb = inode->i_sb; 1572 tmp->d_sb = inode->i_sb;
1573 d_set_d_op(tmp, tmp->d_sb->s_d_op);
1570 tmp->d_inode = inode; 1574 tmp->d_inode = inode;
1571 tmp->d_flags |= DCACHE_DISCONNECTED; 1575 tmp->d_flags |= DCACHE_DISCONNECTED;
1572 list_add(&tmp->d_alias, &inode->i_dentry); 1576 list_add(&tmp->d_alias, &inode->i_dentry);
@@ -1966,7 +1970,7 @@ out:
1966/** 1970/**
1967 * d_validate - verify dentry provided from insecure source (deprecated) 1971 * d_validate - verify dentry provided from insecure source (deprecated)
1968 * @dentry: The dentry alleged to be valid child of @dparent 1972 * @dentry: The dentry alleged to be valid child of @dparent
1969 * @dparent: The parent dentry (known to be valid) 1973 * @parent: The parent dentry (known to be valid)
1970 * 1974 *
1971 * An insecure source has sent us a dentry, here we verify it and dget() it. 1975 * An insecure source has sent us a dentry, here we verify it and dget() it.
1972 * This is used by ncpfs in its readdir implementation. 1976 * This is used by ncpfs in its readdir implementation.
@@ -2449,8 +2453,7 @@ static int prepend_name(char **buffer, int *buflen, struct qstr *name)
2449} 2453}
2450 2454
2451/** 2455/**
2452 * Prepend path string to a buffer 2456 * prepend_path - Prepend path string to a buffer
2453 *
2454 * @path: the dentry/vfsmount to report 2457 * @path: the dentry/vfsmount to report
2455 * @root: root vfsmnt/dentry (may be modified by this function) 2458 * @root: root vfsmnt/dentry (may be modified by this function)
2456 * @buffer: pointer to the end of the buffer 2459 * @buffer: pointer to the end of the buffer
diff --git a/fs/ecryptfs/inode.c b/fs/ecryptfs/inode.c
index 337352a94751..64ff02330752 100644
--- a/fs/ecryptfs/inode.c
+++ b/fs/ecryptfs/inode.c
@@ -441,7 +441,6 @@ static struct dentry *ecryptfs_lookup(struct inode *ecryptfs_dir_inode,
441 struct qstr lower_name; 441 struct qstr lower_name;
442 int rc = 0; 442 int rc = 0;
443 443
444 d_set_d_op(ecryptfs_dentry, &ecryptfs_dops);
445 if ((ecryptfs_dentry->d_name.len == 1 444 if ((ecryptfs_dentry->d_name.len == 1
446 && !strcmp(ecryptfs_dentry->d_name.name, ".")) 445 && !strcmp(ecryptfs_dentry->d_name.name, "."))
447 || (ecryptfs_dentry->d_name.len == 2 446 || (ecryptfs_dentry->d_name.len == 2
diff --git a/fs/ecryptfs/main.c b/fs/ecryptfs/main.c
index 351038675376..9ed476906327 100644
--- a/fs/ecryptfs/main.c
+++ b/fs/ecryptfs/main.c
@@ -141,21 +141,9 @@ int ecryptfs_init_persistent_file(struct dentry *ecryptfs_dentry)
141 return rc; 141 return rc;
142} 142}
143 143
144/** 144static inode *ecryptfs_get_inode(struct inode *lower_inode,
145 * ecryptfs_interpose 145 struct super_block *sb)
146 * @lower_dentry: Existing dentry in the lower filesystem
147 * @dentry: ecryptfs' dentry
148 * @sb: ecryptfs's super_block
149 * @flags: flags to govern behavior of interpose procedure
150 *
151 * Interposes upper and lower dentries.
152 *
153 * Returns zero on success; non-zero otherwise
154 */
155int ecryptfs_interpose(struct dentry *lower_dentry, struct dentry *dentry,
156 struct super_block *sb, u32 flags)
157{ 146{
158 struct inode *lower_inode;
159 struct inode *inode; 147 struct inode *inode;
160 int rc = 0; 148 int rc = 0;
161 149
@@ -189,17 +177,38 @@ int ecryptfs_interpose(struct dentry *lower_dentry, struct dentry *dentry,
189 if (special_file(lower_inode->i_mode)) 177 if (special_file(lower_inode->i_mode))
190 init_special_inode(inode, lower_inode->i_mode, 178 init_special_inode(inode, lower_inode->i_mode,
191 lower_inode->i_rdev); 179 lower_inode->i_rdev);
192 d_set_d_op(dentry, &ecryptfs_dops);
193 fsstack_copy_attr_all(inode, lower_inode); 180 fsstack_copy_attr_all(inode, lower_inode);
194 /* This size will be overwritten for real files w/ headers and 181 /* This size will be overwritten for real files w/ headers and
195 * other metadata */ 182 * other metadata */
196 fsstack_copy_inode_size(inode, lower_inode); 183 fsstack_copy_inode_size(inode, lower_inode);
184 return inode;
185out:
186 return ERR_PTR(rc);
187}
188
189/**
190 * ecryptfs_interpose
191 * @lower_dentry: Existing dentry in the lower filesystem
192 * @dentry: ecryptfs' dentry
193 * @sb: ecryptfs's super_block
194 * @flags: flags to govern behavior of interpose procedure
195 *
196 * Interposes upper and lower dentries.
197 *
198 * Returns zero on success; non-zero otherwise
199 */
200int ecryptfs_interpose(struct dentry *lower_dentry, struct dentry *dentry,
201 struct super_block *sb, u32 flags)
202{
203 struct inode *lower_inode = lower_dentry->d_inode;
204 struct inode *inode = ecryptfs_get_inode(lower_inode, sb);
205 if (IS_ERR(inode)
206 return PTR_ERR(inode);
197 if (flags & ECRYPTFS_INTERPOSE_FLAG_D_ADD) 207 if (flags & ECRYPTFS_INTERPOSE_FLAG_D_ADD)
198 d_add(dentry, inode); 208 d_add(dentry, inode);
199 else 209 else
200 d_instantiate(dentry, inode); 210 d_instantiate(dentry, inode);
201out: 211 return 0;
202 return rc;
203} 212}
204 213
205enum { ecryptfs_opt_sig, ecryptfs_opt_ecryptfs_sig, 214enum { ecryptfs_opt_sig, ecryptfs_opt_ecryptfs_sig,
@@ -492,59 +501,11 @@ struct kmem_cache *ecryptfs_sb_info_cache;
492static struct file_system_type ecryptfs_fs_type; 501static struct file_system_type ecryptfs_fs_type;
493 502
494/** 503/**
495 * ecryptfs_read_super
496 * @sb: The ecryptfs super block
497 * @dev_name: The path to mount over
498 *
499 * Read the super block of the lower filesystem, and use
500 * ecryptfs_interpose to create our initial inode and super block
501 * struct.
502 */
503static int ecryptfs_read_super(struct super_block *sb, const char *dev_name)
504{
505 struct path path;
506 int rc;
507
508 rc = kern_path(dev_name, LOOKUP_FOLLOW | LOOKUP_DIRECTORY, &path);
509 if (rc) {
510 ecryptfs_printk(KERN_WARNING, "path_lookup() failed\n");
511 goto out;
512 }
513 if (path.dentry->d_sb->s_type == &ecryptfs_fs_type) {
514 rc = -EINVAL;
515 printk(KERN_ERR "Mount on filesystem of type "
516 "eCryptfs explicitly disallowed due to "
517 "known incompatibilities\n");
518 goto out_free;
519 }
520 ecryptfs_set_superblock_lower(sb, path.dentry->d_sb);
521 sb->s_maxbytes = path.dentry->d_sb->s_maxbytes;
522 sb->s_blocksize = path.dentry->d_sb->s_blocksize;
523 ecryptfs_set_dentry_lower(sb->s_root, path.dentry);
524 ecryptfs_set_dentry_lower_mnt(sb->s_root, path.mnt);
525 rc = ecryptfs_interpose(path.dentry, sb->s_root, sb, 0);
526 if (rc)
527 goto out_free;
528 rc = 0;
529 goto out;
530out_free:
531 path_put(&path);
532out:
533 return rc;
534}
535
536/**
537 * ecryptfs_get_sb 504 * ecryptfs_get_sb
538 * @fs_type 505 * @fs_type
539 * @flags 506 * @flags
540 * @dev_name: The path to mount over 507 * @dev_name: The path to mount over
541 * @raw_data: The options passed into the kernel 508 * @raw_data: The options passed into the kernel
542 *
543 * The whole ecryptfs_get_sb process is broken into 3 functions:
544 * ecryptfs_parse_options(): handle options passed to ecryptfs, if any
545 * ecryptfs_read_super(): this accesses the lower filesystem and uses
546 * ecryptfs_interpose to perform most of the linking
547 * ecryptfs_interpose(): links the lower filesystem into ecryptfs (inode.c)
548 */ 509 */
549static struct dentry *ecryptfs_mount(struct file_system_type *fs_type, int flags, 510static struct dentry *ecryptfs_mount(struct file_system_type *fs_type, int flags,
550 const char *dev_name, void *raw_data) 511 const char *dev_name, void *raw_data)
@@ -553,6 +514,8 @@ static struct dentry *ecryptfs_mount(struct file_system_type *fs_type, int flags
553 struct ecryptfs_sb_info *sbi; 514 struct ecryptfs_sb_info *sbi;
554 struct ecryptfs_dentry_info *root_info; 515 struct ecryptfs_dentry_info *root_info;
555 const char *err = "Getting sb failed"; 516 const char *err = "Getting sb failed";
517 struct inode *inode;
518 struct path path;
556 int rc; 519 int rc;
557 520
558 sbi = kmem_cache_zalloc(ecryptfs_sb_info_cache, GFP_KERNEL); 521 sbi = kmem_cache_zalloc(ecryptfs_sb_info_cache, GFP_KERNEL);
@@ -575,10 +538,8 @@ static struct dentry *ecryptfs_mount(struct file_system_type *fs_type, int flags
575 538
576 s->s_flags = flags; 539 s->s_flags = flags;
577 rc = bdi_setup_and_register(&sbi->bdi, "ecryptfs", BDI_CAP_MAP_COPY); 540 rc = bdi_setup_and_register(&sbi->bdi, "ecryptfs", BDI_CAP_MAP_COPY);
578 if (rc) { 541 if (rc)
579 deactivate_locked_super(s); 542 goto out1;
580 goto out;
581 }
582 543
583 ecryptfs_set_superblock_private(s, sbi); 544 ecryptfs_set_superblock_private(s, sbi);
584 s->s_bdi = &sbi->bdi; 545 s->s_bdi = &sbi->bdi;
@@ -586,34 +547,54 @@ static struct dentry *ecryptfs_mount(struct file_system_type *fs_type, int flags
586 /* ->kill_sb() will take care of sbi after that point */ 547 /* ->kill_sb() will take care of sbi after that point */
587 sbi = NULL; 548 sbi = NULL;
588 s->s_op = &ecryptfs_sops; 549 s->s_op = &ecryptfs_sops;
550 s->s_d_op = &ecryptfs_dops;
589 551
590 rc = -ENOMEM; 552 err = "Reading sb failed";
591 s->s_root = d_alloc(NULL, &(const struct qstr) { 553 rc = kern_path(dev_name, LOOKUP_FOLLOW | LOOKUP_DIRECTORY, &path);
592 .hash = 0,.name = "/",.len = 1}); 554 if (rc) {
555 ecryptfs_printk(KERN_WARNING, "kern_path() failed\n");
556 goto out1;
557 }
558 if (path.dentry->d_sb->s_type == &ecryptfs_fs_type) {
559 rc = -EINVAL;
560 printk(KERN_ERR "Mount on filesystem of type "
561 "eCryptfs explicitly disallowed due to "
562 "known incompatibilities\n");
563 goto out_free;
564 }
565 ecryptfs_set_superblock_lower(s, path.dentry->d_sb);
566 s->s_maxbytes = path.dentry->d_sb->s_maxbytes;
567 s->s_blocksize = path.dentry->d_sb->s_blocksize;
568
569 inode = ecryptfs_get_inode(path.dentry->d_inode, s);
570 rc = PTR_ERR(inode);
571 if (IS_ERR(inode))
572 goto out_free;
573
574 s->s_root = d_alloc_root(inode);
593 if (!s->s_root) { 575 if (!s->s_root) {
594 deactivate_locked_super(s); 576 iput(inode);
595 goto out; 577 rc = -ENOMEM;
578 goto out_free;
596 } 579 }
597 d_set_d_op(s->s_root, &ecryptfs_dops);
598 s->s_root->d_sb = s;
599 s->s_root->d_parent = s->s_root;
600 580
581 rc = -ENOMEM;
601 root_info = kmem_cache_zalloc(ecryptfs_dentry_info_cache, GFP_KERNEL); 582 root_info = kmem_cache_zalloc(ecryptfs_dentry_info_cache, GFP_KERNEL);
602 if (!root_info) { 583 if (!root_info)
603 deactivate_locked_super(s); 584 goto out_free;
604 goto out; 585
605 }
606 /* ->kill_sb() will take care of root_info */ 586 /* ->kill_sb() will take care of root_info */
607 ecryptfs_set_dentry_private(s->s_root, root_info); 587 ecryptfs_set_dentry_private(s->s_root, root_info);
588 ecryptfs_set_dentry_lower(s->s_root, path.dentry);
589 ecryptfs_set_dentry_lower_mnt(s->s_root, path.mnt);
590
608 s->s_flags |= MS_ACTIVE; 591 s->s_flags |= MS_ACTIVE;
609 rc = ecryptfs_read_super(s, dev_name);
610 if (rc) {
611 deactivate_locked_super(s);
612 err = "Reading sb failed";
613 goto out;
614 }
615 return dget(s->s_root); 592 return dget(s->s_root);
616 593
594out_free:
595 path_put(&path);
596out1:
597 deactivate_locked_super(s);
617out: 598out:
618 if (sbi) { 599 if (sbi) {
619 ecryptfs_destroy_mount_crypt_stat(&sbi->mount_crypt_stat); 600 ecryptfs_destroy_mount_crypt_stat(&sbi->mount_crypt_stat);
diff --git a/fs/eventpoll.c b/fs/eventpoll.c
index 8cf07242067d..cc8a9b7d6064 100644
--- a/fs/eventpoll.c
+++ b/fs/eventpoll.c
@@ -217,7 +217,7 @@ struct ep_send_events_data {
217 * Configuration options available inside /proc/sys/fs/epoll/ 217 * Configuration options available inside /proc/sys/fs/epoll/
218 */ 218 */
219/* Maximum number of epoll watched descriptors, per user */ 219/* Maximum number of epoll watched descriptors, per user */
220static int max_user_watches __read_mostly; 220static long max_user_watches __read_mostly;
221 221
222/* 222/*
223 * This mutex is used to serialize ep_free() and eventpoll_release_file(). 223 * This mutex is used to serialize ep_free() and eventpoll_release_file().
@@ -240,16 +240,18 @@ static struct kmem_cache *pwq_cache __read_mostly;
240 240
241#include <linux/sysctl.h> 241#include <linux/sysctl.h>
242 242
243static int zero; 243static long zero;
244static long long_max = LONG_MAX;
244 245
245ctl_table epoll_table[] = { 246ctl_table epoll_table[] = {
246 { 247 {
247 .procname = "max_user_watches", 248 .procname = "max_user_watches",
248 .data = &max_user_watches, 249 .data = &max_user_watches,
249 .maxlen = sizeof(int), 250 .maxlen = sizeof(max_user_watches),
250 .mode = 0644, 251 .mode = 0644,
251 .proc_handler = proc_dointvec_minmax, 252 .proc_handler = proc_doulongvec_minmax,
252 .extra1 = &zero, 253 .extra1 = &zero,
254 .extra2 = &long_max,
253 }, 255 },
254 { } 256 { }
255}; 257};
@@ -561,7 +563,7 @@ static int ep_remove(struct eventpoll *ep, struct epitem *epi)
561 /* At this point it is safe to free the eventpoll item */ 563 /* At this point it is safe to free the eventpoll item */
562 kmem_cache_free(epi_cache, epi); 564 kmem_cache_free(epi_cache, epi);
563 565
564 atomic_dec(&ep->user->epoll_watches); 566 atomic_long_dec(&ep->user->epoll_watches);
565 567
566 return 0; 568 return 0;
567} 569}
@@ -898,11 +900,12 @@ static int ep_insert(struct eventpoll *ep, struct epoll_event *event,
898{ 900{
899 int error, revents, pwake = 0; 901 int error, revents, pwake = 0;
900 unsigned long flags; 902 unsigned long flags;
903 long user_watches;
901 struct epitem *epi; 904 struct epitem *epi;
902 struct ep_pqueue epq; 905 struct ep_pqueue epq;
903 906
904 if (unlikely(atomic_read(&ep->user->epoll_watches) >= 907 user_watches = atomic_long_read(&ep->user->epoll_watches);
905 max_user_watches)) 908 if (unlikely(user_watches >= max_user_watches))
906 return -ENOSPC; 909 return -ENOSPC;
907 if (!(epi = kmem_cache_alloc(epi_cache, GFP_KERNEL))) 910 if (!(epi = kmem_cache_alloc(epi_cache, GFP_KERNEL)))
908 return -ENOMEM; 911 return -ENOMEM;
@@ -966,7 +969,7 @@ static int ep_insert(struct eventpoll *ep, struct epoll_event *event,
966 969
967 spin_unlock_irqrestore(&ep->lock, flags); 970 spin_unlock_irqrestore(&ep->lock, flags);
968 971
969 atomic_inc(&ep->user->epoll_watches); 972 atomic_long_inc(&ep->user->epoll_watches);
970 973
971 /* We have to call this outside the lock */ 974 /* We have to call this outside the lock */
972 if (pwake) 975 if (pwake)
@@ -1426,6 +1429,7 @@ static int __init eventpoll_init(void)
1426 */ 1429 */
1427 max_user_watches = (((si.totalram - si.totalhigh) / 25) << PAGE_SHIFT) / 1430 max_user_watches = (((si.totalram - si.totalhigh) / 25) << PAGE_SHIFT) /
1428 EP_ITEM_COST; 1431 EP_ITEM_COST;
1432 BUG_ON(max_user_watches < 0);
1429 1433
1430 /* Initialize the structure used to perform safe poll wait head wake ups */ 1434 /* Initialize the structure used to perform safe poll wait head wake ups */
1431 ep_nested_calls_init(&poll_safewake_ncalls); 1435 ep_nested_calls_init(&poll_safewake_ncalls);
diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
index bab2387fba43..1de65f572033 100644
--- a/fs/ext4/ext4.h
+++ b/fs/ext4/ext4.h
@@ -561,7 +561,7 @@ struct ext4_new_group_data {
561#define EXT4_IOC32_SETVERSION_OLD FS_IOC32_SETVERSION 561#define EXT4_IOC32_SETVERSION_OLD FS_IOC32_SETVERSION
562#endif 562#endif
563 563
564/* Max physical block we can addres w/o extents */ 564/* Max physical block we can address w/o extents */
565#define EXT4_MAX_BLOCK_FILE_PHYS 0xFFFFFFFF 565#define EXT4_MAX_BLOCK_FILE_PHYS 0xFFFFFFFF
566 566
567/* 567/*
diff --git a/fs/ext4/extents.c b/fs/ext4/extents.c
index e910720e8bb8..c4068f6abf03 100644
--- a/fs/ext4/extents.c
+++ b/fs/ext4/extents.c
@@ -2845,14 +2845,14 @@ fix_extent_len:
2845 * to an uninitialized extent. 2845 * to an uninitialized extent.
2846 * 2846 *
2847 * Writing to an uninitized extent may result in splitting the uninitialized 2847 * Writing to an uninitized extent may result in splitting the uninitialized
2848 * extent into multiple /intialized unintialized extents (up to three) 2848 * extent into multiple /initialized uninitialized extents (up to three)
2849 * There are three possibilities: 2849 * There are three possibilities:
2850 * a> There is no split required: Entire extent should be uninitialized 2850 * a> There is no split required: Entire extent should be uninitialized
2851 * b> Splits in two extents: Write is happening at either end of the extent 2851 * b> Splits in two extents: Write is happening at either end of the extent
2852 * c> Splits in three extents: Somone is writing in middle of the extent 2852 * c> Splits in three extents: Somone is writing in middle of the extent
2853 * 2853 *
2854 * One of more index blocks maybe needed if the extent tree grow after 2854 * One of more index blocks maybe needed if the extent tree grow after
2855 * the unintialized extent split. To prevent ENOSPC occur at the IO 2855 * the uninitialized extent split. To prevent ENOSPC occur at the IO
2856 * complete, we need to split the uninitialized extent before DIO submit 2856 * complete, we need to split the uninitialized extent before DIO submit
2857 * the IO. The uninitialized extent called at this time will be split 2857 * the IO. The uninitialized extent called at this time will be split
2858 * into three uninitialized extent(at most). After IO complete, the part 2858 * into three uninitialized extent(at most). After IO complete, the part
@@ -3644,6 +3644,10 @@ long ext4_fallocate(struct inode *inode, int mode, loff_t offset, loff_t len)
3644 struct ext4_map_blocks map; 3644 struct ext4_map_blocks map;
3645 unsigned int credits, blkbits = inode->i_blkbits; 3645 unsigned int credits, blkbits = inode->i_blkbits;
3646 3646
3647 /* We only support the FALLOC_FL_KEEP_SIZE mode */
3648 if (mode && (mode != FALLOC_FL_KEEP_SIZE))
3649 return -EOPNOTSUPP;
3650
3647 /* 3651 /*
3648 * currently supporting (pre)allocate mode for extent-based 3652 * currently supporting (pre)allocate mode for extent-based
3649 * files _only_ 3653 * files _only_
diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c
index e80fc513eacc..9f7f9e49914f 100644
--- a/fs/ext4/inode.c
+++ b/fs/ext4/inode.c
@@ -39,6 +39,7 @@
39#include <linux/bio.h> 39#include <linux/bio.h>
40#include <linux/workqueue.h> 40#include <linux/workqueue.h>
41#include <linux/kernel.h> 41#include <linux/kernel.h>
42#include <linux/printk.h>
42#include <linux/slab.h> 43#include <linux/slab.h>
43#include <linux/ratelimit.h> 44#include <linux/ratelimit.h>
44 45
@@ -3379,7 +3380,7 @@ int ext4_alloc_da_blocks(struct inode *inode)
3379 * doing I/O at all. 3380 * doing I/O at all.
3380 * 3381 *
3381 * We could call write_cache_pages(), and then redirty all of 3382 * We could call write_cache_pages(), and then redirty all of
3382 * the pages by calling redirty_page_for_writeback() but that 3383 * the pages by calling redirty_page_for_writepage() but that
3383 * would be ugly in the extreme. So instead we would need to 3384 * would be ugly in the extreme. So instead we would need to
3384 * replicate parts of the code in the above functions, 3385 * replicate parts of the code in the above functions,
3385 * simplifying them becuase we wouldn't actually intend to 3386 * simplifying them becuase we wouldn't actually intend to
@@ -3737,7 +3738,7 @@ static int ext4_set_bh_endio(struct buffer_head *bh, struct inode *inode)
3737retry: 3738retry:
3738 io_end = ext4_init_io_end(inode, GFP_ATOMIC); 3739 io_end = ext4_init_io_end(inode, GFP_ATOMIC);
3739 if (!io_end) { 3740 if (!io_end) {
3740 pr_warning_ratelimited("%s: allocation fail\n", __func__); 3741 pr_warn_ratelimited("%s: allocation fail\n", __func__);
3741 schedule(); 3742 schedule();
3742 goto retry; 3743 goto retry;
3743 } 3744 }
@@ -3761,9 +3762,9 @@ retry:
3761 * preallocated extents, and those write extend the file, no need to 3762 * preallocated extents, and those write extend the file, no need to
3762 * fall back to buffered IO. 3763 * fall back to buffered IO.
3763 * 3764 *
3764 * For holes, we fallocate those blocks, mark them as unintialized 3765 * For holes, we fallocate those blocks, mark them as uninitialized
3765 * If those blocks were preallocated, we mark sure they are splited, but 3766 * If those blocks were preallocated, we mark sure they are splited, but
3766 * still keep the range to write as unintialized. 3767 * still keep the range to write as uninitialized.
3767 * 3768 *
3768 * The unwrritten extents will be converted to written when DIO is completed. 3769 * The unwrritten extents will be converted to written when DIO is completed.
3769 * For async direct IO, since the IO may still pending when return, we 3770 * For async direct IO, since the IO may still pending when return, we
diff --git a/fs/fat/fat.h b/fs/fat/fat.h
index d75a77f85c28..f50408901f7e 100644
--- a/fs/fat/fat.h
+++ b/fs/fat/fat.h
@@ -319,7 +319,8 @@ extern struct inode *fat_build_inode(struct super_block *sb,
319 struct msdos_dir_entry *de, loff_t i_pos); 319 struct msdos_dir_entry *de, loff_t i_pos);
320extern int fat_sync_inode(struct inode *inode); 320extern int fat_sync_inode(struct inode *inode);
321extern int fat_fill_super(struct super_block *sb, void *data, int silent, 321extern int fat_fill_super(struct super_block *sb, void *data, int silent,
322 const struct inode_operations *fs_dir_inode_ops, int isvfat); 322 const struct inode_operations *fs_dir_inode_ops,
323 int isvfat, void (*setup)(struct super_block *));
323 324
324extern int fat_flush_inodes(struct super_block *sb, struct inode *i1, 325extern int fat_flush_inodes(struct super_block *sb, struct inode *i1,
325 struct inode *i2); 326 struct inode *i2);
diff --git a/fs/fat/inode.c b/fs/fat/inode.c
index 206351af7c58..86753fe10bd1 100644
--- a/fs/fat/inode.c
+++ b/fs/fat/inode.c
@@ -703,7 +703,6 @@ static struct dentry *fat_fh_to_dentry(struct super_block *sb,
703 struct fid *fid, int fh_len, int fh_type) 703 struct fid *fid, int fh_len, int fh_type)
704{ 704{
705 struct inode *inode = NULL; 705 struct inode *inode = NULL;
706 struct dentry *result;
707 u32 *fh = fid->raw; 706 u32 *fh = fid->raw;
708 707
709 if (fh_len < 5 || fh_type != 3) 708 if (fh_len < 5 || fh_type != 3)
@@ -748,10 +747,7 @@ static struct dentry *fat_fh_to_dentry(struct super_block *sb,
748 * the fat_iget lookup again. If that fails, then we are totally out 747 * the fat_iget lookup again. If that fails, then we are totally out
749 * of luck. But all that is for another day 748 * of luck. But all that is for another day
750 */ 749 */
751 result = d_obtain_alias(inode); 750 return d_obtain_alias(inode);
752 if (!IS_ERR(result))
753 d_set_d_op(result, sb->s_root->d_op);
754 return result;
755} 751}
756 752
757static int 753static int
@@ -799,8 +795,6 @@ static struct dentry *fat_get_parent(struct dentry *child)
799 brelse(bh); 795 brelse(bh);
800 796
801 parent = d_obtain_alias(inode); 797 parent = d_obtain_alias(inode);
802 if (!IS_ERR(parent))
803 d_set_d_op(parent, sb->s_root->d_op);
804out: 798out:
805 unlock_super(sb); 799 unlock_super(sb);
806 800
@@ -1244,7 +1238,8 @@ static int fat_read_root(struct inode *inode)
1244 * Read the super block of an MS-DOS FS. 1238 * Read the super block of an MS-DOS FS.
1245 */ 1239 */
1246int fat_fill_super(struct super_block *sb, void *data, int silent, 1240int fat_fill_super(struct super_block *sb, void *data, int silent,
1247 const struct inode_operations *fs_dir_inode_ops, int isvfat) 1241 const struct inode_operations *fs_dir_inode_ops, int isvfat,
1242 void (*setup)(struct super_block *))
1248{ 1243{
1249 struct inode *root_inode = NULL, *fat_inode = NULL; 1244 struct inode *root_inode = NULL, *fat_inode = NULL;
1250 struct buffer_head *bh; 1245 struct buffer_head *bh;
@@ -1280,6 +1275,8 @@ int fat_fill_super(struct super_block *sb, void *data, int silent,
1280 if (error) 1275 if (error)
1281 goto out_fail; 1276 goto out_fail;
1282 1277
1278 setup(sb); /* flavour-specific stuff that needs options */
1279
1283 error = -EIO; 1280 error = -EIO;
1284 sb_min_blocksize(sb, 512); 1281 sb_min_blocksize(sb, 512);
1285 bh = sb_bread(sb, 0); 1282 bh = sb_bread(sb, 0);
diff --git a/fs/fat/namei_msdos.c b/fs/fat/namei_msdos.c
index 35ffe43afa4b..711499040eb6 100644
--- a/fs/fat/namei_msdos.c
+++ b/fs/fat/namei_msdos.c
@@ -227,11 +227,7 @@ static struct dentry *msdos_lookup(struct inode *dir, struct dentry *dentry,
227 } 227 }
228out: 228out:
229 unlock_super(sb); 229 unlock_super(sb);
230 d_set_d_op(dentry, &msdos_dentry_operations); 230 return d_splice_alias(inode, dentry);
231 dentry = d_splice_alias(inode, dentry);
232 if (dentry)
233 d_set_d_op(dentry, &msdos_dentry_operations);
234 return dentry;
235 231
236error: 232error:
237 unlock_super(sb); 233 unlock_super(sb);
@@ -661,21 +657,16 @@ static const struct inode_operations msdos_dir_inode_operations = {
661 .getattr = fat_getattr, 657 .getattr = fat_getattr,
662}; 658};
663 659
664static int msdos_fill_super(struct super_block *sb, void *data, int silent) 660static void setup(struct super_block *sb)
665{ 661{
666 int res; 662 sb->s_d_op = &msdos_dentry_operations;
667
668 lock_super(sb);
669 res = fat_fill_super(sb, data, silent, &msdos_dir_inode_operations, 0);
670 if (res) {
671 unlock_super(sb);
672 return res;
673 }
674
675 sb->s_flags |= MS_NOATIME; 663 sb->s_flags |= MS_NOATIME;
676 d_set_d_op(sb->s_root, &msdos_dentry_operations); 664}
677 unlock_super(sb); 665
678 return 0; 666static int msdos_fill_super(struct super_block *sb, void *data, int silent)
667{
668 return fat_fill_super(sb, data, silent, &msdos_dir_inode_operations,
669 0, setup);
679} 670}
680 671
681static struct dentry *msdos_mount(struct file_system_type *fs_type, 672static struct dentry *msdos_mount(struct file_system_type *fs_type,
diff --git a/fs/fat/namei_vfat.c b/fs/fat/namei_vfat.c
index e3ffc5e12332..f88f752babd9 100644
--- a/fs/fat/namei_vfat.c
+++ b/fs/fat/namei_vfat.c
@@ -772,13 +772,10 @@ static struct dentry *vfat_lookup(struct inode *dir, struct dentry *dentry,
772 772
773out: 773out:
774 unlock_super(sb); 774 unlock_super(sb);
775 d_set_d_op(dentry, sb->s_root->d_op);
776 dentry->d_time = dentry->d_parent->d_inode->i_version; 775 dentry->d_time = dentry->d_parent->d_inode->i_version;
777 dentry = d_splice_alias(inode, dentry); 776 dentry = d_splice_alias(inode, dentry);
778 if (dentry) { 777 if (dentry)
779 d_set_d_op(dentry, sb->s_root->d_op);
780 dentry->d_time = dentry->d_parent->d_inode->i_version; 778 dentry->d_time = dentry->d_parent->d_inode->i_version;
781 }
782 return dentry; 779 return dentry;
783 780
784error: 781error:
@@ -1066,24 +1063,18 @@ static const struct inode_operations vfat_dir_inode_operations = {
1066 .getattr = fat_getattr, 1063 .getattr = fat_getattr,
1067}; 1064};
1068 1065
1069static int vfat_fill_super(struct super_block *sb, void *data, int silent) 1066static void setup(struct super_block *sb)
1070{ 1067{
1071 int res;
1072
1073 lock_super(sb);
1074 res = fat_fill_super(sb, data, silent, &vfat_dir_inode_operations, 1);
1075 if (res) {
1076 unlock_super(sb);
1077 return res;
1078 }
1079
1080 if (MSDOS_SB(sb)->options.name_check != 's') 1068 if (MSDOS_SB(sb)->options.name_check != 's')
1081 d_set_d_op(sb->s_root, &vfat_ci_dentry_ops); 1069 sb->s_d_op = &vfat_ci_dentry_ops;
1082 else 1070 else
1083 d_set_d_op(sb->s_root, &vfat_dentry_ops); 1071 sb->s_d_op = &vfat_dentry_ops;
1072}
1084 1073
1085 unlock_super(sb); 1074static int vfat_fill_super(struct super_block *sb, void *data, int silent)
1086 return 0; 1075{
1076 return fat_fill_super(sb, data, silent, &vfat_dir_inode_operations,
1077 1, setup);
1087} 1078}
1088 1079
1089static struct dentry *vfat_mount(struct file_system_type *fs_type, 1080static struct dentry *vfat_mount(struct file_system_type *fs_type,
diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c
index 042af7346ec1..bfed8447ed80 100644
--- a/fs/fuse/dir.c
+++ b/fs/fuse/dir.c
@@ -350,7 +350,6 @@ static struct dentry *fuse_lookup(struct inode *dir, struct dentry *entry,
350 } 350 }
351 351
352 entry = newent ? newent : entry; 352 entry = newent ? newent : entry;
353 d_set_d_op(entry, &fuse_dentry_operations);
354 if (outarg_valid) 353 if (outarg_valid)
355 fuse_change_entry_timeout(entry, &outarg); 354 fuse_change_entry_timeout(entry, &outarg);
356 else 355 else
diff --git a/fs/fuse/inode.c b/fs/fuse/inode.c
index f62b32cffea9..9e3f68cc1bd1 100644
--- a/fs/fuse/inode.c
+++ b/fs/fuse/inode.c
@@ -617,10 +617,8 @@ static struct dentry *fuse_get_dentry(struct super_block *sb,
617 goto out_iput; 617 goto out_iput;
618 618
619 entry = d_obtain_alias(inode); 619 entry = d_obtain_alias(inode);
620 if (!IS_ERR(entry) && get_node_id(inode) != FUSE_ROOT_ID) { 620 if (!IS_ERR(entry) && get_node_id(inode) != FUSE_ROOT_ID)
621 d_set_d_op(entry, &fuse_dentry_operations);
622 fuse_invalidate_entry_cache(entry); 621 fuse_invalidate_entry_cache(entry);
623 }
624 622
625 return entry; 623 return entry;
626 624
@@ -719,10 +717,8 @@ static struct dentry *fuse_get_parent(struct dentry *child)
719 } 717 }
720 718
721 parent = d_obtain_alias(inode); 719 parent = d_obtain_alias(inode);
722 if (!IS_ERR(parent) && get_node_id(inode) != FUSE_ROOT_ID) { 720 if (!IS_ERR(parent) && get_node_id(inode) != FUSE_ROOT_ID)
723 d_set_d_op(parent, &fuse_dentry_operations);
724 fuse_invalidate_entry_cache(parent); 721 fuse_invalidate_entry_cache(parent);
725 }
726 722
727 return parent; 723 return parent;
728} 724}
@@ -989,6 +985,8 @@ static int fuse_fill_super(struct super_block *sb, void *data, int silent)
989 iput(root); 985 iput(root);
990 goto err_put_conn; 986 goto err_put_conn;
991 } 987 }
988 /* only now - we want root dentry with NULL ->d_op */
989 sb->s_d_op = &fuse_dentry_operations;
992 990
993 init_req = fuse_request_alloc(); 991 init_req = fuse_request_alloc();
994 if (!init_req) 992 if (!init_req)
diff --git a/fs/gfs2/export.c b/fs/gfs2/export.c
index 97012ecff560..9023db8184f9 100644
--- a/fs/gfs2/export.c
+++ b/fs/gfs2/export.c
@@ -126,12 +126,7 @@ static int gfs2_get_name(struct dentry *parent, char *name,
126 126
127static struct dentry *gfs2_get_parent(struct dentry *child) 127static struct dentry *gfs2_get_parent(struct dentry *child)
128{ 128{
129 struct dentry *dentry; 129 return d_obtain_alias(gfs2_lookupi(child->d_inode, &gfs2_qdotdot, 1));
130
131 dentry = d_obtain_alias(gfs2_lookupi(child->d_inode, &gfs2_qdotdot, 1));
132 if (!IS_ERR(dentry))
133 d_set_d_op(dentry, &gfs2_dops);
134 return dentry;
135} 130}
136 131
137static struct dentry *gfs2_get_dentry(struct super_block *sb, 132static struct dentry *gfs2_get_dentry(struct super_block *sb,
@@ -139,7 +134,6 @@ static struct dentry *gfs2_get_dentry(struct super_block *sb,
139{ 134{
140 struct gfs2_sbd *sdp = sb->s_fs_info; 135 struct gfs2_sbd *sdp = sb->s_fs_info;
141 struct inode *inode; 136 struct inode *inode;
142 struct dentry *dentry;
143 137
144 inode = gfs2_ilookup(sb, inum->no_addr); 138 inode = gfs2_ilookup(sb, inum->no_addr);
145 if (inode) { 139 if (inode) {
@@ -156,10 +150,7 @@ static struct dentry *gfs2_get_dentry(struct super_block *sb,
156 return ERR_CAST(inode); 150 return ERR_CAST(inode);
157 151
158out_inode: 152out_inode:
159 dentry = d_obtain_alias(inode); 153 return d_obtain_alias(inode);
160 if (!IS_ERR(dentry))
161 d_set_d_op(dentry, &gfs2_dops);
162 return dentry;
163} 154}
164 155
165static struct dentry *gfs2_fh_to_dentry(struct super_block *sb, struct fid *fid, 156static struct dentry *gfs2_fh_to_dentry(struct super_block *sb, struct fid *fid,
diff --git a/fs/gfs2/ops_fstype.c b/fs/gfs2/ops_fstype.c
index 2aeabd4218cc..693f4470a2df 100644
--- a/fs/gfs2/ops_fstype.c
+++ b/fs/gfs2/ops_fstype.c
@@ -440,7 +440,6 @@ static int gfs2_lookup_root(struct super_block *sb, struct dentry **dptr,
440 iput(inode); 440 iput(inode);
441 return -ENOMEM; 441 return -ENOMEM;
442 } 442 }
443 d_set_d_op(dentry, &gfs2_dops);
444 *dptr = dentry; 443 *dptr = dentry;
445 return 0; 444 return 0;
446} 445}
@@ -1106,6 +1105,7 @@ static int fill_super(struct super_block *sb, struct gfs2_args *args, int silent
1106 1105
1107 sb->s_magic = GFS2_MAGIC; 1106 sb->s_magic = GFS2_MAGIC;
1108 sb->s_op = &gfs2_super_ops; 1107 sb->s_op = &gfs2_super_ops;
1108 sb->s_d_op = &gfs2_dops;
1109 sb->s_export_op = &gfs2_export_ops; 1109 sb->s_export_op = &gfs2_export_ops;
1110 sb->s_xattr = gfs2_xattr_handlers; 1110 sb->s_xattr = gfs2_xattr_handlers;
1111 sb->s_qcop = &gfs2_quotactl_ops; 1111 sb->s_qcop = &gfs2_quotactl_ops;
diff --git a/fs/gfs2/ops_inode.c b/fs/gfs2/ops_inode.c
index 1501db4f0e6d..040b5a2e6556 100644
--- a/fs/gfs2/ops_inode.c
+++ b/fs/gfs2/ops_inode.c
@@ -106,8 +106,6 @@ static struct dentry *gfs2_lookup(struct inode *dir, struct dentry *dentry,
106{ 106{
107 struct inode *inode = NULL; 107 struct inode *inode = NULL;
108 108
109 d_set_d_op(dentry, &gfs2_dops);
110
111 inode = gfs2_lookupi(dir, &dentry->d_name, 0); 109 inode = gfs2_lookupi(dir, &dentry->d_name, 0);
112 if (inode && IS_ERR(inode)) 110 if (inode && IS_ERR(inode))
113 return ERR_CAST(inode); 111 return ERR_CAST(inode);
@@ -1427,6 +1425,10 @@ static long gfs2_fallocate(struct inode *inode, int mode, loff_t offset,
1427 loff_t next = (offset + len - 1) >> sdp->sd_sb.sb_bsize_shift; 1425 loff_t next = (offset + len - 1) >> sdp->sd_sb.sb_bsize_shift;
1428 next = (next + 1) << sdp->sd_sb.sb_bsize_shift; 1426 next = (next + 1) << sdp->sd_sb.sb_bsize_shift;
1429 1427
1428 /* We only support the FALLOC_FL_KEEP_SIZE mode */
1429 if (mode && (mode != FALLOC_FL_KEEP_SIZE))
1430 return -EOPNOTSUPP;
1431
1430 offset = (offset >> sdp->sd_sb.sb_bsize_shift) << 1432 offset = (offset >> sdp->sd_sb.sb_bsize_shift) <<
1431 sdp->sd_sb.sb_bsize_shift; 1433 sdp->sd_sb.sb_bsize_shift;
1432 1434
diff --git a/fs/hfs/dir.c b/fs/hfs/dir.c
index ea4aefe7c652..afa66aaa2237 100644
--- a/fs/hfs/dir.c
+++ b/fs/hfs/dir.c
@@ -25,8 +25,6 @@ static struct dentry *hfs_lookup(struct inode *dir, struct dentry *dentry,
25 struct inode *inode = NULL; 25 struct inode *inode = NULL;
26 int res; 26 int res;
27 27
28 d_set_d_op(dentry, &hfs_dentry_operations);
29
30 hfs_find_init(HFS_SB(dir->i_sb)->cat_tree, &fd); 28 hfs_find_init(HFS_SB(dir->i_sb)->cat_tree, &fd);
31 hfs_cat_build_key(dir->i_sb, fd.search_key, dir->i_ino, &dentry->d_name); 29 hfs_cat_build_key(dir->i_sb, fd.search_key, dir->i_ino, &dentry->d_name);
32 res = hfs_brec_read(&fd, &rec, sizeof(rec)); 30 res = hfs_brec_read(&fd, &rec, sizeof(rec));
diff --git a/fs/hfs/super.c b/fs/hfs/super.c
index 0bef62aa4f42..1b55f704fb22 100644
--- a/fs/hfs/super.c
+++ b/fs/hfs/super.c
@@ -429,13 +429,12 @@ static int hfs_fill_super(struct super_block *sb, void *data, int silent)
429 if (!root_inode) 429 if (!root_inode)
430 goto bail_no_root; 430 goto bail_no_root;
431 431
432 sb->s_d_op = &hfs_dentry_operations;
432 res = -ENOMEM; 433 res = -ENOMEM;
433 sb->s_root = d_alloc_root(root_inode); 434 sb->s_root = d_alloc_root(root_inode);
434 if (!sb->s_root) 435 if (!sb->s_root)
435 goto bail_iput; 436 goto bail_iput;
436 437
437 d_set_d_op(sb->s_root, &hfs_dentry_operations);
438
439 /* everything's okay */ 438 /* everything's okay */
440 return 0; 439 return 0;
441 440
diff --git a/fs/hfsplus/dir.c b/fs/hfsplus/dir.c
index f896dc843026..4df5059c25da 100644
--- a/fs/hfsplus/dir.c
+++ b/fs/hfsplus/dir.c
@@ -37,7 +37,6 @@ static struct dentry *hfsplus_lookup(struct inode *dir, struct dentry *dentry,
37 37
38 sb = dir->i_sb; 38 sb = dir->i_sb;
39 39
40 d_set_d_op(dentry, &hfsplus_dentry_operations);
41 dentry->d_fsdata = NULL; 40 dentry->d_fsdata = NULL;
42 hfs_find_init(HFSPLUS_SB(sb)->cat_tree, &fd); 41 hfs_find_init(HFSPLUS_SB(sb)->cat_tree, &fd);
43 hfsplus_cat_build_key(sb, fd.search_key, dir->i_ino, &dentry->d_name); 42 hfsplus_cat_build_key(sb, fd.search_key, dir->i_ino, &dentry->d_name);
diff --git a/fs/hfsplus/super.c b/fs/hfsplus/super.c
index 6ee6ad20acf2..9a3b4795f43c 100644
--- a/fs/hfsplus/super.c
+++ b/fs/hfsplus/super.c
@@ -444,13 +444,13 @@ static int hfsplus_fill_super(struct super_block *sb, void *data, int silent)
444 err = PTR_ERR(root); 444 err = PTR_ERR(root);
445 goto cleanup; 445 goto cleanup;
446 } 446 }
447 sb->s_d_op = &hfsplus_dentry_operations;
447 sb->s_root = d_alloc_root(root); 448 sb->s_root = d_alloc_root(root);
448 if (!sb->s_root) { 449 if (!sb->s_root) {
449 iput(root); 450 iput(root);
450 err = -ENOMEM; 451 err = -ENOMEM;
451 goto cleanup; 452 goto cleanup;
452 } 453 }
453 d_set_d_op(sb->s_root, &hfsplus_dentry_operations);
454 454
455 str.len = sizeof(HFSP_HIDDENDIR_NAME) - 1; 455 str.len = sizeof(HFSP_HIDDENDIR_NAME) - 1;
456 str.name = HFSP_HIDDENDIR_NAME; 456 str.name = HFSP_HIDDENDIR_NAME;
diff --git a/fs/hostfs/hostfs_kern.c b/fs/hostfs/hostfs_kern.c
index d3244d949a4e..2638c834ed28 100644
--- a/fs/hostfs/hostfs_kern.c
+++ b/fs/hostfs/hostfs_kern.c
@@ -612,7 +612,6 @@ struct dentry *hostfs_lookup(struct inode *ino, struct dentry *dentry,
612 goto out_put; 612 goto out_put;
613 613
614 d_add(dentry, inode); 614 d_add(dentry, inode);
615 d_set_d_op(dentry, &hostfs_dentry_ops);
616 return NULL; 615 return NULL;
617 616
618 out_put: 617 out_put:
@@ -922,6 +921,7 @@ static int hostfs_fill_sb_common(struct super_block *sb, void *d, int silent)
922 sb->s_blocksize_bits = 10; 921 sb->s_blocksize_bits = 10;
923 sb->s_magic = HOSTFS_SUPER_MAGIC; 922 sb->s_magic = HOSTFS_SUPER_MAGIC;
924 sb->s_op = &hostfs_sbops; 923 sb->s_op = &hostfs_sbops;
924 sb->s_d_op = &hostfs_dentry_ops;
925 sb->s_maxbytes = MAX_LFS_FILESIZE; 925 sb->s_maxbytes = MAX_LFS_FILESIZE;
926 926
927 /* NULL is printed as <NULL> by sprintf: avoid that. */ 927 /* NULL is printed as <NULL> by sprintf: avoid that. */
diff --git a/fs/hpfs/dentry.c b/fs/hpfs/dentry.c
index 32c13a94e1e9..05d4816e4e77 100644
--- a/fs/hpfs/dentry.c
+++ b/fs/hpfs/dentry.c
@@ -58,12 +58,7 @@ static int hpfs_compare_dentry(const struct dentry *parent,
58 return 0; 58 return 0;
59} 59}
60 60
61static const struct dentry_operations hpfs_dentry_operations = { 61const struct dentry_operations hpfs_dentry_operations = {
62 .d_hash = hpfs_hash_dentry, 62 .d_hash = hpfs_hash_dentry,
63 .d_compare = hpfs_compare_dentry, 63 .d_compare = hpfs_compare_dentry,
64}; 64};
65
66void hpfs_set_dentry_operations(struct dentry *dentry)
67{
68 d_set_d_op(dentry, &hpfs_dentry_operations);
69}
diff --git a/fs/hpfs/dir.c b/fs/hpfs/dir.c
index 2338130cceba..d32f63a569f7 100644
--- a/fs/hpfs/dir.c
+++ b/fs/hpfs/dir.c
@@ -298,7 +298,6 @@ struct dentry *hpfs_lookup(struct inode *dir, struct dentry *dentry, struct name
298 298
299 end: 299 end:
300 end_add: 300 end_add:
301 hpfs_set_dentry_operations(dentry);
302 unlock_kernel(); 301 unlock_kernel();
303 d_add(dentry, result); 302 d_add(dentry, result);
304 return NULL; 303 return NULL;
diff --git a/fs/hpfs/hpfs_fn.h b/fs/hpfs/hpfs_fn.h
index 2fee17d0d9ab..1c43dbea55e8 100644
--- a/fs/hpfs/hpfs_fn.h
+++ b/fs/hpfs/hpfs_fn.h
@@ -233,7 +233,7 @@ void hpfs_mark_4buffers_dirty(struct quad_buffer_head *);
233 233
234/* dentry.c */ 234/* dentry.c */
235 235
236void hpfs_set_dentry_operations(struct dentry *); 236extern const struct dentry_operations hpfs_dentry_operations;
237 237
238/* dir.c */ 238/* dir.c */
239 239
diff --git a/fs/hpfs/super.c b/fs/hpfs/super.c
index 49935ba78db8..b30426b1fc97 100644
--- a/fs/hpfs/super.c
+++ b/fs/hpfs/super.c
@@ -550,6 +550,7 @@ static int hpfs_fill_super(struct super_block *s, void *options, int silent)
550 /* Fill superblock stuff */ 550 /* Fill superblock stuff */
551 s->s_magic = HPFS_SUPER_MAGIC; 551 s->s_magic = HPFS_SUPER_MAGIC;
552 s->s_op = &hpfs_sops; 552 s->s_op = &hpfs_sops;
553 s->s_d_op = &hpfs_dentry_operations;
553 554
554 sbi->sb_root = superblock->root; 555 sbi->sb_root = superblock->root;
555 sbi->sb_fs_size = superblock->n_sectors; 556 sbi->sb_fs_size = superblock->n_sectors;
@@ -651,7 +652,6 @@ static int hpfs_fill_super(struct super_block *s, void *options, int silent)
651 iput(root); 652 iput(root);
652 goto bail0; 653 goto bail0;
653 } 654 }
654 hpfs_set_dentry_operations(s->s_root);
655 655
656 /* 656 /*
657 * find the root directory's . pointer & finish filling in the inode 657 * find the root directory's . pointer & finish filling in the inode
diff --git a/fs/isofs/inode.c b/fs/isofs/inode.c
index 844a7903c72f..a0f3833c0dbf 100644
--- a/fs/isofs/inode.c
+++ b/fs/isofs/inode.c
@@ -939,17 +939,18 @@ root_found:
939 goto out_iput; 939 goto out_iput;
940 } 940 }
941 941
942 /* get the root dentry */
943 s->s_root = d_alloc_root(inode);
944 if (!(s->s_root))
945 goto out_no_root;
946
947 table = 0; 942 table = 0;
948 if (joliet_level) 943 if (joliet_level)
949 table += 2; 944 table += 2;
950 if (opt.check == 'r') 945 if (opt.check == 'r')
951 table++; 946 table++;
952 d_set_d_op(s->s_root, &isofs_dentry_ops[table]); 947
948 s->s_d_op = &isofs_dentry_ops[table];
949
950 /* get the root dentry */
951 s->s_root = d_alloc_root(inode);
952 if (!(s->s_root))
953 goto out_no_root;
953 954
954 kfree(opt.iocharset); 955 kfree(opt.iocharset);
955 956
diff --git a/fs/isofs/namei.c b/fs/isofs/namei.c
index 679a849c3b27..4fb3e8074fd4 100644
--- a/fs/isofs/namei.c
+++ b/fs/isofs/namei.c
@@ -172,8 +172,6 @@ struct dentry *isofs_lookup(struct inode *dir, struct dentry *dentry, struct nam
172 struct inode *inode; 172 struct inode *inode;
173 struct page *page; 173 struct page *page;
174 174
175 d_set_d_op(dentry, dir->i_sb->s_root->d_op);
176
177 page = alloc_page(GFP_USER); 175 page = alloc_page(GFP_USER);
178 if (!page) 176 if (!page)
179 return ERR_PTR(-ENOMEM); 177 return ERR_PTR(-ENOMEM);
diff --git a/fs/jbd/transaction.c b/fs/jbd/transaction.c
index 846a3f314111..5b2e4c30a2a1 100644
--- a/fs/jbd/transaction.c
+++ b/fs/jbd/transaction.c
@@ -207,7 +207,7 @@ repeat_locked:
207 * the committing transaction. Really, we only need to give it 207 * the committing transaction. Really, we only need to give it
208 * committing_transaction->t_outstanding_credits plus "enough" for 208 * committing_transaction->t_outstanding_credits plus "enough" for
209 * the log control blocks. 209 * the log control blocks.
210 * Also, this test is inconsitent with the matching one in 210 * Also, this test is inconsistent with the matching one in
211 * journal_extend(). 211 * journal_extend().
212 */ 212 */
213 if (__log_space_left(journal) < jbd_space_needed(journal)) { 213 if (__log_space_left(journal) < jbd_space_needed(journal)) {
diff --git a/fs/jbd2/transaction.c b/fs/jbd2/transaction.c
index 394893242ae3..faad2bd787c7 100644
--- a/fs/jbd2/transaction.c
+++ b/fs/jbd2/transaction.c
@@ -251,7 +251,7 @@ repeat:
251 * the committing transaction. Really, we only need to give it 251 * the committing transaction. Really, we only need to give it
252 * committing_transaction->t_outstanding_credits plus "enough" for 252 * committing_transaction->t_outstanding_credits plus "enough" for
253 * the log control blocks. 253 * the log control blocks.
254 * Also, this test is inconsitent with the matching one in 254 * Also, this test is inconsistent with the matching one in
255 * jbd2_journal_extend(). 255 * jbd2_journal_extend().
256 */ 256 */
257 if (__jbd2_log_space_left(journal) < jbd_space_needed(journal)) { 257 if (__jbd2_log_space_left(journal) < jbd_space_needed(journal)) {
diff --git a/fs/jfs/namei.c b/fs/jfs/namei.c
index 4414e3a42264..81ead850ddb6 100644
--- a/fs/jfs/namei.c
+++ b/fs/jfs/namei.c
@@ -1465,9 +1465,6 @@ static struct dentry *jfs_lookup(struct inode *dip, struct dentry *dentry, struc
1465 1465
1466 jfs_info("jfs_lookup: name = %s", name); 1466 jfs_info("jfs_lookup: name = %s", name);
1467 1467
1468 if (JFS_SBI(dip->i_sb)->mntflag & JFS_OS2)
1469 d_set_d_op(dentry, &jfs_ci_dentry_operations);
1470
1471 if ((name[0] == '.') && (len == 1)) 1468 if ((name[0] == '.') && (len == 1))
1472 inum = dip->i_ino; 1469 inum = dip->i_ino;
1473 else if (strcmp(name, "..") == 0) 1470 else if (strcmp(name, "..") == 0)
@@ -1492,12 +1489,7 @@ static struct dentry *jfs_lookup(struct inode *dip, struct dentry *dentry, struc
1492 return ERR_CAST(ip); 1489 return ERR_CAST(ip);
1493 } 1490 }
1494 1491
1495 dentry = d_splice_alias(ip, dentry); 1492 return d_splice_alias(ip, dentry);
1496
1497 if (dentry && (JFS_SBI(dip->i_sb)->mntflag & JFS_OS2))
1498 d_set_d_op(dentry, &jfs_ci_dentry_operations);
1499
1500 return dentry;
1501} 1493}
1502 1494
1503static struct inode *jfs_nfs_get_inode(struct super_block *sb, 1495static struct inode *jfs_nfs_get_inode(struct super_block *sb,
diff --git a/fs/jfs/super.c b/fs/jfs/super.c
index 3150d766e0d4..eeca48a031ab 100644
--- a/fs/jfs/super.c
+++ b/fs/jfs/super.c
@@ -515,6 +515,9 @@ static int jfs_fill_super(struct super_block *sb, void *data, int silent)
515 515
516 sb->s_magic = JFS_SUPER_MAGIC; 516 sb->s_magic = JFS_SUPER_MAGIC;
517 517
518 if (sbi->mntflag & JFS_OS2)
519 sb->s_d_op = &jfs_ci_dentry_operations;
520
518 inode = jfs_iget(sb, ROOT_I); 521 inode = jfs_iget(sb, ROOT_I);
519 if (IS_ERR(inode)) { 522 if (IS_ERR(inode)) {
520 ret = PTR_ERR(inode); 523 ret = PTR_ERR(inode);
@@ -524,9 +527,6 @@ static int jfs_fill_super(struct super_block *sb, void *data, int silent)
524 if (!sb->s_root) 527 if (!sb->s_root)
525 goto out_no_root; 528 goto out_no_root;
526 529
527 if (sbi->mntflag & JFS_OS2)
528 d_set_d_op(sb->s_root, &jfs_ci_dentry_operations);
529
530 /* logical blocks are represented by 40 bits in pxd_t, etc. */ 530 /* logical blocks are represented by 40 bits in pxd_t, etc. */
531 sb->s_maxbytes = ((u64) sb->s_blocksize) << 40; 531 sb->s_maxbytes = ((u64) sb->s_blocksize) << 40;
532#if BITS_PER_LONG == 32 532#if BITS_PER_LONG == 32
diff --git a/fs/libfs.c b/fs/libfs.c
index 889311e3d06b..c88eab55aec9 100644
--- a/fs/libfs.c
+++ b/fs/libfs.c
@@ -217,7 +217,8 @@ static const struct super_operations simple_super_operations = {
217 * will never be mountable) 217 * will never be mountable)
218 */ 218 */
219struct dentry *mount_pseudo(struct file_system_type *fs_type, char *name, 219struct dentry *mount_pseudo(struct file_system_type *fs_type, char *name,
220 const struct super_operations *ops, unsigned long magic) 220 const struct super_operations *ops,
221 const struct dentry_operations *dops, unsigned long magic)
221{ 222{
222 struct super_block *s = sget(fs_type, NULL, set_anon_super, NULL); 223 struct super_block *s = sget(fs_type, NULL, set_anon_super, NULL);
223 struct dentry *dentry; 224 struct dentry *dentry;
@@ -254,6 +255,7 @@ struct dentry *mount_pseudo(struct file_system_type *fs_type, char *name,
254 dentry->d_parent = dentry; 255 dentry->d_parent = dentry;
255 d_instantiate(dentry, root); 256 d_instantiate(dentry, root);
256 s->s_root = dentry; 257 s->s_root = dentry;
258 s->s_d_op = dops;
257 s->s_flags |= MS_ACTIVE; 259 s->s_flags |= MS_ACTIVE;
258 return dget(s->s_root); 260 return dget(s->s_root);
259 261
diff --git a/fs/minix/namei.c b/fs/minix/namei.c
index 1b9e07728a9f..ce7337ddfdbf 100644
--- a/fs/minix/namei.c
+++ b/fs/minix/namei.c
@@ -23,8 +23,6 @@ static struct dentry *minix_lookup(struct inode * dir, struct dentry *dentry, st
23 struct inode * inode = NULL; 23 struct inode * inode = NULL;
24 ino_t ino; 24 ino_t ino;
25 25
26 d_set_d_op(dentry, dir->i_sb->s_root->d_op);
27
28 if (dentry->d_name.len > minix_sb(dir->i_sb)->s_namelen) 26 if (dentry->d_name.len > minix_sb(dir->i_sb)->s_namelen)
29 return ERR_PTR(-ENAMETOOLONG); 27 return ERR_PTR(-ENAMETOOLONG);
30 28
diff --git a/fs/namei.c b/fs/namei.c
index 24ece10470b6..0b14f6910fc6 100644
--- a/fs/namei.c
+++ b/fs/namei.c
@@ -1950,8 +1950,9 @@ int may_open(struct path *path, int acc_mode, int flag)
1950 return break_lease(inode, flag); 1950 return break_lease(inode, flag);
1951} 1951}
1952 1952
1953static int handle_truncate(struct path *path) 1953static int handle_truncate(struct file *filp)
1954{ 1954{
1955 struct path *path = &filp->f_path;
1955 struct inode *inode = path->dentry->d_inode; 1956 struct inode *inode = path->dentry->d_inode;
1956 int error = get_write_access(inode); 1957 int error = get_write_access(inode);
1957 if (error) 1958 if (error)
@@ -1965,7 +1966,7 @@ static int handle_truncate(struct path *path)
1965 if (!error) { 1966 if (!error) {
1966 error = do_truncate(path->dentry, 0, 1967 error = do_truncate(path->dentry, 0,
1967 ATTR_MTIME|ATTR_CTIME|ATTR_OPEN, 1968 ATTR_MTIME|ATTR_CTIME|ATTR_OPEN,
1968 NULL); 1969 filp);
1969 } 1970 }
1970 put_write_access(inode); 1971 put_write_access(inode);
1971 return error; 1972 return error;
@@ -2063,7 +2064,7 @@ static struct file *finish_open(struct nameidata *nd,
2063 } 2064 }
2064 if (!IS_ERR(filp)) { 2065 if (!IS_ERR(filp)) {
2065 if (will_truncate) { 2066 if (will_truncate) {
2066 error = handle_truncate(&nd->path); 2067 error = handle_truncate(filp);
2067 if (error) { 2068 if (error) {
2068 fput(filp); 2069 fput(filp);
2069 filp = ERR_PTR(error); 2070 filp = ERR_PTR(error);
diff --git a/fs/ncpfs/dir.c b/fs/ncpfs/dir.c
index 28f136d4aaec..f6946bb5cb55 100644
--- a/fs/ncpfs/dir.c
+++ b/fs/ncpfs/dir.c
@@ -21,9 +21,7 @@
21#include <asm/uaccess.h> 21#include <asm/uaccess.h>
22#include <asm/byteorder.h> 22#include <asm/byteorder.h>
23 23
24#include <linux/ncp_fs.h> 24#include "ncp_fs.h"
25
26#include "ncplib_kernel.h"
27 25
28static void ncp_read_volume_list(struct file *, void *, filldir_t, 26static void ncp_read_volume_list(struct file *, void *, filldir_t,
29 struct ncp_cache_control *); 27 struct ncp_cache_control *);
@@ -82,7 +80,7 @@ static int ncp_compare_dentry(const struct dentry *, const struct inode *,
82 unsigned int, const char *, const struct qstr *); 80 unsigned int, const char *, const struct qstr *);
83static int ncp_delete_dentry(const struct dentry *); 81static int ncp_delete_dentry(const struct dentry *);
84 82
85static const struct dentry_operations ncp_dentry_operations = 83const struct dentry_operations ncp_dentry_operations =
86{ 84{
87 .d_revalidate = ncp_lookup_validate, 85 .d_revalidate = ncp_lookup_validate,
88 .d_hash = ncp_hash_dentry, 86 .d_hash = ncp_hash_dentry,
@@ -90,14 +88,6 @@ static const struct dentry_operations ncp_dentry_operations =
90 .d_delete = ncp_delete_dentry, 88 .d_delete = ncp_delete_dentry,
91}; 89};
92 90
93const struct dentry_operations ncp_root_dentry_operations =
94{
95 .d_hash = ncp_hash_dentry,
96 .d_compare = ncp_compare_dentry,
97 .d_delete = ncp_delete_dentry,
98};
99
100
101#define ncp_namespace(i) (NCP_SERVER(i)->name_space[NCP_FINFO(i)->volNumber]) 91#define ncp_namespace(i) (NCP_SERVER(i)->name_space[NCP_FINFO(i)->volNumber])
102 92
103static inline int ncp_preserve_entry_case(struct inode *i, __u32 nscreator) 93static inline int ncp_preserve_entry_case(struct inode *i, __u32 nscreator)
@@ -309,6 +299,9 @@ ncp_lookup_validate(struct dentry *dentry, struct nameidata *nd)
309 int res, val = 0, len; 299 int res, val = 0, len;
310 __u8 __name[NCP_MAXPATHLEN + 1]; 300 __u8 __name[NCP_MAXPATHLEN + 1];
311 301
302 if (dentry == dentry->d_sb->s_root)
303 return 1;
304
312 if (nd->flags & LOOKUP_RCU) 305 if (nd->flags & LOOKUP_RCU)
313 return -ECHILD; 306 return -ECHILD;
314 307
@@ -637,7 +630,6 @@ ncp_fill_cache(struct file *filp, void *dirent, filldir_t filldir,
637 entry->ino = iunique(dir->i_sb, 2); 630 entry->ino = iunique(dir->i_sb, 2);
638 inode = ncp_iget(dir->i_sb, entry); 631 inode = ncp_iget(dir->i_sb, entry);
639 if (inode) { 632 if (inode) {
640 d_set_d_op(newdent, &ncp_dentry_operations);
641 d_instantiate(newdent, inode); 633 d_instantiate(newdent, inode);
642 if (!hashed) 634 if (!hashed)
643 d_rehash(newdent); 635 d_rehash(newdent);
@@ -893,7 +885,6 @@ static struct dentry *ncp_lookup(struct inode *dir, struct dentry *dentry, struc
893 if (inode) { 885 if (inode) {
894 ncp_new_dentry(dentry); 886 ncp_new_dentry(dentry);
895add_entry: 887add_entry:
896 d_set_d_op(dentry, &ncp_dentry_operations);
897 d_add(dentry, inode); 888 d_add(dentry, inode);
898 error = 0; 889 error = 0;
899 } 890 }
diff --git a/fs/ncpfs/file.c b/fs/ncpfs/file.c
index cb50aaf981df..0ed65e0c3dfe 100644
--- a/fs/ncpfs/file.c
+++ b/fs/ncpfs/file.c
@@ -18,8 +18,7 @@
18#include <linux/vmalloc.h> 18#include <linux/vmalloc.h>
19#include <linux/sched.h> 19#include <linux/sched.h>
20 20
21#include <linux/ncp_fs.h> 21#include "ncp_fs.h"
22#include "ncplib_kernel.h"
23 22
24static int ncp_fsync(struct file *file, int datasync) 23static int ncp_fsync(struct file *file, int datasync)
25{ 24{
diff --git a/fs/ncpfs/inode.c b/fs/ncpfs/inode.c
index 9b39a5dd4131..00a1d1c3d3a4 100644
--- a/fs/ncpfs/inode.c
+++ b/fs/ncpfs/inode.c
@@ -31,11 +31,9 @@
31#include <linux/seq_file.h> 31#include <linux/seq_file.h>
32#include <linux/namei.h> 32#include <linux/namei.h>
33 33
34#include <linux/ncp_fs.h>
35
36#include <net/sock.h> 34#include <net/sock.h>
37 35
38#include "ncplib_kernel.h" 36#include "ncp_fs.h"
39#include "getopt.h" 37#include "getopt.h"
40 38
41#define NCP_DEFAULT_FILE_MODE 0600 39#define NCP_DEFAULT_FILE_MODE 0600
@@ -544,6 +542,7 @@ static int ncp_fill_super(struct super_block *sb, void *raw_data, int silent)
544 sb->s_blocksize_bits = 10; 542 sb->s_blocksize_bits = 10;
545 sb->s_magic = NCP_SUPER_MAGIC; 543 sb->s_magic = NCP_SUPER_MAGIC;
546 sb->s_op = &ncp_sops; 544 sb->s_op = &ncp_sops;
545 sb->s_d_op = &ncp_dentry_operations;
547 sb->s_bdi = &server->bdi; 546 sb->s_bdi = &server->bdi;
548 547
549 server = NCP_SBP(sb); 548 server = NCP_SBP(sb);
@@ -723,7 +722,6 @@ static int ncp_fill_super(struct super_block *sb, void *raw_data, int silent)
723 sb->s_root = d_alloc_root(root_inode); 722 sb->s_root = d_alloc_root(root_inode);
724 if (!sb->s_root) 723 if (!sb->s_root)
725 goto out_no_root; 724 goto out_no_root;
726 d_set_d_op(sb->s_root, &ncp_root_dentry_operations);
727 return 0; 725 return 0;
728 726
729out_no_root: 727out_no_root:
diff --git a/fs/ncpfs/ioctl.c b/fs/ncpfs/ioctl.c
index d40a547e3377..790e92a9ec63 100644
--- a/fs/ncpfs/ioctl.c
+++ b/fs/ncpfs/ioctl.c
@@ -20,11 +20,9 @@
20#include <linux/vmalloc.h> 20#include <linux/vmalloc.h>
21#include <linux/sched.h> 21#include <linux/sched.h>
22 22
23#include <linux/ncp_fs.h>
24
25#include <asm/uaccess.h> 23#include <asm/uaccess.h>
26 24
27#include "ncplib_kernel.h" 25#include "ncp_fs.h"
28 26
29/* maximum limit for ncp_objectname_ioctl */ 27/* maximum limit for ncp_objectname_ioctl */
30#define NCP_OBJECT_NAME_MAX_LEN 4096 28#define NCP_OBJECT_NAME_MAX_LEN 4096
diff --git a/fs/ncpfs/mmap.c b/fs/ncpfs/mmap.c
index 56f5b3a0e1ee..a7c07b44b100 100644
--- a/fs/ncpfs/mmap.c
+++ b/fs/ncpfs/mmap.c
@@ -16,12 +16,12 @@
16#include <linux/mman.h> 16#include <linux/mman.h>
17#include <linux/string.h> 17#include <linux/string.h>
18#include <linux/fcntl.h> 18#include <linux/fcntl.h>
19#include <linux/ncp_fs.h>
20 19
21#include "ncplib_kernel.h"
22#include <asm/uaccess.h> 20#include <asm/uaccess.h>
23#include <asm/system.h> 21#include <asm/system.h>
24 22
23#include "ncp_fs.h"
24
25/* 25/*
26 * Fill in the supplied page for mmap 26 * Fill in the supplied page for mmap
27 * XXX: how are we excluding truncate/invalidate here? Maybe need to lock 27 * XXX: how are we excluding truncate/invalidate here? Maybe need to lock
diff --git a/fs/ncpfs/ncp_fs.h b/fs/ncpfs/ncp_fs.h
new file mode 100644
index 000000000000..31831afe1c3b
--- /dev/null
+++ b/fs/ncpfs/ncp_fs.h
@@ -0,0 +1,98 @@
1#include <linux/ncp_fs.h>
2#include "ncp_fs_i.h"
3#include "ncp_fs_sb.h"
4
5/* define because it is easy to change PRINTK to {*}PRINTK */
6#define PRINTK(format, args...) printk(KERN_DEBUG format , ## args)
7
8#undef NCPFS_PARANOIA
9#ifdef NCPFS_PARANOIA
10#define PPRINTK(format, args...) PRINTK(format , ## args)
11#else
12#define PPRINTK(format, args...)
13#endif
14
15#ifndef DEBUG_NCP
16#define DEBUG_NCP 0
17#endif
18#if DEBUG_NCP > 0
19#define DPRINTK(format, args...) PRINTK(format , ## args)
20#else
21#define DPRINTK(format, args...)
22#endif
23#if DEBUG_NCP > 1
24#define DDPRINTK(format, args...) PRINTK(format , ## args)
25#else
26#define DDPRINTK(format, args...)
27#endif
28
29#define NCP_MAX_RPC_TIMEOUT (6*HZ)
30
31
32struct ncp_entry_info {
33 struct nw_info_struct i;
34 ino_t ino;
35 int opened;
36 int access;
37 unsigned int volume;
38 __u8 file_handle[6];
39};
40
41static inline struct ncp_server *NCP_SBP(const struct super_block *sb)
42{
43 return sb->s_fs_info;
44}
45
46#define NCP_SERVER(inode) NCP_SBP((inode)->i_sb)
47static inline struct ncp_inode_info *NCP_FINFO(const struct inode *inode)
48{
49 return container_of(inode, struct ncp_inode_info, vfs_inode);
50}
51
52/* linux/fs/ncpfs/inode.c */
53int ncp_notify_change(struct dentry *, struct iattr *);
54struct inode *ncp_iget(struct super_block *, struct ncp_entry_info *);
55void ncp_update_inode(struct inode *, struct ncp_entry_info *);
56void ncp_update_inode2(struct inode *, struct ncp_entry_info *);
57
58/* linux/fs/ncpfs/dir.c */
59extern const struct inode_operations ncp_dir_inode_operations;
60extern const struct file_operations ncp_dir_operations;
61extern const struct dentry_operations ncp_dentry_operations;
62int ncp_conn_logged_in(struct super_block *);
63int ncp_date_dos2unix(__le16 time, __le16 date);
64void ncp_date_unix2dos(int unix_date, __le16 * time, __le16 * date);
65
66/* linux/fs/ncpfs/ioctl.c */
67long ncp_ioctl(struct file *, unsigned int, unsigned long);
68long ncp_compat_ioctl(struct file *, unsigned int, unsigned long);
69
70/* linux/fs/ncpfs/sock.c */
71int ncp_request2(struct ncp_server *server, int function,
72 void* reply, int max_reply_size);
73static inline int ncp_request(struct ncp_server *server, int function) {
74 return ncp_request2(server, function, server->packet, server->packet_size);
75}
76int ncp_connect(struct ncp_server *server);
77int ncp_disconnect(struct ncp_server *server);
78void ncp_lock_server(struct ncp_server *server);
79void ncp_unlock_server(struct ncp_server *server);
80
81/* linux/fs/ncpfs/symlink.c */
82#if defined(CONFIG_NCPFS_EXTRAS) || defined(CONFIG_NCPFS_NFS_NS)
83extern const struct address_space_operations ncp_symlink_aops;
84int ncp_symlink(struct inode*, struct dentry*, const char*);
85#endif
86
87/* linux/fs/ncpfs/file.c */
88extern const struct inode_operations ncp_file_inode_operations;
89extern const struct file_operations ncp_file_operations;
90int ncp_make_open(struct inode *, int);
91
92/* linux/fs/ncpfs/mmap.c */
93int ncp_mmap(struct file *, struct vm_area_struct *);
94
95/* linux/fs/ncpfs/ncplib_kernel.c */
96int ncp_make_closed(struct inode *);
97
98#include "ncplib_kernel.h"
diff --git a/include/linux/ncp_fs_i.h b/fs/ncpfs/ncp_fs_i.h
index 4b0bec477846..4b0bec477846 100644
--- a/include/linux/ncp_fs_i.h
+++ b/fs/ncpfs/ncp_fs_i.h
diff --git a/include/linux/ncp_fs_sb.h b/fs/ncpfs/ncp_fs_sb.h
index d64b0e894336..4af803f13516 100644
--- a/include/linux/ncp_fs_sb.h
+++ b/fs/ncpfs/ncp_fs_sb.h
@@ -13,15 +13,30 @@
13#include <linux/net.h> 13#include <linux/net.h>
14#include <linux/mutex.h> 14#include <linux/mutex.h>
15#include <linux/backing-dev.h> 15#include <linux/backing-dev.h>
16
17#ifdef __KERNEL__
18
19#include <linux/workqueue.h> 16#include <linux/workqueue.h>
20 17
21#define NCP_DEFAULT_OPTIONS 0 /* 2 for packet signatures */ 18#define NCP_DEFAULT_OPTIONS 0 /* 2 for packet signatures */
22 19
23struct sock; 20struct sock;
24 21
22struct ncp_mount_data_kernel {
23 unsigned long flags; /* NCP_MOUNT_* flags */
24 unsigned int int_flags; /* internal flags */
25#define NCP_IMOUNT_LOGGEDIN_POSSIBLE 0x0001
26 __kernel_uid32_t mounted_uid; /* Who may umount() this filesystem? */
27 struct pid *wdog_pid; /* Who cares for our watchdog packets? */
28 unsigned int ncp_fd; /* The socket to the ncp port */
29 unsigned int time_out; /* How long should I wait after
30 sending a NCP request? */
31 unsigned int retry_count; /* And how often should I retry? */
32 unsigned char mounted_vol[NCP_VOLNAME_LEN + 1];
33 __kernel_uid32_t uid;
34 __kernel_gid32_t gid;
35 __kernel_mode_t file_mode;
36 __kernel_mode_t dir_mode;
37 int info_fd;
38};
39
25struct ncp_server { 40struct ncp_server {
26 41
27 struct ncp_mount_data_kernel m; /* Nearly all of the mount data is of 42 struct ncp_mount_data_kernel m; /* Nearly all of the mount data is of
@@ -158,7 +173,4 @@ static inline void ncp_invalidate_conn(struct ncp_server *server)
158 server->conn_status |= 0x01; 173 server->conn_status |= 0x01;
159} 174}
160 175
161#endif /* __KERNEL__ */
162
163#endif 176#endif
164
diff --git a/fs/ncpfs/ncplib_kernel.c b/fs/ncpfs/ncplib_kernel.c
index a95615a0b6ac..981a95617fc9 100644
--- a/fs/ncpfs/ncplib_kernel.c
+++ b/fs/ncpfs/ncplib_kernel.c
@@ -11,7 +11,7 @@
11 11
12 12
13 13
14#include "ncplib_kernel.h" 14#include "ncp_fs.h"
15 15
16static inline void assert_server_locked(struct ncp_server *server) 16static inline void assert_server_locked(struct ncp_server *server)
17{ 17{
diff --git a/fs/ncpfs/ncplib_kernel.h b/fs/ncpfs/ncplib_kernel.h
index 1220df75ff22..09881e6aa5ad 100644
--- a/fs/ncpfs/ncplib_kernel.h
+++ b/fs/ncpfs/ncplib_kernel.h
@@ -32,8 +32,6 @@
32#include <linux/ctype.h> 32#include <linux/ctype.h>
33#endif /* CONFIG_NCPFS_NLS */ 33#endif /* CONFIG_NCPFS_NLS */
34 34
35#include <linux/ncp_fs.h>
36
37#define NCP_MIN_SYMLINK_SIZE 8 35#define NCP_MIN_SYMLINK_SIZE 8
38#define NCP_MAX_SYMLINK_SIZE 512 36#define NCP_MAX_SYMLINK_SIZE 512
39 37
diff --git a/fs/ncpfs/ncpsign_kernel.c b/fs/ncpfs/ncpsign_kernel.c
index d8b2d7e6910b..08907599dcd2 100644
--- a/fs/ncpfs/ncpsign_kernel.c
+++ b/fs/ncpfs/ncpsign_kernel.c
@@ -11,6 +11,7 @@
11#include <linux/string.h> 11#include <linux/string.h>
12#include <linux/ncp.h> 12#include <linux/ncp.h>
13#include <linux/bitops.h> 13#include <linux/bitops.h>
14#include "ncp_fs.h"
14#include "ncpsign_kernel.h" 15#include "ncpsign_kernel.h"
15 16
16/* i386: 32-bit, little endian, handles mis-alignment */ 17/* i386: 32-bit, little endian, handles mis-alignment */
diff --git a/fs/ncpfs/ncpsign_kernel.h b/fs/ncpfs/ncpsign_kernel.h
index 6451a68381cc..d9a1438bb1f6 100644
--- a/fs/ncpfs/ncpsign_kernel.h
+++ b/fs/ncpfs/ncpsign_kernel.h
@@ -8,8 +8,6 @@
8#ifndef _NCPSIGN_KERNEL_H 8#ifndef _NCPSIGN_KERNEL_H
9#define _NCPSIGN_KERNEL_H 9#define _NCPSIGN_KERNEL_H
10 10
11#include <linux/ncp_fs.h>
12
13#ifdef CONFIG_NCPFS_PACKET_SIGNING 11#ifdef CONFIG_NCPFS_PACKET_SIGNING
14void __sign_packet(struct ncp_server *server, const char *data, size_t size, __u32 totalsize, void *sign_buff); 12void __sign_packet(struct ncp_server *server, const char *data, size_t size, __u32 totalsize, void *sign_buff);
15int sign_verify_reply(struct ncp_server *server, const char *data, size_t size, __u32 totalsize, const void *sign_buff); 13int sign_verify_reply(struct ncp_server *server, const char *data, size_t size, __u32 totalsize, const void *sign_buff);
diff --git a/fs/ncpfs/sock.c b/fs/ncpfs/sock.c
index 668bd267346e..3a1587222c8a 100644
--- a/fs/ncpfs/sock.c
+++ b/fs/ncpfs/sock.c
@@ -28,7 +28,7 @@
28#include <linux/poll.h> 28#include <linux/poll.h>
29#include <linux/file.h> 29#include <linux/file.h>
30 30
31#include <linux/ncp_fs.h> 31#include "ncp_fs.h"
32 32
33#include "ncpsign_kernel.h" 33#include "ncpsign_kernel.h"
34 34
diff --git a/fs/ncpfs/symlink.c b/fs/ncpfs/symlink.c
index c634fd17b337..661f861d80c6 100644
--- a/fs/ncpfs/symlink.c
+++ b/fs/ncpfs/symlink.c
@@ -25,13 +25,11 @@
25 25
26#include <linux/errno.h> 26#include <linux/errno.h>
27#include <linux/fs.h> 27#include <linux/fs.h>
28#include <linux/ncp_fs.h>
29#include <linux/time.h> 28#include <linux/time.h>
30#include <linux/slab.h> 29#include <linux/slab.h>
31#include <linux/mm.h> 30#include <linux/mm.h>
32#include <linux/stat.h> 31#include <linux/stat.h>
33#include "ncplib_kernel.h" 32#include "ncp_fs.h"
34
35 33
36/* these magic numbers must appear in the symlink file -- this makes it a bit 34/* these magic numbers must appear in the symlink file -- this makes it a bit
37 more resilient against the magic attributes being set on random files. */ 35 more resilient against the magic attributes being set on random files. */
diff --git a/fs/nfs/dir.c b/fs/nfs/dir.c
index abe4f0c8dc5f..95b081bc9e25 100644
--- a/fs/nfs/dir.c
+++ b/fs/nfs/dir.c
@@ -439,7 +439,6 @@ void nfs_prime_dcache(struct dentry *parent, struct nfs_entry *entry)
439 if (dentry == NULL) 439 if (dentry == NULL)
440 return; 440 return;
441 441
442 d_set_d_op(dentry, NFS_PROTO(dir)->dentry_ops);
443 inode = nfs_fhget(dentry->d_sb, entry->fh, entry->fattr); 442 inode = nfs_fhget(dentry->d_sb, entry->fh, entry->fattr);
444 if (IS_ERR(inode)) 443 if (IS_ERR(inode))
445 goto out; 444 goto out;
@@ -1193,8 +1192,6 @@ static struct dentry *nfs_lookup(struct inode *dir, struct dentry * dentry, stru
1193 if (dentry->d_name.len > NFS_SERVER(dir)->namelen) 1192 if (dentry->d_name.len > NFS_SERVER(dir)->namelen)
1194 goto out; 1193 goto out;
1195 1194
1196 d_set_d_op(dentry, NFS_PROTO(dir)->dentry_ops);
1197
1198 /* 1195 /*
1199 * If we're doing an exclusive create, optimize away the lookup 1196 * If we're doing an exclusive create, optimize away the lookup
1200 * but don't hash the dentry. 1197 * but don't hash the dentry.
@@ -1338,7 +1335,6 @@ static struct dentry *nfs_atomic_lookup(struct inode *dir, struct dentry *dentry
1338 res = ERR_PTR(-ENAMETOOLONG); 1335 res = ERR_PTR(-ENAMETOOLONG);
1339 goto out; 1336 goto out;
1340 } 1337 }
1341 d_set_d_op(dentry, NFS_PROTO(dir)->dentry_ops);
1342 1338
1343 /* Let vfs_create() deal with O_EXCL. Instantiate, but don't hash 1339 /* Let vfs_create() deal with O_EXCL. Instantiate, but don't hash
1344 * the dentry. */ 1340 * the dentry. */
diff --git a/fs/nfs/getroot.c b/fs/nfs/getroot.c
index 5596c6a2881e..b5ffe8fa291f 100644
--- a/fs/nfs/getroot.c
+++ b/fs/nfs/getroot.c
@@ -119,9 +119,6 @@ struct dentry *nfs_get_root(struct super_block *sb, struct nfs_fh *mntfh)
119 } 119 }
120 120
121 security_d_instantiate(ret, inode); 121 security_d_instantiate(ret, inode);
122
123 if (ret->d_op == NULL)
124 d_set_d_op(ret, server->nfs_client->rpc_ops->dentry_ops);
125out: 122out:
126 nfs_free_fattr(fsinfo.fattr); 123 nfs_free_fattr(fsinfo.fattr);
127 return ret; 124 return ret;
@@ -227,9 +224,6 @@ struct dentry *nfs4_get_root(struct super_block *sb, struct nfs_fh *mntfh)
227 224
228 security_d_instantiate(ret, inode); 225 security_d_instantiate(ret, inode);
229 226
230 if (ret->d_op == NULL)
231 d_set_d_op(ret, server->nfs_client->rpc_ops->dentry_ops);
232
233out: 227out:
234 nfs_free_fattr(fattr); 228 nfs_free_fattr(fattr);
235 dprintk("<-- nfs4_get_root()\n"); 229 dprintk("<-- nfs4_get_root()\n");
diff --git a/fs/nfs/super.c b/fs/nfs/super.c
index 0f9ea73e7789..b68c8607770f 100644
--- a/fs/nfs/super.c
+++ b/fs/nfs/super.c
@@ -2202,6 +2202,7 @@ static int nfs_set_super(struct super_block *s, void *data)
2202 2202
2203 s->s_flags = sb_mntdata->mntflags; 2203 s->s_flags = sb_mntdata->mntflags;
2204 s->s_fs_info = server; 2204 s->s_fs_info = server;
2205 s->s_d_op = server->nfs_client->rpc_ops->dentry_ops;
2205 ret = set_anon_super(s, server); 2206 ret = set_anon_super(s, server);
2206 if (ret == 0) 2207 if (ret == 0)
2207 server->s_dev = s->s_dev; 2208 server->s_dev = s->s_dev;
diff --git a/fs/notify/fanotify/Kconfig b/fs/notify/fanotify/Kconfig
index 3ac36b7bf6b9..7dceff005a67 100644
--- a/fs/notify/fanotify/Kconfig
+++ b/fs/notify/fanotify/Kconfig
@@ -6,7 +6,7 @@ config FANOTIFY
6 ---help--- 6 ---help---
7 Say Y here to enable fanotify suport. fanotify is a file access 7 Say Y here to enable fanotify suport. fanotify is a file access
8 notification system which differs from inotify in that it sends 8 notification system which differs from inotify in that it sends
9 and open file descriptor to the userspace listener along with 9 an open file descriptor to the userspace listener along with
10 the event. 10 the event.
11 11
12 If unsure, say Y. 12 If unsure, say Y.
diff --git a/fs/ocfs2/export.c b/fs/ocfs2/export.c
index 6adafa576065..5dbc3062b4fd 100644
--- a/fs/ocfs2/export.c
+++ b/fs/ocfs2/export.c
@@ -137,9 +137,7 @@ check_gen:
137 } 137 }
138 138
139 result = d_obtain_alias(inode); 139 result = d_obtain_alias(inode);
140 if (!IS_ERR(result)) 140 if (IS_ERR(result))
141 d_set_d_op(result, &ocfs2_dentry_ops);
142 else
143 mlog_errno(PTR_ERR(result)); 141 mlog_errno(PTR_ERR(result));
144 142
145bail: 143bail:
@@ -175,8 +173,6 @@ static struct dentry *ocfs2_get_parent(struct dentry *child)
175 } 173 }
176 174
177 parent = d_obtain_alias(ocfs2_iget(OCFS2_SB(dir->i_sb), blkno, 0, 0)); 175 parent = d_obtain_alias(ocfs2_iget(OCFS2_SB(dir->i_sb), blkno, 0, 0));
178 if (!IS_ERR(parent))
179 d_set_d_op(parent, &ocfs2_dentry_ops);
180 176
181bail_unlock: 177bail_unlock:
182 ocfs2_inode_unlock(dir, 0); 178 ocfs2_inode_unlock(dir, 0);
diff --git a/fs/ocfs2/file.c b/fs/ocfs2/file.c
index bdadbae09094..63e3fca266e0 100644
--- a/fs/ocfs2/file.c
+++ b/fs/ocfs2/file.c
@@ -1995,6 +1995,7 @@ static long ocfs2_fallocate(struct inode *inode, int mode, loff_t offset,
1995 struct ocfs2_super *osb = OCFS2_SB(inode->i_sb); 1995 struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
1996 struct ocfs2_space_resv sr; 1996 struct ocfs2_space_resv sr;
1997 int change_size = 1; 1997 int change_size = 1;
1998 int cmd = OCFS2_IOC_RESVSP64;
1998 1999
1999 if (!ocfs2_writes_unwritten_extents(osb)) 2000 if (!ocfs2_writes_unwritten_extents(osb))
2000 return -EOPNOTSUPP; 2001 return -EOPNOTSUPP;
@@ -2005,12 +2006,15 @@ static long ocfs2_fallocate(struct inode *inode, int mode, loff_t offset,
2005 if (mode & FALLOC_FL_KEEP_SIZE) 2006 if (mode & FALLOC_FL_KEEP_SIZE)
2006 change_size = 0; 2007 change_size = 0;
2007 2008
2009 if (mode & FALLOC_FL_PUNCH_HOLE)
2010 cmd = OCFS2_IOC_UNRESVSP64;
2011
2008 sr.l_whence = 0; 2012 sr.l_whence = 0;
2009 sr.l_start = (s64)offset; 2013 sr.l_start = (s64)offset;
2010 sr.l_len = (s64)len; 2014 sr.l_len = (s64)len;
2011 2015
2012 return __ocfs2_change_file_space(NULL, inode, offset, 2016 return __ocfs2_change_file_space(NULL, inode, offset, cmd, &sr,
2013 OCFS2_IOC_RESVSP64, &sr, change_size); 2017 change_size);
2014} 2018}
2015 2019
2016int ocfs2_check_range_for_refcount(struct inode *inode, loff_t pos, 2020int ocfs2_check_range_for_refcount(struct inode *inode, loff_t pos,
diff --git a/fs/ocfs2/inode.c b/fs/ocfs2/inode.c
index f935fd6600dd..4068c6c4c6f6 100644
--- a/fs/ocfs2/inode.c
+++ b/fs/ocfs2/inode.c
@@ -434,7 +434,7 @@ static int ocfs2_read_locked_inode(struct inode *inode,
434 * #1 and #2 can be simply solved by never taking the lock 434 * #1 and #2 can be simply solved by never taking the lock
435 * here for system files (which are the only type we read 435 * here for system files (which are the only type we read
436 * during mount). It's a heavier approach, but our main 436 * during mount). It's a heavier approach, but our main
437 * concern is user-accesible files anyway. 437 * concern is user-accessible files anyway.
438 * 438 *
439 * #3 works itself out because we'll eventually take the 439 * #3 works itself out because we'll eventually take the
440 * cluster lock before trusting anything anyway. 440 * cluster lock before trusting anything anyway.
diff --git a/fs/ocfs2/namei.c b/fs/ocfs2/namei.c
index 30c523144452..849fb4a2e814 100644
--- a/fs/ocfs2/namei.c
+++ b/fs/ocfs2/namei.c
@@ -147,7 +147,6 @@ static struct dentry *ocfs2_lookup(struct inode *dir, struct dentry *dentry,
147 spin_unlock(&oi->ip_lock); 147 spin_unlock(&oi->ip_lock);
148 148
149bail_add: 149bail_add:
150 d_set_d_op(dentry, &ocfs2_dentry_ops);
151 ret = d_splice_alias(inode, dentry); 150 ret = d_splice_alias(inode, dentry);
152 151
153 if (inode) { 152 if (inode) {
@@ -415,7 +414,6 @@ static int ocfs2_mknod(struct inode *dir,
415 mlog_errno(status); 414 mlog_errno(status);
416 goto leave; 415 goto leave;
417 } 416 }
418 d_set_d_op(dentry, &ocfs2_dentry_ops);
419 417
420 status = ocfs2_add_entry(handle, dentry, inode, 418 status = ocfs2_add_entry(handle, dentry, inode,
421 OCFS2_I(inode)->ip_blkno, parent_fe_bh, 419 OCFS2_I(inode)->ip_blkno, parent_fe_bh,
@@ -743,7 +741,6 @@ static int ocfs2_link(struct dentry *old_dentry,
743 } 741 }
744 742
745 ihold(inode); 743 ihold(inode);
746 d_set_d_op(dentry, &ocfs2_dentry_ops);
747 d_instantiate(dentry, inode); 744 d_instantiate(dentry, inode);
748 745
749out_commit: 746out_commit:
@@ -1797,7 +1794,6 @@ static int ocfs2_symlink(struct inode *dir,
1797 mlog_errno(status); 1794 mlog_errno(status);
1798 goto bail; 1795 goto bail;
1799 } 1796 }
1800 d_set_d_op(dentry, &ocfs2_dentry_ops);
1801 1797
1802 status = ocfs2_add_entry(handle, dentry, inode, 1798 status = ocfs2_add_entry(handle, dentry, inode,
1803 le64_to_cpu(fe->i_blkno), parent_fe_bh, 1799 le64_to_cpu(fe->i_blkno), parent_fe_bh,
@@ -2462,7 +2458,6 @@ int ocfs2_mv_orphaned_inode_to_new(struct inode *dir,
2462 goto out_commit; 2458 goto out_commit;
2463 } 2459 }
2464 2460
2465 d_set_d_op(dentry, &ocfs2_dentry_ops);
2466 d_instantiate(dentry, inode); 2461 d_instantiate(dentry, inode);
2467 status = 0; 2462 status = 0;
2468out_commit: 2463out_commit:
diff --git a/fs/ocfs2/suballoc.c b/fs/ocfs2/suballoc.c
index 5fed60de7630..71998d4d61d5 100644
--- a/fs/ocfs2/suballoc.c
+++ b/fs/ocfs2/suballoc.c
@@ -1916,7 +1916,7 @@ static int ocfs2_claim_suballoc_bits(struct ocfs2_alloc_context *ac,
1916 if (res->sr_bg_blkno) { 1916 if (res->sr_bg_blkno) {
1917 /* Attempt to short-circuit the usual search mechanism 1917 /* Attempt to short-circuit the usual search mechanism
1918 * by jumping straight to the most recently used 1918 * by jumping straight to the most recently used
1919 * allocation group. This helps us mantain some 1919 * allocation group. This helps us maintain some
1920 * contiguousness across allocations. */ 1920 * contiguousness across allocations. */
1921 status = ocfs2_search_one_group(ac, handle, bits_wanted, 1921 status = ocfs2_search_one_group(ac, handle, bits_wanted,
1922 min_bits, res, &bits_left); 1922 min_bits, res, &bits_left);
diff --git a/fs/ocfs2/super.c b/fs/ocfs2/super.c
index 17ff46fa8a10..06d1f749ca89 100644
--- a/fs/ocfs2/super.c
+++ b/fs/ocfs2/super.c
@@ -2097,6 +2097,7 @@ static int ocfs2_initialize_super(struct super_block *sb,
2097 2097
2098 sb->s_fs_info = osb; 2098 sb->s_fs_info = osb;
2099 sb->s_op = &ocfs2_sops; 2099 sb->s_op = &ocfs2_sops;
2100 sb->s_d_op = &ocfs2_dentry_ops;
2100 sb->s_export_op = &ocfs2_export_ops; 2101 sb->s_export_op = &ocfs2_export_ops;
2101 sb->s_qcop = &ocfs2_quotactl_ops; 2102 sb->s_qcop = &ocfs2_quotactl_ops;
2102 sb->dq_op = &ocfs2_quota_operations; 2103 sb->dq_op = &ocfs2_quota_operations;
diff --git a/fs/open.c b/fs/open.c
index 4197b9ed023d..5b6ef7e2859e 100644
--- a/fs/open.c
+++ b/fs/open.c
@@ -223,7 +223,12 @@ int do_fallocate(struct file *file, int mode, loff_t offset, loff_t len)
223 return -EINVAL; 223 return -EINVAL;
224 224
225 /* Return error if mode is not supported */ 225 /* Return error if mode is not supported */
226 if (mode && !(mode & FALLOC_FL_KEEP_SIZE)) 226 if (mode & ~(FALLOC_FL_KEEP_SIZE | FALLOC_FL_PUNCH_HOLE))
227 return -EOPNOTSUPP;
228
229 /* Punch hole must have keep size set */
230 if ((mode & FALLOC_FL_PUNCH_HOLE) &&
231 !(mode & FALLOC_FL_KEEP_SIZE))
227 return -EOPNOTSUPP; 232 return -EOPNOTSUPP;
228 233
229 if (!(file->f_mode & FMODE_WRITE)) 234 if (!(file->f_mode & FMODE_WRITE))
diff --git a/fs/pipe.c b/fs/pipe.c
index 68f1f8e4e23b..e2e95fb46a1e 100644
--- a/fs/pipe.c
+++ b/fs/pipe.c
@@ -441,7 +441,7 @@ redo:
441 break; 441 break;
442 } 442 }
443 if (do_wakeup) { 443 if (do_wakeup) {
444 wake_up_interruptible_sync(&pipe->wait); 444 wake_up_interruptible_sync_poll(&pipe->wait, POLLOUT);
445 kill_fasync(&pipe->fasync_writers, SIGIO, POLL_OUT); 445 kill_fasync(&pipe->fasync_writers, SIGIO, POLL_OUT);
446 } 446 }
447 pipe_wait(pipe); 447 pipe_wait(pipe);
@@ -450,7 +450,7 @@ redo:
450 450
451 /* Signal writers asynchronously that there is more room. */ 451 /* Signal writers asynchronously that there is more room. */
452 if (do_wakeup) { 452 if (do_wakeup) {
453 wake_up_interruptible_sync(&pipe->wait); 453 wake_up_interruptible_sync_poll(&pipe->wait, POLLOUT);
454 kill_fasync(&pipe->fasync_writers, SIGIO, POLL_OUT); 454 kill_fasync(&pipe->fasync_writers, SIGIO, POLL_OUT);
455 } 455 }
456 if (ret > 0) 456 if (ret > 0)
@@ -612,7 +612,7 @@ redo2:
612 break; 612 break;
613 } 613 }
614 if (do_wakeup) { 614 if (do_wakeup) {
615 wake_up_interruptible_sync(&pipe->wait); 615 wake_up_interruptible_sync_poll(&pipe->wait, POLLIN);
616 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN); 616 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
617 do_wakeup = 0; 617 do_wakeup = 0;
618 } 618 }
@@ -623,7 +623,7 @@ redo2:
623out: 623out:
624 mutex_unlock(&inode->i_mutex); 624 mutex_unlock(&inode->i_mutex);
625 if (do_wakeup) { 625 if (do_wakeup) {
626 wake_up_interruptible_sync(&pipe->wait); 626 wake_up_interruptible_sync_poll(&pipe->wait, POLLIN);
627 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN); 627 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
628 } 628 }
629 if (ret > 0) 629 if (ret > 0)
@@ -715,7 +715,7 @@ pipe_release(struct inode *inode, int decr, int decw)
715 if (!pipe->readers && !pipe->writers) { 715 if (!pipe->readers && !pipe->writers) {
716 free_pipe_info(inode); 716 free_pipe_info(inode);
717 } else { 717 } else {
718 wake_up_interruptible_sync(&pipe->wait); 718 wake_up_interruptible_sync_poll(&pipe->wait, POLLIN | POLLOUT);
719 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN); 719 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
720 kill_fasync(&pipe->fasync_writers, SIGIO, POLL_OUT); 720 kill_fasync(&pipe->fasync_writers, SIGIO, POLL_OUT);
721 } 721 }
@@ -1004,7 +1004,6 @@ struct file *create_write_pipe(int flags)
1004 goto err_inode; 1004 goto err_inode;
1005 path.mnt = mntget(pipe_mnt); 1005 path.mnt = mntget(pipe_mnt);
1006 1006
1007 d_set_d_op(path.dentry, &pipefs_dentry_operations);
1008 d_instantiate(path.dentry, inode); 1007 d_instantiate(path.dentry, inode);
1009 1008
1010 err = -ENFILE; 1009 err = -ENFILE;
@@ -1266,7 +1265,8 @@ static const struct super_operations pipefs_ops = {
1266static struct dentry *pipefs_mount(struct file_system_type *fs_type, 1265static struct dentry *pipefs_mount(struct file_system_type *fs_type,
1267 int flags, const char *dev_name, void *data) 1266 int flags, const char *dev_name, void *data)
1268{ 1267{
1269 return mount_pseudo(fs_type, "pipe:", &pipefs_ops, PIPEFS_MAGIC); 1268 return mount_pseudo(fs_type, "pipe:", &pipefs_ops,
1269 &pipefs_dentry_operations, PIPEFS_MAGIC);
1270} 1270}
1271 1271
1272static struct file_system_type pipe_fs_type = { 1272static struct file_system_type pipe_fs_type = {
diff --git a/fs/proc/Makefile b/fs/proc/Makefile
index 288a49e098bf..df434c5f28fb 100644
--- a/fs/proc/Makefile
+++ b/fs/proc/Makefile
@@ -10,12 +10,12 @@ proc-$(CONFIG_MMU) := mmu.o task_mmu.o
10proc-y += inode.o root.o base.o generic.o array.o \ 10proc-y += inode.o root.o base.o generic.o array.o \
11 proc_tty.o 11 proc_tty.o
12proc-y += cmdline.o 12proc-y += cmdline.o
13proc-y += consoles.o
13proc-y += cpuinfo.o 14proc-y += cpuinfo.o
14proc-y += devices.o 15proc-y += devices.o
15proc-y += interrupts.o 16proc-y += interrupts.o
16proc-y += loadavg.o 17proc-y += loadavg.o
17proc-y += meminfo.o 18proc-y += meminfo.o
18proc-y += proc_console.o
19proc-y += stat.o 19proc-y += stat.o
20proc-y += uptime.o 20proc-y += uptime.o
21proc-y += version.o 21proc-y += version.o
diff --git a/fs/proc/array.c b/fs/proc/array.c
index fff6572676ae..df2b703b9d0f 100644
--- a/fs/proc/array.c
+++ b/fs/proc/array.c
@@ -95,7 +95,7 @@ static inline void task_name(struct seq_file *m, struct task_struct *p)
95 95
96 get_task_comm(tcomm, p); 96 get_task_comm(tcomm, p);
97 97
98 seq_printf(m, "Name:\t"); 98 seq_puts(m, "Name:\t");
99 end = m->buf + m->size; 99 end = m->buf + m->size;
100 buf = m->buf + m->count; 100 buf = m->buf + m->count;
101 name = tcomm; 101 name = tcomm;
@@ -122,7 +122,7 @@ static inline void task_name(struct seq_file *m, struct task_struct *p)
122 buf++; 122 buf++;
123 } 123 }
124 m->count = buf - m->buf; 124 m->count = buf - m->buf;
125 seq_printf(m, "\n"); 125 seq_putc(m, '\n');
126} 126}
127 127
128/* 128/*
@@ -208,7 +208,7 @@ static inline void task_state(struct seq_file *m, struct pid_namespace *ns,
208 seq_printf(m, "%d ", GROUP_AT(group_info, g)); 208 seq_printf(m, "%d ", GROUP_AT(group_info, g));
209 put_cred(cred); 209 put_cred(cred);
210 210
211 seq_printf(m, "\n"); 211 seq_putc(m, '\n');
212} 212}
213 213
214static void render_sigset_t(struct seq_file *m, const char *header, 214static void render_sigset_t(struct seq_file *m, const char *header,
@@ -216,7 +216,7 @@ static void render_sigset_t(struct seq_file *m, const char *header,
216{ 216{
217 int i; 217 int i;
218 218
219 seq_printf(m, "%s", header); 219 seq_puts(m, header);
220 220
221 i = _NSIG; 221 i = _NSIG;
222 do { 222 do {
@@ -230,7 +230,7 @@ static void render_sigset_t(struct seq_file *m, const char *header,
230 seq_printf(m, "%x", x); 230 seq_printf(m, "%x", x);
231 } while (i >= 4); 231 } while (i >= 4);
232 232
233 seq_printf(m, "\n"); 233 seq_putc(m, '\n');
234} 234}
235 235
236static void collect_sigign_sigcatch(struct task_struct *p, sigset_t *ign, 236static void collect_sigign_sigcatch(struct task_struct *p, sigset_t *ign,
@@ -291,12 +291,12 @@ static void render_cap_t(struct seq_file *m, const char *header,
291{ 291{
292 unsigned __capi; 292 unsigned __capi;
293 293
294 seq_printf(m, "%s", header); 294 seq_puts(m, header);
295 CAP_FOR_EACH_U32(__capi) { 295 CAP_FOR_EACH_U32(__capi) {
296 seq_printf(m, "%08x", 296 seq_printf(m, "%08x",
297 a->cap[(_KERNEL_CAPABILITY_U32S-1) - __capi]); 297 a->cap[(_KERNEL_CAPABILITY_U32S-1) - __capi]);
298 } 298 }
299 seq_printf(m, "\n"); 299 seq_putc(m, '\n');
300} 300}
301 301
302static inline void task_cap(struct seq_file *m, struct task_struct *p) 302static inline void task_cap(struct seq_file *m, struct task_struct *p)
@@ -329,12 +329,12 @@ static inline void task_context_switch_counts(struct seq_file *m,
329 329
330static void task_cpus_allowed(struct seq_file *m, struct task_struct *task) 330static void task_cpus_allowed(struct seq_file *m, struct task_struct *task)
331{ 331{
332 seq_printf(m, "Cpus_allowed:\t"); 332 seq_puts(m, "Cpus_allowed:\t");
333 seq_cpumask(m, &task->cpus_allowed); 333 seq_cpumask(m, &task->cpus_allowed);
334 seq_printf(m, "\n"); 334 seq_putc(m, '\n');
335 seq_printf(m, "Cpus_allowed_list:\t"); 335 seq_puts(m, "Cpus_allowed_list:\t");
336 seq_cpumask_list(m, &task->cpus_allowed); 336 seq_cpumask_list(m, &task->cpus_allowed);
337 seq_printf(m, "\n"); 337 seq_putc(m, '\n');
338} 338}
339 339
340int proc_pid_status(struct seq_file *m, struct pid_namespace *ns, 340int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
@@ -535,15 +535,15 @@ int proc_tgid_stat(struct seq_file *m, struct pid_namespace *ns,
535int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns, 535int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
536 struct pid *pid, struct task_struct *task) 536 struct pid *pid, struct task_struct *task)
537{ 537{
538 int size = 0, resident = 0, shared = 0, text = 0, lib = 0, data = 0; 538 unsigned long size = 0, resident = 0, shared = 0, text = 0, data = 0;
539 struct mm_struct *mm = get_task_mm(task); 539 struct mm_struct *mm = get_task_mm(task);
540 540
541 if (mm) { 541 if (mm) {
542 size = task_statm(mm, &shared, &text, &data, &resident); 542 size = task_statm(mm, &shared, &text, &data, &resident);
543 mmput(mm); 543 mmput(mm);
544 } 544 }
545 seq_printf(m, "%d %d %d %d %d %d %d\n", 545 seq_printf(m, "%lu %lu %lu %lu 0 %lu 0\n",
546 size, resident, shared, text, lib, data, 0); 546 size, resident, shared, text, data);
547 547
548 return 0; 548 return 0;
549} 549}
diff --git a/fs/proc/base.c b/fs/proc/base.c
index b20962c71a52..93f1cdd5d3d7 100644
--- a/fs/proc/base.c
+++ b/fs/proc/base.c
@@ -373,26 +373,20 @@ static int lstats_show_proc(struct seq_file *m, void *v)
373 return -ESRCH; 373 return -ESRCH;
374 seq_puts(m, "Latency Top version : v0.1\n"); 374 seq_puts(m, "Latency Top version : v0.1\n");
375 for (i = 0; i < 32; i++) { 375 for (i = 0; i < 32; i++) {
376 if (task->latency_record[i].backtrace[0]) { 376 struct latency_record *lr = &task->latency_record[i];
377 if (lr->backtrace[0]) {
377 int q; 378 int q;
378 seq_printf(m, "%i %li %li ", 379 seq_printf(m, "%i %li %li",
379 task->latency_record[i].count, 380 lr->count, lr->time, lr->max);
380 task->latency_record[i].time,
381 task->latency_record[i].max);
382 for (q = 0; q < LT_BACKTRACEDEPTH; q++) { 381 for (q = 0; q < LT_BACKTRACEDEPTH; q++) {
383 char sym[KSYM_SYMBOL_LEN]; 382 unsigned long bt = lr->backtrace[q];
384 char *c; 383 if (!bt)
385 if (!task->latency_record[i].backtrace[q])
386 break; 384 break;
387 if (task->latency_record[i].backtrace[q] == ULONG_MAX) 385 if (bt == ULONG_MAX)
388 break; 386 break;
389 sprint_symbol(sym, task->latency_record[i].backtrace[q]); 387 seq_printf(m, " %ps", (void *)bt);
390 c = strchr(sym, '+');
391 if (c)
392 *c = 0;
393 seq_printf(m, "%s ", sym);
394 } 388 }
395 seq_printf(m, "\n"); 389 seq_putc(m, '\n');
396 } 390 }
397 391
398 } 392 }
@@ -751,14 +745,7 @@ static int proc_single_show(struct seq_file *m, void *v)
751 745
752static int proc_single_open(struct inode *inode, struct file *filp) 746static int proc_single_open(struct inode *inode, struct file *filp)
753{ 747{
754 int ret; 748 return single_open(filp, proc_single_show, inode);
755 ret = single_open(filp, proc_single_show, NULL);
756 if (!ret) {
757 struct seq_file *m = filp->private_data;
758
759 m->private = inode;
760 }
761 return ret;
762} 749}
763 750
764static const struct file_operations proc_single_file_operations = { 751static const struct file_operations proc_single_file_operations = {
@@ -1386,15 +1373,7 @@ sched_write(struct file *file, const char __user *buf,
1386 1373
1387static int sched_open(struct inode *inode, struct file *filp) 1374static int sched_open(struct inode *inode, struct file *filp)
1388{ 1375{
1389 int ret; 1376 return single_open(filp, sched_show, inode);
1390
1391 ret = single_open(filp, sched_show, NULL);
1392 if (!ret) {
1393 struct seq_file *m = filp->private_data;
1394
1395 m->private = inode;
1396 }
1397 return ret;
1398} 1377}
1399 1378
1400static const struct file_operations proc_pid_sched_operations = { 1379static const struct file_operations proc_pid_sched_operations = {
@@ -1530,15 +1509,7 @@ static int comm_show(struct seq_file *m, void *v)
1530 1509
1531static int comm_open(struct inode *inode, struct file *filp) 1510static int comm_open(struct inode *inode, struct file *filp)
1532{ 1511{
1533 int ret; 1512 return single_open(filp, comm_show, inode);
1534
1535 ret = single_open(filp, comm_show, NULL);
1536 if (!ret) {
1537 struct seq_file *m = filp->private_data;
1538
1539 m->private = inode;
1540 }
1541 return ret;
1542} 1513}
1543 1514
1544static const struct file_operations proc_pid_set_comm_operations = { 1515static const struct file_operations proc_pid_set_comm_operations = {
diff --git a/fs/proc/proc_console.c b/fs/proc/consoles.c
index 8a707609f528..eafc22ab1fdd 100644
--- a/fs/proc/proc_console.c
+++ b/fs/proc/consoles.c
@@ -106,9 +106,9 @@ static const struct file_operations proc_consoles_operations = {
106 .release = seq_release, 106 .release = seq_release,
107}; 107};
108 108
109static int register_proc_consoles(void) 109static int __init proc_consoles_init(void)
110{ 110{
111 proc_create("consoles", 0, NULL, &proc_consoles_operations); 111 proc_create("consoles", 0, NULL, &proc_consoles_operations);
112 return 0; 112 return 0;
113} 113}
114module_init(register_proc_consoles); 114module_init(proc_consoles_init);
diff --git a/fs/proc/devices.c b/fs/proc/devices.c
index 59ee7da959c9..b14347167c35 100644
--- a/fs/proc/devices.c
+++ b/fs/proc/devices.c
@@ -9,14 +9,14 @@ static int devinfo_show(struct seq_file *f, void *v)
9 9
10 if (i < CHRDEV_MAJOR_HASH_SIZE) { 10 if (i < CHRDEV_MAJOR_HASH_SIZE) {
11 if (i == 0) 11 if (i == 0)
12 seq_printf(f, "Character devices:\n"); 12 seq_puts(f, "Character devices:\n");
13 chrdev_show(f, i); 13 chrdev_show(f, i);
14 } 14 }
15#ifdef CONFIG_BLOCK 15#ifdef CONFIG_BLOCK
16 else { 16 else {
17 i -= CHRDEV_MAJOR_HASH_SIZE; 17 i -= CHRDEV_MAJOR_HASH_SIZE;
18 if (i == 0) 18 if (i == 0)
19 seq_printf(f, "\nBlock devices:\n"); 19 seq_puts(f, "\nBlock devices:\n");
20 blkdev_show(f, i); 20 blkdev_show(f, i);
21 } 21 }
22#endif 22#endif
diff --git a/fs/proc/generic.c b/fs/proc/generic.c
index f766be29d2c7..01e07f2a188f 100644
--- a/fs/proc/generic.c
+++ b/fs/proc/generic.c
@@ -425,13 +425,10 @@ struct dentry *proc_lookup_de(struct proc_dir_entry *de, struct inode *dir,
425 if (de->namelen != dentry->d_name.len) 425 if (de->namelen != dentry->d_name.len)
426 continue; 426 continue;
427 if (!memcmp(dentry->d_name.name, de->name, de->namelen)) { 427 if (!memcmp(dentry->d_name.name, de->name, de->namelen)) {
428 unsigned int ino;
429
430 ino = de->low_ino;
431 pde_get(de); 428 pde_get(de);
432 spin_unlock(&proc_subdir_lock); 429 spin_unlock(&proc_subdir_lock);
433 error = -EINVAL; 430 error = -EINVAL;
434 inode = proc_get_inode(dir->i_sb, ino, de); 431 inode = proc_get_inode(dir->i_sb, de);
435 goto out_unlock; 432 goto out_unlock;
436 } 433 }
437 } 434 }
@@ -768,12 +765,7 @@ EXPORT_SYMBOL(proc_create_data);
768 765
769static void free_proc_entry(struct proc_dir_entry *de) 766static void free_proc_entry(struct proc_dir_entry *de)
770{ 767{
771 unsigned int ino = de->low_ino; 768 release_inode_number(de->low_ino);
772
773 if (ino < PROC_DYNAMIC_FIRST)
774 return;
775
776 release_inode_number(ino);
777 769
778 if (S_ISLNK(de->mode)) 770 if (S_ISLNK(de->mode))
779 kfree(de->data); 771 kfree(de->data);
@@ -834,12 +826,9 @@ void remove_proc_entry(const char *name, struct proc_dir_entry *parent)
834 826
835 wait_for_completion(de->pde_unload_completion); 827 wait_for_completion(de->pde_unload_completion);
836 828
837 goto continue_removing; 829 spin_lock(&de->pde_unload_lock);
838 } 830 }
839 spin_unlock(&de->pde_unload_lock);
840 831
841continue_removing:
842 spin_lock(&de->pde_unload_lock);
843 while (!list_empty(&de->pde_openers)) { 832 while (!list_empty(&de->pde_openers)) {
844 struct pde_opener *pdeo; 833 struct pde_opener *pdeo;
845 834
diff --git a/fs/proc/inode.c b/fs/proc/inode.c
index 6bcb926b101b..176ce4cda68a 100644
--- a/fs/proc/inode.c
+++ b/fs/proc/inode.c
@@ -416,12 +416,11 @@ static const struct file_operations proc_reg_file_ops_no_compat = {
416}; 416};
417#endif 417#endif
418 418
419struct inode *proc_get_inode(struct super_block *sb, unsigned int ino, 419struct inode *proc_get_inode(struct super_block *sb, struct proc_dir_entry *de)
420 struct proc_dir_entry *de)
421{ 420{
422 struct inode * inode; 421 struct inode * inode;
423 422
424 inode = iget_locked(sb, ino); 423 inode = iget_locked(sb, de->low_ino);
425 if (!inode) 424 if (!inode)
426 return NULL; 425 return NULL;
427 if (inode->i_state & I_NEW) { 426 if (inode->i_state & I_NEW) {
@@ -471,7 +470,7 @@ int proc_fill_super(struct super_block *s)
471 s->s_time_gran = 1; 470 s->s_time_gran = 1;
472 471
473 pde_get(&proc_root); 472 pde_get(&proc_root);
474 root_inode = proc_get_inode(s, PROC_ROOT_INO, &proc_root); 473 root_inode = proc_get_inode(s, &proc_root);
475 if (!root_inode) 474 if (!root_inode)
476 goto out_no_root; 475 goto out_no_root;
477 root_inode->i_uid = 0; 476 root_inode->i_uid = 0;
diff --git a/fs/proc/internal.h b/fs/proc/internal.h
index 1f24a3eddd12..9ad561ded409 100644
--- a/fs/proc/internal.h
+++ b/fs/proc/internal.h
@@ -96,7 +96,8 @@ extern spinlock_t proc_subdir_lock;
96struct dentry *proc_pid_lookup(struct inode *dir, struct dentry * dentry, struct nameidata *); 96struct dentry *proc_pid_lookup(struct inode *dir, struct dentry * dentry, struct nameidata *);
97int proc_pid_readdir(struct file * filp, void * dirent, filldir_t filldir); 97int proc_pid_readdir(struct file * filp, void * dirent, filldir_t filldir);
98unsigned long task_vsize(struct mm_struct *); 98unsigned long task_vsize(struct mm_struct *);
99int task_statm(struct mm_struct *, int *, int *, int *, int *); 99unsigned long task_statm(struct mm_struct *,
100 unsigned long *, unsigned long *, unsigned long *, unsigned long *);
100void task_mem(struct seq_file *, struct mm_struct *); 101void task_mem(struct seq_file *, struct mm_struct *);
101 102
102static inline struct proc_dir_entry *pde_get(struct proc_dir_entry *pde) 103static inline struct proc_dir_entry *pde_get(struct proc_dir_entry *pde)
@@ -108,7 +109,7 @@ void pde_put(struct proc_dir_entry *pde);
108 109
109extern struct vfsmount *proc_mnt; 110extern struct vfsmount *proc_mnt;
110int proc_fill_super(struct super_block *); 111int proc_fill_super(struct super_block *);
111struct inode *proc_get_inode(struct super_block *, unsigned int, struct proc_dir_entry *); 112struct inode *proc_get_inode(struct super_block *, struct proc_dir_entry *);
112 113
113/* 114/*
114 * These are generic /proc routines that use the internal 115 * These are generic /proc routines that use the internal
diff --git a/fs/proc/kcore.c b/fs/proc/kcore.c
index 6f37c391468d..d245cb23dd72 100644
--- a/fs/proc/kcore.c
+++ b/fs/proc/kcore.c
@@ -558,7 +558,7 @@ static int open_kcore(struct inode *inode, struct file *filp)
558static const struct file_operations proc_kcore_operations = { 558static const struct file_operations proc_kcore_operations = {
559 .read = read_kcore, 559 .read = read_kcore,
560 .open = open_kcore, 560 .open = open_kcore,
561 .llseek = generic_file_llseek, 561 .llseek = default_llseek,
562}; 562};
563 563
564#ifdef CONFIG_MEMORY_HOTPLUG 564#ifdef CONFIG_MEMORY_HOTPLUG
diff --git a/fs/proc/page.c b/fs/proc/page.c
index 3b8b45660331..b06c674624e6 100644
--- a/fs/proc/page.c
+++ b/fs/proc/page.c
@@ -40,7 +40,7 @@ static ssize_t kpagecount_read(struct file *file, char __user *buf,
40 ppage = pfn_to_page(pfn); 40 ppage = pfn_to_page(pfn);
41 else 41 else
42 ppage = NULL; 42 ppage = NULL;
43 if (!ppage) 43 if (!ppage || PageSlab(ppage))
44 pcount = 0; 44 pcount = 0;
45 else 45 else
46 pcount = page_mapcount(ppage); 46 pcount = page_mapcount(ppage);
diff --git a/fs/proc/proc_tty.c b/fs/proc/proc_tty.c
index 83adcc869437..cb761f010300 100644
--- a/fs/proc/proc_tty.c
+++ b/fs/proc/proc_tty.c
@@ -36,27 +36,27 @@ static void show_tty_range(struct seq_file *m, struct tty_driver *p,
36 } 36 }
37 switch (p->type) { 37 switch (p->type) {
38 case TTY_DRIVER_TYPE_SYSTEM: 38 case TTY_DRIVER_TYPE_SYSTEM:
39 seq_printf(m, "system"); 39 seq_puts(m, "system");
40 if (p->subtype == SYSTEM_TYPE_TTY) 40 if (p->subtype == SYSTEM_TYPE_TTY)
41 seq_printf(m, ":/dev/tty"); 41 seq_puts(m, ":/dev/tty");
42 else if (p->subtype == SYSTEM_TYPE_SYSCONS) 42 else if (p->subtype == SYSTEM_TYPE_SYSCONS)
43 seq_printf(m, ":console"); 43 seq_puts(m, ":console");
44 else if (p->subtype == SYSTEM_TYPE_CONSOLE) 44 else if (p->subtype == SYSTEM_TYPE_CONSOLE)
45 seq_printf(m, ":vtmaster"); 45 seq_puts(m, ":vtmaster");
46 break; 46 break;
47 case TTY_DRIVER_TYPE_CONSOLE: 47 case TTY_DRIVER_TYPE_CONSOLE:
48 seq_printf(m, "console"); 48 seq_puts(m, "console");
49 break; 49 break;
50 case TTY_DRIVER_TYPE_SERIAL: 50 case TTY_DRIVER_TYPE_SERIAL:
51 seq_printf(m, "serial"); 51 seq_puts(m, "serial");
52 break; 52 break;
53 case TTY_DRIVER_TYPE_PTY: 53 case TTY_DRIVER_TYPE_PTY:
54 if (p->subtype == PTY_TYPE_MASTER) 54 if (p->subtype == PTY_TYPE_MASTER)
55 seq_printf(m, "pty:master"); 55 seq_puts(m, "pty:master");
56 else if (p->subtype == PTY_TYPE_SLAVE) 56 else if (p->subtype == PTY_TYPE_SLAVE)
57 seq_printf(m, "pty:slave"); 57 seq_puts(m, "pty:slave");
58 else 58 else
59 seq_printf(m, "pty"); 59 seq_puts(m, "pty");
60 break; 60 break;
61 default: 61 default:
62 seq_printf(m, "type:%d.%d", p->type, p->subtype); 62 seq_printf(m, "type:%d.%d", p->type, p->subtype);
@@ -74,19 +74,19 @@ static int show_tty_driver(struct seq_file *m, void *v)
74 /* pseudo-drivers first */ 74 /* pseudo-drivers first */
75 seq_printf(m, "%-20s /dev/%-8s ", "/dev/tty", "tty"); 75 seq_printf(m, "%-20s /dev/%-8s ", "/dev/tty", "tty");
76 seq_printf(m, "%3d %7d ", TTYAUX_MAJOR, 0); 76 seq_printf(m, "%3d %7d ", TTYAUX_MAJOR, 0);
77 seq_printf(m, "system:/dev/tty\n"); 77 seq_puts(m, "system:/dev/tty\n");
78 seq_printf(m, "%-20s /dev/%-8s ", "/dev/console", "console"); 78 seq_printf(m, "%-20s /dev/%-8s ", "/dev/console", "console");
79 seq_printf(m, "%3d %7d ", TTYAUX_MAJOR, 1); 79 seq_printf(m, "%3d %7d ", TTYAUX_MAJOR, 1);
80 seq_printf(m, "system:console\n"); 80 seq_puts(m, "system:console\n");
81#ifdef CONFIG_UNIX98_PTYS 81#ifdef CONFIG_UNIX98_PTYS
82 seq_printf(m, "%-20s /dev/%-8s ", "/dev/ptmx", "ptmx"); 82 seq_printf(m, "%-20s /dev/%-8s ", "/dev/ptmx", "ptmx");
83 seq_printf(m, "%3d %7d ", TTYAUX_MAJOR, 2); 83 seq_printf(m, "%3d %7d ", TTYAUX_MAJOR, 2);
84 seq_printf(m, "system\n"); 84 seq_puts(m, "system\n");
85#endif 85#endif
86#ifdef CONFIG_VT 86#ifdef CONFIG_VT
87 seq_printf(m, "%-20s /dev/%-8s ", "/dev/vc/0", "vc/0"); 87 seq_printf(m, "%-20s /dev/%-8s ", "/dev/vc/0", "vc/0");
88 seq_printf(m, "%3d %7d ", TTY_MAJOR, 0); 88 seq_printf(m, "%3d %7d ", TTY_MAJOR, 0);
89 seq_printf(m, "system:vtmaster\n"); 89 seq_puts(m, "system:vtmaster\n");
90#endif 90#endif
91 } 91 }
92 92
diff --git a/fs/proc/softirqs.c b/fs/proc/softirqs.c
index 37994737c983..62604be9f58d 100644
--- a/fs/proc/softirqs.c
+++ b/fs/proc/softirqs.c
@@ -10,16 +10,16 @@ static int show_softirqs(struct seq_file *p, void *v)
10{ 10{
11 int i, j; 11 int i, j;
12 12
13 seq_printf(p, " "); 13 seq_puts(p, " ");
14 for_each_possible_cpu(i) 14 for_each_possible_cpu(i)
15 seq_printf(p, "CPU%-8d", i); 15 seq_printf(p, "CPU%-8d", i);
16 seq_printf(p, "\n"); 16 seq_putc(p, '\n');
17 17
18 for (i = 0; i < NR_SOFTIRQS; i++) { 18 for (i = 0; i < NR_SOFTIRQS; i++) {
19 seq_printf(p, "%12s:", softirq_to_name[i]); 19 seq_printf(p, "%12s:", softirq_to_name[i]);
20 for_each_possible_cpu(j) 20 for_each_possible_cpu(j)
21 seq_printf(p, " %10u", kstat_softirqs_cpu(i, j)); 21 seq_printf(p, " %10u", kstat_softirqs_cpu(i, j));
22 seq_printf(p, "\n"); 22 seq_putc(p, '\n');
23 } 23 }
24 return 0; 24 return 0;
25} 25}
diff --git a/fs/proc/stat.c b/fs/proc/stat.c
index e15a19c93bae..1cffa2b8a2fc 100644
--- a/fs/proc/stat.c
+++ b/fs/proc/stat.c
@@ -126,7 +126,7 @@ static int show_stat(struct seq_file *p, void *v)
126 126
127 for (i = 0; i < NR_SOFTIRQS; i++) 127 for (i = 0; i < NR_SOFTIRQS; i++)
128 seq_printf(p, " %u", per_softirq_sums[i]); 128 seq_printf(p, " %u", per_softirq_sums[i]);
129 seq_printf(p, "\n"); 129 seq_putc(p, '\n');
130 130
131 return 0; 131 return 0;
132} 132}
diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
index c126c83b9a45..c3755bd8dd3e 100644
--- a/fs/proc/task_mmu.c
+++ b/fs/proc/task_mmu.c
@@ -66,8 +66,9 @@ unsigned long task_vsize(struct mm_struct *mm)
66 return PAGE_SIZE * mm->total_vm; 66 return PAGE_SIZE * mm->total_vm;
67} 67}
68 68
69int task_statm(struct mm_struct *mm, int *shared, int *text, 69unsigned long task_statm(struct mm_struct *mm,
70 int *data, int *resident) 70 unsigned long *shared, unsigned long *text,
71 unsigned long *data, unsigned long *resident)
71{ 72{
72 *shared = get_mm_counter(mm, MM_FILEPAGES); 73 *shared = get_mm_counter(mm, MM_FILEPAGES);
73 *text = (PAGE_ALIGN(mm->end_code) - (mm->start_code & PAGE_MASK)) 74 *text = (PAGE_ALIGN(mm->end_code) - (mm->start_code & PAGE_MASK))
diff --git a/fs/proc/task_nommu.c b/fs/proc/task_nommu.c
index cb6306e63843..b535d3e5d5f1 100644
--- a/fs/proc/task_nommu.c
+++ b/fs/proc/task_nommu.c
@@ -92,13 +92,14 @@ unsigned long task_vsize(struct mm_struct *mm)
92 return vsize; 92 return vsize;
93} 93}
94 94
95int task_statm(struct mm_struct *mm, int *shared, int *text, 95unsigned long task_statm(struct mm_struct *mm,
96 int *data, int *resident) 96 unsigned long *shared, unsigned long *text,
97 unsigned long *data, unsigned long *resident)
97{ 98{
98 struct vm_area_struct *vma; 99 struct vm_area_struct *vma;
99 struct vm_region *region; 100 struct vm_region *region;
100 struct rb_node *p; 101 struct rb_node *p;
101 int size = kobjsize(mm); 102 unsigned long size = kobjsize(mm);
102 103
103 down_read(&mm->mmap_sem); 104 down_read(&mm->mmap_sem);
104 for (p = rb_first(&mm->mm_rb); p; p = rb_next(p)) { 105 for (p = rb_first(&mm->mm_rb); p; p = rb_next(p)) {
diff --git a/fs/read_write.c b/fs/read_write.c
index 5d431bacbea9..5520f8ad5504 100644
--- a/fs/read_write.c
+++ b/fs/read_write.c
@@ -30,18 +30,9 @@ const struct file_operations generic_ro_fops = {
30 30
31EXPORT_SYMBOL(generic_ro_fops); 31EXPORT_SYMBOL(generic_ro_fops);
32 32
33static int 33static inline int unsigned_offsets(struct file *file)
34__negative_fpos_check(struct file *file, loff_t pos, size_t count)
35{ 34{
36 /* 35 return file->f_mode & FMODE_UNSIGNED_OFFSET;
37 * pos or pos+count is negative here, check overflow.
38 * too big "count" will be caught in rw_verify_area().
39 */
40 if ((pos < 0) && (pos + count < pos))
41 return -EOVERFLOW;
42 if (file->f_mode & FMODE_UNSIGNED_OFFSET)
43 return 0;
44 return -EINVAL;
45} 36}
46 37
47/** 38/**
@@ -75,7 +66,7 @@ generic_file_llseek_unlocked(struct file *file, loff_t offset, int origin)
75 break; 66 break;
76 } 67 }
77 68
78 if (offset < 0 && __negative_fpos_check(file, offset, 0)) 69 if (offset < 0 && !unsigned_offsets(file))
79 return -EINVAL; 70 return -EINVAL;
80 if (offset > inode->i_sb->s_maxbytes) 71 if (offset > inode->i_sb->s_maxbytes)
81 return -EINVAL; 72 return -EINVAL;
@@ -152,7 +143,7 @@ loff_t default_llseek(struct file *file, loff_t offset, int origin)
152 offset += file->f_pos; 143 offset += file->f_pos;
153 } 144 }
154 retval = -EINVAL; 145 retval = -EINVAL;
155 if (offset >= 0 || !__negative_fpos_check(file, offset, 0)) { 146 if (offset >= 0 || unsigned_offsets(file)) {
156 if (offset != file->f_pos) { 147 if (offset != file->f_pos) {
157 file->f_pos = offset; 148 file->f_pos = offset;
158 file->f_version = 0; 149 file->f_version = 0;
@@ -252,9 +243,13 @@ int rw_verify_area(int read_write, struct file *file, loff_t *ppos, size_t count
252 if (unlikely((ssize_t) count < 0)) 243 if (unlikely((ssize_t) count < 0))
253 return retval; 244 return retval;
254 pos = *ppos; 245 pos = *ppos;
255 if (unlikely((pos < 0) || (loff_t) (pos + count) < 0)) { 246 if (unlikely(pos < 0)) {
256 retval = __negative_fpos_check(file, pos, count); 247 if (!unsigned_offsets(file))
257 if (retval) 248 return retval;
249 if (count >= -pos) /* both values are in 0..LLONG_MAX */
250 return -EOVERFLOW;
251 } else if (unlikely((loff_t) (pos + count) < 0)) {
252 if (!unsigned_offsets(file))
258 return retval; 253 return retval;
259 } 254 }
260 255
diff --git a/fs/reiserfs/prints.c b/fs/reiserfs/prints.c
index adbc6f538515..45de98b59466 100644
--- a/fs/reiserfs/prints.c
+++ b/fs/reiserfs/prints.c
@@ -586,13 +586,13 @@ void print_block(struct buffer_head *bh, ...) //int print_mode, int first, int l
586 va_list args; 586 va_list args;
587 int mode, first, last; 587 int mode, first, last;
588 588
589 va_start(args, bh);
590
591 if (!bh) { 589 if (!bh) {
592 printk("print_block: buffer is NULL\n"); 590 printk("print_block: buffer is NULL\n");
593 return; 591 return;
594 } 592 }
595 593
594 va_start(args, bh);
595
596 mode = va_arg(args, int); 596 mode = va_arg(args, int);
597 first = va_arg(args, int); 597 first = va_arg(args, int);
598 last = va_arg(args, int); 598 last = va_arg(args, int);
diff --git a/fs/select.c b/fs/select.c
index b7b10aa30861..e56560d2b08a 100644
--- a/fs/select.c
+++ b/fs/select.c
@@ -306,6 +306,8 @@ static int poll_select_copy_remaining(struct timespec *end_time, void __user *p,
306 rts.tv_sec = rts.tv_nsec = 0; 306 rts.tv_sec = rts.tv_nsec = 0;
307 307
308 if (timeval) { 308 if (timeval) {
309 if (sizeof(rtv) > sizeof(rtv.tv_sec) + sizeof(rtv.tv_usec))
310 memset(&rtv, 0, sizeof(rtv));
309 rtv.tv_sec = rts.tv_sec; 311 rtv.tv_sec = rts.tv_sec;
310 rtv.tv_usec = rts.tv_nsec / NSEC_PER_USEC; 312 rtv.tv_usec = rts.tv_nsec / NSEC_PER_USEC;
311 313
diff --git a/fs/sysv/namei.c b/fs/sysv/namei.c
index b5e68da2db32..b427b1208c26 100644
--- a/fs/sysv/namei.c
+++ b/fs/sysv/namei.c
@@ -48,7 +48,6 @@ static struct dentry *sysv_lookup(struct inode * dir, struct dentry * dentry, st
48 struct inode * inode = NULL; 48 struct inode * inode = NULL;
49 ino_t ino; 49 ino_t ino;
50 50
51 d_set_d_op(dentry, dir->i_sb->s_root->d_op);
52 if (dentry->d_name.len > SYSV_NAMELEN) 51 if (dentry->d_name.len > SYSV_NAMELEN)
53 return ERR_PTR(-ENAMETOOLONG); 52 return ERR_PTR(-ENAMETOOLONG);
54 ino = sysv_inode_by_name(dentry); 53 ino = sysv_inode_by_name(dentry);
diff --git a/fs/sysv/super.c b/fs/sysv/super.c
index 76712aefc4ab..f60c196913ea 100644
--- a/fs/sysv/super.c
+++ b/fs/sysv/super.c
@@ -332,6 +332,10 @@ static int complete_read_super(struct super_block *sb, int silent, int size)
332 sb->s_magic = SYSV_MAGIC_BASE + sbi->s_type; 332 sb->s_magic = SYSV_MAGIC_BASE + sbi->s_type;
333 /* set up enough so that it can read an inode */ 333 /* set up enough so that it can read an inode */
334 sb->s_op = &sysv_sops; 334 sb->s_op = &sysv_sops;
335 if (sbi->s_forced_ro)
336 sb->s_flags |= MS_RDONLY;
337 if (sbi->s_truncate)
338 sb->s_d_op = &sysv_dentry_operations;
335 root_inode = sysv_iget(sb, SYSV_ROOT_INO); 339 root_inode = sysv_iget(sb, SYSV_ROOT_INO);
336 if (IS_ERR(root_inode)) { 340 if (IS_ERR(root_inode)) {
337 printk("SysV FS: get root inode failed\n"); 341 printk("SysV FS: get root inode failed\n");
@@ -343,10 +347,6 @@ static int complete_read_super(struct super_block *sb, int silent, int size)
343 printk("SysV FS: get root dentry failed\n"); 347 printk("SysV FS: get root dentry failed\n");
344 return 0; 348 return 0;
345 } 349 }
346 if (sbi->s_forced_ro)
347 sb->s_flags |= MS_RDONLY;
348 if (sbi->s_truncate)
349 d_set_d_op(sb->s_root, &sysv_dentry_operations);
350 return 1; 350 return 1;
351} 351}
352 352
diff --git a/fs/xfs/linux-2.6/xfs_iops.c b/fs/xfs/linux-2.6/xfs_iops.c
index 94d5fd6a2973..da54403633b6 100644
--- a/fs/xfs/linux-2.6/xfs_iops.c
+++ b/fs/xfs/linux-2.6/xfs_iops.c
@@ -516,6 +516,7 @@ xfs_vn_fallocate(
516 loff_t new_size = 0; 516 loff_t new_size = 0;
517 xfs_flock64_t bf; 517 xfs_flock64_t bf;
518 xfs_inode_t *ip = XFS_I(inode); 518 xfs_inode_t *ip = XFS_I(inode);
519 int cmd = XFS_IOC_RESVSP;
519 520
520 /* preallocation on directories not yet supported */ 521 /* preallocation on directories not yet supported */
521 error = -ENODEV; 522 error = -ENODEV;
@@ -528,6 +529,9 @@ xfs_vn_fallocate(
528 529
529 xfs_ilock(ip, XFS_IOLOCK_EXCL); 530 xfs_ilock(ip, XFS_IOLOCK_EXCL);
530 531
532 if (mode & FALLOC_FL_PUNCH_HOLE)
533 cmd = XFS_IOC_UNRESVSP;
534
531 /* check the new inode size is valid before allocating */ 535 /* check the new inode size is valid before allocating */
532 if (!(mode & FALLOC_FL_KEEP_SIZE) && 536 if (!(mode & FALLOC_FL_KEEP_SIZE) &&
533 offset + len > i_size_read(inode)) { 537 offset + len > i_size_read(inode)) {
@@ -537,8 +541,7 @@ xfs_vn_fallocate(
537 goto out_unlock; 541 goto out_unlock;
538 } 542 }
539 543
540 error = -xfs_change_file_space(ip, XFS_IOC_RESVSP, &bf, 544 error = -xfs_change_file_space(ip, cmd, &bf, 0, XFS_ATTR_NOLOCK);
541 0, XFS_ATTR_NOLOCK);
542 if (error) 545 if (error)
543 goto out_unlock; 546 goto out_unlock;
544 547
diff --git a/fs/xfs/linux-2.6/xfs_super.c b/fs/xfs/linux-2.6/xfs_super.c
index c51faaa5e291..a10f6416e563 100644
--- a/fs/xfs/linux-2.6/xfs_super.c
+++ b/fs/xfs/linux-2.6/xfs_super.c
@@ -947,7 +947,7 @@ out_reclaim:
947 * Slab object creation initialisation for the XFS inode. 947 * Slab object creation initialisation for the XFS inode.
948 * This covers only the idempotent fields in the XFS inode; 948 * This covers only the idempotent fields in the XFS inode;
949 * all other fields need to be initialised on allocation 949 * all other fields need to be initialised on allocation
950 * from the slab. This avoids the need to repeatedly intialise 950 * from the slab. This avoids the need to repeatedly initialise
951 * fields in the xfs inode that left in the initialise state 951 * fields in the xfs inode that left in the initialise state
952 * when freeing the inode. 952 * when freeing the inode.
953 */ 953 */
diff --git a/include/acpi/actbl1.h b/include/acpi/actbl1.h
index c637b75b9f3f..cd77aa75c962 100644
--- a/include/acpi/actbl1.h
+++ b/include/acpi/actbl1.h
@@ -119,7 +119,7 @@ struct acpi_whea_header {
119struct acpi_table_bert { 119struct acpi_table_bert {
120 struct acpi_table_header header; /* Common ACPI table header */ 120 struct acpi_table_header header; /* Common ACPI table header */
121 u32 region_length; /* Length of the boot error region */ 121 u32 region_length; /* Length of the boot error region */
122 u64 address; /* Physical addresss of the error region */ 122 u64 address; /* Physical address of the error region */
123}; 123};
124 124
125/* Boot Error Region (not a subtable, pointed to by Address field above) */ 125/* Boot Error Region (not a subtable, pointed to by Address field above) */
diff --git a/include/asm-generic/gpio.h b/include/asm-generic/gpio.h
index ff5c66080c8c..6098cae2af8e 100644
--- a/include/asm-generic/gpio.h
+++ b/include/asm-generic/gpio.h
@@ -147,11 +147,11 @@ extern struct gpio_chip *gpiochip_find(void *data,
147/* Always use the library code for GPIO management calls, 147/* Always use the library code for GPIO management calls,
148 * or when sleeping may be involved. 148 * or when sleeping may be involved.
149 */ 149 */
150extern int gpio_request(unsigned gpio, const char *label); 150extern int __must_check gpio_request(unsigned gpio, const char *label);
151extern void gpio_free(unsigned gpio); 151extern void gpio_free(unsigned gpio);
152 152
153extern int gpio_direction_input(unsigned gpio); 153extern int __must_check gpio_direction_input(unsigned gpio);
154extern int gpio_direction_output(unsigned gpio, int value); 154extern int __must_check gpio_direction_output(unsigned gpio, int value);
155 155
156extern int gpio_set_debounce(unsigned gpio, unsigned debounce); 156extern int gpio_set_debounce(unsigned gpio, unsigned debounce);
157 157
@@ -192,8 +192,8 @@ struct gpio {
192 const char *label; 192 const char *label;
193}; 193};
194 194
195extern int gpio_request_one(unsigned gpio, unsigned long flags, const char *label); 195extern int __must_check gpio_request_one(unsigned gpio, unsigned long flags, const char *label);
196extern int gpio_request_array(struct gpio *array, size_t num); 196extern int __must_check gpio_request_array(struct gpio *array, size_t num);
197extern void gpio_free_array(struct gpio *array, size_t num); 197extern void gpio_free_array(struct gpio *array, size_t num);
198 198
199#ifdef CONFIG_GPIO_SYSFS 199#ifdef CONFIG_GPIO_SYSFS
diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
index 05cbad03c5ab..68649336c4ad 100644
--- a/include/asm-generic/vmlinux.lds.h
+++ b/include/asm-generic/vmlinux.lds.h
@@ -200,7 +200,8 @@
200 200
201#define READ_MOSTLY_DATA(align) \ 201#define READ_MOSTLY_DATA(align) \
202 . = ALIGN(align); \ 202 . = ALIGN(align); \
203 *(.data..read_mostly) 203 *(.data..read_mostly) \
204 . = ALIGN(align);
204 205
205#define CACHELINE_ALIGNED_DATA(align) \ 206#define CACHELINE_ALIGNED_DATA(align) \
206 . = ALIGN(align); \ 207 . = ALIGN(align); \
diff --git a/include/crypto/if_alg.h b/include/crypto/if_alg.h
new file mode 100644
index 000000000000..c5813c87de06
--- /dev/null
+++ b/include/crypto/if_alg.h
@@ -0,0 +1,92 @@
1/*
2 * if_alg: User-space algorithm interface
3 *
4 * Copyright (c) 2010 Herbert Xu <herbert@gondor.apana.org.au>
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the Free
8 * Software Foundation; either version 2 of the License, or (at your option)
9 * any later version.
10 *
11 */
12
13#ifndef _CRYPTO_IF_ALG_H
14#define _CRYPTO_IF_ALG_H
15
16#include <linux/compiler.h>
17#include <linux/completion.h>
18#include <linux/if_alg.h>
19#include <linux/types.h>
20#include <net/sock.h>
21
22#define ALG_MAX_PAGES 16
23
24struct crypto_async_request;
25
26struct alg_sock {
27 /* struct sock must be the first member of struct alg_sock */
28 struct sock sk;
29
30 struct sock *parent;
31
32 const struct af_alg_type *type;
33 void *private;
34};
35
36struct af_alg_completion {
37 struct completion completion;
38 int err;
39};
40
41struct af_alg_control {
42 struct af_alg_iv *iv;
43 int op;
44};
45
46struct af_alg_type {
47 void *(*bind)(const char *name, u32 type, u32 mask);
48 void (*release)(void *private);
49 int (*setkey)(void *private, const u8 *key, unsigned int keylen);
50 int (*accept)(void *private, struct sock *sk);
51
52 struct proto_ops *ops;
53 struct module *owner;
54 char name[14];
55};
56
57struct af_alg_sgl {
58 struct scatterlist sg[ALG_MAX_PAGES];
59 struct page *pages[ALG_MAX_PAGES];
60};
61
62int af_alg_register_type(const struct af_alg_type *type);
63int af_alg_unregister_type(const struct af_alg_type *type);
64
65int af_alg_release(struct socket *sock);
66int af_alg_accept(struct sock *sk, struct socket *newsock);
67
68int af_alg_make_sg(struct af_alg_sgl *sgl, void __user *addr, int len,
69 int write);
70void af_alg_free_sg(struct af_alg_sgl *sgl);
71
72int af_alg_cmsg_send(struct msghdr *msg, struct af_alg_control *con);
73
74int af_alg_wait_for_completion(int err, struct af_alg_completion *completion);
75void af_alg_complete(struct crypto_async_request *req, int err);
76
77static inline struct alg_sock *alg_sk(struct sock *sk)
78{
79 return (struct alg_sock *)sk;
80}
81
82static inline void af_alg_release_parent(struct sock *sk)
83{
84 sock_put(alg_sk(sk)->parent);
85}
86
87static inline void af_alg_init_completion(struct af_alg_completion *completion)
88{
89 init_completion(&completion->completion);
90}
91
92#endif /* _CRYPTO_IF_ALG_H */
diff --git a/drivers/crypto/padlock.h b/include/crypto/padlock.h
index b728e4518bd1..d2cfa2ef49e8 100644
--- a/drivers/crypto/padlock.h
+++ b/include/crypto/padlock.h
@@ -15,9 +15,15 @@
15 15
16#define PADLOCK_ALIGNMENT 16 16#define PADLOCK_ALIGNMENT 16
17 17
18#define PFX "padlock: " 18#define PFX KBUILD_MODNAME ": "
19 19
20#define PADLOCK_CRA_PRIORITY 300 20#define PADLOCK_CRA_PRIORITY 300
21#define PADLOCK_COMPOSITE_PRIORITY 400 21#define PADLOCK_COMPOSITE_PRIORITY 400
22 22
23#ifdef CONFIG_64BIT
24#define STACK_ALIGN 16
25#else
26#define STACK_ALIGN 4
27#endif
28
23#endif /* _CRYPTO_PADLOCK_H */ 29#endif /* _CRYPTO_PADLOCK_H */
diff --git a/include/crypto/scatterwalk.h b/include/crypto/scatterwalk.h
index 833d208c25d6..4fd95a323beb 100644
--- a/include/crypto/scatterwalk.h
+++ b/include/crypto/scatterwalk.h
@@ -68,6 +68,21 @@ static inline struct scatterlist *scatterwalk_sg_next(struct scatterlist *sg)
68 return (++sg)->length ? sg : (void *)sg_page(sg); 68 return (++sg)->length ? sg : (void *)sg_page(sg);
69} 69}
70 70
71static inline void scatterwalk_crypto_chain(struct scatterlist *head,
72 struct scatterlist *sg,
73 int chain, int num)
74{
75 if (chain) {
76 head->length += sg->length;
77 sg = scatterwalk_sg_next(sg);
78 }
79
80 if (sg)
81 scatterwalk_sg_chain(head, num, sg);
82 else
83 sg_mark_end(head);
84}
85
71static inline unsigned long scatterwalk_samebuf(struct scatter_walk *walk_in, 86static inline unsigned long scatterwalk_samebuf(struct scatter_walk *walk_in,
72 struct scatter_walk *walk_out) 87 struct scatter_walk *walk_out)
73{ 88{
diff --git a/include/linux/Kbuild b/include/linux/Kbuild
index d1580c17cab3..2296d8b1931f 100644
--- a/include/linux/Kbuild
+++ b/include/linux/Kbuild
@@ -158,6 +158,7 @@ header-y += icmpv6.h
158header-y += if.h 158header-y += if.h
159header-y += if_addr.h 159header-y += if_addr.h
160header-y += if_addrlabel.h 160header-y += if_addrlabel.h
161header-y += if_alg.h
161header-y += if_arcnet.h 162header-y += if_arcnet.h
162header-y += if_arp.h 163header-y += if_arp.h
163header-y += if_bonding.h 164header-y += if_bonding.h
diff --git a/include/linux/binfmts.h b/include/linux/binfmts.h
index 64a7114a9394..c3d6512eded1 100644
--- a/include/linux/binfmts.h
+++ b/include/linux/binfmts.h
@@ -25,7 +25,7 @@ struct pt_regs;
25/* 25/*
26 * This structure is used to hold the arguments that are used when loading binaries. 26 * This structure is used to hold the arguments that are used when loading binaries.
27 */ 27 */
28struct linux_binprm{ 28struct linux_binprm {
29 char buf[BINPRM_BUF_SIZE]; 29 char buf[BINPRM_BUF_SIZE];
30#ifdef CONFIG_MMU 30#ifdef CONFIG_MMU
31 struct vm_area_struct *vma; 31 struct vm_area_struct *vma;
@@ -93,7 +93,6 @@ struct linux_binfmt {
93 int (*load_shlib)(struct file *); 93 int (*load_shlib)(struct file *);
94 int (*core_dump)(struct coredump_params *cprm); 94 int (*core_dump)(struct coredump_params *cprm);
95 unsigned long min_coredump; /* minimal dump size */ 95 unsigned long min_coredump; /* minimal dump size */
96 int hasvdso;
97}; 96};
98 97
99extern int __register_binfmt(struct linux_binfmt *fmt, int insert); 98extern int __register_binfmt(struct linux_binfmt *fmt, int insert);
@@ -113,7 +112,7 @@ extern void unregister_binfmt(struct linux_binfmt *);
113 112
114extern int prepare_binprm(struct linux_binprm *); 113extern int prepare_binprm(struct linux_binprm *);
115extern int __must_check remove_arg_zero(struct linux_binprm *); 114extern int __must_check remove_arg_zero(struct linux_binprm *);
116extern int search_binary_handler(struct linux_binprm *,struct pt_regs *); 115extern int search_binary_handler(struct linux_binprm *, struct pt_regs *);
117extern int flush_old_exec(struct linux_binprm * bprm); 116extern int flush_old_exec(struct linux_binprm * bprm);
118extern void setup_new_exec(struct linux_binprm * bprm); 117extern void setup_new_exec(struct linux_binprm * bprm);
119 118
diff --git a/include/linux/cdev.h b/include/linux/cdev.h
index f389e319a454..fb4591977b03 100644
--- a/include/linux/cdev.h
+++ b/include/linux/cdev.h
@@ -28,8 +28,6 @@ int cdev_add(struct cdev *, dev_t, unsigned);
28 28
29void cdev_del(struct cdev *); 29void cdev_del(struct cdev *);
30 30
31int cdev_index(struct inode *inode);
32
33void cd_forget(struct inode *); 31void cd_forget(struct inode *);
34 32
35extern struct backing_dev_info directly_mappable_cdev_bdi; 33extern struct backing_dev_info directly_mappable_cdev_bdi;
diff --git a/include/linux/ceph/ceph_fs.h b/include/linux/ceph/ceph_fs.h
index c3c74aef289d..09dcc0c2ffd5 100644
--- a/include/linux/ceph/ceph_fs.h
+++ b/include/linux/ceph/ceph_fs.h
@@ -43,6 +43,10 @@
43#define CEPH_FEATURE_NOSRCADDR (1<<1) 43#define CEPH_FEATURE_NOSRCADDR (1<<1)
44#define CEPH_FEATURE_MONCLOCKCHECK (1<<2) 44#define CEPH_FEATURE_MONCLOCKCHECK (1<<2)
45#define CEPH_FEATURE_FLOCK (1<<3) 45#define CEPH_FEATURE_FLOCK (1<<3)
46#define CEPH_FEATURE_SUBSCRIBE2 (1<<4)
47#define CEPH_FEATURE_MONNAMES (1<<5)
48#define CEPH_FEATURE_RECONNECT_SEQ (1<<6)
49#define CEPH_FEATURE_DIRLAYOUTHASH (1<<7)
46 50
47 51
48/* 52/*
@@ -55,10 +59,10 @@ struct ceph_file_layout {
55 __le32 fl_stripe_count; /* over this many objects */ 59 __le32 fl_stripe_count; /* over this many objects */
56 __le32 fl_object_size; /* until objects are this big, then move to 60 __le32 fl_object_size; /* until objects are this big, then move to
57 new objects */ 61 new objects */
58 __le32 fl_cas_hash; /* 0 = none; 1 = sha256 */ 62 __le32 fl_cas_hash; /* UNUSED. 0 = none; 1 = sha256 */
59 63
60 /* pg -> disk layout */ 64 /* pg -> disk layout */
61 __le32 fl_object_stripe_unit; /* for per-object parity, if any */ 65 __le32 fl_object_stripe_unit; /* UNUSED. for per-object parity, if any */
62 66
63 /* object -> pg layout */ 67 /* object -> pg layout */
64 __le32 fl_pg_preferred; /* preferred primary for pg (-1 for none) */ 68 __le32 fl_pg_preferred; /* preferred primary for pg (-1 for none) */
@@ -69,6 +73,12 @@ struct ceph_file_layout {
69 73
70int ceph_file_layout_is_valid(const struct ceph_file_layout *layout); 74int ceph_file_layout_is_valid(const struct ceph_file_layout *layout);
71 75
76struct ceph_dir_layout {
77 __u8 dl_dir_hash; /* see ceph_hash.h for ids */
78 __u8 dl_unused1;
79 __u16 dl_unused2;
80 __u32 dl_unused3;
81} __attribute__ ((packed));
72 82
73/* crypto algorithms */ 83/* crypto algorithms */
74#define CEPH_CRYPTO_NONE 0x0 84#define CEPH_CRYPTO_NONE 0x0
@@ -457,7 +467,7 @@ struct ceph_mds_reply_inode {
457 struct ceph_timespec rctime; 467 struct ceph_timespec rctime;
458 struct ceph_frag_tree_head fragtree; /* (must be at end of struct) */ 468 struct ceph_frag_tree_head fragtree; /* (must be at end of struct) */
459} __attribute__ ((packed)); 469} __attribute__ ((packed));
460/* followed by frag array, then symlink string, then xattr blob */ 470/* followed by frag array, symlink string, dir layout, xattr blob */
461 471
462/* reply_lease follows dname, and reply_inode */ 472/* reply_lease follows dname, and reply_inode */
463struct ceph_mds_reply_lease { 473struct ceph_mds_reply_lease {
diff --git a/include/linux/ceph/messenger.h b/include/linux/ceph/messenger.h
index a108b425fee2..c3011beac30d 100644
--- a/include/linux/ceph/messenger.h
+++ b/include/linux/ceph/messenger.h
@@ -110,17 +110,12 @@ struct ceph_msg_pos {
110 110
111/* 111/*
112 * ceph_connection state bit flags 112 * ceph_connection state bit flags
113 *
114 * QUEUED and BUSY are used together to ensure that only a single
115 * thread is currently opening, reading or writing data to the socket.
116 */ 113 */
117#define LOSSYTX 0 /* we can close channel or drop messages on errors */ 114#define LOSSYTX 0 /* we can close channel or drop messages on errors */
118#define CONNECTING 1 115#define CONNECTING 1
119#define NEGOTIATING 2 116#define NEGOTIATING 2
120#define KEEPALIVE_PENDING 3 117#define KEEPALIVE_PENDING 3
121#define WRITE_PENDING 4 /* we have data ready to send */ 118#define WRITE_PENDING 4 /* we have data ready to send */
122#define QUEUED 5 /* there is work queued on this connection */
123#define BUSY 6 /* work is being done */
124#define STANDBY 8 /* no outgoing messages, socket closed. we keep 119#define STANDBY 8 /* no outgoing messages, socket closed. we keep
125 * the ceph_connection around to maintain shared 120 * the ceph_connection around to maintain shared
126 * state with the peer. */ 121 * state with the peer. */
diff --git a/include/linux/cgroup.h b/include/linux/cgroup.h
index ed4ba111bc8d..ce104e33cd22 100644
--- a/include/linux/cgroup.h
+++ b/include/linux/cgroup.h
@@ -564,7 +564,7 @@ struct cgroup_iter {
564/* 564/*
565 * To iterate across the tasks in a cgroup: 565 * To iterate across the tasks in a cgroup:
566 * 566 *
567 * 1) call cgroup_iter_start to intialize an iterator 567 * 1) call cgroup_iter_start to initialize an iterator
568 * 568 *
569 * 2) call cgroup_iter_next() to retrieve member tasks until it 569 * 2) call cgroup_iter_next() to retrieve member tasks until it
570 * returns NULL or until you want to end the iteration 570 * returns NULL or until you want to end the iteration
diff --git a/include/linux/cramfs_fs.h b/include/linux/cramfs_fs.h
index 6fc2bed368b8..0e7bf272ec2f 100644
--- a/include/linux/cramfs_fs.h
+++ b/include/linux/cramfs_fs.h
@@ -84,9 +84,11 @@ struct cramfs_super {
84 | CRAMFS_FLAG_WRONG_SIGNATURE \ 84 | CRAMFS_FLAG_WRONG_SIGNATURE \
85 | CRAMFS_FLAG_SHIFTED_ROOT_OFFSET ) 85 | CRAMFS_FLAG_SHIFTED_ROOT_OFFSET )
86 86
87#ifdef __KERNEL__
87/* Uncompression interfaces to the underlying zlib */ 88/* Uncompression interfaces to the underlying zlib */
88int cramfs_uncompress_block(void *dst, int dstlen, void *src, int srclen); 89int cramfs_uncompress_block(void *dst, int dstlen, void *src, int srclen);
89int cramfs_uncompress_init(void); 90int cramfs_uncompress_init(void);
90void cramfs_uncompress_exit(void); 91void cramfs_uncompress_exit(void);
92#endif /* __KERNEL__ */
91 93
92#endif 94#endif
diff --git a/include/linux/cs5535.h b/include/linux/cs5535.h
index d5a1d4810b80..6fe2114f8ad2 100644
--- a/include/linux/cs5535.h
+++ b/include/linux/cs5535.h
@@ -103,14 +103,20 @@ static inline int cs5535_has_vsa2(void)
103#define GPIO_POSITIVE_EDGE_STS 0x48 103#define GPIO_POSITIVE_EDGE_STS 0x48
104#define GPIO_NEGATIVE_EDGE_STS 0x4C 104#define GPIO_NEGATIVE_EDGE_STS 0x4C
105 105
106#define GPIO_FLTR7_AMOUNT 0xD8
107
106#define GPIO_MAP_X 0xE0 108#define GPIO_MAP_X 0xE0
107#define GPIO_MAP_Y 0xE4 109#define GPIO_MAP_Y 0xE4
108#define GPIO_MAP_Z 0xE8 110#define GPIO_MAP_Z 0xE8
109#define GPIO_MAP_W 0xEC 111#define GPIO_MAP_W 0xEC
110 112
113#define GPIO_FE7_SEL 0xF7
114
111void cs5535_gpio_set(unsigned offset, unsigned int reg); 115void cs5535_gpio_set(unsigned offset, unsigned int reg);
112void cs5535_gpio_clear(unsigned offset, unsigned int reg); 116void cs5535_gpio_clear(unsigned offset, unsigned int reg);
113int cs5535_gpio_isset(unsigned offset, unsigned int reg); 117int cs5535_gpio_isset(unsigned offset, unsigned int reg);
118int cs5535_gpio_set_irq(unsigned group, unsigned irq);
119void cs5535_gpio_setup_event(unsigned offset, int pair, int pme);
114 120
115/* MFGPTs */ 121/* MFGPTs */
116 122
diff --git a/include/linux/decompress/inflate.h b/include/linux/decompress/inflate.h
index f9b06ccc3e5c..8c0aef1ba5f5 100644
--- a/include/linux/decompress/inflate.h
+++ b/include/linux/decompress/inflate.h
@@ -1,9 +1,6 @@
1#ifndef INFLATE_H 1#ifndef INFLATE_H
2#define INFLATE_H 2#define INFLATE_H
3 3
4/* Other housekeeping constants */
5#define INBUFSIZ 4096
6
7int gunzip(unsigned char *inbuf, int len, 4int gunzip(unsigned char *inbuf, int len,
8 int(*fill)(void*, unsigned int), 5 int(*fill)(void*, unsigned int),
9 int(*flush)(void*, unsigned int), 6 int(*flush)(void*, unsigned int),
diff --git a/include/linux/decompress/mm.h b/include/linux/decompress/mm.h
index ad5ec1d0475e..4cb72b920c74 100644
--- a/include/linux/decompress/mm.h
+++ b/include/linux/decompress/mm.h
@@ -61,8 +61,6 @@ static void free(void *where)
61#define large_malloc(a) malloc(a) 61#define large_malloc(a) malloc(a)
62#define large_free(a) free(a) 62#define large_free(a) free(a)
63 63
64#define set_error_fn(x)
65
66#define INIT 64#define INIT
67 65
68#else /* STATIC */ 66#else /* STATIC */
@@ -72,6 +70,7 @@ static void free(void *where)
72#include <linux/kernel.h> 70#include <linux/kernel.h>
73#include <linux/fs.h> 71#include <linux/fs.h>
74#include <linux/string.h> 72#include <linux/string.h>
73#include <linux/slab.h>
75#include <linux/vmalloc.h> 74#include <linux/vmalloc.h>
76 75
77/* Use defines rather than static inline in order to avoid spurious 76/* Use defines rather than static inline in order to avoid spurious
@@ -84,9 +83,6 @@ static void free(void *where)
84#define large_malloc(a) vmalloc(a) 83#define large_malloc(a) vmalloc(a)
85#define large_free(a) vfree(a) 84#define large_free(a) vfree(a)
86 85
87static void(*error)(char *m);
88#define set_error_fn(x) error = x;
89
90#define INIT __init 86#define INIT __init
91#define STATIC 87#define STATIC
92 88
diff --git a/include/linux/decompress/unxz.h b/include/linux/decompress/unxz.h
new file mode 100644
index 000000000000..41728fc6c8a1
--- /dev/null
+++ b/include/linux/decompress/unxz.h
@@ -0,0 +1,19 @@
1/*
2 * Wrapper for decompressing XZ-compressed kernel, initramfs, and initrd
3 *
4 * Author: Lasse Collin <lasse.collin@tukaani.org>
5 *
6 * This file has been put into the public domain.
7 * You can do whatever you want with this file.
8 */
9
10#ifndef DECOMPRESS_UNXZ_H
11#define DECOMPRESS_UNXZ_H
12
13int unxz(unsigned char *in, int in_size,
14 int (*fill)(void *dest, unsigned int size),
15 int (*flush)(void *src, unsigned int size),
16 unsigned char *out, int *in_used,
17 void (*error)(char *x));
18
19#endif
diff --git a/include/linux/falloc.h b/include/linux/falloc.h
index 3c155107d61f..73e0b628e058 100644
--- a/include/linux/falloc.h
+++ b/include/linux/falloc.h
@@ -2,6 +2,7 @@
2#define _FALLOC_H_ 2#define _FALLOC_H_
3 3
4#define FALLOC_FL_KEEP_SIZE 0x01 /* default is extend size */ 4#define FALLOC_FL_KEEP_SIZE 0x01 /* default is extend size */
5#define FALLOC_FL_PUNCH_HOLE 0x02 /* de-allocates range */
5 6
6#ifdef __KERNEL__ 7#ifdef __KERNEL__
7 8
diff --git a/include/linux/firewire-cdev.h b/include/linux/firewire-cdev.h
index 68c642d8843d..59ea406be7f6 100644
--- a/include/linux/firewire-cdev.h
+++ b/include/linux/firewire-cdev.h
@@ -273,7 +273,7 @@ struct fw_cdev_event_iso_interrupt {
273 * @closure: See &fw_cdev_event_common; 273 * @closure: See &fw_cdev_event_common;
274 * set by %FW_CDEV_CREATE_ISO_CONTEXT ioctl 274 * set by %FW_CDEV_CREATE_ISO_CONTEXT ioctl
275 * @type: %FW_CDEV_EVENT_ISO_INTERRUPT_MULTICHANNEL 275 * @type: %FW_CDEV_EVENT_ISO_INTERRUPT_MULTICHANNEL
276 * @completed: Offset into the receive buffer; data before this offest is valid 276 * @completed: Offset into the receive buffer; data before this offset is valid
277 * 277 *
278 * This event is sent in multichannel contexts (context type 278 * This event is sent in multichannel contexts (context type
279 * %FW_CDEV_ISO_CONTEXT_RECEIVE_MULTICHANNEL) for &fw_cdev_iso_packet buffer 279 * %FW_CDEV_ISO_CONTEXT_RECEIVE_MULTICHANNEL) for &fw_cdev_iso_packet buffer
diff --git a/include/linux/fs.h b/include/linux/fs.h
index f84d9928bdb1..c0701288d204 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -1423,6 +1423,7 @@ struct super_block {
1423 * generic_show_options() 1423 * generic_show_options()
1424 */ 1424 */
1425 char __rcu *s_options; 1425 char __rcu *s_options;
1426 const struct dentry_operations *s_d_op; /* default d_op for dentries */
1426}; 1427};
1427 1428
1428extern struct timespec current_fs_time(struct super_block *sb); 1429extern struct timespec current_fs_time(struct super_block *sb);
@@ -1834,7 +1835,9 @@ struct super_block *sget(struct file_system_type *type,
1834 int (*set)(struct super_block *,void *), 1835 int (*set)(struct super_block *,void *),
1835 void *data); 1836 void *data);
1836extern struct dentry *mount_pseudo(struct file_system_type *, char *, 1837extern struct dentry *mount_pseudo(struct file_system_type *, char *,
1837 const struct super_operations *ops, unsigned long); 1838 const struct super_operations *ops,
1839 const struct dentry_operations *dops,
1840 unsigned long);
1838extern void simple_set_mnt(struct vfsmount *mnt, struct super_block *sb); 1841extern void simple_set_mnt(struct vfsmount *mnt, struct super_block *sb);
1839 1842
1840static inline void sb_mark_dirty(struct super_block *sb) 1843static inline void sb_mark_dirty(struct super_block *sb)
diff --git a/include/linux/gpio.h b/include/linux/gpio.h
index e41f7dd1ae67..f79d67f413e4 100644
--- a/include/linux/gpio.h
+++ b/include/linux/gpio.h
@@ -13,6 +13,7 @@
13#include <linux/errno.h> 13#include <linux/errno.h>
14 14
15struct device; 15struct device;
16struct gpio;
16struct gpio_chip; 17struct gpio_chip;
17 18
18/* 19/*
@@ -29,7 +30,18 @@ static inline int gpio_is_valid(int number)
29 return 0; 30 return 0;
30} 31}
31 32
32static inline int gpio_request(unsigned gpio, const char *label) 33static inline int __must_check gpio_request(unsigned gpio, const char *label)
34{
35 return -ENOSYS;
36}
37
38static inline int __must_check gpio_request_one(unsigned gpio,
39 unsigned long flags, const char *label)
40{
41 return -ENOSYS;
42}
43
44static inline int __must_check gpio_request_array(struct gpio *array, size_t num)
33{ 45{
34 return -ENOSYS; 46 return -ENOSYS;
35} 47}
@@ -42,12 +54,20 @@ static inline void gpio_free(unsigned gpio)
42 WARN_ON(1); 54 WARN_ON(1);
43} 55}
44 56
45static inline int gpio_direction_input(unsigned gpio) 57static inline void gpio_free_array(struct gpio *array, size_t num)
58{
59 might_sleep();
60
61 /* GPIO can never have been requested */
62 WARN_ON(1);
63}
64
65static inline int __must_check gpio_direction_input(unsigned gpio)
46{ 66{
47 return -ENOSYS; 67 return -ENOSYS;
48} 68}
49 69
50static inline int gpio_direction_output(unsigned gpio, int value) 70static inline int __must_check gpio_direction_output(unsigned gpio, int value)
51{ 71{
52 return -ENOSYS; 72 return -ENOSYS;
53} 73}
diff --git a/include/linux/hid.h b/include/linux/hid.h
index 20b9801f669b..d91c25e253c8 100644
--- a/include/linux/hid.h
+++ b/include/linux/hid.h
@@ -402,7 +402,7 @@ struct hid_field {
402 __u16 dpad; /* dpad input code */ 402 __u16 dpad; /* dpad input code */
403}; 403};
404 404
405#define HID_MAX_FIELDS 64 405#define HID_MAX_FIELDS 128
406 406
407struct hid_report { 407struct hid_report {
408 struct list_head list; 408 struct list_head list;
@@ -593,6 +593,7 @@ struct hid_usage_id {
593 * @report_fixup: called before report descriptor parsing (NULL means nop) 593 * @report_fixup: called before report descriptor parsing (NULL means nop)
594 * @input_mapping: invoked on input registering before mapping an usage 594 * @input_mapping: invoked on input registering before mapping an usage
595 * @input_mapped: invoked on input registering after mapping an usage 595 * @input_mapped: invoked on input registering after mapping an usage
596 * @feature_mapping: invoked on feature registering
596 * @suspend: invoked on suspend (NULL means nop) 597 * @suspend: invoked on suspend (NULL means nop)
597 * @resume: invoked on resume if device was not reset (NULL means nop) 598 * @resume: invoked on resume if device was not reset (NULL means nop)
598 * @reset_resume: invoked on resume if device was reset (NULL means nop) 599 * @reset_resume: invoked on resume if device was reset (NULL means nop)
@@ -636,6 +637,9 @@ struct hid_driver {
636 int (*input_mapped)(struct hid_device *hdev, 637 int (*input_mapped)(struct hid_device *hdev,
637 struct hid_input *hidinput, struct hid_field *field, 638 struct hid_input *hidinput, struct hid_field *field,
638 struct hid_usage *usage, unsigned long **bit, int *max); 639 struct hid_usage *usage, unsigned long **bit, int *max);
640 void (*feature_mapping)(struct hid_device *hdev,
641 struct hid_input *hidinput, struct hid_field *field,
642 struct hid_usage *usage);
639#ifdef CONFIG_PM 643#ifdef CONFIG_PM
640 int (*suspend)(struct hid_device *hdev, pm_message_t message); 644 int (*suspend)(struct hid_device *hdev, pm_message_t message);
641 int (*resume)(struct hid_device *hdev); 645 int (*resume)(struct hid_device *hdev);
diff --git a/include/linux/if_alg.h b/include/linux/if_alg.h
new file mode 100644
index 000000000000..0f9acce5b1ff
--- /dev/null
+++ b/include/linux/if_alg.h
@@ -0,0 +1,40 @@
1/*
2 * if_alg: User-space algorithm interface
3 *
4 * Copyright (c) 2010 Herbert Xu <herbert@gondor.apana.org.au>
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the Free
8 * Software Foundation; either version 2 of the License, or (at your option)
9 * any later version.
10 *
11 */
12
13#ifndef _LINUX_IF_ALG_H
14#define _LINUX_IF_ALG_H
15
16#include <linux/types.h>
17
18struct sockaddr_alg {
19 __u16 salg_family;
20 __u8 salg_type[14];
21 __u32 salg_feat;
22 __u32 salg_mask;
23 __u8 salg_name[64];
24};
25
26struct af_alg_iv {
27 __u32 ivlen;
28 __u8 iv[0];
29};
30
31/* Socket options */
32#define ALG_SET_KEY 1
33#define ALG_SET_IV 2
34#define ALG_SET_OP 3
35
36/* Operations */
37#define ALG_OP_DECRYPT 0
38#define ALG_OP_ENCRYPT 1
39
40#endif /* _LINUX_IF_ALG_H */
diff --git a/include/linux/input.h b/include/linux/input.h
index c4e9d91ec979..e428382ca28a 100644
--- a/include/linux/input.h
+++ b/include/linux/input.h
@@ -802,6 +802,7 @@ struct input_keymap_entry {
802#define SW_CAMERA_LENS_COVER 0x09 /* set = lens covered */ 802#define SW_CAMERA_LENS_COVER 0x09 /* set = lens covered */
803#define SW_KEYPAD_SLIDE 0x0a /* set = keypad slide out */ 803#define SW_KEYPAD_SLIDE 0x0a /* set = keypad slide out */
804#define SW_FRONT_PROXIMITY 0x0b /* set = front proximity sensor active */ 804#define SW_FRONT_PROXIMITY 0x0b /* set = front proximity sensor active */
805#define SW_ROTATE_LOCK 0x0c /* set = rotate locked/disabled */
805#define SW_MAX 0x0f 806#define SW_MAX 0x0f
806#define SW_CNT (SW_MAX+1) 807#define SW_CNT (SW_MAX+1)
807 808
diff --git a/include/linux/input/as5011.h b/include/linux/input/as5011.h
new file mode 100644
index 000000000000..1affd0ddfa9d
--- /dev/null
+++ b/include/linux/input/as5011.h
@@ -0,0 +1,20 @@
1#ifndef _AS5011_H
2#define _AS5011_H
3
4/*
5 * Copyright (c) 2010, 2011 Fabien Marteau <fabien.marteau@armadeus.com>
6 *
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License version 2 as published by
9 * the Free Software Foundation.
10 */
11
12struct as5011_platform_data {
13 unsigned int button_gpio;
14 unsigned int axis_irq; /* irq number */
15 unsigned long axis_irqflags;
16 char xp, xn; /* threshold for x axis */
17 char yp, yn; /* threshold for y axis */
18};
19
20#endif /* _AS5011_H */
diff --git a/include/linux/kernel.h b/include/linux/kernel.h
index d0fbc043de60..57dac7022b63 100644
--- a/include/linux/kernel.h
+++ b/include/linux/kernel.h
@@ -143,9 +143,22 @@ extern int _cond_resched(void);
143 143
144#define might_sleep_if(cond) do { if (cond) might_sleep(); } while (0) 144#define might_sleep_if(cond) do { if (cond) might_sleep(); } while (0)
145 145
146#define abs(x) ({ \ 146/*
147 long __x = (x); \ 147 * abs() handles unsigned and signed longs, ints, shorts and chars. For all
148 (__x < 0) ? -__x : __x; \ 148 * input types abs() returns a signed long.
149 * abs() should not be used for 64-bit types (s64, u64, long long) - use abs64()
150 * for those.
151 */
152#define abs(x) ({ \
153 long ret; \
154 if (sizeof(x) == sizeof(long)) { \
155 long __x = (x); \
156 ret = (__x < 0) ? -__x : __x; \
157 } else { \
158 int __x = (x); \
159 ret = (__x < 0) ? -__x : __x; \
160 } \
161 ret; \
149 }) 162 })
150 163
151#define abs64(x) ({ \ 164#define abs64(x) ({ \
diff --git a/include/linux/kmsg_dump.h b/include/linux/kmsg_dump.h
index 24b44145a886..2a0d7d651dc3 100644
--- a/include/linux/kmsg_dump.h
+++ b/include/linux/kmsg_dump.h
@@ -18,6 +18,10 @@ enum kmsg_dump_reason {
18 KMSG_DUMP_OOPS, 18 KMSG_DUMP_OOPS,
19 KMSG_DUMP_PANIC, 19 KMSG_DUMP_PANIC,
20 KMSG_DUMP_KEXEC, 20 KMSG_DUMP_KEXEC,
21 KMSG_DUMP_RESTART,
22 KMSG_DUMP_HALT,
23 KMSG_DUMP_POWEROFF,
24 KMSG_DUMP_EMERG,
21}; 25};
22 26
23/** 27/**
diff --git a/include/linux/kvm.h b/include/linux/kvm.h
index 919ae53adc5c..ea2dc1a2e13d 100644
--- a/include/linux/kvm.h
+++ b/include/linux/kvm.h
@@ -540,6 +540,7 @@ struct kvm_ppc_pvinfo {
540#endif 540#endif
541#define KVM_CAP_PPC_GET_PVINFO 57 541#define KVM_CAP_PPC_GET_PVINFO 57
542#define KVM_CAP_PPC_IRQ_LEVEL 58 542#define KVM_CAP_PPC_IRQ_LEVEL 58
543#define KVM_CAP_ASYNC_PF 59
543 544
544#ifdef KVM_CAP_IRQ_ROUTING 545#ifdef KVM_CAP_IRQ_ROUTING
545 546
diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
index a0557422715e..b5021db21858 100644
--- a/include/linux/kvm_host.h
+++ b/include/linux/kvm_host.h
@@ -16,6 +16,8 @@
16#include <linux/mm.h> 16#include <linux/mm.h>
17#include <linux/preempt.h> 17#include <linux/preempt.h>
18#include <linux/msi.h> 18#include <linux/msi.h>
19#include <linux/slab.h>
20#include <linux/rcupdate.h>
19#include <asm/signal.h> 21#include <asm/signal.h>
20 22
21#include <linux/kvm.h> 23#include <linux/kvm.h>
@@ -40,6 +42,7 @@
40#define KVM_REQ_KICK 9 42#define KVM_REQ_KICK 9
41#define KVM_REQ_DEACTIVATE_FPU 10 43#define KVM_REQ_DEACTIVATE_FPU 10
42#define KVM_REQ_EVENT 11 44#define KVM_REQ_EVENT 11
45#define KVM_REQ_APF_HALT 12
43 46
44#define KVM_USERSPACE_IRQ_SOURCE_ID 0 47#define KVM_USERSPACE_IRQ_SOURCE_ID 0
45 48
@@ -74,6 +77,27 @@ int kvm_io_bus_register_dev(struct kvm *kvm, enum kvm_bus bus_idx,
74int kvm_io_bus_unregister_dev(struct kvm *kvm, enum kvm_bus bus_idx, 77int kvm_io_bus_unregister_dev(struct kvm *kvm, enum kvm_bus bus_idx,
75 struct kvm_io_device *dev); 78 struct kvm_io_device *dev);
76 79
80#ifdef CONFIG_KVM_ASYNC_PF
81struct kvm_async_pf {
82 struct work_struct work;
83 struct list_head link;
84 struct list_head queue;
85 struct kvm_vcpu *vcpu;
86 struct mm_struct *mm;
87 gva_t gva;
88 unsigned long addr;
89 struct kvm_arch_async_pf arch;
90 struct page *page;
91 bool done;
92};
93
94void kvm_clear_async_pf_completion_queue(struct kvm_vcpu *vcpu);
95void kvm_check_async_pf_completion(struct kvm_vcpu *vcpu);
96int kvm_setup_async_pf(struct kvm_vcpu *vcpu, gva_t gva, gfn_t gfn,
97 struct kvm_arch_async_pf *arch);
98int kvm_async_pf_wakeup_all(struct kvm_vcpu *vcpu);
99#endif
100
77struct kvm_vcpu { 101struct kvm_vcpu {
78 struct kvm *kvm; 102 struct kvm *kvm;
79#ifdef CONFIG_PREEMPT_NOTIFIERS 103#ifdef CONFIG_PREEMPT_NOTIFIERS
@@ -104,6 +128,15 @@ struct kvm_vcpu {
104 gpa_t mmio_phys_addr; 128 gpa_t mmio_phys_addr;
105#endif 129#endif
106 130
131#ifdef CONFIG_KVM_ASYNC_PF
132 struct {
133 u32 queued;
134 struct list_head queue;
135 struct list_head done;
136 spinlock_t lock;
137 } async_pf;
138#endif
139
107 struct kvm_vcpu_arch arch; 140 struct kvm_vcpu_arch arch;
108}; 141};
109 142
@@ -113,16 +146,19 @@ struct kvm_vcpu {
113 */ 146 */
114#define KVM_MEM_MAX_NR_PAGES ((1UL << 31) - 1) 147#define KVM_MEM_MAX_NR_PAGES ((1UL << 31) - 1)
115 148
149struct kvm_lpage_info {
150 unsigned long rmap_pde;
151 int write_count;
152};
153
116struct kvm_memory_slot { 154struct kvm_memory_slot {
117 gfn_t base_gfn; 155 gfn_t base_gfn;
118 unsigned long npages; 156 unsigned long npages;
119 unsigned long flags; 157 unsigned long flags;
120 unsigned long *rmap; 158 unsigned long *rmap;
121 unsigned long *dirty_bitmap; 159 unsigned long *dirty_bitmap;
122 struct { 160 unsigned long *dirty_bitmap_head;
123 unsigned long rmap_pde; 161 struct kvm_lpage_info *lpage_info[KVM_NR_PAGE_SIZES - 1];
124 int write_count;
125 } *lpage_info[KVM_NR_PAGE_SIZES - 1];
126 unsigned long userspace_addr; 162 unsigned long userspace_addr;
127 int user_alloc; 163 int user_alloc;
128 int id; 164 int id;
@@ -169,6 +205,7 @@ struct kvm_irq_routing_table {};
169 205
170struct kvm_memslots { 206struct kvm_memslots {
171 int nmemslots; 207 int nmemslots;
208 u64 generation;
172 struct kvm_memory_slot memslots[KVM_MEMORY_SLOTS + 209 struct kvm_memory_slot memslots[KVM_MEMORY_SLOTS +
173 KVM_PRIVATE_MEM_SLOTS]; 210 KVM_PRIVATE_MEM_SLOTS];
174}; 211};
@@ -206,6 +243,10 @@ struct kvm {
206 243
207 struct mutex irq_lock; 244 struct mutex irq_lock;
208#ifdef CONFIG_HAVE_KVM_IRQCHIP 245#ifdef CONFIG_HAVE_KVM_IRQCHIP
246 /*
247 * Update side is protected by irq_lock and,
248 * if configured, irqfds.lock.
249 */
209 struct kvm_irq_routing_table __rcu *irq_routing; 250 struct kvm_irq_routing_table __rcu *irq_routing;
210 struct hlist_head mask_notifier_list; 251 struct hlist_head mask_notifier_list;
211 struct hlist_head irq_ack_notifier_list; 252 struct hlist_head irq_ack_notifier_list;
@@ -216,6 +257,7 @@ struct kvm {
216 unsigned long mmu_notifier_seq; 257 unsigned long mmu_notifier_seq;
217 long mmu_notifier_count; 258 long mmu_notifier_count;
218#endif 259#endif
260 long tlbs_dirty;
219}; 261};
220 262
221/* The guest did something we don't support. */ 263/* The guest did something we don't support. */
@@ -302,7 +344,11 @@ void kvm_set_page_accessed(struct page *page);
302 344
303pfn_t hva_to_pfn_atomic(struct kvm *kvm, unsigned long addr); 345pfn_t hva_to_pfn_atomic(struct kvm *kvm, unsigned long addr);
304pfn_t gfn_to_pfn_atomic(struct kvm *kvm, gfn_t gfn); 346pfn_t gfn_to_pfn_atomic(struct kvm *kvm, gfn_t gfn);
347pfn_t gfn_to_pfn_async(struct kvm *kvm, gfn_t gfn, bool *async,
348 bool write_fault, bool *writable);
305pfn_t gfn_to_pfn(struct kvm *kvm, gfn_t gfn); 349pfn_t gfn_to_pfn(struct kvm *kvm, gfn_t gfn);
350pfn_t gfn_to_pfn_prot(struct kvm *kvm, gfn_t gfn, bool write_fault,
351 bool *writable);
306pfn_t gfn_to_pfn_memslot(struct kvm *kvm, 352pfn_t gfn_to_pfn_memslot(struct kvm *kvm,
307 struct kvm_memory_slot *slot, gfn_t gfn); 353 struct kvm_memory_slot *slot, gfn_t gfn);
308int memslot_id(struct kvm *kvm, gfn_t gfn); 354int memslot_id(struct kvm *kvm, gfn_t gfn);
@@ -321,18 +367,25 @@ int kvm_write_guest_page(struct kvm *kvm, gfn_t gfn, const void *data,
321 int offset, int len); 367 int offset, int len);
322int kvm_write_guest(struct kvm *kvm, gpa_t gpa, const void *data, 368int kvm_write_guest(struct kvm *kvm, gpa_t gpa, const void *data,
323 unsigned long len); 369 unsigned long len);
370int kvm_write_guest_cached(struct kvm *kvm, struct gfn_to_hva_cache *ghc,
371 void *data, unsigned long len);
372int kvm_gfn_to_hva_cache_init(struct kvm *kvm, struct gfn_to_hva_cache *ghc,
373 gpa_t gpa);
324int kvm_clear_guest_page(struct kvm *kvm, gfn_t gfn, int offset, int len); 374int kvm_clear_guest_page(struct kvm *kvm, gfn_t gfn, int offset, int len);
325int kvm_clear_guest(struct kvm *kvm, gpa_t gpa, unsigned long len); 375int kvm_clear_guest(struct kvm *kvm, gpa_t gpa, unsigned long len);
326struct kvm_memory_slot *gfn_to_memslot(struct kvm *kvm, gfn_t gfn); 376struct kvm_memory_slot *gfn_to_memslot(struct kvm *kvm, gfn_t gfn);
327int kvm_is_visible_gfn(struct kvm *kvm, gfn_t gfn); 377int kvm_is_visible_gfn(struct kvm *kvm, gfn_t gfn);
328unsigned long kvm_host_page_size(struct kvm *kvm, gfn_t gfn); 378unsigned long kvm_host_page_size(struct kvm *kvm, gfn_t gfn);
329void mark_page_dirty(struct kvm *kvm, gfn_t gfn); 379void mark_page_dirty(struct kvm *kvm, gfn_t gfn);
380void mark_page_dirty_in_slot(struct kvm *kvm, struct kvm_memory_slot *memslot,
381 gfn_t gfn);
330 382
331void kvm_vcpu_block(struct kvm_vcpu *vcpu); 383void kvm_vcpu_block(struct kvm_vcpu *vcpu);
332void kvm_vcpu_on_spin(struct kvm_vcpu *vcpu); 384void kvm_vcpu_on_spin(struct kvm_vcpu *vcpu);
333void kvm_resched(struct kvm_vcpu *vcpu); 385void kvm_resched(struct kvm_vcpu *vcpu);
334void kvm_load_guest_fpu(struct kvm_vcpu *vcpu); 386void kvm_load_guest_fpu(struct kvm_vcpu *vcpu);
335void kvm_put_guest_fpu(struct kvm_vcpu *vcpu); 387void kvm_put_guest_fpu(struct kvm_vcpu *vcpu);
388
336void kvm_flush_remote_tlbs(struct kvm *kvm); 389void kvm_flush_remote_tlbs(struct kvm *kvm);
337void kvm_reload_remote_mmus(struct kvm *kvm); 390void kvm_reload_remote_mmus(struct kvm *kvm);
338 391
@@ -398,7 +451,19 @@ int kvm_arch_vcpu_runnable(struct kvm_vcpu *vcpu);
398 451
399void kvm_free_physmem(struct kvm *kvm); 452void kvm_free_physmem(struct kvm *kvm);
400 453
401struct kvm *kvm_arch_create_vm(void); 454#ifndef __KVM_HAVE_ARCH_VM_ALLOC
455static inline struct kvm *kvm_arch_alloc_vm(void)
456{
457 return kzalloc(sizeof(struct kvm), GFP_KERNEL);
458}
459
460static inline void kvm_arch_free_vm(struct kvm *kvm)
461{
462 kfree(kvm);
463}
464#endif
465
466int kvm_arch_init_vm(struct kvm *kvm);
402void kvm_arch_destroy_vm(struct kvm *kvm); 467void kvm_arch_destroy_vm(struct kvm *kvm);
403void kvm_free_all_assigned_devices(struct kvm *kvm); 468void kvm_free_all_assigned_devices(struct kvm *kvm);
404void kvm_arch_sync_events(struct kvm *kvm); 469void kvm_arch_sync_events(struct kvm *kvm);
@@ -414,16 +479,8 @@ struct kvm_irq_ack_notifier {
414 void (*irq_acked)(struct kvm_irq_ack_notifier *kian); 479 void (*irq_acked)(struct kvm_irq_ack_notifier *kian);
415}; 480};
416 481
417#define KVM_ASSIGNED_MSIX_PENDING 0x1
418struct kvm_guest_msix_entry {
419 u32 vector;
420 u16 entry;
421 u16 flags;
422};
423
424struct kvm_assigned_dev_kernel { 482struct kvm_assigned_dev_kernel {
425 struct kvm_irq_ack_notifier ack_notifier; 483 struct kvm_irq_ack_notifier ack_notifier;
426 struct work_struct interrupt_work;
427 struct list_head list; 484 struct list_head list;
428 int assigned_dev_id; 485 int assigned_dev_id;
429 int host_segnr; 486 int host_segnr;
@@ -434,13 +491,14 @@ struct kvm_assigned_dev_kernel {
434 bool host_irq_disabled; 491 bool host_irq_disabled;
435 struct msix_entry *host_msix_entries; 492 struct msix_entry *host_msix_entries;
436 int guest_irq; 493 int guest_irq;
437 struct kvm_guest_msix_entry *guest_msix_entries; 494 struct msix_entry *guest_msix_entries;
438 unsigned long irq_requested_type; 495 unsigned long irq_requested_type;
439 int irq_source_id; 496 int irq_source_id;
440 int flags; 497 int flags;
441 struct pci_dev *dev; 498 struct pci_dev *dev;
442 struct kvm *kvm; 499 struct kvm *kvm;
443 spinlock_t assigned_dev_lock; 500 spinlock_t intx_lock;
501 char irq_name[32];
444}; 502};
445 503
446struct kvm_irq_mask_notifier { 504struct kvm_irq_mask_notifier {
@@ -462,6 +520,8 @@ void kvm_get_intr_delivery_bitmask(struct kvm_ioapic *ioapic,
462 unsigned long *deliver_bitmask); 520 unsigned long *deliver_bitmask);
463#endif 521#endif
464int kvm_set_irq(struct kvm *kvm, int irq_source_id, u32 irq, int level); 522int kvm_set_irq(struct kvm *kvm, int irq_source_id, u32 irq, int level);
523int kvm_set_msi(struct kvm_kernel_irq_routing_entry *irq_entry, struct kvm *kvm,
524 int irq_source_id, int level);
465void kvm_notify_acked_irq(struct kvm *kvm, unsigned irqchip, unsigned pin); 525void kvm_notify_acked_irq(struct kvm *kvm, unsigned irqchip, unsigned pin);
466void kvm_register_irq_ack_notifier(struct kvm *kvm, 526void kvm_register_irq_ack_notifier(struct kvm *kvm,
467 struct kvm_irq_ack_notifier *kian); 527 struct kvm_irq_ack_notifier *kian);
@@ -603,17 +663,28 @@ static inline void kvm_free_irq_routing(struct kvm *kvm) {}
603void kvm_eventfd_init(struct kvm *kvm); 663void kvm_eventfd_init(struct kvm *kvm);
604int kvm_irqfd(struct kvm *kvm, int fd, int gsi, int flags); 664int kvm_irqfd(struct kvm *kvm, int fd, int gsi, int flags);
605void kvm_irqfd_release(struct kvm *kvm); 665void kvm_irqfd_release(struct kvm *kvm);
666void kvm_irq_routing_update(struct kvm *, struct kvm_irq_routing_table *);
606int kvm_ioeventfd(struct kvm *kvm, struct kvm_ioeventfd *args); 667int kvm_ioeventfd(struct kvm *kvm, struct kvm_ioeventfd *args);
607 668
608#else 669#else
609 670
610static inline void kvm_eventfd_init(struct kvm *kvm) {} 671static inline void kvm_eventfd_init(struct kvm *kvm) {}
672
611static inline int kvm_irqfd(struct kvm *kvm, int fd, int gsi, int flags) 673static inline int kvm_irqfd(struct kvm *kvm, int fd, int gsi, int flags)
612{ 674{
613 return -EINVAL; 675 return -EINVAL;
614} 676}
615 677
616static inline void kvm_irqfd_release(struct kvm *kvm) {} 678static inline void kvm_irqfd_release(struct kvm *kvm) {}
679
680#ifdef CONFIG_HAVE_KVM_IRQCHIP
681static inline void kvm_irq_routing_update(struct kvm *kvm,
682 struct kvm_irq_routing_table *irq_rt)
683{
684 rcu_assign_pointer(kvm->irq_routing, irq_rt);
685}
686#endif
687
617static inline int kvm_ioeventfd(struct kvm *kvm, struct kvm_ioeventfd *args) 688static inline int kvm_ioeventfd(struct kvm *kvm, struct kvm_ioeventfd *args)
618{ 689{
619 return -ENOSYS; 690 return -ENOSYS;
diff --git a/include/linux/kvm_types.h b/include/linux/kvm_types.h
index 7ac0d4eee430..fa7cc7244cbd 100644
--- a/include/linux/kvm_types.h
+++ b/include/linux/kvm_types.h
@@ -67,4 +67,11 @@ struct kvm_lapic_irq {
67 u32 dest_id; 67 u32 dest_id;
68}; 68};
69 69
70struct gfn_to_hva_cache {
71 u64 generation;
72 gpa_t gpa;
73 unsigned long hva;
74 struct kvm_memory_slot *memslot;
75};
76
70#endif /* __KVM_TYPES_H__ */ 77#endif /* __KVM_TYPES_H__ */
diff --git a/include/linux/leds-lp5521.h b/include/linux/leds-lp5521.h
index 38368d785f08..fd548d2a8775 100644
--- a/include/linux/leds-lp5521.h
+++ b/include/linux/leds-lp5521.h
@@ -42,6 +42,7 @@ struct lp5521_platform_data {
42 int (*setup_resources)(void); 42 int (*setup_resources)(void);
43 void (*release_resources)(void); 43 void (*release_resources)(void);
44 void (*enable)(bool state); 44 void (*enable)(bool state);
45 const char *label;
45}; 46};
46 47
47#endif /* __LINUX_LP5521_H */ 48#endif /* __LINUX_LP5521_H */
diff --git a/include/linux/leds-lp5523.h b/include/linux/leds-lp5523.h
index 796747637b80..2694289babd0 100644
--- a/include/linux/leds-lp5523.h
+++ b/include/linux/leds-lp5523.h
@@ -42,6 +42,7 @@ struct lp5523_platform_data {
42 int (*setup_resources)(void); 42 int (*setup_resources)(void);
43 void (*release_resources)(void); 43 void (*release_resources)(void);
44 void (*enable)(bool state); 44 void (*enable)(bool state);
45 const char *label;
45}; 46};
46 47
47#endif /* __LINUX_LP5523_H */ 48#endif /* __LINUX_LP5523_H */
diff --git a/include/linux/mfd/ab8500.h b/include/linux/mfd/ab8500.h
index d63b6050b183..85cf2c28fac6 100644
--- a/include/linux/mfd/ab8500.h
+++ b/include/linux/mfd/ab8500.h
@@ -99,8 +99,6 @@
99#define AB8500_NR_IRQS 104 99#define AB8500_NR_IRQS 104
100#define AB8500_NUM_IRQ_REGS 13 100#define AB8500_NUM_IRQ_REGS 13
101 101
102#define AB8500_NUM_REGULATORS 15
103
104/** 102/**
105 * struct ab8500 - ab8500 internal structure 103 * struct ab8500 - ab8500 internal structure
106 * @dev: parent device 104 * @dev: parent device
@@ -145,7 +143,8 @@ struct regulator_init_data;
145struct ab8500_platform_data { 143struct ab8500_platform_data {
146 int irq_base; 144 int irq_base;
147 void (*init) (struct ab8500 *); 145 void (*init) (struct ab8500 *);
148 struct regulator_init_data *regulator[AB8500_NUM_REGULATORS]; 146 int num_regulator;
147 struct regulator_init_data *regulator;
149}; 148};
150 149
151extern int __devinit ab8500_init(struct ab8500 *ab8500); 150extern int __devinit ab8500_init(struct ab8500 *ab8500);
diff --git a/include/linux/mfd/core.h b/include/linux/mfd/core.h
index cb93d80aa642..5582ab3d3e48 100644
--- a/include/linux/mfd/core.h
+++ b/include/linux/mfd/core.h
@@ -39,7 +39,7 @@ struct mfd_cell {
39 size_t data_size; 39 size_t data_size;
40 40
41 /* 41 /*
42 * This resources can be specified relatievly to the parent device. 42 * This resources can be specified relatively to the parent device.
43 * For accessing device you should use resources from device 43 * For accessing device you should use resources from device
44 */ 44 */
45 int num_resources; 45 int num_resources;
diff --git a/include/linux/mfd/mc13783.h b/include/linux/mfd/mc13783.h
index b4c741e352c2..7d0f3d6a0002 100644
--- a/include/linux/mfd/mc13783.h
+++ b/include/linux/mfd/mc13783.h
@@ -1,4 +1,5 @@
1/* 1/*
2 * Copyright 2010 Yong Shen <yong.shen@linaro.org>
2 * Copyright 2009-2010 Pengutronix 3 * Copyright 2009-2010 Pengutronix
3 * Uwe Kleine-Koenig <u.kleine-koenig@pengutronix.de> 4 * Uwe Kleine-Koenig <u.kleine-koenig@pengutronix.de>
4 * 5 *
@@ -122,39 +123,39 @@ int mc13783_adc_do_conversion(struct mc13783 *mc13783, unsigned int mode,
122 unsigned int channel, unsigned int *sample); 123 unsigned int channel, unsigned int *sample);
123 124
124 125
125#define MC13783_SW_SW1A 0 126#define MC13783_REG_SW1A 0
126#define MC13783_SW_SW1B 1 127#define MC13783_REG_SW1B 1
127#define MC13783_SW_SW2A 2 128#define MC13783_REG_SW2A 2
128#define MC13783_SW_SW2B 3 129#define MC13783_REG_SW2B 3
129#define MC13783_SW_SW3 4 130#define MC13783_REG_SW3 4
130#define MC13783_SW_PLL 5 131#define MC13783_REG_PLL 5
131#define MC13783_REGU_VAUDIO 6 132#define MC13783_REG_VAUDIO 6
132#define MC13783_REGU_VIOHI 7 133#define MC13783_REG_VIOHI 7
133#define MC13783_REGU_VIOLO 8 134#define MC13783_REG_VIOLO 8
134#define MC13783_REGU_VDIG 9 135#define MC13783_REG_VDIG 9
135#define MC13783_REGU_VGEN 10 136#define MC13783_REG_VGEN 10
136#define MC13783_REGU_VRFDIG 11 137#define MC13783_REG_VRFDIG 11
137#define MC13783_REGU_VRFREF 12 138#define MC13783_REG_VRFREF 12
138#define MC13783_REGU_VRFCP 13 139#define MC13783_REG_VRFCP 13
139#define MC13783_REGU_VSIM 14 140#define MC13783_REG_VSIM 14
140#define MC13783_REGU_VESIM 15 141#define MC13783_REG_VESIM 15
141#define MC13783_REGU_VCAM 16 142#define MC13783_REG_VCAM 16
142#define MC13783_REGU_VRFBG 17 143#define MC13783_REG_VRFBG 17
143#define MC13783_REGU_VVIB 18 144#define MC13783_REG_VVIB 18
144#define MC13783_REGU_VRF1 19 145#define MC13783_REG_VRF1 19
145#define MC13783_REGU_VRF2 20 146#define MC13783_REG_VRF2 20
146#define MC13783_REGU_VMMC1 21 147#define MC13783_REG_VMMC1 21
147#define MC13783_REGU_VMMC2 22 148#define MC13783_REG_VMMC2 22
148#define MC13783_REGU_GPO1 23 149#define MC13783_REG_GPO1 23
149#define MC13783_REGU_GPO2 24 150#define MC13783_REG_GPO2 24
150#define MC13783_REGU_GPO3 25 151#define MC13783_REG_GPO3 25
151#define MC13783_REGU_GPO4 26 152#define MC13783_REG_GPO4 26
152#define MC13783_REGU_V1 27 153#define MC13783_REG_V1 27
153#define MC13783_REGU_V2 28 154#define MC13783_REG_V2 28
154#define MC13783_REGU_V3 29 155#define MC13783_REG_V3 29
155#define MC13783_REGU_V4 30 156#define MC13783_REG_V4 30
156#define MC13783_REGU_PWGT1SPI 31 157#define MC13783_REG_PWGT1SPI 31
157#define MC13783_REGU_PWGT2SPI 32 158#define MC13783_REG_PWGT2SPI 32
158 159
159#define MC13783_IRQ_ADCDONE MC13XXX_IRQ_ADCDONE 160#define MC13783_IRQ_ADCDONE MC13XXX_IRQ_ADCDONE
160#define MC13783_IRQ_ADCBISDONE MC13XXX_IRQ_ADCBISDONE 161#define MC13783_IRQ_ADCBISDONE MC13XXX_IRQ_ADCBISDONE
diff --git a/include/linux/mfd/mc13892.h b/include/linux/mfd/mc13892.h
new file mode 100644
index 000000000000..a00f2bec178c
--- /dev/null
+++ b/include/linux/mfd/mc13892.h
@@ -0,0 +1,39 @@
1/*
2 * Copyright 2010 Yong Shen <yong.shen@linaro.org>
3 *
4 * This program is free software; you can redistribute it and/or modify it under
5 * the terms of the GNU General Public License version 2 as published by the
6 * Free Software Foundation.
7 */
8
9#ifndef __LINUX_MFD_MC13892_H
10#define __LINUX_MFD_MC13892_H
11
12#include <linux/mfd/mc13xxx.h>
13
14#define MC13892_SW1 0
15#define MC13892_SW2 1
16#define MC13892_SW3 2
17#define MC13892_SW4 3
18#define MC13892_SWBST 4
19#define MC13892_VIOHI 5
20#define MC13892_VPLL 6
21#define MC13892_VDIG 7
22#define MC13892_VSD 8
23#define MC13892_VUSB2 9
24#define MC13892_VVIDEO 10
25#define MC13892_VAUDIO 11
26#define MC13892_VCAM 12
27#define MC13892_VGEN1 13
28#define MC13892_VGEN2 14
29#define MC13892_VGEN3 15
30#define MC13892_VUSB 16
31#define MC13892_GPO1 17
32#define MC13892_GPO2 18
33#define MC13892_GPO3 19
34#define MC13892_GPO4 20
35#define MC13892_PWGT1SPI 21
36#define MC13892_PWGT2SPI 22
37#define MC13892_VCOINCELL 23
38
39#endif
diff --git a/include/linux/mfd/wm8994/core.h b/include/linux/mfd/wm8994/core.h
index de79baee4925..3fd36845ca45 100644
--- a/include/linux/mfd/wm8994/core.h
+++ b/include/linux/mfd/wm8994/core.h
@@ -17,6 +17,11 @@
17 17
18#include <linux/interrupt.h> 18#include <linux/interrupt.h>
19 19
20enum wm8994_type {
21 WM8994 = 0,
22 WM8958 = 1,
23};
24
20struct regulator_dev; 25struct regulator_dev;
21struct regulator_bulk_data; 26struct regulator_bulk_data;
22 27
@@ -48,6 +53,8 @@ struct wm8994 {
48 struct mutex io_lock; 53 struct mutex io_lock;
49 struct mutex irq_lock; 54 struct mutex irq_lock;
50 55
56 enum wm8994_type type;
57
51 struct device *dev; 58 struct device *dev;
52 int (*read_dev)(struct wm8994 *wm8994, unsigned short reg, 59 int (*read_dev)(struct wm8994 *wm8994, unsigned short reg,
53 int bytes, void *dest); 60 int bytes, void *dest);
@@ -68,6 +75,7 @@ struct wm8994 {
68 u16 gpio_regs[WM8994_NUM_GPIO_REGS]; 75 u16 gpio_regs[WM8994_NUM_GPIO_REGS];
69 76
70 struct regulator_dev *dbvdd; 77 struct regulator_dev *dbvdd;
78 int num_supplies;
71 struct regulator_bulk_data *supplies; 79 struct regulator_bulk_data *supplies;
72}; 80};
73 81
diff --git a/include/linux/mfd/wm8994/pdata.h b/include/linux/mfd/wm8994/pdata.h
index add8a1b8bcf0..9eab263658be 100644
--- a/include/linux/mfd/wm8994/pdata.h
+++ b/include/linux/mfd/wm8994/pdata.h
@@ -30,6 +30,8 @@ struct wm8994_ldo_pdata {
30 30
31#define WM8994_DRC_REGS 5 31#define WM8994_DRC_REGS 5
32#define WM8994_EQ_REGS 20 32#define WM8994_EQ_REGS 20
33#define WM8958_MBC_CUTOFF_REGS 20
34#define WM8958_MBC_COEFF_REGS 48
33 35
34/** 36/**
35 * DRC configurations are specified with a label and a set of register 37 * DRC configurations are specified with a label and a set of register
@@ -59,6 +61,18 @@ struct wm8994_retune_mobile_cfg {
59 u16 regs[WM8994_EQ_REGS]; 61 u16 regs[WM8994_EQ_REGS];
60}; 62};
61 63
64/**
65 * Multiband compressor configurations are specified with a label and
66 * two sets of values to write. Configurations are expected to be
67 * generated using the multiband compressor configuration panel in
68 * WISCE - see http://www.wolfsonmicro.com/wisce/
69 */
70struct wm8958_mbc_cfg {
71 const char *name;
72 u16 cutoff_regs[WM8958_MBC_CUTOFF_REGS];
73 u16 coeff_regs[WM8958_MBC_COEFF_REGS];
74};
75
62struct wm8994_pdata { 76struct wm8994_pdata {
63 int gpio_base; 77 int gpio_base;
64 78
@@ -78,6 +92,9 @@ struct wm8994_pdata {
78 int num_retune_mobile_cfgs; 92 int num_retune_mobile_cfgs;
79 struct wm8994_retune_mobile_cfg *retune_mobile_cfgs; 93 struct wm8994_retune_mobile_cfg *retune_mobile_cfgs;
80 94
95 int num_mbc_cfgs;
96 struct wm8958_mbc_cfg *mbc_cfgs;
97
81 /* LINEOUT can be differential or single ended */ 98 /* LINEOUT can be differential or single ended */
82 unsigned int lineout1_diff:1; 99 unsigned int lineout1_diff:1;
83 unsigned int lineout2_diff:1; 100 unsigned int lineout2_diff:1;
diff --git a/include/linux/mfd/wm8994/registers.h b/include/linux/mfd/wm8994/registers.h
index 967f62f54159..be072faec6f0 100644
--- a/include/linux/mfd/wm8994/registers.h
+++ b/include/linux/mfd/wm8994/registers.h
@@ -64,12 +64,16 @@
64#define WM8994_LDO_1 0x3B 64#define WM8994_LDO_1 0x3B
65#define WM8994_LDO_2 0x3C 65#define WM8994_LDO_2 0x3C
66#define WM8994_CHARGE_PUMP_1 0x4C 66#define WM8994_CHARGE_PUMP_1 0x4C
67#define WM8958_CHARGE_PUMP_2 0x4D
67#define WM8994_CLASS_W_1 0x51 68#define WM8994_CLASS_W_1 0x51
68#define WM8994_DC_SERVO_1 0x54 69#define WM8994_DC_SERVO_1 0x54
69#define WM8994_DC_SERVO_2 0x55 70#define WM8994_DC_SERVO_2 0x55
70#define WM8994_DC_SERVO_4 0x57 71#define WM8994_DC_SERVO_4 0x57
71#define WM8994_DC_SERVO_READBACK 0x58 72#define WM8994_DC_SERVO_READBACK 0x58
72#define WM8994_ANALOGUE_HP_1 0x60 73#define WM8994_ANALOGUE_HP_1 0x60
74#define WM8958_MIC_DETECT_1 0xD0
75#define WM8958_MIC_DETECT_2 0xD1
76#define WM8958_MIC_DETECT_3 0xD2
73#define WM8994_CHIP_REVISION 0x100 77#define WM8994_CHIP_REVISION 0x100
74#define WM8994_CONTROL_INTERFACE 0x101 78#define WM8994_CONTROL_INTERFACE 0x101
75#define WM8994_WRITE_SEQUENCER_CTRL_1 0x110 79#define WM8994_WRITE_SEQUENCER_CTRL_1 0x110
@@ -109,6 +113,10 @@
109#define WM8994_AIF2DAC_LRCLK 0x315 113#define WM8994_AIF2DAC_LRCLK 0x315
110#define WM8994_AIF2DAC_DATA 0x316 114#define WM8994_AIF2DAC_DATA 0x316
111#define WM8994_AIF2ADC_DATA 0x317 115#define WM8994_AIF2ADC_DATA 0x317
116#define WM8958_AIF3_CONTROL_1 0x320
117#define WM8958_AIF3_CONTROL_2 0x321
118#define WM8958_AIF3DAC_DATA 0x322
119#define WM8958_AIF3ADC_DATA 0x323
112#define WM8994_AIF1_ADC1_LEFT_VOLUME 0x400 120#define WM8994_AIF1_ADC1_LEFT_VOLUME 0x400
113#define WM8994_AIF1_ADC1_RIGHT_VOLUME 0x401 121#define WM8994_AIF1_ADC1_RIGHT_VOLUME 0x401
114#define WM8994_AIF1_DAC1_LEFT_VOLUME 0x402 122#define WM8994_AIF1_DAC1_LEFT_VOLUME 0x402
@@ -242,6 +250,83 @@
242#define WM8994_INTERRUPT_STATUS_2_MASK 0x739 250#define WM8994_INTERRUPT_STATUS_2_MASK 0x739
243#define WM8994_INTERRUPT_CONTROL 0x740 251#define WM8994_INTERRUPT_CONTROL 0x740
244#define WM8994_IRQ_DEBOUNCE 0x748 252#define WM8994_IRQ_DEBOUNCE 0x748
253#define WM8958_DSP2_PROGRAM 0x900
254#define WM8958_DSP2_CONFIG 0x901
255#define WM8958_DSP2_MAGICNUM 0xA00
256#define WM8958_DSP2_RELEASEYEAR 0xA01
257#define WM8958_DSP2_RELEASEMONTHDAY 0xA02
258#define WM8958_DSP2_RELEASETIME 0xA03
259#define WM8958_DSP2_VERMAJMIN 0xA04
260#define WM8958_DSP2_VERBUILD 0xA05
261#define WM8958_DSP2_EXECCONTROL 0xA0D
262#define WM8958_MBC_BAND_2_LOWER_CUTOFF_C1_1 0x2200
263#define WM8958_MBC_BAND_2_LOWER_CUTOFF_C1_2 0x2201
264#define WM8958_MBC_BAND_2_LOWER_CUTOFF_C2_1 0x2202
265#define WM8958_MBC_BAND_2_LOWER_CUTOFF_C2_2 0x2203
266#define WM8958_MBC_BAND_2_LOWER_CUTOFF_C3_1 0x2204
267#define WM8958_MBC_BAND_2_LOWER_CUTOFF_C3_2 0x2205
268#define WM8958_MBC_BAND_2_UPPER_CUTOFF_C2_1 0x2206
269#define WM8958_MBC_BAND_2_UPPER_CUTOFF_C2_2 0x2207
270#define WM8958_MBC_BAND_2_UPPER_CUTOFF_C3_1 0x2208
271#define WM8958_MBC_BAND_2_UPPER_CUTOFF_C3_2 0x2209
272#define WM8958_MBC_BAND_2_UPPER_CUTOFF_C1_1 0x220A
273#define WM8958_MBC_BAND_2_UPPER_CUTOFF_C1_2 0x220B
274#define WM8958_MBC_BAND_1_UPPER_CUTOFF_C1_1 0x220C
275#define WM8958_MBC_BAND_1_UPPER_CUTOFF_C1_2 0x220D
276#define WM8958_MBC_BAND_1_UPPER_CUTOFF_C2_1 0x220E
277#define WM8958_MBC_BAND_1_UPPER_CUTOFF_C2_2 0x220F
278#define WM8958_MBC_BAND_1_UPPER_CUTOFF_C3_1 0x2210
279#define WM8958_MBC_BAND_1_UPPER_CUTOFF_C3_2 0x2211
280#define WM8958_MBC_BAND_1_LOWER_CUTOFF_1 0x2212
281#define WM8958_MBC_BAND_1_LOWER_CUTOFF_2 0x2213
282#define WM8958_MBC_BAND_1_K_1 0x2400
283#define WM8958_MBC_BAND_1_K_2 0x2401
284#define WM8958_MBC_BAND_1_N1_1 0x2402
285#define WM8958_MBC_BAND_1_N1_2 0x2403
286#define WM8958_MBC_BAND_1_N2_1 0x2404
287#define WM8958_MBC_BAND_1_N2_2 0x2405
288#define WM8958_MBC_BAND_1_N3_1 0x2406
289#define WM8958_MBC_BAND_1_N3_2 0x2407
290#define WM8958_MBC_BAND_1_N4_1 0x2408
291#define WM8958_MBC_BAND_1_N4_2 0x2409
292#define WM8958_MBC_BAND_1_N5_1 0x240A
293#define WM8958_MBC_BAND_1_N5_2 0x240B
294#define WM8958_MBC_BAND_1_X1_1 0x240C
295#define WM8958_MBC_BAND_1_X1_2 0x240D
296#define WM8958_MBC_BAND_1_X2_1 0x240E
297#define WM8958_MBC_BAND_1_X2_2 0x240F
298#define WM8958_MBC_BAND_1_X3_1 0x2410
299#define WM8958_MBC_BAND_1_X3_2 0x2411
300#define WM8958_MBC_BAND_1_ATTACK_1 0x2412
301#define WM8958_MBC_BAND_1_ATTACK_2 0x2413
302#define WM8958_MBC_BAND_1_DECAY_1 0x2414
303#define WM8958_MBC_BAND_1_DECAY_2 0x2415
304#define WM8958_MBC_BAND_2_K_1 0x2416
305#define WM8958_MBC_BAND_2_K_2 0x2417
306#define WM8958_MBC_BAND_2_N1_1 0x2418
307#define WM8958_MBC_BAND_2_N1_2 0x2419
308#define WM8958_MBC_BAND_2_N2_1 0x241A
309#define WM8958_MBC_BAND_2_N2_2 0x241B
310#define WM8958_MBC_BAND_2_N3_1 0x241C
311#define WM8958_MBC_BAND_2_N3_2 0x241D
312#define WM8958_MBC_BAND_2_N4_1 0x241E
313#define WM8958_MBC_BAND_2_N4_2 0x241F
314#define WM8958_MBC_BAND_2_N5_1 0x2420
315#define WM8958_MBC_BAND_2_N5_2 0x2421
316#define WM8958_MBC_BAND_2_X1_1 0x2422
317#define WM8958_MBC_BAND_2_X1_2 0x2423
318#define WM8958_MBC_BAND_2_X2_1 0x2424
319#define WM8958_MBC_BAND_2_X2_2 0x2425
320#define WM8958_MBC_BAND_2_X3_1 0x2426
321#define WM8958_MBC_BAND_2_X3_2 0x2427
322#define WM8958_MBC_BAND_2_ATTACK_1 0x2428
323#define WM8958_MBC_BAND_2_ATTACK_2 0x2429
324#define WM8958_MBC_BAND_2_DECAY_1 0x242A
325#define WM8958_MBC_BAND_2_DECAY_2 0x242B
326#define WM8958_MBC_B2_PG2_1 0x242C
327#define WM8958_MBC_B2_PG2_2 0x242D
328#define WM8958_MBC_B1_PG2_1 0x242E
329#define WM8958_MBC_B1_PG2_2 0x242F
245#define WM8994_WRITE_SEQUENCER_0 0x3000 330#define WM8994_WRITE_SEQUENCER_0 0x3000
246#define WM8994_WRITE_SEQUENCER_1 0x3001 331#define WM8994_WRITE_SEQUENCER_1 0x3001
247#define WM8994_WRITE_SEQUENCER_2 0x3002 332#define WM8994_WRITE_SEQUENCER_2 0x3002
@@ -992,6 +1077,12 @@
992/* 1077/*
993 * R6 (0x06) - Power Management (6) 1078 * R6 (0x06) - Power Management (6)
994 */ 1079 */
1080#define WM8958_AIF3ADC_SRC_MASK 0x0600 /* AIF3ADC_SRC - [10:9] */
1081#define WM8958_AIF3ADC_SRC_SHIFT 9 /* AIF3ADC_SRC - [10:9] */
1082#define WM8958_AIF3ADC_SRC_WIDTH 2 /* AIF3ADC_SRC - [10:9] */
1083#define WM8958_AIF2DAC_SRC_MASK 0x0180 /* AIF2DAC_SRC - [8:7] */
1084#define WM8958_AIF2DAC_SRC_SHIFT 7 /* AIF2DAC_SRC - [8:7] */
1085#define WM8958_AIF2DAC_SRC_WIDTH 2 /* AIF2DAC_SRC - [8:7] */
995#define WM8994_AIF3_TRI 0x0020 /* AIF3_TRI */ 1086#define WM8994_AIF3_TRI 0x0020 /* AIF3_TRI */
996#define WM8994_AIF3_TRI_MASK 0x0020 /* AIF3_TRI */ 1087#define WM8994_AIF3_TRI_MASK 0x0020 /* AIF3_TRI */
997#define WM8994_AIF3_TRI_SHIFT 5 /* AIF3_TRI */ 1088#define WM8994_AIF3_TRI_SHIFT 5 /* AIF3_TRI */
@@ -1836,6 +1927,14 @@
1836#define WM8994_CP_ENA_WIDTH 1 /* CP_ENA */ 1927#define WM8994_CP_ENA_WIDTH 1 /* CP_ENA */
1837 1928
1838/* 1929/*
1930 * R77 (0x4D) - Charge Pump (2)
1931 */
1932#define WM8958_CP_DISCH 0x8000 /* CP_DISCH */
1933#define WM8958_CP_DISCH_MASK 0x8000 /* CP_DISCH */
1934#define WM8958_CP_DISCH_SHIFT 15 /* CP_DISCH */
1935#define WM8958_CP_DISCH_WIDTH 1 /* CP_DISCH */
1936
1937/*
1839 * R81 (0x51) - Class W (1) 1938 * R81 (0x51) - Class W (1)
1840 */ 1939 */
1841#define WM8994_CP_DYN_SRC_SEL_MASK 0x0300 /* CP_DYN_SRC_SEL - [9:8] */ 1940#define WM8994_CP_DYN_SRC_SEL_MASK 0x0300 /* CP_DYN_SRC_SEL - [9:8] */
@@ -1952,6 +2051,46 @@
1952#define WM8994_HPOUT1R_DLY_WIDTH 1 /* HPOUT1R_DLY */ 2051#define WM8994_HPOUT1R_DLY_WIDTH 1 /* HPOUT1R_DLY */
1953 2052
1954/* 2053/*
2054 * R208 (0xD0) - Mic Detect 1
2055 */
2056#define WM8958_MICD_BIAS_STARTTIME_MASK 0xF000 /* MICD_BIAS_STARTTIME - [15:12] */
2057#define WM8958_MICD_BIAS_STARTTIME_SHIFT 12 /* MICD_BIAS_STARTTIME - [15:12] */
2058#define WM8958_MICD_BIAS_STARTTIME_WIDTH 4 /* MICD_BIAS_STARTTIME - [15:12] */
2059#define WM8958_MICD_RATE_MASK 0x0F00 /* MICD_RATE - [11:8] */
2060#define WM8958_MICD_RATE_SHIFT 8 /* MICD_RATE - [11:8] */
2061#define WM8958_MICD_RATE_WIDTH 4 /* MICD_RATE - [11:8] */
2062#define WM8958_MICD_DBTIME 0x0002 /* MICD_DBTIME */
2063#define WM8958_MICD_DBTIME_MASK 0x0002 /* MICD_DBTIME */
2064#define WM8958_MICD_DBTIME_SHIFT 1 /* MICD_DBTIME */
2065#define WM8958_MICD_DBTIME_WIDTH 1 /* MICD_DBTIME */
2066#define WM8958_MICD_ENA 0x0001 /* MICD_ENA */
2067#define WM8958_MICD_ENA_MASK 0x0001 /* MICD_ENA */
2068#define WM8958_MICD_ENA_SHIFT 0 /* MICD_ENA */
2069#define WM8958_MICD_ENA_WIDTH 1 /* MICD_ENA */
2070
2071/*
2072 * R209 (0xD1) - Mic Detect 2
2073 */
2074#define WM8958_MICD_LVL_SEL_MASK 0x00FF /* MICD_LVL_SEL - [7:0] */
2075#define WM8958_MICD_LVL_SEL_SHIFT 0 /* MICD_LVL_SEL - [7:0] */
2076#define WM8958_MICD_LVL_SEL_WIDTH 8 /* MICD_LVL_SEL - [7:0] */
2077
2078/*
2079 * R210 (0xD2) - Mic Detect 3
2080 */
2081#define WM8958_MICD_LVL_MASK 0x07FC /* MICD_LVL - [10:2] */
2082#define WM8958_MICD_LVL_SHIFT 2 /* MICD_LVL - [10:2] */
2083#define WM8958_MICD_LVL_WIDTH 9 /* MICD_LVL - [10:2] */
2084#define WM8958_MICD_VALID 0x0002 /* MICD_VALID */
2085#define WM8958_MICD_VALID_MASK 0x0002 /* MICD_VALID */
2086#define WM8958_MICD_VALID_SHIFT 1 /* MICD_VALID */
2087#define WM8958_MICD_VALID_WIDTH 1 /* MICD_VALID */
2088#define WM8958_MICD_STS 0x0001 /* MICD_STS */
2089#define WM8958_MICD_STS_MASK 0x0001 /* MICD_STS */
2090#define WM8958_MICD_STS_SHIFT 0 /* MICD_STS */
2091#define WM8958_MICD_STS_WIDTH 1 /* MICD_STS */
2092
2093/*
1955 * R256 (0x100) - Chip Revision 2094 * R256 (0x100) - Chip Revision
1956 */ 2095 */
1957#define WM8994_CHIP_REV_MASK 0x000F /* CHIP_REV - [3:0] */ 2096#define WM8994_CHIP_REV_MASK 0x000F /* CHIP_REV - [3:0] */
@@ -2069,6 +2208,14 @@
2069/* 2208/*
2070 * R520 (0x208) - Clocking (1) 2209 * R520 (0x208) - Clocking (1)
2071 */ 2210 */
2211#define WM8958_DSP2CLK_ENA 0x4000 /* DSP2CLK_ENA */
2212#define WM8958_DSP2CLK_ENA_MASK 0x4000 /* DSP2CLK_ENA */
2213#define WM8958_DSP2CLK_ENA_SHIFT 14 /* DSP2CLK_ENA */
2214#define WM8958_DSP2CLK_ENA_WIDTH 1 /* DSP2CLK_ENA */
2215#define WM8958_DSP2CLK_SRC 0x1000 /* DSP2CLK_SRC */
2216#define WM8958_DSP2CLK_SRC_MASK 0x1000 /* DSP2CLK_SRC */
2217#define WM8958_DSP2CLK_SRC_SHIFT 12 /* DSP2CLK_SRC */
2218#define WM8958_DSP2CLK_SRC_WIDTH 1 /* DSP2CLK_SRC */
2072#define WM8994_TOCLK_ENA 0x0010 /* TOCLK_ENA */ 2219#define WM8994_TOCLK_ENA 0x0010 /* TOCLK_ENA */
2073#define WM8994_TOCLK_ENA_MASK 0x0010 /* TOCLK_ENA */ 2220#define WM8994_TOCLK_ENA_MASK 0x0010 /* TOCLK_ENA */
2074#define WM8994_TOCLK_ENA_SHIFT 4 /* TOCLK_ENA */ 2221#define WM8994_TOCLK_ENA_SHIFT 4 /* TOCLK_ENA */
@@ -2553,6 +2700,63 @@
2553#define WM8994_AIF2ADCR_DAT_INV_WIDTH 1 /* AIF2ADCR_DAT_INV */ 2700#define WM8994_AIF2ADCR_DAT_INV_WIDTH 1 /* AIF2ADCR_DAT_INV */
2554 2701
2555/* 2702/*
2703 * R800 (0x320) - AIF3 Control (1)
2704 */
2705#define WM8958_AIF3_LRCLK_INV 0x0080 /* AIF3_LRCLK_INV */
2706#define WM8958_AIF3_LRCLK_INV_MASK 0x0080 /* AIF3_LRCLK_INV */
2707#define WM8958_AIF3_LRCLK_INV_SHIFT 7 /* AIF3_LRCLK_INV */
2708#define WM8958_AIF3_LRCLK_INV_WIDTH 1 /* AIF3_LRCLK_INV */
2709#define WM8958_AIF3_WL_MASK 0x0060 /* AIF3_WL - [6:5] */
2710#define WM8958_AIF3_WL_SHIFT 5 /* AIF3_WL - [6:5] */
2711#define WM8958_AIF3_WL_WIDTH 2 /* AIF3_WL - [6:5] */
2712#define WM8958_AIF3_FMT_MASK 0x0018 /* AIF3_FMT - [4:3] */
2713#define WM8958_AIF3_FMT_SHIFT 3 /* AIF3_FMT - [4:3] */
2714#define WM8958_AIF3_FMT_WIDTH 2 /* AIF3_FMT - [4:3] */
2715
2716/*
2717 * R801 (0x321) - AIF3 Control (2)
2718 */
2719#define WM8958_AIF3DAC_BOOST_MASK 0x0C00 /* AIF3DAC_BOOST - [11:10] */
2720#define WM8958_AIF3DAC_BOOST_SHIFT 10 /* AIF3DAC_BOOST - [11:10] */
2721#define WM8958_AIF3DAC_BOOST_WIDTH 2 /* AIF3DAC_BOOST - [11:10] */
2722#define WM8958_AIF3DAC_COMP 0x0010 /* AIF3DAC_COMP */
2723#define WM8958_AIF3DAC_COMP_MASK 0x0010 /* AIF3DAC_COMP */
2724#define WM8958_AIF3DAC_COMP_SHIFT 4 /* AIF3DAC_COMP */
2725#define WM8958_AIF3DAC_COMP_WIDTH 1 /* AIF3DAC_COMP */
2726#define WM8958_AIF3DAC_COMPMODE 0x0008 /* AIF3DAC_COMPMODE */
2727#define WM8958_AIF3DAC_COMPMODE_MASK 0x0008 /* AIF3DAC_COMPMODE */
2728#define WM8958_AIF3DAC_COMPMODE_SHIFT 3 /* AIF3DAC_COMPMODE */
2729#define WM8958_AIF3DAC_COMPMODE_WIDTH 1 /* AIF3DAC_COMPMODE */
2730#define WM8958_AIF3ADC_COMP 0x0004 /* AIF3ADC_COMP */
2731#define WM8958_AIF3ADC_COMP_MASK 0x0004 /* AIF3ADC_COMP */
2732#define WM8958_AIF3ADC_COMP_SHIFT 2 /* AIF3ADC_COMP */
2733#define WM8958_AIF3ADC_COMP_WIDTH 1 /* AIF3ADC_COMP */
2734#define WM8958_AIF3ADC_COMPMODE 0x0002 /* AIF3ADC_COMPMODE */
2735#define WM8958_AIF3ADC_COMPMODE_MASK 0x0002 /* AIF3ADC_COMPMODE */
2736#define WM8958_AIF3ADC_COMPMODE_SHIFT 1 /* AIF3ADC_COMPMODE */
2737#define WM8958_AIF3ADC_COMPMODE_WIDTH 1 /* AIF3ADC_COMPMODE */
2738#define WM8958_AIF3_LOOPBACK 0x0001 /* AIF3_LOOPBACK */
2739#define WM8958_AIF3_LOOPBACK_MASK 0x0001 /* AIF3_LOOPBACK */
2740#define WM8958_AIF3_LOOPBACK_SHIFT 0 /* AIF3_LOOPBACK */
2741#define WM8958_AIF3_LOOPBACK_WIDTH 1 /* AIF3_LOOPBACK */
2742
2743/*
2744 * R802 (0x322) - AIF3DAC Data
2745 */
2746#define WM8958_AIF3DAC_DAT_INV 0x0001 /* AIF3DAC_DAT_INV */
2747#define WM8958_AIF3DAC_DAT_INV_MASK 0x0001 /* AIF3DAC_DAT_INV */
2748#define WM8958_AIF3DAC_DAT_INV_SHIFT 0 /* AIF3DAC_DAT_INV */
2749#define WM8958_AIF3DAC_DAT_INV_WIDTH 1 /* AIF3DAC_DAT_INV */
2750
2751/*
2752 * R803 (0x323) - AIF3ADC Data
2753 */
2754#define WM8958_AIF3ADC_DAT_INV 0x0001 /* AIF3ADC_DAT_INV */
2755#define WM8958_AIF3ADC_DAT_INV_MASK 0x0001 /* AIF3ADC_DAT_INV */
2756#define WM8958_AIF3ADC_DAT_INV_SHIFT 0 /* AIF3ADC_DAT_INV */
2757#define WM8958_AIF3ADC_DAT_INV_WIDTH 1 /* AIF3ADC_DAT_INV */
2758
2759/*
2556 * R1024 (0x400) - AIF1 ADC1 Left Volume 2760 * R1024 (0x400) - AIF1 ADC1 Left Volume
2557 */ 2761 */
2558#define WM8994_AIF1ADC1_VU 0x0100 /* AIF1ADC1_VU */ 2762#define WM8994_AIF1ADC1_VU 0x0100 /* AIF1ADC1_VU */
@@ -4289,4 +4493,102 @@
4289#define WM8994_TEMP_SHUT_DB_SHIFT 0 /* TEMP_SHUT_DB */ 4493#define WM8994_TEMP_SHUT_DB_SHIFT 0 /* TEMP_SHUT_DB */
4290#define WM8994_TEMP_SHUT_DB_WIDTH 1 /* TEMP_SHUT_DB */ 4494#define WM8994_TEMP_SHUT_DB_WIDTH 1 /* TEMP_SHUT_DB */
4291 4495
4496/*
4497 * R2304 (0x900) - DSP2_Program
4498 */
4499#define WM8958_DSP2_ENA 0x0001 /* DSP2_ENA */
4500#define WM8958_DSP2_ENA_MASK 0x0001 /* DSP2_ENA */
4501#define WM8958_DSP2_ENA_SHIFT 0 /* DSP2_ENA */
4502#define WM8958_DSP2_ENA_WIDTH 1 /* DSP2_ENA */
4503
4504/*
4505 * R2305 (0x901) - DSP2_Config
4506 */
4507#define WM8958_MBC_SEL_MASK 0x0030 /* MBC_SEL - [5:4] */
4508#define WM8958_MBC_SEL_SHIFT 4 /* MBC_SEL - [5:4] */
4509#define WM8958_MBC_SEL_WIDTH 2 /* MBC_SEL - [5:4] */
4510#define WM8958_MBC_ENA 0x0001 /* MBC_ENA */
4511#define WM8958_MBC_ENA_MASK 0x0001 /* MBC_ENA */
4512#define WM8958_MBC_ENA_SHIFT 0 /* MBC_ENA */
4513#define WM8958_MBC_ENA_WIDTH 1 /* MBC_ENA */
4514
4515/*
4516 * R2560 (0xA00) - DSP2_MagicNum
4517 */
4518#define WM8958_DSP2_MAGIC_NUM_MASK 0xFFFF /* DSP2_MAGIC_NUM - [15:0] */
4519#define WM8958_DSP2_MAGIC_NUM_SHIFT 0 /* DSP2_MAGIC_NUM - [15:0] */
4520#define WM8958_DSP2_MAGIC_NUM_WIDTH 16 /* DSP2_MAGIC_NUM - [15:0] */
4521
4522/*
4523 * R2561 (0xA01) - DSP2_ReleaseYear
4524 */
4525#define WM8958_DSP2_RELEASE_YEAR_MASK 0xFFFF /* DSP2_RELEASE_YEAR - [15:0] */
4526#define WM8958_DSP2_RELEASE_YEAR_SHIFT 0 /* DSP2_RELEASE_YEAR - [15:0] */
4527#define WM8958_DSP2_RELEASE_YEAR_WIDTH 16 /* DSP2_RELEASE_YEAR - [15:0] */
4528
4529/*
4530 * R2562 (0xA02) - DSP2_ReleaseMonthDay
4531 */
4532#define WM8958_DSP2_RELEASE_MONTH_MASK 0xFF00 /* DSP2_RELEASE_MONTH - [15:8] */
4533#define WM8958_DSP2_RELEASE_MONTH_SHIFT 8 /* DSP2_RELEASE_MONTH - [15:8] */
4534#define WM8958_DSP2_RELEASE_MONTH_WIDTH 8 /* DSP2_RELEASE_MONTH - [15:8] */
4535#define WM8958_DSP2_RELEASE_DAY_MASK 0x00FF /* DSP2_RELEASE_DAY - [7:0] */
4536#define WM8958_DSP2_RELEASE_DAY_SHIFT 0 /* DSP2_RELEASE_DAY - [7:0] */
4537#define WM8958_DSP2_RELEASE_DAY_WIDTH 8 /* DSP2_RELEASE_DAY - [7:0] */
4538
4539/*
4540 * R2563 (0xA03) - DSP2_ReleaseTime
4541 */
4542#define WM8958_DSP2_RELEASE_HOURS_MASK 0xFF00 /* DSP2_RELEASE_HOURS - [15:8] */
4543#define WM8958_DSP2_RELEASE_HOURS_SHIFT 8 /* DSP2_RELEASE_HOURS - [15:8] */
4544#define WM8958_DSP2_RELEASE_HOURS_WIDTH 8 /* DSP2_RELEASE_HOURS - [15:8] */
4545#define WM8958_DSP2_RELEASE_MINS_MASK 0x00FF /* DSP2_RELEASE_MINS - [7:0] */
4546#define WM8958_DSP2_RELEASE_MINS_SHIFT 0 /* DSP2_RELEASE_MINS - [7:0] */
4547#define WM8958_DSP2_RELEASE_MINS_WIDTH 8 /* DSP2_RELEASE_MINS - [7:0] */
4548
4549/*
4550 * R2564 (0xA04) - DSP2_VerMajMin
4551 */
4552#define WM8958_DSP2_MAJOR_VER_MASK 0xFF00 /* DSP2_MAJOR_VER - [15:8] */
4553#define WM8958_DSP2_MAJOR_VER_SHIFT 8 /* DSP2_MAJOR_VER - [15:8] */
4554#define WM8958_DSP2_MAJOR_VER_WIDTH 8 /* DSP2_MAJOR_VER - [15:8] */
4555#define WM8958_DSP2_MINOR_VER_MASK 0x00FF /* DSP2_MINOR_VER - [7:0] */
4556#define WM8958_DSP2_MINOR_VER_SHIFT 0 /* DSP2_MINOR_VER - [7:0] */
4557#define WM8958_DSP2_MINOR_VER_WIDTH 8 /* DSP2_MINOR_VER - [7:0] */
4558
4559/*
4560 * R2565 (0xA05) - DSP2_VerBuild
4561 */
4562#define WM8958_DSP2_BUILD_VER_MASK 0xFFFF /* DSP2_BUILD_VER - [15:0] */
4563#define WM8958_DSP2_BUILD_VER_SHIFT 0 /* DSP2_BUILD_VER - [15:0] */
4564#define WM8958_DSP2_BUILD_VER_WIDTH 16 /* DSP2_BUILD_VER - [15:0] */
4565
4566/*
4567 * R2573 (0xA0D) - DSP2_ExecControl
4568 */
4569#define WM8958_DSP2_STOPC 0x0020 /* DSP2_STOPC */
4570#define WM8958_DSP2_STOPC_MASK 0x0020 /* DSP2_STOPC */
4571#define WM8958_DSP2_STOPC_SHIFT 5 /* DSP2_STOPC */
4572#define WM8958_DSP2_STOPC_WIDTH 1 /* DSP2_STOPC */
4573#define WM8958_DSP2_STOPS 0x0010 /* DSP2_STOPS */
4574#define WM8958_DSP2_STOPS_MASK 0x0010 /* DSP2_STOPS */
4575#define WM8958_DSP2_STOPS_SHIFT 4 /* DSP2_STOPS */
4576#define WM8958_DSP2_STOPS_WIDTH 1 /* DSP2_STOPS */
4577#define WM8958_DSP2_STOPI 0x0008 /* DSP2_STOPI */
4578#define WM8958_DSP2_STOPI_MASK 0x0008 /* DSP2_STOPI */
4579#define WM8958_DSP2_STOPI_SHIFT 3 /* DSP2_STOPI */
4580#define WM8958_DSP2_STOPI_WIDTH 1 /* DSP2_STOPI */
4581#define WM8958_DSP2_STOP 0x0004 /* DSP2_STOP */
4582#define WM8958_DSP2_STOP_MASK 0x0004 /* DSP2_STOP */
4583#define WM8958_DSP2_STOP_SHIFT 2 /* DSP2_STOP */
4584#define WM8958_DSP2_STOP_WIDTH 1 /* DSP2_STOP */
4585#define WM8958_DSP2_RUNR 0x0002 /* DSP2_RUNR */
4586#define WM8958_DSP2_RUNR_MASK 0x0002 /* DSP2_RUNR */
4587#define WM8958_DSP2_RUNR_SHIFT 1 /* DSP2_RUNR */
4588#define WM8958_DSP2_RUNR_WIDTH 1 /* DSP2_RUNR */
4589#define WM8958_DSP2_RUN 0x0001 /* DSP2_RUN */
4590#define WM8958_DSP2_RUN_MASK 0x0001 /* DSP2_RUN */
4591#define WM8958_DSP2_RUN_SHIFT 0 /* DSP2_RUN */
4592#define WM8958_DSP2_RUN_WIDTH 1 /* DSP2_RUN */
4593
4292#endif 4594#endif
diff --git a/include/linux/ncp_fs.h b/include/linux/ncp_fs.h
index 1c27f201c856..e13eefef0653 100644
--- a/include/linux/ncp_fs.h
+++ b/include/linux/ncp_fs.h
@@ -143,104 +143,4 @@ struct ncp_nls_ioctl
143#define NCP_MAXPATHLEN 255 143#define NCP_MAXPATHLEN 255
144#define NCP_MAXNAMELEN 14 144#define NCP_MAXNAMELEN 14
145 145
146#ifdef __KERNEL__
147
148#include <linux/ncp_fs_i.h>
149#include <linux/ncp_fs_sb.h>
150
151/* define because it is easy to change PRINTK to {*}PRINTK */
152#define PRINTK(format, args...) printk(KERN_DEBUG format , ## args)
153
154#undef NCPFS_PARANOIA
155#ifdef NCPFS_PARANOIA
156#define PPRINTK(format, args...) PRINTK(format , ## args)
157#else
158#define PPRINTK(format, args...)
159#endif
160
161#ifndef DEBUG_NCP
162#define DEBUG_NCP 0
163#endif
164#if DEBUG_NCP > 0
165#define DPRINTK(format, args...) PRINTK(format , ## args)
166#else
167#define DPRINTK(format, args...)
168#endif
169#if DEBUG_NCP > 1
170#define DDPRINTK(format, args...) PRINTK(format , ## args)
171#else
172#define DDPRINTK(format, args...)
173#endif
174
175#define NCP_MAX_RPC_TIMEOUT (6*HZ)
176
177
178struct ncp_entry_info {
179 struct nw_info_struct i;
180 ino_t ino;
181 int opened;
182 int access;
183 unsigned int volume;
184 __u8 file_handle[6];
185};
186
187static inline struct ncp_server *NCP_SBP(const struct super_block *sb)
188{
189 return sb->s_fs_info;
190}
191
192#define NCP_SERVER(inode) NCP_SBP((inode)->i_sb)
193static inline struct ncp_inode_info *NCP_FINFO(const struct inode *inode)
194{
195 return container_of(inode, struct ncp_inode_info, vfs_inode);
196}
197
198/* linux/fs/ncpfs/inode.c */
199int ncp_notify_change(struct dentry *, struct iattr *);
200struct inode *ncp_iget(struct super_block *, struct ncp_entry_info *);
201void ncp_update_inode(struct inode *, struct ncp_entry_info *);
202void ncp_update_inode2(struct inode *, struct ncp_entry_info *);
203
204/* linux/fs/ncpfs/dir.c */
205extern const struct inode_operations ncp_dir_inode_operations;
206extern const struct file_operations ncp_dir_operations;
207extern const struct dentry_operations ncp_root_dentry_operations;
208int ncp_conn_logged_in(struct super_block *);
209int ncp_date_dos2unix(__le16 time, __le16 date);
210void ncp_date_unix2dos(int unix_date, __le16 * time, __le16 * date);
211
212/* linux/fs/ncpfs/ioctl.c */
213long ncp_ioctl(struct file *, unsigned int, unsigned long);
214long ncp_compat_ioctl(struct file *, unsigned int, unsigned long);
215
216/* linux/fs/ncpfs/sock.c */
217int ncp_request2(struct ncp_server *server, int function,
218 void* reply, int max_reply_size);
219static inline int ncp_request(struct ncp_server *server, int function) {
220 return ncp_request2(server, function, server->packet, server->packet_size);
221}
222int ncp_connect(struct ncp_server *server);
223int ncp_disconnect(struct ncp_server *server);
224void ncp_lock_server(struct ncp_server *server);
225void ncp_unlock_server(struct ncp_server *server);
226
227/* linux/fs/ncpfs/symlink.c */
228#if defined(CONFIG_NCPFS_EXTRAS) || defined(CONFIG_NCPFS_NFS_NS)
229extern const struct address_space_operations ncp_symlink_aops;
230int ncp_symlink(struct inode*, struct dentry*, const char*);
231#endif
232
233/* linux/fs/ncpfs/file.c */
234extern const struct inode_operations ncp_file_inode_operations;
235extern const struct file_operations ncp_file_operations;
236int ncp_make_open(struct inode *, int);
237
238/* linux/fs/ncpfs/mmap.c */
239int ncp_mmap(struct file *, struct vm_area_struct *);
240
241/* linux/fs/ncpfs/ncplib_kernel.c */
242int ncp_make_closed(struct inode *);
243
244#endif /* __KERNEL__ */
245
246#endif /* _LINUX_NCP_FS_H */ 146#endif /* _LINUX_NCP_FS_H */
diff --git a/include/linux/ncp_mount.h b/include/linux/ncp_mount.h
index a2b549eb1eca..dfcbea2d889f 100644
--- a/include/linux/ncp_mount.h
+++ b/include/linux/ncp_mount.h
@@ -68,26 +68,4 @@ struct ncp_mount_data_v4 {
68 68
69#define NCP_MOUNT_VERSION_V5 (5) /* Text only */ 69#define NCP_MOUNT_VERSION_V5 (5) /* Text only */
70 70
71#ifdef __KERNEL__
72
73struct ncp_mount_data_kernel {
74 unsigned long flags; /* NCP_MOUNT_* flags */
75 unsigned int int_flags; /* internal flags */
76#define NCP_IMOUNT_LOGGEDIN_POSSIBLE 0x0001
77 __kernel_uid32_t mounted_uid; /* Who may umount() this filesystem? */
78 struct pid *wdog_pid; /* Who cares for our watchdog packets? */
79 unsigned int ncp_fd; /* The socket to the ncp port */
80 unsigned int time_out; /* How long should I wait after
81 sending a NCP request? */
82 unsigned int retry_count; /* And how often should I retry? */
83 unsigned char mounted_vol[NCP_VOLNAME_LEN + 1];
84 __kernel_uid32_t uid;
85 __kernel_gid32_t gid;
86 __kernel_mode_t file_mode;
87 __kernel_mode_t dir_mode;
88 int info_fd;
89};
90
91#endif /* __KERNEL__ */
92
93#endif 71#endif
diff --git a/include/linux/nfc/pn544.h b/include/linux/nfc/pn544.h
new file mode 100644
index 000000000000..7ab8521f2347
--- /dev/null
+++ b/include/linux/nfc/pn544.h
@@ -0,0 +1,97 @@
1/*
2 * Driver include for the PN544 NFC chip.
3 *
4 * Copyright (C) Nokia Corporation
5 *
6 * Author: Jari Vanhala <ext-jari.vanhala@nokia.com>
7 * Contact: Matti Aaltoenn <matti.j.aaltonen@nokia.com>
8 *
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * version 2 as published by the Free Software Foundation.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 */
22
23#ifndef _PN544_H_
24#define _PN544_H_
25
26#include <linux/i2c.h>
27
28#define PN544_DRIVER_NAME "pn544"
29#define PN544_MAXWINDOW_SIZE 7
30#define PN544_WINDOW_SIZE 4
31#define PN544_RETRIES 10
32#define PN544_MAX_I2C_TRANSFER 0x0400
33#define PN544_MSG_MAX_SIZE 0x21 /* at normal HCI mode */
34
35/* ioctl */
36#define PN544_CHAR_BASE 'P'
37#define PN544_IOR(num, dtype) _IOR(PN544_CHAR_BASE, num, dtype)
38#define PN544_IOW(num, dtype) _IOW(PN544_CHAR_BASE, num, dtype)
39#define PN544_GET_FW_MODE PN544_IOW(1, unsigned int)
40#define PN544_SET_FW_MODE PN544_IOW(2, unsigned int)
41#define PN544_GET_DEBUG PN544_IOW(3, unsigned int)
42#define PN544_SET_DEBUG PN544_IOW(4, unsigned int)
43
44/* Timing restrictions (ms) */
45#define PN544_RESETVEN_TIME 30 /* 7 */
46#define PN544_PVDDVEN_TIME 0
47#define PN544_VBATVEN_TIME 0
48#define PN544_GPIO4VEN_TIME 0
49#define PN544_WAKEUP_ACK 5
50#define PN544_WAKEUP_GUARD (PN544_WAKEUP_ACK + 1)
51#define PN544_INACTIVITY_TIME 1000
52#define PN544_INTERFRAME_DELAY 200 /* us */
53#define PN544_BAUDRATE_CHANGE 150 /* us */
54
55/* Debug bits */
56#define PN544_DEBUG_BUF 0x01
57#define PN544_DEBUG_READ 0x02
58#define PN544_DEBUG_WRITE 0x04
59#define PN544_DEBUG_IRQ 0x08
60#define PN544_DEBUG_CALLS 0x10
61#define PN544_DEBUG_MODE 0x20
62
63/* Normal (HCI) mode */
64#define PN544_LLC_HCI_OVERHEAD 3 /* header + crc (to length) */
65#define PN544_LLC_MIN_SIZE (1 + PN544_LLC_HCI_OVERHEAD) /* length + */
66#define PN544_LLC_MAX_DATA (PN544_MSG_MAX_SIZE - 2)
67#define PN544_LLC_MAX_HCI_SIZE (PN544_LLC_MAX_DATA - 2)
68
69struct pn544_llc_packet {
70 unsigned char length; /* of rest of packet */
71 unsigned char header;
72 unsigned char data[PN544_LLC_MAX_DATA]; /* includes crc-ccitt */
73};
74
75/* Firmware upgrade mode */
76#define PN544_FW_HEADER_SIZE 3
77/* max fw transfer is 1024bytes, but I2C limits it to 0xC0 */
78#define PN544_MAX_FW_DATA (PN544_MAX_I2C_TRANSFER - PN544_FW_HEADER_SIZE)
79
80struct pn544_fw_packet {
81 unsigned char command; /* status in answer */
82 unsigned char length[2]; /* big-endian order (msf) */
83 unsigned char data[PN544_MAX_FW_DATA];
84};
85
86#ifdef __KERNEL__
87/* board config */
88struct pn544_nfc_platform_data {
89 int (*request_resources) (struct i2c_client *client);
90 void (*free_resources) (void);
91 void (*enable) (int fw);
92 int (*test) (void);
93 void (*disable) (void);
94};
95#endif /* __KERNEL__ */
96
97#endif /* _PN544_H_ */
diff --git a/include/linux/pci_ids.h b/include/linux/pci_ids.h
index ab47732d81e0..ae0dc453e3e2 100644
--- a/include/linux/pci_ids.h
+++ b/include/linux/pci_ids.h
@@ -2369,8 +2369,10 @@
2369#define PCI_DEVICE_ID_JMICRON_JMB38X_SD 0x2381 2369#define PCI_DEVICE_ID_JMICRON_JMB38X_SD 0x2381
2370#define PCI_DEVICE_ID_JMICRON_JMB38X_MMC 0x2382 2370#define PCI_DEVICE_ID_JMICRON_JMB38X_MMC 0x2382
2371#define PCI_DEVICE_ID_JMICRON_JMB38X_MS 0x2383 2371#define PCI_DEVICE_ID_JMICRON_JMB38X_MS 0x2383
2372#define PCI_DEVICE_ID_JMICRON_JMB385_MS 0x2388
2372#define PCI_DEVICE_ID_JMICRON_JMB388_SD 0x2391 2373#define PCI_DEVICE_ID_JMICRON_JMB388_SD 0x2391
2373#define PCI_DEVICE_ID_JMICRON_JMB388_ESD 0x2392 2374#define PCI_DEVICE_ID_JMICRON_JMB388_ESD 0x2392
2375#define PCI_DEVICE_ID_JMICRON_JMB390_MS 0x2393
2374 2376
2375#define PCI_VENDOR_ID_KORENIX 0x1982 2377#define PCI_VENDOR_ID_KORENIX 0x1982
2376#define PCI_DEVICE_ID_KORENIX_JETCARDF0 0x1600 2378#define PCI_DEVICE_ID_KORENIX_JETCARDF0 0x1600
diff --git a/include/linux/poll.h b/include/linux/poll.h
index 56e76af78102..1a2ccd6f3823 100644
--- a/include/linux/poll.h
+++ b/include/linux/poll.h
@@ -57,7 +57,7 @@ struct poll_table_entry {
57}; 57};
58 58
59/* 59/*
60 * Structures and helpers for sys_poll/sys_poll 60 * Structures and helpers for select/poll syscall
61 */ 61 */
62struct poll_wqueues { 62struct poll_wqueues {
63 poll_table pt; 63 poll_table pt;
diff --git a/include/linux/pps.h b/include/linux/pps.h
index 0194ab06177b..a9bb1d93451a 100644
--- a/include/linux/pps.h
+++ b/include/linux/pps.h
@@ -114,11 +114,18 @@ struct pps_fdata {
114 struct pps_ktime timeout; 114 struct pps_ktime timeout;
115}; 115};
116 116
117struct pps_bind_args {
118 int tsformat; /* format of time stamps */
119 int edge; /* selected event type */
120 int consumer; /* selected kernel consumer */
121};
122
117#include <linux/ioctl.h> 123#include <linux/ioctl.h>
118 124
119#define PPS_GETPARAMS _IOR('p', 0xa1, struct pps_kparams *) 125#define PPS_GETPARAMS _IOR('p', 0xa1, struct pps_kparams *)
120#define PPS_SETPARAMS _IOW('p', 0xa2, struct pps_kparams *) 126#define PPS_SETPARAMS _IOW('p', 0xa2, struct pps_kparams *)
121#define PPS_GETCAP _IOR('p', 0xa3, int *) 127#define PPS_GETCAP _IOR('p', 0xa3, int *)
122#define PPS_FETCH _IOWR('p', 0xa4, struct pps_fdata *) 128#define PPS_FETCH _IOWR('p', 0xa4, struct pps_fdata *)
129#define PPS_KC_BIND _IOW('p', 0xa5, struct pps_bind_args *)
123 130
124#endif /* _PPS_H_ */ 131#endif /* _PPS_H_ */
diff --git a/include/linux/pps_kernel.h b/include/linux/pps_kernel.h
index e0a193f830ef..94048547f29a 100644
--- a/include/linux/pps_kernel.h
+++ b/include/linux/pps_kernel.h
@@ -18,6 +18,9 @@
18 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 18 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 */ 19 */
20 20
21#ifndef LINUX_PPS_KERNEL_H
22#define LINUX_PPS_KERNEL_H
23
21#include <linux/pps.h> 24#include <linux/pps.h>
22 25
23#include <linux/cdev.h> 26#include <linux/cdev.h>
@@ -28,18 +31,28 @@
28 * Global defines 31 * Global defines
29 */ 32 */
30 33
34struct pps_device;
35
31/* The specific PPS source info */ 36/* The specific PPS source info */
32struct pps_source_info { 37struct pps_source_info {
33 char name[PPS_MAX_NAME_LEN]; /* simbolic name */ 38 char name[PPS_MAX_NAME_LEN]; /* simbolic name */
34 char path[PPS_MAX_NAME_LEN]; /* path of connected device */ 39 char path[PPS_MAX_NAME_LEN]; /* path of connected device */
35 int mode; /* PPS's allowed mode */ 40 int mode; /* PPS's allowed mode */
36 41
37 void (*echo)(int source, int event, void *data); /* PPS echo function */ 42 void (*echo)(struct pps_device *pps,
43 int event, void *data); /* PPS echo function */
38 44
39 struct module *owner; 45 struct module *owner;
40 struct device *dev; 46 struct device *dev;
41}; 47};
42 48
49struct pps_event_time {
50#ifdef CONFIG_NTP_PPS
51 struct timespec ts_raw;
52#endif /* CONFIG_NTP_PPS */
53 struct timespec ts_real;
54};
55
43/* The main struct */ 56/* The main struct */
44struct pps_device { 57struct pps_device {
45 struct pps_source_info info; /* PSS source info */ 58 struct pps_source_info info; /* PSS source info */
@@ -52,38 +65,56 @@ struct pps_device {
52 struct pps_ktime clear_tu; 65 struct pps_ktime clear_tu;
53 int current_mode; /* PPS mode at event time */ 66 int current_mode; /* PPS mode at event time */
54 67
55 int go; /* PPS event is arrived? */ 68 unsigned int last_ev; /* last PPS event id */
56 wait_queue_head_t queue; /* PPS event queue */ 69 wait_queue_head_t queue; /* PPS event queue */
57 70
58 unsigned int id; /* PPS source unique ID */ 71 unsigned int id; /* PPS source unique ID */
59 struct cdev cdev; 72 struct cdev cdev;
60 struct device *dev; 73 struct device *dev;
61 int devno;
62 struct fasync_struct *async_queue; /* fasync method */ 74 struct fasync_struct *async_queue; /* fasync method */
63 spinlock_t lock; 75 spinlock_t lock;
64
65 atomic_t usage; /* usage count */
66}; 76};
67 77
68/* 78/*
69 * Global variables 79 * Global variables
70 */ 80 */
71 81
72extern spinlock_t pps_idr_lock;
73extern struct idr pps_idr;
74extern struct timespec pps_irq_ts[];
75
76extern struct device_attribute pps_attrs[]; 82extern struct device_attribute pps_attrs[];
77 83
78/* 84/*
79 * Exported functions 85 * Exported functions
80 */ 86 */
81 87
82struct pps_device *pps_get_source(int source); 88extern struct pps_device *pps_register_source(
83extern void pps_put_source(struct pps_device *pps); 89 struct pps_source_info *info, int default_params);
84extern int pps_register_source(struct pps_source_info *info, 90extern void pps_unregister_source(struct pps_device *pps);
85 int default_params);
86extern void pps_unregister_source(int source);
87extern int pps_register_cdev(struct pps_device *pps); 91extern int pps_register_cdev(struct pps_device *pps);
88extern void pps_unregister_cdev(struct pps_device *pps); 92extern void pps_unregister_cdev(struct pps_device *pps);
89extern void pps_event(int source, struct pps_ktime *ts, int event, void *data); 93extern void pps_event(struct pps_device *pps,
94 struct pps_event_time *ts, int event, void *data);
95
96static inline void timespec_to_pps_ktime(struct pps_ktime *kt,
97 struct timespec ts)
98{
99 kt->sec = ts.tv_sec;
100 kt->nsec = ts.tv_nsec;
101}
102
103#ifdef CONFIG_NTP_PPS
104
105static inline void pps_get_ts(struct pps_event_time *ts)
106{
107 getnstime_raw_and_real(&ts->ts_raw, &ts->ts_real);
108}
109
110#else /* CONFIG_NTP_PPS */
111
112static inline void pps_get_ts(struct pps_event_time *ts)
113{
114 getnstimeofday(&ts->ts_real);
115}
116
117#endif /* CONFIG_NTP_PPS */
118
119#endif /* LINUX_PPS_KERNEL_H */
120
diff --git a/include/linux/printk.h b/include/linux/printk.h
index b772ca5fbdf0..ee048e77e1ae 100644
--- a/include/linux/printk.h
+++ b/include/linux/printk.h
@@ -4,14 +4,14 @@
4extern const char linux_banner[]; 4extern const char linux_banner[];
5extern const char linux_proc_banner[]; 5extern const char linux_proc_banner[];
6 6
7#define KERN_EMERG "<0>" /* system is unusable */ 7#define KERN_EMERG "<0>" /* system is unusable */
8#define KERN_ALERT "<1>" /* action must be taken immediately */ 8#define KERN_ALERT "<1>" /* action must be taken immediately */
9#define KERN_CRIT "<2>" /* critical conditions */ 9#define KERN_CRIT "<2>" /* critical conditions */
10#define KERN_ERR "<3>" /* error conditions */ 10#define KERN_ERR "<3>" /* error conditions */
11#define KERN_WARNING "<4>" /* warning conditions */ 11#define KERN_WARNING "<4>" /* warning conditions */
12#define KERN_NOTICE "<5>" /* normal but significant condition */ 12#define KERN_NOTICE "<5>" /* normal but significant condition */
13#define KERN_INFO "<6>" /* informational */ 13#define KERN_INFO "<6>" /* informational */
14#define KERN_DEBUG "<7>" /* debug-level messages */ 14#define KERN_DEBUG "<7>" /* debug-level messages */
15 15
16/* Use the default kernel loglevel */ 16/* Use the default kernel loglevel */
17#define KERN_DEFAULT "<d>" 17#define KERN_DEFAULT "<d>"
@@ -20,7 +20,7 @@ extern const char linux_proc_banner[];
20 * line that had no enclosing \n). Only to be used by core/arch code 20 * line that had no enclosing \n). Only to be used by core/arch code
21 * during early bootup (a continued line is not SMP-safe otherwise). 21 * during early bootup (a continued line is not SMP-safe otherwise).
22 */ 22 */
23#define KERN_CONT "<c>" 23#define KERN_CONT "<c>"
24 24
25extern int console_printk[]; 25extern int console_printk[];
26 26
@@ -29,6 +29,17 @@ extern int console_printk[];
29#define minimum_console_loglevel (console_printk[2]) 29#define minimum_console_loglevel (console_printk[2])
30#define default_console_loglevel (console_printk[3]) 30#define default_console_loglevel (console_printk[3])
31 31
32static inline void console_silent(void)
33{
34 console_loglevel = 0;
35}
36
37static inline void console_verbose(void)
38{
39 if (console_loglevel)
40 console_loglevel = 15;
41}
42
32struct va_format { 43struct va_format {
33 const char *fmt; 44 const char *fmt;
34 va_list *va; 45 va_list *va;
@@ -65,11 +76,27 @@ struct va_format {
65 */ 76 */
66#define HW_ERR "[Hardware Error]: " 77#define HW_ERR "[Hardware Error]: "
67 78
79/*
80 * Dummy printk for disabled debugging statements to use whilst maintaining
81 * gcc's format and side-effect checking.
82 */
83static inline __attribute__ ((format (printf, 1, 2)))
84int no_printk(const char *fmt, ...)
85{
86 return 0;
87}
88
89extern asmlinkage __attribute__ ((format (printf, 1, 2)))
90void early_printk(const char *fmt, ...);
91
92extern int printk_needs_cpu(int cpu);
93extern void printk_tick(void);
94
68#ifdef CONFIG_PRINTK 95#ifdef CONFIG_PRINTK
69asmlinkage int vprintk(const char *fmt, va_list args) 96asmlinkage __attribute__ ((format (printf, 1, 0)))
70 __attribute__ ((format (printf, 1, 0))); 97int vprintk(const char *fmt, va_list args);
71asmlinkage int printk(const char * fmt, ...) 98asmlinkage __attribute__ ((format (printf, 1, 2))) __cold
72 __attribute__ ((format (printf, 1, 2))) __cold; 99int printk(const char *fmt, ...);
73 100
74/* 101/*
75 * Please don't use printk_ratelimit(), because it shares ratelimiting state 102 * Please don't use printk_ratelimit(), because it shares ratelimiting state
@@ -83,99 +110,56 @@ extern bool printk_timed_ratelimit(unsigned long *caller_jiffies,
83 110
84extern int printk_delay_msec; 111extern int printk_delay_msec;
85extern int dmesg_restrict; 112extern int dmesg_restrict;
86 113extern int kptr_restrict;
87/*
88 * Print a one-time message (analogous to WARN_ONCE() et al):
89 */
90#define printk_once(x...) ({ \
91 static bool __print_once; \
92 \
93 if (!__print_once) { \
94 __print_once = true; \
95 printk(x); \
96 } \
97})
98 114
99void log_buf_kexec_setup(void); 115void log_buf_kexec_setup(void);
100#else 116#else
101static inline int vprintk(const char *s, va_list args) 117static inline __attribute__ ((format (printf, 1, 0)))
102 __attribute__ ((format (printf, 1, 0))); 118int vprintk(const char *s, va_list args)
103static inline int vprintk(const char *s, va_list args) { return 0; }
104static inline int printk(const char *s, ...)
105 __attribute__ ((format (printf, 1, 2)));
106static inline int __cold printk(const char *s, ...) { return 0; }
107static inline int printk_ratelimit(void) { return 0; }
108static inline bool printk_timed_ratelimit(unsigned long *caller_jiffies, \
109 unsigned int interval_msec) \
110 { return false; }
111
112/* No effect, but we still get type checking even in the !PRINTK case: */
113#define printk_once(x...) printk(x)
114
115static inline void log_buf_kexec_setup(void)
116{ 119{
120 return 0;
117} 121}
118#endif 122static inline __attribute__ ((format (printf, 1, 2))) __cold
119 123int printk(const char *s, ...)
120/*
121 * Dummy printk for disabled debugging statements to use whilst maintaining
122 * gcc's format and side-effect checking.
123 */
124static inline __attribute__ ((format (printf, 1, 2)))
125int no_printk(const char *s, ...) { return 0; }
126
127extern int printk_needs_cpu(int cpu);
128extern void printk_tick(void);
129
130extern void asmlinkage __attribute__((format(printf, 1, 2)))
131 early_printk(const char *fmt, ...);
132
133static inline void console_silent(void)
134{ 124{
135 console_loglevel = 0; 125 return 0;
126}
127static inline int printk_ratelimit(void)
128{
129 return 0;
130}
131static inline bool printk_timed_ratelimit(unsigned long *caller_jiffies,
132 unsigned int interval_msec)
133{
134 return false;
136} 135}
137 136
138static inline void console_verbose(void) 137static inline void log_buf_kexec_setup(void)
139{ 138{
140 if (console_loglevel)
141 console_loglevel = 15;
142} 139}
140#endif
143 141
144extern void dump_stack(void) __cold; 142extern void dump_stack(void) __cold;
145 143
146enum {
147 DUMP_PREFIX_NONE,
148 DUMP_PREFIX_ADDRESS,
149 DUMP_PREFIX_OFFSET
150};
151extern void hex_dump_to_buffer(const void *buf, size_t len,
152 int rowsize, int groupsize,
153 char *linebuf, size_t linebuflen, bool ascii);
154extern void print_hex_dump(const char *level, const char *prefix_str,
155 int prefix_type, int rowsize, int groupsize,
156 const void *buf, size_t len, bool ascii);
157extern void print_hex_dump_bytes(const char *prefix_str, int prefix_type,
158 const void *buf, size_t len);
159
160#ifndef pr_fmt 144#ifndef pr_fmt
161#define pr_fmt(fmt) fmt 145#define pr_fmt(fmt) fmt
162#endif 146#endif
163 147
164#define pr_emerg(fmt, ...) \ 148#define pr_emerg(fmt, ...) \
165 printk(KERN_EMERG pr_fmt(fmt), ##__VA_ARGS__) 149 printk(KERN_EMERG pr_fmt(fmt), ##__VA_ARGS__)
166#define pr_alert(fmt, ...) \ 150#define pr_alert(fmt, ...) \
167 printk(KERN_ALERT pr_fmt(fmt), ##__VA_ARGS__) 151 printk(KERN_ALERT pr_fmt(fmt), ##__VA_ARGS__)
168#define pr_crit(fmt, ...) \ 152#define pr_crit(fmt, ...) \
169 printk(KERN_CRIT pr_fmt(fmt), ##__VA_ARGS__) 153 printk(KERN_CRIT pr_fmt(fmt), ##__VA_ARGS__)
170#define pr_err(fmt, ...) \ 154#define pr_err(fmt, ...) \
171 printk(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__) 155 printk(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__)
172#define pr_warning(fmt, ...) \ 156#define pr_warning(fmt, ...) \
173 printk(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__) 157 printk(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__)
174#define pr_warn pr_warning 158#define pr_warn pr_warning
175#define pr_notice(fmt, ...) \ 159#define pr_notice(fmt, ...) \
176 printk(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__) 160 printk(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__)
177#define pr_info(fmt, ...) \ 161#define pr_info(fmt, ...) \
178 printk(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__) 162 printk(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__)
179#define pr_cont(fmt, ...) \ 163#define pr_cont(fmt, ...) \
180 printk(KERN_CONT fmt, ##__VA_ARGS__) 164 printk(KERN_CONT fmt, ##__VA_ARGS__)
181 165
@@ -185,7 +169,7 @@ extern void print_hex_dump_bytes(const char *prefix_str, int prefix_type,
185 printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__) 169 printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
186#else 170#else
187#define pr_devel(fmt, ...) \ 171#define pr_devel(fmt, ...) \
188 ({ if (0) printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__); 0; }) 172 no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
189#endif 173#endif
190 174
191/* If you are writing a driver, please use dev_dbg instead */ 175/* If you are writing a driver, please use dev_dbg instead */
@@ -198,7 +182,51 @@ extern void print_hex_dump_bytes(const char *prefix_str, int prefix_type,
198 dynamic_pr_debug(fmt, ##__VA_ARGS__) 182 dynamic_pr_debug(fmt, ##__VA_ARGS__)
199#else 183#else
200#define pr_debug(fmt, ...) \ 184#define pr_debug(fmt, ...) \
201 ({ if (0) printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__); 0; }) 185 no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
186#endif
187
188/*
189 * Print a one-time message (analogous to WARN_ONCE() et al):
190 */
191
192#ifdef CONFIG_PRINTK
193#define printk_once(fmt, ...) \
194({ \
195 static bool __print_once; \
196 \
197 if (!__print_once) { \
198 __print_once = true; \
199 printk(fmt, ##__VA_ARGS__); \
200 } \
201})
202#else
203#define printk_once(fmt, ...) \
204 no_printk(fmt, ##__VA_ARGS__)
205#endif
206
207#define pr_emerg_once(fmt, ...) \
208 printk_once(KERN_EMERG pr_fmt(fmt), ##__VA_ARGS__)
209#define pr_alert_once(fmt, ...) \
210 printk_once(KERN_ALERT pr_fmt(fmt), ##__VA_ARGS__)
211#define pr_crit_once(fmt, ...) \
212 printk_once(KERN_CRIT pr_fmt(fmt), ##__VA_ARGS__)
213#define pr_err_once(fmt, ...) \
214 printk_once(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__)
215#define pr_warn_once(fmt, ...) \
216 printk_once(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__)
217#define pr_notice_once(fmt, ...) \
218 printk_once(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__)
219#define pr_info_once(fmt, ...) \
220 printk_once(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__)
221#define pr_cont_once(fmt, ...) \
222 printk_once(KERN_CONT pr_fmt(fmt), ##__VA_ARGS__)
223/* If you are writing a driver, please use dev_dbg instead */
224#if defined(DEBUG)
225#define pr_debug_once(fmt, ...) \
226 printk_once(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
227#else
228#define pr_debug_once(fmt, ...) \
229 no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
202#endif 230#endif
203 231
204/* 232/*
@@ -206,7 +234,8 @@ extern void print_hex_dump_bytes(const char *prefix_str, int prefix_type,
206 * no local ratelimit_state used in the !PRINTK case 234 * no local ratelimit_state used in the !PRINTK case
207 */ 235 */
208#ifdef CONFIG_PRINTK 236#ifdef CONFIG_PRINTK
209#define printk_ratelimited(fmt, ...) ({ \ 237#define printk_ratelimited(fmt, ...) \
238({ \
210 static DEFINE_RATELIMIT_STATE(_rs, \ 239 static DEFINE_RATELIMIT_STATE(_rs, \
211 DEFAULT_RATELIMIT_INTERVAL, \ 240 DEFAULT_RATELIMIT_INTERVAL, \
212 DEFAULT_RATELIMIT_BURST); \ 241 DEFAULT_RATELIMIT_BURST); \
@@ -215,34 +244,59 @@ extern void print_hex_dump_bytes(const char *prefix_str, int prefix_type,
215 printk(fmt, ##__VA_ARGS__); \ 244 printk(fmt, ##__VA_ARGS__); \
216}) 245})
217#else 246#else
218/* No effect, but we still get type checking even in the !PRINTK case: */ 247#define printk_ratelimited(fmt, ...) \
219#define printk_ratelimited printk 248 no_printk(fmt, ##__VA_ARGS__)
220#endif 249#endif
221 250
222#define pr_emerg_ratelimited(fmt, ...) \ 251#define pr_emerg_ratelimited(fmt, ...) \
223 printk_ratelimited(KERN_EMERG pr_fmt(fmt), ##__VA_ARGS__) 252 printk_ratelimited(KERN_EMERG pr_fmt(fmt), ##__VA_ARGS__)
224#define pr_alert_ratelimited(fmt, ...) \ 253#define pr_alert_ratelimited(fmt, ...) \
225 printk_ratelimited(KERN_ALERT pr_fmt(fmt), ##__VA_ARGS__) 254 printk_ratelimited(KERN_ALERT pr_fmt(fmt), ##__VA_ARGS__)
226#define pr_crit_ratelimited(fmt, ...) \ 255#define pr_crit_ratelimited(fmt, ...) \
227 printk_ratelimited(KERN_CRIT pr_fmt(fmt), ##__VA_ARGS__) 256 printk_ratelimited(KERN_CRIT pr_fmt(fmt), ##__VA_ARGS__)
228#define pr_err_ratelimited(fmt, ...) \ 257#define pr_err_ratelimited(fmt, ...) \
229 printk_ratelimited(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__) 258 printk_ratelimited(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__)
230#define pr_warning_ratelimited(fmt, ...) \ 259#define pr_warn_ratelimited(fmt, ...) \
231 printk_ratelimited(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__) 260 printk_ratelimited(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__)
232#define pr_warn_ratelimited pr_warning_ratelimited 261#define pr_notice_ratelimited(fmt, ...) \
233#define pr_notice_ratelimited(fmt, ...) \
234 printk_ratelimited(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__) 262 printk_ratelimited(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__)
235#define pr_info_ratelimited(fmt, ...) \ 263#define pr_info_ratelimited(fmt, ...) \
236 printk_ratelimited(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__) 264 printk_ratelimited(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__)
237/* no pr_cont_ratelimited, don't do that... */ 265/* no pr_cont_ratelimited, don't do that... */
238/* If you are writing a driver, please use dev_dbg instead */ 266/* If you are writing a driver, please use dev_dbg instead */
239#if defined(DEBUG) 267#if defined(DEBUG)
240#define pr_debug_ratelimited(fmt, ...) \ 268#define pr_debug_ratelimited(fmt, ...) \
241 printk_ratelimited(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__) 269 printk_ratelimited(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
242#else 270#else
243#define pr_debug_ratelimited(fmt, ...) \ 271#define pr_debug_ratelimited(fmt, ...) \
244 ({ if (0) printk_ratelimited(KERN_DEBUG pr_fmt(fmt), \ 272 no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
245 ##__VA_ARGS__); 0; }) 273#endif
274
275enum {
276 DUMP_PREFIX_NONE,
277 DUMP_PREFIX_ADDRESS,
278 DUMP_PREFIX_OFFSET
279};
280extern void hex_dump_to_buffer(const void *buf, size_t len,
281 int rowsize, int groupsize,
282 char *linebuf, size_t linebuflen, bool ascii);
283#ifdef CONFIG_PRINTK
284extern void print_hex_dump(const char *level, const char *prefix_str,
285 int prefix_type, int rowsize, int groupsize,
286 const void *buf, size_t len, bool ascii);
287extern void print_hex_dump_bytes(const char *prefix_str, int prefix_type,
288 const void *buf, size_t len);
289#else
290static inline void print_hex_dump(const char *level, const char *prefix_str,
291 int prefix_type, int rowsize, int groupsize,
292 const void *buf, size_t len, bool ascii)
293{
294}
295static inline void print_hex_dump_bytes(const char *prefix_str, int prefix_type,
296 const void *buf, size_t len)
297{
298}
299
246#endif 300#endif
247 301
248#endif 302#endif
diff --git a/include/linux/regulator/ab8500.h b/include/linux/regulator/ab8500.h
index f509877c2ed4..6a210f1511fc 100644
--- a/include/linux/regulator/ab8500.h
+++ b/include/linux/regulator/ab8500.h
@@ -11,15 +11,17 @@
11#define __LINUX_MFD_AB8500_REGULATOR_H 11#define __LINUX_MFD_AB8500_REGULATOR_H
12 12
13/* AB8500 regulators */ 13/* AB8500 regulators */
14#define AB8500_LDO_AUX1 0 14enum ab8500_regulator_id {
15#define AB8500_LDO_AUX2 1 15 AB8500_LDO_AUX1,
16#define AB8500_LDO_AUX3 2 16 AB8500_LDO_AUX2,
17#define AB8500_LDO_INTCORE 3 17 AB8500_LDO_AUX3,
18#define AB8500_LDO_TVOUT 4 18 AB8500_LDO_INTCORE,
19#define AB8500_LDO_AUDIO 5 19 AB8500_LDO_TVOUT,
20#define AB8500_LDO_ANAMIC1 6 20 AB8500_LDO_AUDIO,
21#define AB8500_LDO_ANAMIC2 7 21 AB8500_LDO_ANAMIC1,
22#define AB8500_LDO_DMIC 8 22 AB8500_LDO_ANAMIC2,
23#define AB8500_LDO_ANA 9 23 AB8500_LDO_DMIC,
24 24 AB8500_LDO_ANA,
25 AB8500_NUM_REGULATORS,
26};
25#endif 27#endif
diff --git a/include/linux/regulator/consumer.h b/include/linux/regulator/consumer.h
index ebd747265294..7954f6bd7edb 100644
--- a/include/linux/regulator/consumer.h
+++ b/include/linux/regulator/consumer.h
@@ -154,6 +154,7 @@ int regulator_is_supported_voltage(struct regulator *regulator,
154 int min_uV, int max_uV); 154 int min_uV, int max_uV);
155int regulator_set_voltage(struct regulator *regulator, int min_uV, int max_uV); 155int regulator_set_voltage(struct regulator *regulator, int min_uV, int max_uV);
156int regulator_get_voltage(struct regulator *regulator); 156int regulator_get_voltage(struct regulator *regulator);
157int regulator_sync_voltage(struct regulator *regulator);
157int regulator_set_current_limit(struct regulator *regulator, 158int regulator_set_current_limit(struct regulator *regulator,
158 int min_uA, int max_uA); 159 int min_uA, int max_uA);
159int regulator_get_current_limit(struct regulator *regulator); 160int regulator_get_current_limit(struct regulator *regulator);
diff --git a/include/linux/regulator/driver.h b/include/linux/regulator/driver.h
index 592cd7c642c2..b8ed16a33c47 100644
--- a/include/linux/regulator/driver.h
+++ b/include/linux/regulator/driver.h
@@ -42,7 +42,11 @@ enum regulator_status {
42 * 42 *
43 * @set_voltage: Set the voltage for the regulator within the range specified. 43 * @set_voltage: Set the voltage for the regulator within the range specified.
44 * The driver should select the voltage closest to min_uV. 44 * The driver should select the voltage closest to min_uV.
45 * @set_voltage_sel: Set the voltage for the regulator using the specified
46 * selector.
45 * @get_voltage: Return the currently configured voltage for the regulator. 47 * @get_voltage: Return the currently configured voltage for the regulator.
48 * @get_voltage_sel: Return the currently configured voltage selector for the
49 * regulator.
46 * @list_voltage: Return one of the supported voltages, in microvolts; zero 50 * @list_voltage: Return one of the supported voltages, in microvolts; zero
47 * if the selector indicates a voltage that is unusable on this system; 51 * if the selector indicates a voltage that is unusable on this system;
48 * or negative errno. Selectors range from zero to one less than 52 * or negative errno. Selectors range from zero to one less than
@@ -79,8 +83,11 @@ struct regulator_ops {
79 int (*list_voltage) (struct regulator_dev *, unsigned selector); 83 int (*list_voltage) (struct regulator_dev *, unsigned selector);
80 84
81 /* get/set regulator voltage */ 85 /* get/set regulator voltage */
82 int (*set_voltage) (struct regulator_dev *, int min_uV, int max_uV); 86 int (*set_voltage) (struct regulator_dev *, int min_uV, int max_uV,
87 unsigned *selector);
88 int (*set_voltage_sel) (struct regulator_dev *, unsigned selector);
83 int (*get_voltage) (struct regulator_dev *); 89 int (*get_voltage) (struct regulator_dev *);
90 int (*get_voltage_sel) (struct regulator_dev *);
84 91
85 /* get/set regulator current */ 92 /* get/set regulator current */
86 int (*set_current_limit) (struct regulator_dev *, 93 int (*set_current_limit) (struct regulator_dev *,
@@ -168,9 +175,9 @@ struct regulator_desc {
168 */ 175 */
169struct regulator_dev { 176struct regulator_dev {
170 struct regulator_desc *desc; 177 struct regulator_desc *desc;
171 int use_count;
172 int open_count;
173 int exclusive; 178 int exclusive;
179 u32 use_count;
180 u32 open_count;
174 181
175 /* lists we belong to */ 182 /* lists we belong to */
176 struct list_head list; /* list of all regulators */ 183 struct list_head list; /* list of all regulators */
@@ -188,10 +195,14 @@ struct regulator_dev {
188 struct regulator_dev *supply; /* for tree */ 195 struct regulator_dev *supply; /* for tree */
189 196
190 void *reg_data; /* regulator_dev data */ 197 void *reg_data; /* regulator_dev data */
198
199#ifdef CONFIG_DEBUG_FS
200 struct dentry *debugfs;
201#endif
191}; 202};
192 203
193struct regulator_dev *regulator_register(struct regulator_desc *regulator_desc, 204struct regulator_dev *regulator_register(struct regulator_desc *regulator_desc,
194 struct device *dev, struct regulator_init_data *init_data, 205 struct device *dev, const struct regulator_init_data *init_data,
195 void *driver_data); 206 void *driver_data);
196void regulator_unregister(struct regulator_dev *rdev); 207void regulator_unregister(struct regulator_dev *rdev);
197 208
diff --git a/include/linux/rio.h b/include/linux/rio.h
index 0bed941f9b13..ff681ebba585 100644
--- a/include/linux/rio.h
+++ b/include/linux/rio.h
@@ -66,14 +66,62 @@
66 66
67#define RIO_PW_MSG_SIZE 64 67#define RIO_PW_MSG_SIZE 64
68 68
69/*
70 * A component tag value (stored in the component tag CSR) is used as device's
71 * unique identifier assigned during enumeration. Besides being used for
72 * identifying switches (which do not have device ID register), it also is used
73 * by error management notification and therefore has to be assigned
74 * to endpoints as well.
75 */
76#define RIO_CTAG_RESRVD 0xfffe0000 /* Reserved */
77#define RIO_CTAG_UDEVID 0x0001ffff /* Unique device identifier */
78
69extern struct bus_type rio_bus_type; 79extern struct bus_type rio_bus_type;
70extern struct device rio_bus; 80extern struct device rio_bus;
71extern struct list_head rio_devices; /* list of all devices */ 81extern struct list_head rio_devices; /* list of all devices */
72 82
73struct rio_mport; 83struct rio_mport;
84struct rio_dev;
74union rio_pw_msg; 85union rio_pw_msg;
75 86
76/** 87/**
88 * struct rio_switch - RIO switch info
89 * @node: Node in global list of switches
90 * @switchid: Switch ID that is unique across a network
91 * @route_table: Copy of switch routing table
92 * @port_ok: Status of each port (one bit per port) - OK=1 or UNINIT=0
93 * @add_entry: Callback for switch-specific route add function
94 * @get_entry: Callback for switch-specific route get function
95 * @clr_table: Callback for switch-specific clear route table function
96 * @set_domain: Callback for switch-specific domain setting function
97 * @get_domain: Callback for switch-specific domain get function
98 * @em_init: Callback for switch-specific error management init function
99 * @em_handle: Callback for switch-specific error management handler function
100 * @sw_sysfs: Callback that initializes switch-specific sysfs attributes
101 * @nextdev: Array of per-port pointers to the next attached device
102 */
103struct rio_switch {
104 struct list_head node;
105 u16 switchid;
106 u8 *route_table;
107 u32 port_ok;
108 int (*add_entry) (struct rio_mport *mport, u16 destid, u8 hopcount,
109 u16 table, u16 route_destid, u8 route_port);
110 int (*get_entry) (struct rio_mport *mport, u16 destid, u8 hopcount,
111 u16 table, u16 route_destid, u8 *route_port);
112 int (*clr_table) (struct rio_mport *mport, u16 destid, u8 hopcount,
113 u16 table);
114 int (*set_domain) (struct rio_mport *mport, u16 destid, u8 hopcount,
115 u8 sw_domain);
116 int (*get_domain) (struct rio_mport *mport, u16 destid, u8 hopcount,
117 u8 *sw_domain);
118 int (*em_init) (struct rio_dev *dev);
119 int (*em_handle) (struct rio_dev *dev, u8 swport);
120 int (*sw_sysfs) (struct rio_dev *dev, int create);
121 struct rio_dev *nextdev[0];
122};
123
124/**
77 * struct rio_dev - RIO device info 125 * struct rio_dev - RIO device info
78 * @global_list: Node in list of all RIO devices 126 * @global_list: Node in list of all RIO devices
79 * @net_list: Node in list of RIO devices in a network 127 * @net_list: Node in list of RIO devices in a network
@@ -93,13 +141,14 @@ union rio_pw_msg;
93 * @phys_efptr: RIO device extended features pointer 141 * @phys_efptr: RIO device extended features pointer
94 * @em_efptr: RIO Error Management features pointer 142 * @em_efptr: RIO Error Management features pointer
95 * @dma_mask: Mask of bits of RIO address this device implements 143 * @dma_mask: Mask of bits of RIO address this device implements
96 * @rswitch: Pointer to &struct rio_switch if valid for this device
97 * @driver: Driver claiming this device 144 * @driver: Driver claiming this device
98 * @dev: Device model device 145 * @dev: Device model device
99 * @riores: RIO resources this device owns 146 * @riores: RIO resources this device owns
100 * @pwcback: port-write callback function for this device 147 * @pwcback: port-write callback function for this device
101 * @destid: Network destination ID 148 * @destid: Network destination ID (or associated destid for switch)
149 * @hopcount: Hopcount to this device
102 * @prev: Previous RIO device connected to the current one 150 * @prev: Previous RIO device connected to the current one
151 * @rswitch: struct rio_switch (if valid for this device)
103 */ 152 */
104struct rio_dev { 153struct rio_dev {
105 struct list_head global_list; /* node in list of all RIO devices */ 154 struct list_head global_list; /* node in list of all RIO devices */
@@ -120,18 +169,20 @@ struct rio_dev {
120 u32 phys_efptr; 169 u32 phys_efptr;
121 u32 em_efptr; 170 u32 em_efptr;
122 u64 dma_mask; 171 u64 dma_mask;
123 struct rio_switch *rswitch; /* RIO switch info */
124 struct rio_driver *driver; /* RIO driver claiming this device */ 172 struct rio_driver *driver; /* RIO driver claiming this device */
125 struct device dev; /* LDM device structure */ 173 struct device dev; /* LDM device structure */
126 struct resource riores[RIO_MAX_DEV_RESOURCES]; 174 struct resource riores[RIO_MAX_DEV_RESOURCES];
127 int (*pwcback) (struct rio_dev *rdev, union rio_pw_msg *msg, int step); 175 int (*pwcback) (struct rio_dev *rdev, union rio_pw_msg *msg, int step);
128 u16 destid; 176 u16 destid;
177 u8 hopcount;
129 struct rio_dev *prev; 178 struct rio_dev *prev;
179 struct rio_switch rswitch[0]; /* RIO switch info */
130}; 180};
131 181
132#define rio_dev_g(n) list_entry(n, struct rio_dev, global_list) 182#define rio_dev_g(n) list_entry(n, struct rio_dev, global_list)
133#define rio_dev_f(n) list_entry(n, struct rio_dev, net_list) 183#define rio_dev_f(n) list_entry(n, struct rio_dev, net_list)
134#define to_rio_dev(n) container_of(n, struct rio_dev, dev) 184#define to_rio_dev(n) container_of(n, struct rio_dev, dev)
185#define sw_to_rio_dev(n) container_of(n, struct rio_dev, rswitch[0])
135 186
136/** 187/**
137 * struct rio_msg - RIO message event 188 * struct rio_msg - RIO message event
@@ -224,49 +275,6 @@ struct rio_net {
224#define RIO_SW_SYSFS_CREATE 1 /* Create switch attributes */ 275#define RIO_SW_SYSFS_CREATE 1 /* Create switch attributes */
225#define RIO_SW_SYSFS_REMOVE 0 /* Remove switch attributes */ 276#define RIO_SW_SYSFS_REMOVE 0 /* Remove switch attributes */
226 277
227/**
228 * struct rio_switch - RIO switch info
229 * @node: Node in global list of switches
230 * @rdev: Associated RIO device structure
231 * @switchid: Switch ID that is unique across a network
232 * @hopcount: Hopcount to this switch
233 * @destid: Associated destid in the path
234 * @route_table: Copy of switch routing table
235 * @port_ok: Status of each port (one bit per port) - OK=1 or UNINIT=0
236 * @add_entry: Callback for switch-specific route add function
237 * @get_entry: Callback for switch-specific route get function
238 * @clr_table: Callback for switch-specific clear route table function
239 * @set_domain: Callback for switch-specific domain setting function
240 * @get_domain: Callback for switch-specific domain get function
241 * @em_init: Callback for switch-specific error management initialization function
242 * @em_handle: Callback for switch-specific error management handler function
243 * @sw_sysfs: Callback that initializes switch-specific sysfs attributes
244 * @nextdev: Array of per-port pointers to the next attached device
245 */
246struct rio_switch {
247 struct list_head node;
248 struct rio_dev *rdev;
249 u16 switchid;
250 u16 hopcount;
251 u16 destid;
252 u8 *route_table;
253 u32 port_ok;
254 int (*add_entry) (struct rio_mport * mport, u16 destid, u8 hopcount,
255 u16 table, u16 route_destid, u8 route_port);
256 int (*get_entry) (struct rio_mport * mport, u16 destid, u8 hopcount,
257 u16 table, u16 route_destid, u8 * route_port);
258 int (*clr_table) (struct rio_mport *mport, u16 destid, u8 hopcount,
259 u16 table);
260 int (*set_domain) (struct rio_mport *mport, u16 destid, u8 hopcount,
261 u8 sw_domain);
262 int (*get_domain) (struct rio_mport *mport, u16 destid, u8 hopcount,
263 u8 *sw_domain);
264 int (*em_init) (struct rio_dev *dev);
265 int (*em_handle) (struct rio_dev *dev, u8 swport);
266 int (*sw_sysfs) (struct rio_dev *dev, int create);
267 struct rio_dev *nextdev[0];
268};
269
270/* Low-level architecture-dependent routines */ 278/* Low-level architecture-dependent routines */
271 279
272/** 280/**
diff --git a/include/linux/rio_drv.h b/include/linux/rio_drv.h
index edc55da717b3..e09e565c4bce 100644
--- a/include/linux/rio_drv.h
+++ b/include/linux/rio_drv.h
@@ -150,16 +150,8 @@ static inline int rio_local_write_config_8(struct rio_mport *port, u32 offset,
150static inline int rio_read_config_32(struct rio_dev *rdev, u32 offset, 150static inline int rio_read_config_32(struct rio_dev *rdev, u32 offset,
151 u32 * data) 151 u32 * data)
152{ 152{
153 u8 hopcount = 0xff; 153 return rio_mport_read_config_32(rdev->net->hport, rdev->destid,
154 u16 destid = rdev->destid; 154 rdev->hopcount, offset, data);
155
156 if (rdev->rswitch) {
157 destid = rdev->rswitch->destid;
158 hopcount = rdev->rswitch->hopcount;
159 }
160
161 return rio_mport_read_config_32(rdev->net->hport, destid, hopcount,
162 offset, data);
163}; 155};
164 156
165/** 157/**
@@ -174,16 +166,8 @@ static inline int rio_read_config_32(struct rio_dev *rdev, u32 offset,
174static inline int rio_write_config_32(struct rio_dev *rdev, u32 offset, 166static inline int rio_write_config_32(struct rio_dev *rdev, u32 offset,
175 u32 data) 167 u32 data)
176{ 168{
177 u8 hopcount = 0xff; 169 return rio_mport_write_config_32(rdev->net->hport, rdev->destid,
178 u16 destid = rdev->destid; 170 rdev->hopcount, offset, data);
179
180 if (rdev->rswitch) {
181 destid = rdev->rswitch->destid;
182 hopcount = rdev->rswitch->hopcount;
183 }
184
185 return rio_mport_write_config_32(rdev->net->hport, destid, hopcount,
186 offset, data);
187}; 171};
188 172
189/** 173/**
@@ -198,16 +182,8 @@ static inline int rio_write_config_32(struct rio_dev *rdev, u32 offset,
198static inline int rio_read_config_16(struct rio_dev *rdev, u32 offset, 182static inline int rio_read_config_16(struct rio_dev *rdev, u32 offset,
199 u16 * data) 183 u16 * data)
200{ 184{
201 u8 hopcount = 0xff; 185 return rio_mport_read_config_16(rdev->net->hport, rdev->destid,
202 u16 destid = rdev->destid; 186 rdev->hopcount, offset, data);
203
204 if (rdev->rswitch) {
205 destid = rdev->rswitch->destid;
206 hopcount = rdev->rswitch->hopcount;
207 }
208
209 return rio_mport_read_config_16(rdev->net->hport, destid, hopcount,
210 offset, data);
211}; 187};
212 188
213/** 189/**
@@ -222,16 +198,8 @@ static inline int rio_read_config_16(struct rio_dev *rdev, u32 offset,
222static inline int rio_write_config_16(struct rio_dev *rdev, u32 offset, 198static inline int rio_write_config_16(struct rio_dev *rdev, u32 offset,
223 u16 data) 199 u16 data)
224{ 200{
225 u8 hopcount = 0xff; 201 return rio_mport_write_config_16(rdev->net->hport, rdev->destid,
226 u16 destid = rdev->destid; 202 rdev->hopcount, offset, data);
227
228 if (rdev->rswitch) {
229 destid = rdev->rswitch->destid;
230 hopcount = rdev->rswitch->hopcount;
231 }
232
233 return rio_mport_write_config_16(rdev->net->hport, destid, hopcount,
234 offset, data);
235}; 203};
236 204
237/** 205/**
@@ -245,16 +213,8 @@ static inline int rio_write_config_16(struct rio_dev *rdev, u32 offset,
245 */ 213 */
246static inline int rio_read_config_8(struct rio_dev *rdev, u32 offset, u8 * data) 214static inline int rio_read_config_8(struct rio_dev *rdev, u32 offset, u8 * data)
247{ 215{
248 u8 hopcount = 0xff; 216 return rio_mport_read_config_8(rdev->net->hport, rdev->destid,
249 u16 destid = rdev->destid; 217 rdev->hopcount, offset, data);
250
251 if (rdev->rswitch) {
252 destid = rdev->rswitch->destid;
253 hopcount = rdev->rswitch->hopcount;
254 }
255
256 return rio_mport_read_config_8(rdev->net->hport, destid, hopcount,
257 offset, data);
258}; 218};
259 219
260/** 220/**
@@ -268,16 +228,8 @@ static inline int rio_read_config_8(struct rio_dev *rdev, u32 offset, u8 * data)
268 */ 228 */
269static inline int rio_write_config_8(struct rio_dev *rdev, u32 offset, u8 data) 229static inline int rio_write_config_8(struct rio_dev *rdev, u32 offset, u8 data)
270{ 230{
271 u8 hopcount = 0xff; 231 return rio_mport_write_config_8(rdev->net->hport, rdev->destid,
272 u16 destid = rdev->destid; 232 rdev->hopcount, offset, data);
273
274 if (rdev->rswitch) {
275 destid = rdev->rswitch->destid;
276 hopcount = rdev->rswitch->hopcount;
277 }
278
279 return rio_mport_write_config_8(rdev->net->hport, destid, hopcount,
280 offset, data);
281}; 233};
282 234
283extern int rio_mport_send_doorbell(struct rio_mport *mport, u16 destid, 235extern int rio_mport_send_doorbell(struct rio_mport *mport, u16 destid,
diff --git a/include/linux/rio_ids.h b/include/linux/rio_ids.h
index ee7b6ada188f..7410d3365e2a 100644
--- a/include/linux/rio_ids.h
+++ b/include/linux/rio_ids.h
@@ -36,5 +36,7 @@
36#define RIO_DID_IDTCPS10Q 0x035e 36#define RIO_DID_IDTCPS10Q 0x035e
37#define RIO_DID_IDTCPS1848 0x0374 37#define RIO_DID_IDTCPS1848 0x0374
38#define RIO_DID_IDTCPS1616 0x0379 38#define RIO_DID_IDTCPS1616 0x0379
39#define RIO_DID_IDTVPS1616 0x0377
40#define RIO_DID_IDTSPS1616 0x0378
39 41
40#endif /* LINUX_RIO_IDS_H */ 42#endif /* LINUX_RIO_IDS_H */
diff --git a/include/linux/romfs_fs.h b/include/linux/romfs_fs.h
index c490fbc43fe2..5f57f93b284f 100644
--- a/include/linux/romfs_fs.h
+++ b/include/linux/romfs_fs.h
@@ -1,6 +1,9 @@
1#ifndef __LINUX_ROMFS_FS_H 1#ifndef __LINUX_ROMFS_FS_H
2#define __LINUX_ROMFS_FS_H 2#define __LINUX_ROMFS_FS_H
3 3
4#include <linux/types.h>
5#include <linux/fs.h>
6
4/* The basic structures of the romfs filesystem */ 7/* The basic structures of the romfs filesystem */
5 8
6#define ROMBSIZE BLOCK_SIZE 9#define ROMBSIZE BLOCK_SIZE
diff --git a/include/linux/sched.h b/include/linux/sched.h
index abc527aa8550..96e23215e276 100644
--- a/include/linux/sched.h
+++ b/include/linux/sched.h
@@ -683,7 +683,7 @@ struct user_struct {
683 atomic_t fanotify_listeners; 683 atomic_t fanotify_listeners;
684#endif 684#endif
685#ifdef CONFIG_EPOLL 685#ifdef CONFIG_EPOLL
686 atomic_t epoll_watches; /* The number of file descriptors currently watched */ 686 atomic_long_t epoll_watches; /* The number of file descriptors currently watched */
687#endif 687#endif
688#ifdef CONFIG_POSIX_MQUEUE 688#ifdef CONFIG_POSIX_MQUEUE
689 /* protected by mq_lock */ 689 /* protected by mq_lock */
diff --git a/include/linux/serial_core.h b/include/linux/serial_core.h
index a23fa29d4eb0..758c5b0c6fd3 100644
--- a/include/linux/serial_core.h
+++ b/include/linux/serial_core.h
@@ -212,6 +212,7 @@
212#include <linux/tty.h> 212#include <linux/tty.h>
213#include <linux/mutex.h> 213#include <linux/mutex.h>
214#include <linux/sysrq.h> 214#include <linux/sysrq.h>
215#include <linux/pps_kernel.h>
215 216
216struct uart_port; 217struct uart_port;
217struct serial_struct; 218struct serial_struct;
@@ -528,10 +529,10 @@ uart_handle_dcd_change(struct uart_port *uport, unsigned int status)
528 struct uart_state *state = uport->state; 529 struct uart_state *state = uport->state;
529 struct tty_port *port = &state->port; 530 struct tty_port *port = &state->port;
530 struct tty_ldisc *ld = tty_ldisc_ref(port->tty); 531 struct tty_ldisc *ld = tty_ldisc_ref(port->tty);
531 struct timespec ts; 532 struct pps_event_time ts;
532 533
533 if (ld && ld->ops->dcd_change) 534 if (ld && ld->ops->dcd_change)
534 getnstimeofday(&ts); 535 pps_get_ts(&ts);
535 536
536 uport->icount.dcd++; 537 uport->icount.dcd++;
537#ifdef CONFIG_HARD_PPS 538#ifdef CONFIG_HARD_PPS
diff --git a/include/linux/socket.h b/include/linux/socket.h
index 5f65f14c4f44..edbb1d07ddf4 100644
--- a/include/linux/socket.h
+++ b/include/linux/socket.h
@@ -191,7 +191,8 @@ struct ucred {
191#define AF_PHONET 35 /* Phonet sockets */ 191#define AF_PHONET 35 /* Phonet sockets */
192#define AF_IEEE802154 36 /* IEEE802154 sockets */ 192#define AF_IEEE802154 36 /* IEEE802154 sockets */
193#define AF_CAIF 37 /* CAIF sockets */ 193#define AF_CAIF 37 /* CAIF sockets */
194#define AF_MAX 38 /* For now.. */ 194#define AF_ALG 38 /* Algorithm sockets */
195#define AF_MAX 39 /* For now.. */
195 196
196/* Protocol families, same as address families. */ 197/* Protocol families, same as address families. */
197#define PF_UNSPEC AF_UNSPEC 198#define PF_UNSPEC AF_UNSPEC
@@ -232,6 +233,7 @@ struct ucred {
232#define PF_PHONET AF_PHONET 233#define PF_PHONET AF_PHONET
233#define PF_IEEE802154 AF_IEEE802154 234#define PF_IEEE802154 AF_IEEE802154
234#define PF_CAIF AF_CAIF 235#define PF_CAIF AF_CAIF
236#define PF_ALG AF_ALG
235#define PF_MAX AF_MAX 237#define PF_MAX AF_MAX
236 238
237/* Maximum queue length specifiable by listen. */ 239/* Maximum queue length specifiable by listen. */
@@ -305,6 +307,7 @@ struct ucred {
305#define SOL_RDS 276 307#define SOL_RDS 276
306#define SOL_IUCV 277 308#define SOL_IUCV 277
307#define SOL_CAIF 278 309#define SOL_CAIF 278
310#define SOL_ALG 279
308 311
309/* IPX options */ 312/* IPX options */
310#define IPX_TYPE 1 313#define IPX_TYPE 1
diff --git a/include/linux/suspend.h b/include/linux/suspend.h
index 144b34be5c32..c1f499835b2a 100644
--- a/include/linux/suspend.h
+++ b/include/linux/suspend.h
@@ -122,7 +122,7 @@ struct platform_suspend_ops {
122 * suspend_set_ops - set platform dependent suspend operations 122 * suspend_set_ops - set platform dependent suspend operations
123 * @ops: The new suspend operations to set. 123 * @ops: The new suspend operations to set.
124 */ 124 */
125extern void suspend_set_ops(struct platform_suspend_ops *ops); 125extern void suspend_set_ops(const struct platform_suspend_ops *ops);
126extern int suspend_valid_only_mem(suspend_state_t state); 126extern int suspend_valid_only_mem(suspend_state_t state);
127 127
128/** 128/**
@@ -147,7 +147,7 @@ extern int pm_suspend(suspend_state_t state);
147#else /* !CONFIG_SUSPEND */ 147#else /* !CONFIG_SUSPEND */
148#define suspend_valid_only_mem NULL 148#define suspend_valid_only_mem NULL
149 149
150static inline void suspend_set_ops(struct platform_suspend_ops *ops) {} 150static inline void suspend_set_ops(const struct platform_suspend_ops *ops) {}
151static inline int pm_suspend(suspend_state_t state) { return -ENOSYS; } 151static inline int pm_suspend(suspend_state_t state) { return -ENOSYS; }
152#endif /* !CONFIG_SUSPEND */ 152#endif /* !CONFIG_SUSPEND */
153 153
@@ -245,7 +245,7 @@ extern void swsusp_set_page_free(struct page *);
245extern void swsusp_unset_page_free(struct page *); 245extern void swsusp_unset_page_free(struct page *);
246extern unsigned long get_safe_page(gfp_t gfp_mask); 246extern unsigned long get_safe_page(gfp_t gfp_mask);
247 247
248extern void hibernation_set_ops(struct platform_hibernation_ops *ops); 248extern void hibernation_set_ops(const struct platform_hibernation_ops *ops);
249extern int hibernate(void); 249extern int hibernate(void);
250extern bool system_entering_hibernation(void); 250extern bool system_entering_hibernation(void);
251#else /* CONFIG_HIBERNATION */ 251#else /* CONFIG_HIBERNATION */
@@ -253,7 +253,7 @@ static inline int swsusp_page_is_forbidden(struct page *p) { return 0; }
253static inline void swsusp_set_page_free(struct page *p) {} 253static inline void swsusp_set_page_free(struct page *p) {}
254static inline void swsusp_unset_page_free(struct page *p) {} 254static inline void swsusp_unset_page_free(struct page *p) {}
255 255
256static inline void hibernation_set_ops(struct platform_hibernation_ops *ops) {} 256static inline void hibernation_set_ops(const struct platform_hibernation_ops *ops) {}
257static inline int hibernate(void) { return -ENOSYS; } 257static inline int hibernate(void) { return -ENOSYS; }
258static inline bool system_entering_hibernation(void) { return false; } 258static inline bool system_entering_hibernation(void) { return false; }
259#endif /* CONFIG_HIBERNATION */ 259#endif /* CONFIG_HIBERNATION */
diff --git a/include/linux/time.h b/include/linux/time.h
index 9f15ac7ab92a..1e6d3b59238d 100644
--- a/include/linux/time.h
+++ b/include/linux/time.h
@@ -158,6 +158,8 @@ extern unsigned int alarm_setitimer(unsigned int seconds);
158extern int do_getitimer(int which, struct itimerval *value); 158extern int do_getitimer(int which, struct itimerval *value);
159extern void getnstimeofday(struct timespec *tv); 159extern void getnstimeofday(struct timespec *tv);
160extern void getrawmonotonic(struct timespec *ts); 160extern void getrawmonotonic(struct timespec *ts);
161extern void getnstime_raw_and_real(struct timespec *ts_raw,
162 struct timespec *ts_real);
161extern void getboottime(struct timespec *ts); 163extern void getboottime(struct timespec *ts);
162extern void monotonic_to_bootbased(struct timespec *ts); 164extern void monotonic_to_bootbased(struct timespec *ts);
163 165
diff --git a/include/linux/timex.h b/include/linux/timex.h
index 32d852f8cbe4..d23999f9499d 100644
--- a/include/linux/timex.h
+++ b/include/linux/timex.h
@@ -268,6 +268,7 @@ extern u64 tick_length;
268extern void second_overflow(void); 268extern void second_overflow(void);
269extern void update_ntp_one_tick(void); 269extern void update_ntp_one_tick(void);
270extern int do_adjtimex(struct timex *); 270extern int do_adjtimex(struct timex *);
271extern void hardpps(const struct timespec *, const struct timespec *);
271 272
272int read_current_timer(unsigned long *timer_val); 273int read_current_timer(unsigned long *timer_val);
273 274
diff --git a/include/linux/toshiba.h b/include/linux/toshiba.h
index 6a7c4edf0e13..772dedbc3a22 100644
--- a/include/linux/toshiba.h
+++ b/include/linux/toshiba.h
@@ -33,6 +33,8 @@ typedef struct {
33 unsigned int edi __attribute__ ((packed)); 33 unsigned int edi __attribute__ ((packed));
34} SMMRegisters; 34} SMMRegisters;
35 35
36#ifdef __KERNEL__
36int tosh_smm(SMMRegisters *regs); 37int tosh_smm(SMMRegisters *regs);
38#endif /* __KERNEL__ */
37 39
38#endif 40#endif
diff --git a/include/linux/tty_ldisc.h b/include/linux/tty_ldisc.h
index 526d66f066a3..ff7dc08696a8 100644
--- a/include/linux/tty_ldisc.h
+++ b/include/linux/tty_ldisc.h
@@ -101,14 +101,15 @@
101 * any pending driver I/O is completed. 101 * any pending driver I/O is completed.
102 * 102 *
103 * void (*dcd_change)(struct tty_struct *tty, unsigned int status, 103 * void (*dcd_change)(struct tty_struct *tty, unsigned int status,
104 * struct timespec *ts) 104 * struct pps_event_time *ts)
105 * 105 *
106 * Tells the discipline that the DCD pin has changed its status and 106 * Tells the discipline that the DCD pin has changed its status and
107 * the relative timestamp. Pointer ts can be NULL. 107 * the relative timestamp. Pointer ts cannot be NULL.
108 */ 108 */
109 109
110#include <linux/fs.h> 110#include <linux/fs.h>
111#include <linux/wait.h> 111#include <linux/wait.h>
112#include <linux/pps_kernel.h>
112 113
113struct tty_ldisc_ops { 114struct tty_ldisc_ops {
114 int magic; 115 int magic;
@@ -143,7 +144,7 @@ struct tty_ldisc_ops {
143 char *fp, int count); 144 char *fp, int count);
144 void (*write_wakeup)(struct tty_struct *); 145 void (*write_wakeup)(struct tty_struct *);
145 void (*dcd_change)(struct tty_struct *, unsigned int, 146 void (*dcd_change)(struct tty_struct *, unsigned int,
146 struct timespec *); 147 struct pps_event_time *);
147 148
148 struct module *owner; 149 struct module *owner;
149 150
diff --git a/include/linux/u64_stats_sync.h b/include/linux/u64_stats_sync.h
index fa261a0da280..8da8c4e87da3 100644
--- a/include/linux/u64_stats_sync.h
+++ b/include/linux/u64_stats_sync.h
@@ -67,21 +67,21 @@ struct u64_stats_sync {
67#endif 67#endif
68}; 68};
69 69
70static void inline u64_stats_update_begin(struct u64_stats_sync *syncp) 70static inline void u64_stats_update_begin(struct u64_stats_sync *syncp)
71{ 71{
72#if BITS_PER_LONG==32 && defined(CONFIG_SMP) 72#if BITS_PER_LONG==32 && defined(CONFIG_SMP)
73 write_seqcount_begin(&syncp->seq); 73 write_seqcount_begin(&syncp->seq);
74#endif 74#endif
75} 75}
76 76
77static void inline u64_stats_update_end(struct u64_stats_sync *syncp) 77static inline void u64_stats_update_end(struct u64_stats_sync *syncp)
78{ 78{
79#if BITS_PER_LONG==32 && defined(CONFIG_SMP) 79#if BITS_PER_LONG==32 && defined(CONFIG_SMP)
80 write_seqcount_end(&syncp->seq); 80 write_seqcount_end(&syncp->seq);
81#endif 81#endif
82} 82}
83 83
84static unsigned int inline u64_stats_fetch_begin(const struct u64_stats_sync *syncp) 84static inline unsigned int u64_stats_fetch_begin(const struct u64_stats_sync *syncp)
85{ 85{
86#if BITS_PER_LONG==32 && defined(CONFIG_SMP) 86#if BITS_PER_LONG==32 && defined(CONFIG_SMP)
87 return read_seqcount_begin(&syncp->seq); 87 return read_seqcount_begin(&syncp->seq);
@@ -93,7 +93,7 @@ static unsigned int inline u64_stats_fetch_begin(const struct u64_stats_sync *sy
93#endif 93#endif
94} 94}
95 95
96static bool inline u64_stats_fetch_retry(const struct u64_stats_sync *syncp, 96static inline bool u64_stats_fetch_retry(const struct u64_stats_sync *syncp,
97 unsigned int start) 97 unsigned int start)
98{ 98{
99#if BITS_PER_LONG==32 && defined(CONFIG_SMP) 99#if BITS_PER_LONG==32 && defined(CONFIG_SMP)
@@ -112,7 +112,7 @@ static bool inline u64_stats_fetch_retry(const struct u64_stats_sync *syncp,
112 * - UP 32bit must disable BH. 112 * - UP 32bit must disable BH.
113 * - 64bit have no problem atomically reading u64 values, irq safe. 113 * - 64bit have no problem atomically reading u64 values, irq safe.
114 */ 114 */
115static unsigned int inline u64_stats_fetch_begin_bh(const struct u64_stats_sync *syncp) 115static inline unsigned int u64_stats_fetch_begin_bh(const struct u64_stats_sync *syncp)
116{ 116{
117#if BITS_PER_LONG==32 && defined(CONFIG_SMP) 117#if BITS_PER_LONG==32 && defined(CONFIG_SMP)
118 return read_seqcount_begin(&syncp->seq); 118 return read_seqcount_begin(&syncp->seq);
@@ -124,7 +124,7 @@ static unsigned int inline u64_stats_fetch_begin_bh(const struct u64_stats_sync
124#endif 124#endif
125} 125}
126 126
127static bool inline u64_stats_fetch_retry_bh(const struct u64_stats_sync *syncp, 127static inline bool u64_stats_fetch_retry_bh(const struct u64_stats_sync *syncp,
128 unsigned int start) 128 unsigned int start)
129{ 129{
130#if BITS_PER_LONG==32 && defined(CONFIG_SMP) 130#if BITS_PER_LONG==32 && defined(CONFIG_SMP)
diff --git a/include/linux/unaligned/packed_struct.h b/include/linux/unaligned/packed_struct.h
index c9a6abd972a1..c0d817de4df2 100644
--- a/include/linux/unaligned/packed_struct.h
+++ b/include/linux/unaligned/packed_struct.h
@@ -3,9 +3,9 @@
3 3
4#include <linux/kernel.h> 4#include <linux/kernel.h>
5 5
6struct __una_u16 { u16 x; } __attribute__((packed)); 6struct __una_u16 { u16 x; } __packed;
7struct __una_u32 { u32 x; } __attribute__((packed)); 7struct __una_u32 { u32 x; } __packed;
8struct __una_u64 { u64 x; } __attribute__((packed)); 8struct __una_u64 { u64 x; } __packed;
9 9
10static inline u16 __get_unaligned_cpu16(const void *p) 10static inline u16 __get_unaligned_cpu16(const void *p)
11{ 11{
diff --git a/include/linux/user_namespace.h b/include/linux/user_namespace.h
index 8178156711f9..faf467944baf 100644
--- a/include/linux/user_namespace.h
+++ b/include/linux/user_namespace.h
@@ -6,7 +6,7 @@
6#include <linux/sched.h> 6#include <linux/sched.h>
7#include <linux/err.h> 7#include <linux/err.h>
8 8
9#define UIDHASH_BITS (CONFIG_BASE_SMALL ? 3 : 8) 9#define UIDHASH_BITS (CONFIG_BASE_SMALL ? 3 : 7)
10#define UIDHASH_SZ (1 << UIDHASH_BITS) 10#define UIDHASH_SZ (1 << UIDHASH_BITS)
11 11
12struct user_namespace { 12struct user_namespace {
diff --git a/include/linux/xz.h b/include/linux/xz.h
new file mode 100644
index 000000000000..64cffa6ddfce
--- /dev/null
+++ b/include/linux/xz.h
@@ -0,0 +1,264 @@
1/*
2 * XZ decompressor
3 *
4 * Authors: Lasse Collin <lasse.collin@tukaani.org>
5 * Igor Pavlov <http://7-zip.org/>
6 *
7 * This file has been put into the public domain.
8 * You can do whatever you want with this file.
9 */
10
11#ifndef XZ_H
12#define XZ_H
13
14#ifdef __KERNEL__
15# include <linux/stddef.h>
16# include <linux/types.h>
17#else
18# include <stddef.h>
19# include <stdint.h>
20#endif
21
22/* In Linux, this is used to make extern functions static when needed. */
23#ifndef XZ_EXTERN
24# define XZ_EXTERN extern
25#endif
26
27/**
28 * enum xz_mode - Operation mode
29 *
30 * @XZ_SINGLE: Single-call mode. This uses less RAM than
31 * than multi-call modes, because the LZMA2
32 * dictionary doesn't need to be allocated as
33 * part of the decoder state. All required data
34 * structures are allocated at initialization,
35 * so xz_dec_run() cannot return XZ_MEM_ERROR.
36 * @XZ_PREALLOC: Multi-call mode with preallocated LZMA2
37 * dictionary buffer. All data structures are
38 * allocated at initialization, so xz_dec_run()
39 * cannot return XZ_MEM_ERROR.
40 * @XZ_DYNALLOC: Multi-call mode. The LZMA2 dictionary is
41 * allocated once the required size has been
42 * parsed from the stream headers. If the
43 * allocation fails, xz_dec_run() will return
44 * XZ_MEM_ERROR.
45 *
46 * It is possible to enable support only for a subset of the above
47 * modes at compile time by defining XZ_DEC_SINGLE, XZ_DEC_PREALLOC,
48 * or XZ_DEC_DYNALLOC. The xz_dec kernel module is always compiled
49 * with support for all operation modes, but the preboot code may
50 * be built with fewer features to minimize code size.
51 */
52enum xz_mode {
53 XZ_SINGLE,
54 XZ_PREALLOC,
55 XZ_DYNALLOC
56};
57
58/**
59 * enum xz_ret - Return codes
60 * @XZ_OK: Everything is OK so far. More input or more
61 * output space is required to continue. This
62 * return code is possible only in multi-call mode
63 * (XZ_PREALLOC or XZ_DYNALLOC).
64 * @XZ_STREAM_END: Operation finished successfully.
65 * @XZ_UNSUPPORTED_CHECK: Integrity check type is not supported. Decoding
66 * is still possible in multi-call mode by simply
67 * calling xz_dec_run() again.
68 * Note that this return value is used only if
69 * XZ_DEC_ANY_CHECK was defined at build time,
70 * which is not used in the kernel. Unsupported
71 * check types return XZ_OPTIONS_ERROR if
72 * XZ_DEC_ANY_CHECK was not defined at build time.
73 * @XZ_MEM_ERROR: Allocating memory failed. This return code is
74 * possible only if the decoder was initialized
75 * with XZ_DYNALLOC. The amount of memory that was
76 * tried to be allocated was no more than the
77 * dict_max argument given to xz_dec_init().
78 * @XZ_MEMLIMIT_ERROR: A bigger LZMA2 dictionary would be needed than
79 * allowed by the dict_max argument given to
80 * xz_dec_init(). This return value is possible
81 * only in multi-call mode (XZ_PREALLOC or
82 * XZ_DYNALLOC); the single-call mode (XZ_SINGLE)
83 * ignores the dict_max argument.
84 * @XZ_FORMAT_ERROR: File format was not recognized (wrong magic
85 * bytes).
86 * @XZ_OPTIONS_ERROR: This implementation doesn't support the requested
87 * compression options. In the decoder this means
88 * that the header CRC32 matches, but the header
89 * itself specifies something that we don't support.
90 * @XZ_DATA_ERROR: Compressed data is corrupt.
91 * @XZ_BUF_ERROR: Cannot make any progress. Details are slightly
92 * different between multi-call and single-call
93 * mode; more information below.
94 *
95 * In multi-call mode, XZ_BUF_ERROR is returned when two consecutive calls
96 * to XZ code cannot consume any input and cannot produce any new output.
97 * This happens when there is no new input available, or the output buffer
98 * is full while at least one output byte is still pending. Assuming your
99 * code is not buggy, you can get this error only when decoding a compressed
100 * stream that is truncated or otherwise corrupt.
101 *
102 * In single-call mode, XZ_BUF_ERROR is returned only when the output buffer
103 * is too small or the compressed input is corrupt in a way that makes the
104 * decoder produce more output than the caller expected. When it is
105 * (relatively) clear that the compressed input is truncated, XZ_DATA_ERROR
106 * is used instead of XZ_BUF_ERROR.
107 */
108enum xz_ret {
109 XZ_OK,
110 XZ_STREAM_END,
111 XZ_UNSUPPORTED_CHECK,
112 XZ_MEM_ERROR,
113 XZ_MEMLIMIT_ERROR,
114 XZ_FORMAT_ERROR,
115 XZ_OPTIONS_ERROR,
116 XZ_DATA_ERROR,
117 XZ_BUF_ERROR
118};
119
120/**
121 * struct xz_buf - Passing input and output buffers to XZ code
122 * @in: Beginning of the input buffer. This may be NULL if and only
123 * if in_pos is equal to in_size.
124 * @in_pos: Current position in the input buffer. This must not exceed
125 * in_size.
126 * @in_size: Size of the input buffer
127 * @out: Beginning of the output buffer. This may be NULL if and only
128 * if out_pos is equal to out_size.
129 * @out_pos: Current position in the output buffer. This must not exceed
130 * out_size.
131 * @out_size: Size of the output buffer
132 *
133 * Only the contents of the output buffer from out[out_pos] onward, and
134 * the variables in_pos and out_pos are modified by the XZ code.
135 */
136struct xz_buf {
137 const uint8_t *in;
138 size_t in_pos;
139 size_t in_size;
140
141 uint8_t *out;
142 size_t out_pos;
143 size_t out_size;
144};
145
146/**
147 * struct xz_dec - Opaque type to hold the XZ decoder state
148 */
149struct xz_dec;
150
151/**
152 * xz_dec_init() - Allocate and initialize a XZ decoder state
153 * @mode: Operation mode
154 * @dict_max: Maximum size of the LZMA2 dictionary (history buffer) for
155 * multi-call decoding. This is ignored in single-call mode
156 * (mode == XZ_SINGLE). LZMA2 dictionary is always 2^n bytes
157 * or 2^n + 2^(n-1) bytes (the latter sizes are less common
158 * in practice), so other values for dict_max don't make sense.
159 * In the kernel, dictionary sizes of 64 KiB, 128 KiB, 256 KiB,
160 * 512 KiB, and 1 MiB are probably the only reasonable values,
161 * except for kernel and initramfs images where a bigger
162 * dictionary can be fine and useful.
163 *
164 * Single-call mode (XZ_SINGLE): xz_dec_run() decodes the whole stream at
165 * once. The caller must provide enough output space or the decoding will
166 * fail. The output space is used as the dictionary buffer, which is why
167 * there is no need to allocate the dictionary as part of the decoder's
168 * internal state.
169 *
170 * Because the output buffer is used as the workspace, streams encoded using
171 * a big dictionary are not a problem in single-call mode. It is enough that
172 * the output buffer is big enough to hold the actual uncompressed data; it
173 * can be smaller than the dictionary size stored in the stream headers.
174 *
175 * Multi-call mode with preallocated dictionary (XZ_PREALLOC): dict_max bytes
176 * of memory is preallocated for the LZMA2 dictionary. This way there is no
177 * risk that xz_dec_run() could run out of memory, since xz_dec_run() will
178 * never allocate any memory. Instead, if the preallocated dictionary is too
179 * small for decoding the given input stream, xz_dec_run() will return
180 * XZ_MEMLIMIT_ERROR. Thus, it is important to know what kind of data will be
181 * decoded to avoid allocating excessive amount of memory for the dictionary.
182 *
183 * Multi-call mode with dynamically allocated dictionary (XZ_DYNALLOC):
184 * dict_max specifies the maximum allowed dictionary size that xz_dec_run()
185 * may allocate once it has parsed the dictionary size from the stream
186 * headers. This way excessive allocations can be avoided while still
187 * limiting the maximum memory usage to a sane value to prevent running the
188 * system out of memory when decompressing streams from untrusted sources.
189 *
190 * On success, xz_dec_init() returns a pointer to struct xz_dec, which is
191 * ready to be used with xz_dec_run(). If memory allocation fails,
192 * xz_dec_init() returns NULL.
193 */
194XZ_EXTERN struct xz_dec *xz_dec_init(enum xz_mode mode, uint32_t dict_max);
195
196/**
197 * xz_dec_run() - Run the XZ decoder
198 * @s: Decoder state allocated using xz_dec_init()
199 * @b: Input and output buffers
200 *
201 * The possible return values depend on build options and operation mode.
202 * See enum xz_ret for details.
203 *
204 * Note that if an error occurs in single-call mode (return value is not
205 * XZ_STREAM_END), b->in_pos and b->out_pos are not modified and the
206 * contents of the output buffer from b->out[b->out_pos] onward are
207 * undefined. This is true even after XZ_BUF_ERROR, because with some filter
208 * chains, there may be a second pass over the output buffer, and this pass
209 * cannot be properly done if the output buffer is truncated. Thus, you
210 * cannot give the single-call decoder a too small buffer and then expect to
211 * get that amount valid data from the beginning of the stream. You must use
212 * the multi-call decoder if you don't want to uncompress the whole stream.
213 */
214XZ_EXTERN enum xz_ret xz_dec_run(struct xz_dec *s, struct xz_buf *b);
215
216/**
217 * xz_dec_reset() - Reset an already allocated decoder state
218 * @s: Decoder state allocated using xz_dec_init()
219 *
220 * This function can be used to reset the multi-call decoder state without
221 * freeing and reallocating memory with xz_dec_end() and xz_dec_init().
222 *
223 * In single-call mode, xz_dec_reset() is always called in the beginning of
224 * xz_dec_run(). Thus, explicit call to xz_dec_reset() is useful only in
225 * multi-call mode.
226 */
227XZ_EXTERN void xz_dec_reset(struct xz_dec *s);
228
229/**
230 * xz_dec_end() - Free the memory allocated for the decoder state
231 * @s: Decoder state allocated using xz_dec_init(). If s is NULL,
232 * this function does nothing.
233 */
234XZ_EXTERN void xz_dec_end(struct xz_dec *s);
235
236/*
237 * Standalone build (userspace build or in-kernel build for boot time use)
238 * needs a CRC32 implementation. For normal in-kernel use, kernel's own
239 * CRC32 module is used instead, and users of this module don't need to
240 * care about the functions below.
241 */
242#ifndef XZ_INTERNAL_CRC32
243# ifdef __KERNEL__
244# define XZ_INTERNAL_CRC32 0
245# else
246# define XZ_INTERNAL_CRC32 1
247# endif
248#endif
249
250#if XZ_INTERNAL_CRC32
251/*
252 * This must be called before any other xz_* function to initialize
253 * the CRC32 lookup table.
254 */
255XZ_EXTERN void xz_crc32_init(void);
256
257/*
258 * Update CRC32 value using the polynomial from IEEE-802.3. To start a new
259 * calculation, the third argument must be zero. To continue the calculation,
260 * the previously returned value is passed as the third argument.
261 */
262XZ_EXTERN uint32_t xz_crc32(const uint8_t *buf, size_t size, uint32_t crc);
263#endif
264#endif
diff --git a/include/media/davinci/vpss.h b/include/media/davinci/vpss.h
index c59cc029c74a..b586495bcd53 100644
--- a/include/media/davinci/vpss.h
+++ b/include/media/davinci/vpss.h
@@ -44,7 +44,7 @@ struct vpss_pg_frame_size {
44 short pplen; 44 short pplen;
45}; 45};
46 46
47/* Used for enable/diable VPSS Clock */ 47/* Used for enable/disable VPSS Clock */
48enum vpss_clock_sel { 48enum vpss_clock_sel {
49 /* DM355/DM365 */ 49 /* DM355/DM365 */
50 VPSS_CCDC_CLOCK, 50 VPSS_CCDC_CLOCK,
diff --git a/include/net/sctp/user.h b/include/net/sctp/user.h
index 2b2769c5ca9f..2a128c8c2718 100644
--- a/include/net/sctp/user.h
+++ b/include/net/sctp/user.h
@@ -99,8 +99,8 @@ typedef __s32 sctp_assoc_t;
99#define SCTP_SOCKOPT_PEELOFF 102 /* peel off association. */ 99#define SCTP_SOCKOPT_PEELOFF 102 /* peel off association. */
100/* Options 104-106 are deprecated and removed. Do not use this space */ 100/* Options 104-106 are deprecated and removed. Do not use this space */
101#define SCTP_SOCKOPT_CONNECTX_OLD 107 /* CONNECTX old requests. */ 101#define SCTP_SOCKOPT_CONNECTX_OLD 107 /* CONNECTX old requests. */
102#define SCTP_GET_PEER_ADDRS 108 /* Get all peer addresss. */ 102#define SCTP_GET_PEER_ADDRS 108 /* Get all peer address. */
103#define SCTP_GET_LOCAL_ADDRS 109 /* Get all local addresss. */ 103#define SCTP_GET_LOCAL_ADDRS 109 /* Get all local address. */
104#define SCTP_SOCKOPT_CONNECTX 110 /* CONNECTX requests. */ 104#define SCTP_SOCKOPT_CONNECTX 110 /* CONNECTX requests. */
105#define SCTP_SOCKOPT_CONNECTX3 111 /* CONNECTX requests (updated) */ 105#define SCTP_SOCKOPT_CONNECTX3 111 /* CONNECTX requests (updated) */
106 106
diff --git a/include/scsi/fc/fc_fcp.h b/include/scsi/fc/fc_fcp.h
index 8e9b222251c2..8a143ca79878 100644
--- a/include/scsi/fc/fc_fcp.h
+++ b/include/scsi/fc/fc_fcp.h
@@ -46,7 +46,7 @@
46 */ 46 */
47struct fcp_cmnd { 47struct fcp_cmnd {
48 __u8 fc_lun[8]; /* logical unit number */ 48 __u8 fc_lun[8]; /* logical unit number */
49 __u8 fc_cmdref; /* commmand reference number */ 49 __u8 fc_cmdref; /* command reference number */
50 __u8 fc_pri_ta; /* priority and task attribute */ 50 __u8 fc_pri_ta; /* priority and task attribute */
51 __u8 fc_tm_flags; /* task management flags */ 51 __u8 fc_tm_flags; /* task management flags */
52 __u8 fc_flags; /* additional len & flags */ 52 __u8 fc_flags; /* additional len & flags */
@@ -58,7 +58,7 @@ struct fcp_cmnd {
58 58
59struct fcp_cmnd32 { 59struct fcp_cmnd32 {
60 __u8 fc_lun[8]; /* logical unit number */ 60 __u8 fc_lun[8]; /* logical unit number */
61 __u8 fc_cmdref; /* commmand reference number */ 61 __u8 fc_cmdref; /* command reference number */
62 __u8 fc_pri_ta; /* priority and task attribute */ 62 __u8 fc_pri_ta; /* priority and task attribute */
63 __u8 fc_tm_flags; /* task management flags */ 63 __u8 fc_tm_flags; /* task management flags */
64 __u8 fc_flags; /* additional len & flags */ 64 __u8 fc_flags; /* additional len & flags */
diff --git a/include/sound/alc5623.h b/include/sound/alc5623.h
new file mode 100644
index 000000000000..422c97d43df3
--- /dev/null
+++ b/include/sound/alc5623.h
@@ -0,0 +1,15 @@
1#ifndef _INCLUDE_SOUND_ALC5623_H
2#define _INCLUDE_SOUND_ALC5623_H
3struct alc5623_platform_data {
4 /* configure : */
5 /* Lineout/Speaker Amps Vmid ratio control */
6 /* enable/disable adc/dac high pass filters */
7 unsigned int add_ctrl;
8 /* configure : */
9 /* output to enable when jack is low */
10 /* output to enable when jack is high */
11 /* jack detect (gpio/nc/jack detect [12] */
12 unsigned int jack_det_ctrl;
13};
14#endif
15
diff --git a/include/sound/asound.h b/include/sound/asound.h
index a1803ecea34d..5d6074faa279 100644
--- a/include/sound/asound.h
+++ b/include/sound/asound.h
@@ -259,6 +259,7 @@ typedef int __bitwise snd_pcm_subformat_t;
259#define SNDRV_PCM_INFO_HALF_DUPLEX 0x00100000 /* only half duplex */ 259#define SNDRV_PCM_INFO_HALF_DUPLEX 0x00100000 /* only half duplex */
260#define SNDRV_PCM_INFO_JOINT_DUPLEX 0x00200000 /* playback and capture stream are somewhat correlated */ 260#define SNDRV_PCM_INFO_JOINT_DUPLEX 0x00200000 /* playback and capture stream are somewhat correlated */
261#define SNDRV_PCM_INFO_SYNC_START 0x00400000 /* pcm support some kind of sync go */ 261#define SNDRV_PCM_INFO_SYNC_START 0x00400000 /* pcm support some kind of sync go */
262#define SNDRV_PCM_INFO_NO_PERIOD_WAKEUP 0x00800000 /* period wakeup can be disabled */
262#define SNDRV_PCM_INFO_FIFO_IN_FRAMES 0x80000000 /* internal kernel flag - FIFO size is in frames */ 263#define SNDRV_PCM_INFO_FIFO_IN_FRAMES 0x80000000 /* internal kernel flag - FIFO size is in frames */
263 264
264typedef int __bitwise snd_pcm_state_t; 265typedef int __bitwise snd_pcm_state_t;
@@ -334,6 +335,8 @@ typedef int snd_pcm_hw_param_t;
334#define SNDRV_PCM_HW_PARAM_LAST_INTERVAL SNDRV_PCM_HW_PARAM_TICK_TIME 335#define SNDRV_PCM_HW_PARAM_LAST_INTERVAL SNDRV_PCM_HW_PARAM_TICK_TIME
335 336
336#define SNDRV_PCM_HW_PARAMS_NORESAMPLE (1<<0) /* avoid rate resampling */ 337#define SNDRV_PCM_HW_PARAMS_NORESAMPLE (1<<0) /* avoid rate resampling */
338#define SNDRV_PCM_HW_PARAMS_EXPORT_BUFFER (1<<1) /* export buffer */
339#define SNDRV_PCM_HW_PARAMS_NO_PERIOD_WAKEUP (1<<2) /* disable period wakeups */
337 340
338struct snd_interval { 341struct snd_interval {
339 unsigned int min, max; 342 unsigned int min, max;
diff --git a/include/sound/control.h b/include/sound/control.h
index 112374dc0c58..7715e6f00d38 100644
--- a/include/sound/control.h
+++ b/include/sound/control.h
@@ -160,12 +160,14 @@ static inline struct snd_ctl_elem_id *snd_ctl_build_ioff(struct snd_ctl_elem_id
160} 160}
161 161
162/* 162/*
163 * Frequently used control callbacks 163 * Frequently used control callbacks/helpers
164 */ 164 */
165int snd_ctl_boolean_mono_info(struct snd_kcontrol *kcontrol, 165int snd_ctl_boolean_mono_info(struct snd_kcontrol *kcontrol,
166 struct snd_ctl_elem_info *uinfo); 166 struct snd_ctl_elem_info *uinfo);
167int snd_ctl_boolean_stereo_info(struct snd_kcontrol *kcontrol, 167int snd_ctl_boolean_stereo_info(struct snd_kcontrol *kcontrol,
168 struct snd_ctl_elem_info *uinfo); 168 struct snd_ctl_elem_info *uinfo);
169int snd_ctl_enum_info(struct snd_ctl_elem_info *info, unsigned int channels,
170 unsigned int items, const char *const names[]);
169 171
170/* 172/*
171 * virtual master control 173 * virtual master control
diff --git a/include/sound/hdsp.h b/include/sound/hdsp.h
index d98a78dff2db..0909a3843479 100644
--- a/include/sound/hdsp.h
+++ b/include/sound/hdsp.h
@@ -28,6 +28,7 @@ enum HDSP_IO_Type {
28 Multiface, 28 Multiface,
29 H9652, 29 H9652,
30 H9632, 30 H9632,
31 RPM,
31 Undefined, 32 Undefined,
32}; 33};
33 34
diff --git a/include/sound/minors.h b/include/sound/minors.h
index a81798ab73ed..8f764204a856 100644
--- a/include/sound/minors.h
+++ b/include/sound/minors.h
@@ -31,8 +31,8 @@
31/* these minors can still be used for autoloading devices (/dev/aload*) */ 31/* these minors can still be used for autoloading devices (/dev/aload*) */
32#define SNDRV_MINOR_CONTROL 0 /* 0 */ 32#define SNDRV_MINOR_CONTROL 0 /* 0 */
33#define SNDRV_MINOR_GLOBAL 1 /* 1 */ 33#define SNDRV_MINOR_GLOBAL 1 /* 1 */
34#define SNDRV_MINOR_SEQUENCER (SNDRV_MINOR_GLOBAL + 0 * 32) 34#define SNDRV_MINOR_SEQUENCER 1 /* SNDRV_MINOR_GLOBAL + 0 * 32 */
35#define SNDRV_MINOR_TIMER (SNDRV_MINOR_GLOBAL + 1 * 32) 35#define SNDRV_MINOR_TIMER 33 /* SNDRV_MINOR_GLOBAL + 1 * 32 */
36 36
37#ifndef CONFIG_SND_DYNAMIC_MINORS 37#ifndef CONFIG_SND_DYNAMIC_MINORS
38 /* 2 - 3 (reserved) */ 38 /* 2 - 3 (reserved) */
diff --git a/include/sound/pcm.h b/include/sound/pcm.h
index dfd9b76b1853..e731f8d71934 100644
--- a/include/sound/pcm.h
+++ b/include/sound/pcm.h
@@ -297,6 +297,7 @@ struct snd_pcm_runtime {
297 unsigned int info; 297 unsigned int info;
298 unsigned int rate_num; 298 unsigned int rate_num;
299 unsigned int rate_den; 299 unsigned int rate_den;
300 unsigned int no_period_wakeup: 1;
300 301
301 /* -- SW params -- */ 302 /* -- SW params -- */
302 int tstamp_mode; /* mmap timestamp is updated */ 303 int tstamp_mode; /* mmap timestamp is updated */
diff --git a/include/sound/soc-dai.h b/include/sound/soc-dai.h
index e7b680248006..1bafe95dcf41 100644
--- a/include/sound/soc-dai.h
+++ b/include/sound/soc-dai.h
@@ -16,8 +16,6 @@
16 16
17#include <linux/list.h> 17#include <linux/list.h>
18 18
19#include <sound/soc.h>
20
21struct snd_pcm_substream; 19struct snd_pcm_substream;
22 20
23/* 21/*
@@ -205,7 +203,7 @@ struct snd_soc_dai_driver {
205 int (*resume)(struct snd_soc_dai *dai); 203 int (*resume)(struct snd_soc_dai *dai);
206 204
207 /* ops */ 205 /* ops */
208 struct snd_soc_dai_ops *ops; 206 const struct snd_soc_dai_ops *ops;
209 207
210 /* DAI capabilities */ 208 /* DAI capabilities */
211 struct snd_soc_pcm_stream capture; 209 struct snd_soc_pcm_stream capture;
diff --git a/include/sound/soc-dapm.h b/include/sound/soc-dapm.h
index 8fd3b41b763f..8031769ac485 100644
--- a/include/sound/soc-dapm.h
+++ b/include/sound/soc-dapm.h
@@ -16,7 +16,6 @@
16#include <linux/device.h> 16#include <linux/device.h>
17#include <linux/types.h> 17#include <linux/types.h>
18#include <sound/control.h> 18#include <sound/control.h>
19#include <sound/soc.h>
20 19
21/* widget has no PM register bit */ 20/* widget has no PM register bit */
22#define SND_SOC_NOPM -1 21#define SND_SOC_NOPM -1
@@ -72,6 +71,10 @@
72 wcontrols, wncontrols) \ 71 wcontrols, wncontrols) \
73{ .id = snd_soc_dapm_pga, .name = wname, .reg = wreg, .shift = wshift, \ 72{ .id = snd_soc_dapm_pga, .name = wname, .reg = wreg, .shift = wshift, \
74 .invert = winvert, .kcontrols = wcontrols, .num_kcontrols = wncontrols} 73 .invert = winvert, .kcontrols = wcontrols, .num_kcontrols = wncontrols}
74#define SND_SOC_DAPM_OUT_DRV(wname, wreg, wshift, winvert,\
75 wcontrols, wncontrols) \
76{ .id = snd_soc_dapm_out_drv, .name = wname, .reg = wreg, .shift = wshift, \
77 .invert = winvert, .kcontrols = wcontrols, .num_kcontrols = wncontrols}
75#define SND_SOC_DAPM_MIXER(wname, wreg, wshift, winvert, \ 78#define SND_SOC_DAPM_MIXER(wname, wreg, wshift, winvert, \
76 wcontrols, wncontrols)\ 79 wcontrols, wncontrols)\
77{ .id = snd_soc_dapm_mixer, .name = wname, .reg = wreg, .shift = wshift, \ 80{ .id = snd_soc_dapm_mixer, .name = wname, .reg = wreg, .shift = wshift, \
@@ -90,6 +93,9 @@
90#define SND_SOC_DAPM_MUX(wname, wreg, wshift, winvert, wcontrols) \ 93#define SND_SOC_DAPM_MUX(wname, wreg, wshift, winvert, wcontrols) \
91{ .id = snd_soc_dapm_mux, .name = wname, .reg = wreg, .shift = wshift, \ 94{ .id = snd_soc_dapm_mux, .name = wname, .reg = wreg, .shift = wshift, \
92 .invert = winvert, .kcontrols = wcontrols, .num_kcontrols = 1} 95 .invert = winvert, .kcontrols = wcontrols, .num_kcontrols = 1}
96#define SND_SOC_DAPM_VIRT_MUX(wname, wreg, wshift, winvert, wcontrols) \
97{ .id = snd_soc_dapm_virt_mux, .name = wname, .reg = wreg, .shift = wshift, \
98 .invert = winvert, .kcontrols = wcontrols, .num_kcontrols = 1}
93#define SND_SOC_DAPM_VALUE_MUX(wname, wreg, wshift, winvert, wcontrols) \ 99#define SND_SOC_DAPM_VALUE_MUX(wname, wreg, wshift, winvert, wcontrols) \
94{ .id = snd_soc_dapm_value_mux, .name = wname, .reg = wreg, \ 100{ .id = snd_soc_dapm_value_mux, .name = wname, .reg = wreg, \
95 .shift = wshift, .invert = winvert, .kcontrols = wcontrols, \ 101 .shift = wshift, .invert = winvert, .kcontrols = wcontrols, \
@@ -116,6 +122,11 @@
116{ .id = snd_soc_dapm_pga, .name = wname, .reg = wreg, .shift = wshift, \ 122{ .id = snd_soc_dapm_pga, .name = wname, .reg = wreg, .shift = wshift, \
117 .invert = winvert, .kcontrols = wcontrols, .num_kcontrols = wncontrols, \ 123 .invert = winvert, .kcontrols = wcontrols, .num_kcontrols = wncontrols, \
118 .event = wevent, .event_flags = wflags} 124 .event = wevent, .event_flags = wflags}
125#define SND_SOC_DAPM_OUT_DRV_E(wname, wreg, wshift, winvert, wcontrols, \
126 wncontrols, wevent, wflags) \
127{ .id = snd_soc_dapm_out_drv, .name = wname, .reg = wreg, .shift = wshift, \
128 .invert = winvert, .kcontrols = wcontrols, .num_kcontrols = wncontrols, \
129 .event = wevent, .event_flags = wflags}
119#define SND_SOC_DAPM_MIXER_E(wname, wreg, wshift, winvert, wcontrols, \ 130#define SND_SOC_DAPM_MIXER_E(wname, wreg, wshift, winvert, wcontrols, \
120 wncontrols, wevent, wflags) \ 131 wncontrols, wevent, wflags) \
121{ .id = snd_soc_dapm_mixer, .name = wname, .reg = wreg, .shift = wshift, \ 132{ .id = snd_soc_dapm_mixer, .name = wname, .reg = wreg, .shift = wshift, \
@@ -140,6 +151,11 @@
140{ .id = snd_soc_dapm_mux, .name = wname, .reg = wreg, .shift = wshift, \ 151{ .id = snd_soc_dapm_mux, .name = wname, .reg = wreg, .shift = wshift, \
141 .invert = winvert, .kcontrols = wcontrols, .num_kcontrols = 1, \ 152 .invert = winvert, .kcontrols = wcontrols, .num_kcontrols = 1, \
142 .event = wevent, .event_flags = wflags} 153 .event = wevent, .event_flags = wflags}
154#define SND_SOC_DAPM_VIRT_MUX_E(wname, wreg, wshift, winvert, wcontrols, \
155 wevent, wflags) \
156{ .id = snd_soc_dapm_virt_mux, .name = wname, .reg = wreg, .shift = wshift, \
157 .invert = winvert, .kcontrols = wcontrols, .num_kcontrols = 1, \
158 .event = wevent, .event_flags = wflags}
143 159
144/* Simplified versions of above macros, assuming wncontrols = ARRAY_SIZE(wcontrols) */ 160/* Simplified versions of above macros, assuming wncontrols = ARRAY_SIZE(wcontrols) */
145#define SOC_PGA_E_ARRAY(wname, wreg, wshift, winvert, wcontrols, \ 161#define SOC_PGA_E_ARRAY(wname, wreg, wshift, winvert, wcontrols, \
@@ -219,13 +235,6 @@
219 .info = snd_soc_info_volsw, \ 235 .info = snd_soc_info_volsw, \
220 .get = snd_soc_dapm_get_volsw, .put = snd_soc_dapm_put_volsw, \ 236 .get = snd_soc_dapm_get_volsw, .put = snd_soc_dapm_put_volsw, \
221 .private_value = SOC_SINGLE_VALUE(reg, shift, max, invert) } 237 .private_value = SOC_SINGLE_VALUE(reg, shift, max, invert) }
222#define SOC_DAPM_DOUBLE(xname, reg, shift_left, shift_right, max, invert, \
223 power) \
224{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname), \
225 .info = snd_soc_info_volsw, \
226 .get = snd_soc_dapm_get_volsw, .put = snd_soc_dapm_put_volsw, \
227 .private_value = (reg) | ((shift_left) << 8) | ((shift_right) << 12) |\
228 ((max) << 16) | ((invert) << 24) }
229#define SOC_DAPM_SINGLE_TLV(xname, reg, shift, max, invert, tlv_array) \ 238#define SOC_DAPM_SINGLE_TLV(xname, reg, shift, max, invert, tlv_array) \
230{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \ 239{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
231 .info = snd_soc_info_volsw, \ 240 .info = snd_soc_info_volsw, \
@@ -233,15 +242,6 @@
233 .tlv.p = (tlv_array), \ 242 .tlv.p = (tlv_array), \
234 .get = snd_soc_dapm_get_volsw, .put = snd_soc_dapm_put_volsw, \ 243 .get = snd_soc_dapm_get_volsw, .put = snd_soc_dapm_put_volsw, \
235 .private_value = SOC_SINGLE_VALUE(reg, shift, max, invert) } 244 .private_value = SOC_SINGLE_VALUE(reg, shift, max, invert) }
236#define SOC_DAPM_DOUBLE_TLV(xname, reg, shift_left, shift_right, max, invert, \
237 power, tlv_array) \
238{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname), \
239 .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ | SNDRV_CTL_ELEM_ACCESS_READWRITE,\
240 .tlv.p = (tlv_array), \
241 .info = snd_soc_info_volsw, \
242 .get = snd_soc_dapm_get_volsw, .put = snd_soc_dapm_put_volsw, \
243 .private_value = (reg) | ((shift_left) << 8) | ((shift_right) << 12) |\
244 ((max) << 16) | ((invert) << 24) }
245#define SOC_DAPM_ENUM(xname, xenum) \ 245#define SOC_DAPM_ENUM(xname, xenum) \
246{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \ 246{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
247 .info = snd_soc_info_enum_double, \ 247 .info = snd_soc_info_enum_double, \
@@ -297,6 +297,7 @@ enum snd_soc_dapm_type;
297struct snd_soc_dapm_path; 297struct snd_soc_dapm_path;
298struct snd_soc_dapm_pin; 298struct snd_soc_dapm_pin;
299struct snd_soc_dapm_route; 299struct snd_soc_dapm_route;
300struct snd_soc_dapm_context;
300 301
301int dapm_reg_event(struct snd_soc_dapm_widget *w, 302int dapm_reg_event(struct snd_soc_dapm_widget *w,
302 struct snd_kcontrol *kcontrol, int event); 303 struct snd_kcontrol *kcontrol, int event);
@@ -324,16 +325,16 @@ int snd_soc_dapm_get_pin_switch(struct snd_kcontrol *kcontrol,
324 struct snd_ctl_elem_value *uncontrol); 325 struct snd_ctl_elem_value *uncontrol);
325int snd_soc_dapm_put_pin_switch(struct snd_kcontrol *kcontrol, 326int snd_soc_dapm_put_pin_switch(struct snd_kcontrol *kcontrol,
326 struct snd_ctl_elem_value *uncontrol); 327 struct snd_ctl_elem_value *uncontrol);
327int snd_soc_dapm_new_control(struct snd_soc_codec *codec, 328int snd_soc_dapm_new_control(struct snd_soc_dapm_context *dapm,
328 const struct snd_soc_dapm_widget *widget); 329 const struct snd_soc_dapm_widget *widget);
329int snd_soc_dapm_new_controls(struct snd_soc_codec *codec, 330int snd_soc_dapm_new_controls(struct snd_soc_dapm_context *dapm,
330 const struct snd_soc_dapm_widget *widget, 331 const struct snd_soc_dapm_widget *widget,
331 int num); 332 int num);
332 333
333/* dapm path setup */ 334/* dapm path setup */
334int snd_soc_dapm_new_widgets(struct snd_soc_codec *codec); 335int snd_soc_dapm_new_widgets(struct snd_soc_dapm_context *dapm);
335void snd_soc_dapm_free(struct snd_soc_codec *codec); 336void snd_soc_dapm_free(struct snd_soc_dapm_context *dapm);
336int snd_soc_dapm_add_routes(struct snd_soc_codec *codec, 337int snd_soc_dapm_add_routes(struct snd_soc_dapm_context *dapm,
337 const struct snd_soc_dapm_route *route, int num); 338 const struct snd_soc_dapm_route *route, int num);
338 339
339/* dapm events */ 340/* dapm events */
@@ -343,27 +344,33 @@ void snd_soc_dapm_shutdown(struct snd_soc_card *card);
343 344
344/* dapm sys fs - used by the core */ 345/* dapm sys fs - used by the core */
345int snd_soc_dapm_sys_add(struct device *dev); 346int snd_soc_dapm_sys_add(struct device *dev);
346void snd_soc_dapm_debugfs_init(struct snd_soc_codec *codec); 347void snd_soc_dapm_debugfs_init(struct snd_soc_dapm_context *dapm);
347 348
348/* dapm audio pin control and status */ 349/* dapm audio pin control and status */
349int snd_soc_dapm_enable_pin(struct snd_soc_codec *codec, const char *pin); 350int snd_soc_dapm_enable_pin(struct snd_soc_dapm_context *dapm,
350int snd_soc_dapm_disable_pin(struct snd_soc_codec *codec, const char *pin); 351 const char *pin);
351int snd_soc_dapm_nc_pin(struct snd_soc_codec *codec, const char *pin); 352int snd_soc_dapm_disable_pin(struct snd_soc_dapm_context *dapm,
352int snd_soc_dapm_get_pin_status(struct snd_soc_codec *codec, const char *pin); 353 const char *pin);
353int snd_soc_dapm_sync(struct snd_soc_codec *codec); 354int snd_soc_dapm_nc_pin(struct snd_soc_dapm_context *dapm, const char *pin);
354int snd_soc_dapm_force_enable_pin(struct snd_soc_codec *codec, 355int snd_soc_dapm_get_pin_status(struct snd_soc_dapm_context *dapm,
356 const char *pin);
357int snd_soc_dapm_sync(struct snd_soc_dapm_context *dapm);
358int snd_soc_dapm_force_enable_pin(struct snd_soc_dapm_context *dapm,
355 const char *pin); 359 const char *pin);
356int snd_soc_dapm_ignore_suspend(struct snd_soc_codec *codec, const char *pin); 360int snd_soc_dapm_ignore_suspend(struct snd_soc_dapm_context *dapm,
361 const char *pin);
357 362
358/* dapm widget types */ 363/* dapm widget types */
359enum snd_soc_dapm_type { 364enum snd_soc_dapm_type {
360 snd_soc_dapm_input = 0, /* input pin */ 365 snd_soc_dapm_input = 0, /* input pin */
361 snd_soc_dapm_output, /* output pin */ 366 snd_soc_dapm_output, /* output pin */
362 snd_soc_dapm_mux, /* selects 1 analog signal from many inputs */ 367 snd_soc_dapm_mux, /* selects 1 analog signal from many inputs */
368 snd_soc_dapm_virt_mux, /* virtual version of snd_soc_dapm_mux */
363 snd_soc_dapm_value_mux, /* selects 1 analog signal from many inputs */ 369 snd_soc_dapm_value_mux, /* selects 1 analog signal from many inputs */
364 snd_soc_dapm_mixer, /* mixes several analog signals together */ 370 snd_soc_dapm_mixer, /* mixes several analog signals together */
365 snd_soc_dapm_mixer_named_ctl, /* mixer with named controls */ 371 snd_soc_dapm_mixer_named_ctl, /* mixer with named controls */
366 snd_soc_dapm_pga, /* programmable gain/attenuation (volume) */ 372 snd_soc_dapm_pga, /* programmable gain/attenuation (volume) */
373 snd_soc_dapm_out_drv, /* output driver */
367 snd_soc_dapm_adc, /* analog to digital converter */ 374 snd_soc_dapm_adc, /* analog to digital converter */
368 snd_soc_dapm_dac, /* digital to analog converter */ 375 snd_soc_dapm_dac, /* digital to analog converter */
369 snd_soc_dapm_micbias, /* microphone bias (power) */ 376 snd_soc_dapm_micbias, /* microphone bias (power) */
@@ -425,6 +432,7 @@ struct snd_soc_dapm_widget {
425 char *sname; /* stream name */ 432 char *sname; /* stream name */
426 struct snd_soc_codec *codec; 433 struct snd_soc_codec *codec;
427 struct list_head list; 434 struct list_head list;
435 struct snd_soc_dapm_context *dapm;
428 436
429 /* dapm control */ 437 /* dapm control */
430 short reg; /* negative reg = no direct dapm */ 438 short reg; /* negative reg = no direct dapm */
@@ -461,4 +469,35 @@ struct snd_soc_dapm_widget {
461 struct list_head power_list; 469 struct list_head power_list;
462}; 470};
463 471
472struct snd_soc_dapm_update {
473 struct snd_soc_dapm_widget *widget;
474 struct snd_kcontrol *kcontrol;
475 int reg;
476 int mask;
477 int val;
478};
479
480/* DAPM context */
481struct snd_soc_dapm_context {
482 int n_widgets; /* number of widgets in this context */
483 enum snd_soc_bias_level bias_level;
484 enum snd_soc_bias_level suspend_bias_level;
485 struct delayed_work delayed_work;
486 unsigned int idle_bias_off:1; /* Use BIAS_OFF instead of STANDBY */
487
488 struct snd_soc_dapm_update *update;
489
490 struct device *dev; /* from parent - for debug */
491 struct snd_soc_codec *codec; /* parent codec */
492 struct snd_soc_card *card; /* parent card */
493
494 /* used during DAPM updates */
495 int dev_power;
496 struct list_head list;
497
498#ifdef CONFIG_DEBUG_FS
499 struct dentry *debugfs_dapm;
500#endif
501};
502
464#endif 503#endif
diff --git a/include/sound/soc.h b/include/sound/soc.h
index 5c3bce83f28a..74921f20a1d8 100644
--- a/include/sound/soc.h
+++ b/include/sound/soc.h
@@ -222,10 +222,8 @@ enum snd_soc_bias_level {
222 222
223struct snd_jack; 223struct snd_jack;
224struct snd_soc_card; 224struct snd_soc_card;
225struct snd_soc_device;
226struct snd_soc_pcm_stream; 225struct snd_soc_pcm_stream;
227struct snd_soc_ops; 226struct snd_soc_ops;
228struct snd_soc_dai_mode;
229struct snd_soc_pcm_runtime; 227struct snd_soc_pcm_runtime;
230struct snd_soc_dai; 228struct snd_soc_dai;
231struct snd_soc_dai_driver; 229struct snd_soc_dai_driver;
@@ -235,9 +233,10 @@ struct snd_soc_platform_driver;
235struct snd_soc_codec; 233struct snd_soc_codec;
236struct snd_soc_codec_driver; 234struct snd_soc_codec_driver;
237struct soc_enum; 235struct soc_enum;
238struct snd_soc_ac97_ops;
239struct snd_soc_jack; 236struct snd_soc_jack;
240struct snd_soc_jack_pin; 237struct snd_soc_jack_pin;
238struct snd_soc_cache_ops;
239#include <sound/soc-dapm.h>
241 240
242#ifdef CONFIG_GPIOLIB 241#ifdef CONFIG_GPIOLIB
243struct snd_soc_jack_gpio; 242struct snd_soc_jack_gpio;
@@ -253,17 +252,30 @@ enum snd_soc_control_type {
253 SND_SOC_SPI, 252 SND_SOC_SPI,
254}; 253};
255 254
255enum snd_soc_compress_type {
256 SND_SOC_FLAT_COMPRESSION = 1,
257 SND_SOC_LZO_COMPRESSION,
258 SND_SOC_RBTREE_COMPRESSION
259};
260
256int snd_soc_register_platform(struct device *dev, 261int snd_soc_register_platform(struct device *dev,
257 struct snd_soc_platform_driver *platform_drv); 262 struct snd_soc_platform_driver *platform_drv);
258void snd_soc_unregister_platform(struct device *dev); 263void snd_soc_unregister_platform(struct device *dev);
259int snd_soc_register_codec(struct device *dev, 264int snd_soc_register_codec(struct device *dev,
260 struct snd_soc_codec_driver *codec_drv, 265 const struct snd_soc_codec_driver *codec_drv,
261 struct snd_soc_dai_driver *dai_drv, int num_dai); 266 struct snd_soc_dai_driver *dai_drv, int num_dai);
262void snd_soc_unregister_codec(struct device *dev); 267void snd_soc_unregister_codec(struct device *dev);
263int snd_soc_codec_volatile_register(struct snd_soc_codec *codec, int reg); 268int snd_soc_codec_volatile_register(struct snd_soc_codec *codec, int reg);
264int snd_soc_codec_set_cache_io(struct snd_soc_codec *codec, 269int snd_soc_codec_set_cache_io(struct snd_soc_codec *codec,
265 int addr_bits, int data_bits, 270 int addr_bits, int data_bits,
266 enum snd_soc_control_type control); 271 enum snd_soc_control_type control);
272int snd_soc_cache_sync(struct snd_soc_codec *codec);
273int snd_soc_cache_init(struct snd_soc_codec *codec);
274int snd_soc_cache_exit(struct snd_soc_codec *codec);
275int snd_soc_cache_write(struct snd_soc_codec *codec,
276 unsigned int reg, unsigned int value);
277int snd_soc_cache_read(struct snd_soc_codec *codec,
278 unsigned int reg, unsigned int *value);
267 279
268/* Utility functions to get clock rates from various things */ 280/* Utility functions to get clock rates from various things */
269int snd_soc_calc_frame_size(int sample_size, int channels, int tdm_slots); 281int snd_soc_calc_frame_size(int sample_size, int channels, int tdm_slots);
@@ -420,23 +432,37 @@ struct snd_soc_ops {
420 int (*trigger)(struct snd_pcm_substream *, int); 432 int (*trigger)(struct snd_pcm_substream *, int);
421}; 433};
422 434
435/* SoC cache ops */
436struct snd_soc_cache_ops {
437 const char *name;
438 enum snd_soc_compress_type id;
439 int (*init)(struct snd_soc_codec *codec);
440 int (*exit)(struct snd_soc_codec *codec);
441 int (*read)(struct snd_soc_codec *codec, unsigned int reg,
442 unsigned int *value);
443 int (*write)(struct snd_soc_codec *codec, unsigned int reg,
444 unsigned int value);
445 int (*sync)(struct snd_soc_codec *codec);
446};
447
423/* SoC Audio Codec device */ 448/* SoC Audio Codec device */
424struct snd_soc_codec { 449struct snd_soc_codec {
425 const char *name; 450 const char *name;
451 const char *name_prefix;
426 int id; 452 int id;
427 struct device *dev; 453 struct device *dev;
428 struct snd_soc_codec_driver *driver; 454 const struct snd_soc_codec_driver *driver;
429 455
430 struct mutex mutex; 456 struct mutex mutex;
431 struct snd_soc_card *card; 457 struct snd_soc_card *card;
432 struct list_head list; 458 struct list_head list;
433 struct list_head card_list; 459 struct list_head card_list;
434 int num_dai; 460 int num_dai;
461 enum snd_soc_compress_type compress_type;
435 462
436 /* runtime */ 463 /* runtime */
437 struct snd_ac97 *ac97; /* for ad-hoc ac97 devices */ 464 struct snd_ac97 *ac97; /* for ad-hoc ac97 devices */
438 unsigned int active; 465 unsigned int active;
439 unsigned int idle_bias_off:1; /* Use BIAS_OFF instead of STANDBY */
440 unsigned int cache_only:1; /* Suppress writes to hardware */ 466 unsigned int cache_only:1; /* Suppress writes to hardware */
441 unsigned int cache_sync:1; /* Cache needs to be synced to hardware */ 467 unsigned int cache_sync:1; /* Cache needs to be synced to hardware */
442 unsigned int suspended:1; /* Codec is in suspend PM state */ 468 unsigned int suspended:1; /* Codec is in suspend PM state */
@@ -444,25 +470,25 @@ struct snd_soc_codec {
444 unsigned int ac97_registered:1; /* Codec has been AC97 registered */ 470 unsigned int ac97_registered:1; /* Codec has been AC97 registered */
445 unsigned int ac97_created:1; /* Codec has been created by SoC */ 471 unsigned int ac97_created:1; /* Codec has been created by SoC */
446 unsigned int sysfs_registered:1; /* codec has been sysfs registered */ 472 unsigned int sysfs_registered:1; /* codec has been sysfs registered */
473 unsigned int cache_init:1; /* codec cache has been initialized */
447 474
448 /* codec IO */ 475 /* codec IO */
449 void *control_data; /* codec control (i2c/3wire) data */ 476 void *control_data; /* codec control (i2c/3wire) data */
450 hw_write_t hw_write; 477 hw_write_t hw_write;
451 unsigned int (*hw_read)(struct snd_soc_codec *, unsigned int); 478 unsigned int (*hw_read)(struct snd_soc_codec *, unsigned int);
479 unsigned int (*read)(struct snd_soc_codec *, unsigned int);
480 int (*write)(struct snd_soc_codec *, unsigned int, unsigned int);
452 void *reg_cache; 481 void *reg_cache;
482 const void *reg_def_copy;
483 const struct snd_soc_cache_ops *cache_ops;
484 struct mutex cache_rw_mutex;
453 485
454 /* dapm */ 486 /* dapm */
455 u32 pop_time; 487 struct snd_soc_dapm_context dapm;
456 struct list_head dapm_widgets;
457 struct list_head dapm_paths;
458 enum snd_soc_bias_level bias_level;
459 enum snd_soc_bias_level suspend_bias_level;
460 struct delayed_work delayed_work;
461 488
462#ifdef CONFIG_DEBUG_FS 489#ifdef CONFIG_DEBUG_FS
463 struct dentry *debugfs_codec_root; 490 struct dentry *debugfs_codec_root;
464 struct dentry *debugfs_reg; 491 struct dentry *debugfs_reg;
465 struct dentry *debugfs_pop_time;
466 struct dentry *debugfs_dapm; 492 struct dentry *debugfs_dapm;
467#endif 493#endif
468}; 494};
@@ -488,6 +514,7 @@ struct snd_soc_codec_driver {
488 short reg_cache_step; 514 short reg_cache_step;
489 short reg_word_size; 515 short reg_word_size;
490 const void *reg_cache_default; 516 const void *reg_cache_default;
517 enum snd_soc_compress_type compress_type;
491 518
492 /* codec bias level */ 519 /* codec bias level */
493 int (*set_bias_level)(struct snd_soc_codec *, 520 int (*set_bias_level)(struct snd_soc_codec *,
@@ -554,6 +581,30 @@ struct snd_soc_dai_link {
554 struct snd_soc_ops *ops; 581 struct snd_soc_ops *ops;
555}; 582};
556 583
584struct snd_soc_codec_conf {
585 const char *dev_name;
586
587 /*
588 * optional map of kcontrol, widget and path name prefixes that are
589 * associated per device
590 */
591 const char *name_prefix;
592
593 /*
594 * set this to the desired compression type if you want to
595 * override the one supplied in codec->driver->compress_type
596 */
597 enum snd_soc_compress_type compress_type;
598};
599
600struct snd_soc_aux_dev {
601 const char *name; /* Codec name */
602 const char *codec_name; /* for multi-codec */
603
604 /* codec/machine specific init - e.g. add machine controls */
605 int (*init)(struct snd_soc_dapm_context *dapm);
606};
607
557/* SoC card */ 608/* SoC card */
558struct snd_soc_card { 609struct snd_soc_card {
559 const char *name; 610 const char *name;
@@ -579,6 +630,8 @@ struct snd_soc_card {
579 /* callbacks */ 630 /* callbacks */
580 int (*set_bias_level)(struct snd_soc_card *, 631 int (*set_bias_level)(struct snd_soc_card *,
581 enum snd_soc_bias_level level); 632 enum snd_soc_bias_level level);
633 int (*set_bias_level_post)(struct snd_soc_card *,
634 enum snd_soc_bias_level level);
582 635
583 long pmdown_time; 636 long pmdown_time;
584 637
@@ -588,12 +641,35 @@ struct snd_soc_card {
588 struct snd_soc_pcm_runtime *rtd; 641 struct snd_soc_pcm_runtime *rtd;
589 int num_rtd; 642 int num_rtd;
590 643
644 /* optional codec specific configuration */
645 struct snd_soc_codec_conf *codec_conf;
646 int num_configs;
647
648 /*
649 * optional auxiliary devices such as amplifiers or codecs with DAI
650 * link unused
651 */
652 struct snd_soc_aux_dev *aux_dev;
653 int num_aux_devs;
654 struct snd_soc_pcm_runtime *rtd_aux;
655 int num_aux_rtd;
656
591 struct work_struct deferred_resume_work; 657 struct work_struct deferred_resume_work;
592 658
593 /* lists of probed devices belonging to this card */ 659 /* lists of probed devices belonging to this card */
594 struct list_head codec_dev_list; 660 struct list_head codec_dev_list;
595 struct list_head platform_dev_list; 661 struct list_head platform_dev_list;
596 struct list_head dai_dev_list; 662 struct list_head dai_dev_list;
663
664 struct list_head widgets;
665 struct list_head paths;
666 struct list_head dapm_list;
667
668#ifdef CONFIG_DEBUG_FS
669 struct dentry *debugfs_card_root;
670 struct dentry *debugfs_pop_time;
671#endif
672 u32 pop_time;
597}; 673};
598 674
599/* SoC machine DAI configuration, glues a codec and cpu DAI together */ 675/* SoC machine DAI configuration, glues a codec and cpu DAI together */
@@ -639,17 +715,9 @@ struct soc_enum {
639}; 715};
640 716
641/* codec IO */ 717/* codec IO */
642static inline unsigned int snd_soc_read(struct snd_soc_codec *codec, 718unsigned int snd_soc_read(struct snd_soc_codec *codec, unsigned int reg);
643 unsigned int reg) 719unsigned int snd_soc_write(struct snd_soc_codec *codec,
644{ 720 unsigned int reg, unsigned int val);
645 return codec->driver->read(codec, reg);
646}
647
648static inline unsigned int snd_soc_write(struct snd_soc_codec *codec,
649 unsigned int reg, unsigned int val)
650{
651 return codec->driver->write(codec, reg, val);
652}
653 721
654/* device driver data */ 722/* device driver data */
655 723
diff --git a/include/trace/events/asoc.h b/include/trace/events/asoc.h
new file mode 100644
index 000000000000..186e84db4b54
--- /dev/null
+++ b/include/trace/events/asoc.h
@@ -0,0 +1,235 @@
1#undef TRACE_SYSTEM
2#define TRACE_SYSTEM asoc
3
4#if !defined(_TRACE_ASOC_H) || defined(TRACE_HEADER_MULTI_READ)
5#define _TRACE_ASOC_H
6
7#include <linux/ktime.h>
8#include <linux/tracepoint.h>
9
10struct snd_soc_jack;
11struct snd_soc_codec;
12struct snd_soc_card;
13struct snd_soc_dapm_widget;
14
15/*
16 * Log register events
17 */
18DECLARE_EVENT_CLASS(snd_soc_reg,
19
20 TP_PROTO(struct snd_soc_codec *codec, unsigned int reg,
21 unsigned int val),
22
23 TP_ARGS(codec, reg, val),
24
25 TP_STRUCT__entry(
26 __string( name, codec->name )
27 __field( int, id )
28 __field( unsigned int, reg )
29 __field( unsigned int, val )
30 ),
31
32 TP_fast_assign(
33 __assign_str(name, codec->name);
34 __entry->id = codec->id;
35 __entry->reg = reg;
36 __entry->val = val;
37 ),
38
39 TP_printk("codec=%s.%d reg=%x val=%x", __get_str(name),
40 (int)__entry->id, (unsigned int)__entry->reg,
41 (unsigned int)__entry->val)
42);
43
44DEFINE_EVENT(snd_soc_reg, snd_soc_reg_write,
45
46 TP_PROTO(struct snd_soc_codec *codec, unsigned int reg,
47 unsigned int val),
48
49 TP_ARGS(codec, reg, val)
50
51);
52
53DEFINE_EVENT(snd_soc_reg, snd_soc_reg_read,
54
55 TP_PROTO(struct snd_soc_codec *codec, unsigned int reg,
56 unsigned int val),
57
58 TP_ARGS(codec, reg, val)
59
60);
61
62DECLARE_EVENT_CLASS(snd_soc_card,
63
64 TP_PROTO(struct snd_soc_card *card, int val),
65
66 TP_ARGS(card, val),
67
68 TP_STRUCT__entry(
69 __string( name, card->name )
70 __field( int, val )
71 ),
72
73 TP_fast_assign(
74 __assign_str(name, card->name);
75 __entry->val = val;
76 ),
77
78 TP_printk("card=%s val=%d", __get_str(name), (int)__entry->val)
79);
80
81DEFINE_EVENT(snd_soc_card, snd_soc_bias_level_start,
82
83 TP_PROTO(struct snd_soc_card *card, int val),
84
85 TP_ARGS(card, val)
86
87);
88
89DEFINE_EVENT(snd_soc_card, snd_soc_bias_level_done,
90
91 TP_PROTO(struct snd_soc_card *card, int val),
92
93 TP_ARGS(card, val)
94
95);
96
97DECLARE_EVENT_CLASS(snd_soc_dapm_basic,
98
99 TP_PROTO(struct snd_soc_card *card),
100
101 TP_ARGS(card),
102
103 TP_STRUCT__entry(
104 __string( name, card->name )
105 ),
106
107 TP_fast_assign(
108 __assign_str(name, card->name);
109 ),
110
111 TP_printk("card=%s", __get_str(name))
112);
113
114DEFINE_EVENT(snd_soc_dapm_basic, snd_soc_dapm_start,
115
116 TP_PROTO(struct snd_soc_card *card),
117
118 TP_ARGS(card)
119
120);
121
122DEFINE_EVENT(snd_soc_dapm_basic, snd_soc_dapm_done,
123
124 TP_PROTO(struct snd_soc_card *card),
125
126 TP_ARGS(card)
127
128);
129
130DECLARE_EVENT_CLASS(snd_soc_dapm_widget,
131
132 TP_PROTO(struct snd_soc_dapm_widget *w, int val),
133
134 TP_ARGS(w, val),
135
136 TP_STRUCT__entry(
137 __string( name, w->name )
138 __field( int, val )
139 ),
140
141 TP_fast_assign(
142 __assign_str(name, w->name);
143 __entry->val = val;
144 ),
145
146 TP_printk("widget=%s val=%d", __get_str(name),
147 (int)__entry->val)
148);
149
150DEFINE_EVENT(snd_soc_dapm_widget, snd_soc_dapm_widget_power,
151
152 TP_PROTO(struct snd_soc_dapm_widget *w, int val),
153
154 TP_ARGS(w, val)
155
156);
157
158DEFINE_EVENT(snd_soc_dapm_widget, snd_soc_dapm_widget_event_start,
159
160 TP_PROTO(struct snd_soc_dapm_widget *w, int val),
161
162 TP_ARGS(w, val)
163
164);
165
166DEFINE_EVENT(snd_soc_dapm_widget, snd_soc_dapm_widget_event_done,
167
168 TP_PROTO(struct snd_soc_dapm_widget *w, int val),
169
170 TP_ARGS(w, val)
171
172);
173
174TRACE_EVENT(snd_soc_jack_irq,
175
176 TP_PROTO(const char *name),
177
178 TP_ARGS(name),
179
180 TP_STRUCT__entry(
181 __string( name, name )
182 ),
183
184 TP_fast_assign(
185 __assign_str(name, name);
186 ),
187
188 TP_printk("%s", __get_str(name))
189);
190
191TRACE_EVENT(snd_soc_jack_report,
192
193 TP_PROTO(struct snd_soc_jack *jack, int mask, int val),
194
195 TP_ARGS(jack, mask, val),
196
197 TP_STRUCT__entry(
198 __string( name, jack->jack->name )
199 __field( int, mask )
200 __field( int, val )
201 ),
202
203 TP_fast_assign(
204 __assign_str(name, jack->jack->name);
205 __entry->mask = mask;
206 __entry->val = val;
207 ),
208
209 TP_printk("jack=%s %x/%x", __get_str(name), (int)__entry->val,
210 (int)__entry->mask)
211);
212
213TRACE_EVENT(snd_soc_jack_notify,
214
215 TP_PROTO(struct snd_soc_jack *jack, int val),
216
217 TP_ARGS(jack, val),
218
219 TP_STRUCT__entry(
220 __string( name, jack->jack->name )
221 __field( int, val )
222 ),
223
224 TP_fast_assign(
225 __assign_str(name, jack->jack->name);
226 __entry->val = val;
227 ),
228
229 TP_printk("jack=%s %x", __get_str(name), (int)__entry->val)
230);
231
232#endif /* _TRACE_ASOC_H */
233
234/* This part must be outside protection */
235#include <trace/define_trace.h>
diff --git a/include/trace/events/kvm.h b/include/trace/events/kvm.h
index 6dd3a51ab1cb..46e3cd8e197a 100644
--- a/include/trace/events/kvm.h
+++ b/include/trace/events/kvm.h
@@ -6,6 +6,36 @@
6#undef TRACE_SYSTEM 6#undef TRACE_SYSTEM
7#define TRACE_SYSTEM kvm 7#define TRACE_SYSTEM kvm
8 8
9#define ERSN(x) { KVM_EXIT_##x, "KVM_EXIT_" #x }
10
11#define kvm_trace_exit_reason \
12 ERSN(UNKNOWN), ERSN(EXCEPTION), ERSN(IO), ERSN(HYPERCALL), \
13 ERSN(DEBUG), ERSN(HLT), ERSN(MMIO), ERSN(IRQ_WINDOW_OPEN), \
14 ERSN(SHUTDOWN), ERSN(FAIL_ENTRY), ERSN(INTR), ERSN(SET_TPR), \
15 ERSN(TPR_ACCESS), ERSN(S390_SIEIC), ERSN(S390_RESET), ERSN(DCR),\
16 ERSN(NMI), ERSN(INTERNAL_ERROR), ERSN(OSI)
17
18TRACE_EVENT(kvm_userspace_exit,
19 TP_PROTO(__u32 reason, int errno),
20 TP_ARGS(reason, errno),
21
22 TP_STRUCT__entry(
23 __field( __u32, reason )
24 __field( int, errno )
25 ),
26
27 TP_fast_assign(
28 __entry->reason = reason;
29 __entry->errno = errno;
30 ),
31
32 TP_printk("reason %s (%d)",
33 __entry->errno < 0 ?
34 (__entry->errno == -EINTR ? "restart" : "error") :
35 __print_symbolic(__entry->reason, kvm_trace_exit_reason),
36 __entry->errno < 0 ? -__entry->errno : __entry->reason)
37);
38
9#if defined(__KVM_HAVE_IOAPIC) 39#if defined(__KVM_HAVE_IOAPIC)
10TRACE_EVENT(kvm_set_irq, 40TRACE_EVENT(kvm_set_irq,
11 TP_PROTO(unsigned int gsi, int level, int irq_source_id), 41 TP_PROTO(unsigned int gsi, int level, int irq_source_id),
@@ -185,6 +215,97 @@ TRACE_EVENT(kvm_age_page,
185 __entry->referenced ? "YOUNG" : "OLD") 215 __entry->referenced ? "YOUNG" : "OLD")
186); 216);
187 217
218#ifdef CONFIG_KVM_ASYNC_PF
219DECLARE_EVENT_CLASS(kvm_async_get_page_class,
220
221 TP_PROTO(u64 gva, u64 gfn),
222
223 TP_ARGS(gva, gfn),
224
225 TP_STRUCT__entry(
226 __field(__u64, gva)
227 __field(u64, gfn)
228 ),
229
230 TP_fast_assign(
231 __entry->gva = gva;
232 __entry->gfn = gfn;
233 ),
234
235 TP_printk("gva = %#llx, gfn = %#llx", __entry->gva, __entry->gfn)
236);
237
238DEFINE_EVENT(kvm_async_get_page_class, kvm_try_async_get_page,
239
240 TP_PROTO(u64 gva, u64 gfn),
241
242 TP_ARGS(gva, gfn)
243);
244
245DEFINE_EVENT(kvm_async_get_page_class, kvm_async_pf_doublefault,
246
247 TP_PROTO(u64 gva, u64 gfn),
248
249 TP_ARGS(gva, gfn)
250);
251
252DECLARE_EVENT_CLASS(kvm_async_pf_nopresent_ready,
253
254 TP_PROTO(u64 token, u64 gva),
255
256 TP_ARGS(token, gva),
257
258 TP_STRUCT__entry(
259 __field(__u64, token)
260 __field(__u64, gva)
261 ),
262
263 TP_fast_assign(
264 __entry->token = token;
265 __entry->gva = gva;
266 ),
267
268 TP_printk("token %#llx gva %#llx", __entry->token, __entry->gva)
269
270);
271
272DEFINE_EVENT(kvm_async_pf_nopresent_ready, kvm_async_pf_not_present,
273
274 TP_PROTO(u64 token, u64 gva),
275
276 TP_ARGS(token, gva)
277);
278
279DEFINE_EVENT(kvm_async_pf_nopresent_ready, kvm_async_pf_ready,
280
281 TP_PROTO(u64 token, u64 gva),
282
283 TP_ARGS(token, gva)
284);
285
286TRACE_EVENT(
287 kvm_async_pf_completed,
288 TP_PROTO(unsigned long address, struct page *page, u64 gva),
289 TP_ARGS(address, page, gva),
290
291 TP_STRUCT__entry(
292 __field(unsigned long, address)
293 __field(pfn_t, pfn)
294 __field(u64, gva)
295 ),
296
297 TP_fast_assign(
298 __entry->address = address;
299 __entry->pfn = page ? page_to_pfn(page) : 0;
300 __entry->gva = gva;
301 ),
302
303 TP_printk("gva %#llx address %#lx pfn %#llx", __entry->gva,
304 __entry->address, __entry->pfn)
305);
306
307#endif
308
188#endif /* _TRACE_KVM_MAIN_H */ 309#endif /* _TRACE_KVM_MAIN_H */
189 310
190/* This part must be outside protection */ 311/* This part must be outside protection */
diff --git a/include/trace/events/regulator.h b/include/trace/events/regulator.h
new file mode 100644
index 000000000000..37502a7404b7
--- /dev/null
+++ b/include/trace/events/regulator.h
@@ -0,0 +1,141 @@
1#undef TRACE_SYSTEM
2#define TRACE_SYSTEM regulator
3
4#if !defined(_TRACE_REGULATOR_H) || defined(TRACE_HEADER_MULTI_READ)
5#define _TRACE_REGULATOR_H
6
7#include <linux/ktime.h>
8#include <linux/tracepoint.h>
9
10/*
11 * Events which just log themselves and the regulator name for enable/disable
12 * type tracking.
13 */
14DECLARE_EVENT_CLASS(regulator_basic,
15
16 TP_PROTO(const char *name),
17
18 TP_ARGS(name),
19
20 TP_STRUCT__entry(
21 __string( name, name )
22 ),
23
24 TP_fast_assign(
25 __assign_str(name, name);
26 ),
27
28 TP_printk("name=%s", __get_str(name))
29
30);
31
32DEFINE_EVENT(regulator_basic, regulator_enable,
33
34 TP_PROTO(const char *name),
35
36 TP_ARGS(name)
37
38);
39
40DEFINE_EVENT(regulator_basic, regulator_enable_delay,
41
42 TP_PROTO(const char *name),
43
44 TP_ARGS(name)
45
46);
47
48DEFINE_EVENT(regulator_basic, regulator_enable_complete,
49
50 TP_PROTO(const char *name),
51
52 TP_ARGS(name)
53
54);
55
56DEFINE_EVENT(regulator_basic, regulator_disable,
57
58 TP_PROTO(const char *name),
59
60 TP_ARGS(name)
61
62);
63
64DEFINE_EVENT(regulator_basic, regulator_disable_complete,
65
66 TP_PROTO(const char *name),
67
68 TP_ARGS(name)
69
70);
71
72/*
73 * Events that take a range of numerical values, mostly for voltages
74 * and so on.
75 */
76DECLARE_EVENT_CLASS(regulator_range,
77
78 TP_PROTO(const char *name, int min, int max),
79
80 TP_ARGS(name, min, max),
81
82 TP_STRUCT__entry(
83 __string( name, name )
84 __field( int, min )
85 __field( int, max )
86 ),
87
88 TP_fast_assign(
89 __assign_str(name, name);
90 __entry->min = min;
91 __entry->max = max;
92 ),
93
94 TP_printk("name=%s (%d-%d)", __get_str(name),
95 (int)__entry->min, (int)__entry->max)
96);
97
98DEFINE_EVENT(regulator_range, regulator_set_voltage,
99
100 TP_PROTO(const char *name, int min, int max),
101
102 TP_ARGS(name, min, max)
103
104);
105
106
107/*
108 * Events that take a single value, mostly for readback and refcounts.
109 */
110DECLARE_EVENT_CLASS(regulator_value,
111
112 TP_PROTO(const char *name, unsigned int val),
113
114 TP_ARGS(name, val),
115
116 TP_STRUCT__entry(
117 __string( name, name )
118 __field( unsigned int, val )
119 ),
120
121 TP_fast_assign(
122 __assign_str(name, name);
123 __entry->val = val;
124 ),
125
126 TP_printk("name=%s, val=%u", __get_str(name),
127 (int)__entry->val)
128);
129
130DEFINE_EVENT(regulator_value, regulator_set_voltage_complete,
131
132 TP_PROTO(const char *name, unsigned int value),
133
134 TP_ARGS(name, value)
135
136);
137
138#endif /* _TRACE_POWER_H */
139
140/* This part must be outside protection */
141#include <trace/define_trace.h>
diff --git a/init/Kconfig b/init/Kconfig
index 8dfd094e6875..4f6cdbf523eb 100644
--- a/init/Kconfig
+++ b/init/Kconfig
@@ -130,13 +130,16 @@ config HAVE_KERNEL_BZIP2
130config HAVE_KERNEL_LZMA 130config HAVE_KERNEL_LZMA
131 bool 131 bool
132 132
133config HAVE_KERNEL_XZ
134 bool
135
133config HAVE_KERNEL_LZO 136config HAVE_KERNEL_LZO
134 bool 137 bool
135 138
136choice 139choice
137 prompt "Kernel compression mode" 140 prompt "Kernel compression mode"
138 default KERNEL_GZIP 141 default KERNEL_GZIP
139 depends on HAVE_KERNEL_GZIP || HAVE_KERNEL_BZIP2 || HAVE_KERNEL_LZMA || HAVE_KERNEL_LZO 142 depends on HAVE_KERNEL_GZIP || HAVE_KERNEL_BZIP2 || HAVE_KERNEL_LZMA || HAVE_KERNEL_XZ || HAVE_KERNEL_LZO
140 help 143 help
141 The linux kernel is a kind of self-extracting executable. 144 The linux kernel is a kind of self-extracting executable.
142 Several compression algorithms are available, which differ 145 Several compression algorithms are available, which differ
@@ -181,6 +184,21 @@ config KERNEL_LZMA
181 two. Compression is slowest. The kernel size is about 33% 184 two. Compression is slowest. The kernel size is about 33%
182 smaller with LZMA in comparison to gzip. 185 smaller with LZMA in comparison to gzip.
183 186
187config KERNEL_XZ
188 bool "XZ"
189 depends on HAVE_KERNEL_XZ
190 help
191 XZ uses the LZMA2 algorithm and instruction set specific
192 BCJ filters which can improve compression ratio of executable
193 code. The size of the kernel is about 30% smaller with XZ in
194 comparison to gzip. On architectures for which there is a BCJ
195 filter (i386, x86_64, ARM, IA-64, PowerPC, and SPARC), XZ
196 will create a few percent smaller kernel than plain LZMA.
197
198 The speed is about the same as with LZMA: The decompression
199 speed of XZ is better than that of bzip2 but worse than gzip
200 and LZO. Compression is slow.
201
184config KERNEL_LZO 202config KERNEL_LZO
185 bool "LZO" 203 bool "LZO"
186 depends on HAVE_KERNEL_LZO 204 depends on HAVE_KERNEL_LZO
@@ -673,7 +691,7 @@ config CGROUP_MEM_RES_CTLR_SWAP_ENABLED
673 help 691 help
674 Memory Resource Controller Swap Extension comes with its price in 692 Memory Resource Controller Swap Extension comes with its price in
675 a bigger memory consumption. General purpose distribution kernels 693 a bigger memory consumption. General purpose distribution kernels
676 which want to enable the feautre but keep it disabled by default 694 which want to enable the feature but keep it disabled by default
677 and let the user enable it by swapaccount boot command line 695 and let the user enable it by swapaccount boot command line
678 parameter should have this option unselected. 696 parameter should have this option unselected.
679 For those who want to have the feature enabled by default should 697 For those who want to have the feature enabled by default should
diff --git a/kernel/Makefile b/kernel/Makefile
index 5669f71dfdd5..353d3fe8ba33 100644
--- a/kernel/Makefile
+++ b/kernel/Makefile
@@ -43,7 +43,7 @@ obj-$(CONFIG_RT_MUTEXES) += rtmutex.o
43obj-$(CONFIG_DEBUG_RT_MUTEXES) += rtmutex-debug.o 43obj-$(CONFIG_DEBUG_RT_MUTEXES) += rtmutex-debug.o
44obj-$(CONFIG_RT_MUTEX_TESTER) += rtmutex-tester.o 44obj-$(CONFIG_RT_MUTEX_TESTER) += rtmutex-tester.o
45obj-$(CONFIG_GENERIC_ISA_DMA) += dma.o 45obj-$(CONFIG_GENERIC_ISA_DMA) += dma.o
46obj-$(CONFIG_USE_GENERIC_SMP_HELPERS) += smp.o 46obj-$(CONFIG_SMP) += smp.o
47ifneq ($(CONFIG_SMP),y) 47ifneq ($(CONFIG_SMP),y)
48obj-y += up.o 48obj-y += up.o
49endif 49endif
diff --git a/kernel/audit.c b/kernel/audit.c
index 77770a034d59..e4956244ae50 100644
--- a/kernel/audit.c
+++ b/kernel/audit.c
@@ -400,7 +400,7 @@ static void kauditd_send_skb(struct sk_buff *skb)
400 if (err < 0) { 400 if (err < 0) {
401 BUG_ON(err != -ECONNREFUSED); /* Shouldn't happen */ 401 BUG_ON(err != -ECONNREFUSED); /* Shouldn't happen */
402 printk(KERN_ERR "audit: *NO* daemon at audit_pid=%d\n", audit_pid); 402 printk(KERN_ERR "audit: *NO* daemon at audit_pid=%d\n", audit_pid);
403 audit_log_lost("auditd dissapeared\n"); 403 audit_log_lost("auditd disappeared\n");
404 audit_pid = 0; 404 audit_pid = 0;
405 /* we might get lucky and get this in the next auditd */ 405 /* we might get lucky and get this in the next auditd */
406 audit_hold_skb(skb); 406 audit_hold_skb(skb);
diff --git a/kernel/cgroup.c b/kernel/cgroup.c
index 51cddc11cd85..5c5f4cc2e99a 100644
--- a/kernel/cgroup.c
+++ b/kernel/cgroup.c
@@ -763,8 +763,6 @@ EXPORT_SYMBOL_GPL(cgroup_unlock);
763 * -> cgroup_mkdir. 763 * -> cgroup_mkdir.
764 */ 764 */
765 765
766static struct dentry *cgroup_lookup(struct inode *dir,
767 struct dentry *dentry, struct nameidata *nd);
768static int cgroup_mkdir(struct inode *dir, struct dentry *dentry, int mode); 766static int cgroup_mkdir(struct inode *dir, struct dentry *dentry, int mode);
769static int cgroup_rmdir(struct inode *unused_dir, struct dentry *dentry); 767static int cgroup_rmdir(struct inode *unused_dir, struct dentry *dentry);
770static int cgroup_populate_dir(struct cgroup *cgrp); 768static int cgroup_populate_dir(struct cgroup *cgrp);
@@ -1451,6 +1449,10 @@ static int cgroup_set_super(struct super_block *sb, void *data)
1451 1449
1452static int cgroup_get_rootdir(struct super_block *sb) 1450static int cgroup_get_rootdir(struct super_block *sb)
1453{ 1451{
1452 static const struct dentry_operations cgroup_dops = {
1453 .d_iput = cgroup_diput,
1454 };
1455
1454 struct inode *inode = 1456 struct inode *inode =
1455 cgroup_new_inode(S_IFDIR | S_IRUGO | S_IXUGO | S_IWUSR, sb); 1457 cgroup_new_inode(S_IFDIR | S_IRUGO | S_IXUGO | S_IWUSR, sb);
1456 struct dentry *dentry; 1458 struct dentry *dentry;
@@ -1468,6 +1470,8 @@ static int cgroup_get_rootdir(struct super_block *sb)
1468 return -ENOMEM; 1470 return -ENOMEM;
1469 } 1471 }
1470 sb->s_root = dentry; 1472 sb->s_root = dentry;
1473 /* for everything else we want ->d_op set */
1474 sb->s_d_op = &cgroup_dops;
1471 return 0; 1475 return 0;
1472} 1476}
1473 1477
@@ -2191,7 +2195,7 @@ static const struct file_operations cgroup_file_operations = {
2191}; 2195};
2192 2196
2193static const struct inode_operations cgroup_dir_inode_operations = { 2197static const struct inode_operations cgroup_dir_inode_operations = {
2194 .lookup = cgroup_lookup, 2198 .lookup = simple_lookup,
2195 .mkdir = cgroup_mkdir, 2199 .mkdir = cgroup_mkdir,
2196 .rmdir = cgroup_rmdir, 2200 .rmdir = cgroup_rmdir,
2197 .rename = cgroup_rename, 2201 .rename = cgroup_rename,
@@ -2207,26 +2211,6 @@ static inline struct cftype *__file_cft(struct file *file)
2207 return __d_cft(file->f_dentry); 2211 return __d_cft(file->f_dentry);
2208} 2212}
2209 2213
2210static int cgroup_delete_dentry(const struct dentry *dentry)
2211{
2212 return 1;
2213}
2214
2215static struct dentry *cgroup_lookup(struct inode *dir,
2216 struct dentry *dentry, struct nameidata *nd)
2217{
2218 static const struct dentry_operations cgroup_dentry_operations = {
2219 .d_delete = cgroup_delete_dentry,
2220 .d_iput = cgroup_diput,
2221 };
2222
2223 if (dentry->d_name.len > NAME_MAX)
2224 return ERR_PTR(-ENAMETOOLONG);
2225 d_set_d_op(dentry, &cgroup_dentry_operations);
2226 d_add(dentry, NULL);
2227 return NULL;
2228}
2229
2230static int cgroup_create_file(struct dentry *dentry, mode_t mode, 2214static int cgroup_create_file(struct dentry *dentry, mode_t mode,
2231 struct super_block *sb) 2215 struct super_block *sb)
2232{ 2216{
diff --git a/kernel/debug/kdb/kdb_main.c b/kernel/debug/kdb/kdb_main.c
index a6e729766821..bd3e8e29caa3 100644
--- a/kernel/debug/kdb/kdb_main.c
+++ b/kernel/debug/kdb/kdb_main.c
@@ -2914,7 +2914,7 @@ static void __init kdb_cmd_init(void)
2914 } 2914 }
2915} 2915}
2916 2916
2917/* Intialize kdb_printf, breakpoint tables and kdb state */ 2917/* Initialize kdb_printf, breakpoint tables and kdb state */
2918void __init kdb_init(int lvl) 2918void __init kdb_init(int lvl)
2919{ 2919{
2920 static int kdb_init_lvl = KDB_NOT_INITIALIZED; 2920 static int kdb_init_lvl = KDB_NOT_INITIALIZED;
diff --git a/kernel/hrtimer.c b/kernel/hrtimer.c
index 45da2b6920ab..0c8d7c048615 100644
--- a/kernel/hrtimer.c
+++ b/kernel/hrtimer.c
@@ -1745,7 +1745,7 @@ schedule_hrtimeout_range_clock(ktime_t *expires, unsigned long delta,
1745 } 1745 }
1746 1746
1747 /* 1747 /*
1748 * A NULL parameter means "inifinte" 1748 * A NULL parameter means "infinite"
1749 */ 1749 */
1750 if (!expires) { 1750 if (!expires) {
1751 schedule(); 1751 schedule();
diff --git a/kernel/kexec.c b/kernel/kexec.c
index b55045bc7563..ec19b92c7ebd 100644
--- a/kernel/kexec.c
+++ b/kernel/kexec.c
@@ -163,7 +163,7 @@ static int do_kimage_alloc(struct kimage **rimage, unsigned long entry,
163 * just verifies it is an address we can use. 163 * just verifies it is an address we can use.
164 * 164 *
165 * Since the kernel does everything in page size chunks ensure 165 * Since the kernel does everything in page size chunks ensure
166 * the destination addreses are page aligned. Too many 166 * the destination addresses are page aligned. Too many
167 * special cases crop of when we don't do this. The most 167 * special cases crop of when we don't do this. The most
168 * insidious is getting overlapping destination addresses 168 * insidious is getting overlapping destination addresses
169 * simply because addresses are changed to page size 169 * simply because addresses are changed to page size
diff --git a/kernel/latencytop.c b/kernel/latencytop.c
index 17110a4a4fc2..ee74b35e528d 100644
--- a/kernel/latencytop.c
+++ b/kernel/latencytop.c
@@ -241,24 +241,19 @@ static int lstats_show(struct seq_file *m, void *v)
241 seq_puts(m, "Latency Top version : v0.1\n"); 241 seq_puts(m, "Latency Top version : v0.1\n");
242 242
243 for (i = 0; i < MAXLR; i++) { 243 for (i = 0; i < MAXLR; i++) {
244 if (latency_record[i].backtrace[0]) { 244 struct latency_record *lr = &latency_record[i];
245
246 if (lr->backtrace[0]) {
245 int q; 247 int q;
246 seq_printf(m, "%i %lu %lu ", 248 seq_printf(m, "%i %lu %lu",
247 latency_record[i].count, 249 lr->count, lr->time, lr->max);
248 latency_record[i].time,
249 latency_record[i].max);
250 for (q = 0; q < LT_BACKTRACEDEPTH; q++) { 250 for (q = 0; q < LT_BACKTRACEDEPTH; q++) {
251 char sym[KSYM_SYMBOL_LEN]; 251 unsigned long bt = lr->backtrace[q];
252 char *c; 252 if (!bt)
253 if (!latency_record[i].backtrace[q])
254 break; 253 break;
255 if (latency_record[i].backtrace[q] == ULONG_MAX) 254 if (bt == ULONG_MAX)
256 break; 255 break;
257 sprint_symbol(sym, latency_record[i].backtrace[q]); 256 seq_printf(m, " %ps", (void *)bt);
258 c = strchr(sym, '+');
259 if (c)
260 *c = 0;
261 seq_printf(m, "%s ", sym);
262 } 257 }
263 seq_printf(m, "\n"); 258 seq_printf(m, "\n");
264 } 259 }
diff --git a/kernel/perf_event.c b/kernel/perf_event.c
index b782b7a79f00..05ebe841270b 100644
--- a/kernel/perf_event.c
+++ b/kernel/perf_event.c
@@ -4664,7 +4664,7 @@ int perf_swevent_get_recursion_context(void)
4664} 4664}
4665EXPORT_SYMBOL_GPL(perf_swevent_get_recursion_context); 4665EXPORT_SYMBOL_GPL(perf_swevent_get_recursion_context);
4666 4666
4667void inline perf_swevent_put_recursion_context(int rctx) 4667inline void perf_swevent_put_recursion_context(int rctx)
4668{ 4668{
4669 struct swevent_htable *swhash = &__get_cpu_var(swevent_htable); 4669 struct swevent_htable *swhash = &__get_cpu_var(swevent_htable);
4670 4670
diff --git a/kernel/power/hibernate.c b/kernel/power/hibernate.c
index 870f72bc72ae..1832bd264219 100644
--- a/kernel/power/hibernate.c
+++ b/kernel/power/hibernate.c
@@ -51,14 +51,14 @@ enum {
51 51
52static int hibernation_mode = HIBERNATION_SHUTDOWN; 52static int hibernation_mode = HIBERNATION_SHUTDOWN;
53 53
54static struct platform_hibernation_ops *hibernation_ops; 54static const struct platform_hibernation_ops *hibernation_ops;
55 55
56/** 56/**
57 * hibernation_set_ops - set the global hibernate operations 57 * hibernation_set_ops - set the global hibernate operations
58 * @ops: the hibernation operations to use in subsequent hibernation transitions 58 * @ops: the hibernation operations to use in subsequent hibernation transitions
59 */ 59 */
60 60
61void hibernation_set_ops(struct platform_hibernation_ops *ops) 61void hibernation_set_ops(const struct platform_hibernation_ops *ops)
62{ 62{
63 if (ops && !(ops->begin && ops->end && ops->pre_snapshot 63 if (ops && !(ops->begin && ops->end && ops->pre_snapshot
64 && ops->prepare && ops->finish && ops->enter && ops->pre_restore 64 && ops->prepare && ops->finish && ops->enter && ops->pre_restore
diff --git a/kernel/power/suspend.c b/kernel/power/suspend.c
index 8850df68794d..de6f86bfa303 100644
--- a/kernel/power/suspend.c
+++ b/kernel/power/suspend.c
@@ -31,13 +31,13 @@ const char *const pm_states[PM_SUSPEND_MAX] = {
31 [PM_SUSPEND_MEM] = "mem", 31 [PM_SUSPEND_MEM] = "mem",
32}; 32};
33 33
34static struct platform_suspend_ops *suspend_ops; 34static const struct platform_suspend_ops *suspend_ops;
35 35
36/** 36/**
37 * suspend_set_ops - Set the global suspend method table. 37 * suspend_set_ops - Set the global suspend method table.
38 * @ops: Pointer to ops structure. 38 * @ops: Pointer to ops structure.
39 */ 39 */
40void suspend_set_ops(struct platform_suspend_ops *ops) 40void suspend_set_ops(const struct platform_suspend_ops *ops)
41{ 41{
42 mutex_lock(&pm_mutex); 42 mutex_lock(&pm_mutex);
43 suspend_ops = ops; 43 suspend_ops = ops;
diff --git a/kernel/power/swap.c b/kernel/power/swap.c
index 8c7e4832b9be..69425889bd40 100644
--- a/kernel/power/swap.c
+++ b/kernel/power/swap.c
@@ -888,7 +888,7 @@ out_finish:
888/** 888/**
889 * swsusp_read - read the hibernation image. 889 * swsusp_read - read the hibernation image.
890 * @flags_p: flags passed by the "frozen" kernel in the image header should 890 * @flags_p: flags passed by the "frozen" kernel in the image header should
891 * be written into this memeory location 891 * be written into this memory location
892 */ 892 */
893 893
894int swsusp_read(unsigned int *flags_p) 894int swsusp_read(unsigned int *flags_p)
diff --git a/kernel/printk.c b/kernel/printk.c
index f64b8997fc76..53d9a9ec88e6 100644
--- a/kernel/printk.c
+++ b/kernel/printk.c
@@ -39,6 +39,7 @@
39#include <linux/syslog.h> 39#include <linux/syslog.h>
40#include <linux/cpu.h> 40#include <linux/cpu.h>
41#include <linux/notifier.h> 41#include <linux/notifier.h>
42#include <linux/rculist.h>
42 43
43#include <asm/uaccess.h> 44#include <asm/uaccess.h>
44 45
@@ -1502,7 +1503,7 @@ int kmsg_dump_register(struct kmsg_dumper *dumper)
1502 /* Don't allow registering multiple times */ 1503 /* Don't allow registering multiple times */
1503 if (!dumper->registered) { 1504 if (!dumper->registered) {
1504 dumper->registered = 1; 1505 dumper->registered = 1;
1505 list_add_tail(&dumper->list, &dump_list); 1506 list_add_tail_rcu(&dumper->list, &dump_list);
1506 err = 0; 1507 err = 0;
1507 } 1508 }
1508 spin_unlock_irqrestore(&dump_list_lock, flags); 1509 spin_unlock_irqrestore(&dump_list_lock, flags);
@@ -1526,29 +1527,16 @@ int kmsg_dump_unregister(struct kmsg_dumper *dumper)
1526 spin_lock_irqsave(&dump_list_lock, flags); 1527 spin_lock_irqsave(&dump_list_lock, flags);
1527 if (dumper->registered) { 1528 if (dumper->registered) {
1528 dumper->registered = 0; 1529 dumper->registered = 0;
1529 list_del(&dumper->list); 1530 list_del_rcu(&dumper->list);
1530 err = 0; 1531 err = 0;
1531 } 1532 }
1532 spin_unlock_irqrestore(&dump_list_lock, flags); 1533 spin_unlock_irqrestore(&dump_list_lock, flags);
1534 synchronize_rcu();
1533 1535
1534 return err; 1536 return err;
1535} 1537}
1536EXPORT_SYMBOL_GPL(kmsg_dump_unregister); 1538EXPORT_SYMBOL_GPL(kmsg_dump_unregister);
1537 1539
1538static const char * const kmsg_reasons[] = {
1539 [KMSG_DUMP_OOPS] = "oops",
1540 [KMSG_DUMP_PANIC] = "panic",
1541 [KMSG_DUMP_KEXEC] = "kexec",
1542};
1543
1544static const char *kmsg_to_str(enum kmsg_dump_reason reason)
1545{
1546 if (reason >= ARRAY_SIZE(kmsg_reasons) || reason < 0)
1547 return "unknown";
1548
1549 return kmsg_reasons[reason];
1550}
1551
1552/** 1540/**
1553 * kmsg_dump - dump kernel log to kernel message dumpers. 1541 * kmsg_dump - dump kernel log to kernel message dumpers.
1554 * @reason: the reason (oops, panic etc) for dumping 1542 * @reason: the reason (oops, panic etc) for dumping
@@ -1587,13 +1575,9 @@ void kmsg_dump(enum kmsg_dump_reason reason)
1587 l2 = chars; 1575 l2 = chars;
1588 } 1576 }
1589 1577
1590 if (!spin_trylock_irqsave(&dump_list_lock, flags)) { 1578 rcu_read_lock();
1591 printk(KERN_ERR "dump_kmsg: dump list lock is held during %s, skipping dump\n", 1579 list_for_each_entry_rcu(dumper, &dump_list, list)
1592 kmsg_to_str(reason));
1593 return;
1594 }
1595 list_for_each_entry(dumper, &dump_list, list)
1596 dumper->dump(dumper, reason, s1, l1, s2, l2); 1580 dumper->dump(dumper, reason, s1, l1, s2, l2);
1597 spin_unlock_irqrestore(&dump_list_lock, flags); 1581 rcu_read_unlock();
1598} 1582}
1599#endif 1583#endif
diff --git a/kernel/sched.c b/kernel/sched.c
index a0eb0941fa84..ea3e5eff3878 100644
--- a/kernel/sched.c
+++ b/kernel/sched.c
@@ -2505,7 +2505,7 @@ out:
2505 * try_to_wake_up_local - try to wake up a local task with rq lock held 2505 * try_to_wake_up_local - try to wake up a local task with rq lock held
2506 * @p: the thread to be awakened 2506 * @p: the thread to be awakened
2507 * 2507 *
2508 * Put @p on the run-queue if it's not alredy there. The caller must 2508 * Put @p on the run-queue if it's not already there. The caller must
2509 * ensure that this_rq() is locked, @p is bound to this_rq() and not 2509 * ensure that this_rq() is locked, @p is bound to this_rq() and not
2510 * the current task. this_rq() stays locked over invocation. 2510 * the current task. this_rq() stays locked over invocation.
2511 */ 2511 */
diff --git a/kernel/smp.c b/kernel/smp.c
index 12ed8b013e2d..4ec30e069987 100644
--- a/kernel/smp.c
+++ b/kernel/smp.c
@@ -13,6 +13,7 @@
13#include <linux/smp.h> 13#include <linux/smp.h>
14#include <linux/cpu.h> 14#include <linux/cpu.h>
15 15
16#ifdef CONFIG_USE_GENERIC_SMP_HELPERS
16static struct { 17static struct {
17 struct list_head queue; 18 struct list_head queue;
18 raw_spinlock_t lock; 19 raw_spinlock_t lock;
@@ -529,3 +530,21 @@ void ipi_call_unlock_irq(void)
529{ 530{
530 raw_spin_unlock_irq(&call_function.lock); 531 raw_spin_unlock_irq(&call_function.lock);
531} 532}
533#endif /* USE_GENERIC_SMP_HELPERS */
534
535/*
536 * Call a function on all processors
537 */
538int on_each_cpu(void (*func) (void *info), void *info, int wait)
539{
540 int ret = 0;
541
542 preempt_disable();
543 ret = smp_call_function(func, info, wait);
544 local_irq_disable();
545 func(info);
546 local_irq_enable();
547 preempt_enable();
548 return ret;
549}
550EXPORT_SYMBOL(on_each_cpu);
diff --git a/kernel/softirq.c b/kernel/softirq.c
index 0823778f87fc..68eb5efec388 100644
--- a/kernel/softirq.c
+++ b/kernel/softirq.c
@@ -885,25 +885,6 @@ static __init int spawn_ksoftirqd(void)
885} 885}
886early_initcall(spawn_ksoftirqd); 886early_initcall(spawn_ksoftirqd);
887 887
888#ifdef CONFIG_SMP
889/*
890 * Call a function on all processors
891 */
892int on_each_cpu(void (*func) (void *info), void *info, int wait)
893{
894 int ret = 0;
895
896 preempt_disable();
897 ret = smp_call_function(func, info, wait);
898 local_irq_disable();
899 func(info);
900 local_irq_enable();
901 preempt_enable();
902 return ret;
903}
904EXPORT_SYMBOL(on_each_cpu);
905#endif
906
907/* 888/*
908 * [ These __weak aliases are kept in a separate compilation unit, so that 889 * [ These __weak aliases are kept in a separate compilation unit, so that
909 * GCC does not inline them incorrectly. ] 890 * GCC does not inline them incorrectly. ]
diff --git a/kernel/sys.c b/kernel/sys.c
index 2745dcdb6c6c..31b71a276b40 100644
--- a/kernel/sys.c
+++ b/kernel/sys.c
@@ -43,6 +43,8 @@
43#include <linux/kprobes.h> 43#include <linux/kprobes.h>
44#include <linux/user_namespace.h> 44#include <linux/user_namespace.h>
45 45
46#include <linux/kmsg_dump.h>
47
46#include <asm/uaccess.h> 48#include <asm/uaccess.h>
47#include <asm/io.h> 49#include <asm/io.h>
48#include <asm/unistd.h> 50#include <asm/unistd.h>
@@ -285,6 +287,7 @@ out_unlock:
285 */ 287 */
286void emergency_restart(void) 288void emergency_restart(void)
287{ 289{
290 kmsg_dump(KMSG_DUMP_EMERG);
288 machine_emergency_restart(); 291 machine_emergency_restart();
289} 292}
290EXPORT_SYMBOL_GPL(emergency_restart); 293EXPORT_SYMBOL_GPL(emergency_restart);
@@ -312,6 +315,7 @@ void kernel_restart(char *cmd)
312 printk(KERN_EMERG "Restarting system.\n"); 315 printk(KERN_EMERG "Restarting system.\n");
313 else 316 else
314 printk(KERN_EMERG "Restarting system with command '%s'.\n", cmd); 317 printk(KERN_EMERG "Restarting system with command '%s'.\n", cmd);
318 kmsg_dump(KMSG_DUMP_RESTART);
315 machine_restart(cmd); 319 machine_restart(cmd);
316} 320}
317EXPORT_SYMBOL_GPL(kernel_restart); 321EXPORT_SYMBOL_GPL(kernel_restart);
@@ -333,6 +337,7 @@ void kernel_halt(void)
333 kernel_shutdown_prepare(SYSTEM_HALT); 337 kernel_shutdown_prepare(SYSTEM_HALT);
334 sysdev_shutdown(); 338 sysdev_shutdown();
335 printk(KERN_EMERG "System halted.\n"); 339 printk(KERN_EMERG "System halted.\n");
340 kmsg_dump(KMSG_DUMP_HALT);
336 machine_halt(); 341 machine_halt();
337} 342}
338 343
@@ -351,6 +356,7 @@ void kernel_power_off(void)
351 disable_nonboot_cpus(); 356 disable_nonboot_cpus();
352 sysdev_shutdown(); 357 sysdev_shutdown();
353 printk(KERN_EMERG "Power down.\n"); 358 printk(KERN_EMERG "Power down.\n");
359 kmsg_dump(KMSG_DUMP_POWEROFF);
354 machine_power_off(); 360 machine_power_off();
355} 361}
356EXPORT_SYMBOL_GPL(kernel_power_off); 362EXPORT_SYMBOL_GPL(kernel_power_off);
diff --git a/kernel/sysctl.c b/kernel/sysctl.c
index ae5cbb1e3ced..bc86bb32e126 100644
--- a/kernel/sysctl.c
+++ b/kernel/sysctl.c
@@ -24,6 +24,7 @@
24#include <linux/slab.h> 24#include <linux/slab.h>
25#include <linux/sysctl.h> 25#include <linux/sysctl.h>
26#include <linux/signal.h> 26#include <linux/signal.h>
27#include <linux/printk.h>
27#include <linux/proc_fs.h> 28#include <linux/proc_fs.h>
28#include <linux/security.h> 29#include <linux/security.h>
29#include <linux/ctype.h> 30#include <linux/ctype.h>
@@ -245,10 +246,6 @@ static struct ctl_table root_table[] = {
245 .mode = 0555, 246 .mode = 0555,
246 .child = dev_table, 247 .child = dev_table,
247 }, 248 },
248/*
249 * NOTE: do not add new entries to this table unless you have read
250 * Documentation/sysctl/ctl_unnumbered.txt
251 */
252 { } 249 { }
253}; 250};
254 251
@@ -710,6 +707,15 @@ static struct ctl_table kern_table[] = {
710 .extra1 = &zero, 707 .extra1 = &zero,
711 .extra2 = &one, 708 .extra2 = &one,
712 }, 709 },
710 {
711 .procname = "kptr_restrict",
712 .data = &kptr_restrict,
713 .maxlen = sizeof(int),
714 .mode = 0644,
715 .proc_handler = proc_dointvec_minmax,
716 .extra1 = &zero,
717 .extra2 = &two,
718 },
713#endif 719#endif
714 { 720 {
715 .procname = "ngroups_max", 721 .procname = "ngroups_max",
@@ -962,10 +968,6 @@ static struct ctl_table kern_table[] = {
962 .proc_handler = proc_dointvec, 968 .proc_handler = proc_dointvec,
963 }, 969 },
964#endif 970#endif
965/*
966 * NOTE: do not add new entries to this table unless you have read
967 * Documentation/sysctl/ctl_unnumbered.txt
968 */
969 { } 971 { }
970}; 972};
971 973
@@ -1326,11 +1328,6 @@ static struct ctl_table vm_table[] = {
1326 .extra2 = &one, 1328 .extra2 = &one,
1327 }, 1329 },
1328#endif 1330#endif
1329
1330/*
1331 * NOTE: do not add new entries to this table unless you have read
1332 * Documentation/sysctl/ctl_unnumbered.txt
1333 */
1334 { } 1331 { }
1335}; 1332};
1336 1333
@@ -1486,10 +1483,6 @@ static struct ctl_table fs_table[] = {
1486 .proc_handler = &pipe_proc_fn, 1483 .proc_handler = &pipe_proc_fn,
1487 .extra1 = &pipe_min_size, 1484 .extra1 = &pipe_min_size,
1488 }, 1485 },
1489/*
1490 * NOTE: do not add new entries to this table unless you have read
1491 * Documentation/sysctl/ctl_unnumbered.txt
1492 */
1493 { } 1486 { }
1494}; 1487};
1495 1488
@@ -2899,7 +2892,7 @@ int proc_do_large_bitmap(struct ctl_table *table, int write,
2899 } 2892 }
2900} 2893}
2901 2894
2902#else /* CONFIG_PROC_FS */ 2895#else /* CONFIG_PROC_SYSCTL */
2903 2896
2904int proc_dostring(struct ctl_table *table, int write, 2897int proc_dostring(struct ctl_table *table, int write,
2905 void __user *buffer, size_t *lenp, loff_t *ppos) 2898 void __user *buffer, size_t *lenp, loff_t *ppos)
@@ -2951,7 +2944,7 @@ int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
2951} 2944}
2952 2945
2953 2946
2954#endif /* CONFIG_PROC_FS */ 2947#endif /* CONFIG_PROC_SYSCTL */
2955 2948
2956/* 2949/*
2957 * No sense putting this after each symbol definition, twice, 2950 * No sense putting this after each symbol definition, twice,
diff --git a/kernel/sysctl_binary.c b/kernel/sysctl_binary.c
index 4b2545a136ff..b875bedf7c9a 100644
--- a/kernel/sysctl_binary.c
+++ b/kernel/sysctl_binary.c
@@ -1192,7 +1192,7 @@ static ssize_t bin_dn_node_address(struct file *file,
1192 1192
1193 buf[result] = '\0'; 1193 buf[result] = '\0';
1194 1194
1195 /* Convert the decnet addresss to binary */ 1195 /* Convert the decnet address to binary */
1196 result = -EIO; 1196 result = -EIO;
1197 nodep = strchr(buf, '.') + 1; 1197 nodep = strchr(buf, '.') + 1;
1198 if (!nodep) 1198 if (!nodep)
diff --git a/kernel/taskstats.c b/kernel/taskstats.c
index 69691eb4b715..3971c6b9d58d 100644
--- a/kernel/taskstats.c
+++ b/kernel/taskstats.c
@@ -348,7 +348,7 @@ static int parse(struct nlattr *na, struct cpumask *mask)
348 return ret; 348 return ret;
349} 349}
350 350
351#ifdef CONFIG_IA64 351#if defined(CONFIG_64BIT) && !defined(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS)
352#define TASKSTATS_NEEDS_PADDING 1 352#define TASKSTATS_NEEDS_PADDING 1
353#endif 353#endif
354 354
diff --git a/kernel/time.c b/kernel/time.c
index ba9b338d1835..32174359576f 100644
--- a/kernel/time.c
+++ b/kernel/time.c
@@ -238,7 +238,7 @@ EXPORT_SYMBOL(current_fs_time);
238 * Avoid unnecessary multiplications/divisions in the 238 * Avoid unnecessary multiplications/divisions in the
239 * two most common HZ cases: 239 * two most common HZ cases:
240 */ 240 */
241unsigned int inline jiffies_to_msecs(const unsigned long j) 241inline unsigned int jiffies_to_msecs(const unsigned long j)
242{ 242{
243#if HZ <= MSEC_PER_SEC && !(MSEC_PER_SEC % HZ) 243#if HZ <= MSEC_PER_SEC && !(MSEC_PER_SEC % HZ)
244 return (MSEC_PER_SEC / HZ) * j; 244 return (MSEC_PER_SEC / HZ) * j;
@@ -254,7 +254,7 @@ unsigned int inline jiffies_to_msecs(const unsigned long j)
254} 254}
255EXPORT_SYMBOL(jiffies_to_msecs); 255EXPORT_SYMBOL(jiffies_to_msecs);
256 256
257unsigned int inline jiffies_to_usecs(const unsigned long j) 257inline unsigned int jiffies_to_usecs(const unsigned long j)
258{ 258{
259#if HZ <= USEC_PER_SEC && !(USEC_PER_SEC % HZ) 259#if HZ <= USEC_PER_SEC && !(USEC_PER_SEC % HZ)
260 return (USEC_PER_SEC / HZ) * j; 260 return (USEC_PER_SEC / HZ) * j;
diff --git a/kernel/time/clocksource.c b/kernel/time/clocksource.c
index df140cd3ea47..c50a034de30f 100644
--- a/kernel/time/clocksource.c
+++ b/kernel/time/clocksource.c
@@ -679,7 +679,7 @@ EXPORT_SYMBOL_GPL(__clocksource_updatefreq_scale);
679int __clocksource_register_scale(struct clocksource *cs, u32 scale, u32 freq) 679int __clocksource_register_scale(struct clocksource *cs, u32 scale, u32 freq)
680{ 680{
681 681
682 /* Intialize mult/shift and max_idle_ns */ 682 /* Initialize mult/shift and max_idle_ns */
683 __clocksource_updatefreq_scale(cs, scale, freq); 683 __clocksource_updatefreq_scale(cs, scale, freq);
684 684
685 /* Add clocksource to the clcoksource list */ 685 /* Add clocksource to the clcoksource list */
diff --git a/kernel/time/ntp.c b/kernel/time/ntp.c
index d2321891538f..5c00242fa921 100644
--- a/kernel/time/ntp.c
+++ b/kernel/time/ntp.c
@@ -14,6 +14,7 @@
14#include <linux/timex.h> 14#include <linux/timex.h>
15#include <linux/time.h> 15#include <linux/time.h>
16#include <linux/mm.h> 16#include <linux/mm.h>
17#include <linux/module.h>
17 18
18/* 19/*
19 * NTP timekeeping variables: 20 * NTP timekeeping variables:
@@ -74,6 +75,162 @@ static long time_adjust;
74/* constant (boot-param configurable) NTP tick adjustment (upscaled) */ 75/* constant (boot-param configurable) NTP tick adjustment (upscaled) */
75static s64 ntp_tick_adj; 76static s64 ntp_tick_adj;
76 77
78#ifdef CONFIG_NTP_PPS
79
80/*
81 * The following variables are used when a pulse-per-second (PPS) signal
82 * is available. They establish the engineering parameters of the clock
83 * discipline loop when controlled by the PPS signal.
84 */
85#define PPS_VALID 10 /* PPS signal watchdog max (s) */
86#define PPS_POPCORN 4 /* popcorn spike threshold (shift) */
87#define PPS_INTMIN 2 /* min freq interval (s) (shift) */
88#define PPS_INTMAX 8 /* max freq interval (s) (shift) */
89#define PPS_INTCOUNT 4 /* number of consecutive good intervals to
90 increase pps_shift or consecutive bad
91 intervals to decrease it */
92#define PPS_MAXWANDER 100000 /* max PPS freq wander (ns/s) */
93
94static int pps_valid; /* signal watchdog counter */
95static long pps_tf[3]; /* phase median filter */
96static long pps_jitter; /* current jitter (ns) */
97static struct timespec pps_fbase; /* beginning of the last freq interval */
98static int pps_shift; /* current interval duration (s) (shift) */
99static int pps_intcnt; /* interval counter */
100static s64 pps_freq; /* frequency offset (scaled ns/s) */
101static long pps_stabil; /* current stability (scaled ns/s) */
102
103/*
104 * PPS signal quality monitors
105 */
106static long pps_calcnt; /* calibration intervals */
107static long pps_jitcnt; /* jitter limit exceeded */
108static long pps_stbcnt; /* stability limit exceeded */
109static long pps_errcnt; /* calibration errors */
110
111
112/* PPS kernel consumer compensates the whole phase error immediately.
113 * Otherwise, reduce the offset by a fixed factor times the time constant.
114 */
115static inline s64 ntp_offset_chunk(s64 offset)
116{
117 if (time_status & STA_PPSTIME && time_status & STA_PPSSIGNAL)
118 return offset;
119 else
120 return shift_right(offset, SHIFT_PLL + time_constant);
121}
122
123static inline void pps_reset_freq_interval(void)
124{
125 /* the PPS calibration interval may end
126 surprisingly early */
127 pps_shift = PPS_INTMIN;
128 pps_intcnt = 0;
129}
130
131/**
132 * pps_clear - Clears the PPS state variables
133 *
134 * Must be called while holding a write on the xtime_lock
135 */
136static inline void pps_clear(void)
137{
138 pps_reset_freq_interval();
139 pps_tf[0] = 0;
140 pps_tf[1] = 0;
141 pps_tf[2] = 0;
142 pps_fbase.tv_sec = pps_fbase.tv_nsec = 0;
143 pps_freq = 0;
144}
145
146/* Decrease pps_valid to indicate that another second has passed since
147 * the last PPS signal. When it reaches 0, indicate that PPS signal is
148 * missing.
149 *
150 * Must be called while holding a write on the xtime_lock
151 */
152static inline void pps_dec_valid(void)
153{
154 if (pps_valid > 0)
155 pps_valid--;
156 else {
157 time_status &= ~(STA_PPSSIGNAL | STA_PPSJITTER |
158 STA_PPSWANDER | STA_PPSERROR);
159 pps_clear();
160 }
161}
162
163static inline void pps_set_freq(s64 freq)
164{
165 pps_freq = freq;
166}
167
168static inline int is_error_status(int status)
169{
170 return (time_status & (STA_UNSYNC|STA_CLOCKERR))
171 /* PPS signal lost when either PPS time or
172 * PPS frequency synchronization requested
173 */
174 || ((time_status & (STA_PPSFREQ|STA_PPSTIME))
175 && !(time_status & STA_PPSSIGNAL))
176 /* PPS jitter exceeded when
177 * PPS time synchronization requested */
178 || ((time_status & (STA_PPSTIME|STA_PPSJITTER))
179 == (STA_PPSTIME|STA_PPSJITTER))
180 /* PPS wander exceeded or calibration error when
181 * PPS frequency synchronization requested
182 */
183 || ((time_status & STA_PPSFREQ)
184 && (time_status & (STA_PPSWANDER|STA_PPSERROR)));
185}
186
187static inline void pps_fill_timex(struct timex *txc)
188{
189 txc->ppsfreq = shift_right((pps_freq >> PPM_SCALE_INV_SHIFT) *
190 PPM_SCALE_INV, NTP_SCALE_SHIFT);
191 txc->jitter = pps_jitter;
192 if (!(time_status & STA_NANO))
193 txc->jitter /= NSEC_PER_USEC;
194 txc->shift = pps_shift;
195 txc->stabil = pps_stabil;
196 txc->jitcnt = pps_jitcnt;
197 txc->calcnt = pps_calcnt;
198 txc->errcnt = pps_errcnt;
199 txc->stbcnt = pps_stbcnt;
200}
201
202#else /* !CONFIG_NTP_PPS */
203
204static inline s64 ntp_offset_chunk(s64 offset)
205{
206 return shift_right(offset, SHIFT_PLL + time_constant);
207}
208
209static inline void pps_reset_freq_interval(void) {}
210static inline void pps_clear(void) {}
211static inline void pps_dec_valid(void) {}
212static inline void pps_set_freq(s64 freq) {}
213
214static inline int is_error_status(int status)
215{
216 return status & (STA_UNSYNC|STA_CLOCKERR);
217}
218
219static inline void pps_fill_timex(struct timex *txc)
220{
221 /* PPS is not implemented, so these are zero */
222 txc->ppsfreq = 0;
223 txc->jitter = 0;
224 txc->shift = 0;
225 txc->stabil = 0;
226 txc->jitcnt = 0;
227 txc->calcnt = 0;
228 txc->errcnt = 0;
229 txc->stbcnt = 0;
230}
231
232#endif /* CONFIG_NTP_PPS */
233
77/* 234/*
78 * NTP methods: 235 * NTP methods:
79 */ 236 */
@@ -185,6 +342,9 @@ void ntp_clear(void)
185 342
186 tick_length = tick_length_base; 343 tick_length = tick_length_base;
187 time_offset = 0; 344 time_offset = 0;
345
346 /* Clear PPS state variables */
347 pps_clear();
188} 348}
189 349
190/* 350/*
@@ -250,16 +410,16 @@ void second_overflow(void)
250 time_status |= STA_UNSYNC; 410 time_status |= STA_UNSYNC;
251 } 411 }
252 412
253 /* 413 /* Compute the phase adjustment for the next second */
254 * Compute the phase adjustment for the next second. The offset is
255 * reduced by a fixed factor times the time constant.
256 */
257 tick_length = tick_length_base; 414 tick_length = tick_length_base;
258 415
259 delta = shift_right(time_offset, SHIFT_PLL + time_constant); 416 delta = ntp_offset_chunk(time_offset);
260 time_offset -= delta; 417 time_offset -= delta;
261 tick_length += delta; 418 tick_length += delta;
262 419
420 /* Check PPS signal */
421 pps_dec_valid();
422
263 if (!time_adjust) 423 if (!time_adjust)
264 return; 424 return;
265 425
@@ -369,6 +529,8 @@ static inline void process_adj_status(struct timex *txc, struct timespec *ts)
369 if ((time_status & STA_PLL) && !(txc->status & STA_PLL)) { 529 if ((time_status & STA_PLL) && !(txc->status & STA_PLL)) {
370 time_state = TIME_OK; 530 time_state = TIME_OK;
371 time_status = STA_UNSYNC; 531 time_status = STA_UNSYNC;
532 /* restart PPS frequency calibration */
533 pps_reset_freq_interval();
372 } 534 }
373 535
374 /* 536 /*
@@ -418,6 +580,8 @@ static inline void process_adjtimex_modes(struct timex *txc, struct timespec *ts
418 time_freq = txc->freq * PPM_SCALE; 580 time_freq = txc->freq * PPM_SCALE;
419 time_freq = min(time_freq, MAXFREQ_SCALED); 581 time_freq = min(time_freq, MAXFREQ_SCALED);
420 time_freq = max(time_freq, -MAXFREQ_SCALED); 582 time_freq = max(time_freq, -MAXFREQ_SCALED);
583 /* update pps_freq */
584 pps_set_freq(time_freq);
421 } 585 }
422 586
423 if (txc->modes & ADJ_MAXERROR) 587 if (txc->modes & ADJ_MAXERROR)
@@ -508,7 +672,8 @@ int do_adjtimex(struct timex *txc)
508 } 672 }
509 673
510 result = time_state; /* mostly `TIME_OK' */ 674 result = time_state; /* mostly `TIME_OK' */
511 if (time_status & (STA_UNSYNC|STA_CLOCKERR)) 675 /* check for errors */
676 if (is_error_status(time_status))
512 result = TIME_ERROR; 677 result = TIME_ERROR;
513 678
514 txc->freq = shift_right((time_freq >> PPM_SCALE_INV_SHIFT) * 679 txc->freq = shift_right((time_freq >> PPM_SCALE_INV_SHIFT) *
@@ -522,15 +687,8 @@ int do_adjtimex(struct timex *txc)
522 txc->tick = tick_usec; 687 txc->tick = tick_usec;
523 txc->tai = time_tai; 688 txc->tai = time_tai;
524 689
525 /* PPS is not implemented, so these are zero */ 690 /* fill PPS status fields */
526 txc->ppsfreq = 0; 691 pps_fill_timex(txc);
527 txc->jitter = 0;
528 txc->shift = 0;
529 txc->stabil = 0;
530 txc->jitcnt = 0;
531 txc->calcnt = 0;
532 txc->errcnt = 0;
533 txc->stbcnt = 0;
534 692
535 write_sequnlock_irq(&xtime_lock); 693 write_sequnlock_irq(&xtime_lock);
536 694
@@ -544,6 +702,243 @@ int do_adjtimex(struct timex *txc)
544 return result; 702 return result;
545} 703}
546 704
705#ifdef CONFIG_NTP_PPS
706
707/* actually struct pps_normtime is good old struct timespec, but it is
708 * semantically different (and it is the reason why it was invented):
709 * pps_normtime.nsec has a range of ( -NSEC_PER_SEC / 2, NSEC_PER_SEC / 2 ]
710 * while timespec.tv_nsec has a range of [0, NSEC_PER_SEC) */
711struct pps_normtime {
712 __kernel_time_t sec; /* seconds */
713 long nsec; /* nanoseconds */
714};
715
716/* normalize the timestamp so that nsec is in the
717 ( -NSEC_PER_SEC / 2, NSEC_PER_SEC / 2 ] interval */
718static inline struct pps_normtime pps_normalize_ts(struct timespec ts)
719{
720 struct pps_normtime norm = {
721 .sec = ts.tv_sec,
722 .nsec = ts.tv_nsec
723 };
724
725 if (norm.nsec > (NSEC_PER_SEC >> 1)) {
726 norm.nsec -= NSEC_PER_SEC;
727 norm.sec++;
728 }
729
730 return norm;
731}
732
733/* get current phase correction and jitter */
734static inline long pps_phase_filter_get(long *jitter)
735{
736 *jitter = pps_tf[0] - pps_tf[1];
737 if (*jitter < 0)
738 *jitter = -*jitter;
739
740 /* TODO: test various filters */
741 return pps_tf[0];
742}
743
744/* add the sample to the phase filter */
745static inline void pps_phase_filter_add(long err)
746{
747 pps_tf[2] = pps_tf[1];
748 pps_tf[1] = pps_tf[0];
749 pps_tf[0] = err;
750}
751
752/* decrease frequency calibration interval length.
753 * It is halved after four consecutive unstable intervals.
754 */
755static inline void pps_dec_freq_interval(void)
756{
757 if (--pps_intcnt <= -PPS_INTCOUNT) {
758 pps_intcnt = -PPS_INTCOUNT;
759 if (pps_shift > PPS_INTMIN) {
760 pps_shift--;
761 pps_intcnt = 0;
762 }
763 }
764}
765
766/* increase frequency calibration interval length.
767 * It is doubled after four consecutive stable intervals.
768 */
769static inline void pps_inc_freq_interval(void)
770{
771 if (++pps_intcnt >= PPS_INTCOUNT) {
772 pps_intcnt = PPS_INTCOUNT;
773 if (pps_shift < PPS_INTMAX) {
774 pps_shift++;
775 pps_intcnt = 0;
776 }
777 }
778}
779
780/* update clock frequency based on MONOTONIC_RAW clock PPS signal
781 * timestamps
782 *
783 * At the end of the calibration interval the difference between the
784 * first and last MONOTONIC_RAW clock timestamps divided by the length
785 * of the interval becomes the frequency update. If the interval was
786 * too long, the data are discarded.
787 * Returns the difference between old and new frequency values.
788 */
789static long hardpps_update_freq(struct pps_normtime freq_norm)
790{
791 long delta, delta_mod;
792 s64 ftemp;
793
794 /* check if the frequency interval was too long */
795 if (freq_norm.sec > (2 << pps_shift)) {
796 time_status |= STA_PPSERROR;
797 pps_errcnt++;
798 pps_dec_freq_interval();
799 pr_err("hardpps: PPSERROR: interval too long - %ld s\n",
800 freq_norm.sec);
801 return 0;
802 }
803
804 /* here the raw frequency offset and wander (stability) is
805 * calculated. If the wander is less than the wander threshold
806 * the interval is increased; otherwise it is decreased.
807 */
808 ftemp = div_s64(((s64)(-freq_norm.nsec)) << NTP_SCALE_SHIFT,
809 freq_norm.sec);
810 delta = shift_right(ftemp - pps_freq, NTP_SCALE_SHIFT);
811 pps_freq = ftemp;
812 if (delta > PPS_MAXWANDER || delta < -PPS_MAXWANDER) {
813 pr_warning("hardpps: PPSWANDER: change=%ld\n", delta);
814 time_status |= STA_PPSWANDER;
815 pps_stbcnt++;
816 pps_dec_freq_interval();
817 } else { /* good sample */
818 pps_inc_freq_interval();
819 }
820
821 /* the stability metric is calculated as the average of recent
822 * frequency changes, but is used only for performance
823 * monitoring
824 */
825 delta_mod = delta;
826 if (delta_mod < 0)
827 delta_mod = -delta_mod;
828 pps_stabil += (div_s64(((s64)delta_mod) <<
829 (NTP_SCALE_SHIFT - SHIFT_USEC),
830 NSEC_PER_USEC) - pps_stabil) >> PPS_INTMIN;
831
832 /* if enabled, the system clock frequency is updated */
833 if ((time_status & STA_PPSFREQ) != 0 &&
834 (time_status & STA_FREQHOLD) == 0) {
835 time_freq = pps_freq;
836 ntp_update_frequency();
837 }
838
839 return delta;
840}
841
842/* correct REALTIME clock phase error against PPS signal */
843static void hardpps_update_phase(long error)
844{
845 long correction = -error;
846 long jitter;
847
848 /* add the sample to the median filter */
849 pps_phase_filter_add(correction);
850 correction = pps_phase_filter_get(&jitter);
851
852 /* Nominal jitter is due to PPS signal noise. If it exceeds the
853 * threshold, the sample is discarded; otherwise, if so enabled,
854 * the time offset is updated.
855 */
856 if (jitter > (pps_jitter << PPS_POPCORN)) {
857 pr_warning("hardpps: PPSJITTER: jitter=%ld, limit=%ld\n",
858 jitter, (pps_jitter << PPS_POPCORN));
859 time_status |= STA_PPSJITTER;
860 pps_jitcnt++;
861 } else if (time_status & STA_PPSTIME) {
862 /* correct the time using the phase offset */
863 time_offset = div_s64(((s64)correction) << NTP_SCALE_SHIFT,
864 NTP_INTERVAL_FREQ);
865 /* cancel running adjtime() */
866 time_adjust = 0;
867 }
868 /* update jitter */
869 pps_jitter += (jitter - pps_jitter) >> PPS_INTMIN;
870}
871
872/*
873 * hardpps() - discipline CPU clock oscillator to external PPS signal
874 *
875 * This routine is called at each PPS signal arrival in order to
876 * discipline the CPU clock oscillator to the PPS signal. It takes two
877 * parameters: REALTIME and MONOTONIC_RAW clock timestamps. The former
878 * is used to correct clock phase error and the latter is used to
879 * correct the frequency.
880 *
881 * This code is based on David Mills's reference nanokernel
882 * implementation. It was mostly rewritten but keeps the same idea.
883 */
884void hardpps(const struct timespec *phase_ts, const struct timespec *raw_ts)
885{
886 struct pps_normtime pts_norm, freq_norm;
887 unsigned long flags;
888
889 pts_norm = pps_normalize_ts(*phase_ts);
890
891 write_seqlock_irqsave(&xtime_lock, flags);
892
893 /* clear the error bits, they will be set again if needed */
894 time_status &= ~(STA_PPSJITTER | STA_PPSWANDER | STA_PPSERROR);
895
896 /* indicate signal presence */
897 time_status |= STA_PPSSIGNAL;
898 pps_valid = PPS_VALID;
899
900 /* when called for the first time,
901 * just start the frequency interval */
902 if (unlikely(pps_fbase.tv_sec == 0)) {
903 pps_fbase = *raw_ts;
904 write_sequnlock_irqrestore(&xtime_lock, flags);
905 return;
906 }
907
908 /* ok, now we have a base for frequency calculation */
909 freq_norm = pps_normalize_ts(timespec_sub(*raw_ts, pps_fbase));
910
911 /* check that the signal is in the range
912 * [1s - MAXFREQ us, 1s + MAXFREQ us], otherwise reject it */
913 if ((freq_norm.sec == 0) ||
914 (freq_norm.nsec > MAXFREQ * freq_norm.sec) ||
915 (freq_norm.nsec < -MAXFREQ * freq_norm.sec)) {
916 time_status |= STA_PPSJITTER;
917 /* restart the frequency calibration interval */
918 pps_fbase = *raw_ts;
919 write_sequnlock_irqrestore(&xtime_lock, flags);
920 pr_err("hardpps: PPSJITTER: bad pulse\n");
921 return;
922 }
923
924 /* signal is ok */
925
926 /* check if the current frequency interval is finished */
927 if (freq_norm.sec >= (1 << pps_shift)) {
928 pps_calcnt++;
929 /* restart the frequency calibration interval */
930 pps_fbase = *raw_ts;
931 hardpps_update_freq(freq_norm);
932 }
933
934 hardpps_update_phase(pts_norm.nsec);
935
936 write_sequnlock_irqrestore(&xtime_lock, flags);
937}
938EXPORT_SYMBOL(hardpps);
939
940#endif /* CONFIG_NTP_PPS */
941
547static int __init ntp_tick_adj_setup(char *str) 942static int __init ntp_tick_adj_setup(char *str)
548{ 943{
549 ntp_tick_adj = simple_strtol(str, NULL, 0); 944 ntp_tick_adj = simple_strtol(str, NULL, 0);
diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
index 5bb86da82003..5536aaf3ba36 100644
--- a/kernel/time/timekeeping.c
+++ b/kernel/time/timekeeping.c
@@ -288,6 +288,49 @@ void ktime_get_ts(struct timespec *ts)
288} 288}
289EXPORT_SYMBOL_GPL(ktime_get_ts); 289EXPORT_SYMBOL_GPL(ktime_get_ts);
290 290
291#ifdef CONFIG_NTP_PPS
292
293/**
294 * getnstime_raw_and_real - get day and raw monotonic time in timespec format
295 * @ts_raw: pointer to the timespec to be set to raw monotonic time
296 * @ts_real: pointer to the timespec to be set to the time of day
297 *
298 * This function reads both the time of day and raw monotonic time at the
299 * same time atomically and stores the resulting timestamps in timespec
300 * format.
301 */
302void getnstime_raw_and_real(struct timespec *ts_raw, struct timespec *ts_real)
303{
304 unsigned long seq;
305 s64 nsecs_raw, nsecs_real;
306
307 WARN_ON_ONCE(timekeeping_suspended);
308
309 do {
310 u32 arch_offset;
311
312 seq = read_seqbegin(&xtime_lock);
313
314 *ts_raw = raw_time;
315 *ts_real = xtime;
316
317 nsecs_raw = timekeeping_get_ns_raw();
318 nsecs_real = timekeeping_get_ns();
319
320 /* If arch requires, add in gettimeoffset() */
321 arch_offset = arch_gettimeoffset();
322 nsecs_raw += arch_offset;
323 nsecs_real += arch_offset;
324
325 } while (read_seqretry(&xtime_lock, seq));
326
327 timespec_add_ns(ts_raw, nsecs_raw);
328 timespec_add_ns(ts_real, nsecs_real);
329}
330EXPORT_SYMBOL(getnstime_raw_and_real);
331
332#endif /* CONFIG_NTP_PPS */
333
291/** 334/**
292 * do_gettimeofday - Returns the time of day in a timeval 335 * do_gettimeofday - Returns the time of day in a timeval
293 * @tv: pointer to the timeval to be set 336 * @tv: pointer to the timeval to be set
diff --git a/kernel/trace/trace_entries.h b/kernel/trace/trace_entries.h
index e3dfecaf13e6..6cf223764be8 100644
--- a/kernel/trace/trace_entries.h
+++ b/kernel/trace/trace_entries.h
@@ -53,7 +53,7 @@
53 */ 53 */
54 54
55/* 55/*
56 * Function trace entry - function address and parent function addres: 56 * Function trace entry - function address and parent function address:
57 */ 57 */
58FTRACE_ENTRY(function, ftrace_entry, 58FTRACE_ENTRY(function, ftrace_entry,
59 59
diff --git a/kernel/user_namespace.c b/kernel/user_namespace.c
index 25915832291a..9da289c34f22 100644
--- a/kernel/user_namespace.c
+++ b/kernel/user_namespace.c
@@ -12,6 +12,8 @@
12#include <linux/highuid.h> 12#include <linux/highuid.h>
13#include <linux/cred.h> 13#include <linux/cred.h>
14 14
15static struct kmem_cache *user_ns_cachep __read_mostly;
16
15/* 17/*
16 * Create a new user namespace, deriving the creator from the user in the 18 * Create a new user namespace, deriving the creator from the user in the
17 * passed credentials, and replacing that user with the new root user for the 19 * passed credentials, and replacing that user with the new root user for the
@@ -26,7 +28,7 @@ int create_user_ns(struct cred *new)
26 struct user_struct *root_user; 28 struct user_struct *root_user;
27 int n; 29 int n;
28 30
29 ns = kmalloc(sizeof(struct user_namespace), GFP_KERNEL); 31 ns = kmem_cache_alloc(user_ns_cachep, GFP_KERNEL);
30 if (!ns) 32 if (!ns)
31 return -ENOMEM; 33 return -ENOMEM;
32 34
@@ -38,7 +40,7 @@ int create_user_ns(struct cred *new)
38 /* Alloc new root user. */ 40 /* Alloc new root user. */
39 root_user = alloc_uid(ns, 0); 41 root_user = alloc_uid(ns, 0);
40 if (!root_user) { 42 if (!root_user) {
41 kfree(ns); 43 kmem_cache_free(user_ns_cachep, ns);
42 return -ENOMEM; 44 return -ENOMEM;
43 } 45 }
44 46
@@ -71,7 +73,7 @@ static void free_user_ns_work(struct work_struct *work)
71 struct user_namespace *ns = 73 struct user_namespace *ns =
72 container_of(work, struct user_namespace, destroyer); 74 container_of(work, struct user_namespace, destroyer);
73 free_uid(ns->creator); 75 free_uid(ns->creator);
74 kfree(ns); 76 kmem_cache_free(user_ns_cachep, ns);
75} 77}
76 78
77void free_user_ns(struct kref *kref) 79void free_user_ns(struct kref *kref)
@@ -126,3 +128,10 @@ gid_t user_ns_map_gid(struct user_namespace *to, const struct cred *cred, gid_t
126 /* No useful relationship so no mapping */ 128 /* No useful relationship so no mapping */
127 return overflowgid; 129 return overflowgid;
128} 130}
131
132static __init int user_namespaces_init(void)
133{
134 user_ns_cachep = KMEM_CACHE(user_namespace, SLAB_PANIC);
135 return 0;
136}
137module_init(user_namespaces_init);
diff --git a/lib/Kconfig b/lib/Kconfig
index 3116aa631af6..0ee67e08ad3e 100644
--- a/lib/Kconfig
+++ b/lib/Kconfig
@@ -106,6 +106,8 @@ config LZO_COMPRESS
106config LZO_DECOMPRESS 106config LZO_DECOMPRESS
107 tristate 107 tristate
108 108
109source "lib/xz/Kconfig"
110
109# 111#
110# These all provide a common interface (hence the apparent duplication with 112# These all provide a common interface (hence the apparent duplication with
111# ZLIB_INFLATE; DECOMPRESS_GZIP is just a wrapper.) 113# ZLIB_INFLATE; DECOMPRESS_GZIP is just a wrapper.)
@@ -120,6 +122,10 @@ config DECOMPRESS_BZIP2
120config DECOMPRESS_LZMA 122config DECOMPRESS_LZMA
121 tristate 123 tristate
122 124
125config DECOMPRESS_XZ
126 select XZ_DEC
127 tristate
128
123config DECOMPRESS_LZO 129config DECOMPRESS_LZO
124 select LZO_DECOMPRESS 130 select LZO_DECOMPRESS
125 tristate 131 tristate
diff --git a/lib/Makefile b/lib/Makefile
index d7b6e30a3a1e..cbb774f7d41d 100644
--- a/lib/Makefile
+++ b/lib/Makefile
@@ -12,7 +12,7 @@ lib-y := ctype.o string.o vsprintf.o cmdline.o \
12 idr.o int_sqrt.o extable.o prio_tree.o \ 12 idr.o int_sqrt.o extable.o prio_tree.o \
13 sha1.o irq_regs.o reciprocal_div.o argv_split.o \ 13 sha1.o irq_regs.o reciprocal_div.o argv_split.o \
14 proportions.o prio_heap.o ratelimit.o show_mem.o \ 14 proportions.o prio_heap.o ratelimit.o show_mem.o \
15 is_single_threaded.o plist.o decompress.o flex_array.o 15 is_single_threaded.o plist.o decompress.o
16 16
17lib-$(CONFIG_MMU) += ioremap.o 17lib-$(CONFIG_MMU) += ioremap.o
18lib-$(CONFIG_SMP) += cpumask.o 18lib-$(CONFIG_SMP) += cpumask.o
@@ -21,7 +21,7 @@ lib-y += kobject.o kref.o klist.o
21 21
22obj-y += bcd.o div64.o sort.o parser.o halfmd4.o debug_locks.o random32.o \ 22obj-y += bcd.o div64.o sort.o parser.o halfmd4.o debug_locks.o random32.o \
23 bust_spinlocks.o hexdump.o kasprintf.o bitmap.o scatterlist.o \ 23 bust_spinlocks.o hexdump.o kasprintf.o bitmap.o scatterlist.o \
24 string_helpers.o gcd.o lcm.o list_sort.o uuid.o 24 string_helpers.o gcd.o lcm.o list_sort.o uuid.o flex_array.o
25 25
26ifeq ($(CONFIG_DEBUG_KOBJECT),y) 26ifeq ($(CONFIG_DEBUG_KOBJECT),y)
27CFLAGS_kobject.o += -DDEBUG 27CFLAGS_kobject.o += -DDEBUG
@@ -69,11 +69,13 @@ obj-$(CONFIG_ZLIB_DEFLATE) += zlib_deflate/
69obj-$(CONFIG_REED_SOLOMON) += reed_solomon/ 69obj-$(CONFIG_REED_SOLOMON) += reed_solomon/
70obj-$(CONFIG_LZO_COMPRESS) += lzo/ 70obj-$(CONFIG_LZO_COMPRESS) += lzo/
71obj-$(CONFIG_LZO_DECOMPRESS) += lzo/ 71obj-$(CONFIG_LZO_DECOMPRESS) += lzo/
72obj-$(CONFIG_XZ_DEC) += xz/
72obj-$(CONFIG_RAID6_PQ) += raid6/ 73obj-$(CONFIG_RAID6_PQ) += raid6/
73 74
74lib-$(CONFIG_DECOMPRESS_GZIP) += decompress_inflate.o 75lib-$(CONFIG_DECOMPRESS_GZIP) += decompress_inflate.o
75lib-$(CONFIG_DECOMPRESS_BZIP2) += decompress_bunzip2.o 76lib-$(CONFIG_DECOMPRESS_BZIP2) += decompress_bunzip2.o
76lib-$(CONFIG_DECOMPRESS_LZMA) += decompress_unlzma.o 77lib-$(CONFIG_DECOMPRESS_LZMA) += decompress_unlzma.o
78lib-$(CONFIG_DECOMPRESS_XZ) += decompress_unxz.o
77lib-$(CONFIG_DECOMPRESS_LZO) += decompress_unlzo.o 79lib-$(CONFIG_DECOMPRESS_LZO) += decompress_unlzo.o
78 80
79obj-$(CONFIG_TEXTSEARCH) += textsearch.o 81obj-$(CONFIG_TEXTSEARCH) += textsearch.o
diff --git a/lib/decompress.c b/lib/decompress.c
index a7606815541f..3d766b7f60ab 100644
--- a/lib/decompress.c
+++ b/lib/decompress.c
@@ -8,6 +8,7 @@
8 8
9#include <linux/decompress/bunzip2.h> 9#include <linux/decompress/bunzip2.h>
10#include <linux/decompress/unlzma.h> 10#include <linux/decompress/unlzma.h>
11#include <linux/decompress/unxz.h>
11#include <linux/decompress/inflate.h> 12#include <linux/decompress/inflate.h>
12#include <linux/decompress/unlzo.h> 13#include <linux/decompress/unlzo.h>
13 14
@@ -23,6 +24,9 @@
23#ifndef CONFIG_DECOMPRESS_LZMA 24#ifndef CONFIG_DECOMPRESS_LZMA
24# define unlzma NULL 25# define unlzma NULL
25#endif 26#endif
27#ifndef CONFIG_DECOMPRESS_XZ
28# define unxz NULL
29#endif
26#ifndef CONFIG_DECOMPRESS_LZO 30#ifndef CONFIG_DECOMPRESS_LZO
27# define unlzo NULL 31# define unlzo NULL
28#endif 32#endif
@@ -36,6 +40,7 @@ static const struct compress_format {
36 { {037, 0236}, "gzip", gunzip }, 40 { {037, 0236}, "gzip", gunzip },
37 { {0x42, 0x5a}, "bzip2", bunzip2 }, 41 { {0x42, 0x5a}, "bzip2", bunzip2 },
38 { {0x5d, 0x00}, "lzma", unlzma }, 42 { {0x5d, 0x00}, "lzma", unlzma },
43 { {0xfd, 0x37}, "xz", unxz },
39 { {0x89, 0x4c}, "lzo", unlzo }, 44 { {0x89, 0x4c}, "lzo", unlzo },
40 { {0, 0}, NULL, NULL } 45 { {0, 0}, NULL, NULL }
41}; 46};
diff --git a/lib/decompress_bunzip2.c b/lib/decompress_bunzip2.c
index 81c8bb1cc6aa..a7b80c1d6a0d 100644
--- a/lib/decompress_bunzip2.c
+++ b/lib/decompress_bunzip2.c
@@ -49,7 +49,6 @@
49#define PREBOOT 49#define PREBOOT
50#else 50#else
51#include <linux/decompress/bunzip2.h> 51#include <linux/decompress/bunzip2.h>
52#include <linux/slab.h>
53#endif /* STATIC */ 52#endif /* STATIC */
54 53
55#include <linux/decompress/mm.h> 54#include <linux/decompress/mm.h>
@@ -682,13 +681,12 @@ STATIC int INIT bunzip2(unsigned char *buf, int len,
682 int(*flush)(void*, unsigned int), 681 int(*flush)(void*, unsigned int),
683 unsigned char *outbuf, 682 unsigned char *outbuf,
684 int *pos, 683 int *pos,
685 void(*error_fn)(char *x)) 684 void(*error)(char *x))
686{ 685{
687 struct bunzip_data *bd; 686 struct bunzip_data *bd;
688 int i = -1; 687 int i = -1;
689 unsigned char *inbuf; 688 unsigned char *inbuf;
690 689
691 set_error_fn(error_fn);
692 if (flush) 690 if (flush)
693 outbuf = malloc(BZIP2_IOBUF_SIZE); 691 outbuf = malloc(BZIP2_IOBUF_SIZE);
694 692
@@ -751,8 +749,8 @@ STATIC int INIT decompress(unsigned char *buf, int len,
751 int(*flush)(void*, unsigned int), 749 int(*flush)(void*, unsigned int),
752 unsigned char *outbuf, 750 unsigned char *outbuf,
753 int *pos, 751 int *pos,
754 void(*error_fn)(char *x)) 752 void(*error)(char *x))
755{ 753{
756 return bunzip2(buf, len - 4, fill, flush, outbuf, pos, error_fn); 754 return bunzip2(buf, len - 4, fill, flush, outbuf, pos, error);
757} 755}
758#endif 756#endif
diff --git a/lib/decompress_inflate.c b/lib/decompress_inflate.c
index fc686c7a0a0d..19ff89e34eec 100644
--- a/lib/decompress_inflate.c
+++ b/lib/decompress_inflate.c
@@ -19,7 +19,6 @@
19#include "zlib_inflate/inflate.h" 19#include "zlib_inflate/inflate.h"
20 20
21#include "zlib_inflate/infutil.h" 21#include "zlib_inflate/infutil.h"
22#include <linux/slab.h>
23 22
24#endif /* STATIC */ 23#endif /* STATIC */
25 24
@@ -27,7 +26,7 @@
27 26
28#define GZIP_IOBUF_SIZE (16*1024) 27#define GZIP_IOBUF_SIZE (16*1024)
29 28
30static int nofill(void *buffer, unsigned int len) 29static int INIT nofill(void *buffer, unsigned int len)
31{ 30{
32 return -1; 31 return -1;
33} 32}
@@ -38,13 +37,12 @@ STATIC int INIT gunzip(unsigned char *buf, int len,
38 int(*flush)(void*, unsigned int), 37 int(*flush)(void*, unsigned int),
39 unsigned char *out_buf, 38 unsigned char *out_buf,
40 int *pos, 39 int *pos,
41 void(*error_fn)(char *x)) { 40 void(*error)(char *x)) {
42 u8 *zbuf; 41 u8 *zbuf;
43 struct z_stream_s *strm; 42 struct z_stream_s *strm;
44 int rc; 43 int rc;
45 size_t out_len; 44 size_t out_len;
46 45
47 set_error_fn(error_fn);
48 rc = -1; 46 rc = -1;
49 if (flush) { 47 if (flush) {
50 out_len = 0x8000; /* 32 K */ 48 out_len = 0x8000; /* 32 K */
@@ -100,13 +98,22 @@ STATIC int INIT gunzip(unsigned char *buf, int len,
100 * possible asciz filename) 98 * possible asciz filename)
101 */ 99 */
102 strm->next_in = zbuf + 10; 100 strm->next_in = zbuf + 10;
101 strm->avail_in = len - 10;
103 /* skip over asciz filename */ 102 /* skip over asciz filename */
104 if (zbuf[3] & 0x8) { 103 if (zbuf[3] & 0x8) {
105 while (strm->next_in[0]) 104 do {
106 strm->next_in++; 105 /*
107 strm->next_in++; 106 * If the filename doesn't fit into the buffer,
107 * the file is very probably corrupt. Don't try
108 * to read more data.
109 */
110 if (strm->avail_in == 0) {
111 error("header error");
112 goto gunzip_5;
113 }
114 --strm->avail_in;
115 } while (*strm->next_in++);
108 } 116 }
109 strm->avail_in = len - (strm->next_in - zbuf);
110 117
111 strm->next_out = out_buf; 118 strm->next_out = out_buf;
112 strm->avail_out = out_len; 119 strm->avail_out = out_len;
diff --git a/lib/decompress_unlzma.c b/lib/decompress_unlzma.c
index ca82fde81c8f..476c65af9709 100644
--- a/lib/decompress_unlzma.c
+++ b/lib/decompress_unlzma.c
@@ -33,7 +33,6 @@
33#define PREBOOT 33#define PREBOOT
34#else 34#else
35#include <linux/decompress/unlzma.h> 35#include <linux/decompress/unlzma.h>
36#include <linux/slab.h>
37#endif /* STATIC */ 36#endif /* STATIC */
38 37
39#include <linux/decompress/mm.h> 38#include <linux/decompress/mm.h>
@@ -74,6 +73,7 @@ struct rc {
74 uint32_t code; 73 uint32_t code;
75 uint32_t range; 74 uint32_t range;
76 uint32_t bound; 75 uint32_t bound;
76 void (*error)(char *);
77}; 77};
78 78
79 79
@@ -82,7 +82,7 @@ struct rc {
82#define RC_MODEL_TOTAL_BITS 11 82#define RC_MODEL_TOTAL_BITS 11
83 83
84 84
85static int nofill(void *buffer, unsigned int len) 85static int INIT nofill(void *buffer, unsigned int len)
86{ 86{
87 return -1; 87 return -1;
88} 88}
@@ -92,7 +92,7 @@ static void INIT rc_read(struct rc *rc)
92{ 92{
93 rc->buffer_size = rc->fill((char *)rc->buffer, LZMA_IOBUF_SIZE); 93 rc->buffer_size = rc->fill((char *)rc->buffer, LZMA_IOBUF_SIZE);
94 if (rc->buffer_size <= 0) 94 if (rc->buffer_size <= 0)
95 error("unexpected EOF"); 95 rc->error("unexpected EOF");
96 rc->ptr = rc->buffer; 96 rc->ptr = rc->buffer;
97 rc->buffer_end = rc->buffer + rc->buffer_size; 97 rc->buffer_end = rc->buffer + rc->buffer_size;
98} 98}
@@ -127,12 +127,6 @@ static inline void INIT rc_init_code(struct rc *rc)
127} 127}
128 128
129 129
130/* Called once. TODO: bb_maybe_free() */
131static inline void INIT rc_free(struct rc *rc)
132{
133 free(rc->buffer);
134}
135
136/* Called twice, but one callsite is in inline'd rc_is_bit_0_helper() */ 130/* Called twice, but one callsite is in inline'd rc_is_bit_0_helper() */
137static void INIT rc_do_normalize(struct rc *rc) 131static void INIT rc_do_normalize(struct rc *rc)
138{ 132{
@@ -169,7 +163,7 @@ static inline void INIT rc_update_bit_0(struct rc *rc, uint16_t *p)
169 rc->range = rc->bound; 163 rc->range = rc->bound;
170 *p += ((1 << RC_MODEL_TOTAL_BITS) - *p) >> RC_MOVE_BITS; 164 *p += ((1 << RC_MODEL_TOTAL_BITS) - *p) >> RC_MOVE_BITS;
171} 165}
172static inline void rc_update_bit_1(struct rc *rc, uint16_t *p) 166static inline void INIT rc_update_bit_1(struct rc *rc, uint16_t *p)
173{ 167{
174 rc->range -= rc->bound; 168 rc->range -= rc->bound;
175 rc->code -= rc->bound; 169 rc->code -= rc->bound;
@@ -319,32 +313,38 @@ static inline uint8_t INIT peek_old_byte(struct writer *wr,
319 313
320} 314}
321 315
322static inline void INIT write_byte(struct writer *wr, uint8_t byte) 316static inline int INIT write_byte(struct writer *wr, uint8_t byte)
323{ 317{
324 wr->buffer[wr->buffer_pos++] = wr->previous_byte = byte; 318 wr->buffer[wr->buffer_pos++] = wr->previous_byte = byte;
325 if (wr->flush && wr->buffer_pos == wr->header->dict_size) { 319 if (wr->flush && wr->buffer_pos == wr->header->dict_size) {
326 wr->buffer_pos = 0; 320 wr->buffer_pos = 0;
327 wr->global_pos += wr->header->dict_size; 321 wr->global_pos += wr->header->dict_size;
328 wr->flush((char *)wr->buffer, wr->header->dict_size); 322 if (wr->flush((char *)wr->buffer, wr->header->dict_size)
323 != wr->header->dict_size)
324 return -1;
329 } 325 }
326 return 0;
330} 327}
331 328
332 329
333static inline void INIT copy_byte(struct writer *wr, uint32_t offs) 330static inline int INIT copy_byte(struct writer *wr, uint32_t offs)
334{ 331{
335 write_byte(wr, peek_old_byte(wr, offs)); 332 return write_byte(wr, peek_old_byte(wr, offs));
336} 333}
337 334
338static inline void INIT copy_bytes(struct writer *wr, 335static inline int INIT copy_bytes(struct writer *wr,
339 uint32_t rep0, int len) 336 uint32_t rep0, int len)
340{ 337{
341 do { 338 do {
342 copy_byte(wr, rep0); 339 if (copy_byte(wr, rep0))
340 return -1;
343 len--; 341 len--;
344 } while (len != 0 && wr->buffer_pos < wr->header->dst_size); 342 } while (len != 0 && wr->buffer_pos < wr->header->dst_size);
343
344 return len;
345} 345}
346 346
347static inline void INIT process_bit0(struct writer *wr, struct rc *rc, 347static inline int INIT process_bit0(struct writer *wr, struct rc *rc,
348 struct cstate *cst, uint16_t *p, 348 struct cstate *cst, uint16_t *p,
349 int pos_state, uint16_t *prob, 349 int pos_state, uint16_t *prob,
350 int lc, uint32_t literal_pos_mask) { 350 int lc, uint32_t literal_pos_mask) {
@@ -378,16 +378,17 @@ static inline void INIT process_bit0(struct writer *wr, struct rc *rc,
378 uint16_t *prob_lit = prob + mi; 378 uint16_t *prob_lit = prob + mi;
379 rc_get_bit(rc, prob_lit, &mi); 379 rc_get_bit(rc, prob_lit, &mi);
380 } 380 }
381 write_byte(wr, mi);
382 if (cst->state < 4) 381 if (cst->state < 4)
383 cst->state = 0; 382 cst->state = 0;
384 else if (cst->state < 10) 383 else if (cst->state < 10)
385 cst->state -= 3; 384 cst->state -= 3;
386 else 385 else
387 cst->state -= 6; 386 cst->state -= 6;
387
388 return write_byte(wr, mi);
388} 389}
389 390
390static inline void INIT process_bit1(struct writer *wr, struct rc *rc, 391static inline int INIT process_bit1(struct writer *wr, struct rc *rc,
391 struct cstate *cst, uint16_t *p, 392 struct cstate *cst, uint16_t *p,
392 int pos_state, uint16_t *prob) { 393 int pos_state, uint16_t *prob) {
393 int offset; 394 int offset;
@@ -418,8 +419,7 @@ static inline void INIT process_bit1(struct writer *wr, struct rc *rc,
418 419
419 cst->state = cst->state < LZMA_NUM_LIT_STATES ? 420 cst->state = cst->state < LZMA_NUM_LIT_STATES ?
420 9 : 11; 421 9 : 11;
421 copy_byte(wr, cst->rep0); 422 return copy_byte(wr, cst->rep0);
422 return;
423 } else { 423 } else {
424 rc_update_bit_1(rc, prob); 424 rc_update_bit_1(rc, prob);
425 } 425 }
@@ -521,12 +521,15 @@ static inline void INIT process_bit1(struct writer *wr, struct rc *rc,
521 } else 521 } else
522 cst->rep0 = pos_slot; 522 cst->rep0 = pos_slot;
523 if (++(cst->rep0) == 0) 523 if (++(cst->rep0) == 0)
524 return; 524 return 0;
525 if (cst->rep0 > wr->header->dict_size
526 || cst->rep0 > get_pos(wr))
527 return -1;
525 } 528 }
526 529
527 len += LZMA_MATCH_MIN_LEN; 530 len += LZMA_MATCH_MIN_LEN;
528 531
529 copy_bytes(wr, cst->rep0, len); 532 return copy_bytes(wr, cst->rep0, len);
530} 533}
531 534
532 535
@@ -536,7 +539,7 @@ STATIC inline int INIT unlzma(unsigned char *buf, int in_len,
536 int(*flush)(void*, unsigned int), 539 int(*flush)(void*, unsigned int),
537 unsigned char *output, 540 unsigned char *output,
538 int *posp, 541 int *posp,
539 void(*error_fn)(char *x) 542 void(*error)(char *x)
540 ) 543 )
541{ 544{
542 struct lzma_header header; 545 struct lzma_header header;
@@ -552,7 +555,7 @@ STATIC inline int INIT unlzma(unsigned char *buf, int in_len,
552 unsigned char *inbuf; 555 unsigned char *inbuf;
553 int ret = -1; 556 int ret = -1;
554 557
555 set_error_fn(error_fn); 558 rc.error = error;
556 559
557 if (buf) 560 if (buf)
558 inbuf = buf; 561 inbuf = buf;
@@ -580,8 +583,10 @@ STATIC inline int INIT unlzma(unsigned char *buf, int in_len,
580 ((unsigned char *)&header)[i] = *rc.ptr++; 583 ((unsigned char *)&header)[i] = *rc.ptr++;
581 } 584 }
582 585
583 if (header.pos >= (9 * 5 * 5)) 586 if (header.pos >= (9 * 5 * 5)) {
584 error("bad header"); 587 error("bad header");
588 goto exit_1;
589 }
585 590
586 mi = 0; 591 mi = 0;
587 lc = header.pos; 592 lc = header.pos;
@@ -627,21 +632,29 @@ STATIC inline int INIT unlzma(unsigned char *buf, int in_len,
627 int pos_state = get_pos(&wr) & pos_state_mask; 632 int pos_state = get_pos(&wr) & pos_state_mask;
628 uint16_t *prob = p + LZMA_IS_MATCH + 633 uint16_t *prob = p + LZMA_IS_MATCH +
629 (cst.state << LZMA_NUM_POS_BITS_MAX) + pos_state; 634 (cst.state << LZMA_NUM_POS_BITS_MAX) + pos_state;
630 if (rc_is_bit_0(&rc, prob)) 635 if (rc_is_bit_0(&rc, prob)) {
631 process_bit0(&wr, &rc, &cst, p, pos_state, prob, 636 if (process_bit0(&wr, &rc, &cst, p, pos_state, prob,
632 lc, literal_pos_mask); 637 lc, literal_pos_mask)) {
633 else { 638 error("LZMA data is corrupt");
634 process_bit1(&wr, &rc, &cst, p, pos_state, prob); 639 goto exit_3;
640 }
641 } else {
642 if (process_bit1(&wr, &rc, &cst, p, pos_state, prob)) {
643 error("LZMA data is corrupt");
644 goto exit_3;
645 }
635 if (cst.rep0 == 0) 646 if (cst.rep0 == 0)
636 break; 647 break;
637 } 648 }
649 if (rc.buffer_size <= 0)
650 goto exit_3;
638 } 651 }
639 652
640 if (posp) 653 if (posp)
641 *posp = rc.ptr-rc.buffer; 654 *posp = rc.ptr-rc.buffer;
642 if (wr.flush) 655 if (!wr.flush || wr.flush(wr.buffer, wr.buffer_pos) == wr.buffer_pos)
643 wr.flush(wr.buffer, wr.buffer_pos); 656 ret = 0;
644 ret = 0; 657exit_3:
645 large_free(p); 658 large_free(p);
646exit_2: 659exit_2:
647 if (!output) 660 if (!output)
@@ -659,9 +672,9 @@ STATIC int INIT decompress(unsigned char *buf, int in_len,
659 int(*flush)(void*, unsigned int), 672 int(*flush)(void*, unsigned int),
660 unsigned char *output, 673 unsigned char *output,
661 int *posp, 674 int *posp,
662 void(*error_fn)(char *x) 675 void(*error)(char *x)
663 ) 676 )
664{ 677{
665 return unlzma(buf, in_len - 4, fill, flush, output, posp, error_fn); 678 return unlzma(buf, in_len - 4, fill, flush, output, posp, error);
666} 679}
667#endif 680#endif
diff --git a/lib/decompress_unlzo.c b/lib/decompress_unlzo.c
index bcb3a4bd68ff..5a7a2adf4c4c 100644
--- a/lib/decompress_unlzo.c
+++ b/lib/decompress_unlzo.c
@@ -33,7 +33,6 @@
33#ifdef STATIC 33#ifdef STATIC
34#include "lzo/lzo1x_decompress.c" 34#include "lzo/lzo1x_decompress.c"
35#else 35#else
36#include <linux/slab.h>
37#include <linux/decompress/unlzo.h> 36#include <linux/decompress/unlzo.h>
38#endif 37#endif
39 38
@@ -49,14 +48,25 @@ static const unsigned char lzop_magic[] = {
49 48
50#define LZO_BLOCK_SIZE (256*1024l) 49#define LZO_BLOCK_SIZE (256*1024l)
51#define HEADER_HAS_FILTER 0x00000800L 50#define HEADER_HAS_FILTER 0x00000800L
51#define HEADER_SIZE_MIN (9 + 7 + 4 + 8 + 1 + 4)
52#define HEADER_SIZE_MAX (9 + 7 + 1 + 8 + 8 + 4 + 1 + 255 + 4)
52 53
53STATIC inline int INIT parse_header(u8 *input, u8 *skip) 54STATIC inline int INIT parse_header(u8 *input, int *skip, int in_len)
54{ 55{
55 int l; 56 int l;
56 u8 *parse = input; 57 u8 *parse = input;
58 u8 *end = input + in_len;
57 u8 level = 0; 59 u8 level = 0;
58 u16 version; 60 u16 version;
59 61
62 /*
63 * Check that there's enough input to possibly have a valid header.
64 * Then it is possible to parse several fields until the minimum
65 * size may have been used.
66 */
67 if (in_len < HEADER_SIZE_MIN)
68 return 0;
69
60 /* read magic: 9 first bits */ 70 /* read magic: 9 first bits */
61 for (l = 0; l < 9; l++) { 71 for (l = 0; l < 9; l++) {
62 if (*parse++ != lzop_magic[l]) 72 if (*parse++ != lzop_magic[l])
@@ -74,6 +84,15 @@ STATIC inline int INIT parse_header(u8 *input, u8 *skip)
74 else 84 else
75 parse += 4; /* flags */ 85 parse += 4; /* flags */
76 86
87 /*
88 * At least mode, mtime_low, filename length, and checksum must
89 * be left to be parsed. If also mtime_high is present, it's OK
90 * because the next input buffer check is after reading the
91 * filename length.
92 */
93 if (end - parse < 8 + 1 + 4)
94 return 0;
95
77 /* skip mode and mtime_low */ 96 /* skip mode and mtime_low */
78 parse += 8; 97 parse += 8;
79 if (version >= 0x0940) 98 if (version >= 0x0940)
@@ -81,6 +100,8 @@ STATIC inline int INIT parse_header(u8 *input, u8 *skip)
81 100
82 l = *parse++; 101 l = *parse++;
83 /* don't care about the file name, and skip checksum */ 102 /* don't care about the file name, and skip checksum */
103 if (end - parse < l + 4)
104 return 0;
84 parse += l + 4; 105 parse += l + 4;
85 106
86 *skip = parse - input; 107 *skip = parse - input;
@@ -91,16 +112,15 @@ STATIC inline int INIT unlzo(u8 *input, int in_len,
91 int (*fill) (void *, unsigned int), 112 int (*fill) (void *, unsigned int),
92 int (*flush) (void *, unsigned int), 113 int (*flush) (void *, unsigned int),
93 u8 *output, int *posp, 114 u8 *output, int *posp,
94 void (*error_fn) (char *x)) 115 void (*error) (char *x))
95{ 116{
96 u8 skip = 0, r = 0; 117 u8 r = 0;
118 int skip = 0;
97 u32 src_len, dst_len; 119 u32 src_len, dst_len;
98 size_t tmp; 120 size_t tmp;
99 u8 *in_buf, *in_buf_save, *out_buf; 121 u8 *in_buf, *in_buf_save, *out_buf;
100 int ret = -1; 122 int ret = -1;
101 123
102 set_error_fn(error_fn);
103
104 if (output) { 124 if (output) {
105 out_buf = output; 125 out_buf = output;
106 } else if (!flush) { 126 } else if (!flush) {
@@ -119,8 +139,8 @@ STATIC inline int INIT unlzo(u8 *input, int in_len,
119 goto exit_1; 139 goto exit_1;
120 } else if (input) { 140 } else if (input) {
121 in_buf = input; 141 in_buf = input;
122 } else if (!fill || !posp) { 142 } else if (!fill) {
123 error("NULL input pointer and missing position pointer or fill function"); 143 error("NULL input pointer and missing fill function");
124 goto exit_1; 144 goto exit_1;
125 } else { 145 } else {
126 in_buf = malloc(lzo1x_worst_compress(LZO_BLOCK_SIZE)); 146 in_buf = malloc(lzo1x_worst_compress(LZO_BLOCK_SIZE));
@@ -134,22 +154,47 @@ STATIC inline int INIT unlzo(u8 *input, int in_len,
134 if (posp) 154 if (posp)
135 *posp = 0; 155 *posp = 0;
136 156
137 if (fill) 157 if (fill) {
138 fill(in_buf, lzo1x_worst_compress(LZO_BLOCK_SIZE)); 158 /*
159 * Start from in_buf + HEADER_SIZE_MAX to make it possible
160 * to use memcpy() to copy the unused data to the beginning
161 * of the buffer. This way memmove() isn't needed which
162 * is missing from pre-boot environments of most archs.
163 */
164 in_buf += HEADER_SIZE_MAX;
165 in_len = fill(in_buf, HEADER_SIZE_MAX);
166 }
139 167
140 if (!parse_header(input, &skip)) { 168 if (!parse_header(in_buf, &skip, in_len)) {
141 error("invalid header"); 169 error("invalid header");
142 goto exit_2; 170 goto exit_2;
143 } 171 }
144 in_buf += skip; 172 in_buf += skip;
173 in_len -= skip;
174
175 if (fill) {
176 /* Move the unused data to the beginning of the buffer. */
177 memcpy(in_buf_save, in_buf, in_len);
178 in_buf = in_buf_save;
179 }
145 180
146 if (posp) 181 if (posp)
147 *posp = skip; 182 *posp = skip;
148 183
149 for (;;) { 184 for (;;) {
150 /* read uncompressed block size */ 185 /* read uncompressed block size */
186 if (fill && in_len < 4) {
187 skip = fill(in_buf + in_len, 4 - in_len);
188 if (skip > 0)
189 in_len += skip;
190 }
191 if (in_len < 4) {
192 error("file corrupted");
193 goto exit_2;
194 }
151 dst_len = get_unaligned_be32(in_buf); 195 dst_len = get_unaligned_be32(in_buf);
152 in_buf += 4; 196 in_buf += 4;
197 in_len -= 4;
153 198
154 /* exit if last block */ 199 /* exit if last block */
155 if (dst_len == 0) { 200 if (dst_len == 0) {
@@ -164,8 +209,18 @@ STATIC inline int INIT unlzo(u8 *input, int in_len,
164 } 209 }
165 210
166 /* read compressed block size, and skip block checksum info */ 211 /* read compressed block size, and skip block checksum info */
212 if (fill && in_len < 8) {
213 skip = fill(in_buf + in_len, 8 - in_len);
214 if (skip > 0)
215 in_len += skip;
216 }
217 if (in_len < 8) {
218 error("file corrupted");
219 goto exit_2;
220 }
167 src_len = get_unaligned_be32(in_buf); 221 src_len = get_unaligned_be32(in_buf);
168 in_buf += 8; 222 in_buf += 8;
223 in_len -= 8;
169 224
170 if (src_len <= 0 || src_len > dst_len) { 225 if (src_len <= 0 || src_len > dst_len) {
171 error("file corrupted"); 226 error("file corrupted");
@@ -173,6 +228,15 @@ STATIC inline int INIT unlzo(u8 *input, int in_len,
173 } 228 }
174 229
175 /* decompress */ 230 /* decompress */
231 if (fill && in_len < src_len) {
232 skip = fill(in_buf + in_len, src_len - in_len);
233 if (skip > 0)
234 in_len += skip;
235 }
236 if (in_len < src_len) {
237 error("file corrupted");
238 goto exit_2;
239 }
176 tmp = dst_len; 240 tmp = dst_len;
177 241
178 /* When the input data is not compressed at all, 242 /* When the input data is not compressed at all,
@@ -190,17 +254,26 @@ STATIC inline int INIT unlzo(u8 *input, int in_len,
190 } 254 }
191 } 255 }
192 256
193 if (flush) 257 if (flush && flush(out_buf, dst_len) != dst_len)
194 flush(out_buf, dst_len); 258 goto exit_2;
195 if (output) 259 if (output)
196 out_buf += dst_len; 260 out_buf += dst_len;
197 if (posp) 261 if (posp)
198 *posp += src_len + 12; 262 *posp += src_len + 12;
263
264 in_buf += src_len;
265 in_len -= src_len;
199 if (fill) { 266 if (fill) {
267 /*
268 * If there happens to still be unused data left in
269 * in_buf, move it to the beginning of the buffer.
270 * Use a loop to avoid memmove() dependency.
271 */
272 if (in_len > 0)
273 for (skip = 0; skip < in_len; ++skip)
274 in_buf_save[skip] = in_buf[skip];
200 in_buf = in_buf_save; 275 in_buf = in_buf_save;
201 fill(in_buf, lzo1x_worst_compress(LZO_BLOCK_SIZE)); 276 }
202 } else
203 in_buf += src_len;
204 } 277 }
205 278
206 ret = 0; 279 ret = 0;
diff --git a/lib/decompress_unxz.c b/lib/decompress_unxz.c
new file mode 100644
index 000000000000..cecd23df2b9a
--- /dev/null
+++ b/lib/decompress_unxz.c
@@ -0,0 +1,397 @@
1/*
2 * Wrapper for decompressing XZ-compressed kernel, initramfs, and initrd
3 *
4 * Author: Lasse Collin <lasse.collin@tukaani.org>
5 *
6 * This file has been put into the public domain.
7 * You can do whatever you want with this file.
8 */
9
10/*
11 * Important notes about in-place decompression
12 *
13 * At least on x86, the kernel is decompressed in place: the compressed data
14 * is placed to the end of the output buffer, and the decompressor overwrites
15 * most of the compressed data. There must be enough safety margin to
16 * guarantee that the write position is always behind the read position.
17 *
18 * The safety margin for XZ with LZMA2 or BCJ+LZMA2 is calculated below.
19 * Note that the margin with XZ is bigger than with Deflate (gzip)!
20 *
21 * The worst case for in-place decompression is that the beginning of
22 * the file is compressed extremely well, and the rest of the file is
23 * uncompressible. Thus, we must look for worst-case expansion when the
24 * compressor is encoding uncompressible data.
25 *
26 * The structure of the .xz file in case of a compresed kernel is as follows.
27 * Sizes (as bytes) of the fields are in parenthesis.
28 *
29 * Stream Header (12)
30 * Block Header:
31 * Block Header (8-12)
32 * Compressed Data (N)
33 * Block Padding (0-3)
34 * CRC32 (4)
35 * Index (8-20)
36 * Stream Footer (12)
37 *
38 * Normally there is exactly one Block, but let's assume that there are
39 * 2-4 Blocks just in case. Because Stream Header and also Block Header
40 * of the first Block don't make the decompressor produce any uncompressed
41 * data, we can ignore them from our calculations. Block Headers of possible
42 * additional Blocks have to be taken into account still. With these
43 * assumptions, it is safe to assume that the total header overhead is
44 * less than 128 bytes.
45 *
46 * Compressed Data contains LZMA2 or BCJ+LZMA2 encoded data. Since BCJ
47 * doesn't change the size of the data, it is enough to calculate the
48 * safety margin for LZMA2.
49 *
50 * LZMA2 stores the data in chunks. Each chunk has a header whose size is
51 * a maximum of 6 bytes, but to get round 2^n numbers, let's assume that
52 * the maximum chunk header size is 8 bytes. After the chunk header, there
53 * may be up to 64 KiB of actual payload in the chunk. Often the payload is
54 * quite a bit smaller though; to be safe, let's assume that an average
55 * chunk has only 32 KiB of payload.
56 *
57 * The maximum uncompressed size of the payload is 2 MiB. The minimum
58 * uncompressed size of the payload is in practice never less than the
59 * payload size itself. The LZMA2 format would allow uncompressed size
60 * to be less than the payload size, but no sane compressor creates such
61 * files. LZMA2 supports storing uncompressible data in uncompressed form,
62 * so there's never a need to create payloads whose uncompressed size is
63 * smaller than the compressed size.
64 *
65 * The assumption, that the uncompressed size of the payload is never
66 * smaller than the payload itself, is valid only when talking about
67 * the payload as a whole. It is possible that the payload has parts where
68 * the decompressor consumes more input than it produces output. Calculating
69 * the worst case for this would be tricky. Instead of trying to do that,
70 * let's simply make sure that the decompressor never overwrites any bytes
71 * of the payload which it is currently reading.
72 *
73 * Now we have enough information to calculate the safety margin. We need
74 * - 128 bytes for the .xz file format headers;
75 * - 8 bytes per every 32 KiB of uncompressed size (one LZMA2 chunk header
76 * per chunk, each chunk having average payload size of 32 KiB); and
77 * - 64 KiB (biggest possible LZMA2 chunk payload size) to make sure that
78 * the decompressor never overwrites anything from the LZMA2 chunk
79 * payload it is currently reading.
80 *
81 * We get the following formula:
82 *
83 * safety_margin = 128 + uncompressed_size * 8 / 32768 + 65536
84 * = 128 + (uncompressed_size >> 12) + 65536
85 *
86 * For comparision, according to arch/x86/boot/compressed/misc.c, the
87 * equivalent formula for Deflate is this:
88 *
89 * safety_margin = 18 + (uncompressed_size >> 12) + 32768
90 *
91 * Thus, when updating Deflate-only in-place kernel decompressor to
92 * support XZ, the fixed overhead has to be increased from 18+32768 bytes
93 * to 128+65536 bytes.
94 */
95
96/*
97 * STATIC is defined to "static" if we are being built for kernel
98 * decompression (pre-boot code). <linux/decompress/mm.h> will define
99 * STATIC to empty if it wasn't already defined. Since we will need to
100 * know later if we are being used for kernel decompression, we define
101 * XZ_PREBOOT here.
102 */
103#ifdef STATIC
104# define XZ_PREBOOT
105#endif
106#ifdef __KERNEL__
107# include <linux/decompress/mm.h>
108#endif
109#define XZ_EXTERN STATIC
110
111#ifndef XZ_PREBOOT
112# include <linux/slab.h>
113# include <linux/xz.h>
114#else
115/*
116 * Use the internal CRC32 code instead of kernel's CRC32 module, which
117 * is not available in early phase of booting.
118 */
119#define XZ_INTERNAL_CRC32 1
120
121/*
122 * For boot time use, we enable only the BCJ filter of the current
123 * architecture or none if no BCJ filter is available for the architecture.
124 */
125#ifdef CONFIG_X86
126# define XZ_DEC_X86
127#endif
128#ifdef CONFIG_PPC
129# define XZ_DEC_POWERPC
130#endif
131#ifdef CONFIG_ARM
132# define XZ_DEC_ARM
133#endif
134#ifdef CONFIG_IA64
135# define XZ_DEC_IA64
136#endif
137#ifdef CONFIG_SPARC
138# define XZ_DEC_SPARC
139#endif
140
141/*
142 * This will get the basic headers so that memeq() and others
143 * can be defined.
144 */
145#include "xz/xz_private.h"
146
147/*
148 * Replace the normal allocation functions with the versions from
149 * <linux/decompress/mm.h>. vfree() needs to support vfree(NULL)
150 * when XZ_DYNALLOC is used, but the pre-boot free() doesn't support it.
151 * Workaround it here because the other decompressors don't need it.
152 */
153#undef kmalloc
154#undef kfree
155#undef vmalloc
156#undef vfree
157#define kmalloc(size, flags) malloc(size)
158#define kfree(ptr) free(ptr)
159#define vmalloc(size) malloc(size)
160#define vfree(ptr) do { if (ptr != NULL) free(ptr); } while (0)
161
162/*
163 * FIXME: Not all basic memory functions are provided in architecture-specific
164 * files (yet). We define our own versions here for now, but this should be
165 * only a temporary solution.
166 *
167 * memeq and memzero are not used much and any remotely sane implementation
168 * is fast enough. memcpy/memmove speed matters in multi-call mode, but
169 * the kernel image is decompressed in single-call mode, in which only
170 * memcpy speed can matter and only if there is a lot of uncompressible data
171 * (LZMA2 stores uncompressible chunks in uncompressed form). Thus, the
172 * functions below should just be kept small; it's probably not worth
173 * optimizing for speed.
174 */
175
176#ifndef memeq
177static bool memeq(const void *a, const void *b, size_t size)
178{
179 const uint8_t *x = a;
180 const uint8_t *y = b;
181 size_t i;
182
183 for (i = 0; i < size; ++i)
184 if (x[i] != y[i])
185 return false;
186
187 return true;
188}
189#endif
190
191#ifndef memzero
192static void memzero(void *buf, size_t size)
193{
194 uint8_t *b = buf;
195 uint8_t *e = b + size;
196
197 while (b != e)
198 *b++ = '\0';
199}
200#endif
201
202#ifndef memmove
203/* Not static to avoid a conflict with the prototype in the Linux headers. */
204void *memmove(void *dest, const void *src, size_t size)
205{
206 uint8_t *d = dest;
207 const uint8_t *s = src;
208 size_t i;
209
210 if (d < s) {
211 for (i = 0; i < size; ++i)
212 d[i] = s[i];
213 } else if (d > s) {
214 i = size;
215 while (i-- > 0)
216 d[i] = s[i];
217 }
218
219 return dest;
220}
221#endif
222
223/*
224 * Since we need memmove anyway, would use it as memcpy too.
225 * Commented out for now to avoid breaking things.
226 */
227/*
228#ifndef memcpy
229# define memcpy memmove
230#endif
231*/
232
233#include "xz/xz_crc32.c"
234#include "xz/xz_dec_stream.c"
235#include "xz/xz_dec_lzma2.c"
236#include "xz/xz_dec_bcj.c"
237
238#endif /* XZ_PREBOOT */
239
240/* Size of the input and output buffers in multi-call mode */
241#define XZ_IOBUF_SIZE 4096
242
243/*
244 * This function implements the API defined in <linux/decompress/generic.h>.
245 *
246 * This wrapper will automatically choose single-call or multi-call mode
247 * of the native XZ decoder API. The single-call mode can be used only when
248 * both input and output buffers are available as a single chunk, i.e. when
249 * fill() and flush() won't be used.
250 */
251STATIC int INIT unxz(unsigned char *in, int in_size,
252 int (*fill)(void *dest, unsigned int size),
253 int (*flush)(void *src, unsigned int size),
254 unsigned char *out, int *in_used,
255 void (*error)(char *x))
256{
257 struct xz_buf b;
258 struct xz_dec *s;
259 enum xz_ret ret;
260 bool must_free_in = false;
261
262#if XZ_INTERNAL_CRC32
263 xz_crc32_init();
264#endif
265
266 if (in_used != NULL)
267 *in_used = 0;
268
269 if (fill == NULL && flush == NULL)
270 s = xz_dec_init(XZ_SINGLE, 0);
271 else
272 s = xz_dec_init(XZ_DYNALLOC, (uint32_t)-1);
273
274 if (s == NULL)
275 goto error_alloc_state;
276
277 if (flush == NULL) {
278 b.out = out;
279 b.out_size = (size_t)-1;
280 } else {
281 b.out_size = XZ_IOBUF_SIZE;
282 b.out = malloc(XZ_IOBUF_SIZE);
283 if (b.out == NULL)
284 goto error_alloc_out;
285 }
286
287 if (in == NULL) {
288 must_free_in = true;
289 in = malloc(XZ_IOBUF_SIZE);
290 if (in == NULL)
291 goto error_alloc_in;
292 }
293
294 b.in = in;
295 b.in_pos = 0;
296 b.in_size = in_size;
297 b.out_pos = 0;
298
299 if (fill == NULL && flush == NULL) {
300 ret = xz_dec_run(s, &b);
301 } else {
302 do {
303 if (b.in_pos == b.in_size && fill != NULL) {
304 if (in_used != NULL)
305 *in_used += b.in_pos;
306
307 b.in_pos = 0;
308
309 in_size = fill(in, XZ_IOBUF_SIZE);
310 if (in_size < 0) {
311 /*
312 * This isn't an optimal error code
313 * but it probably isn't worth making
314 * a new one either.
315 */
316 ret = XZ_BUF_ERROR;
317 break;
318 }
319
320 b.in_size = in_size;
321 }
322
323 ret = xz_dec_run(s, &b);
324
325 if (flush != NULL && (b.out_pos == b.out_size
326 || (ret != XZ_OK && b.out_pos > 0))) {
327 /*
328 * Setting ret here may hide an error
329 * returned by xz_dec_run(), but probably
330 * it's not too bad.
331 */
332 if (flush(b.out, b.out_pos) != (int)b.out_pos)
333 ret = XZ_BUF_ERROR;
334
335 b.out_pos = 0;
336 }
337 } while (ret == XZ_OK);
338
339 if (must_free_in)
340 free(in);
341
342 if (flush != NULL)
343 free(b.out);
344 }
345
346 if (in_used != NULL)
347 *in_used += b.in_pos;
348
349 xz_dec_end(s);
350
351 switch (ret) {
352 case XZ_STREAM_END:
353 return 0;
354
355 case XZ_MEM_ERROR:
356 /* This can occur only in multi-call mode. */
357 error("XZ decompressor ran out of memory");
358 break;
359
360 case XZ_FORMAT_ERROR:
361 error("Input is not in the XZ format (wrong magic bytes)");
362 break;
363
364 case XZ_OPTIONS_ERROR:
365 error("Input was encoded with settings that are not "
366 "supported by this XZ decoder");
367 break;
368
369 case XZ_DATA_ERROR:
370 case XZ_BUF_ERROR:
371 error("XZ-compressed data is corrupt");
372 break;
373
374 default:
375 error("Bug in the XZ decompressor");
376 break;
377 }
378
379 return -1;
380
381error_alloc_in:
382 if (flush != NULL)
383 free(b.out);
384
385error_alloc_out:
386 xz_dec_end(s);
387
388error_alloc_state:
389 error("XZ decompressor ran out of memory");
390 return -1;
391}
392
393/*
394 * This macro is used by architecture-specific files to decompress
395 * the kernel image.
396 */
397#define decompress unxz
diff --git a/lib/flex_array.c b/lib/flex_array.c
index 77a6fea7481e..c0ea40ba2082 100644
--- a/lib/flex_array.c
+++ b/lib/flex_array.c
@@ -23,6 +23,7 @@
23#include <linux/flex_array.h> 23#include <linux/flex_array.h>
24#include <linux/slab.h> 24#include <linux/slab.h>
25#include <linux/stddef.h> 25#include <linux/stddef.h>
26#include <linux/module.h>
26 27
27struct flex_array_part { 28struct flex_array_part {
28 char elements[FLEX_ARRAY_PART_SIZE]; 29 char elements[FLEX_ARRAY_PART_SIZE];
@@ -103,6 +104,7 @@ struct flex_array *flex_array_alloc(int element_size, unsigned int total,
103 FLEX_ARRAY_BASE_BYTES_LEFT); 104 FLEX_ARRAY_BASE_BYTES_LEFT);
104 return ret; 105 return ret;
105} 106}
107EXPORT_SYMBOL(flex_array_alloc);
106 108
107static int fa_element_to_part_nr(struct flex_array *fa, 109static int fa_element_to_part_nr(struct flex_array *fa,
108 unsigned int element_nr) 110 unsigned int element_nr)
@@ -126,12 +128,14 @@ void flex_array_free_parts(struct flex_array *fa)
126 for (part_nr = 0; part_nr < FLEX_ARRAY_NR_BASE_PTRS; part_nr++) 128 for (part_nr = 0; part_nr < FLEX_ARRAY_NR_BASE_PTRS; part_nr++)
127 kfree(fa->parts[part_nr]); 129 kfree(fa->parts[part_nr]);
128} 130}
131EXPORT_SYMBOL(flex_array_free_parts);
129 132
130void flex_array_free(struct flex_array *fa) 133void flex_array_free(struct flex_array *fa)
131{ 134{
132 flex_array_free_parts(fa); 135 flex_array_free_parts(fa);
133 kfree(fa); 136 kfree(fa);
134} 137}
138EXPORT_SYMBOL(flex_array_free);
135 139
136static unsigned int index_inside_part(struct flex_array *fa, 140static unsigned int index_inside_part(struct flex_array *fa,
137 unsigned int element_nr) 141 unsigned int element_nr)
@@ -196,6 +200,7 @@ int flex_array_put(struct flex_array *fa, unsigned int element_nr, void *src,
196 memcpy(dst, src, fa->element_size); 200 memcpy(dst, src, fa->element_size);
197 return 0; 201 return 0;
198} 202}
203EXPORT_SYMBOL(flex_array_put);
199 204
200/** 205/**
201 * flex_array_clear - clear element in array at @element_nr 206 * flex_array_clear - clear element in array at @element_nr
@@ -223,6 +228,7 @@ int flex_array_clear(struct flex_array *fa, unsigned int element_nr)
223 memset(dst, FLEX_ARRAY_FREE, fa->element_size); 228 memset(dst, FLEX_ARRAY_FREE, fa->element_size);
224 return 0; 229 return 0;
225} 230}
231EXPORT_SYMBOL(flex_array_clear);
226 232
227/** 233/**
228 * flex_array_prealloc - guarantee that array space exists 234 * flex_array_prealloc - guarantee that array space exists
@@ -259,6 +265,7 @@ int flex_array_prealloc(struct flex_array *fa, unsigned int start,
259 } 265 }
260 return 0; 266 return 0;
261} 267}
268EXPORT_SYMBOL(flex_array_prealloc);
262 269
263/** 270/**
264 * flex_array_get - pull data back out of the array 271 * flex_array_get - pull data back out of the array
@@ -288,6 +295,7 @@ void *flex_array_get(struct flex_array *fa, unsigned int element_nr)
288 } 295 }
289 return &part->elements[index_inside_part(fa, element_nr)]; 296 return &part->elements[index_inside_part(fa, element_nr)];
290} 297}
298EXPORT_SYMBOL(flex_array_get);
291 299
292/** 300/**
293 * flex_array_get_ptr - pull a ptr back out of the array 301 * flex_array_get_ptr - pull a ptr back out of the array
@@ -308,6 +316,7 @@ void *flex_array_get_ptr(struct flex_array *fa, unsigned int element_nr)
308 316
309 return *tmp; 317 return *tmp;
310} 318}
319EXPORT_SYMBOL(flex_array_get_ptr);
311 320
312static int part_is_free(struct flex_array_part *part) 321static int part_is_free(struct flex_array_part *part)
313{ 322{
@@ -348,3 +357,4 @@ int flex_array_shrink(struct flex_array *fa)
348 } 357 }
349 return ret; 358 return ret;
350} 359}
360EXPORT_SYMBOL(flex_array_shrink);
diff --git a/lib/hexdump.c b/lib/hexdump.c
index b66b2bd67952..f5fe6ba7a3ab 100644
--- a/lib/hexdump.c
+++ b/lib/hexdump.c
@@ -154,6 +154,7 @@ nil:
154} 154}
155EXPORT_SYMBOL(hex_dump_to_buffer); 155EXPORT_SYMBOL(hex_dump_to_buffer);
156 156
157#ifdef CONFIG_PRINTK
157/** 158/**
158 * print_hex_dump - print a text hex dump to syslog for a binary blob of data 159 * print_hex_dump - print a text hex dump to syslog for a binary blob of data
159 * @level: kernel log level (e.g. KERN_DEBUG) 160 * @level: kernel log level (e.g. KERN_DEBUG)
@@ -238,3 +239,4 @@ void print_hex_dump_bytes(const char *prefix_str, int prefix_type,
238 buf, len, true); 239 buf, len, true);
239} 240}
240EXPORT_SYMBOL(print_hex_dump_bytes); 241EXPORT_SYMBOL(print_hex_dump_bytes);
242#endif
diff --git a/lib/nlattr.c b/lib/nlattr.c
index 00e8a02681a6..5021cbc34411 100644
--- a/lib/nlattr.c
+++ b/lib/nlattr.c
@@ -167,7 +167,7 @@ nla_policy_len(const struct nla_policy *p, int n)
167 * @policy: validation policy 167 * @policy: validation policy
168 * 168 *
169 * Parses a stream of attributes and stores a pointer to each attribute in 169 * Parses a stream of attributes and stores a pointer to each attribute in
170 * the tb array accessable via the attribute type. Attributes with a type 170 * the tb array accessible via the attribute type. Attributes with a type
171 * exceeding maxtype will be silently ignored for backwards compatibility 171 * exceeding maxtype will be silently ignored for backwards compatibility
172 * reasons. policy may be set to NULL if no validation is required. 172 * reasons. policy may be set to NULL if no validation is required.
173 * 173 *
diff --git a/lib/swiotlb.c b/lib/swiotlb.c
index 7c06ee51a29a..c47bbe11b804 100644
--- a/lib/swiotlb.c
+++ b/lib/swiotlb.c
@@ -60,7 +60,7 @@ int swiotlb_force;
60static char *io_tlb_start, *io_tlb_end; 60static char *io_tlb_start, *io_tlb_end;
61 61
62/* 62/*
63 * The number of IO TLB blocks (in groups of 64) betweeen io_tlb_start and 63 * The number of IO TLB blocks (in groups of 64) between io_tlb_start and
64 * io_tlb_end. This is command line adjustable via setup_io_tlb_npages. 64 * io_tlb_end. This is command line adjustable via setup_io_tlb_npages.
65 */ 65 */
66static unsigned long io_tlb_nslabs; 66static unsigned long io_tlb_nslabs;
diff --git a/lib/vsprintf.c b/lib/vsprintf.c
index c150d3dafff4..d3023df8477f 100644
--- a/lib/vsprintf.c
+++ b/lib/vsprintf.c
@@ -936,6 +936,8 @@ char *uuid_string(char *buf, char *end, const u8 *addr,
936 return string(buf, end, uuid, spec); 936 return string(buf, end, uuid, spec);
937} 937}
938 938
939int kptr_restrict = 1;
940
939/* 941/*
940 * Show a '%p' thing. A kernel extension is that the '%p' is followed 942 * Show a '%p' thing. A kernel extension is that the '%p' is followed
941 * by an extra set of alphanumeric characters that are extended format 943 * by an extra set of alphanumeric characters that are extended format
@@ -979,6 +981,7 @@ char *uuid_string(char *buf, char *end, const u8 *addr,
979 * Implements a "recursive vsnprintf". 981 * Implements a "recursive vsnprintf".
980 * Do not use this feature without some mechanism to verify the 982 * Do not use this feature without some mechanism to verify the
981 * correctness of the format string and va_list arguments. 983 * correctness of the format string and va_list arguments.
984 * - 'K' For a kernel pointer that should be hidden from unprivileged users
982 * 985 *
983 * Note: The difference between 'S' and 'F' is that on ia64 and ppc64 986 * Note: The difference between 'S' and 'F' is that on ia64 and ppc64
984 * function pointers are really function descriptors, which contain a 987 * function pointers are really function descriptors, which contain a
@@ -1035,6 +1038,25 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
1035 return buf + vsnprintf(buf, end - buf, 1038 return buf + vsnprintf(buf, end - buf,
1036 ((struct va_format *)ptr)->fmt, 1039 ((struct va_format *)ptr)->fmt,
1037 *(((struct va_format *)ptr)->va)); 1040 *(((struct va_format *)ptr)->va));
1041 case 'K':
1042 /*
1043 * %pK cannot be used in IRQ context because its test
1044 * for CAP_SYSLOG would be meaningless.
1045 */
1046 if (in_irq() || in_serving_softirq() || in_nmi()) {
1047 if (spec.field_width == -1)
1048 spec.field_width = 2 * sizeof(void *);
1049 return string(buf, end, "pK-error", spec);
1050 } else if ((kptr_restrict == 0) ||
1051 (kptr_restrict == 1 &&
1052 has_capability_noaudit(current, CAP_SYSLOG)))
1053 break;
1054
1055 if (spec.field_width == -1) {
1056 spec.field_width = 2 * sizeof(void *);
1057 spec.flags |= ZEROPAD;
1058 }
1059 return number(buf, end, 0, spec);
1038 } 1060 }
1039 spec.flags |= SMALL; 1061 spec.flags |= SMALL;
1040 if (spec.field_width == -1) { 1062 if (spec.field_width == -1) {
@@ -1451,7 +1473,7 @@ EXPORT_SYMBOL(vsnprintf);
1451 * @args: Arguments for the format string 1473 * @args: Arguments for the format string
1452 * 1474 *
1453 * The return value is the number of characters which have been written into 1475 * The return value is the number of characters which have been written into
1454 * the @buf not including the trailing '\0'. If @size is <= 0 the function 1476 * the @buf not including the trailing '\0'. If @size is == 0 the function
1455 * returns 0. 1477 * returns 0.
1456 * 1478 *
1457 * Call this function if you are already dealing with a va_list. 1479 * Call this function if you are already dealing with a va_list.
@@ -1465,7 +1487,11 @@ int vscnprintf(char *buf, size_t size, const char *fmt, va_list args)
1465 1487
1466 i = vsnprintf(buf, size, fmt, args); 1488 i = vsnprintf(buf, size, fmt, args);
1467 1489
1468 return (i >= size) ? (size - 1) : i; 1490 if (likely(i < size))
1491 return i;
1492 if (size != 0)
1493 return size - 1;
1494 return 0;
1469} 1495}
1470EXPORT_SYMBOL(vscnprintf); 1496EXPORT_SYMBOL(vscnprintf);
1471 1497
@@ -1513,14 +1539,10 @@ int scnprintf(char *buf, size_t size, const char *fmt, ...)
1513 int i; 1539 int i;
1514 1540
1515 va_start(args, fmt); 1541 va_start(args, fmt);
1516 i = vsnprintf(buf, size, fmt, args); 1542 i = vscnprintf(buf, size, fmt, args);
1517 va_end(args); 1543 va_end(args);
1518 1544
1519 if (likely(i < size)) 1545 return i;
1520 return i;
1521 if (size != 0)
1522 return size - 1;
1523 return 0;
1524} 1546}
1525EXPORT_SYMBOL(scnprintf); 1547EXPORT_SYMBOL(scnprintf);
1526 1548
diff --git a/lib/xz/Kconfig b/lib/xz/Kconfig
new file mode 100644
index 000000000000..e3b6e18fdac5
--- /dev/null
+++ b/lib/xz/Kconfig
@@ -0,0 +1,59 @@
1config XZ_DEC
2 tristate "XZ decompression support"
3 select CRC32
4 help
5 LZMA2 compression algorithm and BCJ filters are supported using
6 the .xz file format as the container. For integrity checking,
7 CRC32 is supported. See Documentation/xz.txt for more information.
8
9config XZ_DEC_X86
10 bool "x86 BCJ filter decoder" if EMBEDDED
11 default y
12 depends on XZ_DEC
13 select XZ_DEC_BCJ
14
15config XZ_DEC_POWERPC
16 bool "PowerPC BCJ filter decoder" if EMBEDDED
17 default y
18 depends on XZ_DEC
19 select XZ_DEC_BCJ
20
21config XZ_DEC_IA64
22 bool "IA-64 BCJ filter decoder" if EMBEDDED
23 default y
24 depends on XZ_DEC
25 select XZ_DEC_BCJ
26
27config XZ_DEC_ARM
28 bool "ARM BCJ filter decoder" if EMBEDDED
29 default y
30 depends on XZ_DEC
31 select XZ_DEC_BCJ
32
33config XZ_DEC_ARMTHUMB
34 bool "ARM-Thumb BCJ filter decoder" if EMBEDDED
35 default y
36 depends on XZ_DEC
37 select XZ_DEC_BCJ
38
39config XZ_DEC_SPARC
40 bool "SPARC BCJ filter decoder" if EMBEDDED
41 default y
42 depends on XZ_DEC
43 select XZ_DEC_BCJ
44
45config XZ_DEC_BCJ
46 bool
47 default n
48
49config XZ_DEC_TEST
50 tristate "XZ decompressor tester"
51 default n
52 depends on XZ_DEC
53 help
54 This allows passing .xz files to the in-kernel XZ decoder via
55 a character special file. It calculates CRC32 of the decompressed
56 data and writes diagnostics to the system log.
57
58 Unless you are developing the XZ decoder, you don't need this
59 and should say N.
diff --git a/lib/xz/Makefile b/lib/xz/Makefile
new file mode 100644
index 000000000000..a7fa7693f0f3
--- /dev/null
+++ b/lib/xz/Makefile
@@ -0,0 +1,5 @@
1obj-$(CONFIG_XZ_DEC) += xz_dec.o
2xz_dec-y := xz_dec_syms.o xz_dec_stream.o xz_dec_lzma2.o
3xz_dec-$(CONFIG_XZ_DEC_BCJ) += xz_dec_bcj.o
4
5obj-$(CONFIG_XZ_DEC_TEST) += xz_dec_test.o
diff --git a/lib/xz/xz_crc32.c b/lib/xz/xz_crc32.c
new file mode 100644
index 000000000000..34532d14fd4c
--- /dev/null
+++ b/lib/xz/xz_crc32.c
@@ -0,0 +1,59 @@
1/*
2 * CRC32 using the polynomial from IEEE-802.3
3 *
4 * Authors: Lasse Collin <lasse.collin@tukaani.org>
5 * Igor Pavlov <http://7-zip.org/>
6 *
7 * This file has been put into the public domain.
8 * You can do whatever you want with this file.
9 */
10
11/*
12 * This is not the fastest implementation, but it is pretty compact.
13 * The fastest versions of xz_crc32() on modern CPUs without hardware
14 * accelerated CRC instruction are 3-5 times as fast as this version,
15 * but they are bigger and use more memory for the lookup table.
16 */
17
18#include "xz_private.h"
19
20/*
21 * STATIC_RW_DATA is used in the pre-boot environment on some architectures.
22 * See <linux/decompress/mm.h> for details.
23 */
24#ifndef STATIC_RW_DATA
25# define STATIC_RW_DATA static
26#endif
27
28STATIC_RW_DATA uint32_t xz_crc32_table[256];
29
30XZ_EXTERN void xz_crc32_init(void)
31{
32 const uint32_t poly = 0xEDB88320;
33
34 uint32_t i;
35 uint32_t j;
36 uint32_t r;
37
38 for (i = 0; i < 256; ++i) {
39 r = i;
40 for (j = 0; j < 8; ++j)
41 r = (r >> 1) ^ (poly & ~((r & 1) - 1));
42
43 xz_crc32_table[i] = r;
44 }
45
46 return;
47}
48
49XZ_EXTERN uint32_t xz_crc32(const uint8_t *buf, size_t size, uint32_t crc)
50{
51 crc = ~crc;
52
53 while (size != 0) {
54 crc = xz_crc32_table[*buf++ ^ (crc & 0xFF)] ^ (crc >> 8);
55 --size;
56 }
57
58 return ~crc;
59}
diff --git a/lib/xz/xz_dec_bcj.c b/lib/xz/xz_dec_bcj.c
new file mode 100644
index 000000000000..e51e2558ca9d
--- /dev/null
+++ b/lib/xz/xz_dec_bcj.c
@@ -0,0 +1,561 @@
1/*
2 * Branch/Call/Jump (BCJ) filter decoders
3 *
4 * Authors: Lasse Collin <lasse.collin@tukaani.org>
5 * Igor Pavlov <http://7-zip.org/>
6 *
7 * This file has been put into the public domain.
8 * You can do whatever you want with this file.
9 */
10
11#include "xz_private.h"
12
13/*
14 * The rest of the file is inside this ifdef. It makes things a little more
15 * convenient when building without support for any BCJ filters.
16 */
17#ifdef XZ_DEC_BCJ
18
19struct xz_dec_bcj {
20 /* Type of the BCJ filter being used */
21 enum {
22 BCJ_X86 = 4, /* x86 or x86-64 */
23 BCJ_POWERPC = 5, /* Big endian only */
24 BCJ_IA64 = 6, /* Big or little endian */
25 BCJ_ARM = 7, /* Little endian only */
26 BCJ_ARMTHUMB = 8, /* Little endian only */
27 BCJ_SPARC = 9 /* Big or little endian */
28 } type;
29
30 /*
31 * Return value of the next filter in the chain. We need to preserve
32 * this information across calls, because we must not call the next
33 * filter anymore once it has returned XZ_STREAM_END.
34 */
35 enum xz_ret ret;
36
37 /* True if we are operating in single-call mode. */
38 bool single_call;
39
40 /*
41 * Absolute position relative to the beginning of the uncompressed
42 * data (in a single .xz Block). We care only about the lowest 32
43 * bits so this doesn't need to be uint64_t even with big files.
44 */
45 uint32_t pos;
46
47 /* x86 filter state */
48 uint32_t x86_prev_mask;
49
50 /* Temporary space to hold the variables from struct xz_buf */
51 uint8_t *out;
52 size_t out_pos;
53 size_t out_size;
54
55 struct {
56 /* Amount of already filtered data in the beginning of buf */
57 size_t filtered;
58
59 /* Total amount of data currently stored in buf */
60 size_t size;
61
62 /*
63 * Buffer to hold a mix of filtered and unfiltered data. This
64 * needs to be big enough to hold Alignment + 2 * Look-ahead:
65 *
66 * Type Alignment Look-ahead
67 * x86 1 4
68 * PowerPC 4 0
69 * IA-64 16 0
70 * ARM 4 0
71 * ARM-Thumb 2 2
72 * SPARC 4 0
73 */
74 uint8_t buf[16];
75 } temp;
76};
77
78#ifdef XZ_DEC_X86
79/*
80 * This is used to test the most significant byte of a memory address
81 * in an x86 instruction.
82 */
83static inline int bcj_x86_test_msbyte(uint8_t b)
84{
85 return b == 0x00 || b == 0xFF;
86}
87
88static size_t bcj_x86(struct xz_dec_bcj *s, uint8_t *buf, size_t size)
89{
90 static const bool mask_to_allowed_status[8]
91 = { true, true, true, false, true, false, false, false };
92
93 static const uint8_t mask_to_bit_num[8] = { 0, 1, 2, 2, 3, 3, 3, 3 };
94
95 size_t i;
96 size_t prev_pos = (size_t)-1;
97 uint32_t prev_mask = s->x86_prev_mask;
98 uint32_t src;
99 uint32_t dest;
100 uint32_t j;
101 uint8_t b;
102
103 if (size <= 4)
104 return 0;
105
106 size -= 4;
107 for (i = 0; i < size; ++i) {
108 if ((buf[i] & 0xFE) != 0xE8)
109 continue;
110
111 prev_pos = i - prev_pos;
112 if (prev_pos > 3) {
113 prev_mask = 0;
114 } else {
115 prev_mask = (prev_mask << (prev_pos - 1)) & 7;
116 if (prev_mask != 0) {
117 b = buf[i + 4 - mask_to_bit_num[prev_mask]];
118 if (!mask_to_allowed_status[prev_mask]
119 || bcj_x86_test_msbyte(b)) {
120 prev_pos = i;
121 prev_mask = (prev_mask << 1) | 1;
122 continue;
123 }
124 }
125 }
126
127 prev_pos = i;
128
129 if (bcj_x86_test_msbyte(buf[i + 4])) {
130 src = get_unaligned_le32(buf + i + 1);
131 while (true) {
132 dest = src - (s->pos + (uint32_t)i + 5);
133 if (prev_mask == 0)
134 break;
135
136 j = mask_to_bit_num[prev_mask] * 8;
137 b = (uint8_t)(dest >> (24 - j));
138 if (!bcj_x86_test_msbyte(b))
139 break;
140
141 src = dest ^ (((uint32_t)1 << (32 - j)) - 1);
142 }
143
144 dest &= 0x01FFFFFF;
145 dest |= (uint32_t)0 - (dest & 0x01000000);
146 put_unaligned_le32(dest, buf + i + 1);
147 i += 4;
148 } else {
149 prev_mask = (prev_mask << 1) | 1;
150 }
151 }
152
153 prev_pos = i - prev_pos;
154 s->x86_prev_mask = prev_pos > 3 ? 0 : prev_mask << (prev_pos - 1);
155 return i;
156}
157#endif
158
159#ifdef XZ_DEC_POWERPC
160static size_t bcj_powerpc(struct xz_dec_bcj *s, uint8_t *buf, size_t size)
161{
162 size_t i;
163 uint32_t instr;
164
165 for (i = 0; i + 4 <= size; i += 4) {
166 instr = get_unaligned_be32(buf + i);
167 if ((instr & 0xFC000003) == 0x48000001) {
168 instr &= 0x03FFFFFC;
169 instr -= s->pos + (uint32_t)i;
170 instr &= 0x03FFFFFC;
171 instr |= 0x48000001;
172 put_unaligned_be32(instr, buf + i);
173 }
174 }
175
176 return i;
177}
178#endif
179
180#ifdef XZ_DEC_IA64
181static size_t bcj_ia64(struct xz_dec_bcj *s, uint8_t *buf, size_t size)
182{
183 static const uint8_t branch_table[32] = {
184 0, 0, 0, 0, 0, 0, 0, 0,
185 0, 0, 0, 0, 0, 0, 0, 0,
186 4, 4, 6, 6, 0, 0, 7, 7,
187 4, 4, 0, 0, 4, 4, 0, 0
188 };
189
190 /*
191 * The local variables take a little bit stack space, but it's less
192 * than what LZMA2 decoder takes, so it doesn't make sense to reduce
193 * stack usage here without doing that for the LZMA2 decoder too.
194 */
195
196 /* Loop counters */
197 size_t i;
198 size_t j;
199
200 /* Instruction slot (0, 1, or 2) in the 128-bit instruction word */
201 uint32_t slot;
202
203 /* Bitwise offset of the instruction indicated by slot */
204 uint32_t bit_pos;
205
206 /* bit_pos split into byte and bit parts */
207 uint32_t byte_pos;
208 uint32_t bit_res;
209
210 /* Address part of an instruction */
211 uint32_t addr;
212
213 /* Mask used to detect which instructions to convert */
214 uint32_t mask;
215
216 /* 41-bit instruction stored somewhere in the lowest 48 bits */
217 uint64_t instr;
218
219 /* Instruction normalized with bit_res for easier manipulation */
220 uint64_t norm;
221
222 for (i = 0; i + 16 <= size; i += 16) {
223 mask = branch_table[buf[i] & 0x1F];
224 for (slot = 0, bit_pos = 5; slot < 3; ++slot, bit_pos += 41) {
225 if (((mask >> slot) & 1) == 0)
226 continue;
227
228 byte_pos = bit_pos >> 3;
229 bit_res = bit_pos & 7;
230 instr = 0;
231 for (j = 0; j < 6; ++j)
232 instr |= (uint64_t)(buf[i + j + byte_pos])
233 << (8 * j);
234
235 norm = instr >> bit_res;
236
237 if (((norm >> 37) & 0x0F) == 0x05
238 && ((norm >> 9) & 0x07) == 0) {
239 addr = (norm >> 13) & 0x0FFFFF;
240 addr |= ((uint32_t)(norm >> 36) & 1) << 20;
241 addr <<= 4;
242 addr -= s->pos + (uint32_t)i;
243 addr >>= 4;
244
245 norm &= ~((uint64_t)0x8FFFFF << 13);
246 norm |= (uint64_t)(addr & 0x0FFFFF) << 13;
247 norm |= (uint64_t)(addr & 0x100000)
248 << (36 - 20);
249
250 instr &= (1 << bit_res) - 1;
251 instr |= norm << bit_res;
252
253 for (j = 0; j < 6; j++)
254 buf[i + j + byte_pos]
255 = (uint8_t)(instr >> (8 * j));
256 }
257 }
258 }
259
260 return i;
261}
262#endif
263
264#ifdef XZ_DEC_ARM
265static size_t bcj_arm(struct xz_dec_bcj *s, uint8_t *buf, size_t size)
266{
267 size_t i;
268 uint32_t addr;
269
270 for (i = 0; i + 4 <= size; i += 4) {
271 if (buf[i + 3] == 0xEB) {
272 addr = (uint32_t)buf[i] | ((uint32_t)buf[i + 1] << 8)
273 | ((uint32_t)buf[i + 2] << 16);
274 addr <<= 2;
275 addr -= s->pos + (uint32_t)i + 8;
276 addr >>= 2;
277 buf[i] = (uint8_t)addr;
278 buf[i + 1] = (uint8_t)(addr >> 8);
279 buf[i + 2] = (uint8_t)(addr >> 16);
280 }
281 }
282
283 return i;
284}
285#endif
286
287#ifdef XZ_DEC_ARMTHUMB
288static size_t bcj_armthumb(struct xz_dec_bcj *s, uint8_t *buf, size_t size)
289{
290 size_t i;
291 uint32_t addr;
292
293 for (i = 0; i + 4 <= size; i += 2) {
294 if ((buf[i + 1] & 0xF8) == 0xF0
295 && (buf[i + 3] & 0xF8) == 0xF8) {
296 addr = (((uint32_t)buf[i + 1] & 0x07) << 19)
297 | ((uint32_t)buf[i] << 11)
298 | (((uint32_t)buf[i + 3] & 0x07) << 8)
299 | (uint32_t)buf[i + 2];
300 addr <<= 1;
301 addr -= s->pos + (uint32_t)i + 4;
302 addr >>= 1;
303 buf[i + 1] = (uint8_t)(0xF0 | ((addr >> 19) & 0x07));
304 buf[i] = (uint8_t)(addr >> 11);
305 buf[i + 3] = (uint8_t)(0xF8 | ((addr >> 8) & 0x07));
306 buf[i + 2] = (uint8_t)addr;
307 i += 2;
308 }
309 }
310
311 return i;
312}
313#endif
314
315#ifdef XZ_DEC_SPARC
316static size_t bcj_sparc(struct xz_dec_bcj *s, uint8_t *buf, size_t size)
317{
318 size_t i;
319 uint32_t instr;
320
321 for (i = 0; i + 4 <= size; i += 4) {
322 instr = get_unaligned_be32(buf + i);
323 if ((instr >> 22) == 0x100 || (instr >> 22) == 0x1FF) {
324 instr <<= 2;
325 instr -= s->pos + (uint32_t)i;
326 instr >>= 2;
327 instr = ((uint32_t)0x40000000 - (instr & 0x400000))
328 | 0x40000000 | (instr & 0x3FFFFF);
329 put_unaligned_be32(instr, buf + i);
330 }
331 }
332
333 return i;
334}
335#endif
336
337/*
338 * Apply the selected BCJ filter. Update *pos and s->pos to match the amount
339 * of data that got filtered.
340 *
341 * NOTE: This is implemented as a switch statement to avoid using function
342 * pointers, which could be problematic in the kernel boot code, which must
343 * avoid pointers to static data (at least on x86).
344 */
345static void bcj_apply(struct xz_dec_bcj *s,
346 uint8_t *buf, size_t *pos, size_t size)
347{
348 size_t filtered;
349
350 buf += *pos;
351 size -= *pos;
352
353 switch (s->type) {
354#ifdef XZ_DEC_X86
355 case BCJ_X86:
356 filtered = bcj_x86(s, buf, size);
357 break;
358#endif
359#ifdef XZ_DEC_POWERPC
360 case BCJ_POWERPC:
361 filtered = bcj_powerpc(s, buf, size);
362 break;
363#endif
364#ifdef XZ_DEC_IA64
365 case BCJ_IA64:
366 filtered = bcj_ia64(s, buf, size);
367 break;
368#endif
369#ifdef XZ_DEC_ARM
370 case BCJ_ARM:
371 filtered = bcj_arm(s, buf, size);
372 break;
373#endif
374#ifdef XZ_DEC_ARMTHUMB
375 case BCJ_ARMTHUMB:
376 filtered = bcj_armthumb(s, buf, size);
377 break;
378#endif
379#ifdef XZ_DEC_SPARC
380 case BCJ_SPARC:
381 filtered = bcj_sparc(s, buf, size);
382 break;
383#endif
384 default:
385 /* Never reached but silence compiler warnings. */
386 filtered = 0;
387 break;
388 }
389
390 *pos += filtered;
391 s->pos += filtered;
392}
393
394/*
395 * Flush pending filtered data from temp to the output buffer.
396 * Move the remaining mixture of possibly filtered and unfiltered
397 * data to the beginning of temp.
398 */
399static void bcj_flush(struct xz_dec_bcj *s, struct xz_buf *b)
400{
401 size_t copy_size;
402
403 copy_size = min_t(size_t, s->temp.filtered, b->out_size - b->out_pos);
404 memcpy(b->out + b->out_pos, s->temp.buf, copy_size);
405 b->out_pos += copy_size;
406
407 s->temp.filtered -= copy_size;
408 s->temp.size -= copy_size;
409 memmove(s->temp.buf, s->temp.buf + copy_size, s->temp.size);
410}
411
412/*
413 * The BCJ filter functions are primitive in sense that they process the
414 * data in chunks of 1-16 bytes. To hide this issue, this function does
415 * some buffering.
416 */
417XZ_EXTERN enum xz_ret xz_dec_bcj_run(struct xz_dec_bcj *s,
418 struct xz_dec_lzma2 *lzma2,
419 struct xz_buf *b)
420{
421 size_t out_start;
422
423 /*
424 * Flush pending already filtered data to the output buffer. Return
425 * immediatelly if we couldn't flush everything, or if the next
426 * filter in the chain had already returned XZ_STREAM_END.
427 */
428 if (s->temp.filtered > 0) {
429 bcj_flush(s, b);
430 if (s->temp.filtered > 0)
431 return XZ_OK;
432
433 if (s->ret == XZ_STREAM_END)
434 return XZ_STREAM_END;
435 }
436
437 /*
438 * If we have more output space than what is currently pending in
439 * temp, copy the unfiltered data from temp to the output buffer
440 * and try to fill the output buffer by decoding more data from the
441 * next filter in the chain. Apply the BCJ filter on the new data
442 * in the output buffer. If everything cannot be filtered, copy it
443 * to temp and rewind the output buffer position accordingly.
444 */
445 if (s->temp.size < b->out_size - b->out_pos) {
446 out_start = b->out_pos;
447 memcpy(b->out + b->out_pos, s->temp.buf, s->temp.size);
448 b->out_pos += s->temp.size;
449
450 s->ret = xz_dec_lzma2_run(lzma2, b);
451 if (s->ret != XZ_STREAM_END
452 && (s->ret != XZ_OK || s->single_call))
453 return s->ret;
454
455 bcj_apply(s, b->out, &out_start, b->out_pos);
456
457 /*
458 * As an exception, if the next filter returned XZ_STREAM_END,
459 * we can do that too, since the last few bytes that remain
460 * unfiltered are meant to remain unfiltered.
461 */
462 if (s->ret == XZ_STREAM_END)
463 return XZ_STREAM_END;
464
465 s->temp.size = b->out_pos - out_start;
466 b->out_pos -= s->temp.size;
467 memcpy(s->temp.buf, b->out + b->out_pos, s->temp.size);
468 }
469
470 /*
471 * If we have unfiltered data in temp, try to fill by decoding more
472 * data from the next filter. Apply the BCJ filter on temp. Then we
473 * hopefully can fill the actual output buffer by copying filtered
474 * data from temp. A mix of filtered and unfiltered data may be left
475 * in temp; it will be taken care on the next call to this function.
476 */
477 if (s->temp.size > 0) {
478 /* Make b->out{,_pos,_size} temporarily point to s->temp. */
479 s->out = b->out;
480 s->out_pos = b->out_pos;
481 s->out_size = b->out_size;
482 b->out = s->temp.buf;
483 b->out_pos = s->temp.size;
484 b->out_size = sizeof(s->temp.buf);
485
486 s->ret = xz_dec_lzma2_run(lzma2, b);
487
488 s->temp.size = b->out_pos;
489 b->out = s->out;
490 b->out_pos = s->out_pos;
491 b->out_size = s->out_size;
492
493 if (s->ret != XZ_OK && s->ret != XZ_STREAM_END)
494 return s->ret;
495
496 bcj_apply(s, s->temp.buf, &s->temp.filtered, s->temp.size);
497
498 /*
499 * If the next filter returned XZ_STREAM_END, we mark that
500 * everything is filtered, since the last unfiltered bytes
501 * of the stream are meant to be left as is.
502 */
503 if (s->ret == XZ_STREAM_END)
504 s->temp.filtered = s->temp.size;
505
506 bcj_flush(s, b);
507 if (s->temp.filtered > 0)
508 return XZ_OK;
509 }
510
511 return s->ret;
512}
513
514XZ_EXTERN struct xz_dec_bcj *xz_dec_bcj_create(bool single_call)
515{
516 struct xz_dec_bcj *s = kmalloc(sizeof(*s), GFP_KERNEL);
517 if (s != NULL)
518 s->single_call = single_call;
519
520 return s;
521}
522
523XZ_EXTERN enum xz_ret xz_dec_bcj_reset(struct xz_dec_bcj *s, uint8_t id)
524{
525 switch (id) {
526#ifdef XZ_DEC_X86
527 case BCJ_X86:
528#endif
529#ifdef XZ_DEC_POWERPC
530 case BCJ_POWERPC:
531#endif
532#ifdef XZ_DEC_IA64
533 case BCJ_IA64:
534#endif
535#ifdef XZ_DEC_ARM
536 case BCJ_ARM:
537#endif
538#ifdef XZ_DEC_ARMTHUMB
539 case BCJ_ARMTHUMB:
540#endif
541#ifdef XZ_DEC_SPARC
542 case BCJ_SPARC:
543#endif
544 break;
545
546 default:
547 /* Unsupported Filter ID */
548 return XZ_OPTIONS_ERROR;
549 }
550
551 s->type = id;
552 s->ret = XZ_OK;
553 s->pos = 0;
554 s->x86_prev_mask = 0;
555 s->temp.filtered = 0;
556 s->temp.size = 0;
557
558 return XZ_OK;
559}
560
561#endif
diff --git a/lib/xz/xz_dec_lzma2.c b/lib/xz/xz_dec_lzma2.c
new file mode 100644
index 000000000000..ea5fa4fe9d67
--- /dev/null
+++ b/lib/xz/xz_dec_lzma2.c
@@ -0,0 +1,1171 @@
1/*
2 * LZMA2 decoder
3 *
4 * Authors: Lasse Collin <lasse.collin@tukaani.org>
5 * Igor Pavlov <http://7-zip.org/>
6 *
7 * This file has been put into the public domain.
8 * You can do whatever you want with this file.
9 */
10
11#include "xz_private.h"
12#include "xz_lzma2.h"
13
14/*
15 * Range decoder initialization eats the first five bytes of each LZMA chunk.
16 */
17#define RC_INIT_BYTES 5
18
19/*
20 * Minimum number of usable input buffer to safely decode one LZMA symbol.
21 * The worst case is that we decode 22 bits using probabilities and 26
22 * direct bits. This may decode at maximum of 20 bytes of input. However,
23 * lzma_main() does an extra normalization before returning, thus we
24 * need to put 21 here.
25 */
26#define LZMA_IN_REQUIRED 21
27
28/*
29 * Dictionary (history buffer)
30 *
31 * These are always true:
32 * start <= pos <= full <= end
33 * pos <= limit <= end
34 *
35 * In multi-call mode, also these are true:
36 * end == size
37 * size <= size_max
38 * allocated <= size
39 *
40 * Most of these variables are size_t to support single-call mode,
41 * in which the dictionary variables address the actual output
42 * buffer directly.
43 */
44struct dictionary {
45 /* Beginning of the history buffer */
46 uint8_t *buf;
47
48 /* Old position in buf (before decoding more data) */
49 size_t start;
50
51 /* Position in buf */
52 size_t pos;
53
54 /*
55 * How full dictionary is. This is used to detect corrupt input that
56 * would read beyond the beginning of the uncompressed stream.
57 */
58 size_t full;
59
60 /* Write limit; we don't write to buf[limit] or later bytes. */
61 size_t limit;
62
63 /*
64 * End of the dictionary buffer. In multi-call mode, this is
65 * the same as the dictionary size. In single-call mode, this
66 * indicates the size of the output buffer.
67 */
68 size_t end;
69
70 /*
71 * Size of the dictionary as specified in Block Header. This is used
72 * together with "full" to detect corrupt input that would make us
73 * read beyond the beginning of the uncompressed stream.
74 */
75 uint32_t size;
76
77 /*
78 * Maximum allowed dictionary size in multi-call mode.
79 * This is ignored in single-call mode.
80 */
81 uint32_t size_max;
82
83 /*
84 * Amount of memory currently allocated for the dictionary.
85 * This is used only with XZ_DYNALLOC. (With XZ_PREALLOC,
86 * size_max is always the same as the allocated size.)
87 */
88 uint32_t allocated;
89
90 /* Operation mode */
91 enum xz_mode mode;
92};
93
94/* Range decoder */
95struct rc_dec {
96 uint32_t range;
97 uint32_t code;
98
99 /*
100 * Number of initializing bytes remaining to be read
101 * by rc_read_init().
102 */
103 uint32_t init_bytes_left;
104
105 /*
106 * Buffer from which we read our input. It can be either
107 * temp.buf or the caller-provided input buffer.
108 */
109 const uint8_t *in;
110 size_t in_pos;
111 size_t in_limit;
112};
113
114/* Probabilities for a length decoder. */
115struct lzma_len_dec {
116 /* Probability of match length being at least 10 */
117 uint16_t choice;
118
119 /* Probability of match length being at least 18 */
120 uint16_t choice2;
121
122 /* Probabilities for match lengths 2-9 */
123 uint16_t low[POS_STATES_MAX][LEN_LOW_SYMBOLS];
124
125 /* Probabilities for match lengths 10-17 */
126 uint16_t mid[POS_STATES_MAX][LEN_MID_SYMBOLS];
127
128 /* Probabilities for match lengths 18-273 */
129 uint16_t high[LEN_HIGH_SYMBOLS];
130};
131
132struct lzma_dec {
133 /* Distances of latest four matches */
134 uint32_t rep0;
135 uint32_t rep1;
136 uint32_t rep2;
137 uint32_t rep3;
138
139 /* Types of the most recently seen LZMA symbols */
140 enum lzma_state state;
141
142 /*
143 * Length of a match. This is updated so that dict_repeat can
144 * be called again to finish repeating the whole match.
145 */
146 uint32_t len;
147
148 /*
149 * LZMA properties or related bit masks (number of literal
150 * context bits, a mask dervied from the number of literal
151 * position bits, and a mask dervied from the number
152 * position bits)
153 */
154 uint32_t lc;
155 uint32_t literal_pos_mask; /* (1 << lp) - 1 */
156 uint32_t pos_mask; /* (1 << pb) - 1 */
157
158 /* If 1, it's a match. Otherwise it's a single 8-bit literal. */
159 uint16_t is_match[STATES][POS_STATES_MAX];
160
161 /* If 1, it's a repeated match. The distance is one of rep0 .. rep3. */
162 uint16_t is_rep[STATES];
163
164 /*
165 * If 0, distance of a repeated match is rep0.
166 * Otherwise check is_rep1.
167 */
168 uint16_t is_rep0[STATES];
169
170 /*
171 * If 0, distance of a repeated match is rep1.
172 * Otherwise check is_rep2.
173 */
174 uint16_t is_rep1[STATES];
175
176 /* If 0, distance of a repeated match is rep2. Otherwise it is rep3. */
177 uint16_t is_rep2[STATES];
178
179 /*
180 * If 1, the repeated match has length of one byte. Otherwise
181 * the length is decoded from rep_len_decoder.
182 */
183 uint16_t is_rep0_long[STATES][POS_STATES_MAX];
184
185 /*
186 * Probability tree for the highest two bits of the match
187 * distance. There is a separate probability tree for match
188 * lengths of 2 (i.e. MATCH_LEN_MIN), 3, 4, and [5, 273].
189 */
190 uint16_t dist_slot[DIST_STATES][DIST_SLOTS];
191
192 /*
193 * Probility trees for additional bits for match distance
194 * when the distance is in the range [4, 127].
195 */
196 uint16_t dist_special[FULL_DISTANCES - DIST_MODEL_END];
197
198 /*
199 * Probability tree for the lowest four bits of a match
200 * distance that is equal to or greater than 128.
201 */
202 uint16_t dist_align[ALIGN_SIZE];
203
204 /* Length of a normal match */
205 struct lzma_len_dec match_len_dec;
206
207 /* Length of a repeated match */
208 struct lzma_len_dec rep_len_dec;
209
210 /* Probabilities of literals */
211 uint16_t literal[LITERAL_CODERS_MAX][LITERAL_CODER_SIZE];
212};
213
214struct lzma2_dec {
215 /* Position in xz_dec_lzma2_run(). */
216 enum lzma2_seq {
217 SEQ_CONTROL,
218 SEQ_UNCOMPRESSED_1,
219 SEQ_UNCOMPRESSED_2,
220 SEQ_COMPRESSED_0,
221 SEQ_COMPRESSED_1,
222 SEQ_PROPERTIES,
223 SEQ_LZMA_PREPARE,
224 SEQ_LZMA_RUN,
225 SEQ_COPY
226 } sequence;
227
228 /* Next position after decoding the compressed size of the chunk. */
229 enum lzma2_seq next_sequence;
230
231 /* Uncompressed size of LZMA chunk (2 MiB at maximum) */
232 uint32_t uncompressed;
233
234 /*
235 * Compressed size of LZMA chunk or compressed/uncompressed
236 * size of uncompressed chunk (64 KiB at maximum)
237 */
238 uint32_t compressed;
239
240 /*
241 * True if dictionary reset is needed. This is false before
242 * the first chunk (LZMA or uncompressed).
243 */
244 bool need_dict_reset;
245
246 /*
247 * True if new LZMA properties are needed. This is false
248 * before the first LZMA chunk.
249 */
250 bool need_props;
251};
252
253struct xz_dec_lzma2 {
254 /*
255 * The order below is important on x86 to reduce code size and
256 * it shouldn't hurt on other platforms. Everything up to and
257 * including lzma.pos_mask are in the first 128 bytes on x86-32,
258 * which allows using smaller instructions to access those
259 * variables. On x86-64, fewer variables fit into the first 128
260 * bytes, but this is still the best order without sacrificing
261 * the readability by splitting the structures.
262 */
263 struct rc_dec rc;
264 struct dictionary dict;
265 struct lzma2_dec lzma2;
266 struct lzma_dec lzma;
267
268 /*
269 * Temporary buffer which holds small number of input bytes between
270 * decoder calls. See lzma2_lzma() for details.
271 */
272 struct {
273 uint32_t size;
274 uint8_t buf[3 * LZMA_IN_REQUIRED];
275 } temp;
276};
277
278/**************
279 * Dictionary *
280 **************/
281
282/*
283 * Reset the dictionary state. When in single-call mode, set up the beginning
284 * of the dictionary to point to the actual output buffer.
285 */
286static void dict_reset(struct dictionary *dict, struct xz_buf *b)
287{
288 if (DEC_IS_SINGLE(dict->mode)) {
289 dict->buf = b->out + b->out_pos;
290 dict->end = b->out_size - b->out_pos;
291 }
292
293 dict->start = 0;
294 dict->pos = 0;
295 dict->limit = 0;
296 dict->full = 0;
297}
298
299/* Set dictionary write limit */
300static void dict_limit(struct dictionary *dict, size_t out_max)
301{
302 if (dict->end - dict->pos <= out_max)
303 dict->limit = dict->end;
304 else
305 dict->limit = dict->pos + out_max;
306}
307
308/* Return true if at least one byte can be written into the dictionary. */
309static inline bool dict_has_space(const struct dictionary *dict)
310{
311 return dict->pos < dict->limit;
312}
313
314/*
315 * Get a byte from the dictionary at the given distance. The distance is
316 * assumed to valid, or as a special case, zero when the dictionary is
317 * still empty. This special case is needed for single-call decoding to
318 * avoid writing a '\0' to the end of the destination buffer.
319 */
320static inline uint32_t dict_get(const struct dictionary *dict, uint32_t dist)
321{
322 size_t offset = dict->pos - dist - 1;
323
324 if (dist >= dict->pos)
325 offset += dict->end;
326
327 return dict->full > 0 ? dict->buf[offset] : 0;
328}
329
330/*
331 * Put one byte into the dictionary. It is assumed that there is space for it.
332 */
333static inline void dict_put(struct dictionary *dict, uint8_t byte)
334{
335 dict->buf[dict->pos++] = byte;
336
337 if (dict->full < dict->pos)
338 dict->full = dict->pos;
339}
340
341/*
342 * Repeat given number of bytes from the given distance. If the distance is
343 * invalid, false is returned. On success, true is returned and *len is
344 * updated to indicate how many bytes were left to be repeated.
345 */
346static bool dict_repeat(struct dictionary *dict, uint32_t *len, uint32_t dist)
347{
348 size_t back;
349 uint32_t left;
350
351 if (dist >= dict->full || dist >= dict->size)
352 return false;
353
354 left = min_t(size_t, dict->limit - dict->pos, *len);
355 *len -= left;
356
357 back = dict->pos - dist - 1;
358 if (dist >= dict->pos)
359 back += dict->end;
360
361 do {
362 dict->buf[dict->pos++] = dict->buf[back++];
363 if (back == dict->end)
364 back = 0;
365 } while (--left > 0);
366
367 if (dict->full < dict->pos)
368 dict->full = dict->pos;
369
370 return true;
371}
372
373/* Copy uncompressed data as is from input to dictionary and output buffers. */
374static void dict_uncompressed(struct dictionary *dict, struct xz_buf *b,
375 uint32_t *left)
376{
377 size_t copy_size;
378
379 while (*left > 0 && b->in_pos < b->in_size
380 && b->out_pos < b->out_size) {
381 copy_size = min(b->in_size - b->in_pos,
382 b->out_size - b->out_pos);
383 if (copy_size > dict->end - dict->pos)
384 copy_size = dict->end - dict->pos;
385 if (copy_size > *left)
386 copy_size = *left;
387
388 *left -= copy_size;
389
390 memcpy(dict->buf + dict->pos, b->in + b->in_pos, copy_size);
391 dict->pos += copy_size;
392
393 if (dict->full < dict->pos)
394 dict->full = dict->pos;
395
396 if (DEC_IS_MULTI(dict->mode)) {
397 if (dict->pos == dict->end)
398 dict->pos = 0;
399
400 memcpy(b->out + b->out_pos, b->in + b->in_pos,
401 copy_size);
402 }
403
404 dict->start = dict->pos;
405
406 b->out_pos += copy_size;
407 b->in_pos += copy_size;
408 }
409}
410
411/*
412 * Flush pending data from dictionary to b->out. It is assumed that there is
413 * enough space in b->out. This is guaranteed because caller uses dict_limit()
414 * before decoding data into the dictionary.
415 */
416static uint32_t dict_flush(struct dictionary *dict, struct xz_buf *b)
417{
418 size_t copy_size = dict->pos - dict->start;
419
420 if (DEC_IS_MULTI(dict->mode)) {
421 if (dict->pos == dict->end)
422 dict->pos = 0;
423
424 memcpy(b->out + b->out_pos, dict->buf + dict->start,
425 copy_size);
426 }
427
428 dict->start = dict->pos;
429 b->out_pos += copy_size;
430 return copy_size;
431}
432
433/*****************
434 * Range decoder *
435 *****************/
436
437/* Reset the range decoder. */
438static void rc_reset(struct rc_dec *rc)
439{
440 rc->range = (uint32_t)-1;
441 rc->code = 0;
442 rc->init_bytes_left = RC_INIT_BYTES;
443}
444
445/*
446 * Read the first five initial bytes into rc->code if they haven't been
447 * read already. (Yes, the first byte gets completely ignored.)
448 */
449static bool rc_read_init(struct rc_dec *rc, struct xz_buf *b)
450{
451 while (rc->init_bytes_left > 0) {
452 if (b->in_pos == b->in_size)
453 return false;
454
455 rc->code = (rc->code << 8) + b->in[b->in_pos++];
456 --rc->init_bytes_left;
457 }
458
459 return true;
460}
461
462/* Return true if there may not be enough input for the next decoding loop. */
463static inline bool rc_limit_exceeded(const struct rc_dec *rc)
464{
465 return rc->in_pos > rc->in_limit;
466}
467
468/*
469 * Return true if it is possible (from point of view of range decoder) that
470 * we have reached the end of the LZMA chunk.
471 */
472static inline bool rc_is_finished(const struct rc_dec *rc)
473{
474 return rc->code == 0;
475}
476
477/* Read the next input byte if needed. */
478static __always_inline void rc_normalize(struct rc_dec *rc)
479{
480 if (rc->range < RC_TOP_VALUE) {
481 rc->range <<= RC_SHIFT_BITS;
482 rc->code = (rc->code << RC_SHIFT_BITS) + rc->in[rc->in_pos++];
483 }
484}
485
486/*
487 * Decode one bit. In some versions, this function has been splitted in three
488 * functions so that the compiler is supposed to be able to more easily avoid
489 * an extra branch. In this particular version of the LZMA decoder, this
490 * doesn't seem to be a good idea (tested with GCC 3.3.6, 3.4.6, and 4.3.3
491 * on x86). Using a non-splitted version results in nicer looking code too.
492 *
493 * NOTE: This must return an int. Do not make it return a bool or the speed
494 * of the code generated by GCC 3.x decreases 10-15 %. (GCC 4.3 doesn't care,
495 * and it generates 10-20 % faster code than GCC 3.x from this file anyway.)
496 */
497static __always_inline int rc_bit(struct rc_dec *rc, uint16_t *prob)
498{
499 uint32_t bound;
500 int bit;
501
502 rc_normalize(rc);
503 bound = (rc->range >> RC_BIT_MODEL_TOTAL_BITS) * *prob;
504 if (rc->code < bound) {
505 rc->range = bound;
506 *prob += (RC_BIT_MODEL_TOTAL - *prob) >> RC_MOVE_BITS;
507 bit = 0;
508 } else {
509 rc->range -= bound;
510 rc->code -= bound;
511 *prob -= *prob >> RC_MOVE_BITS;
512 bit = 1;
513 }
514
515 return bit;
516}
517
518/* Decode a bittree starting from the most significant bit. */
519static __always_inline uint32_t rc_bittree(struct rc_dec *rc,
520 uint16_t *probs, uint32_t limit)
521{
522 uint32_t symbol = 1;
523
524 do {
525 if (rc_bit(rc, &probs[symbol]))
526 symbol = (symbol << 1) + 1;
527 else
528 symbol <<= 1;
529 } while (symbol < limit);
530
531 return symbol;
532}
533
534/* Decode a bittree starting from the least significant bit. */
535static __always_inline void rc_bittree_reverse(struct rc_dec *rc,
536 uint16_t *probs,
537 uint32_t *dest, uint32_t limit)
538{
539 uint32_t symbol = 1;
540 uint32_t i = 0;
541
542 do {
543 if (rc_bit(rc, &probs[symbol])) {
544 symbol = (symbol << 1) + 1;
545 *dest += 1 << i;
546 } else {
547 symbol <<= 1;
548 }
549 } while (++i < limit);
550}
551
552/* Decode direct bits (fixed fifty-fifty probability) */
553static inline void rc_direct(struct rc_dec *rc, uint32_t *dest, uint32_t limit)
554{
555 uint32_t mask;
556
557 do {
558 rc_normalize(rc);
559 rc->range >>= 1;
560 rc->code -= rc->range;
561 mask = (uint32_t)0 - (rc->code >> 31);
562 rc->code += rc->range & mask;
563 *dest = (*dest << 1) + (mask + 1);
564 } while (--limit > 0);
565}
566
567/********
568 * LZMA *
569 ********/
570
571/* Get pointer to literal coder probability array. */
572static uint16_t *lzma_literal_probs(struct xz_dec_lzma2 *s)
573{
574 uint32_t prev_byte = dict_get(&s->dict, 0);
575 uint32_t low = prev_byte >> (8 - s->lzma.lc);
576 uint32_t high = (s->dict.pos & s->lzma.literal_pos_mask) << s->lzma.lc;
577 return s->lzma.literal[low + high];
578}
579
580/* Decode a literal (one 8-bit byte) */
581static void lzma_literal(struct xz_dec_lzma2 *s)
582{
583 uint16_t *probs;
584 uint32_t symbol;
585 uint32_t match_byte;
586 uint32_t match_bit;
587 uint32_t offset;
588 uint32_t i;
589
590 probs = lzma_literal_probs(s);
591
592 if (lzma_state_is_literal(s->lzma.state)) {
593 symbol = rc_bittree(&s->rc, probs, 0x100);
594 } else {
595 symbol = 1;
596 match_byte = dict_get(&s->dict, s->lzma.rep0) << 1;
597 offset = 0x100;
598
599 do {
600 match_bit = match_byte & offset;
601 match_byte <<= 1;
602 i = offset + match_bit + symbol;
603
604 if (rc_bit(&s->rc, &probs[i])) {
605 symbol = (symbol << 1) + 1;
606 offset &= match_bit;
607 } else {
608 symbol <<= 1;
609 offset &= ~match_bit;
610 }
611 } while (symbol < 0x100);
612 }
613
614 dict_put(&s->dict, (uint8_t)symbol);
615 lzma_state_literal(&s->lzma.state);
616}
617
618/* Decode the length of the match into s->lzma.len. */
619static void lzma_len(struct xz_dec_lzma2 *s, struct lzma_len_dec *l,
620 uint32_t pos_state)
621{
622 uint16_t *probs;
623 uint32_t limit;
624
625 if (!rc_bit(&s->rc, &l->choice)) {
626 probs = l->low[pos_state];
627 limit = LEN_LOW_SYMBOLS;
628 s->lzma.len = MATCH_LEN_MIN;
629 } else {
630 if (!rc_bit(&s->rc, &l->choice2)) {
631 probs = l->mid[pos_state];
632 limit = LEN_MID_SYMBOLS;
633 s->lzma.len = MATCH_LEN_MIN + LEN_LOW_SYMBOLS;
634 } else {
635 probs = l->high;
636 limit = LEN_HIGH_SYMBOLS;
637 s->lzma.len = MATCH_LEN_MIN + LEN_LOW_SYMBOLS
638 + LEN_MID_SYMBOLS;
639 }
640 }
641
642 s->lzma.len += rc_bittree(&s->rc, probs, limit) - limit;
643}
644
645/* Decode a match. The distance will be stored in s->lzma.rep0. */
646static void lzma_match(struct xz_dec_lzma2 *s, uint32_t pos_state)
647{
648 uint16_t *probs;
649 uint32_t dist_slot;
650 uint32_t limit;
651
652 lzma_state_match(&s->lzma.state);
653
654 s->lzma.rep3 = s->lzma.rep2;
655 s->lzma.rep2 = s->lzma.rep1;
656 s->lzma.rep1 = s->lzma.rep0;
657
658 lzma_len(s, &s->lzma.match_len_dec, pos_state);
659
660 probs = s->lzma.dist_slot[lzma_get_dist_state(s->lzma.len)];
661 dist_slot = rc_bittree(&s->rc, probs, DIST_SLOTS) - DIST_SLOTS;
662
663 if (dist_slot < DIST_MODEL_START) {
664 s->lzma.rep0 = dist_slot;
665 } else {
666 limit = (dist_slot >> 1) - 1;
667 s->lzma.rep0 = 2 + (dist_slot & 1);
668
669 if (dist_slot < DIST_MODEL_END) {
670 s->lzma.rep0 <<= limit;
671 probs = s->lzma.dist_special + s->lzma.rep0
672 - dist_slot - 1;
673 rc_bittree_reverse(&s->rc, probs,
674 &s->lzma.rep0, limit);
675 } else {
676 rc_direct(&s->rc, &s->lzma.rep0, limit - ALIGN_BITS);
677 s->lzma.rep0 <<= ALIGN_BITS;
678 rc_bittree_reverse(&s->rc, s->lzma.dist_align,
679 &s->lzma.rep0, ALIGN_BITS);
680 }
681 }
682}
683
684/*
685 * Decode a repeated match. The distance is one of the four most recently
686 * seen matches. The distance will be stored in s->lzma.rep0.
687 */
688static void lzma_rep_match(struct xz_dec_lzma2 *s, uint32_t pos_state)
689{
690 uint32_t tmp;
691
692 if (!rc_bit(&s->rc, &s->lzma.is_rep0[s->lzma.state])) {
693 if (!rc_bit(&s->rc, &s->lzma.is_rep0_long[
694 s->lzma.state][pos_state])) {
695 lzma_state_short_rep(&s->lzma.state);
696 s->lzma.len = 1;
697 return;
698 }
699 } else {
700 if (!rc_bit(&s->rc, &s->lzma.is_rep1[s->lzma.state])) {
701 tmp = s->lzma.rep1;
702 } else {
703 if (!rc_bit(&s->rc, &s->lzma.is_rep2[s->lzma.state])) {
704 tmp = s->lzma.rep2;
705 } else {
706 tmp = s->lzma.rep3;
707 s->lzma.rep3 = s->lzma.rep2;
708 }
709
710 s->lzma.rep2 = s->lzma.rep1;
711 }
712
713 s->lzma.rep1 = s->lzma.rep0;
714 s->lzma.rep0 = tmp;
715 }
716
717 lzma_state_long_rep(&s->lzma.state);
718 lzma_len(s, &s->lzma.rep_len_dec, pos_state);
719}
720
721/* LZMA decoder core */
722static bool lzma_main(struct xz_dec_lzma2 *s)
723{
724 uint32_t pos_state;
725
726 /*
727 * If the dictionary was reached during the previous call, try to
728 * finish the possibly pending repeat in the dictionary.
729 */
730 if (dict_has_space(&s->dict) && s->lzma.len > 0)
731 dict_repeat(&s->dict, &s->lzma.len, s->lzma.rep0);
732
733 /*
734 * Decode more LZMA symbols. One iteration may consume up to
735 * LZMA_IN_REQUIRED - 1 bytes.
736 */
737 while (dict_has_space(&s->dict) && !rc_limit_exceeded(&s->rc)) {
738 pos_state = s->dict.pos & s->lzma.pos_mask;
739
740 if (!rc_bit(&s->rc, &s->lzma.is_match[
741 s->lzma.state][pos_state])) {
742 lzma_literal(s);
743 } else {
744 if (rc_bit(&s->rc, &s->lzma.is_rep[s->lzma.state]))
745 lzma_rep_match(s, pos_state);
746 else
747 lzma_match(s, pos_state);
748
749 if (!dict_repeat(&s->dict, &s->lzma.len, s->lzma.rep0))
750 return false;
751 }
752 }
753
754 /*
755 * Having the range decoder always normalized when we are outside
756 * this function makes it easier to correctly handle end of the chunk.
757 */
758 rc_normalize(&s->rc);
759
760 return true;
761}
762
763/*
764 * Reset the LZMA decoder and range decoder state. Dictionary is nore reset
765 * here, because LZMA state may be reset without resetting the dictionary.
766 */
767static void lzma_reset(struct xz_dec_lzma2 *s)
768{
769 uint16_t *probs;
770 size_t i;
771
772 s->lzma.state = STATE_LIT_LIT;
773 s->lzma.rep0 = 0;
774 s->lzma.rep1 = 0;
775 s->lzma.rep2 = 0;
776 s->lzma.rep3 = 0;
777
778 /*
779 * All probabilities are initialized to the same value. This hack
780 * makes the code smaller by avoiding a separate loop for each
781 * probability array.
782 *
783 * This could be optimized so that only that part of literal
784 * probabilities that are actually required. In the common case
785 * we would write 12 KiB less.
786 */
787 probs = s->lzma.is_match[0];
788 for (i = 0; i < PROBS_TOTAL; ++i)
789 probs[i] = RC_BIT_MODEL_TOTAL / 2;
790
791 rc_reset(&s->rc);
792}
793
794/*
795 * Decode and validate LZMA properties (lc/lp/pb) and calculate the bit masks
796 * from the decoded lp and pb values. On success, the LZMA decoder state is
797 * reset and true is returned.
798 */
799static bool lzma_props(struct xz_dec_lzma2 *s, uint8_t props)
800{
801 if (props > (4 * 5 + 4) * 9 + 8)
802 return false;
803
804 s->lzma.pos_mask = 0;
805 while (props >= 9 * 5) {
806 props -= 9 * 5;
807 ++s->lzma.pos_mask;
808 }
809
810 s->lzma.pos_mask = (1 << s->lzma.pos_mask) - 1;
811
812 s->lzma.literal_pos_mask = 0;
813 while (props >= 9) {
814 props -= 9;
815 ++s->lzma.literal_pos_mask;
816 }
817
818 s->lzma.lc = props;
819
820 if (s->lzma.lc + s->lzma.literal_pos_mask > 4)
821 return false;
822
823 s->lzma.literal_pos_mask = (1 << s->lzma.literal_pos_mask) - 1;
824
825 lzma_reset(s);
826
827 return true;
828}
829
830/*********
831 * LZMA2 *
832 *********/
833
834/*
835 * The LZMA decoder assumes that if the input limit (s->rc.in_limit) hasn't
836 * been exceeded, it is safe to read up to LZMA_IN_REQUIRED bytes. This
837 * wrapper function takes care of making the LZMA decoder's assumption safe.
838 *
839 * As long as there is plenty of input left to be decoded in the current LZMA
840 * chunk, we decode directly from the caller-supplied input buffer until
841 * there's LZMA_IN_REQUIRED bytes left. Those remaining bytes are copied into
842 * s->temp.buf, which (hopefully) gets filled on the next call to this
843 * function. We decode a few bytes from the temporary buffer so that we can
844 * continue decoding from the caller-supplied input buffer again.
845 */
846static bool lzma2_lzma(struct xz_dec_lzma2 *s, struct xz_buf *b)
847{
848 size_t in_avail;
849 uint32_t tmp;
850
851 in_avail = b->in_size - b->in_pos;
852 if (s->temp.size > 0 || s->lzma2.compressed == 0) {
853 tmp = 2 * LZMA_IN_REQUIRED - s->temp.size;
854 if (tmp > s->lzma2.compressed - s->temp.size)
855 tmp = s->lzma2.compressed - s->temp.size;
856 if (tmp > in_avail)
857 tmp = in_avail;
858
859 memcpy(s->temp.buf + s->temp.size, b->in + b->in_pos, tmp);
860
861 if (s->temp.size + tmp == s->lzma2.compressed) {
862 memzero(s->temp.buf + s->temp.size + tmp,
863 sizeof(s->temp.buf)
864 - s->temp.size - tmp);
865 s->rc.in_limit = s->temp.size + tmp;
866 } else if (s->temp.size + tmp < LZMA_IN_REQUIRED) {
867 s->temp.size += tmp;
868 b->in_pos += tmp;
869 return true;
870 } else {
871 s->rc.in_limit = s->temp.size + tmp - LZMA_IN_REQUIRED;
872 }
873
874 s->rc.in = s->temp.buf;
875 s->rc.in_pos = 0;
876
877 if (!lzma_main(s) || s->rc.in_pos > s->temp.size + tmp)
878 return false;
879
880 s->lzma2.compressed -= s->rc.in_pos;
881
882 if (s->rc.in_pos < s->temp.size) {
883 s->temp.size -= s->rc.in_pos;
884 memmove(s->temp.buf, s->temp.buf + s->rc.in_pos,
885 s->temp.size);
886 return true;
887 }
888
889 b->in_pos += s->rc.in_pos - s->temp.size;
890 s->temp.size = 0;
891 }
892
893 in_avail = b->in_size - b->in_pos;
894 if (in_avail >= LZMA_IN_REQUIRED) {
895 s->rc.in = b->in;
896 s->rc.in_pos = b->in_pos;
897
898 if (in_avail >= s->lzma2.compressed + LZMA_IN_REQUIRED)
899 s->rc.in_limit = b->in_pos + s->lzma2.compressed;
900 else
901 s->rc.in_limit = b->in_size - LZMA_IN_REQUIRED;
902
903 if (!lzma_main(s))
904 return false;
905
906 in_avail = s->rc.in_pos - b->in_pos;
907 if (in_avail > s->lzma2.compressed)
908 return false;
909
910 s->lzma2.compressed -= in_avail;
911 b->in_pos = s->rc.in_pos;
912 }
913
914 in_avail = b->in_size - b->in_pos;
915 if (in_avail < LZMA_IN_REQUIRED) {
916 if (in_avail > s->lzma2.compressed)
917 in_avail = s->lzma2.compressed;
918
919 memcpy(s->temp.buf, b->in + b->in_pos, in_avail);
920 s->temp.size = in_avail;
921 b->in_pos += in_avail;
922 }
923
924 return true;
925}
926
927/*
928 * Take care of the LZMA2 control layer, and forward the job of actual LZMA
929 * decoding or copying of uncompressed chunks to other functions.
930 */
931XZ_EXTERN enum xz_ret xz_dec_lzma2_run(struct xz_dec_lzma2 *s,
932 struct xz_buf *b)
933{
934 uint32_t tmp;
935
936 while (b->in_pos < b->in_size || s->lzma2.sequence == SEQ_LZMA_RUN) {
937 switch (s->lzma2.sequence) {
938 case SEQ_CONTROL:
939 /*
940 * LZMA2 control byte
941 *
942 * Exact values:
943 * 0x00 End marker
944 * 0x01 Dictionary reset followed by
945 * an uncompressed chunk
946 * 0x02 Uncompressed chunk (no dictionary reset)
947 *
948 * Highest three bits (s->control & 0xE0):
949 * 0xE0 Dictionary reset, new properties and state
950 * reset, followed by LZMA compressed chunk
951 * 0xC0 New properties and state reset, followed
952 * by LZMA compressed chunk (no dictionary
953 * reset)
954 * 0xA0 State reset using old properties,
955 * followed by LZMA compressed chunk (no
956 * dictionary reset)
957 * 0x80 LZMA chunk (no dictionary or state reset)
958 *
959 * For LZMA compressed chunks, the lowest five bits
960 * (s->control & 1F) are the highest bits of the
961 * uncompressed size (bits 16-20).
962 *
963 * A new LZMA2 stream must begin with a dictionary
964 * reset. The first LZMA chunk must set new
965 * properties and reset the LZMA state.
966 *
967 * Values that don't match anything described above
968 * are invalid and we return XZ_DATA_ERROR.
969 */
970 tmp = b->in[b->in_pos++];
971
972 if (tmp >= 0xE0 || tmp == 0x01) {
973 s->lzma2.need_props = true;
974 s->lzma2.need_dict_reset = false;
975 dict_reset(&s->dict, b);
976 } else if (s->lzma2.need_dict_reset) {
977 return XZ_DATA_ERROR;
978 }
979
980 if (tmp >= 0x80) {
981 s->lzma2.uncompressed = (tmp & 0x1F) << 16;
982 s->lzma2.sequence = SEQ_UNCOMPRESSED_1;
983
984 if (tmp >= 0xC0) {
985 /*
986 * When there are new properties,
987 * state reset is done at
988 * SEQ_PROPERTIES.
989 */
990 s->lzma2.need_props = false;
991 s->lzma2.next_sequence
992 = SEQ_PROPERTIES;
993
994 } else if (s->lzma2.need_props) {
995 return XZ_DATA_ERROR;
996
997 } else {
998 s->lzma2.next_sequence
999 = SEQ_LZMA_PREPARE;
1000 if (tmp >= 0xA0)
1001 lzma_reset(s);
1002 }
1003 } else {
1004 if (tmp == 0x00)
1005 return XZ_STREAM_END;
1006
1007 if (tmp > 0x02)
1008 return XZ_DATA_ERROR;
1009
1010 s->lzma2.sequence = SEQ_COMPRESSED_0;
1011 s->lzma2.next_sequence = SEQ_COPY;
1012 }
1013
1014 break;
1015
1016 case SEQ_UNCOMPRESSED_1:
1017 s->lzma2.uncompressed
1018 += (uint32_t)b->in[b->in_pos++] << 8;
1019 s->lzma2.sequence = SEQ_UNCOMPRESSED_2;
1020 break;
1021
1022 case SEQ_UNCOMPRESSED_2:
1023 s->lzma2.uncompressed
1024 += (uint32_t)b->in[b->in_pos++] + 1;
1025 s->lzma2.sequence = SEQ_COMPRESSED_0;
1026 break;
1027
1028 case SEQ_COMPRESSED_0:
1029 s->lzma2.compressed
1030 = (uint32_t)b->in[b->in_pos++] << 8;
1031 s->lzma2.sequence = SEQ_COMPRESSED_1;
1032 break;
1033
1034 case SEQ_COMPRESSED_1:
1035 s->lzma2.compressed
1036 += (uint32_t)b->in[b->in_pos++] + 1;
1037 s->lzma2.sequence = s->lzma2.next_sequence;
1038 break;
1039
1040 case SEQ_PROPERTIES:
1041 if (!lzma_props(s, b->in[b->in_pos++]))
1042 return XZ_DATA_ERROR;
1043
1044 s->lzma2.sequence = SEQ_LZMA_PREPARE;
1045
1046 case SEQ_LZMA_PREPARE:
1047 if (s->lzma2.compressed < RC_INIT_BYTES)
1048 return XZ_DATA_ERROR;
1049
1050 if (!rc_read_init(&s->rc, b))
1051 return XZ_OK;
1052
1053 s->lzma2.compressed -= RC_INIT_BYTES;
1054 s->lzma2.sequence = SEQ_LZMA_RUN;
1055
1056 case SEQ_LZMA_RUN:
1057 /*
1058 * Set dictionary limit to indicate how much we want
1059 * to be encoded at maximum. Decode new data into the
1060 * dictionary. Flush the new data from dictionary to
1061 * b->out. Check if we finished decoding this chunk.
1062 * In case the dictionary got full but we didn't fill
1063 * the output buffer yet, we may run this loop
1064 * multiple times without changing s->lzma2.sequence.
1065 */
1066 dict_limit(&s->dict, min_t(size_t,
1067 b->out_size - b->out_pos,
1068 s->lzma2.uncompressed));
1069 if (!lzma2_lzma(s, b))
1070 return XZ_DATA_ERROR;
1071
1072 s->lzma2.uncompressed -= dict_flush(&s->dict, b);
1073
1074 if (s->lzma2.uncompressed == 0) {
1075 if (s->lzma2.compressed > 0 || s->lzma.len > 0
1076 || !rc_is_finished(&s->rc))
1077 return XZ_DATA_ERROR;
1078
1079 rc_reset(&s->rc);
1080 s->lzma2.sequence = SEQ_CONTROL;
1081
1082 } else if (b->out_pos == b->out_size
1083 || (b->in_pos == b->in_size
1084 && s->temp.size
1085 < s->lzma2.compressed)) {
1086 return XZ_OK;
1087 }
1088
1089 break;
1090
1091 case SEQ_COPY:
1092 dict_uncompressed(&s->dict, b, &s->lzma2.compressed);
1093 if (s->lzma2.compressed > 0)
1094 return XZ_OK;
1095
1096 s->lzma2.sequence = SEQ_CONTROL;
1097 break;
1098 }
1099 }
1100
1101 return XZ_OK;
1102}
1103
1104XZ_EXTERN struct xz_dec_lzma2 *xz_dec_lzma2_create(enum xz_mode mode,
1105 uint32_t dict_max)
1106{
1107 struct xz_dec_lzma2 *s = kmalloc(sizeof(*s), GFP_KERNEL);
1108 if (s == NULL)
1109 return NULL;
1110
1111 s->dict.mode = mode;
1112 s->dict.size_max = dict_max;
1113
1114 if (DEC_IS_PREALLOC(mode)) {
1115 s->dict.buf = vmalloc(dict_max);
1116 if (s->dict.buf == NULL) {
1117 kfree(s);
1118 return NULL;
1119 }
1120 } else if (DEC_IS_DYNALLOC(mode)) {
1121 s->dict.buf = NULL;
1122 s->dict.allocated = 0;
1123 }
1124
1125 return s;
1126}
1127
1128XZ_EXTERN enum xz_ret xz_dec_lzma2_reset(struct xz_dec_lzma2 *s, uint8_t props)
1129{
1130 /* This limits dictionary size to 3 GiB to keep parsing simpler. */
1131 if (props > 39)
1132 return XZ_OPTIONS_ERROR;
1133
1134 s->dict.size = 2 + (props & 1);
1135 s->dict.size <<= (props >> 1) + 11;
1136
1137 if (DEC_IS_MULTI(s->dict.mode)) {
1138 if (s->dict.size > s->dict.size_max)
1139 return XZ_MEMLIMIT_ERROR;
1140
1141 s->dict.end = s->dict.size;
1142
1143 if (DEC_IS_DYNALLOC(s->dict.mode)) {
1144 if (s->dict.allocated < s->dict.size) {
1145 vfree(s->dict.buf);
1146 s->dict.buf = vmalloc(s->dict.size);
1147 if (s->dict.buf == NULL) {
1148 s->dict.allocated = 0;
1149 return XZ_MEM_ERROR;
1150 }
1151 }
1152 }
1153 }
1154
1155 s->lzma.len = 0;
1156
1157 s->lzma2.sequence = SEQ_CONTROL;
1158 s->lzma2.need_dict_reset = true;
1159
1160 s->temp.size = 0;
1161
1162 return XZ_OK;
1163}
1164
1165XZ_EXTERN void xz_dec_lzma2_end(struct xz_dec_lzma2 *s)
1166{
1167 if (DEC_IS_MULTI(s->dict.mode))
1168 vfree(s->dict.buf);
1169
1170 kfree(s);
1171}
diff --git a/lib/xz/xz_dec_stream.c b/lib/xz/xz_dec_stream.c
new file mode 100644
index 000000000000..ac809b1e64f7
--- /dev/null
+++ b/lib/xz/xz_dec_stream.c
@@ -0,0 +1,821 @@
1/*
2 * .xz Stream decoder
3 *
4 * Author: Lasse Collin <lasse.collin@tukaani.org>
5 *
6 * This file has been put into the public domain.
7 * You can do whatever you want with this file.
8 */
9
10#include "xz_private.h"
11#include "xz_stream.h"
12
13/* Hash used to validate the Index field */
14struct xz_dec_hash {
15 vli_type unpadded;
16 vli_type uncompressed;
17 uint32_t crc32;
18};
19
20struct xz_dec {
21 /* Position in dec_main() */
22 enum {
23 SEQ_STREAM_HEADER,
24 SEQ_BLOCK_START,
25 SEQ_BLOCK_HEADER,
26 SEQ_BLOCK_UNCOMPRESS,
27 SEQ_BLOCK_PADDING,
28 SEQ_BLOCK_CHECK,
29 SEQ_INDEX,
30 SEQ_INDEX_PADDING,
31 SEQ_INDEX_CRC32,
32 SEQ_STREAM_FOOTER
33 } sequence;
34
35 /* Position in variable-length integers and Check fields */
36 uint32_t pos;
37
38 /* Variable-length integer decoded by dec_vli() */
39 vli_type vli;
40
41 /* Saved in_pos and out_pos */
42 size_t in_start;
43 size_t out_start;
44
45 /* CRC32 value in Block or Index */
46 uint32_t crc32;
47
48 /* Type of the integrity check calculated from uncompressed data */
49 enum xz_check check_type;
50
51 /* Operation mode */
52 enum xz_mode mode;
53
54 /*
55 * True if the next call to xz_dec_run() is allowed to return
56 * XZ_BUF_ERROR.
57 */
58 bool allow_buf_error;
59
60 /* Information stored in Block Header */
61 struct {
62 /*
63 * Value stored in the Compressed Size field, or
64 * VLI_UNKNOWN if Compressed Size is not present.
65 */
66 vli_type compressed;
67
68 /*
69 * Value stored in the Uncompressed Size field, or
70 * VLI_UNKNOWN if Uncompressed Size is not present.
71 */
72 vli_type uncompressed;
73
74 /* Size of the Block Header field */
75 uint32_t size;
76 } block_header;
77
78 /* Information collected when decoding Blocks */
79 struct {
80 /* Observed compressed size of the current Block */
81 vli_type compressed;
82
83 /* Observed uncompressed size of the current Block */
84 vli_type uncompressed;
85
86 /* Number of Blocks decoded so far */
87 vli_type count;
88
89 /*
90 * Hash calculated from the Block sizes. This is used to
91 * validate the Index field.
92 */
93 struct xz_dec_hash hash;
94 } block;
95
96 /* Variables needed when verifying the Index field */
97 struct {
98 /* Position in dec_index() */
99 enum {
100 SEQ_INDEX_COUNT,
101 SEQ_INDEX_UNPADDED,
102 SEQ_INDEX_UNCOMPRESSED
103 } sequence;
104
105 /* Size of the Index in bytes */
106 vli_type size;
107
108 /* Number of Records (matches block.count in valid files) */
109 vli_type count;
110
111 /*
112 * Hash calculated from the Records (matches block.hash in
113 * valid files).
114 */
115 struct xz_dec_hash hash;
116 } index;
117
118 /*
119 * Temporary buffer needed to hold Stream Header, Block Header,
120 * and Stream Footer. The Block Header is the biggest (1 KiB)
121 * so we reserve space according to that. buf[] has to be aligned
122 * to a multiple of four bytes; the size_t variables before it
123 * should guarantee this.
124 */
125 struct {
126 size_t pos;
127 size_t size;
128 uint8_t buf[1024];
129 } temp;
130
131 struct xz_dec_lzma2 *lzma2;
132
133#ifdef XZ_DEC_BCJ
134 struct xz_dec_bcj *bcj;
135 bool bcj_active;
136#endif
137};
138
139#ifdef XZ_DEC_ANY_CHECK
140/* Sizes of the Check field with different Check IDs */
141static const uint8_t check_sizes[16] = {
142 0,
143 4, 4, 4,
144 8, 8, 8,
145 16, 16, 16,
146 32, 32, 32,
147 64, 64, 64
148};
149#endif
150
151/*
152 * Fill s->temp by copying data starting from b->in[b->in_pos]. Caller
153 * must have set s->temp.pos to indicate how much data we are supposed
154 * to copy into s->temp.buf. Return true once s->temp.pos has reached
155 * s->temp.size.
156 */
157static bool fill_temp(struct xz_dec *s, struct xz_buf *b)
158{
159 size_t copy_size = min_t(size_t,
160 b->in_size - b->in_pos, s->temp.size - s->temp.pos);
161
162 memcpy(s->temp.buf + s->temp.pos, b->in + b->in_pos, copy_size);
163 b->in_pos += copy_size;
164 s->temp.pos += copy_size;
165
166 if (s->temp.pos == s->temp.size) {
167 s->temp.pos = 0;
168 return true;
169 }
170
171 return false;
172}
173
174/* Decode a variable-length integer (little-endian base-128 encoding) */
175static enum xz_ret dec_vli(struct xz_dec *s, const uint8_t *in,
176 size_t *in_pos, size_t in_size)
177{
178 uint8_t byte;
179
180 if (s->pos == 0)
181 s->vli = 0;
182
183 while (*in_pos < in_size) {
184 byte = in[*in_pos];
185 ++*in_pos;
186
187 s->vli |= (vli_type)(byte & 0x7F) << s->pos;
188
189 if ((byte & 0x80) == 0) {
190 /* Don't allow non-minimal encodings. */
191 if (byte == 0 && s->pos != 0)
192 return XZ_DATA_ERROR;
193
194 s->pos = 0;
195 return XZ_STREAM_END;
196 }
197
198 s->pos += 7;
199 if (s->pos == 7 * VLI_BYTES_MAX)
200 return XZ_DATA_ERROR;
201 }
202
203 return XZ_OK;
204}
205
206/*
207 * Decode the Compressed Data field from a Block. Update and validate
208 * the observed compressed and uncompressed sizes of the Block so that
209 * they don't exceed the values possibly stored in the Block Header
210 * (validation assumes that no integer overflow occurs, since vli_type
211 * is normally uint64_t). Update the CRC32 if presence of the CRC32
212 * field was indicated in Stream Header.
213 *
214 * Once the decoding is finished, validate that the observed sizes match
215 * the sizes possibly stored in the Block Header. Update the hash and
216 * Block count, which are later used to validate the Index field.
217 */
218static enum xz_ret dec_block(struct xz_dec *s, struct xz_buf *b)
219{
220 enum xz_ret ret;
221
222 s->in_start = b->in_pos;
223 s->out_start = b->out_pos;
224
225#ifdef XZ_DEC_BCJ
226 if (s->bcj_active)
227 ret = xz_dec_bcj_run(s->bcj, s->lzma2, b);
228 else
229#endif
230 ret = xz_dec_lzma2_run(s->lzma2, b);
231
232 s->block.compressed += b->in_pos - s->in_start;
233 s->block.uncompressed += b->out_pos - s->out_start;
234
235 /*
236 * There is no need to separately check for VLI_UNKNOWN, since
237 * the observed sizes are always smaller than VLI_UNKNOWN.
238 */
239 if (s->block.compressed > s->block_header.compressed
240 || s->block.uncompressed
241 > s->block_header.uncompressed)
242 return XZ_DATA_ERROR;
243
244 if (s->check_type == XZ_CHECK_CRC32)
245 s->crc32 = xz_crc32(b->out + s->out_start,
246 b->out_pos - s->out_start, s->crc32);
247
248 if (ret == XZ_STREAM_END) {
249 if (s->block_header.compressed != VLI_UNKNOWN
250 && s->block_header.compressed
251 != s->block.compressed)
252 return XZ_DATA_ERROR;
253
254 if (s->block_header.uncompressed != VLI_UNKNOWN
255 && s->block_header.uncompressed
256 != s->block.uncompressed)
257 return XZ_DATA_ERROR;
258
259 s->block.hash.unpadded += s->block_header.size
260 + s->block.compressed;
261
262#ifdef XZ_DEC_ANY_CHECK
263 s->block.hash.unpadded += check_sizes[s->check_type];
264#else
265 if (s->check_type == XZ_CHECK_CRC32)
266 s->block.hash.unpadded += 4;
267#endif
268
269 s->block.hash.uncompressed += s->block.uncompressed;
270 s->block.hash.crc32 = xz_crc32(
271 (const uint8_t *)&s->block.hash,
272 sizeof(s->block.hash), s->block.hash.crc32);
273
274 ++s->block.count;
275 }
276
277 return ret;
278}
279
280/* Update the Index size and the CRC32 value. */
281static void index_update(struct xz_dec *s, const struct xz_buf *b)
282{
283 size_t in_used = b->in_pos - s->in_start;
284 s->index.size += in_used;
285 s->crc32 = xz_crc32(b->in + s->in_start, in_used, s->crc32);
286}
287
288/*
289 * Decode the Number of Records, Unpadded Size, and Uncompressed Size
290 * fields from the Index field. That is, Index Padding and CRC32 are not
291 * decoded by this function.
292 *
293 * This can return XZ_OK (more input needed), XZ_STREAM_END (everything
294 * successfully decoded), or XZ_DATA_ERROR (input is corrupt).
295 */
296static enum xz_ret dec_index(struct xz_dec *s, struct xz_buf *b)
297{
298 enum xz_ret ret;
299
300 do {
301 ret = dec_vli(s, b->in, &b->in_pos, b->in_size);
302 if (ret != XZ_STREAM_END) {
303 index_update(s, b);
304 return ret;
305 }
306
307 switch (s->index.sequence) {
308 case SEQ_INDEX_COUNT:
309 s->index.count = s->vli;
310
311 /*
312 * Validate that the Number of Records field
313 * indicates the same number of Records as
314 * there were Blocks in the Stream.
315 */
316 if (s->index.count != s->block.count)
317 return XZ_DATA_ERROR;
318
319 s->index.sequence = SEQ_INDEX_UNPADDED;
320 break;
321
322 case SEQ_INDEX_UNPADDED:
323 s->index.hash.unpadded += s->vli;
324 s->index.sequence = SEQ_INDEX_UNCOMPRESSED;
325 break;
326
327 case SEQ_INDEX_UNCOMPRESSED:
328 s->index.hash.uncompressed += s->vli;
329 s->index.hash.crc32 = xz_crc32(
330 (const uint8_t *)&s->index.hash,
331 sizeof(s->index.hash),
332 s->index.hash.crc32);
333 --s->index.count;
334 s->index.sequence = SEQ_INDEX_UNPADDED;
335 break;
336 }
337 } while (s->index.count > 0);
338
339 return XZ_STREAM_END;
340}
341
342/*
343 * Validate that the next four input bytes match the value of s->crc32.
344 * s->pos must be zero when starting to validate the first byte.
345 */
346static enum xz_ret crc32_validate(struct xz_dec *s, struct xz_buf *b)
347{
348 do {
349 if (b->in_pos == b->in_size)
350 return XZ_OK;
351
352 if (((s->crc32 >> s->pos) & 0xFF) != b->in[b->in_pos++])
353 return XZ_DATA_ERROR;
354
355 s->pos += 8;
356
357 } while (s->pos < 32);
358
359 s->crc32 = 0;
360 s->pos = 0;
361
362 return XZ_STREAM_END;
363}
364
365#ifdef XZ_DEC_ANY_CHECK
366/*
367 * Skip over the Check field when the Check ID is not supported.
368 * Returns true once the whole Check field has been skipped over.
369 */
370static bool check_skip(struct xz_dec *s, struct xz_buf *b)
371{
372 while (s->pos < check_sizes[s->check_type]) {
373 if (b->in_pos == b->in_size)
374 return false;
375
376 ++b->in_pos;
377 ++s->pos;
378 }
379
380 s->pos = 0;
381
382 return true;
383}
384#endif
385
386/* Decode the Stream Header field (the first 12 bytes of the .xz Stream). */
387static enum xz_ret dec_stream_header(struct xz_dec *s)
388{
389 if (!memeq(s->temp.buf, HEADER_MAGIC, HEADER_MAGIC_SIZE))
390 return XZ_FORMAT_ERROR;
391
392 if (xz_crc32(s->temp.buf + HEADER_MAGIC_SIZE, 2, 0)
393 != get_le32(s->temp.buf + HEADER_MAGIC_SIZE + 2))
394 return XZ_DATA_ERROR;
395
396 if (s->temp.buf[HEADER_MAGIC_SIZE] != 0)
397 return XZ_OPTIONS_ERROR;
398
399 /*
400 * Of integrity checks, we support only none (Check ID = 0) and
401 * CRC32 (Check ID = 1). However, if XZ_DEC_ANY_CHECK is defined,
402 * we will accept other check types too, but then the check won't
403 * be verified and a warning (XZ_UNSUPPORTED_CHECK) will be given.
404 */
405 s->check_type = s->temp.buf[HEADER_MAGIC_SIZE + 1];
406
407#ifdef XZ_DEC_ANY_CHECK
408 if (s->check_type > XZ_CHECK_MAX)
409 return XZ_OPTIONS_ERROR;
410
411 if (s->check_type > XZ_CHECK_CRC32)
412 return XZ_UNSUPPORTED_CHECK;
413#else
414 if (s->check_type > XZ_CHECK_CRC32)
415 return XZ_OPTIONS_ERROR;
416#endif
417
418 return XZ_OK;
419}
420
421/* Decode the Stream Footer field (the last 12 bytes of the .xz Stream) */
422static enum xz_ret dec_stream_footer(struct xz_dec *s)
423{
424 if (!memeq(s->temp.buf + 10, FOOTER_MAGIC, FOOTER_MAGIC_SIZE))
425 return XZ_DATA_ERROR;
426
427 if (xz_crc32(s->temp.buf + 4, 6, 0) != get_le32(s->temp.buf))
428 return XZ_DATA_ERROR;
429
430 /*
431 * Validate Backward Size. Note that we never added the size of the
432 * Index CRC32 field to s->index.size, thus we use s->index.size / 4
433 * instead of s->index.size / 4 - 1.
434 */
435 if ((s->index.size >> 2) != get_le32(s->temp.buf + 4))
436 return XZ_DATA_ERROR;
437
438 if (s->temp.buf[8] != 0 || s->temp.buf[9] != s->check_type)
439 return XZ_DATA_ERROR;
440
441 /*
442 * Use XZ_STREAM_END instead of XZ_OK to be more convenient
443 * for the caller.
444 */
445 return XZ_STREAM_END;
446}
447
448/* Decode the Block Header and initialize the filter chain. */
449static enum xz_ret dec_block_header(struct xz_dec *s)
450{
451 enum xz_ret ret;
452
453 /*
454 * Validate the CRC32. We know that the temp buffer is at least
455 * eight bytes so this is safe.
456 */
457 s->temp.size -= 4;
458 if (xz_crc32(s->temp.buf, s->temp.size, 0)
459 != get_le32(s->temp.buf + s->temp.size))
460 return XZ_DATA_ERROR;
461
462 s->temp.pos = 2;
463
464 /*
465 * Catch unsupported Block Flags. We support only one or two filters
466 * in the chain, so we catch that with the same test.
467 */
468#ifdef XZ_DEC_BCJ
469 if (s->temp.buf[1] & 0x3E)
470#else
471 if (s->temp.buf[1] & 0x3F)
472#endif
473 return XZ_OPTIONS_ERROR;
474
475 /* Compressed Size */
476 if (s->temp.buf[1] & 0x40) {
477 if (dec_vli(s, s->temp.buf, &s->temp.pos, s->temp.size)
478 != XZ_STREAM_END)
479 return XZ_DATA_ERROR;
480
481 s->block_header.compressed = s->vli;
482 } else {
483 s->block_header.compressed = VLI_UNKNOWN;
484 }
485
486 /* Uncompressed Size */
487 if (s->temp.buf[1] & 0x80) {
488 if (dec_vli(s, s->temp.buf, &s->temp.pos, s->temp.size)
489 != XZ_STREAM_END)
490 return XZ_DATA_ERROR;
491
492 s->block_header.uncompressed = s->vli;
493 } else {
494 s->block_header.uncompressed = VLI_UNKNOWN;
495 }
496
497#ifdef XZ_DEC_BCJ
498 /* If there are two filters, the first one must be a BCJ filter. */
499 s->bcj_active = s->temp.buf[1] & 0x01;
500 if (s->bcj_active) {
501 if (s->temp.size - s->temp.pos < 2)
502 return XZ_OPTIONS_ERROR;
503
504 ret = xz_dec_bcj_reset(s->bcj, s->temp.buf[s->temp.pos++]);
505 if (ret != XZ_OK)
506 return ret;
507
508 /*
509 * We don't support custom start offset,
510 * so Size of Properties must be zero.
511 */
512 if (s->temp.buf[s->temp.pos++] != 0x00)
513 return XZ_OPTIONS_ERROR;
514 }
515#endif
516
517 /* Valid Filter Flags always take at least two bytes. */
518 if (s->temp.size - s->temp.pos < 2)
519 return XZ_DATA_ERROR;
520
521 /* Filter ID = LZMA2 */
522 if (s->temp.buf[s->temp.pos++] != 0x21)
523 return XZ_OPTIONS_ERROR;
524
525 /* Size of Properties = 1-byte Filter Properties */
526 if (s->temp.buf[s->temp.pos++] != 0x01)
527 return XZ_OPTIONS_ERROR;
528
529 /* Filter Properties contains LZMA2 dictionary size. */
530 if (s->temp.size - s->temp.pos < 1)
531 return XZ_DATA_ERROR;
532
533 ret = xz_dec_lzma2_reset(s->lzma2, s->temp.buf[s->temp.pos++]);
534 if (ret != XZ_OK)
535 return ret;
536
537 /* The rest must be Header Padding. */
538 while (s->temp.pos < s->temp.size)
539 if (s->temp.buf[s->temp.pos++] != 0x00)
540 return XZ_OPTIONS_ERROR;
541
542 s->temp.pos = 0;
543 s->block.compressed = 0;
544 s->block.uncompressed = 0;
545
546 return XZ_OK;
547}
548
549static enum xz_ret dec_main(struct xz_dec *s, struct xz_buf *b)
550{
551 enum xz_ret ret;
552
553 /*
554 * Store the start position for the case when we are in the middle
555 * of the Index field.
556 */
557 s->in_start = b->in_pos;
558
559 while (true) {
560 switch (s->sequence) {
561 case SEQ_STREAM_HEADER:
562 /*
563 * Stream Header is copied to s->temp, and then
564 * decoded from there. This way if the caller
565 * gives us only little input at a time, we can
566 * still keep the Stream Header decoding code
567 * simple. Similar approach is used in many places
568 * in this file.
569 */
570 if (!fill_temp(s, b))
571 return XZ_OK;
572
573 /*
574 * If dec_stream_header() returns
575 * XZ_UNSUPPORTED_CHECK, it is still possible
576 * to continue decoding if working in multi-call
577 * mode. Thus, update s->sequence before calling
578 * dec_stream_header().
579 */
580 s->sequence = SEQ_BLOCK_START;
581
582 ret = dec_stream_header(s);
583 if (ret != XZ_OK)
584 return ret;
585
586 case SEQ_BLOCK_START:
587 /* We need one byte of input to continue. */
588 if (b->in_pos == b->in_size)
589 return XZ_OK;
590
591 /* See if this is the beginning of the Index field. */
592 if (b->in[b->in_pos] == 0) {
593 s->in_start = b->in_pos++;
594 s->sequence = SEQ_INDEX;
595 break;
596 }
597
598 /*
599 * Calculate the size of the Block Header and
600 * prepare to decode it.
601 */
602 s->block_header.size
603 = ((uint32_t)b->in[b->in_pos] + 1) * 4;
604
605 s->temp.size = s->block_header.size;
606 s->temp.pos = 0;
607 s->sequence = SEQ_BLOCK_HEADER;
608
609 case SEQ_BLOCK_HEADER:
610 if (!fill_temp(s, b))
611 return XZ_OK;
612
613 ret = dec_block_header(s);
614 if (ret != XZ_OK)
615 return ret;
616
617 s->sequence = SEQ_BLOCK_UNCOMPRESS;
618
619 case SEQ_BLOCK_UNCOMPRESS:
620 ret = dec_block(s, b);
621 if (ret != XZ_STREAM_END)
622 return ret;
623
624 s->sequence = SEQ_BLOCK_PADDING;
625
626 case SEQ_BLOCK_PADDING:
627 /*
628 * Size of Compressed Data + Block Padding
629 * must be a multiple of four. We don't need
630 * s->block.compressed for anything else
631 * anymore, so we use it here to test the size
632 * of the Block Padding field.
633 */
634 while (s->block.compressed & 3) {
635 if (b->in_pos == b->in_size)
636 return XZ_OK;
637
638 if (b->in[b->in_pos++] != 0)
639 return XZ_DATA_ERROR;
640
641 ++s->block.compressed;
642 }
643
644 s->sequence = SEQ_BLOCK_CHECK;
645
646 case SEQ_BLOCK_CHECK:
647 if (s->check_type == XZ_CHECK_CRC32) {
648 ret = crc32_validate(s, b);
649 if (ret != XZ_STREAM_END)
650 return ret;
651 }
652#ifdef XZ_DEC_ANY_CHECK
653 else if (!check_skip(s, b)) {
654 return XZ_OK;
655 }
656#endif
657
658 s->sequence = SEQ_BLOCK_START;
659 break;
660
661 case SEQ_INDEX:
662 ret = dec_index(s, b);
663 if (ret != XZ_STREAM_END)
664 return ret;
665
666 s->sequence = SEQ_INDEX_PADDING;
667
668 case SEQ_INDEX_PADDING:
669 while ((s->index.size + (b->in_pos - s->in_start))
670 & 3) {
671 if (b->in_pos == b->in_size) {
672 index_update(s, b);
673 return XZ_OK;
674 }
675
676 if (b->in[b->in_pos++] != 0)
677 return XZ_DATA_ERROR;
678 }
679
680 /* Finish the CRC32 value and Index size. */
681 index_update(s, b);
682
683 /* Compare the hashes to validate the Index field. */
684 if (!memeq(&s->block.hash, &s->index.hash,
685 sizeof(s->block.hash)))
686 return XZ_DATA_ERROR;
687
688 s->sequence = SEQ_INDEX_CRC32;
689
690 case SEQ_INDEX_CRC32:
691 ret = crc32_validate(s, b);
692 if (ret != XZ_STREAM_END)
693 return ret;
694
695 s->temp.size = STREAM_HEADER_SIZE;
696 s->sequence = SEQ_STREAM_FOOTER;
697
698 case SEQ_STREAM_FOOTER:
699 if (!fill_temp(s, b))
700 return XZ_OK;
701
702 return dec_stream_footer(s);
703 }
704 }
705
706 /* Never reached */
707}
708
709/*
710 * xz_dec_run() is a wrapper for dec_main() to handle some special cases in
711 * multi-call and single-call decoding.
712 *
713 * In multi-call mode, we must return XZ_BUF_ERROR when it seems clear that we
714 * are not going to make any progress anymore. This is to prevent the caller
715 * from calling us infinitely when the input file is truncated or otherwise
716 * corrupt. Since zlib-style API allows that the caller fills the input buffer
717 * only when the decoder doesn't produce any new output, we have to be careful
718 * to avoid returning XZ_BUF_ERROR too easily: XZ_BUF_ERROR is returned only
719 * after the second consecutive call to xz_dec_run() that makes no progress.
720 *
721 * In single-call mode, if we couldn't decode everything and no error
722 * occurred, either the input is truncated or the output buffer is too small.
723 * Since we know that the last input byte never produces any output, we know
724 * that if all the input was consumed and decoding wasn't finished, the file
725 * must be corrupt. Otherwise the output buffer has to be too small or the
726 * file is corrupt in a way that decoding it produces too big output.
727 *
728 * If single-call decoding fails, we reset b->in_pos and b->out_pos back to
729 * their original values. This is because with some filter chains there won't
730 * be any valid uncompressed data in the output buffer unless the decoding
731 * actually succeeds (that's the price to pay of using the output buffer as
732 * the workspace).
733 */
734XZ_EXTERN enum xz_ret xz_dec_run(struct xz_dec *s, struct xz_buf *b)
735{
736 size_t in_start;
737 size_t out_start;
738 enum xz_ret ret;
739
740 if (DEC_IS_SINGLE(s->mode))
741 xz_dec_reset(s);
742
743 in_start = b->in_pos;
744 out_start = b->out_pos;
745 ret = dec_main(s, b);
746
747 if (DEC_IS_SINGLE(s->mode)) {
748 if (ret == XZ_OK)
749 ret = b->in_pos == b->in_size
750 ? XZ_DATA_ERROR : XZ_BUF_ERROR;
751
752 if (ret != XZ_STREAM_END) {
753 b->in_pos = in_start;
754 b->out_pos = out_start;
755 }
756
757 } else if (ret == XZ_OK && in_start == b->in_pos
758 && out_start == b->out_pos) {
759 if (s->allow_buf_error)
760 ret = XZ_BUF_ERROR;
761
762 s->allow_buf_error = true;
763 } else {
764 s->allow_buf_error = false;
765 }
766
767 return ret;
768}
769
770XZ_EXTERN struct xz_dec *xz_dec_init(enum xz_mode mode, uint32_t dict_max)
771{
772 struct xz_dec *s = kmalloc(sizeof(*s), GFP_KERNEL);
773 if (s == NULL)
774 return NULL;
775
776 s->mode = mode;
777
778#ifdef XZ_DEC_BCJ
779 s->bcj = xz_dec_bcj_create(DEC_IS_SINGLE(mode));
780 if (s->bcj == NULL)
781 goto error_bcj;
782#endif
783
784 s->lzma2 = xz_dec_lzma2_create(mode, dict_max);
785 if (s->lzma2 == NULL)
786 goto error_lzma2;
787
788 xz_dec_reset(s);
789 return s;
790
791error_lzma2:
792#ifdef XZ_DEC_BCJ
793 xz_dec_bcj_end(s->bcj);
794error_bcj:
795#endif
796 kfree(s);
797 return NULL;
798}
799
800XZ_EXTERN void xz_dec_reset(struct xz_dec *s)
801{
802 s->sequence = SEQ_STREAM_HEADER;
803 s->allow_buf_error = false;
804 s->pos = 0;
805 s->crc32 = 0;
806 memzero(&s->block, sizeof(s->block));
807 memzero(&s->index, sizeof(s->index));
808 s->temp.pos = 0;
809 s->temp.size = STREAM_HEADER_SIZE;
810}
811
812XZ_EXTERN void xz_dec_end(struct xz_dec *s)
813{
814 if (s != NULL) {
815 xz_dec_lzma2_end(s->lzma2);
816#ifdef XZ_DEC_BCJ
817 xz_dec_bcj_end(s->bcj);
818#endif
819 kfree(s);
820 }
821}
diff --git a/lib/xz/xz_dec_syms.c b/lib/xz/xz_dec_syms.c
new file mode 100644
index 000000000000..32eb3c03aede
--- /dev/null
+++ b/lib/xz/xz_dec_syms.c
@@ -0,0 +1,26 @@
1/*
2 * XZ decoder module information
3 *
4 * Author: Lasse Collin <lasse.collin@tukaani.org>
5 *
6 * This file has been put into the public domain.
7 * You can do whatever you want with this file.
8 */
9
10#include <linux/module.h>
11#include <linux/xz.h>
12
13EXPORT_SYMBOL(xz_dec_init);
14EXPORT_SYMBOL(xz_dec_reset);
15EXPORT_SYMBOL(xz_dec_run);
16EXPORT_SYMBOL(xz_dec_end);
17
18MODULE_DESCRIPTION("XZ decompressor");
19MODULE_VERSION("1.0");
20MODULE_AUTHOR("Lasse Collin <lasse.collin@tukaani.org> and Igor Pavlov");
21
22/*
23 * This code is in the public domain, but in Linux it's simplest to just
24 * say it's GPL and consider the authors as the copyright holders.
25 */
26MODULE_LICENSE("GPL");
diff --git a/lib/xz/xz_dec_test.c b/lib/xz/xz_dec_test.c
new file mode 100644
index 000000000000..da28a19d6c98
--- /dev/null
+++ b/lib/xz/xz_dec_test.c
@@ -0,0 +1,220 @@
1/*
2 * XZ decoder tester
3 *
4 * Author: Lasse Collin <lasse.collin@tukaani.org>
5 *
6 * This file has been put into the public domain.
7 * You can do whatever you want with this file.
8 */
9
10#include <linux/kernel.h>
11#include <linux/module.h>
12#include <linux/fs.h>
13#include <linux/uaccess.h>
14#include <linux/crc32.h>
15#include <linux/xz.h>
16
17/* Maximum supported dictionary size */
18#define DICT_MAX (1 << 20)
19
20/* Device name to pass to register_chrdev(). */
21#define DEVICE_NAME "xz_dec_test"
22
23/* Dynamically allocated device major number */
24static int device_major;
25
26/*
27 * We reuse the same decoder state, and thus can decode only one
28 * file at a time.
29 */
30static bool device_is_open;
31
32/* XZ decoder state */
33static struct xz_dec *state;
34
35/*
36 * Return value of xz_dec_run(). We need to avoid calling xz_dec_run() after
37 * it has returned XZ_STREAM_END, so we make this static.
38 */
39static enum xz_ret ret;
40
41/*
42 * Input and output buffers. The input buffer is used as a temporary safe
43 * place for the data coming from the userspace.
44 */
45static uint8_t buffer_in[1024];
46static uint8_t buffer_out[1024];
47
48/*
49 * Structure to pass the input and output buffers to the XZ decoder.
50 * A few of the fields are never modified so we initialize them here.
51 */
52static struct xz_buf buffers = {
53 .in = buffer_in,
54 .out = buffer_out,
55 .out_size = sizeof(buffer_out)
56};
57
58/*
59 * CRC32 of uncompressed data. This is used to give the user a simple way
60 * to check that the decoder produces correct output.
61 */
62static uint32_t crc;
63
64static int xz_dec_test_open(struct inode *i, struct file *f)
65{
66 if (device_is_open)
67 return -EBUSY;
68
69 device_is_open = true;
70
71 xz_dec_reset(state);
72 ret = XZ_OK;
73 crc = 0xFFFFFFFF;
74
75 buffers.in_pos = 0;
76 buffers.in_size = 0;
77 buffers.out_pos = 0;
78
79 printk(KERN_INFO DEVICE_NAME ": opened\n");
80 return 0;
81}
82
83static int xz_dec_test_release(struct inode *i, struct file *f)
84{
85 device_is_open = false;
86
87 if (ret == XZ_OK)
88 printk(KERN_INFO DEVICE_NAME ": input was truncated\n");
89
90 printk(KERN_INFO DEVICE_NAME ": closed\n");
91 return 0;
92}
93
94/*
95 * Decode the data given to us from the userspace. CRC32 of the uncompressed
96 * data is calculated and is printed at the end of successful decoding. The
97 * uncompressed data isn't stored anywhere for further use.
98 *
99 * The .xz file must have exactly one Stream and no Stream Padding. The data
100 * after the first Stream is considered to be garbage.
101 */
102static ssize_t xz_dec_test_write(struct file *file, const char __user *buf,
103 size_t size, loff_t *pos)
104{
105 size_t remaining;
106
107 if (ret != XZ_OK) {
108 if (size > 0)
109 printk(KERN_INFO DEVICE_NAME ": %zu bytes of "
110 "garbage at the end of the file\n",
111 size);
112
113 return -ENOSPC;
114 }
115
116 printk(KERN_INFO DEVICE_NAME ": decoding %zu bytes of input\n",
117 size);
118
119 remaining = size;
120 while ((remaining > 0 || buffers.out_pos == buffers.out_size)
121 && ret == XZ_OK) {
122 if (buffers.in_pos == buffers.in_size) {
123 buffers.in_pos = 0;
124 buffers.in_size = min(remaining, sizeof(buffer_in));
125 if (copy_from_user(buffer_in, buf, buffers.in_size))
126 return -EFAULT;
127
128 buf += buffers.in_size;
129 remaining -= buffers.in_size;
130 }
131
132 buffers.out_pos = 0;
133 ret = xz_dec_run(state, &buffers);
134 crc = crc32(crc, buffer_out, buffers.out_pos);
135 }
136
137 switch (ret) {
138 case XZ_OK:
139 printk(KERN_INFO DEVICE_NAME ": XZ_OK\n");
140 return size;
141
142 case XZ_STREAM_END:
143 printk(KERN_INFO DEVICE_NAME ": XZ_STREAM_END, "
144 "CRC32 = 0x%08X\n", ~crc);
145 return size - remaining - (buffers.in_size - buffers.in_pos);
146
147 case XZ_MEMLIMIT_ERROR:
148 printk(KERN_INFO DEVICE_NAME ": XZ_MEMLIMIT_ERROR\n");
149 break;
150
151 case XZ_FORMAT_ERROR:
152 printk(KERN_INFO DEVICE_NAME ": XZ_FORMAT_ERROR\n");
153 break;
154
155 case XZ_OPTIONS_ERROR:
156 printk(KERN_INFO DEVICE_NAME ": XZ_OPTIONS_ERROR\n");
157 break;
158
159 case XZ_DATA_ERROR:
160 printk(KERN_INFO DEVICE_NAME ": XZ_DATA_ERROR\n");
161 break;
162
163 case XZ_BUF_ERROR:
164 printk(KERN_INFO DEVICE_NAME ": XZ_BUF_ERROR\n");
165 break;
166
167 default:
168 printk(KERN_INFO DEVICE_NAME ": Bug detected!\n");
169 break;
170 }
171
172 return -EIO;
173}
174
175/* Allocate the XZ decoder state and register the character device. */
176static int __init xz_dec_test_init(void)
177{
178 static const struct file_operations fileops = {
179 .owner = THIS_MODULE,
180 .open = &xz_dec_test_open,
181 .release = &xz_dec_test_release,
182 .write = &xz_dec_test_write
183 };
184
185 state = xz_dec_init(XZ_PREALLOC, DICT_MAX);
186 if (state == NULL)
187 return -ENOMEM;
188
189 device_major = register_chrdev(0, DEVICE_NAME, &fileops);
190 if (device_major < 0) {
191 xz_dec_end(state);
192 return device_major;
193 }
194
195 printk(KERN_INFO DEVICE_NAME ": module loaded\n");
196 printk(KERN_INFO DEVICE_NAME ": Create a device node with "
197 "'mknod " DEVICE_NAME " c %d 0' and write .xz files "
198 "to it.\n", device_major);
199 return 0;
200}
201
202static void __exit xz_dec_test_exit(void)
203{
204 unregister_chrdev(device_major, DEVICE_NAME);
205 xz_dec_end(state);
206 printk(KERN_INFO DEVICE_NAME ": module unloaded\n");
207}
208
209module_init(xz_dec_test_init);
210module_exit(xz_dec_test_exit);
211
212MODULE_DESCRIPTION("XZ decompressor tester");
213MODULE_VERSION("1.0");
214MODULE_AUTHOR("Lasse Collin <lasse.collin@tukaani.org>");
215
216/*
217 * This code is in the public domain, but in Linux it's simplest to just
218 * say it's GPL and consider the authors as the copyright holders.
219 */
220MODULE_LICENSE("GPL");
diff --git a/lib/xz/xz_lzma2.h b/lib/xz/xz_lzma2.h
new file mode 100644
index 000000000000..071d67bee9f5
--- /dev/null
+++ b/lib/xz/xz_lzma2.h
@@ -0,0 +1,204 @@
1/*
2 * LZMA2 definitions
3 *
4 * Authors: Lasse Collin <lasse.collin@tukaani.org>
5 * Igor Pavlov <http://7-zip.org/>
6 *
7 * This file has been put into the public domain.
8 * You can do whatever you want with this file.
9 */
10
11#ifndef XZ_LZMA2_H
12#define XZ_LZMA2_H
13
14/* Range coder constants */
15#define RC_SHIFT_BITS 8
16#define RC_TOP_BITS 24
17#define RC_TOP_VALUE (1 << RC_TOP_BITS)
18#define RC_BIT_MODEL_TOTAL_BITS 11
19#define RC_BIT_MODEL_TOTAL (1 << RC_BIT_MODEL_TOTAL_BITS)
20#define RC_MOVE_BITS 5
21
22/*
23 * Maximum number of position states. A position state is the lowest pb
24 * number of bits of the current uncompressed offset. In some places there
25 * are different sets of probabilities for different position states.
26 */
27#define POS_STATES_MAX (1 << 4)
28
29/*
30 * This enum is used to track which LZMA symbols have occurred most recently
31 * and in which order. This information is used to predict the next symbol.
32 *
33 * Symbols:
34 * - Literal: One 8-bit byte
35 * - Match: Repeat a chunk of data at some distance
36 * - Long repeat: Multi-byte match at a recently seen distance
37 * - Short repeat: One-byte repeat at a recently seen distance
38 *
39 * The symbol names are in from STATE_oldest_older_previous. REP means
40 * either short or long repeated match, and NONLIT means any non-literal.
41 */
42enum lzma_state {
43 STATE_LIT_LIT,
44 STATE_MATCH_LIT_LIT,
45 STATE_REP_LIT_LIT,
46 STATE_SHORTREP_LIT_LIT,
47 STATE_MATCH_LIT,
48 STATE_REP_LIT,
49 STATE_SHORTREP_LIT,
50 STATE_LIT_MATCH,
51 STATE_LIT_LONGREP,
52 STATE_LIT_SHORTREP,
53 STATE_NONLIT_MATCH,
54 STATE_NONLIT_REP
55};
56
57/* Total number of states */
58#define STATES 12
59
60/* The lowest 7 states indicate that the previous state was a literal. */
61#define LIT_STATES 7
62
63/* Indicate that the latest symbol was a literal. */
64static inline void lzma_state_literal(enum lzma_state *state)
65{
66 if (*state <= STATE_SHORTREP_LIT_LIT)
67 *state = STATE_LIT_LIT;
68 else if (*state <= STATE_LIT_SHORTREP)
69 *state -= 3;
70 else
71 *state -= 6;
72}
73
74/* Indicate that the latest symbol was a match. */
75static inline void lzma_state_match(enum lzma_state *state)
76{
77 *state = *state < LIT_STATES ? STATE_LIT_MATCH : STATE_NONLIT_MATCH;
78}
79
80/* Indicate that the latest state was a long repeated match. */
81static inline void lzma_state_long_rep(enum lzma_state *state)
82{
83 *state = *state < LIT_STATES ? STATE_LIT_LONGREP : STATE_NONLIT_REP;
84}
85
86/* Indicate that the latest symbol was a short match. */
87static inline void lzma_state_short_rep(enum lzma_state *state)
88{
89 *state = *state < LIT_STATES ? STATE_LIT_SHORTREP : STATE_NONLIT_REP;
90}
91
92/* Test if the previous symbol was a literal. */
93static inline bool lzma_state_is_literal(enum lzma_state state)
94{
95 return state < LIT_STATES;
96}
97
98/* Each literal coder is divided in three sections:
99 * - 0x001-0x0FF: Without match byte
100 * - 0x101-0x1FF: With match byte; match bit is 0
101 * - 0x201-0x2FF: With match byte; match bit is 1
102 *
103 * Match byte is used when the previous LZMA symbol was something else than
104 * a literal (that is, it was some kind of match).
105 */
106#define LITERAL_CODER_SIZE 0x300
107
108/* Maximum number of literal coders */
109#define LITERAL_CODERS_MAX (1 << 4)
110
111/* Minimum length of a match is two bytes. */
112#define MATCH_LEN_MIN 2
113
114/* Match length is encoded with 4, 5, or 10 bits.
115 *
116 * Length Bits
117 * 2-9 4 = Choice=0 + 3 bits
118 * 10-17 5 = Choice=1 + Choice2=0 + 3 bits
119 * 18-273 10 = Choice=1 + Choice2=1 + 8 bits
120 */
121#define LEN_LOW_BITS 3
122#define LEN_LOW_SYMBOLS (1 << LEN_LOW_BITS)
123#define LEN_MID_BITS 3
124#define LEN_MID_SYMBOLS (1 << LEN_MID_BITS)
125#define LEN_HIGH_BITS 8
126#define LEN_HIGH_SYMBOLS (1 << LEN_HIGH_BITS)
127#define LEN_SYMBOLS (LEN_LOW_SYMBOLS + LEN_MID_SYMBOLS + LEN_HIGH_SYMBOLS)
128
129/*
130 * Maximum length of a match is 273 which is a result of the encoding
131 * described above.
132 */
133#define MATCH_LEN_MAX (MATCH_LEN_MIN + LEN_SYMBOLS - 1)
134
135/*
136 * Different sets of probabilities are used for match distances that have
137 * very short match length: Lengths of 2, 3, and 4 bytes have a separate
138 * set of probabilities for each length. The matches with longer length
139 * use a shared set of probabilities.
140 */
141#define DIST_STATES 4
142
143/*
144 * Get the index of the appropriate probability array for decoding
145 * the distance slot.
146 */
147static inline uint32_t lzma_get_dist_state(uint32_t len)
148{
149 return len < DIST_STATES + MATCH_LEN_MIN
150 ? len - MATCH_LEN_MIN : DIST_STATES - 1;
151}
152
153/*
154 * The highest two bits of a 32-bit match distance are encoded using six bits.
155 * This six-bit value is called a distance slot. This way encoding a 32-bit
156 * value takes 6-36 bits, larger values taking more bits.
157 */
158#define DIST_SLOT_BITS 6
159#define DIST_SLOTS (1 << DIST_SLOT_BITS)
160
161/* Match distances up to 127 are fully encoded using probabilities. Since
162 * the highest two bits (distance slot) are always encoded using six bits,
163 * the distances 0-3 don't need any additional bits to encode, since the
164 * distance slot itself is the same as the actual distance. DIST_MODEL_START
165 * indicates the first distance slot where at least one additional bit is
166 * needed.
167 */
168#define DIST_MODEL_START 4
169
170/*
171 * Match distances greater than 127 are encoded in three pieces:
172 * - distance slot: the highest two bits
173 * - direct bits: 2-26 bits below the highest two bits
174 * - alignment bits: four lowest bits
175 *
176 * Direct bits don't use any probabilities.
177 *
178 * The distance slot value of 14 is for distances 128-191.
179 */
180#define DIST_MODEL_END 14
181
182/* Distance slots that indicate a distance <= 127. */
183#define FULL_DISTANCES_BITS (DIST_MODEL_END / 2)
184#define FULL_DISTANCES (1 << FULL_DISTANCES_BITS)
185
186/*
187 * For match distances greater than 127, only the highest two bits and the
188 * lowest four bits (alignment) is encoded using probabilities.
189 */
190#define ALIGN_BITS 4
191#define ALIGN_SIZE (1 << ALIGN_BITS)
192#define ALIGN_MASK (ALIGN_SIZE - 1)
193
194/* Total number of all probability variables */
195#define PROBS_TOTAL (1846 + LITERAL_CODERS_MAX * LITERAL_CODER_SIZE)
196
197/*
198 * LZMA remembers the four most recent match distances. Reusing these
199 * distances tends to take less space than re-encoding the actual
200 * distance value.
201 */
202#define REPS 4
203
204#endif
diff --git a/lib/xz/xz_private.h b/lib/xz/xz_private.h
new file mode 100644
index 000000000000..a65633e06962
--- /dev/null
+++ b/lib/xz/xz_private.h
@@ -0,0 +1,156 @@
1/*
2 * Private includes and definitions
3 *
4 * Author: Lasse Collin <lasse.collin@tukaani.org>
5 *
6 * This file has been put into the public domain.
7 * You can do whatever you want with this file.
8 */
9
10#ifndef XZ_PRIVATE_H
11#define XZ_PRIVATE_H
12
13#ifdef __KERNEL__
14# include <linux/xz.h>
15# include <asm/byteorder.h>
16# include <asm/unaligned.h>
17 /* XZ_PREBOOT may be defined only via decompress_unxz.c. */
18# ifndef XZ_PREBOOT
19# include <linux/slab.h>
20# include <linux/vmalloc.h>
21# include <linux/string.h>
22# ifdef CONFIG_XZ_DEC_X86
23# define XZ_DEC_X86
24# endif
25# ifdef CONFIG_XZ_DEC_POWERPC
26# define XZ_DEC_POWERPC
27# endif
28# ifdef CONFIG_XZ_DEC_IA64
29# define XZ_DEC_IA64
30# endif
31# ifdef CONFIG_XZ_DEC_ARM
32# define XZ_DEC_ARM
33# endif
34# ifdef CONFIG_XZ_DEC_ARMTHUMB
35# define XZ_DEC_ARMTHUMB
36# endif
37# ifdef CONFIG_XZ_DEC_SPARC
38# define XZ_DEC_SPARC
39# endif
40# define memeq(a, b, size) (memcmp(a, b, size) == 0)
41# define memzero(buf, size) memset(buf, 0, size)
42# endif
43# define get_le32(p) le32_to_cpup((const uint32_t *)(p))
44#else
45 /*
46 * For userspace builds, use a separate header to define the required
47 * macros and functions. This makes it easier to adapt the code into
48 * different environments and avoids clutter in the Linux kernel tree.
49 */
50# include "xz_config.h"
51#endif
52
53/* If no specific decoding mode is requested, enable support for all modes. */
54#if !defined(XZ_DEC_SINGLE) && !defined(XZ_DEC_PREALLOC) \
55 && !defined(XZ_DEC_DYNALLOC)
56# define XZ_DEC_SINGLE
57# define XZ_DEC_PREALLOC
58# define XZ_DEC_DYNALLOC
59#endif
60
61/*
62 * The DEC_IS_foo(mode) macros are used in "if" statements. If only some
63 * of the supported modes are enabled, these macros will evaluate to true or
64 * false at compile time and thus allow the compiler to omit unneeded code.
65 */
66#ifdef XZ_DEC_SINGLE
67# define DEC_IS_SINGLE(mode) ((mode) == XZ_SINGLE)
68#else
69# define DEC_IS_SINGLE(mode) (false)
70#endif
71
72#ifdef XZ_DEC_PREALLOC
73# define DEC_IS_PREALLOC(mode) ((mode) == XZ_PREALLOC)
74#else
75# define DEC_IS_PREALLOC(mode) (false)
76#endif
77
78#ifdef XZ_DEC_DYNALLOC
79# define DEC_IS_DYNALLOC(mode) ((mode) == XZ_DYNALLOC)
80#else
81# define DEC_IS_DYNALLOC(mode) (false)
82#endif
83
84#if !defined(XZ_DEC_SINGLE)
85# define DEC_IS_MULTI(mode) (true)
86#elif defined(XZ_DEC_PREALLOC) || defined(XZ_DEC_DYNALLOC)
87# define DEC_IS_MULTI(mode) ((mode) != XZ_SINGLE)
88#else
89# define DEC_IS_MULTI(mode) (false)
90#endif
91
92/*
93 * If any of the BCJ filter decoders are wanted, define XZ_DEC_BCJ.
94 * XZ_DEC_BCJ is used to enable generic support for BCJ decoders.
95 */
96#ifndef XZ_DEC_BCJ
97# if defined(XZ_DEC_X86) || defined(XZ_DEC_POWERPC) \
98 || defined(XZ_DEC_IA64) || defined(XZ_DEC_ARM) \
99 || defined(XZ_DEC_ARM) || defined(XZ_DEC_ARMTHUMB) \
100 || defined(XZ_DEC_SPARC)
101# define XZ_DEC_BCJ
102# endif
103#endif
104
105/*
106 * Allocate memory for LZMA2 decoder. xz_dec_lzma2_reset() must be used
107 * before calling xz_dec_lzma2_run().
108 */
109XZ_EXTERN struct xz_dec_lzma2 *xz_dec_lzma2_create(enum xz_mode mode,
110 uint32_t dict_max);
111
112/*
113 * Decode the LZMA2 properties (one byte) and reset the decoder. Return
114 * XZ_OK on success, XZ_MEMLIMIT_ERROR if the preallocated dictionary is not
115 * big enough, and XZ_OPTIONS_ERROR if props indicates something that this
116 * decoder doesn't support.
117 */
118XZ_EXTERN enum xz_ret xz_dec_lzma2_reset(struct xz_dec_lzma2 *s,
119 uint8_t props);
120
121/* Decode raw LZMA2 stream from b->in to b->out. */
122XZ_EXTERN enum xz_ret xz_dec_lzma2_run(struct xz_dec_lzma2 *s,
123 struct xz_buf *b);
124
125/* Free the memory allocated for the LZMA2 decoder. */
126XZ_EXTERN void xz_dec_lzma2_end(struct xz_dec_lzma2 *s);
127
128#ifdef XZ_DEC_BCJ
129/*
130 * Allocate memory for BCJ decoders. xz_dec_bcj_reset() must be used before
131 * calling xz_dec_bcj_run().
132 */
133XZ_EXTERN struct xz_dec_bcj *xz_dec_bcj_create(bool single_call);
134
135/*
136 * Decode the Filter ID of a BCJ filter. This implementation doesn't
137 * support custom start offsets, so no decoding of Filter Properties
138 * is needed. Returns XZ_OK if the given Filter ID is supported.
139 * Otherwise XZ_OPTIONS_ERROR is returned.
140 */
141XZ_EXTERN enum xz_ret xz_dec_bcj_reset(struct xz_dec_bcj *s, uint8_t id);
142
143/*
144 * Decode raw BCJ + LZMA2 stream. This must be used only if there actually is
145 * a BCJ filter in the chain. If the chain has only LZMA2, xz_dec_lzma2_run()
146 * must be called directly.
147 */
148XZ_EXTERN enum xz_ret xz_dec_bcj_run(struct xz_dec_bcj *s,
149 struct xz_dec_lzma2 *lzma2,
150 struct xz_buf *b);
151
152/* Free the memory allocated for the BCJ filters. */
153#define xz_dec_bcj_end(s) kfree(s)
154#endif
155
156#endif
diff --git a/lib/xz/xz_stream.h b/lib/xz/xz_stream.h
new file mode 100644
index 000000000000..66cb5a7055ec
--- /dev/null
+++ b/lib/xz/xz_stream.h
@@ -0,0 +1,62 @@
1/*
2 * Definitions for handling the .xz file format
3 *
4 * Author: Lasse Collin <lasse.collin@tukaani.org>
5 *
6 * This file has been put into the public domain.
7 * You can do whatever you want with this file.
8 */
9
10#ifndef XZ_STREAM_H
11#define XZ_STREAM_H
12
13#if defined(__KERNEL__) && !XZ_INTERNAL_CRC32
14# include <linux/crc32.h>
15# undef crc32
16# define xz_crc32(buf, size, crc) \
17 (~crc32_le(~(uint32_t)(crc), buf, size))
18#endif
19
20/*
21 * See the .xz file format specification at
22 * http://tukaani.org/xz/xz-file-format.txt
23 * to understand the container format.
24 */
25
26#define STREAM_HEADER_SIZE 12
27
28#define HEADER_MAGIC "\3757zXZ"
29#define HEADER_MAGIC_SIZE 6
30
31#define FOOTER_MAGIC "YZ"
32#define FOOTER_MAGIC_SIZE 2
33
34/*
35 * Variable-length integer can hold a 63-bit unsigned integer or a special
36 * value indicating that the value is unknown.
37 *
38 * Experimental: vli_type can be defined to uint32_t to save a few bytes
39 * in code size (no effect on speed). Doing so limits the uncompressed and
40 * compressed size of the file to less than 256 MiB and may also weaken
41 * error detection slightly.
42 */
43typedef uint64_t vli_type;
44
45#define VLI_MAX ((vli_type)-1 / 2)
46#define VLI_UNKNOWN ((vli_type)-1)
47
48/* Maximum encoded size of a VLI */
49#define VLI_BYTES_MAX (sizeof(vli_type) * 8 / 7)
50
51/* Integrity Check types */
52enum xz_check {
53 XZ_CHECK_NONE = 0,
54 XZ_CHECK_CRC32 = 1,
55 XZ_CHECK_CRC64 = 4,
56 XZ_CHECK_SHA256 = 10
57};
58
59/* Maximum possible Check ID */
60#define XZ_CHECK_MAX 15
61
62#endif
diff --git a/mm/page-writeback.c b/mm/page-writeback.c
index b4edfe7ce06c..b5d8a1f820a0 100644
--- a/mm/page-writeback.c
+++ b/mm/page-writeback.c
@@ -404,7 +404,7 @@ unsigned long determine_dirtyable_memory(void)
404 * - vm.dirty_background_ratio or vm.dirty_background_bytes 404 * - vm.dirty_background_ratio or vm.dirty_background_bytes
405 * - vm.dirty_ratio or vm.dirty_bytes 405 * - vm.dirty_ratio or vm.dirty_bytes
406 * The dirty limits will be lifted by 1/4 for PF_LESS_THROTTLE (ie. nfsd) and 406 * The dirty limits will be lifted by 1/4 for PF_LESS_THROTTLE (ie. nfsd) and
407 * runtime tasks. 407 * real-time tasks.
408 */ 408 */
409void global_dirty_limits(unsigned long *pbackground, unsigned long *pdirty) 409void global_dirty_limits(unsigned long *pbackground, unsigned long *pdirty)
410{ 410{
diff --git a/mm/page_alloc.c b/mm/page_alloc.c
index ff7e15872398..826ba6922e84 100644
--- a/mm/page_alloc.c
+++ b/mm/page_alloc.c
@@ -4014,7 +4014,7 @@ static void __init setup_usemap(struct pglist_data *pgdat,
4014 zone->pageblock_flags = alloc_bootmem_node(pgdat, usemapsize); 4014 zone->pageblock_flags = alloc_bootmem_node(pgdat, usemapsize);
4015} 4015}
4016#else 4016#else
4017static void inline setup_usemap(struct pglist_data *pgdat, 4017static inline void setup_usemap(struct pglist_data *pgdat,
4018 struct zone *zone, unsigned long zonesize) {} 4018 struct zone *zone, unsigned long zonesize) {}
4019#endif /* CONFIG_SPARSEMEM */ 4019#endif /* CONFIG_SPARSEMEM */
4020 4020
diff --git a/mm/percpu.c b/mm/percpu.c
index 3dd4984bdef8..3f930018aa60 100644
--- a/mm/percpu.c
+++ b/mm/percpu.c
@@ -258,7 +258,7 @@ static void __maybe_unused pcpu_next_pop(struct pcpu_chunk *chunk,
258 258
259/* 259/*
260 * (Un)populated page region iterators. Iterate over (un)populated 260 * (Un)populated page region iterators. Iterate over (un)populated
261 * page regions betwen @start and @end in @chunk. @rs and @re should 261 * page regions between @start and @end in @chunk. @rs and @re should
262 * be integer variables and will be set to start and end page index of 262 * be integer variables and will be set to start and end page index of
263 * the current region. 263 * the current region.
264 */ 264 */
diff --git a/mm/rmap.c b/mm/rmap.c
index 1a8bf76bfd03..c95d2ba27a0b 100644
--- a/mm/rmap.c
+++ b/mm/rmap.c
@@ -94,7 +94,7 @@ static void anon_vma_chain_free(struct anon_vma_chain *anon_vma_chain)
94 * anonymous pages mapped into it with that anon_vma. 94 * anonymous pages mapped into it with that anon_vma.
95 * 95 *
96 * The common case will be that we already have one, but if 96 * The common case will be that we already have one, but if
97 * if not we either need to find an adjacent mapping that we 97 * not we either need to find an adjacent mapping that we
98 * can re-use the anon_vma from (very common when the only 98 * can re-use the anon_vma from (very common when the only
99 * reason for splitting a vma has been mprotect()), or we 99 * reason for splitting a vma has been mprotect()), or we
100 * allocate a new one. 100 * allocate a new one.
diff --git a/mm/sparse-vmemmap.c b/mm/sparse-vmemmap.c
index 29d6cbffb283..64b984091edb 100644
--- a/mm/sparse-vmemmap.c
+++ b/mm/sparse-vmemmap.c
@@ -9,7 +9,7 @@
9 * 9 *
10 * However, virtual mappings need a page table and TLBs. Many Linux 10 * However, virtual mappings need a page table and TLBs. Many Linux
11 * architectures already map their physical space using 1-1 mappings 11 * architectures already map their physical space using 1-1 mappings
12 * via TLBs. For those arches the virtual memmory map is essentially 12 * via TLBs. For those arches the virtual memory map is essentially
13 * for free if we use the same page size as the 1-1 mappings. In that 13 * for free if we use the same page size as the 1-1 mappings. In that
14 * case the overhead consists of a few additional pages that are 14 * case the overhead consists of a few additional pages that are
15 * allocated to create a view of memory for vmemmap. 15 * allocated to create a view of memory for vmemmap.
diff --git a/net/Kconfig b/net/Kconfig
index ad0aafe903f8..72840626284b 100644
--- a/net/Kconfig
+++ b/net/Kconfig
@@ -253,7 +253,9 @@ config NET_TCPPROBE
253 what was just said, you don't need it: say N. 253 what was just said, you don't need it: say N.
254 254
255 Documentation on how to use TCP connection probing can be found 255 Documentation on how to use TCP connection probing can be found
256 at http://linux-net.osdl.org/index.php/TcpProbe 256 at:
257
258 http://www.linuxfoundation.org/collaborate/workgroups/networking/tcpprobe
257 259
258 To compile this code as a module, choose M here: the 260 To compile this code as a module, choose M here: the
259 module will be called tcp_probe. 261 module will be called tcp_probe.
diff --git a/net/ceph/ceph_hash.c b/net/ceph/ceph_hash.c
index 815ef8826796..0a1b53bce76d 100644
--- a/net/ceph/ceph_hash.c
+++ b/net/ceph/ceph_hash.c
@@ -1,5 +1,6 @@
1 1
2#include <linux/ceph/types.h> 2#include <linux/ceph/types.h>
3#include <linux/module.h>
3 4
4/* 5/*
5 * Robert Jenkin's hash function. 6 * Robert Jenkin's hash function.
@@ -104,6 +105,7 @@ unsigned ceph_str_hash(int type, const char *s, unsigned len)
104 return -1; 105 return -1;
105 } 106 }
106} 107}
108EXPORT_SYMBOL(ceph_str_hash);
107 109
108const char *ceph_str_hash_name(int type) 110const char *ceph_str_hash_name(int type)
109{ 111{
@@ -116,3 +118,4 @@ const char *ceph_str_hash_name(int type)
116 return "unknown"; 118 return "unknown";
117 } 119 }
118} 120}
121EXPORT_SYMBOL(ceph_str_hash_name);
diff --git a/net/ceph/messenger.c b/net/ceph/messenger.c
index b6ff4a1519ab..dff633d62e5b 100644
--- a/net/ceph/messenger.c
+++ b/net/ceph/messenger.c
@@ -96,7 +96,7 @@ struct workqueue_struct *ceph_msgr_wq;
96 96
97int ceph_msgr_init(void) 97int ceph_msgr_init(void)
98{ 98{
99 ceph_msgr_wq = create_workqueue("ceph-msgr"); 99 ceph_msgr_wq = alloc_workqueue("ceph-msgr", WQ_NON_REENTRANT, 0);
100 if (!ceph_msgr_wq) { 100 if (!ceph_msgr_wq) {
101 pr_err("msgr_init failed to create workqueue\n"); 101 pr_err("msgr_init failed to create workqueue\n");
102 return -ENOMEM; 102 return -ENOMEM;
@@ -1920,20 +1920,6 @@ bad_tag:
1920/* 1920/*
1921 * Atomically queue work on a connection. Bump @con reference to 1921 * Atomically queue work on a connection. Bump @con reference to
1922 * avoid races with connection teardown. 1922 * avoid races with connection teardown.
1923 *
1924 * There is some trickery going on with QUEUED and BUSY because we
1925 * only want a _single_ thread operating on each connection at any
1926 * point in time, but we want to use all available CPUs.
1927 *
1928 * The worker thread only proceeds if it can atomically set BUSY. It
1929 * clears QUEUED and does it's thing. When it thinks it's done, it
1930 * clears BUSY, then rechecks QUEUED.. if it's set again, it loops
1931 * (tries again to set BUSY).
1932 *
1933 * To queue work, we first set QUEUED, _then_ if BUSY isn't set, we
1934 * try to queue work. If that fails (work is already queued, or BUSY)
1935 * we give up (work also already being done or is queued) but leave QUEUED
1936 * set so that the worker thread will loop if necessary.
1937 */ 1923 */
1938static void queue_con(struct ceph_connection *con) 1924static void queue_con(struct ceph_connection *con)
1939{ 1925{
@@ -1948,11 +1934,7 @@ static void queue_con(struct ceph_connection *con)
1948 return; 1934 return;
1949 } 1935 }
1950 1936
1951 set_bit(QUEUED, &con->state); 1937 if (!queue_delayed_work(ceph_msgr_wq, &con->work, 0)) {
1952 if (test_bit(BUSY, &con->state)) {
1953 dout("queue_con %p - already BUSY\n", con);
1954 con->ops->put(con);
1955 } else if (!queue_work(ceph_msgr_wq, &con->work.work)) {
1956 dout("queue_con %p - already queued\n", con); 1938 dout("queue_con %p - already queued\n", con);
1957 con->ops->put(con); 1939 con->ops->put(con);
1958 } else { 1940 } else {
@@ -1967,15 +1949,6 @@ static void con_work(struct work_struct *work)
1967{ 1949{
1968 struct ceph_connection *con = container_of(work, struct ceph_connection, 1950 struct ceph_connection *con = container_of(work, struct ceph_connection,
1969 work.work); 1951 work.work);
1970 int backoff = 0;
1971
1972more:
1973 if (test_and_set_bit(BUSY, &con->state) != 0) {
1974 dout("con_work %p BUSY already set\n", con);
1975 goto out;
1976 }
1977 dout("con_work %p start, clearing QUEUED\n", con);
1978 clear_bit(QUEUED, &con->state);
1979 1952
1980 mutex_lock(&con->mutex); 1953 mutex_lock(&con->mutex);
1981 1954
@@ -1994,28 +1967,13 @@ more:
1994 try_read(con) < 0 || 1967 try_read(con) < 0 ||
1995 try_write(con) < 0) { 1968 try_write(con) < 0) {
1996 mutex_unlock(&con->mutex); 1969 mutex_unlock(&con->mutex);
1997 backoff = 1;
1998 ceph_fault(con); /* error/fault path */ 1970 ceph_fault(con); /* error/fault path */
1999 goto done_unlocked; 1971 goto done_unlocked;
2000 } 1972 }
2001 1973
2002done: 1974done:
2003 mutex_unlock(&con->mutex); 1975 mutex_unlock(&con->mutex);
2004
2005done_unlocked: 1976done_unlocked:
2006 clear_bit(BUSY, &con->state);
2007 dout("con->state=%lu\n", con->state);
2008 if (test_bit(QUEUED, &con->state)) {
2009 if (!backoff || test_bit(OPENING, &con->state)) {
2010 dout("con_work %p QUEUED reset, looping\n", con);
2011 goto more;
2012 }
2013 dout("con_work %p QUEUED reset, but just faulted\n", con);
2014 clear_bit(QUEUED, &con->state);
2015 }
2016 dout("con_work %p done\n", con);
2017
2018out:
2019 con->ops->put(con); 1977 con->ops->put(con);
2020} 1978}
2021 1979
diff --git a/net/ceph/osdmap.c b/net/ceph/osdmap.c
index d73f3f6efa36..71603ac3dff5 100644
--- a/net/ceph/osdmap.c
+++ b/net/ceph/osdmap.c
@@ -605,8 +605,10 @@ struct ceph_osdmap *osdmap_decode(void **p, void *end)
605 goto bad; 605 goto bad;
606 } 606 }
607 err = __decode_pool(p, end, pi); 607 err = __decode_pool(p, end, pi);
608 if (err < 0) 608 if (err < 0) {
609 kfree(pi);
609 goto bad; 610 goto bad;
611 }
610 __insert_pg_pool(&map->pg_pools, pi); 612 __insert_pg_pool(&map->pg_pools, pi);
611 } 613 }
612 614
diff --git a/net/core/dev.c b/net/core/dev.c
index a3ef808b5e36..06d0e7b25385 100644
--- a/net/core/dev.c
+++ b/net/core/dev.c
@@ -6218,7 +6218,7 @@ static void __net_exit default_device_exit(struct net *net)
6218static void __net_exit default_device_exit_batch(struct list_head *net_list) 6218static void __net_exit default_device_exit_batch(struct list_head *net_list)
6219{ 6219{
6220 /* At exit all network devices most be removed from a network 6220 /* At exit all network devices most be removed from a network
6221 * namespace. Do this in the reverse order of registeration. 6221 * namespace. Do this in the reverse order of registration.
6222 * Do this across as many network namespaces as possible to 6222 * Do this across as many network namespaces as possible to
6223 * improve batching efficiency. 6223 * improve batching efficiency.
6224 */ 6224 */
diff --git a/net/core/sock.c b/net/core/sock.c
index a658aeb6d554..7dfed792434d 100644
--- a/net/core/sock.c
+++ b/net/core/sock.c
@@ -157,7 +157,7 @@ static const char *const af_family_key_strings[AF_MAX+1] = {
157 "sk_lock-27" , "sk_lock-28" , "sk_lock-AF_CAN" , 157 "sk_lock-27" , "sk_lock-28" , "sk_lock-AF_CAN" ,
158 "sk_lock-AF_TIPC" , "sk_lock-AF_BLUETOOTH", "sk_lock-IUCV" , 158 "sk_lock-AF_TIPC" , "sk_lock-AF_BLUETOOTH", "sk_lock-IUCV" ,
159 "sk_lock-AF_RXRPC" , "sk_lock-AF_ISDN" , "sk_lock-AF_PHONET" , 159 "sk_lock-AF_RXRPC" , "sk_lock-AF_ISDN" , "sk_lock-AF_PHONET" ,
160 "sk_lock-AF_IEEE802154", "sk_lock-AF_CAIF" , 160 "sk_lock-AF_IEEE802154", "sk_lock-AF_CAIF" , "sk_lock-AF_ALG" ,
161 "sk_lock-AF_MAX" 161 "sk_lock-AF_MAX"
162}; 162};
163static const char *const af_family_slock_key_strings[AF_MAX+1] = { 163static const char *const af_family_slock_key_strings[AF_MAX+1] = {
@@ -173,7 +173,7 @@ static const char *const af_family_slock_key_strings[AF_MAX+1] = {
173 "slock-27" , "slock-28" , "slock-AF_CAN" , 173 "slock-27" , "slock-28" , "slock-AF_CAN" ,
174 "slock-AF_TIPC" , "slock-AF_BLUETOOTH", "slock-AF_IUCV" , 174 "slock-AF_TIPC" , "slock-AF_BLUETOOTH", "slock-AF_IUCV" ,
175 "slock-AF_RXRPC" , "slock-AF_ISDN" , "slock-AF_PHONET" , 175 "slock-AF_RXRPC" , "slock-AF_ISDN" , "slock-AF_PHONET" ,
176 "slock-AF_IEEE802154", "slock-AF_CAIF" , 176 "slock-AF_IEEE802154", "slock-AF_CAIF" , "slock-AF_ALG" ,
177 "slock-AF_MAX" 177 "slock-AF_MAX"
178}; 178};
179static const char *const af_family_clock_key_strings[AF_MAX+1] = { 179static const char *const af_family_clock_key_strings[AF_MAX+1] = {
@@ -189,7 +189,7 @@ static const char *const af_family_clock_key_strings[AF_MAX+1] = {
189 "clock-27" , "clock-28" , "clock-AF_CAN" , 189 "clock-27" , "clock-28" , "clock-AF_CAN" ,
190 "clock-AF_TIPC" , "clock-AF_BLUETOOTH", "clock-AF_IUCV" , 190 "clock-AF_TIPC" , "clock-AF_BLUETOOTH", "clock-AF_IUCV" ,
191 "clock-AF_RXRPC" , "clock-AF_ISDN" , "clock-AF_PHONET" , 191 "clock-AF_RXRPC" , "clock-AF_ISDN" , "clock-AF_PHONET" ,
192 "clock-AF_IEEE802154", "clock-AF_CAIF" , 192 "clock-AF_IEEE802154", "clock-AF_CAIF" , "clock-AF_ALG" ,
193 "clock-AF_MAX" 193 "clock-AF_MAX"
194}; 194};
195 195
diff --git a/net/dccp/Kconfig b/net/dccp/Kconfig
index ad6dffd9070e..b75968a04017 100644
--- a/net/dccp/Kconfig
+++ b/net/dccp/Kconfig
@@ -49,7 +49,9 @@ config NET_DCCPPROBE
49 what was just said, you don't need it: say N. 49 what was just said, you don't need it: say N.
50 50
51 Documentation on how to use DCCP connection probing can be found 51 Documentation on how to use DCCP connection probing can be found
52 at http://linux-net.osdl.org/index.php/DccpProbe 52 at:
53
54 http://www.linuxfoundation.org/collaborate/workgroups/networking/dccpprobe
53 55
54 To compile this code as a module, choose M here: the 56 To compile this code as a module, choose M here: the
55 module will be called dccp_probe. 57 module will be called dccp_probe.
diff --git a/net/decnet/dn_dev.c b/net/decnet/dn_dev.c
index 0ba15633c418..0dcaa903e00e 100644
--- a/net/decnet/dn_dev.c
+++ b/net/decnet/dn_dev.c
@@ -1130,7 +1130,7 @@ static struct dn_dev *dn_dev_create(struct net_device *dev, int *err)
1130/* 1130/*
1131 * This processes a device up event. We only start up 1131 * This processes a device up event. We only start up
1132 * the loopback device & ethernet devices with correct 1132 * the loopback device & ethernet devices with correct
1133 * MAC addreses automatically. Others must be started 1133 * MAC addresses automatically. Others must be started
1134 * specifically. 1134 * specifically.
1135 * 1135 *
1136 * FIXME: How should we configure the loopback address ? If we could dispense 1136 * FIXME: How should we configure the loopback address ? If we could dispense
diff --git a/net/ipv4/Kconfig b/net/ipv4/Kconfig
index 9e95d7fb6d5a..a5a1050595d1 100644
--- a/net/ipv4/Kconfig
+++ b/net/ipv4/Kconfig
@@ -432,7 +432,9 @@ config INET_DIAG
432 ---help--- 432 ---help---
433 Support for INET (TCP, DCCP, etc) socket monitoring interface used by 433 Support for INET (TCP, DCCP, etc) socket monitoring interface used by
434 native Linux tools such as ss. ss is included in iproute2, currently 434 native Linux tools such as ss. ss is included in iproute2, currently
435 downloadable at <http://linux-net.osdl.org/index.php/Iproute2>. 435 downloadable at:
436
437 http://www.linuxfoundation.org/collaborate/workgroups/networking/iproute2
436 438
437 If unsure, say Y. 439 If unsure, say Y.
438 440
diff --git a/net/ipv4/tcp_output.c b/net/ipv4/tcp_output.c
index dc7c096ddfef..406f320336e6 100644
--- a/net/ipv4/tcp_output.c
+++ b/net/ipv4/tcp_output.c
@@ -1350,7 +1350,7 @@ static inline unsigned int tcp_cwnd_test(struct tcp_sock *tp,
1350 return 0; 1350 return 0;
1351} 1351}
1352 1352
1353/* Intialize TSO state of a skb. 1353/* Initialize TSO state of a skb.
1354 * This must be invoked the first time we consider transmitting 1354 * This must be invoked the first time we consider transmitting
1355 * SKB onto the wire. 1355 * SKB onto the wire.
1356 */ 1356 */
diff --git a/net/ipv6/af_inet6.c b/net/ipv6/af_inet6.c
index 059a3de647db..978e80e2c4a8 100644
--- a/net/ipv6/af_inet6.c
+++ b/net/ipv6/af_inet6.c
@@ -300,7 +300,7 @@ int inet6_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len)
300 goto out; 300 goto out;
301 } 301 }
302 302
303 /* Reproduce AF_INET checks to make the bindings consitant */ 303 /* Reproduce AF_INET checks to make the bindings consistent */
304 v4addr = addr->sin6_addr.s6_addr32[3]; 304 v4addr = addr->sin6_addr.s6_addr32[3];
305 chk_addr_ret = inet_addr_type(net, v4addr); 305 chk_addr_ret = inet_addr_type(net, v4addr);
306 if (!sysctl_ip_nonlocal_bind && 306 if (!sysctl_ip_nonlocal_bind &&
diff --git a/net/sched/Kconfig b/net/sched/Kconfig
index a36270a994d7..f04d4a484d53 100644
--- a/net/sched/Kconfig
+++ b/net/sched/Kconfig
@@ -24,7 +24,7 @@ menuconfig NET_SCHED
24 To administer these schedulers, you'll need the user-level utilities 24 To administer these schedulers, you'll need the user-level utilities
25 from the package iproute2+tc at <ftp://ftp.tux.org/pub/net/ip-routing/>. 25 from the package iproute2+tc at <ftp://ftp.tux.org/pub/net/ip-routing/>.
26 That package also contains some documentation; for more, check out 26 That package also contains some documentation; for more, check out
27 <http://linux-net.osdl.org/index.php/Iproute2>. 27 <http://www.linuxfoundation.org/collaborate/workgroups/networking/iproute2>.
28 28
29 This Quality of Service (QoS) support will enable you to use 29 This Quality of Service (QoS) support will enable you to use
30 Differentiated Services (diffserv) and Resource Reservation Protocol 30 Differentiated Services (diffserv) and Resource Reservation Protocol
diff --git a/net/socket.c b/net/socket.c
index ccc576a6a508..ac2219f90d5d 100644
--- a/net/socket.c
+++ b/net/socket.c
@@ -306,20 +306,6 @@ static const struct super_operations sockfs_ops = {
306 .statfs = simple_statfs, 306 .statfs = simple_statfs,
307}; 307};
308 308
309static struct dentry *sockfs_mount(struct file_system_type *fs_type,
310 int flags, const char *dev_name, void *data)
311{
312 return mount_pseudo(fs_type, "socket:", &sockfs_ops, SOCKFS_MAGIC);
313}
314
315static struct vfsmount *sock_mnt __read_mostly;
316
317static struct file_system_type sock_fs_type = {
318 .name = "sockfs",
319 .mount = sockfs_mount,
320 .kill_sb = kill_anon_super,
321};
322
323/* 309/*
324 * sockfs_dname() is called from d_path(). 310 * sockfs_dname() is called from d_path().
325 */ 311 */
@@ -333,6 +319,21 @@ static const struct dentry_operations sockfs_dentry_operations = {
333 .d_dname = sockfs_dname, 319 .d_dname = sockfs_dname,
334}; 320};
335 321
322static struct dentry *sockfs_mount(struct file_system_type *fs_type,
323 int flags, const char *dev_name, void *data)
324{
325 return mount_pseudo(fs_type, "socket:", &sockfs_ops,
326 &sockfs_dentry_operations, SOCKFS_MAGIC);
327}
328
329static struct vfsmount *sock_mnt __read_mostly;
330
331static struct file_system_type sock_fs_type = {
332 .name = "sockfs",
333 .mount = sockfs_mount,
334 .kill_sb = kill_anon_super,
335};
336
336/* 337/*
337 * Obtains the first available file descriptor and sets it up for use. 338 * Obtains the first available file descriptor and sets it up for use.
338 * 339 *
@@ -368,7 +369,6 @@ static int sock_alloc_file(struct socket *sock, struct file **f, int flags)
368 } 369 }
369 path.mnt = mntget(sock_mnt); 370 path.mnt = mntget(sock_mnt);
370 371
371 d_set_d_op(path.dentry, &sockfs_dentry_operations);
372 d_instantiate(path.dentry, SOCK_INODE(sock)); 372 d_instantiate(path.dentry, SOCK_INODE(sock));
373 SOCK_INODE(sock)->i_fop = &socket_file_ops; 373 SOCK_INODE(sock)->i_fop = &socket_file_ops;
374 374
diff --git a/scripts/Makefile.lib b/scripts/Makefile.lib
index 396da16aabf8..1c702ca8aac8 100644
--- a/scripts/Makefile.lib
+++ b/scripts/Makefile.lib
@@ -262,6 +262,34 @@ cmd_lzo = (cat $(filter-out FORCE,$^) | \
262 lzop -9 && $(call size_append, $(filter-out FORCE,$^))) > $@ || \ 262 lzop -9 && $(call size_append, $(filter-out FORCE,$^))) > $@ || \
263 (rm -f $@ ; false) 263 (rm -f $@ ; false)
264 264
265# XZ
266# ---------------------------------------------------------------------------
267# Use xzkern to compress the kernel image and xzmisc to compress other things.
268#
269# xzkern uses a big LZMA2 dictionary since it doesn't increase memory usage
270# of the kernel decompressor. A BCJ filter is used if it is available for
271# the target architecture. xzkern also appends uncompressed size of the data
272# using size_append. The .xz format has the size information available at
273# the end of the file too, but it's in more complex format and it's good to
274# avoid changing the part of the boot code that reads the uncompressed size.
275# Note that the bytes added by size_append will make the xz tool think that
276# the file is corrupt. This is expected.
277#
278# xzmisc doesn't use size_append, so it can be used to create normal .xz
279# files. xzmisc uses smaller LZMA2 dictionary than xzkern, because a very
280# big dictionary would increase the memory usage too much in the multi-call
281# decompression mode. A BCJ filter isn't used either.
282quiet_cmd_xzkern = XZKERN $@
283cmd_xzkern = (cat $(filter-out FORCE,$^) | \
284 sh $(srctree)/scripts/xz_wrap.sh && \
285 $(call size_append, $(filter-out FORCE,$^))) > $@ || \
286 (rm -f $@ ; false)
287
288quiet_cmd_xzmisc = XZMISC $@
289cmd_xzmisc = (cat $(filter-out FORCE,$^) | \
290 xz --check=crc32 --lzma2=dict=1MiB) > $@ || \
291 (rm -f $@ ; false)
292
265# misc stuff 293# misc stuff
266# --------------------------------------------------------------------------- 294# ---------------------------------------------------------------------------
267quote:=" 295quote:="
diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index e3c7fc0dca38..4c0383da1c9a 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -859,7 +859,7 @@ sub annotate_values {
859 $av_preprocessor = 0; 859 $av_preprocessor = 0;
860 } 860 }
861 861
862 } elsif ($cur =~ /^(\(\s*$Type\s*)\)/) { 862 } elsif ($cur =~ /^(\(\s*$Type\s*)\)/ && $av_pending eq '_') {
863 print "CAST($1)\n" if ($dbg_values > 1); 863 print "CAST($1)\n" if ($dbg_values > 1);
864 push(@av_paren_type, $type); 864 push(@av_paren_type, $type);
865 $type = 'C'; 865 $type = 'C';
@@ -2743,6 +2743,11 @@ sub process {
2743 WARN("plain inline is preferred over $1\n" . $herecurr); 2743 WARN("plain inline is preferred over $1\n" . $herecurr);
2744 } 2744 }
2745 2745
2746# Check for __attribute__ packed, prefer __packed
2747 if ($line =~ /\b__attribute__\s*\(\s*\(.*\bpacked\b/) {
2748 WARN("__packed is preferred over __attribute__((packed))\n" . $herecurr);
2749 }
2750
2746# check for sizeof(&) 2751# check for sizeof(&)
2747 if ($line =~ /\bsizeof\s*\(\s*\&/) { 2752 if ($line =~ /\bsizeof\s*\(\s*\&/) {
2748 WARN("sizeof(& should be avoided\n" . $herecurr); 2753 WARN("sizeof(& should be avoided\n" . $herecurr);
@@ -2785,10 +2790,15 @@ sub process {
2785 } 2790 }
2786 2791
2787# check for pointless casting of kmalloc return 2792# check for pointless casting of kmalloc return
2788 if ($line =~ /\*\s*\)\s*k[czm]alloc\b/) { 2793 if ($line =~ /\*\s*\)\s*[kv][czm]alloc(_node){0,1}\b/) {
2789 WARN("unnecessary cast may hide bugs, see http://c-faq.com/malloc/mallocnocast.html\n" . $herecurr); 2794 WARN("unnecessary cast may hide bugs, see http://c-faq.com/malloc/mallocnocast.html\n" . $herecurr);
2790 } 2795 }
2791 2796
2797# check for multiple semicolons
2798 if ($line =~ /;\s*;\s*$/) {
2799 WARN("Statements terminations use 1 semicolon\n" . $herecurr);
2800 }
2801
2792# check for gcc specific __FUNCTION__ 2802# check for gcc specific __FUNCTION__
2793 if ($line =~ /__FUNCTION__/) { 2803 if ($line =~ /__FUNCTION__/) {
2794 WARN("__func__ should be used instead of gcc specific __FUNCTION__\n" . $herecurr); 2804 WARN("__func__ should be used instead of gcc specific __FUNCTION__\n" . $herecurr);
@@ -2892,6 +2902,11 @@ sub process {
2892 ERROR("lockdep_no_validate class is reserved for device->mutex.\n" . $herecurr); 2902 ERROR("lockdep_no_validate class is reserved for device->mutex.\n" . $herecurr);
2893 } 2903 }
2894 } 2904 }
2905
2906 if ($line =~ /debugfs_create_file.*S_IWUGO/ ||
2907 $line =~ /DEVICE_ATTR.*S_IWUGO/ ) {
2908 WARN("Exporting world writable files is usually an error. Consider more restrictive permissions.\n" . $herecurr);
2909 }
2895 } 2910 }
2896 2911
2897 # If we have no input at all, then there is nothing to report on 2912 # If we have no input at all, then there is nothing to report on
diff --git a/scripts/gen_initramfs_list.sh b/scripts/gen_initramfs_list.sh
index 5958fffb2114..55caecdad995 100644
--- a/scripts/gen_initramfs_list.sh
+++ b/scripts/gen_initramfs_list.sh
@@ -243,6 +243,8 @@ case "$arg" in
243 echo "$output_file" | grep -q "\.gz$" && compr="gzip -9 -f" 243 echo "$output_file" | grep -q "\.gz$" && compr="gzip -9 -f"
244 echo "$output_file" | grep -q "\.bz2$" && compr="bzip2 -9 -f" 244 echo "$output_file" | grep -q "\.bz2$" && compr="bzip2 -9 -f"
245 echo "$output_file" | grep -q "\.lzma$" && compr="lzma -9 -f" 245 echo "$output_file" | grep -q "\.lzma$" && compr="lzma -9 -f"
246 echo "$output_file" | grep -q "\.xz$" && \
247 compr="xz --check=crc32 --lzma2=dict=1MiB"
246 echo "$output_file" | grep -q "\.lzo$" && compr="lzop -9 -f" 248 echo "$output_file" | grep -q "\.lzo$" && compr="lzop -9 -f"
247 echo "$output_file" | grep -q "\.cpio$" && compr="cat" 249 echo "$output_file" | grep -q "\.cpio$" && compr="cat"
248 shift 250 shift
diff --git a/scripts/get_maintainer.pl b/scripts/get_maintainer.pl
index d21ec3a89603..139e0fff8e31 100755
--- a/scripts/get_maintainer.pl
+++ b/scripts/get_maintainer.pl
@@ -13,7 +13,7 @@
13use strict; 13use strict;
14 14
15my $P = $0; 15my $P = $0;
16my $V = '0.26-beta6'; 16my $V = '0.26';
17 17
18use Getopt::Long qw(:config no_auto_abbrev); 18use Getopt::Long qw(:config no_auto_abbrev);
19 19
@@ -40,7 +40,7 @@ my $email_use_mailmap = 1;
40my $output_multiline = 1; 40my $output_multiline = 1;
41my $output_separator = ", "; 41my $output_separator = ", ";
42my $output_roles = 0; 42my $output_roles = 0;
43my $output_rolestats = 0; 43my $output_rolestats = 1;
44my $scm = 0; 44my $scm = 0;
45my $web = 0; 45my $web = 0;
46my $subsystem = 0; 46my $subsystem = 0;
@@ -494,6 +494,40 @@ if ($web) {
494 494
495exit($exit); 495exit($exit);
496 496
497sub range_is_maintained {
498 my ($start, $end) = @_;
499
500 for (my $i = $start; $i < $end; $i++) {
501 my $line = $typevalue[$i];
502 if ($line =~ m/^(\C):\s*(.*)/) {
503 my $type = $1;
504 my $value = $2;
505 if ($type eq 'S') {
506 if ($value =~ /(maintain|support)/i) {
507 return 1;
508 }
509 }
510 }
511 }
512 return 0;
513}
514
515sub range_has_maintainer {
516 my ($start, $end) = @_;
517
518 for (my $i = $start; $i < $end; $i++) {
519 my $line = $typevalue[$i];
520 if ($line =~ m/^(\C):\s*(.*)/) {
521 my $type = $1;
522 my $value = $2;
523 if ($type eq 'M') {
524 return 1;
525 }
526 }
527 }
528 return 0;
529}
530
497sub get_maintainers { 531sub get_maintainers {
498 %email_hash_name = (); 532 %email_hash_name = ();
499 %email_hash_address = (); 533 %email_hash_address = ();
@@ -556,7 +590,9 @@ sub get_maintainers {
556 my $file_pd = ($file =~ tr@/@@); 590 my $file_pd = ($file =~ tr@/@@);
557 $value_pd++ if (substr($value,-1,1) ne "/"); 591 $value_pd++ if (substr($value,-1,1) ne "/");
558 $value_pd = -1 if ($value =~ /^\.\*/); 592 $value_pd = -1 if ($value =~ /^\.\*/);
559 if ($value_pd >= $file_pd) { 593 if ($value_pd >= $file_pd &&
594 range_is_maintained($start, $end) &&
595 range_has_maintainer($start, $end)) {
560 $exact_pattern_match_hash{$file} = 1; 596 $exact_pattern_match_hash{$file} = 1;
561 } 597 }
562 if ($pattern_depth == 0 || 598 if ($pattern_depth == 0 ||
@@ -720,7 +756,8 @@ Other options:
720 --help => show this help information 756 --help => show this help information
721 757
722Default options: 758Default options:
723 [--email --git --m --n --l --multiline --pattern-depth=0 --remove-duplicates] 759 [--email --nogit --git-fallback --m --n --l --multiline -pattern-depth=0
760 --remove-duplicates --rolestats]
724 761
725Notes: 762Notes:
726 Using "-f directory" may give unexpected results: 763 Using "-f directory" may give unexpected results:
diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c
index 97d2259ae999..e8fba959fffb 100644
--- a/scripts/mod/modpost.c
+++ b/scripts/mod/modpost.c
@@ -1615,7 +1615,7 @@ static void section_rel(const char *modname, struct elf_info *elf,
1615 * A module includes a number of sections that are discarded 1615 * A module includes a number of sections that are discarded
1616 * either when loaded or when used as built-in. 1616 * either when loaded or when used as built-in.
1617 * For loaded modules all functions marked __init and all data 1617 * For loaded modules all functions marked __init and all data
1618 * marked __initdata will be discarded when the module has been intialized. 1618 * marked __initdata will be discarded when the module has been initialized.
1619 * Likewise for modules used built-in the sections marked __exit 1619 * Likewise for modules used built-in the sections marked __exit
1620 * are discarded because __exit marked function are supposed to be called 1620 * are discarded because __exit marked function are supposed to be called
1621 * only when a module is unloaded which never happens for built-in modules. 1621 * only when a module is unloaded which never happens for built-in modules.
diff --git a/scripts/xz_wrap.sh b/scripts/xz_wrap.sh
new file mode 100644
index 000000000000..17a5798c29da
--- /dev/null
+++ b/scripts/xz_wrap.sh
@@ -0,0 +1,23 @@
1#!/bin/sh
2#
3# This is a wrapper for xz to compress the kernel image using appropriate
4# compression options depending on the architecture.
5#
6# Author: Lasse Collin <lasse.collin@tukaani.org>
7#
8# This file has been put into the public domain.
9# You can do whatever you want with this file.
10#
11
12BCJ=
13LZMA2OPTS=
14
15case $ARCH in
16 x86|x86_64) BCJ=--x86 ;;
17 powerpc) BCJ=--powerpc ;;
18 ia64) BCJ=--ia64; LZMA2OPTS=pb=4 ;;
19 arm) BCJ=--arm ;;
20 sparc) BCJ=--sparc ;;
21esac
22
23exec xz --check=crc32 $BCJ --lzma2=$LZMA2OPTS,dict=32MiB
diff --git a/security/apparmor/include/match.h b/security/apparmor/include/match.h
index 19ba16e8aacd..a4a863997bd5 100644
--- a/security/apparmor/include/match.h
+++ b/security/apparmor/include/match.h
@@ -28,7 +28,7 @@
28 * The format used for transition tables is based on the GNU flex table 28 * The format used for transition tables is based on the GNU flex table
29 * file format (--tables-file option; see Table File Format in the flex 29 * file format (--tables-file option; see Table File Format in the flex
30 * info pages and the flex sources for documentation). The magic number 30 * info pages and the flex sources for documentation). The magic number
31 * used in the header is 0x1B5E783D insted of 0xF13C57B1 though, because 31 * used in the header is 0x1B5E783D instead of 0xF13C57B1 though, because
32 * the YY_ID_CHK (check) and YY_ID_DEF (default) tables are used 32 * the YY_ID_CHK (check) and YY_ID_DEF (default) tables are used
33 * slightly differently (see the apparmor-parser package). 33 * slightly differently (see the apparmor-parser package).
34 */ 34 */
diff --git a/sound/ac97_bus.c b/sound/ac97_bus.c
index a351dd0a09c7..2b50cbe6aca9 100644
--- a/sound/ac97_bus.c
+++ b/sound/ac97_bus.c
@@ -19,8 +19,8 @@
19 19
20/* 20/*
21 * Let drivers decide whether they want to support given codec from their 21 * Let drivers decide whether they want to support given codec from their
22 * probe method. Drivers have direct access to the struct snd_ac97 structure and may 22 * probe method. Drivers have direct access to the struct snd_ac97
23 * decide based on the id field amongst other things. 23 * structure and may decide based on the id field amongst other things.
24 */ 24 */
25static int ac97_bus_match(struct device *dev, struct device_driver *drv) 25static int ac97_bus_match(struct device *dev, struct device_driver *drv)
26{ 26{
diff --git a/sound/aoa/codecs/onyx.c b/sound/aoa/codecs/onyx.c
index 91852e49910e..3687a6cc9881 100644
--- a/sound/aoa/codecs/onyx.c
+++ b/sound/aoa/codecs/onyx.c
@@ -1114,7 +1114,6 @@ static int onyx_i2c_remove(struct i2c_client *client)
1114 of_node_put(onyx->codec.node); 1114 of_node_put(onyx->codec.node);
1115 if (onyx->codec_info) 1115 if (onyx->codec_info)
1116 kfree(onyx->codec_info); 1116 kfree(onyx->codec_info);
1117 i2c_set_clientdata(client, onyx);
1118 kfree(onyx); 1117 kfree(onyx);
1119 return 0; 1118 return 0;
1120} 1119}
diff --git a/sound/aoa/core/gpio-feature.c b/sound/aoa/core/gpio-feature.c
index de8e03afa97b..faa317490545 100644
--- a/sound/aoa/core/gpio-feature.c
+++ b/sound/aoa/core/gpio-feature.c
@@ -287,10 +287,9 @@ static void ftr_gpio_exit(struct gpio_runtime *rt)
287 free_irq(linein_detect_irq, &rt->line_in_notify); 287 free_irq(linein_detect_irq, &rt->line_in_notify);
288 if (rt->line_out_notify.gpio_private) 288 if (rt->line_out_notify.gpio_private)
289 free_irq(lineout_detect_irq, &rt->line_out_notify); 289 free_irq(lineout_detect_irq, &rt->line_out_notify);
290 cancel_delayed_work(&rt->headphone_notify.work); 290 cancel_delayed_work_sync(&rt->headphone_notify.work);
291 cancel_delayed_work(&rt->line_in_notify.work); 291 cancel_delayed_work_sync(&rt->line_in_notify.work);
292 cancel_delayed_work(&rt->line_out_notify.work); 292 cancel_delayed_work_sync(&rt->line_out_notify.work);
293 flush_scheduled_work();
294 mutex_destroy(&rt->headphone_notify.mutex); 293 mutex_destroy(&rt->headphone_notify.mutex);
295 mutex_destroy(&rt->line_in_notify.mutex); 294 mutex_destroy(&rt->line_in_notify.mutex);
296 mutex_destroy(&rt->line_out_notify.mutex); 295 mutex_destroy(&rt->line_out_notify.mutex);
diff --git a/sound/aoa/core/gpio-pmf.c b/sound/aoa/core/gpio-pmf.c
index 7e267c9379bc..c8d8a1a6f964 100644
--- a/sound/aoa/core/gpio-pmf.c
+++ b/sound/aoa/core/gpio-pmf.c
@@ -107,10 +107,9 @@ static void pmf_gpio_exit(struct gpio_runtime *rt)
107 107
108 /* make sure no work is pending before freeing 108 /* make sure no work is pending before freeing
109 * all things */ 109 * all things */
110 cancel_delayed_work(&rt->headphone_notify.work); 110 cancel_delayed_work_sync(&rt->headphone_notify.work);
111 cancel_delayed_work(&rt->line_in_notify.work); 111 cancel_delayed_work_sync(&rt->line_in_notify.work);
112 cancel_delayed_work(&rt->line_out_notify.work); 112 cancel_delayed_work_sync(&rt->line_out_notify.work);
113 flush_scheduled_work();
114 113
115 mutex_destroy(&rt->headphone_notify.mutex); 114 mutex_destroy(&rt->headphone_notify.mutex);
116 mutex_destroy(&rt->line_in_notify.mutex); 115 mutex_destroy(&rt->line_in_notify.mutex);
diff --git a/sound/core/control.c b/sound/core/control.c
index 45a818002d99..9ce00ed20fba 100644
--- a/sound/core/control.c
+++ b/sound/core/control.c
@@ -1488,7 +1488,7 @@ int snd_ctl_create(struct snd_card *card)
1488} 1488}
1489 1489
1490/* 1490/*
1491 * Frequently used control callbacks 1491 * Frequently used control callbacks/helpers
1492 */ 1492 */
1493int snd_ctl_boolean_mono_info(struct snd_kcontrol *kcontrol, 1493int snd_ctl_boolean_mono_info(struct snd_kcontrol *kcontrol,
1494 struct snd_ctl_elem_info *uinfo) 1494 struct snd_ctl_elem_info *uinfo)
@@ -1513,3 +1513,29 @@ int snd_ctl_boolean_stereo_info(struct snd_kcontrol *kcontrol,
1513} 1513}
1514 1514
1515EXPORT_SYMBOL(snd_ctl_boolean_stereo_info); 1515EXPORT_SYMBOL(snd_ctl_boolean_stereo_info);
1516
1517/**
1518 * snd_ctl_enum_info - fills the info structure for an enumerated control
1519 * @info: the structure to be filled
1520 * @channels: the number of the control's channels; often one
1521 * @items: the number of control values; also the size of @names
1522 * @names: an array containing the names of all control values
1523 *
1524 * Sets all required fields in @info to their appropriate values.
1525 * If the control's accessibility is not the default (readable and writable),
1526 * the caller has to fill @info->access.
1527 */
1528int snd_ctl_enum_info(struct snd_ctl_elem_info *info, unsigned int channels,
1529 unsigned int items, const char *const names[])
1530{
1531 info->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
1532 info->count = channels;
1533 info->value.enumerated.items = items;
1534 if (info->value.enumerated.item >= items)
1535 info->value.enumerated.item = items - 1;
1536 strlcpy(info->value.enumerated.name,
1537 names[info->value.enumerated.item],
1538 sizeof(info->value.enumerated.name));
1539 return 0;
1540}
1541EXPORT_SYMBOL(snd_ctl_enum_info);
diff --git a/sound/core/init.c b/sound/core/init.c
index 57b792e2439a..3e65da21a08c 100644
--- a/sound/core/init.c
+++ b/sound/core/init.c
@@ -642,7 +642,7 @@ static struct device_attribute card_number_attrs =
642 * external accesses. Thus, you should call this function at the end 642 * external accesses. Thus, you should call this function at the end
643 * of the initialization of the card. 643 * of the initialization of the card.
644 * 644 *
645 * Returns zero otherwise a negative error code if the registrain failed. 645 * Returns zero otherwise a negative error code if the registration failed.
646 */ 646 */
647int snd_card_register(struct snd_card *card) 647int snd_card_register(struct snd_card *card)
648{ 648{
diff --git a/sound/core/oss/pcm_oss.c b/sound/core/oss/pcm_oss.c
index b753ec661fcf..a2e4eb324699 100644
--- a/sound/core/oss/pcm_oss.c
+++ b/sound/core/oss/pcm_oss.c
@@ -453,8 +453,10 @@ static int snd_pcm_hw_param_near(struct snd_pcm_substream *pcm,
453 } else { 453 } else {
454 *params = *save; 454 *params = *save;
455 max = snd_pcm_hw_param_max(pcm, params, var, max, &maxdir); 455 max = snd_pcm_hw_param_max(pcm, params, var, max, &maxdir);
456 if (max < 0) 456 if (max < 0) {
457 kfree(save);
457 return max; 458 return max;
459 }
458 last = 1; 460 last = 1;
459 } 461 }
460 _end: 462 _end:
diff --git a/sound/core/pcm_lib.c b/sound/core/pcm_lib.c
index 11446a1506da..a82e3756a72d 100644
--- a/sound/core/pcm_lib.c
+++ b/sound/core/pcm_lib.c
@@ -373,6 +373,27 @@ static int snd_pcm_update_hw_ptr0(struct snd_pcm_substream *substream,
373 (unsigned long)new_hw_ptr, 373 (unsigned long)new_hw_ptr,
374 (unsigned long)runtime->hw_ptr_base); 374 (unsigned long)runtime->hw_ptr_base);
375 } 375 }
376
377 if (runtime->no_period_wakeup) {
378 /*
379 * Without regular period interrupts, we have to check
380 * the elapsed time to detect xruns.
381 */
382 jdelta = jiffies - runtime->hw_ptr_jiffies;
383 if (jdelta < runtime->hw_ptr_buffer_jiffies / 2)
384 goto no_delta_check;
385 hdelta = jdelta - delta * HZ / runtime->rate;
386 while (hdelta > runtime->hw_ptr_buffer_jiffies / 2 + 1) {
387 delta += runtime->buffer_size;
388 hw_base += runtime->buffer_size;
389 if (hw_base >= runtime->boundary)
390 hw_base = 0;
391 new_hw_ptr = hw_base + pos;
392 hdelta -= runtime->hw_ptr_buffer_jiffies;
393 }
394 goto no_delta_check;
395 }
396
376 /* something must be really wrong */ 397 /* something must be really wrong */
377 if (delta >= runtime->buffer_size + runtime->period_size) { 398 if (delta >= runtime->buffer_size + runtime->period_size) {
378 hw_ptr_error(substream, 399 hw_ptr_error(substream,
@@ -442,6 +463,7 @@ static int snd_pcm_update_hw_ptr0(struct snd_pcm_substream *substream,
442 (long)old_hw_ptr); 463 (long)old_hw_ptr);
443 } 464 }
444 465
466 no_delta_check:
445 if (runtime->status->hw_ptr == new_hw_ptr) 467 if (runtime->status->hw_ptr == new_hw_ptr)
446 return 0; 468 return 0;
447 469
diff --git a/sound/core/pcm_native.c b/sound/core/pcm_native.c
index e82c1f97d99e..4be45e7be8ad 100644
--- a/sound/core/pcm_native.c
+++ b/sound/core/pcm_native.c
@@ -422,6 +422,9 @@ static int snd_pcm_hw_params(struct snd_pcm_substream *substream,
422 runtime->info = params->info; 422 runtime->info = params->info;
423 runtime->rate_num = params->rate_num; 423 runtime->rate_num = params->rate_num;
424 runtime->rate_den = params->rate_den; 424 runtime->rate_den = params->rate_den;
425 runtime->no_period_wakeup =
426 (params->info & SNDRV_PCM_INFO_NO_PERIOD_WAKEUP) &&
427 (params->flags & SNDRV_PCM_HW_PARAMS_NO_PERIOD_WAKEUP);
425 428
426 bits = snd_pcm_format_physical_width(runtime->format); 429 bits = snd_pcm_format_physical_width(runtime->format);
427 runtime->sample_bits = bits; 430 runtime->sample_bits = bits;
@@ -984,7 +987,7 @@ static int snd_pcm_do_pause(struct snd_pcm_substream *substream, int push)
984 if (push) 987 if (push)
985 snd_pcm_update_hw_ptr(substream); 988 snd_pcm_update_hw_ptr(substream);
986 /* The jiffies check in snd_pcm_update_hw_ptr*() is done by 989 /* The jiffies check in snd_pcm_update_hw_ptr*() is done by
987 * a delta betwen the current jiffies, this gives a large enough 990 * a delta between the current jiffies, this gives a large enough
988 * delta, effectively to skip the check once. 991 * delta, effectively to skip the check once.
989 */ 992 */
990 substream->runtime->hw_ptr_jiffies = jiffies - HZ * 1000; 993 substream->runtime->hw_ptr_jiffies = jiffies - HZ * 1000;
diff --git a/sound/core/seq/seq.c b/sound/core/seq/seq.c
index bf09a5ad1865..119fddb6fc99 100644
--- a/sound/core/seq/seq.c
+++ b/sound/core/seq/seq.c
@@ -32,6 +32,7 @@
32#include "seq_timer.h" 32#include "seq_timer.h"
33#include "seq_system.h" 33#include "seq_system.h"
34#include "seq_info.h" 34#include "seq_info.h"
35#include <sound/minors.h>
35#include <sound/seq_device.h> 36#include <sound/seq_device.h>
36 37
37#if defined(CONFIG_SND_SEQ_DUMMY_MODULE) 38#if defined(CONFIG_SND_SEQ_DUMMY_MODULE)
@@ -73,6 +74,9 @@ MODULE_PARM_DESC(seq_default_timer_subdevice, "The default timer subdevice numbe
73module_param(seq_default_timer_resolution, int, 0644); 74module_param(seq_default_timer_resolution, int, 0644);
74MODULE_PARM_DESC(seq_default_timer_resolution, "The default timer resolution in Hz."); 75MODULE_PARM_DESC(seq_default_timer_resolution, "The default timer resolution in Hz.");
75 76
77MODULE_ALIAS_CHARDEV(CONFIG_SND_MAJOR, SNDRV_MINOR_SEQUENCER);
78MODULE_ALIAS("devname:snd/seq");
79
76/* 80/*
77 * INIT PART 81 * INIT PART
78 */ 82 */
diff --git a/sound/core/sound.c b/sound/core/sound.c
index 66691fe437e6..1c7a3efe1778 100644
--- a/sound/core/sound.c
+++ b/sound/core/sound.c
@@ -188,14 +188,22 @@ static const struct file_operations snd_fops =
188}; 188};
189 189
190#ifdef CONFIG_SND_DYNAMIC_MINORS 190#ifdef CONFIG_SND_DYNAMIC_MINORS
191static int snd_find_free_minor(void) 191static int snd_find_free_minor(int type)
192{ 192{
193 int minor; 193 int minor;
194 194
195 /* static minors for module auto loading */
196 if (type == SNDRV_DEVICE_TYPE_SEQUENCER)
197 return SNDRV_MINOR_SEQUENCER;
198 if (type == SNDRV_DEVICE_TYPE_TIMER)
199 return SNDRV_MINOR_TIMER;
200
195 for (minor = 0; minor < ARRAY_SIZE(snd_minors); ++minor) { 201 for (minor = 0; minor < ARRAY_SIZE(snd_minors); ++minor) {
196 /* skip minors still used statically for autoloading devices */ 202 /* skip static minors still used for module auto loading */
197 if (SNDRV_MINOR_DEVICE(minor) == SNDRV_MINOR_CONTROL || 203 if (SNDRV_MINOR_DEVICE(minor) == SNDRV_MINOR_CONTROL)
198 minor == SNDRV_MINOR_SEQUENCER) 204 continue;
205 if (minor == SNDRV_MINOR_SEQUENCER ||
206 minor == SNDRV_MINOR_TIMER)
199 continue; 207 continue;
200 if (!snd_minors[minor]) 208 if (!snd_minors[minor])
201 return minor; 209 return minor;
@@ -269,7 +277,7 @@ int snd_register_device_for_dev(int type, struct snd_card *card, int dev,
269 preg->private_data = private_data; 277 preg->private_data = private_data;
270 mutex_lock(&sound_mutex); 278 mutex_lock(&sound_mutex);
271#ifdef CONFIG_SND_DYNAMIC_MINORS 279#ifdef CONFIG_SND_DYNAMIC_MINORS
272 minor = snd_find_free_minor(); 280 minor = snd_find_free_minor(type);
273#else 281#else
274 minor = snd_kernel_minor(type, card, dev); 282 minor = snd_kernel_minor(type, card, dev);
275 if (minor >= 0 && snd_minors[minor]) 283 if (minor >= 0 && snd_minors[minor])
diff --git a/sound/core/timer.c b/sound/core/timer.c
index 13afb60999b9..ed016329e911 100644
--- a/sound/core/timer.c
+++ b/sound/core/timer.c
@@ -34,8 +34,8 @@
34#include <sound/initval.h> 34#include <sound/initval.h>
35#include <linux/kmod.h> 35#include <linux/kmod.h>
36 36
37#if defined(CONFIG_SND_HPET) || defined(CONFIG_SND_HPET_MODULE) 37#if defined(CONFIG_SND_HRTIMER) || defined(CONFIG_SND_HRTIMER_MODULE)
38#define DEFAULT_TIMER_LIMIT 3 38#define DEFAULT_TIMER_LIMIT 4
39#elif defined(CONFIG_SND_RTCTIMER) || defined(CONFIG_SND_RTCTIMER_MODULE) 39#elif defined(CONFIG_SND_RTCTIMER) || defined(CONFIG_SND_RTCTIMER_MODULE)
40#define DEFAULT_TIMER_LIMIT 2 40#define DEFAULT_TIMER_LIMIT 2
41#else 41#else
@@ -52,6 +52,9 @@ MODULE_PARM_DESC(timer_limit, "Maximum global timers in system.");
52module_param(timer_tstamp_monotonic, int, 0444); 52module_param(timer_tstamp_monotonic, int, 0444);
53MODULE_PARM_DESC(timer_tstamp_monotonic, "Use posix monotonic clock source for timestamps (default)."); 53MODULE_PARM_DESC(timer_tstamp_monotonic, "Use posix monotonic clock source for timestamps (default).");
54 54
55MODULE_ALIAS_CHARDEV(CONFIG_SND_MAJOR, SNDRV_MINOR_TIMER);
56MODULE_ALIAS("devname:snd/timer");
57
55struct snd_timer_user { 58struct snd_timer_user {
56 struct snd_timer_instance *timeri; 59 struct snd_timer_instance *timeri;
57 int tread; /* enhanced read with timestamps and events */ 60 int tread; /* enhanced read with timestamps and events */
diff --git a/sound/drivers/ml403-ac97cr.c b/sound/drivers/ml403-ac97cr.c
index a1282c1c0591..5cfcb908c430 100644
--- a/sound/drivers/ml403-ac97cr.c
+++ b/sound/drivers/ml403-ac97cr.c
@@ -1143,8 +1143,8 @@ snd_ml403_ac97cr_create(struct snd_card *card, struct platform_device *pfdev,
1143 (resource->start) + 1); 1143 (resource->start) + 1);
1144 if (ml403_ac97cr->port == NULL) { 1144 if (ml403_ac97cr->port == NULL) {
1145 snd_printk(KERN_ERR SND_ML403_AC97CR_DRIVER ": " 1145 snd_printk(KERN_ERR SND_ML403_AC97CR_DRIVER ": "
1146 "unable to remap memory region (%x to %x)\n", 1146 "unable to remap memory region (%pR)\n",
1147 resource->start, resource->end); 1147 resource);
1148 snd_ml403_ac97cr_free(ml403_ac97cr); 1148 snd_ml403_ac97cr_free(ml403_ac97cr);
1149 return -EBUSY; 1149 return -EBUSY;
1150 } 1150 }
diff --git a/sound/i2c/other/ak4113.c b/sound/i2c/other/ak4113.c
index 971a84a4fa77..c424d329f806 100644
--- a/sound/i2c/other/ak4113.c
+++ b/sound/i2c/other/ak4113.c
@@ -57,8 +57,7 @@ static void snd_ak4113_free(struct ak4113 *chip)
57{ 57{
58 chip->init = 1; /* don't schedule new work */ 58 chip->init = 1; /* don't schedule new work */
59 mb(); 59 mb();
60 cancel_delayed_work(&chip->work); 60 cancel_delayed_work_sync(&chip->work);
61 flush_scheduled_work();
62 kfree(chip); 61 kfree(chip);
63} 62}
64 63
@@ -141,7 +140,7 @@ void snd_ak4113_reinit(struct ak4113 *chip)
141{ 140{
142 chip->init = 1; 141 chip->init = 1;
143 mb(); 142 mb();
144 flush_scheduled_work(); 143 flush_delayed_work_sync(&chip->work);
145 ak4113_init_regs(chip); 144 ak4113_init_regs(chip);
146 /* bring up statistics / event queing */ 145 /* bring up statistics / event queing */
147 chip->init = 0; 146 chip->init = 0;
diff --git a/sound/i2c/other/ak4114.c b/sound/i2c/other/ak4114.c
index 0341451f814c..d9fb537b0b94 100644
--- a/sound/i2c/other/ak4114.c
+++ b/sound/i2c/other/ak4114.c
@@ -67,8 +67,7 @@ static void snd_ak4114_free(struct ak4114 *chip)
67{ 67{
68 chip->init = 1; /* don't schedule new work */ 68 chip->init = 1; /* don't schedule new work */
69 mb(); 69 mb();
70 cancel_delayed_work(&chip->work); 70 cancel_delayed_work_sync(&chip->work);
71 flush_scheduled_work();
72 kfree(chip); 71 kfree(chip);
73} 72}
74 73
@@ -154,7 +153,7 @@ void snd_ak4114_reinit(struct ak4114 *chip)
154{ 153{
155 chip->init = 1; 154 chip->init = 1;
156 mb(); 155 mb();
157 flush_scheduled_work(); 156 flush_delayed_work_sync(&chip->work);
158 ak4114_init_regs(chip); 157 ak4114_init_regs(chip);
159 /* bring up statistics / event queing */ 158 /* bring up statistics / event queing */
160 chip->init = 0; 159 chip->init = 0;
diff --git a/sound/isa/opl3sa2.c b/sound/isa/opl3sa2.c
index 265abcce9dba..9b915e27b5bd 100644
--- a/sound/isa/opl3sa2.c
+++ b/sound/isa/opl3sa2.c
@@ -264,7 +264,7 @@ static int __devinit snd_opl3sa2_detect(struct snd_card *card)
264 snd_printd("OPL3-SA [0x%lx] detect (1) = 0x%x (0x%x)\n", port, tmp, tmp1); 264 snd_printd("OPL3-SA [0x%lx] detect (1) = 0x%x (0x%x)\n", port, tmp, tmp1);
265 return -ENODEV; 265 return -ENODEV;
266 } 266 }
267 /* try if the MIC register is accesible */ 267 /* try if the MIC register is accessible */
268 tmp = snd_opl3sa2_read(chip, OPL3SA2_MIC); 268 tmp = snd_opl3sa2_read(chip, OPL3SA2_MIC);
269 snd_opl3sa2_write(chip, OPL3SA2_MIC, 0x8a); 269 snd_opl3sa2_write(chip, OPL3SA2_MIC, 0x8a);
270 if (((tmp1 = snd_opl3sa2_read(chip, OPL3SA2_MIC)) & 0x9f) != 0x8a) { 270 if (((tmp1 = snd_opl3sa2_read(chip, OPL3SA2_MIC)) & 0x9f) != 0x8a) {
diff --git a/sound/pci/Kconfig b/sound/pci/Kconfig
index 12e34653b8a8..9823d59d7ad7 100644
--- a/sound/pci/Kconfig
+++ b/sound/pci/Kconfig
@@ -209,7 +209,7 @@ config SND_OXYGEN_LIB
209 tristate 209 tristate
210 210
211config SND_OXYGEN 211config SND_OXYGEN
212 tristate "C-Media 8788 (Oxygen)" 212 tristate "C-Media 8786, 8787, 8788 (Oxygen)"
213 select SND_OXYGEN_LIB 213 select SND_OXYGEN_LIB
214 select SND_PCM 214 select SND_PCM
215 select SND_MPU401_UART 215 select SND_MPU401_UART
@@ -217,13 +217,18 @@ config SND_OXYGEN
217 Say Y here to include support for sound cards based on the 217 Say Y here to include support for sound cards based on the
218 C-Media CMI8788 (Oxygen HD Audio) chip: 218 C-Media CMI8788 (Oxygen HD Audio) chip:
219 * Asound A-8788 219 * Asound A-8788
220 * Asus Xonar DG
220 * AuzenTech X-Meridian 221 * AuzenTech X-Meridian
222 * AuzenTech X-Meridian 2G
221 * Bgears b-Enspirer 223 * Bgears b-Enspirer
222 * Club3D Theatron DTS 224 * Club3D Theatron DTS
223 * HT-Omega Claro (plus) 225 * HT-Omega Claro (plus)
224 * HT-Omega Claro halo (XT) 226 * HT-Omega Claro halo (XT)
227 * Kuroutoshikou CMI8787-HG2PCI
225 * Razer Barracuda AC-1 228 * Razer Barracuda AC-1
226 * Sondigo Inferno 229 * Sondigo Inferno
230 * TempoTec/MediaTek HiFier Fantasia
231 * TempoTec/MediaTek HiFier Serenade
227 232
228 To compile this driver as a module, choose M here: the module 233 To compile this driver as a module, choose M here: the module
229 will be called snd-oxygen. 234 will be called snd-oxygen.
@@ -578,18 +583,6 @@ config SND_HDSPM
578 To compile this driver as a module, choose M here: the module 583 To compile this driver as a module, choose M here: the module
579 will be called snd-hdspm. 584 will be called snd-hdspm.
580 585
581config SND_HIFIER
582 tristate "TempoTec HiFier Fantasia"
583 select SND_OXYGEN_LIB
584 select SND_PCM
585 select SND_MPU401_UART
586 help
587 Say Y here to include support for the MediaTek/TempoTec HiFier
588 Fantasia sound card.
589
590 To compile this driver as a module, choose M here: the module
591 will be called snd-hifier.
592
593config SND_ICE1712 586config SND_ICE1712
594 tristate "ICEnsemble ICE1712 (Envy24)" 587 tristate "ICEnsemble ICE1712 (Envy24)"
595 select SND_MPU401_UART 588 select SND_MPU401_UART
@@ -826,8 +819,8 @@ config SND_VIRTUOSO
826 Say Y here to include support for sound cards based on the 819 Say Y here to include support for sound cards based on the
827 Asus AV66/AV100/AV200 chips, i.e., Xonar D1, DX, D2, D2X, DS, 820 Asus AV66/AV100/AV200 chips, i.e., Xonar D1, DX, D2, D2X, DS,
828 Essence ST (Deluxe), and Essence STX. 821 Essence ST (Deluxe), and Essence STX.
829 Support for the HDAV1.3 (Deluxe) is incomplete; for the 822 Support for the HDAV1.3 (Deluxe) and HDAV1.3 Slim is experimental;
830 HDAV1.3 Slim and Xense, missing. 823 for the Xense, missing.
831 824
832 To compile this driver as a module, choose M here: the module 825 To compile this driver as a module, choose M here: the module
833 will be called snd-virtuoso. 826 will be called snd-virtuoso.
diff --git a/sound/pci/ac97/ac97_codec.c b/sound/pci/ac97/ac97_codec.c
index a7630e9edf8a..0fc614ce16c1 100644
--- a/sound/pci/ac97/ac97_codec.c
+++ b/sound/pci/ac97/ac97_codec.c
@@ -1014,8 +1014,7 @@ static int snd_ac97_free(struct snd_ac97 *ac97)
1014{ 1014{
1015 if (ac97) { 1015 if (ac97) {
1016#ifdef CONFIG_SND_AC97_POWER_SAVE 1016#ifdef CONFIG_SND_AC97_POWER_SAVE
1017 cancel_delayed_work(&ac97->power_work); 1017 cancel_delayed_work_sync(&ac97->power_work);
1018 flush_scheduled_work();
1019#endif 1018#endif
1020 snd_ac97_proc_done(ac97); 1019 snd_ac97_proc_done(ac97);
1021 if (ac97->bus) 1020 if (ac97->bus)
@@ -2456,8 +2455,7 @@ void snd_ac97_suspend(struct snd_ac97 *ac97)
2456 if (ac97->build_ops->suspend) 2455 if (ac97->build_ops->suspend)
2457 ac97->build_ops->suspend(ac97); 2456 ac97->build_ops->suspend(ac97);
2458#ifdef CONFIG_SND_AC97_POWER_SAVE 2457#ifdef CONFIG_SND_AC97_POWER_SAVE
2459 cancel_delayed_work(&ac97->power_work); 2458 cancel_delayed_work_sync(&ac97->power_work);
2460 flush_scheduled_work();
2461#endif 2459#endif
2462 snd_ac97_powerdown(ac97); 2460 snd_ac97_powerdown(ac97);
2463} 2461}
diff --git a/sound/pci/azt3328.c b/sound/pci/azt3328.c
index 2f3cacbd5528..6117595fc075 100644
--- a/sound/pci/azt3328.c
+++ b/sound/pci/azt3328.c
@@ -1,6 +1,6 @@
1/* 1/*
2 * azt3328.c - driver for Aztech AZF3328 based soundcards (e.g. PCI168). 2 * azt3328.c - driver for Aztech AZF3328 based soundcards (e.g. PCI168).
3 * Copyright (C) 2002, 2005 - 2009 by Andreas Mohr <andi AT lisas.de> 3 * Copyright (C) 2002, 2005 - 2010 by Andreas Mohr <andi AT lisas.de>
4 * 4 *
5 * Framework borrowed from Bart Hartgers's als4000.c. 5 * Framework borrowed from Bart Hartgers's als4000.c.
6 * Driver developed on PCI168 AP(W) version (PCI rev. 10, subsystem ID 1801), 6 * Driver developed on PCI168 AP(W) version (PCI rev. 10, subsystem ID 1801),
@@ -175,6 +175,7 @@
175 175
176#include <asm/io.h> 176#include <asm/io.h>
177#include <linux/init.h> 177#include <linux/init.h>
178#include <linux/bug.h> /* WARN_ONCE */
178#include <linux/pci.h> 179#include <linux/pci.h>
179#include <linux/delay.h> 180#include <linux/delay.h>
180#include <linux/slab.h> 181#include <linux/slab.h>
@@ -201,14 +202,15 @@ MODULE_SUPPORTED_DEVICE("{{Aztech,AZF3328}}");
201 202
202/* === Debug settings === 203/* === Debug settings ===
203 Further diagnostic functionality than the settings below 204 Further diagnostic functionality than the settings below
204 does not need to be provided, since one can easily write a bash script 205 does not need to be provided, since one can easily write a POSIX shell script
205 to dump the card's I/O ports (those listed in lspci -v -v): 206 to dump the card's I/O ports (those listed in lspci -v -v):
206 function dump() 207 dump()
207 { 208 {
208 local descr=$1; local addr=$2; local count=$3 209 local descr=$1; local addr=$2; local count=$3
209 210
210 echo "${descr}: ${count} @ ${addr}:" 211 echo "${descr}: ${count} @ ${addr}:"
211 dd if=/dev/port skip=$[${addr}] count=${count} bs=1 2>/dev/null| hexdump -C 212 dd if=/dev/port skip=`printf %d ${addr}` count=${count} bs=1 \
213 2>/dev/null| hexdump -C
212 } 214 }
213 and then use something like 215 and then use something like
214 "dump joy200 0x200 8", "dump mpu388 0x388 4", "dump joy 0xb400 8", 216 "dump joy200 0x200 8", "dump mpu388 0x388 4", "dump joy 0xb400 8",
@@ -216,14 +218,14 @@ MODULE_SUPPORTED_DEVICE("{{Aztech,AZF3328}}");
216 possibly within a "while true; do ... sleep 1; done" loop. 218 possibly within a "while true; do ... sleep 1; done" loop.
217 Tweaking ports could be done using 219 Tweaking ports could be done using
218 VALSTRING="`printf "%02x" $value`" 220 VALSTRING="`printf "%02x" $value`"
219 printf "\x""$VALSTRING"|dd of=/dev/port seek=$[${addr}] bs=1 2>/dev/null 221 printf "\x""$VALSTRING"|dd of=/dev/port seek=`printf %d ${addr}` bs=1 \
222 2>/dev/null
220*/ 223*/
221 224
222#define DEBUG_MISC 0 225#define DEBUG_MISC 0
223#define DEBUG_CALLS 0 226#define DEBUG_CALLS 0
224#define DEBUG_MIXER 0 227#define DEBUG_MIXER 0
225#define DEBUG_CODEC 0 228#define DEBUG_CODEC 0
226#define DEBUG_IO 0
227#define DEBUG_TIMER 0 229#define DEBUG_TIMER 0
228#define DEBUG_GAME 0 230#define DEBUG_GAME 0
229#define DEBUG_PM 0 231#define DEBUG_PM 0
@@ -291,19 +293,23 @@ static int seqtimer_scaling = 128;
291module_param(seqtimer_scaling, int, 0444); 293module_param(seqtimer_scaling, int, 0444);
292MODULE_PARM_DESC(seqtimer_scaling, "Set 1024000Hz sequencer timer scale factor (lockup danger!). Default 128."); 294MODULE_PARM_DESC(seqtimer_scaling, "Set 1024000Hz sequencer timer scale factor (lockup danger!). Default 128.");
293 295
294struct snd_azf3328_codec_data {
295 unsigned long io_base;
296 struct snd_pcm_substream *substream;
297 bool running;
298 const char *name;
299};
300
301enum snd_azf3328_codec_type { 296enum snd_azf3328_codec_type {
297 /* warning: fixed indices (also used for bitmask checks!) */
302 AZF_CODEC_PLAYBACK = 0, 298 AZF_CODEC_PLAYBACK = 0,
303 AZF_CODEC_CAPTURE = 1, 299 AZF_CODEC_CAPTURE = 1,
304 AZF_CODEC_I2S_OUT = 2, 300 AZF_CODEC_I2S_OUT = 2,
305}; 301};
306 302
303struct snd_azf3328_codec_data {
304 unsigned long io_base; /* keep first! (avoid offset calc) */
305 unsigned int dma_base; /* helper to avoid an indirection in hotpath */
306 spinlock_t *lock; /* TODO: convert to our own per-codec lock member */
307 struct snd_pcm_substream *substream;
308 bool running;
309 enum snd_azf3328_codec_type type;
310 const char *name;
311};
312
307struct snd_azf3328 { 313struct snd_azf3328 {
308 /* often-used fields towards beginning, then grouped */ 314 /* often-used fields towards beginning, then grouped */
309 315
@@ -362,6 +368,9 @@ MODULE_DEVICE_TABLE(pci, snd_azf3328_ids);
362static int 368static int
363snd_azf3328_io_reg_setb(unsigned reg, u8 mask, bool do_set) 369snd_azf3328_io_reg_setb(unsigned reg, u8 mask, bool do_set)
364{ 370{
371 /* Well, strictly spoken, the inb/outb sequence isn't atomic
372 and would need locking. However we currently don't care
373 since it potentially complicates matters. */
365 u8 prev = inb(reg), new; 374 u8 prev = inb(reg), new;
366 375
367 new = (do_set) ? (prev|mask) : (prev & ~mask); 376 new = (do_set) ? (prev|mask) : (prev & ~mask);
@@ -413,6 +422,21 @@ snd_azf3328_codec_outl(const struct snd_azf3328_codec_data *codec,
413 outl(value, codec->io_base + reg); 422 outl(value, codec->io_base + reg);
414} 423}
415 424
425static inline void
426snd_azf3328_codec_outl_multi(const struct snd_azf3328_codec_data *codec,
427 unsigned reg, const void *buffer, int count
428)
429{
430 unsigned long addr = codec->io_base + reg;
431 if (count) {
432 const u32 *buf = buffer;
433 do {
434 outl(*buf++, addr);
435 addr += 4;
436 } while (--count);
437 }
438}
439
416static inline u32 440static inline u32
417snd_azf3328_codec_inl(const struct snd_azf3328_codec_data *codec, unsigned reg) 441snd_azf3328_codec_inl(const struct snd_azf3328_codec_data *codec, unsigned reg)
418{ 442{
@@ -943,38 +967,43 @@ snd_azf3328_hw_free(struct snd_pcm_substream *substream)
943} 967}
944 968
945static void 969static void
946snd_azf3328_codec_setfmt(struct snd_azf3328 *chip, 970snd_azf3328_codec_setfmt(struct snd_azf3328_codec_data *codec,
947 enum snd_azf3328_codec_type codec_type,
948 enum azf_freq_t bitrate, 971 enum azf_freq_t bitrate,
949 unsigned int format_width, 972 unsigned int format_width,
950 unsigned int channels 973 unsigned int channels
951) 974)
952{ 975{
953 unsigned long flags; 976 unsigned long flags;
954 const struct snd_azf3328_codec_data *codec = &chip->codecs[codec_type];
955 u16 val = 0xff00; 977 u16 val = 0xff00;
978 u8 freq = 0;
956 979
957 snd_azf3328_dbgcallenter(); 980 snd_azf3328_dbgcallenter();
958 switch (bitrate) { 981 switch (bitrate) {
959 case AZF_FREQ_4000: val |= SOUNDFORMAT_FREQ_SUSPECTED_4000; break; 982#define AZF_FMT_XLATE(in_freq, out_bits) \
960 case AZF_FREQ_4800: val |= SOUNDFORMAT_FREQ_SUSPECTED_4800; break; 983 do { \
961 case AZF_FREQ_5512: 984 case AZF_FREQ_ ## in_freq: \
962 /* the AZF3328 names it "5510" for some strange reason */ 985 freq = SOUNDFORMAT_FREQ_ ## out_bits; \
963 val |= SOUNDFORMAT_FREQ_5510; break; 986 break; \
964 case AZF_FREQ_6620: val |= SOUNDFORMAT_FREQ_6620; break; 987 } while (0);
965 case AZF_FREQ_8000: val |= SOUNDFORMAT_FREQ_8000; break; 988 AZF_FMT_XLATE(4000, SUSPECTED_4000)
966 case AZF_FREQ_9600: val |= SOUNDFORMAT_FREQ_9600; break; 989 AZF_FMT_XLATE(4800, SUSPECTED_4800)
967 case AZF_FREQ_11025: val |= SOUNDFORMAT_FREQ_11025; break; 990 /* the AZF3328 names it "5510" for some strange reason: */
968 case AZF_FREQ_13240: val |= SOUNDFORMAT_FREQ_SUSPECTED_13240; break; 991 AZF_FMT_XLATE(5512, 5510)
969 case AZF_FREQ_16000: val |= SOUNDFORMAT_FREQ_16000; break; 992 AZF_FMT_XLATE(6620, 6620)
970 case AZF_FREQ_22050: val |= SOUNDFORMAT_FREQ_22050; break; 993 AZF_FMT_XLATE(8000, 8000)
971 case AZF_FREQ_32000: val |= SOUNDFORMAT_FREQ_32000; break; 994 AZF_FMT_XLATE(9600, 9600)
995 AZF_FMT_XLATE(11025, 11025)
996 AZF_FMT_XLATE(13240, SUSPECTED_13240)
997 AZF_FMT_XLATE(16000, 16000)
998 AZF_FMT_XLATE(22050, 22050)
999 AZF_FMT_XLATE(32000, 32000)
972 default: 1000 default:
973 snd_printk(KERN_WARNING "unknown bitrate %d, assuming 44.1kHz!\n", bitrate); 1001 snd_printk(KERN_WARNING "unknown bitrate %d, assuming 44.1kHz!\n", bitrate);
974 /* fall-through */ 1002 /* fall-through */
975 case AZF_FREQ_44100: val |= SOUNDFORMAT_FREQ_44100; break; 1003 AZF_FMT_XLATE(44100, 44100)
976 case AZF_FREQ_48000: val |= SOUNDFORMAT_FREQ_48000; break; 1004 AZF_FMT_XLATE(48000, 48000)
977 case AZF_FREQ_66200: val |= SOUNDFORMAT_FREQ_SUSPECTED_66200; break; 1005 AZF_FMT_XLATE(66200, SUSPECTED_66200)
1006#undef AZF_FMT_XLATE
978 } 1007 }
979 /* val = 0xff07; 3m27.993s (65301Hz; -> 64000Hz???) hmm, 66120, 65967, 66123 */ 1008 /* val = 0xff07; 3m27.993s (65301Hz; -> 64000Hz???) hmm, 66120, 65967, 66123 */
980 /* val = 0xff09; 17m15.098s (13123,478Hz; -> 12000Hz???) hmm, 13237.2Hz? */ 1009 /* val = 0xff09; 17m15.098s (13123,478Hz; -> 12000Hz???) hmm, 13237.2Hz? */
@@ -986,13 +1015,15 @@ snd_azf3328_codec_setfmt(struct snd_azf3328 *chip,
986 /* val = 0xff0d; 41m23.135s (5523,600Hz; -> 5512Hz???) */ 1015 /* val = 0xff0d; 41m23.135s (5523,600Hz; -> 5512Hz???) */
987 /* val = 0xff0e; 28m30.777s (8017Hz; -> 8000Hz???) */ 1016 /* val = 0xff0e; 28m30.777s (8017Hz; -> 8000Hz???) */
988 1017
1018 val |= freq;
1019
989 if (channels == 2) 1020 if (channels == 2)
990 val |= SOUNDFORMAT_FLAG_2CHANNELS; 1021 val |= SOUNDFORMAT_FLAG_2CHANNELS;
991 1022
992 if (format_width == 16) 1023 if (format_width == 16)
993 val |= SOUNDFORMAT_FLAG_16BIT; 1024 val |= SOUNDFORMAT_FLAG_16BIT;
994 1025
995 spin_lock_irqsave(&chip->reg_lock, flags); 1026 spin_lock_irqsave(codec->lock, flags);
996 1027
997 /* set bitrate/format */ 1028 /* set bitrate/format */
998 snd_azf3328_codec_outw(codec, IDX_IO_CODEC_SOUNDFORMAT, val); 1029 snd_azf3328_codec_outw(codec, IDX_IO_CODEC_SOUNDFORMAT, val);
@@ -1004,7 +1035,8 @@ snd_azf3328_codec_setfmt(struct snd_azf3328 *chip,
1004 * (FIXME: yes, it works, but what exactly am I doing here?? :) 1035 * (FIXME: yes, it works, but what exactly am I doing here?? :)
1005 * FIXME: does this have some side effects for full-duplex 1036 * FIXME: does this have some side effects for full-duplex
1006 * or other dramatic side effects? */ 1037 * or other dramatic side effects? */
1007 if (codec_type == AZF_CODEC_PLAYBACK) /* only do it for playback */ 1038 /* do it for non-capture codecs only */
1039 if (codec->type != AZF_CODEC_CAPTURE)
1008 snd_azf3328_codec_outw(codec, IDX_IO_CODEC_DMA_FLAGS, 1040 snd_azf3328_codec_outw(codec, IDX_IO_CODEC_DMA_FLAGS,
1009 snd_azf3328_codec_inw(codec, IDX_IO_CODEC_DMA_FLAGS) | 1041 snd_azf3328_codec_inw(codec, IDX_IO_CODEC_DMA_FLAGS) |
1010 DMA_RUN_SOMETHING1 | 1042 DMA_RUN_SOMETHING1 |
@@ -1014,20 +1046,19 @@ snd_azf3328_codec_setfmt(struct snd_azf3328 *chip,
1014 DMA_SOMETHING_ELSE 1046 DMA_SOMETHING_ELSE
1015 ); 1047 );
1016 1048
1017 spin_unlock_irqrestore(&chip->reg_lock, flags); 1049 spin_unlock_irqrestore(codec->lock, flags);
1018 snd_azf3328_dbgcallleave(); 1050 snd_azf3328_dbgcallleave();
1019} 1051}
1020 1052
1021static inline void 1053static inline void
1022snd_azf3328_codec_setfmt_lowpower(struct snd_azf3328 *chip, 1054snd_azf3328_codec_setfmt_lowpower(struct snd_azf3328_codec_data *codec
1023 enum snd_azf3328_codec_type codec_type
1024) 1055)
1025{ 1056{
1026 /* choose lowest frequency for low power consumption. 1057 /* choose lowest frequency for low power consumption.
1027 * While this will cause louder noise due to rather coarse frequency, 1058 * While this will cause louder noise due to rather coarse frequency,
1028 * it should never matter since output should always 1059 * it should never matter since output should always
1029 * get disabled properly when idle anyway. */ 1060 * get disabled properly when idle anyway. */
1030 snd_azf3328_codec_setfmt(chip, codec_type, AZF_FREQ_4000, 8, 1); 1061 snd_azf3328_codec_setfmt(codec, AZF_FREQ_4000, 8, 1);
1031} 1062}
1032 1063
1033static void 1064static void
@@ -1101,69 +1132,87 @@ snd_azf3328_ctrl_codec_activity(struct snd_azf3328 *chip,
1101 /* ...and adjust clock, too 1132 /* ...and adjust clock, too
1102 * (reduce noise and power consumption) */ 1133 * (reduce noise and power consumption) */
1103 if (!enable) 1134 if (!enable)
1104 snd_azf3328_codec_setfmt_lowpower( 1135 snd_azf3328_codec_setfmt_lowpower(codec);
1105 chip,
1106 codec_type
1107 );
1108 codec->running = enable; 1136 codec->running = enable;
1109 } 1137 }
1110} 1138}
1111 1139
1112static void 1140static void
1113snd_azf3328_codec_setdmaa(struct snd_azf3328 *chip, 1141snd_azf3328_codec_setdmaa(struct snd_azf3328_codec_data *codec,
1114 enum snd_azf3328_codec_type codec_type,
1115 unsigned long addr, 1142 unsigned long addr,
1116 unsigned int count, 1143 unsigned int period_bytes,
1117 unsigned int size 1144 unsigned int buffer_bytes
1118) 1145)
1119{ 1146{
1120 const struct snd_azf3328_codec_data *codec = &chip->codecs[codec_type];
1121 snd_azf3328_dbgcallenter(); 1147 snd_azf3328_dbgcallenter();
1148 WARN_ONCE(period_bytes & 1, "odd period length!?\n");
1149 WARN_ONCE(buffer_bytes != 2 * period_bytes,
1150 "missed our input expectations! %u vs. %u\n",
1151 buffer_bytes, period_bytes);
1122 if (!codec->running) { 1152 if (!codec->running) {
1123 /* AZF3328 uses a two buffer pointer DMA transfer approach */ 1153 /* AZF3328 uses a two buffer pointer DMA transfer approach */
1124 1154
1125 unsigned long flags, addr_area2; 1155 unsigned long flags;
1126 1156
1127 /* width 32bit (prevent overflow): */ 1157 /* width 32bit (prevent overflow): */
1128 u32 count_areas, lengths; 1158 u32 area_length;
1159 struct codec_setup_io {
1160 u32 dma_start_1;
1161 u32 dma_start_2;
1162 u32 dma_lengths;
1163 } __attribute__((packed)) setup_io;
1164
1165 area_length = buffer_bytes/2;
1166
1167 setup_io.dma_start_1 = addr;
1168 setup_io.dma_start_2 = addr+area_length;
1129 1169
1130 count_areas = size/2; 1170 snd_azf3328_dbgcodec(
1131 addr_area2 = addr+count_areas; 1171 "setdma: buffers %08x[%u] / %08x[%u], %u, %u\n",
1132 snd_azf3328_dbgcodec("setdma: buffers %08lx[%u] / %08lx[%u]\n", 1172 setup_io.dma_start_1, area_length,
1133 addr, count_areas, addr_area2, count_areas); 1173 setup_io.dma_start_2, area_length,
1174 period_bytes, buffer_bytes);
1134 1175
1135 count_areas--; /* max. index */ 1176 /* Hmm, are we really supposed to decrement this by 1??
1177 Most definitely certainly not: configuring full length does
1178 work properly (i.e. likely better), and BTW we
1179 violated possibly differing frame sizes with this...
1180
1181 area_length--; |* max. index *|
1182 */
1136 1183
1137 /* build combined I/O buffer length word */ 1184 /* build combined I/O buffer length word */
1138 lengths = (count_areas << 16) | (count_areas); 1185 setup_io.dma_lengths = (area_length << 16) | (area_length);
1139 spin_lock_irqsave(&chip->reg_lock, flags); 1186
1140 snd_azf3328_codec_outl(codec, IDX_IO_CODEC_DMA_START_1, addr); 1187 spin_lock_irqsave(codec->lock, flags);
1141 snd_azf3328_codec_outl(codec, IDX_IO_CODEC_DMA_START_2, 1188 snd_azf3328_codec_outl_multi(
1142 addr_area2); 1189 codec, IDX_IO_CODEC_DMA_START_1, &setup_io, 3
1143 snd_azf3328_codec_outl(codec, IDX_IO_CODEC_DMA_LENGTHS, 1190 );
1144 lengths); 1191 spin_unlock_irqrestore(codec->lock, flags);
1145 spin_unlock_irqrestore(&chip->reg_lock, flags);
1146 } 1192 }
1147 snd_azf3328_dbgcallleave(); 1193 snd_azf3328_dbgcallleave();
1148} 1194}
1149 1195
1150static int 1196static int
1151snd_azf3328_codec_prepare(struct snd_pcm_substream *substream) 1197snd_azf3328_pcm_prepare(struct snd_pcm_substream *substream)
1152{ 1198{
1153#if 0
1154 struct snd_azf3328 *chip = snd_pcm_substream_chip(substream);
1155 struct snd_pcm_runtime *runtime = substream->runtime; 1199 struct snd_pcm_runtime *runtime = substream->runtime;
1200 struct snd_azf3328_codec_data *codec = runtime->private_data;
1201#if 0
1156 unsigned int size = snd_pcm_lib_buffer_bytes(substream); 1202 unsigned int size = snd_pcm_lib_buffer_bytes(substream);
1157 unsigned int count = snd_pcm_lib_period_bytes(substream); 1203 unsigned int count = snd_pcm_lib_period_bytes(substream);
1158#endif 1204#endif
1159 1205
1160 snd_azf3328_dbgcallenter(); 1206 snd_azf3328_dbgcallenter();
1207
1208 codec->dma_base = runtime->dma_addr;
1209
1161#if 0 1210#if 0
1162 snd_azf3328_codec_setfmt(chip, AZF_CODEC_..., 1211 snd_azf3328_codec_setfmt(codec,
1163 runtime->rate, 1212 runtime->rate,
1164 snd_pcm_format_width(runtime->format), 1213 snd_pcm_format_width(runtime->format),
1165 runtime->channels); 1214 runtime->channels);
1166 snd_azf3328_codec_setdmaa(chip, AZF_CODEC_..., 1215 snd_azf3328_codec_setdmaa(codec,
1167 runtime->dma_addr, count, size); 1216 runtime->dma_addr, count, size);
1168#endif 1217#endif
1169 snd_azf3328_dbgcallleave(); 1218 snd_azf3328_dbgcallleave();
@@ -1171,24 +1220,23 @@ snd_azf3328_codec_prepare(struct snd_pcm_substream *substream)
1171} 1220}
1172 1221
1173static int 1222static int
1174snd_azf3328_codec_trigger(enum snd_azf3328_codec_type codec_type, 1223snd_azf3328_pcm_trigger(struct snd_pcm_substream *substream, int cmd)
1175 struct snd_pcm_substream *substream, int cmd)
1176{ 1224{
1177 struct snd_azf3328 *chip = snd_pcm_substream_chip(substream); 1225 struct snd_azf3328 *chip = snd_pcm_substream_chip(substream);
1178 const struct snd_azf3328_codec_data *codec = &chip->codecs[codec_type];
1179 struct snd_pcm_runtime *runtime = substream->runtime; 1226 struct snd_pcm_runtime *runtime = substream->runtime;
1227 struct snd_azf3328_codec_data *codec = runtime->private_data;
1180 int result = 0; 1228 int result = 0;
1181 u16 flags1; 1229 u16 flags1;
1182 bool previously_muted = 0; 1230 bool previously_muted = 0;
1183 bool is_playback_codec = (AZF_CODEC_PLAYBACK == codec_type); 1231 bool is_main_mixer_playback_codec = (AZF_CODEC_PLAYBACK == codec->type);
1184 1232
1185 snd_azf3328_dbgcalls("snd_azf3328_codec_trigger cmd %d\n", cmd); 1233 snd_azf3328_dbgcalls("snd_azf3328_pcm_trigger cmd %d\n", cmd);
1186 1234
1187 switch (cmd) { 1235 switch (cmd) {
1188 case SNDRV_PCM_TRIGGER_START: 1236 case SNDRV_PCM_TRIGGER_START:
1189 snd_azf3328_dbgcodec("START %s\n", codec->name); 1237 snd_azf3328_dbgcodec("START %s\n", codec->name);
1190 1238
1191 if (is_playback_codec) { 1239 if (is_main_mixer_playback_codec) {
1192 /* mute WaveOut (avoid clicking during setup) */ 1240 /* mute WaveOut (avoid clicking during setup) */
1193 previously_muted = 1241 previously_muted =
1194 snd_azf3328_mixer_set_mute( 1242 snd_azf3328_mixer_set_mute(
@@ -1196,12 +1244,12 @@ snd_azf3328_codec_trigger(enum snd_azf3328_codec_type codec_type,
1196 ); 1244 );
1197 } 1245 }
1198 1246
1199 snd_azf3328_codec_setfmt(chip, codec_type, 1247 snd_azf3328_codec_setfmt(codec,
1200 runtime->rate, 1248 runtime->rate,
1201 snd_pcm_format_width(runtime->format), 1249 snd_pcm_format_width(runtime->format),
1202 runtime->channels); 1250 runtime->channels);
1203 1251
1204 spin_lock(&chip->reg_lock); 1252 spin_lock(codec->lock);
1205 /* first, remember current value: */ 1253 /* first, remember current value: */
1206 flags1 = snd_azf3328_codec_inw(codec, IDX_IO_CODEC_DMA_FLAGS); 1254 flags1 = snd_azf3328_codec_inw(codec, IDX_IO_CODEC_DMA_FLAGS);
1207 1255
@@ -1211,14 +1259,14 @@ snd_azf3328_codec_trigger(enum snd_azf3328_codec_type codec_type,
1211 1259
1212 /* FIXME: clear interrupts or what??? */ 1260 /* FIXME: clear interrupts or what??? */
1213 snd_azf3328_codec_outw(codec, IDX_IO_CODEC_IRQTYPE, 0xffff); 1261 snd_azf3328_codec_outw(codec, IDX_IO_CODEC_IRQTYPE, 0xffff);
1214 spin_unlock(&chip->reg_lock); 1262 spin_unlock(codec->lock);
1215 1263
1216 snd_azf3328_codec_setdmaa(chip, codec_type, runtime->dma_addr, 1264 snd_azf3328_codec_setdmaa(codec, runtime->dma_addr,
1217 snd_pcm_lib_period_bytes(substream), 1265 snd_pcm_lib_period_bytes(substream),
1218 snd_pcm_lib_buffer_bytes(substream) 1266 snd_pcm_lib_buffer_bytes(substream)
1219 ); 1267 );
1220 1268
1221 spin_lock(&chip->reg_lock); 1269 spin_lock(codec->lock);
1222#ifdef WIN9X 1270#ifdef WIN9X
1223 /* FIXME: enable playback/recording??? */ 1271 /* FIXME: enable playback/recording??? */
1224 flags1 |= DMA_RUN_SOMETHING1 | DMA_RUN_SOMETHING2; 1272 flags1 |= DMA_RUN_SOMETHING1 | DMA_RUN_SOMETHING2;
@@ -1242,10 +1290,10 @@ snd_azf3328_codec_trigger(enum snd_azf3328_codec_type codec_type,
1242 DMA_EPILOGUE_SOMETHING | 1290 DMA_EPILOGUE_SOMETHING |
1243 DMA_SOMETHING_ELSE); 1291 DMA_SOMETHING_ELSE);
1244#endif 1292#endif
1245 spin_unlock(&chip->reg_lock); 1293 spin_unlock(codec->lock);
1246 snd_azf3328_ctrl_codec_activity(chip, codec_type, 1); 1294 snd_azf3328_ctrl_codec_activity(chip, codec->type, 1);
1247 1295
1248 if (is_playback_codec) { 1296 if (is_main_mixer_playback_codec) {
1249 /* now unmute WaveOut */ 1297 /* now unmute WaveOut */
1250 if (!previously_muted) 1298 if (!previously_muted)
1251 snd_azf3328_mixer_set_mute( 1299 snd_azf3328_mixer_set_mute(
@@ -1258,19 +1306,19 @@ snd_azf3328_codec_trigger(enum snd_azf3328_codec_type codec_type,
1258 case SNDRV_PCM_TRIGGER_RESUME: 1306 case SNDRV_PCM_TRIGGER_RESUME:
1259 snd_azf3328_dbgcodec("RESUME %s\n", codec->name); 1307 snd_azf3328_dbgcodec("RESUME %s\n", codec->name);
1260 /* resume codec if we were active */ 1308 /* resume codec if we were active */
1261 spin_lock(&chip->reg_lock); 1309 spin_lock(codec->lock);
1262 if (codec->running) 1310 if (codec->running)
1263 snd_azf3328_codec_outw(codec, IDX_IO_CODEC_DMA_FLAGS, 1311 snd_azf3328_codec_outw(codec, IDX_IO_CODEC_DMA_FLAGS,
1264 snd_azf3328_codec_inw( 1312 snd_azf3328_codec_inw(
1265 codec, IDX_IO_CODEC_DMA_FLAGS 1313 codec, IDX_IO_CODEC_DMA_FLAGS
1266 ) | DMA_RESUME 1314 ) | DMA_RESUME
1267 ); 1315 );
1268 spin_unlock(&chip->reg_lock); 1316 spin_unlock(codec->lock);
1269 break; 1317 break;
1270 case SNDRV_PCM_TRIGGER_STOP: 1318 case SNDRV_PCM_TRIGGER_STOP:
1271 snd_azf3328_dbgcodec("STOP %s\n", codec->name); 1319 snd_azf3328_dbgcodec("STOP %s\n", codec->name);
1272 1320
1273 if (is_playback_codec) { 1321 if (is_main_mixer_playback_codec) {
1274 /* mute WaveOut (avoid clicking during setup) */ 1322 /* mute WaveOut (avoid clicking during setup) */
1275 previously_muted = 1323 previously_muted =
1276 snd_azf3328_mixer_set_mute( 1324 snd_azf3328_mixer_set_mute(
@@ -1278,7 +1326,7 @@ snd_azf3328_codec_trigger(enum snd_azf3328_codec_type codec_type,
1278 ); 1326 );
1279 } 1327 }
1280 1328
1281 spin_lock(&chip->reg_lock); 1329 spin_lock(codec->lock);
1282 /* first, remember current value: */ 1330 /* first, remember current value: */
1283 flags1 = snd_azf3328_codec_inw(codec, IDX_IO_CODEC_DMA_FLAGS); 1331 flags1 = snd_azf3328_codec_inw(codec, IDX_IO_CODEC_DMA_FLAGS);
1284 1332
@@ -1293,10 +1341,10 @@ snd_azf3328_codec_trigger(enum snd_azf3328_codec_type codec_type,
1293 1341
1294 flags1 &= ~DMA_RUN_SOMETHING1; 1342 flags1 &= ~DMA_RUN_SOMETHING1;
1295 snd_azf3328_codec_outw(codec, IDX_IO_CODEC_DMA_FLAGS, flags1); 1343 snd_azf3328_codec_outw(codec, IDX_IO_CODEC_DMA_FLAGS, flags1);
1296 spin_unlock(&chip->reg_lock); 1344 spin_unlock(codec->lock);
1297 snd_azf3328_ctrl_codec_activity(chip, codec_type, 0); 1345 snd_azf3328_ctrl_codec_activity(chip, codec->type, 0);
1298 1346
1299 if (is_playback_codec) { 1347 if (is_main_mixer_playback_codec) {
1300 /* now unmute WaveOut */ 1348 /* now unmute WaveOut */
1301 if (!previously_muted) 1349 if (!previously_muted)
1302 snd_azf3328_mixer_set_mute( 1350 snd_azf3328_mixer_set_mute(
@@ -1330,67 +1378,29 @@ snd_azf3328_codec_trigger(enum snd_azf3328_codec_type codec_type,
1330 return result; 1378 return result;
1331} 1379}
1332 1380
1333static int
1334snd_azf3328_codec_playback_trigger(struct snd_pcm_substream *substream, int cmd)
1335{
1336 return snd_azf3328_codec_trigger(AZF_CODEC_PLAYBACK, substream, cmd);
1337}
1338
1339static int
1340snd_azf3328_codec_capture_trigger(struct snd_pcm_substream *substream, int cmd)
1341{
1342 return snd_azf3328_codec_trigger(AZF_CODEC_CAPTURE, substream, cmd);
1343}
1344
1345static int
1346snd_azf3328_codec_i2s_out_trigger(struct snd_pcm_substream *substream, int cmd)
1347{
1348 return snd_azf3328_codec_trigger(AZF_CODEC_I2S_OUT, substream, cmd);
1349}
1350
1351static snd_pcm_uframes_t 1381static snd_pcm_uframes_t
1352snd_azf3328_codec_pointer(struct snd_pcm_substream *substream, 1382snd_azf3328_pcm_pointer(struct snd_pcm_substream *substream
1353 enum snd_azf3328_codec_type codec_type
1354) 1383)
1355{ 1384{
1356 const struct snd_azf3328 *chip = snd_pcm_substream_chip(substream); 1385 const struct snd_azf3328_codec_data *codec =
1357 const struct snd_azf3328_codec_data *codec = &chip->codecs[codec_type]; 1386 substream->runtime->private_data;
1358 unsigned long bufptr, result; 1387 unsigned long result;
1359 snd_pcm_uframes_t frmres; 1388 snd_pcm_uframes_t frmres;
1360 1389
1361#ifdef QUERY_HARDWARE
1362 bufptr = snd_azf3328_codec_inl(codec, IDX_IO_CODEC_DMA_START_1);
1363#else
1364 bufptr = substream->runtime->dma_addr;
1365#endif
1366 result = snd_azf3328_codec_inl(codec, IDX_IO_CODEC_DMA_CURRPOS); 1390 result = snd_azf3328_codec_inl(codec, IDX_IO_CODEC_DMA_CURRPOS);
1367 1391
1368 /* calculate offset */ 1392 /* calculate offset */
1369 result -= bufptr; 1393#ifdef QUERY_HARDWARE
1394 result -= snd_azf3328_codec_inl(codec, IDX_IO_CODEC_DMA_START_1);
1395#else
1396 result -= codec->dma_base;
1397#endif
1370 frmres = bytes_to_frames( substream->runtime, result); 1398 frmres = bytes_to_frames( substream->runtime, result);
1371 snd_azf3328_dbgcodec("%s @ 0x%8lx, frames %8ld\n", 1399 snd_azf3328_dbgcodec("%08li %s @ 0x%8lx, frames %8ld\n",
1372 codec->name, result, frmres); 1400 jiffies, codec->name, result, frmres);
1373 return frmres; 1401 return frmres;
1374} 1402}
1375 1403
1376static snd_pcm_uframes_t
1377snd_azf3328_codec_playback_pointer(struct snd_pcm_substream *substream)
1378{
1379 return snd_azf3328_codec_pointer(substream, AZF_CODEC_PLAYBACK);
1380}
1381
1382static snd_pcm_uframes_t
1383snd_azf3328_codec_capture_pointer(struct snd_pcm_substream *substream)
1384{
1385 return snd_azf3328_codec_pointer(substream, AZF_CODEC_CAPTURE);
1386}
1387
1388static snd_pcm_uframes_t
1389snd_azf3328_codec_i2s_out_pointer(struct snd_pcm_substream *substream)
1390{
1391 return snd_azf3328_codec_pointer(substream, AZF_CODEC_I2S_OUT);
1392}
1393
1394/******************************************************************/ 1404/******************************************************************/
1395 1405
1396#ifdef SUPPORT_GAMEPORT 1406#ifdef SUPPORT_GAMEPORT
@@ -1532,7 +1542,7 @@ snd_azf3328_gameport_cooked_read(struct gameport *gameport,
1532 } 1542 }
1533 } 1543 }
1534 1544
1535 /* trigger next axes sampling, to be evaluated the next time we 1545 /* trigger next sampling of axes, to be evaluated the next time we
1536 * enter this function */ 1546 * enter this function */
1537 1547
1538 /* for some very, very strange reason we cannot enable 1548 /* for some very, very strange reason we cannot enable
@@ -1624,29 +1634,29 @@ snd_azf3328_irq_log_unknown_type(u8 which)
1624} 1634}
1625 1635
1626static inline void 1636static inline void
1627snd_azf3328_codec_interrupt(struct snd_azf3328 *chip, u8 status) 1637snd_azf3328_pcm_interrupt(const struct snd_azf3328_codec_data *first_codec,
1638 u8 status
1639)
1628{ 1640{
1629 u8 which; 1641 u8 which;
1630 enum snd_azf3328_codec_type codec_type; 1642 enum snd_azf3328_codec_type codec_type;
1631 const struct snd_azf3328_codec_data *codec; 1643 const struct snd_azf3328_codec_data *codec = first_codec;
1632 1644
1633 for (codec_type = AZF_CODEC_PLAYBACK; 1645 for (codec_type = AZF_CODEC_PLAYBACK;
1634 codec_type <= AZF_CODEC_I2S_OUT; 1646 codec_type <= AZF_CODEC_I2S_OUT;
1635 ++codec_type) { 1647 ++codec_type, ++codec) {
1636 1648
1637 /* skip codec if there's no interrupt for it */ 1649 /* skip codec if there's no interrupt for it */
1638 if (!(status & (1 << codec_type))) 1650 if (!(status & (1 << codec_type)))
1639 continue; 1651 continue;
1640 1652
1641 codec = &chip->codecs[codec_type]; 1653 spin_lock(codec->lock);
1642
1643 spin_lock(&chip->reg_lock);
1644 which = snd_azf3328_codec_inb(codec, IDX_IO_CODEC_IRQTYPE); 1654 which = snd_azf3328_codec_inb(codec, IDX_IO_CODEC_IRQTYPE);
1645 /* ack all IRQ types immediately */ 1655 /* ack all IRQ types immediately */
1646 snd_azf3328_codec_outb(codec, IDX_IO_CODEC_IRQTYPE, which); 1656 snd_azf3328_codec_outb(codec, IDX_IO_CODEC_IRQTYPE, which);
1647 spin_unlock(&chip->reg_lock); 1657 spin_unlock(codec->lock);
1648 1658
1649 if ((chip->pcm[codec_type]) && (codec->substream)) { 1659 if (codec->substream) {
1650 snd_pcm_period_elapsed(codec->substream); 1660 snd_pcm_period_elapsed(codec->substream);
1651 snd_azf3328_dbgcodec("%s period done (#%x), @ %x\n", 1661 snd_azf3328_dbgcodec("%s period done (#%x), @ %x\n",
1652 codec->name, 1662 codec->name,
@@ -1701,7 +1711,7 @@ snd_azf3328_interrupt(int irq, void *dev_id)
1701 } 1711 }
1702 1712
1703 if (status & (IRQ_PLAYBACK|IRQ_RECORDING|IRQ_I2S_OUT)) 1713 if (status & (IRQ_PLAYBACK|IRQ_RECORDING|IRQ_I2S_OUT))
1704 snd_azf3328_codec_interrupt(chip, status); 1714 snd_azf3328_pcm_interrupt(chip->codecs, status);
1705 1715
1706 if (status & IRQ_GAMEPORT) 1716 if (status & IRQ_GAMEPORT)
1707 snd_azf3328_gameport_interrupt(chip); 1717 snd_azf3328_gameport_interrupt(chip);
@@ -1789,101 +1799,85 @@ snd_azf3328_pcm_open(struct snd_pcm_substream *substream,
1789{ 1799{
1790 struct snd_azf3328 *chip = snd_pcm_substream_chip(substream); 1800 struct snd_azf3328 *chip = snd_pcm_substream_chip(substream);
1791 struct snd_pcm_runtime *runtime = substream->runtime; 1801 struct snd_pcm_runtime *runtime = substream->runtime;
1802 struct snd_azf3328_codec_data *codec = &chip->codecs[codec_type];
1792 1803
1793 snd_azf3328_dbgcallenter(); 1804 snd_azf3328_dbgcallenter();
1794 chip->codecs[codec_type].substream = substream; 1805 codec->substream = substream;
1795 1806
1796 /* same parameters for all our codecs - at least we think so... */ 1807 /* same parameters for all our codecs - at least we think so... */
1797 runtime->hw = snd_azf3328_hardware; 1808 runtime->hw = snd_azf3328_hardware;
1798 1809
1799 snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE, 1810 snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE,
1800 &snd_azf3328_hw_constraints_rates); 1811 &snd_azf3328_hw_constraints_rates);
1812 runtime->private_data = codec;
1801 snd_azf3328_dbgcallleave(); 1813 snd_azf3328_dbgcallleave();
1802 return 0; 1814 return 0;
1803} 1815}
1804 1816
1805static int 1817static int
1806snd_azf3328_playback_open(struct snd_pcm_substream *substream) 1818snd_azf3328_pcm_playback_open(struct snd_pcm_substream *substream)
1807{ 1819{
1808 return snd_azf3328_pcm_open(substream, AZF_CODEC_PLAYBACK); 1820 return snd_azf3328_pcm_open(substream, AZF_CODEC_PLAYBACK);
1809} 1821}
1810 1822
1811static int 1823static int
1812snd_azf3328_capture_open(struct snd_pcm_substream *substream) 1824snd_azf3328_pcm_capture_open(struct snd_pcm_substream *substream)
1813{ 1825{
1814 return snd_azf3328_pcm_open(substream, AZF_CODEC_CAPTURE); 1826 return snd_azf3328_pcm_open(substream, AZF_CODEC_CAPTURE);
1815} 1827}
1816 1828
1817static int 1829static int
1818snd_azf3328_i2s_out_open(struct snd_pcm_substream *substream) 1830snd_azf3328_pcm_i2s_out_open(struct snd_pcm_substream *substream)
1819{ 1831{
1820 return snd_azf3328_pcm_open(substream, AZF_CODEC_I2S_OUT); 1832 return snd_azf3328_pcm_open(substream, AZF_CODEC_I2S_OUT);
1821} 1833}
1822 1834
1823static int 1835static int
1824snd_azf3328_pcm_close(struct snd_pcm_substream *substream, 1836snd_azf3328_pcm_close(struct snd_pcm_substream *substream
1825 enum snd_azf3328_codec_type codec_type
1826) 1837)
1827{ 1838{
1828 struct snd_azf3328 *chip = snd_pcm_substream_chip(substream); 1839 struct snd_azf3328_codec_data *codec =
1840 substream->runtime->private_data;
1829 1841
1830 snd_azf3328_dbgcallenter(); 1842 snd_azf3328_dbgcallenter();
1831 chip->codecs[codec_type].substream = NULL; 1843 codec->substream = NULL;
1832 snd_azf3328_dbgcallleave(); 1844 snd_azf3328_dbgcallleave();
1833 return 0; 1845 return 0;
1834} 1846}
1835 1847
1836static int
1837snd_azf3328_playback_close(struct snd_pcm_substream *substream)
1838{
1839 return snd_azf3328_pcm_close(substream, AZF_CODEC_PLAYBACK);
1840}
1841
1842static int
1843snd_azf3328_capture_close(struct snd_pcm_substream *substream)
1844{
1845 return snd_azf3328_pcm_close(substream, AZF_CODEC_CAPTURE);
1846}
1847
1848static int
1849snd_azf3328_i2s_out_close(struct snd_pcm_substream *substream)
1850{
1851 return snd_azf3328_pcm_close(substream, AZF_CODEC_I2S_OUT);
1852}
1853
1854/******************************************************************/ 1848/******************************************************************/
1855 1849
1856static struct snd_pcm_ops snd_azf3328_playback_ops = { 1850static struct snd_pcm_ops snd_azf3328_playback_ops = {
1857 .open = snd_azf3328_playback_open, 1851 .open = snd_azf3328_pcm_playback_open,
1858 .close = snd_azf3328_playback_close, 1852 .close = snd_azf3328_pcm_close,
1859 .ioctl = snd_pcm_lib_ioctl, 1853 .ioctl = snd_pcm_lib_ioctl,
1860 .hw_params = snd_azf3328_hw_params, 1854 .hw_params = snd_azf3328_hw_params,
1861 .hw_free = snd_azf3328_hw_free, 1855 .hw_free = snd_azf3328_hw_free,
1862 .prepare = snd_azf3328_codec_prepare, 1856 .prepare = snd_azf3328_pcm_prepare,
1863 .trigger = snd_azf3328_codec_playback_trigger, 1857 .trigger = snd_azf3328_pcm_trigger,
1864 .pointer = snd_azf3328_codec_playback_pointer 1858 .pointer = snd_azf3328_pcm_pointer
1865}; 1859};
1866 1860
1867static struct snd_pcm_ops snd_azf3328_capture_ops = { 1861static struct snd_pcm_ops snd_azf3328_capture_ops = {
1868 .open = snd_azf3328_capture_open, 1862 .open = snd_azf3328_pcm_capture_open,
1869 .close = snd_azf3328_capture_close, 1863 .close = snd_azf3328_pcm_close,
1870 .ioctl = snd_pcm_lib_ioctl, 1864 .ioctl = snd_pcm_lib_ioctl,
1871 .hw_params = snd_azf3328_hw_params, 1865 .hw_params = snd_azf3328_hw_params,
1872 .hw_free = snd_azf3328_hw_free, 1866 .hw_free = snd_azf3328_hw_free,
1873 .prepare = snd_azf3328_codec_prepare, 1867 .prepare = snd_azf3328_pcm_prepare,
1874 .trigger = snd_azf3328_codec_capture_trigger, 1868 .trigger = snd_azf3328_pcm_trigger,
1875 .pointer = snd_azf3328_codec_capture_pointer 1869 .pointer = snd_azf3328_pcm_pointer
1876}; 1870};
1877 1871
1878static struct snd_pcm_ops snd_azf3328_i2s_out_ops = { 1872static struct snd_pcm_ops snd_azf3328_i2s_out_ops = {
1879 .open = snd_azf3328_i2s_out_open, 1873 .open = snd_azf3328_pcm_i2s_out_open,
1880 .close = snd_azf3328_i2s_out_close, 1874 .close = snd_azf3328_pcm_close,
1881 .ioctl = snd_pcm_lib_ioctl, 1875 .ioctl = snd_pcm_lib_ioctl,
1882 .hw_params = snd_azf3328_hw_params, 1876 .hw_params = snd_azf3328_hw_params,
1883 .hw_free = snd_azf3328_hw_free, 1877 .hw_free = snd_azf3328_hw_free,
1884 .prepare = snd_azf3328_codec_prepare, 1878 .prepare = snd_azf3328_pcm_prepare,
1885 .trigger = snd_azf3328_codec_i2s_out_trigger, 1879 .trigger = snd_azf3328_pcm_trigger,
1886 .pointer = snd_azf3328_codec_i2s_out_pointer 1880 .pointer = snd_azf3328_pcm_pointer
1887}; 1881};
1888 1882
1889static int __devinit 1883static int __devinit
@@ -1966,7 +1960,7 @@ snd_azf3328_timer_start(struct snd_timer *timer)
1966 snd_azf3328_dbgtimer("delay was too low (%d)!\n", delay); 1960 snd_azf3328_dbgtimer("delay was too low (%d)!\n", delay);
1967 delay = 49; /* minimum time is 49 ticks */ 1961 delay = 49; /* minimum time is 49 ticks */
1968 } 1962 }
1969 snd_azf3328_dbgtimer("setting timer countdown value %d, add COUNTDOWN|IRQ\n", delay); 1963 snd_azf3328_dbgtimer("setting timer countdown value %d\n", delay);
1970 delay |= TIMER_COUNTDOWN_ENABLE | TIMER_IRQ_ENABLE; 1964 delay |= TIMER_COUNTDOWN_ENABLE | TIMER_IRQ_ENABLE;
1971 spin_lock_irqsave(&chip->reg_lock, flags); 1965 spin_lock_irqsave(&chip->reg_lock, flags);
1972 snd_azf3328_ctrl_outl(chip, IDX_IO_TIMER_VALUE, delay); 1966 snd_azf3328_ctrl_outl(chip, IDX_IO_TIMER_VALUE, delay);
@@ -2180,6 +2174,7 @@ snd_azf3328_create(struct snd_card *card,
2180 }; 2174 };
2181 u8 dma_init; 2175 u8 dma_init;
2182 enum snd_azf3328_codec_type codec_type; 2176 enum snd_azf3328_codec_type codec_type;
2177 struct snd_azf3328_codec_data *codec_setup;
2183 2178
2184 *rchip = NULL; 2179 *rchip = NULL;
2185 2180
@@ -2217,15 +2212,23 @@ snd_azf3328_create(struct snd_card *card,
2217 chip->opl3_io = pci_resource_start(pci, 3); 2212 chip->opl3_io = pci_resource_start(pci, 3);
2218 chip->mixer_io = pci_resource_start(pci, 4); 2213 chip->mixer_io = pci_resource_start(pci, 4);
2219 2214
2220 chip->codecs[AZF_CODEC_PLAYBACK].io_base = 2215 codec_setup = &chip->codecs[AZF_CODEC_PLAYBACK];
2221 chip->ctrl_io + AZF_IO_OFFS_CODEC_PLAYBACK; 2216 codec_setup->io_base = chip->ctrl_io + AZF_IO_OFFS_CODEC_PLAYBACK;
2222 chip->codecs[AZF_CODEC_PLAYBACK].name = "PLAYBACK"; 2217 codec_setup->lock = &chip->reg_lock;
2223 chip->codecs[AZF_CODEC_CAPTURE].io_base = 2218 codec_setup->type = AZF_CODEC_PLAYBACK;
2224 chip->ctrl_io + AZF_IO_OFFS_CODEC_CAPTURE; 2219 codec_setup->name = "PLAYBACK";
2225 chip->codecs[AZF_CODEC_CAPTURE].name = "CAPTURE"; 2220
2226 chip->codecs[AZF_CODEC_I2S_OUT].io_base = 2221 codec_setup = &chip->codecs[AZF_CODEC_CAPTURE];
2227 chip->ctrl_io + AZF_IO_OFFS_CODEC_I2S_OUT; 2222 codec_setup->io_base = chip->ctrl_io + AZF_IO_OFFS_CODEC_CAPTURE;
2228 chip->codecs[AZF_CODEC_I2S_OUT].name = "I2S_OUT"; 2223 codec_setup->lock = &chip->reg_lock;
2224 codec_setup->type = AZF_CODEC_CAPTURE;
2225 codec_setup->name = "CAPTURE";
2226
2227 codec_setup = &chip->codecs[AZF_CODEC_I2S_OUT];
2228 codec_setup->io_base = chip->ctrl_io + AZF_IO_OFFS_CODEC_I2S_OUT;
2229 codec_setup->lock = &chip->reg_lock;
2230 codec_setup->type = AZF_CODEC_I2S_OUT;
2231 codec_setup->name = "I2S_OUT";
2229 2232
2230 if (request_irq(pci->irq, snd_azf3328_interrupt, 2233 if (request_irq(pci->irq, snd_azf3328_interrupt,
2231 IRQF_SHARED, card->shortname, chip)) { 2234 IRQF_SHARED, card->shortname, chip)) {
@@ -2257,15 +2260,15 @@ snd_azf3328_create(struct snd_card *card,
2257 struct snd_azf3328_codec_data *codec = 2260 struct snd_azf3328_codec_data *codec =
2258 &chip->codecs[codec_type]; 2261 &chip->codecs[codec_type];
2259 2262
2260 /* shutdown codecs to save power */ 2263 /* shutdown codecs to reduce power / noise */
2261 /* have ...ctrl_codec_activity() act properly */ 2264 /* have ...ctrl_codec_activity() act properly */
2262 codec->running = 1; 2265 codec->running = 1;
2263 snd_azf3328_ctrl_codec_activity(chip, codec_type, 0); 2266 snd_azf3328_ctrl_codec_activity(chip, codec_type, 0);
2264 2267
2265 spin_lock_irq(&chip->reg_lock); 2268 spin_lock_irq(codec->lock);
2266 snd_azf3328_codec_outb(codec, IDX_IO_CODEC_DMA_FLAGS, 2269 snd_azf3328_codec_outb(codec, IDX_IO_CODEC_DMA_FLAGS,
2267 dma_init); 2270 dma_init);
2268 spin_unlock_irq(&chip->reg_lock); 2271 spin_unlock_irq(codec->lock);
2269 } 2272 }
2270 2273
2271 snd_card_set_dev(card, &pci->dev); 2274 snd_card_set_dev(card, &pci->dev);
@@ -2419,6 +2422,7 @@ snd_azf3328_suspend(struct pci_dev *pci, pm_message_t state)
2419 2422
2420 snd_power_change_state(card, SNDRV_CTL_POWER_D3hot); 2423 snd_power_change_state(card, SNDRV_CTL_POWER_D3hot);
2421 2424
2425 /* same pcm object for playback/capture */
2422 snd_pcm_suspend_all(chip->pcm[AZF_CODEC_PLAYBACK]); 2426 snd_pcm_suspend_all(chip->pcm[AZF_CODEC_PLAYBACK]);
2423 snd_pcm_suspend_all(chip->pcm[AZF_CODEC_I2S_OUT]); 2427 snd_pcm_suspend_all(chip->pcm[AZF_CODEC_I2S_OUT]);
2424 2428
diff --git a/sound/pci/bt87x.c b/sound/pci/bt87x.c
index 37e1b5df5ab8..2958a05b5293 100644
--- a/sound/pci/bt87x.c
+++ b/sound/pci/bt87x.c
@@ -637,15 +637,9 @@ static struct snd_kcontrol_new snd_bt87x_capture_boost = {
637static int snd_bt87x_capture_source_info(struct snd_kcontrol *kcontrol, 637static int snd_bt87x_capture_source_info(struct snd_kcontrol *kcontrol,
638 struct snd_ctl_elem_info *info) 638 struct snd_ctl_elem_info *info)
639{ 639{
640 static char *texts[3] = {"TV Tuner", "FM", "Mic/Line"}; 640 static const char *const texts[3] = {"TV Tuner", "FM", "Mic/Line"};
641 641
642 info->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; 642 return snd_ctl_enum_info(info, 1, 3, texts);
643 info->count = 1;
644 info->value.enumerated.items = 3;
645 if (info->value.enumerated.item > 2)
646 info->value.enumerated.item = 2;
647 strcpy(info->value.enumerated.name, texts[info->value.enumerated.item]);
648 return 0;
649} 643}
650 644
651static int snd_bt87x_capture_source_get(struct snd_kcontrol *kcontrol, 645static int snd_bt87x_capture_source_get(struct snd_kcontrol *kcontrol,
diff --git a/sound/pci/ca0106/ca0106.h b/sound/pci/ca0106/ca0106.h
index f19c11077255..fc53b9bca26d 100644
--- a/sound/pci/ca0106/ca0106.h
+++ b/sound/pci/ca0106/ca0106.h
@@ -188,7 +188,7 @@
188#define PLAYBACK_LIST_PTR 0x02 /* Pointer to the current period being played */ 188#define PLAYBACK_LIST_PTR 0x02 /* Pointer to the current period being played */
189 /* PTR[5:0], Default: 0x0 */ 189 /* PTR[5:0], Default: 0x0 */
190#define PLAYBACK_UNKNOWN3 0x03 /* Not used ?? */ 190#define PLAYBACK_UNKNOWN3 0x03 /* Not used ?? */
191#define PLAYBACK_DMA_ADDR 0x04 /* Playback DMA addresss */ 191#define PLAYBACK_DMA_ADDR 0x04 /* Playback DMA address */
192 /* DMA[31:0], Default: 0x0 */ 192 /* DMA[31:0], Default: 0x0 */
193#define PLAYBACK_PERIOD_SIZE 0x05 /* Playback period size. win2000 uses 0x04000000 */ 193#define PLAYBACK_PERIOD_SIZE 0x05 /* Playback period size. win2000 uses 0x04000000 */
194 /* SIZE[31:16], Default: 0x0 */ 194 /* SIZE[31:16], Default: 0x0 */
diff --git a/sound/pci/ca0106/ca0106_main.c b/sound/pci/ca0106/ca0106_main.c
index d2d12c08f937..01b49388fafd 100644
--- a/sound/pci/ca0106/ca0106_main.c
+++ b/sound/pci/ca0106/ca0106_main.c
@@ -1082,7 +1082,7 @@ snd_ca0106_pcm_pointer_capture(struct snd_pcm_substream *substream)
1082 struct snd_pcm_runtime *runtime = substream->runtime; 1082 struct snd_pcm_runtime *runtime = substream->runtime;
1083 struct snd_ca0106_pcm *epcm = runtime->private_data; 1083 struct snd_ca0106_pcm *epcm = runtime->private_data;
1084 snd_pcm_uframes_t ptr, ptr1, ptr2 = 0; 1084 snd_pcm_uframes_t ptr, ptr1, ptr2 = 0;
1085 int channel = channel=epcm->channel_id; 1085 int channel = epcm->channel_id;
1086 1086
1087 if (!epcm->running) 1087 if (!epcm->running)
1088 return 0; 1088 return 0;
diff --git a/sound/pci/cmipci.c b/sound/pci/cmipci.c
index 329968edca9b..b5bb036ef73c 100644
--- a/sound/pci/cmipci.c
+++ b/sound/pci/cmipci.c
@@ -2507,14 +2507,12 @@ static int snd_cmipci_line_in_mode_info(struct snd_kcontrol *kcontrol,
2507 struct snd_ctl_elem_info *uinfo) 2507 struct snd_ctl_elem_info *uinfo)
2508{ 2508{
2509 struct cmipci *cm = snd_kcontrol_chip(kcontrol); 2509 struct cmipci *cm = snd_kcontrol_chip(kcontrol);
2510 static char *texts[3] = { "Line-In", "Rear Output", "Bass Output" }; 2510 static const char *const texts[3] = {
2511 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; 2511 "Line-In", "Rear Output", "Bass Output"
2512 uinfo->count = 1; 2512 };
2513 uinfo->value.enumerated.items = cm->chip_version >= 39 ? 3 : 2; 2513
2514 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items) 2514 return snd_ctl_enum_info(uinfo, 1,
2515 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1; 2515 cm->chip_version >= 39 ? 3 : 2, texts);
2516 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
2517 return 0;
2518} 2516}
2519 2517
2520static inline unsigned int get_line_in_mode(struct cmipci *cm) 2518static inline unsigned int get_line_in_mode(struct cmipci *cm)
@@ -2564,14 +2562,9 @@ static int snd_cmipci_line_in_mode_put(struct snd_kcontrol *kcontrol,
2564static int snd_cmipci_mic_in_mode_info(struct snd_kcontrol *kcontrol, 2562static int snd_cmipci_mic_in_mode_info(struct snd_kcontrol *kcontrol,
2565 struct snd_ctl_elem_info *uinfo) 2563 struct snd_ctl_elem_info *uinfo)
2566{ 2564{
2567 static char *texts[2] = { "Mic-In", "Center/LFE Output" }; 2565 static const char *const texts[2] = { "Mic-In", "Center/LFE Output" };
2568 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; 2566
2569 uinfo->count = 1; 2567 return snd_ctl_enum_info(uinfo, 1, 2, texts);
2570 uinfo->value.enumerated.items = 2;
2571 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
2572 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
2573 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
2574 return 0;
2575} 2568}
2576 2569
2577static int snd_cmipci_mic_in_mode_get(struct snd_kcontrol *kcontrol, 2570static int snd_cmipci_mic_in_mode_get(struct snd_kcontrol *kcontrol,
diff --git a/sound/pci/emu10k1/emu10k1x.c b/sound/pci/emu10k1/emu10k1x.c
index df47f738098d..0c701e4ec8a5 100644
--- a/sound/pci/emu10k1/emu10k1x.c
+++ b/sound/pci/emu10k1/emu10k1x.c
@@ -114,7 +114,7 @@ MODULE_PARM_DESC(enable, "Enable the EMU10K1X soundcard.");
114 */ 114 */
115#define PLAYBACK_LIST_SIZE 0x01 /* Size of list in bytes << 16. E.g. 8 periods -> 0x00380000 */ 115#define PLAYBACK_LIST_SIZE 0x01 /* Size of list in bytes << 16. E.g. 8 periods -> 0x00380000 */
116#define PLAYBACK_LIST_PTR 0x02 /* Pointer to the current period being played */ 116#define PLAYBACK_LIST_PTR 0x02 /* Pointer to the current period being played */
117#define PLAYBACK_DMA_ADDR 0x04 /* Playback DMA addresss */ 117#define PLAYBACK_DMA_ADDR 0x04 /* Playback DMA address */
118#define PLAYBACK_PERIOD_SIZE 0x05 /* Playback period size */ 118#define PLAYBACK_PERIOD_SIZE 0x05 /* Playback period size */
119#define PLAYBACK_POINTER 0x06 /* Playback period pointer. Sample currently in DAC */ 119#define PLAYBACK_POINTER 0x06 /* Playback period pointer. Sample currently in DAC */
120#define PLAYBACK_UNKNOWN1 0x07 120#define PLAYBACK_UNKNOWN1 0x07
diff --git a/sound/pci/emu10k1/p16v.h b/sound/pci/emu10k1/p16v.h
index 153214940336..00f4817533b1 100644
--- a/sound/pci/emu10k1/p16v.h
+++ b/sound/pci/emu10k1/p16v.h
@@ -96,7 +96,7 @@
96#define PLAYBACK_LIST_SIZE 0x01 /* Size of list in bytes << 16. E.g. 8 periods -> 0x00380000 */ 96#define PLAYBACK_LIST_SIZE 0x01 /* Size of list in bytes << 16. E.g. 8 periods -> 0x00380000 */
97#define PLAYBACK_LIST_PTR 0x02 /* Pointer to the current period being played */ 97#define PLAYBACK_LIST_PTR 0x02 /* Pointer to the current period being played */
98#define PLAYBACK_UNKNOWN3 0x03 /* Not used */ 98#define PLAYBACK_UNKNOWN3 0x03 /* Not used */
99#define PLAYBACK_DMA_ADDR 0x04 /* Playback DMA addresss */ 99#define PLAYBACK_DMA_ADDR 0x04 /* Playback DMA address */
100#define PLAYBACK_PERIOD_SIZE 0x05 /* Playback period size. win2000 uses 0x04000000 */ 100#define PLAYBACK_PERIOD_SIZE 0x05 /* Playback period size. win2000 uses 0x04000000 */
101#define PLAYBACK_POINTER 0x06 /* Playback period pointer. Used with PLAYBACK_LIST_PTR to determine buffer position currently in DAC */ 101#define PLAYBACK_POINTER 0x06 /* Playback period pointer. Used with PLAYBACK_LIST_PTR to determine buffer position currently in DAC */
102#define PLAYBACK_FIFO_END_ADDRESS 0x07 /* Playback FIFO end address */ 102#define PLAYBACK_FIFO_END_ADDRESS 0x07 /* Playback FIFO end address */
diff --git a/sound/pci/es1968.c b/sound/pci/es1968.c
index 23a58f0d6cb9..7c17f45d876d 100644
--- a/sound/pci/es1968.c
+++ b/sound/pci/es1968.c
@@ -220,7 +220,7 @@ MODULE_PARM_DESC(joystick, "Enable joystick.");
220#define RINGB_EN_2CODEC 0x0020 220#define RINGB_EN_2CODEC 0x0020
221#define RINGB_SING_BIT_DUAL 0x0040 221#define RINGB_SING_BIT_DUAL 0x0040
222 222
223/* ****Port Adresses**** */ 223/* ****Port Addresses**** */
224 224
225/* Write & Read */ 225/* Write & Read */
226#define ESM_INDEX 0x02 226#define ESM_INDEX 0x02
diff --git a/sound/pci/hda/hda_codec.c b/sound/pci/hda/hda_codec.c
index 98b6d02a36c9..05e5ec88c2d9 100644
--- a/sound/pci/hda/hda_codec.c
+++ b/sound/pci/hda/hda_codec.c
@@ -4571,6 +4571,9 @@ int snd_hda_parse_pin_def_config(struct hda_codec *codec,
4571 } 4571 }
4572 memset(cfg->hp_pins + cfg->hp_outs, 0, 4572 memset(cfg->hp_pins + cfg->hp_outs, 0,
4573 sizeof(hda_nid_t) * (AUTO_CFG_MAX_OUTS - cfg->hp_outs)); 4573 sizeof(hda_nid_t) * (AUTO_CFG_MAX_OUTS - cfg->hp_outs));
4574 if (!cfg->hp_outs)
4575 cfg->line_out_type = AUTO_PIN_HP_OUT;
4576
4574 } 4577 }
4575 4578
4576 /* sort by sequence */ 4579 /* sort by sequence */
diff --git a/sound/pci/hda/hda_intel.c b/sound/pci/hda/hda_intel.c
index a1c4008af891..d3d18be483e1 100644
--- a/sound/pci/hda/hda_intel.c
+++ b/sound/pci/hda/hda_intel.c
@@ -1235,7 +1235,8 @@ static int azx_setup_periods(struct azx *chip,
1235 pos_adj = 0; 1235 pos_adj = 0;
1236 } else { 1236 } else {
1237 ofs = setup_bdle(substream, azx_dev, 1237 ofs = setup_bdle(substream, azx_dev,
1238 &bdl, ofs, pos_adj, 1); 1238 &bdl, ofs, pos_adj,
1239 !substream->runtime->no_period_wakeup);
1239 if (ofs < 0) 1240 if (ofs < 0)
1240 goto error; 1241 goto error;
1241 } 1242 }
@@ -1247,7 +1248,8 @@ static int azx_setup_periods(struct azx *chip,
1247 period_bytes - pos_adj, 0); 1248 period_bytes - pos_adj, 0);
1248 else 1249 else
1249 ofs = setup_bdle(substream, azx_dev, &bdl, ofs, 1250 ofs = setup_bdle(substream, azx_dev, &bdl, ofs,
1250 period_bytes, 1); 1251 period_bytes,
1252 !substream->runtime->no_period_wakeup);
1251 if (ofs < 0) 1253 if (ofs < 0)
1252 goto error; 1254 goto error;
1253 } 1255 }
@@ -1515,7 +1517,8 @@ static struct snd_pcm_hardware azx_pcm_hw = {
1515 /* No full-resume yet implemented */ 1517 /* No full-resume yet implemented */
1516 /* SNDRV_PCM_INFO_RESUME |*/ 1518 /* SNDRV_PCM_INFO_RESUME |*/
1517 SNDRV_PCM_INFO_PAUSE | 1519 SNDRV_PCM_INFO_PAUSE |
1518 SNDRV_PCM_INFO_SYNC_START), 1520 SNDRV_PCM_INFO_SYNC_START |
1521 SNDRV_PCM_INFO_NO_PERIOD_WAKEUP),
1519 .formats = SNDRV_PCM_FMTBIT_S16_LE, 1522 .formats = SNDRV_PCM_FMTBIT_S16_LE,
1520 .rates = SNDRV_PCM_RATE_48000, 1523 .rates = SNDRV_PCM_RATE_48000,
1521 .rate_min = 48000, 1524 .rate_min = 48000,
diff --git a/sound/pci/hda/patch_analog.c b/sound/pci/hda/patch_analog.c
index f7ff3f7ccb8e..46780670162b 100644
--- a/sound/pci/hda/patch_analog.c
+++ b/sound/pci/hda/patch_analog.c
@@ -666,7 +666,7 @@ static struct snd_kcontrol_new ad1986a_mixers[] = {
666 HDA_CODEC_MUTE("Aux Playback Switch", 0x16, 0x0, HDA_OUTPUT), 666 HDA_CODEC_MUTE("Aux Playback Switch", 0x16, 0x0, HDA_OUTPUT),
667 HDA_CODEC_VOLUME("Mic Playback Volume", 0x13, 0x0, HDA_OUTPUT), 667 HDA_CODEC_VOLUME("Mic Playback Volume", 0x13, 0x0, HDA_OUTPUT),
668 HDA_CODEC_MUTE("Mic Playback Switch", 0x13, 0x0, HDA_OUTPUT), 668 HDA_CODEC_MUTE("Mic Playback Switch", 0x13, 0x0, HDA_OUTPUT),
669 HDA_CODEC_VOLUME("Mic Boost", 0x0f, 0x0, HDA_OUTPUT), 669 HDA_CODEC_VOLUME("Mic Boost Volume", 0x0f, 0x0, HDA_OUTPUT),
670 HDA_CODEC_VOLUME("Mono Playback Volume", 0x1e, 0x0, HDA_OUTPUT), 670 HDA_CODEC_VOLUME("Mono Playback Volume", 0x1e, 0x0, HDA_OUTPUT),
671 HDA_CODEC_MUTE("Mono Playback Switch", 0x1e, 0x0, HDA_OUTPUT), 671 HDA_CODEC_MUTE("Mono Playback Switch", 0x1e, 0x0, HDA_OUTPUT),
672 HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x0, HDA_OUTPUT), 672 HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x0, HDA_OUTPUT),
@@ -729,7 +729,7 @@ static struct snd_kcontrol_new ad1986a_laptop_mixers[] = {
729 HDA_CODEC_MUTE("Aux Playback Switch", 0x16, 0x0, HDA_OUTPUT), 729 HDA_CODEC_MUTE("Aux Playback Switch", 0x16, 0x0, HDA_OUTPUT),
730 HDA_CODEC_VOLUME("Mic Playback Volume", 0x13, 0x0, HDA_OUTPUT), 730 HDA_CODEC_VOLUME("Mic Playback Volume", 0x13, 0x0, HDA_OUTPUT),
731 HDA_CODEC_MUTE("Mic Playback Switch", 0x13, 0x0, HDA_OUTPUT), 731 HDA_CODEC_MUTE("Mic Playback Switch", 0x13, 0x0, HDA_OUTPUT),
732 HDA_CODEC_VOLUME("Mic Boost", 0x0f, 0x0, HDA_OUTPUT), 732 HDA_CODEC_VOLUME("Mic Boost Volume", 0x0f, 0x0, HDA_OUTPUT),
733 /* 733 /*
734 HDA_CODEC_VOLUME("Mono Playback Volume", 0x1e, 0x0, HDA_OUTPUT), 734 HDA_CODEC_VOLUME("Mono Playback Volume", 0x1e, 0x0, HDA_OUTPUT),
735 HDA_CODEC_MUTE("Mono Playback Switch", 0x1e, 0x0, HDA_OUTPUT), */ 735 HDA_CODEC_MUTE("Mono Playback Switch", 0x1e, 0x0, HDA_OUTPUT), */
@@ -775,7 +775,7 @@ static struct snd_kcontrol_new ad1986a_laptop_eapd_mixers[] = {
775 HDA_CODEC_MUTE("PCM Playback Switch", 0x03, 0x0, HDA_OUTPUT), 775 HDA_CODEC_MUTE("PCM Playback Switch", 0x03, 0x0, HDA_OUTPUT),
776 HDA_CODEC_VOLUME("Mic Playback Volume", 0x13, 0x0, HDA_OUTPUT), 776 HDA_CODEC_VOLUME("Mic Playback Volume", 0x13, 0x0, HDA_OUTPUT),
777 HDA_CODEC_MUTE("Mic Playback Switch", 0x13, 0x0, HDA_OUTPUT), 777 HDA_CODEC_MUTE("Mic Playback Switch", 0x13, 0x0, HDA_OUTPUT),
778 HDA_CODEC_VOLUME("Mic Boost", 0x0f, 0x0, HDA_OUTPUT), 778 HDA_CODEC_VOLUME("Mic Boost Volume", 0x0f, 0x0, HDA_OUTPUT),
779 HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x0, HDA_OUTPUT), 779 HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x0, HDA_OUTPUT),
780 HDA_CODEC_MUTE("Capture Switch", 0x12, 0x0, HDA_OUTPUT), 780 HDA_CODEC_MUTE("Capture Switch", 0x12, 0x0, HDA_OUTPUT),
781 { 781 {
@@ -1358,7 +1358,7 @@ static struct snd_kcontrol_new ad1983_mixers[] = {
1358 HDA_CODEC_MUTE("Mic Playback Switch", 0x12, 0x0, HDA_OUTPUT), 1358 HDA_CODEC_MUTE("Mic Playback Switch", 0x12, 0x0, HDA_OUTPUT),
1359 HDA_CODEC_VOLUME("Line Playback Volume", 0x13, 0x0, HDA_OUTPUT), 1359 HDA_CODEC_VOLUME("Line Playback Volume", 0x13, 0x0, HDA_OUTPUT),
1360 HDA_CODEC_MUTE("Line Playback Switch", 0x13, 0x0, HDA_OUTPUT), 1360 HDA_CODEC_MUTE("Line Playback Switch", 0x13, 0x0, HDA_OUTPUT),
1361 HDA_CODEC_VOLUME("Mic Boost", 0x0c, 0x0, HDA_OUTPUT), 1361 HDA_CODEC_VOLUME("Mic Boost Volume", 0x0c, 0x0, HDA_OUTPUT),
1362 HDA_CODEC_VOLUME("Capture Volume", 0x15, 0x0, HDA_OUTPUT), 1362 HDA_CODEC_VOLUME("Capture Volume", 0x15, 0x0, HDA_OUTPUT),
1363 HDA_CODEC_MUTE("Capture Switch", 0x15, 0x0, HDA_OUTPUT), 1363 HDA_CODEC_MUTE("Capture Switch", 0x15, 0x0, HDA_OUTPUT),
1364 { 1364 {
@@ -1515,8 +1515,8 @@ static struct snd_kcontrol_new ad1981_mixers[] = {
1515 HDA_CODEC_MUTE("Mic Playback Switch", 0x1c, 0x0, HDA_OUTPUT), 1515 HDA_CODEC_MUTE("Mic Playback Switch", 0x1c, 0x0, HDA_OUTPUT),
1516 HDA_CODEC_VOLUME("CD Playback Volume", 0x1d, 0x0, HDA_OUTPUT), 1516 HDA_CODEC_VOLUME("CD Playback Volume", 0x1d, 0x0, HDA_OUTPUT),
1517 HDA_CODEC_MUTE("CD Playback Switch", 0x1d, 0x0, HDA_OUTPUT), 1517 HDA_CODEC_MUTE("CD Playback Switch", 0x1d, 0x0, HDA_OUTPUT),
1518 HDA_CODEC_VOLUME("Front Mic Boost", 0x08, 0x0, HDA_INPUT), 1518 HDA_CODEC_VOLUME("Front Mic Boost Volume", 0x08, 0x0, HDA_INPUT),
1519 HDA_CODEC_VOLUME("Mic Boost", 0x18, 0x0, HDA_INPUT), 1519 HDA_CODEC_VOLUME("Mic Boost Volume", 0x18, 0x0, HDA_INPUT),
1520 HDA_CODEC_VOLUME("Capture Volume", 0x15, 0x0, HDA_OUTPUT), 1520 HDA_CODEC_VOLUME("Capture Volume", 0x15, 0x0, HDA_OUTPUT),
1521 HDA_CODEC_MUTE("Capture Switch", 0x15, 0x0, HDA_OUTPUT), 1521 HDA_CODEC_MUTE("Capture Switch", 0x15, 0x0, HDA_OUTPUT),
1522 { 1522 {
@@ -1726,8 +1726,8 @@ static struct snd_kcontrol_new ad1981_hp_mixers[] = {
1726 HDA_CODEC_VOLUME("CD Playback Volume", 0x1d, 0x0, HDA_OUTPUT), 1726 HDA_CODEC_VOLUME("CD Playback Volume", 0x1d, 0x0, HDA_OUTPUT),
1727 HDA_CODEC_MUTE("CD Playback Switch", 0x1d, 0x0, HDA_OUTPUT), 1727 HDA_CODEC_MUTE("CD Playback Switch", 0x1d, 0x0, HDA_OUTPUT),
1728#endif 1728#endif
1729 HDA_CODEC_VOLUME("Mic Boost", 0x08, 0x0, HDA_INPUT), 1729 HDA_CODEC_VOLUME("Mic Boost Volume", 0x08, 0x0, HDA_INPUT),
1730 HDA_CODEC_VOLUME("Internal Mic Boost", 0x18, 0x0, HDA_INPUT), 1730 HDA_CODEC_VOLUME("Internal Mic Boost Volume", 0x18, 0x0, HDA_INPUT),
1731 HDA_CODEC_VOLUME("Capture Volume", 0x15, 0x0, HDA_OUTPUT), 1731 HDA_CODEC_VOLUME("Capture Volume", 0x15, 0x0, HDA_OUTPUT),
1732 HDA_CODEC_MUTE("Capture Switch", 0x15, 0x0, HDA_OUTPUT), 1732 HDA_CODEC_MUTE("Capture Switch", 0x15, 0x0, HDA_OUTPUT),
1733 { 1733 {
@@ -1774,7 +1774,7 @@ static struct snd_kcontrol_new ad1981_thinkpad_mixers[] = {
1774 HDA_CODEC_MUTE("Mic Playback Switch", 0x12, 0x0, HDA_OUTPUT), 1774 HDA_CODEC_MUTE("Mic Playback Switch", 0x12, 0x0, HDA_OUTPUT),
1775 HDA_CODEC_VOLUME("CD Playback Volume", 0x1d, 0x0, HDA_OUTPUT), 1775 HDA_CODEC_VOLUME("CD Playback Volume", 0x1d, 0x0, HDA_OUTPUT),
1776 HDA_CODEC_MUTE("CD Playback Switch", 0x1d, 0x0, HDA_OUTPUT), 1776 HDA_CODEC_MUTE("CD Playback Switch", 0x1d, 0x0, HDA_OUTPUT),
1777 HDA_CODEC_VOLUME("Mic Boost", 0x08, 0x0, HDA_INPUT), 1777 HDA_CODEC_VOLUME("Mic Boost Volume", 0x08, 0x0, HDA_INPUT),
1778 HDA_CODEC_VOLUME("Capture Volume", 0x15, 0x0, HDA_OUTPUT), 1778 HDA_CODEC_VOLUME("Capture Volume", 0x15, 0x0, HDA_OUTPUT),
1779 HDA_CODEC_MUTE("Capture Switch", 0x15, 0x0, HDA_OUTPUT), 1779 HDA_CODEC_MUTE("Capture Switch", 0x15, 0x0, HDA_OUTPUT),
1780 { 1780 {
@@ -2160,8 +2160,8 @@ static struct snd_kcontrol_new ad1988_6stack_mixers2[] = {
2160 HDA_CODEC_VOLUME("Analog Mix Playback Volume", 0x21, 0x0, HDA_OUTPUT), 2160 HDA_CODEC_VOLUME("Analog Mix Playback Volume", 0x21, 0x0, HDA_OUTPUT),
2161 HDA_CODEC_MUTE("Analog Mix Playback Switch", 0x21, 0x0, HDA_OUTPUT), 2161 HDA_CODEC_MUTE("Analog Mix Playback Switch", 0x21, 0x0, HDA_OUTPUT),
2162 2162
2163 HDA_CODEC_VOLUME("Front Mic Boost", 0x39, 0x0, HDA_OUTPUT), 2163 HDA_CODEC_VOLUME("Front Mic Boost Volume", 0x39, 0x0, HDA_OUTPUT),
2164 HDA_CODEC_VOLUME("Mic Boost", 0x3c, 0x0, HDA_OUTPUT), 2164 HDA_CODEC_VOLUME("Mic Boost Volume", 0x3c, 0x0, HDA_OUTPUT),
2165 2165
2166 { } /* end */ 2166 { } /* end */
2167}; 2167};
@@ -2203,8 +2203,8 @@ static struct snd_kcontrol_new ad1988_3stack_mixers2[] = {
2203 HDA_CODEC_VOLUME("Analog Mix Playback Volume", 0x21, 0x0, HDA_OUTPUT), 2203 HDA_CODEC_VOLUME("Analog Mix Playback Volume", 0x21, 0x0, HDA_OUTPUT),
2204 HDA_CODEC_MUTE("Analog Mix Playback Switch", 0x21, 0x0, HDA_OUTPUT), 2204 HDA_CODEC_MUTE("Analog Mix Playback Switch", 0x21, 0x0, HDA_OUTPUT),
2205 2205
2206 HDA_CODEC_VOLUME("Front Mic Boost", 0x39, 0x0, HDA_OUTPUT), 2206 HDA_CODEC_VOLUME("Front Mic Boost Volume", 0x39, 0x0, HDA_OUTPUT),
2207 HDA_CODEC_VOLUME("Mic Boost", 0x3c, 0x0, HDA_OUTPUT), 2207 HDA_CODEC_VOLUME("Mic Boost Volume", 0x3c, 0x0, HDA_OUTPUT),
2208 { 2208 {
2209 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 2209 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2210 .name = "Channel Mode", 2210 .name = "Channel Mode",
@@ -2232,7 +2232,7 @@ static struct snd_kcontrol_new ad1988_laptop_mixers[] = {
2232 HDA_CODEC_VOLUME("Analog Mix Playback Volume", 0x21, 0x0, HDA_OUTPUT), 2232 HDA_CODEC_VOLUME("Analog Mix Playback Volume", 0x21, 0x0, HDA_OUTPUT),
2233 HDA_CODEC_MUTE("Analog Mix Playback Switch", 0x21, 0x0, HDA_OUTPUT), 2233 HDA_CODEC_MUTE("Analog Mix Playback Switch", 0x21, 0x0, HDA_OUTPUT),
2234 2234
2235 HDA_CODEC_VOLUME("Mic Boost", 0x39, 0x0, HDA_OUTPUT), 2235 HDA_CODEC_VOLUME("Mic Boost Volume", 0x39, 0x0, HDA_OUTPUT),
2236 2236
2237 { 2237 {
2238 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 2238 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
@@ -2902,7 +2902,7 @@ static int new_analog_input(struct ad198x_spec *spec, hda_nid_t pin,
2902 idx = ad1988_pin_idx(pin); 2902 idx = ad1988_pin_idx(pin);
2903 bnid = ad1988_boost_nids[idx]; 2903 bnid = ad1988_boost_nids[idx];
2904 if (bnid) { 2904 if (bnid) {
2905 sprintf(name, "%s Boost", ctlname); 2905 sprintf(name, "%s Boost Volume", ctlname);
2906 return add_control(spec, AD_CTL_WIDGET_VOL, name, 2906 return add_control(spec, AD_CTL_WIDGET_VOL, name,
2907 HDA_COMPOSE_AMP_VAL(bnid, 3, idx, HDA_OUTPUT)); 2907 HDA_COMPOSE_AMP_VAL(bnid, 3, idx, HDA_OUTPUT));
2908 2908
@@ -3300,8 +3300,8 @@ static struct snd_kcontrol_new ad1884_base_mixers[] = {
3300 HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x01, HDA_INPUT), 3300 HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x01, HDA_INPUT),
3301 HDA_CODEC_VOLUME("CD Playback Volume", 0x20, 0x02, HDA_INPUT), 3301 HDA_CODEC_VOLUME("CD Playback Volume", 0x20, 0x02, HDA_INPUT),
3302 HDA_CODEC_MUTE("CD Playback Switch", 0x20, 0x02, HDA_INPUT), 3302 HDA_CODEC_MUTE("CD Playback Switch", 0x20, 0x02, HDA_INPUT),
3303 HDA_CODEC_VOLUME("Mic Boost", 0x15, 0x0, HDA_INPUT), 3303 HDA_CODEC_VOLUME("Mic Boost Volume", 0x15, 0x0, HDA_INPUT),
3304 HDA_CODEC_VOLUME("Front Mic Boost", 0x14, 0x0, HDA_INPUT), 3304 HDA_CODEC_VOLUME("Front Mic Boost Volume", 0x14, 0x0, HDA_INPUT),
3305 HDA_CODEC_VOLUME("Capture Volume", 0x0c, 0x0, HDA_OUTPUT), 3305 HDA_CODEC_VOLUME("Capture Volume", 0x0c, 0x0, HDA_OUTPUT),
3306 HDA_CODEC_MUTE("Capture Switch", 0x0c, 0x0, HDA_OUTPUT), 3306 HDA_CODEC_MUTE("Capture Switch", 0x0c, 0x0, HDA_OUTPUT),
3307 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x0d, 0x0, HDA_OUTPUT), 3307 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x0d, 0x0, HDA_OUTPUT),
@@ -3499,9 +3499,9 @@ static struct snd_kcontrol_new ad1984_thinkpad_mixers[] = {
3499 HDA_CODEC_MUTE("Beep Playback Switch", 0x20, 0x03, HDA_INPUT), 3499 HDA_CODEC_MUTE("Beep Playback Switch", 0x20, 0x03, HDA_INPUT),
3500 HDA_CODEC_VOLUME("Docking Mic Playback Volume", 0x20, 0x04, HDA_INPUT), 3500 HDA_CODEC_VOLUME("Docking Mic Playback Volume", 0x20, 0x04, HDA_INPUT),
3501 HDA_CODEC_MUTE("Docking Mic Playback Switch", 0x20, 0x04, HDA_INPUT), 3501 HDA_CODEC_MUTE("Docking Mic Playback Switch", 0x20, 0x04, HDA_INPUT),
3502 HDA_CODEC_VOLUME("Mic Boost", 0x14, 0x0, HDA_INPUT), 3502 HDA_CODEC_VOLUME("Mic Boost Volume", 0x14, 0x0, HDA_INPUT),
3503 HDA_CODEC_VOLUME("Internal Mic Boost", 0x15, 0x0, HDA_INPUT), 3503 HDA_CODEC_VOLUME("Internal Mic Boost Volume", 0x15, 0x0, HDA_INPUT),
3504 HDA_CODEC_VOLUME("Docking Mic Boost", 0x25, 0x0, HDA_OUTPUT), 3504 HDA_CODEC_VOLUME("Dock Mic Boost Volume", 0x25, 0x0, HDA_OUTPUT),
3505 HDA_CODEC_VOLUME("Capture Volume", 0x0c, 0x0, HDA_OUTPUT), 3505 HDA_CODEC_VOLUME("Capture Volume", 0x0c, 0x0, HDA_OUTPUT),
3506 HDA_CODEC_MUTE("Capture Switch", 0x0c, 0x0, HDA_OUTPUT), 3506 HDA_CODEC_MUTE("Capture Switch", 0x0c, 0x0, HDA_OUTPUT),
3507 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x0d, 0x0, HDA_OUTPUT), 3507 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x0d, 0x0, HDA_OUTPUT),
@@ -3560,8 +3560,8 @@ static struct snd_kcontrol_new ad1984_dell_desktop_mixers[] = {
3560 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x20, 0x00, HDA_INPUT), 3560 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x20, 0x00, HDA_INPUT),
3561 HDA_CODEC_VOLUME("Line-In Playback Volume", 0x20, 0x01, HDA_INPUT), 3561 HDA_CODEC_VOLUME("Line-In Playback Volume", 0x20, 0x01, HDA_INPUT),
3562 HDA_CODEC_MUTE("Line-In Playback Switch", 0x20, 0x01, HDA_INPUT), 3562 HDA_CODEC_MUTE("Line-In Playback Switch", 0x20, 0x01, HDA_INPUT),
3563 HDA_CODEC_VOLUME("Line-In Boost", 0x15, 0x0, HDA_INPUT), 3563 HDA_CODEC_VOLUME("Line-In Boost Volume", 0x15, 0x0, HDA_INPUT),
3564 HDA_CODEC_VOLUME("Front Mic Boost", 0x14, 0x0, HDA_INPUT), 3564 HDA_CODEC_VOLUME("Front Mic Boost Volume", 0x14, 0x0, HDA_INPUT),
3565 HDA_CODEC_VOLUME("Capture Volume", 0x0c, 0x0, HDA_OUTPUT), 3565 HDA_CODEC_VOLUME("Capture Volume", 0x0c, 0x0, HDA_OUTPUT),
3566 HDA_CODEC_MUTE("Capture Switch", 0x0c, 0x0, HDA_OUTPUT), 3566 HDA_CODEC_MUTE("Capture Switch", 0x0c, 0x0, HDA_OUTPUT),
3567 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x0d, 0x0, HDA_OUTPUT), 3567 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x0d, 0x0, HDA_OUTPUT),
@@ -3745,9 +3745,9 @@ static struct snd_kcontrol_new ad1884a_base_mixers[] = {
3745 HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x04, HDA_INPUT), 3745 HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x04, HDA_INPUT),
3746 HDA_CODEC_VOLUME("CD Playback Volume", 0x20, 0x02, HDA_INPUT), 3746 HDA_CODEC_VOLUME("CD Playback Volume", 0x20, 0x02, HDA_INPUT),
3747 HDA_CODEC_MUTE("CD Playback Switch", 0x20, 0x02, HDA_INPUT), 3747 HDA_CODEC_MUTE("CD Playback Switch", 0x20, 0x02, HDA_INPUT),
3748 HDA_CODEC_VOLUME("Front Mic Boost", 0x14, 0x0, HDA_INPUT), 3748 HDA_CODEC_VOLUME("Front Mic Boost Volume", 0x14, 0x0, HDA_INPUT),
3749 HDA_CODEC_VOLUME("Line Boost", 0x15, 0x0, HDA_INPUT), 3749 HDA_CODEC_VOLUME("Line Boost Volume", 0x15, 0x0, HDA_INPUT),
3750 HDA_CODEC_VOLUME("Mic Boost", 0x25, 0x0, HDA_OUTPUT), 3750 HDA_CODEC_VOLUME("Mic Boost Volume", 0x25, 0x0, HDA_OUTPUT),
3751 HDA_CODEC_VOLUME("Capture Volume", 0x0c, 0x0, HDA_OUTPUT), 3751 HDA_CODEC_VOLUME("Capture Volume", 0x0c, 0x0, HDA_OUTPUT),
3752 HDA_CODEC_MUTE("Capture Switch", 0x0c, 0x0, HDA_OUTPUT), 3752 HDA_CODEC_MUTE("Capture Switch", 0x0c, 0x0, HDA_OUTPUT),
3753 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x0d, 0x0, HDA_OUTPUT), 3753 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x0d, 0x0, HDA_OUTPUT),
@@ -3888,9 +3888,9 @@ static struct snd_kcontrol_new ad1884a_laptop_mixers[] = {
3888 HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x20, 0x01, HDA_INPUT), 3888 HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x20, 0x01, HDA_INPUT),
3889 HDA_CODEC_VOLUME("Dock Mic Playback Volume", 0x20, 0x04, HDA_INPUT), 3889 HDA_CODEC_VOLUME("Dock Mic Playback Volume", 0x20, 0x04, HDA_INPUT),
3890 HDA_CODEC_MUTE("Dock Mic Playback Switch", 0x20, 0x04, HDA_INPUT), 3890 HDA_CODEC_MUTE("Dock Mic Playback Switch", 0x20, 0x04, HDA_INPUT),
3891 HDA_CODEC_VOLUME("Mic Boost", 0x14, 0x0, HDA_INPUT), 3891 HDA_CODEC_VOLUME("Mic Boost Volume", 0x14, 0x0, HDA_INPUT),
3892 HDA_CODEC_VOLUME("Internal Mic Boost", 0x15, 0x0, HDA_INPUT), 3892 HDA_CODEC_VOLUME("Internal Mic Boost Volume", 0x15, 0x0, HDA_INPUT),
3893 HDA_CODEC_VOLUME("Dock Mic Boost", 0x25, 0x0, HDA_OUTPUT), 3893 HDA_CODEC_VOLUME("Dock Mic Boost Volume", 0x25, 0x0, HDA_OUTPUT),
3894 HDA_CODEC_VOLUME("Capture Volume", 0x0c, 0x0, HDA_OUTPUT), 3894 HDA_CODEC_VOLUME("Capture Volume", 0x0c, 0x0, HDA_OUTPUT),
3895 HDA_CODEC_MUTE("Capture Switch", 0x0c, 0x0, HDA_OUTPUT), 3895 HDA_CODEC_MUTE("Capture Switch", 0x0c, 0x0, HDA_OUTPUT),
3896 { } /* end */ 3896 { } /* end */
@@ -4126,8 +4126,8 @@ static struct snd_kcontrol_new ad1984a_thinkpad_mixers[] = {
4126 HDA_CODEC_MUTE("PCM Playback Switch", 0x20, 0x5, HDA_INPUT), 4126 HDA_CODEC_MUTE("PCM Playback Switch", 0x20, 0x5, HDA_INPUT),
4127 HDA_CODEC_VOLUME("Mic Playback Volume", 0x20, 0x00, HDA_INPUT), 4127 HDA_CODEC_VOLUME("Mic Playback Volume", 0x20, 0x00, HDA_INPUT),
4128 HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x00, HDA_INPUT), 4128 HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x00, HDA_INPUT),
4129 HDA_CODEC_VOLUME("Mic Boost", 0x14, 0x0, HDA_INPUT), 4129 HDA_CODEC_VOLUME("Mic Boost Volume", 0x14, 0x0, HDA_INPUT),
4130 HDA_CODEC_VOLUME("Internal Mic Boost", 0x17, 0x0, HDA_INPUT), 4130 HDA_CODEC_VOLUME("Internal Mic Boost Volume", 0x17, 0x0, HDA_INPUT),
4131 HDA_CODEC_VOLUME("Capture Volume", 0x0c, 0x0, HDA_OUTPUT), 4131 HDA_CODEC_VOLUME("Capture Volume", 0x0c, 0x0, HDA_OUTPUT),
4132 HDA_CODEC_MUTE("Capture Switch", 0x0c, 0x0, HDA_OUTPUT), 4132 HDA_CODEC_MUTE("Capture Switch", 0x0c, 0x0, HDA_OUTPUT),
4133 { 4133 {
@@ -4255,8 +4255,8 @@ static struct snd_kcontrol_new ad1984a_touchsmart_mixers[] = {
4255 HDA_CODEC_MUTE("PCM Playback Switch", 0x20, 0x5, HDA_INPUT), 4255 HDA_CODEC_MUTE("PCM Playback Switch", 0x20, 0x5, HDA_INPUT),
4256 HDA_CODEC_VOLUME("Capture Volume", 0x0c, 0x0, HDA_OUTPUT), 4256 HDA_CODEC_VOLUME("Capture Volume", 0x0c, 0x0, HDA_OUTPUT),
4257 HDA_CODEC_MUTE("Capture Switch", 0x0c, 0x0, HDA_OUTPUT), 4257 HDA_CODEC_MUTE("Capture Switch", 0x0c, 0x0, HDA_OUTPUT),
4258 HDA_CODEC_VOLUME("Mic Boost", 0x25, 0x0, HDA_OUTPUT), 4258 HDA_CODEC_VOLUME("Mic Boost Volume", 0x25, 0x0, HDA_OUTPUT),
4259 HDA_CODEC_VOLUME("Internal Mic Boost", 0x17, 0x0, HDA_INPUT), 4259 HDA_CODEC_VOLUME("Internal Mic Boost Volume", 0x17, 0x0, HDA_INPUT),
4260 { } /* end */ 4260 { } /* end */
4261}; 4261};
4262 4262
@@ -4494,9 +4494,9 @@ static struct snd_kcontrol_new ad1882_base_mixers[] = {
4494 HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x13, 1, 0x0, HDA_OUTPUT), 4494 HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x13, 1, 0x0, HDA_OUTPUT),
4495 HDA_CODEC_MUTE_MONO("Mono Playback Switch", 0x13, 1, 0x0, HDA_OUTPUT), 4495 HDA_CODEC_MUTE_MONO("Mono Playback Switch", 0x13, 1, 0x0, HDA_OUTPUT),
4496 4496
4497 HDA_CODEC_VOLUME("Mic Boost", 0x3c, 0x0, HDA_OUTPUT), 4497 HDA_CODEC_VOLUME("Mic Boost Volume", 0x3c, 0x0, HDA_OUTPUT),
4498 HDA_CODEC_VOLUME("Front Mic Boost", 0x39, 0x0, HDA_OUTPUT), 4498 HDA_CODEC_VOLUME("Front Mic Boost Volume", 0x39, 0x0, HDA_OUTPUT),
4499 HDA_CODEC_VOLUME("Line-In Boost", 0x3a, 0x0, HDA_OUTPUT), 4499 HDA_CODEC_VOLUME("Line-In Boost Volume", 0x3a, 0x0, HDA_OUTPUT),
4500 HDA_CODEC_VOLUME("Capture Volume", 0x0c, 0x0, HDA_OUTPUT), 4500 HDA_CODEC_VOLUME("Capture Volume", 0x0c, 0x0, HDA_OUTPUT),
4501 HDA_CODEC_MUTE("Capture Switch", 0x0c, 0x0, HDA_OUTPUT), 4501 HDA_CODEC_MUTE("Capture Switch", 0x0c, 0x0, HDA_OUTPUT),
4502 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x0d, 0x0, HDA_OUTPUT), 4502 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x0d, 0x0, HDA_OUTPUT),
@@ -4547,7 +4547,7 @@ static struct snd_kcontrol_new ad1882a_loopback_mixers[] = {
4547 HDA_CODEC_MUTE("Line Playback Switch", 0x20, 0x01, HDA_INPUT), 4547 HDA_CODEC_MUTE("Line Playback Switch", 0x20, 0x01, HDA_INPUT),
4548 HDA_CODEC_VOLUME("CD Playback Volume", 0x20, 0x06, HDA_INPUT), 4548 HDA_CODEC_VOLUME("CD Playback Volume", 0x20, 0x06, HDA_INPUT),
4549 HDA_CODEC_MUTE("CD Playback Switch", 0x20, 0x06, HDA_INPUT), 4549 HDA_CODEC_MUTE("CD Playback Switch", 0x20, 0x06, HDA_INPUT),
4550 HDA_CODEC_VOLUME("Digital Mic Boost", 0x1f, 0x0, HDA_INPUT), 4550 HDA_CODEC_VOLUME("Digital Mic Boost Volume", 0x1f, 0x0, HDA_INPUT),
4551 { } /* end */ 4551 { } /* end */
4552}; 4552};
4553 4553
diff --git a/sound/pci/hda/patch_conexant.c b/sound/pci/hda/patch_conexant.c
index 76bd58a0e2b6..e96581fcdbdb 100644
--- a/sound/pci/hda/patch_conexant.c
+++ b/sound/pci/hda/patch_conexant.c
@@ -869,16 +869,16 @@ static void cxt5045_hp_unsol_event(struct hda_codec *codec,
869} 869}
870 870
871static struct snd_kcontrol_new cxt5045_mixers[] = { 871static struct snd_kcontrol_new cxt5045_mixers[] = {
872 HDA_CODEC_VOLUME("Int Mic Capture Volume", 0x1a, 0x01, HDA_INPUT), 872 HDA_CODEC_VOLUME("Internal Mic Capture Volume", 0x1a, 0x01, HDA_INPUT),
873 HDA_CODEC_MUTE("Int Mic Capture Switch", 0x1a, 0x01, HDA_INPUT), 873 HDA_CODEC_MUTE("Internal Mic Capture Switch", 0x1a, 0x01, HDA_INPUT),
874 HDA_CODEC_VOLUME("Ext Mic Capture Volume", 0x1a, 0x02, HDA_INPUT), 874 HDA_CODEC_VOLUME("Mic Capture Volume", 0x1a, 0x02, HDA_INPUT),
875 HDA_CODEC_MUTE("Ext Mic Capture Switch", 0x1a, 0x02, HDA_INPUT), 875 HDA_CODEC_MUTE("Mic Capture Switch", 0x1a, 0x02, HDA_INPUT),
876 HDA_CODEC_VOLUME("PCM Playback Volume", 0x17, 0x0, HDA_INPUT), 876 HDA_CODEC_VOLUME("PCM Playback Volume", 0x17, 0x0, HDA_INPUT),
877 HDA_CODEC_MUTE("PCM Playback Switch", 0x17, 0x0, HDA_INPUT), 877 HDA_CODEC_MUTE("PCM Playback Switch", 0x17, 0x0, HDA_INPUT),
878 HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x17, 0x1, HDA_INPUT), 878 HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x17, 0x1, HDA_INPUT),
879 HDA_CODEC_MUTE("Int Mic Playback Switch", 0x17, 0x1, HDA_INPUT), 879 HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x17, 0x1, HDA_INPUT),
880 HDA_CODEC_VOLUME("Ext Mic Playback Volume", 0x17, 0x2, HDA_INPUT), 880 HDA_CODEC_VOLUME("Mic Playback Volume", 0x17, 0x2, HDA_INPUT),
881 HDA_CODEC_MUTE("Ext Mic Playback Switch", 0x17, 0x2, HDA_INPUT), 881 HDA_CODEC_MUTE("Mic Playback Switch", 0x17, 0x2, HDA_INPUT),
882 HDA_BIND_VOL("Master Playback Volume", &cxt5045_hp_bind_master_vol), 882 HDA_BIND_VOL("Master Playback Volume", &cxt5045_hp_bind_master_vol),
883 { 883 {
884 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 884 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
@@ -910,16 +910,16 @@ static struct snd_kcontrol_new cxt5045_benq_mixers[] = {
910}; 910};
911 911
912static struct snd_kcontrol_new cxt5045_mixers_hp530[] = { 912static struct snd_kcontrol_new cxt5045_mixers_hp530[] = {
913 HDA_CODEC_VOLUME("Int Mic Capture Volume", 0x1a, 0x02, HDA_INPUT), 913 HDA_CODEC_VOLUME("Internal Mic Capture Volume", 0x1a, 0x02, HDA_INPUT),
914 HDA_CODEC_MUTE("Int Mic Capture Switch", 0x1a, 0x02, HDA_INPUT), 914 HDA_CODEC_MUTE("Internal Mic Capture Switch", 0x1a, 0x02, HDA_INPUT),
915 HDA_CODEC_VOLUME("Ext Mic Capture Volume", 0x1a, 0x01, HDA_INPUT), 915 HDA_CODEC_VOLUME("Mic Capture Volume", 0x1a, 0x01, HDA_INPUT),
916 HDA_CODEC_MUTE("Ext Mic Capture Switch", 0x1a, 0x01, HDA_INPUT), 916 HDA_CODEC_MUTE("Mic Capture Switch", 0x1a, 0x01, HDA_INPUT),
917 HDA_CODEC_VOLUME("PCM Playback Volume", 0x17, 0x0, HDA_INPUT), 917 HDA_CODEC_VOLUME("PCM Playback Volume", 0x17, 0x0, HDA_INPUT),
918 HDA_CODEC_MUTE("PCM Playback Switch", 0x17, 0x0, HDA_INPUT), 918 HDA_CODEC_MUTE("PCM Playback Switch", 0x17, 0x0, HDA_INPUT),
919 HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x17, 0x2, HDA_INPUT), 919 HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x17, 0x2, HDA_INPUT),
920 HDA_CODEC_MUTE("Int Mic Playback Switch", 0x17, 0x2, HDA_INPUT), 920 HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x17, 0x2, HDA_INPUT),
921 HDA_CODEC_VOLUME("Ext Mic Playback Volume", 0x17, 0x1, HDA_INPUT), 921 HDA_CODEC_VOLUME("Mic Playback Volume", 0x17, 0x1, HDA_INPUT),
922 HDA_CODEC_MUTE("Ext Mic Playback Switch", 0x17, 0x1, HDA_INPUT), 922 HDA_CODEC_MUTE("Mic Playback Switch", 0x17, 0x1, HDA_INPUT),
923 HDA_BIND_VOL("Master Playback Volume", &cxt5045_hp_bind_master_vol), 923 HDA_BIND_VOL("Master Playback Volume", &cxt5045_hp_bind_master_vol),
924 { 924 {
925 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 925 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
@@ -947,7 +947,7 @@ static struct hda_verb cxt5045_init_verbs[] = {
947 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, 947 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
948 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, 948 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
949 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, 949 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
950 /* Record selector: Int mic */ 950 /* Record selector: Internal mic */
951 {0x1a, AC_VERB_SET_CONNECT_SEL,0x1}, 951 {0x1a, AC_VERB_SET_CONNECT_SEL,0x1},
952 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, 952 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE,
953 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17}, 953 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
@@ -960,7 +960,7 @@ static struct hda_verb cxt5045_init_verbs[] = {
960}; 960};
961 961
962static struct hda_verb cxt5045_benq_init_verbs[] = { 962static struct hda_verb cxt5045_benq_init_verbs[] = {
963 /* Int Mic, Mic */ 963 /* Internal Mic, Mic */
964 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 }, 964 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
965 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 }, 965 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
966 /* Line In,HP, Amp */ 966 /* Line In,HP, Amp */
@@ -973,7 +973,7 @@ static struct hda_verb cxt5045_benq_init_verbs[] = {
973 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, 973 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
974 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, 974 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
975 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, 975 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
976 /* Record selector: Int mic */ 976 /* Record selector: Internal mic */
977 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x1}, 977 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x1},
978 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, 978 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE,
979 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17}, 979 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
@@ -1376,7 +1376,7 @@ static void cxt5047_hp_unsol_event(struct hda_codec *codec,
1376static struct snd_kcontrol_new cxt5047_base_mixers[] = { 1376static struct snd_kcontrol_new cxt5047_base_mixers[] = {
1377 HDA_CODEC_VOLUME("Mic Playback Volume", 0x19, 0x02, HDA_INPUT), 1377 HDA_CODEC_VOLUME("Mic Playback Volume", 0x19, 0x02, HDA_INPUT),
1378 HDA_CODEC_MUTE("Mic Playback Switch", 0x19, 0x02, HDA_INPUT), 1378 HDA_CODEC_MUTE("Mic Playback Switch", 0x19, 0x02, HDA_INPUT),
1379 HDA_CODEC_VOLUME("Mic Boost", 0x1a, 0x0, HDA_OUTPUT), 1379 HDA_CODEC_VOLUME("Mic Boost Volume", 0x1a, 0x0, HDA_OUTPUT),
1380 HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x03, HDA_INPUT), 1380 HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x03, HDA_INPUT),
1381 HDA_CODEC_MUTE("Capture Switch", 0x12, 0x03, HDA_INPUT), 1381 HDA_CODEC_MUTE("Capture Switch", 0x12, 0x03, HDA_INPUT),
1382 HDA_CODEC_VOLUME("PCM Volume", 0x10, 0x00, HDA_OUTPUT), 1382 HDA_CODEC_VOLUME("PCM Volume", 0x10, 0x00, HDA_OUTPUT),
@@ -1796,8 +1796,8 @@ static struct snd_kcontrol_new cxt5051_playback_mixers[] = {
1796static struct snd_kcontrol_new cxt5051_capture_mixers[] = { 1796static struct snd_kcontrol_new cxt5051_capture_mixers[] = {
1797 HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT), 1797 HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
1798 HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT), 1798 HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
1799 HDA_CODEC_VOLUME("External Mic Volume", 0x14, 0x01, HDA_INPUT), 1799 HDA_CODEC_VOLUME("Mic Volume", 0x14, 0x01, HDA_INPUT),
1800 HDA_CODEC_MUTE("External Mic Switch", 0x14, 0x01, HDA_INPUT), 1800 HDA_CODEC_MUTE("Mic Switch", 0x14, 0x01, HDA_INPUT),
1801 HDA_CODEC_VOLUME("Docking Mic Volume", 0x15, 0x00, HDA_INPUT), 1801 HDA_CODEC_VOLUME("Docking Mic Volume", 0x15, 0x00, HDA_INPUT),
1802 HDA_CODEC_MUTE("Docking Mic Switch", 0x15, 0x00, HDA_INPUT), 1802 HDA_CODEC_MUTE("Docking Mic Switch", 0x15, 0x00, HDA_INPUT),
1803 {} 1803 {}
@@ -1806,8 +1806,8 @@ static struct snd_kcontrol_new cxt5051_capture_mixers[] = {
1806static struct snd_kcontrol_new cxt5051_hp_mixers[] = { 1806static struct snd_kcontrol_new cxt5051_hp_mixers[] = {
1807 HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT), 1807 HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
1808 HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT), 1808 HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
1809 HDA_CODEC_VOLUME("External Mic Volume", 0x15, 0x00, HDA_INPUT), 1809 HDA_CODEC_VOLUME("Mic Volume", 0x15, 0x00, HDA_INPUT),
1810 HDA_CODEC_MUTE("External Mic Switch", 0x15, 0x00, HDA_INPUT), 1810 HDA_CODEC_MUTE("Mic Switch", 0x15, 0x00, HDA_INPUT),
1811 {} 1811 {}
1812}; 1812};
1813 1813
@@ -1826,8 +1826,8 @@ static struct snd_kcontrol_new cxt5051_f700_mixers[] = {
1826static struct snd_kcontrol_new cxt5051_toshiba_mixers[] = { 1826static struct snd_kcontrol_new cxt5051_toshiba_mixers[] = {
1827 HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT), 1827 HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
1828 HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT), 1828 HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
1829 HDA_CODEC_VOLUME("External Mic Volume", 0x14, 0x01, HDA_INPUT), 1829 HDA_CODEC_VOLUME("Mic Volume", 0x14, 0x01, HDA_INPUT),
1830 HDA_CODEC_MUTE("External Mic Switch", 0x14, 0x01, HDA_INPUT), 1830 HDA_CODEC_MUTE("Mic Switch", 0x14, 0x01, HDA_INPUT),
1831 {} 1831 {}
1832}; 1832};
1833 1833
@@ -1847,7 +1847,7 @@ static struct hda_verb cxt5051_init_verbs[] = {
1847 {0x16, AC_VERB_SET_CONNECT_SEL, 0x00}, 1847 {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
1848 /* DAC1 */ 1848 /* DAC1 */
1849 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 1849 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1850 /* Record selector: Int mic */ 1850 /* Record selector: Internal mic */
1851 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44}, 1851 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
1852 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44}, 1852 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
1853 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44}, 1853 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
@@ -1874,7 +1874,7 @@ static struct hda_verb cxt5051_hp_dv6736_init_verbs[] = {
1874 {0x16, AC_VERB_SET_CONNECT_SEL, 0x00}, 1874 {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
1875 /* DAC1 */ 1875 /* DAC1 */
1876 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 1876 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1877 /* Record selector: Int mic */ 1877 /* Record selector: Internal mic */
1878 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44}, 1878 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
1879 {0x14, AC_VERB_SET_CONNECT_SEL, 0x1}, 1879 {0x14, AC_VERB_SET_CONNECT_SEL, 0x1},
1880 /* SPDIF route: PCM */ 1880 /* SPDIF route: PCM */
@@ -1904,7 +1904,7 @@ static struct hda_verb cxt5051_lenovo_x200_init_verbs[] = {
1904 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, 1904 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00},
1905 /* DAC1 */ 1905 /* DAC1 */
1906 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 1906 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1907 /* Record selector: Int mic */ 1907 /* Record selector: Internal mic */
1908 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44}, 1908 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
1909 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44}, 1909 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
1910 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44}, 1910 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
@@ -1932,7 +1932,7 @@ static struct hda_verb cxt5051_f700_init_verbs[] = {
1932 {0x16, AC_VERB_SET_CONNECT_SEL, 0x00}, 1932 {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
1933 /* DAC1 */ 1933 /* DAC1 */
1934 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 1934 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1935 /* Record selector: Int mic */ 1935 /* Record selector: Internal mic */
1936 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44}, 1936 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
1937 {0x14, AC_VERB_SET_CONNECT_SEL, 0x1}, 1937 {0x14, AC_VERB_SET_CONNECT_SEL, 0x1},
1938 /* SPDIF route: PCM */ 1938 /* SPDIF route: PCM */
@@ -2111,6 +2111,11 @@ static struct hda_channel_mode cxt5066_modes[1] = {
2111 { 2, NULL }, 2111 { 2, NULL },
2112}; 2112};
2113 2113
2114#define HP_PRESENT_PORT_A (1 << 0)
2115#define HP_PRESENT_PORT_D (1 << 1)
2116#define hp_port_a_present(spec) ((spec)->hp_present & HP_PRESENT_PORT_A)
2117#define hp_port_d_present(spec) ((spec)->hp_present & HP_PRESENT_PORT_D)
2118
2114static void cxt5066_update_speaker(struct hda_codec *codec) 2119static void cxt5066_update_speaker(struct hda_codec *codec)
2115{ 2120{
2116 struct conexant_spec *spec = codec->spec; 2121 struct conexant_spec *spec = codec->spec;
@@ -2120,24 +2125,20 @@ static void cxt5066_update_speaker(struct hda_codec *codec)
2120 spec->hp_present, spec->cur_eapd); 2125 spec->hp_present, spec->cur_eapd);
2121 2126
2122 /* Port A (HP) */ 2127 /* Port A (HP) */
2123 pinctl = ((spec->hp_present & 1) && spec->cur_eapd) ? PIN_HP : 0; 2128 pinctl = (hp_port_a_present(spec) && spec->cur_eapd) ? PIN_HP : 0;
2124 snd_hda_codec_write(codec, 0x19, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, 2129 snd_hda_codec_write(codec, 0x19, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
2125 pinctl); 2130 pinctl);
2126 2131
2127 /* Port D (HP/LO) */ 2132 /* Port D (HP/LO) */
2128 if (spec->dell_automute) { 2133 pinctl = spec->cur_eapd ? spec->port_d_mode : 0;
2129 /* DELL AIO Port Rule: PortA> PortD> IntSpk */ 2134 if (spec->dell_automute || spec->thinkpad) {
2130 pinctl = (!(spec->hp_present & 1) && spec->cur_eapd) 2135 /* Mute if Port A is connected */
2131 ? PIN_OUT : 0; 2136 if (hp_port_a_present(spec))
2132 } else if (spec->thinkpad) {
2133 if (spec->cur_eapd)
2134 pinctl = spec->port_d_mode;
2135 /* Mute dock line-out if Port A (laptop HP) is present */
2136 if (spec->hp_present& 1)
2137 pinctl = 0; 2137 pinctl = 0;
2138 } else { 2138 } else {
2139 pinctl = ((spec->hp_present & 2) && spec->cur_eapd) 2139 /* Thinkpad/Dell doesn't give pin-D status */
2140 ? spec->port_d_mode : 0; 2140 if (!hp_port_d_present(spec))
2141 pinctl = 0;
2141 } 2142 }
2142 snd_hda_codec_write(codec, 0x1c, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, 2143 snd_hda_codec_write(codec, 0x1c, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
2143 pinctl); 2144 pinctl);
@@ -2379,8 +2380,8 @@ static void cxt5066_hp_automute(struct hda_codec *codec)
2379 /* Port D */ 2380 /* Port D */
2380 portD = snd_hda_jack_detect(codec, 0x1c); 2381 portD = snd_hda_jack_detect(codec, 0x1c);
2381 2382
2382 spec->hp_present = !!(portA); 2383 spec->hp_present = portA ? HP_PRESENT_PORT_A : 0;
2383 spec->hp_present |= portD ? 2 : 0; 2384 spec->hp_present |= portD ? HP_PRESENT_PORT_D : 0;
2384 snd_printdd("CXT5066: hp automute portA=%x portD=%x present=%d\n", 2385 snd_printdd("CXT5066: hp automute portA=%x portD=%x present=%d\n",
2385 portA, portD, spec->hp_present); 2386 portA, portD, spec->hp_present);
2386 cxt5066_update_speaker(codec); 2387 cxt5066_update_speaker(codec);
@@ -2728,7 +2729,7 @@ static struct snd_kcontrol_new cxt5066_mixers[] = {
2728static struct snd_kcontrol_new cxt5066_vostro_mixers[] = { 2729static struct snd_kcontrol_new cxt5066_vostro_mixers[] = {
2729 { 2730 {
2730 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 2731 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2731 .name = "Int Mic Boost Capture Enum", 2732 .name = "Internal Mic Boost Capture Enum",
2732 .info = cxt5066_mic_boost_mux_enum_info, 2733 .info = cxt5066_mic_boost_mux_enum_info,
2733 .get = cxt5066_mic_boost_mux_enum_get, 2734 .get = cxt5066_mic_boost_mux_enum_get,
2734 .put = cxt5066_mic_boost_mux_enum_put, 2735 .put = cxt5066_mic_boost_mux_enum_put,
@@ -2954,7 +2955,7 @@ static struct hda_verb cxt5066_init_verbs_ideapad[] = {
2954 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 2955 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2955 2956
2956 /* internal microphone */ 2957 /* internal microphone */
2957 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* enable int mic */ 2958 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* enable internal mic */
2958 2959
2959 /* EAPD */ 2960 /* EAPD */
2960 {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */ 2961 {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
@@ -3009,7 +3010,7 @@ static struct hda_verb cxt5066_init_verbs_thinkpad[] = {
3009 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 3010 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3010 3011
3011 /* internal microphone */ 3012 /* internal microphone */
3012 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* enable int mic */ 3013 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* enable internal mic */
3013 3014
3014 /* EAPD */ 3015 /* EAPD */
3015 {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */ 3016 {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
@@ -3097,6 +3098,7 @@ static struct snd_pci_quirk cxt5066_cfg_tbl[] = {
3097 SND_PCI_QUIRK_MASK(0x1025, 0xff00, 0x0400, "Acer", CXT5066_IDEAPAD), 3098 SND_PCI_QUIRK_MASK(0x1025, 0xff00, 0x0400, "Acer", CXT5066_IDEAPAD),
3098 SND_PCI_QUIRK(0x1028, 0x02d8, "Dell Vostro", CXT5066_DELL_VOSTRO), 3099 SND_PCI_QUIRK(0x1028, 0x02d8, "Dell Vostro", CXT5066_DELL_VOSTRO),
3099 SND_PCI_QUIRK(0x1028, 0x02f5, "Dell Vostro 320", CXT5066_IDEAPAD), 3100 SND_PCI_QUIRK(0x1028, 0x02f5, "Dell Vostro 320", CXT5066_IDEAPAD),
3101 SND_PCI_QUIRK(0x1028, 0x0401, "Dell Vostro 1014", CXT5066_DELL_VOSTRO),
3100 SND_PCI_QUIRK(0x1028, 0x0402, "Dell Vostro", CXT5066_DELL_VOSTRO), 3102 SND_PCI_QUIRK(0x1028, 0x0402, "Dell Vostro", CXT5066_DELL_VOSTRO),
3101 SND_PCI_QUIRK(0x1028, 0x0408, "Dell Inspiron One 19T", CXT5066_IDEAPAD), 3103 SND_PCI_QUIRK(0x1028, 0x0408, "Dell Inspiron One 19T", CXT5066_IDEAPAD),
3102 SND_PCI_QUIRK(0x103c, 0x360b, "HP G60", CXT5066_HP_LAPTOP), 3104 SND_PCI_QUIRK(0x103c, 0x360b, "HP G60", CXT5066_HP_LAPTOP),
@@ -3108,16 +3110,9 @@ static struct snd_pci_quirk cxt5066_cfg_tbl[] = {
3108 CXT5066_LAPTOP), 3110 CXT5066_LAPTOP),
3109 SND_PCI_QUIRK(0x152d, 0x0833, "OLPC XO-1.5", CXT5066_OLPC_XO_1_5), 3111 SND_PCI_QUIRK(0x152d, 0x0833, "OLPC XO-1.5", CXT5066_OLPC_XO_1_5),
3110 SND_PCI_QUIRK(0x17aa, 0x20f2, "Lenovo T400s", CXT5066_THINKPAD), 3112 SND_PCI_QUIRK(0x17aa, 0x20f2, "Lenovo T400s", CXT5066_THINKPAD),
3111 SND_PCI_QUIRK(0x17aa, 0x21b2, "Thinkpad X100e", CXT5066_IDEAPAD),
3112 SND_PCI_QUIRK(0x17aa, 0x21c5, "Thinkpad Edge 13", CXT5066_THINKPAD), 3113 SND_PCI_QUIRK(0x17aa, 0x21c5, "Thinkpad Edge 13", CXT5066_THINKPAD),
3113 SND_PCI_QUIRK(0x17aa, 0x21b3, "Thinkpad Edge 13 (197)", CXT5066_IDEAPAD),
3114 SND_PCI_QUIRK(0x17aa, 0x21b4, "Thinkpad Edge", CXT5066_IDEAPAD),
3115 SND_PCI_QUIRK(0x17aa, 0x21c8, "Thinkpad Edge 11", CXT5066_IDEAPAD),
3116 SND_PCI_QUIRK(0x17aa, 0x215e, "Lenovo Thinkpad", CXT5066_THINKPAD), 3114 SND_PCI_QUIRK(0x17aa, 0x215e, "Lenovo Thinkpad", CXT5066_THINKPAD),
3117 SND_PCI_QUIRK(0x17aa, 0x38af, "Lenovo G series", CXT5066_IDEAPAD), 3115 SND_PCI_QUIRK_VENDOR(0x17aa, "Lenovo", CXT5066_IDEAPAD), /* Fallback for Lenovos without dock mic */
3118 SND_PCI_QUIRK(0x17aa, 0x390a, "Lenovo S10-3t", CXT5066_IDEAPAD),
3119 SND_PCI_QUIRK(0x17aa, 0x3938, "Lenovo G series (AMD)", CXT5066_IDEAPAD),
3120 SND_PCI_QUIRK(0x17aa, 0x3a0d, "ideapad", CXT5066_IDEAPAD),
3121 {} 3116 {}
3122}; 3117};
3123 3118
@@ -3422,6 +3417,9 @@ static void cx_auto_hp_automute(struct hda_codec *codec)
3422 AC_VERB_SET_PIN_WIDGET_CONTROL, 3417 AC_VERB_SET_PIN_WIDGET_CONTROL,
3423 present ? 0 : PIN_OUT); 3418 present ? 0 : PIN_OUT);
3424 } 3419 }
3420 for (i = 0; !present && i < cfg->line_outs; i++)
3421 if (snd_hda_jack_detect(codec, cfg->line_out_pins[i]))
3422 present = 1;
3425 for (i = 0; i < cfg->speaker_outs; i++) { 3423 for (i = 0; i < cfg->speaker_outs; i++) {
3426 snd_hda_codec_write(codec, cfg->speaker_pins[i], 0, 3424 snd_hda_codec_write(codec, cfg->speaker_pins[i], 0,
3427 AC_VERB_SET_PIN_WIDGET_CONTROL, 3425 AC_VERB_SET_PIN_WIDGET_CONTROL,
diff --git a/sound/pci/hda/patch_hdmi.c b/sound/pci/hda/patch_hdmi.c
index 31df7747990d..f29b97b5de8f 100644
--- a/sound/pci/hda/patch_hdmi.c
+++ b/sound/pci/hda/patch_hdmi.c
@@ -31,10 +31,15 @@
31#include <linux/init.h> 31#include <linux/init.h>
32#include <linux/delay.h> 32#include <linux/delay.h>
33#include <linux/slab.h> 33#include <linux/slab.h>
34#include <linux/moduleparam.h>
34#include <sound/core.h> 35#include <sound/core.h>
35#include "hda_codec.h" 36#include "hda_codec.h"
36#include "hda_local.h" 37#include "hda_local.h"
37 38
39static bool static_hdmi_pcm;
40module_param(static_hdmi_pcm, bool, 0644);
41MODULE_PARM_DESC(static_hdmi_pcm, "Don't restrict PCM parameters per ELD info");
42
38/* 43/*
39 * The HDMI/DisplayPort configuration can be highly dynamic. A graphics device 44 * The HDMI/DisplayPort configuration can be highly dynamic. A graphics device
40 * could support two independent pipes, each of them can be connected to one or 45 * could support two independent pipes, each of them can be connected to one or
@@ -827,7 +832,7 @@ static int hdmi_pcm_open(struct hda_pcm_stream *hinfo,
827 *codec_pars = *hinfo; 832 *codec_pars = *hinfo;
828 833
829 eld = &spec->sink_eld[idx]; 834 eld = &spec->sink_eld[idx];
830 if (eld->sad_count > 0) { 835 if (!static_hdmi_pcm && eld->eld_valid && eld->sad_count > 0) {
831 hdmi_eld_update_pcm_info(eld, hinfo, codec_pars); 836 hdmi_eld_update_pcm_info(eld, hinfo, codec_pars);
832 if (hinfo->channels_min > hinfo->channels_max || 837 if (hinfo->channels_min > hinfo->channels_max ||
833 !hinfo->rates || !hinfo->formats) 838 !hinfo->rates || !hinfo->formats)
@@ -904,23 +909,28 @@ static int hdmi_add_pin(struct hda_codec *codec, hda_nid_t pin_nid)
904 spec->pin[spec->num_pins] = pin_nid; 909 spec->pin[spec->num_pins] = pin_nid;
905 spec->num_pins++; 910 spec->num_pins++;
906 911
907 /*
908 * It is assumed that converter nodes come first in the node list and
909 * hence have been registered and usable now.
910 */
911 return hdmi_read_pin_conn(codec, pin_nid); 912 return hdmi_read_pin_conn(codec, pin_nid);
912} 913}
913 914
914static int hdmi_add_cvt(struct hda_codec *codec, hda_nid_t nid) 915static int hdmi_add_cvt(struct hda_codec *codec, hda_nid_t nid)
915{ 916{
917 int i, found_pin = 0;
916 struct hdmi_spec *spec = codec->spec; 918 struct hdmi_spec *spec = codec->spec;
917 919
918 if (spec->num_cvts >= MAX_HDMI_CVTS) { 920 for (i = 0; i < spec->num_pins; i++)
919 snd_printk(KERN_WARNING 921 if (nid == spec->pin_cvt[i]) {
920 "HDMI: no space for converter %d\n", nid); 922 found_pin = 1;
921 return -E2BIG; 923 break;
924 }
925
926 if (!found_pin) {
927 snd_printdd("HDMI: Skipping node %d (no connection)\n", nid);
928 return -EINVAL;
922 } 929 }
923 930
931 if (snd_BUG_ON(spec->num_cvts >= MAX_HDMI_CVTS))
932 return -E2BIG;
933
924 spec->cvt[spec->num_cvts] = nid; 934 spec->cvt[spec->num_cvts] = nid;
925 spec->num_cvts++; 935 spec->num_cvts++;
926 936
@@ -931,6 +941,8 @@ static int hdmi_parse_codec(struct hda_codec *codec)
931{ 941{
932 hda_nid_t nid; 942 hda_nid_t nid;
933 int i, nodes; 943 int i, nodes;
944 int num_tmp_cvts = 0;
945 hda_nid_t tmp_cvt[MAX_HDMI_CVTS];
934 946
935 nodes = snd_hda_get_sub_nodes(codec, codec->afg, &nid); 947 nodes = snd_hda_get_sub_nodes(codec, codec->afg, &nid);
936 if (!nid || nodes < 0) { 948 if (!nid || nodes < 0) {
@@ -941,6 +953,7 @@ static int hdmi_parse_codec(struct hda_codec *codec)
941 for (i = 0; i < nodes; i++, nid++) { 953 for (i = 0; i < nodes; i++, nid++) {
942 unsigned int caps; 954 unsigned int caps;
943 unsigned int type; 955 unsigned int type;
956 unsigned int config;
944 957
945 caps = snd_hda_param_read(codec, nid, AC_PAR_AUDIO_WIDGET_CAP); 958 caps = snd_hda_param_read(codec, nid, AC_PAR_AUDIO_WIDGET_CAP);
946 type = get_wcaps_type(caps); 959 type = get_wcaps_type(caps);
@@ -950,17 +963,32 @@ static int hdmi_parse_codec(struct hda_codec *codec)
950 963
951 switch (type) { 964 switch (type) {
952 case AC_WID_AUD_OUT: 965 case AC_WID_AUD_OUT:
953 hdmi_add_cvt(codec, nid); 966 if (num_tmp_cvts >= MAX_HDMI_CVTS) {
967 snd_printk(KERN_WARNING
968 "HDMI: no space for converter %d\n", nid);
969 continue;
970 }
971 tmp_cvt[num_tmp_cvts] = nid;
972 num_tmp_cvts++;
954 break; 973 break;
955 case AC_WID_PIN: 974 case AC_WID_PIN:
956 caps = snd_hda_param_read(codec, nid, AC_PAR_PIN_CAP); 975 caps = snd_hda_param_read(codec, nid, AC_PAR_PIN_CAP);
957 if (!(caps & (AC_PINCAP_HDMI | AC_PINCAP_DP))) 976 if (!(caps & (AC_PINCAP_HDMI | AC_PINCAP_DP)))
958 continue; 977 continue;
978
979 config = snd_hda_codec_read(codec, nid, 0,
980 AC_VERB_GET_CONFIG_DEFAULT, 0);
981 if (get_defcfg_connect(config) == AC_JACK_PORT_NONE)
982 continue;
983
959 hdmi_add_pin(codec, nid); 984 hdmi_add_pin(codec, nid);
960 break; 985 break;
961 } 986 }
962 } 987 }
963 988
989 for (i = 0; i < num_tmp_cvts; i++)
990 hdmi_add_cvt(codec, tmp_cvt[i]);
991
964 /* 992 /*
965 * G45/IbexPeak don't support EPSS: the unsolicited pin hot plug event 993 * G45/IbexPeak don't support EPSS: the unsolicited pin hot plug event
966 * can be lost and presence sense verb will become inaccurate if the 994 * can be lost and presence sense verb will become inaccurate if the
@@ -1165,11 +1193,53 @@ static int nvhdmi_7x_init(struct hda_codec *codec)
1165 return 0; 1193 return 0;
1166} 1194}
1167 1195
1196static unsigned int channels_2_6_8[] = {
1197 2, 6, 8
1198};
1199
1200static unsigned int channels_2_8[] = {
1201 2, 8
1202};
1203
1204static struct snd_pcm_hw_constraint_list hw_constraints_2_6_8_channels = {
1205 .count = ARRAY_SIZE(channels_2_6_8),
1206 .list = channels_2_6_8,
1207 .mask = 0,
1208};
1209
1210static struct snd_pcm_hw_constraint_list hw_constraints_2_8_channels = {
1211 .count = ARRAY_SIZE(channels_2_8),
1212 .list = channels_2_8,
1213 .mask = 0,
1214};
1215
1168static int simple_playback_pcm_open(struct hda_pcm_stream *hinfo, 1216static int simple_playback_pcm_open(struct hda_pcm_stream *hinfo,
1169 struct hda_codec *codec, 1217 struct hda_codec *codec,
1170 struct snd_pcm_substream *substream) 1218 struct snd_pcm_substream *substream)
1171{ 1219{
1172 struct hdmi_spec *spec = codec->spec; 1220 struct hdmi_spec *spec = codec->spec;
1221 struct snd_pcm_hw_constraint_list *hw_constraints_channels = NULL;
1222
1223 switch (codec->preset->id) {
1224 case 0x10de0002:
1225 case 0x10de0003:
1226 case 0x10de0005:
1227 case 0x10de0006:
1228 hw_constraints_channels = &hw_constraints_2_8_channels;
1229 break;
1230 case 0x10de0007:
1231 hw_constraints_channels = &hw_constraints_2_6_8_channels;
1232 break;
1233 default:
1234 break;
1235 }
1236
1237 if (hw_constraints_channels != NULL) {
1238 snd_pcm_hw_constraint_list(substream->runtime, 0,
1239 SNDRV_PCM_HW_PARAM_CHANNELS,
1240 hw_constraints_channels);
1241 }
1242
1173 return snd_hda_multi_out_dig_open(codec, &spec->multiout); 1243 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
1174} 1244}
1175 1245
@@ -1532,7 +1602,7 @@ static struct hda_codec_preset snd_hda_preset_hdmi[] = {
1532{ .id = 0x1002793c, .name = "RS600 HDMI", .patch = patch_atihdmi }, 1602{ .id = 0x1002793c, .name = "RS600 HDMI", .patch = patch_atihdmi },
1533{ .id = 0x10027919, .name = "RS600 HDMI", .patch = patch_atihdmi }, 1603{ .id = 0x10027919, .name = "RS600 HDMI", .patch = patch_atihdmi },
1534{ .id = 0x1002791a, .name = "RS690/780 HDMI", .patch = patch_atihdmi }, 1604{ .id = 0x1002791a, .name = "RS690/780 HDMI", .patch = patch_atihdmi },
1535{ .id = 0x1002aa01, .name = "R6xx HDMI", .patch = patch_atihdmi }, 1605{ .id = 0x1002aa01, .name = "R6xx HDMI", .patch = patch_generic_hdmi },
1536{ .id = 0x10951390, .name = "SiI1390 HDMI", .patch = patch_generic_hdmi }, 1606{ .id = 0x10951390, .name = "SiI1390 HDMI", .patch = patch_generic_hdmi },
1537{ .id = 0x10951392, .name = "SiI1392 HDMI", .patch = patch_generic_hdmi }, 1607{ .id = 0x10951392, .name = "SiI1392 HDMI", .patch = patch_generic_hdmi },
1538{ .id = 0x17e80047, .name = "Chrontel HDMI", .patch = patch_generic_hdmi }, 1608{ .id = 0x17e80047, .name = "Chrontel HDMI", .patch = patch_generic_hdmi },
diff --git a/sound/pci/hda/patch_realtek.c b/sound/pci/hda/patch_realtek.c
index 552a09e9211f..51c08edd7563 100644
--- a/sound/pci/hda/patch_realtek.c
+++ b/sound/pci/hda/patch_realtek.c
@@ -231,7 +231,6 @@ enum {
231 ALC888_ACER_ASPIRE_8930G, 231 ALC888_ACER_ASPIRE_8930G,
232 ALC888_ACER_ASPIRE_7730G, 232 ALC888_ACER_ASPIRE_7730G,
233 ALC883_MEDION, 233 ALC883_MEDION,
234 ALC883_MEDION_MD2,
235 ALC883_MEDION_WIM2160, 234 ALC883_MEDION_WIM2160,
236 ALC883_LAPTOP_EAPD, 235 ALC883_LAPTOP_EAPD,
237 ALC883_LENOVO_101E_2ch, 236 ALC883_LENOVO_101E_2ch,
@@ -1678,29 +1677,32 @@ struct alc_pincfg {
1678 u32 val; 1677 u32 val;
1679}; 1678};
1680 1679
1680struct alc_model_fixup {
1681 const int id;
1682 const char *name;
1683};
1684
1681struct alc_fixup { 1685struct alc_fixup {
1682 unsigned int sku; 1686 unsigned int sku;
1683 const struct alc_pincfg *pins; 1687 const struct alc_pincfg *pins;
1684 const struct hda_verb *verbs; 1688 const struct hda_verb *verbs;
1689 void (*func)(struct hda_codec *codec, const struct alc_fixup *fix,
1690 int pre_init);
1685}; 1691};
1686 1692
1687static void alc_pick_fixup(struct hda_codec *codec, 1693static void __alc_pick_fixup(struct hda_codec *codec,
1688 const struct snd_pci_quirk *quirk, 1694 const struct alc_fixup *fix,
1689 const struct alc_fixup *fix, 1695 const char *modelname,
1690 int pre_init) 1696 int pre_init)
1691{ 1697{
1692 const struct alc_pincfg *cfg; 1698 const struct alc_pincfg *cfg;
1693 struct alc_spec *spec; 1699 struct alc_spec *spec;
1694 1700
1695 quirk = snd_pci_quirk_lookup(codec->bus->pci, quirk);
1696 if (!quirk)
1697 return;
1698 fix += quirk->value;
1699 cfg = fix->pins; 1701 cfg = fix->pins;
1700 if (pre_init && fix->sku) { 1702 if (pre_init && fix->sku) {
1701#ifdef CONFIG_SND_DEBUG_VERBOSE 1703#ifdef CONFIG_SND_DEBUG_VERBOSE
1702 snd_printdd(KERN_INFO "hda_codec: %s: Apply sku override for %s\n", 1704 snd_printdd(KERN_INFO "hda_codec: %s: Apply sku override for %s\n",
1703 codec->chip_name, quirk->name); 1705 codec->chip_name, modelname);
1704#endif 1706#endif
1705 spec = codec->spec; 1707 spec = codec->spec;
1706 spec->cdefine.sku_cfg = fix->sku; 1708 spec->cdefine.sku_cfg = fix->sku;
@@ -1709,7 +1711,7 @@ static void alc_pick_fixup(struct hda_codec *codec,
1709 if (pre_init && cfg) { 1711 if (pre_init && cfg) {
1710#ifdef CONFIG_SND_DEBUG_VERBOSE 1712#ifdef CONFIG_SND_DEBUG_VERBOSE
1711 snd_printdd(KERN_INFO "hda_codec: %s: Apply pincfg for %s\n", 1713 snd_printdd(KERN_INFO "hda_codec: %s: Apply pincfg for %s\n",
1712 codec->chip_name, quirk->name); 1714 codec->chip_name, modelname);
1713#endif 1715#endif
1714 for (; cfg->nid; cfg++) 1716 for (; cfg->nid; cfg++)
1715 snd_hda_codec_set_pincfg(codec, cfg->nid, cfg->val); 1717 snd_hda_codec_set_pincfg(codec, cfg->nid, cfg->val);
@@ -1717,10 +1719,53 @@ static void alc_pick_fixup(struct hda_codec *codec,
1717 if (!pre_init && fix->verbs) { 1719 if (!pre_init && fix->verbs) {
1718#ifdef CONFIG_SND_DEBUG_VERBOSE 1720#ifdef CONFIG_SND_DEBUG_VERBOSE
1719 snd_printdd(KERN_INFO "hda_codec: %s: Apply fix-verbs for %s\n", 1721 snd_printdd(KERN_INFO "hda_codec: %s: Apply fix-verbs for %s\n",
1720 codec->chip_name, quirk->name); 1722 codec->chip_name, modelname);
1721#endif 1723#endif
1722 add_verb(codec->spec, fix->verbs); 1724 add_verb(codec->spec, fix->verbs);
1723 } 1725 }
1726 if (fix->func) {
1727#ifdef CONFIG_SND_DEBUG_VERBOSE
1728 snd_printdd(KERN_INFO "hda_codec: %s: Apply fix-func for %s\n",
1729 codec->chip_name, modelname);
1730#endif
1731 fix->func(codec, fix, pre_init);
1732 }
1733}
1734
1735static void alc_pick_fixup(struct hda_codec *codec,
1736 const struct snd_pci_quirk *quirk,
1737 const struct alc_fixup *fix,
1738 int pre_init)
1739{
1740 quirk = snd_pci_quirk_lookup(codec->bus->pci, quirk);
1741 if (quirk) {
1742 fix += quirk->value;
1743#ifdef CONFIG_SND_DEBUG_VERBOSE
1744 __alc_pick_fixup(codec, fix, quirk->name, pre_init);
1745#else
1746 __alc_pick_fixup(codec, fix, NULL, pre_init);
1747#endif
1748 }
1749}
1750
1751static void alc_pick_fixup_model(struct hda_codec *codec,
1752 const struct alc_model_fixup *models,
1753 const struct snd_pci_quirk *quirk,
1754 const struct alc_fixup *fix,
1755 int pre_init)
1756{
1757 if (codec->modelname && models) {
1758 while (models->name) {
1759 if (!strcmp(codec->modelname, models->name)) {
1760 fix += models->id;
1761 break;
1762 }
1763 models++;
1764 }
1765 __alc_pick_fixup(codec, fix, codec->modelname, pre_init);
1766 } else {
1767 alc_pick_fixup(codec, quirk, fix, pre_init);
1768 }
1724} 1769}
1725 1770
1726static int alc_read_coef_idx(struct hda_codec *codec, 1771static int alc_read_coef_idx(struct hda_codec *codec,
@@ -1981,6 +2026,7 @@ static struct hda_verb alc888_acer_aspire_4930g_verbs[] = {
1981 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 2026 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1982 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 2027 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1983 {0x15, AC_VERB_SET_CONNECT_SEL, 0x00}, 2028 {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
2029 {0x15, AC_VERB_SET_EAPD_BTLENABLE, 2},
1984 { } 2030 { }
1985}; 2031};
1986 2032
@@ -2120,17 +2166,17 @@ static struct hda_input_mux alc888_acer_aspire_6530_sources[2] = {
2120 { 2166 {
2121 .num_items = 5, 2167 .num_items = 5,
2122 .items = { 2168 .items = {
2123 { "Ext Mic", 0x0 }, 2169 { "Mic", 0x0 },
2124 { "Line In", 0x2 }, 2170 { "Line In", 0x2 },
2125 { "CD", 0x4 }, 2171 { "CD", 0x4 },
2126 { "Input Mix", 0xa }, 2172 { "Input Mix", 0xa },
2127 { "Int Mic", 0xb }, 2173 { "Internal Mic", 0xb },
2128 }, 2174 },
2129 }, 2175 },
2130 { 2176 {
2131 .num_items = 4, 2177 .num_items = 4,
2132 .items = { 2178 .items = {
2133 { "Ext Mic", 0x0 }, 2179 { "Mic", 0x0 },
2134 { "Line In", 0x2 }, 2180 { "Line In", 0x2 },
2135 { "CD", 0x4 }, 2181 { "CD", 0x4 },
2136 { "Input Mix", 0xa }, 2182 { "Input Mix", 0xa },
@@ -2187,7 +2233,7 @@ static struct snd_kcontrol_new alc888_base_mixer[] = {
2187 HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT), 2233 HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
2188 HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT), 2234 HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
2189 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT), 2235 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
2190 HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT), 2236 HDA_CODEC_VOLUME("Mic Boost Volume", 0x18, 0, HDA_INPUT),
2191 HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT), 2237 HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
2192 { } /* end */ 2238 { } /* end */
2193}; 2239};
@@ -2205,7 +2251,7 @@ static struct snd_kcontrol_new alc889_acer_aspire_8930g_mixer[] = {
2205 HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT), 2251 HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
2206 HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT), 2252 HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
2207 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT), 2253 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
2208 HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT), 2254 HDA_CODEC_VOLUME("Mic Boost Volume", 0x18, 0, HDA_INPUT),
2209 HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT), 2255 HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
2210 { } /* end */ 2256 { } /* end */
2211}; 2257};
@@ -2796,10 +2842,10 @@ static struct snd_kcontrol_new alc880_fujitsu_mixer[] = {
2796 HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT), 2842 HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
2797 HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT), 2843 HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
2798 HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT), 2844 HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
2799 HDA_CODEC_VOLUME("Ext Mic Playback Volume", 0x0b, 0x0, HDA_INPUT), 2845 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
2800 HDA_CODEC_MUTE("Ext Mic Playback Switch", 0x0b, 0x0, HDA_INPUT), 2846 HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
2801 HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT), 2847 HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
2802 HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT), 2848 HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
2803 { } /* end */ 2849 { } /* end */
2804}; 2850};
2805 2851
@@ -3307,7 +3353,7 @@ static struct hda_verb alc880_beep_init_verbs[] = {
3307}; 3353};
3308 3354
3309/* auto-toggle front mic */ 3355/* auto-toggle front mic */
3310static void alc880_uniwill_mic_automute(struct hda_codec *codec) 3356static void alc88x_simple_mic_automute(struct hda_codec *codec)
3311{ 3357{
3312 unsigned int present; 3358 unsigned int present;
3313 unsigned char bits; 3359 unsigned char bits;
@@ -3329,7 +3375,7 @@ static void alc880_uniwill_setup(struct hda_codec *codec)
3329static void alc880_uniwill_init_hook(struct hda_codec *codec) 3375static void alc880_uniwill_init_hook(struct hda_codec *codec)
3330{ 3376{
3331 alc_automute_amp(codec); 3377 alc_automute_amp(codec);
3332 alc880_uniwill_mic_automute(codec); 3378 alc88x_simple_mic_automute(codec);
3333} 3379}
3334 3380
3335static void alc880_uniwill_unsol_event(struct hda_codec *codec, 3381static void alc880_uniwill_unsol_event(struct hda_codec *codec,
@@ -3340,7 +3386,7 @@ static void alc880_uniwill_unsol_event(struct hda_codec *codec,
3340 */ 3386 */
3341 switch (res >> 28) { 3387 switch (res >> 28) {
3342 case ALC880_MIC_EVENT: 3388 case ALC880_MIC_EVENT:
3343 alc880_uniwill_mic_automute(codec); 3389 alc88x_simple_mic_automute(codec);
3344 break; 3390 break;
3345 default: 3391 default:
3346 alc_automute_amp_unsol_event(codec, res); 3392 alc_automute_amp_unsol_event(codec, res);
@@ -5023,6 +5069,25 @@ static int alc880_auto_fill_dac_nids(struct alc_spec *spec,
5023 return 0; 5069 return 0;
5024} 5070}
5025 5071
5072static const char *alc_get_line_out_pfx(const struct auto_pin_cfg *cfg,
5073 bool can_be_master)
5074{
5075 if (!cfg->hp_outs && !cfg->speaker_outs && can_be_master)
5076 return "Master";
5077
5078 switch (cfg->line_out_type) {
5079 case AUTO_PIN_SPEAKER_OUT:
5080 return "Speaker";
5081 case AUTO_PIN_HP_OUT:
5082 return "Headphone";
5083 default:
5084 if (cfg->line_outs == 1)
5085 return "PCM";
5086 break;
5087 }
5088 return NULL;
5089}
5090
5026/* add playback controls from the parsed DAC table */ 5091/* add playback controls from the parsed DAC table */
5027static int alc880_auto_create_multi_out_ctls(struct alc_spec *spec, 5092static int alc880_auto_create_multi_out_ctls(struct alc_spec *spec,
5028 const struct auto_pin_cfg *cfg) 5093 const struct auto_pin_cfg *cfg)
@@ -5030,6 +5095,7 @@ static int alc880_auto_create_multi_out_ctls(struct alc_spec *spec,
5030 static const char *chname[4] = { 5095 static const char *chname[4] = {
5031 "Front", "Surround", NULL /*CLFE*/, "Side" 5096 "Front", "Surround", NULL /*CLFE*/, "Side"
5032 }; 5097 };
5098 const char *pfx = alc_get_line_out_pfx(cfg, false);
5033 hda_nid_t nid; 5099 hda_nid_t nid;
5034 int i, err; 5100 int i, err;
5035 5101
@@ -5037,7 +5103,7 @@ static int alc880_auto_create_multi_out_ctls(struct alc_spec *spec,
5037 if (!spec->multiout.dac_nids[i]) 5103 if (!spec->multiout.dac_nids[i])
5038 continue; 5104 continue;
5039 nid = alc880_idx_to_mixer(alc880_dac_to_idx(spec->multiout.dac_nids[i])); 5105 nid = alc880_idx_to_mixer(alc880_dac_to_idx(spec->multiout.dac_nids[i]));
5040 if (i == 2) { 5106 if (!pfx && i == 2) {
5041 /* Center/LFE */ 5107 /* Center/LFE */
5042 err = add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL, 5108 err = add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL,
5043 "Center", 5109 "Center",
@@ -5064,18 +5130,17 @@ static int alc880_auto_create_multi_out_ctls(struct alc_spec *spec,
5064 if (err < 0) 5130 if (err < 0)
5065 return err; 5131 return err;
5066 } else { 5132 } else {
5067 const char *pfx; 5133 const char *name = pfx;
5068 if (cfg->line_outs == 1 && 5134 if (!name)
5069 cfg->line_out_type == AUTO_PIN_SPEAKER_OUT) 5135 name = chname[i];
5070 pfx = "Speaker"; 5136 err = __add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL,
5071 else 5137 name, i,
5072 pfx = chname[i];
5073 err = add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL, pfx,
5074 HDA_COMPOSE_AMP_VAL(nid, 3, 0, 5138 HDA_COMPOSE_AMP_VAL(nid, 3, 0,
5075 HDA_OUTPUT)); 5139 HDA_OUTPUT));
5076 if (err < 0) 5140 if (err < 0)
5077 return err; 5141 return err;
5078 err = add_pb_sw_ctrl(spec, ALC_CTL_BIND_MUTE, pfx, 5142 err = __add_pb_sw_ctrl(spec, ALC_CTL_BIND_MUTE,
5143 name, i,
5079 HDA_COMPOSE_AMP_VAL(nid, 3, 2, 5144 HDA_COMPOSE_AMP_VAL(nid, 3, 2,
5080 HDA_INPUT)); 5145 HDA_INPUT));
5081 if (err < 0) 5146 if (err < 0)
@@ -5155,7 +5220,8 @@ static int alc_auto_create_input_ctls(struct hda_codec *codec,
5155{ 5220{
5156 struct alc_spec *spec = codec->spec; 5221 struct alc_spec *spec = codec->spec;
5157 struct hda_input_mux *imux = &spec->private_imux[0]; 5222 struct hda_input_mux *imux = &spec->private_imux[0];
5158 int i, err, idx, type, type_idx = 0; 5223 int i, err, idx, type_idx = 0;
5224 const char *prev_label = NULL;
5159 5225
5160 for (i = 0; i < cfg->num_inputs; i++) { 5226 for (i = 0; i < cfg->num_inputs; i++) {
5161 hda_nid_t pin; 5227 hda_nid_t pin;
@@ -5165,12 +5231,13 @@ static int alc_auto_create_input_ctls(struct hda_codec *codec,
5165 if (!alc_is_input_pin(codec, pin)) 5231 if (!alc_is_input_pin(codec, pin))
5166 continue; 5232 continue;
5167 5233
5168 type = cfg->inputs[i].type; 5234 label = hda_get_autocfg_input_label(codec, cfg, i);
5169 if (i > 0 && type == cfg->inputs[i - 1].type) 5235 if (prev_label && !strcmp(label, prev_label))
5170 type_idx++; 5236 type_idx++;
5171 else 5237 else
5172 type_idx = 0; 5238 type_idx = 0;
5173 label = hda_get_autocfg_input_label(codec, cfg, i); 5239 prev_label = label;
5240
5174 if (mixer) { 5241 if (mixer) {
5175 idx = get_connection_index(codec, mixer, pin); 5242 idx = get_connection_index(codec, mixer, pin);
5176 if (idx >= 0) { 5243 if (idx >= 0) {
@@ -7406,7 +7473,7 @@ static struct hda_input_mux alc883_lenovo_nb0763_capture_source = {
7406 .num_items = 4, 7473 .num_items = 4,
7407 .items = { 7474 .items = {
7408 { "Mic", 0x0 }, 7475 { "Mic", 0x0 },
7409 { "Int Mic", 0x1 }, 7476 { "Internal Mic", 0x1 },
7410 { "Line", 0x2 }, 7477 { "Line", 0x2 },
7411 { "CD", 0x4 }, 7478 { "CD", 0x4 },
7412 }, 7479 },
@@ -7416,7 +7483,7 @@ static struct hda_input_mux alc883_fujitsu_pi2515_capture_source = {
7416 .num_items = 2, 7483 .num_items = 2,
7417 .items = { 7484 .items = {
7418 { "Mic", 0x0 }, 7485 { "Mic", 0x0 },
7419 { "Int Mic", 0x1 }, 7486 { "Internal Mic", 0x1 },
7420 }, 7487 },
7421}; 7488};
7422 7489
@@ -7851,10 +7918,10 @@ static struct snd_kcontrol_new alc882_base_mixer[] = {
7851 HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT), 7918 HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7852 HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT), 7919 HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7853 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT), 7920 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7854 HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT), 7921 HDA_CODEC_VOLUME("Mic Boost Volume", 0x18, 0, HDA_INPUT),
7855 HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT), 7922 HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7856 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT), 7923 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7857 HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT), 7924 HDA_CODEC_VOLUME("Front Mic Boost Volume", 0x19, 0, HDA_INPUT),
7858 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT), 7925 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7859 { } /* end */ 7926 { } /* end */
7860}; 7927};
@@ -7878,8 +7945,8 @@ static struct snd_kcontrol_new alc885_mbp3_mixer[] = {
7878 HDA_CODEC_MUTE ("Line Playback Switch", 0x0b, 0x02, HDA_INPUT), 7945 HDA_CODEC_MUTE ("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7879 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x00, HDA_INPUT), 7946 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x00, HDA_INPUT),
7880 HDA_CODEC_MUTE ("Mic Playback Switch", 0x0b, 0x00, HDA_INPUT), 7947 HDA_CODEC_MUTE ("Mic Playback Switch", 0x0b, 0x00, HDA_INPUT),
7881 HDA_CODEC_VOLUME("Line Boost", 0x1a, 0x00, HDA_INPUT), 7948 HDA_CODEC_VOLUME("Line Boost Volume", 0x1a, 0x00, HDA_INPUT),
7882 HDA_CODEC_VOLUME("Mic Boost", 0x18, 0x00, HDA_INPUT), 7949 HDA_CODEC_VOLUME("Mic Boost Volume", 0x18, 0x00, HDA_INPUT),
7883 { } /* end */ 7950 { } /* end */
7884}; 7951};
7885 7952
@@ -7896,8 +7963,8 @@ static struct snd_kcontrol_new alc885_mb5_mixer[] = {
7896 HDA_CODEC_MUTE ("Line Playback Switch", 0x0b, 0x07, HDA_INPUT), 7963 HDA_CODEC_MUTE ("Line Playback Switch", 0x0b, 0x07, HDA_INPUT),
7897 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x01, HDA_INPUT), 7964 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
7898 HDA_CODEC_MUTE ("Mic Playback Switch", 0x0b, 0x01, HDA_INPUT), 7965 HDA_CODEC_MUTE ("Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
7899 HDA_CODEC_VOLUME("Line Boost", 0x15, 0x00, HDA_INPUT), 7966 HDA_CODEC_VOLUME("Line Boost Volume", 0x15, 0x00, HDA_INPUT),
7900 HDA_CODEC_VOLUME("Mic Boost", 0x19, 0x00, HDA_INPUT), 7967 HDA_CODEC_VOLUME("Mic Boost Volume", 0x19, 0x00, HDA_INPUT),
7901 { } /* end */ 7968 { } /* end */
7902}; 7969};
7903 7970
@@ -7912,7 +7979,7 @@ static struct snd_kcontrol_new alc885_macmini3_mixer[] = {
7912 HDA_BIND_MUTE ("Headphone Playback Switch", 0x0f, 0x02, HDA_INPUT), 7979 HDA_BIND_MUTE ("Headphone Playback Switch", 0x0f, 0x02, HDA_INPUT),
7913 HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x07, HDA_INPUT), 7980 HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x07, HDA_INPUT),
7914 HDA_CODEC_MUTE ("Line Playback Switch", 0x0b, 0x07, HDA_INPUT), 7981 HDA_CODEC_MUTE ("Line Playback Switch", 0x0b, 0x07, HDA_INPUT),
7915 HDA_CODEC_VOLUME("Line Boost", 0x15, 0x00, HDA_INPUT), 7982 HDA_CODEC_VOLUME("Line Boost Volume", 0x15, 0x00, HDA_INPUT),
7916 { } /* end */ 7983 { } /* end */
7917}; 7984};
7918 7985
@@ -7931,7 +7998,7 @@ static struct snd_kcontrol_new alc882_w2jc_mixer[] = {
7931 HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT), 7998 HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7932 HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT), 7999 HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7933 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT), 8000 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7934 HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT), 8001 HDA_CODEC_VOLUME("Mic Boost Volume", 0x18, 0, HDA_INPUT),
7935 HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT), 8002 HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7936 { } /* end */ 8003 { } /* end */
7937}; 8004};
@@ -7946,10 +8013,10 @@ static struct snd_kcontrol_new alc882_targa_mixer[] = {
7946 HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT), 8013 HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7947 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT), 8014 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7948 HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT), 8015 HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7949 HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT), 8016 HDA_CODEC_VOLUME("Mic Boost Volume", 0x18, 0, HDA_INPUT),
7950 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT), 8017 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7951 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT), 8018 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7952 HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT), 8019 HDA_CODEC_VOLUME("Front Mic Boost Volume", 0x19, 0, HDA_INPUT),
7953 { } /* end */ 8020 { } /* end */
7954}; 8021};
7955 8022
@@ -7969,7 +8036,7 @@ static struct snd_kcontrol_new alc882_asus_a7j_mixer[] = {
7969 HDA_CODEC_MUTE("Mobile Line Playback Switch", 0x0b, 0x03, HDA_INPUT), 8036 HDA_CODEC_MUTE("Mobile Line Playback Switch", 0x0b, 0x03, HDA_INPUT),
7970 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT), 8037 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7971 HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT), 8038 HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7972 HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT), 8039 HDA_CODEC_VOLUME("Mic Boost Volume", 0x18, 0, HDA_INPUT),
7973 { } /* end */ 8040 { } /* end */
7974}; 8041};
7975 8042
@@ -7982,7 +8049,7 @@ static struct snd_kcontrol_new alc882_asus_a7m_mixer[] = {
7982 HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT), 8049 HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7983 HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT), 8050 HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7984 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT), 8051 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7985 HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT), 8052 HDA_CODEC_VOLUME("Mic Boost Volume", 0x18, 0, HDA_INPUT),
7986 HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT), 8053 HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7987 { } /* end */ 8054 { } /* end */
7988}; 8055};
@@ -8763,10 +8830,10 @@ static struct snd_kcontrol_new alc883_mitac_mixer[] = {
8763 HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT), 8830 HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
8764 HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT), 8831 HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
8765 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT), 8832 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
8766 HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT), 8833 HDA_CODEC_VOLUME("Mic Boost Volume", 0x18, 0, HDA_INPUT),
8767 HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT), 8834 HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
8768 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT), 8835 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
8769 HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT), 8836 HDA_CODEC_VOLUME("Front Mic Boost Volume", 0x19, 0, HDA_INPUT),
8770 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT), 8837 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
8771 { } /* end */ 8838 { } /* end */
8772}; 8839};
@@ -8777,11 +8844,11 @@ static struct snd_kcontrol_new alc883_clevo_m720_mixer[] = {
8777 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT), 8844 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
8778 HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT), 8845 HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
8779 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT), 8846 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
8780 HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT), 8847 HDA_CODEC_VOLUME("Mic Boost Volume", 0x18, 0, HDA_INPUT),
8781 HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT), 8848 HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
8782 HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT), 8849 HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
8783 HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT), 8850 HDA_CODEC_VOLUME("Internal Mic Boost Volume", 0x19, 0, HDA_INPUT),
8784 HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT), 8851 HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
8785 { } /* end */ 8852 { } /* end */
8786}; 8853};
8787 8854
@@ -8791,11 +8858,11 @@ static struct snd_kcontrol_new alc883_2ch_fujitsu_pi2515_mixer[] = {
8791 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT), 8858 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
8792 HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT), 8859 HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
8793 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT), 8860 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
8794 HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT), 8861 HDA_CODEC_VOLUME("Mic Boost Volume", 0x18, 0, HDA_INPUT),
8795 HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT), 8862 HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
8796 HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT), 8863 HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
8797 HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT), 8864 HDA_CODEC_VOLUME("Internal Mic Boost Volume", 0x19, 0, HDA_INPUT),
8798 HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT), 8865 HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
8799 { } /* end */ 8866 { } /* end */
8800}; 8867};
8801 8868
@@ -8808,10 +8875,10 @@ static struct snd_kcontrol_new alc883_3ST_2ch_mixer[] = {
8808 HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT), 8875 HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
8809 HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT), 8876 HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
8810 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT), 8877 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
8811 HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT), 8878 HDA_CODEC_VOLUME("Mic Boost Volume", 0x18, 0, HDA_INPUT),
8812 HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT), 8879 HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
8813 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT), 8880 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
8814 HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT), 8881 HDA_CODEC_VOLUME("Front Mic Boost Volume", 0x19, 0, HDA_INPUT),
8815 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT), 8882 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
8816 { } /* end */ 8883 { } /* end */
8817}; 8884};
@@ -8831,10 +8898,10 @@ static struct snd_kcontrol_new alc883_3ST_6ch_mixer[] = {
8831 HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT), 8898 HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
8832 HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT), 8899 HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
8833 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT), 8900 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
8834 HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT), 8901 HDA_CODEC_VOLUME("Mic Boost Volume", 0x18, 0, HDA_INPUT),
8835 HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT), 8902 HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
8836 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT), 8903 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
8837 HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT), 8904 HDA_CODEC_VOLUME("Front Mic Boost Volume", 0x19, 0, HDA_INPUT),
8838 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT), 8905 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
8839 { } /* end */ 8906 { } /* end */
8840}; 8907};
@@ -8855,10 +8922,10 @@ static struct snd_kcontrol_new alc883_3ST_6ch_intel_mixer[] = {
8855 HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT), 8922 HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
8856 HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT), 8923 HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
8857 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x1, HDA_INPUT), 8924 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
8858 HDA_CODEC_VOLUME("Mic Boost", 0x19, 0, HDA_INPUT), 8925 HDA_CODEC_VOLUME("Mic Boost Volume", 0x19, 0, HDA_INPUT),
8859 HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x1, HDA_INPUT), 8926 HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
8860 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x0, HDA_INPUT), 8927 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
8861 HDA_CODEC_VOLUME("Front Mic Boost", 0x18, 0, HDA_INPUT), 8928 HDA_CODEC_VOLUME("Front Mic Boost Volume", 0x18, 0, HDA_INPUT),
8862 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x0, HDA_INPUT), 8929 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
8863 { } /* end */ 8930 { } /* end */
8864}; 8931};
@@ -8879,10 +8946,10 @@ static struct snd_kcontrol_new alc885_8ch_intel_mixer[] = {
8879 HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT), 8946 HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
8880 HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT), 8947 HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
8881 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x3, HDA_INPUT), 8948 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x3, HDA_INPUT),
8882 HDA_CODEC_VOLUME("Mic Boost", 0x1b, 0, HDA_INPUT), 8949 HDA_CODEC_VOLUME("Mic Boost Volume", 0x1b, 0, HDA_INPUT),
8883 HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x3, HDA_INPUT), 8950 HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x3, HDA_INPUT),
8884 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x0, HDA_INPUT), 8951 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
8885 HDA_CODEC_VOLUME("Front Mic Boost", 0x18, 0, HDA_INPUT), 8952 HDA_CODEC_VOLUME("Front Mic Boost Volume", 0x18, 0, HDA_INPUT),
8886 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x0, HDA_INPUT), 8953 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
8887 { } /* end */ 8954 { } /* end */
8888}; 8955};
@@ -8902,10 +8969,10 @@ static struct snd_kcontrol_new alc883_fivestack_mixer[] = {
8902 HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT), 8969 HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
8903 HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT), 8970 HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
8904 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT), 8971 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
8905 HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT), 8972 HDA_CODEC_VOLUME("Mic Boost Volume", 0x18, 0, HDA_INPUT),
8906 HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT), 8973 HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
8907 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT), 8974 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
8908 HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT), 8975 HDA_CODEC_VOLUME("Front Mic Boost Volume", 0x19, 0, HDA_INPUT),
8909 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT), 8976 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
8910 { } /* end */ 8977 { } /* end */
8911}; 8978};
@@ -8926,7 +8993,7 @@ static struct snd_kcontrol_new alc883_targa_mixer[] = {
8926 HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT), 8993 HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
8927 HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT), 8994 HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
8928 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT), 8995 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
8929 HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT), 8996 HDA_CODEC_VOLUME("Mic Boost Volume", 0x18, 0, HDA_INPUT),
8930 HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT), 8997 HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
8931 { } /* end */ 8998 { } /* end */
8932}; 8999};
@@ -8939,20 +9006,20 @@ static struct snd_kcontrol_new alc883_targa_2ch_mixer[] = {
8939 HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT), 9006 HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
8940 HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT), 9007 HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
8941 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT), 9008 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
8942 HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT), 9009 HDA_CODEC_VOLUME("Mic Boost Volume", 0x18, 0, HDA_INPUT),
8943 HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT), 9010 HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
8944 HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT), 9011 HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
8945 HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT), 9012 HDA_CODEC_VOLUME("Internal Mic Boost Volume", 0x19, 0, HDA_INPUT),
8946 HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT), 9013 HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
8947 { } /* end */ 9014 { } /* end */
8948}; 9015};
8949 9016
8950static struct snd_kcontrol_new alc883_targa_8ch_mixer[] = { 9017static struct snd_kcontrol_new alc883_targa_8ch_mixer[] = {
8951 HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT), 9018 HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
8952 HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT), 9019 HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
8953 HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT), 9020 HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
8954 HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT), 9021 HDA_CODEC_VOLUME("Internal Mic Boost Volume", 0x19, 0, HDA_INPUT),
8955 HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT), 9022 HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
8956 { } /* end */ 9023 { } /* end */
8957}; 9024};
8958 9025
@@ -8963,7 +9030,7 @@ static struct snd_kcontrol_new alc883_lenovo_101e_2ch_mixer[] = {
8963 HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT), 9030 HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
8964 HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT), 9031 HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
8965 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x1, HDA_INPUT), 9032 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
8966 HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT), 9033 HDA_CODEC_VOLUME("Mic Boost Volume", 0x18, 0, HDA_INPUT),
8967 HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x1, HDA_INPUT), 9034 HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
8968 { } /* end */ 9035 { } /* end */
8969}; 9036};
@@ -8976,21 +9043,8 @@ static struct snd_kcontrol_new alc883_lenovo_nb0763_mixer[] = {
8976 HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT), 9043 HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
8977 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT), 9044 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
8978 HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT), 9045 HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
8979 HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT), 9046 HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
8980 HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT), 9047 HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
8981 { } /* end */
8982};
8983
8984static struct snd_kcontrol_new alc883_medion_md2_mixer[] = {
8985 HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
8986 HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
8987 HDA_CODEC_MUTE("Front Playback Switch", 0x15, 0x0, HDA_OUTPUT),
8988 HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
8989 HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
8990 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
8991 HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
8992 HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
8993 HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
8994 { } /* end */ 9048 { } /* end */
8995}; 9049};
8996 9050
@@ -9037,7 +9091,7 @@ static struct snd_kcontrol_new alc883_acer_aspire_mixer[] = {
9037 HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT), 9091 HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
9038 HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT), 9092 HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
9039 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT), 9093 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
9040 HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT), 9094 HDA_CODEC_VOLUME("Mic Boost Volume", 0x18, 0, HDA_INPUT),
9041 HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT), 9095 HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
9042 { } /* end */ 9096 { } /* end */
9043}; 9097};
@@ -9050,7 +9104,7 @@ static struct snd_kcontrol_new alc888_acer_aspire_6530_mixer[] = {
9050 HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT), 9104 HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
9051 HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT), 9105 HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
9052 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT), 9106 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
9053 HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT), 9107 HDA_CODEC_VOLUME("Mic Boost Volume", 0x18, 0, HDA_INPUT),
9054 HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT), 9108 HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
9055 { } /* end */ 9109 { } /* end */
9056}; 9110};
@@ -9072,10 +9126,10 @@ static struct snd_kcontrol_new alc888_lenovo_sky_mixer[] = {
9072 HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT), 9126 HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
9073 HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT), 9127 HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
9074 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT), 9128 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
9075 HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT), 9129 HDA_CODEC_VOLUME("Mic Boost Volume", 0x18, 0, HDA_INPUT),
9076 HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT), 9130 HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
9077 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT), 9131 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
9078 HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT), 9132 HDA_CODEC_VOLUME("Front Mic Boost Volume", 0x19, 0, HDA_INPUT),
9079 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT), 9133 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
9080 { } /* end */ 9134 { } /* end */
9081}; 9135};
@@ -9096,8 +9150,8 @@ static struct snd_kcontrol_new alc889A_mb31_mixer[] = {
9096 HDA_CODEC_MUTE("Enable Headphones", 0x15, 0x00, HDA_OUTPUT), 9150 HDA_CODEC_MUTE("Enable Headphones", 0x15, 0x00, HDA_OUTPUT),
9097 HDA_CODEC_MUTE_MONO("Enable LFE", 0x16, 2, 0x00, HDA_OUTPUT), 9151 HDA_CODEC_MUTE_MONO("Enable LFE", 0x16, 2, 0x00, HDA_OUTPUT),
9098 /* Boost mixers */ 9152 /* Boost mixers */
9099 HDA_CODEC_VOLUME("Mic Boost", 0x18, 0x00, HDA_INPUT), 9153 HDA_CODEC_VOLUME("Mic Boost Volume", 0x18, 0x00, HDA_INPUT),
9100 HDA_CODEC_VOLUME("Line Boost", 0x1a, 0x00, HDA_INPUT), 9154 HDA_CODEC_VOLUME("Line Boost Volume", 0x1a, 0x00, HDA_INPUT),
9101 /* Input mixers */ 9155 /* Input mixers */
9102 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x00, HDA_INPUT), 9156 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x00, HDA_INPUT),
9103 HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x00, HDA_INPUT), 9157 HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x00, HDA_INPUT),
@@ -9111,7 +9165,7 @@ static struct snd_kcontrol_new alc883_vaiott_mixer[] = {
9111 HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT), 9165 HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
9112 HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT), 9166 HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
9113 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x1, HDA_INPUT), 9167 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
9114 HDA_CODEC_VOLUME("Mic Boost", 0x19, 0, HDA_INPUT), 9168 HDA_CODEC_VOLUME("Mic Boost Volume", 0x19, 0, HDA_INPUT),
9115 HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x1, HDA_INPUT), 9169 HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
9116 { } /* end */ 9170 { } /* end */
9117}; 9171};
@@ -9141,7 +9195,7 @@ static struct snd_kcontrol_new alc883_asus_eee1601_mixer[] = {
9141 HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT), 9195 HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
9142 HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT), 9196 HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
9143 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT), 9197 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
9144 HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT), 9198 HDA_CODEC_VOLUME("Mic Boost Volume", 0x18, 0, HDA_INPUT),
9145 HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT), 9199 HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
9146 { } /* end */ 9200 { } /* end */
9147}; 9201};
@@ -9182,16 +9236,6 @@ static void alc883_mitac_setup(struct hda_codec *codec)
9182 spec->autocfg.speaker_pins[1] = 0x17; 9236 spec->autocfg.speaker_pins[1] = 0x17;
9183} 9237}
9184 9238
9185/* auto-toggle front mic */
9186/*
9187static void alc883_mitac_mic_automute(struct hda_codec *codec)
9188{
9189 unsigned char bits = snd_hda_jack_detect(codec, 0x18) ? HDA_AMP_MUTE : 0;
9190
9191 snd_hda_codec_amp_stereo(codec, 0x0b, HDA_INPUT, 1, HDA_AMP_MUTE, bits);
9192}
9193*/
9194
9195static struct hda_verb alc883_mitac_verbs[] = { 9239static struct hda_verb alc883_mitac_verbs[] = {
9196 /* HP */ 9240 /* HP */
9197 {0x15, AC_VERB_SET_CONNECT_SEL, 0x00}, 9241 {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
@@ -9435,18 +9479,8 @@ static void alc883_lenovo_ms7195_unsol_event(struct hda_codec *codec,
9435 alc888_lenovo_ms7195_rca_automute(codec); 9479 alc888_lenovo_ms7195_rca_automute(codec);
9436} 9480}
9437 9481
9438static struct hda_verb alc883_medion_md2_verbs[] = {
9439 {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9440 {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9441
9442 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
9443
9444 {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
9445 { } /* end */
9446};
9447
9448/* toggle speaker-output according to the hp-jack state */ 9482/* toggle speaker-output according to the hp-jack state */
9449static void alc883_medion_md2_setup(struct hda_codec *codec) 9483static void alc883_lenovo_nb0763_setup(struct hda_codec *codec)
9450{ 9484{
9451 struct alc_spec *spec = codec->spec; 9485 struct alc_spec *spec = codec->spec;
9452 9486
@@ -9458,15 +9492,6 @@ static void alc883_medion_md2_setup(struct hda_codec *codec)
9458#define alc883_targa_init_hook alc882_targa_init_hook 9492#define alc883_targa_init_hook alc882_targa_init_hook
9459#define alc883_targa_unsol_event alc882_targa_unsol_event 9493#define alc883_targa_unsol_event alc882_targa_unsol_event
9460 9494
9461static void alc883_clevo_m720_mic_automute(struct hda_codec *codec)
9462{
9463 unsigned int present;
9464
9465 present = snd_hda_jack_detect(codec, 0x18);
9466 snd_hda_codec_amp_stereo(codec, 0x0b, HDA_INPUT, 1,
9467 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
9468}
9469
9470static void alc883_clevo_m720_setup(struct hda_codec *codec) 9495static void alc883_clevo_m720_setup(struct hda_codec *codec)
9471{ 9496{
9472 struct alc_spec *spec = codec->spec; 9497 struct alc_spec *spec = codec->spec;
@@ -9478,7 +9503,7 @@ static void alc883_clevo_m720_setup(struct hda_codec *codec)
9478static void alc883_clevo_m720_init_hook(struct hda_codec *codec) 9503static void alc883_clevo_m720_init_hook(struct hda_codec *codec)
9479{ 9504{
9480 alc_automute_amp(codec); 9505 alc_automute_amp(codec);
9481 alc883_clevo_m720_mic_automute(codec); 9506 alc88x_simple_mic_automute(codec);
9482} 9507}
9483 9508
9484static void alc883_clevo_m720_unsol_event(struct hda_codec *codec, 9509static void alc883_clevo_m720_unsol_event(struct hda_codec *codec,
@@ -9486,7 +9511,7 @@ static void alc883_clevo_m720_unsol_event(struct hda_codec *codec,
9486{ 9511{
9487 switch (res >> 26) { 9512 switch (res >> 26) {
9488 case ALC880_MIC_EVENT: 9513 case ALC880_MIC_EVENT:
9489 alc883_clevo_m720_mic_automute(codec); 9514 alc88x_simple_mic_automute(codec);
9490 break; 9515 break;
9491 default: 9516 default:
9492 alc_automute_amp_unsol_event(codec, res); 9517 alc_automute_amp_unsol_event(codec, res);
@@ -9731,7 +9756,6 @@ static const char *alc882_models[ALC882_MODEL_LAST] = {
9731 [ALC888_ACER_ASPIRE_8930G] = "acer-aspire-8930g", 9756 [ALC888_ACER_ASPIRE_8930G] = "acer-aspire-8930g",
9732 [ALC888_ACER_ASPIRE_7730G] = "acer-aspire-7730g", 9757 [ALC888_ACER_ASPIRE_7730G] = "acer-aspire-7730g",
9733 [ALC883_MEDION] = "medion", 9758 [ALC883_MEDION] = "medion",
9734 [ALC883_MEDION_MD2] = "medion-md2",
9735 [ALC883_MEDION_WIM2160] = "medion-wim2160", 9759 [ALC883_MEDION_WIM2160] = "medion-wim2160",
9736 [ALC883_LAPTOP_EAPD] = "laptop-eapd", 9760 [ALC883_LAPTOP_EAPD] = "laptop-eapd",
9737 [ALC883_LENOVO_101E_2ch] = "lenovo-101e", 9761 [ALC883_LENOVO_101E_2ch] = "lenovo-101e",
@@ -10379,19 +10403,6 @@ static struct alc_config_preset alc882_presets[] = {
10379 .channel_mode = alc883_sixstack_modes, 10403 .channel_mode = alc883_sixstack_modes,
10380 .input_mux = &alc883_capture_source, 10404 .input_mux = &alc883_capture_source,
10381 }, 10405 },
10382 [ALC883_MEDION_MD2] = {
10383 .mixers = { alc883_medion_md2_mixer},
10384 .init_verbs = { alc883_init_verbs, alc883_medion_md2_verbs},
10385 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
10386 .dac_nids = alc883_dac_nids,
10387 .dig_out_nid = ALC883_DIGOUT_NID,
10388 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
10389 .channel_mode = alc883_3ST_2ch_modes,
10390 .input_mux = &alc883_capture_source,
10391 .unsol_event = alc_automute_amp_unsol_event,
10392 .setup = alc883_medion_md2_setup,
10393 .init_hook = alc_automute_amp,
10394 },
10395 [ALC883_MEDION_WIM2160] = { 10406 [ALC883_MEDION_WIM2160] = {
10396 .mixers = { alc883_medion_wim2160_mixer }, 10407 .mixers = { alc883_medion_wim2160_mixer },
10397 .init_verbs = { alc883_init_verbs, alc883_medion_wim2160_verbs }, 10408 .init_verbs = { alc883_init_verbs, alc883_medion_wim2160_verbs },
@@ -10468,7 +10479,7 @@ static struct alc_config_preset alc882_presets[] = {
10468 .need_dac_fix = 1, 10479 .need_dac_fix = 1,
10469 .input_mux = &alc883_lenovo_nb0763_capture_source, 10480 .input_mux = &alc883_lenovo_nb0763_capture_source,
10470 .unsol_event = alc_automute_amp_unsol_event, 10481 .unsol_event = alc_automute_amp_unsol_event,
10471 .setup = alc883_medion_md2_setup, 10482 .setup = alc883_lenovo_nb0763_setup,
10472 .init_hook = alc_automute_amp, 10483 .init_hook = alc_automute_amp,
10473 }, 10484 },
10474 [ALC888_LENOVO_MS7195_DIG] = { 10485 [ALC888_LENOVO_MS7195_DIG] = {
@@ -10830,25 +10841,30 @@ static int alc_auto_add_mic_boost(struct hda_codec *codec)
10830{ 10841{
10831 struct alc_spec *spec = codec->spec; 10842 struct alc_spec *spec = codec->spec;
10832 struct auto_pin_cfg *cfg = &spec->autocfg; 10843 struct auto_pin_cfg *cfg = &spec->autocfg;
10833 int i, err, type; 10844 int i, err;
10834 int type_idx = 0; 10845 int type_idx = 0;
10835 hda_nid_t nid; 10846 hda_nid_t nid;
10847 const char *prev_label = NULL;
10836 10848
10837 for (i = 0; i < cfg->num_inputs; i++) { 10849 for (i = 0; i < cfg->num_inputs; i++) {
10838 if (cfg->inputs[i].type > AUTO_PIN_MIC) 10850 if (cfg->inputs[i].type > AUTO_PIN_MIC)
10839 break; 10851 break;
10840 nid = cfg->inputs[i].pin; 10852 nid = cfg->inputs[i].pin;
10841 if (get_wcaps(codec, nid) & AC_WCAP_IN_AMP) { 10853 if (get_wcaps(codec, nid) & AC_WCAP_IN_AMP) {
10842 char label[32]; 10854 const char *label;
10843 type = cfg->inputs[i].type; 10855 char boost_label[32];
10844 if (i > 0 && type == cfg->inputs[i - 1].type) 10856
10857 label = hda_get_autocfg_input_label(codec, cfg, i);
10858 if (prev_label && !strcmp(label, prev_label))
10845 type_idx++; 10859 type_idx++;
10846 else 10860 else
10847 type_idx = 0; 10861 type_idx = 0;
10848 snprintf(label, sizeof(label), "%s Boost", 10862 prev_label = label;
10849 hda_get_autocfg_input_label(codec, cfg, i)); 10863
10850 err = add_control(spec, ALC_CTL_WIDGET_VOL, label, 10864 snprintf(boost_label, sizeof(boost_label),
10851 type_idx, 10865 "%s Boost Volume", label);
10866 err = add_control(spec, ALC_CTL_WIDGET_VOL,
10867 boost_label, type_idx,
10852 HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT)); 10868 HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT));
10853 if (err < 0) 10869 if (err < 0)
10854 return err; 10870 return err;
@@ -10857,6 +10873,9 @@ static int alc_auto_add_mic_boost(struct hda_codec *codec)
10857 return 0; 10873 return 0;
10858} 10874}
10859 10875
10876static int alc861vd_auto_create_multi_out_ctls(struct alc_spec *spec,
10877 const struct auto_pin_cfg *cfg);
10878
10860/* almost identical with ALC880 parser... */ 10879/* almost identical with ALC880 parser... */
10861static int alc882_parse_auto_config(struct hda_codec *codec) 10880static int alc882_parse_auto_config(struct hda_codec *codec)
10862{ 10881{
@@ -10874,7 +10893,10 @@ static int alc882_parse_auto_config(struct hda_codec *codec)
10874 err = alc880_auto_fill_dac_nids(spec, &spec->autocfg); 10893 err = alc880_auto_fill_dac_nids(spec, &spec->autocfg);
10875 if (err < 0) 10894 if (err < 0)
10876 return err; 10895 return err;
10877 err = alc880_auto_create_multi_out_ctls(spec, &spec->autocfg); 10896 if (codec->vendor_id == 0x10ec0887)
10897 err = alc861vd_auto_create_multi_out_ctls(spec, &spec->autocfg);
10898 else
10899 err = alc880_auto_create_multi_out_ctls(spec, &spec->autocfg);
10878 if (err < 0) 10900 if (err < 0)
10879 return err; 10901 return err;
10880 err = alc880_auto_create_extra_out(spec, spec->autocfg.hp_pins[0], 10902 err = alc880_auto_create_extra_out(spec, spec->autocfg.hp_pins[0],
@@ -11090,10 +11112,10 @@ static struct snd_kcontrol_new alc262_base_mixer[] = {
11090 HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT), 11112 HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
11091 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT), 11113 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
11092 HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT), 11114 HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
11093 HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT), 11115 HDA_CODEC_VOLUME("Mic Boost Volume", 0x18, 0, HDA_INPUT),
11094 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x01, HDA_INPUT), 11116 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
11095 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x01, HDA_INPUT), 11117 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
11096 HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT), 11118 HDA_CODEC_VOLUME("Front Mic Boost Volume", 0x19, 0, HDA_INPUT),
11097 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0D, 0x0, HDA_OUTPUT), 11119 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0D, 0x0, HDA_OUTPUT),
11098 HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT), 11120 HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
11099 HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT), 11121 HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
@@ -11194,10 +11216,10 @@ static struct snd_kcontrol_new alc262_HP_BPC_mixer[] = {
11194 HDA_OUTPUT), 11216 HDA_OUTPUT),
11195 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT), 11217 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
11196 HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT), 11218 HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
11197 HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT), 11219 HDA_CODEC_VOLUME("Mic Boost Volume", 0x18, 0, HDA_INPUT),
11198 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x01, HDA_INPUT), 11220 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
11199 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x01, HDA_INPUT), 11221 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
11200 HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT), 11222 HDA_CODEC_VOLUME("Front Mic Boost Volume", 0x19, 0, HDA_INPUT),
11201 HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT), 11223 HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
11202 HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT), 11224 HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
11203 HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT), 11225 HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
@@ -11219,7 +11241,7 @@ static struct snd_kcontrol_new alc262_HP_BPC_WildWest_mixer[] = {
11219 HDA_OUTPUT), 11241 HDA_OUTPUT),
11220 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x02, HDA_INPUT), 11242 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x02, HDA_INPUT),
11221 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x02, HDA_INPUT), 11243 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x02, HDA_INPUT),
11222 HDA_CODEC_VOLUME("Front Mic Boost", 0x1a, 0, HDA_INPUT), 11244 HDA_CODEC_VOLUME("Front Mic Boost Volume", 0x1a, 0, HDA_INPUT),
11223 HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x01, HDA_INPUT), 11245 HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x01, HDA_INPUT),
11224 HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x01, HDA_INPUT), 11246 HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x01, HDA_INPUT),
11225 HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT), 11247 HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
@@ -11230,7 +11252,7 @@ static struct snd_kcontrol_new alc262_HP_BPC_WildWest_mixer[] = {
11230static struct snd_kcontrol_new alc262_HP_BPC_WildWest_option_mixer[] = { 11252static struct snd_kcontrol_new alc262_HP_BPC_WildWest_option_mixer[] = {
11231 HDA_CODEC_VOLUME("Rear Mic Playback Volume", 0x0b, 0x0, HDA_INPUT), 11253 HDA_CODEC_VOLUME("Rear Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
11232 HDA_CODEC_MUTE("Rear Mic Playback Switch", 0x0b, 0x0, HDA_INPUT), 11254 HDA_CODEC_MUTE("Rear Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
11233 HDA_CODEC_VOLUME("Rear Mic Boost", 0x18, 0, HDA_INPUT), 11255 HDA_CODEC_VOLUME("Rear Mic Boost Volume", 0x18, 0, HDA_INPUT),
11234 { } /* end */ 11256 { } /* end */
11235}; 11257};
11236 11258
@@ -11250,7 +11272,7 @@ static struct snd_kcontrol_new alc262_hp_t5735_mixer[] = {
11250 HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT), 11272 HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
11251 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT), 11273 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
11252 HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT), 11274 HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
11253 HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT), 11275 HDA_CODEC_VOLUME("Mic Boost Volume", 0x18, 0, HDA_INPUT),
11254 { } /* end */ 11276 { } /* end */
11255}; 11277};
11256 11278
@@ -11357,10 +11379,10 @@ static struct snd_kcontrol_new alc262_hippo_mixer[] = {
11357 HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT), 11379 HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
11358 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT), 11380 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
11359 HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT), 11381 HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
11360 HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT), 11382 HDA_CODEC_VOLUME("Mic Boost Volume", 0x18, 0, HDA_INPUT),
11361 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x01, HDA_INPUT), 11383 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
11362 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x01, HDA_INPUT), 11384 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
11363 HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT), 11385 HDA_CODEC_VOLUME("Front Mic Boost Volume", 0x19, 0, HDA_INPUT),
11364 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0d, 0x0, HDA_OUTPUT), 11386 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
11365 { } /* end */ 11387 { } /* end */
11366}; 11388};
@@ -11374,10 +11396,10 @@ static struct snd_kcontrol_new alc262_hippo1_mixer[] = {
11374 HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT), 11396 HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
11375 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT), 11397 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
11376 HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT), 11398 HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
11377 HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT), 11399 HDA_CODEC_VOLUME("Mic Boost Volume", 0x18, 0, HDA_INPUT),
11378 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x01, HDA_INPUT), 11400 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
11379 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x01, HDA_INPUT), 11401 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
11380 HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT), 11402 HDA_CODEC_VOLUME("Front Mic Boost Volume", 0x19, 0, HDA_INPUT),
11381 { } /* end */ 11403 { } /* end */
11382}; 11404};
11383 11405
@@ -11445,10 +11467,10 @@ static struct snd_kcontrol_new alc262_tyan_mixer[] = {
11445 HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT), 11467 HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
11446 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT), 11468 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
11447 HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT), 11469 HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
11448 HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT), 11470 HDA_CODEC_VOLUME("Mic Boost Volume", 0x18, 0, HDA_INPUT),
11449 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x01, HDA_INPUT), 11471 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
11450 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x01, HDA_INPUT), 11472 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
11451 HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT), 11473 HDA_CODEC_VOLUME("Front Mic Boost Volume", 0x19, 0, HDA_INPUT),
11452 { } /* end */ 11474 { } /* end */
11453}; 11475};
11454 11476
@@ -11632,7 +11654,7 @@ static struct snd_kcontrol_new alc262_nec_mixer[] = {
11632 11654
11633 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT), 11655 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
11634 HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT), 11656 HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
11635 HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT), 11657 HDA_CODEC_VOLUME("Mic Boost Volume", 0x18, 0, HDA_INPUT),
11636 11658
11637 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0d, 0x0, HDA_OUTPUT), 11659 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
11638 HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT), 11660 HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
@@ -11687,7 +11709,7 @@ static struct hda_input_mux alc262_fujitsu_capture_source = {
11687 .num_items = 3, 11709 .num_items = 3,
11688 .items = { 11710 .items = {
11689 { "Mic", 0x0 }, 11711 { "Mic", 0x0 },
11690 { "Int Mic", 0x1 }, 11712 { "Internal Mic", 0x1 },
11691 { "CD", 0x4 }, 11713 { "CD", 0x4 },
11692 }, 11714 },
11693}; 11715};
@@ -11839,12 +11861,12 @@ static struct snd_kcontrol_new alc262_fujitsu_mixer[] = {
11839 }, 11861 },
11840 HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT), 11862 HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
11841 HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT), 11863 HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
11842 HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT), 11864 HDA_CODEC_VOLUME("Mic Boost Volume", 0x18, 0, HDA_INPUT),
11843 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT), 11865 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
11844 HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT), 11866 HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
11845 HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT), 11867 HDA_CODEC_VOLUME("Internal Mic Boost Volume", 0x19, 0, HDA_INPUT),
11846 HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT), 11868 HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
11847 HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT), 11869 HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
11848 { } /* end */ 11870 { } /* end */
11849}; 11871};
11850 11872
@@ -11875,12 +11897,12 @@ static struct snd_kcontrol_new alc262_lenovo_3000_mixer[] = {
11875 }, 11897 },
11876 HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT), 11898 HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
11877 HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT), 11899 HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
11878 HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT), 11900 HDA_CODEC_VOLUME("Mic Boost Volume", 0x18, 0, HDA_INPUT),
11879 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT), 11901 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
11880 HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT), 11902 HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
11881 HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT), 11903 HDA_CODEC_VOLUME("Internal Mic Boost Volume", 0x19, 0, HDA_INPUT),
11882 HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT), 11904 HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
11883 HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT), 11905 HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
11884 { } /* end */ 11906 { } /* end */
11885}; 11907};
11886 11908
@@ -11889,10 +11911,10 @@ static struct snd_kcontrol_new alc262_toshiba_rx1_mixer[] = {
11889 ALC262_HIPPO_MASTER_SWITCH, 11911 ALC262_HIPPO_MASTER_SWITCH,
11890 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT), 11912 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
11891 HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT), 11913 HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
11892 HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT), 11914 HDA_CODEC_VOLUME("Mic Boost Volume", 0x18, 0, HDA_INPUT),
11893 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x01, HDA_INPUT), 11915 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
11894 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x01, HDA_INPUT), 11916 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
11895 HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT), 11917 HDA_CODEC_VOLUME("Front Mic Boost Volume", 0x19, 0, HDA_INPUT),
11896 { } /* end */ 11918 { } /* end */
11897}; 11919};
11898 11920
@@ -11918,8 +11940,8 @@ static struct snd_kcontrol_new alc262_ultra_mixer[] = {
11918 HDA_BIND_MUTE("Master Playback Switch", 0x0c, 2, HDA_INPUT), 11940 HDA_BIND_MUTE("Master Playback Switch", 0x0c, 2, HDA_INPUT),
11919 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x01, HDA_INPUT), 11941 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
11920 HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x01, HDA_INPUT), 11942 HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
11921 HDA_CODEC_VOLUME("Mic Boost", 0x19, 0, HDA_INPUT), 11943 HDA_CODEC_VOLUME("Mic Boost Volume", 0x19, 0, HDA_INPUT),
11922 HDA_CODEC_VOLUME("Headphone Mic Boost", 0x15, 0, HDA_INPUT), 11944 HDA_CODEC_VOLUME("Headphone Mic Boost Volume", 0x15, 0, HDA_INPUT),
11923 { } /* end */ 11945 { } /* end */
11924}; 11946};
11925 11947
@@ -12089,13 +12111,8 @@ static int alc262_auto_create_multi_out_ctls(struct alc_spec *spec,
12089 spec->multiout.dac_nids = spec->private_dac_nids; 12111 spec->multiout.dac_nids = spec->private_dac_nids;
12090 spec->multiout.dac_nids[0] = 2; 12112 spec->multiout.dac_nids[0] = 2;
12091 12113
12092 if (!cfg->speaker_pins[0] && !cfg->hp_pins[0]) 12114 pfx = alc_get_line_out_pfx(cfg, true);
12093 pfx = "Master"; 12115 if (!pfx)
12094 else if (cfg->line_out_type == AUTO_PIN_SPEAKER_OUT)
12095 pfx = "Speaker";
12096 else if (cfg->line_out_type == AUTO_PIN_HP_OUT)
12097 pfx = "Headphone";
12098 else
12099 pfx = "Front"; 12116 pfx = "Front";
12100 for (i = 0; i < 2; i++) { 12117 for (i = 0; i < 2; i++) {
12101 err = alc262_add_out_sw_ctl(spec, cfg->line_out_pins[i], pfx, i); 12118 err = alc262_add_out_sw_ctl(spec, cfg->line_out_pins[i], pfx, i);
@@ -12996,9 +13013,9 @@ static struct snd_kcontrol_new alc268_base_mixer[] = {
12996 HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT), 13013 HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
12997 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x3, 0x0, HDA_OUTPUT), 13014 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x3, 0x0, HDA_OUTPUT),
12998 HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT), 13015 HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
12999 HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT), 13016 HDA_CODEC_VOLUME("Mic Boost Volume", 0x18, 0, HDA_INPUT),
13000 HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT), 13017 HDA_CODEC_VOLUME("Front Mic Boost Volume", 0x19, 0, HDA_INPUT),
13001 HDA_CODEC_VOLUME("Line In Boost", 0x1a, 0, HDA_INPUT), 13018 HDA_CODEC_VOLUME("Line In Boost Volume", 0x1a, 0, HDA_INPUT),
13002 { } 13019 { }
13003}; 13020};
13004 13021
@@ -13007,9 +13024,9 @@ static struct snd_kcontrol_new alc268_toshiba_mixer[] = {
13007 HDA_CODEC_VOLUME("Front Playback Volume", 0x2, 0x0, HDA_OUTPUT), 13024 HDA_CODEC_VOLUME("Front Playback Volume", 0x2, 0x0, HDA_OUTPUT),
13008 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x3, 0x0, HDA_OUTPUT), 13025 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x3, 0x0, HDA_OUTPUT),
13009 ALC262_HIPPO_MASTER_SWITCH, 13026 ALC262_HIPPO_MASTER_SWITCH,
13010 HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT), 13027 HDA_CODEC_VOLUME("Mic Boost Volume", 0x18, 0, HDA_INPUT),
13011 HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT), 13028 HDA_CODEC_VOLUME("Front Mic Boost Volume", 0x19, 0, HDA_INPUT),
13012 HDA_CODEC_VOLUME("Line In Boost", 0x1a, 0, HDA_INPUT), 13029 HDA_CODEC_VOLUME("Line In Boost Volume", 0x1a, 0, HDA_INPUT),
13013 { } 13030 { }
13014}; 13031};
13015 13032
@@ -13113,9 +13130,9 @@ static struct snd_kcontrol_new alc268_acer_mixer[] = {
13113 .put = alc268_acer_master_sw_put, 13130 .put = alc268_acer_master_sw_put,
13114 .private_value = HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT), 13131 .private_value = HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
13115 }, 13132 },
13116 HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT), 13133 HDA_CODEC_VOLUME("Mic Boost Volume", 0x18, 0, HDA_INPUT),
13117 HDA_CODEC_VOLUME("Internal Mic Boost", 0x19, 0, HDA_INPUT), 13134 HDA_CODEC_VOLUME("Internal Mic Boost Volume", 0x19, 0, HDA_INPUT),
13118 HDA_CODEC_VOLUME("Line In Boost", 0x1a, 0, HDA_INPUT), 13135 HDA_CODEC_VOLUME("Line In Boost Volume", 0x1a, 0, HDA_INPUT),
13119 { } 13136 { }
13120}; 13137};
13121 13138
@@ -13131,8 +13148,8 @@ static struct snd_kcontrol_new alc268_acer_dmic_mixer[] = {
13131 .put = alc268_acer_master_sw_put, 13148 .put = alc268_acer_master_sw_put,
13132 .private_value = HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT), 13149 .private_value = HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
13133 }, 13150 },
13134 HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT), 13151 HDA_CODEC_VOLUME("Mic Boost Volume", 0x18, 0, HDA_INPUT),
13135 HDA_CODEC_VOLUME("Line In Boost", 0x1a, 0, HDA_INPUT), 13152 HDA_CODEC_VOLUME("Line In Boost Volume", 0x1a, 0, HDA_INPUT),
13136 { } 13153 { }
13137}; 13154};
13138 13155
@@ -13224,8 +13241,8 @@ static struct snd_kcontrol_new alc268_dell_mixer[] = {
13224 HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT), 13241 HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
13225 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x03, 0x0, HDA_OUTPUT), 13242 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x03, 0x0, HDA_OUTPUT),
13226 HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT), 13243 HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
13227 HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT), 13244 HDA_CODEC_VOLUME("Mic Boost Volume", 0x18, 0, HDA_INPUT),
13228 HDA_CODEC_VOLUME("Internal Mic Boost", 0x19, 0, HDA_INPUT), 13245 HDA_CODEC_VOLUME("Internal Mic Boost Volume", 0x19, 0, HDA_INPUT),
13229 { } 13246 { }
13230}; 13247};
13231 13248
@@ -13258,8 +13275,8 @@ static struct snd_kcontrol_new alc267_quanta_il1_mixer[] = {
13258 HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT), 13275 HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
13259 HDA_CODEC_VOLUME("Mic Capture Volume", 0x23, 0x0, HDA_OUTPUT), 13276 HDA_CODEC_VOLUME("Mic Capture Volume", 0x23, 0x0, HDA_OUTPUT),
13260 HDA_BIND_MUTE("Mic Capture Switch", 0x23, 2, HDA_OUTPUT), 13277 HDA_BIND_MUTE("Mic Capture Switch", 0x23, 2, HDA_OUTPUT),
13261 HDA_CODEC_VOLUME("Ext Mic Boost", 0x18, 0, HDA_INPUT), 13278 HDA_CODEC_VOLUME("Mic Boost Volume", 0x18, 0, HDA_INPUT),
13262 HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT), 13279 HDA_CODEC_VOLUME("Internal Mic Boost Volume", 0x19, 0, HDA_INPUT),
13263 { } 13280 { }
13264}; 13281};
13265 13282
@@ -14082,10 +14099,10 @@ static struct snd_kcontrol_new alc269_base_mixer[] = {
14082 HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT), 14099 HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
14083 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT), 14100 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
14084 HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT), 14101 HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
14085 HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT), 14102 HDA_CODEC_VOLUME("Mic Boost Volume", 0x18, 0, HDA_INPUT),
14086 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x01, HDA_INPUT), 14103 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
14087 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x01, HDA_INPUT), 14104 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
14088 HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT), 14105 HDA_CODEC_VOLUME("Front Mic Boost Volume", 0x19, 0, HDA_INPUT),
14089 HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT), 14106 HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
14090 HDA_CODEC_MUTE_MONO("Mono Playback Switch", 0x16, 2, 0x0, HDA_OUTPUT), 14107 HDA_CODEC_MUTE_MONO("Mono Playback Switch", 0x16, 2, 0x0, HDA_OUTPUT),
14091 { } /* end */ 14108 { } /* end */
@@ -14105,10 +14122,10 @@ static struct snd_kcontrol_new alc269_quanta_fl1_mixer[] = {
14105 }, 14122 },
14106 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT), 14123 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
14107 HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT), 14124 HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
14108 HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT), 14125 HDA_CODEC_VOLUME("Mic Boost Volume", 0x18, 0, HDA_INPUT),
14109 HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x01, HDA_INPUT), 14126 HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
14110 HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x0b, 0x01, HDA_INPUT), 14127 HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
14111 HDA_CODEC_VOLUME("Internal Mic Boost", 0x19, 0, HDA_INPUT), 14128 HDA_CODEC_VOLUME("Internal Mic Boost Volume", 0x19, 0, HDA_INPUT),
14112 { } 14129 { }
14113}; 14130};
14114 14131
@@ -14126,13 +14143,13 @@ static struct snd_kcontrol_new alc269_lifebook_mixer[] = {
14126 }, 14143 },
14127 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT), 14144 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
14128 HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT), 14145 HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
14129 HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT), 14146 HDA_CODEC_VOLUME("Mic Boost Volume", 0x18, 0, HDA_INPUT),
14130 HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x01, HDA_INPUT), 14147 HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
14131 HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x0b, 0x01, HDA_INPUT), 14148 HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
14132 HDA_CODEC_VOLUME("Internal Mic Boost", 0x19, 0, HDA_INPUT), 14149 HDA_CODEC_VOLUME("Internal Mic Boost Volume", 0x19, 0, HDA_INPUT),
14133 HDA_CODEC_VOLUME("Dock Mic Playback Volume", 0x0b, 0x03, HDA_INPUT), 14150 HDA_CODEC_VOLUME("Dock Mic Playback Volume", 0x0b, 0x03, HDA_INPUT),
14134 HDA_CODEC_MUTE("Dock Mic Playback Switch", 0x0b, 0x03, HDA_INPUT), 14151 HDA_CODEC_MUTE("Dock Mic Playback Switch", 0x0b, 0x03, HDA_INPUT),
14135 HDA_CODEC_VOLUME("Dock Mic Boost", 0x1b, 0, HDA_INPUT), 14152 HDA_CODEC_VOLUME("Dock Mic Boost Volume", 0x1b, 0, HDA_INPUT),
14136 { } 14153 { }
14137}; 14154};
14138 14155
@@ -14162,30 +14179,30 @@ static struct snd_kcontrol_new alc269_asus_mixer[] = {
14162static struct snd_kcontrol_new alc269_laptop_analog_capture_mixer[] = { 14179static struct snd_kcontrol_new alc269_laptop_analog_capture_mixer[] = {
14163 HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT), 14180 HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
14164 HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT), 14181 HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
14165 HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT), 14182 HDA_CODEC_VOLUME("Mic Boost Volume", 0x18, 0, HDA_INPUT),
14166 HDA_CODEC_VOLUME("IntMic Boost", 0x19, 0, HDA_INPUT), 14183 HDA_CODEC_VOLUME("Internal Mic Boost Volume", 0x19, 0, HDA_INPUT),
14167 { } /* end */ 14184 { } /* end */
14168}; 14185};
14169 14186
14170static struct snd_kcontrol_new alc269_laptop_digital_capture_mixer[] = { 14187static struct snd_kcontrol_new alc269_laptop_digital_capture_mixer[] = {
14171 HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT), 14188 HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
14172 HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT), 14189 HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
14173 HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT), 14190 HDA_CODEC_VOLUME("Mic Boost Volume", 0x18, 0, HDA_INPUT),
14174 { } /* end */ 14191 { } /* end */
14175}; 14192};
14176 14193
14177static struct snd_kcontrol_new alc269vb_laptop_analog_capture_mixer[] = { 14194static struct snd_kcontrol_new alc269vb_laptop_analog_capture_mixer[] = {
14178 HDA_CODEC_VOLUME("Capture Volume", 0x09, 0x0, HDA_INPUT), 14195 HDA_CODEC_VOLUME("Capture Volume", 0x09, 0x0, HDA_INPUT),
14179 HDA_CODEC_MUTE("Capture Switch", 0x09, 0x0, HDA_INPUT), 14196 HDA_CODEC_MUTE("Capture Switch", 0x09, 0x0, HDA_INPUT),
14180 HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT), 14197 HDA_CODEC_VOLUME("Mic Boost Volume", 0x18, 0, HDA_INPUT),
14181 HDA_CODEC_VOLUME("IntMic Boost", 0x19, 0, HDA_INPUT), 14198 HDA_CODEC_VOLUME("Internal Mic Boost Volume", 0x19, 0, HDA_INPUT),
14182 { } /* end */ 14199 { } /* end */
14183}; 14200};
14184 14201
14185static struct snd_kcontrol_new alc269vb_laptop_digital_capture_mixer[] = { 14202static struct snd_kcontrol_new alc269vb_laptop_digital_capture_mixer[] = {
14186 HDA_CODEC_VOLUME("Capture Volume", 0x09, 0x0, HDA_INPUT), 14203 HDA_CODEC_VOLUME("Capture Volume", 0x09, 0x0, HDA_INPUT),
14187 HDA_CODEC_MUTE("Capture Switch", 0x09, 0x0, HDA_INPUT), 14204 HDA_CODEC_MUTE("Capture Switch", 0x09, 0x0, HDA_INPUT),
14188 HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT), 14205 HDA_CODEC_VOLUME("Mic Boost Volume", 0x18, 0, HDA_INPUT),
14189 { } /* end */ 14206 { } /* end */
14190}; 14207};
14191 14208
@@ -14804,12 +14821,23 @@ static int alc269_resume(struct hda_codec *codec)
14804} 14821}
14805#endif /* SND_HDA_NEEDS_RESUME */ 14822#endif /* SND_HDA_NEEDS_RESUME */
14806 14823
14824static void alc269_fixup_hweq(struct hda_codec *codec,
14825 const struct alc_fixup *fix, int pre_init)
14826{
14827 int coef;
14828
14829 coef = alc_read_coef_idx(codec, 0x1e);
14830 alc_write_coef_idx(codec, 0x1e, coef | 0x80);
14831}
14832
14807enum { 14833enum {
14808 ALC269_FIXUP_SONY_VAIO, 14834 ALC269_FIXUP_SONY_VAIO,
14809 ALC275_FIX_SONY_VAIO_GPIO2, 14835 ALC275_FIX_SONY_VAIO_GPIO2,
14810 ALC269_FIXUP_DELL_M101Z, 14836 ALC269_FIXUP_DELL_M101Z,
14811 ALC269_FIXUP_SKU_IGNORE, 14837 ALC269_FIXUP_SKU_IGNORE,
14812 ALC269_FIXUP_ASUS_G73JW, 14838 ALC269_FIXUP_ASUS_G73JW,
14839 ALC269_FIXUP_LENOVO_EAPD,
14840 ALC275_FIXUP_SONY_HWEQ,
14813}; 14841};
14814 14842
14815static const struct alc_fixup alc269_fixups[] = { 14843static const struct alc_fixup alc269_fixups[] = {
@@ -14824,6 +14852,7 @@ static const struct alc_fixup alc269_fixups[] = {
14824 {0x01, AC_VERB_SET_GPIO_MASK, 0x04}, 14852 {0x01, AC_VERB_SET_GPIO_MASK, 0x04},
14825 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x04}, 14853 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x04},
14826 {0x01, AC_VERB_SET_GPIO_DATA, 0x00}, 14854 {0x01, AC_VERB_SET_GPIO_DATA, 0x00},
14855 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREFGRD},
14827 { } 14856 { }
14828 } 14857 }
14829 }, 14858 },
@@ -14844,17 +14873,34 @@ static const struct alc_fixup alc269_fixups[] = {
14844 { } 14873 { }
14845 } 14874 }
14846 }, 14875 },
14876 [ALC269_FIXUP_LENOVO_EAPD] = {
14877 .verbs = (const struct hda_verb[]) {
14878 {0x14, AC_VERB_SET_EAPD_BTLENABLE, 0},
14879 {}
14880 }
14881 },
14882 [ALC275_FIXUP_SONY_HWEQ] = {
14883 .func = alc269_fixup_hweq,
14884 .verbs = (const struct hda_verb[]) {
14885 {0x01, AC_VERB_SET_GPIO_MASK, 0x04},
14886 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x04},
14887 {0x01, AC_VERB_SET_GPIO_DATA, 0x00},
14888 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREFGRD},
14889 { }
14890 }
14891 }
14847}; 14892};
14848 14893
14849static struct snd_pci_quirk alc269_fixup_tbl[] = { 14894static struct snd_pci_quirk alc269_fixup_tbl[] = {
14850 SND_PCI_QUIRK(0x104d, 0x9073, "Sony VAIO", ALC275_FIX_SONY_VAIO_GPIO2), 14895 SND_PCI_QUIRK(0x104d, 0x9073, "Sony VAIO", ALC275_FIX_SONY_VAIO_GPIO2),
14851 SND_PCI_QUIRK(0x104d, 0x907b, "Sony VAIO", ALC275_FIX_SONY_VAIO_GPIO2), 14896 SND_PCI_QUIRK(0x104d, 0x907b, "Sony VAIO", ALC275_FIXUP_SONY_HWEQ),
14852 SND_PCI_QUIRK(0x104d, 0x9084, "Sony VAIO", ALC275_FIX_SONY_VAIO_GPIO2), 14897 SND_PCI_QUIRK(0x104d, 0x9084, "Sony VAIO", ALC275_FIXUP_SONY_HWEQ),
14853 SND_PCI_QUIRK_VENDOR(0x104d, "Sony VAIO", ALC269_FIXUP_SONY_VAIO), 14898 SND_PCI_QUIRK_VENDOR(0x104d, "Sony VAIO", ALC269_FIXUP_SONY_VAIO),
14854 SND_PCI_QUIRK(0x1028, 0x0470, "Dell M101z", ALC269_FIXUP_DELL_M101Z), 14899 SND_PCI_QUIRK(0x1028, 0x0470, "Dell M101z", ALC269_FIXUP_DELL_M101Z),
14855 SND_PCI_QUIRK(0x17aa, 0x21b8, "Thinkpad Edge 14", ALC269_FIXUP_SKU_IGNORE), 14900 SND_PCI_QUIRK(0x17aa, 0x21b8, "Thinkpad Edge 14", ALC269_FIXUP_SKU_IGNORE),
14856 SND_PCI_QUIRK(0x17aa, 0x20f2, "Thinkpad SL410/510", ALC269_FIXUP_SKU_IGNORE), 14901 SND_PCI_QUIRK(0x17aa, 0x20f2, "Thinkpad SL410/510", ALC269_FIXUP_SKU_IGNORE),
14857 SND_PCI_QUIRK(0x1043, 0x1a13, "Asus G73Jw", ALC269_FIXUP_ASUS_G73JW), 14902 SND_PCI_QUIRK(0x1043, 0x1a13, "Asus G73Jw", ALC269_FIXUP_ASUS_G73JW),
14903 SND_PCI_QUIRK(0x17aa, 0x9e54, "LENOVO NB", ALC269_FIXUP_LENOVO_EAPD),
14858 {} 14904 {}
14859}; 14905};
14860 14906
@@ -15889,13 +15935,16 @@ static int alc861_auto_fill_dac_nids(struct hda_codec *codec,
15889 return 0; 15935 return 0;
15890} 15936}
15891 15937
15892static int alc861_create_out_sw(struct hda_codec *codec, const char *pfx, 15938static int __alc861_create_out_sw(struct hda_codec *codec, const char *pfx,
15893 hda_nid_t nid, unsigned int chs) 15939 hda_nid_t nid, int idx, unsigned int chs)
15894{ 15940{
15895 return add_pb_sw_ctrl(codec->spec, ALC_CTL_WIDGET_MUTE, pfx, 15941 return __add_pb_sw_ctrl(codec->spec, ALC_CTL_WIDGET_MUTE, pfx, idx,
15896 HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT)); 15942 HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT));
15897} 15943}
15898 15944
15945#define alc861_create_out_sw(codec, pfx, nid, chs) \
15946 __alc861_create_out_sw(codec, pfx, nid, 0, chs)
15947
15899/* add playback controls from the parsed DAC table */ 15948/* add playback controls from the parsed DAC table */
15900static int alc861_auto_create_multi_out_ctls(struct hda_codec *codec, 15949static int alc861_auto_create_multi_out_ctls(struct hda_codec *codec,
15901 const struct auto_pin_cfg *cfg) 15950 const struct auto_pin_cfg *cfg)
@@ -15904,26 +15953,15 @@ static int alc861_auto_create_multi_out_ctls(struct hda_codec *codec,
15904 static const char *chname[4] = { 15953 static const char *chname[4] = {
15905 "Front", "Surround", NULL /*CLFE*/, "Side" 15954 "Front", "Surround", NULL /*CLFE*/, "Side"
15906 }; 15955 };
15956 const char *pfx = alc_get_line_out_pfx(cfg, true);
15907 hda_nid_t nid; 15957 hda_nid_t nid;
15908 int i, err; 15958 int i, err;
15909 15959
15910 if (cfg->line_outs == 1) {
15911 const char *pfx = NULL;
15912 if (!cfg->hp_outs)
15913 pfx = "Master";
15914 else if (cfg->line_out_type == AUTO_PIN_SPEAKER_OUT)
15915 pfx = "Speaker";
15916 if (pfx) {
15917 nid = spec->multiout.dac_nids[0];
15918 return alc861_create_out_sw(codec, pfx, nid, 3);
15919 }
15920 }
15921
15922 for (i = 0; i < cfg->line_outs; i++) { 15960 for (i = 0; i < cfg->line_outs; i++) {
15923 nid = spec->multiout.dac_nids[i]; 15961 nid = spec->multiout.dac_nids[i];
15924 if (!nid) 15962 if (!nid)
15925 continue; 15963 continue;
15926 if (i == 2) { 15964 if (!pfx && i == 2) {
15927 /* Center/LFE */ 15965 /* Center/LFE */
15928 err = alc861_create_out_sw(codec, "Center", nid, 1); 15966 err = alc861_create_out_sw(codec, "Center", nid, 1);
15929 if (err < 0) 15967 if (err < 0)
@@ -15932,7 +15970,10 @@ static int alc861_auto_create_multi_out_ctls(struct hda_codec *codec,
15932 if (err < 0) 15970 if (err < 0)
15933 return err; 15971 return err;
15934 } else { 15972 } else {
15935 err = alc861_create_out_sw(codec, chname[i], nid, 3); 15973 const char *name = pfx;
15974 if (!name)
15975 name = chname[i];
15976 err = __alc861_create_out_sw(codec, name, nid, i, 3);
15936 if (err < 0) 15977 if (err < 0)
15937 return err; 15978 return err;
15938 } 15979 }
@@ -16404,8 +16445,8 @@ static struct hda_input_mux alc861vd_capture_source = {
16404static struct hda_input_mux alc861vd_dallas_capture_source = { 16445static struct hda_input_mux alc861vd_dallas_capture_source = {
16405 .num_items = 2, 16446 .num_items = 2,
16406 .items = { 16447 .items = {
16407 { "Ext Mic", 0x0 }, 16448 { "Mic", 0x0 },
16408 { "Int Mic", 0x1 }, 16449 { "Internal Mic", 0x1 },
16409 }, 16450 },
16410}; 16451};
16411 16452
@@ -16484,11 +16525,11 @@ static struct snd_kcontrol_new alc861vd_6st_mixer[] = {
16484 16525
16485 HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT), 16526 HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
16486 16527
16487 HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT), 16528 HDA_CODEC_VOLUME("Mic Boost Volume", 0x18, 0, HDA_INPUT),
16488 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT), 16529 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
16489 HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT), 16530 HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
16490 16531
16491 HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT), 16532 HDA_CODEC_VOLUME("Front Mic Boost Volume", 0x19, 0, HDA_INPUT),
16492 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT), 16533 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
16493 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT), 16534 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
16494 16535
@@ -16507,11 +16548,11 @@ static struct snd_kcontrol_new alc861vd_3st_mixer[] = {
16507 16548
16508 HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT), 16549 HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
16509 16550
16510 HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT), 16551 HDA_CODEC_VOLUME("Mic Boost Volume", 0x18, 0, HDA_INPUT),
16511 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT), 16552 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
16512 HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT), 16553 HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
16513 16554
16514 HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT), 16555 HDA_CODEC_VOLUME("Front Mic Boost Volume", 0x19, 0, HDA_INPUT),
16515 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT), 16556 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
16516 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT), 16557 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
16517 16558
@@ -16531,11 +16572,11 @@ static struct snd_kcontrol_new alc861vd_lenovo_mixer[] = {
16531 16572
16532 HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT), 16573 HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
16533 16574
16534 HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT), 16575 HDA_CODEC_VOLUME("Mic Boost Volume", 0x18, 0, HDA_INPUT),
16535 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT), 16576 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
16536 HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT), 16577 HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
16537 16578
16538 HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT), 16579 HDA_CODEC_VOLUME("Front Mic Boost Volume", 0x19, 0, HDA_INPUT),
16539 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT), 16580 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
16540 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT), 16581 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
16541 16582
@@ -16546,19 +16587,19 @@ static struct snd_kcontrol_new alc861vd_lenovo_mixer[] = {
16546}; 16587};
16547 16588
16548/* Pin assignment: Speaker=0x14, HP = 0x15, 16589/* Pin assignment: Speaker=0x14, HP = 0x15,
16549 * Ext Mic=0x18, Int Mic = 0x19, CD = 0x1c, PC Beep = 0x1d 16590 * Mic=0x18, Internal Mic = 0x19, CD = 0x1c, PC Beep = 0x1d
16550 */ 16591 */
16551static struct snd_kcontrol_new alc861vd_dallas_mixer[] = { 16592static struct snd_kcontrol_new alc861vd_dallas_mixer[] = {
16552 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x02, 0x0, HDA_OUTPUT), 16593 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x02, 0x0, HDA_OUTPUT),
16553 HDA_BIND_MUTE("Speaker Playback Switch", 0x0c, 2, HDA_INPUT), 16594 HDA_BIND_MUTE("Speaker Playback Switch", 0x0c, 2, HDA_INPUT),
16554 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x03, 0x0, HDA_OUTPUT), 16595 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x03, 0x0, HDA_OUTPUT),
16555 HDA_BIND_MUTE("Headphone Playback Switch", 0x0d, 2, HDA_INPUT), 16596 HDA_BIND_MUTE("Headphone Playback Switch", 0x0d, 2, HDA_INPUT),
16556 HDA_CODEC_VOLUME("Ext Mic Boost", 0x18, 0, HDA_INPUT), 16597 HDA_CODEC_VOLUME("Mic Boost Volume", 0x18, 0, HDA_INPUT),
16557 HDA_CODEC_VOLUME("Ext Mic Playback Volume", 0x0b, 0x0, HDA_INPUT), 16598 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
16558 HDA_CODEC_MUTE("Ext Mic Playback Switch", 0x0b, 0x0, HDA_INPUT), 16599 HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
16559 HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT), 16600 HDA_CODEC_VOLUME("Internal Mic Boost Volume", 0x19, 0, HDA_INPUT),
16560 HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT), 16601 HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
16561 HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT), 16602 HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
16562 { } /* end */ 16603 { } /* end */
16563}; 16604};
16564 16605
@@ -16723,18 +16764,6 @@ static struct hda_verb alc861vd_lenovo_unsol_verbs[] = {
16723 {} 16764 {}
16724}; 16765};
16725 16766
16726static void alc861vd_lenovo_mic_automute(struct hda_codec *codec)
16727{
16728 unsigned int present;
16729 unsigned char bits;
16730
16731 present = snd_hda_jack_detect(codec, 0x18);
16732 bits = present ? HDA_AMP_MUTE : 0;
16733
16734 snd_hda_codec_amp_stereo(codec, 0x0b, HDA_INPUT, 1,
16735 HDA_AMP_MUTE, bits);
16736}
16737
16738static void alc861vd_lenovo_setup(struct hda_codec *codec) 16767static void alc861vd_lenovo_setup(struct hda_codec *codec)
16739{ 16768{
16740 struct alc_spec *spec = codec->spec; 16769 struct alc_spec *spec = codec->spec;
@@ -16745,7 +16774,7 @@ static void alc861vd_lenovo_setup(struct hda_codec *codec)
16745static void alc861vd_lenovo_init_hook(struct hda_codec *codec) 16774static void alc861vd_lenovo_init_hook(struct hda_codec *codec)
16746{ 16775{
16747 alc_automute_amp(codec); 16776 alc_automute_amp(codec);
16748 alc861vd_lenovo_mic_automute(codec); 16777 alc88x_simple_mic_automute(codec);
16749} 16778}
16750 16779
16751static void alc861vd_lenovo_unsol_event(struct hda_codec *codec, 16780static void alc861vd_lenovo_unsol_event(struct hda_codec *codec,
@@ -16753,7 +16782,7 @@ static void alc861vd_lenovo_unsol_event(struct hda_codec *codec,
16753{ 16782{
16754 switch (res >> 26) { 16783 switch (res >> 26) {
16755 case ALC880_MIC_EVENT: 16784 case ALC880_MIC_EVENT:
16756 alc861vd_lenovo_mic_automute(codec); 16785 alc88x_simple_mic_automute(codec);
16757 break; 16786 break;
16758 default: 16787 default:
16759 alc_automute_amp_unsol_event(codec, res); 16788 alc_automute_amp_unsol_event(codec, res);
@@ -17043,12 +17072,13 @@ static void alc861vd_auto_init_analog_input(struct hda_codec *codec)
17043#define alc861vd_idx_to_mixer_switch(nid) ((nid) + 0x0c) 17072#define alc861vd_idx_to_mixer_switch(nid) ((nid) + 0x0c)
17044 17073
17045/* add playback controls from the parsed DAC table */ 17074/* add playback controls from the parsed DAC table */
17046/* Based on ALC880 version. But ALC861VD has separate, 17075/* Based on ALC880 version. But ALC861VD and ALC887 have separate,
17047 * different NIDs for mute/unmute switch and volume control */ 17076 * different NIDs for mute/unmute switch and volume control */
17048static int alc861vd_auto_create_multi_out_ctls(struct alc_spec *spec, 17077static int alc861vd_auto_create_multi_out_ctls(struct alc_spec *spec,
17049 const struct auto_pin_cfg *cfg) 17078 const struct auto_pin_cfg *cfg)
17050{ 17079{
17051 static const char *chname[4] = {"Front", "Surround", "CLFE", "Side"}; 17080 static const char *chname[4] = {"Front", "Surround", "CLFE", "Side"};
17081 const char *pfx = alc_get_line_out_pfx(cfg, true);
17052 hda_nid_t nid_v, nid_s; 17082 hda_nid_t nid_v, nid_s;
17053 int i, err; 17083 int i, err;
17054 17084
@@ -17062,7 +17092,7 @@ static int alc861vd_auto_create_multi_out_ctls(struct alc_spec *spec,
17062 alc880_dac_to_idx( 17092 alc880_dac_to_idx(
17063 spec->multiout.dac_nids[i])); 17093 spec->multiout.dac_nids[i]));
17064 17094
17065 if (i == 2) { 17095 if (!pfx && i == 2) {
17066 /* Center/LFE */ 17096 /* Center/LFE */
17067 err = add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL, 17097 err = add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL,
17068 "Center", 17098 "Center",
@@ -17089,24 +17119,17 @@ static int alc861vd_auto_create_multi_out_ctls(struct alc_spec *spec,
17089 if (err < 0) 17119 if (err < 0)
17090 return err; 17120 return err;
17091 } else { 17121 } else {
17092 const char *pfx; 17122 const char *name = pfx;
17093 if (cfg->line_outs == 1 && 17123 if (!name)
17094 cfg->line_out_type == AUTO_PIN_SPEAKER_OUT) { 17124 name = chname[i];
17095 if (!cfg->hp_pins) 17125 err = __add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL,
17096 pfx = "Speaker"; 17126 name, i,
17097 else
17098 pfx = "PCM";
17099 } else
17100 pfx = chname[i];
17101 err = add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL, pfx,
17102 HDA_COMPOSE_AMP_VAL(nid_v, 3, 0, 17127 HDA_COMPOSE_AMP_VAL(nid_v, 3, 0,
17103 HDA_OUTPUT)); 17128 HDA_OUTPUT));
17104 if (err < 0) 17129 if (err < 0)
17105 return err; 17130 return err;
17106 if (cfg->line_outs == 1 && 17131 err = __add_pb_sw_ctrl(spec, ALC_CTL_BIND_MUTE,
17107 cfg->line_out_type == AUTO_PIN_SPEAKER_OUT) 17132 name, i,
17108 pfx = "Speaker";
17109 err = add_pb_sw_ctrl(spec, ALC_CTL_BIND_MUTE, pfx,
17110 HDA_COMPOSE_AMP_VAL(nid_s, 3, 2, 17133 HDA_COMPOSE_AMP_VAL(nid_s, 3, 2,
17111 HDA_INPUT)); 17134 HDA_INPUT));
17112 if (err < 0) 17135 if (err < 0)
@@ -17570,13 +17593,13 @@ static struct snd_kcontrol_new alc662_eeepc_p701_mixer[] = {
17570 HDA_CODEC_VOLUME("Master Playback Volume", 0x02, 0x0, HDA_OUTPUT), 17593 HDA_CODEC_VOLUME("Master Playback Volume", 0x02, 0x0, HDA_OUTPUT),
17571 ALC262_HIPPO_MASTER_SWITCH, 17594 ALC262_HIPPO_MASTER_SWITCH,
17572 17595
17573 HDA_CODEC_VOLUME("e-Mic Boost", 0x18, 0, HDA_INPUT), 17596 HDA_CODEC_VOLUME("Mic Boost Volume", 0x18, 0, HDA_INPUT),
17574 HDA_CODEC_VOLUME("e-Mic Playback Volume", 0x0b, 0x0, HDA_INPUT), 17597 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
17575 HDA_CODEC_MUTE("e-Mic Playback Switch", 0x0b, 0x0, HDA_INPUT), 17598 HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
17576 17599
17577 HDA_CODEC_VOLUME("i-Mic Boost", 0x19, 0, HDA_INPUT), 17600 HDA_CODEC_VOLUME("Internal Mic Boost Volume", 0x19, 0, HDA_INPUT),
17578 HDA_CODEC_VOLUME("i-Mic Playback Volume", 0x0b, 0x1, HDA_INPUT), 17601 HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
17579 HDA_CODEC_MUTE("i-Mic Playback Switch", 0x0b, 0x1, HDA_INPUT), 17602 HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
17580 { } /* end */ 17603 { } /* end */
17581}; 17604};
17582 17605
@@ -17720,8 +17743,8 @@ static struct snd_kcontrol_new alc663_g71v_mixer[] = {
17720 17743
17721 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT), 17744 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
17722 HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT), 17745 HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
17723 HDA_CODEC_VOLUME("i-Mic Playback Volume", 0x0b, 0x1, HDA_INPUT), 17746 HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
17724 HDA_CODEC_MUTE("i-Mic Playback Switch", 0x0b, 0x1, HDA_INPUT), 17747 HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
17725 { } /* end */ 17748 { } /* end */
17726}; 17749};
17727 17750
@@ -17732,8 +17755,8 @@ static struct snd_kcontrol_new alc663_g50v_mixer[] = {
17732 17755
17733 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT), 17756 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
17734 HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT), 17757 HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
17735 HDA_CODEC_VOLUME("i-Mic Playback Volume", 0x0b, 0x1, HDA_INPUT), 17758 HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
17736 HDA_CODEC_MUTE("i-Mic Playback Switch", 0x0b, 0x1, HDA_INPUT), 17759 HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
17737 HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT), 17760 HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
17738 HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT), 17761 HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
17739 { } /* end */ 17762 { } /* end */
@@ -18566,13 +18589,13 @@ static struct snd_kcontrol_new alc662_ecs_mixer[] = {
18566 HDA_CODEC_VOLUME("Master Playback Volume", 0x02, 0x0, HDA_OUTPUT), 18589 HDA_CODEC_VOLUME("Master Playback Volume", 0x02, 0x0, HDA_OUTPUT),
18567 ALC262_HIPPO_MASTER_SWITCH, 18590 ALC262_HIPPO_MASTER_SWITCH,
18568 18591
18569 HDA_CODEC_VOLUME("e-Mic/LineIn Boost", 0x18, 0, HDA_INPUT), 18592 HDA_CODEC_VOLUME("Mic/LineIn Boost Volume", 0x18, 0, HDA_INPUT),
18570 HDA_CODEC_VOLUME("e-Mic/LineIn Playback Volume", 0x0b, 0x0, HDA_INPUT), 18593 HDA_CODEC_VOLUME("Mic/LineIn Playback Volume", 0x0b, 0x0, HDA_INPUT),
18571 HDA_CODEC_MUTE("e-Mic/LineIn Playback Switch", 0x0b, 0x0, HDA_INPUT), 18594 HDA_CODEC_MUTE("Mic/LineIn Playback Switch", 0x0b, 0x0, HDA_INPUT),
18572 18595
18573 HDA_CODEC_VOLUME("i-Mic Boost", 0x19, 0, HDA_INPUT), 18596 HDA_CODEC_VOLUME("Internal Mic Boost Volume", 0x19, 0, HDA_INPUT),
18574 HDA_CODEC_VOLUME("i-Mic Playback Volume", 0x0b, 0x1, HDA_INPUT), 18597 HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
18575 HDA_CODEC_MUTE("i-Mic Playback Switch", 0x0b, 0x1, HDA_INPUT), 18598 HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
18576 { } /* end */ 18599 { } /* end */
18577}; 18600};
18578 18601
@@ -18583,13 +18606,13 @@ static struct snd_kcontrol_new alc272_nc10_mixer[] = {
18583 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x03, 0x0, HDA_OUTPUT), 18606 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x03, 0x0, HDA_OUTPUT),
18584 HDA_CODEC_MUTE("Headphone Playback Switch", 0x21, 0x0, HDA_OUTPUT), 18607 HDA_CODEC_MUTE("Headphone Playback Switch", 0x21, 0x0, HDA_OUTPUT),
18585 18608
18586 HDA_CODEC_VOLUME("Ext Mic Playback Volume", 0x0b, 0x0, HDA_INPUT), 18609 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
18587 HDA_CODEC_MUTE("Ext Mic Playback Switch", 0x0b, 0x0, HDA_INPUT), 18610 HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
18588 HDA_CODEC_VOLUME("Ext Mic Boost", 0x18, 0, HDA_INPUT), 18611 HDA_CODEC_VOLUME("Mic Boost Volume", 0x18, 0, HDA_INPUT),
18589 18612
18590 HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT), 18613 HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
18591 HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT), 18614 HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
18592 HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT), 18615 HDA_CODEC_VOLUME("Internal Mic Boost Volume", 0x19, 0, HDA_INPUT),
18593 { } /* end */ 18616 { } /* end */
18594}; 18617};
18595 18618
@@ -19094,20 +19117,24 @@ static int alc662_auto_fill_dac_nids(struct hda_codec *codec,
19094 return 0; 19117 return 0;
19095} 19118}
19096 19119
19097static inline int alc662_add_vol_ctl(struct alc_spec *spec, const char *pfx, 19120static inline int __alc662_add_vol_ctl(struct alc_spec *spec, const char *pfx,
19098 hda_nid_t nid, unsigned int chs) 19121 hda_nid_t nid, int idx, unsigned int chs)
19099{ 19122{
19100 return add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL, pfx, 19123 return __add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL, pfx, idx,
19101 HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT)); 19124 HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT));
19102} 19125}
19103 19126
19104static inline int alc662_add_sw_ctl(struct alc_spec *spec, const char *pfx, 19127static inline int __alc662_add_sw_ctl(struct alc_spec *spec, const char *pfx,
19105 hda_nid_t nid, unsigned int chs) 19128 hda_nid_t nid, int idx, unsigned int chs)
19106{ 19129{
19107 return add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, pfx, 19130 return __add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, pfx, idx,
19108 HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_INPUT)); 19131 HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_INPUT));
19109} 19132}
19110 19133
19134#define alc662_add_vol_ctl(spec, pfx, nid, chs) \
19135 __alc662_add_vol_ctl(spec, pfx, nid, 0, chs)
19136#define alc662_add_sw_ctl(spec, pfx, nid, chs) \
19137 __alc662_add_sw_ctl(spec, pfx, nid, 0, chs)
19111#define alc662_add_stereo_vol(spec, pfx, nid) \ 19138#define alc662_add_stereo_vol(spec, pfx, nid) \
19112 alc662_add_vol_ctl(spec, pfx, nid, 3) 19139 alc662_add_vol_ctl(spec, pfx, nid, 3)
19113#define alc662_add_stereo_sw(spec, pfx, nid) \ 19140#define alc662_add_stereo_sw(spec, pfx, nid) \
@@ -19121,6 +19148,7 @@ static int alc662_auto_create_multi_out_ctls(struct hda_codec *codec,
19121 static const char *chname[4] = { 19148 static const char *chname[4] = {
19122 "Front", "Surround", NULL /*CLFE*/, "Side" 19149 "Front", "Surround", NULL /*CLFE*/, "Side"
19123 }; 19150 };
19151 const char *pfx = alc_get_line_out_pfx(cfg, true);
19124 hda_nid_t nid, mix; 19152 hda_nid_t nid, mix;
19125 int i, err; 19153 int i, err;
19126 19154
@@ -19131,7 +19159,7 @@ static int alc662_auto_create_multi_out_ctls(struct hda_codec *codec,
19131 mix = alc662_dac_to_mix(codec, cfg->line_out_pins[i], nid); 19159 mix = alc662_dac_to_mix(codec, cfg->line_out_pins[i], nid);
19132 if (!mix) 19160 if (!mix)
19133 continue; 19161 continue;
19134 if (i == 2) { 19162 if (!pfx && i == 2) {
19135 /* Center/LFE */ 19163 /* Center/LFE */
19136 err = alc662_add_vol_ctl(spec, "Center", nid, 1); 19164 err = alc662_add_vol_ctl(spec, "Center", nid, 1);
19137 if (err < 0) 19165 if (err < 0)
@@ -19146,22 +19174,13 @@ static int alc662_auto_create_multi_out_ctls(struct hda_codec *codec,
19146 if (err < 0) 19174 if (err < 0)
19147 return err; 19175 return err;
19148 } else { 19176 } else {
19149 const char *pfx; 19177 const char *name = pfx;
19150 if (cfg->line_outs == 1 && 19178 if (!name)
19151 cfg->line_out_type == AUTO_PIN_SPEAKER_OUT) { 19179 name = chname[i];
19152 if (cfg->hp_outs) 19180 err = __alc662_add_vol_ctl(spec, name, nid, i, 3);
19153 pfx = "Speaker";
19154 else
19155 pfx = "PCM";
19156 } else
19157 pfx = chname[i];
19158 err = alc662_add_vol_ctl(spec, pfx, nid, 3);
19159 if (err < 0) 19181 if (err < 0)
19160 return err; 19182 return err;
19161 if (cfg->line_outs == 1 && 19183 err = __alc662_add_sw_ctl(spec, name, mix, i, 3);
19162 cfg->line_out_type == AUTO_PIN_SPEAKER_OUT)
19163 pfx = "Speaker";
19164 err = alc662_add_sw_ctl(spec, pfx, mix, 3);
19165 if (err < 0) 19184 if (err < 0)
19166 return err; 19185 return err;
19167 } 19186 }
@@ -19358,9 +19377,21 @@ static void alc662_auto_init(struct hda_codec *codec)
19358 alc_inithook(codec); 19377 alc_inithook(codec);
19359} 19378}
19360 19379
19380static void alc272_fixup_mario(struct hda_codec *codec,
19381 const struct alc_fixup *fix, int pre_init) {
19382 if (snd_hda_override_amp_caps(codec, 0x2, HDA_OUTPUT,
19383 (0x3b << AC_AMPCAP_OFFSET_SHIFT) |
19384 (0x3b << AC_AMPCAP_NUM_STEPS_SHIFT) |
19385 (0x03 << AC_AMPCAP_STEP_SIZE_SHIFT) |
19386 (0 << AC_AMPCAP_MUTE_SHIFT)))
19387 printk(KERN_WARNING
19388 "hda_codec: failed to override amp caps for NID 0x2\n");
19389}
19390
19361enum { 19391enum {
19362 ALC662_FIXUP_ASPIRE, 19392 ALC662_FIXUP_ASPIRE,
19363 ALC662_FIXUP_IDEAPAD, 19393 ALC662_FIXUP_IDEAPAD,
19394 ALC272_FIXUP_MARIO,
19364}; 19395};
19365 19396
19366static const struct alc_fixup alc662_fixups[] = { 19397static const struct alc_fixup alc662_fixups[] = {
@@ -19376,6 +19407,9 @@ static const struct alc_fixup alc662_fixups[] = {
19376 { } 19407 { }
19377 } 19408 }
19378 }, 19409 },
19410 [ALC272_FIXUP_MARIO] = {
19411 .func = alc272_fixup_mario,
19412 }
19379}; 19413};
19380 19414
19381static struct snd_pci_quirk alc662_fixup_tbl[] = { 19415static struct snd_pci_quirk alc662_fixup_tbl[] = {
@@ -19386,6 +19420,10 @@ static struct snd_pci_quirk alc662_fixup_tbl[] = {
19386 {} 19420 {}
19387}; 19421};
19388 19422
19423static const struct alc_model_fixup alc662_fixup_models[] = {
19424 {.id = ALC272_FIXUP_MARIO, .name = "mario"},
19425 {}
19426};
19389 19427
19390 19428
19391static int patch_alc662(struct hda_codec *codec) 19429static int patch_alc662(struct hda_codec *codec)
@@ -19485,7 +19523,8 @@ static int patch_alc662(struct hda_codec *codec)
19485 codec->patch_ops = alc_patch_ops; 19523 codec->patch_ops = alc_patch_ops;
19486 if (board_config == ALC662_AUTO) { 19524 if (board_config == ALC662_AUTO) {
19487 spec->init_hook = alc662_auto_init; 19525 spec->init_hook = alc662_auto_init;
19488 alc_pick_fixup(codec, alc662_fixup_tbl, alc662_fixups, 0); 19526 alc_pick_fixup_model(codec, alc662_fixup_models,
19527 alc662_fixup_tbl, alc662_fixups, 0);
19489 } 19528 }
19490 19529
19491 alc_init_jacks(codec); 19530 alc_init_jacks(codec);
@@ -19612,9 +19651,9 @@ static struct snd_kcontrol_new alc680_base_mixer[] = {
19612 HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT), 19651 HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
19613 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x4, 0x0, HDA_OUTPUT), 19652 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x4, 0x0, HDA_OUTPUT),
19614 HDA_CODEC_MUTE("Headphone Playback Switch", 0x16, 0x0, HDA_OUTPUT), 19653 HDA_CODEC_MUTE("Headphone Playback Switch", 0x16, 0x0, HDA_OUTPUT),
19615 HDA_CODEC_VOLUME("Int Mic Boost", 0x12, 0, HDA_INPUT), 19654 HDA_CODEC_VOLUME("Internal Mic Boost Volume", 0x12, 0, HDA_INPUT),
19616 HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT), 19655 HDA_CODEC_VOLUME("Mic Boost Volume", 0x18, 0, HDA_INPUT),
19617 HDA_CODEC_VOLUME("Line In Boost", 0x19, 0, HDA_INPUT), 19656 HDA_CODEC_VOLUME("Line In Boost Volume", 0x19, 0, HDA_INPUT),
19618 { } 19657 { }
19619}; 19658};
19620 19659
diff --git a/sound/pci/hda/patch_sigmatel.c b/sound/pci/hda/patch_sigmatel.c
index f03b2ff90496..4ab019d0924e 100644
--- a/sound/pci/hda/patch_sigmatel.c
+++ b/sound/pci/hda/patch_sigmatel.c
@@ -389,6 +389,9 @@ static hda_nid_t stac92hd83xxx_dmic_nids[STAC92HD83XXX_NUM_DMICS + 1] = {
389 0x11, 0x20, 0 389 0x11, 0x20, 0
390}; 390};
391 391
392#define STAC92HD88XXX_NUM_DMICS STAC92HD83XXX_NUM_DMICS
393#define stac92hd88xxx_dmic_nids stac92hd83xxx_dmic_nids
394
392#define STAC92HD87B_NUM_DMICS 1 395#define STAC92HD87B_NUM_DMICS 1
393static hda_nid_t stac92hd87b_dmic_nids[STAC92HD87B_NUM_DMICS + 1] = { 396static hda_nid_t stac92hd87b_dmic_nids[STAC92HD87B_NUM_DMICS + 1] = {
394 0x11, 0 397 0x11, 0
@@ -3591,7 +3594,7 @@ static int stac_check_auto_mic(struct hda_codec *codec)
3591 if (check_mic_pin(codec, spec->dmic_nids[i], 3594 if (check_mic_pin(codec, spec->dmic_nids[i],
3592 &fixed, &ext, &dock)) 3595 &fixed, &ext, &dock))
3593 return 0; 3596 return 0;
3594 if (!fixed && !ext && !dock) 3597 if (!fixed || (!ext && !dock))
3595 return 0; /* no input to switch */ 3598 return 0; /* no input to switch */
3596 if (!(get_wcaps(codec, ext) & AC_WCAP_UNSOL_CAP)) 3599 if (!(get_wcaps(codec, ext) & AC_WCAP_UNSOL_CAP))
3597 return 0; /* no unsol support */ 3600 return 0; /* no unsol support */
@@ -5422,7 +5425,7 @@ static int patch_stac92hd83xxx(struct hda_codec *codec)
5422 snd_hda_codec_write_cache(codec, codec->afg, 0, 0x7ED, 0); 5425 snd_hda_codec_write_cache(codec, codec->afg, 0, 0x7ED, 0);
5423 codec->no_trigger_sense = 1; 5426 codec->no_trigger_sense = 1;
5424 codec->spec = spec; 5427 codec->spec = spec;
5425 spec->linear_tone_beep = 1; 5428 spec->linear_tone_beep = 0;
5426 codec->slave_dig_outs = stac92hd83xxx_slave_dig_outs; 5429 codec->slave_dig_outs = stac92hd83xxx_slave_dig_outs;
5427 spec->digbeep_nid = 0x21; 5430 spec->digbeep_nid = 0x21;
5428 spec->dmic_nids = stac92hd83xxx_dmic_nids; 5431 spec->dmic_nids = stac92hd83xxx_dmic_nids;
@@ -5462,15 +5465,21 @@ again:
5462 spec->num_dmics = stac92xx_connected_ports(codec, 5465 spec->num_dmics = stac92xx_connected_ports(codec,
5463 stac92hd87b_dmic_nids, 5466 stac92hd87b_dmic_nids,
5464 STAC92HD87B_NUM_DMICS); 5467 STAC92HD87B_NUM_DMICS);
5465 /* Fall through */ 5468 spec->num_pins = ARRAY_SIZE(stac92hd88xxx_pin_nids);
5469 spec->pin_nids = stac92hd88xxx_pin_nids;
5470 spec->mono_nid = 0;
5471 spec->num_pwrs = 0;
5472 break;
5466 case 0x111d7666: 5473 case 0x111d7666:
5467 case 0x111d7667: 5474 case 0x111d7667:
5468 case 0x111d7668: 5475 case 0x111d7668:
5469 case 0x111d7669: 5476 case 0x111d7669:
5477 spec->num_dmics = stac92xx_connected_ports(codec,
5478 stac92hd88xxx_dmic_nids,
5479 STAC92HD88XXX_NUM_DMICS);
5470 spec->num_pins = ARRAY_SIZE(stac92hd88xxx_pin_nids); 5480 spec->num_pins = ARRAY_SIZE(stac92hd88xxx_pin_nids);
5471 spec->pin_nids = stac92hd88xxx_pin_nids; 5481 spec->pin_nids = stac92hd88xxx_pin_nids;
5472 spec->mono_nid = 0; 5482 spec->mono_nid = 0;
5473 spec->digbeep_nid = 0;
5474 spec->num_pwrs = 0; 5483 spec->num_pwrs = 0;
5475 break; 5484 break;
5476 case 0x111d7604: 5485 case 0x111d7604:
diff --git a/sound/pci/hda/patch_via.c b/sound/pci/hda/patch_via.c
index d1c3f8defc48..7f4852a478a1 100644
--- a/sound/pci/hda/patch_via.c
+++ b/sound/pci/hda/patch_via.c
@@ -263,8 +263,7 @@ static void vt1708_stop_hp_work(struct via_spec *spec)
263 return; 263 return;
264 snd_hda_codec_write(spec->codec, 0x1, 0, 0xf81, 264 snd_hda_codec_write(spec->codec, 0x1, 0, 0xf81,
265 !spec->vt1708_jack_detectect); 265 !spec->vt1708_jack_detectect);
266 cancel_delayed_work(&spec->vt1708_hp_work); 266 cancel_delayed_work_sync(&spec->vt1708_hp_work);
267 flush_scheduled_work();
268} 267}
269 268
270 269
diff --git a/sound/pci/ice1712/delta.c b/sound/pci/ice1712/delta.c
index 712c1710f9a2..7b62de089fee 100644
--- a/sound/pci/ice1712/delta.c
+++ b/sound/pci/ice1712/delta.c
@@ -96,6 +96,11 @@ static unsigned char ap_cs8427_codec_select(struct snd_ice1712 *ice)
96 tmp |= ICE1712_DELTA_AP_CCLK | ICE1712_DELTA_AP_CS_CODEC; 96 tmp |= ICE1712_DELTA_AP_CCLK | ICE1712_DELTA_AP_CS_CODEC;
97 tmp &= ~ICE1712_DELTA_AP_CS_DIGITAL; 97 tmp &= ~ICE1712_DELTA_AP_CS_DIGITAL;
98 break; 98 break;
99 case ICE1712_SUBDEVICE_DELTA66E:
100 tmp |= ICE1712_DELTA_66E_CCLK | ICE1712_DELTA_66E_CS_CHIP_A |
101 ICE1712_DELTA_66E_CS_CHIP_B;
102 tmp &= ~ICE1712_DELTA_66E_CS_CS8427;
103 break;
99 case ICE1712_SUBDEVICE_VX442: 104 case ICE1712_SUBDEVICE_VX442:
100 tmp |= ICE1712_VX442_CCLK | ICE1712_VX442_CODEC_CHIP_A | ICE1712_VX442_CODEC_CHIP_B; 105 tmp |= ICE1712_VX442_CCLK | ICE1712_VX442_CODEC_CHIP_A | ICE1712_VX442_CODEC_CHIP_B;
101 tmp &= ~ICE1712_VX442_CS_DIGITAL; 106 tmp &= ~ICE1712_VX442_CS_DIGITAL;
@@ -119,6 +124,9 @@ static void ap_cs8427_codec_deassert(struct snd_ice1712 *ice, unsigned char tmp)
119 case ICE1712_SUBDEVICE_DELTA410: 124 case ICE1712_SUBDEVICE_DELTA410:
120 tmp |= ICE1712_DELTA_AP_CS_DIGITAL; 125 tmp |= ICE1712_DELTA_AP_CS_DIGITAL;
121 break; 126 break;
127 case ICE1712_SUBDEVICE_DELTA66E:
128 tmp |= ICE1712_DELTA_66E_CS_CS8427;
129 break;
122 case ICE1712_SUBDEVICE_VX442: 130 case ICE1712_SUBDEVICE_VX442:
123 tmp |= ICE1712_VX442_CS_DIGITAL; 131 tmp |= ICE1712_VX442_CS_DIGITAL;
124 break; 132 break;
@@ -276,6 +284,20 @@ static void delta1010lt_ak4524_lock(struct snd_akm4xxx *ak, int chip)
276} 284}
277 285
278/* 286/*
287 * AK4524 on Delta66 rev E to choose the chip address
288 */
289static void delta66e_ak4524_lock(struct snd_akm4xxx *ak, int chip)
290{
291 struct snd_ak4xxx_private *priv = (void *)ak->private_value[0];
292 struct snd_ice1712 *ice = ak->private_data[0];
293
294 snd_ice1712_save_gpio_status(ice);
295 priv->cs_mask =
296 priv->cs_addr = chip == 0 ? ICE1712_DELTA_66E_CS_CHIP_A :
297 ICE1712_DELTA_66E_CS_CHIP_B;
298}
299
300/*
279 * AK4528 on VX442 to choose the chip mask 301 * AK4528 on VX442 to choose the chip mask
280 */ 302 */
281static void vx442_ak4524_lock(struct snd_akm4xxx *ak, int chip) 303static void vx442_ak4524_lock(struct snd_akm4xxx *ak, int chip)
@@ -487,6 +509,29 @@ static struct snd_ak4xxx_private akm_delta1010lt_priv __devinitdata = {
487 .mask_flags = 0, 509 .mask_flags = 0,
488}; 510};
489 511
512static struct snd_akm4xxx akm_delta66e __devinitdata = {
513 .type = SND_AK4524,
514 .num_adcs = 4,
515 .num_dacs = 4,
516 .ops = {
517 .lock = delta66e_ak4524_lock,
518 .set_rate_val = delta_ak4524_set_rate_val
519 }
520};
521
522static struct snd_ak4xxx_private akm_delta66e_priv __devinitdata = {
523 .caddr = 2,
524 .cif = 0, /* the default level of the CIF pin from AK4524 */
525 .data_mask = ICE1712_DELTA_66E_DOUT,
526 .clk_mask = ICE1712_DELTA_66E_CCLK,
527 .cs_mask = 0,
528 .cs_addr = 0, /* set later */
529 .cs_none = 0,
530 .add_flags = 0,
531 .mask_flags = 0,
532};
533
534
490static struct snd_akm4xxx akm_delta44 __devinitdata = { 535static struct snd_akm4xxx akm_delta44 __devinitdata = {
491 .type = SND_AK4524, 536 .type = SND_AK4524,
492 .num_adcs = 4, 537 .num_adcs = 4,
@@ -644,9 +689,11 @@ static int __devinit snd_ice1712_delta_init(struct snd_ice1712 *ice)
644 err = snd_ice1712_akm4xxx_init(ak, &akm_delta44, &akm_delta44_priv, ice); 689 err = snd_ice1712_akm4xxx_init(ak, &akm_delta44, &akm_delta44_priv, ice);
645 break; 690 break;
646 case ICE1712_SUBDEVICE_VX442: 691 case ICE1712_SUBDEVICE_VX442:
647 case ICE1712_SUBDEVICE_DELTA66E:
648 err = snd_ice1712_akm4xxx_init(ak, &akm_vx442, &akm_vx442_priv, ice); 692 err = snd_ice1712_akm4xxx_init(ak, &akm_vx442, &akm_vx442_priv, ice);
649 break; 693 break;
694 case ICE1712_SUBDEVICE_DELTA66E:
695 err = snd_ice1712_akm4xxx_init(ak, &akm_delta66e, &akm_delta66e_priv, ice);
696 break;
650 default: 697 default:
651 snd_BUG(); 698 snd_BUG();
652 return -EINVAL; 699 return -EINVAL;
diff --git a/sound/pci/ice1712/delta.h b/sound/pci/ice1712/delta.h
index 1a0ac6cd6501..11a9c3a76507 100644
--- a/sound/pci/ice1712/delta.h
+++ b/sound/pci/ice1712/delta.h
@@ -144,6 +144,17 @@ extern struct snd_ice1712_card_info snd_ice1712_delta_cards[];
144#define ICE1712_DELTA_1010LT_CS_NONE 0x50 /* nothing */ 144#define ICE1712_DELTA_1010LT_CS_NONE 0x50 /* nothing */
145#define ICE1712_DELTA_1010LT_WORDCLOCK 0x80 /* sample clock source: 0 = Word Clock Input, 1 = S/PDIF Input ??? */ 145#define ICE1712_DELTA_1010LT_WORDCLOCK 0x80 /* sample clock source: 0 = Word Clock Input, 1 = S/PDIF Input ??? */
146 146
147/* M-Audio Delta 66 rev. E definitions.
148 * Newer revisions of Delta 66 have CS8427 over SPI for
149 * S/PDIF transceiver instead of CS8404/CS8414. */
150/* 0x01 = DFS */
151#define ICE1712_DELTA_66E_CCLK 0x02 /* SPI clock */
152#define ICE1712_DELTA_66E_DIN 0x04 /* data input */
153#define ICE1712_DELTA_66E_DOUT 0x08 /* data output */
154#define ICE1712_DELTA_66E_CS_CS8427 0x10 /* chip select, low = CS8427 */
155#define ICE1712_DELTA_66E_CS_CHIP_A 0x20 /* AK4524 #0 */
156#define ICE1712_DELTA_66E_CS_CHIP_B 0x40 /* AK4524 #1 */
157
147/* Digigram VX442 definitions */ 158/* Digigram VX442 definitions */
148#define ICE1712_VX442_CCLK 0x02 /* SPI clock */ 159#define ICE1712_VX442_CCLK 0x02 /* SPI clock */
149#define ICE1712_VX442_DIN 0x04 /* data input */ 160#define ICE1712_VX442_DIN 0x04 /* data input */
diff --git a/sound/pci/oxygen/Makefile b/sound/pci/oxygen/Makefile
index acd8f15f7bff..0f8726551fde 100644
--- a/sound/pci/oxygen/Makefile
+++ b/sound/pci/oxygen/Makefile
@@ -1,10 +1,8 @@
1snd-oxygen-lib-objs := oxygen_io.o oxygen_lib.o oxygen_mixer.o oxygen_pcm.o 1snd-oxygen-lib-objs := oxygen_io.o oxygen_lib.o oxygen_mixer.o oxygen_pcm.o
2snd-hifier-objs := hifier.o 2snd-oxygen-objs := oxygen.o xonar_dg.o
3snd-oxygen-objs := oxygen.o
4snd-virtuoso-objs := virtuoso.o xonar_lib.o \ 3snd-virtuoso-objs := virtuoso.o xonar_lib.o \
5 xonar_pcm179x.o xonar_cs43xx.o xonar_wm87x6.o xonar_hdmi.o 4 xonar_pcm179x.o xonar_cs43xx.o xonar_wm87x6.o xonar_hdmi.o
6 5
7obj-$(CONFIG_SND_OXYGEN_LIB) += snd-oxygen-lib.o 6obj-$(CONFIG_SND_OXYGEN_LIB) += snd-oxygen-lib.o
8obj-$(CONFIG_SND_HIFIER) += snd-hifier.o
9obj-$(CONFIG_SND_OXYGEN) += snd-oxygen.o 7obj-$(CONFIG_SND_OXYGEN) += snd-oxygen.o
10obj-$(CONFIG_SND_VIRTUOSO) += snd-virtuoso.o 8obj-$(CONFIG_SND_VIRTUOSO) += snd-virtuoso.o
diff --git a/sound/pci/oxygen/cs4245.h b/sound/pci/oxygen/cs4245.h
new file mode 100644
index 000000000000..5e0197e07dd1
--- /dev/null
+++ b/sound/pci/oxygen/cs4245.h
@@ -0,0 +1,107 @@
1#define CS4245_CHIP_ID 0x01
2#define CS4245_POWER_CTRL 0x02
3#define CS4245_DAC_CTRL_1 0x03
4#define CS4245_ADC_CTRL 0x04
5#define CS4245_MCLK_FREQ 0x05
6#define CS4245_SIGNAL_SEL 0x06
7#define CS4245_PGA_B_CTRL 0x07
8#define CS4245_PGA_A_CTRL 0x08
9#define CS4245_ANALOG_IN 0x09
10#define CS4245_DAC_A_CTRL 0x0a
11#define CS4245_DAC_B_CTRL 0x0b
12#define CS4245_DAC_CTRL_2 0x0c
13#define CS4245_INT_STATUS 0x0d
14#define CS4245_INT_MASK 0x0e
15#define CS4245_INT_MODE_MSB 0x0f
16#define CS4245_INT_MODE_LSB 0x10
17
18/* Chip ID */
19#define CS4245_CHIP_PART_MASK 0xf0
20#define CS4245_CHIP_REV_MASK 0x0f
21
22/* Power Control */
23#define CS4245_FREEZE 0x80
24#define CS4245_PDN_MIC 0x08
25#define CS4245_PDN_ADC 0x04
26#define CS4245_PDN_DAC 0x02
27#define CS4245_PDN 0x01
28
29/* DAC Control */
30#define CS4245_DAC_FM_MASK 0xc0
31#define CS4245_DAC_FM_SINGLE 0x00
32#define CS4245_DAC_FM_DOUBLE 0x40
33#define CS4245_DAC_FM_QUAD 0x80
34#define CS4245_DAC_DIF_MASK 0x30
35#define CS4245_DAC_DIF_LJUST 0x00
36#define CS4245_DAC_DIF_I2S 0x10
37#define CS4245_DAC_DIF_RJUST_16 0x20
38#define CS4245_DAC_DIF_RJUST_24 0x30
39#define CS4245_RESERVED_1 0x08
40#define CS4245_MUTE_DAC 0x04
41#define CS4245_DEEMPH 0x02
42#define CS4245_DAC_MASTER 0x01
43
44/* ADC Control */
45#define CS4245_ADC_FM_MASK 0xc0
46#define CS4245_ADC_FM_SINGLE 0x00
47#define CS4245_ADC_FM_DOUBLE 0x40
48#define CS4245_ADC_FM_QUAD 0x80
49#define CS4245_ADC_DIF_MASK 0x10
50#define CS4245_ADC_DIF_LJUST 0x00
51#define CS4245_ADC_DIF_I2S 0x10
52#define CS4245_MUTE_ADC 0x04
53#define CS4245_HPF_FREEZE 0x02
54#define CS4245_ADC_MASTER 0x01
55
56/* MCLK Frequency */
57#define CS4245_MCLK1_MASK 0x70
58#define CS4245_MCLK1_SHIFT 4
59#define CS4245_MCLK2_MASK 0x07
60#define CS4245_MCLK2_SHIFT 0
61#define CS4245_MCLK_1 0
62#define CS4245_MCLK_1_5 1
63#define CS4245_MCLK_2 2
64#define CS4245_MCLK_3 3
65#define CS4245_MCLK_4 4
66
67/* Signal Selection */
68#define CS4245_A_OUT_SEL_MASK 0x60
69#define CS4245_A_OUT_SEL_HIZ 0x00
70#define CS4245_A_OUT_SEL_DAC 0x20
71#define CS4245_A_OUT_SEL_PGA 0x40
72#define CS4245_LOOP 0x02
73#define CS4245_ASYNCH 0x01
74
75/* Channel B/A PGA Control */
76#define CS4245_PGA_GAIN_MASK 0x3f
77
78/* ADC Input Control */
79#define CS4245_PGA_SOFT 0x10
80#define CS4245_PGA_ZERO 0x08
81#define CS4245_SEL_MASK 0x07
82#define CS4245_SEL_MIC 0x00
83#define CS4245_SEL_INPUT_1 0x01
84#define CS4245_SEL_INPUT_2 0x02
85#define CS4245_SEL_INPUT_3 0x03
86#define CS4245_SEL_INPUT_4 0x04
87#define CS4245_SEL_INPUT_5 0x05
88#define CS4245_SEL_INPUT_6 0x06
89
90/* DAC Channel A/B Volume Control */
91#define CS4245_VOL_MASK 0xff
92
93/* DAC Control 2 */
94#define CS4245_DAC_SOFT 0x80
95#define CS4245_DAC_ZERO 0x40
96#define CS4245_INVERT_DAC 0x20
97#define CS4245_INT_ACTIVE_HIGH 0x01
98
99/* Interrupt Status/Mask/Mode */
100#define CS4245_ADC_CLK_ERR 0x08
101#define CS4245_DAC_CLK_ERR 0x04
102#define CS4245_ADC_OVFL 0x02
103#define CS4245_ADC_UNDRFL 0x01
104
105
106#define CS4245_SPI_ADDRESS (0x9e << 16)
107#define CS4245_SPI_WRITE (0 << 16)
diff --git a/sound/pci/oxygen/hifier.c b/sound/pci/oxygen/hifier.c
deleted file mode 100644
index 5a87d683691f..000000000000
--- a/sound/pci/oxygen/hifier.c
+++ /dev/null
@@ -1,239 +0,0 @@
1/*
2 * C-Media CMI8788 driver for the MediaTek/TempoTec HiFier Fantasia
3 *
4 * Copyright (c) Clemens Ladisch <clemens@ladisch.de>
5 *
6 *
7 * This driver is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License, version 2.
9 *
10 * This driver is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this driver; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 */
19
20/*
21 * CMI8788:
22 *
23 * SPI 0 -> AK4396
24 */
25
26#include <linux/delay.h>
27#include <linux/pci.h>
28#include <sound/control.h>
29#include <sound/core.h>
30#include <sound/initval.h>
31#include <sound/pcm.h>
32#include <sound/tlv.h>
33#include "oxygen.h"
34#include "ak4396.h"
35
36MODULE_AUTHOR("Clemens Ladisch <clemens@ladisch.de>");
37MODULE_DESCRIPTION("TempoTec HiFier driver");
38MODULE_LICENSE("GPL v2");
39
40static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX;
41static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR;
42static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP;
43
44module_param_array(index, int, NULL, 0444);
45MODULE_PARM_DESC(index, "card index");
46module_param_array(id, charp, NULL, 0444);
47MODULE_PARM_DESC(id, "ID string");
48module_param_array(enable, bool, NULL, 0444);
49MODULE_PARM_DESC(enable, "enable card");
50
51static DEFINE_PCI_DEVICE_TABLE(hifier_ids) = {
52 { OXYGEN_PCI_SUBID(0x14c3, 0x1710) },
53 { OXYGEN_PCI_SUBID(0x14c3, 0x1711) },
54 { OXYGEN_PCI_SUBID_BROKEN_EEPROM },
55 { }
56};
57MODULE_DEVICE_TABLE(pci, hifier_ids);
58
59struct hifier_data {
60 u8 ak4396_regs[5];
61};
62
63static void ak4396_write(struct oxygen *chip, u8 reg, u8 value)
64{
65 struct hifier_data *data = chip->model_data;
66
67 oxygen_write_spi(chip, OXYGEN_SPI_TRIGGER |
68 OXYGEN_SPI_DATA_LENGTH_2 |
69 OXYGEN_SPI_CLOCK_160 |
70 (0 << OXYGEN_SPI_CODEC_SHIFT) |
71 OXYGEN_SPI_CEN_LATCH_CLOCK_HI,
72 AK4396_WRITE | (reg << 8) | value);
73 data->ak4396_regs[reg] = value;
74}
75
76static void ak4396_write_cached(struct oxygen *chip, u8 reg, u8 value)
77{
78 struct hifier_data *data = chip->model_data;
79
80 if (value != data->ak4396_regs[reg])
81 ak4396_write(chip, reg, value);
82}
83
84static void hifier_registers_init(struct oxygen *chip)
85{
86 struct hifier_data *data = chip->model_data;
87
88 ak4396_write(chip, AK4396_CONTROL_1, AK4396_DIF_24_MSB | AK4396_RSTN);
89 ak4396_write(chip, AK4396_CONTROL_2,
90 data->ak4396_regs[AK4396_CONTROL_2]);
91 ak4396_write(chip, AK4396_CONTROL_3, AK4396_PCM);
92 ak4396_write(chip, AK4396_LCH_ATT, chip->dac_volume[0]);
93 ak4396_write(chip, AK4396_RCH_ATT, chip->dac_volume[1]);
94}
95
96static void hifier_init(struct oxygen *chip)
97{
98 struct hifier_data *data = chip->model_data;
99
100 data->ak4396_regs[AK4396_CONTROL_2] =
101 AK4396_SMUTE | AK4396_DEM_OFF | AK4396_DFS_NORMAL;
102 hifier_registers_init(chip);
103
104 snd_component_add(chip->card, "AK4396");
105 snd_component_add(chip->card, "CS5340");
106}
107
108static void hifier_cleanup(struct oxygen *chip)
109{
110}
111
112static void hifier_resume(struct oxygen *chip)
113{
114 hifier_registers_init(chip);
115}
116
117static void set_ak4396_params(struct oxygen *chip,
118 struct snd_pcm_hw_params *params)
119{
120 struct hifier_data *data = chip->model_data;
121 u8 value;
122
123 value = data->ak4396_regs[AK4396_CONTROL_2] & ~AK4396_DFS_MASK;
124 if (params_rate(params) <= 54000)
125 value |= AK4396_DFS_NORMAL;
126 else if (params_rate(params) <= 108000)
127 value |= AK4396_DFS_DOUBLE;
128 else
129 value |= AK4396_DFS_QUAD;
130
131 msleep(1); /* wait for the new MCLK to become stable */
132
133 if (value != data->ak4396_regs[AK4396_CONTROL_2]) {
134 ak4396_write(chip, AK4396_CONTROL_1,
135 AK4396_DIF_24_MSB);
136 ak4396_write(chip, AK4396_CONTROL_2, value);
137 ak4396_write(chip, AK4396_CONTROL_1,
138 AK4396_DIF_24_MSB | AK4396_RSTN);
139 }
140}
141
142static void update_ak4396_volume(struct oxygen *chip)
143{
144 ak4396_write_cached(chip, AK4396_LCH_ATT, chip->dac_volume[0]);
145 ak4396_write_cached(chip, AK4396_RCH_ATT, chip->dac_volume[1]);
146}
147
148static void update_ak4396_mute(struct oxygen *chip)
149{
150 struct hifier_data *data = chip->model_data;
151 u8 value;
152
153 value = data->ak4396_regs[AK4396_CONTROL_2] & ~AK4396_SMUTE;
154 if (chip->dac_mute)
155 value |= AK4396_SMUTE;
156 ak4396_write_cached(chip, AK4396_CONTROL_2, value);
157}
158
159static void set_cs5340_params(struct oxygen *chip,
160 struct snd_pcm_hw_params *params)
161{
162}
163
164static const DECLARE_TLV_DB_LINEAR(ak4396_db_scale, TLV_DB_GAIN_MUTE, 0);
165
166static const struct oxygen_model model_hifier = {
167 .shortname = "C-Media CMI8787",
168 .longname = "C-Media Oxygen HD Audio",
169 .chip = "CMI8788",
170 .init = hifier_init,
171 .cleanup = hifier_cleanup,
172 .resume = hifier_resume,
173 .get_i2s_mclk = oxygen_default_i2s_mclk,
174 .set_dac_params = set_ak4396_params,
175 .set_adc_params = set_cs5340_params,
176 .update_dac_volume = update_ak4396_volume,
177 .update_dac_mute = update_ak4396_mute,
178 .dac_tlv = ak4396_db_scale,
179 .model_data_size = sizeof(struct hifier_data),
180 .device_config = PLAYBACK_0_TO_I2S |
181 PLAYBACK_1_TO_SPDIF |
182 CAPTURE_0_FROM_I2S_1,
183 .dac_channels = 2,
184 .dac_volume_min = 0,
185 .dac_volume_max = 255,
186 .function_flags = OXYGEN_FUNCTION_SPI,
187 .dac_i2s_format = OXYGEN_I2S_FORMAT_LJUST,
188 .adc_i2s_format = OXYGEN_I2S_FORMAT_LJUST,
189};
190
191static int __devinit get_hifier_model(struct oxygen *chip,
192 const struct pci_device_id *id)
193{
194 chip->model = model_hifier;
195 return 0;
196}
197
198static int __devinit hifier_probe(struct pci_dev *pci,
199 const struct pci_device_id *pci_id)
200{
201 static int dev;
202 int err;
203
204 if (dev >= SNDRV_CARDS)
205 return -ENODEV;
206 if (!enable[dev]) {
207 ++dev;
208 return -ENOENT;
209 }
210 err = oxygen_pci_probe(pci, index[dev], id[dev], THIS_MODULE,
211 hifier_ids, get_hifier_model);
212 if (err >= 0)
213 ++dev;
214 return err;
215}
216
217static struct pci_driver hifier_driver = {
218 .name = "CMI8787HiFier",
219 .id_table = hifier_ids,
220 .probe = hifier_probe,
221 .remove = __devexit_p(oxygen_pci_remove),
222#ifdef CONFIG_PM
223 .suspend = oxygen_pci_suspend,
224 .resume = oxygen_pci_resume,
225#endif
226};
227
228static int __init alsa_card_hifier_init(void)
229{
230 return pci_register_driver(&hifier_driver);
231}
232
233static void __exit alsa_card_hifier_exit(void)
234{
235 pci_unregister_driver(&hifier_driver);
236}
237
238module_init(alsa_card_hifier_init)
239module_exit(alsa_card_hifier_exit)
diff --git a/sound/pci/oxygen/oxygen.c b/sound/pci/oxygen/oxygen.c
index 98a8eb3c92f7..d7e8ddd9a67b 100644
--- a/sound/pci/oxygen/oxygen.c
+++ b/sound/pci/oxygen/oxygen.c
@@ -20,19 +20,32 @@
20/* 20/*
21 * CMI8788: 21 * CMI8788:
22 * 22 *
23 * SPI 0 -> 1st AK4396 (front) 23 * SPI 0 -> 1st AK4396 (front)
24 * SPI 1 -> 2nd AK4396 (surround) 24 * SPI 1 -> 2nd AK4396 (surround)
25 * SPI 2 -> 3rd AK4396 (center/LFE) 25 * SPI 2 -> 3rd AK4396 (center/LFE)
26 * SPI 3 -> WM8785 26 * SPI 3 -> WM8785
27 * SPI 4 -> 4th AK4396 (back) 27 * SPI 4 -> 4th AK4396 (back)
28 * 28 *
29 * GPIO 0 -> DFS0 of AK5385 29 * GPIO 0 -> DFS0 of AK5385
30 * GPIO 1 -> DFS1 of AK5385 30 * GPIO 1 -> DFS1 of AK5385
31 * GPIO 8 -> enable headphone amplifier on HT-Omega models 31 *
32 * X-Meridian models:
33 * GPIO 4 -> enable extension S/PDIF input
34 * GPIO 6 -> enable on-board S/PDIF input
35 *
36 * Claro models:
37 * GPIO 6 -> S/PDIF from optical (0) or coaxial (1) input
38 * GPIO 8 -> enable headphone amplifier
32 * 39 *
33 * CM9780: 40 * CM9780:
34 * 41 *
35 * GPO 0 -> route line-in (0) or AC97 output (1) to ADC input 42 * LINE_OUT -> input of ADC
43 *
44 * AUX_IN <- aux
45 * CD_IN <- CD
46 * MIC_IN <- mic
47 *
48 * GPO 0 -> route line-in (0) or AC97 output (1) to ADC input
36 */ 49 */
37 50
38#include <linux/delay.h> 51#include <linux/delay.h>
@@ -41,18 +54,22 @@
41#include <sound/ac97_codec.h> 54#include <sound/ac97_codec.h>
42#include <sound/control.h> 55#include <sound/control.h>
43#include <sound/core.h> 56#include <sound/core.h>
57#include <sound/info.h>
44#include <sound/initval.h> 58#include <sound/initval.h>
45#include <sound/pcm.h> 59#include <sound/pcm.h>
46#include <sound/pcm_params.h> 60#include <sound/pcm_params.h>
47#include <sound/tlv.h> 61#include <sound/tlv.h>
48#include "oxygen.h" 62#include "oxygen.h"
63#include "xonar_dg.h"
49#include "ak4396.h" 64#include "ak4396.h"
50#include "wm8785.h" 65#include "wm8785.h"
51 66
52MODULE_AUTHOR("Clemens Ladisch <clemens@ladisch.de>"); 67MODULE_AUTHOR("Clemens Ladisch <clemens@ladisch.de>");
53MODULE_DESCRIPTION("C-Media CMI8788 driver"); 68MODULE_DESCRIPTION("C-Media CMI8788 driver");
54MODULE_LICENSE("GPL v2"); 69MODULE_LICENSE("GPL v2");
55MODULE_SUPPORTED_DEVICE("{{C-Media,CMI8788}}"); 70MODULE_SUPPORTED_DEVICE("{{C-Media,CMI8786}"
71 ",{C-Media,CMI8787}"
72 ",{C-Media,CMI8788}}");
56 73
57static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; 74static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX;
58static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; 75static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR;
@@ -66,24 +83,46 @@ module_param_array(enable, bool, NULL, 0444);
66MODULE_PARM_DESC(enable, "enable card"); 83MODULE_PARM_DESC(enable, "enable card");
67 84
68enum { 85enum {
69 MODEL_CMEDIA_REF, /* C-Media's reference design */ 86 MODEL_CMEDIA_REF,
70 MODEL_MERIDIAN, /* AuzenTech X-Meridian */ 87 MODEL_MERIDIAN,
71 MODEL_CLARO, /* HT-Omega Claro */ 88 MODEL_MERIDIAN_2G,
72 MODEL_CLARO_HALO, /* HT-Omega Claro halo */ 89 MODEL_CLARO,
90 MODEL_CLARO_HALO,
91 MODEL_FANTASIA,
92 MODEL_SERENADE,
93 MODEL_2CH_OUTPUT,
94 MODEL_HG2PCI,
95 MODEL_XONAR_DG,
73}; 96};
74 97
75static DEFINE_PCI_DEVICE_TABLE(oxygen_ids) = { 98static DEFINE_PCI_DEVICE_TABLE(oxygen_ids) = {
99 /* C-Media's reference design */
76 { OXYGEN_PCI_SUBID(0x10b0, 0x0216), .driver_data = MODEL_CMEDIA_REF }, 100 { OXYGEN_PCI_SUBID(0x10b0, 0x0216), .driver_data = MODEL_CMEDIA_REF },
101 { OXYGEN_PCI_SUBID(0x10b0, 0x0217), .driver_data = MODEL_CMEDIA_REF },
77 { OXYGEN_PCI_SUBID(0x10b0, 0x0218), .driver_data = MODEL_CMEDIA_REF }, 102 { OXYGEN_PCI_SUBID(0x10b0, 0x0218), .driver_data = MODEL_CMEDIA_REF },
78 { OXYGEN_PCI_SUBID(0x10b0, 0x0219), .driver_data = MODEL_CMEDIA_REF }, 103 { OXYGEN_PCI_SUBID(0x10b0, 0x0219), .driver_data = MODEL_CMEDIA_REF },
79 { OXYGEN_PCI_SUBID(0x13f6, 0x0001), .driver_data = MODEL_CMEDIA_REF }, 104 { OXYGEN_PCI_SUBID(0x13f6, 0x0001), .driver_data = MODEL_CMEDIA_REF },
80 { OXYGEN_PCI_SUBID(0x13f6, 0x0010), .driver_data = MODEL_CMEDIA_REF }, 105 { OXYGEN_PCI_SUBID(0x13f6, 0x0010), .driver_data = MODEL_CMEDIA_REF },
81 { OXYGEN_PCI_SUBID(0x13f6, 0x8788), .driver_data = MODEL_CMEDIA_REF }, 106 { OXYGEN_PCI_SUBID(0x13f6, 0x8788), .driver_data = MODEL_CMEDIA_REF },
82 { OXYGEN_PCI_SUBID(0x13f6, 0xffff), .driver_data = MODEL_CMEDIA_REF },
83 { OXYGEN_PCI_SUBID(0x147a, 0xa017), .driver_data = MODEL_CMEDIA_REF }, 107 { OXYGEN_PCI_SUBID(0x147a, 0xa017), .driver_data = MODEL_CMEDIA_REF },
84 { OXYGEN_PCI_SUBID(0x1a58, 0x0910), .driver_data = MODEL_CMEDIA_REF }, 108 { OXYGEN_PCI_SUBID(0x1a58, 0x0910), .driver_data = MODEL_CMEDIA_REF },
109 /* Asus Xonar DG */
110 { OXYGEN_PCI_SUBID(0x1043, 0x8467), .driver_data = MODEL_XONAR_DG },
111 /* PCI 2.0 HD Audio */
112 { OXYGEN_PCI_SUBID(0x13f6, 0x8782), .driver_data = MODEL_2CH_OUTPUT },
113 /* Kuroutoshikou CMI8787-HG2PCI */
114 { OXYGEN_PCI_SUBID(0x13f6, 0xffff), .driver_data = MODEL_HG2PCI },
115 /* TempoTec HiFier Fantasia */
116 { OXYGEN_PCI_SUBID(0x14c3, 0x1710), .driver_data = MODEL_FANTASIA },
117 /* TempoTec HiFier Serenade */
118 { OXYGEN_PCI_SUBID(0x14c3, 0x1711), .driver_data = MODEL_SERENADE },
119 /* AuzenTech X-Meridian */
85 { OXYGEN_PCI_SUBID(0x415a, 0x5431), .driver_data = MODEL_MERIDIAN }, 120 { OXYGEN_PCI_SUBID(0x415a, 0x5431), .driver_data = MODEL_MERIDIAN },
121 /* AuzenTech X-Meridian 2G */
122 { OXYGEN_PCI_SUBID(0x5431, 0x017a), .driver_data = MODEL_MERIDIAN_2G },
123 /* HT-Omega Claro */
86 { OXYGEN_PCI_SUBID(0x7284, 0x9761), .driver_data = MODEL_CLARO }, 124 { OXYGEN_PCI_SUBID(0x7284, 0x9761), .driver_data = MODEL_CLARO },
125 /* HT-Omega Claro halo */
87 { OXYGEN_PCI_SUBID(0x7284, 0x9781), .driver_data = MODEL_CLARO_HALO }, 126 { OXYGEN_PCI_SUBID(0x7284, 0x9781), .driver_data = MODEL_CLARO_HALO },
88 { } 127 { }
89}; 128};
@@ -95,9 +134,15 @@ MODULE_DEVICE_TABLE(pci, oxygen_ids);
95#define GPIO_AK5385_DFS_DOUBLE 0x0001 134#define GPIO_AK5385_DFS_DOUBLE 0x0001
96#define GPIO_AK5385_DFS_QUAD 0x0002 135#define GPIO_AK5385_DFS_QUAD 0x0002
97 136
137#define GPIO_MERIDIAN_DIG_MASK 0x0050
138#define GPIO_MERIDIAN_DIG_EXT 0x0010
139#define GPIO_MERIDIAN_DIG_BOARD 0x0040
140
141#define GPIO_CLARO_DIG_COAX 0x0040
98#define GPIO_CLARO_HP 0x0100 142#define GPIO_CLARO_HP 0x0100
99 143
100struct generic_data { 144struct generic_data {
145 unsigned int dacs;
101 u8 ak4396_regs[4][5]; 146 u8 ak4396_regs[4][5];
102 u16 wm8785_regs[3]; 147 u16 wm8785_regs[3];
103}; 148};
@@ -148,7 +193,7 @@ static void ak4396_registers_init(struct oxygen *chip)
148 struct generic_data *data = chip->model_data; 193 struct generic_data *data = chip->model_data;
149 unsigned int i; 194 unsigned int i;
150 195
151 for (i = 0; i < 4; ++i) { 196 for (i = 0; i < data->dacs; ++i) {
152 ak4396_write(chip, i, AK4396_CONTROL_1, 197 ak4396_write(chip, i, AK4396_CONTROL_1,
153 AK4396_DIF_24_MSB | AK4396_RSTN); 198 AK4396_DIF_24_MSB | AK4396_RSTN);
154 ak4396_write(chip, i, AK4396_CONTROL_2, 199 ak4396_write(chip, i, AK4396_CONTROL_2,
@@ -166,6 +211,7 @@ static void ak4396_init(struct oxygen *chip)
166{ 211{
167 struct generic_data *data = chip->model_data; 212 struct generic_data *data = chip->model_data;
168 213
214 data->dacs = chip->model.dac_channels_pcm / 2;
169 data->ak4396_regs[0][AK4396_CONTROL_2] = 215 data->ak4396_regs[0][AK4396_CONTROL_2] =
170 AK4396_SMUTE | AK4396_DEM_OFF | AK4396_DFS_NORMAL; 216 AK4396_SMUTE | AK4396_DEM_OFF | AK4396_DFS_NORMAL;
171 ak4396_registers_init(chip); 217 ak4396_registers_init(chip);
@@ -207,6 +253,10 @@ static void generic_init(struct oxygen *chip)
207 253
208static void meridian_init(struct oxygen *chip) 254static void meridian_init(struct oxygen *chip)
209{ 255{
256 oxygen_set_bits16(chip, OXYGEN_GPIO_CONTROL,
257 GPIO_MERIDIAN_DIG_MASK);
258 oxygen_write16_masked(chip, OXYGEN_GPIO_DATA,
259 GPIO_MERIDIAN_DIG_BOARD, GPIO_MERIDIAN_DIG_MASK);
210 ak4396_init(chip); 260 ak4396_init(chip);
211 ak5385_init(chip); 261 ak5385_init(chip);
212} 262}
@@ -220,6 +270,8 @@ static void claro_enable_hp(struct oxygen *chip)
220 270
221static void claro_init(struct oxygen *chip) 271static void claro_init(struct oxygen *chip)
222{ 272{
273 oxygen_set_bits16(chip, OXYGEN_GPIO_CONTROL, GPIO_CLARO_DIG_COAX);
274 oxygen_clear_bits16(chip, OXYGEN_GPIO_DATA, GPIO_CLARO_DIG_COAX);
223 ak4396_init(chip); 275 ak4396_init(chip);
224 wm8785_init(chip); 276 wm8785_init(chip);
225 claro_enable_hp(chip); 277 claro_enable_hp(chip);
@@ -227,11 +279,24 @@ static void claro_init(struct oxygen *chip)
227 279
228static void claro_halo_init(struct oxygen *chip) 280static void claro_halo_init(struct oxygen *chip)
229{ 281{
282 oxygen_set_bits16(chip, OXYGEN_GPIO_CONTROL, GPIO_CLARO_DIG_COAX);
283 oxygen_clear_bits16(chip, OXYGEN_GPIO_DATA, GPIO_CLARO_DIG_COAX);
230 ak4396_init(chip); 284 ak4396_init(chip);
231 ak5385_init(chip); 285 ak5385_init(chip);
232 claro_enable_hp(chip); 286 claro_enable_hp(chip);
233} 287}
234 288
289static void fantasia_init(struct oxygen *chip)
290{
291 ak4396_init(chip);
292 snd_component_add(chip->card, "CS5340");
293}
294
295static void stereo_output_init(struct oxygen *chip)
296{
297 ak4396_init(chip);
298}
299
235static void generic_cleanup(struct oxygen *chip) 300static void generic_cleanup(struct oxygen *chip)
236{ 301{
237} 302}
@@ -268,6 +333,11 @@ static void claro_resume(struct oxygen *chip)
268 claro_enable_hp(chip); 333 claro_enable_hp(chip);
269} 334}
270 335
336static void stereo_resume(struct oxygen *chip)
337{
338 ak4396_registers_init(chip);
339}
340
271static void set_ak4396_params(struct oxygen *chip, 341static void set_ak4396_params(struct oxygen *chip,
272 struct snd_pcm_hw_params *params) 342 struct snd_pcm_hw_params *params)
273{ 343{
@@ -286,7 +356,7 @@ static void set_ak4396_params(struct oxygen *chip,
286 msleep(1); /* wait for the new MCLK to become stable */ 356 msleep(1); /* wait for the new MCLK to become stable */
287 357
288 if (value != data->ak4396_regs[0][AK4396_CONTROL_2]) { 358 if (value != data->ak4396_regs[0][AK4396_CONTROL_2]) {
289 for (i = 0; i < 4; ++i) { 359 for (i = 0; i < data->dacs; ++i) {
290 ak4396_write(chip, i, AK4396_CONTROL_1, 360 ak4396_write(chip, i, AK4396_CONTROL_1,
291 AK4396_DIF_24_MSB); 361 AK4396_DIF_24_MSB);
292 ak4396_write(chip, i, AK4396_CONTROL_2, value); 362 ak4396_write(chip, i, AK4396_CONTROL_2, value);
@@ -298,9 +368,10 @@ static void set_ak4396_params(struct oxygen *chip,
298 368
299static void update_ak4396_volume(struct oxygen *chip) 369static void update_ak4396_volume(struct oxygen *chip)
300{ 370{
371 struct generic_data *data = chip->model_data;
301 unsigned int i; 372 unsigned int i;
302 373
303 for (i = 0; i < 4; ++i) { 374 for (i = 0; i < data->dacs; ++i) {
304 ak4396_write_cached(chip, i, AK4396_LCH_ATT, 375 ak4396_write_cached(chip, i, AK4396_LCH_ATT,
305 chip->dac_volume[i * 2]); 376 chip->dac_volume[i * 2]);
306 ak4396_write_cached(chip, i, AK4396_RCH_ATT, 377 ak4396_write_cached(chip, i, AK4396_RCH_ATT,
@@ -317,7 +388,7 @@ static void update_ak4396_mute(struct oxygen *chip)
317 value = data->ak4396_regs[0][AK4396_CONTROL_2] & ~AK4396_SMUTE; 388 value = data->ak4396_regs[0][AK4396_CONTROL_2] & ~AK4396_SMUTE;
318 if (chip->dac_mute) 389 if (chip->dac_mute)
319 value |= AK4396_SMUTE; 390 value |= AK4396_SMUTE;
320 for (i = 0; i < 4; ++i) 391 for (i = 0; i < data->dacs; ++i)
321 ak4396_write_cached(chip, i, AK4396_CONTROL_2, value); 392 ak4396_write_cached(chip, i, AK4396_CONTROL_2, value);
322} 393}
323 394
@@ -356,6 +427,10 @@ static void set_ak5385_params(struct oxygen *chip,
356 value, GPIO_AK5385_DFS_MASK); 427 value, GPIO_AK5385_DFS_MASK);
357} 428}
358 429
430static void set_no_params(struct oxygen *chip, struct snd_pcm_hw_params *params)
431{
432}
433
359static int rolloff_info(struct snd_kcontrol *ctl, 434static int rolloff_info(struct snd_kcontrol *ctl,
360 struct snd_ctl_elem_info *info) 435 struct snd_ctl_elem_info *info)
361{ 436{
@@ -363,13 +438,7 @@ static int rolloff_info(struct snd_kcontrol *ctl,
363 "Sharp Roll-off", "Slow Roll-off" 438 "Sharp Roll-off", "Slow Roll-off"
364 }; 439 };
365 440
366 info->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; 441 return snd_ctl_enum_info(info, 1, 2, names);
367 info->count = 1;
368 info->value.enumerated.items = 2;
369 if (info->value.enumerated.item >= 2)
370 info->value.enumerated.item = 1;
371 strcpy(info->value.enumerated.name, names[info->value.enumerated.item]);
372 return 0;
373} 442}
374 443
375static int rolloff_get(struct snd_kcontrol *ctl, 444static int rolloff_get(struct snd_kcontrol *ctl,
@@ -400,7 +469,7 @@ static int rolloff_put(struct snd_kcontrol *ctl,
400 reg &= ~AK4396_SLOW; 469 reg &= ~AK4396_SLOW;
401 changed = reg != data->ak4396_regs[0][AK4396_CONTROL_2]; 470 changed = reg != data->ak4396_regs[0][AK4396_CONTROL_2];
402 if (changed) { 471 if (changed) {
403 for (i = 0; i < 4; ++i) 472 for (i = 0; i < data->dacs; ++i)
404 ak4396_write(chip, i, AK4396_CONTROL_2, reg); 473 ak4396_write(chip, i, AK4396_CONTROL_2, reg);
405 } 474 }
406 mutex_unlock(&chip->mutex); 475 mutex_unlock(&chip->mutex);
@@ -421,13 +490,7 @@ static int hpf_info(struct snd_kcontrol *ctl, struct snd_ctl_elem_info *info)
421 "None", "High-pass Filter" 490 "None", "High-pass Filter"
422 }; 491 };
423 492
424 info->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; 493 return snd_ctl_enum_info(info, 1, 2, names);
425 info->count = 1;
426 info->value.enumerated.items = 2;
427 if (info->value.enumerated.item >= 2)
428 info->value.enumerated.item = 1;
429 strcpy(info->value.enumerated.name, names[info->value.enumerated.item]);
430 return 0;
431} 494}
432 495
433static int hpf_get(struct snd_kcontrol *ctl, struct snd_ctl_elem_value *value) 496static int hpf_get(struct snd_kcontrol *ctl, struct snd_ctl_elem_value *value)
@@ -466,6 +529,100 @@ static const struct snd_kcontrol_new hpf_control = {
466 .put = hpf_put, 529 .put = hpf_put,
467}; 530};
468 531
532static int meridian_dig_source_info(struct snd_kcontrol *ctl,
533 struct snd_ctl_elem_info *info)
534{
535 static const char *const names[2] = { "On-board", "Extension" };
536
537 return snd_ctl_enum_info(info, 1, 2, names);
538}
539
540static int claro_dig_source_info(struct snd_kcontrol *ctl,
541 struct snd_ctl_elem_info *info)
542{
543 static const char *const names[2] = { "Optical", "Coaxial" };
544
545 return snd_ctl_enum_info(info, 1, 2, names);
546}
547
548static int meridian_dig_source_get(struct snd_kcontrol *ctl,
549 struct snd_ctl_elem_value *value)
550{
551 struct oxygen *chip = ctl->private_data;
552
553 value->value.enumerated.item[0] =
554 !!(oxygen_read16(chip, OXYGEN_GPIO_DATA) &
555 GPIO_MERIDIAN_DIG_EXT);
556 return 0;
557}
558
559static int claro_dig_source_get(struct snd_kcontrol *ctl,
560 struct snd_ctl_elem_value *value)
561{
562 struct oxygen *chip = ctl->private_data;
563
564 value->value.enumerated.item[0] =
565 !!(oxygen_read16(chip, OXYGEN_GPIO_DATA) &
566 GPIO_CLARO_DIG_COAX);
567 return 0;
568}
569
570static int meridian_dig_source_put(struct snd_kcontrol *ctl,
571 struct snd_ctl_elem_value *value)
572{
573 struct oxygen *chip = ctl->private_data;
574 u16 old_reg, new_reg;
575 int changed;
576
577 mutex_lock(&chip->mutex);
578 old_reg = oxygen_read16(chip, OXYGEN_GPIO_DATA);
579 new_reg = old_reg & ~GPIO_MERIDIAN_DIG_MASK;
580 if (value->value.enumerated.item[0] == 0)
581 new_reg |= GPIO_MERIDIAN_DIG_BOARD;
582 else
583 new_reg |= GPIO_MERIDIAN_DIG_EXT;
584 changed = new_reg != old_reg;
585 if (changed)
586 oxygen_write16(chip, OXYGEN_GPIO_DATA, new_reg);
587 mutex_unlock(&chip->mutex);
588 return changed;
589}
590
591static int claro_dig_source_put(struct snd_kcontrol *ctl,
592 struct snd_ctl_elem_value *value)
593{
594 struct oxygen *chip = ctl->private_data;
595 u16 old_reg, new_reg;
596 int changed;
597
598 mutex_lock(&chip->mutex);
599 old_reg = oxygen_read16(chip, OXYGEN_GPIO_DATA);
600 new_reg = old_reg & ~GPIO_CLARO_DIG_COAX;
601 if (value->value.enumerated.item[0])
602 new_reg |= GPIO_CLARO_DIG_COAX;
603 changed = new_reg != old_reg;
604 if (changed)
605 oxygen_write16(chip, OXYGEN_GPIO_DATA, new_reg);
606 mutex_unlock(&chip->mutex);
607 return changed;
608}
609
610static const struct snd_kcontrol_new meridian_dig_source_control = {
611 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
612 .name = "IEC958 Source Capture Enum",
613 .info = meridian_dig_source_info,
614 .get = meridian_dig_source_get,
615 .put = meridian_dig_source_put,
616};
617
618static const struct snd_kcontrol_new claro_dig_source_control = {
619 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
620 .name = "IEC958 Source Capture Enum",
621 .info = claro_dig_source_info,
622 .get = claro_dig_source_get,
623 .put = claro_dig_source_put,
624};
625
469static int generic_mixer_init(struct oxygen *chip) 626static int generic_mixer_init(struct oxygen *chip)
470{ 627{
471 return snd_ctl_add(chip->card, snd_ctl_new1(&rolloff_control, chip)); 628 return snd_ctl_add(chip->card, snd_ctl_new1(&rolloff_control, chip));
@@ -484,6 +641,81 @@ static int generic_wm8785_mixer_init(struct oxygen *chip)
484 return 0; 641 return 0;
485} 642}
486 643
644static int meridian_mixer_init(struct oxygen *chip)
645{
646 int err;
647
648 err = generic_mixer_init(chip);
649 if (err < 0)
650 return err;
651 err = snd_ctl_add(chip->card,
652 snd_ctl_new1(&meridian_dig_source_control, chip));
653 if (err < 0)
654 return err;
655 return 0;
656}
657
658static int claro_mixer_init(struct oxygen *chip)
659{
660 int err;
661
662 err = generic_wm8785_mixer_init(chip);
663 if (err < 0)
664 return err;
665 err = snd_ctl_add(chip->card,
666 snd_ctl_new1(&claro_dig_source_control, chip));
667 if (err < 0)
668 return err;
669 return 0;
670}
671
672static int claro_halo_mixer_init(struct oxygen *chip)
673{
674 int err;
675
676 err = generic_mixer_init(chip);
677 if (err < 0)
678 return err;
679 err = snd_ctl_add(chip->card,
680 snd_ctl_new1(&claro_dig_source_control, chip));
681 if (err < 0)
682 return err;
683 return 0;
684}
685
686static void dump_ak4396_registers(struct oxygen *chip,
687 struct snd_info_buffer *buffer)
688{
689 struct generic_data *data = chip->model_data;
690 unsigned int dac, i;
691
692 for (dac = 0; dac < data->dacs; ++dac) {
693 snd_iprintf(buffer, "\nAK4396 %u:", dac + 1);
694 for (i = 0; i < 5; ++i)
695 snd_iprintf(buffer, " %02x", data->ak4396_regs[dac][i]);
696 }
697 snd_iprintf(buffer, "\n");
698}
699
700static void dump_wm8785_registers(struct oxygen *chip,
701 struct snd_info_buffer *buffer)
702{
703 struct generic_data *data = chip->model_data;
704 unsigned int i;
705
706 snd_iprintf(buffer, "\nWM8785:");
707 for (i = 0; i < 3; ++i)
708 snd_iprintf(buffer, " %03x", data->wm8785_regs[i]);
709 snd_iprintf(buffer, "\n");
710}
711
712static void dump_oxygen_registers(struct oxygen *chip,
713 struct snd_info_buffer *buffer)
714{
715 dump_ak4396_registers(chip, buffer);
716 dump_wm8785_registers(chip, buffer);
717}
718
487static const DECLARE_TLV_DB_LINEAR(ak4396_db_scale, TLV_DB_GAIN_MUTE, 0); 719static const DECLARE_TLV_DB_LINEAR(ak4396_db_scale, TLV_DB_GAIN_MUTE, 0);
488 720
489static const struct oxygen_model model_generic = { 721static const struct oxygen_model model_generic = {
@@ -494,11 +726,11 @@ static const struct oxygen_model model_generic = {
494 .mixer_init = generic_wm8785_mixer_init, 726 .mixer_init = generic_wm8785_mixer_init,
495 .cleanup = generic_cleanup, 727 .cleanup = generic_cleanup,
496 .resume = generic_resume, 728 .resume = generic_resume,
497 .get_i2s_mclk = oxygen_default_i2s_mclk,
498 .set_dac_params = set_ak4396_params, 729 .set_dac_params = set_ak4396_params,
499 .set_adc_params = set_wm8785_params, 730 .set_adc_params = set_wm8785_params,
500 .update_dac_volume = update_ak4396_volume, 731 .update_dac_volume = update_ak4396_volume,
501 .update_dac_mute = update_ak4396_mute, 732 .update_dac_mute = update_ak4396_mute,
733 .dump_registers = dump_oxygen_registers,
502 .dac_tlv = ak4396_db_scale, 734 .dac_tlv = ak4396_db_scale,
503 .model_data_size = sizeof(struct generic_data), 735 .model_data_size = sizeof(struct generic_data),
504 .device_config = PLAYBACK_0_TO_I2S | 736 .device_config = PLAYBACK_0_TO_I2S |
@@ -508,11 +740,14 @@ static const struct oxygen_model model_generic = {
508 CAPTURE_1_FROM_SPDIF | 740 CAPTURE_1_FROM_SPDIF |
509 CAPTURE_2_FROM_AC97_1 | 741 CAPTURE_2_FROM_AC97_1 |
510 AC97_CD_INPUT, 742 AC97_CD_INPUT,
511 .dac_channels = 8, 743 .dac_channels_pcm = 8,
744 .dac_channels_mixer = 8,
512 .dac_volume_min = 0, 745 .dac_volume_min = 0,
513 .dac_volume_max = 255, 746 .dac_volume_max = 255,
514 .function_flags = OXYGEN_FUNCTION_SPI | 747 .function_flags = OXYGEN_FUNCTION_SPI |
515 OXYGEN_FUNCTION_ENABLE_SPI_4_5, 748 OXYGEN_FUNCTION_ENABLE_SPI_4_5,
749 .dac_mclks = OXYGEN_MCLKS(256, 128, 128),
750 .adc_mclks = OXYGEN_MCLKS(256, 256, 128),
516 .dac_i2s_format = OXYGEN_I2S_FORMAT_LJUST, 751 .dac_i2s_format = OXYGEN_I2S_FORMAT_LJUST,
517 .adc_i2s_format = OXYGEN_I2S_FORMAT_LJUST, 752 .adc_i2s_format = OXYGEN_I2S_FORMAT_LJUST,
518}; 753};
@@ -520,42 +755,87 @@ static const struct oxygen_model model_generic = {
520static int __devinit get_oxygen_model(struct oxygen *chip, 755static int __devinit get_oxygen_model(struct oxygen *chip,
521 const struct pci_device_id *id) 756 const struct pci_device_id *id)
522{ 757{
758 static const char *const names[] = {
759 [MODEL_MERIDIAN] = "AuzenTech X-Meridian",
760 [MODEL_MERIDIAN_2G] = "AuzenTech X-Meridian 2G",
761 [MODEL_CLARO] = "HT-Omega Claro",
762 [MODEL_CLARO_HALO] = "HT-Omega Claro halo",
763 [MODEL_FANTASIA] = "TempoTec HiFier Fantasia",
764 [MODEL_SERENADE] = "TempoTec HiFier Serenade",
765 [MODEL_HG2PCI] = "CMI8787-HG2PCI",
766 };
767
523 chip->model = model_generic; 768 chip->model = model_generic;
524 switch (id->driver_data) { 769 switch (id->driver_data) {
525 case MODEL_MERIDIAN: 770 case MODEL_MERIDIAN:
771 case MODEL_MERIDIAN_2G:
526 chip->model.init = meridian_init; 772 chip->model.init = meridian_init;
527 chip->model.mixer_init = generic_mixer_init; 773 chip->model.mixer_init = meridian_mixer_init;
528 chip->model.resume = meridian_resume; 774 chip->model.resume = meridian_resume;
529 chip->model.set_adc_params = set_ak5385_params; 775 chip->model.set_adc_params = set_ak5385_params;
776 chip->model.dump_registers = dump_ak4396_registers;
530 chip->model.device_config = PLAYBACK_0_TO_I2S | 777 chip->model.device_config = PLAYBACK_0_TO_I2S |
531 PLAYBACK_1_TO_SPDIF | 778 PLAYBACK_1_TO_SPDIF |
532 CAPTURE_0_FROM_I2S_2 | 779 CAPTURE_0_FROM_I2S_2 |
533 CAPTURE_1_FROM_SPDIF; 780 CAPTURE_1_FROM_SPDIF;
781 if (id->driver_data == MODEL_MERIDIAN)
782 chip->model.device_config |= AC97_CD_INPUT;
534 break; 783 break;
535 case MODEL_CLARO: 784 case MODEL_CLARO:
536 chip->model.init = claro_init; 785 chip->model.init = claro_init;
786 chip->model.mixer_init = claro_mixer_init;
537 chip->model.cleanup = claro_cleanup; 787 chip->model.cleanup = claro_cleanup;
538 chip->model.suspend = claro_suspend; 788 chip->model.suspend = claro_suspend;
539 chip->model.resume = claro_resume; 789 chip->model.resume = claro_resume;
540 break; 790 break;
541 case MODEL_CLARO_HALO: 791 case MODEL_CLARO_HALO:
542 chip->model.init = claro_halo_init; 792 chip->model.init = claro_halo_init;
543 chip->model.mixer_init = generic_mixer_init; 793 chip->model.mixer_init = claro_halo_mixer_init;
544 chip->model.cleanup = claro_cleanup; 794 chip->model.cleanup = claro_cleanup;
545 chip->model.suspend = claro_suspend; 795 chip->model.suspend = claro_suspend;
546 chip->model.resume = claro_resume; 796 chip->model.resume = claro_resume;
547 chip->model.set_adc_params = set_ak5385_params; 797 chip->model.set_adc_params = set_ak5385_params;
798 chip->model.dump_registers = dump_ak4396_registers;
548 chip->model.device_config = PLAYBACK_0_TO_I2S | 799 chip->model.device_config = PLAYBACK_0_TO_I2S |
549 PLAYBACK_1_TO_SPDIF | 800 PLAYBACK_1_TO_SPDIF |
550 CAPTURE_0_FROM_I2S_2 | 801 CAPTURE_0_FROM_I2S_2 |
551 CAPTURE_1_FROM_SPDIF; 802 CAPTURE_1_FROM_SPDIF;
552 break; 803 break;
804 case MODEL_FANTASIA:
805 case MODEL_SERENADE:
806 case MODEL_2CH_OUTPUT:
807 case MODEL_HG2PCI:
808 chip->model.shortname = "C-Media CMI8787";
809 chip->model.chip = "CMI8787";
810 if (id->driver_data == MODEL_FANTASIA)
811 chip->model.init = fantasia_init;
812 else
813 chip->model.init = stereo_output_init;
814 chip->model.resume = stereo_resume;
815 chip->model.mixer_init = generic_mixer_init;
816 chip->model.set_adc_params = set_no_params;
817 chip->model.dump_registers = dump_ak4396_registers;
818 chip->model.device_config = PLAYBACK_0_TO_I2S |
819 PLAYBACK_1_TO_SPDIF;
820 if (id->driver_data == MODEL_FANTASIA) {
821 chip->model.device_config |= CAPTURE_0_FROM_I2S_1;
822 chip->model.adc_mclks = OXYGEN_MCLKS(256, 128, 128);
823 }
824 chip->model.dac_channels_pcm = 2;
825 chip->model.dac_channels_mixer = 2;
826 break;
827 case MODEL_XONAR_DG:
828 chip->model = model_xonar_dg;
829 break;
553 } 830 }
554 if (id->driver_data == MODEL_MERIDIAN || 831 if (id->driver_data == MODEL_MERIDIAN ||
832 id->driver_data == MODEL_MERIDIAN_2G ||
555 id->driver_data == MODEL_CLARO_HALO) { 833 id->driver_data == MODEL_CLARO_HALO) {
556 chip->model.misc_flags = OXYGEN_MISC_MIDI; 834 chip->model.misc_flags = OXYGEN_MISC_MIDI;
557 chip->model.device_config |= MIDI_OUTPUT | MIDI_INPUT; 835 chip->model.device_config |= MIDI_OUTPUT | MIDI_INPUT;
558 } 836 }
837 if (id->driver_data < ARRAY_SIZE(names) && names[id->driver_data])
838 chip->model.shortname = names[id->driver_data];
559 return 0; 839 return 0;
560} 840}
561 841
diff --git a/sound/pci/oxygen/oxygen.h b/sound/pci/oxygen/oxygen.h
index 7d5222caa0a9..c2ae63d17cd2 100644
--- a/sound/pci/oxygen/oxygen.h
+++ b/sound/pci/oxygen/oxygen.h
@@ -16,6 +16,10 @@
16#define PCM_AC97 5 16#define PCM_AC97 5
17#define PCM_COUNT 6 17#define PCM_COUNT 6
18 18
19#define OXYGEN_MCLKS(f_single, f_double, f_quad) ((MCLK_##f_single << 0) | \
20 (MCLK_##f_double << 2) | \
21 (MCLK_##f_quad << 4))
22
19#define OXYGEN_IO_SIZE 0x100 23#define OXYGEN_IO_SIZE 0x100
20 24
21#define OXYGEN_EEPROM_ID 0x434d /* "CM" */ 25#define OXYGEN_EEPROM_ID 0x434d /* "CM" */
@@ -35,6 +39,7 @@
35#define MIDI_OUTPUT 0x0800 39#define MIDI_OUTPUT 0x0800
36#define MIDI_INPUT 0x1000 40#define MIDI_INPUT 0x1000
37#define AC97_CD_INPUT 0x2000 41#define AC97_CD_INPUT 0x2000
42#define AC97_FMIC_SWITCH 0x4000
38 43
39enum { 44enum {
40 CONTROL_SPDIF_PCM, 45 CONTROL_SPDIF_PCM,
@@ -65,6 +70,7 @@ struct snd_pcm_hardware;
65struct snd_pcm_hw_params; 70struct snd_pcm_hw_params;
66struct snd_kcontrol_new; 71struct snd_kcontrol_new;
67struct snd_rawmidi; 72struct snd_rawmidi;
73struct snd_info_buffer;
68struct oxygen; 74struct oxygen;
69 75
70struct oxygen_model { 76struct oxygen_model {
@@ -79,8 +85,6 @@ struct oxygen_model {
79 void (*resume)(struct oxygen *chip); 85 void (*resume)(struct oxygen *chip);
80 void (*pcm_hardware_filter)(unsigned int channel, 86 void (*pcm_hardware_filter)(unsigned int channel,
81 struct snd_pcm_hardware *hardware); 87 struct snd_pcm_hardware *hardware);
82 unsigned int (*get_i2s_mclk)(struct oxygen *chip, unsigned int channel,
83 struct snd_pcm_hw_params *hw_params);
84 void (*set_dac_params)(struct oxygen *chip, 88 void (*set_dac_params)(struct oxygen *chip,
85 struct snd_pcm_hw_params *params); 89 struct snd_pcm_hw_params *params);
86 void (*set_adc_params)(struct oxygen *chip, 90 void (*set_adc_params)(struct oxygen *chip,
@@ -92,15 +96,19 @@ struct oxygen_model {
92 void (*uart_input)(struct oxygen *chip); 96 void (*uart_input)(struct oxygen *chip);
93 void (*ac97_switch)(struct oxygen *chip, 97 void (*ac97_switch)(struct oxygen *chip,
94 unsigned int reg, unsigned int mute); 98 unsigned int reg, unsigned int mute);
99 void (*dump_registers)(struct oxygen *chip,
100 struct snd_info_buffer *buffer);
95 const unsigned int *dac_tlv; 101 const unsigned int *dac_tlv;
96 unsigned long private_data;
97 size_t model_data_size; 102 size_t model_data_size;
98 unsigned int device_config; 103 unsigned int device_config;
99 u8 dac_channels; 104 u8 dac_channels_pcm;
105 u8 dac_channels_mixer;
100 u8 dac_volume_min; 106 u8 dac_volume_min;
101 u8 dac_volume_max; 107 u8 dac_volume_max;
102 u8 misc_flags; 108 u8 misc_flags;
103 u8 function_flags; 109 u8 function_flags;
110 u8 dac_mclks;
111 u8 adc_mclks;
104 u16 dac_i2s_format; 112 u16 dac_i2s_format;
105 u16 adc_i2s_format; 113 u16 adc_i2s_format;
106}; 114};
@@ -121,7 +129,6 @@ struct oxygen {
121 u8 pcm_running; 129 u8 pcm_running;
122 u8 dac_routing; 130 u8 dac_routing;
123 u8 spdif_playback_enable; 131 u8 spdif_playback_enable;
124 u8 revision;
125 u8 has_ac97_0; 132 u8 has_ac97_0;
126 u8 has_ac97_1; 133 u8 has_ac97_1;
127 u32 spdif_bits; 134 u32 spdif_bits;
@@ -167,8 +174,6 @@ void oxygen_update_spdif_source(struct oxygen *chip);
167/* oxygen_pcm.c */ 174/* oxygen_pcm.c */
168 175
169int oxygen_pcm_init(struct oxygen *chip); 176int oxygen_pcm_init(struct oxygen *chip);
170unsigned int oxygen_default_i2s_mclk(struct oxygen *chip, unsigned int channel,
171 struct snd_pcm_hw_params *hw_params);
172 177
173/* oxygen_io.c */ 178/* oxygen_io.c */
174 179
diff --git a/sound/pci/oxygen/oxygen_io.c b/sound/pci/oxygen/oxygen_io.c
index 09b2b2a36df5..f5164b1e1c80 100644
--- a/sound/pci/oxygen/oxygen_io.c
+++ b/sound/pci/oxygen/oxygen_io.c
@@ -197,11 +197,11 @@ void oxygen_write_spi(struct oxygen *chip, u8 control, unsigned int data)
197{ 197{
198 unsigned int count; 198 unsigned int count;
199 199
200 /* should not need more than 7.68 us (24 * 320 ns) */ 200 /* should not need more than 30.72 us (24 * 1.28 us) */
201 count = 10; 201 count = 10;
202 while ((oxygen_read8(chip, OXYGEN_SPI_CONTROL) & OXYGEN_SPI_BUSY) 202 while ((oxygen_read8(chip, OXYGEN_SPI_CONTROL) & OXYGEN_SPI_BUSY)
203 && count > 0) { 203 && count > 0) {
204 udelay(1); 204 udelay(4);
205 --count; 205 --count;
206 } 206 }
207 207
diff --git a/sound/pci/oxygen/oxygen_lib.c b/sound/pci/oxygen/oxygen_lib.c
index e5ebe56fb0c5..70b739816fcc 100644
--- a/sound/pci/oxygen/oxygen_lib.c
+++ b/sound/pci/oxygen/oxygen_lib.c
@@ -202,7 +202,13 @@ static void oxygen_proc_read(struct snd_info_entry *entry,
202 struct oxygen *chip = entry->private_data; 202 struct oxygen *chip = entry->private_data;
203 int i, j; 203 int i, j;
204 204
205 snd_iprintf(buffer, "CMI8788\n\n"); 205 switch (oxygen_read8(chip, OXYGEN_REVISION) & OXYGEN_PACKAGE_ID_MASK) {
206 case OXYGEN_PACKAGE_ID_8786: i = '6'; break;
207 case OXYGEN_PACKAGE_ID_8787: i = '7'; break;
208 case OXYGEN_PACKAGE_ID_8788: i = '8'; break;
209 default: i = '?'; break;
210 }
211 snd_iprintf(buffer, "CMI878%c:\n", i);
206 for (i = 0; i < OXYGEN_IO_SIZE; i += 0x10) { 212 for (i = 0; i < OXYGEN_IO_SIZE; i += 0x10) {
207 snd_iprintf(buffer, "%02x:", i); 213 snd_iprintf(buffer, "%02x:", i);
208 for (j = 0; j < 0x10; ++j) 214 for (j = 0; j < 0x10; ++j)
@@ -212,7 +218,7 @@ static void oxygen_proc_read(struct snd_info_entry *entry,
212 if (mutex_lock_interruptible(&chip->mutex) < 0) 218 if (mutex_lock_interruptible(&chip->mutex) < 0)
213 return; 219 return;
214 if (chip->has_ac97_0) { 220 if (chip->has_ac97_0) {
215 snd_iprintf(buffer, "\nAC97\n"); 221 snd_iprintf(buffer, "\nAC97:\n");
216 for (i = 0; i < 0x80; i += 0x10) { 222 for (i = 0; i < 0x80; i += 0x10) {
217 snd_iprintf(buffer, "%02x:", i); 223 snd_iprintf(buffer, "%02x:", i);
218 for (j = 0; j < 0x10; j += 2) 224 for (j = 0; j < 0x10; j += 2)
@@ -222,7 +228,7 @@ static void oxygen_proc_read(struct snd_info_entry *entry,
222 } 228 }
223 } 229 }
224 if (chip->has_ac97_1) { 230 if (chip->has_ac97_1) {
225 snd_iprintf(buffer, "\nAC97 2\n"); 231 snd_iprintf(buffer, "\nAC97 2:\n");
226 for (i = 0; i < 0x80; i += 0x10) { 232 for (i = 0; i < 0x80; i += 0x10) {
227 snd_iprintf(buffer, "%02x:", i); 233 snd_iprintf(buffer, "%02x:", i);
228 for (j = 0; j < 0x10; j += 2) 234 for (j = 0; j < 0x10; j += 2)
@@ -232,13 +238,15 @@ static void oxygen_proc_read(struct snd_info_entry *entry,
232 } 238 }
233 } 239 }
234 mutex_unlock(&chip->mutex); 240 mutex_unlock(&chip->mutex);
241 if (chip->model.dump_registers)
242 chip->model.dump_registers(chip, buffer);
235} 243}
236 244
237static void oxygen_proc_init(struct oxygen *chip) 245static void oxygen_proc_init(struct oxygen *chip)
238{ 246{
239 struct snd_info_entry *entry; 247 struct snd_info_entry *entry;
240 248
241 if (!snd_card_proc_new(chip->card, "cmi8788", &entry)) 249 if (!snd_card_proc_new(chip->card, "oxygen", &entry))
242 snd_info_set_text_ops(entry, chip, oxygen_proc_read); 250 snd_info_set_text_ops(entry, chip, oxygen_proc_read);
243} 251}
244#else 252#else
@@ -262,7 +270,7 @@ oxygen_search_pci_id(struct oxygen *chip, const struct pci_device_id ids[])
262 */ 270 */
263 subdevice = oxygen_read_eeprom(chip, 2); 271 subdevice = oxygen_read_eeprom(chip, 2);
264 /* use default ID if EEPROM is missing */ 272 /* use default ID if EEPROM is missing */
265 if (subdevice == 0xffff) 273 if (subdevice == 0xffff && oxygen_read_eeprom(chip, 1) == 0xffff)
266 subdevice = 0x8788; 274 subdevice = 0x8788;
267 /* 275 /*
268 * We use only the subsystem device ID for searching because it is 276 * We use only the subsystem device ID for searching because it is
@@ -364,12 +372,7 @@ static void oxygen_init(struct oxygen *chip)
364 (IEC958_AES1_CON_PCM_CODER << OXYGEN_SPDIF_CATEGORY_SHIFT); 372 (IEC958_AES1_CON_PCM_CODER << OXYGEN_SPDIF_CATEGORY_SHIFT);
365 chip->spdif_pcm_bits = chip->spdif_bits; 373 chip->spdif_pcm_bits = chip->spdif_bits;
366 374
367 if (oxygen_read8(chip, OXYGEN_REVISION) & OXYGEN_REVISION_2) 375 if (!(oxygen_read8(chip, OXYGEN_REVISION) & OXYGEN_REVISION_2))
368 chip->revision = 2;
369 else
370 chip->revision = 1;
371
372 if (chip->revision == 1)
373 oxygen_set_bits8(chip, OXYGEN_MISC, 376 oxygen_set_bits8(chip, OXYGEN_MISC,
374 OXYGEN_MISC_PCI_MEM_W_1_CLOCK); 377 OXYGEN_MISC_PCI_MEM_W_1_CLOCK);
375 378
@@ -406,28 +409,40 @@ static void oxygen_init(struct oxygen *chip)
406 (OXYGEN_FORMAT_16 << OXYGEN_MULTICH_FORMAT_SHIFT)); 409 (OXYGEN_FORMAT_16 << OXYGEN_MULTICH_FORMAT_SHIFT));
407 oxygen_write8(chip, OXYGEN_REC_CHANNELS, OXYGEN_REC_CHANNELS_2_2_2); 410 oxygen_write8(chip, OXYGEN_REC_CHANNELS, OXYGEN_REC_CHANNELS_2_2_2);
408 oxygen_write16(chip, OXYGEN_I2S_MULTICH_FORMAT, 411 oxygen_write16(chip, OXYGEN_I2S_MULTICH_FORMAT,
409 OXYGEN_RATE_48000 | chip->model.dac_i2s_format | 412 OXYGEN_RATE_48000 |
410 OXYGEN_I2S_MCLK_256 | OXYGEN_I2S_BITS_16 | 413 chip->model.dac_i2s_format |
411 OXYGEN_I2S_MASTER | OXYGEN_I2S_BCLK_64); 414 OXYGEN_I2S_MCLK(chip->model.dac_mclks) |
415 OXYGEN_I2S_BITS_16 |
416 OXYGEN_I2S_MASTER |
417 OXYGEN_I2S_BCLK_64);
412 if (chip->model.device_config & CAPTURE_0_FROM_I2S_1) 418 if (chip->model.device_config & CAPTURE_0_FROM_I2S_1)
413 oxygen_write16(chip, OXYGEN_I2S_A_FORMAT, 419 oxygen_write16(chip, OXYGEN_I2S_A_FORMAT,
414 OXYGEN_RATE_48000 | chip->model.adc_i2s_format | 420 OXYGEN_RATE_48000 |
415 OXYGEN_I2S_MCLK_256 | OXYGEN_I2S_BITS_16 | 421 chip->model.adc_i2s_format |
416 OXYGEN_I2S_MASTER | OXYGEN_I2S_BCLK_64); 422 OXYGEN_I2S_MCLK(chip->model.adc_mclks) |
423 OXYGEN_I2S_BITS_16 |
424 OXYGEN_I2S_MASTER |
425 OXYGEN_I2S_BCLK_64);
417 else 426 else
418 oxygen_write16(chip, OXYGEN_I2S_A_FORMAT, 427 oxygen_write16(chip, OXYGEN_I2S_A_FORMAT,
419 OXYGEN_I2S_MASTER | OXYGEN_I2S_MUTE_MCLK); 428 OXYGEN_I2S_MASTER |
429 OXYGEN_I2S_MUTE_MCLK);
420 if (chip->model.device_config & (CAPTURE_0_FROM_I2S_2 | 430 if (chip->model.device_config & (CAPTURE_0_FROM_I2S_2 |
421 CAPTURE_2_FROM_I2S_2)) 431 CAPTURE_2_FROM_I2S_2))
422 oxygen_write16(chip, OXYGEN_I2S_B_FORMAT, 432 oxygen_write16(chip, OXYGEN_I2S_B_FORMAT,
423 OXYGEN_RATE_48000 | chip->model.adc_i2s_format | 433 OXYGEN_RATE_48000 |
424 OXYGEN_I2S_MCLK_256 | OXYGEN_I2S_BITS_16 | 434 chip->model.adc_i2s_format |
425 OXYGEN_I2S_MASTER | OXYGEN_I2S_BCLK_64); 435 OXYGEN_I2S_MCLK(chip->model.adc_mclks) |
436 OXYGEN_I2S_BITS_16 |
437 OXYGEN_I2S_MASTER |
438 OXYGEN_I2S_BCLK_64);
426 else 439 else
427 oxygen_write16(chip, OXYGEN_I2S_B_FORMAT, 440 oxygen_write16(chip, OXYGEN_I2S_B_FORMAT,
428 OXYGEN_I2S_MASTER | OXYGEN_I2S_MUTE_MCLK); 441 OXYGEN_I2S_MASTER |
442 OXYGEN_I2S_MUTE_MCLK);
429 oxygen_write16(chip, OXYGEN_I2S_C_FORMAT, 443 oxygen_write16(chip, OXYGEN_I2S_C_FORMAT,
430 OXYGEN_I2S_MASTER | OXYGEN_I2S_MUTE_MCLK); 444 OXYGEN_I2S_MASTER |
445 OXYGEN_I2S_MUTE_MCLK);
431 oxygen_clear_bits32(chip, OXYGEN_SPDIF_CONTROL, 446 oxygen_clear_bits32(chip, OXYGEN_SPDIF_CONTROL,
432 OXYGEN_SPDIF_OUT_ENABLE | 447 OXYGEN_SPDIF_OUT_ENABLE |
433 OXYGEN_SPDIF_LOOPBACK); 448 OXYGEN_SPDIF_LOOPBACK);
@@ -557,7 +572,8 @@ static void oxygen_card_free(struct snd_card *card)
557 oxygen_shutdown(chip); 572 oxygen_shutdown(chip);
558 if (chip->irq >= 0) 573 if (chip->irq >= 0)
559 free_irq(chip->irq, chip); 574 free_irq(chip->irq, chip);
560 flush_scheduled_work(); 575 flush_work_sync(&chip->spdif_input_bits_work);
576 flush_work_sync(&chip->gpio_work);
561 chip->model.cleanup(chip); 577 chip->model.cleanup(chip);
562 kfree(chip->model_data); 578 kfree(chip->model_data);
563 mutex_destroy(&chip->mutex); 579 mutex_destroy(&chip->mutex);
@@ -648,8 +664,8 @@ int oxygen_pci_probe(struct pci_dev *pci, int index, char *id,
648 664
649 strcpy(card->driver, chip->model.chip); 665 strcpy(card->driver, chip->model.chip);
650 strcpy(card->shortname, chip->model.shortname); 666 strcpy(card->shortname, chip->model.shortname);
651 sprintf(card->longname, "%s (rev %u) at %#lx, irq %i", 667 sprintf(card->longname, "%s at %#lx, irq %i",
652 chip->model.longname, chip->revision, chip->addr, chip->irq); 668 chip->model.longname, chip->addr, chip->irq);
653 strcpy(card->mixername, chip->model.chip); 669 strcpy(card->mixername, chip->model.chip);
654 snd_component_add(card, chip->model.chip); 670 snd_component_add(card, chip->model.chip);
655 671
@@ -733,7 +749,8 @@ int oxygen_pci_suspend(struct pci_dev *pci, pm_message_t state)
733 spin_unlock_irq(&chip->reg_lock); 749 spin_unlock_irq(&chip->reg_lock);
734 750
735 synchronize_irq(chip->irq); 751 synchronize_irq(chip->irq);
736 flush_scheduled_work(); 752 flush_work_sync(&chip->spdif_input_bits_work);
753 flush_work_sync(&chip->gpio_work);
737 chip->interrupt_mask = saved_interrupt_mask; 754 chip->interrupt_mask = saved_interrupt_mask;
738 755
739 pci_disable_device(pci); 756 pci_disable_device(pci);
diff --git a/sound/pci/oxygen/oxygen_mixer.c b/sound/pci/oxygen/oxygen_mixer.c
index 2849b36f5f7e..9bff14d5895d 100644
--- a/sound/pci/oxygen/oxygen_mixer.c
+++ b/sound/pci/oxygen/oxygen_mixer.c
@@ -31,7 +31,7 @@ static int dac_volume_info(struct snd_kcontrol *ctl,
31 struct oxygen *chip = ctl->private_data; 31 struct oxygen *chip = ctl->private_data;
32 32
33 info->type = SNDRV_CTL_ELEM_TYPE_INTEGER; 33 info->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
34 info->count = chip->model.dac_channels; 34 info->count = chip->model.dac_channels_mixer;
35 info->value.integer.min = chip->model.dac_volume_min; 35 info->value.integer.min = chip->model.dac_volume_min;
36 info->value.integer.max = chip->model.dac_volume_max; 36 info->value.integer.max = chip->model.dac_volume_max;
37 return 0; 37 return 0;
@@ -44,7 +44,7 @@ static int dac_volume_get(struct snd_kcontrol *ctl,
44 unsigned int i; 44 unsigned int i;
45 45
46 mutex_lock(&chip->mutex); 46 mutex_lock(&chip->mutex);
47 for (i = 0; i < chip->model.dac_channels; ++i) 47 for (i = 0; i < chip->model.dac_channels_mixer; ++i)
48 value->value.integer.value[i] = chip->dac_volume[i]; 48 value->value.integer.value[i] = chip->dac_volume[i];
49 mutex_unlock(&chip->mutex); 49 mutex_unlock(&chip->mutex);
50 return 0; 50 return 0;
@@ -59,7 +59,7 @@ static int dac_volume_put(struct snd_kcontrol *ctl,
59 59
60 changed = 0; 60 changed = 0;
61 mutex_lock(&chip->mutex); 61 mutex_lock(&chip->mutex);
62 for (i = 0; i < chip->model.dac_channels; ++i) 62 for (i = 0; i < chip->model.dac_channels_mixer; ++i)
63 if (value->value.integer.value[i] != chip->dac_volume[i]) { 63 if (value->value.integer.value[i] != chip->dac_volume[i]) {
64 chip->dac_volume[i] = value->value.integer.value[i]; 64 chip->dac_volume[i] = value->value.integer.value[i];
65 changed = 1; 65 changed = 1;
@@ -97,6 +97,16 @@ static int dac_mute_put(struct snd_kcontrol *ctl,
97 return changed; 97 return changed;
98} 98}
99 99
100static unsigned int upmix_item_count(struct oxygen *chip)
101{
102 if (chip->model.dac_channels_pcm < 8)
103 return 2;
104 else if (chip->model.update_center_lfe_mix)
105 return 5;
106 else
107 return 3;
108}
109
100static int upmix_info(struct snd_kcontrol *ctl, struct snd_ctl_elem_info *info) 110static int upmix_info(struct snd_kcontrol *ctl, struct snd_ctl_elem_info *info)
101{ 111{
102 static const char *const names[5] = { 112 static const char *const names[5] = {
@@ -107,15 +117,9 @@ static int upmix_info(struct snd_kcontrol *ctl, struct snd_ctl_elem_info *info)
107 "Front+Surround+Center/LFE+Back", 117 "Front+Surround+Center/LFE+Back",
108 }; 118 };
109 struct oxygen *chip = ctl->private_data; 119 struct oxygen *chip = ctl->private_data;
110 unsigned int count = chip->model.update_center_lfe_mix ? 5 : 3; 120 unsigned int count = upmix_item_count(chip);
111 121
112 info->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; 122 return snd_ctl_enum_info(info, 1, count, names);
113 info->count = 1;
114 info->value.enumerated.items = count;
115 if (info->value.enumerated.item >= count)
116 info->value.enumerated.item = count - 1;
117 strcpy(info->value.enumerated.name, names[info->value.enumerated.item]);
118 return 0;
119} 123}
120 124
121static int upmix_get(struct snd_kcontrol *ctl, struct snd_ctl_elem_value *value) 125static int upmix_get(struct snd_kcontrol *ctl, struct snd_ctl_elem_value *value)
@@ -188,7 +192,7 @@ void oxygen_update_dac_routing(struct oxygen *chip)
188static int upmix_put(struct snd_kcontrol *ctl, struct snd_ctl_elem_value *value) 192static int upmix_put(struct snd_kcontrol *ctl, struct snd_ctl_elem_value *value)
189{ 193{
190 struct oxygen *chip = ctl->private_data; 194 struct oxygen *chip = ctl->private_data;
191 unsigned int count = chip->model.update_center_lfe_mix ? 5 : 3; 195 unsigned int count = upmix_item_count(chip);
192 int changed; 196 int changed;
193 197
194 if (value->value.enumerated.item[0] >= count) 198 if (value->value.enumerated.item[0] >= count)
@@ -430,30 +434,31 @@ static int spdif_input_default_get(struct snd_kcontrol *ctl,
430 return 0; 434 return 0;
431} 435}
432 436
433static int spdif_loopback_get(struct snd_kcontrol *ctl, 437static int spdif_bit_switch_get(struct snd_kcontrol *ctl,
434 struct snd_ctl_elem_value *value) 438 struct snd_ctl_elem_value *value)
435{ 439{
436 struct oxygen *chip = ctl->private_data; 440 struct oxygen *chip = ctl->private_data;
441 u32 bit = ctl->private_value;
437 442
438 value->value.integer.value[0] = 443 value->value.integer.value[0] =
439 !!(oxygen_read32(chip, OXYGEN_SPDIF_CONTROL) 444 !!(oxygen_read32(chip, OXYGEN_SPDIF_CONTROL) & bit);
440 & OXYGEN_SPDIF_LOOPBACK);
441 return 0; 445 return 0;
442} 446}
443 447
444static int spdif_loopback_put(struct snd_kcontrol *ctl, 448static int spdif_bit_switch_put(struct snd_kcontrol *ctl,
445 struct snd_ctl_elem_value *value) 449 struct snd_ctl_elem_value *value)
446{ 450{
447 struct oxygen *chip = ctl->private_data; 451 struct oxygen *chip = ctl->private_data;
452 u32 bit = ctl->private_value;
448 u32 oldreg, newreg; 453 u32 oldreg, newreg;
449 int changed; 454 int changed;
450 455
451 spin_lock_irq(&chip->reg_lock); 456 spin_lock_irq(&chip->reg_lock);
452 oldreg = oxygen_read32(chip, OXYGEN_SPDIF_CONTROL); 457 oldreg = oxygen_read32(chip, OXYGEN_SPDIF_CONTROL);
453 if (value->value.integer.value[0]) 458 if (value->value.integer.value[0])
454 newreg = oldreg | OXYGEN_SPDIF_LOOPBACK; 459 newreg = oldreg | bit;
455 else 460 else
456 newreg = oldreg & ~OXYGEN_SPDIF_LOOPBACK; 461 newreg = oldreg & ~bit;
457 changed = newreg != oldreg; 462 changed = newreg != oldreg;
458 if (changed) 463 if (changed)
459 oxygen_write32(chip, OXYGEN_SPDIF_CONTROL, newreg); 464 oxygen_write32(chip, OXYGEN_SPDIF_CONTROL, newreg);
@@ -644,6 +649,46 @@ static int ac97_volume_put(struct snd_kcontrol *ctl,
644 return change; 649 return change;
645} 650}
646 651
652static int mic_fmic_source_info(struct snd_kcontrol *ctl,
653 struct snd_ctl_elem_info *info)
654{
655 static const char *const names[] = { "Mic Jack", "Front Panel" };
656
657 return snd_ctl_enum_info(info, 1, 2, names);
658}
659
660static int mic_fmic_source_get(struct snd_kcontrol *ctl,
661 struct snd_ctl_elem_value *value)
662{
663 struct oxygen *chip = ctl->private_data;
664
665 mutex_lock(&chip->mutex);
666 value->value.enumerated.item[0] =
667 !!(oxygen_read_ac97(chip, 0, CM9780_JACK) & CM9780_FMIC2MIC);
668 mutex_unlock(&chip->mutex);
669 return 0;
670}
671
672static int mic_fmic_source_put(struct snd_kcontrol *ctl,
673 struct snd_ctl_elem_value *value)
674{
675 struct oxygen *chip = ctl->private_data;
676 u16 oldreg, newreg;
677 int change;
678
679 mutex_lock(&chip->mutex);
680 oldreg = oxygen_read_ac97(chip, 0, CM9780_JACK);
681 if (value->value.enumerated.item[0])
682 newreg = oldreg | CM9780_FMIC2MIC;
683 else
684 newreg = oldreg & ~CM9780_FMIC2MIC;
685 change = newreg != oldreg;
686 if (change)
687 oxygen_write_ac97(chip, 0, CM9780_JACK, newreg);
688 mutex_unlock(&chip->mutex);
689 return change;
690}
691
647static int ac97_fp_rec_volume_info(struct snd_kcontrol *ctl, 692static int ac97_fp_rec_volume_info(struct snd_kcontrol *ctl,
648 struct snd_ctl_elem_info *info) 693 struct snd_ctl_elem_info *info)
649{ 694{
@@ -791,8 +836,17 @@ static const struct snd_kcontrol_new spdif_input_controls[] = {
791 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 836 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
792 .name = SNDRV_CTL_NAME_IEC958("Loopback ", NONE, SWITCH), 837 .name = SNDRV_CTL_NAME_IEC958("Loopback ", NONE, SWITCH),
793 .info = snd_ctl_boolean_mono_info, 838 .info = snd_ctl_boolean_mono_info,
794 .get = spdif_loopback_get, 839 .get = spdif_bit_switch_get,
795 .put = spdif_loopback_put, 840 .put = spdif_bit_switch_put,
841 .private_value = OXYGEN_SPDIF_LOOPBACK,
842 },
843 {
844 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
845 .name = SNDRV_CTL_NAME_IEC958("Validity Check ",CAPTURE,SWITCH),
846 .info = snd_ctl_boolean_mono_info,
847 .get = spdif_bit_switch_get,
848 .put = spdif_bit_switch_put,
849 .private_value = OXYGEN_SPDIF_SPDVALID,
796 }, 850 },
797}; 851};
798 852
@@ -908,6 +962,13 @@ static const struct snd_kcontrol_new ac97_controls[] = {
908 AC97_VOLUME("Mic Capture Volume", 0, AC97_MIC, 0), 962 AC97_VOLUME("Mic Capture Volume", 0, AC97_MIC, 0),
909 AC97_SWITCH("Mic Capture Switch", 0, AC97_MIC, 15, 1), 963 AC97_SWITCH("Mic Capture Switch", 0, AC97_MIC, 15, 1),
910 AC97_SWITCH("Mic Boost (+20dB)", 0, AC97_MIC, 6, 0), 964 AC97_SWITCH("Mic Boost (+20dB)", 0, AC97_MIC, 6, 0),
965 {
966 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
967 .name = "Mic Source Capture Enum",
968 .info = mic_fmic_source_info,
969 .get = mic_fmic_source_get,
970 .put = mic_fmic_source_put,
971 },
911 AC97_SWITCH("Line Capture Switch", 0, AC97_LINE, 15, 1), 972 AC97_SWITCH("Line Capture Switch", 0, AC97_LINE, 15, 1),
912 AC97_VOLUME("CD Capture Volume", 0, AC97_CD, 1), 973 AC97_VOLUME("CD Capture Volume", 0, AC97_CD, 1),
913 AC97_SWITCH("CD Capture Switch", 0, AC97_CD, 15, 1), 974 AC97_SWITCH("CD Capture Switch", 0, AC97_CD, 15, 1),
@@ -970,7 +1031,10 @@ static int add_controls(struct oxygen *chip,
970 continue; 1031 continue;
971 } 1032 }
972 if (!strcmp(template.name, "Stereo Upmixing") && 1033 if (!strcmp(template.name, "Stereo Upmixing") &&
973 chip->model.dac_channels == 2) 1034 chip->model.dac_channels_pcm == 2)
1035 continue;
1036 if (!strcmp(template.name, "Mic Source Capture Enum") &&
1037 !(chip->model.device_config & AC97_FMIC_SWITCH))
974 continue; 1038 continue;
975 if (!strncmp(template.name, "CD Capture ", 11) && 1039 if (!strncmp(template.name, "CD Capture ", 11) &&
976 !(chip->model.device_config & AC97_CD_INPUT)) 1040 !(chip->model.device_config & AC97_CD_INPUT))
diff --git a/sound/pci/oxygen/oxygen_pcm.c b/sound/pci/oxygen/oxygen_pcm.c
index 814667442eb0..d5533e34ece9 100644
--- a/sound/pci/oxygen/oxygen_pcm.c
+++ b/sound/pci/oxygen/oxygen_pcm.c
@@ -39,7 +39,8 @@ static const struct snd_pcm_hardware oxygen_stereo_hardware = {
39 SNDRV_PCM_INFO_MMAP_VALID | 39 SNDRV_PCM_INFO_MMAP_VALID |
40 SNDRV_PCM_INFO_INTERLEAVED | 40 SNDRV_PCM_INFO_INTERLEAVED |
41 SNDRV_PCM_INFO_PAUSE | 41 SNDRV_PCM_INFO_PAUSE |
42 SNDRV_PCM_INFO_SYNC_START, 42 SNDRV_PCM_INFO_SYNC_START |
43 SNDRV_PCM_INFO_NO_PERIOD_WAKEUP,
43 .formats = SNDRV_PCM_FMTBIT_S16_LE | 44 .formats = SNDRV_PCM_FMTBIT_S16_LE |
44 SNDRV_PCM_FMTBIT_S32_LE, 45 SNDRV_PCM_FMTBIT_S32_LE,
45 .rates = SNDRV_PCM_RATE_32000 | 46 .rates = SNDRV_PCM_RATE_32000 |
@@ -65,7 +66,8 @@ static const struct snd_pcm_hardware oxygen_multichannel_hardware = {
65 SNDRV_PCM_INFO_MMAP_VALID | 66 SNDRV_PCM_INFO_MMAP_VALID |
66 SNDRV_PCM_INFO_INTERLEAVED | 67 SNDRV_PCM_INFO_INTERLEAVED |
67 SNDRV_PCM_INFO_PAUSE | 68 SNDRV_PCM_INFO_PAUSE |
68 SNDRV_PCM_INFO_SYNC_START, 69 SNDRV_PCM_INFO_SYNC_START |
70 SNDRV_PCM_INFO_NO_PERIOD_WAKEUP,
69 .formats = SNDRV_PCM_FMTBIT_S16_LE | 71 .formats = SNDRV_PCM_FMTBIT_S16_LE |
70 SNDRV_PCM_FMTBIT_S32_LE, 72 SNDRV_PCM_FMTBIT_S32_LE,
71 .rates = SNDRV_PCM_RATE_32000 | 73 .rates = SNDRV_PCM_RATE_32000 |
@@ -91,7 +93,8 @@ static const struct snd_pcm_hardware oxygen_ac97_hardware = {
91 SNDRV_PCM_INFO_MMAP_VALID | 93 SNDRV_PCM_INFO_MMAP_VALID |
92 SNDRV_PCM_INFO_INTERLEAVED | 94 SNDRV_PCM_INFO_INTERLEAVED |
93 SNDRV_PCM_INFO_PAUSE | 95 SNDRV_PCM_INFO_PAUSE |
94 SNDRV_PCM_INFO_SYNC_START, 96 SNDRV_PCM_INFO_SYNC_START |
97 SNDRV_PCM_INFO_NO_PERIOD_WAKEUP,
95 .formats = SNDRV_PCM_FMTBIT_S16_LE, 98 .formats = SNDRV_PCM_FMTBIT_S16_LE,
96 .rates = SNDRV_PCM_RATE_48000, 99 .rates = SNDRV_PCM_RATE_48000,
97 .rate_min = 48000, 100 .rate_min = 48000,
@@ -140,7 +143,7 @@ static int oxygen_open(struct snd_pcm_substream *substream,
140 runtime->hw.rate_min = 44100; 143 runtime->hw.rate_min = 44100;
141 break; 144 break;
142 case PCM_MULTICH: 145 case PCM_MULTICH:
143 runtime->hw.channels_max = chip->model.dac_channels; 146 runtime->hw.channels_max = chip->model.dac_channels_pcm;
144 break; 147 break;
145 } 148 }
146 if (chip->model.pcm_hardware_filter) 149 if (chip->model.pcm_hardware_filter)
@@ -271,17 +274,6 @@ static unsigned int oxygen_rate(struct snd_pcm_hw_params *hw_params)
271 } 274 }
272} 275}
273 276
274unsigned int oxygen_default_i2s_mclk(struct oxygen *chip,
275 unsigned int channel,
276 struct snd_pcm_hw_params *hw_params)
277{
278 if (params_rate(hw_params) <= 96000)
279 return OXYGEN_I2S_MCLK_256;
280 else
281 return OXYGEN_I2S_MCLK_128;
282}
283EXPORT_SYMBOL(oxygen_default_i2s_mclk);
284
285static unsigned int oxygen_i2s_bits(struct snd_pcm_hw_params *hw_params) 277static unsigned int oxygen_i2s_bits(struct snd_pcm_hw_params *hw_params)
286{ 278{
287 if (params_format(hw_params) == SNDRV_PCM_FORMAT_S32_LE) 279 if (params_format(hw_params) == SNDRV_PCM_FORMAT_S32_LE)
@@ -341,6 +333,26 @@ static int oxygen_hw_params(struct snd_pcm_substream *substream,
341 return 0; 333 return 0;
342} 334}
343 335
336static u16 get_mclk(struct oxygen *chip, unsigned int channel,
337 struct snd_pcm_hw_params *params)
338{
339 unsigned int mclks, shift;
340
341 if (channel == PCM_MULTICH)
342 mclks = chip->model.dac_mclks;
343 else
344 mclks = chip->model.adc_mclks;
345
346 if (params_rate(params) <= 48000)
347 shift = 0;
348 else if (params_rate(params) <= 96000)
349 shift = 2;
350 else
351 shift = 4;
352
353 return OXYGEN_I2S_MCLK(mclks >> shift);
354}
355
344static int oxygen_rec_a_hw_params(struct snd_pcm_substream *substream, 356static int oxygen_rec_a_hw_params(struct snd_pcm_substream *substream,
345 struct snd_pcm_hw_params *hw_params) 357 struct snd_pcm_hw_params *hw_params)
346{ 358{
@@ -357,8 +369,8 @@ static int oxygen_rec_a_hw_params(struct snd_pcm_substream *substream,
357 OXYGEN_REC_FORMAT_A_MASK); 369 OXYGEN_REC_FORMAT_A_MASK);
358 oxygen_write16_masked(chip, OXYGEN_I2S_A_FORMAT, 370 oxygen_write16_masked(chip, OXYGEN_I2S_A_FORMAT,
359 oxygen_rate(hw_params) | 371 oxygen_rate(hw_params) |
360 chip->model.get_i2s_mclk(chip, PCM_A, hw_params) |
361 chip->model.adc_i2s_format | 372 chip->model.adc_i2s_format |
373 get_mclk(chip, PCM_A, hw_params) |
362 oxygen_i2s_bits(hw_params), 374 oxygen_i2s_bits(hw_params),
363 OXYGEN_I2S_RATE_MASK | 375 OXYGEN_I2S_RATE_MASK |
364 OXYGEN_I2S_FORMAT_MASK | 376 OXYGEN_I2S_FORMAT_MASK |
@@ -393,9 +405,8 @@ static int oxygen_rec_b_hw_params(struct snd_pcm_substream *substream,
393 if (!is_ac97) 405 if (!is_ac97)
394 oxygen_write16_masked(chip, OXYGEN_I2S_B_FORMAT, 406 oxygen_write16_masked(chip, OXYGEN_I2S_B_FORMAT,
395 oxygen_rate(hw_params) | 407 oxygen_rate(hw_params) |
396 chip->model.get_i2s_mclk(chip, PCM_B,
397 hw_params) |
398 chip->model.adc_i2s_format | 408 chip->model.adc_i2s_format |
409 get_mclk(chip, PCM_B, hw_params) |
399 oxygen_i2s_bits(hw_params), 410 oxygen_i2s_bits(hw_params),
400 OXYGEN_I2S_RATE_MASK | 411 OXYGEN_I2S_RATE_MASK |
401 OXYGEN_I2S_FORMAT_MASK | 412 OXYGEN_I2S_FORMAT_MASK |
@@ -476,8 +487,7 @@ static int oxygen_multich_hw_params(struct snd_pcm_substream *substream,
476 oxygen_write16_masked(chip, OXYGEN_I2S_MULTICH_FORMAT, 487 oxygen_write16_masked(chip, OXYGEN_I2S_MULTICH_FORMAT,
477 oxygen_rate(hw_params) | 488 oxygen_rate(hw_params) |
478 chip->model.dac_i2s_format | 489 chip->model.dac_i2s_format |
479 chip->model.get_i2s_mclk(chip, PCM_MULTICH, 490 get_mclk(chip, PCM_MULTICH, hw_params) |
480 hw_params) |
481 oxygen_i2s_bits(hw_params), 491 oxygen_i2s_bits(hw_params),
482 OXYGEN_I2S_RATE_MASK | 492 OXYGEN_I2S_RATE_MASK |
483 OXYGEN_I2S_FORMAT_MASK | 493 OXYGEN_I2S_FORMAT_MASK |
@@ -530,7 +540,10 @@ static int oxygen_prepare(struct snd_pcm_substream *substream)
530 oxygen_set_bits8(chip, OXYGEN_DMA_FLUSH, channel_mask); 540 oxygen_set_bits8(chip, OXYGEN_DMA_FLUSH, channel_mask);
531 oxygen_clear_bits8(chip, OXYGEN_DMA_FLUSH, channel_mask); 541 oxygen_clear_bits8(chip, OXYGEN_DMA_FLUSH, channel_mask);
532 542
533 chip->interrupt_mask |= channel_mask; 543 if (substream->runtime->no_period_wakeup)
544 chip->interrupt_mask &= ~channel_mask;
545 else
546 chip->interrupt_mask |= channel_mask;
534 oxygen_write16(chip, OXYGEN_INTERRUPT_MASK, chip->interrupt_mask); 547 oxygen_write16(chip, OXYGEN_INTERRUPT_MASK, chip->interrupt_mask);
535 spin_unlock_irq(&chip->reg_lock); 548 spin_unlock_irq(&chip->reg_lock);
536 return 0; 549 return 0;
diff --git a/sound/pci/oxygen/oxygen_regs.h b/sound/pci/oxygen/oxygen_regs.h
index 4dcd41b78258..63dc7a0ab555 100644
--- a/sound/pci/oxygen/oxygen_regs.h
+++ b/sound/pci/oxygen/oxygen_regs.h
@@ -139,9 +139,11 @@
139#define OXYGEN_I2S_FORMAT_I2S 0x0000 139#define OXYGEN_I2S_FORMAT_I2S 0x0000
140#define OXYGEN_I2S_FORMAT_LJUST 0x0008 140#define OXYGEN_I2S_FORMAT_LJUST 0x0008
141#define OXYGEN_I2S_MCLK_MASK 0x0030 /* MCLK/LRCK */ 141#define OXYGEN_I2S_MCLK_MASK 0x0030 /* MCLK/LRCK */
142#define OXYGEN_I2S_MCLK_128 0x0000 142#define OXYGEN_I2S_MCLK_SHIFT 4
143#define OXYGEN_I2S_MCLK_256 0x0010 143#define MCLK_128 0
144#define OXYGEN_I2S_MCLK_512 0x0020 144#define MCLK_256 1
145#define MCLK_512 2
146#define OXYGEN_I2S_MCLK(f) (((f) & 3) << OXYGEN_I2S_MCLK_SHIFT)
145#define OXYGEN_I2S_BITS_MASK 0x00c0 147#define OXYGEN_I2S_BITS_MASK 0x00c0
146#define OXYGEN_I2S_BITS_16 0x0000 148#define OXYGEN_I2S_BITS_16 0x0000
147#define OXYGEN_I2S_BITS_20 0x0040 149#define OXYGEN_I2S_BITS_20 0x0040
@@ -238,11 +240,11 @@
238#define OXYGEN_SPI_DATA_LENGTH_MASK 0x02 240#define OXYGEN_SPI_DATA_LENGTH_MASK 0x02
239#define OXYGEN_SPI_DATA_LENGTH_2 0x00 241#define OXYGEN_SPI_DATA_LENGTH_2 0x00
240#define OXYGEN_SPI_DATA_LENGTH_3 0x02 242#define OXYGEN_SPI_DATA_LENGTH_3 0x02
241#define OXYGEN_SPI_CLOCK_MASK 0xc0 243#define OXYGEN_SPI_CLOCK_MASK 0x0c
242#define OXYGEN_SPI_CLOCK_160 0x00 /* ns */ 244#define OXYGEN_SPI_CLOCK_160 0x00 /* ns */
243#define OXYGEN_SPI_CLOCK_320 0x40 245#define OXYGEN_SPI_CLOCK_320 0x04
244#define OXYGEN_SPI_CLOCK_640 0x80 246#define OXYGEN_SPI_CLOCK_640 0x08
245#define OXYGEN_SPI_CLOCK_1280 0xc0 247#define OXYGEN_SPI_CLOCK_1280 0x0c
246#define OXYGEN_SPI_CODEC_MASK 0x70 /* 0..5 */ 248#define OXYGEN_SPI_CODEC_MASK 0x70 /* 0..5 */
247#define OXYGEN_SPI_CODEC_SHIFT 4 249#define OXYGEN_SPI_CODEC_SHIFT 4
248#define OXYGEN_SPI_CEN_MASK 0x80 250#define OXYGEN_SPI_CEN_MASK 0x80
diff --git a/sound/pci/oxygen/xonar.h b/sound/pci/oxygen/xonar.h
index b35343b0a9a5..0434c207e811 100644
--- a/sound/pci/oxygen/xonar.h
+++ b/sound/pci/oxygen/xonar.h
@@ -24,6 +24,8 @@ void xonar_init_ext_power(struct oxygen *chip);
24void xonar_init_cs53x1(struct oxygen *chip); 24void xonar_init_cs53x1(struct oxygen *chip);
25void xonar_set_cs53x1_params(struct oxygen *chip, 25void xonar_set_cs53x1_params(struct oxygen *chip,
26 struct snd_pcm_hw_params *params); 26 struct snd_pcm_hw_params *params);
27
28#define XONAR_GPIO_BIT_INVERT (1 << 16)
27int xonar_gpio_bit_switch_get(struct snd_kcontrol *ctl, 29int xonar_gpio_bit_switch_get(struct snd_kcontrol *ctl,
28 struct snd_ctl_elem_value *value); 30 struct snd_ctl_elem_value *value);
29int xonar_gpio_bit_switch_put(struct snd_kcontrol *ctl, 31int xonar_gpio_bit_switch_put(struct snd_kcontrol *ctl,
diff --git a/sound/pci/oxygen/xonar_cs43xx.c b/sound/pci/oxygen/xonar_cs43xx.c
index aa27c31049af..9f72d424969c 100644
--- a/sound/pci/oxygen/xonar_cs43xx.c
+++ b/sound/pci/oxygen/xonar_cs43xx.c
@@ -22,29 +22,28 @@
22 * 22 *
23 * CMI8788: 23 * CMI8788:
24 * 24 *
25 * I²C <-> CS4398 (front) 25 * I²C <-> CS4398 (addr 1001111) (front)
26 * <-> CS4362A (surround, center/LFE, back) 26 * <-> CS4362A (addr 0011000) (surround, center/LFE, back)
27 * 27 *
28 * GPI 0 <- external power present (DX only) 28 * GPI 0 <- external power present (DX only)
29 * 29 *
30 * GPIO 0 -> enable output to speakers 30 * GPIO 0 -> enable output to speakers
31 * GPIO 1 -> enable front panel I/O 31 * GPIO 1 -> route output to front panel
32 * GPIO 2 -> M0 of CS5361 32 * GPIO 2 -> M0 of CS5361
33 * GPIO 3 -> M1 of CS5361 33 * GPIO 3 -> M1 of CS5361
34 * GPIO 8 -> route input jack to line-in (0) or mic-in (1) 34 * GPIO 6 -> ?
35 * GPIO 7 -> ?
36 * GPIO 8 -> route input jack to line-in (0) or mic-in (1)
35 * 37 *
36 * CS4398: 38 * CM9780:
37 *
38 * AD0 <- 1
39 * AD1 <- 1
40 * 39 *
41 * CS4362A: 40 * LINE_OUT -> input of ADC
42 * 41 *
43 * AD0 <- 0 42 * AUX_IN <- aux
43 * MIC_IN <- mic
44 * FMIC_IN <- front mic
44 * 45 *
45 * CM9780: 46 * GPO 0 -> route line-in (0) or AC97 output (1) to CS5361 input
46 *
47 * GPO 0 -> route line-in (0) or AC97 output (1) to CS5361 input
48 */ 47 */
49 48
50#include <linux/pci.h> 49#include <linux/pci.h>
@@ -63,6 +62,7 @@
63#define GPI_EXT_POWER 0x01 62#define GPI_EXT_POWER 0x01
64#define GPIO_D1_OUTPUT_ENABLE 0x0001 63#define GPIO_D1_OUTPUT_ENABLE 0x0001
65#define GPIO_D1_FRONT_PANEL 0x0002 64#define GPIO_D1_FRONT_PANEL 0x0002
65#define GPIO_D1_MAGIC 0x00c0
66#define GPIO_D1_INPUT_ROUTE 0x0100 66#define GPIO_D1_INPUT_ROUTE 0x0100
67 67
68#define I2C_DEVICE_CS4398 0x9e /* 10011, AD1=1, AD0=1, /W=0 */ 68#define I2C_DEVICE_CS4398 0x9e /* 10011, AD1=1, AD0=1, /W=0 */
@@ -169,12 +169,12 @@ static void xonar_d1_init(struct oxygen *chip)
169 cs43xx_registers_init(chip); 169 cs43xx_registers_init(chip);
170 170
171 oxygen_set_bits16(chip, OXYGEN_GPIO_CONTROL, 171 oxygen_set_bits16(chip, OXYGEN_GPIO_CONTROL,
172 GPIO_D1_FRONT_PANEL | GPIO_D1_INPUT_ROUTE); 172 GPIO_D1_FRONT_PANEL |
173 GPIO_D1_MAGIC |
174 GPIO_D1_INPUT_ROUTE);
173 oxygen_clear_bits16(chip, OXYGEN_GPIO_DATA, 175 oxygen_clear_bits16(chip, OXYGEN_GPIO_DATA,
174 GPIO_D1_FRONT_PANEL | GPIO_D1_INPUT_ROUTE); 176 GPIO_D1_FRONT_PANEL | GPIO_D1_INPUT_ROUTE);
175 177
176 oxygen_ac97_set_bits(chip, 0, CM9780_JACK, CM9780_FMIC2MIC);
177
178 xonar_init_cs53x1(chip); 178 xonar_init_cs53x1(chip);
179 xonar_enable_output(chip); 179 xonar_enable_output(chip);
180 180
@@ -284,7 +284,7 @@ static void update_cs43xx_center_lfe_mix(struct oxygen *chip, bool mixed)
284 284
285static const struct snd_kcontrol_new front_panel_switch = { 285static const struct snd_kcontrol_new front_panel_switch = {
286 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 286 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
287 .name = "Front Panel Switch", 287 .name = "Front Panel Playback Switch",
288 .info = snd_ctl_boolean_mono_info, 288 .info = snd_ctl_boolean_mono_info,
289 .get = xonar_gpio_bit_switch_get, 289 .get = xonar_gpio_bit_switch_get,
290 .put = xonar_gpio_bit_switch_put, 290 .put = xonar_gpio_bit_switch_put,
@@ -298,13 +298,7 @@ static int rolloff_info(struct snd_kcontrol *ctl,
298 "Fast Roll-off", "Slow Roll-off" 298 "Fast Roll-off", "Slow Roll-off"
299 }; 299 };
300 300
301 info->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; 301 return snd_ctl_enum_info(info, 1, 2, names);
302 info->count = 1;
303 info->value.enumerated.items = 2;
304 if (info->value.enumerated.item >= 2)
305 info->value.enumerated.item = 1;
306 strcpy(info->value.enumerated.name, names[info->value.enumerated.item]);
307 return 0;
308} 302}
309 303
310static int rolloff_get(struct snd_kcontrol *ctl, 304static int rolloff_get(struct snd_kcontrol *ctl,
@@ -380,6 +374,30 @@ static int xonar_d1_mixer_init(struct oxygen *chip)
380 return 0; 374 return 0;
381} 375}
382 376
377static void dump_cs4362a_registers(struct xonar_cs43xx *data,
378 struct snd_info_buffer *buffer)
379{
380 unsigned int i;
381
382 snd_iprintf(buffer, "\nCS4362A:");
383 for (i = 1; i <= 14; ++i)
384 snd_iprintf(buffer, " %02x", data->cs4362a_regs[i]);
385 snd_iprintf(buffer, "\n");
386}
387
388static void dump_d1_registers(struct oxygen *chip,
389 struct snd_info_buffer *buffer)
390{
391 struct xonar_cs43xx *data = chip->model_data;
392 unsigned int i;
393
394 snd_iprintf(buffer, "\nCS4398: 7?");
395 for (i = 2; i <= 8; ++i)
396 snd_iprintf(buffer, " %02x", data->cs4398_regs[i]);
397 snd_iprintf(buffer, "\n");
398 dump_cs4362a_registers(data, buffer);
399}
400
383static const struct oxygen_model model_xonar_d1 = { 401static const struct oxygen_model model_xonar_d1 = {
384 .longname = "Asus Virtuoso 100", 402 .longname = "Asus Virtuoso 100",
385 .chip = "AV200", 403 .chip = "AV200",
@@ -388,22 +406,26 @@ static const struct oxygen_model model_xonar_d1 = {
388 .cleanup = xonar_d1_cleanup, 406 .cleanup = xonar_d1_cleanup,
389 .suspend = xonar_d1_suspend, 407 .suspend = xonar_d1_suspend,
390 .resume = xonar_d1_resume, 408 .resume = xonar_d1_resume,
391 .get_i2s_mclk = oxygen_default_i2s_mclk,
392 .set_dac_params = set_cs43xx_params, 409 .set_dac_params = set_cs43xx_params,
393 .set_adc_params = xonar_set_cs53x1_params, 410 .set_adc_params = xonar_set_cs53x1_params,
394 .update_dac_volume = update_cs43xx_volume, 411 .update_dac_volume = update_cs43xx_volume,
395 .update_dac_mute = update_cs43xx_mute, 412 .update_dac_mute = update_cs43xx_mute,
396 .update_center_lfe_mix = update_cs43xx_center_lfe_mix, 413 .update_center_lfe_mix = update_cs43xx_center_lfe_mix,
397 .ac97_switch = xonar_d1_line_mic_ac97_switch, 414 .ac97_switch = xonar_d1_line_mic_ac97_switch,
415 .dump_registers = dump_d1_registers,
398 .dac_tlv = cs4362a_db_scale, 416 .dac_tlv = cs4362a_db_scale,
399 .model_data_size = sizeof(struct xonar_cs43xx), 417 .model_data_size = sizeof(struct xonar_cs43xx),
400 .device_config = PLAYBACK_0_TO_I2S | 418 .device_config = PLAYBACK_0_TO_I2S |
401 PLAYBACK_1_TO_SPDIF | 419 PLAYBACK_1_TO_SPDIF |
402 CAPTURE_0_FROM_I2S_2, 420 CAPTURE_0_FROM_I2S_2 |
403 .dac_channels = 8, 421 AC97_FMIC_SWITCH,
422 .dac_channels_pcm = 8,
423 .dac_channels_mixer = 8,
404 .dac_volume_min = 127 - 60, 424 .dac_volume_min = 127 - 60,
405 .dac_volume_max = 127, 425 .dac_volume_max = 127,
406 .function_flags = OXYGEN_FUNCTION_2WIRE, 426 .function_flags = OXYGEN_FUNCTION_2WIRE,
427 .dac_mclks = OXYGEN_MCLKS(256, 128, 128),
428 .adc_mclks = OXYGEN_MCLKS(256, 128, 128),
407 .dac_i2s_format = OXYGEN_I2S_FORMAT_LJUST, 429 .dac_i2s_format = OXYGEN_I2S_FORMAT_LJUST,
408 .adc_i2s_format = OXYGEN_I2S_FORMAT_LJUST, 430 .adc_i2s_format = OXYGEN_I2S_FORMAT_LJUST,
409}; 431};
diff --git a/sound/pci/oxygen/xonar_dg.c b/sound/pci/oxygen/xonar_dg.c
new file mode 100644
index 000000000000..e4de0b8d087a
--- /dev/null
+++ b/sound/pci/oxygen/xonar_dg.c
@@ -0,0 +1,572 @@
1/*
2 * card driver for the Xonar DG
3 *
4 * Copyright (c) Clemens Ladisch <clemens@ladisch.de>
5 *
6 *
7 * This driver is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License, version 2.
9 *
10 * This driver is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this driver; if not, see <http://www.gnu.org/licenses/>.
17 */
18
19/*
20 * Xonar DG
21 * --------
22 *
23 * CMI8788:
24 *
25 * SPI 0 -> CS4245
26 *
27 * GPIO 3 <- ?
28 * GPIO 4 <- headphone detect
29 * GPIO 5 -> route input jack to line-in (0) or mic-in (1)
30 * GPIO 6 -> route input jack to line-in (0) or mic-in (1)
31 * GPIO 7 -> enable rear headphone amp
32 * GPIO 8 -> enable output to speakers
33 *
34 * CS4245:
35 *
36 * input 1 <- aux
37 * input 2 <- front mic
38 * input 4 <- line/mic
39 * aux out -> front panel headphones
40 */
41
42#include <linux/pci.h>
43#include <linux/delay.h>
44#include <sound/control.h>
45#include <sound/core.h>
46#include <sound/info.h>
47#include <sound/pcm.h>
48#include <sound/tlv.h>
49#include "oxygen.h"
50#include "xonar_dg.h"
51#include "cs4245.h"
52
53#define GPIO_MAGIC 0x0008
54#define GPIO_HP_DETECT 0x0010
55#define GPIO_INPUT_ROUTE 0x0060
56#define GPIO_HP_REAR 0x0080
57#define GPIO_OUTPUT_ENABLE 0x0100
58
59struct dg {
60 unsigned int output_sel;
61 s8 input_vol[4][2];
62 unsigned int input_sel;
63 u8 hp_vol_att;
64 u8 cs4245_regs[0x11];
65};
66
67static void cs4245_write(struct oxygen *chip, unsigned int reg, u8 value)
68{
69 struct dg *data = chip->model_data;
70
71 oxygen_write_spi(chip, OXYGEN_SPI_TRIGGER |
72 OXYGEN_SPI_DATA_LENGTH_3 |
73 OXYGEN_SPI_CLOCK_1280 |
74 (0 << OXYGEN_SPI_CODEC_SHIFT) |
75 OXYGEN_SPI_CEN_LATCH_CLOCK_HI,
76 CS4245_SPI_ADDRESS |
77 CS4245_SPI_WRITE |
78 (value << 8) | reg);
79 data->cs4245_regs[reg] = value;
80}
81
82static void cs4245_write_cached(struct oxygen *chip, unsigned int reg, u8 value)
83{
84 struct dg *data = chip->model_data;
85
86 if (value != data->cs4245_regs[reg])
87 cs4245_write(chip, reg, value);
88}
89
90static void cs4245_registers_init(struct oxygen *chip)
91{
92 struct dg *data = chip->model_data;
93
94 cs4245_write(chip, CS4245_POWER_CTRL, CS4245_PDN);
95 cs4245_write(chip, CS4245_DAC_CTRL_1,
96 data->cs4245_regs[CS4245_DAC_CTRL_1]);
97 cs4245_write(chip, CS4245_ADC_CTRL,
98 data->cs4245_regs[CS4245_ADC_CTRL]);
99 cs4245_write(chip, CS4245_SIGNAL_SEL,
100 data->cs4245_regs[CS4245_SIGNAL_SEL]);
101 cs4245_write(chip, CS4245_PGA_B_CTRL,
102 data->cs4245_regs[CS4245_PGA_B_CTRL]);
103 cs4245_write(chip, CS4245_PGA_A_CTRL,
104 data->cs4245_regs[CS4245_PGA_A_CTRL]);
105 cs4245_write(chip, CS4245_ANALOG_IN,
106 data->cs4245_regs[CS4245_ANALOG_IN]);
107 cs4245_write(chip, CS4245_DAC_A_CTRL,
108 data->cs4245_regs[CS4245_DAC_A_CTRL]);
109 cs4245_write(chip, CS4245_DAC_B_CTRL,
110 data->cs4245_regs[CS4245_DAC_B_CTRL]);
111 cs4245_write(chip, CS4245_DAC_CTRL_2,
112 CS4245_DAC_SOFT | CS4245_DAC_ZERO | CS4245_INVERT_DAC);
113 cs4245_write(chip, CS4245_INT_MASK, 0);
114 cs4245_write(chip, CS4245_POWER_CTRL, 0);
115}
116
117static void cs4245_init(struct oxygen *chip)
118{
119 struct dg *data = chip->model_data;
120
121 data->cs4245_regs[CS4245_DAC_CTRL_1] =
122 CS4245_DAC_FM_SINGLE | CS4245_DAC_DIF_LJUST;
123 data->cs4245_regs[CS4245_ADC_CTRL] =
124 CS4245_ADC_FM_SINGLE | CS4245_ADC_DIF_LJUST;
125 data->cs4245_regs[CS4245_SIGNAL_SEL] =
126 CS4245_A_OUT_SEL_HIZ | CS4245_ASYNCH;
127 data->cs4245_regs[CS4245_PGA_B_CTRL] = 0;
128 data->cs4245_regs[CS4245_PGA_A_CTRL] = 0;
129 data->cs4245_regs[CS4245_ANALOG_IN] =
130 CS4245_PGA_SOFT | CS4245_PGA_ZERO | CS4245_SEL_INPUT_4;
131 data->cs4245_regs[CS4245_DAC_A_CTRL] = 0;
132 data->cs4245_regs[CS4245_DAC_B_CTRL] = 0;
133 cs4245_registers_init(chip);
134 snd_component_add(chip->card, "CS4245");
135}
136
137static void dg_output_enable(struct oxygen *chip)
138{
139 msleep(2500);
140 oxygen_set_bits16(chip, OXYGEN_GPIO_DATA, GPIO_OUTPUT_ENABLE);
141}
142
143static void dg_init(struct oxygen *chip)
144{
145 struct dg *data = chip->model_data;
146
147 data->output_sel = 0;
148 data->input_sel = 3;
149 data->hp_vol_att = 2 * 16;
150
151 cs4245_init(chip);
152
153 oxygen_clear_bits16(chip, OXYGEN_GPIO_CONTROL,
154 GPIO_MAGIC | GPIO_HP_DETECT);
155 oxygen_set_bits16(chip, OXYGEN_GPIO_CONTROL,
156 GPIO_INPUT_ROUTE | GPIO_HP_REAR | GPIO_OUTPUT_ENABLE);
157 oxygen_clear_bits16(chip, OXYGEN_GPIO_DATA,
158 GPIO_INPUT_ROUTE | GPIO_HP_REAR);
159 dg_output_enable(chip);
160}
161
162static void dg_cleanup(struct oxygen *chip)
163{
164 oxygen_clear_bits16(chip, OXYGEN_GPIO_DATA, GPIO_OUTPUT_ENABLE);
165}
166
167static void dg_suspend(struct oxygen *chip)
168{
169 dg_cleanup(chip);
170}
171
172static void dg_resume(struct oxygen *chip)
173{
174 cs4245_registers_init(chip);
175 dg_output_enable(chip);
176}
177
178static void set_cs4245_dac_params(struct oxygen *chip,
179 struct snd_pcm_hw_params *params)
180{
181 struct dg *data = chip->model_data;
182 u8 value;
183
184 value = data->cs4245_regs[CS4245_DAC_CTRL_1] & ~CS4245_DAC_FM_MASK;
185 if (params_rate(params) <= 50000)
186 value |= CS4245_DAC_FM_SINGLE;
187 else if (params_rate(params) <= 100000)
188 value |= CS4245_DAC_FM_DOUBLE;
189 else
190 value |= CS4245_DAC_FM_QUAD;
191 cs4245_write_cached(chip, CS4245_DAC_CTRL_1, value);
192}
193
194static void set_cs4245_adc_params(struct oxygen *chip,
195 struct snd_pcm_hw_params *params)
196{
197 struct dg *data = chip->model_data;
198 u8 value;
199
200 value = data->cs4245_regs[CS4245_ADC_CTRL] & ~CS4245_ADC_FM_MASK;
201 if (params_rate(params) <= 50000)
202 value |= CS4245_ADC_FM_SINGLE;
203 else if (params_rate(params) <= 100000)
204 value |= CS4245_ADC_FM_DOUBLE;
205 else
206 value |= CS4245_ADC_FM_QUAD;
207 cs4245_write_cached(chip, CS4245_ADC_CTRL, value);
208}
209
210static int output_switch_info(struct snd_kcontrol *ctl,
211 struct snd_ctl_elem_info *info)
212{
213 static const char *const names[3] = {
214 "Speakers", "Headphones", "FP Headphones"
215 };
216
217 return snd_ctl_enum_info(info, 1, 3, names);
218}
219
220static int output_switch_get(struct snd_kcontrol *ctl,
221 struct snd_ctl_elem_value *value)
222{
223 struct oxygen *chip = ctl->private_data;
224 struct dg *data = chip->model_data;
225
226 mutex_lock(&chip->mutex);
227 value->value.enumerated.item[0] = data->output_sel;
228 mutex_unlock(&chip->mutex);
229 return 0;
230}
231
232static int output_switch_put(struct snd_kcontrol *ctl,
233 struct snd_ctl_elem_value *value)
234{
235 struct oxygen *chip = ctl->private_data;
236 struct dg *data = chip->model_data;
237 u8 reg;
238 int changed;
239
240 if (value->value.enumerated.item[0] > 2)
241 return -EINVAL;
242
243 mutex_lock(&chip->mutex);
244 changed = value->value.enumerated.item[0] != data->output_sel;
245 if (changed) {
246 data->output_sel = value->value.enumerated.item[0];
247
248 reg = data->cs4245_regs[CS4245_SIGNAL_SEL] &
249 ~CS4245_A_OUT_SEL_MASK;
250 reg |= data->output_sel == 2 ?
251 CS4245_A_OUT_SEL_DAC : CS4245_A_OUT_SEL_HIZ;
252 cs4245_write_cached(chip, CS4245_SIGNAL_SEL, reg);
253
254 cs4245_write_cached(chip, CS4245_DAC_A_CTRL,
255 data->output_sel ? data->hp_vol_att : 0);
256 cs4245_write_cached(chip, CS4245_DAC_B_CTRL,
257 data->output_sel ? data->hp_vol_att : 0);
258
259 oxygen_write16_masked(chip, OXYGEN_GPIO_DATA,
260 data->output_sel == 1 ? GPIO_HP_REAR : 0,
261 GPIO_HP_REAR);
262 }
263 mutex_unlock(&chip->mutex);
264 return changed;
265}
266
267static int hp_volume_offset_info(struct snd_kcontrol *ctl,
268 struct snd_ctl_elem_info *info)
269{
270 static const char *const names[3] = {
271 "< 64 ohms", "64-150 ohms", "150-300 ohms"
272 };
273
274 return snd_ctl_enum_info(info, 1, 3, names);
275}
276
277static int hp_volume_offset_get(struct snd_kcontrol *ctl,
278 struct snd_ctl_elem_value *value)
279{
280 struct oxygen *chip = ctl->private_data;
281 struct dg *data = chip->model_data;
282
283 mutex_lock(&chip->mutex);
284 if (data->hp_vol_att > 2 * 7)
285 value->value.enumerated.item[0] = 0;
286 else if (data->hp_vol_att > 0)
287 value->value.enumerated.item[0] = 1;
288 else
289 value->value.enumerated.item[0] = 2;
290 mutex_unlock(&chip->mutex);
291 return 0;
292}
293
294static int hp_volume_offset_put(struct snd_kcontrol *ctl,
295 struct snd_ctl_elem_value *value)
296{
297 static const s8 atts[3] = { 2 * 16, 2 * 7, 0 };
298 struct oxygen *chip = ctl->private_data;
299 struct dg *data = chip->model_data;
300 s8 att;
301 int changed;
302
303 if (value->value.enumerated.item[0] > 2)
304 return -EINVAL;
305 att = atts[value->value.enumerated.item[0]];
306 mutex_lock(&chip->mutex);
307 changed = att != data->hp_vol_att;
308 if (changed) {
309 data->hp_vol_att = att;
310 if (data->output_sel) {
311 cs4245_write_cached(chip, CS4245_DAC_A_CTRL, att);
312 cs4245_write_cached(chip, CS4245_DAC_B_CTRL, att);
313 }
314 }
315 mutex_unlock(&chip->mutex);
316 return changed;
317}
318
319static int input_vol_info(struct snd_kcontrol *ctl,
320 struct snd_ctl_elem_info *info)
321{
322 info->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
323 info->count = 2;
324 info->value.integer.min = 2 * -12;
325 info->value.integer.max = 2 * 12;
326 return 0;
327}
328
329static int input_vol_get(struct snd_kcontrol *ctl,
330 struct snd_ctl_elem_value *value)
331{
332 struct oxygen *chip = ctl->private_data;
333 struct dg *data = chip->model_data;
334 unsigned int idx = ctl->private_value;
335
336 mutex_lock(&chip->mutex);
337 value->value.integer.value[0] = data->input_vol[idx][0];
338 value->value.integer.value[1] = data->input_vol[idx][1];
339 mutex_unlock(&chip->mutex);
340 return 0;
341}
342
343static int input_vol_put(struct snd_kcontrol *ctl,
344 struct snd_ctl_elem_value *value)
345{
346 struct oxygen *chip = ctl->private_data;
347 struct dg *data = chip->model_data;
348 unsigned int idx = ctl->private_value;
349 int changed = 0;
350
351 if (value->value.integer.value[0] < 2 * -12 ||
352 value->value.integer.value[0] > 2 * 12 ||
353 value->value.integer.value[1] < 2 * -12 ||
354 value->value.integer.value[1] > 2 * 12)
355 return -EINVAL;
356 mutex_lock(&chip->mutex);
357 changed = data->input_vol[idx][0] != value->value.integer.value[0] ||
358 data->input_vol[idx][1] != value->value.integer.value[1];
359 if (changed) {
360 data->input_vol[idx][0] = value->value.integer.value[0];
361 data->input_vol[idx][1] = value->value.integer.value[1];
362 if (idx == data->input_sel) {
363 cs4245_write_cached(chip, CS4245_PGA_A_CTRL,
364 data->input_vol[idx][0]);
365 cs4245_write_cached(chip, CS4245_PGA_B_CTRL,
366 data->input_vol[idx][1]);
367 }
368 }
369 mutex_unlock(&chip->mutex);
370 return changed;
371}
372
373static DECLARE_TLV_DB_SCALE(cs4245_pga_db_scale, -1200, 50, 0);
374
375static int input_sel_info(struct snd_kcontrol *ctl,
376 struct snd_ctl_elem_info *info)
377{
378 static const char *const names[4] = {
379 "Mic", "Aux", "Front Mic", "Line"
380 };
381
382 return snd_ctl_enum_info(info, 1, 4, names);
383}
384
385static int input_sel_get(struct snd_kcontrol *ctl,
386 struct snd_ctl_elem_value *value)
387{
388 struct oxygen *chip = ctl->private_data;
389 struct dg *data = chip->model_data;
390
391 mutex_lock(&chip->mutex);
392 value->value.enumerated.item[0] = data->input_sel;
393 mutex_unlock(&chip->mutex);
394 return 0;
395}
396
397static int input_sel_put(struct snd_kcontrol *ctl,
398 struct snd_ctl_elem_value *value)
399{
400 static const u8 sel_values[4] = {
401 CS4245_SEL_MIC,
402 CS4245_SEL_INPUT_1,
403 CS4245_SEL_INPUT_2,
404 CS4245_SEL_INPUT_4
405 };
406 struct oxygen *chip = ctl->private_data;
407 struct dg *data = chip->model_data;
408 int changed;
409
410 if (value->value.enumerated.item[0] > 3)
411 return -EINVAL;
412
413 mutex_lock(&chip->mutex);
414 changed = value->value.enumerated.item[0] != data->input_sel;
415 if (changed) {
416 data->input_sel = value->value.enumerated.item[0];
417
418 cs4245_write(chip, CS4245_ANALOG_IN,
419 (data->cs4245_regs[CS4245_ANALOG_IN] &
420 ~CS4245_SEL_MASK) |
421 sel_values[data->input_sel]);
422
423 cs4245_write_cached(chip, CS4245_PGA_A_CTRL,
424 data->input_vol[data->input_sel][0]);
425 cs4245_write_cached(chip, CS4245_PGA_B_CTRL,
426 data->input_vol[data->input_sel][1]);
427
428 oxygen_write16_masked(chip, OXYGEN_GPIO_DATA,
429 data->input_sel ? 0 : GPIO_INPUT_ROUTE,
430 GPIO_INPUT_ROUTE);
431 }
432 mutex_unlock(&chip->mutex);
433 return changed;
434}
435
436static int hpf_info(struct snd_kcontrol *ctl, struct snd_ctl_elem_info *info)
437{
438 static const char *const names[2] = { "Active", "Frozen" };
439
440 return snd_ctl_enum_info(info, 1, 2, names);
441}
442
443static int hpf_get(struct snd_kcontrol *ctl, struct snd_ctl_elem_value *value)
444{
445 struct oxygen *chip = ctl->private_data;
446 struct dg *data = chip->model_data;
447
448 value->value.enumerated.item[0] =
449 !!(data->cs4245_regs[CS4245_ADC_CTRL] & CS4245_HPF_FREEZE);
450 return 0;
451}
452
453static int hpf_put(struct snd_kcontrol *ctl, struct snd_ctl_elem_value *value)
454{
455 struct oxygen *chip = ctl->private_data;
456 struct dg *data = chip->model_data;
457 u8 reg;
458 int changed;
459
460 mutex_lock(&chip->mutex);
461 reg = data->cs4245_regs[CS4245_ADC_CTRL] & ~CS4245_HPF_FREEZE;
462 if (value->value.enumerated.item[0])
463 reg |= CS4245_HPF_FREEZE;
464 changed = reg != data->cs4245_regs[CS4245_ADC_CTRL];
465 if (changed)
466 cs4245_write(chip, CS4245_ADC_CTRL, reg);
467 mutex_unlock(&chip->mutex);
468 return changed;
469}
470
471#define INPUT_VOLUME(xname, index) { \
472 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
473 .name = xname, \
474 .info = input_vol_info, \
475 .get = input_vol_get, \
476 .put = input_vol_put, \
477 .tlv = { .p = cs4245_pga_db_scale }, \
478 .private_value = index, \
479}
480static const struct snd_kcontrol_new dg_controls[] = {
481 {
482 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
483 .name = "Analog Output Playback Enum",
484 .info = output_switch_info,
485 .get = output_switch_get,
486 .put = output_switch_put,
487 },
488 {
489 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
490 .name = "Headphones Impedance Playback Enum",
491 .info = hp_volume_offset_info,
492 .get = hp_volume_offset_get,
493 .put = hp_volume_offset_put,
494 },
495 INPUT_VOLUME("Mic Capture Volume", 0),
496 INPUT_VOLUME("Aux Capture Volume", 1),
497 INPUT_VOLUME("Front Mic Capture Volume", 2),
498 INPUT_VOLUME("Line Capture Volume", 3),
499 {
500 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
501 .name = "Capture Source",
502 .info = input_sel_info,
503 .get = input_sel_get,
504 .put = input_sel_put,
505 },
506 {
507 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
508 .name = "ADC High-pass Filter Capture Enum",
509 .info = hpf_info,
510 .get = hpf_get,
511 .put = hpf_put,
512 },
513};
514
515static int dg_control_filter(struct snd_kcontrol_new *template)
516{
517 if (!strncmp(template->name, "Master Playback ", 16))
518 return 1;
519 return 0;
520}
521
522static int dg_mixer_init(struct oxygen *chip)
523{
524 unsigned int i;
525 int err;
526
527 for (i = 0; i < ARRAY_SIZE(dg_controls); ++i) {
528 err = snd_ctl_add(chip->card,
529 snd_ctl_new1(&dg_controls[i], chip));
530 if (err < 0)
531 return err;
532 }
533 return 0;
534}
535
536static void dump_cs4245_registers(struct oxygen *chip,
537 struct snd_info_buffer *buffer)
538{
539 struct dg *data = chip->model_data;
540 unsigned int i;
541
542 snd_iprintf(buffer, "\nCS4245:");
543 for (i = 1; i <= 0x10; ++i)
544 snd_iprintf(buffer, " %02x", data->cs4245_regs[i]);
545 snd_iprintf(buffer, "\n");
546}
547
548struct oxygen_model model_xonar_dg = {
549 .shortname = "Xonar DG",
550 .longname = "C-Media Oxygen HD Audio",
551 .chip = "CMI8786",
552 .init = dg_init,
553 .control_filter = dg_control_filter,
554 .mixer_init = dg_mixer_init,
555 .cleanup = dg_cleanup,
556 .suspend = dg_suspend,
557 .resume = dg_resume,
558 .set_dac_params = set_cs4245_dac_params,
559 .set_adc_params = set_cs4245_adc_params,
560 .dump_registers = dump_cs4245_registers,
561 .model_data_size = sizeof(struct dg),
562 .device_config = PLAYBACK_0_TO_I2S |
563 PLAYBACK_1_TO_SPDIF |
564 CAPTURE_0_FROM_I2S_2,
565 .dac_channels_pcm = 6,
566 .dac_channels_mixer = 0,
567 .function_flags = OXYGEN_FUNCTION_SPI,
568 .dac_mclks = OXYGEN_MCLKS(256, 128, 128),
569 .adc_mclks = OXYGEN_MCLKS(256, 128, 128),
570 .dac_i2s_format = OXYGEN_I2S_FORMAT_LJUST,
571 .adc_i2s_format = OXYGEN_I2S_FORMAT_LJUST,
572};
diff --git a/sound/pci/oxygen/xonar_dg.h b/sound/pci/oxygen/xonar_dg.h
new file mode 100644
index 000000000000..5688d78609a9
--- /dev/null
+++ b/sound/pci/oxygen/xonar_dg.h
@@ -0,0 +1,8 @@
1#ifndef XONAR_DG_H_INCLUDED
2#define XONAR_DG_H_INCLUDED
3
4#include "oxygen.h"
5
6extern struct oxygen_model model_xonar_dg;
7
8#endif
diff --git a/sound/pci/oxygen/xonar_hdmi.c b/sound/pci/oxygen/xonar_hdmi.c
index b12db1f1cea9..136dac6a3964 100644
--- a/sound/pci/oxygen/xonar_hdmi.c
+++ b/sound/pci/oxygen/xonar_hdmi.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * helper functions for HDMI models (Xonar HDAV1.3) 2 * helper functions for HDMI models (Xonar HDAV1.3/HDAV1.3 Slim)
3 * 3 *
4 * Copyright (c) Clemens Ladisch <clemens@ladisch.de> 4 * Copyright (c) Clemens Ladisch <clemens@ladisch.de>
5 * 5 *
diff --git a/sound/pci/oxygen/xonar_lib.c b/sound/pci/oxygen/xonar_lib.c
index b3ff71316653..0ebe7f5916f9 100644
--- a/sound/pci/oxygen/xonar_lib.c
+++ b/sound/pci/oxygen/xonar_lib.c
@@ -104,9 +104,10 @@ int xonar_gpio_bit_switch_get(struct snd_kcontrol *ctl,
104{ 104{
105 struct oxygen *chip = ctl->private_data; 105 struct oxygen *chip = ctl->private_data;
106 u16 bit = ctl->private_value; 106 u16 bit = ctl->private_value;
107 bool invert = ctl->private_value & XONAR_GPIO_BIT_INVERT;
107 108
108 value->value.integer.value[0] = 109 value->value.integer.value[0] =
109 !!(oxygen_read16(chip, OXYGEN_GPIO_DATA) & bit); 110 !!(oxygen_read16(chip, OXYGEN_GPIO_DATA) & bit) ^ invert;
110 return 0; 111 return 0;
111} 112}
112 113
@@ -115,12 +116,13 @@ int xonar_gpio_bit_switch_put(struct snd_kcontrol *ctl,
115{ 116{
116 struct oxygen *chip = ctl->private_data; 117 struct oxygen *chip = ctl->private_data;
117 u16 bit = ctl->private_value; 118 u16 bit = ctl->private_value;
119 bool invert = ctl->private_value & XONAR_GPIO_BIT_INVERT;
118 u16 old_bits, new_bits; 120 u16 old_bits, new_bits;
119 int changed; 121 int changed;
120 122
121 spin_lock_irq(&chip->reg_lock); 123 spin_lock_irq(&chip->reg_lock);
122 old_bits = oxygen_read16(chip, OXYGEN_GPIO_DATA); 124 old_bits = oxygen_read16(chip, OXYGEN_GPIO_DATA);
123 if (value->value.integer.value[0]) 125 if (!!value->value.integer.value[0] ^ invert)
124 new_bits = old_bits | bit; 126 new_bits = old_bits | bit;
125 else 127 else
126 new_bits = old_bits & ~bit; 128 new_bits = old_bits & ~bit;
diff --git a/sound/pci/oxygen/xonar_pcm179x.c b/sound/pci/oxygen/xonar_pcm179x.c
index d491fd6c0be2..54cad38ec30a 100644
--- a/sound/pci/oxygen/xonar_pcm179x.c
+++ b/sound/pci/oxygen/xonar_pcm179x.c
@@ -22,20 +22,26 @@
22 * 22 *
23 * CMI8788: 23 * CMI8788:
24 * 24 *
25 * SPI 0 -> 1st PCM1796 (front) 25 * SPI 0 -> 1st PCM1796 (front)
26 * SPI 1 -> 2nd PCM1796 (surround) 26 * SPI 1 -> 2nd PCM1796 (surround)
27 * SPI 2 -> 3rd PCM1796 (center/LFE) 27 * SPI 2 -> 3rd PCM1796 (center/LFE)
28 * SPI 4 -> 4th PCM1796 (back) 28 * SPI 4 -> 4th PCM1796 (back)
29 * 29 *
30 * GPIO 2 -> M0 of CS5381 30 * GPIO 2 -> M0 of CS5381
31 * GPIO 3 -> M1 of CS5381 31 * GPIO 3 -> M1 of CS5381
32 * GPIO 5 <- external power present (D2X only) 32 * GPIO 5 <- external power present (D2X only)
33 * GPIO 7 -> ALT 33 * GPIO 7 -> ALT
34 * GPIO 8 -> enable output to speakers 34 * GPIO 8 -> enable output to speakers
35 * 35 *
36 * CM9780: 36 * CM9780:
37 * 37 *
38 * GPO 0 -> route line-in (0) or AC97 output (1) to CS5381 input 38 * LINE_OUT -> input of ADC
39 *
40 * AUX_IN <- aux
41 * VIDEO_IN <- CD
42 * FMIC_IN <- mic
43 *
44 * GPO 0 -> route line-in (0) or AC97 output (1) to CS5381 input
39 */ 45 */
40 46
41/* 47/*
@@ -44,52 +50,53 @@
44 * 50 *
45 * CMI8788: 51 * CMI8788:
46 * 52 *
47 * I²C <-> PCM1796 (front) 53 * I²C <-> PCM1796 (addr 1001100) (front)
48 * 54 *
49 * GPI 0 <- external power present 55 * GPI 0 <- external power present
50 * 56 *
51 * GPIO 0 -> enable output to speakers 57 * GPIO 0 -> enable HDMI (0) or speaker (1) output
52 * GPIO 2 -> M0 of CS5381 58 * GPIO 2 -> M0 of CS5381
53 * GPIO 3 -> M1 of CS5381 59 * GPIO 3 -> M1 of CS5381
54 * GPIO 8 -> route input jack to line-in (0) or mic-in (1) 60 * GPIO 4 <- daughterboard detection
61 * GPIO 5 <- daughterboard detection
62 * GPIO 6 -> ?
63 * GPIO 7 -> ?
64 * GPIO 8 -> route input jack to line-in (0) or mic-in (1)
55 * 65 *
56 * TXD -> HDMI controller 66 * UART <-> HDMI controller
57 * RXD <- HDMI controller
58 *
59 * PCM1796 front: AD1,0 <- 0,0
60 * 67 *
61 * CM9780: 68 * CM9780:
62 * 69 *
63 * GPO 0 -> route line-in (0) or AC97 output (1) to CS5381 input 70 * LINE_OUT -> input of ADC
71 *
72 * AUX_IN <- aux
73 * CD_IN <- CD
74 * MIC_IN <- mic
75 *
76 * GPO 0 -> route line-in (0) or AC97 output (1) to CS5381 input
64 * 77 *
65 * no daughterboard 78 * no daughterboard
66 * ---------------- 79 * ----------------
67 * 80 *
68 * GPIO 4 <- 1 81 * GPIO 4 <- 1
69 * 82 *
70 * H6 daughterboard 83 * H6 daughterboard
71 * ---------------- 84 * ----------------
72 * 85 *
73 * GPIO 4 <- 0 86 * GPIO 4 <- 0
74 * GPIO 5 <- 0 87 * GPIO 5 <- 0
75 *
76 * I²C <-> PCM1796 (surround)
77 * <-> PCM1796 (center/LFE)
78 * <-> PCM1796 (back)
79 * 88 *
80 * PCM1796 surround: AD1,0 <- 0,1 89 * I²C <-> PCM1796 (addr 1001101) (surround)
81 * PCM1796 center/LFE: AD1,0 <- 1,0 90 * <-> PCM1796 (addr 1001110) (center/LFE)
82 * PCM1796 back: AD1,0 <- 1,1 91 * <-> PCM1796 (addr 1001111) (back)
83 * 92 *
84 * unknown daughterboard 93 * unknown daughterboard
85 * --------------------- 94 * ---------------------
86 * 95 *
87 * GPIO 4 <- 0 96 * GPIO 4 <- 0
88 * GPIO 5 <- 1 97 * GPIO 5 <- 1
89 *
90 * I²C <-> CS4362A (surround, center/LFE, back)
91 * 98 *
92 * CS4362A: AD0 <- 0 99 * I²C <-> CS4362A (addr 0011000) (surround, center/LFE, back)
93 */ 100 */
94 101
95/* 102/*
@@ -98,32 +105,35 @@
98 * 105 *
99 * CMI8788: 106 * CMI8788:
100 * 107 *
101 * I²C <-> PCM1792A 108 * I²C <-> PCM1792A (addr 1001100)
102 * <-> CS2000 (ST only) 109 * <-> CS2000 (addr 1001110) (ST only)
103 * 110 *
104 * ADC1 MCLK -> REF_CLK of CS2000 (ST only) 111 * ADC1 MCLK -> REF_CLK of CS2000 (ST only)
105 * 112 *
106 * GPI 0 <- external power present (STX only) 113 * GPI 0 <- external power present (STX only)
107 * 114 *
108 * GPIO 0 -> enable output to speakers 115 * GPIO 0 -> enable output to speakers
109 * GPIO 1 -> route HP to front panel (0) or rear jack (1) 116 * GPIO 1 -> route HP to front panel (0) or rear jack (1)
110 * GPIO 2 -> M0 of CS5381 117 * GPIO 2 -> M0 of CS5381
111 * GPIO 3 -> M1 of CS5381 118 * GPIO 3 -> M1 of CS5381
112 * GPIO 7 -> route output to speaker jacks (0) or HP (1) 119 * GPIO 4 <- daughterboard detection
113 * GPIO 8 -> route input jack to line-in (0) or mic-in (1) 120 * GPIO 5 <- daughterboard detection
121 * GPIO 6 -> ?
122 * GPIO 7 -> route output to speaker jacks (0) or HP (1)
123 * GPIO 8 -> route input jack to line-in (0) or mic-in (1)
114 * 124 *
115 * PCM1792A: 125 * PCM1792A:
116 * 126 *
117 * AD1,0 <- 0,0 127 * SCK <- CLK_OUT of CS2000 (ST only)
118 * SCK <- CLK_OUT of CS2000 (ST only)
119 * 128 *
120 * CS2000: 129 * CM9780:
121 * 130 *
122 * AD0 <- 0 131 * LINE_OUT -> input of ADC
123 * 132 *
124 * CM9780: 133 * AUX_IN <- aux
134 * MIC_IN <- mic
125 * 135 *
126 * GPO 0 -> route line-in (0) or AC97 output (1) to CS5381 input 136 * GPO 0 -> route line-in (0) or AC97 output (1) to CS5381 input
127 * 137 *
128 * H6 daughterboard 138 * H6 daughterboard
129 * ---------------- 139 * ----------------
@@ -133,15 +143,39 @@
133 */ 143 */
134 144
135/* 145/*
136 * Xonar HDAV1.3 Slim 146 * Xonar Xense
137 * ------------------ 147 * -----------
138 * 148 *
139 * CMI8788: 149 * CMI8788:
140 * 150 *
141 * GPIO 1 -> enable output 151 * I²C <-> PCM1796 (addr 1001100) (front)
152 * <-> CS4362A (addr 0011000) (surround, center/LFE, back)
153 * <-> CS2000 (addr 1001110)
154 *
155 * ADC1 MCLK -> REF_CLK of CS2000
156 *
157 * GPI 0 <- external power present
158 *
159 * GPIO 0 -> enable output
160 * GPIO 1 -> route HP to front panel (0) or rear jack (1)
161 * GPIO 2 -> M0 of CS5381
162 * GPIO 3 -> M1 of CS5381
163 * GPIO 4 -> enable output
164 * GPIO 5 -> enable output
165 * GPIO 6 -> ?
166 * GPIO 7 -> route output to HP (0) or speaker (1)
167 * GPIO 8 -> route input jack to mic-in (0) or line-in (1)
142 * 168 *
143 * TXD -> HDMI controller 169 * CM9780:
144 * RXD <- HDMI controller 170 *
171 * LINE_OUT -> input of ADC
172 *
173 * AUX_IN <- aux
174 * VIDEO_IN <- ?
175 * FMIC_IN <- mic
176 *
177 * GPO 0 -> route line-in (0) or AC97 output (1) to CS5381 input
178 * GPO 1 -> route mic-in from input jack (0) or front panel header (1)
145 */ 179 */
146 180
147#include <linux/pci.h> 181#include <linux/pci.h>
@@ -150,6 +184,7 @@
150#include <sound/ac97_codec.h> 184#include <sound/ac97_codec.h>
151#include <sound/control.h> 185#include <sound/control.h>
152#include <sound/core.h> 186#include <sound/core.h>
187#include <sound/info.h>
153#include <sound/pcm.h> 188#include <sound/pcm.h>
154#include <sound/pcm_params.h> 189#include <sound/pcm_params.h>
155#include <sound/tlv.h> 190#include <sound/tlv.h>
@@ -167,12 +202,14 @@
167#define GPIO_INPUT_ROUTE 0x0100 202#define GPIO_INPUT_ROUTE 0x0100
168 203
169#define GPIO_HDAV_OUTPUT_ENABLE 0x0001 204#define GPIO_HDAV_OUTPUT_ENABLE 0x0001
205#define GPIO_HDAV_MAGIC 0x00c0
170 206
171#define GPIO_DB_MASK 0x0030 207#define GPIO_DB_MASK 0x0030
172#define GPIO_DB_H6 0x0000 208#define GPIO_DB_H6 0x0000
173 209
174#define GPIO_ST_OUTPUT_ENABLE 0x0001 210#define GPIO_ST_OUTPUT_ENABLE 0x0001
175#define GPIO_ST_HP_REAR 0x0002 211#define GPIO_ST_HP_REAR 0x0002
212#define GPIO_ST_MAGIC 0x0040
176#define GPIO_ST_HP 0x0080 213#define GPIO_ST_HP 0x0080
177 214
178#define I2C_DEVICE_PCM1796(i) (0x98 + ((i) << 1)) /* 10011, ii, /W=0 */ 215#define I2C_DEVICE_PCM1796(i) (0x98 + ((i) << 1)) /* 10011, ii, /W=0 */
@@ -186,11 +223,12 @@ struct xonar_pcm179x {
186 unsigned int dacs; 223 unsigned int dacs;
187 u8 pcm1796_regs[4][5]; 224 u8 pcm1796_regs[4][5];
188 unsigned int current_rate; 225 unsigned int current_rate;
189 bool os_128; 226 bool h6;
190 bool hp_active; 227 bool hp_active;
191 s8 hp_gain_offset; 228 s8 hp_gain_offset;
192 bool has_cs2000; 229 bool has_cs2000;
193 u8 cs2000_fun_cfg_1; 230 u8 cs2000_regs[0x1f];
231 bool broken_i2c;
194}; 232};
195 233
196struct xonar_hdav { 234struct xonar_hdav {
@@ -249,16 +287,14 @@ static void cs2000_write(struct oxygen *chip, u8 reg, u8 value)
249 struct xonar_pcm179x *data = chip->model_data; 287 struct xonar_pcm179x *data = chip->model_data;
250 288
251 oxygen_write_i2c(chip, I2C_DEVICE_CS2000, reg, value); 289 oxygen_write_i2c(chip, I2C_DEVICE_CS2000, reg, value);
252 if (reg == CS2000_FUN_CFG_1) 290 data->cs2000_regs[reg] = value;
253 data->cs2000_fun_cfg_1 = value;
254} 291}
255 292
256static void cs2000_write_cached(struct oxygen *chip, u8 reg, u8 value) 293static void cs2000_write_cached(struct oxygen *chip, u8 reg, u8 value)
257{ 294{
258 struct xonar_pcm179x *data = chip->model_data; 295 struct xonar_pcm179x *data = chip->model_data;
259 296
260 if (reg != CS2000_FUN_CFG_1 || 297 if (value != data->cs2000_regs[reg])
261 value != data->cs2000_fun_cfg_1)
262 cs2000_write(chip, reg, value); 298 cs2000_write(chip, reg, value);
263} 299}
264 300
@@ -268,6 +304,7 @@ static void pcm1796_registers_init(struct oxygen *chip)
268 unsigned int i; 304 unsigned int i;
269 s8 gain_offset; 305 s8 gain_offset;
270 306
307 msleep(1);
271 gain_offset = data->hp_active ? data->hp_gain_offset : 0; 308 gain_offset = data->hp_active ? data->hp_gain_offset : 0;
272 for (i = 0; i < data->dacs; ++i) { 309 for (i = 0; i < data->dacs; ++i) {
273 /* set ATLD before ATL/ATR */ 310 /* set ATLD before ATL/ATR */
@@ -282,6 +319,7 @@ static void pcm1796_registers_init(struct oxygen *chip)
282 pcm1796_write(chip, i, 20, 319 pcm1796_write(chip, i, 20,
283 data->pcm1796_regs[0][20 - PCM1796_REG_BASE]); 320 data->pcm1796_regs[0][20 - PCM1796_REG_BASE]);
284 pcm1796_write(chip, i, 21, 0); 321 pcm1796_write(chip, i, 21, 0);
322 gain_offset = 0;
285 } 323 }
286} 324}
287 325
@@ -290,10 +328,11 @@ static void pcm1796_init(struct oxygen *chip)
290 struct xonar_pcm179x *data = chip->model_data; 328 struct xonar_pcm179x *data = chip->model_data;
291 329
292 data->pcm1796_regs[0][18 - PCM1796_REG_BASE] = PCM1796_MUTE | 330 data->pcm1796_regs[0][18 - PCM1796_REG_BASE] = PCM1796_MUTE |
293 PCM1796_DMF_DISABLED | PCM1796_FMT_24_LJUST | PCM1796_ATLD; 331 PCM1796_DMF_DISABLED | PCM1796_FMT_24_I2S | PCM1796_ATLD;
294 data->pcm1796_regs[0][19 - PCM1796_REG_BASE] = 332 data->pcm1796_regs[0][19 - PCM1796_REG_BASE] =
295 PCM1796_FLT_SHARP | PCM1796_ATS_1; 333 PCM1796_FLT_SHARP | PCM1796_ATS_1;
296 data->pcm1796_regs[0][20 - PCM1796_REG_BASE] = PCM1796_OS_64; 334 data->pcm1796_regs[0][20 - PCM1796_REG_BASE] =
335 data->h6 ? PCM1796_OS_64 : PCM1796_OS_128;
297 pcm1796_registers_init(chip); 336 pcm1796_registers_init(chip);
298 data->current_rate = 48000; 337 data->current_rate = 48000;
299} 338}
@@ -339,18 +378,20 @@ static void xonar_hdav_init(struct oxygen *chip)
339 oxygen_write16(chip, OXYGEN_2WIRE_BUS_STATUS, 378 oxygen_write16(chip, OXYGEN_2WIRE_BUS_STATUS,
340 OXYGEN_2WIRE_LENGTH_8 | 379 OXYGEN_2WIRE_LENGTH_8 |
341 OXYGEN_2WIRE_INTERRUPT_MASK | 380 OXYGEN_2WIRE_INTERRUPT_MASK |
342 OXYGEN_2WIRE_SPEED_FAST); 381 OXYGEN_2WIRE_SPEED_STANDARD);
343 382
344 data->pcm179x.generic.anti_pop_delay = 100; 383 data->pcm179x.generic.anti_pop_delay = 100;
345 data->pcm179x.generic.output_enable_bit = GPIO_HDAV_OUTPUT_ENABLE; 384 data->pcm179x.generic.output_enable_bit = GPIO_HDAV_OUTPUT_ENABLE;
346 data->pcm179x.generic.ext_power_reg = OXYGEN_GPI_DATA; 385 data->pcm179x.generic.ext_power_reg = OXYGEN_GPI_DATA;
347 data->pcm179x.generic.ext_power_int_reg = OXYGEN_GPI_INTERRUPT_MASK; 386 data->pcm179x.generic.ext_power_int_reg = OXYGEN_GPI_INTERRUPT_MASK;
348 data->pcm179x.generic.ext_power_bit = GPI_EXT_POWER; 387 data->pcm179x.generic.ext_power_bit = GPI_EXT_POWER;
349 data->pcm179x.dacs = chip->model.private_data ? 4 : 1; 388 data->pcm179x.dacs = chip->model.dac_channels_mixer / 2;
389 data->pcm179x.h6 = chip->model.dac_channels_mixer > 2;
350 390
351 pcm1796_init(chip); 391 pcm1796_init(chip);
352 392
353 oxygen_set_bits16(chip, OXYGEN_GPIO_CONTROL, GPIO_INPUT_ROUTE); 393 oxygen_set_bits16(chip, OXYGEN_GPIO_CONTROL,
394 GPIO_HDAV_MAGIC | GPIO_INPUT_ROUTE);
354 oxygen_clear_bits16(chip, OXYGEN_GPIO_DATA, GPIO_INPUT_ROUTE); 395 oxygen_clear_bits16(chip, OXYGEN_GPIO_DATA, GPIO_INPUT_ROUTE);
355 396
356 xonar_init_cs53x1(chip); 397 xonar_init_cs53x1(chip);
@@ -367,7 +408,7 @@ static void xonar_st_init_i2c(struct oxygen *chip)
367 oxygen_write16(chip, OXYGEN_2WIRE_BUS_STATUS, 408 oxygen_write16(chip, OXYGEN_2WIRE_BUS_STATUS,
368 OXYGEN_2WIRE_LENGTH_8 | 409 OXYGEN_2WIRE_LENGTH_8 |
369 OXYGEN_2WIRE_INTERRUPT_MASK | 410 OXYGEN_2WIRE_INTERRUPT_MASK |
370 OXYGEN_2WIRE_SPEED_FAST); 411 OXYGEN_2WIRE_SPEED_STANDARD);
371} 412}
372 413
373static void xonar_st_init_common(struct oxygen *chip) 414static void xonar_st_init_common(struct oxygen *chip)
@@ -375,13 +416,14 @@ static void xonar_st_init_common(struct oxygen *chip)
375 struct xonar_pcm179x *data = chip->model_data; 416 struct xonar_pcm179x *data = chip->model_data;
376 417
377 data->generic.output_enable_bit = GPIO_ST_OUTPUT_ENABLE; 418 data->generic.output_enable_bit = GPIO_ST_OUTPUT_ENABLE;
378 data->dacs = chip->model.private_data ? 4 : 1; 419 data->dacs = chip->model.dac_channels_mixer / 2;
379 data->hp_gain_offset = 2*-18; 420 data->hp_gain_offset = 2*-18;
380 421
381 pcm1796_init(chip); 422 pcm1796_init(chip);
382 423
383 oxygen_set_bits16(chip, OXYGEN_GPIO_CONTROL, 424 oxygen_set_bits16(chip, OXYGEN_GPIO_CONTROL,
384 GPIO_INPUT_ROUTE | GPIO_ST_HP_REAR | GPIO_ST_HP); 425 GPIO_INPUT_ROUTE | GPIO_ST_HP_REAR |
426 GPIO_ST_MAGIC | GPIO_ST_HP);
385 oxygen_clear_bits16(chip, OXYGEN_GPIO_DATA, 427 oxygen_clear_bits16(chip, OXYGEN_GPIO_DATA,
386 GPIO_INPUT_ROUTE | GPIO_ST_HP_REAR | GPIO_ST_HP); 428 GPIO_INPUT_ROUTE | GPIO_ST_HP_REAR | GPIO_ST_HP);
387 429
@@ -410,9 +452,11 @@ static void cs2000_registers_init(struct oxygen *chip)
410 cs2000_write(chip, CS2000_RATIO_0 + 1, 0x10); 452 cs2000_write(chip, CS2000_RATIO_0 + 1, 0x10);
411 cs2000_write(chip, CS2000_RATIO_0 + 2, 0x00); 453 cs2000_write(chip, CS2000_RATIO_0 + 2, 0x00);
412 cs2000_write(chip, CS2000_RATIO_0 + 3, 0x00); 454 cs2000_write(chip, CS2000_RATIO_0 + 3, 0x00);
413 cs2000_write(chip, CS2000_FUN_CFG_1, data->cs2000_fun_cfg_1); 455 cs2000_write(chip, CS2000_FUN_CFG_1,
456 data->cs2000_regs[CS2000_FUN_CFG_1]);
414 cs2000_write(chip, CS2000_FUN_CFG_2, 0); 457 cs2000_write(chip, CS2000_FUN_CFG_2, 0);
415 cs2000_write(chip, CS2000_GLOBAL_CFG, CS2000_EN_DEV_CFG_2); 458 cs2000_write(chip, CS2000_GLOBAL_CFG, CS2000_EN_DEV_CFG_2);
459 msleep(3); /* PLL lock delay */
416} 460}
417 461
418static void xonar_st_init(struct oxygen *chip) 462static void xonar_st_init(struct oxygen *chip)
@@ -420,13 +464,18 @@ static void xonar_st_init(struct oxygen *chip)
420 struct xonar_pcm179x *data = chip->model_data; 464 struct xonar_pcm179x *data = chip->model_data;
421 465
422 data->generic.anti_pop_delay = 100; 466 data->generic.anti_pop_delay = 100;
467 data->h6 = chip->model.dac_channels_mixer > 2;
423 data->has_cs2000 = 1; 468 data->has_cs2000 = 1;
424 data->cs2000_fun_cfg_1 = CS2000_REF_CLK_DIV_1; 469 data->cs2000_regs[CS2000_FUN_CFG_1] = CS2000_REF_CLK_DIV_1;
470 data->broken_i2c = true;
425 471
426 oxygen_write16(chip, OXYGEN_I2S_A_FORMAT, 472 oxygen_write16(chip, OXYGEN_I2S_A_FORMAT,
427 OXYGEN_RATE_48000 | OXYGEN_I2S_FORMAT_I2S | 473 OXYGEN_RATE_48000 |
428 OXYGEN_I2S_MCLK_128 | OXYGEN_I2S_BITS_16 | 474 OXYGEN_I2S_FORMAT_I2S |
429 OXYGEN_I2S_MASTER | OXYGEN_I2S_BCLK_64); 475 OXYGEN_I2S_MCLK(data->h6 ? MCLK_256 : MCLK_512) |
476 OXYGEN_I2S_BITS_16 |
477 OXYGEN_I2S_MASTER |
478 OXYGEN_I2S_BCLK_64);
430 479
431 xonar_st_init_i2c(chip); 480 xonar_st_init_i2c(chip);
432 cs2000_registers_init(chip); 481 cs2000_registers_init(chip);
@@ -507,44 +556,16 @@ static void xonar_st_resume(struct oxygen *chip)
507 xonar_stx_resume(chip); 556 xonar_stx_resume(chip);
508} 557}
509 558
510static unsigned int mclk_from_rate(struct oxygen *chip, unsigned int rate)
511{
512 struct xonar_pcm179x *data = chip->model_data;
513
514 if (rate <= 32000)
515 return OXYGEN_I2S_MCLK_512;
516 else if (rate <= 48000 && data->os_128)
517 return OXYGEN_I2S_MCLK_512;
518 else if (rate <= 96000)
519 return OXYGEN_I2S_MCLK_256;
520 else
521 return OXYGEN_I2S_MCLK_128;
522}
523
524static unsigned int get_pcm1796_i2s_mclk(struct oxygen *chip,
525 unsigned int channel,
526 struct snd_pcm_hw_params *params)
527{
528 if (channel == PCM_MULTICH)
529 return mclk_from_rate(chip, params_rate(params));
530 else
531 return oxygen_default_i2s_mclk(chip, channel, params);
532}
533
534static void update_pcm1796_oversampling(struct oxygen *chip) 559static void update_pcm1796_oversampling(struct oxygen *chip)
535{ 560{
536 struct xonar_pcm179x *data = chip->model_data; 561 struct xonar_pcm179x *data = chip->model_data;
537 unsigned int i; 562 unsigned int i;
538 u8 reg; 563 u8 reg;
539 564
540 if (data->current_rate <= 32000) 565 if (data->current_rate <= 48000 && !data->h6)
541 reg = PCM1796_OS_128; 566 reg = PCM1796_OS_128;
542 else if (data->current_rate <= 48000 && data->os_128)
543 reg = PCM1796_OS_128;
544 else if (data->current_rate <= 96000 || data->os_128)
545 reg = PCM1796_OS_64;
546 else 567 else
547 reg = PCM1796_OS_32; 568 reg = PCM1796_OS_64;
548 for (i = 0; i < data->dacs; ++i) 569 for (i = 0; i < data->dacs; ++i)
549 pcm1796_write_cached(chip, i, 20, reg); 570 pcm1796_write_cached(chip, i, 20, reg);
550} 571}
@@ -554,6 +575,7 @@ static void set_pcm1796_params(struct oxygen *chip,
554{ 575{
555 struct xonar_pcm179x *data = chip->model_data; 576 struct xonar_pcm179x *data = chip->model_data;
556 577
578 msleep(1);
557 data->current_rate = params_rate(params); 579 data->current_rate = params_rate(params);
558 update_pcm1796_oversampling(chip); 580 update_pcm1796_oversampling(chip);
559} 581}
@@ -570,6 +592,7 @@ static void update_pcm1796_volume(struct oxygen *chip)
570 + gain_offset); 592 + gain_offset);
571 pcm1796_write_cached(chip, i, 17, chip->dac_volume[i * 2 + 1] 593 pcm1796_write_cached(chip, i, 17, chip->dac_volume[i * 2 + 1]
572 + gain_offset); 594 + gain_offset);
595 gain_offset = 0;
573 } 596 }
574} 597}
575 598
@@ -579,7 +602,7 @@ static void update_pcm1796_mute(struct oxygen *chip)
579 unsigned int i; 602 unsigned int i;
580 u8 value; 603 u8 value;
581 604
582 value = PCM1796_DMF_DISABLED | PCM1796_FMT_24_LJUST | PCM1796_ATLD; 605 value = PCM1796_DMF_DISABLED | PCM1796_FMT_24_I2S | PCM1796_ATLD;
583 if (chip->dac_mute) 606 if (chip->dac_mute)
584 value |= PCM1796_MUTE; 607 value |= PCM1796_MUTE;
585 for (i = 0; i < data->dacs; ++i) 608 for (i = 0; i < data->dacs; ++i)
@@ -592,45 +615,35 @@ static void update_cs2000_rate(struct oxygen *chip, unsigned int rate)
592 u8 rate_mclk, reg; 615 u8 rate_mclk, reg;
593 616
594 switch (rate) { 617 switch (rate) {
595 /* XXX Why is the I2S A MCLK half the actual I2S MCLK? */
596 case 32000: 618 case 32000:
597 rate_mclk = OXYGEN_RATE_32000 | OXYGEN_I2S_MCLK_256;
598 break;
599 case 44100:
600 if (data->os_128)
601 rate_mclk = OXYGEN_RATE_44100 | OXYGEN_I2S_MCLK_256;
602 else
603 rate_mclk = OXYGEN_RATE_44100 | OXYGEN_I2S_MCLK_128;
604 break;
605 default: /* 48000 */
606 if (data->os_128)
607 rate_mclk = OXYGEN_RATE_48000 | OXYGEN_I2S_MCLK_256;
608 else
609 rate_mclk = OXYGEN_RATE_48000 | OXYGEN_I2S_MCLK_128;
610 break;
611 case 64000: 619 case 64000:
612 rate_mclk = OXYGEN_RATE_32000 | OXYGEN_I2S_MCLK_256; 620 rate_mclk = OXYGEN_RATE_32000;
613 break; 621 break;
622 case 44100:
614 case 88200: 623 case 88200:
615 rate_mclk = OXYGEN_RATE_44100 | OXYGEN_I2S_MCLK_256;
616 break;
617 case 96000:
618 rate_mclk = OXYGEN_RATE_48000 | OXYGEN_I2S_MCLK_256;
619 break;
620 case 176400: 624 case 176400:
621 rate_mclk = OXYGEN_RATE_44100 | OXYGEN_I2S_MCLK_256; 625 rate_mclk = OXYGEN_RATE_44100;
622 break; 626 break;
627 default:
628 case 48000:
629 case 96000:
623 case 192000: 630 case 192000:
624 rate_mclk = OXYGEN_RATE_48000 | OXYGEN_I2S_MCLK_256; 631 rate_mclk = OXYGEN_RATE_48000;
625 break; 632 break;
626 } 633 }
627 oxygen_write16_masked(chip, OXYGEN_I2S_A_FORMAT, rate_mclk, 634
628 OXYGEN_I2S_RATE_MASK | OXYGEN_I2S_MCLK_MASK); 635 if (rate <= 96000 && (rate > 48000 || data->h6)) {
629 if ((rate_mclk & OXYGEN_I2S_MCLK_MASK) <= OXYGEN_I2S_MCLK_128) 636 rate_mclk |= OXYGEN_I2S_MCLK(MCLK_256);
630 reg = CS2000_REF_CLK_DIV_1; 637 reg = CS2000_REF_CLK_DIV_1;
631 else 638 } else {
639 rate_mclk |= OXYGEN_I2S_MCLK(MCLK_512);
632 reg = CS2000_REF_CLK_DIV_2; 640 reg = CS2000_REF_CLK_DIV_2;
641 }
642
643 oxygen_write16_masked(chip, OXYGEN_I2S_A_FORMAT, rate_mclk,
644 OXYGEN_I2S_RATE_MASK | OXYGEN_I2S_MCLK_MASK);
633 cs2000_write_cached(chip, CS2000_FUN_CFG_1, reg); 645 cs2000_write_cached(chip, CS2000_FUN_CFG_1, reg);
646 msleep(3); /* PLL lock delay */
634} 647}
635 648
636static void set_st_params(struct oxygen *chip, 649static void set_st_params(struct oxygen *chip,
@@ -665,13 +678,7 @@ static int rolloff_info(struct snd_kcontrol *ctl,
665 "Sharp Roll-off", "Slow Roll-off" 678 "Sharp Roll-off", "Slow Roll-off"
666 }; 679 };
667 680
668 info->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; 681 return snd_ctl_enum_info(info, 1, 2, names);
669 info->count = 1;
670 info->value.enumerated.items = 2;
671 if (info->value.enumerated.item >= 2)
672 info->value.enumerated.item = 1;
673 strcpy(info->value.enumerated.name, names[info->value.enumerated.item]);
674 return 0;
675} 682}
676 683
677static int rolloff_get(struct snd_kcontrol *ctl, 684static int rolloff_get(struct snd_kcontrol *ctl,
@@ -719,57 +726,13 @@ static const struct snd_kcontrol_new rolloff_control = {
719 .put = rolloff_put, 726 .put = rolloff_put,
720}; 727};
721 728
722static int os_128_info(struct snd_kcontrol *ctl, struct snd_ctl_elem_info *info) 729static const struct snd_kcontrol_new hdav_hdmi_control = {
723{
724 static const char *const names[2] = { "64x", "128x" };
725
726 info->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
727 info->count = 1;
728 info->value.enumerated.items = 2;
729 if (info->value.enumerated.item >= 2)
730 info->value.enumerated.item = 1;
731 strcpy(info->value.enumerated.name, names[info->value.enumerated.item]);
732 return 0;
733}
734
735static int os_128_get(struct snd_kcontrol *ctl,
736 struct snd_ctl_elem_value *value)
737{
738 struct oxygen *chip = ctl->private_data;
739 struct xonar_pcm179x *data = chip->model_data;
740
741 value->value.enumerated.item[0] = data->os_128;
742 return 0;
743}
744
745static int os_128_put(struct snd_kcontrol *ctl,
746 struct snd_ctl_elem_value *value)
747{
748 struct oxygen *chip = ctl->private_data;
749 struct xonar_pcm179x *data = chip->model_data;
750 int changed;
751
752 mutex_lock(&chip->mutex);
753 changed = value->value.enumerated.item[0] != data->os_128;
754 if (changed) {
755 data->os_128 = value->value.enumerated.item[0];
756 if (data->has_cs2000)
757 update_cs2000_rate(chip, data->current_rate);
758 oxygen_write16_masked(chip, OXYGEN_I2S_MULTICH_FORMAT,
759 mclk_from_rate(chip, data->current_rate),
760 OXYGEN_I2S_MCLK_MASK);
761 update_pcm1796_oversampling(chip);
762 }
763 mutex_unlock(&chip->mutex);
764 return changed;
765}
766
767static const struct snd_kcontrol_new os_128_control = {
768 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 730 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
769 .name = "DAC Oversampling Playback Enum", 731 .name = "HDMI Playback Switch",
770 .info = os_128_info, 732 .info = snd_ctl_boolean_mono_info,
771 .get = os_128_get, 733 .get = xonar_gpio_bit_switch_get,
772 .put = os_128_put, 734 .put = xonar_gpio_bit_switch_put,
735 .private_value = GPIO_HDAV_OUTPUT_ENABLE | XONAR_GPIO_BIT_INVERT,
773}; 736};
774 737
775static int st_output_switch_info(struct snd_kcontrol *ctl, 738static int st_output_switch_info(struct snd_kcontrol *ctl,
@@ -779,13 +742,7 @@ static int st_output_switch_info(struct snd_kcontrol *ctl,
779 "Speakers", "Headphones", "FP Headphones" 742 "Speakers", "Headphones", "FP Headphones"
780 }; 743 };
781 744
782 info->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; 745 return snd_ctl_enum_info(info, 1, 3, names);
783 info->count = 1;
784 info->value.enumerated.items = 3;
785 if (info->value.enumerated.item >= 3)
786 info->value.enumerated.item = 2;
787 strcpy(info->value.enumerated.name, names[info->value.enumerated.item]);
788 return 0;
789} 746}
790 747
791static int st_output_switch_get(struct snd_kcontrol *ctl, 748static int st_output_switch_get(struct snd_kcontrol *ctl,
@@ -840,13 +797,7 @@ static int st_hp_volume_offset_info(struct snd_kcontrol *ctl,
840 "< 64 ohms", "64-300 ohms", "300-600 ohms" 797 "< 64 ohms", "64-300 ohms", "300-600 ohms"
841 }; 798 };
842 799
843 info->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; 800 return snd_ctl_enum_info(info, 1, 3, names);
844 info->count = 1;
845 info->value.enumerated.items = 3;
846 if (info->value.enumerated.item > 2)
847 info->value.enumerated.item = 2;
848 strcpy(info->value.enumerated.name, names[info->value.enumerated.item]);
849 return 0;
850} 801}
851 802
852static int st_hp_volume_offset_get(struct snd_kcontrol *ctl, 803static int st_hp_volume_offset_get(struct snd_kcontrol *ctl,
@@ -928,16 +879,25 @@ static int xonar_d2_control_filter(struct snd_kcontrol_new *template)
928 return 0; 879 return 0;
929} 880}
930 881
882static int xonar_st_h6_control_filter(struct snd_kcontrol_new *template)
883{
884 if (!strncmp(template->name, "Master Playback ", 16))
885 /* no volume/mute, as I²C to the third DAC does not work */
886 return 1;
887 return 0;
888}
889
931static int add_pcm1796_controls(struct oxygen *chip) 890static int add_pcm1796_controls(struct oxygen *chip)
932{ 891{
892 struct xonar_pcm179x *data = chip->model_data;
933 int err; 893 int err;
934 894
935 err = snd_ctl_add(chip->card, snd_ctl_new1(&rolloff_control, chip)); 895 if (!data->broken_i2c) {
936 if (err < 0) 896 err = snd_ctl_add(chip->card,
937 return err; 897 snd_ctl_new1(&rolloff_control, chip));
938 err = snd_ctl_add(chip->card, snd_ctl_new1(&os_128_control, chip)); 898 if (err < 0)
939 if (err < 0) 899 return err;
940 return err; 900 }
941 return 0; 901 return 0;
942} 902}
943 903
@@ -956,7 +916,15 @@ static int xonar_d2_mixer_init(struct oxygen *chip)
956 916
957static int xonar_hdav_mixer_init(struct oxygen *chip) 917static int xonar_hdav_mixer_init(struct oxygen *chip)
958{ 918{
959 return add_pcm1796_controls(chip); 919 int err;
920
921 err = snd_ctl_add(chip->card, snd_ctl_new1(&hdav_hdmi_control, chip));
922 if (err < 0)
923 return err;
924 err = add_pcm1796_controls(chip);
925 if (err < 0)
926 return err;
927 return 0;
960} 928}
961 929
962static int xonar_st_mixer_init(struct oxygen *chip) 930static int xonar_st_mixer_init(struct oxygen *chip)
@@ -976,6 +944,45 @@ static int xonar_st_mixer_init(struct oxygen *chip)
976 return 0; 944 return 0;
977} 945}
978 946
947static void dump_pcm1796_registers(struct oxygen *chip,
948 struct snd_info_buffer *buffer)
949{
950 struct xonar_pcm179x *data = chip->model_data;
951 unsigned int dac, i;
952
953 for (dac = 0; dac < data->dacs; ++dac) {
954 snd_iprintf(buffer, "\nPCM1796 %u:", dac + 1);
955 for (i = 0; i < 5; ++i)
956 snd_iprintf(buffer, " %02x",
957 data->pcm1796_regs[dac][i]);
958 }
959 snd_iprintf(buffer, "\n");
960}
961
962static void dump_cs2000_registers(struct oxygen *chip,
963 struct snd_info_buffer *buffer)
964{
965 struct xonar_pcm179x *data = chip->model_data;
966 unsigned int i;
967
968 if (data->has_cs2000) {
969 snd_iprintf(buffer, "\nCS2000:\n00: ");
970 for (i = 1; i < 0x10; ++i)
971 snd_iprintf(buffer, " %02x", data->cs2000_regs[i]);
972 snd_iprintf(buffer, "\n10:");
973 for (i = 0x10; i < 0x1f; ++i)
974 snd_iprintf(buffer, " %02x", data->cs2000_regs[i]);
975 snd_iprintf(buffer, "\n");
976 }
977}
978
979static void dump_st_registers(struct oxygen *chip,
980 struct snd_info_buffer *buffer)
981{
982 dump_pcm1796_registers(chip, buffer);
983 dump_cs2000_registers(chip, buffer);
984}
985
979static const struct oxygen_model model_xonar_d2 = { 986static const struct oxygen_model model_xonar_d2 = {
980 .longname = "Asus Virtuoso 200", 987 .longname = "Asus Virtuoso 200",
981 .chip = "AV200", 988 .chip = "AV200",
@@ -985,11 +992,11 @@ static const struct oxygen_model model_xonar_d2 = {
985 .cleanup = xonar_d2_cleanup, 992 .cleanup = xonar_d2_cleanup,
986 .suspend = xonar_d2_suspend, 993 .suspend = xonar_d2_suspend,
987 .resume = xonar_d2_resume, 994 .resume = xonar_d2_resume,
988 .get_i2s_mclk = get_pcm1796_i2s_mclk,
989 .set_dac_params = set_pcm1796_params, 995 .set_dac_params = set_pcm1796_params,
990 .set_adc_params = xonar_set_cs53x1_params, 996 .set_adc_params = xonar_set_cs53x1_params,
991 .update_dac_volume = update_pcm1796_volume, 997 .update_dac_volume = update_pcm1796_volume,
992 .update_dac_mute = update_pcm1796_mute, 998 .update_dac_mute = update_pcm1796_mute,
999 .dump_registers = dump_pcm1796_registers,
993 .dac_tlv = pcm1796_db_scale, 1000 .dac_tlv = pcm1796_db_scale,
994 .model_data_size = sizeof(struct xonar_pcm179x), 1001 .model_data_size = sizeof(struct xonar_pcm179x),
995 .device_config = PLAYBACK_0_TO_I2S | 1002 .device_config = PLAYBACK_0_TO_I2S |
@@ -999,13 +1006,16 @@ static const struct oxygen_model model_xonar_d2 = {
999 MIDI_OUTPUT | 1006 MIDI_OUTPUT |
1000 MIDI_INPUT | 1007 MIDI_INPUT |
1001 AC97_CD_INPUT, 1008 AC97_CD_INPUT,
1002 .dac_channels = 8, 1009 .dac_channels_pcm = 8,
1010 .dac_channels_mixer = 8,
1003 .dac_volume_min = 255 - 2*60, 1011 .dac_volume_min = 255 - 2*60,
1004 .dac_volume_max = 255, 1012 .dac_volume_max = 255,
1005 .misc_flags = OXYGEN_MISC_MIDI, 1013 .misc_flags = OXYGEN_MISC_MIDI,
1006 .function_flags = OXYGEN_FUNCTION_SPI | 1014 .function_flags = OXYGEN_FUNCTION_SPI |
1007 OXYGEN_FUNCTION_ENABLE_SPI_4_5, 1015 OXYGEN_FUNCTION_ENABLE_SPI_4_5,
1008 .dac_i2s_format = OXYGEN_I2S_FORMAT_LJUST, 1016 .dac_mclks = OXYGEN_MCLKS(512, 128, 128),
1017 .adc_mclks = OXYGEN_MCLKS(256, 128, 128),
1018 .dac_i2s_format = OXYGEN_I2S_FORMAT_I2S,
1009 .adc_i2s_format = OXYGEN_I2S_FORMAT_LJUST, 1019 .adc_i2s_format = OXYGEN_I2S_FORMAT_LJUST,
1010}; 1020};
1011 1021
@@ -1018,25 +1028,28 @@ static const struct oxygen_model model_xonar_hdav = {
1018 .suspend = xonar_hdav_suspend, 1028 .suspend = xonar_hdav_suspend,
1019 .resume = xonar_hdav_resume, 1029 .resume = xonar_hdav_resume,
1020 .pcm_hardware_filter = xonar_hdmi_pcm_hardware_filter, 1030 .pcm_hardware_filter = xonar_hdmi_pcm_hardware_filter,
1021 .get_i2s_mclk = get_pcm1796_i2s_mclk,
1022 .set_dac_params = set_hdav_params, 1031 .set_dac_params = set_hdav_params,
1023 .set_adc_params = xonar_set_cs53x1_params, 1032 .set_adc_params = xonar_set_cs53x1_params,
1024 .update_dac_volume = update_pcm1796_volume, 1033 .update_dac_volume = update_pcm1796_volume,
1025 .update_dac_mute = update_pcm1796_mute, 1034 .update_dac_mute = update_pcm1796_mute,
1026 .uart_input = xonar_hdmi_uart_input, 1035 .uart_input = xonar_hdmi_uart_input,
1027 .ac97_switch = xonar_line_mic_ac97_switch, 1036 .ac97_switch = xonar_line_mic_ac97_switch,
1037 .dump_registers = dump_pcm1796_registers,
1028 .dac_tlv = pcm1796_db_scale, 1038 .dac_tlv = pcm1796_db_scale,
1029 .model_data_size = sizeof(struct xonar_hdav), 1039 .model_data_size = sizeof(struct xonar_hdav),
1030 .device_config = PLAYBACK_0_TO_I2S | 1040 .device_config = PLAYBACK_0_TO_I2S |
1031 PLAYBACK_1_TO_SPDIF | 1041 PLAYBACK_1_TO_SPDIF |
1032 CAPTURE_0_FROM_I2S_2 | 1042 CAPTURE_0_FROM_I2S_2 |
1033 CAPTURE_1_FROM_SPDIF, 1043 CAPTURE_1_FROM_SPDIF,
1034 .dac_channels = 8, 1044 .dac_channels_pcm = 8,
1045 .dac_channels_mixer = 2,
1035 .dac_volume_min = 255 - 2*60, 1046 .dac_volume_min = 255 - 2*60,
1036 .dac_volume_max = 255, 1047 .dac_volume_max = 255,
1037 .misc_flags = OXYGEN_MISC_MIDI, 1048 .misc_flags = OXYGEN_MISC_MIDI,
1038 .function_flags = OXYGEN_FUNCTION_2WIRE, 1049 .function_flags = OXYGEN_FUNCTION_2WIRE,
1039 .dac_i2s_format = OXYGEN_I2S_FORMAT_LJUST, 1050 .dac_mclks = OXYGEN_MCLKS(512, 128, 128),
1051 .adc_mclks = OXYGEN_MCLKS(256, 128, 128),
1052 .dac_i2s_format = OXYGEN_I2S_FORMAT_I2S,
1040 .adc_i2s_format = OXYGEN_I2S_FORMAT_LJUST, 1053 .adc_i2s_format = OXYGEN_I2S_FORMAT_LJUST,
1041}; 1054};
1042 1055
@@ -1048,22 +1061,26 @@ static const struct oxygen_model model_xonar_st = {
1048 .cleanup = xonar_st_cleanup, 1061 .cleanup = xonar_st_cleanup,
1049 .suspend = xonar_st_suspend, 1062 .suspend = xonar_st_suspend,
1050 .resume = xonar_st_resume, 1063 .resume = xonar_st_resume,
1051 .get_i2s_mclk = get_pcm1796_i2s_mclk,
1052 .set_dac_params = set_st_params, 1064 .set_dac_params = set_st_params,
1053 .set_adc_params = xonar_set_cs53x1_params, 1065 .set_adc_params = xonar_set_cs53x1_params,
1054 .update_dac_volume = update_pcm1796_volume, 1066 .update_dac_volume = update_pcm1796_volume,
1055 .update_dac_mute = update_pcm1796_mute, 1067 .update_dac_mute = update_pcm1796_mute,
1056 .ac97_switch = xonar_line_mic_ac97_switch, 1068 .ac97_switch = xonar_line_mic_ac97_switch,
1069 .dump_registers = dump_st_registers,
1057 .dac_tlv = pcm1796_db_scale, 1070 .dac_tlv = pcm1796_db_scale,
1058 .model_data_size = sizeof(struct xonar_pcm179x), 1071 .model_data_size = sizeof(struct xonar_pcm179x),
1059 .device_config = PLAYBACK_0_TO_I2S | 1072 .device_config = PLAYBACK_0_TO_I2S |
1060 PLAYBACK_1_TO_SPDIF | 1073 PLAYBACK_1_TO_SPDIF |
1061 CAPTURE_0_FROM_I2S_2, 1074 CAPTURE_0_FROM_I2S_2 |
1062 .dac_channels = 2, 1075 AC97_FMIC_SWITCH,
1076 .dac_channels_pcm = 2,
1077 .dac_channels_mixer = 2,
1063 .dac_volume_min = 255 - 2*60, 1078 .dac_volume_min = 255 - 2*60,
1064 .dac_volume_max = 255, 1079 .dac_volume_max = 255,
1065 .function_flags = OXYGEN_FUNCTION_2WIRE, 1080 .function_flags = OXYGEN_FUNCTION_2WIRE,
1066 .dac_i2s_format = OXYGEN_I2S_FORMAT_LJUST, 1081 .dac_mclks = OXYGEN_MCLKS(512, 128, 128),
1082 .adc_mclks = OXYGEN_MCLKS(256, 128, 128),
1083 .dac_i2s_format = OXYGEN_I2S_FORMAT_I2S,
1067 .adc_i2s_format = OXYGEN_I2S_FORMAT_LJUST, 1084 .adc_i2s_format = OXYGEN_I2S_FORMAT_LJUST,
1068}; 1085};
1069 1086
@@ -1089,7 +1106,8 @@ int __devinit get_xonar_pcm179x_model(struct oxygen *chip,
1089 break; 1106 break;
1090 case GPIO_DB_H6: 1107 case GPIO_DB_H6:
1091 chip->model.shortname = "Xonar HDAV1.3+H6"; 1108 chip->model.shortname = "Xonar HDAV1.3+H6";
1092 chip->model.private_data = 1; 1109 chip->model.dac_channels_mixer = 8;
1110 chip->model.dac_mclks = OXYGEN_MCLKS(256, 128, 128);
1093 break; 1111 break;
1094 } 1112 }
1095 break; 1113 break;
@@ -1102,8 +1120,10 @@ int __devinit get_xonar_pcm179x_model(struct oxygen *chip,
1102 break; 1120 break;
1103 case GPIO_DB_H6: 1121 case GPIO_DB_H6:
1104 chip->model.shortname = "Xonar ST+H6"; 1122 chip->model.shortname = "Xonar ST+H6";
1105 chip->model.dac_channels = 8; 1123 chip->model.control_filter = xonar_st_h6_control_filter;
1106 chip->model.private_data = 1; 1124 chip->model.dac_channels_pcm = 8;
1125 chip->model.dac_channels_mixer = 8;
1126 chip->model.dac_mclks = OXYGEN_MCLKS(256, 128, 128);
1107 break; 1127 break;
1108 } 1128 }
1109 break; 1129 break;
@@ -1114,9 +1134,6 @@ int __devinit get_xonar_pcm179x_model(struct oxygen *chip,
1114 chip->model.resume = xonar_stx_resume; 1134 chip->model.resume = xonar_stx_resume;
1115 chip->model.set_dac_params = set_pcm1796_params; 1135 chip->model.set_dac_params = set_pcm1796_params;
1116 break; 1136 break;
1117 case 0x835e:
1118 snd_printk(KERN_ERR "the HDAV1.3 Slim is not supported\n");
1119 return -ENODEV;
1120 default: 1137 default:
1121 return -EINVAL; 1138 return -EINVAL;
1122 } 1139 }
diff --git a/sound/pci/oxygen/xonar_wm87x6.c b/sound/pci/oxygen/xonar_wm87x6.c
index 200f7601276f..42d1ab136217 100644
--- a/sound/pci/oxygen/xonar_wm87x6.c
+++ b/sound/pci/oxygen/xonar_wm87x6.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * card driver for models with WM8776/WM8766 DACs (Xonar DS) 2 * card driver for models with WM8776/WM8766 DACs (Xonar DS/HDAV1.3 Slim)
3 * 3 *
4 * Copyright (c) Clemens Ladisch <clemens@ladisch.de> 4 * Copyright (c) Clemens Ladisch <clemens@ladisch.de>
5 * 5 *
@@ -22,26 +22,48 @@
22 * 22 *
23 * CMI8788: 23 * CMI8788:
24 * 24 *
25 * SPI 0 -> WM8766 (surround, center/LFE, back) 25 * SPI 0 -> WM8766 (surround, center/LFE, back)
26 * SPI 1 -> WM8776 (front, input) 26 * SPI 1 -> WM8776 (front, input)
27 * 27 *
28 * GPIO 4 <- headphone detect, 0 = plugged 28 * GPIO 4 <- headphone detect, 0 = plugged
29 * GPIO 6 -> route input jack to mic-in (0) or line-in (1) 29 * GPIO 6 -> route input jack to mic-in (0) or line-in (1)
30 * GPIO 7 -> enable output to front L/R speaker channels 30 * GPIO 7 -> enable output to front L/R speaker channels
31 * GPIO 8 -> enable output to other speaker channels and front panel headphone 31 * GPIO 8 -> enable output to other speaker channels and front panel headphone
32 * 32 *
33 * WM8766: 33 * WM8776:
34 * 34 *
35 * input 1 <- line 35 * input 1 <- line
36 * input 2 <- mic 36 * input 2 <- mic
37 * input 3 <- front mic 37 * input 3 <- front mic
38 * input 4 <- aux 38 * input 4 <- aux
39 */
40
41/*
42 * Xonar HDAV1.3 Slim
43 * ------------------
44 *
45 * CMI8788:
46 *
47 * I²C <-> WM8776 (addr 0011010)
48 *
49 * GPIO 0 -> disable HDMI output
50 * GPIO 1 -> enable HP output
51 * GPIO 6 -> firmware EEPROM I²C clock
52 * GPIO 7 <-> firmware EEPROM I²C data
53 *
54 * UART <-> HDMI controller
55 *
56 * WM8776:
57 *
58 * input 1 <- mic
59 * input 2 <- aux
39 */ 60 */
40 61
41#include <linux/pci.h> 62#include <linux/pci.h>
42#include <linux/delay.h> 63#include <linux/delay.h>
43#include <sound/control.h> 64#include <sound/control.h>
44#include <sound/core.h> 65#include <sound/core.h>
66#include <sound/info.h>
45#include <sound/jack.h> 67#include <sound/jack.h>
46#include <sound/pcm.h> 68#include <sound/pcm.h>
47#include <sound/pcm_params.h> 69#include <sound/pcm_params.h>
@@ -55,6 +77,13 @@
55#define GPIO_DS_OUTPUT_FRONTLR 0x0080 77#define GPIO_DS_OUTPUT_FRONTLR 0x0080
56#define GPIO_DS_OUTPUT_ENABLE 0x0100 78#define GPIO_DS_OUTPUT_ENABLE 0x0100
57 79
80#define GPIO_SLIM_HDMI_DISABLE 0x0001
81#define GPIO_SLIM_OUTPUT_ENABLE 0x0002
82#define GPIO_SLIM_FIRMWARE_CLK 0x0040
83#define GPIO_SLIM_FIRMWARE_DATA 0x0080
84
85#define I2C_DEVICE_WM8776 0x34 /* 001101, 0, /W=0 */
86
58#define LC_CONTROL_LIMITER 0x40000000 87#define LC_CONTROL_LIMITER 0x40000000
59#define LC_CONTROL_ALC 0x20000000 88#define LC_CONTROL_ALC 0x20000000
60 89
@@ -66,19 +95,37 @@ struct xonar_wm87x6 {
66 struct snd_kcontrol *mic_adcmux_control; 95 struct snd_kcontrol *mic_adcmux_control;
67 struct snd_kcontrol *lc_controls[13]; 96 struct snd_kcontrol *lc_controls[13];
68 struct snd_jack *hp_jack; 97 struct snd_jack *hp_jack;
98 struct xonar_hdmi hdmi;
69}; 99};
70 100
71static void wm8776_write(struct oxygen *chip, 101static void wm8776_write_spi(struct oxygen *chip,
72 unsigned int reg, unsigned int value) 102 unsigned int reg, unsigned int value)
73{ 103{
74 struct xonar_wm87x6 *data = chip->model_data;
75
76 oxygen_write_spi(chip, OXYGEN_SPI_TRIGGER | 104 oxygen_write_spi(chip, OXYGEN_SPI_TRIGGER |
77 OXYGEN_SPI_DATA_LENGTH_2 | 105 OXYGEN_SPI_DATA_LENGTH_2 |
78 OXYGEN_SPI_CLOCK_160 | 106 OXYGEN_SPI_CLOCK_160 |
79 (1 << OXYGEN_SPI_CODEC_SHIFT) | 107 (1 << OXYGEN_SPI_CODEC_SHIFT) |
80 OXYGEN_SPI_CEN_LATCH_CLOCK_LO, 108 OXYGEN_SPI_CEN_LATCH_CLOCK_LO,
81 (reg << 9) | value); 109 (reg << 9) | value);
110}
111
112static void wm8776_write_i2c(struct oxygen *chip,
113 unsigned int reg, unsigned int value)
114{
115 oxygen_write_i2c(chip, I2C_DEVICE_WM8776,
116 (reg << 1) | (value >> 8), value);
117}
118
119static void wm8776_write(struct oxygen *chip,
120 unsigned int reg, unsigned int value)
121{
122 struct xonar_wm87x6 *data = chip->model_data;
123
124 if ((chip->model.function_flags & OXYGEN_FUNCTION_2WIRE_SPI_MASK) ==
125 OXYGEN_FUNCTION_SPI)
126 wm8776_write_spi(chip, reg, value);
127 else
128 wm8776_write_i2c(chip, reg, value);
82 if (reg < ARRAY_SIZE(data->wm8776_regs)) { 129 if (reg < ARRAY_SIZE(data->wm8776_regs)) {
83 if (reg >= WM8776_HPLVOL && reg <= WM8776_DACMASTER) 130 if (reg >= WM8776_HPLVOL && reg <= WM8776_DACMASTER)
84 value &= ~WM8776_UPDATE; 131 value &= ~WM8776_UPDATE;
@@ -245,17 +292,50 @@ static void xonar_ds_init(struct oxygen *chip)
245 snd_component_add(chip->card, "WM8766"); 292 snd_component_add(chip->card, "WM8766");
246} 293}
247 294
295static void xonar_hdav_slim_init(struct oxygen *chip)
296{
297 struct xonar_wm87x6 *data = chip->model_data;
298
299 data->generic.anti_pop_delay = 300;
300 data->generic.output_enable_bit = GPIO_SLIM_OUTPUT_ENABLE;
301
302 wm8776_init(chip);
303
304 oxygen_set_bits16(chip, OXYGEN_GPIO_CONTROL,
305 GPIO_SLIM_HDMI_DISABLE |
306 GPIO_SLIM_FIRMWARE_CLK |
307 GPIO_SLIM_FIRMWARE_DATA);
308
309 xonar_hdmi_init(chip, &data->hdmi);
310 xonar_enable_output(chip);
311
312 snd_component_add(chip->card, "WM8776");
313}
314
248static void xonar_ds_cleanup(struct oxygen *chip) 315static void xonar_ds_cleanup(struct oxygen *chip)
249{ 316{
250 xonar_disable_output(chip); 317 xonar_disable_output(chip);
251 wm8776_write(chip, WM8776_RESET, 0); 318 wm8776_write(chip, WM8776_RESET, 0);
252} 319}
253 320
321static void xonar_hdav_slim_cleanup(struct oxygen *chip)
322{
323 xonar_hdmi_cleanup(chip);
324 xonar_disable_output(chip);
325 wm8776_write(chip, WM8776_RESET, 0);
326 msleep(2);
327}
328
254static void xonar_ds_suspend(struct oxygen *chip) 329static void xonar_ds_suspend(struct oxygen *chip)
255{ 330{
256 xonar_ds_cleanup(chip); 331 xonar_ds_cleanup(chip);
257} 332}
258 333
334static void xonar_hdav_slim_suspend(struct oxygen *chip)
335{
336 xonar_hdav_slim_cleanup(chip);
337}
338
259static void xonar_ds_resume(struct oxygen *chip) 339static void xonar_ds_resume(struct oxygen *chip)
260{ 340{
261 wm8776_registers_init(chip); 341 wm8776_registers_init(chip);
@@ -264,6 +344,15 @@ static void xonar_ds_resume(struct oxygen *chip)
264 xonar_ds_handle_hp_jack(chip); 344 xonar_ds_handle_hp_jack(chip);
265} 345}
266 346
347static void xonar_hdav_slim_resume(struct oxygen *chip)
348{
349 struct xonar_wm87x6 *data = chip->model_data;
350
351 wm8776_registers_init(chip);
352 xonar_hdmi_resume(chip, &data->hdmi);
353 xonar_enable_output(chip);
354}
355
267static void wm8776_adc_hardware_filter(unsigned int channel, 356static void wm8776_adc_hardware_filter(unsigned int channel,
268 struct snd_pcm_hardware *hardware) 357 struct snd_pcm_hardware *hardware)
269{ 358{
@@ -278,6 +367,13 @@ static void wm8776_adc_hardware_filter(unsigned int channel,
278 } 367 }
279} 368}
280 369
370static void xonar_hdav_slim_hardware_filter(unsigned int channel,
371 struct snd_pcm_hardware *hardware)
372{
373 wm8776_adc_hardware_filter(channel, hardware);
374 xonar_hdmi_pcm_hardware_filter(channel, hardware);
375}
376
281static void set_wm87x6_dac_params(struct oxygen *chip, 377static void set_wm87x6_dac_params(struct oxygen *chip,
282 struct snd_pcm_hw_params *params) 378 struct snd_pcm_hw_params *params)
283{ 379{
@@ -294,6 +390,14 @@ static void set_wm8776_adc_params(struct oxygen *chip,
294 wm8776_write_cached(chip, WM8776_MSTRCTRL, reg); 390 wm8776_write_cached(chip, WM8776_MSTRCTRL, reg);
295} 391}
296 392
393static void set_hdav_slim_dac_params(struct oxygen *chip,
394 struct snd_pcm_hw_params *params)
395{
396 struct xonar_wm87x6 *data = chip->model_data;
397
398 xonar_set_hdmi_params(chip, &data->hdmi, params);
399}
400
297static void update_wm8776_volume(struct oxygen *chip) 401static void update_wm8776_volume(struct oxygen *chip)
298{ 402{
299 struct xonar_wm87x6 *data = chip->model_data; 403 struct xonar_wm87x6 *data = chip->model_data;
@@ -473,11 +577,6 @@ static int wm8776_field_enum_info(struct snd_kcontrol *ctl,
473 const char *const *names; 577 const char *const *names;
474 578
475 max = (ctl->private_value >> 12) & 0xf; 579 max = (ctl->private_value >> 12) & 0xf;
476 info->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
477 info->count = 1;
478 info->value.enumerated.items = max + 1;
479 if (info->value.enumerated.item > max)
480 info->value.enumerated.item = max;
481 switch ((ctl->private_value >> 24) & 0x1f) { 580 switch ((ctl->private_value >> 24) & 0x1f) {
482 case WM8776_ALCCTRL2: 581 case WM8776_ALCCTRL2:
483 names = hld; 582 names = hld;
@@ -501,8 +600,7 @@ static int wm8776_field_enum_info(struct snd_kcontrol *ctl,
501 default: 600 default:
502 return -ENXIO; 601 return -ENXIO;
503 } 602 }
504 strcpy(info->value.enumerated.name, names[info->value.enumerated.item]); 603 return snd_ctl_enum_info(info, 1, max + 1, names);
505 return 0;
506} 604}
507 605
508static int wm8776_field_volume_info(struct snd_kcontrol *ctl, 606static int wm8776_field_volume_info(struct snd_kcontrol *ctl,
@@ -759,13 +857,8 @@ static int wm8776_level_control_info(struct snd_kcontrol *ctl,
759 static const char *const names[3] = { 857 static const char *const names[3] = {
760 "None", "Peak Limiter", "Automatic Level Control" 858 "None", "Peak Limiter", "Automatic Level Control"
761 }; 859 };
762 info->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; 860
763 info->count = 1; 861 return snd_ctl_enum_info(info, 1, 3, names);
764 info->value.enumerated.items = 3;
765 if (info->value.enumerated.item >= 3)
766 info->value.enumerated.item = 2;
767 strcpy(info->value.enumerated.name, names[info->value.enumerated.item]);
768 return 0;
769} 862}
770 863
771static int wm8776_level_control_get(struct snd_kcontrol *ctl, 864static int wm8776_level_control_get(struct snd_kcontrol *ctl,
@@ -851,13 +944,7 @@ static int hpf_info(struct snd_kcontrol *ctl, struct snd_ctl_elem_info *info)
851 "None", "High-pass Filter" 944 "None", "High-pass Filter"
852 }; 945 };
853 946
854 info->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; 947 return snd_ctl_enum_info(info, 1, 2, names);
855 info->count = 1;
856 info->value.enumerated.items = 2;
857 if (info->value.enumerated.item >= 2)
858 info->value.enumerated.item = 1;
859 strcpy(info->value.enumerated.name, names[info->value.enumerated.item]);
860 return 0;
861} 948}
862 949
863static int hpf_get(struct snd_kcontrol *ctl, struct snd_ctl_elem_value *value) 950static int hpf_get(struct snd_kcontrol *ctl, struct snd_ctl_elem_value *value)
@@ -985,6 +1072,53 @@ static const struct snd_kcontrol_new ds_controls[] = {
985 .private_value = 0, 1072 .private_value = 0,
986 }, 1073 },
987}; 1074};
1075static const struct snd_kcontrol_new hdav_slim_controls[] = {
1076 {
1077 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1078 .name = "HDMI Playback Switch",
1079 .info = snd_ctl_boolean_mono_info,
1080 .get = xonar_gpio_bit_switch_get,
1081 .put = xonar_gpio_bit_switch_put,
1082 .private_value = GPIO_SLIM_HDMI_DISABLE | XONAR_GPIO_BIT_INVERT,
1083 },
1084 {
1085 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1086 .name = "Headphone Playback Volume",
1087 .info = wm8776_hp_vol_info,
1088 .get = wm8776_hp_vol_get,
1089 .put = wm8776_hp_vol_put,
1090 .tlv = { .p = wm8776_hp_db_scale },
1091 },
1092 WM8776_BIT_SWITCH("Headphone Playback Switch",
1093 WM8776_PWRDOWN, WM8776_HPPD, 1, 0),
1094 {
1095 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1096 .name = "Input Capture Volume",
1097 .info = wm8776_input_vol_info,
1098 .get = wm8776_input_vol_get,
1099 .put = wm8776_input_vol_put,
1100 .tlv = { .p = wm8776_adc_db_scale },
1101 },
1102 WM8776_BIT_SWITCH("Mic Capture Switch",
1103 WM8776_ADCMUX, 1 << 0, 0, 0),
1104 WM8776_BIT_SWITCH("Aux Capture Switch",
1105 WM8776_ADCMUX, 1 << 1, 0, 0),
1106 {
1107 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1108 .name = "ADC Filter Capture Enum",
1109 .info = hpf_info,
1110 .get = hpf_get,
1111 .put = hpf_put,
1112 },
1113 {
1114 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1115 .name = "Level Control Capture Enum",
1116 .info = wm8776_level_control_info,
1117 .get = wm8776_level_control_get,
1118 .put = wm8776_level_control_put,
1119 .private_value = 0,
1120 },
1121};
988static const struct snd_kcontrol_new lc_controls[] = { 1122static const struct snd_kcontrol_new lc_controls[] = {
989 WM8776_FIELD_CTL_VOLUME("Limiter Threshold", 1123 WM8776_FIELD_CTL_VOLUME("Limiter Threshold",
990 WM8776_ALCCTRL1, 0, 11, 0, 15, 0xf, 1124 WM8776_ALCCTRL1, 0, 11, 0, 15, 0xf,
@@ -1028,6 +1162,26 @@ static const struct snd_kcontrol_new lc_controls[] = {
1028 LC_CONTROL_ALC, wm8776_ngth_db_scale), 1162 LC_CONTROL_ALC, wm8776_ngth_db_scale),
1029}; 1163};
1030 1164
1165static int add_lc_controls(struct oxygen *chip)
1166{
1167 struct xonar_wm87x6 *data = chip->model_data;
1168 unsigned int i;
1169 struct snd_kcontrol *ctl;
1170 int err;
1171
1172 BUILD_BUG_ON(ARRAY_SIZE(lc_controls) != ARRAY_SIZE(data->lc_controls));
1173 for (i = 0; i < ARRAY_SIZE(lc_controls); ++i) {
1174 ctl = snd_ctl_new1(&lc_controls[i], chip);
1175 if (!ctl)
1176 return -ENOMEM;
1177 err = snd_ctl_add(chip->card, ctl);
1178 if (err < 0)
1179 return err;
1180 data->lc_controls[i] = ctl;
1181 }
1182 return 0;
1183}
1184
1031static int xonar_ds_mixer_init(struct oxygen *chip) 1185static int xonar_ds_mixer_init(struct oxygen *chip)
1032{ 1186{
1033 struct xonar_wm87x6 *data = chip->model_data; 1187 struct xonar_wm87x6 *data = chip->model_data;
@@ -1049,17 +1203,54 @@ static int xonar_ds_mixer_init(struct oxygen *chip)
1049 } 1203 }
1050 if (!data->line_adcmux_control || !data->mic_adcmux_control) 1204 if (!data->line_adcmux_control || !data->mic_adcmux_control)
1051 return -ENXIO; 1205 return -ENXIO;
1052 BUILD_BUG_ON(ARRAY_SIZE(lc_controls) != ARRAY_SIZE(data->lc_controls)); 1206
1053 for (i = 0; i < ARRAY_SIZE(lc_controls); ++i) { 1207 return add_lc_controls(chip);
1054 ctl = snd_ctl_new1(&lc_controls[i], chip); 1208}
1209
1210static int xonar_hdav_slim_mixer_init(struct oxygen *chip)
1211{
1212 unsigned int i;
1213 struct snd_kcontrol *ctl;
1214 int err;
1215
1216 for (i = 0; i < ARRAY_SIZE(hdav_slim_controls); ++i) {
1217 ctl = snd_ctl_new1(&hdav_slim_controls[i], chip);
1055 if (!ctl) 1218 if (!ctl)
1056 return -ENOMEM; 1219 return -ENOMEM;
1057 err = snd_ctl_add(chip->card, ctl); 1220 err = snd_ctl_add(chip->card, ctl);
1058 if (err < 0) 1221 if (err < 0)
1059 return err; 1222 return err;
1060 data->lc_controls[i] = ctl;
1061 } 1223 }
1062 return 0; 1224
1225 return add_lc_controls(chip);
1226}
1227
1228static void dump_wm8776_registers(struct oxygen *chip,
1229 struct snd_info_buffer *buffer)
1230{
1231 struct xonar_wm87x6 *data = chip->model_data;
1232 unsigned int i;
1233
1234 snd_iprintf(buffer, "\nWM8776:\n00:");
1235 for (i = 0; i < 0x10; ++i)
1236 snd_iprintf(buffer, " %03x", data->wm8776_regs[i]);
1237 snd_iprintf(buffer, "\n10:");
1238 for (i = 0x10; i < 0x17; ++i)
1239 snd_iprintf(buffer, " %03x", data->wm8776_regs[i]);
1240 snd_iprintf(buffer, "\n");
1241}
1242
1243static void dump_wm87x6_registers(struct oxygen *chip,
1244 struct snd_info_buffer *buffer)
1245{
1246 struct xonar_wm87x6 *data = chip->model_data;
1247 unsigned int i;
1248
1249 dump_wm8776_registers(chip, buffer);
1250 snd_iprintf(buffer, "\nWM8766:\n00:");
1251 for (i = 0; i < 0x10; ++i)
1252 snd_iprintf(buffer, " %03x", data->wm8766_regs[i]);
1253 snd_iprintf(buffer, "\n");
1063} 1254}
1064 1255
1065static const struct oxygen_model model_xonar_ds = { 1256static const struct oxygen_model model_xonar_ds = {
@@ -1072,22 +1263,57 @@ static const struct oxygen_model model_xonar_ds = {
1072 .suspend = xonar_ds_suspend, 1263 .suspend = xonar_ds_suspend,
1073 .resume = xonar_ds_resume, 1264 .resume = xonar_ds_resume,
1074 .pcm_hardware_filter = wm8776_adc_hardware_filter, 1265 .pcm_hardware_filter = wm8776_adc_hardware_filter,
1075 .get_i2s_mclk = oxygen_default_i2s_mclk,
1076 .set_dac_params = set_wm87x6_dac_params, 1266 .set_dac_params = set_wm87x6_dac_params,
1077 .set_adc_params = set_wm8776_adc_params, 1267 .set_adc_params = set_wm8776_adc_params,
1078 .update_dac_volume = update_wm87x6_volume, 1268 .update_dac_volume = update_wm87x6_volume,
1079 .update_dac_mute = update_wm87x6_mute, 1269 .update_dac_mute = update_wm87x6_mute,
1080 .update_center_lfe_mix = update_wm8766_center_lfe_mix, 1270 .update_center_lfe_mix = update_wm8766_center_lfe_mix,
1081 .gpio_changed = xonar_ds_gpio_changed, 1271 .gpio_changed = xonar_ds_gpio_changed,
1272 .dump_registers = dump_wm87x6_registers,
1082 .dac_tlv = wm87x6_dac_db_scale, 1273 .dac_tlv = wm87x6_dac_db_scale,
1083 .model_data_size = sizeof(struct xonar_wm87x6), 1274 .model_data_size = sizeof(struct xonar_wm87x6),
1084 .device_config = PLAYBACK_0_TO_I2S | 1275 .device_config = PLAYBACK_0_TO_I2S |
1085 PLAYBACK_1_TO_SPDIF | 1276 PLAYBACK_1_TO_SPDIF |
1086 CAPTURE_0_FROM_I2S_1, 1277 CAPTURE_0_FROM_I2S_1,
1087 .dac_channels = 8, 1278 .dac_channels_pcm = 8,
1279 .dac_channels_mixer = 8,
1088 .dac_volume_min = 255 - 2*60, 1280 .dac_volume_min = 255 - 2*60,
1089 .dac_volume_max = 255, 1281 .dac_volume_max = 255,
1090 .function_flags = OXYGEN_FUNCTION_SPI, 1282 .function_flags = OXYGEN_FUNCTION_SPI,
1283 .dac_mclks = OXYGEN_MCLKS(256, 256, 128),
1284 .adc_mclks = OXYGEN_MCLKS(256, 256, 128),
1285 .dac_i2s_format = OXYGEN_I2S_FORMAT_LJUST,
1286 .adc_i2s_format = OXYGEN_I2S_FORMAT_LJUST,
1287};
1288
1289static const struct oxygen_model model_xonar_hdav_slim = {
1290 .shortname = "Xonar HDAV1.3 Slim",
1291 .longname = "Asus Virtuoso 200",
1292 .chip = "AV200",
1293 .init = xonar_hdav_slim_init,
1294 .mixer_init = xonar_hdav_slim_mixer_init,
1295 .cleanup = xonar_hdav_slim_cleanup,
1296 .suspend = xonar_hdav_slim_suspend,
1297 .resume = xonar_hdav_slim_resume,
1298 .pcm_hardware_filter = xonar_hdav_slim_hardware_filter,
1299 .set_dac_params = set_hdav_slim_dac_params,
1300 .set_adc_params = set_wm8776_adc_params,
1301 .update_dac_volume = update_wm8776_volume,
1302 .update_dac_mute = update_wm8776_mute,
1303 .uart_input = xonar_hdmi_uart_input,
1304 .dump_registers = dump_wm8776_registers,
1305 .dac_tlv = wm87x6_dac_db_scale,
1306 .model_data_size = sizeof(struct xonar_wm87x6),
1307 .device_config = PLAYBACK_0_TO_I2S |
1308 PLAYBACK_1_TO_SPDIF |
1309 CAPTURE_0_FROM_I2S_1,
1310 .dac_channels_pcm = 8,
1311 .dac_channels_mixer = 2,
1312 .dac_volume_min = 255 - 2*60,
1313 .dac_volume_max = 255,
1314 .function_flags = OXYGEN_FUNCTION_2WIRE,
1315 .dac_mclks = OXYGEN_MCLKS(256, 256, 128),
1316 .adc_mclks = OXYGEN_MCLKS(256, 256, 128),
1091 .dac_i2s_format = OXYGEN_I2S_FORMAT_LJUST, 1317 .dac_i2s_format = OXYGEN_I2S_FORMAT_LJUST,
1092 .adc_i2s_format = OXYGEN_I2S_FORMAT_LJUST, 1318 .adc_i2s_format = OXYGEN_I2S_FORMAT_LJUST,
1093}; 1319};
@@ -1099,6 +1325,9 @@ int __devinit get_xonar_wm87x6_model(struct oxygen *chip,
1099 case 0x838e: 1325 case 0x838e:
1100 chip->model = model_xonar_ds; 1326 chip->model = model_xonar_ds;
1101 break; 1327 break;
1328 case 0x835e:
1329 chip->model = model_xonar_hdav_slim;
1330 break;
1102 default: 1331 default:
1103 return -EINVAL; 1332 return -EINVAL;
1104 } 1333 }
diff --git a/sound/pci/rme9652/hdsp.c b/sound/pci/rme9652/hdsp.c
index 0b720cf7783e..2d8332416c83 100644
--- a/sound/pci/rme9652/hdsp.c
+++ b/sound/pci/rme9652/hdsp.c
@@ -60,6 +60,7 @@ MODULE_SUPPORTED_DEVICE("{{RME Hammerfall-DSP},"
60 "{RME HDSP-9652}," 60 "{RME HDSP-9652},"
61 "{RME HDSP-9632}}"); 61 "{RME HDSP-9632}}");
62#ifdef HDSP_FW_LOADER 62#ifdef HDSP_FW_LOADER
63MODULE_FIRMWARE("rpm_firmware.bin");
63MODULE_FIRMWARE("multiface_firmware.bin"); 64MODULE_FIRMWARE("multiface_firmware.bin");
64MODULE_FIRMWARE("multiface_firmware_rev11.bin"); 65MODULE_FIRMWARE("multiface_firmware_rev11.bin");
65MODULE_FIRMWARE("digiface_firmware.bin"); 66MODULE_FIRMWARE("digiface_firmware.bin");
@@ -81,6 +82,7 @@ MODULE_FIRMWARE("digiface_firmware_rev11.bin");
81#define H9632_SS_CHANNELS 12 82#define H9632_SS_CHANNELS 12
82#define H9632_DS_CHANNELS 8 83#define H9632_DS_CHANNELS 8
83#define H9632_QS_CHANNELS 4 84#define H9632_QS_CHANNELS 4
85#define RPM_CHANNELS 6
84 86
85/* Write registers. These are defined as byte-offsets from the iobase value. 87/* Write registers. These are defined as byte-offsets from the iobase value.
86 */ 88 */
@@ -191,6 +193,25 @@ MODULE_FIRMWARE("digiface_firmware_rev11.bin");
191#define HDSP_PhoneGain1 (1<<30) 193#define HDSP_PhoneGain1 (1<<30)
192#define HDSP_QuadSpeed (1<<31) 194#define HDSP_QuadSpeed (1<<31)
193 195
196/* RPM uses some of the registers for special purposes */
197#define HDSP_RPM_Inp12 0x04A00
198#define HDSP_RPM_Inp12_Phon_6dB 0x00800 /* Dolby */
199#define HDSP_RPM_Inp12_Phon_0dB 0x00000 /* .. */
200#define HDSP_RPM_Inp12_Phon_n6dB 0x04000 /* inp_0 */
201#define HDSP_RPM_Inp12_Line_0dB 0x04200 /* Dolby+PRO */
202#define HDSP_RPM_Inp12_Line_n6dB 0x00200 /* PRO */
203
204#define HDSP_RPM_Inp34 0x32000
205#define HDSP_RPM_Inp34_Phon_6dB 0x20000 /* SyncRef1 */
206#define HDSP_RPM_Inp34_Phon_0dB 0x00000 /* .. */
207#define HDSP_RPM_Inp34_Phon_n6dB 0x02000 /* SyncRef2 */
208#define HDSP_RPM_Inp34_Line_0dB 0x30000 /* SyncRef1+SyncRef0 */
209#define HDSP_RPM_Inp34_Line_n6dB 0x10000 /* SyncRef0 */
210
211#define HDSP_RPM_Bypass 0x01000
212
213#define HDSP_RPM_Disconnect 0x00001
214
194#define HDSP_ADGainMask (HDSP_ADGain0|HDSP_ADGain1) 215#define HDSP_ADGainMask (HDSP_ADGain0|HDSP_ADGain1)
195#define HDSP_ADGainMinus10dBV HDSP_ADGainMask 216#define HDSP_ADGainMinus10dBV HDSP_ADGainMask
196#define HDSP_ADGainPlus4dBu (HDSP_ADGain0) 217#define HDSP_ADGainPlus4dBu (HDSP_ADGain0)
@@ -450,7 +471,7 @@ struct hdsp {
450 u32 creg_spdif; 471 u32 creg_spdif;
451 u32 creg_spdif_stream; 472 u32 creg_spdif_stream;
452 int clock_source_locked; 473 int clock_source_locked;
453 char *card_name; /* digiface/multiface */ 474 char *card_name; /* digiface/multiface/rpm */
454 enum HDSP_IO_Type io_type; /* ditto, but for code use */ 475 enum HDSP_IO_Type io_type; /* ditto, but for code use */
455 unsigned short firmware_rev; 476 unsigned short firmware_rev;
456 unsigned short state; /* stores state bits */ 477 unsigned short state; /* stores state bits */
@@ -612,6 +633,7 @@ static int hdsp_playback_to_output_key (struct hdsp *hdsp, int in, int out)
612 switch (hdsp->io_type) { 633 switch (hdsp->io_type) {
613 case Multiface: 634 case Multiface:
614 case Digiface: 635 case Digiface:
636 case RPM:
615 default: 637 default:
616 if (hdsp->firmware_rev == 0xa) 638 if (hdsp->firmware_rev == 0xa)
617 return (64 * out) + (32 + (in)); 639 return (64 * out) + (32 + (in));
@@ -629,6 +651,7 @@ static int hdsp_input_to_output_key (struct hdsp *hdsp, int in, int out)
629 switch (hdsp->io_type) { 651 switch (hdsp->io_type) {
630 case Multiface: 652 case Multiface:
631 case Digiface: 653 case Digiface:
654 case RPM:
632 default: 655 default:
633 if (hdsp->firmware_rev == 0xa) 656 if (hdsp->firmware_rev == 0xa)
634 return (64 * out) + in; 657 return (64 * out) + in;
@@ -655,7 +678,7 @@ static int hdsp_check_for_iobox (struct hdsp *hdsp)
655{ 678{
656 if (hdsp->io_type == H9652 || hdsp->io_type == H9632) return 0; 679 if (hdsp->io_type == H9652 || hdsp->io_type == H9632) return 0;
657 if (hdsp_read (hdsp, HDSP_statusRegister) & HDSP_ConfigError) { 680 if (hdsp_read (hdsp, HDSP_statusRegister) & HDSP_ConfigError) {
658 snd_printk ("Hammerfall-DSP: no Digiface or Multiface connected!\n"); 681 snd_printk("Hammerfall-DSP: no IO box connected!\n");
659 hdsp->state &= ~HDSP_FirmwareLoaded; 682 hdsp->state &= ~HDSP_FirmwareLoaded;
660 return -EIO; 683 return -EIO;
661 } 684 }
@@ -680,7 +703,7 @@ static int hdsp_wait_for_iobox(struct hdsp *hdsp, unsigned int loops,
680 } 703 }
681 } 704 }
682 705
683 snd_printk("Hammerfall-DSP: no Digiface or Multiface connected!\n"); 706 snd_printk("Hammerfall-DSP: no IO box connected!\n");
684 hdsp->state &= ~HDSP_FirmwareLoaded; 707 hdsp->state &= ~HDSP_FirmwareLoaded;
685 return -EIO; 708 return -EIO;
686} 709}
@@ -752,17 +775,21 @@ static int hdsp_get_iobox_version (struct hdsp *hdsp)
752 hdsp_write (hdsp, HDSP_control2Reg, HDSP_S_LOAD); 775 hdsp_write (hdsp, HDSP_control2Reg, HDSP_S_LOAD);
753 hdsp_write (hdsp, HDSP_fifoData, 0); 776 hdsp_write (hdsp, HDSP_fifoData, 0);
754 777
755 if (hdsp_fifo_wait (hdsp, 0, HDSP_SHORT_WAIT)) { 778 if (hdsp_fifo_wait(hdsp, 0, HDSP_SHORT_WAIT)) {
756 hdsp->io_type = Multiface; 779 hdsp_write(hdsp, HDSP_control2Reg, HDSP_VERSION_BIT);
757 hdsp_write (hdsp, HDSP_control2Reg, HDSP_VERSION_BIT); 780 hdsp_write(hdsp, HDSP_control2Reg, HDSP_S_LOAD);
758 hdsp_write (hdsp, HDSP_control2Reg, HDSP_S_LOAD); 781 if (hdsp_fifo_wait(hdsp, 0, HDSP_SHORT_WAIT))
759 hdsp_fifo_wait (hdsp, 0, HDSP_SHORT_WAIT); 782 hdsp->io_type = RPM;
783 else
784 hdsp->io_type = Multiface;
760 } else { 785 } else {
761 hdsp->io_type = Digiface; 786 hdsp->io_type = Digiface;
762 } 787 }
763 } else { 788 } else {
764 /* firmware was already loaded, get iobox type */ 789 /* firmware was already loaded, get iobox type */
765 if (hdsp_read(hdsp, HDSP_status2Register) & HDSP_version1) 790 if (hdsp_read(hdsp, HDSP_status2Register) & HDSP_version2)
791 hdsp->io_type = RPM;
792 else if (hdsp_read(hdsp, HDSP_status2Register) & HDSP_version1)
766 hdsp->io_type = Multiface; 793 hdsp->io_type = Multiface;
767 else 794 else
768 hdsp->io_type = Digiface; 795 hdsp->io_type = Digiface;
@@ -1184,6 +1211,7 @@ static int hdsp_set_rate(struct hdsp *hdsp, int rate, int called_internally)
1184 hdsp->channel_map = channel_map_ds; 1211 hdsp->channel_map = channel_map_ds;
1185 } else { 1212 } else {
1186 switch (hdsp->io_type) { 1213 switch (hdsp->io_type) {
1214 case RPM:
1187 case Multiface: 1215 case Multiface:
1188 hdsp->channel_map = channel_map_mf_ss; 1216 hdsp->channel_map = channel_map_mf_ss;
1189 break; 1217 break;
@@ -3231,6 +3259,318 @@ HDSP_PRECISE_POINTER("Precise Pointer", 0),
3231HDSP_USE_MIDI_TASKLET("Use Midi Tasklet", 0), 3259HDSP_USE_MIDI_TASKLET("Use Midi Tasklet", 0),
3232}; 3260};
3233 3261
3262
3263static int hdsp_rpm_input12(struct hdsp *hdsp)
3264{
3265 switch (hdsp->control_register & HDSP_RPM_Inp12) {
3266 case HDSP_RPM_Inp12_Phon_6dB:
3267 return 0;
3268 case HDSP_RPM_Inp12_Phon_n6dB:
3269 return 2;
3270 case HDSP_RPM_Inp12_Line_0dB:
3271 return 3;
3272 case HDSP_RPM_Inp12_Line_n6dB:
3273 return 4;
3274 }
3275 return 1;
3276}
3277
3278
3279static int snd_hdsp_get_rpm_input12(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
3280{
3281 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
3282
3283 ucontrol->value.enumerated.item[0] = hdsp_rpm_input12(hdsp);
3284 return 0;
3285}
3286
3287
3288static int hdsp_set_rpm_input12(struct hdsp *hdsp, int mode)
3289{
3290 hdsp->control_register &= ~HDSP_RPM_Inp12;
3291 switch (mode) {
3292 case 0:
3293 hdsp->control_register |= HDSP_RPM_Inp12_Phon_6dB;
3294 break;
3295 case 1:
3296 break;
3297 case 2:
3298 hdsp->control_register |= HDSP_RPM_Inp12_Phon_n6dB;
3299 break;
3300 case 3:
3301 hdsp->control_register |= HDSP_RPM_Inp12_Line_0dB;
3302 break;
3303 case 4:
3304 hdsp->control_register |= HDSP_RPM_Inp12_Line_n6dB;
3305 break;
3306 default:
3307 return -1;
3308 }
3309
3310 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
3311 return 0;
3312}
3313
3314
3315static int snd_hdsp_put_rpm_input12(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
3316{
3317 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
3318 int change;
3319 int val;
3320
3321 if (!snd_hdsp_use_is_exclusive(hdsp))
3322 return -EBUSY;
3323 val = ucontrol->value.enumerated.item[0];
3324 if (val < 0)
3325 val = 0;
3326 if (val > 4)
3327 val = 4;
3328 spin_lock_irq(&hdsp->lock);
3329 if (val != hdsp_rpm_input12(hdsp))
3330 change = (hdsp_set_rpm_input12(hdsp, val) == 0) ? 1 : 0;
3331 else
3332 change = 0;
3333 spin_unlock_irq(&hdsp->lock);
3334 return change;
3335}
3336
3337
3338static int snd_hdsp_info_rpm_input(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
3339{
3340 static char *texts[] = {"Phono +6dB", "Phono 0dB", "Phono -6dB", "Line 0dB", "Line -6dB"};
3341
3342 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
3343 uinfo->count = 1;
3344 uinfo->value.enumerated.items = 5;
3345 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
3346 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
3347 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
3348 return 0;
3349}
3350
3351
3352static int hdsp_rpm_input34(struct hdsp *hdsp)
3353{
3354 switch (hdsp->control_register & HDSP_RPM_Inp34) {
3355 case HDSP_RPM_Inp34_Phon_6dB:
3356 return 0;
3357 case HDSP_RPM_Inp34_Phon_n6dB:
3358 return 2;
3359 case HDSP_RPM_Inp34_Line_0dB:
3360 return 3;
3361 case HDSP_RPM_Inp34_Line_n6dB:
3362 return 4;
3363 }
3364 return 1;
3365}
3366
3367
3368static int snd_hdsp_get_rpm_input34(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
3369{
3370 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
3371
3372 ucontrol->value.enumerated.item[0] = hdsp_rpm_input34(hdsp);
3373 return 0;
3374}
3375
3376
3377static int hdsp_set_rpm_input34(struct hdsp *hdsp, int mode)
3378{
3379 hdsp->control_register &= ~HDSP_RPM_Inp34;
3380 switch (mode) {
3381 case 0:
3382 hdsp->control_register |= HDSP_RPM_Inp34_Phon_6dB;
3383 break;
3384 case 1:
3385 break;
3386 case 2:
3387 hdsp->control_register |= HDSP_RPM_Inp34_Phon_n6dB;
3388 break;
3389 case 3:
3390 hdsp->control_register |= HDSP_RPM_Inp34_Line_0dB;
3391 break;
3392 case 4:
3393 hdsp->control_register |= HDSP_RPM_Inp34_Line_n6dB;
3394 break;
3395 default:
3396 return -1;
3397 }
3398
3399 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
3400 return 0;
3401}
3402
3403
3404static int snd_hdsp_put_rpm_input34(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
3405{
3406 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
3407 int change;
3408 int val;
3409
3410 if (!snd_hdsp_use_is_exclusive(hdsp))
3411 return -EBUSY;
3412 val = ucontrol->value.enumerated.item[0];
3413 if (val < 0)
3414 val = 0;
3415 if (val > 4)
3416 val = 4;
3417 spin_lock_irq(&hdsp->lock);
3418 if (val != hdsp_rpm_input34(hdsp))
3419 change = (hdsp_set_rpm_input34(hdsp, val) == 0) ? 1 : 0;
3420 else
3421 change = 0;
3422 spin_unlock_irq(&hdsp->lock);
3423 return change;
3424}
3425
3426
3427/* RPM Bypass switch */
3428static int hdsp_rpm_bypass(struct hdsp *hdsp)
3429{
3430 return (hdsp->control_register & HDSP_RPM_Bypass) ? 1 : 0;
3431}
3432
3433
3434static int snd_hdsp_get_rpm_bypass(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
3435{
3436 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
3437
3438 ucontrol->value.integer.value[0] = hdsp_rpm_bypass(hdsp);
3439 return 0;
3440}
3441
3442
3443static int hdsp_set_rpm_bypass(struct hdsp *hdsp, int on)
3444{
3445 if (on)
3446 hdsp->control_register |= HDSP_RPM_Bypass;
3447 else
3448 hdsp->control_register &= ~HDSP_RPM_Bypass;
3449 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
3450 return 0;
3451}
3452
3453
3454static int snd_hdsp_put_rpm_bypass(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
3455{
3456 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
3457 int change;
3458 unsigned int val;
3459
3460 if (!snd_hdsp_use_is_exclusive(hdsp))
3461 return -EBUSY;
3462 val = ucontrol->value.integer.value[0] & 1;
3463 spin_lock_irq(&hdsp->lock);
3464 change = (int)val != hdsp_rpm_bypass(hdsp);
3465 hdsp_set_rpm_bypass(hdsp, val);
3466 spin_unlock_irq(&hdsp->lock);
3467 return change;
3468}
3469
3470
3471static int snd_hdsp_info_rpm_bypass(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
3472{
3473 static char *texts[] = {"On", "Off"};
3474
3475 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
3476 uinfo->count = 1;
3477 uinfo->value.enumerated.items = 2;
3478 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
3479 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
3480 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
3481 return 0;
3482}
3483
3484
3485/* RPM Disconnect switch */
3486static int hdsp_rpm_disconnect(struct hdsp *hdsp)
3487{
3488 return (hdsp->control_register & HDSP_RPM_Disconnect) ? 1 : 0;
3489}
3490
3491
3492static int snd_hdsp_get_rpm_disconnect(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
3493{
3494 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
3495
3496 ucontrol->value.integer.value[0] = hdsp_rpm_disconnect(hdsp);
3497 return 0;
3498}
3499
3500
3501static int hdsp_set_rpm_disconnect(struct hdsp *hdsp, int on)
3502{
3503 if (on)
3504 hdsp->control_register |= HDSP_RPM_Disconnect;
3505 else
3506 hdsp->control_register &= ~HDSP_RPM_Disconnect;
3507 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
3508 return 0;
3509}
3510
3511
3512static int snd_hdsp_put_rpm_disconnect(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
3513{
3514 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
3515 int change;
3516 unsigned int val;
3517
3518 if (!snd_hdsp_use_is_exclusive(hdsp))
3519 return -EBUSY;
3520 val = ucontrol->value.integer.value[0] & 1;
3521 spin_lock_irq(&hdsp->lock);
3522 change = (int)val != hdsp_rpm_disconnect(hdsp);
3523 hdsp_set_rpm_disconnect(hdsp, val);
3524 spin_unlock_irq(&hdsp->lock);
3525 return change;
3526}
3527
3528static int snd_hdsp_info_rpm_disconnect(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
3529{
3530 static char *texts[] = {"On", "Off"};
3531
3532 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
3533 uinfo->count = 1;
3534 uinfo->value.enumerated.items = 2;
3535 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
3536 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
3537 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
3538 return 0;
3539}
3540
3541static struct snd_kcontrol_new snd_hdsp_rpm_controls[] = {
3542 {
3543 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3544 .name = "RPM Bypass",
3545 .get = snd_hdsp_get_rpm_bypass,
3546 .put = snd_hdsp_put_rpm_bypass,
3547 .info = snd_hdsp_info_rpm_bypass
3548 },
3549 {
3550 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3551 .name = "RPM Disconnect",
3552 .get = snd_hdsp_get_rpm_disconnect,
3553 .put = snd_hdsp_put_rpm_disconnect,
3554 .info = snd_hdsp_info_rpm_disconnect
3555 },
3556 {
3557 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3558 .name = "Input 1/2",
3559 .get = snd_hdsp_get_rpm_input12,
3560 .put = snd_hdsp_put_rpm_input12,
3561 .info = snd_hdsp_info_rpm_input
3562 },
3563 {
3564 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3565 .name = "Input 3/4",
3566 .get = snd_hdsp_get_rpm_input34,
3567 .put = snd_hdsp_put_rpm_input34,
3568 .info = snd_hdsp_info_rpm_input
3569 },
3570 HDSP_SYSTEM_SAMPLE_RATE("System Sample Rate", 0),
3571 HDSP_MIXER("Mixer", 0)
3572};
3573
3234static struct snd_kcontrol_new snd_hdsp_96xx_aeb = HDSP_AEB("Analog Extension Board", 0); 3574static struct snd_kcontrol_new snd_hdsp_96xx_aeb = HDSP_AEB("Analog Extension Board", 0);
3235static struct snd_kcontrol_new snd_hdsp_adat_sync_check = HDSP_ADAT_SYNC_CHECK; 3575static struct snd_kcontrol_new snd_hdsp_adat_sync_check = HDSP_ADAT_SYNC_CHECK;
3236 3576
@@ -3240,6 +3580,16 @@ static int snd_hdsp_create_controls(struct snd_card *card, struct hdsp *hdsp)
3240 int err; 3580 int err;
3241 struct snd_kcontrol *kctl; 3581 struct snd_kcontrol *kctl;
3242 3582
3583 if (hdsp->io_type == RPM) {
3584 /* RPM Bypass, Disconnect and Input switches */
3585 for (idx = 0; idx < ARRAY_SIZE(snd_hdsp_rpm_controls); idx++) {
3586 err = snd_ctl_add(card, kctl = snd_ctl_new1(&snd_hdsp_rpm_controls[idx], hdsp));
3587 if (err < 0)
3588 return err;
3589 }
3590 return 0;
3591 }
3592
3243 for (idx = 0; idx < ARRAY_SIZE(snd_hdsp_controls); idx++) { 3593 for (idx = 0; idx < ARRAY_SIZE(snd_hdsp_controls); idx++) {
3244 if ((err = snd_ctl_add(card, kctl = snd_ctl_new1(&snd_hdsp_controls[idx], hdsp))) < 0) 3594 if ((err = snd_ctl_add(card, kctl = snd_ctl_new1(&snd_hdsp_controls[idx], hdsp))) < 0)
3245 return err; 3595 return err;
@@ -3459,48 +3809,102 @@ snd_hdsp_proc_read(struct snd_info_entry *entry, struct snd_info_buffer *buffer)
3459 3809
3460 snd_iprintf(buffer, "\n"); 3810 snd_iprintf(buffer, "\n");
3461 3811
3462 switch (hdsp_spdif_in(hdsp)) { 3812 if (hdsp->io_type != RPM) {
3463 case HDSP_SPDIFIN_OPTICAL: 3813 switch (hdsp_spdif_in(hdsp)) {
3464 snd_iprintf(buffer, "IEC958 input: Optical\n"); 3814 case HDSP_SPDIFIN_OPTICAL:
3465 break; 3815 snd_iprintf(buffer, "IEC958 input: Optical\n");
3466 case HDSP_SPDIFIN_COAXIAL: 3816 break;
3467 snd_iprintf(buffer, "IEC958 input: Coaxial\n"); 3817 case HDSP_SPDIFIN_COAXIAL:
3468 break; 3818 snd_iprintf(buffer, "IEC958 input: Coaxial\n");
3469 case HDSP_SPDIFIN_INTERNAL: 3819 break;
3470 snd_iprintf(buffer, "IEC958 input: Internal\n"); 3820 case HDSP_SPDIFIN_INTERNAL:
3471 break; 3821 snd_iprintf(buffer, "IEC958 input: Internal\n");
3472 case HDSP_SPDIFIN_AES: 3822 break;
3473 snd_iprintf(buffer, "IEC958 input: AES\n"); 3823 case HDSP_SPDIFIN_AES:
3474 break; 3824 snd_iprintf(buffer, "IEC958 input: AES\n");
3475 default: 3825 break;
3476 snd_iprintf(buffer, "IEC958 input: ???\n"); 3826 default:
3477 break; 3827 snd_iprintf(buffer, "IEC958 input: ???\n");
3828 break;
3829 }
3478 } 3830 }
3479 3831
3480 if (hdsp->control_register & HDSP_SPDIFOpticalOut) 3832 if (RPM == hdsp->io_type) {
3481 snd_iprintf(buffer, "IEC958 output: Coaxial & ADAT1\n"); 3833 if (hdsp->control_register & HDSP_RPM_Bypass)
3482 else 3834 snd_iprintf(buffer, "RPM Bypass: disabled\n");
3483 snd_iprintf(buffer, "IEC958 output: Coaxial only\n"); 3835 else
3836 snd_iprintf(buffer, "RPM Bypass: enabled\n");
3837 if (hdsp->control_register & HDSP_RPM_Disconnect)
3838 snd_iprintf(buffer, "RPM disconnected\n");
3839 else
3840 snd_iprintf(buffer, "RPM connected\n");
3484 3841
3485 if (hdsp->control_register & HDSP_SPDIFProfessional) 3842 switch (hdsp->control_register & HDSP_RPM_Inp12) {
3486 snd_iprintf(buffer, "IEC958 quality: Professional\n"); 3843 case HDSP_RPM_Inp12_Phon_6dB:
3487 else 3844 snd_iprintf(buffer, "Input 1/2: Phono, 6dB\n");
3488 snd_iprintf(buffer, "IEC958 quality: Consumer\n"); 3845 break;
3846 case HDSP_RPM_Inp12_Phon_0dB:
3847 snd_iprintf(buffer, "Input 1/2: Phono, 0dB\n");
3848 break;
3849 case HDSP_RPM_Inp12_Phon_n6dB:
3850 snd_iprintf(buffer, "Input 1/2: Phono, -6dB\n");
3851 break;
3852 case HDSP_RPM_Inp12_Line_0dB:
3853 snd_iprintf(buffer, "Input 1/2: Line, 0dB\n");
3854 break;
3855 case HDSP_RPM_Inp12_Line_n6dB:
3856 snd_iprintf(buffer, "Input 1/2: Line, -6dB\n");
3857 break;
3858 default:
3859 snd_iprintf(buffer, "Input 1/2: ???\n");
3860 }
3489 3861
3490 if (hdsp->control_register & HDSP_SPDIFEmphasis) 3862 switch (hdsp->control_register & HDSP_RPM_Inp34) {
3491 snd_iprintf(buffer, "IEC958 emphasis: on\n"); 3863 case HDSP_RPM_Inp34_Phon_6dB:
3492 else 3864 snd_iprintf(buffer, "Input 3/4: Phono, 6dB\n");
3493 snd_iprintf(buffer, "IEC958 emphasis: off\n"); 3865 break;
3866 case HDSP_RPM_Inp34_Phon_0dB:
3867 snd_iprintf(buffer, "Input 3/4: Phono, 0dB\n");
3868 break;
3869 case HDSP_RPM_Inp34_Phon_n6dB:
3870 snd_iprintf(buffer, "Input 3/4: Phono, -6dB\n");
3871 break;
3872 case HDSP_RPM_Inp34_Line_0dB:
3873 snd_iprintf(buffer, "Input 3/4: Line, 0dB\n");
3874 break;
3875 case HDSP_RPM_Inp34_Line_n6dB:
3876 snd_iprintf(buffer, "Input 3/4: Line, -6dB\n");
3877 break;
3878 default:
3879 snd_iprintf(buffer, "Input 3/4: ???\n");
3880 }
3494 3881
3495 if (hdsp->control_register & HDSP_SPDIFNonAudio) 3882 } else {
3496 snd_iprintf(buffer, "IEC958 NonAudio: on\n"); 3883 if (hdsp->control_register & HDSP_SPDIFOpticalOut)
3497 else 3884 snd_iprintf(buffer, "IEC958 output: Coaxial & ADAT1\n");
3498 snd_iprintf(buffer, "IEC958 NonAudio: off\n"); 3885 else
3499 if ((x = hdsp_spdif_sample_rate (hdsp)) != 0) 3886 snd_iprintf(buffer, "IEC958 output: Coaxial only\n");
3500 snd_iprintf (buffer, "IEC958 sample rate: %d\n", x); 3887
3501 else 3888 if (hdsp->control_register & HDSP_SPDIFProfessional)
3502 snd_iprintf (buffer, "IEC958 sample rate: Error flag set\n"); 3889 snd_iprintf(buffer, "IEC958 quality: Professional\n");
3890 else
3891 snd_iprintf(buffer, "IEC958 quality: Consumer\n");
3892
3893 if (hdsp->control_register & HDSP_SPDIFEmphasis)
3894 snd_iprintf(buffer, "IEC958 emphasis: on\n");
3895 else
3896 snd_iprintf(buffer, "IEC958 emphasis: off\n");
3503 3897
3898 if (hdsp->control_register & HDSP_SPDIFNonAudio)
3899 snd_iprintf(buffer, "IEC958 NonAudio: on\n");
3900 else
3901 snd_iprintf(buffer, "IEC958 NonAudio: off\n");
3902 x = hdsp_spdif_sample_rate(hdsp);
3903 if (x != 0)
3904 snd_iprintf(buffer, "IEC958 sample rate: %d\n", x);
3905 else
3906 snd_iprintf(buffer, "IEC958 sample rate: Error flag set\n");
3907 }
3504 snd_iprintf(buffer, "\n"); 3908 snd_iprintf(buffer, "\n");
3505 3909
3506 /* Sync Check */ 3910 /* Sync Check */
@@ -3765,7 +4169,7 @@ static irqreturn_t snd_hdsp_interrupt(int irq, void *dev_id)
3765 snd_hdsp_midi_input_read (&hdsp->midi[0]); 4169 snd_hdsp_midi_input_read (&hdsp->midi[0]);
3766 } 4170 }
3767 } 4171 }
3768 if (hdsp->io_type != Multiface && hdsp->io_type != H9632 && midi1 && midi1status) { 4172 if (hdsp->io_type != Multiface && hdsp->io_type != RPM && hdsp->io_type != H9632 && midi1 && midi1status) {
3769 if (hdsp->use_midi_tasklet) { 4173 if (hdsp->use_midi_tasklet) {
3770 /* we disable interrupts for this input until processing is done */ 4174 /* we disable interrupts for this input until processing is done */
3771 hdsp->control_register &= ~HDSP_Midi1InterruptEnable; 4175 hdsp->control_register &= ~HDSP_Midi1InterruptEnable;
@@ -4093,7 +4497,7 @@ static struct snd_pcm_hardware snd_hdsp_playback_subinfo =
4093 SNDRV_PCM_RATE_96000), 4497 SNDRV_PCM_RATE_96000),
4094 .rate_min = 32000, 4498 .rate_min = 32000,
4095 .rate_max = 96000, 4499 .rate_max = 96000,
4096 .channels_min = 14, 4500 .channels_min = 6,
4097 .channels_max = HDSP_MAX_CHANNELS, 4501 .channels_max = HDSP_MAX_CHANNELS,
4098 .buffer_bytes_max = HDSP_CHANNEL_BUFFER_BYTES * HDSP_MAX_CHANNELS, 4502 .buffer_bytes_max = HDSP_CHANNEL_BUFFER_BYTES * HDSP_MAX_CHANNELS,
4099 .period_bytes_min = (64 * 4) * 10, 4503 .period_bytes_min = (64 * 4) * 10,
@@ -4122,7 +4526,7 @@ static struct snd_pcm_hardware snd_hdsp_capture_subinfo =
4122 SNDRV_PCM_RATE_96000), 4526 SNDRV_PCM_RATE_96000),
4123 .rate_min = 32000, 4527 .rate_min = 32000,
4124 .rate_max = 96000, 4528 .rate_max = 96000,
4125 .channels_min = 14, 4529 .channels_min = 5,
4126 .channels_max = HDSP_MAX_CHANNELS, 4530 .channels_max = HDSP_MAX_CHANNELS,
4127 .buffer_bytes_max = HDSP_CHANNEL_BUFFER_BYTES * HDSP_MAX_CHANNELS, 4531 .buffer_bytes_max = HDSP_CHANNEL_BUFFER_BYTES * HDSP_MAX_CHANNELS,
4128 .period_bytes_min = (64 * 4) * 10, 4532 .period_bytes_min = (64 * 4) * 10,
@@ -4357,10 +4761,12 @@ static int snd_hdsp_playback_open(struct snd_pcm_substream *substream)
4357 snd_hdsp_hw_rule_rate_out_channels, hdsp, 4761 snd_hdsp_hw_rule_rate_out_channels, hdsp,
4358 SNDRV_PCM_HW_PARAM_CHANNELS, -1); 4762 SNDRV_PCM_HW_PARAM_CHANNELS, -1);
4359 4763
4360 hdsp->creg_spdif_stream = hdsp->creg_spdif; 4764 if (RPM != hdsp->io_type) {
4361 hdsp->spdif_ctl->vd[0].access &= ~SNDRV_CTL_ELEM_ACCESS_INACTIVE; 4765 hdsp->creg_spdif_stream = hdsp->creg_spdif;
4362 snd_ctl_notify(hdsp->card, SNDRV_CTL_EVENT_MASK_VALUE | 4766 hdsp->spdif_ctl->vd[0].access &= ~SNDRV_CTL_ELEM_ACCESS_INACTIVE;
4363 SNDRV_CTL_EVENT_MASK_INFO, &hdsp->spdif_ctl->id); 4767 snd_ctl_notify(hdsp->card, SNDRV_CTL_EVENT_MASK_VALUE |
4768 SNDRV_CTL_EVENT_MASK_INFO, &hdsp->spdif_ctl->id);
4769 }
4364 return 0; 4770 return 0;
4365} 4771}
4366 4772
@@ -4375,9 +4781,11 @@ static int snd_hdsp_playback_release(struct snd_pcm_substream *substream)
4375 4781
4376 spin_unlock_irq(&hdsp->lock); 4782 spin_unlock_irq(&hdsp->lock);
4377 4783
4378 hdsp->spdif_ctl->vd[0].access |= SNDRV_CTL_ELEM_ACCESS_INACTIVE; 4784 if (RPM != hdsp->io_type) {
4379 snd_ctl_notify(hdsp->card, SNDRV_CTL_EVENT_MASK_VALUE | 4785 hdsp->spdif_ctl->vd[0].access |= SNDRV_CTL_ELEM_ACCESS_INACTIVE;
4380 SNDRV_CTL_EVENT_MASK_INFO, &hdsp->spdif_ctl->id); 4786 snd_ctl_notify(hdsp->card, SNDRV_CTL_EVENT_MASK_VALUE |
4787 SNDRV_CTL_EVENT_MASK_INFO, &hdsp->spdif_ctl->id);
4788 }
4381 return 0; 4789 return 0;
4382} 4790}
4383 4791
@@ -4616,7 +5024,7 @@ static int snd_hdsp_hwdep_ioctl(struct snd_hwdep *hw, struct file *file, unsigne
4616 if (hdsp->io_type != H9632) 5024 if (hdsp->io_type != H9632)
4617 info.adatsync_sync_check = (unsigned char)hdsp_adatsync_sync_check(hdsp); 5025 info.adatsync_sync_check = (unsigned char)hdsp_adatsync_sync_check(hdsp);
4618 info.spdif_sync_check = (unsigned char)hdsp_spdif_sync_check(hdsp); 5026 info.spdif_sync_check = (unsigned char)hdsp_spdif_sync_check(hdsp);
4619 for (i = 0; i < ((hdsp->io_type != Multiface && hdsp->io_type != H9632) ? 3 : 1); ++i) 5027 for (i = 0; i < ((hdsp->io_type != Multiface && hdsp->io_type != RPM && hdsp->io_type != H9632) ? 3 : 1); ++i)
4620 info.adat_sync_check[i] = (unsigned char)hdsp_adat_sync_check(hdsp, i); 5028 info.adat_sync_check[i] = (unsigned char)hdsp_adat_sync_check(hdsp, i);
4621 info.spdif_in = (unsigned char)hdsp_spdif_in(hdsp); 5029 info.spdif_in = (unsigned char)hdsp_spdif_in(hdsp);
4622 info.spdif_out = (unsigned char)hdsp_spdif_out(hdsp); 5030 info.spdif_out = (unsigned char)hdsp_spdif_out(hdsp);
@@ -4636,6 +5044,9 @@ static int snd_hdsp_hwdep_ioctl(struct snd_hwdep *hw, struct file *file, unsigne
4636 info.phone_gain = (unsigned char)hdsp_phone_gain(hdsp); 5044 info.phone_gain = (unsigned char)hdsp_phone_gain(hdsp);
4637 info.xlr_breakout_cable = (unsigned char)hdsp_xlr_breakout_cable(hdsp); 5045 info.xlr_breakout_cable = (unsigned char)hdsp_xlr_breakout_cable(hdsp);
4638 5046
5047 } else if (hdsp->io_type == RPM) {
5048 info.da_gain = (unsigned char) hdsp_rpm_input12(hdsp);
5049 info.ad_gain = (unsigned char) hdsp_rpm_input34(hdsp);
4639 } 5050 }
4640 if (hdsp->io_type == H9632 || hdsp->io_type == H9652) 5051 if (hdsp->io_type == H9632 || hdsp->io_type == H9652)
4641 info.analog_extension_board = (unsigned char)hdsp_aeb(hdsp); 5052 info.analog_extension_board = (unsigned char)hdsp_aeb(hdsp);
@@ -4844,6 +5255,14 @@ static void snd_hdsp_initialize_channels(struct hdsp *hdsp)
4844 hdsp->ds_in_channels = hdsp->ds_out_channels = MULTIFACE_DS_CHANNELS; 5255 hdsp->ds_in_channels = hdsp->ds_out_channels = MULTIFACE_DS_CHANNELS;
4845 break; 5256 break;
4846 5257
5258 case RPM:
5259 hdsp->card_name = "RME Hammerfall DSP + RPM";
5260 hdsp->ss_in_channels = RPM_CHANNELS-1;
5261 hdsp->ss_out_channels = RPM_CHANNELS;
5262 hdsp->ds_in_channels = RPM_CHANNELS-1;
5263 hdsp->ds_out_channels = RPM_CHANNELS;
5264 break;
5265
4847 default: 5266 default:
4848 /* should never get here */ 5267 /* should never get here */
4849 break; 5268 break;
@@ -4930,6 +5349,9 @@ static int hdsp_request_fw_loader(struct hdsp *hdsp)
4930 5349
4931 /* caution: max length of firmware filename is 30! */ 5350 /* caution: max length of firmware filename is 30! */
4932 switch (hdsp->io_type) { 5351 switch (hdsp->io_type) {
5352 case RPM:
5353 fwfile = "rpm_firmware.bin";
5354 break;
4933 case Multiface: 5355 case Multiface:
4934 if (hdsp->firmware_rev == 0xa) 5356 if (hdsp->firmware_rev == 0xa)
4935 fwfile = "multiface_firmware.bin"; 5357 fwfile = "multiface_firmware.bin";
@@ -5100,7 +5522,9 @@ static int __devinit snd_hdsp_create(struct snd_card *card,
5100 return 0; 5522 return 0;
5101 } else { 5523 } else {
5102 snd_printk(KERN_INFO "Hammerfall-DSP: Firmware already present, initializing card.\n"); 5524 snd_printk(KERN_INFO "Hammerfall-DSP: Firmware already present, initializing card.\n");
5103 if (hdsp_read(hdsp, HDSP_status2Register) & HDSP_version1) 5525 if (hdsp_read(hdsp, HDSP_status2Register) & HDSP_version2)
5526 hdsp->io_type = RPM;
5527 else if (hdsp_read(hdsp, HDSP_status2Register) & HDSP_version1)
5104 hdsp->io_type = Multiface; 5528 hdsp->io_type = Multiface;
5105 else 5529 else
5106 hdsp->io_type = Digiface; 5530 hdsp->io_type = Digiface;
diff --git a/sound/pci/rme9652/hdspm.c b/sound/pci/rme9652/hdspm.c
index 0c98ef9156d8..f5eadfc0672a 100644
--- a/sound/pci/rme9652/hdspm.c
+++ b/sound/pci/rme9652/hdspm.c
@@ -487,7 +487,7 @@ struct hdspm {
487 struct snd_kcontrol *playback_mixer_ctls[HDSPM_MAX_CHANNELS]; 487 struct snd_kcontrol *playback_mixer_ctls[HDSPM_MAX_CHANNELS];
488 /* but input to much, so not used */ 488 /* but input to much, so not used */
489 struct snd_kcontrol *input_mixer_ctls[HDSPM_MAX_CHANNELS]; 489 struct snd_kcontrol *input_mixer_ctls[HDSPM_MAX_CHANNELS];
490 /* full mixer accessable over mixer ioctl or hwdep-device */ 490 /* full mixer accessible over mixer ioctl or hwdep-device */
491 struct hdspm_mixer *mixer; 491 struct hdspm_mixer *mixer;
492 492
493}; 493};
@@ -550,7 +550,7 @@ static inline int HDSPM_bit2freq(int n)
550 return bit2freq_tab[n]; 550 return bit2freq_tab[n];
551} 551}
552 552
553/* Write/read to/from HDSPM with Adresses in Bytes 553/* Write/read to/from HDSPM with Addresses in Bytes
554 not words but only 32Bit writes are allowed */ 554 not words but only 32Bit writes are allowed */
555 555
556static inline void hdspm_write(struct hdspm * hdspm, unsigned int reg, 556static inline void hdspm_write(struct hdspm * hdspm, unsigned int reg,
@@ -2908,7 +2908,7 @@ static int snd_hdspm_create_controls(struct snd_card *card, struct hdspm * hdspm
2908 2908
2909 /* Channel playback mixer as default control 2909 /* Channel playback mixer as default control
2910 Note: the whole matrix would be 128*HDSPM_MIXER_CHANNELS Faders, 2910 Note: the whole matrix would be 128*HDSPM_MIXER_CHANNELS Faders,
2911 thats too * big for any alsamixer they are accesible via special 2911 thats too * big for any alsamixer they are accessible via special
2912 IOCTL on hwdep and the mixer 2dimensional mixer control 2912 IOCTL on hwdep and the mixer 2dimensional mixer control
2913 */ 2913 */
2914 2914
diff --git a/sound/pci/ymfpci/ymfpci_main.c b/sound/pci/ymfpci/ymfpci_main.c
index 5518371db13f..c94c051ad0c8 100644
--- a/sound/pci/ymfpci/ymfpci_main.c
+++ b/sound/pci/ymfpci/ymfpci_main.c
@@ -1389,15 +1389,9 @@ static struct snd_kcontrol_new snd_ymfpci_spdif_stream __devinitdata =
1389 1389
1390static int snd_ymfpci_drec_source_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *info) 1390static int snd_ymfpci_drec_source_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *info)
1391{ 1391{
1392 static char *texts[3] = {"AC'97", "IEC958", "ZV Port"}; 1392 static const char *const texts[3] = {"AC'97", "IEC958", "ZV Port"};
1393 1393
1394 info->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; 1394 return snd_ctl_enum_info(info, 1, 3, texts);
1395 info->count = 1;
1396 info->value.enumerated.items = 3;
1397 if (info->value.enumerated.item > 2)
1398 info->value.enumerated.item = 2;
1399 strcpy(info->value.enumerated.name, texts[info->value.enumerated.item]);
1400 return 0;
1401} 1395}
1402 1396
1403static int snd_ymfpci_drec_source_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *value) 1397static int snd_ymfpci_drec_source_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *value)
diff --git a/sound/ppc/snd_ps3.c b/sound/ppc/snd_ps3.c
index 581a670e8261..edce8a27e3ee 100644
--- a/sound/ppc/snd_ps3.c
+++ b/sound/ppc/snd_ps3.c
@@ -51,7 +51,7 @@ static struct snd_ps3_card_info the_card;
51static int snd_ps3_start_delay = CONFIG_SND_PS3_DEFAULT_START_DELAY; 51static int snd_ps3_start_delay = CONFIG_SND_PS3_DEFAULT_START_DELAY;
52 52
53module_param_named(start_delay, snd_ps3_start_delay, uint, 0644); 53module_param_named(start_delay, snd_ps3_start_delay, uint, 0644);
54MODULE_PARM_DESC(start_delay, "time to insert silent data in milisec"); 54MODULE_PARM_DESC(start_delay, "time to insert silent data in ms");
55 55
56static int index = SNDRV_DEFAULT_IDX1; 56static int index = SNDRV_DEFAULT_IDX1;
57static char *id = SNDRV_DEFAULT_STR1; 57static char *id = SNDRV_DEFAULT_STR1;
diff --git a/sound/soc/Kconfig b/sound/soc/Kconfig
index 3e598e756e54..a3efc52a34da 100644
--- a/sound/soc/Kconfig
+++ b/sound/soc/Kconfig
@@ -20,6 +20,21 @@ menuconfig SND_SOC
20 20
21if SND_SOC 21if SND_SOC
22 22
23config SND_SOC_CACHE_LZO
24 bool "Support LZO compression for register caches"
25 select LZO_COMPRESS
26 select LZO_DECOMPRESS
27 ---help---
28 Select this to enable LZO compression for register caches.
29 This will allow machine or CODEC drivers to compress register
30 caches in memory, reducing the memory consumption at the
31 expense of performance. If this is not present and is used
32 the system will fall back to uncompressed caches.
33
34 Usually it is safe to disable this option, where cache
35 compression in used the rbtree option will typically perform
36 better.
37
23config SND_SOC_AC97_BUS 38config SND_SOC_AC97_BUS
24 bool 39 bool
25 40
@@ -36,7 +51,7 @@ source "sound/soc/nuc900/Kconfig"
36source "sound/soc/omap/Kconfig" 51source "sound/soc/omap/Kconfig"
37source "sound/soc/kirkwood/Kconfig" 52source "sound/soc/kirkwood/Kconfig"
38source "sound/soc/pxa/Kconfig" 53source "sound/soc/pxa/Kconfig"
39source "sound/soc/s3c24xx/Kconfig" 54source "sound/soc/samsung/Kconfig"
40source "sound/soc/s6000/Kconfig" 55source "sound/soc/s6000/Kconfig"
41source "sound/soc/sh/Kconfig" 56source "sound/soc/sh/Kconfig"
42source "sound/soc/txx9/Kconfig" 57source "sound/soc/txx9/Kconfig"
diff --git a/sound/soc/Makefile b/sound/soc/Makefile
index eb183443eee4..ce913bf5213c 100644
--- a/sound/soc/Makefile
+++ b/sound/soc/Makefile
@@ -14,7 +14,7 @@ obj-$(CONFIG_SND_SOC) += nuc900/
14obj-$(CONFIG_SND_SOC) += omap/ 14obj-$(CONFIG_SND_SOC) += omap/
15obj-$(CONFIG_SND_SOC) += kirkwood/ 15obj-$(CONFIG_SND_SOC) += kirkwood/
16obj-$(CONFIG_SND_SOC) += pxa/ 16obj-$(CONFIG_SND_SOC) += pxa/
17obj-$(CONFIG_SND_SOC) += s3c24xx/ 17obj-$(CONFIG_SND_SOC) += samsung/
18obj-$(CONFIG_SND_SOC) += s6000/ 18obj-$(CONFIG_SND_SOC) += s6000/
19obj-$(CONFIG_SND_SOC) += sh/ 19obj-$(CONFIG_SND_SOC) += sh/
20obj-$(CONFIG_SND_SOC) += txx9/ 20obj-$(CONFIG_SND_SOC) += txx9/
diff --git a/sound/soc/atmel/playpaq_wm8510.c b/sound/soc/atmel/playpaq_wm8510.c
index 5f4e59f4461c..1aac2f4dbcf6 100644
--- a/sound/soc/atmel/playpaq_wm8510.c
+++ b/sound/soc/atmel/playpaq_wm8510.c
@@ -33,7 +33,6 @@
33#include <sound/pcm.h> 33#include <sound/pcm.h>
34#include <sound/pcm_params.h> 34#include <sound/pcm_params.h>
35#include <sound/soc.h> 35#include <sound/soc.h>
36#include <sound/soc-dapm.h>
37 36
38#include <mach/at32ap700x.h> 37#include <mach/at32ap700x.h>
39#include <mach/portmux.h> 38#include <mach/portmux.h>
@@ -318,27 +317,28 @@ static const struct snd_soc_dapm_route intercon[] = {
318static int playpaq_wm8510_init(struct snd_soc_pcm_runtime *rtd) 317static int playpaq_wm8510_init(struct snd_soc_pcm_runtime *rtd)
319{ 318{
320 struct snd_soc_codec *codec = rtd->codec; 319 struct snd_soc_codec *codec = rtd->codec;
320 struct snd_soc_dapm_context *dapm = &codec->dapm;
321 int i; 321 int i;
322 322
323 /* 323 /*
324 * Add DAPM widgets 324 * Add DAPM widgets
325 */ 325 */
326 for (i = 0; i < ARRAY_SIZE(playpaq_dapm_widgets); i++) 326 for (i = 0; i < ARRAY_SIZE(playpaq_dapm_widgets); i++)
327 snd_soc_dapm_new_control(codec, &playpaq_dapm_widgets[i]); 327 snd_soc_dapm_new_control(dapm, &playpaq_dapm_widgets[i]);
328 328
329 329
330 330
331 /* 331 /*
332 * Setup audio path interconnects 332 * Setup audio path interconnects
333 */ 333 */
334 snd_soc_dapm_add_routes(codec, intercon, ARRAY_SIZE(intercon)); 334 snd_soc_dapm_add_routes(dapm, intercon, ARRAY_SIZE(intercon));
335 335
336 336
337 337
338 /* always connected pins */ 338 /* always connected pins */
339 snd_soc_dapm_enable_pin(codec, "Int Mic"); 339 snd_soc_dapm_enable_pin(dapm, "Int Mic");
340 snd_soc_dapm_enable_pin(codec, "Ext Spk"); 340 snd_soc_dapm_enable_pin(dapm, "Ext Spk");
341 snd_soc_dapm_sync(codec); 341 snd_soc_dapm_sync(dapm);
342 342
343 343
344 344
diff --git a/sound/soc/atmel/sam9g20_wm8731.c b/sound/soc/atmel/sam9g20_wm8731.c
index e521ada80542..af3c73053ee4 100644
--- a/sound/soc/atmel/sam9g20_wm8731.c
+++ b/sound/soc/atmel/sam9g20_wm8731.c
@@ -44,7 +44,6 @@
44#include <sound/pcm.h> 44#include <sound/pcm.h>
45#include <sound/pcm_params.h> 45#include <sound/pcm_params.h>
46#include <sound/soc.h> 46#include <sound/soc.h>
47#include <sound/soc-dapm.h>
48 47
49#include <asm/mach-types.h> 48#include <asm/mach-types.h>
50#include <mach/hardware.h> 49#include <mach/hardware.h>
@@ -140,6 +139,7 @@ static int at91sam9g20ek_wm8731_init(struct snd_soc_pcm_runtime *rtd)
140{ 139{
141 struct snd_soc_codec *codec = rtd->codec; 140 struct snd_soc_codec *codec = rtd->codec;
142 struct snd_soc_dai *codec_dai = rtd->codec_dai; 141 struct snd_soc_dai *codec_dai = rtd->codec_dai;
142 struct snd_soc_dapm_context *dapm = &codec->dapm;
143 int ret; 143 int ret;
144 144
145 printk(KERN_DEBUG 145 printk(KERN_DEBUG
@@ -154,25 +154,25 @@ static int at91sam9g20ek_wm8731_init(struct snd_soc_pcm_runtime *rtd)
154 } 154 }
155 155
156 /* Add specific widgets */ 156 /* Add specific widgets */
157 snd_soc_dapm_new_controls(codec, at91sam9g20ek_dapm_widgets, 157 snd_soc_dapm_new_controls(dapm, at91sam9g20ek_dapm_widgets,
158 ARRAY_SIZE(at91sam9g20ek_dapm_widgets)); 158 ARRAY_SIZE(at91sam9g20ek_dapm_widgets));
159 /* Set up specific audio path interconnects */ 159 /* Set up specific audio path interconnects */
160 snd_soc_dapm_add_routes(codec, intercon, ARRAY_SIZE(intercon)); 160 snd_soc_dapm_add_routes(dapm, intercon, ARRAY_SIZE(intercon));
161 161
162 /* not connected */ 162 /* not connected */
163 snd_soc_dapm_nc_pin(codec, "RLINEIN"); 163 snd_soc_dapm_nc_pin(dapm, "RLINEIN");
164 snd_soc_dapm_nc_pin(codec, "LLINEIN"); 164 snd_soc_dapm_nc_pin(dapm, "LLINEIN");
165 165
166#ifdef ENABLE_MIC_INPUT 166#ifdef ENABLE_MIC_INPUT
167 snd_soc_dapm_enable_pin(codec, "Int Mic"); 167 snd_soc_dapm_enable_pin(dapm, "Int Mic");
168#else 168#else
169 snd_soc_dapm_nc_pin(codec, "Int Mic"); 169 snd_soc_dapm_nc_pin(dapm, "Int Mic");
170#endif 170#endif
171 171
172 /* always connected */ 172 /* always connected */
173 snd_soc_dapm_enable_pin(codec, "Ext Spk"); 173 snd_soc_dapm_enable_pin(dapm, "Ext Spk");
174 174
175 snd_soc_dapm_sync(codec); 175 snd_soc_dapm_sync(dapm);
176 176
177 return 0; 177 return 0;
178} 178}
diff --git a/sound/soc/atmel/snd-soc-afeb9260.c b/sound/soc/atmel/snd-soc-afeb9260.c
index 86e0f8586dc3..da2208e06b0d 100644
--- a/sound/soc/atmel/snd-soc-afeb9260.c
+++ b/sound/soc/atmel/snd-soc-afeb9260.c
@@ -30,7 +30,6 @@
30#include <sound/pcm.h> 30#include <sound/pcm.h>
31#include <sound/pcm_params.h> 31#include <sound/pcm_params.h>
32#include <sound/soc.h> 32#include <sound/soc.h>
33#include <sound/soc-dapm.h>
34 33
35#include <asm/mach-types.h> 34#include <asm/mach-types.h>
36#include <mach/hardware.h> 35#include <mach/hardware.h>
@@ -105,19 +104,20 @@ static const struct snd_soc_dapm_route audio_map[] = {
105static int afeb9260_tlv320aic23_init(struct snd_soc_pcm_runtime *rtd) 104static int afeb9260_tlv320aic23_init(struct snd_soc_pcm_runtime *rtd)
106{ 105{
107 struct snd_soc_codec *codec = rtd->codec; 106 struct snd_soc_codec *codec = rtd->codec;
107 struct snd_soc_dapm_context *dapm = &codec->dapm;
108 108
109 /* Add afeb9260 specific widgets */ 109 /* Add afeb9260 specific widgets */
110 snd_soc_dapm_new_controls(codec, tlv320aic23_dapm_widgets, 110 snd_soc_dapm_new_controls(dapm, tlv320aic23_dapm_widgets,
111 ARRAY_SIZE(tlv320aic23_dapm_widgets)); 111 ARRAY_SIZE(tlv320aic23_dapm_widgets));
112 112
113 /* Set up afeb9260 specific audio path audio_map */ 113 /* Set up afeb9260 specific audio path audio_map */
114 snd_soc_dapm_add_routes(codec, audio_map, ARRAY_SIZE(audio_map)); 114 snd_soc_dapm_add_routes(dapm, audio_map, ARRAY_SIZE(audio_map));
115 115
116 snd_soc_dapm_enable_pin(codec, "Headphone Jack"); 116 snd_soc_dapm_enable_pin(dapm, "Headphone Jack");
117 snd_soc_dapm_enable_pin(codec, "Line In"); 117 snd_soc_dapm_enable_pin(dapm, "Line In");
118 snd_soc_dapm_enable_pin(codec, "Mic Jack"); 118 snd_soc_dapm_enable_pin(dapm, "Mic Jack");
119 119
120 snd_soc_dapm_sync(codec); 120 snd_soc_dapm_sync(dapm);
121 121
122 return 0; 122 return 0;
123} 123}
diff --git a/sound/soc/au1x/db1200.c b/sound/soc/au1x/db1200.c
index b62fcd33e586..cb99f04abe88 100644
--- a/sound/soc/au1x/db1200.c
+++ b/sound/soc/au1x/db1200.c
@@ -13,7 +13,6 @@
13#include <sound/core.h> 13#include <sound/core.h>
14#include <sound/pcm.h> 14#include <sound/pcm.h>
15#include <sound/soc.h> 15#include <sound/soc.h>
16#include <sound/soc-dapm.h>
17#include <asm/mach-au1x00/au1000.h> 16#include <asm/mach-au1x00/au1000.h>
18#include <asm/mach-au1x00/au1xxx_psc.h> 17#include <asm/mach-au1x00/au1xxx_psc.h>
19#include <asm/mach-au1x00/au1xxx_dbdma.h> 18#include <asm/mach-au1x00/au1xxx_dbdma.h>
diff --git a/sound/soc/blackfin/bf5xx-ad1836.c b/sound/soc/blackfin/bf5xx-ad1836.c
index 2394bff2b655..83012da9dfc2 100644
--- a/sound/soc/blackfin/bf5xx-ad1836.c
+++ b/sound/soc/blackfin/bf5xx-ad1836.c
@@ -20,7 +20,6 @@
20#include <sound/core.h> 20#include <sound/core.h>
21#include <sound/pcm.h> 21#include <sound/pcm.h>
22#include <sound/soc.h> 22#include <sound/soc.h>
23#include <sound/soc-dapm.h>
24#include <sound/pcm_params.h> 23#include <sound/pcm_params.h>
25 24
26#include <asm/blackfin.h> 25#include <asm/blackfin.h>
diff --git a/sound/soc/blackfin/bf5xx-ad193x.c b/sound/soc/blackfin/bf5xx-ad193x.c
index e4a625317a1a..d3ccb926b5e4 100644
--- a/sound/soc/blackfin/bf5xx-ad193x.c
+++ b/sound/soc/blackfin/bf5xx-ad193x.c
@@ -29,7 +29,6 @@
29#include <sound/core.h> 29#include <sound/core.h>
30#include <sound/pcm.h> 30#include <sound/pcm.h>
31#include <sound/soc.h> 31#include <sound/soc.h>
32#include <sound/soc-dapm.h>
33#include <sound/pcm_params.h> 32#include <sound/pcm_params.h>
34 33
35#include <asm/blackfin.h> 34#include <asm/blackfin.h>
diff --git a/sound/soc/blackfin/bf5xx-ad73311.c b/sound/soc/blackfin/bf5xx-ad73311.c
index 900ced54ac79..732fb8bad076 100644
--- a/sound/soc/blackfin/bf5xx-ad73311.c
+++ b/sound/soc/blackfin/bf5xx-ad73311.c
@@ -35,7 +35,6 @@
35#include <sound/core.h> 35#include <sound/core.h>
36#include <sound/pcm.h> 36#include <sound/pcm.h>
37#include <sound/soc.h> 37#include <sound/soc.h>
38#include <sound/soc-dapm.h>
39#include <sound/pcm_params.h> 38#include <sound/pcm_params.h>
40 39
41#include <asm/blackfin.h> 40#include <asm/blackfin.h>
diff --git a/sound/soc/blackfin/bf5xx-ssm2602.c b/sound/soc/blackfin/bf5xx-ssm2602.c
index 36f2769eb912..e902b24c1856 100644
--- a/sound/soc/blackfin/bf5xx-ssm2602.c
+++ b/sound/soc/blackfin/bf5xx-ssm2602.c
@@ -33,7 +33,6 @@
33#include <sound/core.h> 33#include <sound/core.h>
34#include <sound/pcm.h> 34#include <sound/pcm.h>
35#include <sound/soc.h> 35#include <sound/soc.h>
36#include <sound/soc-dapm.h>
37#include <sound/pcm_params.h> 36#include <sound/pcm_params.h>
38 37
39#include <asm/dma.h> 38#include <asm/dma.h>
diff --git a/sound/soc/codecs/88pm860x-codec.c b/sound/soc/codecs/88pm860x-codec.c
index 01d19e9f53f9..06b6981b8d6d 100644
--- a/sound/soc/codecs/88pm860x-codec.c
+++ b/sound/soc/codecs/88pm860x-codec.c
@@ -19,10 +19,10 @@
19#include <sound/pcm.h> 19#include <sound/pcm.h>
20#include <sound/pcm_params.h> 20#include <sound/pcm_params.h>
21#include <sound/soc.h> 21#include <sound/soc.h>
22#include <sound/soc-dapm.h>
23#include <sound/tlv.h> 22#include <sound/tlv.h>
24#include <sound/initval.h> 23#include <sound/initval.h>
25#include <sound/jack.h> 24#include <sound/jack.h>
25#include <trace/events/asoc.h>
26 26
27#include "88pm860x-codec.h" 27#include "88pm860x-codec.h"
28 28
@@ -146,7 +146,6 @@ struct pm860x_priv {
146 146
147 int irq[4]; 147 int irq[4];
148 unsigned char name[4][MAX_NAME_LEN]; 148 unsigned char name[4][MAX_NAME_LEN];
149 unsigned char reg_cache[REG_CACHE_SIZE];
150}; 149};
151 150
152/* -9450dB to 0dB in 150dB steps ( mute instead of -9450dB) */ 151/* -9450dB to 0dB in 150dB steps ( mute instead of -9450dB) */
@@ -1172,7 +1171,7 @@ static int pm860x_set_bias_level(struct snd_soc_codec *codec,
1172 break; 1171 break;
1173 1172
1174 case SND_SOC_BIAS_STANDBY: 1173 case SND_SOC_BIAS_STANDBY:
1175 if (codec->bias_level == SND_SOC_BIAS_OFF) { 1174 if (codec->dapm.bias_level == SND_SOC_BIAS_OFF) {
1176 /* Enable Audio PLL & Audio section */ 1175 /* Enable Audio PLL & Audio section */
1177 data = AUDIO_PLL | AUDIO_SECTION_RESET 1176 data = AUDIO_PLL | AUDIO_SECTION_RESET
1178 | AUDIO_SECTION_ON; 1177 | AUDIO_SECTION_ON;
@@ -1185,7 +1184,7 @@ static int pm860x_set_bias_level(struct snd_soc_codec *codec,
1185 pm860x_set_bits(codec->control_data, REG_MISC2, data, 0); 1184 pm860x_set_bits(codec->control_data, REG_MISC2, data, 0);
1186 break; 1185 break;
1187 } 1186 }
1188 codec->bias_level = level; 1187 codec->dapm.bias_level = level;
1189 return 0; 1188 return 0;
1190} 1189}
1191 1190
@@ -1263,6 +1262,12 @@ static irqreturn_t pm860x_codec_handler(int irq, void *data)
1263 mask = pm860x->det.hs_shrt | pm860x->det.hook_det | pm860x->det.lo_shrt 1262 mask = pm860x->det.hs_shrt | pm860x->det.hook_det | pm860x->det.lo_shrt
1264 | pm860x->det.hp_det; 1263 | pm860x->det.hp_det;
1265 1264
1265#ifndef CONFIG_SND_SOC_88PM860X_MODULE
1266 if (status & (HEADSET_STATUS | MIC_STATUS | SHORT_HS1 | SHORT_HS2 |
1267 SHORT_LO1 | SHORT_LO2))
1268 trace_snd_soc_jack_irq(dev_name(pm860x->codec->dev));
1269#endif
1270
1266 if ((pm860x->det.hp_det & SND_JACK_HEADPHONE) 1271 if ((pm860x->det.hp_det & SND_JACK_HEADPHONE)
1267 && (status & HEADSET_STATUS)) 1272 && (status & HEADSET_STATUS))
1268 report |= SND_JACK_HEADPHONE; 1273 report |= SND_JACK_HEADPHONE;
@@ -1346,6 +1351,7 @@ EXPORT_SYMBOL_GPL(pm860x_mic_jack_detect);
1346static int pm860x_probe(struct snd_soc_codec *codec) 1351static int pm860x_probe(struct snd_soc_codec *codec)
1347{ 1352{
1348 struct pm860x_priv *pm860x = snd_soc_codec_get_drvdata(codec); 1353 struct pm860x_priv *pm860x = snd_soc_codec_get_drvdata(codec);
1354 struct snd_soc_dapm_context *dapm = &codec->dapm;
1349 int i, ret; 1355 int i, ret;
1350 1356
1351 pm860x->codec = codec; 1357 pm860x->codec = codec;
@@ -1358,7 +1364,7 @@ static int pm860x_probe(struct snd_soc_codec *codec)
1358 pm860x->name[i], pm860x); 1364 pm860x->name[i], pm860x);
1359 if (ret < 0) { 1365 if (ret < 0) {
1360 dev_err(codec->dev, "Failed to request IRQ!\n"); 1366 dev_err(codec->dev, "Failed to request IRQ!\n");
1361 goto out_irq; 1367 goto out;
1362 } 1368 }
1363 } 1369 }
1364 1370
@@ -1369,22 +1375,20 @@ static int pm860x_probe(struct snd_soc_codec *codec)
1369 if (ret < 0) { 1375 if (ret < 0) {
1370 dev_err(codec->dev, "Failed to fill register cache: %d\n", 1376 dev_err(codec->dev, "Failed to fill register cache: %d\n",
1371 ret); 1377 ret);
1372 goto out_codec; 1378 goto out;
1373 } 1379 }
1374 1380
1375 snd_soc_add_controls(codec, pm860x_snd_controls, 1381 snd_soc_add_controls(codec, pm860x_snd_controls,
1376 ARRAY_SIZE(pm860x_snd_controls)); 1382 ARRAY_SIZE(pm860x_snd_controls));
1377 snd_soc_dapm_new_controls(codec, pm860x_dapm_widgets, 1383 snd_soc_dapm_new_controls(dapm, pm860x_dapm_widgets,
1378 ARRAY_SIZE(pm860x_dapm_widgets)); 1384 ARRAY_SIZE(pm860x_dapm_widgets));
1379 snd_soc_dapm_add_routes(codec, audio_map, ARRAY_SIZE(audio_map)); 1385 snd_soc_dapm_add_routes(dapm, audio_map, ARRAY_SIZE(audio_map));
1380 return 0; 1386 return 0;
1381 1387
1382out_codec: 1388out:
1383 i = 3; 1389 while (--i >= 0)
1384out_irq:
1385 for (; i >= 0; i--)
1386 free_irq(pm860x->irq[i], pm860x); 1390 free_irq(pm860x->irq[i], pm860x);
1387 return -EINVAL; 1391 return ret;
1388} 1392}
1389 1393
1390static int pm860x_remove(struct snd_soc_codec *codec) 1394static int pm860x_remove(struct snd_soc_codec *codec)
diff --git a/sound/soc/codecs/Kconfig b/sound/soc/codecs/Kconfig
index 3b5690d28b8b..883a312bb293 100644
--- a/sound/soc/codecs/Kconfig
+++ b/sound/soc/codecs/Kconfig
@@ -22,6 +22,7 @@ config SND_SOC_ALL_CODECS
22 select SND_SOC_AK4535 if I2C 22 select SND_SOC_AK4535 if I2C
23 select SND_SOC_AK4642 if I2C 23 select SND_SOC_AK4642 if I2C
24 select SND_SOC_AK4671 if I2C 24 select SND_SOC_AK4671 if I2C
25 select SND_SOC_ALC5623 if I2C
25 select SND_SOC_CQ0093VC if MFD_DAVINCI_VOICECODEC 26 select SND_SOC_CQ0093VC if MFD_DAVINCI_VOICECODEC
26 select SND_SOC_CS42L51 if I2C 27 select SND_SOC_CS42L51 if I2C
27 select SND_SOC_CS4270 if I2C 28 select SND_SOC_CS4270 if I2C
@@ -54,9 +55,11 @@ config SND_SOC_ALL_CODECS
54 select SND_SOC_WM8727 55 select SND_SOC_WM8727
55 select SND_SOC_WM8728 if SND_SOC_I2C_AND_SPI 56 select SND_SOC_WM8728 if SND_SOC_I2C_AND_SPI
56 select SND_SOC_WM8731 if SND_SOC_I2C_AND_SPI 57 select SND_SOC_WM8731 if SND_SOC_I2C_AND_SPI
58 select SND_SOC_WM8737 if SND_SOC_I2C_AND_SPI
57 select SND_SOC_WM8741 if SND_SOC_I2C_AND_SPI 59 select SND_SOC_WM8741 if SND_SOC_I2C_AND_SPI
58 select SND_SOC_WM8750 if SND_SOC_I2C_AND_SPI 60 select SND_SOC_WM8750 if SND_SOC_I2C_AND_SPI
59 select SND_SOC_WM8753 if SND_SOC_I2C_AND_SPI 61 select SND_SOC_WM8753 if SND_SOC_I2C_AND_SPI
62 select SND_SOC_WM8770 if SPI_MASTER
60 select SND_SOC_WM8776 if SND_SOC_I2C_AND_SPI 63 select SND_SOC_WM8776 if SND_SOC_I2C_AND_SPI
61 select SND_SOC_WM8804 if SND_SOC_I2C_AND_SPI 64 select SND_SOC_WM8804 if SND_SOC_I2C_AND_SPI
62 select SND_SOC_WM8900 if I2C 65 select SND_SOC_WM8900 if I2C
@@ -75,6 +78,7 @@ config SND_SOC_ALL_CODECS
75 select SND_SOC_WM8990 if I2C 78 select SND_SOC_WM8990 if I2C
76 select SND_SOC_WM8993 if I2C 79 select SND_SOC_WM8993 if I2C
77 select SND_SOC_WM8994 if MFD_WM8994 80 select SND_SOC_WM8994 if MFD_WM8994
81 select SND_SOC_WM8995 if SND_SOC_I2C_AND_SPI
78 select SND_SOC_WM9081 if I2C 82 select SND_SOC_WM9081 if I2C
79 select SND_SOC_WM9090 if I2C 83 select SND_SOC_WM9090 if I2C
80 select SND_SOC_WM9705 if SND_SOC_AC97_BUS 84 select SND_SOC_WM9705 if SND_SOC_AC97_BUS
@@ -130,6 +134,9 @@ config SND_SOC_AK4642
130config SND_SOC_AK4671 134config SND_SOC_AK4671
131 tristate 135 tristate
132 136
137config SND_SOC_ALC5623
138 tristate
139
133config SND_SOC_CQ0093VC 140config SND_SOC_CQ0093VC
134 tristate 141 tristate
135 142
@@ -160,6 +167,9 @@ config SND_SOC_L3
160config SND_SOC_DA7210 167config SND_SOC_DA7210
161 tristate 168 tristate
162 169
170config SND_SOC_DMIC
171 tristate
172
163config SND_SOC_MAX98088 173config SND_SOC_MAX98088
164 tristate 174 tristate
165 175
@@ -231,6 +241,9 @@ config SND_SOC_WM8728
231config SND_SOC_WM8731 241config SND_SOC_WM8731
232 tristate 242 tristate
233 243
244config SND_SOC_WM8737
245 tristate
246
234config SND_SOC_WM8741 247config SND_SOC_WM8741
235 tristate 248 tristate
236 249
@@ -240,6 +253,9 @@ config SND_SOC_WM8750
240config SND_SOC_WM8753 253config SND_SOC_WM8753
241 tristate 254 tristate
242 255
256config SND_SOC_WM8770
257 tristate
258
243config SND_SOC_WM8776 259config SND_SOC_WM8776
244 tristate 260 tristate
245 261
@@ -294,6 +310,9 @@ config SND_SOC_WM8993
294config SND_SOC_WM8994 310config SND_SOC_WM8994
295 tristate 311 tristate
296 312
313config SND_SOC_WM8995
314 tristate
315
297config SND_SOC_WM9081 316config SND_SOC_WM9081
298 tristate 317 tristate
299 318
@@ -318,3 +337,4 @@ config SND_SOC_WM2000
318 337
319config SND_SOC_WM9090 338config SND_SOC_WM9090
320 tristate 339 tristate
340
diff --git a/sound/soc/codecs/Makefile b/sound/soc/codecs/Makefile
index f67a2d6f7a46..579af9c4f128 100644
--- a/sound/soc/codecs/Makefile
+++ b/sound/soc/codecs/Makefile
@@ -14,9 +14,11 @@ snd-soc-cs42l51-objs := cs42l51.o
14snd-soc-cs4270-objs := cs4270.o 14snd-soc-cs4270-objs := cs4270.o
15snd-soc-cx20442-objs := cx20442.o 15snd-soc-cx20442-objs := cx20442.o
16snd-soc-da7210-objs := da7210.o 16snd-soc-da7210-objs := da7210.o
17snd-soc-dmic-objs := dmic.o
17snd-soc-l3-objs := l3.o 18snd-soc-l3-objs := l3.o
18snd-soc-max98088-objs := max98088.o 19snd-soc-max98088-objs := max98088.o
19snd-soc-pcm3008-objs := pcm3008.o 20snd-soc-pcm3008-objs := pcm3008.o
21snd-soc-alc5623-objs := alc5623.o
20snd-soc-spdif-objs := spdif_transciever.o 22snd-soc-spdif-objs := spdif_transciever.o
21snd-soc-ssm2602-objs := ssm2602.o 23snd-soc-ssm2602-objs := ssm2602.o
22snd-soc-stac9766-objs := stac9766.o 24snd-soc-stac9766-objs := stac9766.o
@@ -38,9 +40,11 @@ snd-soc-wm8711-objs := wm8711.o
38snd-soc-wm8727-objs := wm8727.o 40snd-soc-wm8727-objs := wm8727.o
39snd-soc-wm8728-objs := wm8728.o 41snd-soc-wm8728-objs := wm8728.o
40snd-soc-wm8731-objs := wm8731.o 42snd-soc-wm8731-objs := wm8731.o
43snd-soc-wm8737-objs := wm8737.o
41snd-soc-wm8741-objs := wm8741.o 44snd-soc-wm8741-objs := wm8741.o
42snd-soc-wm8750-objs := wm8750.o 45snd-soc-wm8750-objs := wm8750.o
43snd-soc-wm8753-objs := wm8753.o 46snd-soc-wm8753-objs := wm8753.o
47snd-soc-wm8770-objs := wm8770.o
44snd-soc-wm8776-objs := wm8776.o 48snd-soc-wm8776-objs := wm8776.o
45snd-soc-wm8804-objs := wm8804.o 49snd-soc-wm8804-objs := wm8804.o
46snd-soc-wm8900-objs := wm8900.o 50snd-soc-wm8900-objs := wm8900.o
@@ -58,7 +62,8 @@ snd-soc-wm8985-objs := wm8985.o
58snd-soc-wm8988-objs := wm8988.o 62snd-soc-wm8988-objs := wm8988.o
59snd-soc-wm8990-objs := wm8990.o 63snd-soc-wm8990-objs := wm8990.o
60snd-soc-wm8993-objs := wm8993.o 64snd-soc-wm8993-objs := wm8993.o
61snd-soc-wm8994-objs := wm8994.o 65snd-soc-wm8994-objs := wm8994.o wm8994-tables.o
66snd-soc-wm8995-objs := wm8995.o
62snd-soc-wm9081-objs := wm9081.o 67snd-soc-wm9081-objs := wm9081.o
63snd-soc-wm9705-objs := wm9705.o 68snd-soc-wm9705-objs := wm9705.o
64snd-soc-wm9712-objs := wm9712.o 69snd-soc-wm9712-objs := wm9712.o
@@ -88,10 +93,12 @@ obj-$(CONFIG_SND_SOC_CS42L51) += snd-soc-cs42l51.o
88obj-$(CONFIG_SND_SOC_CS4270) += snd-soc-cs4270.o 93obj-$(CONFIG_SND_SOC_CS4270) += snd-soc-cs4270.o
89obj-$(CONFIG_SND_SOC_CX20442) += snd-soc-cx20442.o 94obj-$(CONFIG_SND_SOC_CX20442) += snd-soc-cx20442.o
90obj-$(CONFIG_SND_SOC_DA7210) += snd-soc-da7210.o 95obj-$(CONFIG_SND_SOC_DA7210) += snd-soc-da7210.o
96obj-$(CONFIG_SND_SOC_DMIC) += snd-soc-dmic.o
91obj-$(CONFIG_SND_SOC_L3) += snd-soc-l3.o 97obj-$(CONFIG_SND_SOC_L3) += snd-soc-l3.o
92obj-$(CONFIG_SND_SOC_JZ4740_CODEC) += snd-soc-jz4740-codec.o 98obj-$(CONFIG_SND_SOC_JZ4740_CODEC) += snd-soc-jz4740-codec.o
93obj-$(CONFIG_SND_SOC_MAX98088) += snd-soc-max98088.o 99obj-$(CONFIG_SND_SOC_MAX98088) += snd-soc-max98088.o
94obj-$(CONFIG_SND_SOC_PCM3008) += snd-soc-pcm3008.o 100obj-$(CONFIG_SND_SOC_PCM3008) += snd-soc-pcm3008.o
101obj-$(CONFIG_SND_SOC_ALC5623) += snd-soc-alc5623.o
95obj-$(CONFIG_SND_SOC_SPDIF) += snd-soc-spdif.o 102obj-$(CONFIG_SND_SOC_SPDIF) += snd-soc-spdif.o
96obj-$(CONFIG_SND_SOC_SSM2602) += snd-soc-ssm2602.o 103obj-$(CONFIG_SND_SOC_SSM2602) += snd-soc-ssm2602.o
97obj-$(CONFIG_SND_SOC_STAC9766) += snd-soc-stac9766.o 104obj-$(CONFIG_SND_SOC_STAC9766) += snd-soc-stac9766.o
@@ -113,9 +120,11 @@ obj-$(CONFIG_SND_SOC_WM8711) += snd-soc-wm8711.o
113obj-$(CONFIG_SND_SOC_WM8727) += snd-soc-wm8727.o 120obj-$(CONFIG_SND_SOC_WM8727) += snd-soc-wm8727.o
114obj-$(CONFIG_SND_SOC_WM8728) += snd-soc-wm8728.o 121obj-$(CONFIG_SND_SOC_WM8728) += snd-soc-wm8728.o
115obj-$(CONFIG_SND_SOC_WM8731) += snd-soc-wm8731.o 122obj-$(CONFIG_SND_SOC_WM8731) += snd-soc-wm8731.o
123obj-$(CONFIG_SND_SOC_WM8737) += snd-soc-wm8737.o
116obj-$(CONFIG_SND_SOC_WM8741) += snd-soc-wm8741.o 124obj-$(CONFIG_SND_SOC_WM8741) += snd-soc-wm8741.o
117obj-$(CONFIG_SND_SOC_WM8750) += snd-soc-wm8750.o 125obj-$(CONFIG_SND_SOC_WM8750) += snd-soc-wm8750.o
118obj-$(CONFIG_SND_SOC_WM8753) += snd-soc-wm8753.o 126obj-$(CONFIG_SND_SOC_WM8753) += snd-soc-wm8753.o
127obj-$(CONFIG_SND_SOC_WM8770) += snd-soc-wm8770.o
119obj-$(CONFIG_SND_SOC_WM8776) += snd-soc-wm8776.o 128obj-$(CONFIG_SND_SOC_WM8776) += snd-soc-wm8776.o
120obj-$(CONFIG_SND_SOC_WM8804) += snd-soc-wm8804.o 129obj-$(CONFIG_SND_SOC_WM8804) += snd-soc-wm8804.o
121obj-$(CONFIG_SND_SOC_WM8900) += snd-soc-wm8900.o 130obj-$(CONFIG_SND_SOC_WM8900) += snd-soc-wm8900.o
@@ -134,6 +143,7 @@ obj-$(CONFIG_SND_SOC_WM8988) += snd-soc-wm8988.o
134obj-$(CONFIG_SND_SOC_WM8990) += snd-soc-wm8990.o 143obj-$(CONFIG_SND_SOC_WM8990) += snd-soc-wm8990.o
135obj-$(CONFIG_SND_SOC_WM8993) += snd-soc-wm8993.o 144obj-$(CONFIG_SND_SOC_WM8993) += snd-soc-wm8993.o
136obj-$(CONFIG_SND_SOC_WM8994) += snd-soc-wm8994.o 145obj-$(CONFIG_SND_SOC_WM8994) += snd-soc-wm8994.o
146obj-$(CONFIG_SND_SOC_WM8995) += snd-soc-wm8995.o
137obj-$(CONFIG_SND_SOC_WM9081) += snd-soc-wm9081.o 147obj-$(CONFIG_SND_SOC_WM9081) += snd-soc-wm9081.o
138obj-$(CONFIG_SND_SOC_WM9705) += snd-soc-wm9705.o 148obj-$(CONFIG_SND_SOC_WM9705) += snd-soc-wm9705.o
139obj-$(CONFIG_SND_SOC_WM9712) += snd-soc-wm9712.o 149obj-$(CONFIG_SND_SOC_WM9712) += snd-soc-wm9712.o
diff --git a/sound/soc/codecs/ad1836.c b/sound/soc/codecs/ad1836.c
index d272534c8f84..ab63d52e36e1 100644
--- a/sound/soc/codecs/ad1836.c
+++ b/sound/soc/codecs/ad1836.c
@@ -27,7 +27,6 @@
27#include <sound/initval.h> 27#include <sound/initval.h>
28#include <sound/soc.h> 28#include <sound/soc.h>
29#include <sound/tlv.h> 29#include <sound/tlv.h>
30#include <sound/soc-dapm.h>
31#include <linux/spi/spi.h> 30#include <linux/spi/spi.h>
32#include "ad1836.h" 31#include "ad1836.h"
33 32
@@ -220,6 +219,7 @@ static struct snd_soc_dai_driver ad1836_dai = {
220static int ad1836_probe(struct snd_soc_codec *codec) 219static int ad1836_probe(struct snd_soc_codec *codec)
221{ 220{
222 struct ad1836_priv *ad1836 = snd_soc_codec_get_drvdata(codec); 221 struct ad1836_priv *ad1836 = snd_soc_codec_get_drvdata(codec);
222 struct snd_soc_dapm_context *dapm = &codec->dapm;
223 int ret = 0; 223 int ret = 0;
224 224
225 codec->control_data = ad1836->control_data; 225 codec->control_data = ad1836->control_data;
@@ -227,7 +227,6 @@ static int ad1836_probe(struct snd_soc_codec *codec)
227 if (ret < 0) { 227 if (ret < 0) {
228 dev_err(codec->dev, "failed to set cache I/O: %d\n", 228 dev_err(codec->dev, "failed to set cache I/O: %d\n",
229 ret); 229 ret);
230 kfree(ad1836);
231 return ret; 230 return ret;
232 } 231 }
233 232
@@ -252,9 +251,9 @@ static int ad1836_probe(struct snd_soc_codec *codec)
252 251
253 snd_soc_add_controls(codec, ad1836_snd_controls, 252 snd_soc_add_controls(codec, ad1836_snd_controls,
254 ARRAY_SIZE(ad1836_snd_controls)); 253 ARRAY_SIZE(ad1836_snd_controls));
255 snd_soc_dapm_new_controls(codec, ad1836_dapm_widgets, 254 snd_soc_dapm_new_controls(dapm, ad1836_dapm_widgets,
256 ARRAY_SIZE(ad1836_dapm_widgets)); 255 ARRAY_SIZE(ad1836_dapm_widgets));
257 snd_soc_dapm_add_routes(codec, audio_paths, ARRAY_SIZE(audio_paths)); 256 snd_soc_dapm_add_routes(dapm, audio_paths, ARRAY_SIZE(audio_paths));
258 257
259 return ret; 258 return ret;
260} 259}
diff --git a/sound/soc/codecs/ad193x.c b/sound/soc/codecs/ad193x.c
index fa2834c91b9f..da46479bfcfa 100644
--- a/sound/soc/codecs/ad193x.c
+++ b/sound/soc/codecs/ad193x.c
@@ -19,12 +19,10 @@
19#include <sound/initval.h> 19#include <sound/initval.h>
20#include <sound/soc.h> 20#include <sound/soc.h>
21#include <sound/tlv.h> 21#include <sound/tlv.h>
22#include <sound/soc-dapm.h>
23#include "ad193x.h" 22#include "ad193x.h"
24 23
25/* codec private data */ 24/* codec private data */
26struct ad193x_priv { 25struct ad193x_priv {
27 u8 reg_cache[AD193X_NUM_REGS];
28 enum snd_soc_control_type bus_type; 26 enum snd_soc_control_type bus_type;
29 void *control_data; 27 void *control_data;
30 int sysclk; 28 int sysclk;
@@ -353,6 +351,7 @@ static struct snd_soc_dai_driver ad193x_dai = {
353static int ad193x_probe(struct snd_soc_codec *codec) 351static int ad193x_probe(struct snd_soc_codec *codec)
354{ 352{
355 struct ad193x_priv *ad193x = snd_soc_codec_get_drvdata(codec); 353 struct ad193x_priv *ad193x = snd_soc_codec_get_drvdata(codec);
354 struct snd_soc_dapm_context *dapm = &codec->dapm;
356 int ret; 355 int ret;
357 356
358 codec->control_data = ad193x->control_data; 357 codec->control_data = ad193x->control_data;
@@ -363,7 +362,6 @@ static int ad193x_probe(struct snd_soc_codec *codec)
363 if (ret < 0) { 362 if (ret < 0) {
364 dev_err(codec->dev, "failed to set cache I/O: %d\n", 363 dev_err(codec->dev, "failed to set cache I/O: %d\n",
365 ret); 364 ret);
366 kfree(ad193x);
367 return ret; 365 return ret;
368 } 366 }
369 367
@@ -385,9 +383,9 @@ static int ad193x_probe(struct snd_soc_codec *codec)
385 383
386 snd_soc_add_controls(codec, ad193x_snd_controls, 384 snd_soc_add_controls(codec, ad193x_snd_controls,
387 ARRAY_SIZE(ad193x_snd_controls)); 385 ARRAY_SIZE(ad193x_snd_controls));
388 snd_soc_dapm_new_controls(codec, ad193x_dapm_widgets, 386 snd_soc_dapm_new_controls(dapm, ad193x_dapm_widgets,
389 ARRAY_SIZE(ad193x_dapm_widgets)); 387 ARRAY_SIZE(ad193x_dapm_widgets));
390 snd_soc_dapm_add_routes(codec, audio_paths, ARRAY_SIZE(audio_paths)); 388 snd_soc_dapm_add_routes(dapm, audio_paths, ARRAY_SIZE(audio_paths));
391 389
392 return ret; 390 return ret;
393} 391}
diff --git a/sound/soc/codecs/ad1980.c b/sound/soc/codecs/ad1980.c
index 410ccd5d41cd..34cb51ef2156 100644
--- a/sound/soc/codecs/ad1980.c
+++ b/sound/soc/codecs/ad1980.c
@@ -29,7 +29,6 @@
29#include <sound/ac97_codec.h> 29#include <sound/ac97_codec.h>
30#include <sound/initval.h> 30#include <sound/initval.h>
31#include <sound/soc.h> 31#include <sound/soc.h>
32#include <sound/soc-dapm.h>
33 32
34#include "ad1980.h" 33#include "ad1980.h"
35 34
diff --git a/sound/soc/codecs/ak4535.c b/sound/soc/codecs/ak4535.c
index cd88c8f32a38..8b38739c88f8 100644
--- a/sound/soc/codecs/ak4535.c
+++ b/sound/soc/codecs/ak4535.c
@@ -24,7 +24,6 @@
24#include <sound/pcm.h> 24#include <sound/pcm.h>
25#include <sound/pcm_params.h> 25#include <sound/pcm_params.h>
26#include <sound/soc.h> 26#include <sound/soc.h>
27#include <sound/soc-dapm.h>
28#include <sound/initval.h> 27#include <sound/initval.h>
29 28
30#include "ak4535.h" 29#include "ak4535.h"
@@ -290,10 +289,11 @@ static const struct snd_soc_dapm_route audio_map[] = {
290 289
291static int ak4535_add_widgets(struct snd_soc_codec *codec) 290static int ak4535_add_widgets(struct snd_soc_codec *codec)
292{ 291{
293 snd_soc_dapm_new_controls(codec, ak4535_dapm_widgets, 292 struct snd_soc_dapm_context *dapm = &codec->dapm;
294 ARRAY_SIZE(ak4535_dapm_widgets));
295 293
296 snd_soc_dapm_add_routes(codec, audio_map, ARRAY_SIZE(audio_map)); 294 snd_soc_dapm_new_controls(dapm, ak4535_dapm_widgets,
295 ARRAY_SIZE(ak4535_dapm_widgets));
296 snd_soc_dapm_add_routes(dapm, audio_map, ARRAY_SIZE(audio_map));
297 297
298 return 0; 298 return 0;
299} 299}
@@ -366,9 +366,9 @@ static int ak4535_set_dai_fmt(struct snd_soc_dai *codec_dai,
366static int ak4535_mute(struct snd_soc_dai *dai, int mute) 366static int ak4535_mute(struct snd_soc_dai *dai, int mute)
367{ 367{
368 struct snd_soc_codec *codec = dai->codec; 368 struct snd_soc_codec *codec = dai->codec;
369 u16 mute_reg = ak4535_read_reg_cache(codec, AK4535_DAC) & 0xffdf; 369 u16 mute_reg = ak4535_read_reg_cache(codec, AK4535_DAC);
370 if (!mute) 370 if (!mute)
371 ak4535_write(codec, AK4535_DAC, mute_reg); 371 ak4535_write(codec, AK4535_DAC, mute_reg & ~0x20);
372 else 372 else
373 ak4535_write(codec, AK4535_DAC, mute_reg | 0x20); 373 ak4535_write(codec, AK4535_DAC, mute_reg | 0x20);
374 return 0; 374 return 0;
@@ -381,11 +381,11 @@ static int ak4535_set_bias_level(struct snd_soc_codec *codec,
381 381
382 switch (level) { 382 switch (level) {
383 case SND_SOC_BIAS_ON: 383 case SND_SOC_BIAS_ON:
384 mute_reg = ak4535_read_reg_cache(codec, AK4535_DAC) & 0xffdf; 384 mute_reg = ak4535_read_reg_cache(codec, AK4535_DAC);
385 ak4535_write(codec, AK4535_DAC, mute_reg); 385 ak4535_write(codec, AK4535_DAC, mute_reg & ~0x20);
386 break; 386 break;
387 case SND_SOC_BIAS_PREPARE: 387 case SND_SOC_BIAS_PREPARE:
388 mute_reg = ak4535_read_reg_cache(codec, AK4535_DAC) & 0xffdf; 388 mute_reg = ak4535_read_reg_cache(codec, AK4535_DAC);
389 ak4535_write(codec, AK4535_DAC, mute_reg | 0x20); 389 ak4535_write(codec, AK4535_DAC, mute_reg | 0x20);
390 break; 390 break;
391 case SND_SOC_BIAS_STANDBY: 391 case SND_SOC_BIAS_STANDBY:
@@ -399,7 +399,7 @@ static int ak4535_set_bias_level(struct snd_soc_codec *codec,
399 ak4535_write(codec, AK4535_PM1, i & (~0x80)); 399 ak4535_write(codec, AK4535_PM1, i & (~0x80));
400 break; 400 break;
401 } 401 }
402 codec->bias_level = level; 402 codec->dapm.bias_level = level;
403 return 0; 403 return 0;
404} 404}
405 405
diff --git a/sound/soc/codecs/ak4642.c b/sound/soc/codecs/ak4642.c
index 90c90b7f4a2e..f00eba313dfd 100644
--- a/sound/soc/codecs/ak4642.c
+++ b/sound/soc/codecs/ak4642.c
@@ -26,7 +26,7 @@
26#include <linux/i2c.h> 26#include <linux/i2c.h>
27#include <linux/platform_device.h> 27#include <linux/platform_device.h>
28#include <linux/slab.h> 28#include <linux/slab.h>
29#include <sound/soc-dapm.h> 29#include <sound/soc.h>
30#include <sound/initval.h> 30#include <sound/initval.h>
31#include <sound/tlv.h> 31#include <sound/tlv.h>
32 32
diff --git a/sound/soc/codecs/ak4671.c b/sound/soc/codecs/ak4671.c
index 24f5f49bb9d2..2ec75abfa3e9 100644
--- a/sound/soc/codecs/ak4671.c
+++ b/sound/soc/codecs/ak4671.c
@@ -17,7 +17,6 @@
17#include <linux/delay.h> 17#include <linux/delay.h>
18#include <linux/slab.h> 18#include <linux/slab.h>
19#include <sound/soc.h> 19#include <sound/soc.h>
20#include <sound/soc-dapm.h>
21#include <sound/initval.h> 20#include <sound/initval.h>
22#include <sound/tlv.h> 21#include <sound/tlv.h>
23 22
@@ -28,7 +27,6 @@
28struct ak4671_priv { 27struct ak4671_priv {
29 enum snd_soc_control_type control_type; 28 enum snd_soc_control_type control_type;
30 void *control_data; 29 void *control_data;
31 u8 reg_cache[AK4671_CACHEREGNUM];
32}; 30};
33 31
34/* ak4671 register cache & default register settings */ 32/* ak4671 register cache & default register settings */
@@ -437,10 +435,11 @@ static const struct snd_soc_dapm_route intercon[] = {
437 435
438static int ak4671_add_widgets(struct snd_soc_codec *codec) 436static int ak4671_add_widgets(struct snd_soc_codec *codec)
439{ 437{
440 snd_soc_dapm_new_controls(codec, ak4671_dapm_widgets, 438 struct snd_soc_dapm_context *dapm = &codec->dapm;
441 ARRAY_SIZE(ak4671_dapm_widgets));
442 439
443 snd_soc_dapm_add_routes(codec, intercon, ARRAY_SIZE(intercon)); 440 snd_soc_dapm_new_controls(dapm, ak4671_dapm_widgets,
441 ARRAY_SIZE(ak4671_dapm_widgets));
442 snd_soc_dapm_add_routes(dapm, intercon, ARRAY_SIZE(intercon));
444 443
445 return 0; 444 return 0;
446} 445}
@@ -602,7 +601,7 @@ static int ak4671_set_bias_level(struct snd_soc_codec *codec,
602 snd_soc_write(codec, AK4671_AD_DA_POWER_MANAGEMENT, 0x00); 601 snd_soc_write(codec, AK4671_AD_DA_POWER_MANAGEMENT, 0x00);
603 break; 602 break;
604 } 603 }
605 codec->bias_level = level; 604 codec->dapm.bias_level = level;
606 return 0; 605 return 0;
607} 606}
608 607
diff --git a/sound/soc/codecs/alc5623.c b/sound/soc/codecs/alc5623.c
new file mode 100644
index 000000000000..4f377c9e868d
--- /dev/null
+++ b/sound/soc/codecs/alc5623.c
@@ -0,0 +1,1117 @@
1/*
2 * alc5623.c -- alc562[123] ALSA Soc Audio driver
3 *
4 * Copyright 2008 Realtek Microelectronics
5 * Author: flove <flove@realtek.com> Ethan <eku@marvell.com>
6 *
7 * Copyright 2010 Arnaud Patard <arnaud.patard@rtp-net.org>
8 *
9 *
10 * Based on WM8753.c
11 *
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License version 2 as
14 * published by the Free Software Foundation.
15 *
16 */
17
18#include <linux/module.h>
19#include <linux/kernel.h>
20#include <linux/init.h>
21#include <linux/delay.h>
22#include <linux/pm.h>
23#include <linux/i2c.h>
24#include <linux/slab.h>
25#include <linux/platform_device.h>
26#include <sound/core.h>
27#include <sound/pcm.h>
28#include <sound/pcm_params.h>
29#include <sound/tlv.h>
30#include <sound/soc.h>
31#include <sound/initval.h>
32#include <sound/alc5623.h>
33
34#include "alc5623.h"
35
36static int caps_charge = 2000;
37module_param(caps_charge, int, 0);
38MODULE_PARM_DESC(caps_charge, "ALC5623 cap charge time (msecs)");
39
40/* codec private data */
41struct alc5623_priv {
42 enum snd_soc_control_type control_type;
43 void *control_data;
44 struct mutex mutex;
45 u8 id;
46 unsigned int sysclk;
47 u16 reg_cache[ALC5623_VENDOR_ID2+2];
48 unsigned int add_ctrl;
49 unsigned int jack_det_ctrl;
50};
51
52static void alc5623_fill_cache(struct snd_soc_codec *codec)
53{
54 int i, step = codec->driver->reg_cache_step;
55 u16 *cache = codec->reg_cache;
56
57 /* not really efficient ... */
58 for (i = 0 ; i < codec->driver->reg_cache_size ; i += step)
59 cache[i] = codec->hw_read(codec, i);
60}
61
62static inline int alc5623_reset(struct snd_soc_codec *codec)
63{
64 return snd_soc_write(codec, ALC5623_RESET, 0);
65}
66
67static int amp_mixer_event(struct snd_soc_dapm_widget *w,
68 struct snd_kcontrol *kcontrol, int event)
69{
70 /* to power-on/off class-d amp generators/speaker */
71 /* need to write to 'index-46h' register : */
72 /* so write index num (here 0x46) to reg 0x6a */
73 /* and then 0xffff/0 to reg 0x6c */
74 snd_soc_write(w->codec, ALC5623_HID_CTRL_INDEX, 0x46);
75
76 switch (event) {
77 case SND_SOC_DAPM_PRE_PMU:
78 snd_soc_write(w->codec, ALC5623_HID_CTRL_DATA, 0xFFFF);
79 break;
80 case SND_SOC_DAPM_POST_PMD:
81 snd_soc_write(w->codec, ALC5623_HID_CTRL_DATA, 0);
82 break;
83 }
84
85 return 0;
86}
87
88/*
89 * ALC5623 Controls
90 */
91
92static const DECLARE_TLV_DB_SCALE(vol_tlv, -3450, 150, 0);
93static const DECLARE_TLV_DB_SCALE(hp_tlv, -4650, 150, 0);
94static const DECLARE_TLV_DB_SCALE(adc_rec_tlv, -1650, 150, 0);
95static const unsigned int boost_tlv[] = {
96 TLV_DB_RANGE_HEAD(3),
97 0, 0, TLV_DB_SCALE_ITEM(0, 0, 0),
98 1, 1, TLV_DB_SCALE_ITEM(2000, 0, 0),
99 2, 2, TLV_DB_SCALE_ITEM(3000, 0, 0),
100};
101static const DECLARE_TLV_DB_SCALE(dig_tlv, 0, 600, 0);
102
103static const struct snd_kcontrol_new rt5621_vol_snd_controls[] = {
104 SOC_DOUBLE_TLV("Speaker Playback Volume",
105 ALC5623_SPK_OUT_VOL, 8, 0, 31, 1, hp_tlv),
106 SOC_DOUBLE("Speaker Playback Switch",
107 ALC5623_SPK_OUT_VOL, 15, 7, 1, 1),
108 SOC_DOUBLE_TLV("Headphone Playback Volume",
109 ALC5623_HP_OUT_VOL, 8, 0, 31, 1, hp_tlv),
110 SOC_DOUBLE("Headphone Playback Switch",
111 ALC5623_HP_OUT_VOL, 15, 7, 1, 1),
112};
113
114static const struct snd_kcontrol_new rt5622_vol_snd_controls[] = {
115 SOC_DOUBLE_TLV("Speaker Playback Volume",
116 ALC5623_SPK_OUT_VOL, 8, 0, 31, 1, hp_tlv),
117 SOC_DOUBLE("Speaker Playback Switch",
118 ALC5623_SPK_OUT_VOL, 15, 7, 1, 1),
119 SOC_DOUBLE_TLV("Line Playback Volume",
120 ALC5623_HP_OUT_VOL, 8, 0, 31, 1, hp_tlv),
121 SOC_DOUBLE("Line Playback Switch",
122 ALC5623_HP_OUT_VOL, 15, 7, 1, 1),
123};
124
125static const struct snd_kcontrol_new alc5623_vol_snd_controls[] = {
126 SOC_DOUBLE_TLV("Line Playback Volume",
127 ALC5623_SPK_OUT_VOL, 8, 0, 31, 1, hp_tlv),
128 SOC_DOUBLE("Line Playback Switch",
129 ALC5623_SPK_OUT_VOL, 15, 7, 1, 1),
130 SOC_DOUBLE_TLV("Headphone Playback Volume",
131 ALC5623_HP_OUT_VOL, 8, 0, 31, 1, hp_tlv),
132 SOC_DOUBLE("Headphone Playback Switch",
133 ALC5623_HP_OUT_VOL, 15, 7, 1, 1),
134};
135
136static const struct snd_kcontrol_new alc5623_snd_controls[] = {
137 SOC_DOUBLE_TLV("Auxout Playback Volume",
138 ALC5623_MONO_AUX_OUT_VOL, 8, 0, 31, 1, hp_tlv),
139 SOC_DOUBLE("Auxout Playback Switch",
140 ALC5623_MONO_AUX_OUT_VOL, 15, 7, 1, 1),
141 SOC_DOUBLE_TLV("PCM Playback Volume",
142 ALC5623_STEREO_DAC_VOL, 8, 0, 31, 1, vol_tlv),
143 SOC_DOUBLE_TLV("AuxI Capture Volume",
144 ALC5623_AUXIN_VOL, 8, 0, 31, 1, vol_tlv),
145 SOC_DOUBLE_TLV("LineIn Capture Volume",
146 ALC5623_LINE_IN_VOL, 8, 0, 31, 1, vol_tlv),
147 SOC_SINGLE_TLV("Mic1 Capture Volume",
148 ALC5623_MIC_VOL, 8, 31, 1, vol_tlv),
149 SOC_SINGLE_TLV("Mic2 Capture Volume",
150 ALC5623_MIC_VOL, 0, 31, 1, vol_tlv),
151 SOC_DOUBLE_TLV("Rec Capture Volume",
152 ALC5623_ADC_REC_GAIN, 7, 0, 31, 0, adc_rec_tlv),
153 SOC_SINGLE_TLV("Mic 1 Boost Volume",
154 ALC5623_MIC_CTRL, 10, 2, 0, boost_tlv),
155 SOC_SINGLE_TLV("Mic 2 Boost Volume",
156 ALC5623_MIC_CTRL, 8, 2, 0, boost_tlv),
157 SOC_SINGLE_TLV("Digital Boost Volume",
158 ALC5623_ADD_CTRL_REG, 4, 3, 0, dig_tlv),
159};
160
161/*
162 * DAPM Controls
163 */
164static const struct snd_kcontrol_new alc5623_hp_mixer_controls[] = {
165SOC_DAPM_SINGLE("LI2HP Playback Switch", ALC5623_LINE_IN_VOL, 15, 1, 1),
166SOC_DAPM_SINGLE("AUXI2HP Playback Switch", ALC5623_AUXIN_VOL, 15, 1, 1),
167SOC_DAPM_SINGLE("MIC12HP Playback Switch", ALC5623_MIC_ROUTING_CTRL, 15, 1, 1),
168SOC_DAPM_SINGLE("MIC22HP Playback Switch", ALC5623_MIC_ROUTING_CTRL, 7, 1, 1),
169SOC_DAPM_SINGLE("DAC2HP Playback Switch", ALC5623_STEREO_DAC_VOL, 15, 1, 1),
170};
171
172static const struct snd_kcontrol_new alc5623_hpl_mixer_controls[] = {
173SOC_DAPM_SINGLE("ADC2HP_L Playback Switch", ALC5623_ADC_REC_GAIN, 15, 1, 1),
174};
175
176static const struct snd_kcontrol_new alc5623_hpr_mixer_controls[] = {
177SOC_DAPM_SINGLE("ADC2HP_R Playback Switch", ALC5623_ADC_REC_GAIN, 14, 1, 1),
178};
179
180static const struct snd_kcontrol_new alc5623_mono_mixer_controls[] = {
181SOC_DAPM_SINGLE("ADC2MONO_L Playback Switch", ALC5623_ADC_REC_GAIN, 13, 1, 1),
182SOC_DAPM_SINGLE("ADC2MONO_R Playback Switch", ALC5623_ADC_REC_GAIN, 12, 1, 1),
183SOC_DAPM_SINGLE("LI2MONO Playback Switch", ALC5623_LINE_IN_VOL, 13, 1, 1),
184SOC_DAPM_SINGLE("AUXI2MONO Playback Switch", ALC5623_AUXIN_VOL, 13, 1, 1),
185SOC_DAPM_SINGLE("MIC12MONO Playback Switch", ALC5623_MIC_ROUTING_CTRL, 13, 1, 1),
186SOC_DAPM_SINGLE("MIC22MONO Playback Switch", ALC5623_MIC_ROUTING_CTRL, 5, 1, 1),
187SOC_DAPM_SINGLE("DAC2MONO Playback Switch", ALC5623_STEREO_DAC_VOL, 13, 1, 1),
188};
189
190static const struct snd_kcontrol_new alc5623_speaker_mixer_controls[] = {
191SOC_DAPM_SINGLE("LI2SPK Playback Switch", ALC5623_LINE_IN_VOL, 14, 1, 1),
192SOC_DAPM_SINGLE("AUXI2SPK Playback Switch", ALC5623_AUXIN_VOL, 14, 1, 1),
193SOC_DAPM_SINGLE("MIC12SPK Playback Switch", ALC5623_MIC_ROUTING_CTRL, 14, 1, 1),
194SOC_DAPM_SINGLE("MIC22SPK Playback Switch", ALC5623_MIC_ROUTING_CTRL, 6, 1, 1),
195SOC_DAPM_SINGLE("DAC2SPK Playback Switch", ALC5623_STEREO_DAC_VOL, 14, 1, 1),
196};
197
198/* Left Record Mixer */
199static const struct snd_kcontrol_new alc5623_captureL_mixer_controls[] = {
200SOC_DAPM_SINGLE("Mic1 Capture Switch", ALC5623_ADC_REC_MIXER, 14, 1, 1),
201SOC_DAPM_SINGLE("Mic2 Capture Switch", ALC5623_ADC_REC_MIXER, 13, 1, 1),
202SOC_DAPM_SINGLE("LineInL Capture Switch", ALC5623_ADC_REC_MIXER, 12, 1, 1),
203SOC_DAPM_SINGLE("Left AuxI Capture Switch", ALC5623_ADC_REC_MIXER, 11, 1, 1),
204SOC_DAPM_SINGLE("HPMixerL Capture Switch", ALC5623_ADC_REC_MIXER, 10, 1, 1),
205SOC_DAPM_SINGLE("SPKMixer Capture Switch", ALC5623_ADC_REC_MIXER, 9, 1, 1),
206SOC_DAPM_SINGLE("MonoMixer Capture Switch", ALC5623_ADC_REC_MIXER, 8, 1, 1),
207};
208
209/* Right Record Mixer */
210static const struct snd_kcontrol_new alc5623_captureR_mixer_controls[] = {
211SOC_DAPM_SINGLE("Mic1 Capture Switch", ALC5623_ADC_REC_MIXER, 6, 1, 1),
212SOC_DAPM_SINGLE("Mic2 Capture Switch", ALC5623_ADC_REC_MIXER, 5, 1, 1),
213SOC_DAPM_SINGLE("LineInR Capture Switch", ALC5623_ADC_REC_MIXER, 4, 1, 1),
214SOC_DAPM_SINGLE("Right AuxI Capture Switch", ALC5623_ADC_REC_MIXER, 3, 1, 1),
215SOC_DAPM_SINGLE("HPMixerR Capture Switch", ALC5623_ADC_REC_MIXER, 2, 1, 1),
216SOC_DAPM_SINGLE("SPKMixer Capture Switch", ALC5623_ADC_REC_MIXER, 1, 1, 1),
217SOC_DAPM_SINGLE("MonoMixer Capture Switch", ALC5623_ADC_REC_MIXER, 0, 1, 1),
218};
219
220static const char *alc5623_spk_n_sour_sel[] = {
221 "RN/-R", "RP/+R", "LN/-R", "Vmid" };
222static const char *alc5623_hpl_out_input_sel[] = {
223 "Vmid", "HP Left Mix"};
224static const char *alc5623_hpr_out_input_sel[] = {
225 "Vmid", "HP Right Mix"};
226static const char *alc5623_spkout_input_sel[] = {
227 "Vmid", "HPOut Mix", "Speaker Mix", "Mono Mix"};
228static const char *alc5623_aux_out_input_sel[] = {
229 "Vmid", "HPOut Mix", "Speaker Mix", "Mono Mix"};
230
231/* auxout output mux */
232static const struct soc_enum alc5623_aux_out_input_enum =
233SOC_ENUM_SINGLE(ALC5623_OUTPUT_MIXER_CTRL, 6, 4, alc5623_aux_out_input_sel);
234static const struct snd_kcontrol_new alc5623_auxout_mux_controls =
235SOC_DAPM_ENUM("Route", alc5623_aux_out_input_enum);
236
237/* speaker output mux */
238static const struct soc_enum alc5623_spkout_input_enum =
239SOC_ENUM_SINGLE(ALC5623_OUTPUT_MIXER_CTRL, 10, 4, alc5623_spkout_input_sel);
240static const struct snd_kcontrol_new alc5623_spkout_mux_controls =
241SOC_DAPM_ENUM("Route", alc5623_spkout_input_enum);
242
243/* headphone left output mux */
244static const struct soc_enum alc5623_hpl_out_input_enum =
245SOC_ENUM_SINGLE(ALC5623_OUTPUT_MIXER_CTRL, 9, 2, alc5623_hpl_out_input_sel);
246static const struct snd_kcontrol_new alc5623_hpl_out_mux_controls =
247SOC_DAPM_ENUM("Route", alc5623_hpl_out_input_enum);
248
249/* headphone right output mux */
250static const struct soc_enum alc5623_hpr_out_input_enum =
251SOC_ENUM_SINGLE(ALC5623_OUTPUT_MIXER_CTRL, 8, 2, alc5623_hpr_out_input_sel);
252static const struct snd_kcontrol_new alc5623_hpr_out_mux_controls =
253SOC_DAPM_ENUM("Route", alc5623_hpr_out_input_enum);
254
255/* speaker output N select */
256static const struct soc_enum alc5623_spk_n_sour_enum =
257SOC_ENUM_SINGLE(ALC5623_OUTPUT_MIXER_CTRL, 14, 4, alc5623_spk_n_sour_sel);
258static const struct snd_kcontrol_new alc5623_spkoutn_mux_controls =
259SOC_DAPM_ENUM("Route", alc5623_spk_n_sour_enum);
260
261static const struct snd_soc_dapm_widget alc5623_dapm_widgets[] = {
262/* Muxes */
263SND_SOC_DAPM_MUX("AuxOut Mux", SND_SOC_NOPM, 0, 0,
264 &alc5623_auxout_mux_controls),
265SND_SOC_DAPM_MUX("SpeakerOut Mux", SND_SOC_NOPM, 0, 0,
266 &alc5623_spkout_mux_controls),
267SND_SOC_DAPM_MUX("Left Headphone Mux", SND_SOC_NOPM, 0, 0,
268 &alc5623_hpl_out_mux_controls),
269SND_SOC_DAPM_MUX("Right Headphone Mux", SND_SOC_NOPM, 0, 0,
270 &alc5623_hpr_out_mux_controls),
271SND_SOC_DAPM_MUX("SpeakerOut N Mux", SND_SOC_NOPM, 0, 0,
272 &alc5623_spkoutn_mux_controls),
273
274/* output mixers */
275SND_SOC_DAPM_MIXER("HP Mix", SND_SOC_NOPM, 0, 0,
276 &alc5623_hp_mixer_controls[0],
277 ARRAY_SIZE(alc5623_hp_mixer_controls)),
278SND_SOC_DAPM_MIXER("HPR Mix", ALC5623_PWR_MANAG_ADD2, 4, 0,
279 &alc5623_hpr_mixer_controls[0],
280 ARRAY_SIZE(alc5623_hpr_mixer_controls)),
281SND_SOC_DAPM_MIXER("HPL Mix", ALC5623_PWR_MANAG_ADD2, 5, 0,
282 &alc5623_hpl_mixer_controls[0],
283 ARRAY_SIZE(alc5623_hpl_mixer_controls)),
284SND_SOC_DAPM_MIXER("HPOut Mix", SND_SOC_NOPM, 0, 0, NULL, 0),
285SND_SOC_DAPM_MIXER("Mono Mix", ALC5623_PWR_MANAG_ADD2, 2, 0,
286 &alc5623_mono_mixer_controls[0],
287 ARRAY_SIZE(alc5623_mono_mixer_controls)),
288SND_SOC_DAPM_MIXER("Speaker Mix", ALC5623_PWR_MANAG_ADD2, 3, 0,
289 &alc5623_speaker_mixer_controls[0],
290 ARRAY_SIZE(alc5623_speaker_mixer_controls)),
291
292/* input mixers */
293SND_SOC_DAPM_MIXER("Left Capture Mix", ALC5623_PWR_MANAG_ADD2, 1, 0,
294 &alc5623_captureL_mixer_controls[0],
295 ARRAY_SIZE(alc5623_captureL_mixer_controls)),
296SND_SOC_DAPM_MIXER("Right Capture Mix", ALC5623_PWR_MANAG_ADD2, 0, 0,
297 &alc5623_captureR_mixer_controls[0],
298 ARRAY_SIZE(alc5623_captureR_mixer_controls)),
299
300SND_SOC_DAPM_DAC("Left DAC", "Left HiFi Playback",
301 ALC5623_PWR_MANAG_ADD2, 9, 0),
302SND_SOC_DAPM_DAC("Right DAC", "Right HiFi Playback",
303 ALC5623_PWR_MANAG_ADD2, 8, 0),
304SND_SOC_DAPM_MIXER("I2S Mix", ALC5623_PWR_MANAG_ADD1, 15, 0, NULL, 0),
305SND_SOC_DAPM_MIXER("AuxI Mix", SND_SOC_NOPM, 0, 0, NULL, 0),
306SND_SOC_DAPM_MIXER("Line Mix", SND_SOC_NOPM, 0, 0, NULL, 0),
307SND_SOC_DAPM_ADC("Left ADC", "Left HiFi Capture",
308 ALC5623_PWR_MANAG_ADD2, 7, 0),
309SND_SOC_DAPM_ADC("Right ADC", "Right HiFi Capture",
310 ALC5623_PWR_MANAG_ADD2, 6, 0),
311SND_SOC_DAPM_PGA("Left Headphone", ALC5623_PWR_MANAG_ADD3, 10, 0, NULL, 0),
312SND_SOC_DAPM_PGA("Right Headphone", ALC5623_PWR_MANAG_ADD3, 9, 0, NULL, 0),
313SND_SOC_DAPM_PGA("SpeakerOut", ALC5623_PWR_MANAG_ADD3, 12, 0, NULL, 0),
314SND_SOC_DAPM_PGA("Left AuxOut", ALC5623_PWR_MANAG_ADD3, 14, 0, NULL, 0),
315SND_SOC_DAPM_PGA("Right AuxOut", ALC5623_PWR_MANAG_ADD3, 13, 0, NULL, 0),
316SND_SOC_DAPM_PGA("Left LineIn", ALC5623_PWR_MANAG_ADD3, 7, 0, NULL, 0),
317SND_SOC_DAPM_PGA("Right LineIn", ALC5623_PWR_MANAG_ADD3, 6, 0, NULL, 0),
318SND_SOC_DAPM_PGA("Left AuxI", ALC5623_PWR_MANAG_ADD3, 5, 0, NULL, 0),
319SND_SOC_DAPM_PGA("Right AuxI", ALC5623_PWR_MANAG_ADD3, 4, 0, NULL, 0),
320SND_SOC_DAPM_PGA("MIC1 PGA", ALC5623_PWR_MANAG_ADD3, 3, 0, NULL, 0),
321SND_SOC_DAPM_PGA("MIC2 PGA", ALC5623_PWR_MANAG_ADD3, 2, 0, NULL, 0),
322SND_SOC_DAPM_PGA("MIC1 Pre Amp", ALC5623_PWR_MANAG_ADD3, 1, 0, NULL, 0),
323SND_SOC_DAPM_PGA("MIC2 Pre Amp", ALC5623_PWR_MANAG_ADD3, 0, 0, NULL, 0),
324SND_SOC_DAPM_MICBIAS("Mic Bias1", ALC5623_PWR_MANAG_ADD1, 11, 0),
325
326SND_SOC_DAPM_OUTPUT("AUXOUTL"),
327SND_SOC_DAPM_OUTPUT("AUXOUTR"),
328SND_SOC_DAPM_OUTPUT("HPL"),
329SND_SOC_DAPM_OUTPUT("HPR"),
330SND_SOC_DAPM_OUTPUT("SPKOUT"),
331SND_SOC_DAPM_OUTPUT("SPKOUTN"),
332SND_SOC_DAPM_INPUT("LINEINL"),
333SND_SOC_DAPM_INPUT("LINEINR"),
334SND_SOC_DAPM_INPUT("AUXINL"),
335SND_SOC_DAPM_INPUT("AUXINR"),
336SND_SOC_DAPM_INPUT("MIC1"),
337SND_SOC_DAPM_INPUT("MIC2"),
338SND_SOC_DAPM_VMID("Vmid"),
339};
340
341static const char *alc5623_amp_names[] = {"AB Amp", "D Amp"};
342static const struct soc_enum alc5623_amp_enum =
343 SOC_ENUM_SINGLE(ALC5623_OUTPUT_MIXER_CTRL, 13, 2, alc5623_amp_names);
344static const struct snd_kcontrol_new alc5623_amp_mux_controls =
345 SOC_DAPM_ENUM("Route", alc5623_amp_enum);
346
347static const struct snd_soc_dapm_widget alc5623_dapm_amp_widgets[] = {
348SND_SOC_DAPM_PGA_E("D Amp", ALC5623_PWR_MANAG_ADD2, 14, 0, NULL, 0,
349 amp_mixer_event, SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
350SND_SOC_DAPM_PGA("AB Amp", ALC5623_PWR_MANAG_ADD2, 15, 0, NULL, 0),
351SND_SOC_DAPM_MUX("AB-D Amp Mux", SND_SOC_NOPM, 0, 0,
352 &alc5623_amp_mux_controls),
353};
354
355static const struct snd_soc_dapm_route intercon[] = {
356 /* virtual mixer - mixes left & right channels */
357 {"I2S Mix", NULL, "Left DAC"},
358 {"I2S Mix", NULL, "Right DAC"},
359 {"Line Mix", NULL, "Right LineIn"},
360 {"Line Mix", NULL, "Left LineIn"},
361 {"AuxI Mix", NULL, "Left AuxI"},
362 {"AuxI Mix", NULL, "Right AuxI"},
363 {"AUXOUTL", NULL, "Left AuxOut"},
364 {"AUXOUTR", NULL, "Right AuxOut"},
365
366 /* HP mixer */
367 {"HPL Mix", "ADC2HP_L Playback Switch", "Left Capture Mix"},
368 {"HPL Mix", NULL, "HP Mix"},
369 {"HPR Mix", "ADC2HP_R Playback Switch", "Right Capture Mix"},
370 {"HPR Mix", NULL, "HP Mix"},
371 {"HP Mix", "LI2HP Playback Switch", "Line Mix"},
372 {"HP Mix", "AUXI2HP Playback Switch", "AuxI Mix"},
373 {"HP Mix", "MIC12HP Playback Switch", "MIC1 PGA"},
374 {"HP Mix", "MIC22HP Playback Switch", "MIC2 PGA"},
375 {"HP Mix", "DAC2HP Playback Switch", "I2S Mix"},
376
377 /* speaker mixer */
378 {"Speaker Mix", "LI2SPK Playback Switch", "Line Mix"},
379 {"Speaker Mix", "AUXI2SPK Playback Switch", "AuxI Mix"},
380 {"Speaker Mix", "MIC12SPK Playback Switch", "MIC1 PGA"},
381 {"Speaker Mix", "MIC22SPK Playback Switch", "MIC2 PGA"},
382 {"Speaker Mix", "DAC2SPK Playback Switch", "I2S Mix"},
383
384 /* mono mixer */
385 {"Mono Mix", "ADC2MONO_L Playback Switch", "Left Capture Mix"},
386 {"Mono Mix", "ADC2MONO_R Playback Switch", "Right Capture Mix"},
387 {"Mono Mix", "LI2MONO Playback Switch", "Line Mix"},
388 {"Mono Mix", "AUXI2MONO Playback Switch", "AuxI Mix"},
389 {"Mono Mix", "MIC12MONO Playback Switch", "MIC1 PGA"},
390 {"Mono Mix", "MIC22MONO Playback Switch", "MIC2 PGA"},
391 {"Mono Mix", "DAC2MONO Playback Switch", "I2S Mix"},
392
393 /* Left record mixer */
394 {"Left Capture Mix", "LineInL Capture Switch", "LINEINL"},
395 {"Left Capture Mix", "Left AuxI Capture Switch", "AUXINL"},
396 {"Left Capture Mix", "Mic1 Capture Switch", "MIC1 Pre Amp"},
397 {"Left Capture Mix", "Mic2 Capture Switch", "MIC2 Pre Amp"},
398 {"Left Capture Mix", "HPMixerL Capture Switch", "HPL Mix"},
399 {"Left Capture Mix", "SPKMixer Capture Switch", "Speaker Mix"},
400 {"Left Capture Mix", "MonoMixer Capture Switch", "Mono Mix"},
401
402 /*Right record mixer */
403 {"Right Capture Mix", "LineInR Capture Switch", "LINEINR"},
404 {"Right Capture Mix", "Right AuxI Capture Switch", "AUXINR"},
405 {"Right Capture Mix", "Mic1 Capture Switch", "MIC1 Pre Amp"},
406 {"Right Capture Mix", "Mic2 Capture Switch", "MIC2 Pre Amp"},
407 {"Right Capture Mix", "HPMixerR Capture Switch", "HPR Mix"},
408 {"Right Capture Mix", "SPKMixer Capture Switch", "Speaker Mix"},
409 {"Right Capture Mix", "MonoMixer Capture Switch", "Mono Mix"},
410
411 /* headphone left mux */
412 {"Left Headphone Mux", "HP Left Mix", "HPL Mix"},
413 {"Left Headphone Mux", "Vmid", "Vmid"},
414
415 /* headphone right mux */
416 {"Right Headphone Mux", "HP Right Mix", "HPR Mix"},
417 {"Right Headphone Mux", "Vmid", "Vmid"},
418
419 /* speaker out mux */
420 {"SpeakerOut Mux", "Vmid", "Vmid"},
421 {"SpeakerOut Mux", "HPOut Mix", "HPOut Mix"},
422 {"SpeakerOut Mux", "Speaker Mix", "Speaker Mix"},
423 {"SpeakerOut Mux", "Mono Mix", "Mono Mix"},
424
425 /* Mono/Aux Out mux */
426 {"AuxOut Mux", "Vmid", "Vmid"},
427 {"AuxOut Mux", "HPOut Mix", "HPOut Mix"},
428 {"AuxOut Mux", "Speaker Mix", "Speaker Mix"},
429 {"AuxOut Mux", "Mono Mix", "Mono Mix"},
430
431 /* output pga */
432 {"HPL", NULL, "Left Headphone"},
433 {"Left Headphone", NULL, "Left Headphone Mux"},
434 {"HPR", NULL, "Right Headphone"},
435 {"Right Headphone", NULL, "Right Headphone Mux"},
436 {"Left AuxOut", NULL, "AuxOut Mux"},
437 {"Right AuxOut", NULL, "AuxOut Mux"},
438
439 /* input pga */
440 {"Left LineIn", NULL, "LINEINL"},
441 {"Right LineIn", NULL, "LINEINR"},
442 {"Left AuxI", NULL, "AUXINL"},
443 {"Right AuxI", NULL, "AUXINR"},
444 {"MIC1 Pre Amp", NULL, "MIC1"},
445 {"MIC2 Pre Amp", NULL, "MIC2"},
446 {"MIC1 PGA", NULL, "MIC1 Pre Amp"},
447 {"MIC2 PGA", NULL, "MIC2 Pre Amp"},
448
449 /* left ADC */
450 {"Left ADC", NULL, "Left Capture Mix"},
451
452 /* right ADC */
453 {"Right ADC", NULL, "Right Capture Mix"},
454
455 {"SpeakerOut N Mux", "RN/-R", "SpeakerOut"},
456 {"SpeakerOut N Mux", "RP/+R", "SpeakerOut"},
457 {"SpeakerOut N Mux", "LN/-R", "SpeakerOut"},
458 {"SpeakerOut N Mux", "Vmid", "Vmid"},
459
460 {"SPKOUT", NULL, "SpeakerOut"},
461 {"SPKOUTN", NULL, "SpeakerOut N Mux"},
462};
463
464static const struct snd_soc_dapm_route intercon_spk[] = {
465 {"SpeakerOut", NULL, "SpeakerOut Mux"},
466};
467
468static const struct snd_soc_dapm_route intercon_amp_spk[] = {
469 {"AB Amp", NULL, "SpeakerOut Mux"},
470 {"D Amp", NULL, "SpeakerOut Mux"},
471 {"AB-D Amp Mux", "AB Amp", "AB Amp"},
472 {"AB-D Amp Mux", "D Amp", "D Amp"},
473 {"SpeakerOut", NULL, "AB-D Amp Mux"},
474};
475
476/* PLL divisors */
477struct _pll_div {
478 u32 pll_in;
479 u32 pll_out;
480 u16 regvalue;
481};
482
483/* Note : pll code from original alc5623 driver. Not sure of how good it is */
484/* usefull only for master mode */
485static const struct _pll_div codec_master_pll_div[] = {
486
487 { 2048000, 8192000, 0x0ea0},
488 { 3686400, 8192000, 0x4e27},
489 { 12000000, 8192000, 0x456b},
490 { 13000000, 8192000, 0x495f},
491 { 13100000, 8192000, 0x0320},
492 { 2048000, 11289600, 0xf637},
493 { 3686400, 11289600, 0x2f22},
494 { 12000000, 11289600, 0x3e2f},
495 { 13000000, 11289600, 0x4d5b},
496 { 13100000, 11289600, 0x363b},
497 { 2048000, 16384000, 0x1ea0},
498 { 3686400, 16384000, 0x9e27},
499 { 12000000, 16384000, 0x452b},
500 { 13000000, 16384000, 0x542f},
501 { 13100000, 16384000, 0x03a0},
502 { 2048000, 16934400, 0xe625},
503 { 3686400, 16934400, 0x9126},
504 { 12000000, 16934400, 0x4d2c},
505 { 13000000, 16934400, 0x742f},
506 { 13100000, 16934400, 0x3c27},
507 { 2048000, 22579200, 0x2aa0},
508 { 3686400, 22579200, 0x2f20},
509 { 12000000, 22579200, 0x7e2f},
510 { 13000000, 22579200, 0x742f},
511 { 13100000, 22579200, 0x3c27},
512 { 2048000, 24576000, 0x2ea0},
513 { 3686400, 24576000, 0xee27},
514 { 12000000, 24576000, 0x2915},
515 { 13000000, 24576000, 0x772e},
516 { 13100000, 24576000, 0x0d20},
517};
518
519static const struct _pll_div codec_slave_pll_div[] = {
520
521 { 1024000, 16384000, 0x3ea0},
522 { 1411200, 22579200, 0x3ea0},
523 { 1536000, 24576000, 0x3ea0},
524 { 2048000, 16384000, 0x1ea0},
525 { 2822400, 22579200, 0x1ea0},
526 { 3072000, 24576000, 0x1ea0},
527
528};
529
530static int alc5623_set_dai_pll(struct snd_soc_dai *codec_dai, int pll_id,
531 int source, unsigned int freq_in, unsigned int freq_out)
532{
533 int i;
534 struct snd_soc_codec *codec = codec_dai->codec;
535 int gbl_clk = 0, pll_div = 0;
536 u16 reg;
537
538 if (pll_id < ALC5623_PLL_FR_MCLK || pll_id > ALC5623_PLL_FR_BCK)
539 return -ENODEV;
540
541 /* Disable PLL power */
542 snd_soc_update_bits(codec, ALC5623_PWR_MANAG_ADD2,
543 ALC5623_PWR_ADD2_PLL,
544 0);
545
546 /* pll is not used in slave mode */
547 reg = snd_soc_read(codec, ALC5623_DAI_CONTROL);
548 if (reg & ALC5623_DAI_SDP_SLAVE_MODE)
549 return 0;
550
551 if (!freq_in || !freq_out)
552 return 0;
553
554 switch (pll_id) {
555 case ALC5623_PLL_FR_MCLK:
556 for (i = 0; i < ARRAY_SIZE(codec_master_pll_div); i++) {
557 if (codec_master_pll_div[i].pll_in == freq_in
558 && codec_master_pll_div[i].pll_out == freq_out) {
559 /* PLL source from MCLK */
560 pll_div = codec_master_pll_div[i].regvalue;
561 break;
562 }
563 }
564 break;
565 case ALC5623_PLL_FR_BCK:
566 for (i = 0; i < ARRAY_SIZE(codec_slave_pll_div); i++) {
567 if (codec_slave_pll_div[i].pll_in == freq_in
568 && codec_slave_pll_div[i].pll_out == freq_out) {
569 /* PLL source from Bitclk */
570 gbl_clk = ALC5623_GBL_CLK_PLL_SOUR_SEL_BITCLK;
571 pll_div = codec_slave_pll_div[i].regvalue;
572 break;
573 }
574 }
575 break;
576 default:
577 return -EINVAL;
578 }
579
580 if (!pll_div)
581 return -EINVAL;
582
583 snd_soc_write(codec, ALC5623_GLOBAL_CLK_CTRL_REG, gbl_clk);
584 snd_soc_write(codec, ALC5623_PLL_CTRL, pll_div);
585 snd_soc_update_bits(codec, ALC5623_PWR_MANAG_ADD2,
586 ALC5623_PWR_ADD2_PLL,
587 ALC5623_PWR_ADD2_PLL);
588 gbl_clk |= ALC5623_GBL_CLK_SYS_SOUR_SEL_PLL;
589 snd_soc_write(codec, ALC5623_GLOBAL_CLK_CTRL_REG, gbl_clk);
590
591 return 0;
592}
593
594struct _coeff_div {
595 u16 fs;
596 u16 regvalue;
597};
598
599/* codec hifi mclk (after PLL) clock divider coefficients */
600/* values inspired from column BCLK=32Fs of Appendix A table */
601static const struct _coeff_div coeff_div[] = {
602 {256*8, 0x3a69},
603 {384*8, 0x3c6b},
604 {256*4, 0x2a69},
605 {384*4, 0x2c6b},
606 {256*2, 0x1a69},
607 {384*2, 0x1c6b},
608 {256*1, 0x0a69},
609 {384*1, 0x0c6b},
610};
611
612static int get_coeff(struct snd_soc_codec *codec, int rate)
613{
614 struct alc5623_priv *alc5623 = snd_soc_codec_get_drvdata(codec);
615 int i;
616
617 for (i = 0; i < ARRAY_SIZE(coeff_div); i++) {
618 if (coeff_div[i].fs * rate == alc5623->sysclk)
619 return i;
620 }
621 return -EINVAL;
622}
623
624/*
625 * Clock after PLL and dividers
626 */
627static int alc5623_set_dai_sysclk(struct snd_soc_dai *codec_dai,
628 int clk_id, unsigned int freq, int dir)
629{
630 struct snd_soc_codec *codec = codec_dai->codec;
631 struct alc5623_priv *alc5623 = snd_soc_codec_get_drvdata(codec);
632
633 switch (freq) {
634 case 8192000:
635 case 11289600:
636 case 12288000:
637 case 16384000:
638 case 16934400:
639 case 18432000:
640 case 22579200:
641 case 24576000:
642 alc5623->sysclk = freq;
643 return 0;
644 }
645 return -EINVAL;
646}
647
648static int alc5623_set_dai_fmt(struct snd_soc_dai *codec_dai,
649 unsigned int fmt)
650{
651 struct snd_soc_codec *codec = codec_dai->codec;
652 u16 iface = 0;
653
654 /* set master/slave audio interface */
655 switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
656 case SND_SOC_DAIFMT_CBM_CFM:
657 iface = ALC5623_DAI_SDP_MASTER_MODE;
658 break;
659 case SND_SOC_DAIFMT_CBS_CFS:
660 iface = ALC5623_DAI_SDP_SLAVE_MODE;
661 break;
662 default:
663 return -EINVAL;
664 }
665
666 /* interface format */
667 switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
668 case SND_SOC_DAIFMT_I2S:
669 iface |= ALC5623_DAI_I2S_DF_I2S;
670 break;
671 case SND_SOC_DAIFMT_RIGHT_J:
672 iface |= ALC5623_DAI_I2S_DF_RIGHT;
673 break;
674 case SND_SOC_DAIFMT_LEFT_J:
675 iface |= ALC5623_DAI_I2S_DF_LEFT;
676 break;
677 case SND_SOC_DAIFMT_DSP_A:
678 iface |= ALC5623_DAI_I2S_DF_PCM;
679 break;
680 case SND_SOC_DAIFMT_DSP_B:
681 iface |= ALC5623_DAI_I2S_DF_PCM | ALC5623_DAI_I2S_PCM_MODE;
682 break;
683 default:
684 return -EINVAL;
685 }
686
687 /* clock inversion */
688 switch (fmt & SND_SOC_DAIFMT_INV_MASK) {
689 case SND_SOC_DAIFMT_NB_NF:
690 break;
691 case SND_SOC_DAIFMT_IB_IF:
692 iface |= ALC5623_DAI_MAIN_I2S_BCLK_POL_CTRL;
693 break;
694 case SND_SOC_DAIFMT_IB_NF:
695 iface |= ALC5623_DAI_MAIN_I2S_BCLK_POL_CTRL;
696 break;
697 case SND_SOC_DAIFMT_NB_IF:
698 break;
699 default:
700 return -EINVAL;
701 }
702
703 return snd_soc_write(codec, ALC5623_DAI_CONTROL, iface);
704}
705
706static int alc5623_pcm_hw_params(struct snd_pcm_substream *substream,
707 struct snd_pcm_hw_params *params, struct snd_soc_dai *dai)
708{
709 struct snd_soc_pcm_runtime *rtd = substream->private_data;
710 struct snd_soc_codec *codec = rtd->codec;
711 struct alc5623_priv *alc5623 = snd_soc_codec_get_drvdata(codec);
712 int coeff, rate;
713 u16 iface;
714
715 iface = snd_soc_read(codec, ALC5623_DAI_CONTROL);
716 iface &= ~ALC5623_DAI_I2S_DL_MASK;
717
718 /* bit size */
719 switch (params_format(params)) {
720 case SNDRV_PCM_FORMAT_S16_LE:
721 iface |= ALC5623_DAI_I2S_DL_16;
722 break;
723 case SNDRV_PCM_FORMAT_S20_3LE:
724 iface |= ALC5623_DAI_I2S_DL_20;
725 break;
726 case SNDRV_PCM_FORMAT_S24_LE:
727 iface |= ALC5623_DAI_I2S_DL_24;
728 break;
729 case SNDRV_PCM_FORMAT_S32_LE:
730 iface |= ALC5623_DAI_I2S_DL_32;
731 break;
732 default:
733 return -EINVAL;
734 }
735
736 /* set iface & srate */
737 snd_soc_write(codec, ALC5623_DAI_CONTROL, iface);
738 rate = params_rate(params);
739 coeff = get_coeff(codec, rate);
740 if (coeff < 0)
741 return -EINVAL;
742
743 coeff = coeff_div[coeff].regvalue;
744 dev_dbg(codec->dev, "%s: sysclk=%d,rate=%d,coeff=0x%04x\n",
745 __func__, alc5623->sysclk, rate, coeff);
746 snd_soc_write(codec, ALC5623_STEREO_AD_DA_CLK_CTRL, coeff);
747
748 return 0;
749}
750
751static int alc5623_mute(struct snd_soc_dai *dai, int mute)
752{
753 struct snd_soc_codec *codec = dai->codec;
754 u16 hp_mute = ALC5623_MISC_M_DAC_L_INPUT | ALC5623_MISC_M_DAC_R_INPUT;
755 u16 mute_reg = snd_soc_read(codec, ALC5623_MISC_CTRL) & ~hp_mute;
756
757 if (mute)
758 mute_reg |= hp_mute;
759
760 return snd_soc_write(codec, ALC5623_MISC_CTRL, mute_reg);
761}
762
763#define ALC5623_ADD2_POWER_EN (ALC5623_PWR_ADD2_VREF \
764 | ALC5623_PWR_ADD2_DAC_REF_CIR)
765
766#define ALC5623_ADD3_POWER_EN (ALC5623_PWR_ADD3_MAIN_BIAS \
767 | ALC5623_PWR_ADD3_MIC1_BOOST_AD)
768
769#define ALC5623_ADD1_POWER_EN \
770 (ALC5623_PWR_ADD1_SHORT_CURR_DET_EN | ALC5623_PWR_ADD1_SOFTGEN_EN \
771 | ALC5623_PWR_ADD1_DEPOP_BUF_HP | ALC5623_PWR_ADD1_HP_OUT_AMP \
772 | ALC5623_PWR_ADD1_HP_OUT_ENH_AMP)
773
774#define ALC5623_ADD1_POWER_EN_5622 \
775 (ALC5623_PWR_ADD1_SHORT_CURR_DET_EN \
776 | ALC5623_PWR_ADD1_HP_OUT_AMP)
777
778static void enable_power_depop(struct snd_soc_codec *codec)
779{
780 struct alc5623_priv *alc5623 = snd_soc_codec_get_drvdata(codec);
781
782 snd_soc_update_bits(codec, ALC5623_PWR_MANAG_ADD1,
783 ALC5623_PWR_ADD1_SOFTGEN_EN,
784 ALC5623_PWR_ADD1_SOFTGEN_EN);
785
786 snd_soc_write(codec, ALC5623_PWR_MANAG_ADD3, ALC5623_ADD3_POWER_EN);
787
788 snd_soc_update_bits(codec, ALC5623_MISC_CTRL,
789 ALC5623_MISC_HP_DEPOP_MODE2_EN,
790 ALC5623_MISC_HP_DEPOP_MODE2_EN);
791
792 msleep(500);
793
794 snd_soc_write(codec, ALC5623_PWR_MANAG_ADD2, ALC5623_ADD2_POWER_EN);
795
796 /* avoid writing '1' into 5622 reserved bits */
797 if (alc5623->id == 0x22)
798 snd_soc_write(codec, ALC5623_PWR_MANAG_ADD1,
799 ALC5623_ADD1_POWER_EN_5622);
800 else
801 snd_soc_write(codec, ALC5623_PWR_MANAG_ADD1,
802 ALC5623_ADD1_POWER_EN);
803
804 /* disable HP Depop2 */
805 snd_soc_update_bits(codec, ALC5623_MISC_CTRL,
806 ALC5623_MISC_HP_DEPOP_MODE2_EN,
807 0);
808
809}
810
811static int alc5623_set_bias_level(struct snd_soc_codec *codec,
812 enum snd_soc_bias_level level)
813{
814 switch (level) {
815 case SND_SOC_BIAS_ON:
816 enable_power_depop(codec);
817 break;
818 case SND_SOC_BIAS_PREPARE:
819 break;
820 case SND_SOC_BIAS_STANDBY:
821 /* everything off except vref/vmid, */
822 snd_soc_write(codec, ALC5623_PWR_MANAG_ADD2,
823 ALC5623_PWR_ADD2_VREF);
824 snd_soc_write(codec, ALC5623_PWR_MANAG_ADD3,
825 ALC5623_PWR_ADD3_MAIN_BIAS);
826 break;
827 case SND_SOC_BIAS_OFF:
828 /* everything off, dac mute, inactive */
829 snd_soc_write(codec, ALC5623_PWR_MANAG_ADD2, 0);
830 snd_soc_write(codec, ALC5623_PWR_MANAG_ADD3, 0);
831 snd_soc_write(codec, ALC5623_PWR_MANAG_ADD1, 0);
832 break;
833 }
834 codec->dapm.bias_level = level;
835 return 0;
836}
837
838#define ALC5623_FORMATS (SNDRV_PCM_FMTBIT_S16_LE \
839 | SNDRV_PCM_FMTBIT_S24_LE \
840 | SNDRV_PCM_FMTBIT_S32_LE)
841
842static struct snd_soc_dai_ops alc5623_dai_ops = {
843 .hw_params = alc5623_pcm_hw_params,
844 .digital_mute = alc5623_mute,
845 .set_fmt = alc5623_set_dai_fmt,
846 .set_sysclk = alc5623_set_dai_sysclk,
847 .set_pll = alc5623_set_dai_pll,
848};
849
850static struct snd_soc_dai_driver alc5623_dai = {
851 .name = "alc5623-hifi",
852 .playback = {
853 .stream_name = "Playback",
854 .channels_min = 1,
855 .channels_max = 2,
856 .rate_min = 8000,
857 .rate_max = 48000,
858 .rates = SNDRV_PCM_RATE_8000_48000,
859 .formats = ALC5623_FORMATS,},
860 .capture = {
861 .stream_name = "Capture",
862 .channels_min = 1,
863 .channels_max = 2,
864 .rate_min = 8000,
865 .rate_max = 48000,
866 .rates = SNDRV_PCM_RATE_8000_48000,
867 .formats = ALC5623_FORMATS,},
868
869 .ops = &alc5623_dai_ops,
870};
871
872static int alc5623_suspend(struct snd_soc_codec *codec, pm_message_t mesg)
873{
874 alc5623_set_bias_level(codec, SND_SOC_BIAS_OFF);
875 return 0;
876}
877
878static int alc5623_resume(struct snd_soc_codec *codec)
879{
880 int i, step = codec->driver->reg_cache_step;
881 u16 *cache = codec->reg_cache;
882
883 /* Sync reg_cache with the hardware */
884 for (i = 2 ; i < codec->driver->reg_cache_size ; i += step)
885 snd_soc_write(codec, i, cache[i]);
886
887 alc5623_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
888
889 /* charge alc5623 caps */
890 if (codec->dapm.suspend_bias_level == SND_SOC_BIAS_ON) {
891 alc5623_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
892 codec->dapm.bias_level = SND_SOC_BIAS_ON;
893 alc5623_set_bias_level(codec, codec->dapm.bias_level);
894 }
895
896 return 0;
897}
898
899static int alc5623_probe(struct snd_soc_codec *codec)
900{
901 struct alc5623_priv *alc5623 = snd_soc_codec_get_drvdata(codec);
902 struct snd_soc_dapm_context *dapm = &codec->dapm;
903 int ret;
904
905 ret = snd_soc_codec_set_cache_io(codec, 8, 16, alc5623->control_type);
906 if (ret < 0) {
907 dev_err(codec->dev, "Failed to set cache I/O: %d\n", ret);
908 return ret;
909 }
910
911 alc5623_reset(codec);
912 alc5623_fill_cache(codec);
913
914 /* power on device */
915 alc5623_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
916
917 if (alc5623->add_ctrl) {
918 snd_soc_write(codec, ALC5623_ADD_CTRL_REG,
919 alc5623->add_ctrl);
920 }
921
922 if (alc5623->jack_det_ctrl) {
923 snd_soc_write(codec, ALC5623_JACK_DET_CTRL,
924 alc5623->jack_det_ctrl);
925 }
926
927 switch (alc5623->id) {
928 case 0x21:
929 snd_soc_add_controls(codec, rt5621_vol_snd_controls,
930 ARRAY_SIZE(rt5621_vol_snd_controls));
931 break;
932 case 0x22:
933 snd_soc_add_controls(codec, rt5622_vol_snd_controls,
934 ARRAY_SIZE(rt5622_vol_snd_controls));
935 break;
936 case 0x23:
937 snd_soc_add_controls(codec, alc5623_vol_snd_controls,
938 ARRAY_SIZE(alc5623_vol_snd_controls));
939 break;
940 default:
941 return -EINVAL;
942 }
943
944 snd_soc_add_controls(codec, alc5623_snd_controls,
945 ARRAY_SIZE(alc5623_snd_controls));
946
947 snd_soc_dapm_new_controls(dapm, alc5623_dapm_widgets,
948 ARRAY_SIZE(alc5623_dapm_widgets));
949
950 /* set up audio path interconnects */
951 snd_soc_dapm_add_routes(dapm, intercon, ARRAY_SIZE(intercon));
952
953 switch (alc5623->id) {
954 case 0x21:
955 case 0x22:
956 snd_soc_dapm_new_controls(dapm, alc5623_dapm_amp_widgets,
957 ARRAY_SIZE(alc5623_dapm_amp_widgets));
958 snd_soc_dapm_add_routes(dapm, intercon_amp_spk,
959 ARRAY_SIZE(intercon_amp_spk));
960 break;
961 case 0x23:
962 snd_soc_dapm_add_routes(dapm, intercon_spk,
963 ARRAY_SIZE(intercon_spk));
964 break;
965 default:
966 return -EINVAL;
967 }
968
969 return ret;
970}
971
972/* power down chip */
973static int alc5623_remove(struct snd_soc_codec *codec)
974{
975 alc5623_set_bias_level(codec, SND_SOC_BIAS_OFF);
976 return 0;
977}
978
979static struct snd_soc_codec_driver soc_codec_device_alc5623 = {
980 .probe = alc5623_probe,
981 .remove = alc5623_remove,
982 .suspend = alc5623_suspend,
983 .resume = alc5623_resume,
984 .set_bias_level = alc5623_set_bias_level,
985 .reg_cache_size = ALC5623_VENDOR_ID2+2,
986 .reg_word_size = sizeof(u16),
987 .reg_cache_step = 2,
988};
989
990/*
991 * ALC5623 2 wire address is determined by A1 pin
992 * state during powerup.
993 * low = 0x1a
994 * high = 0x1b
995 */
996static int alc5623_i2c_probe(struct i2c_client *client,
997 const struct i2c_device_id *id)
998{
999 struct alc5623_platform_data *pdata;
1000 struct alc5623_priv *alc5623;
1001 int ret, vid1, vid2;
1002
1003 vid1 = i2c_smbus_read_word_data(client, ALC5623_VENDOR_ID1);
1004 if (vid1 < 0) {
1005 dev_err(&client->dev, "failed to read I2C\n");
1006 return -EIO;
1007 }
1008 vid1 = ((vid1 & 0xff) << 8) | (vid1 >> 8);
1009
1010 vid2 = i2c_smbus_read_byte_data(client, ALC5623_VENDOR_ID2);
1011 if (vid2 < 0) {
1012 dev_err(&client->dev, "failed to read I2C\n");
1013 return -EIO;
1014 }
1015
1016 if ((vid1 != 0x10ec) || (vid2 != id->driver_data)) {
1017 dev_err(&client->dev, "unknown or wrong codec\n");
1018 dev_err(&client->dev, "Expected %x:%lx, got %x:%x\n",
1019 0x10ec, id->driver_data,
1020 vid1, vid2);
1021 return -ENODEV;
1022 }
1023
1024 dev_dbg(&client->dev, "Found codec id : alc56%02x\n", vid2);
1025
1026 alc5623 = kzalloc(sizeof(struct alc5623_priv), GFP_KERNEL);
1027 if (alc5623 == NULL)
1028 return -ENOMEM;
1029
1030 pdata = client->dev.platform_data;
1031 if (pdata) {
1032 alc5623->add_ctrl = pdata->add_ctrl;
1033 alc5623->jack_det_ctrl = pdata->jack_det_ctrl;
1034 }
1035
1036 alc5623->id = vid2;
1037 switch (alc5623->id) {
1038 case 0x21:
1039 alc5623_dai.name = "alc5621-hifi";
1040 break;
1041 case 0x22:
1042 alc5623_dai.name = "alc5622-hifi";
1043 break;
1044 case 0x23:
1045 alc5623_dai.name = "alc5623-hifi";
1046 break;
1047 default:
1048 kfree(alc5623);
1049 return -EINVAL;
1050 }
1051
1052 i2c_set_clientdata(client, alc5623);
1053 alc5623->control_data = client;
1054 alc5623->control_type = SND_SOC_I2C;
1055 mutex_init(&alc5623->mutex);
1056
1057 ret = snd_soc_register_codec(&client->dev,
1058 &soc_codec_device_alc5623, &alc5623_dai, 1);
1059 if (ret != 0) {
1060 dev_err(&client->dev, "Failed to register codec: %d\n", ret);
1061 kfree(alc5623);
1062 }
1063
1064 return ret;
1065}
1066
1067static int alc5623_i2c_remove(struct i2c_client *client)
1068{
1069 struct alc5623_priv *alc5623 = i2c_get_clientdata(client);
1070
1071 snd_soc_unregister_codec(&client->dev);
1072 kfree(alc5623);
1073 return 0;
1074}
1075
1076static const struct i2c_device_id alc5623_i2c_table[] = {
1077 {"alc5621", 0x21},
1078 {"alc5622", 0x22},
1079 {"alc5623", 0x23},
1080 {}
1081};
1082MODULE_DEVICE_TABLE(i2c, alc5623_i2c_table);
1083
1084/* i2c codec control layer */
1085static struct i2c_driver alc5623_i2c_driver = {
1086 .driver = {
1087 .name = "alc562x-codec",
1088 .owner = THIS_MODULE,
1089 },
1090 .probe = alc5623_i2c_probe,
1091 .remove = __devexit_p(alc5623_i2c_remove),
1092 .id_table = alc5623_i2c_table,
1093};
1094
1095static int __init alc5623_modinit(void)
1096{
1097 int ret;
1098
1099 ret = i2c_add_driver(&alc5623_i2c_driver);
1100 if (ret != 0) {
1101 printk(KERN_ERR "%s: can't add i2c driver", __func__);
1102 return ret;
1103 }
1104
1105 return ret;
1106}
1107module_init(alc5623_modinit);
1108
1109static void __exit alc5623_modexit(void)
1110{
1111 i2c_del_driver(&alc5623_i2c_driver);
1112}
1113module_exit(alc5623_modexit);
1114
1115MODULE_DESCRIPTION("ASoC alc5621/2/3 driver");
1116MODULE_AUTHOR("Arnaud Patard <arnaud.patard@rtp-net.org>");
1117MODULE_LICENSE("GPL");
diff --git a/sound/soc/codecs/alc5623.h b/sound/soc/codecs/alc5623.h
new file mode 100644
index 000000000000..f3d68260d425
--- /dev/null
+++ b/sound/soc/codecs/alc5623.h
@@ -0,0 +1,161 @@
1/*
2 * alc5623.h -- alc562[123] ALSA Soc Audio driver
3 *
4 * Copyright 2008 Realtek Microelectronics
5 * Copyright 2010 Arnaud Patard <arnaud.patard@rtp-net.org>
6 *
7 * Author: flove <flove@realtek.com>
8 * Arnaud Patard <arnaud.patard@rtp-net.org>
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License version 2 as
12 * published by the Free Software Foundation.
13 *
14 */
15
16#ifndef _ALC5623_H
17#define _ALC5623_H
18
19#define ALC5623_RESET 0x00
20/* 5621 5622 5623 */
21/* speaker output vol 2 2 */
22/* line output vol 4 2 */
23/* HP output vol 4 0 4 */
24#define ALC5623_SPK_OUT_VOL 0x02
25#define ALC5623_HP_OUT_VOL 0x04
26#define ALC5623_MONO_AUX_OUT_VOL 0x06
27#define ALC5623_AUXIN_VOL 0x08
28#define ALC5623_LINE_IN_VOL 0x0A
29#define ALC5623_STEREO_DAC_VOL 0x0C
30#define ALC5623_MIC_VOL 0x0E
31#define ALC5623_MIC_ROUTING_CTRL 0x10
32#define ALC5623_ADC_REC_GAIN 0x12
33#define ALC5623_ADC_REC_MIXER 0x14
34#define ALC5623_SOFT_VOL_CTRL_TIME 0x16
35/* ALC5623_OUTPUT_MIXER_CTRL : */
36/* same remark as for reg 2 line vs speaker */
37#define ALC5623_OUTPUT_MIXER_CTRL 0x1C
38#define ALC5623_MIC_CTRL 0x22
39
40#define ALC5623_DAI_CONTROL 0x34
41#define ALC5623_DAI_SDP_MASTER_MODE (0 << 15)
42#define ALC5623_DAI_SDP_SLAVE_MODE (1 << 15)
43#define ALC5623_DAI_I2S_PCM_MODE (1 << 14)
44#define ALC5623_DAI_MAIN_I2S_BCLK_POL_CTRL (1 << 7)
45#define ALC5623_DAI_ADC_DATA_L_R_SWAP (1 << 5)
46#define ALC5623_DAI_DAC_DATA_L_R_SWAP (1 << 4)
47#define ALC5623_DAI_I2S_DL_MASK (3 << 2)
48#define ALC5623_DAI_I2S_DL_32 (3 << 2)
49#define ALC5623_DAI_I2S_DL_24 (2 << 2)
50#define ALC5623_DAI_I2S_DL_20 (1 << 2)
51#define ALC5623_DAI_I2S_DL_16 (0 << 2)
52#define ALC5623_DAI_I2S_DF_PCM (3 << 0)
53#define ALC5623_DAI_I2S_DF_LEFT (2 << 0)
54#define ALC5623_DAI_I2S_DF_RIGHT (1 << 0)
55#define ALC5623_DAI_I2S_DF_I2S (0 << 0)
56
57#define ALC5623_STEREO_AD_DA_CLK_CTRL 0x36
58#define ALC5623_COMPANDING_CTRL 0x38
59
60#define ALC5623_PWR_MANAG_ADD1 0x3A
61#define ALC5623_PWR_ADD1_MAIN_I2S_EN (1 << 15)
62#define ALC5623_PWR_ADD1_ZC_DET_PD_EN (1 << 14)
63#define ALC5623_PWR_ADD1_MIC1_BIAS_EN (1 << 11)
64#define ALC5623_PWR_ADD1_SHORT_CURR_DET_EN (1 << 10)
65#define ALC5623_PWR_ADD1_SOFTGEN_EN (1 << 8) /* rsvd on 5622 */
66#define ALC5623_PWR_ADD1_DEPOP_BUF_HP (1 << 6) /* rsvd on 5622 */
67#define ALC5623_PWR_ADD1_HP_OUT_AMP (1 << 5)
68#define ALC5623_PWR_ADD1_HP_OUT_ENH_AMP (1 << 4) /* rsvd on 5622 */
69#define ALC5623_PWR_ADD1_DEPOP_BUF_AUX (1 << 2)
70#define ALC5623_PWR_ADD1_AUX_OUT_AMP (1 << 1)
71#define ALC5623_PWR_ADD1_AUX_OUT_ENH_AMP (1 << 0) /* rsvd on 5622 */
72
73#define ALC5623_PWR_MANAG_ADD2 0x3C
74#define ALC5623_PWR_ADD2_LINEOUT (1 << 15) /* rt5623 */
75#define ALC5623_PWR_ADD2_CLASS_AB (1 << 15) /* rt5621 */
76#define ALC5623_PWR_ADD2_CLASS_D (1 << 14) /* rt5621 */
77#define ALC5623_PWR_ADD2_VREF (1 << 13)
78#define ALC5623_PWR_ADD2_PLL (1 << 12)
79#define ALC5623_PWR_ADD2_DAC_REF_CIR (1 << 10)
80#define ALC5623_PWR_ADD2_L_DAC_CLK (1 << 9)
81#define ALC5623_PWR_ADD2_R_DAC_CLK (1 << 8)
82#define ALC5623_PWR_ADD2_L_ADC_CLK_GAIN (1 << 7)
83#define ALC5623_PWR_ADD2_R_ADC_CLK_GAIN (1 << 6)
84#define ALC5623_PWR_ADD2_L_HP_MIXER (1 << 5)
85#define ALC5623_PWR_ADD2_R_HP_MIXER (1 << 4)
86#define ALC5623_PWR_ADD2_SPK_MIXER (1 << 3)
87#define ALC5623_PWR_ADD2_MONO_MIXER (1 << 2)
88#define ALC5623_PWR_ADD2_L_ADC_REC_MIXER (1 << 1)
89#define ALC5623_PWR_ADD2_R_ADC_REC_MIXER (1 << 0)
90
91#define ALC5623_PWR_MANAG_ADD3 0x3E
92#define ALC5623_PWR_ADD3_MAIN_BIAS (1 << 15)
93#define ALC5623_PWR_ADD3_AUXOUT_L_VOL_AMP (1 << 14)
94#define ALC5623_PWR_ADD3_AUXOUT_R_VOL_AMP (1 << 13)
95#define ALC5623_PWR_ADD3_SPK_OUT (1 << 12)
96#define ALC5623_PWR_ADD3_HP_L_OUT_VOL (1 << 10)
97#define ALC5623_PWR_ADD3_HP_R_OUT_VOL (1 << 9)
98#define ALC5623_PWR_ADD3_LINEIN_L_VOL (1 << 7)
99#define ALC5623_PWR_ADD3_LINEIN_R_VOL (1 << 6)
100#define ALC5623_PWR_ADD3_AUXIN_L_VOL (1 << 5)
101#define ALC5623_PWR_ADD3_AUXIN_R_VOL (1 << 4)
102#define ALC5623_PWR_ADD3_MIC1_FUN_CTRL (1 << 3)
103#define ALC5623_PWR_ADD3_MIC2_FUN_CTRL (1 << 2)
104#define ALC5623_PWR_ADD3_MIC1_BOOST_AD (1 << 1)
105#define ALC5623_PWR_ADD3_MIC2_BOOST_AD (1 << 0)
106
107#define ALC5623_ADD_CTRL_REG 0x40
108
109#define ALC5623_GLOBAL_CLK_CTRL_REG 0x42
110#define ALC5623_GBL_CLK_SYS_SOUR_SEL_PLL (1 << 15)
111#define ALC5623_GBL_CLK_SYS_SOUR_SEL_MCLK (0 << 15)
112#define ALC5623_GBL_CLK_PLL_SOUR_SEL_BITCLK (1 << 14)
113#define ALC5623_GBL_CLK_PLL_SOUR_SEL_MCLK (0 << 14)
114#define ALC5623_GBL_CLK_PLL_DIV_RATIO_DIV8 (3 << 1)
115#define ALC5623_GBL_CLK_PLL_DIV_RATIO_DIV4 (2 << 1)
116#define ALC5623_GBL_CLK_PLL_DIV_RATIO_DIV2 (1 << 1)
117#define ALC5623_GBL_CLK_PLL_DIV_RATIO_DIV1 (0 << 1)
118#define ALC5623_GBL_CLK_PLL_PRE_DIV2 (1 << 0)
119#define ALC5623_GBL_CLK_PLL_PRE_DIV1 (0 << 0)
120
121#define ALC5623_PLL_CTRL 0x44
122#define ALC5623_PLL_CTRL_N_VAL(n) (((n)&0xff) << 8)
123#define ALC5623_PLL_CTRL_K_VAL(k) (((k)&0x7) << 4)
124#define ALC5623_PLL_CTRL_M_VAL(m) ((m)&0xf)
125
126#define ALC5623_GPIO_OUTPUT_PIN_CTRL 0x4A
127#define ALC5623_GPIO_PIN_CONFIG 0x4C
128#define ALC5623_GPIO_PIN_POLARITY 0x4E
129#define ALC5623_GPIO_PIN_STICKY 0x50
130#define ALC5623_GPIO_PIN_WAKEUP 0x52
131#define ALC5623_GPIO_PIN_STATUS 0x54
132#define ALC5623_GPIO_PIN_SHARING 0x56
133#define ALC5623_OVER_CURR_STATUS 0x58
134#define ALC5623_JACK_DET_CTRL 0x5A
135
136#define ALC5623_MISC_CTRL 0x5E
137#define ALC5623_MISC_DISABLE_FAST_VREG (1 << 15)
138#define ALC5623_MISC_SPK_CLASS_AB_OC_PD (1 << 13) /* 5621 */
139#define ALC5623_MISC_SPK_CLASS_AB_OC_DET (1 << 12) /* 5621 */
140#define ALC5623_MISC_HP_DEPOP_MODE3_EN (1 << 10)
141#define ALC5623_MISC_HP_DEPOP_MODE2_EN (1 << 9)
142#define ALC5623_MISC_HP_DEPOP_MODE1_EN (1 << 8)
143#define ALC5623_MISC_AUXOUT_DEPOP_MODE3_EN (1 << 6)
144#define ALC5623_MISC_AUXOUT_DEPOP_MODE2_EN (1 << 5)
145#define ALC5623_MISC_AUXOUT_DEPOP_MODE1_EN (1 << 4)
146#define ALC5623_MISC_M_DAC_L_INPUT (1 << 3)
147#define ALC5623_MISC_M_DAC_R_INPUT (1 << 2)
148#define ALC5623_MISC_IRQOUT_INV_CTRL (1 << 0)
149
150#define ALC5623_PSEDUEO_SPATIAL_CTRL 0x60
151#define ALC5623_EQ_CTRL 0x62
152#define ALC5623_EQ_MODE_ENABLE 0x66
153#define ALC5623_AVC_CTRL 0x68
154#define ALC5623_HID_CTRL_INDEX 0x6A
155#define ALC5623_HID_CTRL_DATA 0x6C
156#define ALC5623_VENDOR_ID1 0x7C
157#define ALC5623_VENDOR_ID2 0x7E
158
159#define ALC5623_PLL_FR_MCLK 0
160#define ALC5623_PLL_FR_BCK 1
161#endif
diff --git a/sound/soc/codecs/cq93vc.c b/sound/soc/codecs/cq93vc.c
index 823643932dde..46dbfd067f79 100644
--- a/sound/soc/codecs/cq93vc.c
+++ b/sound/soc/codecs/cq93vc.c
@@ -36,8 +36,6 @@
36#include <sound/pcm.h> 36#include <sound/pcm.h>
37#include <sound/pcm_params.h> 37#include <sound/pcm_params.h>
38#include <sound/soc.h> 38#include <sound/soc.h>
39#include <sound/soc-dai.h>
40#include <sound/soc-dapm.h>
41#include <sound/initval.h> 39#include <sound/initval.h>
42 40
43#include <mach/dm365.h> 41#include <mach/dm365.h>
@@ -116,7 +114,7 @@ static int cq93vc_set_bias_level(struct snd_soc_codec *codec,
116 DAVINCI_VC_REG12_POWER_ALL_OFF); 114 DAVINCI_VC_REG12_POWER_ALL_OFF);
117 break; 115 break;
118 } 116 }
119 codec->bias_level = level; 117 codec->dapm.bias_level = level;
120 118
121 return 0; 119 return 0;
122} 120}
diff --git a/sound/soc/codecs/cs4270.c b/sound/soc/codecs/cs4270.c
index 6d4bdc609ac8..8b51245f2318 100644
--- a/sound/soc/codecs/cs4270.c
+++ b/sound/soc/codecs/cs4270.c
@@ -106,6 +106,21 @@
106#define CS4270_MUTE_DAC_A 0x01 106#define CS4270_MUTE_DAC_A 0x01
107#define CS4270_MUTE_DAC_B 0x02 107#define CS4270_MUTE_DAC_B 0x02
108 108
109/* Power-on default values for the registers
110 *
111 * This array contains the power-on default values of the registers, with the
112 * exception of the "CHIPID" register (01h). The lower four bits of that
113 * register contain the hardware revision, so it is treated as volatile.
114 *
115 * Also note that on the CS4270, the first readable register is 1, but ASoC
116 * assumes the first register is 0. Therfore, the array must have an entry for
117 * register 0, but we use cs4270_reg_is_readable() to tell ASoC that it can't
118 * be read.
119 */
120static const u8 cs4270_default_reg_cache[CS4270_LASTREG + 1] = {
121 0x00, 0x00, 0x00, 0x30, 0x00, 0x60, 0x20, 0x00, 0x00
122};
123
109static const char *supply_names[] = { 124static const char *supply_names[] = {
110 "va", "vd", "vlc" 125 "va", "vd", "vlc"
111}; 126};
@@ -114,7 +129,6 @@ static const char *supply_names[] = {
114struct cs4270_private { 129struct cs4270_private {
115 enum snd_soc_control_type control_type; 130 enum snd_soc_control_type control_type;
116 void *control_data; 131 void *control_data;
117 u8 reg_cache[CS4270_NUMREGS];
118 unsigned int mclk; /* Input frequency of the MCLK pin */ 132 unsigned int mclk; /* Input frequency of the MCLK pin */
119 unsigned int mode; /* The mode (I2S or left-justified) */ 133 unsigned int mode; /* The mode (I2S or left-justified) */
120 unsigned int slave_mode; 134 unsigned int slave_mode;
@@ -179,6 +193,20 @@ static struct cs4270_mode_ratios cs4270_mode_ratios[] = {
179/* The number of MCLK/LRCK ratios supported by the CS4270 */ 193/* The number of MCLK/LRCK ratios supported by the CS4270 */
180#define NUM_MCLK_RATIOS ARRAY_SIZE(cs4270_mode_ratios) 194#define NUM_MCLK_RATIOS ARRAY_SIZE(cs4270_mode_ratios)
181 195
196static int cs4270_reg_is_readable(unsigned int reg)
197{
198 return (reg >= CS4270_FIRSTREG) && (reg <= CS4270_LASTREG);
199}
200
201static int cs4270_reg_is_volatile(unsigned int reg)
202{
203 /* Unreadable registers are considered volatile */
204 if ((reg < CS4270_FIRSTREG) || (reg > CS4270_LASTREG))
205 return 1;
206
207 return reg == CS4270_CHIPID;
208}
209
182/** 210/**
183 * cs4270_set_dai_sysclk - determine the CS4270 samples rates. 211 * cs4270_set_dai_sysclk - determine the CS4270 samples rates.
184 * @codec_dai: the codec DAI 212 * @codec_dai: the codec DAI
@@ -264,97 +292,6 @@ static int cs4270_set_dai_fmt(struct snd_soc_dai *codec_dai,
264} 292}
265 293
266/** 294/**
267 * cs4270_fill_cache - pre-fill the CS4270 register cache.
268 * @codec: the codec for this CS4270
269 *
270 * This function fills in the CS4270 register cache by reading the register
271 * values from the hardware.
272 *
273 * This CS4270 registers are cached to avoid excessive I2C I/O operations.
274 * After the initial read to pre-fill the cache, the CS4270 never updates
275 * the register values, so we won't have a cache coherency problem.
276 *
277 * We use the auto-increment feature of the CS4270 to read all registers in
278 * one shot.
279 */
280static int cs4270_fill_cache(struct snd_soc_codec *codec)
281{
282 u8 *cache = codec->reg_cache;
283 struct i2c_client *i2c_client = codec->control_data;
284 s32 length;
285
286 length = i2c_smbus_read_i2c_block_data(i2c_client,
287 CS4270_FIRSTREG | CS4270_I2C_INCR, CS4270_NUMREGS, cache);
288
289 if (length != CS4270_NUMREGS) {
290 dev_err(codec->dev, "i2c read failure, addr=0x%x\n",
291 i2c_client->addr);
292 return -EIO;
293 }
294
295 return 0;
296}
297
298/**
299 * cs4270_read_reg_cache - read from the CS4270 register cache.
300 * @codec: the codec for this CS4270
301 * @reg: the register to read
302 *
303 * This function returns the value for a given register. It reads only from
304 * the register cache, not the hardware itself.
305 *
306 * This CS4270 registers are cached to avoid excessive I2C I/O operations.
307 * After the initial read to pre-fill the cache, the CS4270 never updates
308 * the register values, so we won't have a cache coherency problem.
309 */
310static unsigned int cs4270_read_reg_cache(struct snd_soc_codec *codec,
311 unsigned int reg)
312{
313 u8 *cache = codec->reg_cache;
314
315 if ((reg < CS4270_FIRSTREG) || (reg > CS4270_LASTREG))
316 return -EIO;
317
318 return cache[reg - CS4270_FIRSTREG];
319}
320
321/**
322 * cs4270_i2c_write - write to a CS4270 register via the I2C bus.
323 * @codec: the codec for this CS4270
324 * @reg: the register to write
325 * @value: the value to write to the register
326 *
327 * This function writes the given value to the given CS4270 register, and
328 * also updates the register cache.
329 *
330 * Note that we don't use the hw_write function pointer of snd_soc_codec.
331 * That's because it's too clunky: the hw_write_t prototype does not match
332 * i2c_smbus_write_byte_data(), and it's just another layer of overhead.
333 */
334static int cs4270_i2c_write(struct snd_soc_codec *codec, unsigned int reg,
335 unsigned int value)
336{
337 u8 *cache = codec->reg_cache;
338
339 if ((reg < CS4270_FIRSTREG) || (reg > CS4270_LASTREG))
340 return -EIO;
341
342 /* Only perform an I2C operation if the new value is different */
343 if (cache[reg - CS4270_FIRSTREG] != value) {
344 struct i2c_client *client = codec->control_data;
345 if (i2c_smbus_write_byte_data(client, reg, value)) {
346 dev_err(codec->dev, "i2c write failed\n");
347 return -EIO;
348 }
349
350 /* We've written to the hardware, so update the cache */
351 cache[reg - CS4270_FIRSTREG] = value;
352 }
353
354 return 0;
355}
356
357/**
358 * cs4270_hw_params - program the CS4270 with the given hardware parameters. 295 * cs4270_hw_params - program the CS4270 with the given hardware parameters.
359 * @substream: the audio stream 296 * @substream: the audio stream
360 * @params: the hardware parameters to set 297 * @params: the hardware parameters to set
@@ -551,15 +488,16 @@ static struct snd_soc_dai_driver cs4270_dai = {
551static int cs4270_probe(struct snd_soc_codec *codec) 488static int cs4270_probe(struct snd_soc_codec *codec)
552{ 489{
553 struct cs4270_private *cs4270 = snd_soc_codec_get_drvdata(codec); 490 struct cs4270_private *cs4270 = snd_soc_codec_get_drvdata(codec);
554 int i, ret, reg; 491 int i, ret;
555 492
556 codec->control_data = cs4270->control_data; 493 codec->control_data = cs4270->control_data;
557 494
558 /* The I2C interface is set up, so pre-fill our register cache */ 495 /* Tell ASoC what kind of I/O to use to read the registers. ASoC will
559 496 * then do the I2C transactions itself.
560 ret = cs4270_fill_cache(codec); 497 */
498 ret = snd_soc_codec_set_cache_io(codec, 8, 8, cs4270->control_type);
561 if (ret < 0) { 499 if (ret < 0) {
562 dev_err(codec->dev, "failed to fill register cache\n"); 500 dev_err(codec->dev, "failed to set cache I/O (ret=%i)\n", ret);
563 return ret; 501 return ret;
564 } 502 }
565 503
@@ -568,10 +506,7 @@ static int cs4270_probe(struct snd_soc_codec *codec)
568 * this feature disabled by default. An application (e.g. alsactl) can 506 * this feature disabled by default. An application (e.g. alsactl) can
569 * re-enabled it by using the controls. 507 * re-enabled it by using the controls.
570 */ 508 */
571 509 ret = snd_soc_update_bits(codec, CS4270_MUTE, CS4270_MUTE_AUTO, 0);
572 reg = cs4270_read_reg_cache(codec, CS4270_MUTE);
573 reg &= ~CS4270_MUTE_AUTO;
574 ret = cs4270_i2c_write(codec, CS4270_MUTE, reg);
575 if (ret < 0) { 510 if (ret < 0) {
576 dev_err(codec->dev, "i2c write failed\n"); 511 dev_err(codec->dev, "i2c write failed\n");
577 return ret; 512 return ret;
@@ -582,10 +517,8 @@ static int cs4270_probe(struct snd_soc_codec *codec)
582 * playback has started. An application (e.g. alsactl) can 517 * playback has started. An application (e.g. alsactl) can
583 * re-enabled it by using the controls. 518 * re-enabled it by using the controls.
584 */ 519 */
585 520 ret = snd_soc_update_bits(codec, CS4270_TRANS,
586 reg = cs4270_read_reg_cache(codec, CS4270_TRANS); 521 CS4270_TRANS_SOFT | CS4270_TRANS_ZERO, 0);
587 reg &= ~(CS4270_TRANS_SOFT | CS4270_TRANS_ZERO);
588 ret = cs4270_i2c_write(codec, CS4270_TRANS, reg);
589 if (ret < 0) { 522 if (ret < 0) {
590 dev_err(codec->dev, "i2c write failed\n"); 523 dev_err(codec->dev, "i2c write failed\n");
591 return ret; 524 return ret;
@@ -708,15 +641,16 @@ static int cs4270_soc_resume(struct snd_soc_codec *codec)
708 * Assign this variable to the codec_dev field of the machine driver's 641 * Assign this variable to the codec_dev field of the machine driver's
709 * snd_soc_device structure. 642 * snd_soc_device structure.
710 */ 643 */
711static struct snd_soc_codec_driver soc_codec_device_cs4270 = { 644static const struct snd_soc_codec_driver soc_codec_device_cs4270 = {
712 .probe = cs4270_probe, 645 .probe = cs4270_probe,
713 .remove = cs4270_remove, 646 .remove = cs4270_remove,
714 .suspend = cs4270_soc_suspend, 647 .suspend = cs4270_soc_suspend,
715 .resume = cs4270_soc_resume, 648 .resume = cs4270_soc_resume,
716 .read = cs4270_read_reg_cache, 649 .volatile_register = cs4270_reg_is_volatile,
717 .write = cs4270_i2c_write, 650 .readable_register = cs4270_reg_is_readable,
718 .reg_cache_size = CS4270_NUMREGS, 651 .reg_cache_size = CS4270_LASTREG + 1,
719 .reg_word_size = sizeof(u8), 652 .reg_word_size = sizeof(u8),
653 .reg_cache_default = cs4270_default_reg_cache,
720}; 654};
721 655
722/** 656/**
diff --git a/sound/soc/codecs/cs42l51.c b/sound/soc/codecs/cs42l51.c
index cb086eaf4e07..8fb7070108dd 100644
--- a/sound/soc/codecs/cs42l51.c
+++ b/sound/soc/codecs/cs42l51.c
@@ -26,7 +26,6 @@
26#include <linux/slab.h> 26#include <linux/slab.h>
27#include <sound/core.h> 27#include <sound/core.h>
28#include <sound/soc.h> 28#include <sound/soc.h>
29#include <sound/soc-dapm.h>
30#include <sound/tlv.h> 29#include <sound/tlv.h>
31#include <sound/initval.h> 30#include <sound/initval.h>
32#include <sound/pcm_params.h> 31#include <sound/pcm_params.h>
@@ -47,7 +46,6 @@ struct cs42l51_private {
47 unsigned int mclk; 46 unsigned int mclk;
48 unsigned int audio_mode; /* The mode (I2S or left-justified) */ 47 unsigned int audio_mode; /* The mode (I2S or left-justified) */
49 enum master_slave_mode func; 48 enum master_slave_mode func;
50 u8 reg_cache[CS42L51_NUMREGS];
51}; 49};
52 50
53#define CS42L51_FORMATS ( \ 51#define CS42L51_FORMATS ( \
@@ -519,6 +517,7 @@ static struct snd_soc_dai_driver cs42l51_dai = {
519static int cs42l51_probe(struct snd_soc_codec *codec) 517static int cs42l51_probe(struct snd_soc_codec *codec)
520{ 518{
521 struct cs42l51_private *cs42l51 = snd_soc_codec_get_drvdata(codec); 519 struct cs42l51_private *cs42l51 = snd_soc_codec_get_drvdata(codec);
520 struct snd_soc_dapm_context *dapm = &codec->dapm;
522 int ret, reg; 521 int ret, reg;
523 522
524 codec->control_data = cs42l51->control_data; 523 codec->control_data = cs42l51->control_data;
@@ -550,9 +549,9 @@ static int cs42l51_probe(struct snd_soc_codec *codec)
550 549
551 snd_soc_add_controls(codec, cs42l51_snd_controls, 550 snd_soc_add_controls(codec, cs42l51_snd_controls,
552 ARRAY_SIZE(cs42l51_snd_controls)); 551 ARRAY_SIZE(cs42l51_snd_controls));
553 snd_soc_dapm_new_controls(codec, cs42l51_dapm_widgets, 552 snd_soc_dapm_new_controls(dapm, cs42l51_dapm_widgets,
554 ARRAY_SIZE(cs42l51_dapm_widgets)); 553 ARRAY_SIZE(cs42l51_dapm_widgets));
555 snd_soc_dapm_add_routes(codec, cs42l51_routes, 554 snd_soc_dapm_add_routes(dapm, cs42l51_routes,
556 ARRAY_SIZE(cs42l51_routes)); 555 ARRAY_SIZE(cs42l51_routes));
557 556
558 return 0; 557 return 0;
diff --git a/sound/soc/codecs/cx20442.c b/sound/soc/codecs/cx20442.c
index e8d27c8f9ba3..03d1e860d229 100644
--- a/sound/soc/codecs/cx20442.c
+++ b/sound/soc/codecs/cx20442.c
@@ -18,7 +18,7 @@
18 18
19#include <sound/core.h> 19#include <sound/core.h>
20#include <sound/initval.h> 20#include <sound/initval.h>
21#include <sound/soc-dapm.h> 21#include <sound/soc.h>
22 22
23#include "cx20442.h" 23#include "cx20442.h"
24 24
@@ -26,7 +26,6 @@
26struct cx20442_priv { 26struct cx20442_priv {
27 enum snd_soc_control_type control_type; 27 enum snd_soc_control_type control_type;
28 void *control_data; 28 void *control_data;
29 u8 reg_cache[1];
30}; 29};
31 30
32#define CX20442_PM 0x0 31#define CX20442_PM 0x0
@@ -89,10 +88,11 @@ static const struct snd_soc_dapm_route cx20442_audio_map[] = {
89 88
90static int cx20442_add_widgets(struct snd_soc_codec *codec) 89static int cx20442_add_widgets(struct snd_soc_codec *codec)
91{ 90{
92 snd_soc_dapm_new_controls(codec, cx20442_dapm_widgets, 91 struct snd_soc_dapm_context *dapm = &codec->dapm;
93 ARRAY_SIZE(cx20442_dapm_widgets));
94 92
95 snd_soc_dapm_add_routes(codec, cx20442_audio_map, 93 snd_soc_dapm_new_controls(dapm, cx20442_dapm_widgets,
94 ARRAY_SIZE(cx20442_dapm_widgets));
95 snd_soc_dapm_add_routes(dapm, cx20442_audio_map,
96 ARRAY_SIZE(cx20442_audio_map)); 96 ARRAY_SIZE(cx20442_audio_map));
97 97
98 return 0; 98 return 0;
@@ -263,7 +263,7 @@ static void v253_close(struct tty_struct *tty)
263 /* Prevent the codec driver from further accessing the modem */ 263 /* Prevent the codec driver from further accessing the modem */
264 codec->hw_write = NULL; 264 codec->hw_write = NULL;
265 cx20442->control_data = NULL; 265 cx20442->control_data = NULL;
266 codec->pop_time = 0; 266 codec->card->pop_time = 0;
267} 267}
268 268
269/* Line discipline .hangup() */ 269/* Line discipline .hangup() */
@@ -291,7 +291,7 @@ static void v253_receive(struct tty_struct *tty,
291 /* Set up codec driver access to modem controls */ 291 /* Set up codec driver access to modem controls */
292 cx20442->control_data = tty; 292 cx20442->control_data = tty;
293 codec->hw_write = (hw_write_t)tty->ops->write; 293 codec->hw_write = (hw_write_t)tty->ops->write;
294 codec->pop_time = 1; 294 codec->card->pop_time = 1;
295 } 295 }
296} 296}
297 297
@@ -348,7 +348,7 @@ static int cx20442_codec_probe(struct snd_soc_codec *codec)
348 348
349 cx20442->control_data = NULL; 349 cx20442->control_data = NULL;
350 codec->hw_write = NULL; 350 codec->hw_write = NULL;
351 codec->pop_time = 0; 351 codec->card->pop_time = 0;
352 352
353 return 0; 353 return 0;
354} 354}
diff --git a/sound/soc/codecs/da7210.c b/sound/soc/codecs/da7210.c
index 58bb9b994811..92fd9d7a9221 100644
--- a/sound/soc/codecs/da7210.c
+++ b/sound/soc/codecs/da7210.c
@@ -21,7 +21,7 @@
21#include <linux/slab.h> 21#include <linux/slab.h>
22#include <sound/pcm.h> 22#include <sound/pcm.h>
23#include <sound/pcm_params.h> 23#include <sound/pcm_params.h>
24#include <sound/soc-dapm.h> 24#include <sound/soc.h>
25#include <sound/initval.h> 25#include <sound/initval.h>
26#include <sound/tlv.h> 26#include <sound/tlv.h>
27 27
diff --git a/sound/soc/codecs/dmic.c b/sound/soc/codecs/dmic.c
new file mode 100644
index 000000000000..57e9dac88d38
--- /dev/null
+++ b/sound/soc/codecs/dmic.c
@@ -0,0 +1,81 @@
1/*
2 * dmic.c -- SoC audio for Generic Digital MICs
3 *
4 * Author: Liam Girdwood <lrg@slimlogic.co.uk>
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * version 2 as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
18 * 02110-1301 USA
19 *
20 */
21
22#include <linux/platform_device.h>
23#include <linux/slab.h>
24#include <sound/core.h>
25#include <sound/pcm.h>
26#include <sound/soc.h>
27#include <sound/soc-dapm.h>
28
29static struct snd_soc_dai_driver dmic_dai = {
30 .name = "dmic-hifi",
31 .capture = {
32 .stream_name = "Capture",
33 .channels_min = 1,
34 .channels_max = 8,
35 .rates = SNDRV_PCM_RATE_CONTINUOUS,
36 .formats = SNDRV_PCM_FMTBIT_S32_LE
37 | SNDRV_PCM_FMTBIT_S24_LE
38 | SNDRV_PCM_FMTBIT_S16_LE,
39 },
40};
41
42static struct snd_soc_codec_driver soc_dmic = {};
43
44static int __devinit dmic_dev_probe(struct platform_device *pdev)
45{
46 return snd_soc_register_codec(&pdev->dev,
47 &soc_dmic, &dmic_dai, 1);
48}
49
50static int __devexit dmic_dev_remove(struct platform_device *pdev)
51{
52 snd_soc_unregister_codec(&pdev->dev);
53 return 0;
54}
55
56MODULE_ALIAS("platform:dmic-codec");
57
58static struct platform_driver dmic_driver = {
59 .driver = {
60 .name = "dmic-codec",
61 .owner = THIS_MODULE,
62 },
63 .probe = dmic_dev_probe,
64 .remove = __devexit_p(dmic_dev_remove),
65};
66
67static int __init dmic_init(void)
68{
69 return platform_driver_register(&dmic_driver);
70}
71module_init(dmic_init);
72
73static void __exit dmic_exit(void)
74{
75 platform_driver_unregister(&dmic_driver);
76}
77module_exit(dmic_exit);
78
79MODULE_DESCRIPTION("Generic DMIC driver");
80MODULE_AUTHOR("Liam Girdwood <lrg@slimlogic.co.uk>");
81MODULE_LICENSE("GPL");
diff --git a/sound/soc/codecs/jz4740.c b/sound/soc/codecs/jz4740.c
index 16253ec9b022..f7cd346fd727 100644
--- a/sound/soc/codecs/jz4740.c
+++ b/sound/soc/codecs/jz4740.c
@@ -22,7 +22,6 @@
22#include <sound/pcm.h> 22#include <sound/pcm.h>
23#include <sound/pcm_params.h> 23#include <sound/pcm_params.h>
24#include <sound/initval.h> 24#include <sound/initval.h>
25#include <sound/soc-dapm.h>
26#include <sound/soc.h> 25#include <sound/soc.h>
27 26
28#define JZ4740_REG_CODEC_1 0x0 27#define JZ4740_REG_CODEC_1 0x0
@@ -266,7 +265,7 @@ static int jz4740_codec_set_bias_level(struct snd_soc_codec *codec,
266 break; 265 break;
267 case SND_SOC_BIAS_STANDBY: 266 case SND_SOC_BIAS_STANDBY:
268 /* The only way to clear the suspend flag is to reset the codec */ 267 /* The only way to clear the suspend flag is to reset the codec */
269 if (codec->bias_level == SND_SOC_BIAS_OFF) 268 if (codec->dapm.bias_level == SND_SOC_BIAS_OFF)
270 jz4740_codec_wakeup(codec); 269 jz4740_codec_wakeup(codec);
271 270
272 mask = JZ4740_CODEC_1_VREF_DISABLE | 271 mask = JZ4740_CODEC_1_VREF_DISABLE |
@@ -288,23 +287,25 @@ static int jz4740_codec_set_bias_level(struct snd_soc_codec *codec,
288 break; 287 break;
289 } 288 }
290 289
291 codec->bias_level = level; 290 codec->dapm.bias_level = level;
292 291
293 return 0; 292 return 0;
294} 293}
295 294
296static int jz4740_codec_dev_probe(struct snd_soc_codec *codec) 295static int jz4740_codec_dev_probe(struct snd_soc_codec *codec)
297{ 296{
297 struct snd_soc_dapm_context *dapm = &codec->dapm;
298
298 snd_soc_update_bits(codec, JZ4740_REG_CODEC_1, 299 snd_soc_update_bits(codec, JZ4740_REG_CODEC_1,
299 JZ4740_CODEC_1_SW2_ENABLE, JZ4740_CODEC_1_SW2_ENABLE); 300 JZ4740_CODEC_1_SW2_ENABLE, JZ4740_CODEC_1_SW2_ENABLE);
300 301
301 snd_soc_add_controls(codec, jz4740_codec_controls, 302 snd_soc_add_controls(codec, jz4740_codec_controls,
302 ARRAY_SIZE(jz4740_codec_controls)); 303 ARRAY_SIZE(jz4740_codec_controls));
303 304
304 snd_soc_dapm_new_controls(codec, jz4740_codec_dapm_widgets, 305 snd_soc_dapm_new_controls(dapm, jz4740_codec_dapm_widgets,
305 ARRAY_SIZE(jz4740_codec_dapm_widgets)); 306 ARRAY_SIZE(jz4740_codec_dapm_widgets));
306 307
307 snd_soc_dapm_add_routes(codec, jz4740_codec_dapm_routes, 308 snd_soc_dapm_add_routes(dapm, jz4740_codec_dapm_routes,
308 ARRAY_SIZE(jz4740_codec_dapm_routes)); 309 ARRAY_SIZE(jz4740_codec_dapm_routes));
309 310
310 snd_soc_dapm_new_widgets(codec); 311 snd_soc_dapm_new_widgets(codec);
diff --git a/sound/soc/codecs/max98088.c b/sound/soc/codecs/max98088.c
index 6447dbb2f123..89498f9ad2e5 100644
--- a/sound/soc/codecs/max98088.c
+++ b/sound/soc/codecs/max98088.c
@@ -20,7 +20,6 @@
20#include <sound/pcm.h> 20#include <sound/pcm.h>
21#include <sound/pcm_params.h> 21#include <sound/pcm_params.h>
22#include <sound/soc.h> 22#include <sound/soc.h>
23#include <sound/soc-dapm.h>
24#include <sound/initval.h> 23#include <sound/initval.h>
25#include <sound/tlv.h> 24#include <sound/tlv.h>
26#include <linux/slab.h> 25#include <linux/slab.h>
@@ -1229,15 +1228,17 @@ static const struct snd_soc_dapm_route audio_map[] = {
1229 1228
1230static int max98088_add_widgets(struct snd_soc_codec *codec) 1229static int max98088_add_widgets(struct snd_soc_codec *codec)
1231{ 1230{
1232 snd_soc_dapm_new_controls(codec, max98088_dapm_widgets, 1231 struct snd_soc_dapm_context *dapm = &codec->dapm;
1232
1233 snd_soc_dapm_new_controls(dapm, max98088_dapm_widgets,
1233 ARRAY_SIZE(max98088_dapm_widgets)); 1234 ARRAY_SIZE(max98088_dapm_widgets));
1234 1235
1235 snd_soc_dapm_add_routes(codec, audio_map, ARRAY_SIZE(audio_map)); 1236 snd_soc_dapm_add_routes(dapm, audio_map, ARRAY_SIZE(audio_map));
1236 1237
1237 snd_soc_add_controls(codec, max98088_snd_controls, 1238 snd_soc_add_controls(codec, max98088_snd_controls,
1238 ARRAY_SIZE(max98088_snd_controls)); 1239 ARRAY_SIZE(max98088_snd_controls));
1239 1240
1240 snd_soc_dapm_new_widgets(codec); 1241 snd_soc_dapm_new_widgets(dapm);
1241 return 0; 1242 return 0;
1242} 1243}
1243 1244
@@ -1622,7 +1623,7 @@ static int max98088_set_bias_level(struct snd_soc_codec *codec,
1622 break; 1623 break;
1623 1624
1624 case SND_SOC_BIAS_STANDBY: 1625 case SND_SOC_BIAS_STANDBY:
1625 if (codec->bias_level == SND_SOC_BIAS_OFF) 1626 if (codec->dapm.bias_level == SND_SOC_BIAS_OFF)
1626 max98088_sync_cache(codec); 1627 max98088_sync_cache(codec);
1627 1628
1628 snd_soc_update_bits(codec, M98088_REG_4C_PWR_EN_IN, 1629 snd_soc_update_bits(codec, M98088_REG_4C_PWR_EN_IN,
@@ -1635,7 +1636,7 @@ static int max98088_set_bias_level(struct snd_soc_codec *codec,
1635 codec->cache_sync = 1; 1636 codec->cache_sync = 1;
1636 break; 1637 break;
1637 } 1638 }
1638 codec->bias_level = level; 1639 codec->dapm.bias_level = level;
1639 return 0; 1640 return 0;
1640} 1641}
1641 1642
@@ -1957,7 +1958,7 @@ static int max98088_probe(struct snd_soc_codec *codec)
1957 return ret; 1958 return ret;
1958 } 1959 }
1959 1960
1960 /* initalize private data */ 1961 /* initialize private data */
1961 1962
1962 max98088->sysclk = (unsigned)-1; 1963 max98088->sysclk = (unsigned)-1;
1963 max98088->eq_textcnt = 0; 1964 max98088->eq_textcnt = 0;
diff --git a/sound/soc/codecs/ssm2602.c b/sound/soc/codecs/ssm2602.c
index 6f38d619bf8a..2727befd158e 100644
--- a/sound/soc/codecs/ssm2602.c
+++ b/sound/soc/codecs/ssm2602.c
@@ -38,7 +38,6 @@
38#include <sound/pcm.h> 38#include <sound/pcm.h>
39#include <sound/pcm_params.h> 39#include <sound/pcm_params.h>
40#include <sound/soc.h> 40#include <sound/soc.h>
41#include <sound/soc-dapm.h>
42#include <sound/initval.h> 41#include <sound/initval.h>
43 42
44#include "ssm2602.h" 43#include "ssm2602.h"
@@ -207,10 +206,11 @@ static const struct snd_soc_dapm_route audio_conn[] = {
207 206
208static int ssm2602_add_widgets(struct snd_soc_codec *codec) 207static int ssm2602_add_widgets(struct snd_soc_codec *codec)
209{ 208{
210 snd_soc_dapm_new_controls(codec, ssm2602_dapm_widgets, 209 struct snd_soc_dapm_context *dapm = &codec->dapm;
211 ARRAY_SIZE(ssm2602_dapm_widgets));
212 210
213 snd_soc_dapm_add_routes(codec, audio_conn, ARRAY_SIZE(audio_conn)); 211 snd_soc_dapm_new_controls(dapm, ssm2602_dapm_widgets,
212 ARRAY_SIZE(ssm2602_dapm_widgets));
213 snd_soc_dapm_add_routes(dapm, audio_conn, ARRAY_SIZE(audio_conn));
214 214
215 return 0; 215 return 0;
216} 216}
@@ -493,7 +493,7 @@ static int ssm2602_set_bias_level(struct snd_soc_codec *codec,
493 break; 493 break;
494 494
495 } 495 }
496 codec->bias_level = level; 496 codec->dapm.bias_level = level;
497 return 0; 497 return 0;
498} 498}
499 499
diff --git a/sound/soc/codecs/stac9766.c b/sound/soc/codecs/stac9766.c
index 061f9e5a497b..78b2b50271e2 100644
--- a/sound/soc/codecs/stac9766.c
+++ b/sound/soc/codecs/stac9766.c
@@ -236,7 +236,7 @@ static int stac9766_set_bias_level(struct snd_soc_codec *codec,
236 stac9766_ac97_write(codec, AC97_POWERDOWN, 0xffff); 236 stac9766_ac97_write(codec, AC97_POWERDOWN, 0xffff);
237 break; 237 break;
238 } 238 }
239 codec->bias_level = level; 239 codec->dapm.bias_level = level;
240 return 0; 240 return 0;
241} 241}
242 242
diff --git a/sound/soc/codecs/tlv320aic23.c b/sound/soc/codecs/tlv320aic23.c
index e8652b1ae326..54a30ef0ec8b 100644
--- a/sound/soc/codecs/tlv320aic23.c
+++ b/sound/soc/codecs/tlv320aic23.c
@@ -30,7 +30,6 @@
30#include <sound/pcm.h> 30#include <sound/pcm.h>
31#include <sound/pcm_params.h> 31#include <sound/pcm_params.h>
32#include <sound/soc.h> 32#include <sound/soc.h>
33#include <sound/soc-dapm.h>
34#include <sound/tlv.h> 33#include <sound/tlv.h>
35#include <sound/initval.h> 34#include <sound/initval.h>
36 35
@@ -391,11 +390,12 @@ static int set_sample_rate_control(struct snd_soc_codec *codec, int mclk,
391 390
392static int tlv320aic23_add_widgets(struct snd_soc_codec *codec) 391static int tlv320aic23_add_widgets(struct snd_soc_codec *codec)
393{ 392{
394 snd_soc_dapm_new_controls(codec, tlv320aic23_dapm_widgets, 393 struct snd_soc_dapm_context *dapm = &codec->dapm;
395 ARRAY_SIZE(tlv320aic23_dapm_widgets));
396 394
395 snd_soc_dapm_new_controls(dapm, tlv320aic23_dapm_widgets,
396 ARRAY_SIZE(tlv320aic23_dapm_widgets));
397 /* set up audio path interconnects */ 397 /* set up audio path interconnects */
398 snd_soc_dapm_add_routes(codec, intercon, ARRAY_SIZE(intercon)); 398 snd_soc_dapm_add_routes(dapm, intercon, ARRAY_SIZE(intercon));
399 399
400 return 0; 400 return 0;
401} 401}
@@ -574,7 +574,7 @@ static int tlv320aic23_set_bias_level(struct snd_soc_codec *codec,
574 tlv320aic23_write(codec, TLV320AIC23_PWR, 0xffff); 574 tlv320aic23_write(codec, TLV320AIC23_PWR, 0xffff);
575 break; 575 break;
576 } 576 }
577 codec->bias_level = level; 577 codec->dapm.bias_level = level;
578 return 0; 578 return 0;
579} 579}
580 580
diff --git a/sound/soc/codecs/tlv320aic26.c b/sound/soc/codecs/tlv320aic26.c
index 6b7d71ec0004..e2a7608d3944 100644
--- a/sound/soc/codecs/tlv320aic26.c
+++ b/sound/soc/codecs/tlv320aic26.c
@@ -18,7 +18,6 @@
18#include <sound/pcm.h> 18#include <sound/pcm.h>
19#include <sound/pcm_params.h> 19#include <sound/pcm_params.h>
20#include <sound/soc.h> 20#include <sound/soc.h>
21#include <sound/soc-dapm.h>
22#include <sound/initval.h> 21#include <sound/initval.h>
23 22
24#include "tlv320aic26.h" 23#include "tlv320aic26.h"
@@ -31,7 +30,6 @@ MODULE_LICENSE("GPL");
31struct aic26 { 30struct aic26 {
32 struct spi_device *spi; 31 struct spi_device *spi;
33 struct snd_soc_codec codec; 32 struct snd_soc_codec codec;
34 u16 reg_cache[AIC26_NUM_REGS]; /* shadow registers */
35 int master; 33 int master;
36 int datfm; 34 int datfm;
37 int mclk; 35 int mclk;
@@ -355,7 +353,6 @@ static DEVICE_ATTR(keyclick, 0644, aic26_keyclick_show, aic26_keyclick_set);
355 */ 353 */
356static int aic26_probe(struct snd_soc_codec *codec) 354static int aic26_probe(struct snd_soc_codec *codec)
357{ 355{
358 struct aic26 *aic26 = snd_soc_codec_get_drvdata(codec);
359 int ret, err, i, reg; 356 int ret, err, i, reg;
360 357
361 dev_info(codec->dev, "Probing AIC26 SoC CODEC driver\n"); 358 dev_info(codec->dev, "Probing AIC26 SoC CODEC driver\n");
@@ -373,7 +370,7 @@ static int aic26_probe(struct snd_soc_codec *codec)
373 aic26_reg_write(codec, AIC26_REG_AUDIO_CTRL3, reg); 370 aic26_reg_write(codec, AIC26_REG_AUDIO_CTRL3, reg);
374 371
375 /* Fill register cache */ 372 /* Fill register cache */
376 for (i = 0; i < ARRAY_SIZE(aic26->reg_cache); i++) 373 for (i = 0; i < codec->driver->reg_cache_size; i++)
377 aic26_reg_read(codec, i); 374 aic26_reg_read(codec, i);
378 375
379 /* Register the sysfs files for debugging */ 376 /* Register the sysfs files for debugging */
diff --git a/sound/soc/codecs/tlv320aic3x.c b/sound/soc/codecs/tlv320aic3x.c
index 77b8f9ae29be..3bedab26892f 100644
--- a/sound/soc/codecs/tlv320aic3x.c
+++ b/sound/soc/codecs/tlv320aic3x.c
@@ -46,7 +46,6 @@
46#include <sound/pcm.h> 46#include <sound/pcm.h>
47#include <sound/pcm_params.h> 47#include <sound/pcm_params.h>
48#include <sound/soc.h> 48#include <sound/soc.h>
49#include <sound/soc-dapm.h>
50#include <sound/initval.h> 49#include <sound/initval.h>
51#include <sound/tlv.h> 50#include <sound/tlv.h>
52#include <sound/tlv320aic3x.h> 51#include <sound/tlv320aic3x.h>
@@ -61,6 +60,8 @@ static const char *aic3x_supply_names[AIC3X_NUM_SUPPLIES] = {
61 "DRVDD", /* ADC Analog and Output Driver Voltage */ 60 "DRVDD", /* ADC Analog and Output Driver Voltage */
62}; 61};
63 62
63static LIST_HEAD(reset_list);
64
64struct aic3x_priv; 65struct aic3x_priv;
65 66
66struct aic3x_disable_nb { 67struct aic3x_disable_nb {
@@ -77,6 +78,7 @@ struct aic3x_priv {
77 struct aic3x_setup_data *setup; 78 struct aic3x_setup_data *setup;
78 void *control_data; 79 void *control_data;
79 unsigned int sysclk; 80 unsigned int sysclk;
81 struct list_head list;
80 int master; 82 int master;
81 int gpio_reset; 83 int gpio_reset;
82 int power; 84 int power;
@@ -183,7 +185,7 @@ static int snd_soc_dapm_put_volsw_aic3x(struct snd_kcontrol *kcontrol,
183 185
184 if (snd_soc_test_bits(widget->codec, reg, val_mask, val)) { 186 if (snd_soc_test_bits(widget->codec, reg, val_mask, val)) {
185 /* find dapm widget path assoc with kcontrol */ 187 /* find dapm widget path assoc with kcontrol */
186 list_for_each_entry(path, &widget->codec->dapm_paths, list) { 188 list_for_each_entry(path, &widget->dapm->card->paths, list) {
187 if (path->kcontrol != kcontrol) 189 if (path->kcontrol != kcontrol)
188 continue; 190 continue;
189 191
@@ -199,7 +201,7 @@ static int snd_soc_dapm_put_volsw_aic3x(struct snd_kcontrol *kcontrol,
199 } 201 }
200 202
201 if (found) 203 if (found)
202 snd_soc_dapm_sync(widget->codec); 204 snd_soc_dapm_sync(widget->dapm);
203 } 205 }
204 206
205 ret = snd_soc_update_bits(widget->codec, reg, val_mask, val); 207 ret = snd_soc_update_bits(widget->codec, reg, val_mask, val);
@@ -788,17 +790,19 @@ static const struct snd_soc_dapm_route intercon_3007[] = {
788static int aic3x_add_widgets(struct snd_soc_codec *codec) 790static int aic3x_add_widgets(struct snd_soc_codec *codec)
789{ 791{
790 struct aic3x_priv *aic3x = snd_soc_codec_get_drvdata(codec); 792 struct aic3x_priv *aic3x = snd_soc_codec_get_drvdata(codec);
793 struct snd_soc_dapm_context *dapm = &codec->dapm;
791 794
792 snd_soc_dapm_new_controls(codec, aic3x_dapm_widgets, 795 snd_soc_dapm_new_controls(dapm, aic3x_dapm_widgets,
793 ARRAY_SIZE(aic3x_dapm_widgets)); 796 ARRAY_SIZE(aic3x_dapm_widgets));
794 797
795 /* set up audio path interconnects */ 798 /* set up audio path interconnects */
796 snd_soc_dapm_add_routes(codec, intercon, ARRAY_SIZE(intercon)); 799 snd_soc_dapm_add_routes(dapm, intercon, ARRAY_SIZE(intercon));
797 800
798 if (aic3x->model == AIC3X_MODEL_3007) { 801 if (aic3x->model == AIC3X_MODEL_3007) {
799 snd_soc_dapm_new_controls(codec, aic3007_dapm_widgets, 802 snd_soc_dapm_new_controls(dapm, aic3007_dapm_widgets,
800 ARRAY_SIZE(aic3007_dapm_widgets)); 803 ARRAY_SIZE(aic3007_dapm_widgets));
801 snd_soc_dapm_add_routes(codec, intercon_3007, ARRAY_SIZE(intercon_3007)); 804 snd_soc_dapm_add_routes(dapm, intercon_3007,
805 ARRAY_SIZE(intercon_3007));
802 } 806 }
803 807
804 return 0; 808 return 0;
@@ -1075,7 +1079,7 @@ static int aic3x_regulator_event(struct notifier_block *nb,
1075 * Put codec to reset and require cache sync as at least one 1079 * Put codec to reset and require cache sync as at least one
1076 * of the supplies was disabled 1080 * of the supplies was disabled
1077 */ 1081 */
1078 if (aic3x->gpio_reset >= 0) 1082 if (gpio_is_valid(aic3x->gpio_reset))
1079 gpio_set_value(aic3x->gpio_reset, 0); 1083 gpio_set_value(aic3x->gpio_reset, 0);
1080 aic3x->codec->cache_sync = 1; 1084 aic3x->codec->cache_sync = 1;
1081 } 1085 }
@@ -1102,7 +1106,7 @@ static int aic3x_set_power(struct snd_soc_codec *codec, int power)
1102 if (!codec->cache_sync) 1106 if (!codec->cache_sync)
1103 goto out; 1107 goto out;
1104 1108
1105 if (aic3x->gpio_reset >= 0) { 1109 if (gpio_is_valid(aic3x->gpio_reset)) {
1106 udelay(1); 1110 udelay(1);
1107 gpio_set_value(aic3x->gpio_reset, 1); 1111 gpio_set_value(aic3x->gpio_reset, 1);
1108 } 1112 }
@@ -1135,7 +1139,7 @@ static int aic3x_set_bias_level(struct snd_soc_codec *codec,
1135 case SND_SOC_BIAS_ON: 1139 case SND_SOC_BIAS_ON:
1136 break; 1140 break;
1137 case SND_SOC_BIAS_PREPARE: 1141 case SND_SOC_BIAS_PREPARE:
1138 if (codec->bias_level == SND_SOC_BIAS_STANDBY && 1142 if (codec->dapm.bias_level == SND_SOC_BIAS_STANDBY &&
1139 aic3x->master) { 1143 aic3x->master) {
1140 /* enable pll */ 1144 /* enable pll */
1141 reg = snd_soc_read(codec, AIC3X_PLL_PROGA_REG); 1145 reg = snd_soc_read(codec, AIC3X_PLL_PROGA_REG);
@@ -1146,7 +1150,7 @@ static int aic3x_set_bias_level(struct snd_soc_codec *codec,
1146 case SND_SOC_BIAS_STANDBY: 1150 case SND_SOC_BIAS_STANDBY:
1147 if (!aic3x->power) 1151 if (!aic3x->power)
1148 aic3x_set_power(codec, 1); 1152 aic3x_set_power(codec, 1);
1149 if (codec->bias_level == SND_SOC_BIAS_PREPARE && 1153 if (codec->dapm.bias_level == SND_SOC_BIAS_PREPARE &&
1150 aic3x->master) { 1154 aic3x->master) {
1151 /* disable pll */ 1155 /* disable pll */
1152 reg = snd_soc_read(codec, AIC3X_PLL_PROGA_REG); 1156 reg = snd_soc_read(codec, AIC3X_PLL_PROGA_REG);
@@ -1159,7 +1163,7 @@ static int aic3x_set_bias_level(struct snd_soc_codec *codec,
1159 aic3x_set_power(codec, 0); 1163 aic3x_set_power(codec, 0);
1160 break; 1164 break;
1161 } 1165 }
1162 codec->bias_level = level; 1166 codec->dapm.bias_level = level;
1163 1167
1164 return 0; 1168 return 0;
1165} 1169}
@@ -1344,14 +1348,28 @@ static int aic3x_init(struct snd_soc_codec *codec)
1344 return 0; 1348 return 0;
1345} 1349}
1346 1350
1351static bool aic3x_is_shared_reset(struct aic3x_priv *aic3x)
1352{
1353 struct aic3x_priv *a;
1354
1355 list_for_each_entry(a, &reset_list, list) {
1356 if (gpio_is_valid(aic3x->gpio_reset) &&
1357 aic3x->gpio_reset == a->gpio_reset)
1358 return true;
1359 }
1360
1361 return false;
1362}
1363
1347static int aic3x_probe(struct snd_soc_codec *codec) 1364static int aic3x_probe(struct snd_soc_codec *codec)
1348{ 1365{
1349 struct aic3x_priv *aic3x = snd_soc_codec_get_drvdata(codec); 1366 struct aic3x_priv *aic3x = snd_soc_codec_get_drvdata(codec);
1350 int ret, i; 1367 int ret, i;
1351 1368
1369 INIT_LIST_HEAD(&aic3x->list);
1352 codec->control_data = aic3x->control_data; 1370 codec->control_data = aic3x->control_data;
1353 aic3x->codec = codec; 1371 aic3x->codec = codec;
1354 codec->idle_bias_off = 1; 1372 codec->dapm.idle_bias_off = 1;
1355 1373
1356 ret = snd_soc_codec_set_cache_io(codec, 8, 8, aic3x->control_type); 1374 ret = snd_soc_codec_set_cache_io(codec, 8, 8, aic3x->control_type);
1357 if (ret != 0) { 1375 if (ret != 0) {
@@ -1359,7 +1377,8 @@ static int aic3x_probe(struct snd_soc_codec *codec)
1359 return ret; 1377 return ret;
1360 } 1378 }
1361 1379
1362 if (aic3x->gpio_reset >= 0) { 1380 if (gpio_is_valid(aic3x->gpio_reset) &&
1381 !aic3x_is_shared_reset(aic3x)) {
1363 ret = gpio_request(aic3x->gpio_reset, "tlv320aic3x reset"); 1382 ret = gpio_request(aic3x->gpio_reset, "tlv320aic3x reset");
1364 if (ret != 0) 1383 if (ret != 0)
1365 goto err_gpio; 1384 goto err_gpio;
@@ -1405,6 +1424,7 @@ static int aic3x_probe(struct snd_soc_codec *codec)
1405 snd_soc_add_controls(codec, &aic3x_classd_amp_gain_ctrl, 1); 1424 snd_soc_add_controls(codec, &aic3x_classd_amp_gain_ctrl, 1);
1406 1425
1407 aic3x_add_widgets(codec); 1426 aic3x_add_widgets(codec);
1427 list_add(&aic3x->list, &reset_list);
1408 1428
1409 return 0; 1429 return 0;
1410 1430
@@ -1414,10 +1434,10 @@ err_notif:
1414 &aic3x->disable_nb[i].nb); 1434 &aic3x->disable_nb[i].nb);
1415 regulator_bulk_free(ARRAY_SIZE(aic3x->supplies), aic3x->supplies); 1435 regulator_bulk_free(ARRAY_SIZE(aic3x->supplies), aic3x->supplies);
1416err_get: 1436err_get:
1417 if (aic3x->gpio_reset >= 0) 1437 if (gpio_is_valid(aic3x->gpio_reset) &&
1438 !aic3x_is_shared_reset(aic3x))
1418 gpio_free(aic3x->gpio_reset); 1439 gpio_free(aic3x->gpio_reset);
1419err_gpio: 1440err_gpio:
1420 kfree(aic3x);
1421 return ret; 1441 return ret;
1422} 1442}
1423 1443
@@ -1427,7 +1447,9 @@ static int aic3x_remove(struct snd_soc_codec *codec)
1427 int i; 1447 int i;
1428 1448
1429 aic3x_set_bias_level(codec, SND_SOC_BIAS_OFF); 1449 aic3x_set_bias_level(codec, SND_SOC_BIAS_OFF);
1430 if (aic3x->gpio_reset >= 0) { 1450 list_del(&aic3x->list);
1451 if (gpio_is_valid(aic3x->gpio_reset) &&
1452 !aic3x_is_shared_reset(aic3x)) {
1431 gpio_set_value(aic3x->gpio_reset, 0); 1453 gpio_set_value(aic3x->gpio_reset, 0);
1432 gpio_free(aic3x->gpio_reset); 1454 gpio_free(aic3x->gpio_reset);
1433 } 1455 }
@@ -1523,21 +1545,6 @@ static struct i2c_driver aic3x_i2c_driver = {
1523 .remove = aic3x_i2c_remove, 1545 .remove = aic3x_i2c_remove,
1524 .id_table = aic3x_i2c_id, 1546 .id_table = aic3x_i2c_id,
1525}; 1547};
1526
1527static inline void aic3x_i2c_init(void)
1528{
1529 int ret;
1530
1531 ret = i2c_add_driver(&aic3x_i2c_driver);
1532 if (ret)
1533 printk(KERN_ERR "%s: error regsitering i2c driver, %d\n",
1534 __func__, ret);
1535}
1536
1537static inline void aic3x_i2c_exit(void)
1538{
1539 i2c_del_driver(&aic3x_i2c_driver);
1540}
1541#endif 1548#endif
1542 1549
1543static int __init aic3x_modinit(void) 1550static int __init aic3x_modinit(void)
diff --git a/sound/soc/codecs/tlv320dac33.c b/sound/soc/codecs/tlv320dac33.c
index c5ab8c805771..71d7be8ac488 100644
--- a/sound/soc/codecs/tlv320dac33.c
+++ b/sound/soc/codecs/tlv320dac33.c
@@ -36,21 +36,21 @@
36#include <sound/pcm.h> 36#include <sound/pcm.h>
37#include <sound/pcm_params.h> 37#include <sound/pcm_params.h>
38#include <sound/soc.h> 38#include <sound/soc.h>
39#include <sound/soc-dapm.h>
40#include <sound/initval.h> 39#include <sound/initval.h>
41#include <sound/tlv.h> 40#include <sound/tlv.h>
42 41
43#include <sound/tlv320dac33-plat.h> 42#include <sound/tlv320dac33-plat.h>
44#include "tlv320dac33.h" 43#include "tlv320dac33.h"
45 44
46#define DAC33_BUFFER_SIZE_BYTES 24576 /* bytes, 12288 16 bit words, 45/*
47 * 6144 stereo */ 46 * The internal FIFO is 24576 bytes long
48#define DAC33_BUFFER_SIZE_SAMPLES 6144 47 * It can be configured to hold 16bit or 24bit samples
49 48 * In 16bit configuration the FIFO can hold 6144 stereo samples
50#define NSAMPLE_MAX 5700 49 * In 24bit configuration the FIFO can hold 4096 stereo samples
51 50 */
52#define MODE7_LTHR 10 51#define DAC33_FIFO_SIZE_16BIT 6144
53#define MODE7_UTHR (DAC33_BUFFER_SIZE_SAMPLES - 10) 52#define DAC33_FIFO_SIZE_24BIT 4096
53#define DAC33_MODE7_MARGIN 10 /* Safety margin for FIFO in Mode7 */
54 54
55#define BURST_BASEFREQ_HZ 49152000 55#define BURST_BASEFREQ_HZ 49152000
56 56
@@ -100,16 +100,11 @@ struct tlv320dac33_priv {
100 unsigned int refclk; 100 unsigned int refclk;
101 101
102 unsigned int alarm_threshold; /* set to be half of LATENCY_TIME_MS */ 102 unsigned int alarm_threshold; /* set to be half of LATENCY_TIME_MS */
103 unsigned int nsample_min; /* nsample should not be lower than
104 * this */
105 unsigned int nsample_max; /* nsample should not be higher than
106 * this */
107 enum dac33_fifo_modes fifo_mode;/* FIFO mode selection */ 103 enum dac33_fifo_modes fifo_mode;/* FIFO mode selection */
104 unsigned int fifo_size; /* Size of the FIFO in samples */
108 unsigned int nsample; /* burst read amount from host */ 105 unsigned int nsample; /* burst read amount from host */
109 int mode1_latency; /* latency caused by the i2c writes in 106 int mode1_latency; /* latency caused by the i2c writes in
110 * us */ 107 * us */
111 int auto_fifo_config; /* Configure the FIFO based on the
112 * period size */
113 u8 burst_bclkdiv; /* BCLK divider value in burst mode */ 108 u8 burst_bclkdiv; /* BCLK divider value in burst mode */
114 unsigned int burst_rate; /* Interface speed in Burst modes */ 109 unsigned int burst_rate; /* Interface speed in Burst modes */
115 110
@@ -303,7 +298,6 @@ static void dac33_init_chip(struct snd_soc_codec *codec)
303 if (unlikely(!dac33->chip_power)) 298 if (unlikely(!dac33->chip_power))
304 return; 299 return;
305 300
306 /* 44-46: DAC Control Registers */
307 /* A : DAC sample rate Fsref/1.5 */ 301 /* A : DAC sample rate Fsref/1.5 */
308 dac33_write(codec, DAC33_DAC_CTRL_A, DAC33_DACRATE(0)); 302 dac33_write(codec, DAC33_DAC_CTRL_A, DAC33_DACRATE(0));
309 /* B : DAC src=normal, not muted */ 303 /* B : DAC src=normal, not muted */
@@ -316,8 +310,6 @@ static void dac33_init_chip(struct snd_soc_codec *codec)
316 clock source = internal osc (?) */ 310 clock source = internal osc (?) */
317 dac33_write(codec, DAC33_ANA_VOL_SOFT_STEP_CTRL, DAC33_VOLCLKEN); 311 dac33_write(codec, DAC33_ANA_VOL_SOFT_STEP_CTRL, DAC33_VOLCLKEN);
318 312
319 dac33_write(codec, DAC33_PWR_CTRL, DAC33_PDNALLB);
320
321 /* Restore only selected registers (gains mostly) */ 313 /* Restore only selected registers (gains mostly) */
322 dac33_write(codec, DAC33_LDAC_DIG_VOL_CTRL, 314 dac33_write(codec, DAC33_LDAC_DIG_VOL_CTRL,
323 dac33_read_reg_cache(codec, DAC33_LDAC_DIG_VOL_CTRL)); 315 dac33_read_reg_cache(codec, DAC33_LDAC_DIG_VOL_CTRL));
@@ -328,6 +320,10 @@ static void dac33_init_chip(struct snd_soc_codec *codec)
328 dac33_read_reg_cache(codec, DAC33_LINEL_TO_LLO_VOL)); 320 dac33_read_reg_cache(codec, DAC33_LINEL_TO_LLO_VOL));
329 dac33_write(codec, DAC33_LINER_TO_RLO_VOL, 321 dac33_write(codec, DAC33_LINER_TO_RLO_VOL,
330 dac33_read_reg_cache(codec, DAC33_LINER_TO_RLO_VOL)); 322 dac33_read_reg_cache(codec, DAC33_LINER_TO_RLO_VOL));
323
324 dac33_write(codec, DAC33_OUT_AMP_CTRL,
325 dac33_read_reg_cache(codec, DAC33_OUT_AMP_CTRL));
326
331} 327}
332 328
333static inline int dac33_read_id(struct snd_soc_codec *codec) 329static inline int dac33_read_id(struct snd_soc_codec *codec)
@@ -357,6 +353,21 @@ static inline void dac33_soft_power(struct snd_soc_codec *codec, int power)
357 dac33_write(codec, DAC33_PWR_CTRL, reg); 353 dac33_write(codec, DAC33_PWR_CTRL, reg);
358} 354}
359 355
356static inline void dac33_disable_digital(struct snd_soc_codec *codec)
357{
358 u8 reg;
359
360 /* Stop the DAI clock */
361 reg = dac33_read_reg_cache(codec, DAC33_SER_AUDIOIF_CTRL_B);
362 reg &= ~DAC33_BCLKON;
363 dac33_write(codec, DAC33_SER_AUDIOIF_CTRL_B, reg);
364
365 /* Power down the Oscillator, and DACs */
366 reg = dac33_read_reg_cache(codec, DAC33_PWR_CTRL);
367 reg &= ~(DAC33_OSCPDNB | DAC33_DACRPDNB | DAC33_DACLPDNB);
368 dac33_write(codec, DAC33_PWR_CTRL, reg);
369}
370
360static int dac33_hard_power(struct snd_soc_codec *codec, int power) 371static int dac33_hard_power(struct snd_soc_codec *codec, int power)
361{ 372{
362 struct tlv320dac33_priv *dac33 = snd_soc_codec_get_drvdata(codec); 373 struct tlv320dac33_priv *dac33 = snd_soc_codec_get_drvdata(codec);
@@ -405,7 +416,7 @@ exit:
405 return ret; 416 return ret;
406} 417}
407 418
408static int playback_event(struct snd_soc_dapm_widget *w, 419static int dac33_playback_event(struct snd_soc_dapm_widget *w,
409 struct snd_kcontrol *kcontrol, int event) 420 struct snd_kcontrol *kcontrol, int event)
410{ 421{
411 struct tlv320dac33_priv *dac33 = snd_soc_codec_get_drvdata(w->codec); 422 struct tlv320dac33_priv *dac33 = snd_soc_codec_get_drvdata(w->codec);
@@ -417,77 +428,13 @@ static int playback_event(struct snd_soc_dapm_widget *w,
417 dac33_prepare_chip(dac33->substream); 428 dac33_prepare_chip(dac33->substream);
418 } 429 }
419 break; 430 break;
431 case SND_SOC_DAPM_POST_PMD:
432 dac33_disable_digital(w->codec);
433 break;
420 } 434 }
421 return 0; 435 return 0;
422} 436}
423 437
424static int dac33_get_nsample(struct snd_kcontrol *kcontrol,
425 struct snd_ctl_elem_value *ucontrol)
426{
427 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
428 struct tlv320dac33_priv *dac33 = snd_soc_codec_get_drvdata(codec);
429
430 ucontrol->value.integer.value[0] = dac33->nsample;
431
432 return 0;
433}
434
435static int dac33_set_nsample(struct snd_kcontrol *kcontrol,
436 struct snd_ctl_elem_value *ucontrol)
437{
438 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
439 struct tlv320dac33_priv *dac33 = snd_soc_codec_get_drvdata(codec);
440 int ret = 0;
441
442 if (dac33->nsample == ucontrol->value.integer.value[0])
443 return 0;
444
445 if (ucontrol->value.integer.value[0] < dac33->nsample_min ||
446 ucontrol->value.integer.value[0] > dac33->nsample_max) {
447 ret = -EINVAL;
448 } else {
449 dac33->nsample = ucontrol->value.integer.value[0];
450 /* Re calculate the burst time */
451 dac33->mode1_us_burst = SAMPLES_TO_US(dac33->burst_rate,
452 dac33->nsample);
453 }
454
455 return ret;
456}
457
458static int dac33_get_uthr(struct snd_kcontrol *kcontrol,
459 struct snd_ctl_elem_value *ucontrol)
460{
461 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
462 struct tlv320dac33_priv *dac33 = snd_soc_codec_get_drvdata(codec);
463
464 ucontrol->value.integer.value[0] = dac33->uthr;
465
466 return 0;
467}
468
469static int dac33_set_uthr(struct snd_kcontrol *kcontrol,
470 struct snd_ctl_elem_value *ucontrol)
471{
472 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
473 struct tlv320dac33_priv *dac33 = snd_soc_codec_get_drvdata(codec);
474 int ret = 0;
475
476 if (dac33->substream)
477 return -EBUSY;
478
479 if (dac33->uthr == ucontrol->value.integer.value[0])
480 return 0;
481
482 if (ucontrol->value.integer.value[0] < (MODE7_LTHR + 10) ||
483 ucontrol->value.integer.value[0] > MODE7_UTHR)
484 ret = -EINVAL;
485 else
486 dac33->uthr = ucontrol->value.integer.value[0];
487
488 return ret;
489}
490
491static int dac33_get_fifo_mode(struct snd_kcontrol *kcontrol, 438static int dac33_get_fifo_mode(struct snd_kcontrol *kcontrol,
492 struct snd_ctl_elem_value *ucontrol) 439 struct snd_ctl_elem_value *ucontrol)
493{ 440{
@@ -572,13 +519,6 @@ static const struct snd_kcontrol_new dac33_mode_snd_controls[] = {
572 dac33_get_fifo_mode, dac33_set_fifo_mode), 519 dac33_get_fifo_mode, dac33_set_fifo_mode),
573}; 520};
574 521
575static const struct snd_kcontrol_new dac33_fifo_snd_controls[] = {
576 SOC_SINGLE_EXT("nSample", 0, 0, 5900, 0,
577 dac33_get_nsample, dac33_set_nsample),
578 SOC_SINGLE_EXT("UTHR", 0, 0, MODE7_UTHR, 0,
579 dac33_get_uthr, dac33_set_uthr),
580};
581
582/* Analog bypass */ 522/* Analog bypass */
583static const struct snd_kcontrol_new dac33_dapm_abypassl_control = 523static const struct snd_kcontrol_new dac33_dapm_abypassl_control =
584 SOC_DAPM_SINGLE("Switch", DAC33_LINEL_TO_LLO_VOL, 7, 1, 1); 524 SOC_DAPM_SINGLE("Switch", DAC33_LINEL_TO_LLO_VOL, 7, 1, 1);
@@ -586,6 +526,25 @@ static const struct snd_kcontrol_new dac33_dapm_abypassl_control =
586static const struct snd_kcontrol_new dac33_dapm_abypassr_control = 526static const struct snd_kcontrol_new dac33_dapm_abypassr_control =
587 SOC_DAPM_SINGLE("Switch", DAC33_LINER_TO_RLO_VOL, 7, 1, 1); 527 SOC_DAPM_SINGLE("Switch", DAC33_LINER_TO_RLO_VOL, 7, 1, 1);
588 528
529/* LOP L/R invert selection */
530static const char *dac33_lr_lom_texts[] = {"DAC", "LOP"};
531
532static const struct soc_enum dac33_left_lom_enum =
533 SOC_ENUM_SINGLE(DAC33_OUT_AMP_CTRL, 3,
534 ARRAY_SIZE(dac33_lr_lom_texts),
535 dac33_lr_lom_texts);
536
537static const struct snd_kcontrol_new dac33_dapm_left_lom_control =
538SOC_DAPM_ENUM("Route", dac33_left_lom_enum);
539
540static const struct soc_enum dac33_right_lom_enum =
541 SOC_ENUM_SINGLE(DAC33_OUT_AMP_CTRL, 2,
542 ARRAY_SIZE(dac33_lr_lom_texts),
543 dac33_lr_lom_texts);
544
545static const struct snd_kcontrol_new dac33_dapm_right_lom_control =
546SOC_DAPM_ENUM("Route", dac33_right_lom_enum);
547
589static const struct snd_soc_dapm_widget dac33_dapm_widgets[] = { 548static const struct snd_soc_dapm_widget dac33_dapm_widgets[] = {
590 SND_SOC_DAPM_OUTPUT("LEFT_LO"), 549 SND_SOC_DAPM_OUTPUT("LEFT_LO"),
591 SND_SOC_DAPM_OUTPUT("RIGHT_LO"), 550 SND_SOC_DAPM_OUTPUT("RIGHT_LO"),
@@ -593,8 +552,8 @@ static const struct snd_soc_dapm_widget dac33_dapm_widgets[] = {
593 SND_SOC_DAPM_INPUT("LINEL"), 552 SND_SOC_DAPM_INPUT("LINEL"),
594 SND_SOC_DAPM_INPUT("LINER"), 553 SND_SOC_DAPM_INPUT("LINER"),
595 554
596 SND_SOC_DAPM_DAC("DACL", "Left Playback", DAC33_LDAC_PWR_CTRL, 2, 0), 555 SND_SOC_DAPM_DAC("DACL", "Left Playback", SND_SOC_NOPM, 0, 0),
597 SND_SOC_DAPM_DAC("DACR", "Right Playback", DAC33_RDAC_PWR_CTRL, 2, 0), 556 SND_SOC_DAPM_DAC("DACR", "Right Playback", SND_SOC_NOPM, 0, 0),
598 557
599 /* Analog bypass */ 558 /* Analog bypass */
600 SND_SOC_DAPM_SWITCH("Analog Left Bypass", SND_SOC_NOPM, 0, 0, 559 SND_SOC_DAPM_SWITCH("Analog Left Bypass", SND_SOC_NOPM, 0, 0,
@@ -602,12 +561,30 @@ static const struct snd_soc_dapm_widget dac33_dapm_widgets[] = {
602 SND_SOC_DAPM_SWITCH("Analog Right Bypass", SND_SOC_NOPM, 0, 0, 561 SND_SOC_DAPM_SWITCH("Analog Right Bypass", SND_SOC_NOPM, 0, 0,
603 &dac33_dapm_abypassr_control), 562 &dac33_dapm_abypassr_control),
604 563
605 SND_SOC_DAPM_REG(snd_soc_dapm_mixer, "Output Left Amp Power", 564 SND_SOC_DAPM_MUX("Left LOM Inverted From", SND_SOC_NOPM, 0, 0,
565 &dac33_dapm_left_lom_control),
566 SND_SOC_DAPM_MUX("Right LOM Inverted From", SND_SOC_NOPM, 0, 0,
567 &dac33_dapm_right_lom_control),
568 /*
569 * For DAPM path, when only the anlog bypass path is enabled, and the
570 * LOP inverted from the corresponding DAC side.
571 * This is needed, so we can attach the DAC power supply in this case.
572 */
573 SND_SOC_DAPM_PGA("Left Bypass PGA", SND_SOC_NOPM, 0, 0, NULL, 0),
574 SND_SOC_DAPM_PGA("Right Bypass PGA", SND_SOC_NOPM, 0, 0, NULL, 0),
575
576 SND_SOC_DAPM_REG(snd_soc_dapm_mixer, "Output Left Amplifier",
606 DAC33_OUT_AMP_PWR_CTRL, 6, 3, 3, 0), 577 DAC33_OUT_AMP_PWR_CTRL, 6, 3, 3, 0),
607 SND_SOC_DAPM_REG(snd_soc_dapm_mixer, "Output Right Amp Power", 578 SND_SOC_DAPM_REG(snd_soc_dapm_mixer, "Output Right Amplifier",
608 DAC33_OUT_AMP_PWR_CTRL, 4, 3, 3, 0), 579 DAC33_OUT_AMP_PWR_CTRL, 4, 3, 3, 0),
609 580
610 SND_SOC_DAPM_PRE("Prepare Playback", playback_event), 581 SND_SOC_DAPM_SUPPLY("Left DAC Power",
582 DAC33_LDAC_PWR_CTRL, 2, 0, NULL, 0),
583 SND_SOC_DAPM_SUPPLY("Right DAC Power",
584 DAC33_RDAC_PWR_CTRL, 2, 0, NULL, 0),
585
586 SND_SOC_DAPM_PRE("Pre Playback", dac33_playback_event),
587 SND_SOC_DAPM_POST("Post Playback", dac33_playback_event),
611}; 588};
612 589
613static const struct snd_soc_dapm_route audio_map[] = { 590static const struct snd_soc_dapm_route audio_map[] = {
@@ -615,24 +592,39 @@ static const struct snd_soc_dapm_route audio_map[] = {
615 {"Analog Left Bypass", "Switch", "LINEL"}, 592 {"Analog Left Bypass", "Switch", "LINEL"},
616 {"Analog Right Bypass", "Switch", "LINER"}, 593 {"Analog Right Bypass", "Switch", "LINER"},
617 594
618 {"Output Left Amp Power", NULL, "DACL"}, 595 {"Output Left Amplifier", NULL, "DACL"},
619 {"Output Right Amp Power", NULL, "DACR"}, 596 {"Output Right Amplifier", NULL, "DACR"},
620 597
621 {"Output Left Amp Power", NULL, "Analog Left Bypass"}, 598 {"Left Bypass PGA", NULL, "Analog Left Bypass"},
622 {"Output Right Amp Power", NULL, "Analog Right Bypass"}, 599 {"Right Bypass PGA", NULL, "Analog Right Bypass"},
600
601 {"Left LOM Inverted From", "DAC", "Left Bypass PGA"},
602 {"Right LOM Inverted From", "DAC", "Right Bypass PGA"},
603 {"Left LOM Inverted From", "LOP", "Analog Left Bypass"},
604 {"Right LOM Inverted From", "LOP", "Analog Right Bypass"},
605
606 {"Output Left Amplifier", NULL, "Left LOM Inverted From"},
607 {"Output Right Amplifier", NULL, "Right LOM Inverted From"},
608
609 {"DACL", NULL, "Left DAC Power"},
610 {"DACR", NULL, "Right DAC Power"},
611
612 {"Left Bypass PGA", NULL, "Left DAC Power"},
613 {"Right Bypass PGA", NULL, "Right DAC Power"},
623 614
624 /* output */ 615 /* output */
625 {"LEFT_LO", NULL, "Output Left Amp Power"}, 616 {"LEFT_LO", NULL, "Output Left Amplifier"},
626 {"RIGHT_LO", NULL, "Output Right Amp Power"}, 617 {"RIGHT_LO", NULL, "Output Right Amplifier"},
627}; 618};
628 619
629static int dac33_add_widgets(struct snd_soc_codec *codec) 620static int dac33_add_widgets(struct snd_soc_codec *codec)
630{ 621{
631 snd_soc_dapm_new_controls(codec, dac33_dapm_widgets, 622 struct snd_soc_dapm_context *dapm = &codec->dapm;
632 ARRAY_SIZE(dac33_dapm_widgets));
633 623
624 snd_soc_dapm_new_controls(dapm, dac33_dapm_widgets,
625 ARRAY_SIZE(dac33_dapm_widgets));
634 /* set up audio path interconnects */ 626 /* set up audio path interconnects */
635 snd_soc_dapm_add_routes(codec, audio_map, ARRAY_SIZE(audio_map)); 627 snd_soc_dapm_add_routes(dapm, audio_map, ARRAY_SIZE(audio_map));
636 628
637 return 0; 629 return 0;
638} 630}
@@ -640,16 +632,18 @@ static int dac33_add_widgets(struct snd_soc_codec *codec)
640static int dac33_set_bias_level(struct snd_soc_codec *codec, 632static int dac33_set_bias_level(struct snd_soc_codec *codec,
641 enum snd_soc_bias_level level) 633 enum snd_soc_bias_level level)
642{ 634{
635 struct tlv320dac33_priv *dac33 = snd_soc_codec_get_drvdata(codec);
643 int ret; 636 int ret;
644 637
645 switch (level) { 638 switch (level) {
646 case SND_SOC_BIAS_ON: 639 case SND_SOC_BIAS_ON:
647 dac33_soft_power(codec, 1); 640 if (!dac33->substream)
641 dac33_soft_power(codec, 1);
648 break; 642 break;
649 case SND_SOC_BIAS_PREPARE: 643 case SND_SOC_BIAS_PREPARE:
650 break; 644 break;
651 case SND_SOC_BIAS_STANDBY: 645 case SND_SOC_BIAS_STANDBY:
652 if (codec->bias_level == SND_SOC_BIAS_OFF) { 646 if (codec->dapm.bias_level == SND_SOC_BIAS_OFF) {
653 /* Coming from OFF, switch on the codec */ 647 /* Coming from OFF, switch on the codec */
654 ret = dac33_hard_power(codec, 1); 648 ret = dac33_hard_power(codec, 1);
655 if (ret != 0) 649 if (ret != 0)
@@ -660,14 +654,14 @@ static int dac33_set_bias_level(struct snd_soc_codec *codec,
660 break; 654 break;
661 case SND_SOC_BIAS_OFF: 655 case SND_SOC_BIAS_OFF:
662 /* Do not power off, when the codec is already off */ 656 /* Do not power off, when the codec is already off */
663 if (codec->bias_level == SND_SOC_BIAS_OFF) 657 if (codec->dapm.bias_level == SND_SOC_BIAS_OFF)
664 return 0; 658 return 0;
665 ret = dac33_hard_power(codec, 0); 659 ret = dac33_hard_power(codec, 0);
666 if (ret != 0) 660 if (ret != 0)
667 return ret; 661 return ret;
668 break; 662 break;
669 } 663 }
670 codec->bias_level = level; 664 codec->dapm.bias_level = level;
671 665
672 return 0; 666 return 0;
673} 667}
@@ -705,7 +699,7 @@ static inline void dac33_prefill_handler(struct tlv320dac33_priv *dac33)
705 spin_unlock_irq(&dac33->lock); 699 spin_unlock_irq(&dac33->lock);
706 700
707 dac33_write16(codec, DAC33_PREFILL_MSB, 701 dac33_write16(codec, DAC33_PREFILL_MSB,
708 DAC33_THRREG(MODE7_LTHR)); 702 DAC33_THRREG(DAC33_MODE7_MARGIN));
709 703
710 /* Enable Upper Threshold IRQ */ 704 /* Enable Upper Threshold IRQ */
711 dac33_write(codec, DAC33_FIFO_IRQ_MASK, DAC33_MUT); 705 dac33_write(codec, DAC33_FIFO_IRQ_MASK, DAC33_MUT);
@@ -815,6 +809,8 @@ static int dac33_startup(struct snd_pcm_substream *substream,
815 /* Stream started, save the substream pointer */ 809 /* Stream started, save the substream pointer */
816 dac33->substream = substream; 810 dac33->substream = substream;
817 811
812 snd_pcm_hw_constraint_msbits(substream->runtime, 0, 32, 24);
813
818 return 0; 814 return 0;
819} 815}
820 816
@@ -826,18 +822,17 @@ static void dac33_shutdown(struct snd_pcm_substream *substream,
826 struct tlv320dac33_priv *dac33 = snd_soc_codec_get_drvdata(codec); 822 struct tlv320dac33_priv *dac33 = snd_soc_codec_get_drvdata(codec);
827 823
828 dac33->substream = NULL; 824 dac33->substream = NULL;
829
830 /* Reset the nSample restrictions */
831 dac33->nsample_min = 0;
832 dac33->nsample_max = NSAMPLE_MAX;
833} 825}
834 826
827#define CALC_BURST_RATE(bclkdiv, bclk_per_sample) \
828 (BURST_BASEFREQ_HZ / bclkdiv / bclk_per_sample)
835static int dac33_hw_params(struct snd_pcm_substream *substream, 829static int dac33_hw_params(struct snd_pcm_substream *substream,
836 struct snd_pcm_hw_params *params, 830 struct snd_pcm_hw_params *params,
837 struct snd_soc_dai *dai) 831 struct snd_soc_dai *dai)
838{ 832{
839 struct snd_soc_pcm_runtime *rtd = substream->private_data; 833 struct snd_soc_pcm_runtime *rtd = substream->private_data;
840 struct snd_soc_codec *codec = rtd->codec; 834 struct snd_soc_codec *codec = rtd->codec;
835 struct tlv320dac33_priv *dac33 = snd_soc_codec_get_drvdata(codec);
841 836
842 /* Check parameters for validity */ 837 /* Check parameters for validity */
843 switch (params_rate(params)) { 838 switch (params_rate(params)) {
@@ -852,6 +847,12 @@ static int dac33_hw_params(struct snd_pcm_substream *substream,
852 847
853 switch (params_format(params)) { 848 switch (params_format(params)) {
854 case SNDRV_PCM_FORMAT_S16_LE: 849 case SNDRV_PCM_FORMAT_S16_LE:
850 dac33->fifo_size = DAC33_FIFO_SIZE_16BIT;
851 dac33->burst_rate = CALC_BURST_RATE(dac33->burst_bclkdiv, 32);
852 break;
853 case SNDRV_PCM_FORMAT_S32_LE:
854 dac33->fifo_size = DAC33_FIFO_SIZE_24BIT;
855 dac33->burst_rate = CALC_BURST_RATE(dac33->burst_bclkdiv, 64);
855 break; 856 break;
856 default: 857 default:
857 dev_err(codec->dev, "unsupported format %d\n", 858 dev_err(codec->dev, "unsupported format %d\n",
@@ -906,6 +907,9 @@ static int dac33_prepare_chip(struct snd_pcm_substream *substream)
906 aictrl_a |= (DAC33_NCYCL_16 | DAC33_WLEN_16); 907 aictrl_a |= (DAC33_NCYCL_16 | DAC33_WLEN_16);
907 fifoctrl_a |= DAC33_WIDTH; 908 fifoctrl_a |= DAC33_WIDTH;
908 break; 909 break;
910 case SNDRV_PCM_FORMAT_S32_LE:
911 aictrl_a |= (DAC33_NCYCL_32 | DAC33_WLEN_24);
912 break;
909 default: 913 default:
910 dev_err(codec->dev, "unsupported format %d\n", 914 dev_err(codec->dev, "unsupported format %d\n",
911 substream->runtime->format); 915 substream->runtime->format);
@@ -1040,7 +1044,10 @@ static int dac33_prepare_chip(struct snd_pcm_substream *substream)
1040 dac33_write(codec, DAC33_SER_AUDIOIF_CTRL_C, 1044 dac33_write(codec, DAC33_SER_AUDIOIF_CTRL_C,
1041 dac33->burst_bclkdiv); 1045 dac33->burst_bclkdiv);
1042 else 1046 else
1043 dac33_write(codec, DAC33_SER_AUDIOIF_CTRL_C, 32); 1047 if (substream->runtime->format == SNDRV_PCM_FORMAT_S16_LE)
1048 dac33_write(codec, DAC33_SER_AUDIOIF_CTRL_C, 32);
1049 else
1050 dac33_write(codec, DAC33_SER_AUDIOIF_CTRL_C, 16);
1044 1051
1045 switch (dac33->fifo_mode) { 1052 switch (dac33->fifo_mode) {
1046 case DAC33_FIFO_MODE1: 1053 case DAC33_FIFO_MODE1:
@@ -1053,7 +1060,8 @@ static int dac33_prepare_chip(struct snd_pcm_substream *substream)
1053 * at the bottom, and also at the top of the FIFO 1060 * at the bottom, and also at the top of the FIFO
1054 */ 1061 */
1055 dac33_write16(codec, DAC33_UTHR_MSB, DAC33_THRREG(dac33->uthr)); 1062 dac33_write16(codec, DAC33_UTHR_MSB, DAC33_THRREG(dac33->uthr));
1056 dac33_write16(codec, DAC33_LTHR_MSB, DAC33_THRREG(MODE7_LTHR)); 1063 dac33_write16(codec, DAC33_LTHR_MSB,
1064 DAC33_THRREG(DAC33_MODE7_MARGIN));
1057 break; 1065 break;
1058 default: 1066 default:
1059 break; 1067 break;
@@ -1082,42 +1090,21 @@ static void dac33_calculate_times(struct snd_pcm_substream *substream)
1082 /* Number of samples under i2c latency */ 1090 /* Number of samples under i2c latency */
1083 dac33->alarm_threshold = US_TO_SAMPLES(rate, 1091 dac33->alarm_threshold = US_TO_SAMPLES(rate,
1084 dac33->mode1_latency); 1092 dac33->mode1_latency);
1085 nsample_limit = DAC33_BUFFER_SIZE_SAMPLES - 1093 nsample_limit = dac33->fifo_size - dac33->alarm_threshold;
1086 dac33->alarm_threshold; 1094
1087 1095 if (period_size <= dac33->alarm_threshold)
1088 if (dac33->auto_fifo_config) {
1089 if (period_size <= dac33->alarm_threshold)
1090 /*
1091 * Configure nSamaple to number of periods,
1092 * which covers the latency requironment.
1093 */
1094 dac33->nsample = period_size *
1095 ((dac33->alarm_threshold / period_size) +
1096 (dac33->alarm_threshold % period_size ?
1097 1 : 0));
1098 else if (period_size > nsample_limit)
1099 dac33->nsample = nsample_limit;
1100 else
1101 dac33->nsample = period_size;
1102 } else {
1103 /* nSample time shall not be shorter than i2c latency */
1104 dac33->nsample_min = dac33->alarm_threshold;
1105 /* 1096 /*
1106 * nSample should not be bigger than alsa buffer minus 1097 * Configure nSamaple to number of periods,
1107 * size of one period to avoid overruns 1098 * which covers the latency requironment.
1108 */ 1099 */
1109 dac33->nsample_max = substream->runtime->buffer_size - 1100 dac33->nsample = period_size *
1110 period_size; 1101 ((dac33->alarm_threshold / period_size) +
1111 1102 (dac33->alarm_threshold % period_size ?
1112 if (dac33->nsample_max > nsample_limit) 1103 1 : 0));
1113 dac33->nsample_max = nsample_limit; 1104 else if (period_size > nsample_limit)
1114 1105 dac33->nsample = nsample_limit;
1115 /* Correct the nSample if it is outside of the ranges */ 1106 else
1116 if (dac33->nsample < dac33->nsample_min) 1107 dac33->nsample = period_size;
1117 dac33->nsample = dac33->nsample_min;
1118 if (dac33->nsample > dac33->nsample_max)
1119 dac33->nsample = dac33->nsample_max;
1120 }
1121 1108
1122 dac33->mode1_us_burst = SAMPLES_TO_US(dac33->burst_rate, 1109 dac33->mode1_us_burst = SAMPLES_TO_US(dac33->burst_rate,
1123 dac33->nsample); 1110 dac33->nsample);
@@ -1125,19 +1112,16 @@ static void dac33_calculate_times(struct snd_pcm_substream *substream)
1125 dac33->t_stamp2 = 0; 1112 dac33->t_stamp2 = 0;
1126 break; 1113 break;
1127 case DAC33_FIFO_MODE7: 1114 case DAC33_FIFO_MODE7:
1128 if (dac33->auto_fifo_config) { 1115 dac33->uthr = UTHR_FROM_PERIOD_SIZE(period_size, rate,
1129 dac33->uthr = UTHR_FROM_PERIOD_SIZE( 1116 dac33->burst_rate) + 9;
1130 period_size, 1117 if (dac33->uthr > (dac33->fifo_size - DAC33_MODE7_MARGIN))
1131 rate, 1118 dac33->uthr = dac33->fifo_size - DAC33_MODE7_MARGIN;
1132 dac33->burst_rate) + 9; 1119 if (dac33->uthr < (DAC33_MODE7_MARGIN + 10))
1133 if (dac33->uthr > MODE7_UTHR) 1120 dac33->uthr = (DAC33_MODE7_MARGIN + 10);
1134 dac33->uthr = MODE7_UTHR; 1121
1135 if (dac33->uthr < (MODE7_LTHR + 10))
1136 dac33->uthr = (MODE7_LTHR + 10);
1137 }
1138 dac33->mode7_us_to_lthr = 1122 dac33->mode7_us_to_lthr =
1139 SAMPLES_TO_US(substream->runtime->rate, 1123 SAMPLES_TO_US(substream->runtime->rate,
1140 dac33->uthr - MODE7_LTHR + 1); 1124 dac33->uthr - DAC33_MODE7_MARGIN + 1);
1141 dac33->t_stamp1 = 0; 1125 dac33->t_stamp1 = 0;
1142 break; 1126 break;
1143 default: 1127 default:
@@ -1255,8 +1239,8 @@ static snd_pcm_sframes_t dac33_dai_delay(
1255 samples += (samples_in - samples_out); 1239 samples += (samples_in - samples_out);
1256 1240
1257 if (likely(samples > 0)) 1241 if (likely(samples > 0))
1258 delay = samples > DAC33_BUFFER_SIZE_SAMPLES ? 1242 delay = samples > dac33->fifo_size ?
1259 DAC33_BUFFER_SIZE_SAMPLES : samples; 1243 dac33->fifo_size : samples;
1260 else 1244 else
1261 delay = 0; 1245 delay = 0;
1262 } 1246 }
@@ -1308,7 +1292,7 @@ static snd_pcm_sframes_t dac33_dai_delay(
1308 samples_in = US_TO_SAMPLES( 1292 samples_in = US_TO_SAMPLES(
1309 dac33->burst_rate, 1293 dac33->burst_rate,
1310 time_delta); 1294 time_delta);
1311 delay = MODE7_LTHR + samples_in - samples_out; 1295 delay = DAC33_MODE7_MARGIN + samples_in - samples_out;
1312 1296
1313 if (unlikely(delay > uthr)) 1297 if (unlikely(delay > uthr))
1314 delay = uthr; 1298 delay = uthr;
@@ -1415,7 +1399,7 @@ static int dac33_soc_probe(struct snd_soc_codec *codec)
1415 1399
1416 codec->control_data = dac33->control_data; 1400 codec->control_data = dac33->control_data;
1417 codec->hw_write = (hw_write_t) i2c_master_send; 1401 codec->hw_write = (hw_write_t) i2c_master_send;
1418 codec->idle_bias_off = 1; 1402 codec->dapm.idle_bias_off = 1;
1419 dac33->codec = codec; 1403 dac33->codec = codec;
1420 1404
1421 /* Read the tlv320dac33 ID registers */ 1405 /* Read the tlv320dac33 ID registers */
@@ -1459,14 +1443,10 @@ static int dac33_soc_probe(struct snd_soc_codec *codec)
1459 snd_soc_add_controls(codec, dac33_snd_controls, 1443 snd_soc_add_controls(codec, dac33_snd_controls,
1460 ARRAY_SIZE(dac33_snd_controls)); 1444 ARRAY_SIZE(dac33_snd_controls));
1461 /* Only add the FIFO controls, if we have valid IRQ number */ 1445 /* Only add the FIFO controls, if we have valid IRQ number */
1462 if (dac33->irq >= 0) { 1446 if (dac33->irq >= 0)
1463 snd_soc_add_controls(codec, dac33_mode_snd_controls, 1447 snd_soc_add_controls(codec, dac33_mode_snd_controls,
1464 ARRAY_SIZE(dac33_mode_snd_controls)); 1448 ARRAY_SIZE(dac33_mode_snd_controls));
1465 /* FIFO usage controls only, if autoio config is not selected */ 1449
1466 if (!dac33->auto_fifo_config)
1467 snd_soc_add_controls(codec, dac33_fifo_snd_controls,
1468 ARRAY_SIZE(dac33_fifo_snd_controls));
1469 }
1470 dac33_add_widgets(codec); 1450 dac33_add_widgets(codec);
1471 1451
1472err_power: 1452err_power:
@@ -1515,7 +1495,7 @@ static struct snd_soc_codec_driver soc_codec_dev_tlv320dac33 = {
1515 1495
1516#define DAC33_RATES (SNDRV_PCM_RATE_44100 | \ 1496#define DAC33_RATES (SNDRV_PCM_RATE_44100 | \
1517 SNDRV_PCM_RATE_48000) 1497 SNDRV_PCM_RATE_48000)
1518#define DAC33_FORMATS SNDRV_PCM_FMTBIT_S16_LE 1498#define DAC33_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S32_LE)
1519 1499
1520static struct snd_soc_dai_ops dac33_dai_ops = { 1500static struct snd_soc_dai_ops dac33_dai_ops = {
1521 .startup = dac33_startup, 1501 .startup = dac33_startup,
@@ -1563,17 +1543,11 @@ static int __devinit dac33_i2c_probe(struct i2c_client *client,
1563 1543
1564 dac33->power_gpio = pdata->power_gpio; 1544 dac33->power_gpio = pdata->power_gpio;
1565 dac33->burst_bclkdiv = pdata->burst_bclkdiv; 1545 dac33->burst_bclkdiv = pdata->burst_bclkdiv;
1566 /* Pre calculate the burst rate */
1567 dac33->burst_rate = BURST_BASEFREQ_HZ / dac33->burst_bclkdiv / 32;
1568 dac33->keep_bclk = pdata->keep_bclk; 1546 dac33->keep_bclk = pdata->keep_bclk;
1569 dac33->auto_fifo_config = pdata->auto_fifo_config;
1570 dac33->mode1_latency = pdata->mode1_latency; 1547 dac33->mode1_latency = pdata->mode1_latency;
1571 if (!dac33->mode1_latency) 1548 if (!dac33->mode1_latency)
1572 dac33->mode1_latency = 10000; /* 10ms */ 1549 dac33->mode1_latency = 10000; /* 10ms */
1573 dac33->irq = client->irq; 1550 dac33->irq = client->irq;
1574 dac33->nsample = NSAMPLE_MAX;
1575 dac33->nsample_max = NSAMPLE_MAX;
1576 dac33->uthr = MODE7_UTHR;
1577 /* Disable FIFO use by default */ 1551 /* Disable FIFO use by default */
1578 dac33->fifo_mode = DAC33_FIFO_BYPASS; 1552 dac33->fifo_mode = DAC33_FIFO_BYPASS;
1579 1553
diff --git a/sound/soc/codecs/tpa6130a2.c b/sound/soc/codecs/tpa6130a2.c
index d2c243095673..1f1ac8110bef 100644
--- a/sound/soc/codecs/tpa6130a2.c
+++ b/sound/soc/codecs/tpa6130a2.c
@@ -29,7 +29,6 @@
29#include <linux/slab.h> 29#include <linux/slab.h>
30#include <sound/tpa6130a2-plat.h> 30#include <sound/tpa6130a2-plat.h>
31#include <sound/soc.h> 31#include <sound/soc.h>
32#include <sound/soc-dapm.h>
33#include <sound/tlv.h> 32#include <sound/tlv.h>
34 33
35#include "tpa6130a2.h" 34#include "tpa6130a2.h"
@@ -42,7 +41,7 @@ struct tpa6130a2_data {
42 unsigned char regs[TPA6130A2_CACHEREGNUM]; 41 unsigned char regs[TPA6130A2_CACHEREGNUM];
43 struct regulator *supply; 42 struct regulator *supply;
44 int power_gpio; 43 int power_gpio;
45 unsigned char power_state; 44 u8 power_state:1;
46 enum tpa_model id; 45 enum tpa_model id;
47}; 46};
48 47
@@ -117,7 +116,7 @@ static int tpa6130a2_initialize(void)
117 return ret; 116 return ret;
118} 117}
119 118
120static int tpa6130a2_power(int power) 119static int tpa6130a2_power(u8 power)
121{ 120{
122 struct tpa6130a2_data *data; 121 struct tpa6130a2_data *data;
123 u8 val; 122 u8 val;
@@ -127,17 +126,19 @@ static int tpa6130a2_power(int power)
127 data = i2c_get_clientdata(tpa6130a2_client); 126 data = i2c_get_clientdata(tpa6130a2_client);
128 127
129 mutex_lock(&data->mutex); 128 mutex_lock(&data->mutex);
130 if (power && !data->power_state) { 129 if (power == data->power_state)
131 /* Power on */ 130 goto exit;
132 if (data->power_gpio >= 0)
133 gpio_set_value(data->power_gpio, 1);
134 131
132 if (power) {
135 ret = regulator_enable(data->supply); 133 ret = regulator_enable(data->supply);
136 if (ret != 0) { 134 if (ret != 0) {
137 dev_err(&tpa6130a2_client->dev, 135 dev_err(&tpa6130a2_client->dev,
138 "Failed to enable supply: %d\n", ret); 136 "Failed to enable supply: %d\n", ret);
139 goto exit; 137 goto exit;
140 } 138 }
139 /* Power on */
140 if (data->power_gpio >= 0)
141 gpio_set_value(data->power_gpio, 1);
141 142
142 data->power_state = 1; 143 data->power_state = 1;
143 ret = tpa6130a2_initialize(); 144 ret = tpa6130a2_initialize();
@@ -150,12 +151,7 @@ static int tpa6130a2_power(int power)
150 data->power_state = 0; 151 data->power_state = 0;
151 goto exit; 152 goto exit;
152 } 153 }
153 154 } else {
154 /* Clear SWS */
155 val = tpa6130a2_read(TPA6130A2_REG_CONTROL);
156 val &= ~TPA6130A2_SWS;
157 tpa6130a2_i2c_write(TPA6130A2_REG_CONTROL, val);
158 } else if (!power && data->power_state) {
159 /* set SWS */ 155 /* set SWS */
160 val = tpa6130a2_read(TPA6130A2_REG_CONTROL); 156 val = tpa6130a2_read(TPA6130A2_REG_CONTROL);
161 val |= TPA6130A2_SWS; 157 val |= TPA6130A2_SWS;
@@ -300,6 +296,7 @@ static void tpa6130a2_channel_enable(u8 channel, int enable)
300 /* Enable amplifier */ 296 /* Enable amplifier */
301 val = tpa6130a2_read(TPA6130A2_REG_CONTROL); 297 val = tpa6130a2_read(TPA6130A2_REG_CONTROL);
302 val |= channel; 298 val |= channel;
299 val &= ~TPA6130A2_SWS;
303 tpa6130a2_i2c_write(TPA6130A2_REG_CONTROL, val); 300 tpa6130a2_i2c_write(TPA6130A2_REG_CONTROL, val);
304 301
305 /* Unmute channel */ 302 /* Unmute channel */
@@ -320,72 +317,24 @@ static void tpa6130a2_channel_enable(u8 channel, int enable)
320 } 317 }
321} 318}
322 319
323static int tpa6130a2_left_event(struct snd_soc_dapm_widget *w, 320int tpa6130a2_stereo_enable(struct snd_soc_codec *codec, int enable)
324 struct snd_kcontrol *kcontrol, int event)
325{
326 switch (event) {
327 case SND_SOC_DAPM_POST_PMU:
328 tpa6130a2_channel_enable(TPA6130A2_HP_EN_L, 1);
329 break;
330 case SND_SOC_DAPM_POST_PMD:
331 tpa6130a2_channel_enable(TPA6130A2_HP_EN_L, 0);
332 break;
333 }
334 return 0;
335}
336
337static int tpa6130a2_right_event(struct snd_soc_dapm_widget *w,
338 struct snd_kcontrol *kcontrol, int event)
339{
340 switch (event) {
341 case SND_SOC_DAPM_POST_PMU:
342 tpa6130a2_channel_enable(TPA6130A2_HP_EN_R, 1);
343 break;
344 case SND_SOC_DAPM_POST_PMD:
345 tpa6130a2_channel_enable(TPA6130A2_HP_EN_R, 0);
346 break;
347 }
348 return 0;
349}
350
351static int tpa6130a2_supply_event(struct snd_soc_dapm_widget *w,
352 struct snd_kcontrol *kcontrol, int event)
353{ 321{
354 int ret = 0; 322 int ret = 0;
355 323 if (enable) {
356 switch (event) {
357 case SND_SOC_DAPM_POST_PMU:
358 ret = tpa6130a2_power(1); 324 ret = tpa6130a2_power(1);
359 break; 325 if (ret < 0)
360 case SND_SOC_DAPM_POST_PMD: 326 return ret;
327 tpa6130a2_channel_enable(TPA6130A2_HP_EN_R | TPA6130A2_HP_EN_L,
328 1);
329 } else {
330 tpa6130a2_channel_enable(TPA6130A2_HP_EN_R | TPA6130A2_HP_EN_L,
331 0);
361 ret = tpa6130a2_power(0); 332 ret = tpa6130a2_power(0);
362 break;
363 } 333 }
334
364 return ret; 335 return ret;
365} 336}
366 337EXPORT_SYMBOL_GPL(tpa6130a2_stereo_enable);
367static const struct snd_soc_dapm_widget tpa6130a2_dapm_widgets[] = {
368 SND_SOC_DAPM_PGA_E("TPA6130A2 Left", SND_SOC_NOPM,
369 0, 0, NULL, 0, tpa6130a2_left_event,
370 SND_SOC_DAPM_POST_PMU|SND_SOC_DAPM_POST_PMD),
371 SND_SOC_DAPM_PGA_E("TPA6130A2 Right", SND_SOC_NOPM,
372 0, 0, NULL, 0, tpa6130a2_right_event,
373 SND_SOC_DAPM_POST_PMU|SND_SOC_DAPM_POST_PMD),
374 SND_SOC_DAPM_SUPPLY("TPA6130A2 Enable", SND_SOC_NOPM,
375 0, 0, tpa6130a2_supply_event,
376 SND_SOC_DAPM_POST_PMU|SND_SOC_DAPM_POST_PMD),
377 /* Outputs */
378 SND_SOC_DAPM_OUTPUT("TPA6130A2 Headphone Left"),
379 SND_SOC_DAPM_OUTPUT("TPA6130A2 Headphone Right"),
380};
381
382static const struct snd_soc_dapm_route audio_map[] = {
383 {"TPA6130A2 Headphone Left", NULL, "TPA6130A2 Left"},
384 {"TPA6130A2 Headphone Right", NULL, "TPA6130A2 Right"},
385
386 {"TPA6130A2 Headphone Left", NULL, "TPA6130A2 Enable"},
387 {"TPA6130A2 Headphone Right", NULL, "TPA6130A2 Enable"},
388};
389 338
390int tpa6130a2_add_controls(struct snd_soc_codec *codec) 339int tpa6130a2_add_controls(struct snd_soc_codec *codec)
391{ 340{
@@ -396,18 +345,12 @@ int tpa6130a2_add_controls(struct snd_soc_codec *codec)
396 345
397 data = i2c_get_clientdata(tpa6130a2_client); 346 data = i2c_get_clientdata(tpa6130a2_client);
398 347
399 snd_soc_dapm_new_controls(codec, tpa6130a2_dapm_widgets,
400 ARRAY_SIZE(tpa6130a2_dapm_widgets));
401
402 snd_soc_dapm_add_routes(codec, audio_map, ARRAY_SIZE(audio_map));
403
404 if (data->id == TPA6140A2) 348 if (data->id == TPA6140A2)
405 return snd_soc_add_controls(codec, tpa6140a2_controls, 349 return snd_soc_add_controls(codec, tpa6140a2_controls,
406 ARRAY_SIZE(tpa6140a2_controls)); 350 ARRAY_SIZE(tpa6140a2_controls));
407 else 351 else
408 return snd_soc_add_controls(codec, tpa6130a2_controls, 352 return snd_soc_add_controls(codec, tpa6130a2_controls,
409 ARRAY_SIZE(tpa6130a2_controls)); 353 ARRAY_SIZE(tpa6130a2_controls));
410
411} 354}
412EXPORT_SYMBOL_GPL(tpa6130a2_add_controls); 355EXPORT_SYMBOL_GPL(tpa6130a2_add_controls);
413 356
diff --git a/sound/soc/codecs/tpa6130a2.h b/sound/soc/codecs/tpa6130a2.h
index 57e867fd86d1..5df49c8756b2 100644
--- a/sound/soc/codecs/tpa6130a2.h
+++ b/sound/soc/codecs/tpa6130a2.h
@@ -57,5 +57,6 @@
57#define TPA6130A2_VERSION_MASK (0x0f) 57#define TPA6130A2_VERSION_MASK (0x0f)
58 58
59extern int tpa6130a2_add_controls(struct snd_soc_codec *codec); 59extern int tpa6130a2_add_controls(struct snd_soc_codec *codec);
60extern int tpa6130a2_stereo_enable(struct snd_soc_codec *codec, int enable);
60 61
61#endif /* __TPA6130A2_H__ */ 62#endif /* __TPA6130A2_H__ */
diff --git a/sound/soc/codecs/twl4030.c b/sound/soc/codecs/twl4030.c
index cbebec6ba1ba..e4d464b937d6 100644
--- a/sound/soc/codecs/twl4030.c
+++ b/sound/soc/codecs/twl4030.c
@@ -32,7 +32,6 @@
32#include <sound/pcm.h> 32#include <sound/pcm.h>
33#include <sound/pcm_params.h> 33#include <sound/pcm_params.h>
34#include <sound/soc.h> 34#include <sound/soc.h>
35#include <sound/soc-dapm.h>
36#include <sound/initval.h> 35#include <sound/initval.h>
37#include <sound/tlv.h> 36#include <sound/tlv.h>
38 37
@@ -233,6 +232,16 @@ static int twl4030_write(struct snd_soc_codec *codec,
233 return 0; 232 return 0;
234} 233}
235 234
235static inline void twl4030_wait_ms(int time)
236{
237 if (time < 60) {
238 time *= 1000;
239 usleep_range(time, time + 500);
240 } else {
241 msleep(time);
242 }
243}
244
236static void twl4030_codec_enable(struct snd_soc_codec *codec, int enable) 245static void twl4030_codec_enable(struct snd_soc_codec *codec, int enable)
237{ 246{
238 struct twl4030_priv *twl4030 = snd_soc_codec_get_drvdata(codec); 247 struct twl4030_priv *twl4030 = snd_soc_codec_get_drvdata(codec);
@@ -338,10 +347,14 @@ static void twl4030_init_chip(struct snd_soc_codec *codec)
338 twl4030_write(codec, TWL4030_REG_ANAMICL, 347 twl4030_write(codec, TWL4030_REG_ANAMICL,
339 reg | TWL4030_CNCL_OFFSET_START); 348 reg | TWL4030_CNCL_OFFSET_START);
340 349
341 /* wait for offset cancellation to complete */ 350 /*
351 * Wait for offset cancellation to complete.
352 * Since this takes a while, do not slam the i2c.
353 * Start polling the status after ~20ms.
354 */
355 msleep(20);
342 do { 356 do {
343 /* this takes a little while, so don't slam i2c */ 357 usleep_range(1000, 2000);
344 udelay(2000);
345 twl_i2c_read_u8(TWL4030_MODULE_AUDIO_VOICE, &byte, 358 twl_i2c_read_u8(TWL4030_MODULE_AUDIO_VOICE, &byte,
346 TWL4030_REG_ANAMICL); 359 TWL4030_REG_ANAMICL);
347 } while ((i++ < 100) && 360 } while ((i++ < 100) &&
@@ -725,9 +738,12 @@ static void headset_ramp(struct snd_soc_codec *codec, int ramp)
725 /* Base values for ramp delay calculation: 2^19 - 2^26 */ 738 /* Base values for ramp delay calculation: 2^19 - 2^26 */
726 unsigned int ramp_base[] = {524288, 1048576, 2097152, 4194304, 739 unsigned int ramp_base[] = {524288, 1048576, 2097152, 4194304,
727 8388608, 16777216, 33554432, 67108864}; 740 8388608, 16777216, 33554432, 67108864};
741 unsigned int delay;
728 742
729 hs_gain = twl4030_read_reg_cache(codec, TWL4030_REG_HS_GAIN_SET); 743 hs_gain = twl4030_read_reg_cache(codec, TWL4030_REG_HS_GAIN_SET);
730 hs_pop = twl4030_read_reg_cache(codec, TWL4030_REG_HS_POPN_SET); 744 hs_pop = twl4030_read_reg_cache(codec, TWL4030_REG_HS_POPN_SET);
745 delay = (ramp_base[(hs_pop & TWL4030_RAMP_DELAY) >> 2] /
746 twl4030->sysclk) + 1;
731 747
732 /* Enable external mute control, this dramatically reduces 748 /* Enable external mute control, this dramatically reduces
733 * the pop-noise */ 749 * the pop-noise */
@@ -751,16 +767,14 @@ static void headset_ramp(struct snd_soc_codec *codec, int ramp)
751 hs_pop |= TWL4030_RAMP_EN; 767 hs_pop |= TWL4030_RAMP_EN;
752 twl4030_write(codec, TWL4030_REG_HS_POPN_SET, hs_pop); 768 twl4030_write(codec, TWL4030_REG_HS_POPN_SET, hs_pop);
753 /* Wait ramp delay time + 1, so the VMID can settle */ 769 /* Wait ramp delay time + 1, so the VMID can settle */
754 mdelay((ramp_base[(hs_pop & TWL4030_RAMP_DELAY) >> 2] / 770 twl4030_wait_ms(delay);
755 twl4030->sysclk) + 1);
756 } else { 771 } else {
757 /* Headset ramp-down _not_ according to 772 /* Headset ramp-down _not_ according to
758 * the TRM, but in a way that it is working */ 773 * the TRM, but in a way that it is working */
759 hs_pop &= ~TWL4030_RAMP_EN; 774 hs_pop &= ~TWL4030_RAMP_EN;
760 twl4030_write(codec, TWL4030_REG_HS_POPN_SET, hs_pop); 775 twl4030_write(codec, TWL4030_REG_HS_POPN_SET, hs_pop);
761 /* Wait ramp delay time + 1, so the VMID can settle */ 776 /* Wait ramp delay time + 1, so the VMID can settle */
762 mdelay((ramp_base[(hs_pop & TWL4030_RAMP_DELAY) >> 2] / 777 twl4030_wait_ms(delay);
763 twl4030->sysclk) + 1);
764 /* Bypass the reg_cache to mute the headset */ 778 /* Bypass the reg_cache to mute the headset */
765 twl_i2c_write_u8(TWL4030_MODULE_AUDIO_VOICE, 779 twl_i2c_write_u8(TWL4030_MODULE_AUDIO_VOICE,
766 hs_gain & (~0x0f), 780 hs_gain & (~0x0f),
@@ -835,7 +849,7 @@ static int digimic_event(struct snd_soc_dapm_widget *w,
835 struct twl4030_priv *twl4030 = snd_soc_codec_get_drvdata(w->codec); 849 struct twl4030_priv *twl4030 = snd_soc_codec_get_drvdata(w->codec);
836 850
837 if (twl4030->digimic_delay) 851 if (twl4030->digimic_delay)
838 mdelay(twl4030->digimic_delay); 852 twl4030_wait_ms(twl4030->digimic_delay);
839 return 0; 853 return 0;
840} 854}
841 855
@@ -1621,10 +1635,11 @@ static const struct snd_soc_dapm_route intercon[] = {
1621 1635
1622static int twl4030_add_widgets(struct snd_soc_codec *codec) 1636static int twl4030_add_widgets(struct snd_soc_codec *codec)
1623{ 1637{
1624 snd_soc_dapm_new_controls(codec, twl4030_dapm_widgets, 1638 struct snd_soc_dapm_context *dapm = &codec->dapm;
1625 ARRAY_SIZE(twl4030_dapm_widgets));
1626 1639
1627 snd_soc_dapm_add_routes(codec, intercon, ARRAY_SIZE(intercon)); 1640 snd_soc_dapm_new_controls(dapm, twl4030_dapm_widgets,
1641 ARRAY_SIZE(twl4030_dapm_widgets));
1642 snd_soc_dapm_add_routes(dapm, intercon, ARRAY_SIZE(intercon));
1628 1643
1629 return 0; 1644 return 0;
1630} 1645}
@@ -1638,14 +1653,14 @@ static int twl4030_set_bias_level(struct snd_soc_codec *codec,
1638 case SND_SOC_BIAS_PREPARE: 1653 case SND_SOC_BIAS_PREPARE:
1639 break; 1654 break;
1640 case SND_SOC_BIAS_STANDBY: 1655 case SND_SOC_BIAS_STANDBY:
1641 if (codec->bias_level == SND_SOC_BIAS_OFF) 1656 if (codec->dapm.bias_level == SND_SOC_BIAS_OFF)
1642 twl4030_codec_enable(codec, 1); 1657 twl4030_codec_enable(codec, 1);
1643 break; 1658 break;
1644 case SND_SOC_BIAS_OFF: 1659 case SND_SOC_BIAS_OFF:
1645 twl4030_codec_enable(codec, 0); 1660 twl4030_codec_enable(codec, 0);
1646 break; 1661 break;
1647 } 1662 }
1648 codec->bias_level = level; 1663 codec->dapm.bias_level = level;
1649 1664
1650 return 0; 1665 return 0;
1651} 1666}
@@ -1709,6 +1724,7 @@ static int twl4030_startup(struct snd_pcm_substream *substream,
1709 struct snd_soc_codec *codec = rtd->codec; 1724 struct snd_soc_codec *codec = rtd->codec;
1710 struct twl4030_priv *twl4030 = snd_soc_codec_get_drvdata(codec); 1725 struct twl4030_priv *twl4030 = snd_soc_codec_get_drvdata(codec);
1711 1726
1727 snd_pcm_hw_constraint_msbits(substream->runtime, 0, 32, 24);
1712 if (twl4030->master_substream) { 1728 if (twl4030->master_substream) {
1713 twl4030->slave_substream = substream; 1729 twl4030->slave_substream = substream;
1714 /* The DAI has one configuration for playback and capture, so 1730 /* The DAI has one configuration for playback and capture, so
@@ -1833,7 +1849,7 @@ static int twl4030_hw_params(struct snd_pcm_substream *substream,
1833 case SNDRV_PCM_FORMAT_S16_LE: 1849 case SNDRV_PCM_FORMAT_S16_LE:
1834 format |= TWL4030_DATA_WIDTH_16S_16W; 1850 format |= TWL4030_DATA_WIDTH_16S_16W;
1835 break; 1851 break;
1836 case SNDRV_PCM_FORMAT_S24_LE: 1852 case SNDRV_PCM_FORMAT_S32_LE:
1837 format |= TWL4030_DATA_WIDTH_32S_24W; 1853 format |= TWL4030_DATA_WIDTH_32S_24W;
1838 break; 1854 break;
1839 default: 1855 default:
@@ -2166,7 +2182,7 @@ static int twl4030_voice_set_tristate(struct snd_soc_dai *dai, int tristate)
2166} 2182}
2167 2183
2168#define TWL4030_RATES (SNDRV_PCM_RATE_8000_48000) 2184#define TWL4030_RATES (SNDRV_PCM_RATE_8000_48000)
2169#define TWL4030_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FORMAT_S24_LE) 2185#define TWL4030_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S32_LE)
2170 2186
2171static struct snd_soc_dai_ops twl4030_dai_hifi_ops = { 2187static struct snd_soc_dai_ops twl4030_dai_hifi_ops = {
2172 .startup = twl4030_startup, 2188 .startup = twl4030_startup,
@@ -2245,7 +2261,7 @@ static int twl4030_soc_probe(struct snd_soc_codec *codec)
2245 snd_soc_codec_set_drvdata(codec, twl4030); 2261 snd_soc_codec_set_drvdata(codec, twl4030);
2246 /* Set the defaults, and power up the codec */ 2262 /* Set the defaults, and power up the codec */
2247 twl4030->sysclk = twl4030_codec_get_mclk() / 1000; 2263 twl4030->sysclk = twl4030_codec_get_mclk() / 1000;
2248 codec->idle_bias_off = 1; 2264 codec->dapm.idle_bias_off = 1;
2249 2265
2250 twl4030_init_chip(codec); 2266 twl4030_init_chip(codec);
2251 2267
@@ -2257,9 +2273,12 @@ static int twl4030_soc_probe(struct snd_soc_codec *codec)
2257 2273
2258static int twl4030_soc_remove(struct snd_soc_codec *codec) 2274static int twl4030_soc_remove(struct snd_soc_codec *codec)
2259{ 2275{
2276 struct twl4030_priv *twl4030 = snd_soc_codec_get_drvdata(codec);
2277
2260 /* Reset registers to their chip default before leaving */ 2278 /* Reset registers to their chip default before leaving */
2261 twl4030_reset_registers(codec); 2279 twl4030_reset_registers(codec);
2262 twl4030_set_bias_level(codec, SND_SOC_BIAS_OFF); 2280 twl4030_set_bias_level(codec, SND_SOC_BIAS_OFF);
2281 kfree(twl4030);
2263 return 0; 2282 return 0;
2264} 2283}
2265 2284
@@ -2291,10 +2310,7 @@ static int __devinit twl4030_codec_probe(struct platform_device *pdev)
2291 2310
2292static int __devexit twl4030_codec_remove(struct platform_device *pdev) 2311static int __devexit twl4030_codec_remove(struct platform_device *pdev)
2293{ 2312{
2294 struct twl4030_priv *twl4030 = dev_get_drvdata(&pdev->dev);
2295
2296 snd_soc_unregister_codec(&pdev->dev); 2313 snd_soc_unregister_codec(&pdev->dev);
2297 kfree(twl4030);
2298 return 0; 2314 return 0;
2299} 2315}
2300 2316
diff --git a/sound/soc/codecs/twl6040.c b/sound/soc/codecs/twl6040.c
index 10f6e5214511..4bbf1b15a493 100644
--- a/sound/soc/codecs/twl6040.c
+++ b/sound/soc/codecs/twl6040.c
@@ -34,14 +34,46 @@
34#include <sound/pcm.h> 34#include <sound/pcm.h>
35#include <sound/pcm_params.h> 35#include <sound/pcm_params.h>
36#include <sound/soc.h> 36#include <sound/soc.h>
37#include <sound/soc-dapm.h>
38#include <sound/initval.h> 37#include <sound/initval.h>
39#include <sound/tlv.h> 38#include <sound/tlv.h>
40 39
41#include "twl6040.h" 40#include "twl6040.h"
42 41
43#define TWL6040_RATES (SNDRV_PCM_RATE_88200 | SNDRV_PCM_RATE_96000) 42#define TWL6040_RATES SNDRV_PCM_RATE_8000_96000
44#define TWL6040_FORMATS (SNDRV_PCM_FMTBIT_S32_LE) 43#define TWL6040_FORMATS (SNDRV_PCM_FMTBIT_S32_LE)
44
45#define TWL6040_OUTHS_0dB 0x00
46#define TWL6040_OUTHS_M30dB 0x0F
47#define TWL6040_OUTHF_0dB 0x03
48#define TWL6040_OUTHF_M52dB 0x1D
49
50#define TWL6040_RAMP_NONE 0
51#define TWL6040_RAMP_UP 1
52#define TWL6040_RAMP_DOWN 2
53
54#define TWL6040_HSL_VOL_MASK 0x0F
55#define TWL6040_HSL_VOL_SHIFT 0
56#define TWL6040_HSR_VOL_MASK 0xF0
57#define TWL6040_HSR_VOL_SHIFT 4
58#define TWL6040_HF_VOL_MASK 0x1F
59#define TWL6040_HF_VOL_SHIFT 0
60
61struct twl6040_output {
62 u16 active;
63 u16 left_vol;
64 u16 right_vol;
65 u16 left_step;
66 u16 right_step;
67 unsigned int step_delay;
68 u16 ramp;
69 u16 mute;
70 struct completion ramp_done;
71};
72
73struct twl6040_jack_data {
74 struct snd_soc_jack *jack;
75 int report;
76};
45 77
46/* codec private data */ 78/* codec private data */
47struct twl6040_data { 79struct twl6040_data {
@@ -53,6 +85,17 @@ struct twl6040_data {
53 unsigned int sysclk; 85 unsigned int sysclk;
54 struct snd_pcm_hw_constraint_list *sysclk_constraints; 86 struct snd_pcm_hw_constraint_list *sysclk_constraints;
55 struct completion ready; 87 struct completion ready;
88 struct twl6040_jack_data hs_jack;
89 struct snd_soc_codec *codec;
90 struct workqueue_struct *workqueue;
91 struct delayed_work delayed_work;
92 struct mutex mutex;
93 struct twl6040_output headset;
94 struct twl6040_output handsfree;
95 struct workqueue_struct *hf_workqueue;
96 struct workqueue_struct *hs_workqueue;
97 struct delayed_work hs_delayed_work;
98 struct delayed_work hf_delayed_work;
56}; 99};
57 100
58/* 101/*
@@ -201,7 +244,7 @@ static int twl6040_read_reg_volatile(struct snd_soc_codec *codec,
201 if (reg >= TWL6040_CACHEREGNUM) 244 if (reg >= TWL6040_CACHEREGNUM)
202 return -EIO; 245 return -EIO;
203 246
204 twl_i2c_read_u8(TWL4030_MODULE_AUDIO_VOICE, &value, reg); 247 twl_i2c_read_u8(TWL_MODULE_AUDIO_VOICE, &value, reg);
205 twl6040_write_reg_cache(codec, reg, value); 248 twl6040_write_reg_cache(codec, reg, value);
206 249
207 return value; 250 return value;
@@ -217,7 +260,7 @@ static int twl6040_write(struct snd_soc_codec *codec,
217 return -EIO; 260 return -EIO;
218 261
219 twl6040_write_reg_cache(codec, reg, value); 262 twl6040_write_reg_cache(codec, reg, value);
220 return twl_i2c_write_u8(TWL4030_MODULE_AUDIO_VOICE, value, reg); 263 return twl_i2c_write_u8(TWL_MODULE_AUDIO_VOICE, value, reg);
221} 264}
222 265
223static void twl6040_init_vio_regs(struct snd_soc_codec *codec) 266static void twl6040_init_vio_regs(struct snd_soc_codec *codec)
@@ -254,6 +297,305 @@ static void twl6040_init_vdd_regs(struct snd_soc_codec *codec)
254 } 297 }
255} 298}
256 299
300/*
301 * Ramp HS PGA volume to minimise pops at stream startup and shutdown.
302 */
303static inline int twl6040_hs_ramp_step(struct snd_soc_codec *codec,
304 unsigned int left_step, unsigned int right_step)
305{
306
307 struct twl6040_data *priv = snd_soc_codec_get_drvdata(codec);
308 struct twl6040_output *headset = &priv->headset;
309 int left_complete = 0, right_complete = 0;
310 u8 reg, val;
311
312 /* left channel */
313 left_step = (left_step > 0xF) ? 0xF : left_step;
314 reg = twl6040_read_reg_cache(codec, TWL6040_REG_HSGAIN);
315 val = (~reg & TWL6040_HSL_VOL_MASK);
316
317 if (headset->ramp == TWL6040_RAMP_UP) {
318 /* ramp step up */
319 if (val < headset->left_vol) {
320 val += left_step;
321 reg &= ~TWL6040_HSL_VOL_MASK;
322 twl6040_write(codec, TWL6040_REG_HSGAIN,
323 (reg | (~val & TWL6040_HSL_VOL_MASK)));
324 } else {
325 left_complete = 1;
326 }
327 } else if (headset->ramp == TWL6040_RAMP_DOWN) {
328 /* ramp step down */
329 if (val > 0x0) {
330 val -= left_step;
331 reg &= ~TWL6040_HSL_VOL_MASK;
332 twl6040_write(codec, TWL6040_REG_HSGAIN, reg |
333 (~val & TWL6040_HSL_VOL_MASK));
334 } else {
335 left_complete = 1;
336 }
337 }
338
339 /* right channel */
340 right_step = (right_step > 0xF) ? 0xF : right_step;
341 reg = twl6040_read_reg_cache(codec, TWL6040_REG_HSGAIN);
342 val = (~reg & TWL6040_HSR_VOL_MASK) >> TWL6040_HSR_VOL_SHIFT;
343
344 if (headset->ramp == TWL6040_RAMP_UP) {
345 /* ramp step up */
346 if (val < headset->right_vol) {
347 val += right_step;
348 reg &= ~TWL6040_HSR_VOL_MASK;
349 twl6040_write(codec, TWL6040_REG_HSGAIN,
350 (reg | (~val << TWL6040_HSR_VOL_SHIFT)));
351 } else {
352 right_complete = 1;
353 }
354 } else if (headset->ramp == TWL6040_RAMP_DOWN) {
355 /* ramp step down */
356 if (val > 0x0) {
357 val -= right_step;
358 reg &= ~TWL6040_HSR_VOL_MASK;
359 twl6040_write(codec, TWL6040_REG_HSGAIN,
360 reg | (~val << TWL6040_HSR_VOL_SHIFT));
361 } else {
362 right_complete = 1;
363 }
364 }
365
366 return left_complete & right_complete;
367}
368
369/*
370 * Ramp HF PGA volume to minimise pops at stream startup and shutdown.
371 */
372static inline int twl6040_hf_ramp_step(struct snd_soc_codec *codec,
373 unsigned int left_step, unsigned int right_step)
374{
375 struct twl6040_data *priv = snd_soc_codec_get_drvdata(codec);
376 struct twl6040_output *handsfree = &priv->handsfree;
377 int left_complete = 0, right_complete = 0;
378 u16 reg, val;
379
380 /* left channel */
381 left_step = (left_step > 0x1D) ? 0x1D : left_step;
382 reg = twl6040_read_reg_cache(codec, TWL6040_REG_HFLGAIN);
383 reg = 0x1D - reg;
384 val = (reg & TWL6040_HF_VOL_MASK);
385 if (handsfree->ramp == TWL6040_RAMP_UP) {
386 /* ramp step up */
387 if (val < handsfree->left_vol) {
388 val += left_step;
389 reg &= ~TWL6040_HF_VOL_MASK;
390 twl6040_write(codec, TWL6040_REG_HFLGAIN,
391 reg | (0x1D - val));
392 } else {
393 left_complete = 1;
394 }
395 } else if (handsfree->ramp == TWL6040_RAMP_DOWN) {
396 /* ramp step down */
397 if (val > 0) {
398 val -= left_step;
399 reg &= ~TWL6040_HF_VOL_MASK;
400 twl6040_write(codec, TWL6040_REG_HFLGAIN,
401 reg | (0x1D - val));
402 } else {
403 left_complete = 1;
404 }
405 }
406
407 /* right channel */
408 right_step = (right_step > 0x1D) ? 0x1D : right_step;
409 reg = twl6040_read_reg_cache(codec, TWL6040_REG_HFRGAIN);
410 reg = 0x1D - reg;
411 val = (reg & TWL6040_HF_VOL_MASK);
412 if (handsfree->ramp == TWL6040_RAMP_UP) {
413 /* ramp step up */
414 if (val < handsfree->right_vol) {
415 val += right_step;
416 reg &= ~TWL6040_HF_VOL_MASK;
417 twl6040_write(codec, TWL6040_REG_HFRGAIN,
418 reg | (0x1D - val));
419 } else {
420 right_complete = 1;
421 }
422 } else if (handsfree->ramp == TWL6040_RAMP_DOWN) {
423 /* ramp step down */
424 if (val > 0) {
425 val -= right_step;
426 reg &= ~TWL6040_HF_VOL_MASK;
427 twl6040_write(codec, TWL6040_REG_HFRGAIN,
428 reg | (0x1D - val));
429 }
430 }
431
432 return left_complete & right_complete;
433}
434
435/*
436 * This work ramps both output PGAs at stream start/stop time to
437 * minimise pop associated with DAPM power switching.
438 */
439static void twl6040_pga_hs_work(struct work_struct *work)
440{
441 struct twl6040_data *priv =
442 container_of(work, struct twl6040_data, hs_delayed_work.work);
443 struct snd_soc_codec *codec = priv->codec;
444 struct twl6040_output *headset = &priv->headset;
445 unsigned int delay = headset->step_delay;
446 int i, headset_complete;
447
448 /* do we need to ramp at all ? */
449 if (headset->ramp == TWL6040_RAMP_NONE)
450 return;
451
452 /* HS PGA volumes have 4 bits of resolution to ramp */
453 for (i = 0; i <= 16; i++) {
454 headset_complete = 1;
455 if (headset->ramp != TWL6040_RAMP_NONE)
456 headset_complete = twl6040_hs_ramp_step(codec,
457 headset->left_step,
458 headset->right_step);
459
460 /* ramp finished ? */
461 if (headset_complete)
462 break;
463
464 /*
465 * TODO: tune: delay is longer over 0dB
466 * as increases are larger.
467 */
468 if (i >= 8)
469 schedule_timeout_interruptible(msecs_to_jiffies(delay +
470 (delay >> 1)));
471 else
472 schedule_timeout_interruptible(msecs_to_jiffies(delay));
473 }
474
475 if (headset->ramp == TWL6040_RAMP_DOWN) {
476 headset->active = 0;
477 complete(&headset->ramp_done);
478 } else {
479 headset->active = 1;
480 }
481 headset->ramp = TWL6040_RAMP_NONE;
482}
483
484static void twl6040_pga_hf_work(struct work_struct *work)
485{
486 struct twl6040_data *priv =
487 container_of(work, struct twl6040_data, hf_delayed_work.work);
488 struct snd_soc_codec *codec = priv->codec;
489 struct twl6040_output *handsfree = &priv->handsfree;
490 unsigned int delay = handsfree->step_delay;
491 int i, handsfree_complete;
492
493 /* do we need to ramp at all ? */
494 if (handsfree->ramp == TWL6040_RAMP_NONE)
495 return;
496
497 /* HF PGA volumes have 5 bits of resolution to ramp */
498 for (i = 0; i <= 32; i++) {
499 handsfree_complete = 1;
500 if (handsfree->ramp != TWL6040_RAMP_NONE)
501 handsfree_complete = twl6040_hf_ramp_step(codec,
502 handsfree->left_step,
503 handsfree->right_step);
504
505 /* ramp finished ? */
506 if (handsfree_complete)
507 break;
508
509 /*
510 * TODO: tune: delay is longer over 0dB
511 * as increases are larger.
512 */
513 if (i >= 16)
514 schedule_timeout_interruptible(msecs_to_jiffies(delay +
515 (delay >> 1)));
516 else
517 schedule_timeout_interruptible(msecs_to_jiffies(delay));
518 }
519
520
521 if (handsfree->ramp == TWL6040_RAMP_DOWN) {
522 handsfree->active = 0;
523 complete(&handsfree->ramp_done);
524 } else
525 handsfree->active = 1;
526 handsfree->ramp = TWL6040_RAMP_NONE;
527}
528
529static int pga_event(struct snd_soc_dapm_widget *w,
530 struct snd_kcontrol *kcontrol, int event)
531{
532 struct snd_soc_codec *codec = w->codec;
533 struct twl6040_data *priv = snd_soc_codec_get_drvdata(codec);
534 struct twl6040_output *out;
535 struct delayed_work *work;
536 struct workqueue_struct *queue;
537
538 switch (w->shift) {
539 case 2:
540 case 3:
541 out = &priv->headset;
542 work = &priv->hs_delayed_work;
543 queue = priv->hs_workqueue;
544 out->step_delay = 5; /* 5 ms between volume ramp steps */
545 break;
546 case 4:
547 out = &priv->handsfree;
548 work = &priv->hf_delayed_work;
549 queue = priv->hf_workqueue;
550 out->step_delay = 5; /* 5 ms between volume ramp steps */
551 if (SND_SOC_DAPM_EVENT_ON(event))
552 priv->non_lp++;
553 else
554 priv->non_lp--;
555 break;
556 default:
557 return -1;
558 }
559
560 switch (event) {
561 case SND_SOC_DAPM_POST_PMU:
562 if (out->active)
563 break;
564
565 /* don't use volume ramp for power-up */
566 out->left_step = out->left_vol;
567 out->right_step = out->right_vol;
568
569 if (!delayed_work_pending(work)) {
570 out->ramp = TWL6040_RAMP_UP;
571 queue_delayed_work(queue, work,
572 msecs_to_jiffies(1));
573 }
574 break;
575
576 case SND_SOC_DAPM_PRE_PMD:
577 if (!out->active)
578 break;
579
580 if (!delayed_work_pending(work)) {
581 /* use volume ramp for power-down */
582 out->left_step = 1;
583 out->right_step = 1;
584 out->ramp = TWL6040_RAMP_DOWN;
585 INIT_COMPLETION(out->ramp_done);
586
587 queue_delayed_work(queue, work,
588 msecs_to_jiffies(1));
589
590 wait_for_completion_timeout(&out->ramp_done,
591 msecs_to_jiffies(2000));
592 }
593 break;
594 }
595
596 return 0;
597}
598
257/* twl6040 codec manual power-up sequence */ 599/* twl6040 codec manual power-up sequence */
258static void twl6040_power_up(struct snd_soc_codec *codec) 600static void twl6040_power_up(struct snd_soc_codec *codec)
259{ 601{
@@ -382,6 +724,47 @@ static int twl6040_power_mode_event(struct snd_soc_dapm_widget *w,
382 return 0; 724 return 0;
383} 725}
384 726
727void twl6040_hs_jack_report(struct snd_soc_codec *codec,
728 struct snd_soc_jack *jack, int report)
729{
730 struct twl6040_data *priv = snd_soc_codec_get_drvdata(codec);
731 int status;
732
733 mutex_lock(&priv->mutex);
734
735 /* Sync status */
736 status = twl6040_read_reg_volatile(codec, TWL6040_REG_STATUS);
737 if (status & TWL6040_PLUGCOMP)
738 snd_soc_jack_report(jack, report, report);
739 else
740 snd_soc_jack_report(jack, 0, report);
741
742 mutex_unlock(&priv->mutex);
743}
744
745void twl6040_hs_jack_detect(struct snd_soc_codec *codec,
746 struct snd_soc_jack *jack, int report)
747{
748 struct twl6040_data *priv = snd_soc_codec_get_drvdata(codec);
749 struct twl6040_jack_data *hs_jack = &priv->hs_jack;
750
751 hs_jack->jack = jack;
752 hs_jack->report = report;
753
754 twl6040_hs_jack_report(codec, hs_jack->jack, hs_jack->report);
755}
756EXPORT_SYMBOL_GPL(twl6040_hs_jack_detect);
757
758static void twl6040_accessory_work(struct work_struct *work)
759{
760 struct twl6040_data *priv = container_of(work,
761 struct twl6040_data, delayed_work.work);
762 struct snd_soc_codec *codec = priv->codec;
763 struct twl6040_jack_data *hs_jack = &priv->hs_jack;
764
765 twl6040_hs_jack_report(codec, hs_jack->jack, hs_jack->report);
766}
767
385/* audio interrupt handler */ 768/* audio interrupt handler */
386static irqreturn_t twl6040_naudint_handler(int irq, void *data) 769static irqreturn_t twl6040_naudint_handler(int irq, void *data)
387{ 770{
@@ -389,33 +772,180 @@ static irqreturn_t twl6040_naudint_handler(int irq, void *data)
389 struct twl6040_data *priv = snd_soc_codec_get_drvdata(codec); 772 struct twl6040_data *priv = snd_soc_codec_get_drvdata(codec);
390 u8 intid; 773 u8 intid;
391 774
392 twl_i2c_read_u8(TWL4030_MODULE_AUDIO_VOICE, &intid, TWL6040_REG_INTID); 775 twl_i2c_read_u8(TWL_MODULE_AUDIO_VOICE, &intid, TWL6040_REG_INTID);
393 776
394 switch (intid) { 777 if (intid & TWL6040_THINT)
395 case TWL6040_THINT:
396 dev_alert(codec->dev, "die temp over-limit detection\n"); 778 dev_alert(codec->dev, "die temp over-limit detection\n");
779
780 if ((intid & TWL6040_PLUGINT) || (intid & TWL6040_UNPLUGINT))
781 queue_delayed_work(priv->workqueue, &priv->delayed_work,
782 msecs_to_jiffies(200));
783
784 if (intid & TWL6040_HOOKINT)
785 dev_info(codec->dev, "hook detection\n");
786
787 if (intid & TWL6040_HFINT)
788 dev_alert(codec->dev, "hf drivers over current detection\n");
789
790 if (intid & TWL6040_VIBINT)
791 dev_alert(codec->dev, "vib drivers over current detection\n");
792
793 if (intid & TWL6040_READYINT)
794 complete(&priv->ready);
795
796 return IRQ_HANDLED;
797}
798
799static int twl6040_put_volsw(struct snd_kcontrol *kcontrol,
800 struct snd_ctl_elem_value *ucontrol)
801{
802 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
803 struct twl6040_data *twl6040_priv = snd_soc_codec_get_drvdata(codec);
804 struct twl6040_output *out = NULL;
805 struct soc_mixer_control *mc =
806 (struct soc_mixer_control *)kcontrol->private_value;
807 int ret;
808 unsigned int reg = mc->reg;
809
810 /* For HS and HF we shadow the values and only actually write
811 * them out when active in order to ensure the amplifier comes on
812 * as quietly as possible. */
813 switch (reg) {
814 case TWL6040_REG_HSGAIN:
815 out = &twl6040_priv->headset;
397 break; 816 break;
398 case TWL6040_PLUGINT: 817 default:
399 case TWL6040_UNPLUGINT:
400 case TWL6040_HOOKINT:
401 break; 818 break;
402 case TWL6040_HFINT: 819 }
403 dev_alert(codec->dev, "hf drivers over current detection\n"); 820
821 if (out) {
822 out->left_vol = ucontrol->value.integer.value[0];
823 out->right_vol = ucontrol->value.integer.value[1];
824 if (!out->active)
825 return 1;
826 }
827
828 ret = snd_soc_put_volsw(kcontrol, ucontrol);
829 if (ret < 0)
830 return ret;
831
832 return 1;
833}
834
835static int twl6040_get_volsw(struct snd_kcontrol *kcontrol,
836 struct snd_ctl_elem_value *ucontrol)
837{
838 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
839 struct twl6040_data *twl6040_priv = snd_soc_codec_get_drvdata(codec);
840 struct twl6040_output *out = &twl6040_priv->headset;
841 struct soc_mixer_control *mc =
842 (struct soc_mixer_control *)kcontrol->private_value;
843 unsigned int reg = mc->reg;
844
845 switch (reg) {
846 case TWL6040_REG_HSGAIN:
847 out = &twl6040_priv->headset;
848 ucontrol->value.integer.value[0] = out->left_vol;
849 ucontrol->value.integer.value[1] = out->right_vol;
850 return 0;
851
852 default:
404 break; 853 break;
405 case TWL6040_VIBINT: 854 }
406 dev_alert(codec->dev, "vib drivers over current detection\n"); 855
856 return snd_soc_get_volsw(kcontrol, ucontrol);
857}
858
859static int twl6040_put_volsw_2r_vu(struct snd_kcontrol *kcontrol,
860 struct snd_ctl_elem_value *ucontrol)
861{
862 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
863 struct twl6040_data *twl6040_priv = snd_soc_codec_get_drvdata(codec);
864 struct twl6040_output *out = NULL;
865 struct soc_mixer_control *mc =
866 (struct soc_mixer_control *)kcontrol->private_value;
867 int ret;
868 unsigned int reg = mc->reg;
869
870 /* For HS and HF we shadow the values and only actually write
871 * them out when active in order to ensure the amplifier comes on
872 * as quietly as possible. */
873 switch (reg) {
874 case TWL6040_REG_HFLGAIN:
875 case TWL6040_REG_HFRGAIN:
876 out = &twl6040_priv->handsfree;
407 break; 877 break;
408 case TWL6040_READYINT: 878 default:
409 complete(&priv->ready);
410 break; 879 break;
880 }
881
882 if (out) {
883 out->left_vol = ucontrol->value.integer.value[0];
884 out->right_vol = ucontrol->value.integer.value[1];
885 if (!out->active)
886 return 1;
887 }
888
889 ret = snd_soc_put_volsw_2r(kcontrol, ucontrol);
890 if (ret < 0)
891 return ret;
892
893 return 1;
894}
895
896static int twl6040_get_volsw_2r(struct snd_kcontrol *kcontrol,
897 struct snd_ctl_elem_value *ucontrol)
898{
899 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
900 struct twl6040_data *twl6040_priv = snd_soc_codec_get_drvdata(codec);
901 struct twl6040_output *out = &twl6040_priv->handsfree;
902 struct soc_mixer_control *mc =
903 (struct soc_mixer_control *)kcontrol->private_value;
904 unsigned int reg = mc->reg;
905
906 /* If these are cached registers use the cache */
907 switch (reg) {
908 case TWL6040_REG_HFLGAIN:
909 case TWL6040_REG_HFRGAIN:
910 out = &twl6040_priv->handsfree;
911 ucontrol->value.integer.value[0] = out->left_vol;
912 ucontrol->value.integer.value[1] = out->right_vol;
913 return 0;
914
411 default: 915 default:
412 dev_err(codec->dev, "unknown audio interrupt %d\n", intid);
413 break; 916 break;
414 } 917 }
415 918
416 return IRQ_HANDLED; 919 return snd_soc_get_volsw_2r(kcontrol, ucontrol);
417} 920}
418 921
922/* double control with volume update */
923#define SOC_TWL6040_DOUBLE_TLV(xname, xreg, shift_left, shift_right, xmax,\
924 xinvert, tlv_array)\
925{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname),\
926 .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ |\
927 SNDRV_CTL_ELEM_ACCESS_READWRITE,\
928 .tlv.p = (tlv_array), \
929 .info = snd_soc_info_volsw, .get = twl6040_get_volsw, \
930 .put = twl6040_put_volsw, \
931 .private_value = (unsigned long)&(struct soc_mixer_control) \
932 {.reg = xreg, .shift = shift_left, .rshift = shift_right,\
933 .max = xmax, .platform_max = xmax, .invert = xinvert} }
934
935/* double control with volume update */
936#define SOC_TWL6040_DOUBLE_R_TLV(xname, reg_left, reg_right, xshift, xmax,\
937 xinvert, tlv_array)\
938{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname),\
939 .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
940 SNDRV_CTL_ELEM_ACCESS_READWRITE | \
941 SNDRV_CTL_ELEM_ACCESS_VOLATILE, \
942 .tlv.p = (tlv_array), \
943 .info = snd_soc_info_volsw_2r, \
944 .get = twl6040_get_volsw_2r, .put = twl6040_put_volsw_2r_vu, \
945 .private_value = (unsigned long)&(struct soc_mixer_control) \
946 {.reg = reg_left, .rreg = reg_right, .shift = xshift, \
947 .rshift = xshift, .max = xmax, .invert = xinvert}, }
948
419/* 949/*
420 * MICATT volume control: 950 * MICATT volume control:
421 * from -6 to 0 dB in 6 dB steps 951 * from -6 to 0 dB in 6 dB steps
@@ -424,9 +954,15 @@ static DECLARE_TLV_DB_SCALE(mic_preamp_tlv, -600, 600, 0);
424 954
425/* 955/*
426 * MICGAIN volume control: 956 * MICGAIN volume control:
427 * from 6 to 30 dB in 6 dB steps 957 * from -6 to 30 dB in 6 dB steps
428 */ 958 */
429static DECLARE_TLV_DB_SCALE(mic_amp_tlv, 600, 600, 0); 959static DECLARE_TLV_DB_SCALE(mic_amp_tlv, -600, 600, 0);
960
961/*
962 * AFMGAIN volume control:
963 * from 18 to 24 dB in 6 dB steps
964 */
965static DECLARE_TLV_DB_SCALE(afm_amp_tlv, 1800, 600, 0);
430 966
431/* 967/*
432 * HSGAIN volume control: 968 * HSGAIN volume control:
@@ -455,8 +991,30 @@ static const char *twl6040_amicr_texts[] =
455 {"Headset Mic", "Sub Mic", "Aux/FM Right", "Off"}; 991 {"Headset Mic", "Sub Mic", "Aux/FM Right", "Off"};
456 992
457static const struct soc_enum twl6040_enum[] = { 993static const struct soc_enum twl6040_enum[] = {
458 SOC_ENUM_SINGLE(TWL6040_REG_MICLCTL, 3, 3, twl6040_amicl_texts), 994 SOC_ENUM_SINGLE(TWL6040_REG_MICLCTL, 3, 4, twl6040_amicl_texts),
459 SOC_ENUM_SINGLE(TWL6040_REG_MICRCTL, 3, 3, twl6040_amicr_texts), 995 SOC_ENUM_SINGLE(TWL6040_REG_MICRCTL, 3, 4, twl6040_amicr_texts),
996};
997
998static const char *twl6040_hs_texts[] = {
999 "Off", "HS DAC", "Line-In amp"
1000};
1001
1002static const struct soc_enum twl6040_hs_enum[] = {
1003 SOC_ENUM_SINGLE(TWL6040_REG_HSLCTL, 5, ARRAY_SIZE(twl6040_hs_texts),
1004 twl6040_hs_texts),
1005 SOC_ENUM_SINGLE(TWL6040_REG_HSRCTL, 5, ARRAY_SIZE(twl6040_hs_texts),
1006 twl6040_hs_texts),
1007};
1008
1009static const char *twl6040_hf_texts[] = {
1010 "Off", "HF DAC", "Line-In amp"
1011};
1012
1013static const struct soc_enum twl6040_hf_enum[] = {
1014 SOC_ENUM_SINGLE(TWL6040_REG_HFLCTL, 2, ARRAY_SIZE(twl6040_hf_texts),
1015 twl6040_hf_texts),
1016 SOC_ENUM_SINGLE(TWL6040_REG_HFRCTL, 2, ARRAY_SIZE(twl6040_hf_texts),
1017 twl6040_hf_texts),
460}; 1018};
461 1019
462static const struct snd_kcontrol_new amicl_control = 1020static const struct snd_kcontrol_new amicl_control =
@@ -466,18 +1024,18 @@ static const struct snd_kcontrol_new amicr_control =
466 SOC_DAPM_ENUM("Route", twl6040_enum[1]); 1024 SOC_DAPM_ENUM("Route", twl6040_enum[1]);
467 1025
468/* Headset DAC playback switches */ 1026/* Headset DAC playback switches */
469static const struct snd_kcontrol_new hsdacl_switch_controls = 1027static const struct snd_kcontrol_new hsl_mux_controls =
470 SOC_DAPM_SINGLE("Switch", TWL6040_REG_HSLCTL, 5, 1, 0); 1028 SOC_DAPM_ENUM("Route", twl6040_hs_enum[0]);
471 1029
472static const struct snd_kcontrol_new hsdacr_switch_controls = 1030static const struct snd_kcontrol_new hsr_mux_controls =
473 SOC_DAPM_SINGLE("Switch", TWL6040_REG_HSRCTL, 5, 1, 0); 1031 SOC_DAPM_ENUM("Route", twl6040_hs_enum[1]);
474 1032
475/* Handsfree DAC playback switches */ 1033/* Handsfree DAC playback switches */
476static const struct snd_kcontrol_new hfdacl_switch_controls = 1034static const struct snd_kcontrol_new hfl_mux_controls =
477 SOC_DAPM_SINGLE("Switch", TWL6040_REG_HFLCTL, 2, 1, 0); 1035 SOC_DAPM_ENUM("Route", twl6040_hf_enum[0]);
478 1036
479static const struct snd_kcontrol_new hfdacr_switch_controls = 1037static const struct snd_kcontrol_new hfr_mux_controls =
480 SOC_DAPM_SINGLE("Switch", TWL6040_REG_HFRCTL, 2, 1, 0); 1038 SOC_DAPM_ENUM("Route", twl6040_hf_enum[1]);
481 1039
482static const struct snd_kcontrol_new ep_driver_switch_controls = 1040static const struct snd_kcontrol_new ep_driver_switch_controls =
483 SOC_DAPM_SINGLE("Switch", TWL6040_REG_EARCTL, 0, 1, 0); 1041 SOC_DAPM_SINGLE("Switch", TWL6040_REG_EARCTL, 0, 1, 0);
@@ -489,10 +1047,14 @@ static const struct snd_kcontrol_new twl6040_snd_controls[] = {
489 SOC_DOUBLE_TLV("Capture Volume", 1047 SOC_DOUBLE_TLV("Capture Volume",
490 TWL6040_REG_MICGAIN, 0, 3, 4, 0, mic_amp_tlv), 1048 TWL6040_REG_MICGAIN, 0, 3, 4, 0, mic_amp_tlv),
491 1049
1050 /* AFM gains */
1051 SOC_DOUBLE_TLV("Aux FM Volume",
1052 TWL6040_REG_LINEGAIN, 0, 4, 0xF, 0, afm_amp_tlv),
1053
492 /* Playback gains */ 1054 /* Playback gains */
493 SOC_DOUBLE_TLV("Headset Playback Volume", 1055 SOC_TWL6040_DOUBLE_TLV("Headset Playback Volume",
494 TWL6040_REG_HSGAIN, 0, 4, 0xF, 1, hs_tlv), 1056 TWL6040_REG_HSGAIN, 0, 4, 0xF, 1, hs_tlv),
495 SOC_DOUBLE_R_TLV("Handsfree Playback Volume", 1057 SOC_TWL6040_DOUBLE_R_TLV("Handsfree Playback Volume",
496 TWL6040_REG_HFLGAIN, TWL6040_REG_HFRGAIN, 0, 0x1D, 1, hf_tlv), 1058 TWL6040_REG_HFLGAIN, TWL6040_REG_HFRGAIN, 0, 0x1D, 1, hf_tlv),
497 SOC_SINGLE_TLV("Earphone Playback Volume", 1059 SOC_SINGLE_TLV("Earphone Playback Volume",
498 TWL6040_REG_EARCTL, 1, 0xF, 1, ep_tlv), 1060 TWL6040_REG_EARCTL, 1, 0xF, 1, ep_tlv),
@@ -525,6 +1087,12 @@ static const struct snd_soc_dapm_widget twl6040_dapm_widgets[] = {
525 SND_SOC_DAPM_PGA("MicAmpR", 1087 SND_SOC_DAPM_PGA("MicAmpR",
526 TWL6040_REG_MICRCTL, 0, 0, NULL, 0), 1088 TWL6040_REG_MICRCTL, 0, 0, NULL, 0),
527 1089
1090 /* Auxiliary FM PGAs */
1091 SND_SOC_DAPM_PGA("AFMAmpL",
1092 TWL6040_REG_MICLCTL, 1, 0, NULL, 0),
1093 SND_SOC_DAPM_PGA("AFMAmpR",
1094 TWL6040_REG_MICRCTL, 1, 0, NULL, 0),
1095
528 /* ADCs */ 1096 /* ADCs */
529 SND_SOC_DAPM_ADC("ADC Left", "Left Front Capture", 1097 SND_SOC_DAPM_ADC("ADC Left", "Left Front Capture",
530 TWL6040_REG_MICLCTL, 2, 0), 1098 TWL6040_REG_MICLCTL, 2, 0),
@@ -559,29 +1127,33 @@ static const struct snd_soc_dapm_widget twl6040_dapm_widgets[] = {
559 twl6040_power_mode_event, 1127 twl6040_power_mode_event,
560 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), 1128 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
561 1129
562 /* Analog playback switches */ 1130 SND_SOC_DAPM_MUX("HF Left Playback",
563 SND_SOC_DAPM_SWITCH("HSDAC Left Playback", 1131 SND_SOC_NOPM, 0, 0, &hfl_mux_controls),
564 SND_SOC_NOPM, 0, 0, &hsdacl_switch_controls), 1132 SND_SOC_DAPM_MUX("HF Right Playback",
565 SND_SOC_DAPM_SWITCH("HSDAC Right Playback", 1133 SND_SOC_NOPM, 0, 0, &hfr_mux_controls),
566 SND_SOC_NOPM, 0, 0, &hsdacr_switch_controls), 1134 /* Analog playback Muxes */
567 SND_SOC_DAPM_SWITCH("HFDAC Left Playback", 1135 SND_SOC_DAPM_MUX("HS Left Playback",
568 SND_SOC_NOPM, 0, 0, &hfdacl_switch_controls), 1136 SND_SOC_NOPM, 0, 0, &hsl_mux_controls),
569 SND_SOC_DAPM_SWITCH("HFDAC Right Playback", 1137 SND_SOC_DAPM_MUX("HS Right Playback",
570 SND_SOC_NOPM, 0, 0, &hfdacr_switch_controls), 1138 SND_SOC_NOPM, 0, 0, &hsr_mux_controls),
571 1139
572 /* Analog playback drivers */ 1140 /* Analog playback drivers */
573 SND_SOC_DAPM_PGA_E("Handsfree Left Driver", 1141 SND_SOC_DAPM_OUT_DRV_E("Handsfree Left Driver",
574 TWL6040_REG_HFLCTL, 4, 0, NULL, 0, 1142 TWL6040_REG_HFLCTL, 4, 0, NULL, 0,
575 twl6040_power_mode_event, 1143 pga_event,
576 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), 1144 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD),
577 SND_SOC_DAPM_PGA_E("Handsfree Right Driver", 1145 SND_SOC_DAPM_OUT_DRV_E("Handsfree Right Driver",
578 TWL6040_REG_HFRCTL, 4, 0, NULL, 0, 1146 TWL6040_REG_HFRCTL, 4, 0, NULL, 0,
579 twl6040_power_mode_event, 1147 pga_event,
580 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), 1148 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD),
581 SND_SOC_DAPM_PGA("Headset Left Driver", 1149 SND_SOC_DAPM_OUT_DRV_E("Headset Left Driver",
582 TWL6040_REG_HSLCTL, 2, 0, NULL, 0), 1150 TWL6040_REG_HSLCTL, 2, 0, NULL, 0,
583 SND_SOC_DAPM_PGA("Headset Right Driver", 1151 pga_event,
584 TWL6040_REG_HSRCTL, 2, 0, NULL, 0), 1152 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD),
1153 SND_SOC_DAPM_OUT_DRV_E("Headset Right Driver",
1154 TWL6040_REG_HSRCTL, 2, 0, NULL, 0,
1155 pga_event,
1156 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD),
585 SND_SOC_DAPM_SWITCH_E("Earphone Driver", 1157 SND_SOC_DAPM_SWITCH_E("Earphone Driver",
586 SND_SOC_NOPM, 0, 0, &ep_driver_switch_controls, 1158 SND_SOC_NOPM, 0, 0, &ep_driver_switch_controls,
587 twl6040_power_mode_event, 1159 twl6040_power_mode_event,
@@ -611,12 +1183,18 @@ static const struct snd_soc_dapm_route intercon[] = {
611 {"ADC Left", NULL, "MicAmpL"}, 1183 {"ADC Left", NULL, "MicAmpL"},
612 {"ADC Right", NULL, "MicAmpR"}, 1184 {"ADC Right", NULL, "MicAmpR"},
613 1185
614 /* Headset playback path */ 1186 /* AFM path */
615 {"HSDAC Left Playback", "Switch", "HSDAC Left"}, 1187 {"AFMAmpL", "NULL", "AFML"},
616 {"HSDAC Right Playback", "Switch", "HSDAC Right"}, 1188 {"AFMAmpR", "NULL", "AFMR"},
1189
1190 {"HS Left Playback", "HS DAC", "HSDAC Left"},
1191 {"HS Left Playback", "Line-In amp", "AFMAmpL"},
617 1192
618 {"Headset Left Driver", NULL, "HSDAC Left Playback"}, 1193 {"HS Right Playback", "HS DAC", "HSDAC Right"},
619 {"Headset Right Driver", NULL, "HSDAC Right Playback"}, 1194 {"HS Right Playback", "Line-In amp", "AFMAmpR"},
1195
1196 {"Headset Left Driver", "NULL", "HS Left Playback"},
1197 {"Headset Right Driver", "NULL", "HS Right Playback"},
620 1198
621 {"HSOL", NULL, "Headset Left Driver"}, 1199 {"HSOL", NULL, "Headset Left Driver"},
622 {"HSOR", NULL, "Headset Right Driver"}, 1200 {"HSOR", NULL, "Headset Right Driver"},
@@ -625,12 +1203,14 @@ static const struct snd_soc_dapm_route intercon[] = {
625 {"Earphone Driver", "Switch", "HSDAC Left"}, 1203 {"Earphone Driver", "Switch", "HSDAC Left"},
626 {"EP", NULL, "Earphone Driver"}, 1204 {"EP", NULL, "Earphone Driver"},
627 1205
628 /* Handsfree playback path */ 1206 {"HF Left Playback", "HF DAC", "HFDAC Left"},
629 {"HFDAC Left Playback", "Switch", "HFDAC Left"}, 1207 {"HF Left Playback", "Line-In amp", "AFMAmpL"},
630 {"HFDAC Right Playback", "Switch", "HFDAC Right"}, 1208
1209 {"HF Right Playback", "HF DAC", "HFDAC Right"},
1210 {"HF Right Playback", "Line-In amp", "AFMAmpR"},
631 1211
632 {"HFDAC Left PGA", NULL, "HFDAC Left Playback"}, 1212 {"HFDAC Left PGA", NULL, "HF Left Playback"},
633 {"HFDAC Right PGA", NULL, "HFDAC Right Playback"}, 1213 {"HFDAC Right PGA", NULL, "HF Right Playback"},
634 1214
635 {"Handsfree Left Driver", "Switch", "HFDAC Left PGA"}, 1215 {"Handsfree Left Driver", "Switch", "HFDAC Left PGA"},
636 {"Handsfree Right Driver", "Switch", "HFDAC Right PGA"}, 1216 {"Handsfree Right Driver", "Switch", "HFDAC Right PGA"},
@@ -641,12 +1221,12 @@ static const struct snd_soc_dapm_route intercon[] = {
641 1221
642static int twl6040_add_widgets(struct snd_soc_codec *codec) 1222static int twl6040_add_widgets(struct snd_soc_codec *codec)
643{ 1223{
644 snd_soc_dapm_new_controls(codec, twl6040_dapm_widgets, 1224 struct snd_soc_dapm_context *dapm = &codec->dapm;
645 ARRAY_SIZE(twl6040_dapm_widgets));
646
647 snd_soc_dapm_add_routes(codec, intercon, ARRAY_SIZE(intercon));
648 1225
649 snd_soc_dapm_new_widgets(codec); 1226 snd_soc_dapm_new_controls(dapm, twl6040_dapm_widgets,
1227 ARRAY_SIZE(twl6040_dapm_widgets));
1228 snd_soc_dapm_add_routes(dapm, intercon, ARRAY_SIZE(intercon));
1229 snd_soc_dapm_new_widgets(dapm);
650 1230
651 return 0; 1231 return 0;
652} 1232}
@@ -659,10 +1239,10 @@ static int twl6040_power_up_completion(struct snd_soc_codec *codec,
659 u8 intid; 1239 u8 intid;
660 1240
661 time_left = wait_for_completion_timeout(&priv->ready, 1241 time_left = wait_for_completion_timeout(&priv->ready,
662 msecs_to_jiffies(48)); 1242 msecs_to_jiffies(144));
663 1243
664 if (!time_left) { 1244 if (!time_left) {
665 twl_i2c_read_u8(TWL4030_MODULE_AUDIO_VOICE, &intid, 1245 twl_i2c_read_u8(TWL_MODULE_AUDIO_VOICE, &intid,
666 TWL6040_REG_INTID); 1246 TWL6040_REG_INTID);
667 if (!(intid & TWL6040_READYINT)) { 1247 if (!(intid & TWL6040_READYINT)) {
668 dev_err(codec->dev, "timeout waiting for READYINT\n"); 1248 dev_err(codec->dev, "timeout waiting for READYINT\n");
@@ -713,6 +1293,15 @@ static int twl6040_set_bias_level(struct snd_soc_codec *codec,
713 1293
714 /* initialize vdd/vss registers with reg_cache */ 1294 /* initialize vdd/vss registers with reg_cache */
715 twl6040_init_vdd_regs(codec); 1295 twl6040_init_vdd_regs(codec);
1296
1297 /* Set external boost GPO */
1298 twl6040_write(codec, TWL6040_REG_GPOCTL, 0x02);
1299
1300 /* Set initial minimal gain values */
1301 twl6040_write(codec, TWL6040_REG_HSGAIN, 0xFF);
1302 twl6040_write(codec, TWL6040_REG_EARCTL, 0x1E);
1303 twl6040_write(codec, TWL6040_REG_HFLGAIN, 0x1D);
1304 twl6040_write(codec, TWL6040_REG_HFRGAIN, 0x1D);
716 break; 1305 break;
717 case SND_SOC_BIAS_OFF: 1306 case SND_SOC_BIAS_OFF:
718 if (!priv->codec_powered) 1307 if (!priv->codec_powered)
@@ -739,7 +1328,7 @@ static int twl6040_set_bias_level(struct snd_soc_codec *codec,
739 break; 1328 break;
740 } 1329 }
741 1330
742 codec->bias_level = level; 1331 codec->dapm.bias_level = level;
743 1332
744 return 0; 1333 return 0;
745} 1334}
@@ -772,23 +1361,6 @@ static int twl6040_startup(struct snd_pcm_substream *substream,
772 struct snd_soc_codec *codec = rtd->codec; 1361 struct snd_soc_codec *codec = rtd->codec;
773 struct twl6040_data *priv = snd_soc_codec_get_drvdata(codec); 1362 struct twl6040_data *priv = snd_soc_codec_get_drvdata(codec);
774 1363
775 if (!priv->sysclk) {
776 dev_err(codec->dev,
777 "no mclk configured, call set_sysclk() on init\n");
778 return -EINVAL;
779 }
780
781 /*
782 * capture is not supported at 17.64 MHz,
783 * it's reserved for headset low-power playback scenario
784 */
785 if ((priv->sysclk == 17640000) && substream->stream) {
786 dev_err(codec->dev,
787 "capture mode is not supported at %dHz\n",
788 priv->sysclk);
789 return -EINVAL;
790 }
791
792 snd_pcm_hw_constraint_list(substream->runtime, 0, 1364 snd_pcm_hw_constraint_list(substream->runtime, 0,
793 SNDRV_PCM_HW_PARAM_RATE, 1365 SNDRV_PCM_HW_PARAM_RATE,
794 priv->sysclk_constraints); 1366 priv->sysclk_constraints);
@@ -814,10 +1386,17 @@ static int twl6040_hw_params(struct snd_pcm_substream *substream,
814 1386
815 rate = params_rate(params); 1387 rate = params_rate(params);
816 switch (rate) { 1388 switch (rate) {
1389 case 11250:
1390 case 22500:
1391 case 44100:
817 case 88200: 1392 case 88200:
818 lppllctl |= TWL6040_LPLLFIN; 1393 lppllctl |= TWL6040_LPLLFIN;
819 priv->sysclk = 17640000; 1394 priv->sysclk = 17640000;
820 break; 1395 break;
1396 case 8000:
1397 case 16000:
1398 case 32000:
1399 case 48000:
821 case 96000: 1400 case 96000:
822 lppllctl &= ~TWL6040_LPLLFIN; 1401 lppllctl &= ~TWL6040_LPLLFIN;
823 priv->sysclk = 19200000; 1402 priv->sysclk = 19200000;
@@ -832,31 +1411,37 @@ static int twl6040_hw_params(struct snd_pcm_substream *substream,
832 return 0; 1411 return 0;
833} 1412}
834 1413
835static int twl6040_trigger(struct snd_pcm_substream *substream, 1414static int twl6040_prepare(struct snd_pcm_substream *substream,
836 int cmd, struct snd_soc_dai *dai) 1415 struct snd_soc_dai *dai)
837{ 1416{
838 struct snd_soc_pcm_runtime *rtd = substream->private_data; 1417 struct snd_soc_pcm_runtime *rtd = substream->private_data;
839 struct snd_soc_codec *codec = rtd->codec; 1418 struct snd_soc_codec *codec = rtd->codec;
840 struct twl6040_data *priv = snd_soc_codec_get_drvdata(codec); 1419 struct twl6040_data *priv = snd_soc_codec_get_drvdata(codec);
841 1420
842 switch (cmd) { 1421 if (!priv->sysclk) {
843 case SNDRV_PCM_TRIGGER_START: 1422 dev_err(codec->dev,
844 case SNDRV_PCM_TRIGGER_RESUME: 1423 "no mclk configured, call set_sysclk() on init\n");
845 /* 1424 return -EINVAL;
846 * low-power playback mode is restricted 1425 }
847 * for headset path only 1426
848 */ 1427 /*
849 if ((priv->sysclk == 17640000) && priv->non_lp) { 1428 * capture is not supported at 17.64 MHz,
1429 * it's reserved for headset low-power playback scenario
1430 */
1431 if ((priv->sysclk == 17640000) &&
1432 substream->stream == SNDRV_PCM_STREAM_CAPTURE) {
1433 dev_err(codec->dev,
1434 "capture mode is not supported at %dHz\n",
1435 priv->sysclk);
1436 return -EINVAL;
1437 }
1438
1439 if ((priv->sysclk == 17640000) && priv->non_lp) {
850 dev_err(codec->dev, 1440 dev_err(codec->dev,
851 "some enabled paths aren't supported at %dHz\n", 1441 "some enabled paths aren't supported at %dHz\n",
852 priv->sysclk); 1442 priv->sysclk);
853 return -EPERM; 1443 return -EPERM;
854 }
855 break;
856 default:
857 break;
858 } 1444 }
859
860 return 0; 1445 return 0;
861} 1446}
862 1447
@@ -970,7 +1555,7 @@ static int twl6040_set_dai_sysclk(struct snd_soc_dai *codec_dai,
970static struct snd_soc_dai_ops twl6040_dai_ops = { 1555static struct snd_soc_dai_ops twl6040_dai_ops = {
971 .startup = twl6040_startup, 1556 .startup = twl6040_startup,
972 .hw_params = twl6040_hw_params, 1557 .hw_params = twl6040_hw_params,
973 .trigger = twl6040_trigger, 1558 .prepare = twl6040_prepare,
974 .set_sysclk = twl6040_set_dai_sysclk, 1559 .set_sysclk = twl6040_set_dai_sysclk,
975}; 1560};
976 1561
@@ -1004,6 +1589,7 @@ static int twl6040_suspend(struct snd_soc_codec *codec, pm_message_t state)
1004static int twl6040_resume(struct snd_soc_codec *codec) 1589static int twl6040_resume(struct snd_soc_codec *codec)
1005{ 1590{
1006 twl6040_set_bias_level(codec, SND_SOC_BIAS_STANDBY); 1591 twl6040_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
1592 twl6040_set_bias_level(codec, codec->dapm.suspend_bias_level);
1007 1593
1008 return 0; 1594 return 0;
1009} 1595}
@@ -1018,24 +1604,41 @@ static int twl6040_probe(struct snd_soc_codec *codec)
1018 struct twl6040_data *priv; 1604 struct twl6040_data *priv;
1019 int audpwron, naudint; 1605 int audpwron, naudint;
1020 int ret = 0; 1606 int ret = 0;
1607 u8 icrev, intmr = TWL6040_ALLINT_MSK;
1021 1608
1022 priv = kzalloc(sizeof(struct twl6040_data), GFP_KERNEL); 1609 priv = kzalloc(sizeof(struct twl6040_data), GFP_KERNEL);
1023 if (priv == NULL) 1610 if (priv == NULL)
1024 return -ENOMEM; 1611 return -ENOMEM;
1025 snd_soc_codec_set_drvdata(codec, priv); 1612 snd_soc_codec_set_drvdata(codec, priv);
1026 1613
1027 if (twl_codec) { 1614 priv->codec = codec;
1615
1616 twl_i2c_read_u8(TWL_MODULE_AUDIO_VOICE, &icrev, TWL6040_REG_ASICREV);
1617
1618 if (twl_codec && (icrev > 0))
1028 audpwron = twl_codec->audpwron_gpio; 1619 audpwron = twl_codec->audpwron_gpio;
1029 naudint = twl_codec->naudint_irq; 1620 else
1030 } else {
1031 audpwron = -EINVAL; 1621 audpwron = -EINVAL;
1622
1623 if (twl_codec)
1624 naudint = twl_codec->naudint_irq;
1625 else
1032 naudint = 0; 1626 naudint = 0;
1033 }
1034 1627
1035 priv->audpwron = audpwron; 1628 priv->audpwron = audpwron;
1036 priv->naudint = naudint; 1629 priv->naudint = naudint;
1630 priv->workqueue = create_singlethread_workqueue("twl6040-codec");
1631
1632 if (!priv->workqueue)
1633 goto work_err;
1634
1635 INIT_DELAYED_WORK(&priv->delayed_work, twl6040_accessory_work);
1636
1637 mutex_init(&priv->mutex);
1037 1638
1038 init_completion(&priv->ready); 1639 init_completion(&priv->ready);
1640 init_completion(&priv->headset.ramp_done);
1641 init_completion(&priv->handsfree.ramp_done);
1039 1642
1040 if (gpio_is_valid(audpwron)) { 1643 if (gpio_is_valid(audpwron)) {
1041 ret = gpio_request(audpwron, "audpwron"); 1644 ret = gpio_request(audpwron, "audpwron");
@@ -1047,7 +1650,14 @@ static int twl6040_probe(struct snd_soc_codec *codec)
1047 goto gpio2_err; 1650 goto gpio2_err;
1048 1651
1049 priv->codec_powered = 0; 1652 priv->codec_powered = 0;
1653
1654 /* enable only codec ready interrupt */
1655 intmr &= ~(TWL6040_READYMSK | TWL6040_PLUGMSK);
1656
1657 /* reset interrupt status to allow correct power up sequence */
1658 twl6040_read_reg_volatile(codec, TWL6040_REG_INTID);
1050 } 1659 }
1660 twl6040_write(codec, TWL6040_REG_INTMR, intmr);
1051 1661
1052 if (naudint) { 1662 if (naudint) {
1053 /* audio interrupt */ 1663 /* audio interrupt */
@@ -1057,25 +1667,29 @@ static int twl6040_probe(struct snd_soc_codec *codec)
1057 "twl6040_codec", codec); 1667 "twl6040_codec", codec);
1058 if (ret) 1668 if (ret)
1059 goto gpio2_err; 1669 goto gpio2_err;
1060 } else {
1061 if (gpio_is_valid(audpwron)) {
1062 /* enable only codec ready interrupt */
1063 twl6040_write_reg_cache(codec, TWL6040_REG_INTMR,
1064 ~TWL6040_READYMSK & TWL6040_ALLINT_MSK);
1065 } else {
1066 /* no interrupts at all */
1067 twl6040_write_reg_cache(codec, TWL6040_REG_INTMR,
1068 TWL6040_ALLINT_MSK);
1069 }
1070 } 1670 }
1071 1671
1072 /* init vio registers */ 1672 /* init vio registers */
1073 twl6040_init_vio_regs(codec); 1673 twl6040_init_vio_regs(codec);
1074 1674
1675 priv->hf_workqueue = create_singlethread_workqueue("twl6040-hf");
1676 if (priv->hf_workqueue == NULL) {
1677 ret = -ENOMEM;
1678 goto irq_err;
1679 }
1680 priv->hs_workqueue = create_singlethread_workqueue("twl6040-hs");
1681 if (priv->hs_workqueue == NULL) {
1682 ret = -ENOMEM;
1683 goto wq_err;
1684 }
1685
1686 INIT_DELAYED_WORK(&priv->hs_delayed_work, twl6040_pga_hs_work);
1687 INIT_DELAYED_WORK(&priv->hf_delayed_work, twl6040_pga_hf_work);
1688
1075 /* power on device */ 1689 /* power on device */
1076 ret = twl6040_set_bias_level(codec, SND_SOC_BIAS_STANDBY); 1690 ret = twl6040_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
1077 if (ret) 1691 if (ret)
1078 goto irq_err; 1692 goto bias_err;
1079 1693
1080 snd_soc_add_controls(codec, twl6040_snd_controls, 1694 snd_soc_add_controls(codec, twl6040_snd_controls,
1081 ARRAY_SIZE(twl6040_snd_controls)); 1695 ARRAY_SIZE(twl6040_snd_controls));
@@ -1083,6 +1697,10 @@ static int twl6040_probe(struct snd_soc_codec *codec)
1083 1697
1084 return 0; 1698 return 0;
1085 1699
1700bias_err:
1701 destroy_workqueue(priv->hs_workqueue);
1702wq_err:
1703 destroy_workqueue(priv->hf_workqueue);
1086irq_err: 1704irq_err:
1087 if (naudint) 1705 if (naudint)
1088 free_irq(naudint, codec); 1706 free_irq(naudint, codec);
@@ -1090,6 +1708,8 @@ gpio2_err:
1090 if (gpio_is_valid(audpwron)) 1708 if (gpio_is_valid(audpwron))
1091 gpio_free(audpwron); 1709 gpio_free(audpwron);
1092gpio1_err: 1710gpio1_err:
1711 destroy_workqueue(priv->workqueue);
1712work_err:
1093 kfree(priv); 1713 kfree(priv);
1094 return ret; 1714 return ret;
1095} 1715}
@@ -1108,6 +1728,9 @@ static int twl6040_remove(struct snd_soc_codec *codec)
1108 if (naudint) 1728 if (naudint)
1109 free_irq(naudint, codec); 1729 free_irq(naudint, codec);
1110 1730
1731 destroy_workqueue(priv->workqueue);
1732 destroy_workqueue(priv->hf_workqueue);
1733 destroy_workqueue(priv->hs_workqueue);
1111 kfree(priv); 1734 kfree(priv);
1112 1735
1113 return 0; 1736 return 0;
diff --git a/sound/soc/codecs/twl6040.h b/sound/soc/codecs/twl6040.h
index f7c77fa58a3c..23aeed0963e6 100644
--- a/sound/soc/codecs/twl6040.h
+++ b/sound/soc/codecs/twl6040.h
@@ -79,6 +79,7 @@
79 79
80/* INTMR (0x04) fields */ 80/* INTMR (0x04) fields */
81 81
82#define TWL6040_PLUGMSK 0x02
82#define TWL6040_READYMSK 0x40 83#define TWL6040_READYMSK 0x40
83#define TWL6040_ALLINT_MSK 0x7B 84#define TWL6040_ALLINT_MSK 0x7B
84 85
@@ -135,4 +136,11 @@
135#define TWL6040_HPPLL_ID 1 136#define TWL6040_HPPLL_ID 1
136#define TWL6040_LPPLL_ID 2 137#define TWL6040_LPPLL_ID 2
137 138
139/* STATUS (0x2E) fields */
140
141#define TWL6040_PLUGCOMP 0x02
142
143void twl6040_hs_jack_detect(struct snd_soc_codec *codec,
144 struct snd_soc_jack *jack, int report);
145
138#endif /* End of __TWL6040_H__ */ 146#endif /* End of __TWL6040_H__ */
diff --git a/sound/soc/codecs/uda134x.c b/sound/soc/codecs/uda134x.c
index 464f0cfa4c7a..e76847a9438b 100644
--- a/sound/soc/codecs/uda134x.c
+++ b/sound/soc/codecs/uda134x.c
@@ -19,7 +19,6 @@
19#include <sound/pcm.h> 19#include <sound/pcm.h>
20#include <sound/pcm_params.h> 20#include <sound/pcm_params.h>
21#include <sound/soc.h> 21#include <sound/soc.h>
22#include <sound/soc-dapm.h>
23#include <sound/initval.h> 22#include <sound/initval.h>
24 23
25#include <sound/uda134x.h> 24#include <sound/uda134x.h>
@@ -389,7 +388,7 @@ static int uda134x_set_bias_level(struct snd_soc_codec *codec,
389 pd->power(0); 388 pd->power(0);
390 break; 389 break;
391 } 390 }
392 codec->bias_level = level; 391 codec->dapm.bias_level = level;
393 return 0; 392 return 0;
394} 393}
395 394
diff --git a/sound/soc/codecs/uda1380.c b/sound/soc/codecs/uda1380.c
index 0c6c725736c6..c5ca8cfea60f 100644
--- a/sound/soc/codecs/uda1380.c
+++ b/sound/soc/codecs/uda1380.c
@@ -27,7 +27,6 @@
27#include <sound/control.h> 27#include <sound/control.h>
28#include <sound/initval.h> 28#include <sound/initval.h>
29#include <sound/soc.h> 29#include <sound/soc.h>
30#include <sound/soc-dapm.h>
31#include <sound/tlv.h> 30#include <sound/tlv.h>
32#include <sound/uda1380.h> 31#include <sound/uda1380.h>
33 32
@@ -36,7 +35,6 @@
36/* codec private data */ 35/* codec private data */
37struct uda1380_priv { 36struct uda1380_priv {
38 struct snd_soc_codec *codec; 37 struct snd_soc_codec *codec;
39 u16 reg_cache[UDA1380_CACHEREGNUM];
40 unsigned int dac_clk; 38 unsigned int dac_clk;
41 struct work_struct work; 39 struct work_struct work;
42 void *control_data; 40 void *control_data;
@@ -414,10 +412,11 @@ static const struct snd_soc_dapm_route audio_map[] = {
414 412
415static int uda1380_add_widgets(struct snd_soc_codec *codec) 413static int uda1380_add_widgets(struct snd_soc_codec *codec)
416{ 414{
417 snd_soc_dapm_new_controls(codec, uda1380_dapm_widgets, 415 struct snd_soc_dapm_context *dapm = &codec->dapm;
418 ARRAY_SIZE(uda1380_dapm_widgets));
419 416
420 snd_soc_dapm_add_routes(codec, audio_map, ARRAY_SIZE(audio_map)); 417 snd_soc_dapm_new_controls(dapm, uda1380_dapm_widgets,
418 ARRAY_SIZE(uda1380_dapm_widgets));
419 snd_soc_dapm_add_routes(dapm, audio_map, ARRAY_SIZE(audio_map));
421 420
422 return 0; 421 return 0;
423} 422}
@@ -603,7 +602,7 @@ static int uda1380_set_bias_level(struct snd_soc_codec *codec,
603 int reg; 602 int reg;
604 struct uda1380_platform_data *pdata = codec->dev->platform_data; 603 struct uda1380_platform_data *pdata = codec->dev->platform_data;
605 604
606 if (codec->bias_level == level) 605 if (codec->dapm.bias_level == level)
607 return 0; 606 return 0;
608 607
609 switch (level) { 608 switch (level) {
@@ -613,7 +612,7 @@ static int uda1380_set_bias_level(struct snd_soc_codec *codec,
613 uda1380_write(codec, UDA1380_PM, R02_PON_BIAS | pm); 612 uda1380_write(codec, UDA1380_PM, R02_PON_BIAS | pm);
614 break; 613 break;
615 case SND_SOC_BIAS_STANDBY: 614 case SND_SOC_BIAS_STANDBY:
616 if (codec->bias_level == SND_SOC_BIAS_OFF) { 615 if (codec->dapm.bias_level == SND_SOC_BIAS_OFF) {
617 if (gpio_is_valid(pdata->gpio_power)) { 616 if (gpio_is_valid(pdata->gpio_power)) {
618 gpio_set_value(pdata->gpio_power, 1); 617 gpio_set_value(pdata->gpio_power, 1);
619 mdelay(1); 618 mdelay(1);
@@ -636,7 +635,7 @@ static int uda1380_set_bias_level(struct snd_soc_codec *codec,
636 for (reg = UDA1380_MVOL; reg < UDA1380_CACHEREGNUM; reg++) 635 for (reg = UDA1380_MVOL; reg < UDA1380_CACHEREGNUM; reg++)
637 set_bit(reg - 0x10, &uda1380_cache_dirty); 636 set_bit(reg - 0x10, &uda1380_cache_dirty);
638 } 637 }
639 codec->bias_level = level; 638 codec->dapm.bias_level = level;
640 return 0; 639 return 0;
641} 640}
642 641
diff --git a/sound/soc/codecs/wl1273.c b/sound/soc/codecs/wl1273.c
index 0c47c788ccdf..d3ffa2f0122a 100644
--- a/sound/soc/codecs/wl1273.c
+++ b/sound/soc/codecs/wl1273.c
@@ -25,8 +25,7 @@
25#include <linux/slab.h> 25#include <linux/slab.h>
26#include <sound/pcm.h> 26#include <sound/pcm.h>
27#include <sound/pcm_params.h> 27#include <sound/pcm_params.h>
28#include <sound/soc-dai.h> 28#include <sound/soc.h>
29#include <sound/soc-dapm.h>
30#include <sound/initval.h> 29#include <sound/initval.h>
31 30
32#include "wl1273.h" 31#include "wl1273.h"
diff --git a/sound/soc/codecs/wm2000.c b/sound/soc/codecs/wm2000.c
index 4bcd168794e1..80ddf4fd23db 100644
--- a/sound/soc/codecs/wm2000.c
+++ b/sound/soc/codecs/wm2000.c
@@ -36,7 +36,6 @@
36#include <sound/pcm.h> 36#include <sound/pcm.h>
37#include <sound/pcm_params.h> 37#include <sound/pcm_params.h>
38#include <sound/soc.h> 38#include <sound/soc.h>
39#include <sound/soc-dapm.h>
40#include <sound/initval.h> 39#include <sound/initval.h>
41#include <sound/tlv.h> 40#include <sound/tlv.h>
42 41
@@ -705,6 +704,7 @@ static const struct snd_soc_dapm_route audio_map[] = {
705/* Called from the machine driver */ 704/* Called from the machine driver */
706int wm2000_add_controls(struct snd_soc_codec *codec) 705int wm2000_add_controls(struct snd_soc_codec *codec)
707{ 706{
707 struct snd_soc_dapm_context *dapm = &codec->dapm;
708 int ret; 708 int ret;
709 709
710 if (!wm2000_i2c) { 710 if (!wm2000_i2c) {
@@ -712,12 +712,12 @@ int wm2000_add_controls(struct snd_soc_codec *codec)
712 return -ENODEV; 712 return -ENODEV;
713 } 713 }
714 714
715 ret = snd_soc_dapm_new_controls(codec, wm2000_dapm_widgets, 715 ret = snd_soc_dapm_new_controls(dapm, wm2000_dapm_widgets,
716 ARRAY_SIZE(wm2000_dapm_widgets)); 716 ARRAY_SIZE(wm2000_dapm_widgets));
717 if (ret < 0) 717 if (ret < 0)
718 return ret; 718 return ret;
719 719
720 ret = snd_soc_dapm_add_routes(codec, audio_map, ARRAY_SIZE(audio_map)); 720 ret = snd_soc_dapm_add_routes(dapm, audio_map, ARRAY_SIZE(audio_map));
721 if (ret < 0) 721 if (ret < 0)
722 return ret; 722 return ret;
723 723
diff --git a/sound/soc/codecs/wm8350.c b/sound/soc/codecs/wm8350.c
index 7611add7f8c3..6d6dc9efe914 100644
--- a/sound/soc/codecs/wm8350.c
+++ b/sound/soc/codecs/wm8350.c
@@ -24,9 +24,9 @@
24#include <sound/pcm.h> 24#include <sound/pcm.h>
25#include <sound/pcm_params.h> 25#include <sound/pcm_params.h>
26#include <sound/soc.h> 26#include <sound/soc.h>
27#include <sound/soc-dapm.h>
28#include <sound/initval.h> 27#include <sound/initval.h>
29#include <sound/tlv.h> 28#include <sound/tlv.h>
29#include <trace/events/asoc.h>
30 30
31#include "wm8350.h" 31#include "wm8350.h"
32 32
@@ -54,6 +54,7 @@ struct wm8350_output {
54 54
55struct wm8350_jack_data { 55struct wm8350_jack_data {
56 struct snd_soc_jack *jack; 56 struct snd_soc_jack *jack;
57 struct delayed_work work;
57 int report; 58 int report;
58 int short_report; 59 int short_report;
59}; 60};
@@ -230,8 +231,9 @@ static inline int wm8350_out2_ramp_step(struct snd_soc_codec *codec)
230 */ 231 */
231static void wm8350_pga_work(struct work_struct *work) 232static void wm8350_pga_work(struct work_struct *work)
232{ 233{
233 struct snd_soc_codec *codec = 234 struct snd_soc_dapm_context *dapm =
234 container_of(work, struct snd_soc_codec, delayed_work.work); 235 container_of(work, struct snd_soc_dapm_context, delayed_work.work);
236 struct snd_soc_codec *codec = dapm->codec;
235 struct wm8350_data *wm8350_data = snd_soc_codec_get_drvdata(codec); 237 struct wm8350_data *wm8350_data = snd_soc_codec_get_drvdata(codec);
236 struct wm8350_output *out1 = &wm8350_data->out1, 238 struct wm8350_output *out1 = &wm8350_data->out1,
237 *out2 = &wm8350_data->out2; 239 *out2 = &wm8350_data->out2;
@@ -302,8 +304,8 @@ static int pga_event(struct snd_soc_dapm_widget *w,
302 out->ramp = WM8350_RAMP_UP; 304 out->ramp = WM8350_RAMP_UP;
303 out->active = 1; 305 out->active = 1;
304 306
305 if (!delayed_work_pending(&codec->delayed_work)) 307 if (!delayed_work_pending(&codec->dapm.delayed_work))
306 schedule_delayed_work(&codec->delayed_work, 308 schedule_delayed_work(&codec->dapm.delayed_work,
307 msecs_to_jiffies(1)); 309 msecs_to_jiffies(1));
308 break; 310 break;
309 311
@@ -311,8 +313,8 @@ static int pga_event(struct snd_soc_dapm_widget *w,
311 out->ramp = WM8350_RAMP_DOWN; 313 out->ramp = WM8350_RAMP_DOWN;
312 out->active = 0; 314 out->active = 0;
313 315
314 if (!delayed_work_pending(&codec->delayed_work)) 316 if (!delayed_work_pending(&codec->dapm.delayed_work))
315 schedule_delayed_work(&codec->delayed_work, 317 schedule_delayed_work(&codec->dapm.delayed_work,
316 msecs_to_jiffies(1)); 318 msecs_to_jiffies(1));
317 break; 319 break;
318 } 320 }
@@ -786,9 +788,10 @@ static const struct snd_soc_dapm_route audio_map[] = {
786 788
787static int wm8350_add_widgets(struct snd_soc_codec *codec) 789static int wm8350_add_widgets(struct snd_soc_codec *codec)
788{ 790{
791 struct snd_soc_dapm_context *dapm = &codec->dapm;
789 int ret; 792 int ret;
790 793
791 ret = snd_soc_dapm_new_controls(codec, 794 ret = snd_soc_dapm_new_controls(dapm,
792 wm8350_dapm_widgets, 795 wm8350_dapm_widgets,
793 ARRAY_SIZE(wm8350_dapm_widgets)); 796 ARRAY_SIZE(wm8350_dapm_widgets));
794 if (ret != 0) { 797 if (ret != 0) {
@@ -797,7 +800,7 @@ static int wm8350_add_widgets(struct snd_soc_codec *codec)
797 } 800 }
798 801
799 /* set up audio paths */ 802 /* set up audio paths */
800 ret = snd_soc_dapm_add_routes(codec, audio_map, ARRAY_SIZE(audio_map)); 803 ret = snd_soc_dapm_add_routes(dapm, audio_map, ARRAY_SIZE(audio_map));
801 if (ret != 0) { 804 if (ret != 0) {
802 dev_err(codec->dev, "DAPM route register failed\n"); 805 dev_err(codec->dev, "DAPM route register failed\n");
803 return ret; 806 return ret;
@@ -1184,7 +1187,7 @@ static int wm8350_set_bias_level(struct snd_soc_codec *codec,
1184 break; 1187 break;
1185 1188
1186 case SND_SOC_BIAS_STANDBY: 1189 case SND_SOC_BIAS_STANDBY:
1187 if (codec->bias_level == SND_SOC_BIAS_OFF) { 1190 if (codec->dapm.bias_level == SND_SOC_BIAS_OFF) {
1188 ret = regulator_bulk_enable(ARRAY_SIZE(priv->supplies), 1191 ret = regulator_bulk_enable(ARRAY_SIZE(priv->supplies),
1189 priv->supplies); 1192 priv->supplies);
1190 if (ret != 0) 1193 if (ret != 0)
@@ -1317,7 +1320,7 @@ static int wm8350_set_bias_level(struct snd_soc_codec *codec,
1317 priv->supplies); 1320 priv->supplies);
1318 break; 1321 break;
1319 } 1322 }
1320 codec->bias_level = level; 1323 codec->dapm.bias_level = level;
1321 return 0; 1324 return 0;
1322} 1325}
1323 1326
@@ -1334,45 +1337,69 @@ static int wm8350_resume(struct snd_soc_codec *codec)
1334 return 0; 1337 return 0;
1335} 1338}
1336 1339
1337static irqreturn_t wm8350_hp_jack_handler(int irq, void *data) 1340static void wm8350_hp_work(struct wm8350_data *priv,
1341 struct wm8350_jack_data *jack,
1342 u16 mask)
1338{ 1343{
1339 struct wm8350_data *priv = data;
1340 struct wm8350 *wm8350 = priv->codec.control_data; 1344 struct wm8350 *wm8350 = priv->codec.control_data;
1341 u16 reg; 1345 u16 reg;
1342 int report; 1346 int report;
1343 int mask; 1347
1348 reg = wm8350_reg_read(wm8350, WM8350_JACK_PIN_STATUS);
1349 if (reg & mask)
1350 report = jack->report;
1351 else
1352 report = 0;
1353
1354 snd_soc_jack_report(jack->jack, report, jack->report);
1355
1356}
1357
1358static void wm8350_hpl_work(struct work_struct *work)
1359{
1360 struct wm8350_data *priv =
1361 container_of(work, struct wm8350_data, hpl.work.work);
1362
1363 wm8350_hp_work(priv, &priv->hpl, WM8350_JACK_L_LVL);
1364}
1365
1366static void wm8350_hpr_work(struct work_struct *work)
1367{
1368 struct wm8350_data *priv =
1369 container_of(work, struct wm8350_data, hpr.work.work);
1370
1371 wm8350_hp_work(priv, &priv->hpr, WM8350_JACK_R_LVL);
1372}
1373
1374static irqreturn_t wm8350_hp_jack_handler(int irq, void *data)
1375{
1376 struct wm8350_data *priv = data;
1377 struct wm8350 *wm8350 = priv->codec.control_data;
1344 struct wm8350_jack_data *jack = NULL; 1378 struct wm8350_jack_data *jack = NULL;
1345 1379
1346 switch (irq - wm8350->irq_base) { 1380 switch (irq - wm8350->irq_base) {
1347 case WM8350_IRQ_CODEC_JCK_DET_L: 1381 case WM8350_IRQ_CODEC_JCK_DET_L:
1382#ifndef CONFIG_SND_SOC_WM8350_MODULE
1383 trace_snd_soc_jack_irq("WM8350 HPL");
1384#endif
1348 jack = &priv->hpl; 1385 jack = &priv->hpl;
1349 mask = WM8350_JACK_L_LVL;
1350 break; 1386 break;
1351 1387
1352 case WM8350_IRQ_CODEC_JCK_DET_R: 1388 case WM8350_IRQ_CODEC_JCK_DET_R:
1389#ifndef CONFIG_SND_SOC_WM8350_MODULE
1390 trace_snd_soc_jack_irq("WM8350 HPR");
1391#endif
1353 jack = &priv->hpr; 1392 jack = &priv->hpr;
1354 mask = WM8350_JACK_R_LVL;
1355 break; 1393 break;
1356 1394
1357 default: 1395 default:
1358 BUG(); 1396 BUG();
1359 } 1397 }
1360 1398
1361 if (!jack->jack) { 1399 if (device_may_wakeup(wm8350->dev))
1362 dev_warn(wm8350->dev, "Jack interrupt called with no jack\n"); 1400 pm_wakeup_event(wm8350->dev, 250);
1363 return IRQ_NONE;
1364 }
1365
1366 /* Debounce */
1367 msleep(200);
1368
1369 reg = wm8350_reg_read(wm8350, WM8350_JACK_PIN_STATUS);
1370 if (reg & mask)
1371 report = jack->report;
1372 else
1373 report = 0;
1374 1401
1375 snd_soc_jack_report(jack->jack, report, jack->report); 1402 schedule_delayed_work(&jack->work, 200);
1376 1403
1377 return IRQ_HANDLED; 1404 return IRQ_HANDLED;
1378} 1405}
@@ -1436,6 +1463,10 @@ static irqreturn_t wm8350_mic_handler(int irq, void *data)
1436 u16 reg; 1463 u16 reg;
1437 int report = 0; 1464 int report = 0;
1438 1465
1466#ifndef CONFIG_SND_SOC_WM8350_MODULE
1467 trace_snd_soc_jack_irq("WM8350 mic");
1468#endif
1469
1439 reg = wm8350_reg_read(wm8350, WM8350_JACK_PIN_STATUS); 1470 reg = wm8350_reg_read(wm8350, WM8350_JACK_PIN_STATUS);
1440 if (reg & WM8350_JACK_MICSCD_LVL) 1471 if (reg & WM8350_JACK_MICSCD_LVL)
1441 report |= priv->mic.short_report; 1472 report |= priv->mic.short_report;
@@ -1550,7 +1581,9 @@ static int wm8350_codec_probe(struct snd_soc_codec *codec)
1550 /* Put the codec into reset if it wasn't already */ 1581 /* Put the codec into reset if it wasn't already */
1551 wm8350_clear_bits(wm8350, WM8350_POWER_MGMT_5, WM8350_CODEC_ENA); 1582 wm8350_clear_bits(wm8350, WM8350_POWER_MGMT_5, WM8350_CODEC_ENA);
1552 1583
1553 INIT_DELAYED_WORK(&codec->delayed_work, wm8350_pga_work); 1584 INIT_DELAYED_WORK(&codec->dapm.delayed_work, wm8350_pga_work);
1585 INIT_DELAYED_WORK(&priv->hpl.work, wm8350_hpl_work);
1586 INIT_DELAYED_WORK(&priv->hpr.work, wm8350_hpr_work);
1554 1587
1555 /* Enable the codec */ 1588 /* Enable the codec */
1556 wm8350_set_bits(wm8350, WM8350_POWER_MGMT_5, WM8350_CODEC_ENA); 1589 wm8350_set_bits(wm8350, WM8350_POWER_MGMT_5, WM8350_CODEC_ENA);
@@ -1626,7 +1659,6 @@ static int wm8350_codec_remove(struct snd_soc_codec *codec)
1626{ 1659{
1627 struct wm8350_data *priv = snd_soc_codec_get_drvdata(codec); 1660 struct wm8350_data *priv = snd_soc_codec_get_drvdata(codec);
1628 struct wm8350 *wm8350 = dev_get_platdata(codec->dev); 1661 struct wm8350 *wm8350 = dev_get_platdata(codec->dev);
1629 int ret;
1630 1662
1631 wm8350_clear_bits(wm8350, WM8350_JACK_DETECT, 1663 wm8350_clear_bits(wm8350, WM8350_JACK_DETECT,
1632 WM8350_JDL_ENA | WM8350_JDR_ENA); 1664 WM8350_JDL_ENA | WM8350_JDR_ENA);
@@ -1641,15 +1673,12 @@ static int wm8350_codec_remove(struct snd_soc_codec *codec)
1641 priv->hpr.jack = NULL; 1673 priv->hpr.jack = NULL;
1642 priv->mic.jack = NULL; 1674 priv->mic.jack = NULL;
1643 1675
1644 /* cancel any work waiting to be queued. */ 1676 cancel_delayed_work_sync(&priv->hpl.work);
1645 ret = cancel_delayed_work(&codec->delayed_work); 1677 cancel_delayed_work_sync(&priv->hpr.work);
1646 1678
1647 /* if there was any work waiting then we run it now and 1679 /* if there was any work waiting then we run it now and
1648 * wait for its completion */ 1680 * wait for its completion */
1649 if (ret) { 1681 flush_delayed_work_sync(&codec->dapm.delayed_work);
1650 schedule_delayed_work(&codec->delayed_work, 0);
1651 flush_scheduled_work();
1652 }
1653 1682
1654 wm8350_set_bias_level(codec, SND_SOC_BIAS_OFF); 1683 wm8350_set_bias_level(codec, SND_SOC_BIAS_OFF);
1655 1684
diff --git a/sound/soc/codecs/wm8400.c b/sound/soc/codecs/wm8400.c
index 850299786e02..3c3bc079167e 100644
--- a/sound/soc/codecs/wm8400.c
+++ b/sound/soc/codecs/wm8400.c
@@ -26,7 +26,6 @@
26#include <sound/pcm.h> 26#include <sound/pcm.h>
27#include <sound/pcm_params.h> 27#include <sound/pcm_params.h>
28#include <sound/soc.h> 28#include <sound/soc.h>
29#include <sound/soc-dapm.h>
30#include <sound/initval.h> 29#include <sound/initval.h>
31#include <sound/tlv.h> 30#include <sound/tlv.h>
32 31
@@ -911,10 +910,11 @@ static const struct snd_soc_dapm_route audio_map[] = {
911 910
912static int wm8400_add_widgets(struct snd_soc_codec *codec) 911static int wm8400_add_widgets(struct snd_soc_codec *codec)
913{ 912{
914 snd_soc_dapm_new_controls(codec, wm8400_dapm_widgets, 913 struct snd_soc_dapm_context *dapm = &codec->dapm;
915 ARRAY_SIZE(wm8400_dapm_widgets));
916 914
917 snd_soc_dapm_add_routes(codec, audio_map, ARRAY_SIZE(audio_map)); 915 snd_soc_dapm_new_controls(dapm, wm8400_dapm_widgets,
916 ARRAY_SIZE(wm8400_dapm_widgets));
917 snd_soc_dapm_add_routes(dapm, audio_map, ARRAY_SIZE(audio_map));
918 918
919 return 0; 919 return 0;
920} 920}
@@ -1219,7 +1219,7 @@ static int wm8400_set_bias_level(struct snd_soc_codec *codec,
1219 break; 1219 break;
1220 1220
1221 case SND_SOC_BIAS_STANDBY: 1221 case SND_SOC_BIAS_STANDBY:
1222 if (codec->bias_level == SND_SOC_BIAS_OFF) { 1222 if (codec->dapm.bias_level == SND_SOC_BIAS_OFF) {
1223 ret = regulator_bulk_enable(ARRAY_SIZE(power), 1223 ret = regulator_bulk_enable(ARRAY_SIZE(power),
1224 &power[0]); 1224 &power[0]);
1225 if (ret != 0) { 1225 if (ret != 0) {
@@ -1306,7 +1306,7 @@ static int wm8400_set_bias_level(struct snd_soc_codec *codec,
1306 break; 1306 break;
1307 } 1307 }
1308 1308
1309 codec->bias_level = level; 1309 codec->dapm.bias_level = level;
1310 return 0; 1310 return 0;
1311} 1311}
1312 1312
diff --git a/sound/soc/codecs/wm8510.c b/sound/soc/codecs/wm8510.c
index 8f107095760e..db0dced74843 100644
--- a/sound/soc/codecs/wm8510.c
+++ b/sound/soc/codecs/wm8510.c
@@ -24,7 +24,6 @@
24#include <sound/pcm.h> 24#include <sound/pcm.h>
25#include <sound/pcm_params.h> 25#include <sound/pcm_params.h>
26#include <sound/soc.h> 26#include <sound/soc.h>
27#include <sound/soc-dapm.h>
28#include <sound/initval.h> 27#include <sound/initval.h>
29 28
30#include "wm8510.h" 29#include "wm8510.h"
@@ -216,10 +215,11 @@ static const struct snd_soc_dapm_route audio_map[] = {
216 215
217static int wm8510_add_widgets(struct snd_soc_codec *codec) 216static int wm8510_add_widgets(struct snd_soc_codec *codec)
218{ 217{
219 snd_soc_dapm_new_controls(codec, wm8510_dapm_widgets, 218 struct snd_soc_dapm_context *dapm = &codec->dapm;
220 ARRAY_SIZE(wm8510_dapm_widgets));
221 219
222 snd_soc_dapm_add_routes(codec, audio_map, ARRAY_SIZE(audio_map)); 220 snd_soc_dapm_new_controls(dapm, wm8510_dapm_widgets,
221 ARRAY_SIZE(wm8510_dapm_widgets));
222 snd_soc_dapm_add_routes(dapm, audio_map, ARRAY_SIZE(audio_map));
223 223
224 return 0; 224 return 0;
225} 225}
@@ -478,7 +478,7 @@ static int wm8510_set_bias_level(struct snd_soc_codec *codec,
478 case SND_SOC_BIAS_STANDBY: 478 case SND_SOC_BIAS_STANDBY:
479 power1 |= WM8510_POWER1_BIASEN | WM8510_POWER1_BUFIOEN; 479 power1 |= WM8510_POWER1_BIASEN | WM8510_POWER1_BUFIOEN;
480 480
481 if (codec->bias_level == SND_SOC_BIAS_OFF) { 481 if (codec->dapm.bias_level == SND_SOC_BIAS_OFF) {
482 /* Initial cap charge at VMID 5k */ 482 /* Initial cap charge at VMID 5k */
483 snd_soc_write(codec, WM8510_POWER1, power1 | 0x3); 483 snd_soc_write(codec, WM8510_POWER1, power1 | 0x3);
484 mdelay(100); 484 mdelay(100);
@@ -495,7 +495,7 @@ static int wm8510_set_bias_level(struct snd_soc_codec *codec,
495 break; 495 break;
496 } 496 }
497 497
498 codec->bias_level = level; 498 codec->dapm.bias_level = level;
499 return 0; 499 return 0;
500} 500}
501 501
diff --git a/sound/soc/codecs/wm8523.c b/sound/soc/codecs/wm8523.c
index deca79ea2b4b..5eb2f501ce32 100644
--- a/sound/soc/codecs/wm8523.c
+++ b/sound/soc/codecs/wm8523.c
@@ -24,7 +24,6 @@
24#include <sound/pcm.h> 24#include <sound/pcm.h>
25#include <sound/pcm_params.h> 25#include <sound/pcm_params.h>
26#include <sound/soc.h> 26#include <sound/soc.h>
27#include <sound/soc-dapm.h>
28#include <sound/initval.h> 27#include <sound/initval.h>
29#include <sound/tlv.h> 28#include <sound/tlv.h>
30 29
@@ -109,10 +108,11 @@ static const struct snd_soc_dapm_route intercon[] = {
109 108
110static int wm8523_add_widgets(struct snd_soc_codec *codec) 109static int wm8523_add_widgets(struct snd_soc_codec *codec)
111{ 110{
112 snd_soc_dapm_new_controls(codec, wm8523_dapm_widgets, 111 struct snd_soc_dapm_context *dapm = &codec->dapm;
113 ARRAY_SIZE(wm8523_dapm_widgets));
114 112
115 snd_soc_dapm_add_routes(codec, intercon, ARRAY_SIZE(intercon)); 113 snd_soc_dapm_new_controls(dapm, wm8523_dapm_widgets,
114 ARRAY_SIZE(wm8523_dapm_widgets));
115 snd_soc_dapm_add_routes(dapm, intercon, ARRAY_SIZE(intercon));
116 116
117 return 0; 117 return 0;
118} 118}
@@ -327,7 +327,7 @@ static int wm8523_set_bias_level(struct snd_soc_codec *codec,
327 break; 327 break;
328 328
329 case SND_SOC_BIAS_STANDBY: 329 case SND_SOC_BIAS_STANDBY:
330 if (codec->bias_level == SND_SOC_BIAS_OFF) { 330 if (codec->dapm.bias_level == SND_SOC_BIAS_OFF) {
331 ret = regulator_bulk_enable(ARRAY_SIZE(wm8523->supplies), 331 ret = regulator_bulk_enable(ARRAY_SIZE(wm8523->supplies),
332 wm8523->supplies); 332 wm8523->supplies);
333 if (ret != 0) { 333 if (ret != 0) {
@@ -366,7 +366,7 @@ static int wm8523_set_bias_level(struct snd_soc_codec *codec,
366 wm8523->supplies); 366 wm8523->supplies);
367 break; 367 break;
368 } 368 }
369 codec->bias_level = level; 369 codec->dapm.bias_level = level;
370 return 0; 370 return 0;
371} 371}
372 372
diff --git a/sound/soc/codecs/wm8580.c b/sound/soc/codecs/wm8580.c
index 8725d4e75431..8f6b5ee6645b 100644
--- a/sound/soc/codecs/wm8580.c
+++ b/sound/soc/codecs/wm8580.c
@@ -31,7 +31,6 @@
31#include <sound/pcm.h> 31#include <sound/pcm.h>
32#include <sound/pcm_params.h> 32#include <sound/pcm_params.h>
33#include <sound/soc.h> 33#include <sound/soc.h>
34#include <sound/soc-dapm.h>
35#include <sound/tlv.h> 34#include <sound/tlv.h>
36#include <sound/initval.h> 35#include <sound/initval.h>
37#include <asm/div64.h> 36#include <asm/div64.h>
@@ -191,7 +190,6 @@ static const char *wm8580_supply_names[WM8580_NUM_SUPPLIES] = {
191struct wm8580_priv { 190struct wm8580_priv {
192 enum snd_soc_control_type control_type; 191 enum snd_soc_control_type control_type;
193 struct regulator_bulk_data supplies[WM8580_NUM_SUPPLIES]; 192 struct regulator_bulk_data supplies[WM8580_NUM_SUPPLIES];
194 u16 reg_cache[WM8580_MAX_REGISTER + 1];
195 struct pll_state a; 193 struct pll_state a;
196 struct pll_state b; 194 struct pll_state b;
197 int sysclk[2]; 195 int sysclk[2];
@@ -302,10 +300,11 @@ static const struct snd_soc_dapm_route audio_map[] = {
302 300
303static int wm8580_add_widgets(struct snd_soc_codec *codec) 301static int wm8580_add_widgets(struct snd_soc_codec *codec)
304{ 302{
305 snd_soc_dapm_new_controls(codec, wm8580_dapm_widgets, 303 struct snd_soc_dapm_context *dapm = &codec->dapm;
306 ARRAY_SIZE(wm8580_dapm_widgets));
307 304
308 snd_soc_dapm_add_routes(codec, audio_map, ARRAY_SIZE(audio_map)); 305 snd_soc_dapm_new_controls(dapm, wm8580_dapm_widgets,
306 ARRAY_SIZE(wm8580_dapm_widgets));
307 snd_soc_dapm_add_routes(dapm, audio_map, ARRAY_SIZE(audio_map));
309 308
310 return 0; 309 return 0;
311} 310}
@@ -507,13 +506,13 @@ static int wm8580_paif_hw_params(struct snd_pcm_substream *substream,
507 } 506 }
508 507
509 /* Look up the SYSCLK ratio; accept only exact matches */ 508 /* Look up the SYSCLK ratio; accept only exact matches */
510 ratio = wm8580->sysclk[dai->id] / params_rate(params); 509 ratio = wm8580->sysclk[dai->driver->id] / params_rate(params);
511 for (i = 0; i < ARRAY_SIZE(wm8580_sysclk_ratios); i++) 510 for (i = 0; i < ARRAY_SIZE(wm8580_sysclk_ratios); i++)
512 if (ratio == wm8580_sysclk_ratios[i]) 511 if (ratio == wm8580_sysclk_ratios[i])
513 break; 512 break;
514 if (i == ARRAY_SIZE(wm8580_sysclk_ratios)) { 513 if (i == ARRAY_SIZE(wm8580_sysclk_ratios)) {
515 dev_err(codec->dev, "Invalid clock ratio %d/%d\n", 514 dev_err(codec->dev, "Invalid clock ratio %d/%d\n",
516 wm8580->sysclk[dai->id], params_rate(params)); 515 wm8580->sysclk[dai->driver->id], params_rate(params));
517 return -EINVAL; 516 return -EINVAL;
518 } 517 }
519 paifa |= i; 518 paifa |= i;
@@ -716,7 +715,7 @@ static int wm8580_set_sysclk(struct snd_soc_dai *dai, int clk_id,
716 715
717 switch (clk_id) { 716 switch (clk_id) {
718 case WM8580_CLKSRC_ADCMCLK: 717 case WM8580_CLKSRC_ADCMCLK:
719 if (dai->id != WM8580_DAI_PAIFTX) 718 if (dai->driver->id != WM8580_DAI_PAIFTX)
720 return -EINVAL; 719 return -EINVAL;
721 sel = 0 << sel_shift; 720 sel = 0 << sel_shift;
722 break; 721 break;
@@ -735,7 +734,7 @@ static int wm8580_set_sysclk(struct snd_soc_dai *dai, int clk_id,
735 } 734 }
736 735
737 /* We really should validate PLL settings but not yet */ 736 /* We really should validate PLL settings but not yet */
738 wm8580->sysclk[dai->id] = freq; 737 wm8580->sysclk[dai->driver->id] = freq;
739 738
740 return snd_soc_update_bits(codec, WM8580_CLKSEL, sel_mask, sel); 739 return snd_soc_update_bits(codec, WM8580_CLKSEL, sel_mask, sel);
741} 740}
@@ -767,7 +766,7 @@ static int wm8580_set_bias_level(struct snd_soc_codec *codec,
767 break; 766 break;
768 767
769 case SND_SOC_BIAS_STANDBY: 768 case SND_SOC_BIAS_STANDBY:
770 if (codec->bias_level == SND_SOC_BIAS_OFF) { 769 if (codec->dapm.bias_level == SND_SOC_BIAS_OFF) {
771 /* Power up and get individual control of the DACs */ 770 /* Power up and get individual control of the DACs */
772 reg = snd_soc_read(codec, WM8580_PWRDN1); 771 reg = snd_soc_read(codec, WM8580_PWRDN1);
773 reg &= ~(WM8580_PWRDN1_PWDN | WM8580_PWRDN1_ALLDACPD); 772 reg &= ~(WM8580_PWRDN1_PWDN | WM8580_PWRDN1_ALLDACPD);
@@ -785,7 +784,7 @@ static int wm8580_set_bias_level(struct snd_soc_codec *codec,
785 snd_soc_write(codec, WM8580_PWRDN1, reg | WM8580_PWRDN1_PWDN); 784 snd_soc_write(codec, WM8580_PWRDN1, reg | WM8580_PWRDN1_PWDN);
786 break; 785 break;
787 } 786 }
788 codec->bias_level = level; 787 codec->dapm.bias_level = level;
789 return 0; 788 return 0;
790} 789}
791 790
@@ -905,7 +904,7 @@ static struct snd_soc_codec_driver soc_codec_dev_wm8580 = {
905 .set_bias_level = wm8580_set_bias_level, 904 .set_bias_level = wm8580_set_bias_level,
906 .reg_cache_size = ARRAY_SIZE(wm8580_reg), 905 .reg_cache_size = ARRAY_SIZE(wm8580_reg),
907 .reg_word_size = sizeof(u16), 906 .reg_word_size = sizeof(u16),
908 .reg_cache_default = &wm8580_reg, 907 .reg_cache_default = wm8580_reg,
909}; 908};
910 909
911#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE) 910#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
diff --git a/sound/soc/codecs/wm8711.c b/sound/soc/codecs/wm8711.c
index 54fbd76c8bca..97c30382d3ff 100644
--- a/sound/soc/codecs/wm8711.c
+++ b/sound/soc/codecs/wm8711.c
@@ -25,7 +25,6 @@
25#include <sound/pcm.h> 25#include <sound/pcm.h>
26#include <sound/pcm_params.h> 26#include <sound/pcm_params.h>
27#include <sound/soc.h> 27#include <sound/soc.h>
28#include <sound/soc-dapm.h>
29#include <sound/tlv.h> 28#include <sound/tlv.h>
30#include <sound/initval.h> 29#include <sound/initval.h>
31 30
@@ -34,7 +33,6 @@
34/* codec private data */ 33/* codec private data */
35struct wm8711_priv { 34struct wm8711_priv {
36 enum snd_soc_control_type bus_type; 35 enum snd_soc_control_type bus_type;
37 u16 reg_cache[WM8711_CACHEREGNUM];
38 unsigned int sysclk; 36 unsigned int sysclk;
39}; 37};
40 38
@@ -93,10 +91,11 @@ static const struct snd_soc_dapm_route intercon[] = {
93 91
94static int wm8711_add_widgets(struct snd_soc_codec *codec) 92static int wm8711_add_widgets(struct snd_soc_codec *codec)
95{ 93{
96 snd_soc_dapm_new_controls(codec, wm8711_dapm_widgets, 94 struct snd_soc_dapm_context *dapm = &codec->dapm;
97 ARRAY_SIZE(wm8711_dapm_widgets));
98 95
99 snd_soc_dapm_add_routes(codec, intercon, ARRAY_SIZE(intercon)); 96 snd_soc_dapm_new_controls(dapm, wm8711_dapm_widgets,
97 ARRAY_SIZE(wm8711_dapm_widgets));
98 snd_soc_dapm_add_routes(dapm, intercon, ARRAY_SIZE(intercon));
100 99
101 return 0; 100 return 0;
102} 101}
@@ -318,7 +317,7 @@ static int wm8711_set_bias_level(struct snd_soc_codec *codec,
318 snd_soc_write(codec, WM8711_PWR, 0xffff); 317 snd_soc_write(codec, WM8711_PWR, 0xffff);
319 break; 318 break;
320 } 319 }
321 codec->bias_level = level; 320 codec->dapm.bias_level = level;
322 return 0; 321 return 0;
323} 322}
324 323
diff --git a/sound/soc/codecs/wm8728.c b/sound/soc/codecs/wm8728.c
index 075f35e4f4cb..736b0352d0a7 100644
--- a/sound/soc/codecs/wm8728.c
+++ b/sound/soc/codecs/wm8728.c
@@ -23,7 +23,6 @@
23#include <sound/pcm.h> 23#include <sound/pcm.h>
24#include <sound/pcm_params.h> 24#include <sound/pcm_params.h>
25#include <sound/soc.h> 25#include <sound/soc.h>
26#include <sound/soc-dapm.h>
27#include <sound/initval.h> 26#include <sound/initval.h>
28#include <sound/tlv.h> 27#include <sound/tlv.h>
29 28
@@ -73,10 +72,11 @@ static const struct snd_soc_dapm_route intercon[] = {
73 72
74static int wm8728_add_widgets(struct snd_soc_codec *codec) 73static int wm8728_add_widgets(struct snd_soc_codec *codec)
75{ 74{
76 snd_soc_dapm_new_controls(codec, wm8728_dapm_widgets, 75 struct snd_soc_dapm_context *dapm = &codec->dapm;
77 ARRAY_SIZE(wm8728_dapm_widgets));
78 76
79 snd_soc_dapm_add_routes(codec, intercon, ARRAY_SIZE(intercon)); 77 snd_soc_dapm_new_controls(dapm, wm8728_dapm_widgets,
78 ARRAY_SIZE(wm8728_dapm_widgets));
79 snd_soc_dapm_add_routes(dapm, intercon, ARRAY_SIZE(intercon));
80 80
81 return 0; 81 return 0;
82} 82}
@@ -180,7 +180,7 @@ static int wm8728_set_bias_level(struct snd_soc_codec *codec,
180 case SND_SOC_BIAS_ON: 180 case SND_SOC_BIAS_ON:
181 case SND_SOC_BIAS_PREPARE: 181 case SND_SOC_BIAS_PREPARE:
182 case SND_SOC_BIAS_STANDBY: 182 case SND_SOC_BIAS_STANDBY:
183 if (codec->bias_level == SND_SOC_BIAS_OFF) { 183 if (codec->dapm.bias_level == SND_SOC_BIAS_OFF) {
184 /* Power everything up... */ 184 /* Power everything up... */
185 reg = snd_soc_read(codec, WM8728_DACCTL); 185 reg = snd_soc_read(codec, WM8728_DACCTL);
186 snd_soc_write(codec, WM8728_DACCTL, reg & ~0x4); 186 snd_soc_write(codec, WM8728_DACCTL, reg & ~0x4);
@@ -197,7 +197,7 @@ static int wm8728_set_bias_level(struct snd_soc_codec *codec,
197 snd_soc_write(codec, WM8728_DACCTL, reg | 0x4); 197 snd_soc_write(codec, WM8728_DACCTL, reg | 0x4);
198 break; 198 break;
199 } 199 }
200 codec->bias_level = level; 200 codec->dapm.bias_level = level;
201 return 0; 201 return 0;
202} 202}
203 203
diff --git a/sound/soc/codecs/wm8731.c b/sound/soc/codecs/wm8731.c
index e725c09a3e79..0a67c31b2663 100644
--- a/sound/soc/codecs/wm8731.c
+++ b/sound/soc/codecs/wm8731.c
@@ -26,7 +26,6 @@
26#include <sound/pcm.h> 26#include <sound/pcm.h>
27#include <sound/pcm_params.h> 27#include <sound/pcm_params.h>
28#include <sound/soc.h> 28#include <sound/soc.h>
29#include <sound/soc-dapm.h>
30#include <sound/initval.h> 29#include <sound/initval.h>
31#include <sound/tlv.h> 30#include <sound/tlv.h>
32 31
@@ -44,9 +43,10 @@ static const char *wm8731_supply_names[WM8731_NUM_SUPPLIES] = {
44struct wm8731_priv { 43struct wm8731_priv {
45 enum snd_soc_control_type control_type; 44 enum snd_soc_control_type control_type;
46 struct regulator_bulk_data supplies[WM8731_NUM_SUPPLIES]; 45 struct regulator_bulk_data supplies[WM8731_NUM_SUPPLIES];
47 u16 reg_cache[WM8731_CACHEREGNUM];
48 unsigned int sysclk; 46 unsigned int sysclk;
49 int sysclk_type; 47 int sysclk_type;
48 int playback_fs;
49 bool deemph;
50}; 50};
51 51
52 52
@@ -65,16 +65,79 @@ static const u16 wm8731_reg[WM8731_CACHEREGNUM] = {
65#define wm8731_reset(c) snd_soc_write(c, WM8731_RESET, 0) 65#define wm8731_reset(c) snd_soc_write(c, WM8731_RESET, 0)
66 66
67static const char *wm8731_input_select[] = {"Line In", "Mic"}; 67static const char *wm8731_input_select[] = {"Line In", "Mic"};
68static const char *wm8731_deemph[] = {"None", "32Khz", "44.1Khz", "48Khz"};
69 68
70static const struct soc_enum wm8731_enum[] = { 69static const struct soc_enum wm8731_insel_enum =
71 SOC_ENUM_SINGLE(WM8731_APANA, 2, 2, wm8731_input_select), 70 SOC_ENUM_SINGLE(WM8731_APANA, 2, 2, wm8731_input_select);
72 SOC_ENUM_SINGLE(WM8731_APDIGI, 1, 4, wm8731_deemph), 71
73}; 72static int wm8731_deemph[] = { 0, 32000, 44100, 48000 };
73
74static int wm8731_set_deemph(struct snd_soc_codec *codec)
75{
76 struct wm8731_priv *wm8731 = snd_soc_codec_get_drvdata(codec);
77 int val, i, best;
78
79 /* If we're using deemphasis select the nearest available sample
80 * rate.
81 */
82 if (wm8731->deemph) {
83 best = 1;
84 for (i = 2; i < ARRAY_SIZE(wm8731_deemph); i++) {
85 if (abs(wm8731_deemph[i] - wm8731->playback_fs) <
86 abs(wm8731_deemph[best] - wm8731->playback_fs))
87 best = i;
88 }
89
90 val = best << 1;
91 } else {
92 best = 0;
93 val = 0;
94 }
95
96 dev_dbg(codec->dev, "Set deemphasis %d (%dHz)\n",
97 best, wm8731_deemph[best]);
98
99 return snd_soc_update_bits(codec, WM8731_APDIGI, 0x6, val);
100}
101
102static int wm8731_get_deemph(struct snd_kcontrol *kcontrol,
103 struct snd_ctl_elem_value *ucontrol)
104{
105 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
106 struct wm8731_priv *wm8731 = snd_soc_codec_get_drvdata(codec);
107
108 ucontrol->value.enumerated.item[0] = wm8731->deemph;
109
110 return 0;
111}
112
113static int wm8731_put_deemph(struct snd_kcontrol *kcontrol,
114 struct snd_ctl_elem_value *ucontrol)
115{
116 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
117 struct wm8731_priv *wm8731 = snd_soc_codec_get_drvdata(codec);
118 int deemph = ucontrol->value.enumerated.item[0];
119 int ret = 0;
120
121 if (deemph > 1)
122 return -EINVAL;
123
124 mutex_lock(&codec->mutex);
125 if (wm8731->deemph != deemph) {
126 wm8731->deemph = deemph;
127
128 wm8731_set_deemph(codec);
129
130 ret = 1;
131 }
132 mutex_unlock(&codec->mutex);
133
134 return ret;
135}
74 136
75static const DECLARE_TLV_DB_SCALE(in_tlv, -3450, 150, 0); 137static const DECLARE_TLV_DB_SCALE(in_tlv, -3450, 150, 0);
76static const DECLARE_TLV_DB_SCALE(sidetone_tlv, -1500, 300, 0); 138static const DECLARE_TLV_DB_SCALE(sidetone_tlv, -1500, 300, 0);
77static const DECLARE_TLV_DB_SCALE(out_tlv, -12100, 100, 1); 139static const DECLARE_TLV_DB_SCALE(out_tlv, -12100, 100, 1);
140static const DECLARE_TLV_DB_SCALE(mic_tlv, 0, 2000, 0);
78 141
79static const struct snd_kcontrol_new wm8731_snd_controls[] = { 142static const struct snd_kcontrol_new wm8731_snd_controls[] = {
80 143
@@ -87,7 +150,7 @@ SOC_DOUBLE_R_TLV("Capture Volume", WM8731_LINVOL, WM8731_RINVOL, 0, 31, 0,
87 in_tlv), 150 in_tlv),
88SOC_DOUBLE_R("Line Capture Switch", WM8731_LINVOL, WM8731_RINVOL, 7, 1, 1), 151SOC_DOUBLE_R("Line Capture Switch", WM8731_LINVOL, WM8731_RINVOL, 7, 1, 1),
89 152
90SOC_SINGLE("Mic Boost (+20dB)", WM8731_APANA, 0, 1, 0), 153SOC_SINGLE_TLV("Mic Boost Volume", WM8731_APANA, 0, 1, 0, mic_tlv),
91SOC_SINGLE("Mic Capture Switch", WM8731_APANA, 1, 1, 1), 154SOC_SINGLE("Mic Capture Switch", WM8731_APANA, 1, 1, 1),
92 155
93SOC_SINGLE_TLV("Sidetone Playback Volume", WM8731_APANA, 6, 3, 1, 156SOC_SINGLE_TLV("Sidetone Playback Volume", WM8731_APANA, 6, 3, 1,
@@ -96,7 +159,8 @@ SOC_SINGLE_TLV("Sidetone Playback Volume", WM8731_APANA, 6, 3, 1,
96SOC_SINGLE("ADC High Pass Filter Switch", WM8731_APDIGI, 0, 1, 1), 159SOC_SINGLE("ADC High Pass Filter Switch", WM8731_APDIGI, 0, 1, 1),
97SOC_SINGLE("Store DC Offset Switch", WM8731_APDIGI, 4, 1, 0), 160SOC_SINGLE("Store DC Offset Switch", WM8731_APDIGI, 4, 1, 0),
98 161
99SOC_ENUM("Playback De-emphasis", wm8731_enum[1]), 162SOC_SINGLE_BOOL_EXT("Playback Deemphasis Switch", 0,
163 wm8731_get_deemph, wm8731_put_deemph),
100}; 164};
101 165
102/* Output Mixer */ 166/* Output Mixer */
@@ -108,7 +172,7 @@ SOC_DAPM_SINGLE("HiFi Playback Switch", WM8731_APANA, 4, 1, 0),
108 172
109/* Input mux */ 173/* Input mux */
110static const struct snd_kcontrol_new wm8731_input_mux_controls = 174static const struct snd_kcontrol_new wm8731_input_mux_controls =
111SOC_DAPM_ENUM("Input Select", wm8731_enum[0]); 175SOC_DAPM_ENUM("Input Select", wm8731_insel_enum);
112 176
113static const struct snd_soc_dapm_widget wm8731_dapm_widgets[] = { 177static const struct snd_soc_dapm_widget wm8731_dapm_widgets[] = {
114SND_SOC_DAPM_SUPPLY("OSC", WM8731_PWR, 5, 1, NULL, 0), 178SND_SOC_DAPM_SUPPLY("OSC", WM8731_PWR, 5, 1, NULL, 0),
@@ -165,10 +229,11 @@ static const struct snd_soc_dapm_route intercon[] = {
165 229
166static int wm8731_add_widgets(struct snd_soc_codec *codec) 230static int wm8731_add_widgets(struct snd_soc_codec *codec)
167{ 231{
168 snd_soc_dapm_new_controls(codec, wm8731_dapm_widgets, 232 struct snd_soc_dapm_context *dapm = &codec->dapm;
169 ARRAY_SIZE(wm8731_dapm_widgets));
170 233
171 snd_soc_dapm_add_routes(codec, intercon, ARRAY_SIZE(intercon)); 234 snd_soc_dapm_new_controls(dapm, wm8731_dapm_widgets,
235 ARRAY_SIZE(wm8731_dapm_widgets));
236 snd_soc_dapm_add_routes(dapm, intercon, ARRAY_SIZE(intercon));
172 237
173 return 0; 238 return 0;
174} 239}
@@ -239,6 +304,8 @@ static int wm8731_hw_params(struct snd_pcm_substream *substream,
239 u16 srate = (coeff_div[i].sr << 2) | 304 u16 srate = (coeff_div[i].sr << 2) |
240 (coeff_div[i].bosr << 1) | coeff_div[i].usb; 305 (coeff_div[i].bosr << 1) | coeff_div[i].usb;
241 306
307 wm8731->playback_fs = params_rate(params);
308
242 snd_soc_write(codec, WM8731_SRATE, srate); 309 snd_soc_write(codec, WM8731_SRATE, srate);
243 310
244 /* bit size */ 311 /* bit size */
@@ -253,6 +320,8 @@ static int wm8731_hw_params(struct snd_pcm_substream *substream,
253 break; 320 break;
254 } 321 }
255 322
323 wm8731_set_deemph(codec);
324
256 snd_soc_write(codec, WM8731_IFACE, iface); 325 snd_soc_write(codec, WM8731_IFACE, iface);
257 return 0; 326 return 0;
258} 327}
@@ -319,7 +388,7 @@ static int wm8731_set_dai_sysclk(struct snd_soc_dai *codec_dai,
319 return -EINVAL; 388 return -EINVAL;
320 } 389 }
321 390
322 snd_soc_dapm_sync(codec); 391 snd_soc_dapm_sync(&codec->dapm);
323 392
324 return 0; 393 return 0;
325} 394}
@@ -399,7 +468,7 @@ static int wm8731_set_bias_level(struct snd_soc_codec *codec,
399 case SND_SOC_BIAS_PREPARE: 468 case SND_SOC_BIAS_PREPARE:
400 break; 469 break;
401 case SND_SOC_BIAS_STANDBY: 470 case SND_SOC_BIAS_STANDBY:
402 if (codec->bias_level == SND_SOC_BIAS_OFF) { 471 if (codec->dapm.bias_level == SND_SOC_BIAS_OFF) {
403 ret = regulator_bulk_enable(ARRAY_SIZE(wm8731->supplies), 472 ret = regulator_bulk_enable(ARRAY_SIZE(wm8731->supplies),
404 wm8731->supplies); 473 wm8731->supplies);
405 if (ret != 0) 474 if (ret != 0)
@@ -428,7 +497,7 @@ static int wm8731_set_bias_level(struct snd_soc_codec *codec,
428 wm8731->supplies); 497 wm8731->supplies);
429 break; 498 break;
430 } 499 }
431 codec->bias_level = level; 500 codec->dapm.bias_level = level;
432 return 0; 501 return 0;
433} 502}
434 503
@@ -542,7 +611,6 @@ err_regulator_enable:
542err_regulator_get: 611err_regulator_get:
543 regulator_bulk_free(ARRAY_SIZE(wm8731->supplies), wm8731->supplies); 612 regulator_bulk_free(ARRAY_SIZE(wm8731->supplies), wm8731->supplies);
544 613
545 kfree(wm8731);
546 return ret; 614 return ret;
547} 615}
548 616
diff --git a/sound/soc/codecs/wm8737.c b/sound/soc/codecs/wm8737.c
new file mode 100644
index 000000000000..30c67d06a904
--- /dev/null
+++ b/sound/soc/codecs/wm8737.c
@@ -0,0 +1,754 @@
1/*
2 * wm8737.c -- WM8737 ALSA SoC Audio driver
3 *
4 * Copyright 2010 Wolfson Microelectronics plc
5 *
6 * Author: Mark Brown <broonie@opensource.wolfsonmicro.com>
7 *
8 * This program is free software; you can redistribute it and/or modify
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/moduleparam.h>
15#include <linux/init.h>
16#include <linux/delay.h>
17#include <linux/pm.h>
18#include <linux/i2c.h>
19#include <linux/platform_device.h>
20#include <linux/regulator/consumer.h>
21#include <linux/spi/spi.h>
22#include <linux/slab.h>
23#include <sound/core.h>
24#include <sound/pcm.h>
25#include <sound/pcm_params.h>
26#include <sound/soc.h>
27#include <sound/soc-dapm.h>
28#include <sound/initval.h>
29#include <sound/tlv.h>
30
31#include "wm8737.h"
32
33#define WM8737_NUM_SUPPLIES 4
34static const char *wm8737_supply_names[WM8737_NUM_SUPPLIES] = {
35 "DCVDD",
36 "DBVDD",
37 "AVDD",
38 "MVDD",
39};
40
41/* codec private data */
42struct wm8737_priv {
43 enum snd_soc_control_type control_type;
44 struct regulator_bulk_data supplies[WM8737_NUM_SUPPLIES];
45 unsigned int mclk;
46};
47
48static const u16 wm8737_reg[WM8737_REGISTER_COUNT] = {
49 0x00C3, /* R0 - Left PGA volume */
50 0x00C3, /* R1 - Right PGA volume */
51 0x0007, /* R2 - AUDIO path L */
52 0x0007, /* R3 - AUDIO path R */
53 0x0000, /* R4 - 3D Enhance */
54 0x0000, /* R5 - ADC Control */
55 0x0000, /* R6 - Power Management */
56 0x000A, /* R7 - Audio Format */
57 0x0000, /* R8 - Clocking */
58 0x000F, /* R9 - MIC Preamp Control */
59 0x0003, /* R10 - Misc Bias Control */
60 0x0000, /* R11 - Noise Gate */
61 0x007C, /* R12 - ALC1 */
62 0x0000, /* R13 - ALC2 */
63 0x0032, /* R14 - ALC3 */
64};
65
66static int wm8737_reset(struct snd_soc_codec *codec)
67{
68 return snd_soc_write(codec, WM8737_RESET, 0);
69}
70
71static const unsigned int micboost_tlv[] = {
72 TLV_DB_RANGE_HEAD(4),
73 0, 0, TLV_DB_SCALE_ITEM(1300, 0, 0),
74 1, 1, TLV_DB_SCALE_ITEM(1800, 0, 0),
75 2, 2, TLV_DB_SCALE_ITEM(2800, 0, 0),
76 3, 3, TLV_DB_SCALE_ITEM(3300, 0, 0),
77};
78static const DECLARE_TLV_DB_SCALE(pga_tlv, -9750, 50, 1);
79static const DECLARE_TLV_DB_SCALE(adc_tlv, -600, 600, 0);
80static const DECLARE_TLV_DB_SCALE(ng_tlv, -7800, 600, 0);
81static const DECLARE_TLV_DB_SCALE(alc_max_tlv, -1200, 600, 0);
82static const DECLARE_TLV_DB_SCALE(alc_target_tlv, -1800, 100, 0);
83
84static const char *micbias_enum_text[] = {
85 "25%",
86 "50%",
87 "75%",
88 "100%",
89};
90
91static const struct soc_enum micbias_enum =
92 SOC_ENUM_SINGLE(WM8737_MIC_PREAMP_CONTROL, 0, 4, micbias_enum_text);
93
94static const char *low_cutoff_text[] = {
95 "Low", "High"
96};
97
98static const struct soc_enum low_3d =
99 SOC_ENUM_SINGLE(WM8737_3D_ENHANCE, 6, 2, low_cutoff_text);
100
101static const char *high_cutoff_text[] = {
102 "High", "Low"
103};
104
105static const struct soc_enum high_3d =
106 SOC_ENUM_SINGLE(WM8737_3D_ENHANCE, 5, 2, high_cutoff_text);
107
108static const char *alc_fn_text[] = {
109 "Disabled", "Right", "Left", "Stereo"
110};
111
112static const struct soc_enum alc_fn =
113 SOC_ENUM_SINGLE(WM8737_ALC1, 7, 4, alc_fn_text);
114
115static const char *alc_hold_text[] = {
116 "0", "2.67ms", "5.33ms", "10.66ms", "21.32ms", "42.64ms", "85.28ms",
117 "170.56ms", "341.12ms", "682.24ms", "1.364s", "2.728s", "5.458s",
118 "10.916s", "21.832s", "43.691s"
119};
120
121static const struct soc_enum alc_hold =
122 SOC_ENUM_SINGLE(WM8737_ALC2, 0, 16, alc_hold_text);
123
124static const char *alc_atk_text[] = {
125 "8.4ms", "16.8ms", "33.6ms", "67.2ms", "134.4ms", "268.8ms", "537.6ms",
126 "1.075s", "2.15s", "4.3s", "8.6s"
127};
128
129static const struct soc_enum alc_atk =
130 SOC_ENUM_SINGLE(WM8737_ALC3, 0, 11, alc_atk_text);
131
132static const char *alc_dcy_text[] = {
133 "33.6ms", "67.2ms", "134.4ms", "268.8ms", "537.6ms", "1.075s", "2.15s",
134 "4.3s", "8.6s", "17.2s", "34.41s"
135};
136
137static const struct soc_enum alc_dcy =
138 SOC_ENUM_SINGLE(WM8737_ALC3, 4, 11, alc_dcy_text);
139
140static const struct snd_kcontrol_new wm8737_snd_controls[] = {
141SOC_DOUBLE_R_TLV("Mic Boost Volume", WM8737_AUDIO_PATH_L, WM8737_AUDIO_PATH_R,
142 6, 3, 0, micboost_tlv),
143SOC_DOUBLE_R("Mic Boost Switch", WM8737_AUDIO_PATH_L, WM8737_AUDIO_PATH_R,
144 4, 1, 0),
145SOC_DOUBLE("Mic ZC Switch", WM8737_AUDIO_PATH_L, WM8737_AUDIO_PATH_R,
146 3, 1, 0),
147
148SOC_DOUBLE_R_TLV("Capture Volume", WM8737_LEFT_PGA_VOLUME,
149 WM8737_RIGHT_PGA_VOLUME, 0, 255, 0, pga_tlv),
150SOC_DOUBLE("Capture ZC Switch", WM8737_AUDIO_PATH_L, WM8737_AUDIO_PATH_R,
151 2, 1, 0),
152
153SOC_DOUBLE("INPUT1 DC Bias Switch", WM8737_MISC_BIAS_CONTROL, 0, 1, 1, 0),
154
155SOC_ENUM("Mic PGA Bias", micbias_enum),
156SOC_SINGLE("ADC Low Power Switch", WM8737_ADC_CONTROL, 2, 1, 0),
157SOC_SINGLE("High Pass Filter Switch", WM8737_ADC_CONTROL, 0, 1, 1),
158SOC_DOUBLE("Polarity Invert Switch", WM8737_ADC_CONTROL, 5, 6, 1, 0),
159
160SOC_SINGLE("3D Switch", WM8737_3D_ENHANCE, 0, 1, 0),
161SOC_SINGLE("3D Depth", WM8737_3D_ENHANCE, 1, 15, 0),
162SOC_ENUM("3D Low Cut-off", low_3d),
163SOC_ENUM("3D High Cut-off", low_3d),
164SOC_SINGLE_TLV("3D ADC Volume", WM8737_3D_ENHANCE, 7, 1, 1, adc_tlv),
165
166SOC_SINGLE("Noise Gate Switch", WM8737_NOISE_GATE, 0, 1, 0),
167SOC_SINGLE_TLV("Noise Gate Threshold Volume", WM8737_NOISE_GATE, 2, 7, 0,
168 ng_tlv),
169
170SOC_ENUM("ALC", alc_fn),
171SOC_SINGLE_TLV("ALC Max Gain Volume", WM8737_ALC1, 4, 7, 0, alc_max_tlv),
172SOC_SINGLE_TLV("ALC Target Volume", WM8737_ALC1, 0, 15, 0, alc_target_tlv),
173SOC_ENUM("ALC Hold Time", alc_hold),
174SOC_SINGLE("ALC ZC Switch", WM8737_ALC2, 4, 1, 0),
175SOC_ENUM("ALC Attack Time", alc_atk),
176SOC_ENUM("ALC Decay Time", alc_dcy),
177};
178
179static const char *linsel_text[] = {
180 "LINPUT1", "LINPUT2", "LINPUT3", "LINPUT1 DC",
181};
182
183static const struct soc_enum linsel_enum =
184 SOC_ENUM_SINGLE(WM8737_AUDIO_PATH_L, 7, 4, linsel_text);
185
186static const struct snd_kcontrol_new linsel_mux =
187 SOC_DAPM_ENUM("LINSEL", linsel_enum);
188
189
190static const char *rinsel_text[] = {
191 "RINPUT1", "RINPUT2", "RINPUT3", "RINPUT1 DC",
192};
193
194static const struct soc_enum rinsel_enum =
195 SOC_ENUM_SINGLE(WM8737_AUDIO_PATH_R, 7, 4, rinsel_text);
196
197static const struct snd_kcontrol_new rinsel_mux =
198 SOC_DAPM_ENUM("RINSEL", rinsel_enum);
199
200static const char *bypass_text[] = {
201 "Direct", "Preamp"
202};
203
204static const struct soc_enum lbypass_enum =
205 SOC_ENUM_SINGLE(WM8737_MIC_PREAMP_CONTROL, 2, 2, bypass_text);
206
207static const struct snd_kcontrol_new lbypass_mux =
208 SOC_DAPM_ENUM("Left Bypass", lbypass_enum);
209
210
211static const struct soc_enum rbypass_enum =
212 SOC_ENUM_SINGLE(WM8737_MIC_PREAMP_CONTROL, 3, 2, bypass_text);
213
214static const struct snd_kcontrol_new rbypass_mux =
215 SOC_DAPM_ENUM("Left Bypass", rbypass_enum);
216
217static const struct snd_soc_dapm_widget wm8737_dapm_widgets[] = {
218SND_SOC_DAPM_INPUT("LINPUT1"),
219SND_SOC_DAPM_INPUT("LINPUT2"),
220SND_SOC_DAPM_INPUT("LINPUT3"),
221SND_SOC_DAPM_INPUT("RINPUT1"),
222SND_SOC_DAPM_INPUT("RINPUT2"),
223SND_SOC_DAPM_INPUT("RINPUT3"),
224SND_SOC_DAPM_INPUT("LACIN"),
225SND_SOC_DAPM_INPUT("RACIN"),
226
227SND_SOC_DAPM_MUX("LINSEL", SND_SOC_NOPM, 0, 0, &linsel_mux),
228SND_SOC_DAPM_MUX("RINSEL", SND_SOC_NOPM, 0, 0, &rinsel_mux),
229
230SND_SOC_DAPM_MUX("Left Preamp Mux", SND_SOC_NOPM, 0, 0, &lbypass_mux),
231SND_SOC_DAPM_MUX("Right Preamp Mux", SND_SOC_NOPM, 0, 0, &rbypass_mux),
232
233SND_SOC_DAPM_PGA("PGAL", WM8737_POWER_MANAGEMENT, 5, 0, NULL, 0),
234SND_SOC_DAPM_PGA("PGAR", WM8737_POWER_MANAGEMENT, 4, 0, NULL, 0),
235
236SND_SOC_DAPM_DAC("ADCL", NULL, WM8737_POWER_MANAGEMENT, 3, 0),
237SND_SOC_DAPM_DAC("ADCR", NULL, WM8737_POWER_MANAGEMENT, 2, 0),
238
239SND_SOC_DAPM_AIF_OUT("AIF", "Capture", 0, WM8737_POWER_MANAGEMENT, 6, 0),
240};
241
242static const struct snd_soc_dapm_route intercon[] = {
243 { "LINSEL", "LINPUT1", "LINPUT1" },
244 { "LINSEL", "LINPUT2", "LINPUT2" },
245 { "LINSEL", "LINPUT3", "LINPUT3" },
246 { "LINSEL", "LINPUT1 DC", "LINPUT1" },
247
248 { "RINSEL", "RINPUT1", "RINPUT1" },
249 { "RINSEL", "RINPUT2", "RINPUT2" },
250 { "RINSEL", "RINPUT3", "RINPUT3" },
251 { "RINSEL", "RINPUT1 DC", "RINPUT1" },
252
253 { "Left Preamp Mux", "Preamp", "LINSEL" },
254 { "Left Preamp Mux", "Direct", "LACIN" },
255
256 { "Right Preamp Mux", "Preamp", "RINSEL" },
257 { "Right Preamp Mux", "Direct", "RACIN" },
258
259 { "PGAL", NULL, "Left Preamp Mux" },
260 { "PGAR", NULL, "Right Preamp Mux" },
261
262 { "ADCL", NULL, "PGAL" },
263 { "ADCR", NULL, "PGAR" },
264
265 { "AIF", NULL, "ADCL" },
266 { "AIF", NULL, "ADCR" },
267};
268
269static int wm8737_add_widgets(struct snd_soc_codec *codec)
270{
271 struct snd_soc_dapm_context *dapm = &codec->dapm;
272
273 snd_soc_dapm_new_controls(dapm, wm8737_dapm_widgets,
274 ARRAY_SIZE(wm8737_dapm_widgets));
275 snd_soc_dapm_add_routes(dapm, intercon, ARRAY_SIZE(intercon));
276
277 return 0;
278}
279
280/* codec mclk clock divider coefficients */
281static const struct {
282 u32 mclk;
283 u32 rate;
284 u8 usb;
285 u8 sr;
286} coeff_div[] = {
287 { 12288000, 8000, 0, 0x4 },
288 { 12288000, 12000, 0, 0x8 },
289 { 12288000, 16000, 0, 0xa },
290 { 12288000, 24000, 0, 0x1c },
291 { 12288000, 32000, 0, 0xc },
292 { 12288000, 48000, 0, 0 },
293 { 12288000, 96000, 0, 0xe },
294
295 { 11289600, 8000, 0, 0x14 },
296 { 11289600, 11025, 0, 0x18 },
297 { 11289600, 22050, 0, 0x1a },
298 { 11289600, 44100, 0, 0x10 },
299 { 11289600, 88200, 0, 0x1e },
300
301 { 18432000, 8000, 0, 0x5 },
302 { 18432000, 12000, 0, 0x9 },
303 { 18432000, 16000, 0, 0xb },
304 { 18432000, 24000, 0, 0x1b },
305 { 18432000, 32000, 0, 0xd },
306 { 18432000, 48000, 0, 0x1 },
307 { 18432000, 96000, 0, 0x1f },
308
309 { 16934400, 8000, 0, 0x15 },
310 { 16934400, 11025, 0, 0x19 },
311 { 16934400, 22050, 0, 0x1b },
312 { 16934400, 44100, 0, 0x11 },
313 { 16934400, 88200, 0, 0x1f },
314
315 { 12000000, 8000, 1, 0x4 },
316 { 12000000, 11025, 1, 0x19 },
317 { 12000000, 12000, 1, 0x8 },
318 { 12000000, 16000, 1, 0xa },
319 { 12000000, 22050, 1, 0x1b },
320 { 12000000, 24000, 1, 0x1c },
321 { 12000000, 32000, 1, 0xc },
322 { 12000000, 44100, 1, 0x11 },
323 { 12000000, 48000, 1, 0x0 },
324 { 12000000, 88200, 1, 0x1f },
325 { 12000000, 96000, 1, 0xe },
326};
327
328static int wm8737_hw_params(struct snd_pcm_substream *substream,
329 struct snd_pcm_hw_params *params,
330 struct snd_soc_dai *dai)
331{
332 struct snd_soc_pcm_runtime *rtd = substream->private_data;
333 struct snd_soc_codec *codec = rtd->codec;
334 struct wm8737_priv *wm8737 = snd_soc_codec_get_drvdata(codec);
335 int i;
336 u16 clocking = 0;
337 u16 af = 0;
338
339 for (i = 0; i < ARRAY_SIZE(coeff_div); i++) {
340 if (coeff_div[i].rate != params_rate(params))
341 continue;
342
343 if (coeff_div[i].mclk == wm8737->mclk)
344 break;
345
346 if (coeff_div[i].mclk == wm8737->mclk * 2) {
347 clocking |= WM8737_CLKDIV2;
348 break;
349 }
350 }
351
352 if (i == ARRAY_SIZE(coeff_div)) {
353 dev_err(codec->dev, "%dHz MCLK can't support %dHz\n",
354 wm8737->mclk, params_rate(params));
355 return -EINVAL;
356 }
357
358 clocking |= coeff_div[i].usb | (coeff_div[i].sr << WM8737_SR_SHIFT);
359
360 switch (params_format(params)) {
361 case SNDRV_PCM_FORMAT_S16_LE:
362 break;
363 case SNDRV_PCM_FORMAT_S20_3LE:
364 af |= 0x8;
365 break;
366 case SNDRV_PCM_FORMAT_S24_LE:
367 af |= 0x10;
368 break;
369 case SNDRV_PCM_FORMAT_S32_LE:
370 af |= 0x18;
371 break;
372 default:
373 return -EINVAL;
374 }
375
376 snd_soc_update_bits(codec, WM8737_AUDIO_FORMAT, WM8737_WL_MASK, af);
377 snd_soc_update_bits(codec, WM8737_CLOCKING,
378 WM8737_USB_MODE | WM8737_CLKDIV2 | WM8737_SR_MASK,
379 clocking);
380
381 return 0;
382}
383
384static int wm8737_set_dai_sysclk(struct snd_soc_dai *codec_dai,
385 int clk_id, unsigned int freq, int dir)
386{
387 struct snd_soc_codec *codec = codec_dai->codec;
388 struct wm8737_priv *wm8737 = snd_soc_codec_get_drvdata(codec);
389 int i;
390
391 for (i = 0; i < ARRAY_SIZE(coeff_div); i++) {
392 if (freq == coeff_div[i].mclk ||
393 freq == coeff_div[i].mclk * 2) {
394 wm8737->mclk = freq;
395 return 0;
396 }
397 }
398
399 dev_err(codec->dev, "MCLK rate %dHz not supported\n", freq);
400
401 return -EINVAL;
402}
403
404
405static int wm8737_set_dai_fmt(struct snd_soc_dai *codec_dai,
406 unsigned int fmt)
407{
408 struct snd_soc_codec *codec = codec_dai->codec;
409 u16 af = 0;
410
411 switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
412 case SND_SOC_DAIFMT_CBM_CFM:
413 af |= WM8737_MS;
414 break;
415 case SND_SOC_DAIFMT_CBS_CFS:
416 break;
417 default:
418 return -EINVAL;
419 }
420
421 switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
422 case SND_SOC_DAIFMT_I2S:
423 af |= 0x2;
424 break;
425 case SND_SOC_DAIFMT_RIGHT_J:
426 break;
427 case SND_SOC_DAIFMT_LEFT_J:
428 af |= 0x1;
429 break;
430 case SND_SOC_DAIFMT_DSP_A:
431 af |= 0x3;
432 break;
433 case SND_SOC_DAIFMT_DSP_B:
434 af |= 0x13;
435 break;
436 default:
437 return -EINVAL;
438 }
439
440 switch (fmt & SND_SOC_DAIFMT_INV_MASK) {
441 case SND_SOC_DAIFMT_NB_NF:
442 break;
443 case SND_SOC_DAIFMT_NB_IF:
444 af |= WM8737_LRP;
445 break;
446 default:
447 return -EINVAL;
448 }
449
450 snd_soc_update_bits(codec, WM8737_AUDIO_FORMAT,
451 WM8737_FORMAT_MASK | WM8737_LRP | WM8737_MS, af);
452
453 return 0;
454}
455
456static int wm8737_set_bias_level(struct snd_soc_codec *codec,
457 enum snd_soc_bias_level level)
458{
459 struct wm8737_priv *wm8737 = snd_soc_codec_get_drvdata(codec);
460 int ret;
461
462 switch (level) {
463 case SND_SOC_BIAS_ON:
464 break;
465
466 case SND_SOC_BIAS_PREPARE:
467 /* VMID at 2*75k */
468 snd_soc_update_bits(codec, WM8737_MISC_BIAS_CONTROL,
469 WM8737_VMIDSEL_MASK, 0);
470 break;
471
472 case SND_SOC_BIAS_STANDBY:
473 if (codec->dapm.bias_level == SND_SOC_BIAS_OFF) {
474 ret = regulator_bulk_enable(ARRAY_SIZE(wm8737->supplies),
475 wm8737->supplies);
476 if (ret != 0) {
477 dev_err(codec->dev,
478 "Failed to enable supplies: %d\n",
479 ret);
480 return ret;
481 }
482
483 snd_soc_cache_sync(codec);
484
485 /* Fast VMID ramp at 2*2.5k */
486 snd_soc_update_bits(codec, WM8737_MISC_BIAS_CONTROL,
487 WM8737_VMIDSEL_MASK, 0x4);
488
489 /* Bring VMID up */
490 snd_soc_update_bits(codec, WM8737_POWER_MANAGEMENT,
491 WM8737_VMID_MASK |
492 WM8737_VREF_MASK,
493 WM8737_VMID_MASK |
494 WM8737_VREF_MASK);
495
496 msleep(500);
497 }
498
499 /* VMID at 2*300k */
500 snd_soc_update_bits(codec, WM8737_MISC_BIAS_CONTROL,
501 WM8737_VMIDSEL_MASK, 2);
502
503 break;
504
505 case SND_SOC_BIAS_OFF:
506 snd_soc_update_bits(codec, WM8737_POWER_MANAGEMENT,
507 WM8737_VMID_MASK | WM8737_VREF_MASK, 0);
508
509 regulator_bulk_disable(ARRAY_SIZE(wm8737->supplies),
510 wm8737->supplies);
511 break;
512 }
513
514 codec->dapm.bias_level = level;
515 return 0;
516}
517
518#define WM8737_RATES SNDRV_PCM_RATE_8000_96000
519
520#define WM8737_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE |\
521 SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S32_LE)
522
523static struct snd_soc_dai_ops wm8737_dai_ops = {
524 .hw_params = wm8737_hw_params,
525 .set_sysclk = wm8737_set_dai_sysclk,
526 .set_fmt = wm8737_set_dai_fmt,
527};
528
529static struct snd_soc_dai_driver wm8737_dai = {
530 .name = "wm8737",
531 .capture = {
532 .stream_name = "Capture",
533 .channels_min = 2, /* Mono modes not yet supported */
534 .channels_max = 2,
535 .rates = WM8737_RATES,
536 .formats = WM8737_FORMATS,
537 },
538 .ops = &wm8737_dai_ops,
539};
540
541#ifdef CONFIG_PM
542static int wm8737_suspend(struct snd_soc_codec *codec, pm_message_t state)
543{
544 wm8737_set_bias_level(codec, SND_SOC_BIAS_OFF);
545 return 0;
546}
547
548static int wm8737_resume(struct snd_soc_codec *codec)
549{
550 wm8737_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
551 return 0;
552}
553#else
554#define wm8737_suspend NULL
555#define wm8737_resume NULL
556#endif
557
558static int wm8737_probe(struct snd_soc_codec *codec)
559{
560 struct wm8737_priv *wm8737 = snd_soc_codec_get_drvdata(codec);
561 int ret, i;
562
563 ret = snd_soc_codec_set_cache_io(codec, 7, 9, wm8737->control_type);
564 if (ret != 0) {
565 dev_err(codec->dev, "Failed to set cache I/O: %d\n", ret);
566 return ret;
567 }
568
569 for (i = 0; i < ARRAY_SIZE(wm8737->supplies); i++)
570 wm8737->supplies[i].supply = wm8737_supply_names[i];
571
572 ret = regulator_bulk_get(codec->dev, ARRAY_SIZE(wm8737->supplies),
573 wm8737->supplies);
574 if (ret != 0) {
575 dev_err(codec->dev, "Failed to request supplies: %d\n", ret);
576 return ret;
577 }
578
579 ret = regulator_bulk_enable(ARRAY_SIZE(wm8737->supplies),
580 wm8737->supplies);
581 if (ret != 0) {
582 dev_err(codec->dev, "Failed to enable supplies: %d\n", ret);
583 goto err_get;
584 }
585
586 ret = wm8737_reset(codec);
587 if (ret < 0) {
588 dev_err(codec->dev, "Failed to issue reset\n");
589 goto err_enable;
590 }
591
592 snd_soc_update_bits(codec, WM8737_LEFT_PGA_VOLUME, WM8737_LVU,
593 WM8737_LVU);
594 snd_soc_update_bits(codec, WM8737_RIGHT_PGA_VOLUME, WM8737_RVU,
595 WM8737_RVU);
596
597 wm8737_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
598
599 /* Bias level configuration will have done an extra enable */
600 regulator_bulk_disable(ARRAY_SIZE(wm8737->supplies), wm8737->supplies);
601
602 snd_soc_add_controls(codec, wm8737_snd_controls,
603 ARRAY_SIZE(wm8737_snd_controls));
604 wm8737_add_widgets(codec);
605
606 return 0;
607
608err_enable:
609 regulator_bulk_disable(ARRAY_SIZE(wm8737->supplies), wm8737->supplies);
610err_get:
611 regulator_bulk_free(ARRAY_SIZE(wm8737->supplies), wm8737->supplies);
612
613 return ret;
614}
615
616static int wm8737_remove(struct snd_soc_codec *codec)
617{
618 struct wm8737_priv *wm8737 = snd_soc_codec_get_drvdata(codec);
619
620 wm8737_set_bias_level(codec, SND_SOC_BIAS_OFF);
621 regulator_bulk_free(ARRAY_SIZE(wm8737->supplies), wm8737->supplies);
622 return 0;
623}
624
625static struct snd_soc_codec_driver soc_codec_dev_wm8737 = {
626 .probe = wm8737_probe,
627 .remove = wm8737_remove,
628 .suspend = wm8737_suspend,
629 .resume = wm8737_resume,
630 .set_bias_level = wm8737_set_bias_level,
631
632 .reg_cache_size = WM8737_REGISTER_COUNT - 1, /* Skip reset */
633 .reg_word_size = sizeof(u16),
634 .reg_cache_default = wm8737_reg,
635};
636
637#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
638static __devinit int wm8737_i2c_probe(struct i2c_client *i2c,
639 const struct i2c_device_id *id)
640{
641 struct wm8737_priv *wm8737;
642 int ret;
643
644 wm8737 = kzalloc(sizeof(struct wm8737_priv), GFP_KERNEL);
645 if (wm8737 == NULL)
646 return -ENOMEM;
647
648 i2c_set_clientdata(i2c, wm8737);
649 wm8737->control_type = SND_SOC_I2C;
650
651 ret = snd_soc_register_codec(&i2c->dev,
652 &soc_codec_dev_wm8737, &wm8737_dai, 1);
653 if (ret < 0)
654 kfree(wm8737);
655 return ret;
656
657}
658
659static __devexit int wm8737_i2c_remove(struct i2c_client *client)
660{
661 snd_soc_unregister_codec(&client->dev);
662 kfree(i2c_get_clientdata(client));
663 return 0;
664}
665
666static const struct i2c_device_id wm8737_i2c_id[] = {
667 { "wm8737", 0 },
668 { }
669};
670MODULE_DEVICE_TABLE(i2c, wm8737_i2c_id);
671
672static struct i2c_driver wm8737_i2c_driver = {
673 .driver = {
674 .name = "wm8737",
675 .owner = THIS_MODULE,
676 },
677 .probe = wm8737_i2c_probe,
678 .remove = __devexit_p(wm8737_i2c_remove),
679 .id_table = wm8737_i2c_id,
680};
681#endif
682
683#if defined(CONFIG_SPI_MASTER)
684static int __devinit wm8737_spi_probe(struct spi_device *spi)
685{
686 struct wm8737_priv *wm8737;
687 int ret;
688
689 wm8737 = kzalloc(sizeof(struct wm8737_priv), GFP_KERNEL);
690 if (wm8737 == NULL)
691 return -ENOMEM;
692
693 wm8737->control_type = SND_SOC_SPI;
694 spi_set_drvdata(spi, wm8737);
695
696 ret = snd_soc_register_codec(&spi->dev,
697 &soc_codec_dev_wm8737, &wm8737_dai, 1);
698 if (ret < 0)
699 kfree(wm8737);
700 return ret;
701}
702
703static int __devexit wm8737_spi_remove(struct spi_device *spi)
704{
705 snd_soc_unregister_codec(&spi->dev);
706 kfree(spi_get_drvdata(spi));
707 return 0;
708}
709
710static struct spi_driver wm8737_spi_driver = {
711 .driver = {
712 .name = "wm8737",
713 .owner = THIS_MODULE,
714 },
715 .probe = wm8737_spi_probe,
716 .remove = __devexit_p(wm8737_spi_remove),
717};
718#endif /* CONFIG_SPI_MASTER */
719
720static int __init wm8737_modinit(void)
721{
722 int ret;
723#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
724 ret = i2c_add_driver(&wm8737_i2c_driver);
725 if (ret != 0) {
726 printk(KERN_ERR "Failed to register WM8737 I2C driver: %d\n",
727 ret);
728 }
729#endif
730#if defined(CONFIG_SPI_MASTER)
731 ret = spi_register_driver(&wm8737_spi_driver);
732 if (ret != 0) {
733 printk(KERN_ERR "Failed to register WM8737 SPI driver: %d\n",
734 ret);
735 }
736#endif
737 return 0;
738}
739module_init(wm8737_modinit);
740
741static void __exit wm8737_exit(void)
742{
743#if defined(CONFIG_SPI_MASTER)
744 spi_unregister_driver(&wm8737_spi_driver);
745#endif
746#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
747 i2c_del_driver(&wm8737_i2c_driver);
748#endif
749}
750module_exit(wm8737_exit);
751
752MODULE_DESCRIPTION("ASoC WM8737 driver");
753MODULE_AUTHOR("Mark Brown <broonie@opensource.wolfsonmicro.com>");
754MODULE_LICENSE("GPL");
diff --git a/sound/soc/codecs/wm8737.h b/sound/soc/codecs/wm8737.h
new file mode 100644
index 000000000000..23d14c8ff6e7
--- /dev/null
+++ b/sound/soc/codecs/wm8737.h
@@ -0,0 +1,322 @@
1#ifndef _WM8737_H
2#define _WM8737_H
3
4/*
5 * wm8737.c -- WM8523 ALSA SoC Audio driver
6 *
7 * Copyright 2010 Wolfson Microelectronics plc
8 *
9 * Author: Mark Brown <broonie@opensource.wolfsonmicro.com>
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License version 2 as
13 * published by the Free Software Foundation.
14 */
15
16/*
17 * Register values.
18 */
19#define WM8737_LEFT_PGA_VOLUME 0x00
20#define WM8737_RIGHT_PGA_VOLUME 0x01
21#define WM8737_AUDIO_PATH_L 0x02
22#define WM8737_AUDIO_PATH_R 0x03
23#define WM8737_3D_ENHANCE 0x04
24#define WM8737_ADC_CONTROL 0x05
25#define WM8737_POWER_MANAGEMENT 0x06
26#define WM8737_AUDIO_FORMAT 0x07
27#define WM8737_CLOCKING 0x08
28#define WM8737_MIC_PREAMP_CONTROL 0x09
29#define WM8737_MISC_BIAS_CONTROL 0x0A
30#define WM8737_NOISE_GATE 0x0B
31#define WM8737_ALC1 0x0C
32#define WM8737_ALC2 0x0D
33#define WM8737_ALC3 0x0E
34#define WM8737_RESET 0x0F
35
36#define WM8737_REGISTER_COUNT 16
37#define WM8737_MAX_REGISTER 0x0F
38
39/*
40 * Field Definitions.
41 */
42
43/*
44 * R0 (0x00) - Left PGA volume
45 */
46#define WM8737_LVU 0x0100 /* LVU */
47#define WM8737_LVU_MASK 0x0100 /* LVU */
48#define WM8737_LVU_SHIFT 8 /* LVU */
49#define WM8737_LVU_WIDTH 1 /* LVU */
50#define WM8737_LINVOL_MASK 0x00FF /* LINVOL - [7:0] */
51#define WM8737_LINVOL_SHIFT 0 /* LINVOL - [7:0] */
52#define WM8737_LINVOL_WIDTH 8 /* LINVOL - [7:0] */
53
54/*
55 * R1 (0x01) - Right PGA volume
56 */
57#define WM8737_RVU 0x0100 /* RVU */
58#define WM8737_RVU_MASK 0x0100 /* RVU */
59#define WM8737_RVU_SHIFT 8 /* RVU */
60#define WM8737_RVU_WIDTH 1 /* RVU */
61#define WM8737_RINVOL_MASK 0x00FF /* RINVOL - [7:0] */
62#define WM8737_RINVOL_SHIFT 0 /* RINVOL - [7:0] */
63#define WM8737_RINVOL_WIDTH 8 /* RINVOL - [7:0] */
64
65/*
66 * R2 (0x02) - AUDIO path L
67 */
68#define WM8737_LINSEL_MASK 0x0180 /* LINSEL - [8:7] */
69#define WM8737_LINSEL_SHIFT 7 /* LINSEL - [8:7] */
70#define WM8737_LINSEL_WIDTH 2 /* LINSEL - [8:7] */
71#define WM8737_LMICBOOST_MASK 0x0060 /* LMICBOOST - [6:5] */
72#define WM8737_LMICBOOST_SHIFT 5 /* LMICBOOST - [6:5] */
73#define WM8737_LMICBOOST_WIDTH 2 /* LMICBOOST - [6:5] */
74#define WM8737_LMBE 0x0010 /* LMBE */
75#define WM8737_LMBE_MASK 0x0010 /* LMBE */
76#define WM8737_LMBE_SHIFT 4 /* LMBE */
77#define WM8737_LMBE_WIDTH 1 /* LMBE */
78#define WM8737_LMZC 0x0008 /* LMZC */
79#define WM8737_LMZC_MASK 0x0008 /* LMZC */
80#define WM8737_LMZC_SHIFT 3 /* LMZC */
81#define WM8737_LMZC_WIDTH 1 /* LMZC */
82#define WM8737_LPZC 0x0004 /* LPZC */
83#define WM8737_LPZC_MASK 0x0004 /* LPZC */
84#define WM8737_LPZC_SHIFT 2 /* LPZC */
85#define WM8737_LPZC_WIDTH 1 /* LPZC */
86#define WM8737_LZCTO_MASK 0x0003 /* LZCTO - [1:0] */
87#define WM8737_LZCTO_SHIFT 0 /* LZCTO - [1:0] */
88#define WM8737_LZCTO_WIDTH 2 /* LZCTO - [1:0] */
89
90/*
91 * R3 (0x03) - AUDIO path R
92 */
93#define WM8737_RINSEL_MASK 0x0180 /* RINSEL - [8:7] */
94#define WM8737_RINSEL_SHIFT 7 /* RINSEL - [8:7] */
95#define WM8737_RINSEL_WIDTH 2 /* RINSEL - [8:7] */
96#define WM8737_RMICBOOST_MASK 0x0060 /* RMICBOOST - [6:5] */
97#define WM8737_RMICBOOST_SHIFT 5 /* RMICBOOST - [6:5] */
98#define WM8737_RMICBOOST_WIDTH 2 /* RMICBOOST - [6:5] */
99#define WM8737_RMBE 0x0010 /* RMBE */
100#define WM8737_RMBE_MASK 0x0010 /* RMBE */
101#define WM8737_RMBE_SHIFT 4 /* RMBE */
102#define WM8737_RMBE_WIDTH 1 /* RMBE */
103#define WM8737_RMZC 0x0008 /* RMZC */
104#define WM8737_RMZC_MASK 0x0008 /* RMZC */
105#define WM8737_RMZC_SHIFT 3 /* RMZC */
106#define WM8737_RMZC_WIDTH 1 /* RMZC */
107#define WM8737_RPZC 0x0004 /* RPZC */
108#define WM8737_RPZC_MASK 0x0004 /* RPZC */
109#define WM8737_RPZC_SHIFT 2 /* RPZC */
110#define WM8737_RPZC_WIDTH 1 /* RPZC */
111#define WM8737_RZCTO_MASK 0x0003 /* RZCTO - [1:0] */
112#define WM8737_RZCTO_SHIFT 0 /* RZCTO - [1:0] */
113#define WM8737_RZCTO_WIDTH 2 /* RZCTO - [1:0] */
114
115/*
116 * R4 (0x04) - 3D Enhance
117 */
118#define WM8737_DIV2 0x0080 /* DIV2 */
119#define WM8737_DIV2_MASK 0x0080 /* DIV2 */
120#define WM8737_DIV2_SHIFT 7 /* DIV2 */
121#define WM8737_DIV2_WIDTH 1 /* DIV2 */
122#define WM8737_3DLC 0x0040 /* 3DLC */
123#define WM8737_3DLC_MASK 0x0040 /* 3DLC */
124#define WM8737_3DLC_SHIFT 6 /* 3DLC */
125#define WM8737_3DLC_WIDTH 1 /* 3DLC */
126#define WM8737_3DUC 0x0020 /* 3DUC */
127#define WM8737_3DUC_MASK 0x0020 /* 3DUC */
128#define WM8737_3DUC_SHIFT 5 /* 3DUC */
129#define WM8737_3DUC_WIDTH 1 /* 3DUC */
130#define WM8737_3DDEPTH_MASK 0x001E /* 3DDEPTH - [4:1] */
131#define WM8737_3DDEPTH_SHIFT 1 /* 3DDEPTH - [4:1] */
132#define WM8737_3DDEPTH_WIDTH 4 /* 3DDEPTH - [4:1] */
133#define WM8737_3DE 0x0001 /* 3DE */
134#define WM8737_3DE_MASK 0x0001 /* 3DE */
135#define WM8737_3DE_SHIFT 0 /* 3DE */
136#define WM8737_3DE_WIDTH 1 /* 3DE */
137
138/*
139 * R5 (0x05) - ADC Control
140 */
141#define WM8737_MONOMIX_MASK 0x0180 /* MONOMIX - [8:7] */
142#define WM8737_MONOMIX_SHIFT 7 /* MONOMIX - [8:7] */
143#define WM8737_MONOMIX_WIDTH 2 /* MONOMIX - [8:7] */
144#define WM8737_POLARITY_MASK 0x0060 /* POLARITY - [6:5] */
145#define WM8737_POLARITY_SHIFT 5 /* POLARITY - [6:5] */
146#define WM8737_POLARITY_WIDTH 2 /* POLARITY - [6:5] */
147#define WM8737_HPOR 0x0010 /* HPOR */
148#define WM8737_HPOR_MASK 0x0010 /* HPOR */
149#define WM8737_HPOR_SHIFT 4 /* HPOR */
150#define WM8737_HPOR_WIDTH 1 /* HPOR */
151#define WM8737_LP 0x0004 /* LP */
152#define WM8737_LP_MASK 0x0004 /* LP */
153#define WM8737_LP_SHIFT 2 /* LP */
154#define WM8737_LP_WIDTH 1 /* LP */
155#define WM8737_MONOUT 0x0002 /* MONOUT */
156#define WM8737_MONOUT_MASK 0x0002 /* MONOUT */
157#define WM8737_MONOUT_SHIFT 1 /* MONOUT */
158#define WM8737_MONOUT_WIDTH 1 /* MONOUT */
159#define WM8737_ADCHPD 0x0001 /* ADCHPD */
160#define WM8737_ADCHPD_MASK 0x0001 /* ADCHPD */
161#define WM8737_ADCHPD_SHIFT 0 /* ADCHPD */
162#define WM8737_ADCHPD_WIDTH 1 /* ADCHPD */
163
164/*
165 * R6 (0x06) - Power Management
166 */
167#define WM8737_VMID 0x0100 /* VMID */
168#define WM8737_VMID_MASK 0x0100 /* VMID */
169#define WM8737_VMID_SHIFT 8 /* VMID */
170#define WM8737_VMID_WIDTH 1 /* VMID */
171#define WM8737_VREF 0x0080 /* VREF */
172#define WM8737_VREF_MASK 0x0080 /* VREF */
173#define WM8737_VREF_SHIFT 7 /* VREF */
174#define WM8737_VREF_WIDTH 1 /* VREF */
175#define WM8737_AI 0x0040 /* AI */
176#define WM8737_AI_MASK 0x0040 /* AI */
177#define WM8737_AI_SHIFT 6 /* AI */
178#define WM8737_AI_WIDTH 1 /* AI */
179#define WM8737_PGL 0x0020 /* PGL */
180#define WM8737_PGL_MASK 0x0020 /* PGL */
181#define WM8737_PGL_SHIFT 5 /* PGL */
182#define WM8737_PGL_WIDTH 1 /* PGL */
183#define WM8737_PGR 0x0010 /* PGR */
184#define WM8737_PGR_MASK 0x0010 /* PGR */
185#define WM8737_PGR_SHIFT 4 /* PGR */
186#define WM8737_PGR_WIDTH 1 /* PGR */
187#define WM8737_ADL 0x0008 /* ADL */
188#define WM8737_ADL_MASK 0x0008 /* ADL */
189#define WM8737_ADL_SHIFT 3 /* ADL */
190#define WM8737_ADL_WIDTH 1 /* ADL */
191#define WM8737_ADR 0x0004 /* ADR */
192#define WM8737_ADR_MASK 0x0004 /* ADR */
193#define WM8737_ADR_SHIFT 2 /* ADR */
194#define WM8737_ADR_WIDTH 1 /* ADR */
195#define WM8737_MICBIAS_MASK 0x0003 /* MICBIAS - [1:0] */
196#define WM8737_MICBIAS_SHIFT 0 /* MICBIAS - [1:0] */
197#define WM8737_MICBIAS_WIDTH 2 /* MICBIAS - [1:0] */
198
199/*
200 * R7 (0x07) - Audio Format
201 */
202#define WM8737_SDODIS 0x0080 /* SDODIS */
203#define WM8737_SDODIS_MASK 0x0080 /* SDODIS */
204#define WM8737_SDODIS_SHIFT 7 /* SDODIS */
205#define WM8737_SDODIS_WIDTH 1 /* SDODIS */
206#define WM8737_MS 0x0040 /* MS */
207#define WM8737_MS_MASK 0x0040 /* MS */
208#define WM8737_MS_SHIFT 6 /* MS */
209#define WM8737_MS_WIDTH 1 /* MS */
210#define WM8737_LRP 0x0010 /* LRP */
211#define WM8737_LRP_MASK 0x0010 /* LRP */
212#define WM8737_LRP_SHIFT 4 /* LRP */
213#define WM8737_LRP_WIDTH 1 /* LRP */
214#define WM8737_WL_MASK 0x000C /* WL - [3:2] */
215#define WM8737_WL_SHIFT 2 /* WL - [3:2] */
216#define WM8737_WL_WIDTH 2 /* WL - [3:2] */
217#define WM8737_FORMAT_MASK 0x0003 /* FORMAT - [1:0] */
218#define WM8737_FORMAT_SHIFT 0 /* FORMAT - [1:0] */
219#define WM8737_FORMAT_WIDTH 2 /* FORMAT - [1:0] */
220
221/*
222 * R8 (0x08) - Clocking
223 */
224#define WM8737_AUTODETECT 0x0080 /* AUTODETECT */
225#define WM8737_AUTODETECT_MASK 0x0080 /* AUTODETECT */
226#define WM8737_AUTODETECT_SHIFT 7 /* AUTODETECT */
227#define WM8737_AUTODETECT_WIDTH 1 /* AUTODETECT */
228#define WM8737_CLKDIV2 0x0040 /* CLKDIV2 */
229#define WM8737_CLKDIV2_MASK 0x0040 /* CLKDIV2 */
230#define WM8737_CLKDIV2_SHIFT 6 /* CLKDIV2 */
231#define WM8737_CLKDIV2_WIDTH 1 /* CLKDIV2 */
232#define WM8737_SR_MASK 0x003E /* SR - [5:1] */
233#define WM8737_SR_SHIFT 1 /* SR - [5:1] */
234#define WM8737_SR_WIDTH 5 /* SR - [5:1] */
235#define WM8737_USB_MODE 0x0001 /* USB MODE */
236#define WM8737_USB_MODE_MASK 0x0001 /* USB MODE */
237#define WM8737_USB_MODE_SHIFT 0 /* USB MODE */
238#define WM8737_USB_MODE_WIDTH 1 /* USB MODE */
239
240/*
241 * R9 (0x09) - MIC Preamp Control
242 */
243#define WM8737_RBYPEN 0x0008 /* RBYPEN */
244#define WM8737_RBYPEN_MASK 0x0008 /* RBYPEN */
245#define WM8737_RBYPEN_SHIFT 3 /* RBYPEN */
246#define WM8737_RBYPEN_WIDTH 1 /* RBYPEN */
247#define WM8737_LBYPEN 0x0004 /* LBYPEN */
248#define WM8737_LBYPEN_MASK 0x0004 /* LBYPEN */
249#define WM8737_LBYPEN_SHIFT 2 /* LBYPEN */
250#define WM8737_LBYPEN_WIDTH 1 /* LBYPEN */
251#define WM8737_MBCTRL_MASK 0x0003 /* MBCTRL - [1:0] */
252#define WM8737_MBCTRL_SHIFT 0 /* MBCTRL - [1:0] */
253#define WM8737_MBCTRL_WIDTH 2 /* MBCTRL - [1:0] */
254
255/*
256 * R10 (0x0A) - Misc Bias Control
257 */
258#define WM8737_VMIDSEL_MASK 0x000C /* VMIDSEL - [3:2] */
259#define WM8737_VMIDSEL_SHIFT 2 /* VMIDSEL - [3:2] */
260#define WM8737_VMIDSEL_WIDTH 2 /* VMIDSEL - [3:2] */
261#define WM8737_LINPUT1_DC_BIAS_ENABLE 0x0002 /* LINPUT1 DC BIAS ENABLE */
262#define WM8737_LINPUT1_DC_BIAS_ENABLE_MASK 0x0002 /* LINPUT1 DC BIAS ENABLE */
263#define WM8737_LINPUT1_DC_BIAS_ENABLE_SHIFT 1 /* LINPUT1 DC BIAS ENABLE */
264#define WM8737_LINPUT1_DC_BIAS_ENABLE_WIDTH 1 /* LINPUT1 DC BIAS ENABLE */
265#define WM8737_RINPUT1_DC_BIAS_ENABLE 0x0001 /* RINPUT1 DC BIAS ENABLE */
266#define WM8737_RINPUT1_DC_BIAS_ENABLE_MASK 0x0001 /* RINPUT1 DC BIAS ENABLE */
267#define WM8737_RINPUT1_DC_BIAS_ENABLE_SHIFT 0 /* RINPUT1 DC BIAS ENABLE */
268#define WM8737_RINPUT1_DC_BIAS_ENABLE_WIDTH 1 /* RINPUT1 DC BIAS ENABLE */
269
270/*
271 * R11 (0x0B) - Noise Gate
272 */
273#define WM8737_NGTH_MASK 0x001C /* NGTH - [4:2] */
274#define WM8737_NGTH_SHIFT 2 /* NGTH - [4:2] */
275#define WM8737_NGTH_WIDTH 3 /* NGTH - [4:2] */
276#define WM8737_NGAT 0x0001 /* NGAT */
277#define WM8737_NGAT_MASK 0x0001 /* NGAT */
278#define WM8737_NGAT_SHIFT 0 /* NGAT */
279#define WM8737_NGAT_WIDTH 1 /* NGAT */
280
281/*
282 * R12 (0x0C) - ALC1
283 */
284#define WM8737_ALCSEL_MASK 0x0180 /* ALCSEL - [8:7] */
285#define WM8737_ALCSEL_SHIFT 7 /* ALCSEL - [8:7] */
286#define WM8737_ALCSEL_WIDTH 2 /* ALCSEL - [8:7] */
287#define WM8737_MAX_GAIN_MASK 0x0070 /* MAX GAIN - [6:4] */
288#define WM8737_MAX_GAIN_SHIFT 4 /* MAX GAIN - [6:4] */
289#define WM8737_MAX_GAIN_WIDTH 3 /* MAX GAIN - [6:4] */
290#define WM8737_ALCL_MASK 0x000F /* ALCL - [3:0] */
291#define WM8737_ALCL_SHIFT 0 /* ALCL - [3:0] */
292#define WM8737_ALCL_WIDTH 4 /* ALCL - [3:0] */
293
294/*
295 * R13 (0x0D) - ALC2
296 */
297#define WM8737_ALCZCE 0x0010 /* ALCZCE */
298#define WM8737_ALCZCE_MASK 0x0010 /* ALCZCE */
299#define WM8737_ALCZCE_SHIFT 4 /* ALCZCE */
300#define WM8737_ALCZCE_WIDTH 1 /* ALCZCE */
301#define WM8737_HLD_MASK 0x000F /* HLD - [3:0] */
302#define WM8737_HLD_SHIFT 0 /* HLD - [3:0] */
303#define WM8737_HLD_WIDTH 4 /* HLD - [3:0] */
304
305/*
306 * R14 (0x0E) - ALC3
307 */
308#define WM8737_DCY_MASK 0x00F0 /* DCY - [7:4] */
309#define WM8737_DCY_SHIFT 4 /* DCY - [7:4] */
310#define WM8737_DCY_WIDTH 4 /* DCY - [7:4] */
311#define WM8737_ATK_MASK 0x000F /* ATK - [3:0] */
312#define WM8737_ATK_SHIFT 0 /* ATK - [3:0] */
313#define WM8737_ATK_WIDTH 4 /* ATK - [3:0] */
314
315/*
316 * R15 (0x0F) - Reset
317 */
318#define WM8737_RESET_MASK 0x01FF /* RESET - [8:0] */
319#define WM8737_RESET_SHIFT 0 /* RESET - [8:0] */
320#define WM8737_RESET_WIDTH 9 /* RESET - [8:0] */
321
322#endif
diff --git a/sound/soc/codecs/wm8741.c b/sound/soc/codecs/wm8741.c
index aea60ef8aba7..494f2d31d75b 100644
--- a/sound/soc/codecs/wm8741.c
+++ b/sound/soc/codecs/wm8741.c
@@ -24,7 +24,6 @@
24#include <sound/pcm.h> 24#include <sound/pcm.h>
25#include <sound/pcm_params.h> 25#include <sound/pcm_params.h>
26#include <sound/soc.h> 26#include <sound/soc.h>
27#include <sound/soc-dapm.h>
28#include <sound/initval.h> 27#include <sound/initval.h>
29#include <sound/tlv.h> 28#include <sound/tlv.h>
30 29
@@ -94,10 +93,11 @@ static const struct snd_soc_dapm_route intercon[] = {
94 93
95static int wm8741_add_widgets(struct snd_soc_codec *codec) 94static int wm8741_add_widgets(struct snd_soc_codec *codec)
96{ 95{
97 snd_soc_dapm_new_controls(codec, wm8741_dapm_widgets, 96 struct snd_soc_dapm_context *dapm = &codec->dapm;
98 ARRAY_SIZE(wm8741_dapm_widgets));
99 97
100 snd_soc_dapm_add_routes(codec, intercon, ARRAY_SIZE(intercon)); 98 snd_soc_dapm_new_controls(dapm, wm8741_dapm_widgets,
99 ARRAY_SIZE(wm8741_dapm_widgets));
100 snd_soc_dapm_add_routes(dapm, intercon, ARRAY_SIZE(intercon));
101 101
102 return 0; 102 return 0;
103} 103}
@@ -455,7 +455,7 @@ static struct snd_soc_codec_driver soc_codec_dev_wm8741 = {
455 .resume = wm8741_resume, 455 .resume = wm8741_resume,
456 .reg_cache_size = ARRAY_SIZE(wm8741_reg_defaults), 456 .reg_cache_size = ARRAY_SIZE(wm8741_reg_defaults),
457 .reg_word_size = sizeof(u16), 457 .reg_word_size = sizeof(u16),
458 .reg_cache_default = &wm8741_reg_defaults, 458 .reg_cache_default = wm8741_reg_defaults,
459}; 459};
460 460
461#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE) 461#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
diff --git a/sound/soc/codecs/wm8750.c b/sound/soc/codecs/wm8750.c
index 6c924cd2cfd4..38f38fddd190 100644
--- a/sound/soc/codecs/wm8750.c
+++ b/sound/soc/codecs/wm8750.c
@@ -25,7 +25,6 @@
25#include <sound/pcm.h> 25#include <sound/pcm.h>
26#include <sound/pcm_params.h> 26#include <sound/pcm_params.h>
27#include <sound/soc.h> 27#include <sound/soc.h>
28#include <sound/soc-dapm.h>
29#include <sound/initval.h> 28#include <sound/initval.h>
30 29
31#include "wm8750.h" 30#include "wm8750.h"
@@ -53,7 +52,6 @@ static const u16 wm8750_reg[] = {
53struct wm8750_priv { 52struct wm8750_priv {
54 unsigned int sysclk; 53 unsigned int sysclk;
55 enum snd_soc_control_type control_type; 54 enum snd_soc_control_type control_type;
56 u16 reg_cache[ARRAY_SIZE(wm8750_reg)];
57}; 55};
58 56
59#define wm8750_reset(c) snd_soc_write(c, WM8750_RESET, 0) 57#define wm8750_reset(c) snd_soc_write(c, WM8750_RESET, 0)
@@ -399,10 +397,11 @@ static const struct snd_soc_dapm_route audio_map[] = {
399 397
400static int wm8750_add_widgets(struct snd_soc_codec *codec) 398static int wm8750_add_widgets(struct snd_soc_codec *codec)
401{ 399{
402 snd_soc_dapm_new_controls(codec, wm8750_dapm_widgets, 400 struct snd_soc_dapm_context *dapm = &codec->dapm;
403 ARRAY_SIZE(wm8750_dapm_widgets));
404 401
405 snd_soc_dapm_add_routes(codec, audio_map, ARRAY_SIZE(audio_map)); 402 snd_soc_dapm_new_controls(dapm, wm8750_dapm_widgets,
403 ARRAY_SIZE(wm8750_dapm_widgets));
404 snd_soc_dapm_add_routes(dapm, audio_map, ARRAY_SIZE(audio_map));
406 405
407 return 0; 406 return 0;
408} 407}
@@ -615,7 +614,7 @@ static int wm8750_set_bias_level(struct snd_soc_codec *codec,
615 case SND_SOC_BIAS_PREPARE: 614 case SND_SOC_BIAS_PREPARE:
616 break; 615 break;
617 case SND_SOC_BIAS_STANDBY: 616 case SND_SOC_BIAS_STANDBY:
618 if (codec->bias_level == SND_SOC_BIAS_OFF) { 617 if (codec->dapm.bias_level == SND_SOC_BIAS_OFF) {
619 /* Set VMID to 5k */ 618 /* Set VMID to 5k */
620 snd_soc_write(codec, WM8750_PWR1, pwr_reg | 0x01c1); 619 snd_soc_write(codec, WM8750_PWR1, pwr_reg | 0x01c1);
621 620
@@ -630,7 +629,7 @@ static int wm8750_set_bias_level(struct snd_soc_codec *codec,
630 snd_soc_write(codec, WM8750_PWR1, 0x0001); 629 snd_soc_write(codec, WM8750_PWR1, 0x0001);
631 break; 630 break;
632 } 631 }
633 codec->bias_level = level; 632 codec->dapm.bias_level = level;
634 return 0; 633 return 0;
635} 634}
636 635
diff --git a/sound/soc/codecs/wm8753.c b/sound/soc/codecs/wm8753.c
index 87caae59e939..79b02ae125c5 100644
--- a/sound/soc/codecs/wm8753.c
+++ b/sound/soc/codecs/wm8753.c
@@ -45,7 +45,6 @@
45#include <sound/pcm.h> 45#include <sound/pcm.h>
46#include <sound/pcm_params.h> 46#include <sound/pcm_params.h>
47#include <sound/soc.h> 47#include <sound/soc.h>
48#include <sound/soc-dapm.h>
49#include <sound/initval.h> 48#include <sound/initval.h>
50#include <sound/tlv.h> 49#include <sound/tlv.h>
51#include <asm/div64.h> 50#include <asm/div64.h>
@@ -623,10 +622,11 @@ static const struct snd_soc_dapm_route audio_map[] = {
623 622
624static int wm8753_add_widgets(struct snd_soc_codec *codec) 623static int wm8753_add_widgets(struct snd_soc_codec *codec)
625{ 624{
626 snd_soc_dapm_new_controls(codec, wm8753_dapm_widgets, 625 struct snd_soc_dapm_context *dapm = &codec->dapm;
627 ARRAY_SIZE(wm8753_dapm_widgets));
628 626
629 snd_soc_dapm_add_routes(codec, audio_map, ARRAY_SIZE(audio_map)); 627 snd_soc_dapm_new_controls(dapm, wm8753_dapm_widgets,
628 ARRAY_SIZE(wm8753_dapm_widgets));
629 snd_soc_dapm_add_routes(dapm, audio_map, ARRAY_SIZE(audio_map));
630 630
631 return 0; 631 return 0;
632} 632}
@@ -1245,7 +1245,7 @@ static int wm8753_set_bias_level(struct snd_soc_codec *codec,
1245 snd_soc_write(codec, WM8753_PWR1, 0x0001); 1245 snd_soc_write(codec, WM8753_PWR1, 0x0001);
1246 break; 1246 break;
1247 } 1247 }
1248 codec->bias_level = level; 1248 codec->dapm.bias_level = level;
1249 return 0; 1249 return 0;
1250} 1250}
1251 1251
@@ -1435,9 +1435,11 @@ static void wm8753_set_dai_mode(struct snd_soc_codec *codec,
1435 1435
1436static void wm8753_work(struct work_struct *work) 1436static void wm8753_work(struct work_struct *work)
1437{ 1437{
1438 struct snd_soc_codec *codec = 1438 struct snd_soc_dapm_context *dapm =
1439 container_of(work, struct snd_soc_codec, delayed_work.work); 1439 container_of(work, struct snd_soc_dapm_context,
1440 wm8753_set_bias_level(codec, codec->bias_level); 1440 delayed_work.work);
1441 struct snd_soc_codec *codec = dapm->codec;
1442 wm8753_set_bias_level(codec, dapm->bias_level);
1441} 1443}
1442 1444
1443static int wm8753_suspend(struct snd_soc_codec *codec, pm_message_t state) 1445static int wm8753_suspend(struct snd_soc_codec *codec, pm_message_t state)
@@ -1466,41 +1468,22 @@ static int wm8753_resume(struct snd_soc_codec *codec)
1466 wm8753_set_bias_level(codec, SND_SOC_BIAS_STANDBY); 1468 wm8753_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
1467 1469
1468 /* charge wm8753 caps */ 1470 /* charge wm8753 caps */
1469 if (codec->suspend_bias_level == SND_SOC_BIAS_ON) { 1471 if (codec->dapm.suspend_bias_level == SND_SOC_BIAS_ON) {
1470 wm8753_set_bias_level(codec, SND_SOC_BIAS_PREPARE); 1472 wm8753_set_bias_level(codec, SND_SOC_BIAS_PREPARE);
1471 codec->bias_level = SND_SOC_BIAS_ON; 1473 codec->dapm.bias_level = SND_SOC_BIAS_ON;
1472 schedule_delayed_work(&codec->delayed_work, 1474 schedule_delayed_work(&codec->dapm.delayed_work,
1473 msecs_to_jiffies(caps_charge)); 1475 msecs_to_jiffies(caps_charge));
1474 } 1476 }
1475 1477
1476 return 0; 1478 return 0;
1477} 1479}
1478 1480
1479/*
1480 * This function forces any delayed work to be queued and run.
1481 */
1482static int run_delayed_work(struct delayed_work *dwork)
1483{
1484 int ret;
1485
1486 /* cancel any work waiting to be queued. */
1487 ret = cancel_delayed_work(dwork);
1488
1489 /* if there was any work waiting then we run it now and
1490 * wait for it's completion */
1491 if (ret) {
1492 schedule_delayed_work(dwork, 0);
1493 flush_scheduled_work();
1494 }
1495 return ret;
1496}
1497
1498static int wm8753_probe(struct snd_soc_codec *codec) 1481static int wm8753_probe(struct snd_soc_codec *codec)
1499{ 1482{
1500 struct wm8753_priv *wm8753 = snd_soc_codec_get_drvdata(codec); 1483 struct wm8753_priv *wm8753 = snd_soc_codec_get_drvdata(codec);
1501 int ret; 1484 int ret;
1502 1485
1503 INIT_DELAYED_WORK(&codec->delayed_work, wm8753_work); 1486 INIT_DELAYED_WORK(&codec->dapm.delayed_work, wm8753_work);
1504 1487
1505 ret = snd_soc_codec_set_cache_io(codec, 7, 9, wm8753->control_type); 1488 ret = snd_soc_codec_set_cache_io(codec, 7, 9, wm8753->control_type);
1506 if (ret < 0) { 1489 if (ret < 0) {
@@ -1519,7 +1502,7 @@ static int wm8753_probe(struct snd_soc_codec *codec)
1519 1502
1520 /* charge output caps */ 1503 /* charge output caps */
1521 wm8753_set_bias_level(codec, SND_SOC_BIAS_PREPARE); 1504 wm8753_set_bias_level(codec, SND_SOC_BIAS_PREPARE);
1522 schedule_delayed_work(&codec->delayed_work, 1505 schedule_delayed_work(&codec->dapm.delayed_work,
1523 msecs_to_jiffies(caps_charge)); 1506 msecs_to_jiffies(caps_charge));
1524 1507
1525 /* set the update bits */ 1508 /* set the update bits */
@@ -1544,7 +1527,7 @@ static int wm8753_probe(struct snd_soc_codec *codec)
1544/* power down chip */ 1527/* power down chip */
1545static int wm8753_remove(struct snd_soc_codec *codec) 1528static int wm8753_remove(struct snd_soc_codec *codec)
1546{ 1529{
1547 run_delayed_work(&codec->delayed_work); 1530 flush_delayed_work_sync(&codec->dapm.delayed_work);
1548 wm8753_set_bias_level(codec, SND_SOC_BIAS_OFF); 1531 wm8753_set_bias_level(codec, SND_SOC_BIAS_OFF);
1549 1532
1550 return 0; 1533 return 0;
diff --git a/sound/soc/codecs/wm8770.c b/sound/soc/codecs/wm8770.c
new file mode 100644
index 000000000000..19b92baa9e8c
--- /dev/null
+++ b/sound/soc/codecs/wm8770.c
@@ -0,0 +1,749 @@
1/*
2 * wm8770.c -- WM8770 ALSA SoC Audio driver
3 *
4 * Copyright 2010 Wolfson Microelectronics plc
5 *
6 * Author: Dimitris Papastamos <dp@opensource.wolfsonmicro.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/moduleparam.h>
15#include <linux/init.h>
16#include <linux/delay.h>
17#include <linux/pm.h>
18#include <linux/platform_device.h>
19#include <linux/spi/spi.h>
20#include <linux/regulator/consumer.h>
21#include <linux/slab.h>
22#include <sound/core.h>
23#include <sound/pcm.h>
24#include <sound/pcm_params.h>
25#include <sound/soc.h>
26#include <sound/initval.h>
27#include <sound/tlv.h>
28
29#include "wm8770.h"
30
31#define WM8770_NUM_SUPPLIES 3
32static const char *wm8770_supply_names[WM8770_NUM_SUPPLIES] = {
33 "AVDD1",
34 "AVDD2",
35 "DVDD"
36};
37
38static const u16 wm8770_reg_defs[WM8770_CACHEREGNUM] = {
39 0x7f, 0x7f, 0x7f, 0x7f,
40 0x7f, 0x7f, 0x7f, 0x7f,
41 0x7f, 0xff, 0xff, 0xff,
42 0xff, 0xff, 0xff, 0xff,
43 0xff, 0xff, 0, 0x90, 0,
44 0, 0x22, 0x22, 0x3e,
45 0xc, 0xc, 0x100, 0x189,
46 0x189, 0x8770
47};
48
49struct wm8770_priv {
50 enum snd_soc_control_type control_type;
51 struct regulator_bulk_data supplies[WM8770_NUM_SUPPLIES];
52 struct notifier_block disable_nb[WM8770_NUM_SUPPLIES];
53 struct snd_soc_codec *codec;
54 int sysclk;
55};
56
57static int vout12supply_event(struct snd_soc_dapm_widget *w,
58 struct snd_kcontrol *kcontrol, int event);
59static int vout34supply_event(struct snd_soc_dapm_widget *w,
60 struct snd_kcontrol *kcontrol, int event);
61
62/*
63 * We can't use the same notifier block for more than one supply and
64 * there's no way I can see to get from a callback to the caller
65 * except container_of().
66 */
67#define WM8770_REGULATOR_EVENT(n) \
68static int wm8770_regulator_event_##n(struct notifier_block *nb, \
69 unsigned long event, void *data) \
70{ \
71 struct wm8770_priv *wm8770 = container_of(nb, struct wm8770_priv, \
72 disable_nb[n]); \
73 if (event & REGULATOR_EVENT_DISABLE) { \
74 wm8770->codec->cache_sync = 1; \
75 } \
76 return 0; \
77}
78
79WM8770_REGULATOR_EVENT(0)
80WM8770_REGULATOR_EVENT(1)
81WM8770_REGULATOR_EVENT(2)
82
83static const DECLARE_TLV_DB_SCALE(adc_tlv, -1200, 100, 0);
84static const DECLARE_TLV_DB_SCALE(dac_dig_tlv, -12750, 50, 1);
85static const DECLARE_TLV_DB_SCALE(dac_alg_tlv, -12700, 100, 1);
86
87static const char *dac_phase_text[][2] = {
88 { "DAC1 Normal", "DAC1 Inverted" },
89 { "DAC2 Normal", "DAC2 Inverted" },
90 { "DAC3 Normal", "DAC3 Inverted" },
91 { "DAC4 Normal", "DAC4 Inverted" },
92};
93
94static const struct soc_enum dac_phase[] = {
95 SOC_ENUM_DOUBLE(WM8770_DACPHASE, 0, 1, 2, dac_phase_text[0]),
96 SOC_ENUM_DOUBLE(WM8770_DACPHASE, 2, 3, 2, dac_phase_text[1]),
97 SOC_ENUM_DOUBLE(WM8770_DACPHASE, 4, 5, 2, dac_phase_text[2]),
98 SOC_ENUM_DOUBLE(WM8770_DACPHASE, 6, 7, 2, dac_phase_text[3]),
99};
100
101static const struct snd_kcontrol_new wm8770_snd_controls[] = {
102 /* global DAC playback controls */
103 SOC_SINGLE_TLV("DAC Playback Volume", WM8770_MSDIGVOL, 0, 255, 0,
104 dac_dig_tlv),
105 SOC_SINGLE("DAC Playback Switch", WM8770_DACMUTE, 4, 1, 1),
106 SOC_SINGLE("DAC Playback ZC Switch", WM8770_DACCTRL1, 0, 1, 0),
107
108 /* global VOUT playback controls */
109 SOC_SINGLE_TLV("VOUT Playback Volume", WM8770_MSALGVOL, 0, 127, 0,
110 dac_alg_tlv),
111 SOC_SINGLE("VOUT Playback ZC Switch", WM8770_MSALGVOL, 7, 1, 0),
112
113 /* VOUT1/2/3/4 specific controls */
114 SOC_DOUBLE_R_TLV("VOUT1 Playback Volume", WM8770_VOUT1LVOL,
115 WM8770_VOUT1RVOL, 0, 127, 0, dac_alg_tlv),
116 SOC_DOUBLE_R("VOUT1 Playback ZC Switch", WM8770_VOUT1LVOL,
117 WM8770_VOUT1RVOL, 7, 1, 0),
118 SOC_DOUBLE_R_TLV("VOUT2 Playback Volume", WM8770_VOUT2LVOL,
119 WM8770_VOUT2RVOL, 0, 127, 0, dac_alg_tlv),
120 SOC_DOUBLE_R("VOUT2 Playback ZC Switch", WM8770_VOUT2LVOL,
121 WM8770_VOUT2RVOL, 7, 1, 0),
122 SOC_DOUBLE_R_TLV("VOUT3 Playback Volume", WM8770_VOUT3LVOL,
123 WM8770_VOUT3RVOL, 0, 127, 0, dac_alg_tlv),
124 SOC_DOUBLE_R("VOUT3 Playback ZC Switch", WM8770_VOUT3LVOL,
125 WM8770_VOUT3RVOL, 7, 1, 0),
126 SOC_DOUBLE_R_TLV("VOUT4 Playback Volume", WM8770_VOUT4LVOL,
127 WM8770_VOUT4RVOL, 0, 127, 0, dac_alg_tlv),
128 SOC_DOUBLE_R("VOUT4 Playback ZC Switch", WM8770_VOUT4LVOL,
129 WM8770_VOUT4RVOL, 7, 1, 0),
130
131 /* DAC1/2/3/4 specific controls */
132 SOC_DOUBLE_R_TLV("DAC1 Playback Volume", WM8770_DAC1LVOL,
133 WM8770_DAC1RVOL, 0, 255, 0, dac_dig_tlv),
134 SOC_SINGLE("DAC1 Deemphasis Switch", WM8770_DACCTRL2, 0, 1, 0),
135 SOC_ENUM("DAC1 Phase", dac_phase[0]),
136 SOC_DOUBLE_R_TLV("DAC2 Playback Volume", WM8770_DAC2LVOL,
137 WM8770_DAC2RVOL, 0, 255, 0, dac_dig_tlv),
138 SOC_SINGLE("DAC2 Deemphasis Switch", WM8770_DACCTRL2, 1, 1, 0),
139 SOC_ENUM("DAC2 Phase", dac_phase[1]),
140 SOC_DOUBLE_R_TLV("DAC3 Playback Volume", WM8770_DAC3LVOL,
141 WM8770_DAC3RVOL, 0, 255, 0, dac_dig_tlv),
142 SOC_SINGLE("DAC3 Deemphasis Switch", WM8770_DACCTRL2, 2, 1, 0),
143 SOC_ENUM("DAC3 Phase", dac_phase[2]),
144 SOC_DOUBLE_R_TLV("DAC4 Playback Volume", WM8770_DAC4LVOL,
145 WM8770_DAC4RVOL, 0, 255, 0, dac_dig_tlv),
146 SOC_SINGLE("DAC4 Deemphasis Switch", WM8770_DACCTRL2, 3, 1, 0),
147 SOC_ENUM("DAC4 Phase", dac_phase[3]),
148
149 /* ADC specific controls */
150 SOC_DOUBLE_R_TLV("Capture Volume", WM8770_ADCLCTRL, WM8770_ADCRCTRL,
151 0, 31, 0, adc_tlv),
152 SOC_DOUBLE_R("Capture Switch", WM8770_ADCLCTRL, WM8770_ADCRCTRL,
153 5, 1, 1),
154
155 /* other controls */
156 SOC_SINGLE("ADC 128x Oversampling Switch", WM8770_MSTRCTRL, 3, 1, 0),
157 SOC_SINGLE("ADC Highpass Filter Switch", WM8770_IFACECTRL, 8, 1, 1)
158};
159
160static const char *ain_text[] = {
161 "AIN1", "AIN2", "AIN3", "AIN4",
162 "AIN5", "AIN6", "AIN7", "AIN8"
163};
164
165static const struct soc_enum ain_enum =
166 SOC_ENUM_DOUBLE(WM8770_ADCMUX, 0, 4, 8, ain_text);
167
168static const struct snd_kcontrol_new ain_mux =
169 SOC_DAPM_ENUM("Capture Mux", ain_enum);
170
171static const struct snd_kcontrol_new vout1_mix_controls[] = {
172 SOC_DAPM_SINGLE("DAC1 Switch", WM8770_OUTMUX1, 0, 1, 0),
173 SOC_DAPM_SINGLE("AUX1 Switch", WM8770_OUTMUX1, 1, 1, 0),
174 SOC_DAPM_SINGLE("Bypass Switch", WM8770_OUTMUX1, 2, 1, 0)
175};
176
177static const struct snd_kcontrol_new vout2_mix_controls[] = {
178 SOC_DAPM_SINGLE("DAC2 Switch", WM8770_OUTMUX1, 3, 1, 0),
179 SOC_DAPM_SINGLE("AUX2 Switch", WM8770_OUTMUX1, 4, 1, 0),
180 SOC_DAPM_SINGLE("Bypass Switch", WM8770_OUTMUX1, 5, 1, 0)
181};
182
183static const struct snd_kcontrol_new vout3_mix_controls[] = {
184 SOC_DAPM_SINGLE("DAC3 Switch", WM8770_OUTMUX2, 0, 1, 0),
185 SOC_DAPM_SINGLE("AUX3 Switch", WM8770_OUTMUX2, 1, 1, 0),
186 SOC_DAPM_SINGLE("Bypass Switch", WM8770_OUTMUX2, 2, 1, 0)
187};
188
189static const struct snd_kcontrol_new vout4_mix_controls[] = {
190 SOC_DAPM_SINGLE("DAC4 Switch", WM8770_OUTMUX2, 3, 1, 0),
191 SOC_DAPM_SINGLE("Bypass Switch", WM8770_OUTMUX2, 4, 1, 0)
192};
193
194static const struct snd_soc_dapm_widget wm8770_dapm_widgets[] = {
195 SND_SOC_DAPM_INPUT("AUX1"),
196 SND_SOC_DAPM_INPUT("AUX2"),
197 SND_SOC_DAPM_INPUT("AUX3"),
198
199 SND_SOC_DAPM_INPUT("AIN1"),
200 SND_SOC_DAPM_INPUT("AIN2"),
201 SND_SOC_DAPM_INPUT("AIN3"),
202 SND_SOC_DAPM_INPUT("AIN4"),
203 SND_SOC_DAPM_INPUT("AIN5"),
204 SND_SOC_DAPM_INPUT("AIN6"),
205 SND_SOC_DAPM_INPUT("AIN7"),
206 SND_SOC_DAPM_INPUT("AIN8"),
207
208 SND_SOC_DAPM_MUX("Capture Mux", WM8770_ADCMUX, 8, 1, &ain_mux),
209
210 SND_SOC_DAPM_ADC("ADC", "Capture", WM8770_PWDNCTRL, 1, 1),
211
212 SND_SOC_DAPM_DAC("DAC1", "Playback", WM8770_PWDNCTRL, 2, 1),
213 SND_SOC_DAPM_DAC("DAC2", "Playback", WM8770_PWDNCTRL, 3, 1),
214 SND_SOC_DAPM_DAC("DAC3", "Playback", WM8770_PWDNCTRL, 4, 1),
215 SND_SOC_DAPM_DAC("DAC4", "Playback", WM8770_PWDNCTRL, 5, 1),
216
217 SND_SOC_DAPM_SUPPLY("VOUT12 Supply", SND_SOC_NOPM, 0, 0,
218 vout12supply_event, SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
219 SND_SOC_DAPM_SUPPLY("VOUT34 Supply", SND_SOC_NOPM, 0, 0,
220 vout34supply_event, SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
221
222 SND_SOC_DAPM_MIXER("VOUT1 Mixer", SND_SOC_NOPM, 0, 0,
223 vout1_mix_controls, ARRAY_SIZE(vout1_mix_controls)),
224 SND_SOC_DAPM_MIXER("VOUT2 Mixer", SND_SOC_NOPM, 0, 0,
225 vout2_mix_controls, ARRAY_SIZE(vout2_mix_controls)),
226 SND_SOC_DAPM_MIXER("VOUT3 Mixer", SND_SOC_NOPM, 0, 0,
227 vout3_mix_controls, ARRAY_SIZE(vout3_mix_controls)),
228 SND_SOC_DAPM_MIXER("VOUT4 Mixer", SND_SOC_NOPM, 0, 0,
229 vout4_mix_controls, ARRAY_SIZE(vout4_mix_controls)),
230
231 SND_SOC_DAPM_OUTPUT("VOUT1"),
232 SND_SOC_DAPM_OUTPUT("VOUT2"),
233 SND_SOC_DAPM_OUTPUT("VOUT3"),
234 SND_SOC_DAPM_OUTPUT("VOUT4")
235};
236
237static const struct snd_soc_dapm_route wm8770_intercon[] = {
238 { "Capture Mux", "AIN1", "AIN1" },
239 { "Capture Mux", "AIN2", "AIN2" },
240 { "Capture Mux", "AIN3", "AIN3" },
241 { "Capture Mux", "AIN4", "AIN4" },
242 { "Capture Mux", "AIN5", "AIN5" },
243 { "Capture Mux", "AIN6", "AIN6" },
244 { "Capture Mux", "AIN7", "AIN7" },
245 { "Capture Mux", "AIN8", "AIN8" },
246
247 { "ADC", NULL, "Capture Mux" },
248
249 { "VOUT1 Mixer", NULL, "VOUT12 Supply" },
250 { "VOUT1 Mixer", "DAC1 Switch", "DAC1" },
251 { "VOUT1 Mixer", "AUX1 Switch", "AUX1" },
252 { "VOUT1 Mixer", "Bypass Switch", "Capture Mux" },
253
254 { "VOUT2 Mixer", NULL, "VOUT12 Supply" },
255 { "VOUT2 Mixer", "DAC2 Switch", "DAC2" },
256 { "VOUT2 Mixer", "AUX2 Switch", "AUX2" },
257 { "VOUT2 Mixer", "Bypass Switch", "Capture Mux" },
258
259 { "VOUT3 Mixer", NULL, "VOUT34 Supply" },
260 { "VOUT3 Mixer", "DAC3 Switch", "DAC3" },
261 { "VOUT3 Mixer", "AUX3 Switch", "AUX3" },
262 { "VOUT3 Mixer", "Bypass Switch", "Capture Mux" },
263
264 { "VOUT4 Mixer", NULL, "VOUT34 Supply" },
265 { "VOUT4 Mixer", "DAC4 Switch", "DAC4" },
266 { "VOUT4 Mixer", "Bypass Switch", "Capture Mux" },
267
268 { "VOUT1", NULL, "VOUT1 Mixer" },
269 { "VOUT2", NULL, "VOUT2 Mixer" },
270 { "VOUT3", NULL, "VOUT3 Mixer" },
271 { "VOUT4", NULL, "VOUT4 Mixer" }
272};
273
274static int vout12supply_event(struct snd_soc_dapm_widget *w,
275 struct snd_kcontrol *kcontrol, int event)
276{
277 struct snd_soc_codec *codec;
278
279 codec = w->codec;
280
281 switch (event) {
282 case SND_SOC_DAPM_PRE_PMU:
283 snd_soc_update_bits(codec, WM8770_OUTMUX1, 0x180, 0);
284 break;
285 case SND_SOC_DAPM_POST_PMD:
286 snd_soc_update_bits(codec, WM8770_OUTMUX1, 0x180, 0x180);
287 break;
288 }
289
290 return 0;
291}
292
293static int vout34supply_event(struct snd_soc_dapm_widget *w,
294 struct snd_kcontrol *kcontrol, int event)
295{
296 struct snd_soc_codec *codec;
297
298 codec = w->codec;
299
300 switch (event) {
301 case SND_SOC_DAPM_PRE_PMU:
302 snd_soc_update_bits(codec, WM8770_OUTMUX2, 0x180, 0);
303 break;
304 case SND_SOC_DAPM_POST_PMD:
305 snd_soc_update_bits(codec, WM8770_OUTMUX2, 0x180, 0x180);
306 break;
307 }
308
309 return 0;
310}
311
312static int wm8770_reset(struct snd_soc_codec *codec)
313{
314 return snd_soc_write(codec, WM8770_RESET, 0);
315}
316
317static int wm8770_set_fmt(struct snd_soc_dai *dai, unsigned int fmt)
318{
319 struct snd_soc_codec *codec;
320 int iface, master;
321
322 codec = dai->codec;
323
324 switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
325 case SND_SOC_DAIFMT_CBM_CFM:
326 master = 0x100;
327 break;
328 case SND_SOC_DAIFMT_CBS_CFS:
329 master = 0;
330 break;
331 default:
332 return -EINVAL;
333 }
334
335 iface = 0;
336 switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
337 case SND_SOC_DAIFMT_I2S:
338 iface |= 0x2;
339 break;
340 case SND_SOC_DAIFMT_RIGHT_J:
341 break;
342 case SND_SOC_DAIFMT_LEFT_J:
343 iface |= 0x1;
344 break;
345 default:
346 return -EINVAL;
347 }
348
349 switch (fmt & SND_SOC_DAIFMT_INV_MASK) {
350 case SND_SOC_DAIFMT_NB_NF:
351 break;
352 case SND_SOC_DAIFMT_IB_IF:
353 iface |= 0xc;
354 break;
355 case SND_SOC_DAIFMT_IB_NF:
356 iface |= 0x8;
357 break;
358 case SND_SOC_DAIFMT_NB_IF:
359 iface |= 0x4;
360 break;
361 default:
362 return -EINVAL;
363 }
364
365 snd_soc_update_bits(codec, WM8770_IFACECTRL, 0xf, iface);
366 snd_soc_update_bits(codec, WM8770_MSTRCTRL, 0x100, master);
367
368 return 0;
369}
370
371static const int mclk_ratios[] = {
372 128,
373 192,
374 256,
375 384,
376 512,
377 768
378};
379
380static int wm8770_hw_params(struct snd_pcm_substream *substream,
381 struct snd_pcm_hw_params *params,
382 struct snd_soc_dai *dai)
383{
384 struct snd_soc_codec *codec;
385 struct wm8770_priv *wm8770;
386 int i;
387 int iface;
388 int shift;
389 int ratio;
390
391 codec = dai->codec;
392 wm8770 = snd_soc_codec_get_drvdata(codec);
393
394 iface = 0;
395 switch (params_format(params)) {
396 case SNDRV_PCM_FORMAT_S16_LE:
397 break;
398 case SNDRV_PCM_FORMAT_S20_3LE:
399 iface |= 0x10;
400 break;
401 case SNDRV_PCM_FORMAT_S24_LE:
402 iface |= 0x20;
403 break;
404 case SNDRV_PCM_FORMAT_S32_LE:
405 iface |= 0x30;
406 break;
407 }
408
409 switch (substream->stream) {
410 case SNDRV_PCM_STREAM_PLAYBACK:
411 i = 0;
412 shift = 4;
413 break;
414 case SNDRV_PCM_STREAM_CAPTURE:
415 i = 2;
416 shift = 0;
417 break;
418 default:
419 return -EINVAL;
420 }
421
422 /* Only need to set MCLK/LRCLK ratio if we're master */
423 if (snd_soc_read(codec, WM8770_MSTRCTRL) & 0x100) {
424 for (; i < ARRAY_SIZE(mclk_ratios); ++i) {
425 ratio = wm8770->sysclk / params_rate(params);
426 if (ratio == mclk_ratios[i])
427 break;
428 }
429
430 if (i == ARRAY_SIZE(mclk_ratios)) {
431 dev_err(codec->dev,
432 "Unable to configure MCLK ratio %d/%d\n",
433 wm8770->sysclk, params_rate(params));
434 return -EINVAL;
435 }
436
437 dev_dbg(codec->dev, "MCLK is %dfs\n", mclk_ratios[i]);
438
439 snd_soc_update_bits(codec, WM8770_MSTRCTRL, 0x7 << shift,
440 i << shift);
441 }
442
443 snd_soc_update_bits(codec, WM8770_IFACECTRL, 0x30, iface);
444
445 return 0;
446}
447
448static int wm8770_mute(struct snd_soc_dai *dai, int mute)
449{
450 struct snd_soc_codec *codec;
451
452 codec = dai->codec;
453 return snd_soc_update_bits(codec, WM8770_DACMUTE, 0x10,
454 !!mute << 4);
455}
456
457static int wm8770_set_sysclk(struct snd_soc_dai *dai,
458 int clk_id, unsigned int freq, int dir)
459{
460 struct snd_soc_codec *codec;
461 struct wm8770_priv *wm8770;
462
463 codec = dai->codec;
464 wm8770 = snd_soc_codec_get_drvdata(codec);
465 wm8770->sysclk = freq;
466 return 0;
467}
468
469static void wm8770_sync_cache(struct snd_soc_codec *codec)
470{
471 int i;
472 u16 *cache;
473
474 if (!codec->cache_sync)
475 return;
476
477 codec->cache_only = 0;
478 cache = codec->reg_cache;
479 for (i = 0; i < codec->driver->reg_cache_size; i++) {
480 if (i == WM8770_RESET || cache[i] == wm8770_reg_defs[i])
481 continue;
482 snd_soc_write(codec, i, cache[i]);
483 }
484 codec->cache_sync = 0;
485}
486
487static int wm8770_set_bias_level(struct snd_soc_codec *codec,
488 enum snd_soc_bias_level level)
489{
490 int ret;
491 struct wm8770_priv *wm8770;
492
493 wm8770 = snd_soc_codec_get_drvdata(codec);
494
495 switch (level) {
496 case SND_SOC_BIAS_ON:
497 break;
498 case SND_SOC_BIAS_PREPARE:
499 break;
500 case SND_SOC_BIAS_STANDBY:
501 if (codec->dapm.bias_level == SND_SOC_BIAS_OFF) {
502 ret = regulator_bulk_enable(ARRAY_SIZE(wm8770->supplies),
503 wm8770->supplies);
504 if (ret) {
505 dev_err(codec->dev,
506 "Failed to enable supplies: %d\n",
507 ret);
508 return ret;
509 }
510 wm8770_sync_cache(codec);
511 /* global powerup */
512 snd_soc_write(codec, WM8770_PWDNCTRL, 0);
513 }
514 break;
515 case SND_SOC_BIAS_OFF:
516 /* global powerdown */
517 snd_soc_write(codec, WM8770_PWDNCTRL, 1);
518 regulator_bulk_disable(ARRAY_SIZE(wm8770->supplies),
519 wm8770->supplies);
520 break;
521 }
522
523 codec->dapm.bias_level = level;
524 return 0;
525}
526
527#define WM8770_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE | \
528 SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S32_LE)
529
530static struct snd_soc_dai_ops wm8770_dai_ops = {
531 .digital_mute = wm8770_mute,
532 .hw_params = wm8770_hw_params,
533 .set_fmt = wm8770_set_fmt,
534 .set_sysclk = wm8770_set_sysclk,
535};
536
537static struct snd_soc_dai_driver wm8770_dai = {
538 .name = "wm8770-hifi",
539 .playback = {
540 .stream_name = "Playback",
541 .channels_min = 2,
542 .channels_max = 2,
543 .rates = SNDRV_PCM_RATE_8000_192000,
544 .formats = WM8770_FORMATS
545 },
546 .capture = {
547 .stream_name = "Capture",
548 .channels_min = 2,
549 .channels_max = 2,
550 .rates = SNDRV_PCM_RATE_8000_96000,
551 .formats = WM8770_FORMATS
552 },
553 .ops = &wm8770_dai_ops,
554 .symmetric_rates = 1
555};
556
557#ifdef CONFIG_PM
558static int wm8770_suspend(struct snd_soc_codec *codec, pm_message_t state)
559{
560 wm8770_set_bias_level(codec, SND_SOC_BIAS_OFF);
561 return 0;
562}
563
564static int wm8770_resume(struct snd_soc_codec *codec)
565{
566 wm8770_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
567 return 0;
568}
569#else
570#define wm8770_suspend NULL
571#define wm8770_resume NULL
572#endif
573
574static int wm8770_probe(struct snd_soc_codec *codec)
575{
576 struct wm8770_priv *wm8770;
577 int ret;
578 int i;
579
580 wm8770 = snd_soc_codec_get_drvdata(codec);
581 wm8770->codec = codec;
582
583 codec->dapm.idle_bias_off = 1;
584
585 ret = snd_soc_codec_set_cache_io(codec, 7, 9, wm8770->control_type);
586 if (ret < 0) {
587 dev_err(codec->dev, "Failed to set cache I/O: %d\n", ret);
588 return ret;
589 }
590
591 for (i = 0; i < ARRAY_SIZE(wm8770->supplies); i++)
592 wm8770->supplies[i].supply = wm8770_supply_names[i];
593
594 ret = regulator_bulk_get(codec->dev, ARRAY_SIZE(wm8770->supplies),
595 wm8770->supplies);
596 if (ret) {
597 dev_err(codec->dev, "Failed to request supplies: %d\n", ret);
598 return ret;
599 }
600
601 wm8770->disable_nb[0].notifier_call = wm8770_regulator_event_0;
602 wm8770->disable_nb[1].notifier_call = wm8770_regulator_event_1;
603 wm8770->disable_nb[2].notifier_call = wm8770_regulator_event_2;
604
605 /* This should really be moved into the regulator core */
606 for (i = 0; i < ARRAY_SIZE(wm8770->supplies); i++) {
607 ret = regulator_register_notifier(wm8770->supplies[i].consumer,
608 &wm8770->disable_nb[i]);
609 if (ret) {
610 dev_err(codec->dev,
611 "Failed to register regulator notifier: %d\n",
612 ret);
613 }
614 }
615
616 ret = regulator_bulk_enable(ARRAY_SIZE(wm8770->supplies),
617 wm8770->supplies);
618 if (ret) {
619 dev_err(codec->dev, "Failed to enable supplies: %d\n", ret);
620 goto err_reg_get;
621 }
622
623 ret = wm8770_reset(codec);
624 if (ret < 0) {
625 dev_err(codec->dev, "Failed to issue reset: %d\n", ret);
626 goto err_reg_enable;
627 }
628
629 wm8770_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
630
631 /* latch the volume update bits */
632 snd_soc_update_bits(codec, WM8770_MSDIGVOL, 0x100, 0x100);
633 snd_soc_update_bits(codec, WM8770_MSALGVOL, 0x100, 0x100);
634 snd_soc_update_bits(codec, WM8770_VOUT1RVOL, 0x100, 0x100);
635 snd_soc_update_bits(codec, WM8770_VOUT2RVOL, 0x100, 0x100);
636 snd_soc_update_bits(codec, WM8770_VOUT3RVOL, 0x100, 0x100);
637 snd_soc_update_bits(codec, WM8770_VOUT4RVOL, 0x100, 0x100);
638 snd_soc_update_bits(codec, WM8770_DAC1RVOL, 0x100, 0x100);
639 snd_soc_update_bits(codec, WM8770_DAC2RVOL, 0x100, 0x100);
640 snd_soc_update_bits(codec, WM8770_DAC3RVOL, 0x100, 0x100);
641 snd_soc_update_bits(codec, WM8770_DAC4RVOL, 0x100, 0x100);
642
643 /* mute all DACs */
644 snd_soc_update_bits(codec, WM8770_DACMUTE, 0x10, 0x10);
645
646 snd_soc_add_controls(codec, wm8770_snd_controls,
647 ARRAY_SIZE(wm8770_snd_controls));
648 snd_soc_dapm_new_controls(&codec->dapm, wm8770_dapm_widgets,
649 ARRAY_SIZE(wm8770_dapm_widgets));
650 snd_soc_dapm_add_routes(&codec->dapm, wm8770_intercon,
651 ARRAY_SIZE(wm8770_intercon));
652 return 0;
653
654err_reg_enable:
655 regulator_bulk_disable(ARRAY_SIZE(wm8770->supplies), wm8770->supplies);
656err_reg_get:
657 regulator_bulk_free(ARRAY_SIZE(wm8770->supplies), wm8770->supplies);
658 return ret;
659}
660
661static int wm8770_remove(struct snd_soc_codec *codec)
662{
663 struct wm8770_priv *wm8770;
664 int i;
665
666 wm8770 = snd_soc_codec_get_drvdata(codec);
667 wm8770_set_bias_level(codec, SND_SOC_BIAS_OFF);
668
669 for (i = 0; i < ARRAY_SIZE(wm8770->supplies); ++i)
670 regulator_unregister_notifier(wm8770->supplies[i].consumer,
671 &wm8770->disable_nb[i]);
672 regulator_bulk_free(ARRAY_SIZE(wm8770->supplies), wm8770->supplies);
673 return 0;
674}
675
676static struct snd_soc_codec_driver soc_codec_dev_wm8770 = {
677 .probe = wm8770_probe,
678 .remove = wm8770_remove,
679 .suspend = wm8770_suspend,
680 .resume = wm8770_resume,
681 .set_bias_level = wm8770_set_bias_level,
682 .reg_cache_size = ARRAY_SIZE(wm8770_reg_defs),
683 .reg_word_size = sizeof (u16),
684 .reg_cache_default = wm8770_reg_defs
685};
686
687#if defined(CONFIG_SPI_MASTER)
688static int __devinit wm8770_spi_probe(struct spi_device *spi)
689{
690 struct wm8770_priv *wm8770;
691 int ret;
692
693 wm8770 = kzalloc(sizeof(struct wm8770_priv), GFP_KERNEL);
694 if (!wm8770)
695 return -ENOMEM;
696
697 wm8770->control_type = SND_SOC_SPI;
698 spi_set_drvdata(spi, wm8770);
699
700 ret = snd_soc_register_codec(&spi->dev,
701 &soc_codec_dev_wm8770, &wm8770_dai, 1);
702 if (ret < 0)
703 kfree(wm8770);
704 return ret;
705}
706
707static int __devexit wm8770_spi_remove(struct spi_device *spi)
708{
709 snd_soc_unregister_codec(&spi->dev);
710 kfree(spi_get_drvdata(spi));
711 return 0;
712}
713
714static struct spi_driver wm8770_spi_driver = {
715 .driver = {
716 .name = "wm8770",
717 .owner = THIS_MODULE,
718 },
719 .probe = wm8770_spi_probe,
720 .remove = __devexit_p(wm8770_spi_remove)
721};
722#endif
723
724static int __init wm8770_modinit(void)
725{
726 int ret = 0;
727
728#if defined(CONFIG_SPI_MASTER)
729 ret = spi_register_driver(&wm8770_spi_driver);
730 if (ret) {
731 printk(KERN_ERR "Failed to register wm8770 SPI driver: %d\n",
732 ret);
733 }
734#endif
735 return ret;
736}
737module_init(wm8770_modinit);
738
739static void __exit wm8770_exit(void)
740{
741#if defined(CONFIG_SPI_MASTER)
742 spi_unregister_driver(&wm8770_spi_driver);
743#endif
744}
745module_exit(wm8770_exit);
746
747MODULE_DESCRIPTION("ASoC WM8770 driver");
748MODULE_AUTHOR("Dimitris Papastamos <dp@opensource.wolfsonmicro.com>");
749MODULE_LICENSE("GPL");
diff --git a/sound/soc/codecs/wm8770.h b/sound/soc/codecs/wm8770.h
new file mode 100644
index 000000000000..5f1b3bda6cc8
--- /dev/null
+++ b/sound/soc/codecs/wm8770.h
@@ -0,0 +1,51 @@
1/*
2 * wm8770.h -- WM8770 ASoC driver
3 *
4 * Copyright 2010 Wolfson Microelectronics plc
5 *
6 * Author: Dimitris Papastamos <dp@opensource.wolfsonmicro.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#ifndef _WM8770_H
14#define _WM8770_H
15
16/* Registers */
17#define WM8770_VOUT1LVOL 0
18#define WM8770_VOUT1RVOL 0x1
19#define WM8770_VOUT2LVOL 0x2
20#define WM8770_VOUT2RVOL 0x3
21#define WM8770_VOUT3LVOL 0x4
22#define WM8770_VOUT3RVOL 0x5
23#define WM8770_VOUT4LVOL 0x6
24#define WM8770_VOUT4RVOL 0x7
25#define WM8770_MSALGVOL 0x8
26#define WM8770_DAC1LVOL 0x9
27#define WM8770_DAC1RVOL 0xa
28#define WM8770_DAC2LVOL 0xb
29#define WM8770_DAC2RVOL 0xc
30#define WM8770_DAC3LVOL 0xd
31#define WM8770_DAC3RVOL 0xe
32#define WM8770_DAC4LVOL 0xf
33#define WM8770_DAC4RVOL 0x10
34#define WM8770_MSDIGVOL 0x11
35#define WM8770_DACPHASE 0x12
36#define WM8770_DACCTRL1 0x13
37#define WM8770_DACMUTE 0x14
38#define WM8770_DACCTRL2 0x15
39#define WM8770_IFACECTRL 0x16
40#define WM8770_MSTRCTRL 0x17
41#define WM8770_PWDNCTRL 0x18
42#define WM8770_ADCLCTRL 0x19
43#define WM8770_ADCRCTRL 0x1a
44#define WM8770_ADCMUX 0x1b
45#define WM8770_OUTMUX1 0x1c
46#define WM8770_OUTMUX2 0x1d
47#define WM8770_RESET 0x31
48
49#define WM8770_CACHEREGNUM 0x20
50
51#endif
diff --git a/sound/soc/codecs/wm8776.c b/sound/soc/codecs/wm8776.c
index 0132a27140ae..8e7953b1b790 100644
--- a/sound/soc/codecs/wm8776.c
+++ b/sound/soc/codecs/wm8776.c
@@ -25,7 +25,6 @@
25#include <sound/pcm.h> 25#include <sound/pcm.h>
26#include <sound/pcm_params.h> 26#include <sound/pcm_params.h>
27#include <sound/soc.h> 27#include <sound/soc.h>
28#include <sound/soc-dapm.h>
29#include <sound/initval.h> 28#include <sound/initval.h>
30#include <sound/tlv.h> 29#include <sound/tlv.h>
31 30
@@ -306,7 +305,7 @@ static int wm8776_set_bias_level(struct snd_soc_codec *codec,
306 case SND_SOC_BIAS_PREPARE: 305 case SND_SOC_BIAS_PREPARE:
307 break; 306 break;
308 case SND_SOC_BIAS_STANDBY: 307 case SND_SOC_BIAS_STANDBY:
309 if (codec->bias_level == SND_SOC_BIAS_OFF) { 308 if (codec->dapm.bias_level == SND_SOC_BIAS_OFF) {
310 /* Disable the global powerdown; DAPM does the rest */ 309 /* Disable the global powerdown; DAPM does the rest */
311 snd_soc_update_bits(codec, WM8776_PWRDOWN, 1, 0); 310 snd_soc_update_bits(codec, WM8776_PWRDOWN, 1, 0);
312 } 311 }
@@ -317,7 +316,7 @@ static int wm8776_set_bias_level(struct snd_soc_codec *codec,
317 break; 316 break;
318 } 317 }
319 318
320 codec->bias_level = level; 319 codec->dapm.bias_level = level;
321 return 0; 320 return 0;
322} 321}
323 322
@@ -404,6 +403,7 @@ static int wm8776_resume(struct snd_soc_codec *codec)
404static int wm8776_probe(struct snd_soc_codec *codec) 403static int wm8776_probe(struct snd_soc_codec *codec)
405{ 404{
406 struct wm8776_priv *wm8776 = snd_soc_codec_get_drvdata(codec); 405 struct wm8776_priv *wm8776 = snd_soc_codec_get_drvdata(codec);
406 struct snd_soc_dapm_context *dapm = &codec->dapm;
407 int ret = 0; 407 int ret = 0;
408 408
409 ret = snd_soc_codec_set_cache_io(codec, 7, 9, wm8776->control_type); 409 ret = snd_soc_codec_set_cache_io(codec, 7, 9, wm8776->control_type);
@@ -427,9 +427,9 @@ static int wm8776_probe(struct snd_soc_codec *codec)
427 427
428 snd_soc_add_controls(codec, wm8776_snd_controls, 428 snd_soc_add_controls(codec, wm8776_snd_controls,
429 ARRAY_SIZE(wm8776_snd_controls)); 429 ARRAY_SIZE(wm8776_snd_controls));
430 snd_soc_dapm_new_controls(codec, wm8776_dapm_widgets, 430 snd_soc_dapm_new_controls(dapm, wm8776_dapm_widgets,
431 ARRAY_SIZE(wm8776_dapm_widgets)); 431 ARRAY_SIZE(wm8776_dapm_widgets));
432 snd_soc_dapm_add_routes(codec, routes, ARRAY_SIZE(routes)); 432 snd_soc_dapm_add_routes(dapm, routes, ARRAY_SIZE(routes));
433 433
434 return ret; 434 return ret;
435} 435}
diff --git a/sound/soc/codecs/wm8804.c b/sound/soc/codecs/wm8804.c
index 4599e8e95aa2..6dae1b40c9f7 100644
--- a/sound/soc/codecs/wm8804.c
+++ b/sound/soc/codecs/wm8804.c
@@ -23,7 +23,6 @@
23#include <sound/pcm.h> 23#include <sound/pcm.h>
24#include <sound/pcm_params.h> 24#include <sound/pcm_params.h>
25#include <sound/soc.h> 25#include <sound/soc.h>
26#include <sound/soc-dapm.h>
27#include <sound/initval.h> 26#include <sound/initval.h>
28#include <sound/tlv.h> 27#include <sound/tlv.h>
29 28
@@ -515,7 +514,7 @@ static int wm8804_set_bias_level(struct snd_soc_codec *codec,
515 snd_soc_update_bits(codec, WM8804_PWRDN, 0x9, 0); 514 snd_soc_update_bits(codec, WM8804_PWRDN, 0x9, 0);
516 break; 515 break;
517 case SND_SOC_BIAS_STANDBY: 516 case SND_SOC_BIAS_STANDBY:
518 if (codec->bias_level == SND_SOC_BIAS_OFF) { 517 if (codec->dapm.bias_level == SND_SOC_BIAS_OFF) {
519 ret = regulator_bulk_enable(ARRAY_SIZE(wm8804->supplies), 518 ret = regulator_bulk_enable(ARRAY_SIZE(wm8804->supplies),
520 wm8804->supplies); 519 wm8804->supplies);
521 if (ret) { 520 if (ret) {
@@ -537,7 +536,7 @@ static int wm8804_set_bias_level(struct snd_soc_codec *codec,
537 break; 536 break;
538 } 537 }
539 538
540 codec->bias_level = level; 539 codec->dapm.bias_level = level;
541 return 0; 540 return 0;
542} 541}
543 542
@@ -581,7 +580,7 @@ static int wm8804_probe(struct snd_soc_codec *codec)
581 wm8804 = snd_soc_codec_get_drvdata(codec); 580 wm8804 = snd_soc_codec_get_drvdata(codec);
582 wm8804->codec = codec; 581 wm8804->codec = codec;
583 582
584 codec->idle_bias_off = 1; 583 codec->dapm.idle_bias_off = 1;
585 584
586 ret = snd_soc_codec_set_cache_io(codec, 8, 8, wm8804->control_type); 585 ret = snd_soc_codec_set_cache_io(codec, 8, 8, wm8804->control_type);
587 if (ret < 0) { 586 if (ret < 0) {
diff --git a/sound/soc/codecs/wm8900.c b/sound/soc/codecs/wm8900.c
index aca4b1ea10bb..cd0959926d12 100644
--- a/sound/soc/codecs/wm8900.c
+++ b/sound/soc/codecs/wm8900.c
@@ -30,7 +30,6 @@
30#include <sound/pcm.h> 30#include <sound/pcm.h>
31#include <sound/pcm_params.h> 31#include <sound/pcm_params.h>
32#include <sound/soc.h> 32#include <sound/soc.h>
33#include <sound/soc-dapm.h>
34#include <sound/initval.h> 33#include <sound/initval.h>
35#include <sound/tlv.h> 34#include <sound/tlv.h>
36 35
@@ -140,7 +139,6 @@
140 139
141struct wm8900_priv { 140struct wm8900_priv {
142 enum snd_soc_control_type control_type; 141 enum snd_soc_control_type control_type;
143 u16 reg_cache[WM8900_MAXREG];
144 142
145 u32 fll_in; /* FLL input frequency */ 143 u32 fll_in; /* FLL input frequency */
146 u32 fll_out; /* FLL output frequency */ 144 u32 fll_out; /* FLL output frequency */
@@ -611,10 +609,11 @@ static const struct snd_soc_dapm_route audio_map[] = {
611 609
612static int wm8900_add_widgets(struct snd_soc_codec *codec) 610static int wm8900_add_widgets(struct snd_soc_codec *codec)
613{ 611{
614 snd_soc_dapm_new_controls(codec, wm8900_dapm_widgets, 612 struct snd_soc_dapm_context *dapm = &codec->dapm;
615 ARRAY_SIZE(wm8900_dapm_widgets));
616 613
617 snd_soc_dapm_add_routes(codec, audio_map, ARRAY_SIZE(audio_map)); 614 snd_soc_dapm_new_controls(dapm, wm8900_dapm_widgets,
615 ARRAY_SIZE(wm8900_dapm_widgets));
616 snd_soc_dapm_add_routes(dapm, audio_map, ARRAY_SIZE(audio_map));
618 617
619 return 0; 618 return 0;
620} 619}
@@ -1051,7 +1050,7 @@ static int wm8900_set_bias_level(struct snd_soc_codec *codec,
1051 1050
1052 case SND_SOC_BIAS_STANDBY: 1051 case SND_SOC_BIAS_STANDBY:
1053 /* Charge capacitors if initial power up */ 1052 /* Charge capacitors if initial power up */
1054 if (codec->bias_level == SND_SOC_BIAS_OFF) { 1053 if (codec->dapm.bias_level == SND_SOC_BIAS_OFF) {
1055 /* STARTUP_BIAS_ENA on */ 1054 /* STARTUP_BIAS_ENA on */
1056 snd_soc_write(codec, WM8900_REG_POWER1, 1055 snd_soc_write(codec, WM8900_REG_POWER1,
1057 WM8900_REG_POWER1_STARTUP_BIAS_ENA); 1056 WM8900_REG_POWER1_STARTUP_BIAS_ENA);
@@ -1119,7 +1118,7 @@ static int wm8900_set_bias_level(struct snd_soc_codec *codec,
1119 WM8900_REG_POWER2_SYSCLK_ENA); 1118 WM8900_REG_POWER2_SYSCLK_ENA);
1120 break; 1119 break;
1121 } 1120 }
1122 codec->bias_level = level; 1121 codec->dapm.bias_level = level;
1123 return 0; 1122 return 0;
1124} 1123}
1125 1124
diff --git a/sound/soc/codecs/wm8903.c b/sound/soc/codecs/wm8903.c
index 622b60238a82..987476a5895f 100644
--- a/sound/soc/codecs/wm8903.c
+++ b/sound/soc/codecs/wm8903.c
@@ -29,9 +29,9 @@
29#include <sound/pcm_params.h> 29#include <sound/pcm_params.h>
30#include <sound/tlv.h> 30#include <sound/tlv.h>
31#include <sound/soc.h> 31#include <sound/soc.h>
32#include <sound/soc-dapm.h>
33#include <sound/initval.h> 32#include <sound/initval.h>
34#include <sound/wm8903.h> 33#include <sound/wm8903.h>
34#include <trace/events/asoc.h>
35 35
36#include "wm8903.h" 36#include "wm8903.h"
37 37
@@ -214,15 +214,14 @@ static u16 wm8903_reg_defaults[] = {
214 214
215struct wm8903_priv { 215struct wm8903_priv {
216 216
217 u16 reg_cache[ARRAY_SIZE(wm8903_reg_defaults)];
218
219 int sysclk; 217 int sysclk;
220 int irq; 218 int irq;
221 219
222 /* Reference counts */ 220 int fs;
221 int deemph;
222
223 /* Reference count */
223 int class_w_users; 224 int class_w_users;
224 int playback_active;
225 int capture_active;
226 225
227 struct completion wseq; 226 struct completion wseq;
228 227
@@ -231,9 +230,6 @@ struct wm8903_priv {
231 int mic_short; 230 int mic_short;
232 int mic_last_report; 231 int mic_last_report;
233 int mic_delay; 232 int mic_delay;
234
235 struct snd_pcm_substream *master_substream;
236 struct snd_pcm_substream *slave_substream;
237}; 233};
238 234
239static int wm8903_volatile_register(unsigned int reg) 235static int wm8903_volatile_register(unsigned int reg)
@@ -463,6 +459,72 @@ static int wm8903_class_w_put(struct snd_kcontrol *kcontrol,
463 .private_value = SOC_SINGLE_VALUE(reg, shift, max, invert) } 459 .private_value = SOC_SINGLE_VALUE(reg, shift, max, invert) }
464 460
465 461
462static int wm8903_deemph[] = { 0, 32000, 44100, 48000 };
463
464static int wm8903_set_deemph(struct snd_soc_codec *codec)
465{
466 struct wm8903_priv *wm8903 = snd_soc_codec_get_drvdata(codec);
467 int val, i, best;
468
469 /* If we're using deemphasis select the nearest available sample
470 * rate.
471 */
472 if (wm8903->deemph) {
473 best = 1;
474 for (i = 2; i < ARRAY_SIZE(wm8903_deemph); i++) {
475 if (abs(wm8903_deemph[i] - wm8903->fs) <
476 abs(wm8903_deemph[best] - wm8903->fs))
477 best = i;
478 }
479
480 val = best << WM8903_DEEMPH_SHIFT;
481 } else {
482 best = 0;
483 val = 0;
484 }
485
486 dev_dbg(codec->dev, "Set deemphasis %d (%dHz)\n",
487 best, wm8903_deemph[best]);
488
489 return snd_soc_update_bits(codec, WM8903_DAC_DIGITAL_1,
490 WM8903_DEEMPH_MASK, val);
491}
492
493static int wm8903_get_deemph(struct snd_kcontrol *kcontrol,
494 struct snd_ctl_elem_value *ucontrol)
495{
496 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
497 struct wm8903_priv *wm8903 = snd_soc_codec_get_drvdata(codec);
498
499 ucontrol->value.enumerated.item[0] = wm8903->deemph;
500
501 return 0;
502}
503
504static int wm8903_put_deemph(struct snd_kcontrol *kcontrol,
505 struct snd_ctl_elem_value *ucontrol)
506{
507 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
508 struct wm8903_priv *wm8903 = snd_soc_codec_get_drvdata(codec);
509 int deemph = ucontrol->value.enumerated.item[0];
510 int ret = 0;
511
512 if (deemph > 1)
513 return -EINVAL;
514
515 mutex_lock(&codec->mutex);
516 if (wm8903->deemph != deemph) {
517 wm8903->deemph = deemph;
518
519 wm8903_set_deemph(codec);
520
521 ret = 1;
522 }
523 mutex_unlock(&codec->mutex);
524
525 return ret;
526}
527
466/* ALSA can only do steps of .01dB */ 528/* ALSA can only do steps of .01dB */
467static const DECLARE_TLV_DB_SCALE(digital_tlv, -7200, 75, 1); 529static const DECLARE_TLV_DB_SCALE(digital_tlv, -7200, 75, 1);
468 530
@@ -475,6 +537,23 @@ static const DECLARE_TLV_DB_SCALE(drc_tlv_min, 0, 600, 0);
475static const DECLARE_TLV_DB_SCALE(drc_tlv_max, 1200, 600, 0); 537static const DECLARE_TLV_DB_SCALE(drc_tlv_max, 1200, 600, 0);
476static const DECLARE_TLV_DB_SCALE(drc_tlv_startup, -300, 50, 0); 538static const DECLARE_TLV_DB_SCALE(drc_tlv_startup, -300, 50, 0);
477 539
540static const char *hpf_mode_text[] = {
541 "Hi-fi", "Voice 1", "Voice 2", "Voice 3"
542};
543
544static const struct soc_enum hpf_mode =
545 SOC_ENUM_SINGLE(WM8903_ADC_DIGITAL_0, 5, 4, hpf_mode_text);
546
547static const char *osr_text[] = {
548 "Low power", "High performance"
549};
550
551static const struct soc_enum adc_osr =
552 SOC_ENUM_SINGLE(WM8903_ANALOGUE_ADC_0, 0, 2, osr_text);
553
554static const struct soc_enum dac_osr =
555 SOC_ENUM_SINGLE(WM8903_DAC_DIGITAL_1, 0, 2, osr_text);
556
478static const char *drc_slope_text[] = { 557static const char *drc_slope_text[] = {
479 "1", "1/2", "1/4", "1/8", "1/16", "0" 558 "1", "1/2", "1/4", "1/8", "1/16", "0"
480}; 559};
@@ -537,13 +616,6 @@ static const char *mute_mode_text[] = {
537static const struct soc_enum mute_mode = 616static const struct soc_enum mute_mode =
538 SOC_ENUM_SINGLE(WM8903_DAC_DIGITAL_1, 9, 2, mute_mode_text); 617 SOC_ENUM_SINGLE(WM8903_DAC_DIGITAL_1, 9, 2, mute_mode_text);
539 618
540static const char *dac_deemphasis_text[] = {
541 "Disabled", "32kHz", "44.1kHz", "48kHz"
542};
543
544static const struct soc_enum dac_deemphasis =
545 SOC_ENUM_SINGLE(WM8903_DAC_DIGITAL_1, 1, 4, dac_deemphasis_text);
546
547static const char *companding_text[] = { 619static const char *companding_text[] = {
548 "ulaw", "alaw" 620 "ulaw", "alaw"
549}; 621};
@@ -613,6 +685,9 @@ SOC_SINGLE("Right Input PGA Common Mode Switch", WM8903_ANALOGUE_RIGHT_INPUT_1,
613 6, 1, 0), 685 6, 1, 0),
614 686
615/* ADCs */ 687/* ADCs */
688SOC_ENUM("ADC OSR", adc_osr),
689SOC_SINGLE("HPF Switch", WM8903_ADC_DIGITAL_0, 4, 1, 0),
690SOC_ENUM("HPF Mode", hpf_mode),
616SOC_SINGLE("DRC Switch", WM8903_DRC_0, 15, 1, 0), 691SOC_SINGLE("DRC Switch", WM8903_DRC_0, 15, 1, 0),
617SOC_ENUM("DRC Compressor Slope R0", drc_slope_r0), 692SOC_ENUM("DRC Compressor Slope R0", drc_slope_r0),
618SOC_ENUM("DRC Compressor Slope R1", drc_slope_r1), 693SOC_ENUM("DRC Compressor Slope R1", drc_slope_r1),
@@ -642,14 +717,16 @@ SOC_DOUBLE_TLV("Digital Sidetone Volume", WM8903_DAC_DIGITAL_0, 4, 8,
642 12, 0, digital_sidetone_tlv), 717 12, 0, digital_sidetone_tlv),
643 718
644/* DAC */ 719/* DAC */
720SOC_ENUM("DAC OSR", dac_osr),
645SOC_DOUBLE_R_TLV("Digital Playback Volume", WM8903_DAC_DIGITAL_VOLUME_LEFT, 721SOC_DOUBLE_R_TLV("Digital Playback Volume", WM8903_DAC_DIGITAL_VOLUME_LEFT,
646 WM8903_DAC_DIGITAL_VOLUME_RIGHT, 1, 120, 0, digital_tlv), 722 WM8903_DAC_DIGITAL_VOLUME_RIGHT, 1, 120, 0, digital_tlv),
647SOC_ENUM("DAC Soft Mute Rate", soft_mute), 723SOC_ENUM("DAC Soft Mute Rate", soft_mute),
648SOC_ENUM("DAC Mute Mode", mute_mode), 724SOC_ENUM("DAC Mute Mode", mute_mode),
649SOC_SINGLE("DAC Mono Switch", WM8903_DAC_DIGITAL_1, 12, 1, 0), 725SOC_SINGLE("DAC Mono Switch", WM8903_DAC_DIGITAL_1, 12, 1, 0),
650SOC_ENUM("DAC De-emphasis", dac_deemphasis),
651SOC_ENUM("DAC Companding Mode", dac_companding), 726SOC_ENUM("DAC Companding Mode", dac_companding),
652SOC_SINGLE("DAC Companding Switch", WM8903_AUDIO_INTERFACE_0, 1, 1, 0), 727SOC_SINGLE("DAC Companding Switch", WM8903_AUDIO_INTERFACE_0, 1, 1, 0),
728SOC_SINGLE_BOOL_EXT("Playback Deemphasis Switch", 0,
729 wm8903_get_deemph, wm8903_put_deemph),
653 730
654/* Headphones */ 731/* Headphones */
655SOC_DOUBLE_R("Headphone Switch", 732SOC_DOUBLE_R("Headphone Switch",
@@ -923,10 +1000,11 @@ static const struct snd_soc_dapm_route intercon[] = {
923 1000
924static int wm8903_add_widgets(struct snd_soc_codec *codec) 1001static int wm8903_add_widgets(struct snd_soc_codec *codec)
925{ 1002{
926 snd_soc_dapm_new_controls(codec, wm8903_dapm_widgets, 1003 struct snd_soc_dapm_context *dapm = &codec->dapm;
927 ARRAY_SIZE(wm8903_dapm_widgets));
928 1004
929 snd_soc_dapm_add_routes(codec, intercon, ARRAY_SIZE(intercon)); 1005 snd_soc_dapm_new_controls(dapm, wm8903_dapm_widgets,
1006 ARRAY_SIZE(wm8903_dapm_widgets));
1007 snd_soc_dapm_add_routes(dapm, intercon, ARRAY_SIZE(intercon));
930 1008
931 return 0; 1009 return 0;
932} 1010}
@@ -934,7 +1012,7 @@ static int wm8903_add_widgets(struct snd_soc_codec *codec)
934static int wm8903_set_bias_level(struct snd_soc_codec *codec, 1012static int wm8903_set_bias_level(struct snd_soc_codec *codec,
935 enum snd_soc_bias_level level) 1013 enum snd_soc_bias_level level)
936{ 1014{
937 u16 reg, reg2; 1015 u16 reg;
938 1016
939 switch (level) { 1017 switch (level) {
940 case SND_SOC_BIAS_ON: 1018 case SND_SOC_BIAS_ON:
@@ -946,7 +1024,7 @@ static int wm8903_set_bias_level(struct snd_soc_codec *codec,
946 break; 1024 break;
947 1025
948 case SND_SOC_BIAS_STANDBY: 1026 case SND_SOC_BIAS_STANDBY:
949 if (codec->bias_level == SND_SOC_BIAS_OFF) { 1027 if (codec->dapm.bias_level == SND_SOC_BIAS_OFF) {
950 snd_soc_write(codec, WM8903_CLOCK_RATES_2, 1028 snd_soc_write(codec, WM8903_CLOCK_RATES_2,
951 WM8903_CLK_SYS_ENA); 1029 WM8903_CLK_SYS_ENA);
952 1030
@@ -958,23 +1036,15 @@ static int wm8903_set_bias_level(struct snd_soc_codec *codec,
958 wm8903_run_sequence(codec, 0); 1036 wm8903_run_sequence(codec, 0);
959 wm8903_sync_reg_cache(codec, codec->reg_cache); 1037 wm8903_sync_reg_cache(codec, codec->reg_cache);
960 1038
961 /* Enable low impedence charge pump output */
962 reg = snd_soc_read(codec,
963 WM8903_CONTROL_INTERFACE_TEST_1);
964 snd_soc_write(codec, WM8903_CONTROL_INTERFACE_TEST_1,
965 reg | WM8903_TEST_KEY);
966 reg2 = snd_soc_read(codec, WM8903_CHARGE_PUMP_TEST_1);
967 snd_soc_write(codec, WM8903_CHARGE_PUMP_TEST_1,
968 reg2 | WM8903_CP_SW_KELVIN_MODE_MASK);
969 snd_soc_write(codec, WM8903_CONTROL_INTERFACE_TEST_1,
970 reg);
971
972 /* By default no bypass paths are enabled so 1039 /* By default no bypass paths are enabled so
973 * enable Class W support. 1040 * enable Class W support.
974 */ 1041 */
975 dev_dbg(codec->dev, "Enabling Class W\n"); 1042 dev_dbg(codec->dev, "Enabling Class W\n");
976 snd_soc_write(codec, WM8903_CLASS_W_0, reg | 1043 snd_soc_update_bits(codec, WM8903_CLASS_W_0,
977 WM8903_CP_DYN_FREQ | WM8903_CP_DYN_V); 1044 WM8903_CP_DYN_FREQ |
1045 WM8903_CP_DYN_V,
1046 WM8903_CP_DYN_FREQ |
1047 WM8903_CP_DYN_V);
978 } 1048 }
979 1049
980 reg = snd_soc_read(codec, WM8903_VMID_CONTROL_0); 1050 reg = snd_soc_read(codec, WM8903_VMID_CONTROL_0);
@@ -991,7 +1061,7 @@ static int wm8903_set_bias_level(struct snd_soc_codec *codec,
991 break; 1061 break;
992 } 1062 }
993 1063
994 codec->bias_level = level; 1064 codec->dapm.bias_level = level;
995 1065
996 return 0; 1066 return 0;
997} 1067}
@@ -1222,58 +1292,6 @@ static struct {
1222 { 0, 0 }, 1292 { 0, 0 },
1223}; 1293};
1224 1294
1225static int wm8903_startup(struct snd_pcm_substream *substream,
1226 struct snd_soc_dai *dai)
1227{
1228 struct snd_soc_pcm_runtime *rtd = substream->private_data;
1229 struct snd_soc_codec *codec = rtd->codec;
1230 struct wm8903_priv *wm8903 = snd_soc_codec_get_drvdata(codec);
1231 struct snd_pcm_runtime *master_runtime;
1232
1233 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
1234 wm8903->playback_active++;
1235 else
1236 wm8903->capture_active++;
1237
1238 /* The DAI has shared clocks so if we already have a playback or
1239 * capture going then constrain this substream to match it.
1240 */
1241 if (wm8903->master_substream) {
1242 master_runtime = wm8903->master_substream->runtime;
1243
1244 dev_dbg(codec->dev, "Constraining to %d bits\n",
1245 master_runtime->sample_bits);
1246
1247 snd_pcm_hw_constraint_minmax(substream->runtime,
1248 SNDRV_PCM_HW_PARAM_SAMPLE_BITS,
1249 master_runtime->sample_bits,
1250 master_runtime->sample_bits);
1251
1252 wm8903->slave_substream = substream;
1253 } else
1254 wm8903->master_substream = substream;
1255
1256 return 0;
1257}
1258
1259static void wm8903_shutdown(struct snd_pcm_substream *substream,
1260 struct snd_soc_dai *dai)
1261{
1262 struct snd_soc_pcm_runtime *rtd = substream->private_data;
1263 struct snd_soc_codec *codec = rtd->codec;
1264 struct wm8903_priv *wm8903 = snd_soc_codec_get_drvdata(codec);
1265
1266 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
1267 wm8903->playback_active--;
1268 else
1269 wm8903->capture_active--;
1270
1271 if (wm8903->master_substream == substream)
1272 wm8903->master_substream = wm8903->slave_substream;
1273
1274 wm8903->slave_substream = NULL;
1275}
1276
1277static int wm8903_hw_params(struct snd_pcm_substream *substream, 1295static int wm8903_hw_params(struct snd_pcm_substream *substream,
1278 struct snd_pcm_hw_params *params, 1296 struct snd_pcm_hw_params *params,
1279 struct snd_soc_dai *dai) 1297 struct snd_soc_dai *dai)
@@ -1298,11 +1316,6 @@ static int wm8903_hw_params(struct snd_pcm_substream *substream,
1298 u16 clock1 = snd_soc_read(codec, WM8903_CLOCK_RATES_1); 1316 u16 clock1 = snd_soc_read(codec, WM8903_CLOCK_RATES_1);
1299 u16 dac_digital1 = snd_soc_read(codec, WM8903_DAC_DIGITAL_1); 1317 u16 dac_digital1 = snd_soc_read(codec, WM8903_DAC_DIGITAL_1);
1300 1318
1301 if (substream == wm8903->slave_substream) {
1302 dev_dbg(codec->dev, "Ignoring hw_params for slave substream\n");
1303 return 0;
1304 }
1305
1306 /* Enable sloping stopband filter for low sample rates */ 1319 /* Enable sloping stopband filter for low sample rates */
1307 if (fs <= 24000) 1320 if (fs <= 24000)
1308 dac_digital1 |= WM8903_DAC_SB_FILT; 1321 dac_digital1 |= WM8903_DAC_SB_FILT;
@@ -1320,19 +1333,6 @@ static int wm8903_hw_params(struct snd_pcm_substream *substream,
1320 } 1333 }
1321 } 1334 }
1322 1335
1323 /* Constraints should stop us hitting this but let's make sure */
1324 if (wm8903->capture_active)
1325 switch (sample_rates[dsp_config].rate) {
1326 case 88200:
1327 case 96000:
1328 dev_err(codec->dev, "%dHz unsupported by ADC\n",
1329 fs);
1330 return -EINVAL;
1331
1332 default:
1333 break;
1334 }
1335
1336 dev_dbg(codec->dev, "DSP fs = %dHz\n", sample_rates[dsp_config].rate); 1336 dev_dbg(codec->dev, "DSP fs = %dHz\n", sample_rates[dsp_config].rate);
1337 clock1 &= ~WM8903_SAMPLE_RATE_MASK; 1337 clock1 &= ~WM8903_SAMPLE_RATE_MASK;
1338 clock1 |= sample_rates[dsp_config].value; 1338 clock1 |= sample_rates[dsp_config].value;
@@ -1428,6 +1428,9 @@ static int wm8903_hw_params(struct snd_pcm_substream *substream,
1428 aif2 |= bclk_divs[bclk_div].div; 1428 aif2 |= bclk_divs[bclk_div].div;
1429 aif3 |= bclk / fs; 1429 aif3 |= bclk / fs;
1430 1430
1431 wm8903->fs = params_rate(params);
1432 wm8903_set_deemph(codec);
1433
1431 snd_soc_write(codec, WM8903_CLOCK_RATES_0, clock0); 1434 snd_soc_write(codec, WM8903_CLOCK_RATES_0, clock0);
1432 snd_soc_write(codec, WM8903_CLOCK_RATES_1, clock1); 1435 snd_soc_write(codec, WM8903_CLOCK_RATES_1, clock1);
1433 snd_soc_write(codec, WM8903_AUDIO_INTERFACE_1, aif1); 1436 snd_soc_write(codec, WM8903_AUDIO_INTERFACE_1, aif1);
@@ -1521,6 +1524,11 @@ static irqreturn_t wm8903_irq(int irq, void *data)
1521 mic_report = wm8903->mic_last_report; 1524 mic_report = wm8903->mic_last_report;
1522 int_pol = snd_soc_read(codec, WM8903_INTERRUPT_POLARITY_1); 1525 int_pol = snd_soc_read(codec, WM8903_INTERRUPT_POLARITY_1);
1523 1526
1527#ifndef CONFIG_SND_SOC_WM8903_MODULE
1528 if (int_val & (WM8903_MICSHRT_EINT | WM8903_MICDET_EINT))
1529 trace_snd_soc_jack_irq(dev_name(codec->dev));
1530#endif
1531
1524 if (int_val & WM8903_MICSHRT_EINT) { 1532 if (int_val & WM8903_MICSHRT_EINT) {
1525 dev_dbg(codec->dev, "Microphone short (pol=%x)\n", int_pol); 1533 dev_dbg(codec->dev, "Microphone short (pol=%x)\n", int_pol);
1526 1534
@@ -1571,8 +1579,6 @@ static irqreturn_t wm8903_irq(int irq, void *data)
1571 SNDRV_PCM_FMTBIT_S24_LE) 1579 SNDRV_PCM_FMTBIT_S24_LE)
1572 1580
1573static struct snd_soc_dai_ops wm8903_dai_ops = { 1581static struct snd_soc_dai_ops wm8903_dai_ops = {
1574 .startup = wm8903_startup,
1575 .shutdown = wm8903_shutdown,
1576 .hw_params = wm8903_hw_params, 1582 .hw_params = wm8903_hw_params,
1577 .digital_mute = wm8903_digital_mute, 1583 .digital_mute = wm8903_digital_mute,
1578 .set_fmt = wm8903_set_dai_fmt, 1584 .set_fmt = wm8903_set_dai_fmt,
diff --git a/sound/soc/codecs/wm8903.h b/sound/soc/codecs/wm8903.h
index 996435e681e5..e8490f3edd03 100644
--- a/sound/soc/codecs/wm8903.h
+++ b/sound/soc/codecs/wm8903.h
@@ -19,10 +19,6 @@ extern int wm8903_mic_detect(struct snd_soc_codec *codec,
19 struct snd_soc_jack *jack, 19 struct snd_soc_jack *jack,
20 int det, int shrt); 20 int det, int shrt);
21 21
22#define WM8903_MCLK_DIV_2 1
23#define WM8903_CLK_SYS 2
24#define WM8903_BCLK 3
25#define WM8903_LRCLK 4
26 22
27/* 23/*
28 * Register values. 24 * Register values.
@@ -98,8 +94,6 @@ extern int wm8903_mic_detect(struct snd_soc_codec *codec,
98#define WM8903_INTERRUPT_STATUS_1_MASK 0x7A 94#define WM8903_INTERRUPT_STATUS_1_MASK 0x7A
99#define WM8903_INTERRUPT_POLARITY_1 0x7B 95#define WM8903_INTERRUPT_POLARITY_1 0x7B
100#define WM8903_INTERRUPT_CONTROL 0x7E 96#define WM8903_INTERRUPT_CONTROL 0x7E
101#define WM8903_CONTROL_INTERFACE_TEST_1 0x81
102#define WM8903_CHARGE_PUMP_TEST_1 0x95
103#define WM8903_CLOCK_RATE_TEST_4 0xA4 97#define WM8903_CLOCK_RATE_TEST_4 0xA4
104#define WM8903_ANALOGUE_OUTPUT_BIAS_0 0xAC 98#define WM8903_ANALOGUE_OUTPUT_BIAS_0 0xAC
105 99
@@ -1206,25 +1200,6 @@ extern int wm8903_mic_detect(struct snd_soc_codec *codec,
1206#define WM8903_IRQ_POL_WIDTH 1 /* IRQ_POL */ 1200#define WM8903_IRQ_POL_WIDTH 1 /* IRQ_POL */
1207 1201
1208/* 1202/*
1209 * R129 (0x81) - Control Interface Test 1
1210 */
1211#define WM8903_USER_KEY 0x0002 /* USER_KEY */
1212#define WM8903_USER_KEY_MASK 0x0002 /* USER_KEY */
1213#define WM8903_USER_KEY_SHIFT 1 /* USER_KEY */
1214#define WM8903_USER_KEY_WIDTH 1 /* USER_KEY */
1215#define WM8903_TEST_KEY 0x0001 /* TEST_KEY */
1216#define WM8903_TEST_KEY_MASK 0x0001 /* TEST_KEY */
1217#define WM8903_TEST_KEY_SHIFT 0 /* TEST_KEY */
1218#define WM8903_TEST_KEY_WIDTH 1 /* TEST_KEY */
1219
1220/*
1221 * R149 (0x95) - Charge Pump Test 1
1222 */
1223#define WM8903_CP_SW_KELVIN_MODE_MASK 0x0006 /* CP_SW_KELVIN_MODE - [2:1] */
1224#define WM8903_CP_SW_KELVIN_MODE_SHIFT 1 /* CP_SW_KELVIN_MODE - [2:1] */
1225#define WM8903_CP_SW_KELVIN_MODE_WIDTH 2 /* CP_SW_KELVIN_MODE - [2:1] */
1226
1227/*
1228 * R164 (0xA4) - Clock Rate Test 4 1203 * R164 (0xA4) - Clock Rate Test 4
1229 */ 1204 */
1230#define WM8903_ADC_DIG_MIC 0x0200 /* ADC_DIG_MIC */ 1205#define WM8903_ADC_DIG_MIC 0x0200 /* ADC_DIG_MIC */
diff --git a/sound/soc/codecs/wm8904.c b/sound/soc/codecs/wm8904.c
index 1ec12eff0620..9de44a4c05c0 100644
--- a/sound/soc/codecs/wm8904.c
+++ b/sound/soc/codecs/wm8904.c
@@ -24,7 +24,6 @@
24#include <sound/pcm.h> 24#include <sound/pcm.h>
25#include <sound/pcm_params.h> 25#include <sound/pcm_params.h>
26#include <sound/soc.h> 26#include <sound/soc.h>
27#include <sound/soc-dapm.h>
28#include <sound/initval.h> 27#include <sound/initval.h>
29#include <sound/tlv.h> 28#include <sound/tlv.h>
30#include <sound/wm8904.h> 29#include <sound/wm8904.h>
@@ -1427,10 +1426,11 @@ static const struct snd_soc_dapm_route wm8912_intercon[] = {
1427static int wm8904_add_widgets(struct snd_soc_codec *codec) 1426static int wm8904_add_widgets(struct snd_soc_codec *codec)
1428{ 1427{
1429 struct wm8904_priv *wm8904 = snd_soc_codec_get_drvdata(codec); 1428 struct wm8904_priv *wm8904 = snd_soc_codec_get_drvdata(codec);
1429 struct snd_soc_dapm_context *dapm = &codec->dapm;
1430 1430
1431 snd_soc_dapm_new_controls(codec, wm8904_core_dapm_widgets, 1431 snd_soc_dapm_new_controls(dapm, wm8904_core_dapm_widgets,
1432 ARRAY_SIZE(wm8904_core_dapm_widgets)); 1432 ARRAY_SIZE(wm8904_core_dapm_widgets));
1433 snd_soc_dapm_add_routes(codec, core_intercon, 1433 snd_soc_dapm_add_routes(dapm, core_intercon,
1434 ARRAY_SIZE(core_intercon)); 1434 ARRAY_SIZE(core_intercon));
1435 1435
1436 switch (wm8904->devtype) { 1436 switch (wm8904->devtype) {
@@ -1442,20 +1442,20 @@ static int wm8904_add_widgets(struct snd_soc_codec *codec)
1442 snd_soc_add_controls(codec, wm8904_snd_controls, 1442 snd_soc_add_controls(codec, wm8904_snd_controls,
1443 ARRAY_SIZE(wm8904_snd_controls)); 1443 ARRAY_SIZE(wm8904_snd_controls));
1444 1444
1445 snd_soc_dapm_new_controls(codec, wm8904_adc_dapm_widgets, 1445 snd_soc_dapm_new_controls(dapm, wm8904_adc_dapm_widgets,
1446 ARRAY_SIZE(wm8904_adc_dapm_widgets)); 1446 ARRAY_SIZE(wm8904_adc_dapm_widgets));
1447 snd_soc_dapm_new_controls(codec, wm8904_dac_dapm_widgets, 1447 snd_soc_dapm_new_controls(dapm, wm8904_dac_dapm_widgets,
1448 ARRAY_SIZE(wm8904_dac_dapm_widgets)); 1448 ARRAY_SIZE(wm8904_dac_dapm_widgets));
1449 snd_soc_dapm_new_controls(codec, wm8904_dapm_widgets, 1449 snd_soc_dapm_new_controls(dapm, wm8904_dapm_widgets,
1450 ARRAY_SIZE(wm8904_dapm_widgets)); 1450 ARRAY_SIZE(wm8904_dapm_widgets));
1451 1451
1452 snd_soc_dapm_add_routes(codec, core_intercon, 1452 snd_soc_dapm_add_routes(dapm, core_intercon,
1453 ARRAY_SIZE(core_intercon)); 1453 ARRAY_SIZE(core_intercon));
1454 snd_soc_dapm_add_routes(codec, adc_intercon, 1454 snd_soc_dapm_add_routes(dapm, adc_intercon,
1455 ARRAY_SIZE(adc_intercon)); 1455 ARRAY_SIZE(adc_intercon));
1456 snd_soc_dapm_add_routes(codec, dac_intercon, 1456 snd_soc_dapm_add_routes(dapm, dac_intercon,
1457 ARRAY_SIZE(dac_intercon)); 1457 ARRAY_SIZE(dac_intercon));
1458 snd_soc_dapm_add_routes(codec, wm8904_intercon, 1458 snd_soc_dapm_add_routes(dapm, wm8904_intercon,
1459 ARRAY_SIZE(wm8904_intercon)); 1459 ARRAY_SIZE(wm8904_intercon));
1460 break; 1460 break;
1461 1461
@@ -1463,17 +1463,17 @@ static int wm8904_add_widgets(struct snd_soc_codec *codec)
1463 snd_soc_add_controls(codec, wm8904_dac_snd_controls, 1463 snd_soc_add_controls(codec, wm8904_dac_snd_controls,
1464 ARRAY_SIZE(wm8904_dac_snd_controls)); 1464 ARRAY_SIZE(wm8904_dac_snd_controls));
1465 1465
1466 snd_soc_dapm_new_controls(codec, wm8904_dac_dapm_widgets, 1466 snd_soc_dapm_new_controls(dapm, wm8904_dac_dapm_widgets,
1467 ARRAY_SIZE(wm8904_dac_dapm_widgets)); 1467 ARRAY_SIZE(wm8904_dac_dapm_widgets));
1468 1468
1469 snd_soc_dapm_add_routes(codec, dac_intercon, 1469 snd_soc_dapm_add_routes(dapm, dac_intercon,
1470 ARRAY_SIZE(dac_intercon)); 1470 ARRAY_SIZE(dac_intercon));
1471 snd_soc_dapm_add_routes(codec, wm8912_intercon, 1471 snd_soc_dapm_add_routes(dapm, wm8912_intercon,
1472 ARRAY_SIZE(wm8912_intercon)); 1472 ARRAY_SIZE(wm8912_intercon));
1473 break; 1473 break;
1474 } 1474 }
1475 1475
1476 snd_soc_dapm_new_widgets(codec); 1476 snd_soc_dapm_new_widgets(dapm);
1477 return 0; 1477 return 0;
1478} 1478}
1479 1479
@@ -1589,7 +1589,7 @@ static int wm8904_hw_params(struct snd_pcm_substream *substream,
1589 - wm8904->fs); 1589 - wm8904->fs);
1590 for (i = 1; i < ARRAY_SIZE(clk_sys_rates); i++) { 1590 for (i = 1; i < ARRAY_SIZE(clk_sys_rates); i++) {
1591 cur_val = abs((wm8904->sysclk_rate / 1591 cur_val = abs((wm8904->sysclk_rate /
1592 clk_sys_rates[i].ratio) - wm8904->fs);; 1592 clk_sys_rates[i].ratio) - wm8904->fs);
1593 if (cur_val < best_val) { 1593 if (cur_val < best_val) {
1594 best = i; 1594 best = i;
1595 best_val = cur_val; 1595 best_val = cur_val;
@@ -2138,7 +2138,7 @@ static int wm8904_set_bias_level(struct snd_soc_codec *codec,
2138 break; 2138 break;
2139 2139
2140 case SND_SOC_BIAS_STANDBY: 2140 case SND_SOC_BIAS_STANDBY:
2141 if (codec->bias_level == SND_SOC_BIAS_OFF) { 2141 if (codec->dapm.bias_level == SND_SOC_BIAS_OFF) {
2142 ret = regulator_bulk_enable(ARRAY_SIZE(wm8904->supplies), 2142 ret = regulator_bulk_enable(ARRAY_SIZE(wm8904->supplies),
2143 wm8904->supplies); 2143 wm8904->supplies);
2144 if (ret != 0) { 2144 if (ret != 0) {
@@ -2197,7 +2197,7 @@ static int wm8904_set_bias_level(struct snd_soc_codec *codec,
2197 wm8904->supplies); 2197 wm8904->supplies);
2198 break; 2198 break;
2199 } 2199 }
2200 codec->bias_level = level; 2200 codec->dapm.bias_level = level;
2201 return 0; 2201 return 0;
2202} 2202}
2203 2203
@@ -2373,7 +2373,7 @@ static int wm8904_probe(struct snd_soc_codec *codec)
2373 int ret, i; 2373 int ret, i;
2374 2374
2375 codec->cache_sync = 1; 2375 codec->cache_sync = 1;
2376 codec->idle_bias_off = 1; 2376 codec->dapm.idle_bias_off = 1;
2377 2377
2378 switch (wm8904->devtype) { 2378 switch (wm8904->devtype) {
2379 case WM8904: 2379 case WM8904:
diff --git a/sound/soc/codecs/wm8940.c b/sound/soc/codecs/wm8940.c
index 23086e2c976a..25580e3ee7c4 100644
--- a/sound/soc/codecs/wm8940.c
+++ b/sound/soc/codecs/wm8940.c
@@ -35,7 +35,6 @@
35#include <sound/pcm.h> 35#include <sound/pcm.h>
36#include <sound/pcm_params.h> 36#include <sound/pcm_params.h>
37#include <sound/soc.h> 37#include <sound/soc.h>
38#include <sound/soc-dapm.h>
39#include <sound/initval.h> 38#include <sound/initval.h>
40#include <sound/tlv.h> 39#include <sound/tlv.h>
41 40
@@ -43,7 +42,6 @@
43 42
44struct wm8940_priv { 43struct wm8940_priv {
45 unsigned int sysclk; 44 unsigned int sysclk;
46 u16 reg_cache[WM8940_CACHEREGNUM];
47 enum snd_soc_control_type control_type; 45 enum snd_soc_control_type control_type;
48 void *control_data; 46 void *control_data;
49}; 47};
@@ -291,13 +289,14 @@ static const struct snd_soc_dapm_route audio_map[] = {
291 289
292static int wm8940_add_widgets(struct snd_soc_codec *codec) 290static int wm8940_add_widgets(struct snd_soc_codec *codec)
293{ 291{
292 struct snd_soc_dapm_context *dapm = &codec->dapm;
294 int ret; 293 int ret;
295 294
296 ret = snd_soc_dapm_new_controls(codec, wm8940_dapm_widgets, 295 ret = snd_soc_dapm_new_controls(dapm, wm8940_dapm_widgets,
297 ARRAY_SIZE(wm8940_dapm_widgets)); 296 ARRAY_SIZE(wm8940_dapm_widgets));
298 if (ret) 297 if (ret)
299 goto error_ret; 298 goto error_ret;
300 ret = snd_soc_dapm_add_routes(codec, audio_map, ARRAY_SIZE(audio_map)); 299 ret = snd_soc_dapm_add_routes(dapm, audio_map, ARRAY_SIZE(audio_map));
301 if (ret) 300 if (ret)
302 goto error_ret; 301 goto error_ret;
303 302
@@ -735,7 +734,6 @@ static int wm8940_probe(struct snd_soc_codec *codec)
735 return ret; 734 return ret;
736 735
737 return ret; 736 return ret;
738;
739} 737}
740 738
741static int wm8940_remove(struct snd_soc_codec *codec) 739static int wm8940_remove(struct snd_soc_codec *codec)
diff --git a/sound/soc/codecs/wm8955.c b/sound/soc/codecs/wm8955.c
index 2ac35b0be86a..7167dfc96aa7 100644
--- a/sound/soc/codecs/wm8955.c
+++ b/sound/soc/codecs/wm8955.c
@@ -23,7 +23,6 @@
23#include <sound/pcm.h> 23#include <sound/pcm.h>
24#include <sound/pcm_params.h> 24#include <sound/pcm_params.h>
25#include <sound/soc.h> 25#include <sound/soc.h>
26#include <sound/soc-dapm.h>
27#include <sound/initval.h> 26#include <sound/initval.h>
28#include <sound/tlv.h> 27#include <sound/tlv.h>
29#include <sound/wm8955.h> 28#include <sound/wm8955.h>
@@ -576,13 +575,14 @@ static const struct snd_soc_dapm_route wm8955_intercon[] = {
576 575
577static int wm8955_add_widgets(struct snd_soc_codec *codec) 576static int wm8955_add_widgets(struct snd_soc_codec *codec)
578{ 577{
578 struct snd_soc_dapm_context *dapm = &codec->dapm;
579
579 snd_soc_add_controls(codec, wm8955_snd_controls, 580 snd_soc_add_controls(codec, wm8955_snd_controls,
580 ARRAY_SIZE(wm8955_snd_controls)); 581 ARRAY_SIZE(wm8955_snd_controls));
581 582
582 snd_soc_dapm_new_controls(codec, wm8955_dapm_widgets, 583 snd_soc_dapm_new_controls(dapm, wm8955_dapm_widgets,
583 ARRAY_SIZE(wm8955_dapm_widgets)); 584 ARRAY_SIZE(wm8955_dapm_widgets));
584 585 snd_soc_dapm_add_routes(dapm, wm8955_intercon,
585 snd_soc_dapm_add_routes(codec, wm8955_intercon,
586 ARRAY_SIZE(wm8955_intercon)); 586 ARRAY_SIZE(wm8955_intercon));
587 587
588 return 0; 588 return 0;
@@ -786,7 +786,7 @@ static int wm8955_set_bias_level(struct snd_soc_codec *codec,
786 break; 786 break;
787 787
788 case SND_SOC_BIAS_STANDBY: 788 case SND_SOC_BIAS_STANDBY:
789 if (codec->bias_level == SND_SOC_BIAS_OFF) { 789 if (codec->dapm.bias_level == SND_SOC_BIAS_OFF) {
790 ret = regulator_bulk_enable(ARRAY_SIZE(wm8955->supplies), 790 ret = regulator_bulk_enable(ARRAY_SIZE(wm8955->supplies),
791 wm8955->supplies); 791 wm8955->supplies);
792 if (ret != 0) { 792 if (ret != 0) {
@@ -850,7 +850,7 @@ static int wm8955_set_bias_level(struct snd_soc_codec *codec,
850 wm8955->supplies); 850 wm8955->supplies);
851 break; 851 break;
852 } 852 }
853 codec->bias_level = level; 853 codec->dapm.bias_level = level;
854 return 0; 854 return 0;
855} 855}
856 856
diff --git a/sound/soc/codecs/wm8960.c b/sound/soc/codecs/wm8960.c
index ff6ff2f529d2..4393394b7bc1 100644
--- a/sound/soc/codecs/wm8960.c
+++ b/sound/soc/codecs/wm8960.c
@@ -20,7 +20,6 @@
20#include <sound/pcm.h> 20#include <sound/pcm.h>
21#include <sound/pcm_params.h> 21#include <sound/pcm_params.h>
22#include <sound/soc.h> 22#include <sound/soc.h>
23#include <sound/soc-dapm.h>
24#include <sound/initval.h> 23#include <sound/initval.h>
25#include <sound/tlv.h> 24#include <sound/tlv.h>
26#include <sound/wm8960.h> 25#include <sound/wm8960.h>
@@ -72,7 +71,6 @@ static const u16 wm8960_reg[WM8960_CACHEREGNUM] = {
72}; 71};
73 72
74struct wm8960_priv { 73struct wm8960_priv {
75 u16 reg_cache[WM8960_CACHEREGNUM];
76 enum snd_soc_control_type control_type; 74 enum snd_soc_control_type control_type;
77 void *control_data; 75 void *control_data;
78 int (*set_bias_level)(struct snd_soc_codec *, 76 int (*set_bias_level)(struct snd_soc_codec *,
@@ -389,27 +387,28 @@ static int wm8960_add_widgets(struct snd_soc_codec *codec)
389{ 387{
390 struct wm8960_data *pdata = codec->dev->platform_data; 388 struct wm8960_data *pdata = codec->dev->platform_data;
391 struct wm8960_priv *wm8960 = snd_soc_codec_get_drvdata(codec); 389 struct wm8960_priv *wm8960 = snd_soc_codec_get_drvdata(codec);
390 struct snd_soc_dapm_context *dapm = &codec->dapm;
392 struct snd_soc_dapm_widget *w; 391 struct snd_soc_dapm_widget *w;
393 392
394 snd_soc_dapm_new_controls(codec, wm8960_dapm_widgets, 393 snd_soc_dapm_new_controls(dapm, wm8960_dapm_widgets,
395 ARRAY_SIZE(wm8960_dapm_widgets)); 394 ARRAY_SIZE(wm8960_dapm_widgets));
396 395
397 snd_soc_dapm_add_routes(codec, audio_paths, ARRAY_SIZE(audio_paths)); 396 snd_soc_dapm_add_routes(dapm, audio_paths, ARRAY_SIZE(audio_paths));
398 397
399 /* In capless mode OUT3 is used to provide VMID for the 398 /* In capless mode OUT3 is used to provide VMID for the
400 * headphone outputs, otherwise it is used as a mono mixer. 399 * headphone outputs, otherwise it is used as a mono mixer.
401 */ 400 */
402 if (pdata && pdata->capless) { 401 if (pdata && pdata->capless) {
403 snd_soc_dapm_new_controls(codec, wm8960_dapm_widgets_capless, 402 snd_soc_dapm_new_controls(dapm, wm8960_dapm_widgets_capless,
404 ARRAY_SIZE(wm8960_dapm_widgets_capless)); 403 ARRAY_SIZE(wm8960_dapm_widgets_capless));
405 404
406 snd_soc_dapm_add_routes(codec, audio_paths_capless, 405 snd_soc_dapm_add_routes(dapm, audio_paths_capless,
407 ARRAY_SIZE(audio_paths_capless)); 406 ARRAY_SIZE(audio_paths_capless));
408 } else { 407 } else {
409 snd_soc_dapm_new_controls(codec, wm8960_dapm_widgets_out3, 408 snd_soc_dapm_new_controls(dapm, wm8960_dapm_widgets_out3,
410 ARRAY_SIZE(wm8960_dapm_widgets_out3)); 409 ARRAY_SIZE(wm8960_dapm_widgets_out3));
411 410
412 snd_soc_dapm_add_routes(codec, audio_paths_out3, 411 snd_soc_dapm_add_routes(dapm, audio_paths_out3,
413 ARRAY_SIZE(audio_paths_out3)); 412 ARRAY_SIZE(audio_paths_out3));
414 } 413 }
415 414
@@ -418,7 +417,9 @@ static int wm8960_add_widgets(struct snd_soc_codec *codec)
418 * list each time to find the desired power state do so now 417 * list each time to find the desired power state do so now
419 * and save the result. 418 * and save the result.
420 */ 419 */
421 list_for_each_entry(w, &codec->dapm_widgets, list) { 420 list_for_each_entry(w, &codec->card->widgets, list) {
421 if (w->dapm != &codec->dapm)
422 continue;
422 if (strcmp(w->name, "LOUT1 PGA") == 0) 423 if (strcmp(w->name, "LOUT1 PGA") == 0)
423 wm8960->lout1 = w; 424 wm8960->lout1 = w;
424 if (strcmp(w->name, "ROUT1 PGA") == 0) 425 if (strcmp(w->name, "ROUT1 PGA") == 0)
@@ -573,7 +574,7 @@ static int wm8960_set_bias_level_out3(struct snd_soc_codec *codec,
573 break; 574 break;
574 575
575 case SND_SOC_BIAS_STANDBY: 576 case SND_SOC_BIAS_STANDBY:
576 if (codec->bias_level == SND_SOC_BIAS_OFF) { 577 if (codec->dapm.bias_level == SND_SOC_BIAS_OFF) {
577 /* Enable anti-pop features */ 578 /* Enable anti-pop features */
578 snd_soc_write(codec, WM8960_APOP1, 579 snd_soc_write(codec, WM8960_APOP1,
579 WM8960_POBCTRL | WM8960_SOFT_ST | 580 WM8960_POBCTRL | WM8960_SOFT_ST |
@@ -611,7 +612,7 @@ static int wm8960_set_bias_level_out3(struct snd_soc_codec *codec,
611 break; 612 break;
612 } 613 }
613 614
614 codec->bias_level = level; 615 codec->dapm.bias_level = level;
615 616
616 return 0; 617 return 0;
617} 618}
@@ -627,7 +628,7 @@ static int wm8960_set_bias_level_capless(struct snd_soc_codec *codec,
627 break; 628 break;
628 629
629 case SND_SOC_BIAS_PREPARE: 630 case SND_SOC_BIAS_PREPARE:
630 switch (codec->bias_level) { 631 switch (codec->dapm.bias_level) {
631 case SND_SOC_BIAS_STANDBY: 632 case SND_SOC_BIAS_STANDBY:
632 /* Enable anti pop mode */ 633 /* Enable anti pop mode */
633 snd_soc_update_bits(codec, WM8960_APOP1, 634 snd_soc_update_bits(codec, WM8960_APOP1,
@@ -682,7 +683,7 @@ static int wm8960_set_bias_level_capless(struct snd_soc_codec *codec,
682 break; 683 break;
683 684
684 case SND_SOC_BIAS_STANDBY: 685 case SND_SOC_BIAS_STANDBY:
685 switch (codec->bias_level) { 686 switch (codec->dapm.bias_level) {
686 case SND_SOC_BIAS_PREPARE: 687 case SND_SOC_BIAS_PREPARE:
687 /* Disable HP discharge */ 688 /* Disable HP discharge */
688 snd_soc_update_bits(codec, WM8960_APOP2, 689 snd_soc_update_bits(codec, WM8960_APOP2,
@@ -706,7 +707,7 @@ static int wm8960_set_bias_level_capless(struct snd_soc_codec *codec,
706 break; 707 break;
707 } 708 }
708 709
709 codec->bias_level = level; 710 codec->dapm.bias_level = level;
710 711
711 return 0; 712 return 0;
712} 713}
diff --git a/sound/soc/codecs/wm8961.c b/sound/soc/codecs/wm8961.c
index 8340485c9851..55252e7d02c9 100644
--- a/sound/soc/codecs/wm8961.c
+++ b/sound/soc/codecs/wm8961.c
@@ -23,7 +23,6 @@
23#include <sound/pcm.h> 23#include <sound/pcm.h>
24#include <sound/pcm_params.h> 24#include <sound/pcm_params.h>
25#include <sound/soc.h> 25#include <sound/soc.h>
26#include <sound/soc-dapm.h>
27#include <sound/initval.h> 26#include <sound/initval.h>
28#include <sound/tlv.h> 27#include <sound/tlv.h>
29 28
@@ -290,7 +289,6 @@ static u16 wm8961_reg_defaults[] = {
290struct wm8961_priv { 289struct wm8961_priv {
291 enum snd_soc_control_type control_type; 290 enum snd_soc_control_type control_type;
292 int sysclk; 291 int sysclk;
293 u16 reg_cache[WM8961_MAX_REGISTER];
294}; 292};
295 293
296static int wm8961_volatile_register(unsigned int reg) 294static int wm8961_volatile_register(unsigned int reg)
@@ -882,7 +880,7 @@ static int wm8961_set_bias_level(struct snd_soc_codec *codec,
882 break; 880 break;
883 881
884 case SND_SOC_BIAS_PREPARE: 882 case SND_SOC_BIAS_PREPARE:
885 if (codec->bias_level == SND_SOC_BIAS_STANDBY) { 883 if (codec->dapm.bias_level == SND_SOC_BIAS_STANDBY) {
886 /* Enable bias generation */ 884 /* Enable bias generation */
887 reg = snd_soc_read(codec, WM8961_ANTI_POP); 885 reg = snd_soc_read(codec, WM8961_ANTI_POP);
888 reg |= WM8961_BUFIOEN | WM8961_BUFDCOPEN; 886 reg |= WM8961_BUFIOEN | WM8961_BUFDCOPEN;
@@ -897,7 +895,7 @@ static int wm8961_set_bias_level(struct snd_soc_codec *codec,
897 break; 895 break;
898 896
899 case SND_SOC_BIAS_STANDBY: 897 case SND_SOC_BIAS_STANDBY:
900 if (codec->bias_level == SND_SOC_BIAS_PREPARE) { 898 if (codec->dapm.bias_level == SND_SOC_BIAS_PREPARE) {
901 /* VREF off */ 899 /* VREF off */
902 reg = snd_soc_read(codec, WM8961_PWR_MGMT_1); 900 reg = snd_soc_read(codec, WM8961_PWR_MGMT_1);
903 reg &= ~WM8961_VREF; 901 reg &= ~WM8961_VREF;
@@ -919,7 +917,7 @@ static int wm8961_set_bias_level(struct snd_soc_codec *codec,
919 break; 917 break;
920 } 918 }
921 919
922 codec->bias_level = level; 920 codec->dapm.bias_level = level;
923 921
924 return 0; 922 return 0;
925} 923}
@@ -959,6 +957,7 @@ static struct snd_soc_dai_driver wm8961_dai = {
959 957
960static int wm8961_probe(struct snd_soc_codec *codec) 958static int wm8961_probe(struct snd_soc_codec *codec)
961{ 959{
960 struct snd_soc_dapm_context *dapm = &codec->dapm;
962 int ret = 0; 961 int ret = 0;
963 u16 reg; 962 u16 reg;
964 963
@@ -1024,9 +1023,9 @@ static int wm8961_probe(struct snd_soc_codec *codec)
1024 1023
1025 snd_soc_add_controls(codec, wm8961_snd_controls, 1024 snd_soc_add_controls(codec, wm8961_snd_controls,
1026 ARRAY_SIZE(wm8961_snd_controls)); 1025 ARRAY_SIZE(wm8961_snd_controls));
1027 snd_soc_dapm_new_controls(codec, wm8961_dapm_widgets, 1026 snd_soc_dapm_new_controls(dapm, wm8961_dapm_widgets,
1028 ARRAY_SIZE(wm8961_dapm_widgets)); 1027 ARRAY_SIZE(wm8961_dapm_widgets));
1029 snd_soc_dapm_add_routes(codec, audio_paths, ARRAY_SIZE(audio_paths)); 1028 snd_soc_dapm_add_routes(dapm, audio_paths, ARRAY_SIZE(audio_paths));
1030 1029
1031 return 0; 1030 return 0;
1032} 1031}
diff --git a/sound/soc/codecs/wm8962.c b/sound/soc/codecs/wm8962.c
index 7c421cc837bd..b9cb1fcf8c92 100644
--- a/sound/soc/codecs/wm8962.c
+++ b/sound/soc/codecs/wm8962.c
@@ -29,10 +29,10 @@
29#include <sound/pcm.h> 29#include <sound/pcm.h>
30#include <sound/pcm_params.h> 30#include <sound/pcm_params.h>
31#include <sound/soc.h> 31#include <sound/soc.h>
32#include <sound/soc-dapm.h>
33#include <sound/initval.h> 32#include <sound/initval.h>
34#include <sound/tlv.h> 33#include <sound/tlv.h>
35#include <sound/wm8962.h> 34#include <sound/wm8962.h>
35#include <trace/events/asoc.h>
36 36
37#include "wm8962.h" 37#include "wm8962.h"
38 38
@@ -1956,7 +1956,7 @@ static int wm8962_readable_register(unsigned int reg)
1956 1956
1957static int wm8962_reset(struct snd_soc_codec *codec) 1957static int wm8962_reset(struct snd_soc_codec *codec)
1958{ 1958{
1959 return snd_soc_write(codec, WM8962_SOFTWARE_RESET, 0); 1959 return snd_soc_write(codec, WM8962_SOFTWARE_RESET, 0x6243);
1960} 1960}
1961 1961
1962static const DECLARE_TLV_DB_SCALE(inpga_tlv, -2325, 75, 0); 1962static const DECLARE_TLV_DB_SCALE(inpga_tlv, -2325, 75, 0);
@@ -2677,6 +2677,7 @@ static const struct snd_soc_dapm_route wm8962_spk_stereo_intercon[] = {
2677static int wm8962_add_widgets(struct snd_soc_codec *codec) 2677static int wm8962_add_widgets(struct snd_soc_codec *codec)
2678{ 2678{
2679 struct wm8962_pdata *pdata = dev_get_platdata(codec->dev); 2679 struct wm8962_pdata *pdata = dev_get_platdata(codec->dev);
2680 struct snd_soc_dapm_context *dapm = &codec->dapm;
2680 2681
2681 snd_soc_add_controls(codec, wm8962_snd_controls, 2682 snd_soc_add_controls(codec, wm8962_snd_controls,
2682 ARRAY_SIZE(wm8962_snd_controls)); 2683 ARRAY_SIZE(wm8962_snd_controls));
@@ -2688,26 +2689,26 @@ static int wm8962_add_widgets(struct snd_soc_codec *codec)
2688 ARRAY_SIZE(wm8962_spk_stereo_controls)); 2689 ARRAY_SIZE(wm8962_spk_stereo_controls));
2689 2690
2690 2691
2691 snd_soc_dapm_new_controls(codec, wm8962_dapm_widgets, 2692 snd_soc_dapm_new_controls(dapm, wm8962_dapm_widgets,
2692 ARRAY_SIZE(wm8962_dapm_widgets)); 2693 ARRAY_SIZE(wm8962_dapm_widgets));
2693 if (pdata && pdata->spk_mono) 2694 if (pdata && pdata->spk_mono)
2694 snd_soc_dapm_new_controls(codec, wm8962_dapm_spk_mono_widgets, 2695 snd_soc_dapm_new_controls(dapm, wm8962_dapm_spk_mono_widgets,
2695 ARRAY_SIZE(wm8962_dapm_spk_mono_widgets)); 2696 ARRAY_SIZE(wm8962_dapm_spk_mono_widgets));
2696 else 2697 else
2697 snd_soc_dapm_new_controls(codec, wm8962_dapm_spk_stereo_widgets, 2698 snd_soc_dapm_new_controls(dapm, wm8962_dapm_spk_stereo_widgets,
2698 ARRAY_SIZE(wm8962_dapm_spk_stereo_widgets)); 2699 ARRAY_SIZE(wm8962_dapm_spk_stereo_widgets));
2699 2700
2700 snd_soc_dapm_add_routes(codec, wm8962_intercon, 2701 snd_soc_dapm_add_routes(dapm, wm8962_intercon,
2701 ARRAY_SIZE(wm8962_intercon)); 2702 ARRAY_SIZE(wm8962_intercon));
2702 if (pdata && pdata->spk_mono) 2703 if (pdata && pdata->spk_mono)
2703 snd_soc_dapm_add_routes(codec, wm8962_spk_mono_intercon, 2704 snd_soc_dapm_add_routes(dapm, wm8962_spk_mono_intercon,
2704 ARRAY_SIZE(wm8962_spk_mono_intercon)); 2705 ARRAY_SIZE(wm8962_spk_mono_intercon));
2705 else 2706 else
2706 snd_soc_dapm_add_routes(codec, wm8962_spk_stereo_intercon, 2707 snd_soc_dapm_add_routes(dapm, wm8962_spk_stereo_intercon,
2707 ARRAY_SIZE(wm8962_spk_stereo_intercon)); 2708 ARRAY_SIZE(wm8962_spk_stereo_intercon));
2708 2709
2709 2710
2710 snd_soc_dapm_disable_pin(codec, "Beep"); 2711 snd_soc_dapm_disable_pin(dapm, "Beep");
2711 2712
2712 return 0; 2713 return 0;
2713} 2714}
@@ -2814,7 +2815,7 @@ static int wm8962_set_bias_level(struct snd_soc_codec *codec,
2814 struct wm8962_priv *wm8962 = snd_soc_codec_get_drvdata(codec); 2815 struct wm8962_priv *wm8962 = snd_soc_codec_get_drvdata(codec);
2815 int ret; 2816 int ret;
2816 2817
2817 if (level == codec->bias_level) 2818 if (level == codec->dapm.bias_level)
2818 return 0; 2819 return 0;
2819 2820
2820 switch (level) { 2821 switch (level) {
@@ -2828,7 +2829,7 @@ static int wm8962_set_bias_level(struct snd_soc_codec *codec,
2828 break; 2829 break;
2829 2830
2830 case SND_SOC_BIAS_STANDBY: 2831 case SND_SOC_BIAS_STANDBY:
2831 if (codec->bias_level == SND_SOC_BIAS_OFF) { 2832 if (codec->dapm.bias_level == SND_SOC_BIAS_OFF) {
2832 ret = regulator_bulk_enable(ARRAY_SIZE(wm8962->supplies), 2833 ret = regulator_bulk_enable(ARRAY_SIZE(wm8962->supplies),
2833 wm8962->supplies); 2834 wm8962->supplies);
2834 if (ret != 0) { 2835 if (ret != 0) {
@@ -2878,7 +2879,7 @@ static int wm8962_set_bias_level(struct snd_soc_codec *codec,
2878 wm8962->supplies); 2879 wm8962->supplies);
2879 break; 2880 break;
2880 } 2881 }
2881 codec->bias_level = level; 2882 codec->dapm.bias_level = level;
2882 return 0; 2883 return 0;
2883} 2884}
2884 2885
@@ -3348,6 +3349,12 @@ static irqreturn_t wm8962_irq(int irq, void *data)
3348 if (active & (WM8962_MICSCD_EINT | WM8962_MICD_EINT)) { 3349 if (active & (WM8962_MICSCD_EINT | WM8962_MICD_EINT)) {
3349 dev_dbg(codec->dev, "Microphone event detected\n"); 3350 dev_dbg(codec->dev, "Microphone event detected\n");
3350 3351
3352#ifndef CONFIG_SND_SOC_WM8962_MODULE
3353 trace_snd_soc_jack_irq(dev_name(codec->dev));
3354#endif
3355
3356 pm_wakeup_event(codec->dev, 300);
3357
3351 schedule_delayed_work(&wm8962->mic_work, 3358 schedule_delayed_work(&wm8962->mic_work,
3352 msecs_to_jiffies(250)); 3359 msecs_to_jiffies(250));
3353 } 3360 }
@@ -3433,6 +3440,7 @@ static void wm8962_beep_work(struct work_struct *work)
3433 struct wm8962_priv *wm8962 = 3440 struct wm8962_priv *wm8962 =
3434 container_of(work, struct wm8962_priv, beep_work); 3441 container_of(work, struct wm8962_priv, beep_work);
3435 struct snd_soc_codec *codec = wm8962->codec; 3442 struct snd_soc_codec *codec = wm8962->codec;
3443 struct snd_soc_dapm_context *dapm = &codec->dapm;
3436 int i; 3444 int i;
3437 int reg = 0; 3445 int reg = 0;
3438 int best = 0; 3446 int best = 0;
@@ -3449,16 +3457,16 @@ static void wm8962_beep_work(struct work_struct *work)
3449 3457
3450 reg = WM8962_BEEP_ENA | (best << WM8962_BEEP_RATE_SHIFT); 3458 reg = WM8962_BEEP_ENA | (best << WM8962_BEEP_RATE_SHIFT);
3451 3459
3452 snd_soc_dapm_enable_pin(codec, "Beep"); 3460 snd_soc_dapm_enable_pin(dapm, "Beep");
3453 } else { 3461 } else {
3454 dev_dbg(codec->dev, "Disabling beep\n"); 3462 dev_dbg(codec->dev, "Disabling beep\n");
3455 snd_soc_dapm_disable_pin(codec, "Beep"); 3463 snd_soc_dapm_disable_pin(dapm, "Beep");
3456 } 3464 }
3457 3465
3458 snd_soc_update_bits(codec, WM8962_BEEP_GENERATOR_1, 3466 snd_soc_update_bits(codec, WM8962_BEEP_GENERATOR_1,
3459 WM8962_BEEP_ENA | WM8962_BEEP_RATE_MASK, reg); 3467 WM8962_BEEP_ENA | WM8962_BEEP_RATE_MASK, reg);
3460 3468
3461 snd_soc_dapm_sync(codec); 3469 snd_soc_dapm_sync(dapm);
3462} 3470}
3463 3471
3464/* For usability define a way of injecting beep events for the device - 3472/* For usability define a way of injecting beep events for the device -
@@ -3706,7 +3714,7 @@ static int wm8962_probe(struct snd_soc_codec *codec)
3706 INIT_DELAYED_WORK(&wm8962->mic_work, wm8962_mic_work); 3714 INIT_DELAYED_WORK(&wm8962->mic_work, wm8962_mic_work);
3707 3715
3708 codec->cache_sync = 1; 3716 codec->cache_sync = 1;
3709 codec->idle_bias_off = 1; 3717 codec->dapm.idle_bias_off = 1;
3710 3718
3711 ret = snd_soc_codec_set_cache_io(codec, 16, 16, SND_SOC_I2C); 3719 ret = snd_soc_codec_set_cache_io(codec, 16, 16, SND_SOC_I2C);
3712 if (ret != 0) { 3720 if (ret != 0) {
@@ -3865,7 +3873,6 @@ err_enable:
3865err_get: 3873err_get:
3866 regulator_bulk_free(ARRAY_SIZE(wm8962->supplies), wm8962->supplies); 3874 regulator_bulk_free(ARRAY_SIZE(wm8962->supplies), wm8962->supplies);
3867err: 3875err:
3868 kfree(wm8962);
3869 return ret; 3876 return ret;
3870} 3877}
3871 3878
diff --git a/sound/soc/codecs/wm8971.c b/sound/soc/codecs/wm8971.c
index 9f18db6e167c..572bb80627a4 100644
--- a/sound/soc/codecs/wm8971.c
+++ b/sound/soc/codecs/wm8971.c
@@ -25,7 +25,6 @@
25#include <sound/pcm.h> 25#include <sound/pcm.h>
26#include <sound/pcm_params.h> 26#include <sound/pcm_params.h>
27#include <sound/soc.h> 27#include <sound/soc.h>
28#include <sound/soc-dapm.h>
29#include <sound/initval.h> 28#include <sound/initval.h>
30 29
31#include "wm8971.h" 30#include "wm8971.h"
@@ -333,10 +332,11 @@ static const struct snd_soc_dapm_route audio_map[] = {
333 332
334static int wm8971_add_widgets(struct snd_soc_codec *codec) 333static int wm8971_add_widgets(struct snd_soc_codec *codec)
335{ 334{
336 snd_soc_dapm_new_controls(codec, wm8971_dapm_widgets, 335 struct snd_soc_dapm_context *dapm = &codec->dapm;
337 ARRAY_SIZE(wm8971_dapm_widgets));
338 336
339 snd_soc_dapm_add_routes(codec, audio_map, ARRAY_SIZE(audio_map)); 337 snd_soc_dapm_new_controls(dapm, wm8971_dapm_widgets,
338 ARRAY_SIZE(wm8971_dapm_widgets));
339 snd_soc_dapm_add_routes(dapm, audio_map, ARRAY_SIZE(audio_map));
340 340
341 return 0; 341 return 0;
342} 342}
@@ -553,7 +553,7 @@ static int wm8971_set_bias_level(struct snd_soc_codec *codec,
553 snd_soc_write(codec, WM8971_PWR1, 0x0001); 553 snd_soc_write(codec, WM8971_PWR1, 0x0001);
554 break; 554 break;
555 } 555 }
556 codec->bias_level = level; 556 codec->dapm.bias_level = level;
557 return 0; 557 return 0;
558} 558}
559 559
@@ -590,9 +590,11 @@ static struct snd_soc_dai_driver wm8971_dai = {
590 590
591static void wm8971_work(struct work_struct *work) 591static void wm8971_work(struct work_struct *work)
592{ 592{
593 struct snd_soc_codec *codec = 593 struct snd_soc_dapm_context *dapm =
594 container_of(work, struct snd_soc_codec, delayed_work.work); 594 container_of(work, struct snd_soc_dapm_context,
595 wm8971_set_bias_level(codec, codec->bias_level); 595 delayed_work.work);
596 struct snd_soc_codec *codec = dapm->codec;
597 wm8971_set_bias_level(codec, codec->dapm.bias_level);
596} 598}
597 599
598static int wm8971_suspend(struct snd_soc_codec *codec, pm_message_t state) 600static int wm8971_suspend(struct snd_soc_codec *codec, pm_message_t state)
@@ -620,11 +622,11 @@ static int wm8971_resume(struct snd_soc_codec *codec)
620 wm8971_set_bias_level(codec, SND_SOC_BIAS_STANDBY); 622 wm8971_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
621 623
622 /* charge wm8971 caps */ 624 /* charge wm8971 caps */
623 if (codec->suspend_bias_level == SND_SOC_BIAS_ON) { 625 if (codec->dapm.suspend_bias_level == SND_SOC_BIAS_ON) {
624 reg = snd_soc_read(codec, WM8971_PWR1) & 0xfe3e; 626 reg = snd_soc_read(codec, WM8971_PWR1) & 0xfe3e;
625 snd_soc_write(codec, WM8971_PWR1, reg | 0x01c0); 627 snd_soc_write(codec, WM8971_PWR1, reg | 0x01c0);
626 codec->bias_level = SND_SOC_BIAS_ON; 628 codec->dapm.bias_level = SND_SOC_BIAS_ON;
627 queue_delayed_work(wm8971_workq, &codec->delayed_work, 629 queue_delayed_work(wm8971_workq, &codec->dapm.delayed_work,
628 msecs_to_jiffies(1000)); 630 msecs_to_jiffies(1000));
629 } 631 }
630 632
@@ -643,7 +645,7 @@ static int wm8971_probe(struct snd_soc_codec *codec)
643 return ret; 645 return ret;
644 } 646 }
645 647
646 INIT_DELAYED_WORK(&codec->delayed_work, wm8971_work); 648 INIT_DELAYED_WORK(&codec->dapm.delayed_work, wm8971_work);
647 wm8971_workq = create_workqueue("wm8971"); 649 wm8971_workq = create_workqueue("wm8971");
648 if (wm8971_workq == NULL) 650 if (wm8971_workq == NULL)
649 return -ENOMEM; 651 return -ENOMEM;
@@ -653,8 +655,8 @@ static int wm8971_probe(struct snd_soc_codec *codec)
653 /* charge output caps - set vmid to 5k for quick power up */ 655 /* charge output caps - set vmid to 5k for quick power up */
654 reg = snd_soc_read(codec, WM8971_PWR1) & 0xfe3e; 656 reg = snd_soc_read(codec, WM8971_PWR1) & 0xfe3e;
655 snd_soc_write(codec, WM8971_PWR1, reg | 0x01c0); 657 snd_soc_write(codec, WM8971_PWR1, reg | 0x01c0);
656 codec->bias_level = SND_SOC_BIAS_STANDBY; 658 codec->dapm.bias_level = SND_SOC_BIAS_STANDBY;
657 queue_delayed_work(wm8971_workq, &codec->delayed_work, 659 queue_delayed_work(wm8971_workq, &codec->dapm.delayed_work,
658 msecs_to_jiffies(1000)); 660 msecs_to_jiffies(1000));
659 661
660 /* set the update bits */ 662 /* set the update bits */
diff --git a/sound/soc/codecs/wm8974.c b/sound/soc/codecs/wm8974.c
index b4363f6d19b3..ca646a822444 100644
--- a/sound/soc/codecs/wm8974.c
+++ b/sound/soc/codecs/wm8974.c
@@ -23,7 +23,6 @@
23#include <sound/pcm.h> 23#include <sound/pcm.h>
24#include <sound/pcm_params.h> 24#include <sound/pcm_params.h>
25#include <sound/soc.h> 25#include <sound/soc.h>
26#include <sound/soc-dapm.h>
27#include <sound/initval.h> 26#include <sound/initval.h>
28#include <sound/tlv.h> 27#include <sound/tlv.h>
29 28
@@ -52,7 +51,6 @@ static const u16 wm8974_reg[WM8974_CACHEREGNUM] = {
52 51
53struct wm8974_priv { 52struct wm8974_priv {
54 enum snd_soc_control_type control_type; 53 enum snd_soc_control_type control_type;
55 u16 reg_cache[WM8974_CACHEREGNUM];
56}; 54};
57 55
58#define wm8974_reset(c) snd_soc_write(c, WM8974_RESET, 0) 56#define wm8974_reset(c) snd_soc_write(c, WM8974_RESET, 0)
@@ -274,10 +272,11 @@ static const struct snd_soc_dapm_route audio_map[] = {
274 272
275static int wm8974_add_widgets(struct snd_soc_codec *codec) 273static int wm8974_add_widgets(struct snd_soc_codec *codec)
276{ 274{
277 snd_soc_dapm_new_controls(codec, wm8974_dapm_widgets, 275 struct snd_soc_dapm_context *dapm = &codec->dapm;
278 ARRAY_SIZE(wm8974_dapm_widgets));
279 276
280 snd_soc_dapm_add_routes(codec, audio_map, ARRAY_SIZE(audio_map)); 277 snd_soc_dapm_new_controls(dapm, wm8974_dapm_widgets,
278 ARRAY_SIZE(wm8974_dapm_widgets));
279 snd_soc_dapm_add_routes(dapm, audio_map, ARRAY_SIZE(audio_map));
281 280
282 return 0; 281 return 0;
283} 282}
@@ -530,7 +529,7 @@ static int wm8974_set_bias_level(struct snd_soc_codec *codec,
530 case SND_SOC_BIAS_STANDBY: 529 case SND_SOC_BIAS_STANDBY:
531 power1 |= WM8974_POWER1_BIASEN | WM8974_POWER1_BUFIOEN; 530 power1 |= WM8974_POWER1_BIASEN | WM8974_POWER1_BUFIOEN;
532 531
533 if (codec->bias_level == SND_SOC_BIAS_OFF) { 532 if (codec->dapm.bias_level == SND_SOC_BIAS_OFF) {
534 /* Initial cap charge at VMID 5k */ 533 /* Initial cap charge at VMID 5k */
535 snd_soc_write(codec, WM8974_POWER1, power1 | 0x3); 534 snd_soc_write(codec, WM8974_POWER1, power1 | 0x3);
536 mdelay(100); 535 mdelay(100);
@@ -547,7 +546,7 @@ static int wm8974_set_bias_level(struct snd_soc_codec *codec,
547 break; 546 break;
548 } 547 }
549 548
550 codec->bias_level = level; 549 codec->dapm.bias_level = level;
551 return 0; 550 return 0;
552} 551}
553 552
diff --git a/sound/soc/codecs/wm8978.c b/sound/soc/codecs/wm8978.c
index 13b979a71a7c..4bbc3442703f 100644
--- a/sound/soc/codecs/wm8978.c
+++ b/sound/soc/codecs/wm8978.c
@@ -24,7 +24,6 @@
24#include <sound/pcm.h> 24#include <sound/pcm.h>
25#include <sound/pcm_params.h> 25#include <sound/pcm_params.h>
26#include <sound/soc.h> 26#include <sound/soc.h>
27#include <sound/soc-dapm.h>
28#include <sound/initval.h> 27#include <sound/initval.h>
29#include <sound/tlv.h> 28#include <sound/tlv.h>
30#include <asm/div64.h> 29#include <asm/div64.h>
@@ -60,7 +59,6 @@ struct wm8978_priv {
60 unsigned int f_opclk; 59 unsigned int f_opclk;
61 int mclk_idx; 60 int mclk_idx;
62 enum wm8978_sysclk_src sysclk; 61 enum wm8978_sysclk_src sysclk;
63 u16 reg_cache[WM8978_CACHEREGNUM];
64}; 62};
65 63
66static const char *wm8978_companding[] = {"Off", "NC", "u-law", "A-law"}; 64static const char *wm8978_companding[] = {"Off", "NC", "u-law", "A-law"};
@@ -355,11 +353,12 @@ static const struct snd_soc_dapm_route audio_map[] = {
355 353
356static int wm8978_add_widgets(struct snd_soc_codec *codec) 354static int wm8978_add_widgets(struct snd_soc_codec *codec)
357{ 355{
358 snd_soc_dapm_new_controls(codec, wm8978_dapm_widgets, 356 struct snd_soc_dapm_context *dapm = &codec->dapm;
359 ARRAY_SIZE(wm8978_dapm_widgets));
360 357
358 snd_soc_dapm_new_controls(dapm, wm8978_dapm_widgets,
359 ARRAY_SIZE(wm8978_dapm_widgets));
361 /* set up the WM8978 audio map */ 360 /* set up the WM8978 audio map */
362 snd_soc_dapm_add_routes(codec, audio_map, ARRAY_SIZE(audio_map)); 361 snd_soc_dapm_add_routes(dapm, audio_map, ARRAY_SIZE(audio_map));
363 362
364 return 0; 363 return 0;
365} 364}
@@ -837,7 +836,7 @@ static int wm8978_set_bias_level(struct snd_soc_codec *codec,
837 /* bit 3: enable bias, bit 2: enable I/O tie off buffer */ 836 /* bit 3: enable bias, bit 2: enable I/O tie off buffer */
838 power1 |= 0xc; 837 power1 |= 0xc;
839 838
840 if (codec->bias_level == SND_SOC_BIAS_OFF) { 839 if (codec->dapm.bias_level == SND_SOC_BIAS_OFF) {
841 /* Initial cap charge at VMID 5k */ 840 /* Initial cap charge at VMID 5k */
842 snd_soc_write(codec, WM8978_POWER_MANAGEMENT_1, 841 snd_soc_write(codec, WM8978_POWER_MANAGEMENT_1,
843 power1 | 0x3); 842 power1 | 0x3);
@@ -857,7 +856,7 @@ static int wm8978_set_bias_level(struct snd_soc_codec *codec,
857 856
858 dev_dbg(codec->dev, "%s: %d, %x\n", __func__, level, power1); 857 dev_dbg(codec->dev, "%s: %d, %x\n", __func__, level, power1);
859 858
860 codec->bias_level = level; 859 codec->dapm.bias_level = level;
861 return 0; 860 return 0;
862} 861}
863 862
diff --git a/sound/soc/codecs/wm8985.c b/sound/soc/codecs/wm8985.c
index fd2e7cca1228..bae510acdec8 100644
--- a/sound/soc/codecs/wm8985.c
+++ b/sound/soc/codecs/wm8985.c
@@ -26,7 +26,6 @@
26#include <sound/pcm.h> 26#include <sound/pcm.h>
27#include <sound/pcm_params.h> 27#include <sound/pcm_params.h>
28#include <sound/soc.h> 28#include <sound/soc.h>
29#include <sound/soc-dapm.h>
30#include <sound/initval.h> 29#include <sound/initval.h>
31#include <sound/tlv.h> 30#include <sound/tlv.h>
32 31
@@ -533,10 +532,11 @@ static int eqmode_put(struct snd_kcontrol *kcontrol,
533 532
534static int wm8985_add_widgets(struct snd_soc_codec *codec) 533static int wm8985_add_widgets(struct snd_soc_codec *codec)
535{ 534{
536 snd_soc_dapm_new_controls(codec, wm8985_dapm_widgets, 535 struct snd_soc_dapm_context *dapm = &codec->dapm;
537 ARRAY_SIZE(wm8985_dapm_widgets));
538 536
539 snd_soc_dapm_add_routes(codec, audio_map, 537 snd_soc_dapm_new_controls(dapm, wm8985_dapm_widgets,
538 ARRAY_SIZE(wm8985_dapm_widgets));
539 snd_soc_dapm_add_routes(dapm, audio_map,
540 ARRAY_SIZE(audio_map)); 540 ARRAY_SIZE(audio_map));
541 return 0; 541 return 0;
542} 542}
@@ -879,7 +879,7 @@ static int wm8985_set_bias_level(struct snd_soc_codec *codec,
879 1 << WM8985_VMIDSEL_SHIFT); 879 1 << WM8985_VMIDSEL_SHIFT);
880 break; 880 break;
881 case SND_SOC_BIAS_STANDBY: 881 case SND_SOC_BIAS_STANDBY:
882 if (codec->bias_level == SND_SOC_BIAS_OFF) { 882 if (codec->dapm.bias_level == SND_SOC_BIAS_OFF) {
883 ret = regulator_bulk_enable(ARRAY_SIZE(wm8985->supplies), 883 ret = regulator_bulk_enable(ARRAY_SIZE(wm8985->supplies),
884 wm8985->supplies); 884 wm8985->supplies);
885 if (ret) { 885 if (ret) {
@@ -939,7 +939,7 @@ static int wm8985_set_bias_level(struct snd_soc_codec *codec,
939 break; 939 break;
940 } 940 }
941 941
942 codec->bias_level = level; 942 codec->dapm.bias_level = level;
943 return 0; 943 return 0;
944} 944}
945 945
diff --git a/sound/soc/codecs/wm8988.c b/sound/soc/codecs/wm8988.c
index d7f259711970..d7170f1381aa 100644
--- a/sound/soc/codecs/wm8988.c
+++ b/sound/soc/codecs/wm8988.c
@@ -25,7 +25,6 @@
25#include <sound/pcm_params.h> 25#include <sound/pcm_params.h>
26#include <sound/tlv.h> 26#include <sound/tlv.h>
27#include <sound/soc.h> 27#include <sound/soc.h>
28#include <sound/soc-dapm.h>
29#include <sound/initval.h> 28#include <sound/initval.h>
30 29
31#include "wm8988.h" 30#include "wm8988.h"
@@ -54,7 +53,6 @@ struct wm8988_priv {
54 unsigned int sysclk; 53 unsigned int sysclk;
55 enum snd_soc_control_type control_type; 54 enum snd_soc_control_type control_type;
56 struct snd_pcm_hw_constraint_list *sysclk_constraints; 55 struct snd_pcm_hw_constraint_list *sysclk_constraints;
57 u16 reg_cache[WM8988_NUM_REG];
58}; 56};
59 57
60 58
@@ -677,7 +675,7 @@ static int wm8988_set_bias_level(struct snd_soc_codec *codec,
677 break; 675 break;
678 676
679 case SND_SOC_BIAS_STANDBY: 677 case SND_SOC_BIAS_STANDBY:
680 if (codec->bias_level == SND_SOC_BIAS_OFF) { 678 if (codec->dapm.bias_level == SND_SOC_BIAS_OFF) {
681 /* VREF, VMID=2x5k */ 679 /* VREF, VMID=2x5k */
682 snd_soc_write(codec, WM8988_PWR1, pwr_reg | 0x1c1); 680 snd_soc_write(codec, WM8988_PWR1, pwr_reg | 0x1c1);
683 681
@@ -693,7 +691,7 @@ static int wm8988_set_bias_level(struct snd_soc_codec *codec,
693 snd_soc_write(codec, WM8988_PWR1, 0x0000); 691 snd_soc_write(codec, WM8988_PWR1, 0x0000);
694 break; 692 break;
695 } 693 }
696 codec->bias_level = level; 694 codec->dapm.bias_level = level;
697 return 0; 695 return 0;
698} 696}
699 697
@@ -759,6 +757,7 @@ static int wm8988_resume(struct snd_soc_codec *codec)
759static int wm8988_probe(struct snd_soc_codec *codec) 757static int wm8988_probe(struct snd_soc_codec *codec)
760{ 758{
761 struct wm8988_priv *wm8988 = snd_soc_codec_get_drvdata(codec); 759 struct wm8988_priv *wm8988 = snd_soc_codec_get_drvdata(codec);
760 struct snd_soc_dapm_context *dapm = &codec->dapm;
762 int ret = 0; 761 int ret = 0;
763 u16 reg; 762 u16 reg;
764 763
@@ -790,9 +789,9 @@ static int wm8988_probe(struct snd_soc_codec *codec)
790 789
791 snd_soc_add_controls(codec, wm8988_snd_controls, 790 snd_soc_add_controls(codec, wm8988_snd_controls,
792 ARRAY_SIZE(wm8988_snd_controls)); 791 ARRAY_SIZE(wm8988_snd_controls));
793 snd_soc_dapm_new_controls(codec, wm8988_dapm_widgets, 792 snd_soc_dapm_new_controls(dapm, wm8988_dapm_widgets,
794 ARRAY_SIZE(wm8988_dapm_widgets)); 793 ARRAY_SIZE(wm8988_dapm_widgets));
795 snd_soc_dapm_add_routes(codec, audio_map, ARRAY_SIZE(audio_map)); 794 snd_soc_dapm_add_routes(dapm, audio_map, ARRAY_SIZE(audio_map));
796 795
797 return 0; 796 return 0;
798} 797}
diff --git a/sound/soc/codecs/wm8990.c b/sound/soc/codecs/wm8990.c
index 264828e4e67c..5c87a634fc04 100644
--- a/sound/soc/codecs/wm8990.c
+++ b/sound/soc/codecs/wm8990.c
@@ -23,7 +23,6 @@
23#include <sound/pcm.h> 23#include <sound/pcm.h>
24#include <sound/pcm_params.h> 24#include <sound/pcm_params.h>
25#include <sound/soc.h> 25#include <sound/soc.h>
26#include <sound/soc-dapm.h>
27#include <sound/initval.h> 26#include <sound/initval.h>
28#include <sound/tlv.h> 27#include <sound/tlv.h>
29#include <asm/div64.h> 28#include <asm/div64.h>
@@ -914,11 +913,12 @@ static const struct snd_soc_dapm_route audio_map[] = {
914 913
915static int wm8990_add_widgets(struct snd_soc_codec *codec) 914static int wm8990_add_widgets(struct snd_soc_codec *codec)
916{ 915{
917 snd_soc_dapm_new_controls(codec, wm8990_dapm_widgets, 916 struct snd_soc_dapm_context *dapm = &codec->dapm;
918 ARRAY_SIZE(wm8990_dapm_widgets));
919 917
918 snd_soc_dapm_new_controls(dapm, wm8990_dapm_widgets,
919 ARRAY_SIZE(wm8990_dapm_widgets));
920 /* set up the WM8990 audio map */ 920 /* set up the WM8990 audio map */
921 snd_soc_dapm_add_routes(codec, audio_map, ARRAY_SIZE(audio_map)); 921 snd_soc_dapm_add_routes(dapm, audio_map, ARRAY_SIZE(audio_map));
922 922
923 return 0; 923 return 0;
924} 924}
@@ -1170,7 +1170,7 @@ static int wm8990_set_bias_level(struct snd_soc_codec *codec,
1170 break; 1170 break;
1171 1171
1172 case SND_SOC_BIAS_STANDBY: 1172 case SND_SOC_BIAS_STANDBY:
1173 if (codec->bias_level == SND_SOC_BIAS_OFF) { 1173 if (codec->dapm.bias_level == SND_SOC_BIAS_OFF) {
1174 /* Enable all output discharge bits */ 1174 /* Enable all output discharge bits */
1175 snd_soc_write(codec, WM8990_ANTIPOP1, WM8990_DIS_LLINE | 1175 snd_soc_write(codec, WM8990_ANTIPOP1, WM8990_DIS_LLINE |
1176 WM8990_DIS_RLINE | WM8990_DIS_OUT3 | 1176 WM8990_DIS_RLINE | WM8990_DIS_OUT3 |
@@ -1266,7 +1266,7 @@ static int wm8990_set_bias_level(struct snd_soc_codec *codec,
1266 break; 1266 break;
1267 } 1267 }
1268 1268
1269 codec->bias_level = level; 1269 codec->dapm.bias_level = level;
1270 return 0; 1270 return 0;
1271} 1271}
1272 1272
diff --git a/sound/soc/codecs/wm8993.c b/sound/soc/codecs/wm8993.c
index 589e3fa24734..18c0d9ce7c32 100644
--- a/sound/soc/codecs/wm8993.c
+++ b/sound/soc/codecs/wm8993.c
@@ -24,7 +24,6 @@
24#include <sound/pcm_params.h> 24#include <sound/pcm_params.h>
25#include <sound/tlv.h> 25#include <sound/tlv.h>
26#include <sound/soc.h> 26#include <sound/soc.h>
27#include <sound/soc-dapm.h>
28#include <sound/initval.h> 27#include <sound/initval.h>
29#include <sound/wm8993.h> 28#include <sound/wm8993.h>
30 29
@@ -226,7 +225,6 @@ static struct {
226 225
227struct wm8993_priv { 226struct wm8993_priv {
228 struct wm_hubs_data hubs_data; 227 struct wm_hubs_data hubs_data;
229 u16 reg_cache[WM8993_REGISTER_COUNT];
230 struct regulator_bulk_data supplies[WM8993_NUM_SUPPLIES]; 228 struct regulator_bulk_data supplies[WM8993_NUM_SUPPLIES];
231 struct wm8993_platform_data pdata; 229 struct wm8993_platform_data pdata;
232 enum snd_soc_control_type control_type; 230 enum snd_soc_control_type control_type;
@@ -735,6 +733,7 @@ static int class_w_put(struct snd_kcontrol *kcontrol,
735 0); 733 0);
736 } 734 }
737 wm8993->class_w_users++; 735 wm8993->class_w_users++;
736 wm8993->hubs_data.class_w = true;
738 } 737 }
739 738
740 /* Implement the change */ 739 /* Implement the change */
@@ -751,6 +750,7 @@ static int class_w_put(struct snd_kcontrol *kcontrol,
751 WM8993_CP_DYN_V); 750 WM8993_CP_DYN_V);
752 } 751 }
753 wm8993->class_w_users--; 752 wm8993->class_w_users--;
753 wm8993->hubs_data.class_w = false;
754 } 754 }
755 755
756 dev_dbg(codec->dev, "Indirect DAC use count now %d\n", 756 dev_dbg(codec->dev, "Indirect DAC use count now %d\n",
@@ -968,7 +968,7 @@ static int wm8993_set_bias_level(struct snd_soc_codec *codec,
968 break; 968 break;
969 969
970 case SND_SOC_BIAS_STANDBY: 970 case SND_SOC_BIAS_STANDBY:
971 if (codec->bias_level == SND_SOC_BIAS_OFF) { 971 if (codec->dapm.bias_level == SND_SOC_BIAS_OFF) {
972 ret = regulator_bulk_enable(ARRAY_SIZE(wm8993->supplies), 972 ret = regulator_bulk_enable(ARRAY_SIZE(wm8993->supplies),
973 wm8993->supplies); 973 wm8993->supplies);
974 if (ret != 0) 974 if (ret != 0)
@@ -1029,6 +1029,12 @@ static int wm8993_set_bias_level(struct snd_soc_codec *codec,
1029 WM8993_VMID_SEL_MASK | WM8993_BIAS_ENA, 1029 WM8993_VMID_SEL_MASK | WM8993_BIAS_ENA,
1030 0); 1030 0);
1031 1031
1032 snd_soc_update_bits(codec, WM8993_ANTIPOP2,
1033 WM8993_STARTUP_BIAS_ENA |
1034 WM8993_VMID_BUF_ENA |
1035 WM8993_VMID_RAMP_MASK |
1036 WM8993_BIAS_SRC, 0);
1037
1032#ifdef CONFIG_REGULATOR 1038#ifdef CONFIG_REGULATOR
1033 /* Post 2.6.34 we will be able to get a callback when 1039 /* Post 2.6.34 we will be able to get a callback when
1034 * the regulators are disabled which we can use but 1040 * the regulators are disabled which we can use but
@@ -1043,7 +1049,7 @@ static int wm8993_set_bias_level(struct snd_soc_codec *codec,
1043 break; 1049 break;
1044 } 1050 }
1045 1051
1046 codec->bias_level = level; 1052 codec->dapm.bias_level = level;
1047 1053
1048 return 0; 1054 return 0;
1049} 1055}
@@ -1225,7 +1231,7 @@ static int wm8993_hw_params(struct snd_pcm_substream *substream,
1225 - wm8993->fs); 1231 - wm8993->fs);
1226 for (i = 1; i < ARRAY_SIZE(clk_sys_rates); i++) { 1232 for (i = 1; i < ARRAY_SIZE(clk_sys_rates); i++) {
1227 cur_val = abs((wm8993->sysclk_rate / 1233 cur_val = abs((wm8993->sysclk_rate /
1228 clk_sys_rates[i].ratio) - wm8993->fs);; 1234 clk_sys_rates[i].ratio) - wm8993->fs);
1229 if (cur_val < best_val) { 1235 if (cur_val < best_val) {
1230 best = i; 1236 best = i;
1231 best_val = cur_val; 1237 best_val = cur_val;
@@ -1422,6 +1428,7 @@ static struct snd_soc_dai_driver wm8993_dai = {
1422static int wm8993_probe(struct snd_soc_codec *codec) 1428static int wm8993_probe(struct snd_soc_codec *codec)
1423{ 1429{
1424 struct wm8993_priv *wm8993 = snd_soc_codec_get_drvdata(codec); 1430 struct wm8993_priv *wm8993 = snd_soc_codec_get_drvdata(codec);
1431 struct snd_soc_dapm_context *dapm = &codec->dapm;
1425 int ret, i, val; 1432 int ret, i, val;
1426 1433
1427 wm8993->hubs_data.hp_startup_mode = 1; 1434 wm8993->hubs_data.hp_startup_mode = 1;
@@ -1503,11 +1510,11 @@ static int wm8993_probe(struct snd_soc_codec *codec)
1503 ARRAY_SIZE(wm8993_eq_controls)); 1510 ARRAY_SIZE(wm8993_eq_controls));
1504 } 1511 }
1505 1512
1506 snd_soc_dapm_new_controls(codec, wm8993_dapm_widgets, 1513 snd_soc_dapm_new_controls(dapm, wm8993_dapm_widgets,
1507 ARRAY_SIZE(wm8993_dapm_widgets)); 1514 ARRAY_SIZE(wm8993_dapm_widgets));
1508 wm_hubs_add_analogue_controls(codec); 1515 wm_hubs_add_analogue_controls(codec);
1509 1516
1510 snd_soc_dapm_add_routes(codec, routes, ARRAY_SIZE(routes)); 1517 snd_soc_dapm_add_routes(dapm, routes, ARRAY_SIZE(routes));
1511 wm_hubs_add_analogue_routes(codec, wm8993->pdata.lineout1_diff, 1518 wm_hubs_add_analogue_routes(codec, wm8993->pdata.lineout1_diff,
1512 wm8993->pdata.lineout2_diff); 1519 wm8993->pdata.lineout2_diff);
1513 1520
diff --git a/sound/soc/codecs/wm8994-tables.c b/sound/soc/codecs/wm8994-tables.c
new file mode 100644
index 000000000000..68e9b024dd48
--- /dev/null
+++ b/sound/soc/codecs/wm8994-tables.c
@@ -0,0 +1,3147 @@
1#include "wm8994.h"
2
3const struct wm8994_access_mask wm8994_access_masks[WM8994_CACHE_SIZE] = {
4 { 0xFFFF, 0xFFFF }, /* R0 - Software Reset */
5 { 0x3B37, 0x3B37 }, /* R1 - Power Management (1) */
6 { 0x6BF0, 0x6BF0 }, /* R2 - Power Management (2) */
7 { 0x3FF0, 0x3FF0 }, /* R3 - Power Management (3) */
8 { 0x3F3F, 0x3F3F }, /* R4 - Power Management (4) */
9 { 0x3F0F, 0x3F0F }, /* R5 - Power Management (5) */
10 { 0x003F, 0x003F }, /* R6 - Power Management (6) */
11 { 0x0000, 0x0000 }, /* R7 */
12 { 0x0000, 0x0000 }, /* R8 */
13 { 0x0000, 0x0000 }, /* R9 */
14 { 0x0000, 0x0000 }, /* R10 */
15 { 0x0000, 0x0000 }, /* R11 */
16 { 0x0000, 0x0000 }, /* R12 */
17 { 0x0000, 0x0000 }, /* R13 */
18 { 0x0000, 0x0000 }, /* R14 */
19 { 0x0000, 0x0000 }, /* R15 */
20 { 0x0000, 0x0000 }, /* R16 */
21 { 0x0000, 0x0000 }, /* R17 */
22 { 0x0000, 0x0000 }, /* R18 */
23 { 0x0000, 0x0000 }, /* R19 */
24 { 0x0000, 0x0000 }, /* R20 */
25 { 0x01C0, 0x01C0 }, /* R21 - Input Mixer (1) */
26 { 0x0000, 0x0000 }, /* R22 */
27 { 0x0000, 0x0000 }, /* R23 */
28 { 0x00DF, 0x01DF }, /* R24 - Left Line Input 1&2 Volume */
29 { 0x00DF, 0x01DF }, /* R25 - Left Line Input 3&4 Volume */
30 { 0x00DF, 0x01DF }, /* R26 - Right Line Input 1&2 Volume */
31 { 0x00DF, 0x01DF }, /* R27 - Right Line Input 3&4 Volume */
32 { 0x00FF, 0x01FF }, /* R28 - Left Output Volume */
33 { 0x00FF, 0x01FF }, /* R29 - Right Output Volume */
34 { 0x0077, 0x0077 }, /* R30 - Line Outputs Volume */
35 { 0x0030, 0x0030 }, /* R31 - HPOUT2 Volume */
36 { 0x00FF, 0x01FF }, /* R32 - Left OPGA Volume */
37 { 0x00FF, 0x01FF }, /* R33 - Right OPGA Volume */
38 { 0x007F, 0x007F }, /* R34 - SPKMIXL Attenuation */
39 { 0x017F, 0x017F }, /* R35 - SPKMIXR Attenuation */
40 { 0x003F, 0x003F }, /* R36 - SPKOUT Mixers */
41 { 0x003F, 0x003F }, /* R37 - ClassD */
42 { 0x00FF, 0x01FF }, /* R38 - Speaker Volume Left */
43 { 0x00FF, 0x01FF }, /* R39 - Speaker Volume Right */
44 { 0x00FF, 0x00FF }, /* R40 - Input Mixer (2) */
45 { 0x01B7, 0x01B7 }, /* R41 - Input Mixer (3) */
46 { 0x01B7, 0x01B7 }, /* R42 - Input Mixer (4) */
47 { 0x01C7, 0x01C7 }, /* R43 - Input Mixer (5) */
48 { 0x01C7, 0x01C7 }, /* R44 - Input Mixer (6) */
49 { 0x01FF, 0x01FF }, /* R45 - Output Mixer (1) */
50 { 0x01FF, 0x01FF }, /* R46 - Output Mixer (2) */
51 { 0x0FFF, 0x0FFF }, /* R47 - Output Mixer (3) */
52 { 0x0FFF, 0x0FFF }, /* R48 - Output Mixer (4) */
53 { 0x0FFF, 0x0FFF }, /* R49 - Output Mixer (5) */
54 { 0x0FFF, 0x0FFF }, /* R50 - Output Mixer (6) */
55 { 0x0038, 0x0038 }, /* R51 - HPOUT2 Mixer */
56 { 0x0077, 0x0077 }, /* R52 - Line Mixer (1) */
57 { 0x0077, 0x0077 }, /* R53 - Line Mixer (2) */
58 { 0x03FF, 0x03FF }, /* R54 - Speaker Mixer */
59 { 0x00C1, 0x00C1 }, /* R55 - Additional Control */
60 { 0x00F0, 0x00F0 }, /* R56 - AntiPOP (1) */
61 { 0x01EF, 0x01EF }, /* R57 - AntiPOP (2) */
62 { 0x00FF, 0x00FF }, /* R58 - MICBIAS */
63 { 0x000F, 0x000F }, /* R59 - LDO 1 */
64 { 0x0007, 0x0007 }, /* R60 - LDO 2 */
65 { 0x0000, 0x0000 }, /* R61 */
66 { 0x0000, 0x0000 }, /* R62 */
67 { 0x0000, 0x0000 }, /* R63 */
68 { 0x0000, 0x0000 }, /* R64 */
69 { 0x0000, 0x0000 }, /* R65 */
70 { 0x0000, 0x0000 }, /* R66 */
71 { 0x0000, 0x0000 }, /* R67 */
72 { 0x0000, 0x0000 }, /* R68 */
73 { 0x0000, 0x0000 }, /* R69 */
74 { 0x0000, 0x0000 }, /* R70 */
75 { 0x0000, 0x0000 }, /* R71 */
76 { 0x0000, 0x0000 }, /* R72 */
77 { 0x0000, 0x0000 }, /* R73 */
78 { 0x0000, 0x0000 }, /* R74 */
79 { 0x0000, 0x0000 }, /* R75 */
80 { 0x8000, 0x8000 }, /* R76 - Charge Pump (1) */
81 { 0x0000, 0x0000 }, /* R77 */
82 { 0x0000, 0x0000 }, /* R78 */
83 { 0x0000, 0x0000 }, /* R79 */
84 { 0x0000, 0x0000 }, /* R80 */
85 { 0x0301, 0x0301 }, /* R81 - Class W (1) */
86 { 0x0000, 0x0000 }, /* R82 */
87 { 0x0000, 0x0000 }, /* R83 */
88 { 0x333F, 0x333F }, /* R84 - DC Servo (1) */
89 { 0x0FEF, 0x0FEF }, /* R85 - DC Servo (2) */
90 { 0x0000, 0x0000 }, /* R86 */
91 { 0xFFFF, 0xFFFF }, /* R87 - DC Servo (4) */
92 { 0x0333, 0x0000 }, /* R88 - DC Servo Readback */
93 { 0x0000, 0x0000 }, /* R89 */
94 { 0x0000, 0x0000 }, /* R90 */
95 { 0x0000, 0x0000 }, /* R91 */
96 { 0x0000, 0x0000 }, /* R92 */
97 { 0x0000, 0x0000 }, /* R93 */
98 { 0x0000, 0x0000 }, /* R94 */
99 { 0x0000, 0x0000 }, /* R95 */
100 { 0x00EE, 0x00EE }, /* R96 - Analogue HP (1) */
101 { 0x0000, 0x0000 }, /* R97 */
102 { 0x0000, 0x0000 }, /* R98 */
103 { 0x0000, 0x0000 }, /* R99 */
104 { 0x0000, 0x0000 }, /* R100 */
105 { 0x0000, 0x0000 }, /* R101 */
106 { 0x0000, 0x0000 }, /* R102 */
107 { 0x0000, 0x0000 }, /* R103 */
108 { 0x0000, 0x0000 }, /* R104 */
109 { 0x0000, 0x0000 }, /* R105 */
110 { 0x0000, 0x0000 }, /* R106 */
111 { 0x0000, 0x0000 }, /* R107 */
112 { 0x0000, 0x0000 }, /* R108 */
113 { 0x0000, 0x0000 }, /* R109 */
114 { 0x0000, 0x0000 }, /* R110 */
115 { 0x0000, 0x0000 }, /* R111 */
116 { 0x0000, 0x0000 }, /* R112 */
117 { 0x0000, 0x0000 }, /* R113 */
118 { 0x0000, 0x0000 }, /* R114 */
119 { 0x0000, 0x0000 }, /* R115 */
120 { 0x0000, 0x0000 }, /* R116 */
121 { 0x0000, 0x0000 }, /* R117 */
122 { 0x0000, 0x0000 }, /* R118 */
123 { 0x0000, 0x0000 }, /* R119 */
124 { 0x0000, 0x0000 }, /* R120 */
125 { 0x0000, 0x0000 }, /* R121 */
126 { 0x0000, 0x0000 }, /* R122 */
127 { 0x0000, 0x0000 }, /* R123 */
128 { 0x0000, 0x0000 }, /* R124 */
129 { 0x0000, 0x0000 }, /* R125 */
130 { 0x0000, 0x0000 }, /* R126 */
131 { 0x0000, 0x0000 }, /* R127 */
132 { 0x0000, 0x0000 }, /* R128 */
133 { 0x0000, 0x0000 }, /* R129 */
134 { 0x0000, 0x0000 }, /* R130 */
135 { 0x0000, 0x0000 }, /* R131 */
136 { 0x0000, 0x0000 }, /* R132 */
137 { 0x0000, 0x0000 }, /* R133 */
138 { 0x0000, 0x0000 }, /* R134 */
139 { 0x0000, 0x0000 }, /* R135 */
140 { 0x0000, 0x0000 }, /* R136 */
141 { 0x0000, 0x0000 }, /* R137 */
142 { 0x0000, 0x0000 }, /* R138 */
143 { 0x0000, 0x0000 }, /* R139 */
144 { 0x0000, 0x0000 }, /* R140 */
145 { 0x0000, 0x0000 }, /* R141 */
146 { 0x0000, 0x0000 }, /* R142 */
147 { 0x0000, 0x0000 }, /* R143 */
148 { 0x0000, 0x0000 }, /* R144 */
149 { 0x0000, 0x0000 }, /* R145 */
150 { 0x0000, 0x0000 }, /* R146 */
151 { 0x0000, 0x0000 }, /* R147 */
152 { 0x0000, 0x0000 }, /* R148 */
153 { 0x0000, 0x0000 }, /* R149 */
154 { 0x0000, 0x0000 }, /* R150 */
155 { 0x0000, 0x0000 }, /* R151 */
156 { 0x0000, 0x0000 }, /* R152 */
157 { 0x0000, 0x0000 }, /* R153 */
158 { 0x0000, 0x0000 }, /* R154 */
159 { 0x0000, 0x0000 }, /* R155 */
160 { 0x0000, 0x0000 }, /* R156 */
161 { 0x0000, 0x0000 }, /* R157 */
162 { 0x0000, 0x0000 }, /* R158 */
163 { 0x0000, 0x0000 }, /* R159 */
164 { 0x0000, 0x0000 }, /* R160 */
165 { 0x0000, 0x0000 }, /* R161 */
166 { 0x0000, 0x0000 }, /* R162 */
167 { 0x0000, 0x0000 }, /* R163 */
168 { 0x0000, 0x0000 }, /* R164 */
169 { 0x0000, 0x0000 }, /* R165 */
170 { 0x0000, 0x0000 }, /* R166 */
171 { 0x0000, 0x0000 }, /* R167 */
172 { 0x0000, 0x0000 }, /* R168 */
173 { 0x0000, 0x0000 }, /* R169 */
174 { 0x0000, 0x0000 }, /* R170 */
175 { 0x0000, 0x0000 }, /* R171 */
176 { 0x0000, 0x0000 }, /* R172 */
177 { 0x0000, 0x0000 }, /* R173 */
178 { 0x0000, 0x0000 }, /* R174 */
179 { 0x0000, 0x0000 }, /* R175 */
180 { 0x0000, 0x0000 }, /* R176 */
181 { 0x0000, 0x0000 }, /* R177 */
182 { 0x0000, 0x0000 }, /* R178 */
183 { 0x0000, 0x0000 }, /* R179 */
184 { 0x0000, 0x0000 }, /* R180 */
185 { 0x0000, 0x0000 }, /* R181 */
186 { 0x0000, 0x0000 }, /* R182 */
187 { 0x0000, 0x0000 }, /* R183 */
188 { 0x0000, 0x0000 }, /* R184 */
189 { 0x0000, 0x0000 }, /* R185 */
190 { 0x0000, 0x0000 }, /* R186 */
191 { 0x0000, 0x0000 }, /* R187 */
192 { 0x0000, 0x0000 }, /* R188 */
193 { 0x0000, 0x0000 }, /* R189 */
194 { 0x0000, 0x0000 }, /* R190 */
195 { 0x0000, 0x0000 }, /* R191 */
196 { 0x0000, 0x0000 }, /* R192 */
197 { 0x0000, 0x0000 }, /* R193 */
198 { 0x0000, 0x0000 }, /* R194 */
199 { 0x0000, 0x0000 }, /* R195 */
200 { 0x0000, 0x0000 }, /* R196 */
201 { 0x0000, 0x0000 }, /* R197 */
202 { 0x0000, 0x0000 }, /* R198 */
203 { 0x0000, 0x0000 }, /* R199 */
204 { 0x0000, 0x0000 }, /* R200 */
205 { 0x0000, 0x0000 }, /* R201 */
206 { 0x0000, 0x0000 }, /* R202 */
207 { 0x0000, 0x0000 }, /* R203 */
208 { 0x0000, 0x0000 }, /* R204 */
209 { 0x0000, 0x0000 }, /* R205 */
210 { 0x0000, 0x0000 }, /* R206 */
211 { 0x0000, 0x0000 }, /* R207 */
212 { 0x0000, 0x0000 }, /* R208 */
213 { 0x0000, 0x0000 }, /* R209 */
214 { 0x0000, 0x0000 }, /* R210 */
215 { 0x0000, 0x0000 }, /* R211 */
216 { 0x0000, 0x0000 }, /* R212 */
217 { 0x0000, 0x0000 }, /* R213 */
218 { 0x0000, 0x0000 }, /* R214 */
219 { 0x0000, 0x0000 }, /* R215 */
220 { 0x0000, 0x0000 }, /* R216 */
221 { 0x0000, 0x0000 }, /* R217 */
222 { 0x0000, 0x0000 }, /* R218 */
223 { 0x0000, 0x0000 }, /* R219 */
224 { 0x0000, 0x0000 }, /* R220 */
225 { 0x0000, 0x0000 }, /* R221 */
226 { 0x0000, 0x0000 }, /* R222 */
227 { 0x0000, 0x0000 }, /* R223 */
228 { 0x0000, 0x0000 }, /* R224 */
229 { 0x0000, 0x0000 }, /* R225 */
230 { 0x0000, 0x0000 }, /* R226 */
231 { 0x0000, 0x0000 }, /* R227 */
232 { 0x0000, 0x0000 }, /* R228 */
233 { 0x0000, 0x0000 }, /* R229 */
234 { 0x0000, 0x0000 }, /* R230 */
235 { 0x0000, 0x0000 }, /* R231 */
236 { 0x0000, 0x0000 }, /* R232 */
237 { 0x0000, 0x0000 }, /* R233 */
238 { 0x0000, 0x0000 }, /* R234 */
239 { 0x0000, 0x0000 }, /* R235 */
240 { 0x0000, 0x0000 }, /* R236 */
241 { 0x0000, 0x0000 }, /* R237 */
242 { 0x0000, 0x0000 }, /* R238 */
243 { 0x0000, 0x0000 }, /* R239 */
244 { 0x0000, 0x0000 }, /* R240 */
245 { 0x0000, 0x0000 }, /* R241 */
246 { 0x0000, 0x0000 }, /* R242 */
247 { 0x0000, 0x0000 }, /* R243 */
248 { 0x0000, 0x0000 }, /* R244 */
249 { 0x0000, 0x0000 }, /* R245 */
250 { 0x0000, 0x0000 }, /* R246 */
251 { 0x0000, 0x0000 }, /* R247 */
252 { 0x0000, 0x0000 }, /* R248 */
253 { 0x0000, 0x0000 }, /* R249 */
254 { 0x0000, 0x0000 }, /* R250 */
255 { 0x0000, 0x0000 }, /* R251 */
256 { 0x0000, 0x0000 }, /* R252 */
257 { 0x0000, 0x0000 }, /* R253 */
258 { 0x0000, 0x0000 }, /* R254 */
259 { 0x0000, 0x0000 }, /* R255 */
260 { 0x000F, 0x0000 }, /* R256 - Chip Revision */
261 { 0x0074, 0x0074 }, /* R257 - Control Interface */
262 { 0x0000, 0x0000 }, /* R258 */
263 { 0x0000, 0x0000 }, /* R259 */
264 { 0x0000, 0x0000 }, /* R260 */
265 { 0x0000, 0x0000 }, /* R261 */
266 { 0x0000, 0x0000 }, /* R262 */
267 { 0x0000, 0x0000 }, /* R263 */
268 { 0x0000, 0x0000 }, /* R264 */
269 { 0x0000, 0x0000 }, /* R265 */
270 { 0x0000, 0x0000 }, /* R266 */
271 { 0x0000, 0x0000 }, /* R267 */
272 { 0x0000, 0x0000 }, /* R268 */
273 { 0x0000, 0x0000 }, /* R269 */
274 { 0x0000, 0x0000 }, /* R270 */
275 { 0x0000, 0x0000 }, /* R271 */
276 { 0x807F, 0x837F }, /* R272 - Write Sequencer Ctrl (1) */
277 { 0x017F, 0x0000 }, /* R273 - Write Sequencer Ctrl (2) */
278 { 0x0000, 0x0000 }, /* R274 */
279 { 0x0000, 0x0000 }, /* R275 */
280 { 0x0000, 0x0000 }, /* R276 */
281 { 0x0000, 0x0000 }, /* R277 */
282 { 0x0000, 0x0000 }, /* R278 */
283 { 0x0000, 0x0000 }, /* R279 */
284 { 0x0000, 0x0000 }, /* R280 */
285 { 0x0000, 0x0000 }, /* R281 */
286 { 0x0000, 0x0000 }, /* R282 */
287 { 0x0000, 0x0000 }, /* R283 */
288 { 0x0000, 0x0000 }, /* R284 */
289 { 0x0000, 0x0000 }, /* R285 */
290 { 0x0000, 0x0000 }, /* R286 */
291 { 0x0000, 0x0000 }, /* R287 */
292 { 0x0000, 0x0000 }, /* R288 */
293 { 0x0000, 0x0000 }, /* R289 */
294 { 0x0000, 0x0000 }, /* R290 */
295 { 0x0000, 0x0000 }, /* R291 */
296 { 0x0000, 0x0000 }, /* R292 */
297 { 0x0000, 0x0000 }, /* R293 */
298 { 0x0000, 0x0000 }, /* R294 */
299 { 0x0000, 0x0000 }, /* R295 */
300 { 0x0000, 0x0000 }, /* R296 */
301 { 0x0000, 0x0000 }, /* R297 */
302 { 0x0000, 0x0000 }, /* R298 */
303 { 0x0000, 0x0000 }, /* R299 */
304 { 0x0000, 0x0000 }, /* R300 */
305 { 0x0000, 0x0000 }, /* R301 */
306 { 0x0000, 0x0000 }, /* R302 */
307 { 0x0000, 0x0000 }, /* R303 */
308 { 0x0000, 0x0000 }, /* R304 */
309 { 0x0000, 0x0000 }, /* R305 */
310 { 0x0000, 0x0000 }, /* R306 */
311 { 0x0000, 0x0000 }, /* R307 */
312 { 0x0000, 0x0000 }, /* R308 */
313 { 0x0000, 0x0000 }, /* R309 */
314 { 0x0000, 0x0000 }, /* R310 */
315 { 0x0000, 0x0000 }, /* R311 */
316 { 0x0000, 0x0000 }, /* R312 */
317 { 0x0000, 0x0000 }, /* R313 */
318 { 0x0000, 0x0000 }, /* R314 */
319 { 0x0000, 0x0000 }, /* R315 */
320 { 0x0000, 0x0000 }, /* R316 */
321 { 0x0000, 0x0000 }, /* R317 */
322 { 0x0000, 0x0000 }, /* R318 */
323 { 0x0000, 0x0000 }, /* R319 */
324 { 0x0000, 0x0000 }, /* R320 */
325 { 0x0000, 0x0000 }, /* R321 */
326 { 0x0000, 0x0000 }, /* R322 */
327 { 0x0000, 0x0000 }, /* R323 */
328 { 0x0000, 0x0000 }, /* R324 */
329 { 0x0000, 0x0000 }, /* R325 */
330 { 0x0000, 0x0000 }, /* R326 */
331 { 0x0000, 0x0000 }, /* R327 */
332 { 0x0000, 0x0000 }, /* R328 */
333 { 0x0000, 0x0000 }, /* R329 */
334 { 0x0000, 0x0000 }, /* R330 */
335 { 0x0000, 0x0000 }, /* R331 */
336 { 0x0000, 0x0000 }, /* R332 */
337 { 0x0000, 0x0000 }, /* R333 */
338 { 0x0000, 0x0000 }, /* R334 */
339 { 0x0000, 0x0000 }, /* R335 */
340 { 0x0000, 0x0000 }, /* R336 */
341 { 0x0000, 0x0000 }, /* R337 */
342 { 0x0000, 0x0000 }, /* R338 */
343 { 0x0000, 0x0000 }, /* R339 */
344 { 0x0000, 0x0000 }, /* R340 */
345 { 0x0000, 0x0000 }, /* R341 */
346 { 0x0000, 0x0000 }, /* R342 */
347 { 0x0000, 0x0000 }, /* R343 */
348 { 0x0000, 0x0000 }, /* R344 */
349 { 0x0000, 0x0000 }, /* R345 */
350 { 0x0000, 0x0000 }, /* R346 */
351 { 0x0000, 0x0000 }, /* R347 */
352 { 0x0000, 0x0000 }, /* R348 */
353 { 0x0000, 0x0000 }, /* R349 */
354 { 0x0000, 0x0000 }, /* R350 */
355 { 0x0000, 0x0000 }, /* R351 */
356 { 0x0000, 0x0000 }, /* R352 */
357 { 0x0000, 0x0000 }, /* R353 */
358 { 0x0000, 0x0000 }, /* R354 */
359 { 0x0000, 0x0000 }, /* R355 */
360 { 0x0000, 0x0000 }, /* R356 */
361 { 0x0000, 0x0000 }, /* R357 */
362 { 0x0000, 0x0000 }, /* R358 */
363 { 0x0000, 0x0000 }, /* R359 */
364 { 0x0000, 0x0000 }, /* R360 */
365 { 0x0000, 0x0000 }, /* R361 */
366 { 0x0000, 0x0000 }, /* R362 */
367 { 0x0000, 0x0000 }, /* R363 */
368 { 0x0000, 0x0000 }, /* R364 */
369 { 0x0000, 0x0000 }, /* R365 */
370 { 0x0000, 0x0000 }, /* R366 */
371 { 0x0000, 0x0000 }, /* R367 */
372 { 0x0000, 0x0000 }, /* R368 */
373 { 0x0000, 0x0000 }, /* R369 */
374 { 0x0000, 0x0000 }, /* R370 */
375 { 0x0000, 0x0000 }, /* R371 */
376 { 0x0000, 0x0000 }, /* R372 */
377 { 0x0000, 0x0000 }, /* R373 */
378 { 0x0000, 0x0000 }, /* R374 */
379 { 0x0000, 0x0000 }, /* R375 */
380 { 0x0000, 0x0000 }, /* R376 */
381 { 0x0000, 0x0000 }, /* R377 */
382 { 0x0000, 0x0000 }, /* R378 */
383 { 0x0000, 0x0000 }, /* R379 */
384 { 0x0000, 0x0000 }, /* R380 */
385 { 0x0000, 0x0000 }, /* R381 */
386 { 0x0000, 0x0000 }, /* R382 */
387 { 0x0000, 0x0000 }, /* R383 */
388 { 0x0000, 0x0000 }, /* R384 */
389 { 0x0000, 0x0000 }, /* R385 */
390 { 0x0000, 0x0000 }, /* R386 */
391 { 0x0000, 0x0000 }, /* R387 */
392 { 0x0000, 0x0000 }, /* R388 */
393 { 0x0000, 0x0000 }, /* R389 */
394 { 0x0000, 0x0000 }, /* R390 */
395 { 0x0000, 0x0000 }, /* R391 */
396 { 0x0000, 0x0000 }, /* R392 */
397 { 0x0000, 0x0000 }, /* R393 */
398 { 0x0000, 0x0000 }, /* R394 */
399 { 0x0000, 0x0000 }, /* R395 */
400 { 0x0000, 0x0000 }, /* R396 */
401 { 0x0000, 0x0000 }, /* R397 */
402 { 0x0000, 0x0000 }, /* R398 */
403 { 0x0000, 0x0000 }, /* R399 */
404 { 0x0000, 0x0000 }, /* R400 */
405 { 0x0000, 0x0000 }, /* R401 */
406 { 0x0000, 0x0000 }, /* R402 */
407 { 0x0000, 0x0000 }, /* R403 */
408 { 0x0000, 0x0000 }, /* R404 */
409 { 0x0000, 0x0000 }, /* R405 */
410 { 0x0000, 0x0000 }, /* R406 */
411 { 0x0000, 0x0000 }, /* R407 */
412 { 0x0000, 0x0000 }, /* R408 */
413 { 0x0000, 0x0000 }, /* R409 */
414 { 0x0000, 0x0000 }, /* R410 */
415 { 0x0000, 0x0000 }, /* R411 */
416 { 0x0000, 0x0000 }, /* R412 */
417 { 0x0000, 0x0000 }, /* R413 */
418 { 0x0000, 0x0000 }, /* R414 */
419 { 0x0000, 0x0000 }, /* R415 */
420 { 0x0000, 0x0000 }, /* R416 */
421 { 0x0000, 0x0000 }, /* R417 */
422 { 0x0000, 0x0000 }, /* R418 */
423 { 0x0000, 0x0000 }, /* R419 */
424 { 0x0000, 0x0000 }, /* R420 */
425 { 0x0000, 0x0000 }, /* R421 */
426 { 0x0000, 0x0000 }, /* R422 */
427 { 0x0000, 0x0000 }, /* R423 */
428 { 0x0000, 0x0000 }, /* R424 */
429 { 0x0000, 0x0000 }, /* R425 */
430 { 0x0000, 0x0000 }, /* R426 */
431 { 0x0000, 0x0000 }, /* R427 */
432 { 0x0000, 0x0000 }, /* R428 */
433 { 0x0000, 0x0000 }, /* R429 */
434 { 0x0000, 0x0000 }, /* R430 */
435 { 0x0000, 0x0000 }, /* R431 */
436 { 0x0000, 0x0000 }, /* R432 */
437 { 0x0000, 0x0000 }, /* R433 */
438 { 0x0000, 0x0000 }, /* R434 */
439 { 0x0000, 0x0000 }, /* R435 */
440 { 0x0000, 0x0000 }, /* R436 */
441 { 0x0000, 0x0000 }, /* R437 */
442 { 0x0000, 0x0000 }, /* R438 */
443 { 0x0000, 0x0000 }, /* R439 */
444 { 0x0000, 0x0000 }, /* R440 */
445 { 0x0000, 0x0000 }, /* R441 */
446 { 0x0000, 0x0000 }, /* R442 */
447 { 0x0000, 0x0000 }, /* R443 */
448 { 0x0000, 0x0000 }, /* R444 */
449 { 0x0000, 0x0000 }, /* R445 */
450 { 0x0000, 0x0000 }, /* R446 */
451 { 0x0000, 0x0000 }, /* R447 */
452 { 0x0000, 0x0000 }, /* R448 */
453 { 0x0000, 0x0000 }, /* R449 */
454 { 0x0000, 0x0000 }, /* R450 */
455 { 0x0000, 0x0000 }, /* R451 */
456 { 0x0000, 0x0000 }, /* R452 */
457 { 0x0000, 0x0000 }, /* R453 */
458 { 0x0000, 0x0000 }, /* R454 */
459 { 0x0000, 0x0000 }, /* R455 */
460 { 0x0000, 0x0000 }, /* R456 */
461 { 0x0000, 0x0000 }, /* R457 */
462 { 0x0000, 0x0000 }, /* R458 */
463 { 0x0000, 0x0000 }, /* R459 */
464 { 0x0000, 0x0000 }, /* R460 */
465 { 0x0000, 0x0000 }, /* R461 */
466 { 0x0000, 0x0000 }, /* R462 */
467 { 0x0000, 0x0000 }, /* R463 */
468 { 0x0000, 0x0000 }, /* R464 */
469 { 0x0000, 0x0000 }, /* R465 */
470 { 0x0000, 0x0000 }, /* R466 */
471 { 0x0000, 0x0000 }, /* R467 */
472 { 0x0000, 0x0000 }, /* R468 */
473 { 0x0000, 0x0000 }, /* R469 */
474 { 0x0000, 0x0000 }, /* R470 */
475 { 0x0000, 0x0000 }, /* R471 */
476 { 0x0000, 0x0000 }, /* R472 */
477 { 0x0000, 0x0000 }, /* R473 */
478 { 0x0000, 0x0000 }, /* R474 */
479 { 0x0000, 0x0000 }, /* R475 */
480 { 0x0000, 0x0000 }, /* R476 */
481 { 0x0000, 0x0000 }, /* R477 */
482 { 0x0000, 0x0000 }, /* R478 */
483 { 0x0000, 0x0000 }, /* R479 */
484 { 0x0000, 0x0000 }, /* R480 */
485 { 0x0000, 0x0000 }, /* R481 */
486 { 0x0000, 0x0000 }, /* R482 */
487 { 0x0000, 0x0000 }, /* R483 */
488 { 0x0000, 0x0000 }, /* R484 */
489 { 0x0000, 0x0000 }, /* R485 */
490 { 0x0000, 0x0000 }, /* R486 */
491 { 0x0000, 0x0000 }, /* R487 */
492 { 0x0000, 0x0000 }, /* R488 */
493 { 0x0000, 0x0000 }, /* R489 */
494 { 0x0000, 0x0000 }, /* R490 */
495 { 0x0000, 0x0000 }, /* R491 */
496 { 0x0000, 0x0000 }, /* R492 */
497 { 0x0000, 0x0000 }, /* R493 */
498 { 0x0000, 0x0000 }, /* R494 */
499 { 0x0000, 0x0000 }, /* R495 */
500 { 0x0000, 0x0000 }, /* R496 */
501 { 0x0000, 0x0000 }, /* R497 */
502 { 0x0000, 0x0000 }, /* R498 */
503 { 0x0000, 0x0000 }, /* R499 */
504 { 0x0000, 0x0000 }, /* R500 */
505 { 0x0000, 0x0000 }, /* R501 */
506 { 0x0000, 0x0000 }, /* R502 */
507 { 0x0000, 0x0000 }, /* R503 */
508 { 0x0000, 0x0000 }, /* R504 */
509 { 0x0000, 0x0000 }, /* R505 */
510 { 0x0000, 0x0000 }, /* R506 */
511 { 0x0000, 0x0000 }, /* R507 */
512 { 0x0000, 0x0000 }, /* R508 */
513 { 0x0000, 0x0000 }, /* R509 */
514 { 0x0000, 0x0000 }, /* R510 */
515 { 0x0000, 0x0000 }, /* R511 */
516 { 0x001F, 0x001F }, /* R512 - AIF1 Clocking (1) */
517 { 0x003F, 0x003F }, /* R513 - AIF1 Clocking (2) */
518 { 0x0000, 0x0000 }, /* R514 */
519 { 0x0000, 0x0000 }, /* R515 */
520 { 0x001F, 0x001F }, /* R516 - AIF2 Clocking (1) */
521 { 0x003F, 0x003F }, /* R517 - AIF2 Clocking (2) */
522 { 0x0000, 0x0000 }, /* R518 */
523 { 0x0000, 0x0000 }, /* R519 */
524 { 0x001F, 0x001F }, /* R520 - Clocking (1) */
525 { 0x0777, 0x0777 }, /* R521 - Clocking (2) */
526 { 0x0000, 0x0000 }, /* R522 */
527 { 0x0000, 0x0000 }, /* R523 */
528 { 0x0000, 0x0000 }, /* R524 */
529 { 0x0000, 0x0000 }, /* R525 */
530 { 0x0000, 0x0000 }, /* R526 */
531 { 0x0000, 0x0000 }, /* R527 */
532 { 0x00FF, 0x00FF }, /* R528 - AIF1 Rate */
533 { 0x00FF, 0x00FF }, /* R529 - AIF2 Rate */
534 { 0x000F, 0x0000 }, /* R530 - Rate Status */
535 { 0x0000, 0x0000 }, /* R531 */
536 { 0x0000, 0x0000 }, /* R532 */
537 { 0x0000, 0x0000 }, /* R533 */
538 { 0x0000, 0x0000 }, /* R534 */
539 { 0x0000, 0x0000 }, /* R535 */
540 { 0x0000, 0x0000 }, /* R536 */
541 { 0x0000, 0x0000 }, /* R537 */
542 { 0x0000, 0x0000 }, /* R538 */
543 { 0x0000, 0x0000 }, /* R539 */
544 { 0x0000, 0x0000 }, /* R540 */
545 { 0x0000, 0x0000 }, /* R541 */
546 { 0x0000, 0x0000 }, /* R542 */
547 { 0x0000, 0x0000 }, /* R543 */
548 { 0x0007, 0x0007 }, /* R544 - FLL1 Control (1) */
549 { 0x3F77, 0x3F77 }, /* R545 - FLL1 Control (2) */
550 { 0xFFFF, 0xFFFF }, /* R546 - FLL1 Control (3) */
551 { 0x7FEF, 0x7FEF }, /* R547 - FLL1 Control (4) */
552 { 0x1FDB, 0x1FDB }, /* R548 - FLL1 Control (5) */
553 { 0x0000, 0x0000 }, /* R549 */
554 { 0x0000, 0x0000 }, /* R550 */
555 { 0x0000, 0x0000 }, /* R551 */
556 { 0x0000, 0x0000 }, /* R552 */
557 { 0x0000, 0x0000 }, /* R553 */
558 { 0x0000, 0x0000 }, /* R554 */
559 { 0x0000, 0x0000 }, /* R555 */
560 { 0x0000, 0x0000 }, /* R556 */
561 { 0x0000, 0x0000 }, /* R557 */
562 { 0x0000, 0x0000 }, /* R558 */
563 { 0x0000, 0x0000 }, /* R559 */
564 { 0x0000, 0x0000 }, /* R560 */
565 { 0x0000, 0x0000 }, /* R561 */
566 { 0x0000, 0x0000 }, /* R562 */
567 { 0x0000, 0x0000 }, /* R563 */
568 { 0x0000, 0x0000 }, /* R564 */
569 { 0x0000, 0x0000 }, /* R565 */
570 { 0x0000, 0x0000 }, /* R566 */
571 { 0x0000, 0x0000 }, /* R567 */
572 { 0x0000, 0x0000 }, /* R568 */
573 { 0x0000, 0x0000 }, /* R569 */
574 { 0x0000, 0x0000 }, /* R570 */
575 { 0x0000, 0x0000 }, /* R571 */
576 { 0x0000, 0x0000 }, /* R572 */
577 { 0x0000, 0x0000 }, /* R573 */
578 { 0x0000, 0x0000 }, /* R574 */
579 { 0x0000, 0x0000 }, /* R575 */
580 { 0x0007, 0x0007 }, /* R576 - FLL2 Control (1) */
581 { 0x3F77, 0x3F77 }, /* R577 - FLL2 Control (2) */
582 { 0xFFFF, 0xFFFF }, /* R578 - FLL2 Control (3) */
583 { 0x7FEF, 0x7FEF }, /* R579 - FLL2 Control (4) */
584 { 0x1FDB, 0x1FDB }, /* R580 - FLL2 Control (5) */
585 { 0x0000, 0x0000 }, /* R581 */
586 { 0x0000, 0x0000 }, /* R582 */
587 { 0x0000, 0x0000 }, /* R583 */
588 { 0x0000, 0x0000 }, /* R584 */
589 { 0x0000, 0x0000 }, /* R585 */
590 { 0x0000, 0x0000 }, /* R586 */
591 { 0x0000, 0x0000 }, /* R587 */
592 { 0x0000, 0x0000 }, /* R588 */
593 { 0x0000, 0x0000 }, /* R589 */
594 { 0x0000, 0x0000 }, /* R590 */
595 { 0x0000, 0x0000 }, /* R591 */
596 { 0x0000, 0x0000 }, /* R592 */
597 { 0x0000, 0x0000 }, /* R593 */
598 { 0x0000, 0x0000 }, /* R594 */
599 { 0x0000, 0x0000 }, /* R595 */
600 { 0x0000, 0x0000 }, /* R596 */
601 { 0x0000, 0x0000 }, /* R597 */
602 { 0x0000, 0x0000 }, /* R598 */
603 { 0x0000, 0x0000 }, /* R599 */
604 { 0x0000, 0x0000 }, /* R600 */
605 { 0x0000, 0x0000 }, /* R601 */
606 { 0x0000, 0x0000 }, /* R602 */
607 { 0x0000, 0x0000 }, /* R603 */
608 { 0x0000, 0x0000 }, /* R604 */
609 { 0x0000, 0x0000 }, /* R605 */
610 { 0x0000, 0x0000 }, /* R606 */
611 { 0x0000, 0x0000 }, /* R607 */
612 { 0x0000, 0x0000 }, /* R608 */
613 { 0x0000, 0x0000 }, /* R609 */
614 { 0x0000, 0x0000 }, /* R610 */
615 { 0x0000, 0x0000 }, /* R611 */
616 { 0x0000, 0x0000 }, /* R612 */
617 { 0x0000, 0x0000 }, /* R613 */
618 { 0x0000, 0x0000 }, /* R614 */
619 { 0x0000, 0x0000 }, /* R615 */
620 { 0x0000, 0x0000 }, /* R616 */
621 { 0x0000, 0x0000 }, /* R617 */
622 { 0x0000, 0x0000 }, /* R618 */
623 { 0x0000, 0x0000 }, /* R619 */
624 { 0x0000, 0x0000 }, /* R620 */
625 { 0x0000, 0x0000 }, /* R621 */
626 { 0x0000, 0x0000 }, /* R622 */
627 { 0x0000, 0x0000 }, /* R623 */
628 { 0x0000, 0x0000 }, /* R624 */
629 { 0x0000, 0x0000 }, /* R625 */
630 { 0x0000, 0x0000 }, /* R626 */
631 { 0x0000, 0x0000 }, /* R627 */
632 { 0x0000, 0x0000 }, /* R628 */
633 { 0x0000, 0x0000 }, /* R629 */
634 { 0x0000, 0x0000 }, /* R630 */
635 { 0x0000, 0x0000 }, /* R631 */
636 { 0x0000, 0x0000 }, /* R632 */
637 { 0x0000, 0x0000 }, /* R633 */
638 { 0x0000, 0x0000 }, /* R634 */
639 { 0x0000, 0x0000 }, /* R635 */
640 { 0x0000, 0x0000 }, /* R636 */
641 { 0x0000, 0x0000 }, /* R637 */
642 { 0x0000, 0x0000 }, /* R638 */
643 { 0x0000, 0x0000 }, /* R639 */
644 { 0x0000, 0x0000 }, /* R640 */
645 { 0x0000, 0x0000 }, /* R641 */
646 { 0x0000, 0x0000 }, /* R642 */
647 { 0x0000, 0x0000 }, /* R643 */
648 { 0x0000, 0x0000 }, /* R644 */
649 { 0x0000, 0x0000 }, /* R645 */
650 { 0x0000, 0x0000 }, /* R646 */
651 { 0x0000, 0x0000 }, /* R647 */
652 { 0x0000, 0x0000 }, /* R648 */
653 { 0x0000, 0x0000 }, /* R649 */
654 { 0x0000, 0x0000 }, /* R650 */
655 { 0x0000, 0x0000 }, /* R651 */
656 { 0x0000, 0x0000 }, /* R652 */
657 { 0x0000, 0x0000 }, /* R653 */
658 { 0x0000, 0x0000 }, /* R654 */
659 { 0x0000, 0x0000 }, /* R655 */
660 { 0x0000, 0x0000 }, /* R656 */
661 { 0x0000, 0x0000 }, /* R657 */
662 { 0x0000, 0x0000 }, /* R658 */
663 { 0x0000, 0x0000 }, /* R659 */
664 { 0x0000, 0x0000 }, /* R660 */
665 { 0x0000, 0x0000 }, /* R661 */
666 { 0x0000, 0x0000 }, /* R662 */
667 { 0x0000, 0x0000 }, /* R663 */
668 { 0x0000, 0x0000 }, /* R664 */
669 { 0x0000, 0x0000 }, /* R665 */
670 { 0x0000, 0x0000 }, /* R666 */
671 { 0x0000, 0x0000 }, /* R667 */
672 { 0x0000, 0x0000 }, /* R668 */
673 { 0x0000, 0x0000 }, /* R669 */
674 { 0x0000, 0x0000 }, /* R670 */
675 { 0x0000, 0x0000 }, /* R671 */
676 { 0x0000, 0x0000 }, /* R672 */
677 { 0x0000, 0x0000 }, /* R673 */
678 { 0x0000, 0x0000 }, /* R674 */
679 { 0x0000, 0x0000 }, /* R675 */
680 { 0x0000, 0x0000 }, /* R676 */
681 { 0x0000, 0x0000 }, /* R677 */
682 { 0x0000, 0x0000 }, /* R678 */
683 { 0x0000, 0x0000 }, /* R679 */
684 { 0x0000, 0x0000 }, /* R680 */
685 { 0x0000, 0x0000 }, /* R681 */
686 { 0x0000, 0x0000 }, /* R682 */
687 { 0x0000, 0x0000 }, /* R683 */
688 { 0x0000, 0x0000 }, /* R684 */
689 { 0x0000, 0x0000 }, /* R685 */
690 { 0x0000, 0x0000 }, /* R686 */
691 { 0x0000, 0x0000 }, /* R687 */
692 { 0x0000, 0x0000 }, /* R688 */
693 { 0x0000, 0x0000 }, /* R689 */
694 { 0x0000, 0x0000 }, /* R690 */
695 { 0x0000, 0x0000 }, /* R691 */
696 { 0x0000, 0x0000 }, /* R692 */
697 { 0x0000, 0x0000 }, /* R693 */
698 { 0x0000, 0x0000 }, /* R694 */
699 { 0x0000, 0x0000 }, /* R695 */
700 { 0x0000, 0x0000 }, /* R696 */
701 { 0x0000, 0x0000 }, /* R697 */
702 { 0x0000, 0x0000 }, /* R698 */
703 { 0x0000, 0x0000 }, /* R699 */
704 { 0x0000, 0x0000 }, /* R700 */
705 { 0x0000, 0x0000 }, /* R701 */
706 { 0x0000, 0x0000 }, /* R702 */
707 { 0x0000, 0x0000 }, /* R703 */
708 { 0x0000, 0x0000 }, /* R704 */
709 { 0x0000, 0x0000 }, /* R705 */
710 { 0x0000, 0x0000 }, /* R706 */
711 { 0x0000, 0x0000 }, /* R707 */
712 { 0x0000, 0x0000 }, /* R708 */
713 { 0x0000, 0x0000 }, /* R709 */
714 { 0x0000, 0x0000 }, /* R710 */
715 { 0x0000, 0x0000 }, /* R711 */
716 { 0x0000, 0x0000 }, /* R712 */
717 { 0x0000, 0x0000 }, /* R713 */
718 { 0x0000, 0x0000 }, /* R714 */
719 { 0x0000, 0x0000 }, /* R715 */
720 { 0x0000, 0x0000 }, /* R716 */
721 { 0x0000, 0x0000 }, /* R717 */
722 { 0x0000, 0x0000 }, /* R718 */
723 { 0x0000, 0x0000 }, /* R719 */
724 { 0x0000, 0x0000 }, /* R720 */
725 { 0x0000, 0x0000 }, /* R721 */
726 { 0x0000, 0x0000 }, /* R722 */
727 { 0x0000, 0x0000 }, /* R723 */
728 { 0x0000, 0x0000 }, /* R724 */
729 { 0x0000, 0x0000 }, /* R725 */
730 { 0x0000, 0x0000 }, /* R726 */
731 { 0x0000, 0x0000 }, /* R727 */
732 { 0x0000, 0x0000 }, /* R728 */
733 { 0x0000, 0x0000 }, /* R729 */
734 { 0x0000, 0x0000 }, /* R730 */
735 { 0x0000, 0x0000 }, /* R731 */
736 { 0x0000, 0x0000 }, /* R732 */
737 { 0x0000, 0x0000 }, /* R733 */
738 { 0x0000, 0x0000 }, /* R734 */
739 { 0x0000, 0x0000 }, /* R735 */
740 { 0x0000, 0x0000 }, /* R736 */
741 { 0x0000, 0x0000 }, /* R737 */
742 { 0x0000, 0x0000 }, /* R738 */
743 { 0x0000, 0x0000 }, /* R739 */
744 { 0x0000, 0x0000 }, /* R740 */
745 { 0x0000, 0x0000 }, /* R741 */
746 { 0x0000, 0x0000 }, /* R742 */
747 { 0x0000, 0x0000 }, /* R743 */
748 { 0x0000, 0x0000 }, /* R744 */
749 { 0x0000, 0x0000 }, /* R745 */
750 { 0x0000, 0x0000 }, /* R746 */
751 { 0x0000, 0x0000 }, /* R747 */
752 { 0x0000, 0x0000 }, /* R748 */
753 { 0x0000, 0x0000 }, /* R749 */
754 { 0x0000, 0x0000 }, /* R750 */
755 { 0x0000, 0x0000 }, /* R751 */
756 { 0x0000, 0x0000 }, /* R752 */
757 { 0x0000, 0x0000 }, /* R753 */
758 { 0x0000, 0x0000 }, /* R754 */
759 { 0x0000, 0x0000 }, /* R755 */
760 { 0x0000, 0x0000 }, /* R756 */
761 { 0x0000, 0x0000 }, /* R757 */
762 { 0x0000, 0x0000 }, /* R758 */
763 { 0x0000, 0x0000 }, /* R759 */
764 { 0x0000, 0x0000 }, /* R760 */
765 { 0x0000, 0x0000 }, /* R761 */
766 { 0x0000, 0x0000 }, /* R762 */
767 { 0x0000, 0x0000 }, /* R763 */
768 { 0x0000, 0x0000 }, /* R764 */
769 { 0x0000, 0x0000 }, /* R765 */
770 { 0x0000, 0x0000 }, /* R766 */
771 { 0x0000, 0x0000 }, /* R767 */
772 { 0xE1F8, 0xE1F8 }, /* R768 - AIF1 Control (1) */
773 { 0xCD1F, 0xCD1F }, /* R769 - AIF1 Control (2) */
774 { 0xF000, 0xF000 }, /* R770 - AIF1 Master/Slave */
775 { 0x01F0, 0x01F0 }, /* R771 - AIF1 BCLK */
776 { 0x0FFF, 0x0FFF }, /* R772 - AIF1ADC LRCLK */
777 { 0x0FFF, 0x0FFF }, /* R773 - AIF1DAC LRCLK */
778 { 0x0003, 0x0003 }, /* R774 - AIF1DAC Data */
779 { 0x0003, 0x0003 }, /* R775 - AIF1ADC Data */
780 { 0x0000, 0x0000 }, /* R776 */
781 { 0x0000, 0x0000 }, /* R777 */
782 { 0x0000, 0x0000 }, /* R778 */
783 { 0x0000, 0x0000 }, /* R779 */
784 { 0x0000, 0x0000 }, /* R780 */
785 { 0x0000, 0x0000 }, /* R781 */
786 { 0x0000, 0x0000 }, /* R782 */
787 { 0x0000, 0x0000 }, /* R783 */
788 { 0xF1F8, 0xF1F8 }, /* R784 - AIF2 Control (1) */
789 { 0xFD1F, 0xFD1F }, /* R785 - AIF2 Control (2) */
790 { 0xF000, 0xF000 }, /* R786 - AIF2 Master/Slave */
791 { 0x01F0, 0x01F0 }, /* R787 - AIF2 BCLK */
792 { 0x0FFF, 0x0FFF }, /* R788 - AIF2ADC LRCLK */
793 { 0x0FFF, 0x0FFF }, /* R789 - AIF2DAC LRCLK */
794 { 0x0003, 0x0003 }, /* R790 - AIF2DAC Data */
795 { 0x0003, 0x0003 }, /* R791 - AIF2ADC Data */
796 { 0x0000, 0x0000 }, /* R792 */
797 { 0x0000, 0x0000 }, /* R793 */
798 { 0x0000, 0x0000 }, /* R794 */
799 { 0x0000, 0x0000 }, /* R795 */
800 { 0x0000, 0x0000 }, /* R796 */
801 { 0x0000, 0x0000 }, /* R797 */
802 { 0x0000, 0x0000 }, /* R798 */
803 { 0x0000, 0x0000 }, /* R799 */
804 { 0x0000, 0x0000 }, /* R800 */
805 { 0x0000, 0x0000 }, /* R801 */
806 { 0x0000, 0x0000 }, /* R802 */
807 { 0x0000, 0x0000 }, /* R803 */
808 { 0x0000, 0x0000 }, /* R804 */
809 { 0x0000, 0x0000 }, /* R805 */
810 { 0x0000, 0x0000 }, /* R806 */
811 { 0x0000, 0x0000 }, /* R807 */
812 { 0x0000, 0x0000 }, /* R808 */
813 { 0x0000, 0x0000 }, /* R809 */
814 { 0x0000, 0x0000 }, /* R810 */
815 { 0x0000, 0x0000 }, /* R811 */
816 { 0x0000, 0x0000 }, /* R812 */
817 { 0x0000, 0x0000 }, /* R813 */
818 { 0x0000, 0x0000 }, /* R814 */
819 { 0x0000, 0x0000 }, /* R815 */
820 { 0x0000, 0x0000 }, /* R816 */
821 { 0x0000, 0x0000 }, /* R817 */
822 { 0x0000, 0x0000 }, /* R818 */
823 { 0x0000, 0x0000 }, /* R819 */
824 { 0x0000, 0x0000 }, /* R820 */
825 { 0x0000, 0x0000 }, /* R821 */
826 { 0x0000, 0x0000 }, /* R822 */
827 { 0x0000, 0x0000 }, /* R823 */
828 { 0x0000, 0x0000 }, /* R824 */
829 { 0x0000, 0x0000 }, /* R825 */
830 { 0x0000, 0x0000 }, /* R826 */
831 { 0x0000, 0x0000 }, /* R827 */
832 { 0x0000, 0x0000 }, /* R828 */
833 { 0x0000, 0x0000 }, /* R829 */
834 { 0x0000, 0x0000 }, /* R830 */
835 { 0x0000, 0x0000 }, /* R831 */
836 { 0x0000, 0x0000 }, /* R832 */
837 { 0x0000, 0x0000 }, /* R833 */
838 { 0x0000, 0x0000 }, /* R834 */
839 { 0x0000, 0x0000 }, /* R835 */
840 { 0x0000, 0x0000 }, /* R836 */
841 { 0x0000, 0x0000 }, /* R837 */
842 { 0x0000, 0x0000 }, /* R838 */
843 { 0x0000, 0x0000 }, /* R839 */
844 { 0x0000, 0x0000 }, /* R840 */
845 { 0x0000, 0x0000 }, /* R841 */
846 { 0x0000, 0x0000 }, /* R842 */
847 { 0x0000, 0x0000 }, /* R843 */
848 { 0x0000, 0x0000 }, /* R844 */
849 { 0x0000, 0x0000 }, /* R845 */
850 { 0x0000, 0x0000 }, /* R846 */
851 { 0x0000, 0x0000 }, /* R847 */
852 { 0x0000, 0x0000 }, /* R848 */
853 { 0x0000, 0x0000 }, /* R849 */
854 { 0x0000, 0x0000 }, /* R850 */
855 { 0x0000, 0x0000 }, /* R851 */
856 { 0x0000, 0x0000 }, /* R852 */
857 { 0x0000, 0x0000 }, /* R853 */
858 { 0x0000, 0x0000 }, /* R854 */
859 { 0x0000, 0x0000 }, /* R855 */
860 { 0x0000, 0x0000 }, /* R856 */
861 { 0x0000, 0x0000 }, /* R857 */
862 { 0x0000, 0x0000 }, /* R858 */
863 { 0x0000, 0x0000 }, /* R859 */
864 { 0x0000, 0x0000 }, /* R860 */
865 { 0x0000, 0x0000 }, /* R861 */
866 { 0x0000, 0x0000 }, /* R862 */
867 { 0x0000, 0x0000 }, /* R863 */
868 { 0x0000, 0x0000 }, /* R864 */
869 { 0x0000, 0x0000 }, /* R865 */
870 { 0x0000, 0x0000 }, /* R866 */
871 { 0x0000, 0x0000 }, /* R867 */
872 { 0x0000, 0x0000 }, /* R868 */
873 { 0x0000, 0x0000 }, /* R869 */
874 { 0x0000, 0x0000 }, /* R870 */
875 { 0x0000, 0x0000 }, /* R871 */
876 { 0x0000, 0x0000 }, /* R872 */
877 { 0x0000, 0x0000 }, /* R873 */
878 { 0x0000, 0x0000 }, /* R874 */
879 { 0x0000, 0x0000 }, /* R875 */
880 { 0x0000, 0x0000 }, /* R876 */
881 { 0x0000, 0x0000 }, /* R877 */
882 { 0x0000, 0x0000 }, /* R878 */
883 { 0x0000, 0x0000 }, /* R879 */
884 { 0x0000, 0x0000 }, /* R880 */
885 { 0x0000, 0x0000 }, /* R881 */
886 { 0x0000, 0x0000 }, /* R882 */
887 { 0x0000, 0x0000 }, /* R883 */
888 { 0x0000, 0x0000 }, /* R884 */
889 { 0x0000, 0x0000 }, /* R885 */
890 { 0x0000, 0x0000 }, /* R886 */
891 { 0x0000, 0x0000 }, /* R887 */
892 { 0x0000, 0x0000 }, /* R888 */
893 { 0x0000, 0x0000 }, /* R889 */
894 { 0x0000, 0x0000 }, /* R890 */
895 { 0x0000, 0x0000 }, /* R891 */
896 { 0x0000, 0x0000 }, /* R892 */
897 { 0x0000, 0x0000 }, /* R893 */
898 { 0x0000, 0x0000 }, /* R894 */
899 { 0x0000, 0x0000 }, /* R895 */
900 { 0x0000, 0x0000 }, /* R896 */
901 { 0x0000, 0x0000 }, /* R897 */
902 { 0x0000, 0x0000 }, /* R898 */
903 { 0x0000, 0x0000 }, /* R899 */
904 { 0x0000, 0x0000 }, /* R900 */
905 { 0x0000, 0x0000 }, /* R901 */
906 { 0x0000, 0x0000 }, /* R902 */
907 { 0x0000, 0x0000 }, /* R903 */
908 { 0x0000, 0x0000 }, /* R904 */
909 { 0x0000, 0x0000 }, /* R905 */
910 { 0x0000, 0x0000 }, /* R906 */
911 { 0x0000, 0x0000 }, /* R907 */
912 { 0x0000, 0x0000 }, /* R908 */
913 { 0x0000, 0x0000 }, /* R909 */
914 { 0x0000, 0x0000 }, /* R910 */
915 { 0x0000, 0x0000 }, /* R911 */
916 { 0x0000, 0x0000 }, /* R912 */
917 { 0x0000, 0x0000 }, /* R913 */
918 { 0x0000, 0x0000 }, /* R914 */
919 { 0x0000, 0x0000 }, /* R915 */
920 { 0x0000, 0x0000 }, /* R916 */
921 { 0x0000, 0x0000 }, /* R917 */
922 { 0x0000, 0x0000 }, /* R918 */
923 { 0x0000, 0x0000 }, /* R919 */
924 { 0x0000, 0x0000 }, /* R920 */
925 { 0x0000, 0x0000 }, /* R921 */
926 { 0x0000, 0x0000 }, /* R922 */
927 { 0x0000, 0x0000 }, /* R923 */
928 { 0x0000, 0x0000 }, /* R924 */
929 { 0x0000, 0x0000 }, /* R925 */
930 { 0x0000, 0x0000 }, /* R926 */
931 { 0x0000, 0x0000 }, /* R927 */
932 { 0x0000, 0x0000 }, /* R928 */
933 { 0x0000, 0x0000 }, /* R929 */
934 { 0x0000, 0x0000 }, /* R930 */
935 { 0x0000, 0x0000 }, /* R931 */
936 { 0x0000, 0x0000 }, /* R932 */
937 { 0x0000, 0x0000 }, /* R933 */
938 { 0x0000, 0x0000 }, /* R934 */
939 { 0x0000, 0x0000 }, /* R935 */
940 { 0x0000, 0x0000 }, /* R936 */
941 { 0x0000, 0x0000 }, /* R937 */
942 { 0x0000, 0x0000 }, /* R938 */
943 { 0x0000, 0x0000 }, /* R939 */
944 { 0x0000, 0x0000 }, /* R940 */
945 { 0x0000, 0x0000 }, /* R941 */
946 { 0x0000, 0x0000 }, /* R942 */
947 { 0x0000, 0x0000 }, /* R943 */
948 { 0x0000, 0x0000 }, /* R944 */
949 { 0x0000, 0x0000 }, /* R945 */
950 { 0x0000, 0x0000 }, /* R946 */
951 { 0x0000, 0x0000 }, /* R947 */
952 { 0x0000, 0x0000 }, /* R948 */
953 { 0x0000, 0x0000 }, /* R949 */
954 { 0x0000, 0x0000 }, /* R950 */
955 { 0x0000, 0x0000 }, /* R951 */
956 { 0x0000, 0x0000 }, /* R952 */
957 { 0x0000, 0x0000 }, /* R953 */
958 { 0x0000, 0x0000 }, /* R954 */
959 { 0x0000, 0x0000 }, /* R955 */
960 { 0x0000, 0x0000 }, /* R956 */
961 { 0x0000, 0x0000 }, /* R957 */
962 { 0x0000, 0x0000 }, /* R958 */
963 { 0x0000, 0x0000 }, /* R959 */
964 { 0x0000, 0x0000 }, /* R960 */
965 { 0x0000, 0x0000 }, /* R961 */
966 { 0x0000, 0x0000 }, /* R962 */
967 { 0x0000, 0x0000 }, /* R963 */
968 { 0x0000, 0x0000 }, /* R964 */
969 { 0x0000, 0x0000 }, /* R965 */
970 { 0x0000, 0x0000 }, /* R966 */
971 { 0x0000, 0x0000 }, /* R967 */
972 { 0x0000, 0x0000 }, /* R968 */
973 { 0x0000, 0x0000 }, /* R969 */
974 { 0x0000, 0x0000 }, /* R970 */
975 { 0x0000, 0x0000 }, /* R971 */
976 { 0x0000, 0x0000 }, /* R972 */
977 { 0x0000, 0x0000 }, /* R973 */
978 { 0x0000, 0x0000 }, /* R974 */
979 { 0x0000, 0x0000 }, /* R975 */
980 { 0x0000, 0x0000 }, /* R976 */
981 { 0x0000, 0x0000 }, /* R977 */
982 { 0x0000, 0x0000 }, /* R978 */
983 { 0x0000, 0x0000 }, /* R979 */
984 { 0x0000, 0x0000 }, /* R980 */
985 { 0x0000, 0x0000 }, /* R981 */
986 { 0x0000, 0x0000 }, /* R982 */
987 { 0x0000, 0x0000 }, /* R983 */
988 { 0x0000, 0x0000 }, /* R984 */
989 { 0x0000, 0x0000 }, /* R985 */
990 { 0x0000, 0x0000 }, /* R986 */
991 { 0x0000, 0x0000 }, /* R987 */
992 { 0x0000, 0x0000 }, /* R988 */
993 { 0x0000, 0x0000 }, /* R989 */
994 { 0x0000, 0x0000 }, /* R990 */
995 { 0x0000, 0x0000 }, /* R991 */
996 { 0x0000, 0x0000 }, /* R992 */
997 { 0x0000, 0x0000 }, /* R993 */
998 { 0x0000, 0x0000 }, /* R994 */
999 { 0x0000, 0x0000 }, /* R995 */
1000 { 0x0000, 0x0000 }, /* R996 */
1001 { 0x0000, 0x0000 }, /* R997 */
1002 { 0x0000, 0x0000 }, /* R998 */
1003 { 0x0000, 0x0000 }, /* R999 */
1004 { 0x0000, 0x0000 }, /* R1000 */
1005 { 0x0000, 0x0000 }, /* R1001 */
1006 { 0x0000, 0x0000 }, /* R1002 */
1007 { 0x0000, 0x0000 }, /* R1003 */
1008 { 0x0000, 0x0000 }, /* R1004 */
1009 { 0x0000, 0x0000 }, /* R1005 */
1010 { 0x0000, 0x0000 }, /* R1006 */
1011 { 0x0000, 0x0000 }, /* R1007 */
1012 { 0x0000, 0x0000 }, /* R1008 */
1013 { 0x0000, 0x0000 }, /* R1009 */
1014 { 0x0000, 0x0000 }, /* R1010 */
1015 { 0x0000, 0x0000 }, /* R1011 */
1016 { 0x0000, 0x0000 }, /* R1012 */
1017 { 0x0000, 0x0000 }, /* R1013 */
1018 { 0x0000, 0x0000 }, /* R1014 */
1019 { 0x0000, 0x0000 }, /* R1015 */
1020 { 0x0000, 0x0000 }, /* R1016 */
1021 { 0x0000, 0x0000 }, /* R1017 */
1022 { 0x0000, 0x0000 }, /* R1018 */
1023 { 0x0000, 0x0000 }, /* R1019 */
1024 { 0x0000, 0x0000 }, /* R1020 */
1025 { 0x0000, 0x0000 }, /* R1021 */
1026 { 0x0000, 0x0000 }, /* R1022 */
1027 { 0x0000, 0x0000 }, /* R1023 */
1028 { 0x00FF, 0x01FF }, /* R1024 - AIF1 ADC1 Left Volume */
1029 { 0x00FF, 0x01FF }, /* R1025 - AIF1 ADC1 Right Volume */
1030 { 0x00FF, 0x01FF }, /* R1026 - AIF1 DAC1 Left Volume */
1031 { 0x00FF, 0x01FF }, /* R1027 - AIF1 DAC1 Right Volume */
1032 { 0x00FF, 0x01FF }, /* R1028 - AIF1 ADC2 Left Volume */
1033 { 0x00FF, 0x01FF }, /* R1029 - AIF1 ADC2 Right Volume */
1034 { 0x00FF, 0x01FF }, /* R1030 - AIF1 DAC2 Left Volume */
1035 { 0x00FF, 0x01FF }, /* R1031 - AIF1 DAC2 Right Volume */
1036 { 0x0000, 0x0000 }, /* R1032 */
1037 { 0x0000, 0x0000 }, /* R1033 */
1038 { 0x0000, 0x0000 }, /* R1034 */
1039 { 0x0000, 0x0000 }, /* R1035 */
1040 { 0x0000, 0x0000 }, /* R1036 */
1041 { 0x0000, 0x0000 }, /* R1037 */
1042 { 0x0000, 0x0000 }, /* R1038 */
1043 { 0x0000, 0x0000 }, /* R1039 */
1044 { 0xF800, 0xF800 }, /* R1040 - AIF1 ADC1 Filters */
1045 { 0x7800, 0x7800 }, /* R1041 - AIF1 ADC2 Filters */
1046 { 0x0000, 0x0000 }, /* R1042 */
1047 { 0x0000, 0x0000 }, /* R1043 */
1048 { 0x0000, 0x0000 }, /* R1044 */
1049 { 0x0000, 0x0000 }, /* R1045 */
1050 { 0x0000, 0x0000 }, /* R1046 */
1051 { 0x0000, 0x0000 }, /* R1047 */
1052 { 0x0000, 0x0000 }, /* R1048 */
1053 { 0x0000, 0x0000 }, /* R1049 */
1054 { 0x0000, 0x0000 }, /* R1050 */
1055 { 0x0000, 0x0000 }, /* R1051 */
1056 { 0x0000, 0x0000 }, /* R1052 */
1057 { 0x0000, 0x0000 }, /* R1053 */
1058 { 0x0000, 0x0000 }, /* R1054 */
1059 { 0x0000, 0x0000 }, /* R1055 */
1060 { 0x02B6, 0x02B6 }, /* R1056 - AIF1 DAC1 Filters (1) */
1061 { 0x3F00, 0x3F00 }, /* R1057 - AIF1 DAC1 Filters (2) */
1062 { 0x02B6, 0x02B6 }, /* R1058 - AIF1 DAC2 Filters (1) */
1063 { 0x3F00, 0x3F00 }, /* R1059 - AIF1 DAC2 Filters (2) */
1064 { 0x0000, 0x0000 }, /* R1060 */
1065 { 0x0000, 0x0000 }, /* R1061 */
1066 { 0x0000, 0x0000 }, /* R1062 */
1067 { 0x0000, 0x0000 }, /* R1063 */
1068 { 0x0000, 0x0000 }, /* R1064 */
1069 { 0x0000, 0x0000 }, /* R1065 */
1070 { 0x0000, 0x0000 }, /* R1066 */
1071 { 0x0000, 0x0000 }, /* R1067 */
1072 { 0x0000, 0x0000 }, /* R1068 */
1073 { 0x0000, 0x0000 }, /* R1069 */
1074 { 0x0000, 0x0000 }, /* R1070 */
1075 { 0x0000, 0x0000 }, /* R1071 */
1076 { 0x0000, 0x0000 }, /* R1072 */
1077 { 0x0000, 0x0000 }, /* R1073 */
1078 { 0x0000, 0x0000 }, /* R1074 */
1079 { 0x0000, 0x0000 }, /* R1075 */
1080 { 0x0000, 0x0000 }, /* R1076 */
1081 { 0x0000, 0x0000 }, /* R1077 */
1082 { 0x0000, 0x0000 }, /* R1078 */
1083 { 0x0000, 0x0000 }, /* R1079 */
1084 { 0x0000, 0x0000 }, /* R1080 */
1085 { 0x0000, 0x0000 }, /* R1081 */
1086 { 0x0000, 0x0000 }, /* R1082 */
1087 { 0x0000, 0x0000 }, /* R1083 */
1088 { 0x0000, 0x0000 }, /* R1084 */
1089 { 0x0000, 0x0000 }, /* R1085 */
1090 { 0x0000, 0x0000 }, /* R1086 */
1091 { 0x0000, 0x0000 }, /* R1087 */
1092 { 0xFFFF, 0xFFFF }, /* R1088 - AIF1 DRC1 (1) */
1093 { 0x1FFF, 0x1FFF }, /* R1089 - AIF1 DRC1 (2) */
1094 { 0xFFFF, 0xFFFF }, /* R1090 - AIF1 DRC1 (3) */
1095 { 0x07FF, 0x07FF }, /* R1091 - AIF1 DRC1 (4) */
1096 { 0x03FF, 0x03FF }, /* R1092 - AIF1 DRC1 (5) */
1097 { 0x0000, 0x0000 }, /* R1093 */
1098 { 0x0000, 0x0000 }, /* R1094 */
1099 { 0x0000, 0x0000 }, /* R1095 */
1100 { 0x0000, 0x0000 }, /* R1096 */
1101 { 0x0000, 0x0000 }, /* R1097 */
1102 { 0x0000, 0x0000 }, /* R1098 */
1103 { 0x0000, 0x0000 }, /* R1099 */
1104 { 0x0000, 0x0000 }, /* R1100 */
1105 { 0x0000, 0x0000 }, /* R1101 */
1106 { 0x0000, 0x0000 }, /* R1102 */
1107 { 0x0000, 0x0000 }, /* R1103 */
1108 { 0xFFFF, 0xFFFF }, /* R1104 - AIF1 DRC2 (1) */
1109 { 0x1FFF, 0x1FFF }, /* R1105 - AIF1 DRC2 (2) */
1110 { 0xFFFF, 0xFFFF }, /* R1106 - AIF1 DRC2 (3) */
1111 { 0x07FF, 0x07FF }, /* R1107 - AIF1 DRC2 (4) */
1112 { 0x03FF, 0x03FF }, /* R1108 - AIF1 DRC2 (5) */
1113 { 0x0000, 0x0000 }, /* R1109 */
1114 { 0x0000, 0x0000 }, /* R1110 */
1115 { 0x0000, 0x0000 }, /* R1111 */
1116 { 0x0000, 0x0000 }, /* R1112 */
1117 { 0x0000, 0x0000 }, /* R1113 */
1118 { 0x0000, 0x0000 }, /* R1114 */
1119 { 0x0000, 0x0000 }, /* R1115 */
1120 { 0x0000, 0x0000 }, /* R1116 */
1121 { 0x0000, 0x0000 }, /* R1117 */
1122 { 0x0000, 0x0000 }, /* R1118 */
1123 { 0x0000, 0x0000 }, /* R1119 */
1124 { 0x0000, 0x0000 }, /* R1120 */
1125 { 0x0000, 0x0000 }, /* R1121 */
1126 { 0x0000, 0x0000 }, /* R1122 */
1127 { 0x0000, 0x0000 }, /* R1123 */
1128 { 0x0000, 0x0000 }, /* R1124 */
1129 { 0x0000, 0x0000 }, /* R1125 */
1130 { 0x0000, 0x0000 }, /* R1126 */
1131 { 0x0000, 0x0000 }, /* R1127 */
1132 { 0x0000, 0x0000 }, /* R1128 */
1133 { 0x0000, 0x0000 }, /* R1129 */
1134 { 0x0000, 0x0000 }, /* R1130 */
1135 { 0x0000, 0x0000 }, /* R1131 */
1136 { 0x0000, 0x0000 }, /* R1132 */
1137 { 0x0000, 0x0000 }, /* R1133 */
1138 { 0x0000, 0x0000 }, /* R1134 */
1139 { 0x0000, 0x0000 }, /* R1135 */
1140 { 0x0000, 0x0000 }, /* R1136 */
1141 { 0x0000, 0x0000 }, /* R1137 */
1142 { 0x0000, 0x0000 }, /* R1138 */
1143 { 0x0000, 0x0000 }, /* R1139 */
1144 { 0x0000, 0x0000 }, /* R1140 */
1145 { 0x0000, 0x0000 }, /* R1141 */
1146 { 0x0000, 0x0000 }, /* R1142 */
1147 { 0x0000, 0x0000 }, /* R1143 */
1148 { 0x0000, 0x0000 }, /* R1144 */
1149 { 0x0000, 0x0000 }, /* R1145 */
1150 { 0x0000, 0x0000 }, /* R1146 */
1151 { 0x0000, 0x0000 }, /* R1147 */
1152 { 0x0000, 0x0000 }, /* R1148 */
1153 { 0x0000, 0x0000 }, /* R1149 */
1154 { 0x0000, 0x0000 }, /* R1150 */
1155 { 0x0000, 0x0000 }, /* R1151 */
1156 { 0xFFFF, 0xFFFF }, /* R1152 - AIF1 DAC1 EQ Gains (1) */
1157 { 0xFFC0, 0xFFC0 }, /* R1153 - AIF1 DAC1 EQ Gains (2) */
1158 { 0xFFFF, 0xFFFF }, /* R1154 - AIF1 DAC1 EQ Band 1 A */
1159 { 0xFFFF, 0xFFFF }, /* R1155 - AIF1 DAC1 EQ Band 1 B */
1160 { 0xFFFF, 0xFFFF }, /* R1156 - AIF1 DAC1 EQ Band 1 PG */
1161 { 0xFFFF, 0xFFFF }, /* R1157 - AIF1 DAC1 EQ Band 2 A */
1162 { 0xFFFF, 0xFFFF }, /* R1158 - AIF1 DAC1 EQ Band 2 B */
1163 { 0xFFFF, 0xFFFF }, /* R1159 - AIF1 DAC1 EQ Band 2 C */
1164 { 0xFFFF, 0xFFFF }, /* R1160 - AIF1 DAC1 EQ Band 2 PG */
1165 { 0xFFFF, 0xFFFF }, /* R1161 - AIF1 DAC1 EQ Band 3 A */
1166 { 0xFFFF, 0xFFFF }, /* R1162 - AIF1 DAC1 EQ Band 3 B */
1167 { 0xFFFF, 0xFFFF }, /* R1163 - AIF1 DAC1 EQ Band 3 C */
1168 { 0xFFFF, 0xFFFF }, /* R1164 - AIF1 DAC1 EQ Band 3 PG */
1169 { 0xFFFF, 0xFFFF }, /* R1165 - AIF1 DAC1 EQ Band 4 A */
1170 { 0xFFFF, 0xFFFF }, /* R1166 - AIF1 DAC1 EQ Band 4 B */
1171 { 0xFFFF, 0xFFFF }, /* R1167 - AIF1 DAC1 EQ Band 4 C */
1172 { 0xFFFF, 0xFFFF }, /* R1168 - AIF1 DAC1 EQ Band 4 PG */
1173 { 0xFFFF, 0xFFFF }, /* R1169 - AIF1 DAC1 EQ Band 5 A */
1174 { 0xFFFF, 0xFFFF }, /* R1170 - AIF1 DAC1 EQ Band 5 B */
1175 { 0xFFFF, 0xFFFF }, /* R1171 - AIF1 DAC1 EQ Band 5 PG */
1176 { 0x0000, 0x0000 }, /* R1172 */
1177 { 0x0000, 0x0000 }, /* R1173 */
1178 { 0x0000, 0x0000 }, /* R1174 */
1179 { 0x0000, 0x0000 }, /* R1175 */
1180 { 0x0000, 0x0000 }, /* R1176 */
1181 { 0x0000, 0x0000 }, /* R1177 */
1182 { 0x0000, 0x0000 }, /* R1178 */
1183 { 0x0000, 0x0000 }, /* R1179 */
1184 { 0x0000, 0x0000 }, /* R1180 */
1185 { 0x0000, 0x0000 }, /* R1181 */
1186 { 0x0000, 0x0000 }, /* R1182 */
1187 { 0x0000, 0x0000 }, /* R1183 */
1188 { 0xFFFF, 0xFFFF }, /* R1184 - AIF1 DAC2 EQ Gains (1) */
1189 { 0xFFC0, 0xFFC0 }, /* R1185 - AIF1 DAC2 EQ Gains (2) */
1190 { 0xFFFF, 0xFFFF }, /* R1186 - AIF1 DAC2 EQ Band 1 A */
1191 { 0xFFFF, 0xFFFF }, /* R1187 - AIF1 DAC2 EQ Band 1 B */
1192 { 0xFFFF, 0xFFFF }, /* R1188 - AIF1 DAC2 EQ Band 1 PG */
1193 { 0xFFFF, 0xFFFF }, /* R1189 - AIF1 DAC2 EQ Band 2 A */
1194 { 0xFFFF, 0xFFFF }, /* R1190 - AIF1 DAC2 EQ Band 2 B */
1195 { 0xFFFF, 0xFFFF }, /* R1191 - AIF1 DAC2 EQ Band 2 C */
1196 { 0xFFFF, 0xFFFF }, /* R1192 - AIF1 DAC2 EQ Band 2 PG */
1197 { 0xFFFF, 0xFFFF }, /* R1193 - AIF1 DAC2 EQ Band 3 A */
1198 { 0xFFFF, 0xFFFF }, /* R1194 - AIF1 DAC2 EQ Band 3 B */
1199 { 0xFFFF, 0xFFFF }, /* R1195 - AIF1 DAC2 EQ Band 3 C */
1200 { 0xFFFF, 0xFFFF }, /* R1196 - AIF1 DAC2 EQ Band 3 PG */
1201 { 0xFFFF, 0xFFFF }, /* R1197 - AIF1 DAC2 EQ Band 4 A */
1202 { 0xFFFF, 0xFFFF }, /* R1198 - AIF1 DAC2 EQ Band 4 B */
1203 { 0xFFFF, 0xFFFF }, /* R1199 - AIF1 DAC2 EQ Band 4 C */
1204 { 0xFFFF, 0xFFFF }, /* R1200 - AIF1 DAC2 EQ Band 4 PG */
1205 { 0xFFFF, 0xFFFF }, /* R1201 - AIF1 DAC2 EQ Band 5 A */
1206 { 0xFFFF, 0xFFFF }, /* R1202 - AIF1 DAC2 EQ Band 5 B */
1207 { 0xFFFF, 0xFFFF }, /* R1203 - AIF1 DAC2 EQ Band 5 PG */
1208 { 0x0000, 0x0000 }, /* R1204 */
1209 { 0x0000, 0x0000 }, /* R1205 */
1210 { 0x0000, 0x0000 }, /* R1206 */
1211 { 0x0000, 0x0000 }, /* R1207 */
1212 { 0x0000, 0x0000 }, /* R1208 */
1213 { 0x0000, 0x0000 }, /* R1209 */
1214 { 0x0000, 0x0000 }, /* R1210 */
1215 { 0x0000, 0x0000 }, /* R1211 */
1216 { 0x0000, 0x0000 }, /* R1212 */
1217 { 0x0000, 0x0000 }, /* R1213 */
1218 { 0x0000, 0x0000 }, /* R1214 */
1219 { 0x0000, 0x0000 }, /* R1215 */
1220 { 0x0000, 0x0000 }, /* R1216 */
1221 { 0x0000, 0x0000 }, /* R1217 */
1222 { 0x0000, 0x0000 }, /* R1218 */
1223 { 0x0000, 0x0000 }, /* R1219 */
1224 { 0x0000, 0x0000 }, /* R1220 */
1225 { 0x0000, 0x0000 }, /* R1221 */
1226 { 0x0000, 0x0000 }, /* R1222 */
1227 { 0x0000, 0x0000 }, /* R1223 */
1228 { 0x0000, 0x0000 }, /* R1224 */
1229 { 0x0000, 0x0000 }, /* R1225 */
1230 { 0x0000, 0x0000 }, /* R1226 */
1231 { 0x0000, 0x0000 }, /* R1227 */
1232 { 0x0000, 0x0000 }, /* R1228 */
1233 { 0x0000, 0x0000 }, /* R1229 */
1234 { 0x0000, 0x0000 }, /* R1230 */
1235 { 0x0000, 0x0000 }, /* R1231 */
1236 { 0x0000, 0x0000 }, /* R1232 */
1237 { 0x0000, 0x0000 }, /* R1233 */
1238 { 0x0000, 0x0000 }, /* R1234 */
1239 { 0x0000, 0x0000 }, /* R1235 */
1240 { 0x0000, 0x0000 }, /* R1236 */
1241 { 0x0000, 0x0000 }, /* R1237 */
1242 { 0x0000, 0x0000 }, /* R1238 */
1243 { 0x0000, 0x0000 }, /* R1239 */
1244 { 0x0000, 0x0000 }, /* R1240 */
1245 { 0x0000, 0x0000 }, /* R1241 */
1246 { 0x0000, 0x0000 }, /* R1242 */
1247 { 0x0000, 0x0000 }, /* R1243 */
1248 { 0x0000, 0x0000 }, /* R1244 */
1249 { 0x0000, 0x0000 }, /* R1245 */
1250 { 0x0000, 0x0000 }, /* R1246 */
1251 { 0x0000, 0x0000 }, /* R1247 */
1252 { 0x0000, 0x0000 }, /* R1248 */
1253 { 0x0000, 0x0000 }, /* R1249 */
1254 { 0x0000, 0x0000 }, /* R1250 */
1255 { 0x0000, 0x0000 }, /* R1251 */
1256 { 0x0000, 0x0000 }, /* R1252 */
1257 { 0x0000, 0x0000 }, /* R1253 */
1258 { 0x0000, 0x0000 }, /* R1254 */
1259 { 0x0000, 0x0000 }, /* R1255 */
1260 { 0x0000, 0x0000 }, /* R1256 */
1261 { 0x0000, 0x0000 }, /* R1257 */
1262 { 0x0000, 0x0000 }, /* R1258 */
1263 { 0x0000, 0x0000 }, /* R1259 */
1264 { 0x0000, 0x0000 }, /* R1260 */
1265 { 0x0000, 0x0000 }, /* R1261 */
1266 { 0x0000, 0x0000 }, /* R1262 */
1267 { 0x0000, 0x0000 }, /* R1263 */
1268 { 0x0000, 0x0000 }, /* R1264 */
1269 { 0x0000, 0x0000 }, /* R1265 */
1270 { 0x0000, 0x0000 }, /* R1266 */
1271 { 0x0000, 0x0000 }, /* R1267 */
1272 { 0x0000, 0x0000 }, /* R1268 */
1273 { 0x0000, 0x0000 }, /* R1269 */
1274 { 0x0000, 0x0000 }, /* R1270 */
1275 { 0x0000, 0x0000 }, /* R1271 */
1276 { 0x0000, 0x0000 }, /* R1272 */
1277 { 0x0000, 0x0000 }, /* R1273 */
1278 { 0x0000, 0x0000 }, /* R1274 */
1279 { 0x0000, 0x0000 }, /* R1275 */
1280 { 0x0000, 0x0000 }, /* R1276 */
1281 { 0x0000, 0x0000 }, /* R1277 */
1282 { 0x0000, 0x0000 }, /* R1278 */
1283 { 0x0000, 0x0000 }, /* R1279 */
1284 { 0x00FF, 0x01FF }, /* R1280 - AIF2 ADC Left Volume */
1285 { 0x00FF, 0x01FF }, /* R1281 - AIF2 ADC Right Volume */
1286 { 0x00FF, 0x01FF }, /* R1282 - AIF2 DAC Left Volume */
1287 { 0x00FF, 0x01FF }, /* R1283 - AIF2 DAC Right Volume */
1288 { 0x0000, 0x0000 }, /* R1284 */
1289 { 0x0000, 0x0000 }, /* R1285 */
1290 { 0x0000, 0x0000 }, /* R1286 */
1291 { 0x0000, 0x0000 }, /* R1287 */
1292 { 0x0000, 0x0000 }, /* R1288 */
1293 { 0x0000, 0x0000 }, /* R1289 */
1294 { 0x0000, 0x0000 }, /* R1290 */
1295 { 0x0000, 0x0000 }, /* R1291 */
1296 { 0x0000, 0x0000 }, /* R1292 */
1297 { 0x0000, 0x0000 }, /* R1293 */
1298 { 0x0000, 0x0000 }, /* R1294 */
1299 { 0x0000, 0x0000 }, /* R1295 */
1300 { 0xF800, 0xF800 }, /* R1296 - AIF2 ADC Filters */
1301 { 0x0000, 0x0000 }, /* R1297 */
1302 { 0x0000, 0x0000 }, /* R1298 */
1303 { 0x0000, 0x0000 }, /* R1299 */
1304 { 0x0000, 0x0000 }, /* R1300 */
1305 { 0x0000, 0x0000 }, /* R1301 */
1306 { 0x0000, 0x0000 }, /* R1302 */
1307 { 0x0000, 0x0000 }, /* R1303 */
1308 { 0x0000, 0x0000 }, /* R1304 */
1309 { 0x0000, 0x0000 }, /* R1305 */
1310 { 0x0000, 0x0000 }, /* R1306 */
1311 { 0x0000, 0x0000 }, /* R1307 */
1312 { 0x0000, 0x0000 }, /* R1308 */
1313 { 0x0000, 0x0000 }, /* R1309 */
1314 { 0x0000, 0x0000 }, /* R1310 */
1315 { 0x0000, 0x0000 }, /* R1311 */
1316 { 0x02B6, 0x02B6 }, /* R1312 - AIF2 DAC Filters (1) */
1317 { 0x3F00, 0x3F00 }, /* R1313 - AIF2 DAC Filters (2) */
1318 { 0x0000, 0x0000 }, /* R1314 */
1319 { 0x0000, 0x0000 }, /* R1315 */
1320 { 0x0000, 0x0000 }, /* R1316 */
1321 { 0x0000, 0x0000 }, /* R1317 */
1322 { 0x0000, 0x0000 }, /* R1318 */
1323 { 0x0000, 0x0000 }, /* R1319 */
1324 { 0x0000, 0x0000 }, /* R1320 */
1325 { 0x0000, 0x0000 }, /* R1321 */
1326 { 0x0000, 0x0000 }, /* R1322 */
1327 { 0x0000, 0x0000 }, /* R1323 */
1328 { 0x0000, 0x0000 }, /* R1324 */
1329 { 0x0000, 0x0000 }, /* R1325 */
1330 { 0x0000, 0x0000 }, /* R1326 */
1331 { 0x0000, 0x0000 }, /* R1327 */
1332 { 0x0000, 0x0000 }, /* R1328 */
1333 { 0x0000, 0x0000 }, /* R1329 */
1334 { 0x0000, 0x0000 }, /* R1330 */
1335 { 0x0000, 0x0000 }, /* R1331 */
1336 { 0x0000, 0x0000 }, /* R1332 */
1337 { 0x0000, 0x0000 }, /* R1333 */
1338 { 0x0000, 0x0000 }, /* R1334 */
1339 { 0x0000, 0x0000 }, /* R1335 */
1340 { 0x0000, 0x0000 }, /* R1336 */
1341 { 0x0000, 0x0000 }, /* R1337 */
1342 { 0x0000, 0x0000 }, /* R1338 */
1343 { 0x0000, 0x0000 }, /* R1339 */
1344 { 0x0000, 0x0000 }, /* R1340 */
1345 { 0x0000, 0x0000 }, /* R1341 */
1346 { 0x0000, 0x0000 }, /* R1342 */
1347 { 0x0000, 0x0000 }, /* R1343 */
1348 { 0xFFFF, 0xFFFF }, /* R1344 - AIF2 DRC (1) */
1349 { 0x1FFF, 0x1FFF }, /* R1345 - AIF2 DRC (2) */
1350 { 0xFFFF, 0xFFFF }, /* R1346 - AIF2 DRC (3) */
1351 { 0x07FF, 0x07FF }, /* R1347 - AIF2 DRC (4) */
1352 { 0x03FF, 0x03FF }, /* R1348 - AIF2 DRC (5) */
1353 { 0x0000, 0x0000 }, /* R1349 */
1354 { 0x0000, 0x0000 }, /* R1350 */
1355 { 0x0000, 0x0000 }, /* R1351 */
1356 { 0x0000, 0x0000 }, /* R1352 */
1357 { 0x0000, 0x0000 }, /* R1353 */
1358 { 0x0000, 0x0000 }, /* R1354 */
1359 { 0x0000, 0x0000 }, /* R1355 */
1360 { 0x0000, 0x0000 }, /* R1356 */
1361 { 0x0000, 0x0000 }, /* R1357 */
1362 { 0x0000, 0x0000 }, /* R1358 */
1363 { 0x0000, 0x0000 }, /* R1359 */
1364 { 0x0000, 0x0000 }, /* R1360 */
1365 { 0x0000, 0x0000 }, /* R1361 */
1366 { 0x0000, 0x0000 }, /* R1362 */
1367 { 0x0000, 0x0000 }, /* R1363 */
1368 { 0x0000, 0x0000 }, /* R1364 */
1369 { 0x0000, 0x0000 }, /* R1365 */
1370 { 0x0000, 0x0000 }, /* R1366 */
1371 { 0x0000, 0x0000 }, /* R1367 */
1372 { 0x0000, 0x0000 }, /* R1368 */
1373 { 0x0000, 0x0000 }, /* R1369 */
1374 { 0x0000, 0x0000 }, /* R1370 */
1375 { 0x0000, 0x0000 }, /* R1371 */
1376 { 0x0000, 0x0000 }, /* R1372 */
1377 { 0x0000, 0x0000 }, /* R1373 */
1378 { 0x0000, 0x0000 }, /* R1374 */
1379 { 0x0000, 0x0000 }, /* R1375 */
1380 { 0x0000, 0x0000 }, /* R1376 */
1381 { 0x0000, 0x0000 }, /* R1377 */
1382 { 0x0000, 0x0000 }, /* R1378 */
1383 { 0x0000, 0x0000 }, /* R1379 */
1384 { 0x0000, 0x0000 }, /* R1380 */
1385 { 0x0000, 0x0000 }, /* R1381 */
1386 { 0x0000, 0x0000 }, /* R1382 */
1387 { 0x0000, 0x0000 }, /* R1383 */
1388 { 0x0000, 0x0000 }, /* R1384 */
1389 { 0x0000, 0x0000 }, /* R1385 */
1390 { 0x0000, 0x0000 }, /* R1386 */
1391 { 0x0000, 0x0000 }, /* R1387 */
1392 { 0x0000, 0x0000 }, /* R1388 */
1393 { 0x0000, 0x0000 }, /* R1389 */
1394 { 0x0000, 0x0000 }, /* R1390 */
1395 { 0x0000, 0x0000 }, /* R1391 */
1396 { 0x0000, 0x0000 }, /* R1392 */
1397 { 0x0000, 0x0000 }, /* R1393 */
1398 { 0x0000, 0x0000 }, /* R1394 */
1399 { 0x0000, 0x0000 }, /* R1395 */
1400 { 0x0000, 0x0000 }, /* R1396 */
1401 { 0x0000, 0x0000 }, /* R1397 */
1402 { 0x0000, 0x0000 }, /* R1398 */
1403 { 0x0000, 0x0000 }, /* R1399 */
1404 { 0x0000, 0x0000 }, /* R1400 */
1405 { 0x0000, 0x0000 }, /* R1401 */
1406 { 0x0000, 0x0000 }, /* R1402 */
1407 { 0x0000, 0x0000 }, /* R1403 */
1408 { 0x0000, 0x0000 }, /* R1404 */
1409 { 0x0000, 0x0000 }, /* R1405 */
1410 { 0x0000, 0x0000 }, /* R1406 */
1411 { 0x0000, 0x0000 }, /* R1407 */
1412 { 0xFFFF, 0xFFFF }, /* R1408 - AIF2 EQ Gains (1) */
1413 { 0xFFC0, 0xFFC0 }, /* R1409 - AIF2 EQ Gains (2) */
1414 { 0xFFFF, 0xFFFF }, /* R1410 - AIF2 EQ Band 1 A */
1415 { 0xFFFF, 0xFFFF }, /* R1411 - AIF2 EQ Band 1 B */
1416 { 0xFFFF, 0xFFFF }, /* R1412 - AIF2 EQ Band 1 PG */
1417 { 0xFFFF, 0xFFFF }, /* R1413 - AIF2 EQ Band 2 A */
1418 { 0xFFFF, 0xFFFF }, /* R1414 - AIF2 EQ Band 2 B */
1419 { 0xFFFF, 0xFFFF }, /* R1415 - AIF2 EQ Band 2 C */
1420 { 0xFFFF, 0xFFFF }, /* R1416 - AIF2 EQ Band 2 PG */
1421 { 0xFFFF, 0xFFFF }, /* R1417 - AIF2 EQ Band 3 A */
1422 { 0xFFFF, 0xFFFF }, /* R1418 - AIF2 EQ Band 3 B */
1423 { 0xFFFF, 0xFFFF }, /* R1419 - AIF2 EQ Band 3 C */
1424 { 0xFFFF, 0xFFFF }, /* R1420 - AIF2 EQ Band 3 PG */
1425 { 0xFFFF, 0xFFFF }, /* R1421 - AIF2 EQ Band 4 A */
1426 { 0xFFFF, 0xFFFF }, /* R1422 - AIF2 EQ Band 4 B */
1427 { 0xFFFF, 0xFFFF }, /* R1423 - AIF2 EQ Band 4 C */
1428 { 0xFFFF, 0xFFFF }, /* R1424 - AIF2 EQ Band 4 PG */
1429 { 0xFFFF, 0xFFFF }, /* R1425 - AIF2 EQ Band 5 A */
1430 { 0xFFFF, 0xFFFF }, /* R1426 - AIF2 EQ Band 5 B */
1431 { 0xFFFF, 0xFFFF }, /* R1427 - AIF2 EQ Band 5 PG */
1432 { 0x0000, 0x0000 }, /* R1428 */
1433 { 0x0000, 0x0000 }, /* R1429 */
1434 { 0x0000, 0x0000 }, /* R1430 */
1435 { 0x0000, 0x0000 }, /* R1431 */
1436 { 0x0000, 0x0000 }, /* R1432 */
1437 { 0x0000, 0x0000 }, /* R1433 */
1438 { 0x0000, 0x0000 }, /* R1434 */
1439 { 0x0000, 0x0000 }, /* R1435 */
1440 { 0x0000, 0x0000 }, /* R1436 */
1441 { 0x0000, 0x0000 }, /* R1437 */
1442 { 0x0000, 0x0000 }, /* R1438 */
1443 { 0x0000, 0x0000 }, /* R1439 */
1444 { 0x0000, 0x0000 }, /* R1440 */
1445 { 0x0000, 0x0000 }, /* R1441 */
1446 { 0x0000, 0x0000 }, /* R1442 */
1447 { 0x0000, 0x0000 }, /* R1443 */
1448 { 0x0000, 0x0000 }, /* R1444 */
1449 { 0x0000, 0x0000 }, /* R1445 */
1450 { 0x0000, 0x0000 }, /* R1446 */
1451 { 0x0000, 0x0000 }, /* R1447 */
1452 { 0x0000, 0x0000 }, /* R1448 */
1453 { 0x0000, 0x0000 }, /* R1449 */
1454 { 0x0000, 0x0000 }, /* R1450 */
1455 { 0x0000, 0x0000 }, /* R1451 */
1456 { 0x0000, 0x0000 }, /* R1452 */
1457 { 0x0000, 0x0000 }, /* R1453 */
1458 { 0x0000, 0x0000 }, /* R1454 */
1459 { 0x0000, 0x0000 }, /* R1455 */
1460 { 0x0000, 0x0000 }, /* R1456 */
1461 { 0x0000, 0x0000 }, /* R1457 */
1462 { 0x0000, 0x0000 }, /* R1458 */
1463 { 0x0000, 0x0000 }, /* R1459 */
1464 { 0x0000, 0x0000 }, /* R1460 */
1465 { 0x0000, 0x0000 }, /* R1461 */
1466 { 0x0000, 0x0000 }, /* R1462 */
1467 { 0x0000, 0x0000 }, /* R1463 */
1468 { 0x0000, 0x0000 }, /* R1464 */
1469 { 0x0000, 0x0000 }, /* R1465 */
1470 { 0x0000, 0x0000 }, /* R1466 */
1471 { 0x0000, 0x0000 }, /* R1467 */
1472 { 0x0000, 0x0000 }, /* R1468 */
1473 { 0x0000, 0x0000 }, /* R1469 */
1474 { 0x0000, 0x0000 }, /* R1470 */
1475 { 0x0000, 0x0000 }, /* R1471 */
1476 { 0x0000, 0x0000 }, /* R1472 */
1477 { 0x0000, 0x0000 }, /* R1473 */
1478 { 0x0000, 0x0000 }, /* R1474 */
1479 { 0x0000, 0x0000 }, /* R1475 */
1480 { 0x0000, 0x0000 }, /* R1476 */
1481 { 0x0000, 0x0000 }, /* R1477 */
1482 { 0x0000, 0x0000 }, /* R1478 */
1483 { 0x0000, 0x0000 }, /* R1479 */
1484 { 0x0000, 0x0000 }, /* R1480 */
1485 { 0x0000, 0x0000 }, /* R1481 */
1486 { 0x0000, 0x0000 }, /* R1482 */
1487 { 0x0000, 0x0000 }, /* R1483 */
1488 { 0x0000, 0x0000 }, /* R1484 */
1489 { 0x0000, 0x0000 }, /* R1485 */
1490 { 0x0000, 0x0000 }, /* R1486 */
1491 { 0x0000, 0x0000 }, /* R1487 */
1492 { 0x0000, 0x0000 }, /* R1488 */
1493 { 0x0000, 0x0000 }, /* R1489 */
1494 { 0x0000, 0x0000 }, /* R1490 */
1495 { 0x0000, 0x0000 }, /* R1491 */
1496 { 0x0000, 0x0000 }, /* R1492 */
1497 { 0x0000, 0x0000 }, /* R1493 */
1498 { 0x0000, 0x0000 }, /* R1494 */
1499 { 0x0000, 0x0000 }, /* R1495 */
1500 { 0x0000, 0x0000 }, /* R1496 */
1501 { 0x0000, 0x0000 }, /* R1497 */
1502 { 0x0000, 0x0000 }, /* R1498 */
1503 { 0x0000, 0x0000 }, /* R1499 */
1504 { 0x0000, 0x0000 }, /* R1500 */
1505 { 0x0000, 0x0000 }, /* R1501 */
1506 { 0x0000, 0x0000 }, /* R1502 */
1507 { 0x0000, 0x0000 }, /* R1503 */
1508 { 0x0000, 0x0000 }, /* R1504 */
1509 { 0x0000, 0x0000 }, /* R1505 */
1510 { 0x0000, 0x0000 }, /* R1506 */
1511 { 0x0000, 0x0000 }, /* R1507 */
1512 { 0x0000, 0x0000 }, /* R1508 */
1513 { 0x0000, 0x0000 }, /* R1509 */
1514 { 0x0000, 0x0000 }, /* R1510 */
1515 { 0x0000, 0x0000 }, /* R1511 */
1516 { 0x0000, 0x0000 }, /* R1512 */
1517 { 0x0000, 0x0000 }, /* R1513 */
1518 { 0x0000, 0x0000 }, /* R1514 */
1519 { 0x0000, 0x0000 }, /* R1515 */
1520 { 0x0000, 0x0000 }, /* R1516 */
1521 { 0x0000, 0x0000 }, /* R1517 */
1522 { 0x0000, 0x0000 }, /* R1518 */
1523 { 0x0000, 0x0000 }, /* R1519 */
1524 { 0x0000, 0x0000 }, /* R1520 */
1525 { 0x0000, 0x0000 }, /* R1521 */
1526 { 0x0000, 0x0000 }, /* R1522 */
1527 { 0x0000, 0x0000 }, /* R1523 */
1528 { 0x0000, 0x0000 }, /* R1524 */
1529 { 0x0000, 0x0000 }, /* R1525 */
1530 { 0x0000, 0x0000 }, /* R1526 */
1531 { 0x0000, 0x0000 }, /* R1527 */
1532 { 0x0000, 0x0000 }, /* R1528 */
1533 { 0x0000, 0x0000 }, /* R1529 */
1534 { 0x0000, 0x0000 }, /* R1530 */
1535 { 0x0000, 0x0000 }, /* R1531 */
1536 { 0x0000, 0x0000 }, /* R1532 */
1537 { 0x0000, 0x0000 }, /* R1533 */
1538 { 0x0000, 0x0000 }, /* R1534 */
1539 { 0x0000, 0x0000 }, /* R1535 */
1540 { 0x01EF, 0x01EF }, /* R1536 - DAC1 Mixer Volumes */
1541 { 0x0037, 0x0037 }, /* R1537 - DAC1 Left Mixer Routing */
1542 { 0x0037, 0x0037 }, /* R1538 - DAC1 Right Mixer Routing */
1543 { 0x01EF, 0x01EF }, /* R1539 - DAC2 Mixer Volumes */
1544 { 0x0037, 0x0037 }, /* R1540 - DAC2 Left Mixer Routing */
1545 { 0x0037, 0x0037 }, /* R1541 - DAC2 Right Mixer Routing */
1546 { 0x0003, 0x0003 }, /* R1542 - AIF1 ADC1 Left Mixer Routing */
1547 { 0x0003, 0x0003 }, /* R1543 - AIF1 ADC1 Right Mixer Routing */
1548 { 0x0003, 0x0003 }, /* R1544 - AIF1 ADC2 Left Mixer Routing */
1549 { 0x0003, 0x0003 }, /* R1545 - AIF1 ADC2 Right mixer Routing */
1550 { 0x0000, 0x0000 }, /* R1546 */
1551 { 0x0000, 0x0000 }, /* R1547 */
1552 { 0x0000, 0x0000 }, /* R1548 */
1553 { 0x0000, 0x0000 }, /* R1549 */
1554 { 0x0000, 0x0000 }, /* R1550 */
1555 { 0x0000, 0x0000 }, /* R1551 */
1556 { 0x02FF, 0x03FF }, /* R1552 - DAC1 Left Volume */
1557 { 0x02FF, 0x03FF }, /* R1553 - DAC1 Right Volume */
1558 { 0x02FF, 0x03FF }, /* R1554 - DAC2 Left Volume */
1559 { 0x02FF, 0x03FF }, /* R1555 - DAC2 Right Volume */
1560 { 0x0003, 0x0003 }, /* R1556 - DAC Softmute */
1561 { 0x0000, 0x0000 }, /* R1557 */
1562 { 0x0000, 0x0000 }, /* R1558 */
1563 { 0x0000, 0x0000 }, /* R1559 */
1564 { 0x0000, 0x0000 }, /* R1560 */
1565 { 0x0000, 0x0000 }, /* R1561 */
1566 { 0x0000, 0x0000 }, /* R1562 */
1567 { 0x0000, 0x0000 }, /* R1563 */
1568 { 0x0000, 0x0000 }, /* R1564 */
1569 { 0x0000, 0x0000 }, /* R1565 */
1570 { 0x0000, 0x0000 }, /* R1566 */
1571 { 0x0000, 0x0000 }, /* R1567 */
1572 { 0x0003, 0x0003 }, /* R1568 - Oversampling */
1573 { 0x03C3, 0x03C3 }, /* R1569 - Sidetone */
1574};
1575
1576const __devinitdata u16 wm8994_reg_defaults[WM8994_CACHE_SIZE] = {
1577 0x8994, /* R0 - Software Reset */
1578 0x0000, /* R1 - Power Management (1) */
1579 0x6000, /* R2 - Power Management (2) */
1580 0x0000, /* R3 - Power Management (3) */
1581 0x0000, /* R4 - Power Management (4) */
1582 0x0000, /* R5 - Power Management (5) */
1583 0x0000, /* R6 - Power Management (6) */
1584 0x0000, /* R7 */
1585 0x0000, /* R8 */
1586 0x0000, /* R9 */
1587 0x0000, /* R10 */
1588 0x0000, /* R11 */
1589 0x0000, /* R12 */
1590 0x0000, /* R13 */
1591 0x0000, /* R14 */
1592 0x0000, /* R15 */
1593 0x0000, /* R16 */
1594 0x0000, /* R17 */
1595 0x0000, /* R18 */
1596 0x0000, /* R19 */
1597 0x0000, /* R20 */
1598 0x0000, /* R21 - Input Mixer (1) */
1599 0x0000, /* R22 */
1600 0x0000, /* R23 */
1601 0x008B, /* R24 - Left Line Input 1&2 Volume */
1602 0x008B, /* R25 - Left Line Input 3&4 Volume */
1603 0x008B, /* R26 - Right Line Input 1&2 Volume */
1604 0x008B, /* R27 - Right Line Input 3&4 Volume */
1605 0x006D, /* R28 - Left Output Volume */
1606 0x006D, /* R29 - Right Output Volume */
1607 0x0066, /* R30 - Line Outputs Volume */
1608 0x0020, /* R31 - HPOUT2 Volume */
1609 0x0079, /* R32 - Left OPGA Volume */
1610 0x0079, /* R33 - Right OPGA Volume */
1611 0x0003, /* R34 - SPKMIXL Attenuation */
1612 0x0003, /* R35 - SPKMIXR Attenuation */
1613 0x0011, /* R36 - SPKOUT Mixers */
1614 0x0140, /* R37 - ClassD */
1615 0x0079, /* R38 - Speaker Volume Left */
1616 0x0079, /* R39 - Speaker Volume Right */
1617 0x0000, /* R40 - Input Mixer (2) */
1618 0x0000, /* R41 - Input Mixer (3) */
1619 0x0000, /* R42 - Input Mixer (4) */
1620 0x0000, /* R43 - Input Mixer (5) */
1621 0x0000, /* R44 - Input Mixer (6) */
1622 0x0000, /* R45 - Output Mixer (1) */
1623 0x0000, /* R46 - Output Mixer (2) */
1624 0x0000, /* R47 - Output Mixer (3) */
1625 0x0000, /* R48 - Output Mixer (4) */
1626 0x0000, /* R49 - Output Mixer (5) */
1627 0x0000, /* R50 - Output Mixer (6) */
1628 0x0000, /* R51 - HPOUT2 Mixer */
1629 0x0000, /* R52 - Line Mixer (1) */
1630 0x0000, /* R53 - Line Mixer (2) */
1631 0x0000, /* R54 - Speaker Mixer */
1632 0x0000, /* R55 - Additional Control */
1633 0x0000, /* R56 - AntiPOP (1) */
1634 0x0000, /* R57 - AntiPOP (2) */
1635 0x0000, /* R58 - MICBIAS */
1636 0x000D, /* R59 - LDO 1 */
1637 0x0003, /* R60 - LDO 2 */
1638 0x0000, /* R61 */
1639 0x0000, /* R62 */
1640 0x0000, /* R63 */
1641 0x0000, /* R64 */
1642 0x0000, /* R65 */
1643 0x0000, /* R66 */
1644 0x0000, /* R67 */
1645 0x0000, /* R68 */
1646 0x0000, /* R69 */
1647 0x0000, /* R70 */
1648 0x0000, /* R71 */
1649 0x0000, /* R72 */
1650 0x0000, /* R73 */
1651 0x0000, /* R74 */
1652 0x0000, /* R75 */
1653 0x1F25, /* R76 - Charge Pump (1) */
1654 0x0000, /* R77 */
1655 0x0000, /* R78 */
1656 0x0000, /* R79 */
1657 0x0000, /* R80 */
1658 0x0004, /* R81 - Class W (1) */
1659 0x0000, /* R82 */
1660 0x0000, /* R83 */
1661 0x0000, /* R84 - DC Servo (1) */
1662 0x054A, /* R85 - DC Servo (2) */
1663 0x0000, /* R86 */
1664 0x0000, /* R87 - DC Servo (4) */
1665 0x0000, /* R88 - DC Servo Readback */
1666 0x0000, /* R89 */
1667 0x0000, /* R90 */
1668 0x0000, /* R91 */
1669 0x0000, /* R92 */
1670 0x0000, /* R93 */
1671 0x0000, /* R94 */
1672 0x0000, /* R95 */
1673 0x0000, /* R96 - Analogue HP (1) */
1674 0x0000, /* R97 */
1675 0x0000, /* R98 */
1676 0x0000, /* R99 */
1677 0x0000, /* R100 */
1678 0x0000, /* R101 */
1679 0x0000, /* R102 */
1680 0x0000, /* R103 */
1681 0x0000, /* R104 */
1682 0x0000, /* R105 */
1683 0x0000, /* R106 */
1684 0x0000, /* R107 */
1685 0x0000, /* R108 */
1686 0x0000, /* R109 */
1687 0x0000, /* R110 */
1688 0x0000, /* R111 */
1689 0x0000, /* R112 */
1690 0x0000, /* R113 */
1691 0x0000, /* R114 */
1692 0x0000, /* R115 */
1693 0x0000, /* R116 */
1694 0x0000, /* R117 */
1695 0x0000, /* R118 */
1696 0x0000, /* R119 */
1697 0x0000, /* R120 */
1698 0x0000, /* R121 */
1699 0x0000, /* R122 */
1700 0x0000, /* R123 */
1701 0x0000, /* R124 */
1702 0x0000, /* R125 */
1703 0x0000, /* R126 */
1704 0x0000, /* R127 */
1705 0x0000, /* R128 */
1706 0x0000, /* R129 */
1707 0x0000, /* R130 */
1708 0x0000, /* R131 */
1709 0x0000, /* R132 */
1710 0x0000, /* R133 */
1711 0x0000, /* R134 */
1712 0x0000, /* R135 */
1713 0x0000, /* R136 */
1714 0x0000, /* R137 */
1715 0x0000, /* R138 */
1716 0x0000, /* R139 */
1717 0x0000, /* R140 */
1718 0x0000, /* R141 */
1719 0x0000, /* R142 */
1720 0x0000, /* R143 */
1721 0x0000, /* R144 */
1722 0x0000, /* R145 */
1723 0x0000, /* R146 */
1724 0x0000, /* R147 */
1725 0x0000, /* R148 */
1726 0x0000, /* R149 */
1727 0x0000, /* R150 */
1728 0x0000, /* R151 */
1729 0x0000, /* R152 */
1730 0x0000, /* R153 */
1731 0x0000, /* R154 */
1732 0x0000, /* R155 */
1733 0x0000, /* R156 */
1734 0x0000, /* R157 */
1735 0x0000, /* R158 */
1736 0x0000, /* R159 */
1737 0x0000, /* R160 */
1738 0x0000, /* R161 */
1739 0x0000, /* R162 */
1740 0x0000, /* R163 */
1741 0x0000, /* R164 */
1742 0x0000, /* R165 */
1743 0x0000, /* R166 */
1744 0x0000, /* R167 */
1745 0x0000, /* R168 */
1746 0x0000, /* R169 */
1747 0x0000, /* R170 */
1748 0x0000, /* R171 */
1749 0x0000, /* R172 */
1750 0x0000, /* R173 */
1751 0x0000, /* R174 */
1752 0x0000, /* R175 */
1753 0x0000, /* R176 */
1754 0x0000, /* R177 */
1755 0x0000, /* R178 */
1756 0x0000, /* R179 */
1757 0x0000, /* R180 */
1758 0x0000, /* R181 */
1759 0x0000, /* R182 */
1760 0x0000, /* R183 */
1761 0x0000, /* R184 */
1762 0x0000, /* R185 */
1763 0x0000, /* R186 */
1764 0x0000, /* R187 */
1765 0x0000, /* R188 */
1766 0x0000, /* R189 */
1767 0x0000, /* R190 */
1768 0x0000, /* R191 */
1769 0x0000, /* R192 */
1770 0x0000, /* R193 */
1771 0x0000, /* R194 */
1772 0x0000, /* R195 */
1773 0x0000, /* R196 */
1774 0x0000, /* R197 */
1775 0x0000, /* R198 */
1776 0x0000, /* R199 */
1777 0x0000, /* R200 */
1778 0x0000, /* R201 */
1779 0x0000, /* R202 */
1780 0x0000, /* R203 */
1781 0x0000, /* R204 */
1782 0x0000, /* R205 */
1783 0x0000, /* R206 */
1784 0x0000, /* R207 */
1785 0x0000, /* R208 */
1786 0x0000, /* R209 */
1787 0x0000, /* R210 */
1788 0x0000, /* R211 */
1789 0x0000, /* R212 */
1790 0x0000, /* R213 */
1791 0x0000, /* R214 */
1792 0x0000, /* R215 */
1793 0x0000, /* R216 */
1794 0x0000, /* R217 */
1795 0x0000, /* R218 */
1796 0x0000, /* R219 */
1797 0x0000, /* R220 */
1798 0x0000, /* R221 */
1799 0x0000, /* R222 */
1800 0x0000, /* R223 */
1801 0x0000, /* R224 */
1802 0x0000, /* R225 */
1803 0x0000, /* R226 */
1804 0x0000, /* R227 */
1805 0x0000, /* R228 */
1806 0x0000, /* R229 */
1807 0x0000, /* R230 */
1808 0x0000, /* R231 */
1809 0x0000, /* R232 */
1810 0x0000, /* R233 */
1811 0x0000, /* R234 */
1812 0x0000, /* R235 */
1813 0x0000, /* R236 */
1814 0x0000, /* R237 */
1815 0x0000, /* R238 */
1816 0x0000, /* R239 */
1817 0x0000, /* R240 */
1818 0x0000, /* R241 */
1819 0x0000, /* R242 */
1820 0x0000, /* R243 */
1821 0x0000, /* R244 */
1822 0x0000, /* R245 */
1823 0x0000, /* R246 */
1824 0x0000, /* R247 */
1825 0x0000, /* R248 */
1826 0x0000, /* R249 */
1827 0x0000, /* R250 */
1828 0x0000, /* R251 */
1829 0x0000, /* R252 */
1830 0x0000, /* R253 */
1831 0x0000, /* R254 */
1832 0x0000, /* R255 */
1833 0x0003, /* R256 - Chip Revision */
1834 0x8004, /* R257 - Control Interface */
1835 0x0000, /* R258 */
1836 0x0000, /* R259 */
1837 0x0000, /* R260 */
1838 0x0000, /* R261 */
1839 0x0000, /* R262 */
1840 0x0000, /* R263 */
1841 0x0000, /* R264 */
1842 0x0000, /* R265 */
1843 0x0000, /* R266 */
1844 0x0000, /* R267 */
1845 0x0000, /* R268 */
1846 0x0000, /* R269 */
1847 0x0000, /* R270 */
1848 0x0000, /* R271 */
1849 0x0000, /* R272 - Write Sequencer Ctrl (1) */
1850 0x0000, /* R273 - Write Sequencer Ctrl (2) */
1851 0x0000, /* R274 */
1852 0x0000, /* R275 */
1853 0x0000, /* R276 */
1854 0x0000, /* R277 */
1855 0x0000, /* R278 */
1856 0x0000, /* R279 */
1857 0x0000, /* R280 */
1858 0x0000, /* R281 */
1859 0x0000, /* R282 */
1860 0x0000, /* R283 */
1861 0x0000, /* R284 */
1862 0x0000, /* R285 */
1863 0x0000, /* R286 */
1864 0x0000, /* R287 */
1865 0x0000, /* R288 */
1866 0x0000, /* R289 */
1867 0x0000, /* R290 */
1868 0x0000, /* R291 */
1869 0x0000, /* R292 */
1870 0x0000, /* R293 */
1871 0x0000, /* R294 */
1872 0x0000, /* R295 */
1873 0x0000, /* R296 */
1874 0x0000, /* R297 */
1875 0x0000, /* R298 */
1876 0x0000, /* R299 */
1877 0x0000, /* R300 */
1878 0x0000, /* R301 */
1879 0x0000, /* R302 */
1880 0x0000, /* R303 */
1881 0x0000, /* R304 */
1882 0x0000, /* R305 */
1883 0x0000, /* R306 */
1884 0x0000, /* R307 */
1885 0x0000, /* R308 */
1886 0x0000, /* R309 */
1887 0x0000, /* R310 */
1888 0x0000, /* R311 */
1889 0x0000, /* R312 */
1890 0x0000, /* R313 */
1891 0x0000, /* R314 */
1892 0x0000, /* R315 */
1893 0x0000, /* R316 */
1894 0x0000, /* R317 */
1895 0x0000, /* R318 */
1896 0x0000, /* R319 */
1897 0x0000, /* R320 */
1898 0x0000, /* R321 */
1899 0x0000, /* R322 */
1900 0x0000, /* R323 */
1901 0x0000, /* R324 */
1902 0x0000, /* R325 */
1903 0x0000, /* R326 */
1904 0x0000, /* R327 */
1905 0x0000, /* R328 */
1906 0x0000, /* R329 */
1907 0x0000, /* R330 */
1908 0x0000, /* R331 */
1909 0x0000, /* R332 */
1910 0x0000, /* R333 */
1911 0x0000, /* R334 */
1912 0x0000, /* R335 */
1913 0x0000, /* R336 */
1914 0x0000, /* R337 */
1915 0x0000, /* R338 */
1916 0x0000, /* R339 */
1917 0x0000, /* R340 */
1918 0x0000, /* R341 */
1919 0x0000, /* R342 */
1920 0x0000, /* R343 */
1921 0x0000, /* R344 */
1922 0x0000, /* R345 */
1923 0x0000, /* R346 */
1924 0x0000, /* R347 */
1925 0x0000, /* R348 */
1926 0x0000, /* R349 */
1927 0x0000, /* R350 */
1928 0x0000, /* R351 */
1929 0x0000, /* R352 */
1930 0x0000, /* R353 */
1931 0x0000, /* R354 */
1932 0x0000, /* R355 */
1933 0x0000, /* R356 */
1934 0x0000, /* R357 */
1935 0x0000, /* R358 */
1936 0x0000, /* R359 */
1937 0x0000, /* R360 */
1938 0x0000, /* R361 */
1939 0x0000, /* R362 */
1940 0x0000, /* R363 */
1941 0x0000, /* R364 */
1942 0x0000, /* R365 */
1943 0x0000, /* R366 */
1944 0x0000, /* R367 */
1945 0x0000, /* R368 */
1946 0x0000, /* R369 */
1947 0x0000, /* R370 */
1948 0x0000, /* R371 */
1949 0x0000, /* R372 */
1950 0x0000, /* R373 */
1951 0x0000, /* R374 */
1952 0x0000, /* R375 */
1953 0x0000, /* R376 */
1954 0x0000, /* R377 */
1955 0x0000, /* R378 */
1956 0x0000, /* R379 */
1957 0x0000, /* R380 */
1958 0x0000, /* R381 */
1959 0x0000, /* R382 */
1960 0x0000, /* R383 */
1961 0x0000, /* R384 */
1962 0x0000, /* R385 */
1963 0x0000, /* R386 */
1964 0x0000, /* R387 */
1965 0x0000, /* R388 */
1966 0x0000, /* R389 */
1967 0x0000, /* R390 */
1968 0x0000, /* R391 */
1969 0x0000, /* R392 */
1970 0x0000, /* R393 */
1971 0x0000, /* R394 */
1972 0x0000, /* R395 */
1973 0x0000, /* R396 */
1974 0x0000, /* R397 */
1975 0x0000, /* R398 */
1976 0x0000, /* R399 */
1977 0x0000, /* R400 */
1978 0x0000, /* R401 */
1979 0x0000, /* R402 */
1980 0x0000, /* R403 */
1981 0x0000, /* R404 */
1982 0x0000, /* R405 */
1983 0x0000, /* R406 */
1984 0x0000, /* R407 */
1985 0x0000, /* R408 */
1986 0x0000, /* R409 */
1987 0x0000, /* R410 */
1988 0x0000, /* R411 */
1989 0x0000, /* R412 */
1990 0x0000, /* R413 */
1991 0x0000, /* R414 */
1992 0x0000, /* R415 */
1993 0x0000, /* R416 */
1994 0x0000, /* R417 */
1995 0x0000, /* R418 */
1996 0x0000, /* R419 */
1997 0x0000, /* R420 */
1998 0x0000, /* R421 */
1999 0x0000, /* R422 */
2000 0x0000, /* R423 */
2001 0x0000, /* R424 */
2002 0x0000, /* R425 */
2003 0x0000, /* R426 */
2004 0x0000, /* R427 */
2005 0x0000, /* R428 */
2006 0x0000, /* R429 */
2007 0x0000, /* R430 */
2008 0x0000, /* R431 */
2009 0x0000, /* R432 */
2010 0x0000, /* R433 */
2011 0x0000, /* R434 */
2012 0x0000, /* R435 */
2013 0x0000, /* R436 */
2014 0x0000, /* R437 */
2015 0x0000, /* R438 */
2016 0x0000, /* R439 */
2017 0x0000, /* R440 */
2018 0x0000, /* R441 */
2019 0x0000, /* R442 */
2020 0x0000, /* R443 */
2021 0x0000, /* R444 */
2022 0x0000, /* R445 */
2023 0x0000, /* R446 */
2024 0x0000, /* R447 */
2025 0x0000, /* R448 */
2026 0x0000, /* R449 */
2027 0x0000, /* R450 */
2028 0x0000, /* R451 */
2029 0x0000, /* R452 */
2030 0x0000, /* R453 */
2031 0x0000, /* R454 */
2032 0x0000, /* R455 */
2033 0x0000, /* R456 */
2034 0x0000, /* R457 */
2035 0x0000, /* R458 */
2036 0x0000, /* R459 */
2037 0x0000, /* R460 */
2038 0x0000, /* R461 */
2039 0x0000, /* R462 */
2040 0x0000, /* R463 */
2041 0x0000, /* R464 */
2042 0x0000, /* R465 */
2043 0x0000, /* R466 */
2044 0x0000, /* R467 */
2045 0x0000, /* R468 */
2046 0x0000, /* R469 */
2047 0x0000, /* R470 */
2048 0x0000, /* R471 */
2049 0x0000, /* R472 */
2050 0x0000, /* R473 */
2051 0x0000, /* R474 */
2052 0x0000, /* R475 */
2053 0x0000, /* R476 */
2054 0x0000, /* R477 */
2055 0x0000, /* R478 */
2056 0x0000, /* R479 */
2057 0x0000, /* R480 */
2058 0x0000, /* R481 */
2059 0x0000, /* R482 */
2060 0x0000, /* R483 */
2061 0x0000, /* R484 */
2062 0x0000, /* R485 */
2063 0x0000, /* R486 */
2064 0x0000, /* R487 */
2065 0x0000, /* R488 */
2066 0x0000, /* R489 */
2067 0x0000, /* R490 */
2068 0x0000, /* R491 */
2069 0x0000, /* R492 */
2070 0x0000, /* R493 */
2071 0x0000, /* R494 */
2072 0x0000, /* R495 */
2073 0x0000, /* R496 */
2074 0x0000, /* R497 */
2075 0x0000, /* R498 */
2076 0x0000, /* R499 */
2077 0x0000, /* R500 */
2078 0x0000, /* R501 */
2079 0x0000, /* R502 */
2080 0x0000, /* R503 */
2081 0x0000, /* R504 */
2082 0x0000, /* R505 */
2083 0x0000, /* R506 */
2084 0x0000, /* R507 */
2085 0x0000, /* R508 */
2086 0x0000, /* R509 */
2087 0x0000, /* R510 */
2088 0x0000, /* R511 */
2089 0x0000, /* R512 - AIF1 Clocking (1) */
2090 0x0000, /* R513 - AIF1 Clocking (2) */
2091 0x0000, /* R514 */
2092 0x0000, /* R515 */
2093 0x0000, /* R516 - AIF2 Clocking (1) */
2094 0x0000, /* R517 - AIF2 Clocking (2) */
2095 0x0000, /* R518 */
2096 0x0000, /* R519 */
2097 0x0000, /* R520 - Clocking (1) */
2098 0x0000, /* R521 - Clocking (2) */
2099 0x0000, /* R522 */
2100 0x0000, /* R523 */
2101 0x0000, /* R524 */
2102 0x0000, /* R525 */
2103 0x0000, /* R526 */
2104 0x0000, /* R527 */
2105 0x0083, /* R528 - AIF1 Rate */
2106 0x0083, /* R529 - AIF2 Rate */
2107 0x0000, /* R530 - Rate Status */
2108 0x0000, /* R531 */
2109 0x0000, /* R532 */
2110 0x0000, /* R533 */
2111 0x0000, /* R534 */
2112 0x0000, /* R535 */
2113 0x0000, /* R536 */
2114 0x0000, /* R537 */
2115 0x0000, /* R538 */
2116 0x0000, /* R539 */
2117 0x0000, /* R540 */
2118 0x0000, /* R541 */
2119 0x0000, /* R542 */
2120 0x0000, /* R543 */
2121 0x0000, /* R544 - FLL1 Control (1) */
2122 0x0000, /* R545 - FLL1 Control (2) */
2123 0x0000, /* R546 - FLL1 Control (3) */
2124 0x0000, /* R547 - FLL1 Control (4) */
2125 0x0C80, /* R548 - FLL1 Control (5) */
2126 0x0000, /* R549 */
2127 0x0000, /* R550 */
2128 0x0000, /* R551 */
2129 0x0000, /* R552 */
2130 0x0000, /* R553 */
2131 0x0000, /* R554 */
2132 0x0000, /* R555 */
2133 0x0000, /* R556 */
2134 0x0000, /* R557 */
2135 0x0000, /* R558 */
2136 0x0000, /* R559 */
2137 0x0000, /* R560 */
2138 0x0000, /* R561 */
2139 0x0000, /* R562 */
2140 0x0000, /* R563 */
2141 0x0000, /* R564 */
2142 0x0000, /* R565 */
2143 0x0000, /* R566 */
2144 0x0000, /* R567 */
2145 0x0000, /* R568 */
2146 0x0000, /* R569 */
2147 0x0000, /* R570 */
2148 0x0000, /* R571 */
2149 0x0000, /* R572 */
2150 0x0000, /* R573 */
2151 0x0000, /* R574 */
2152 0x0000, /* R575 */
2153 0x0000, /* R576 - FLL2 Control (1) */
2154 0x0000, /* R577 - FLL2 Control (2) */
2155 0x0000, /* R578 - FLL2 Control (3) */
2156 0x0000, /* R579 - FLL2 Control (4) */
2157 0x0C80, /* R580 - FLL2 Control (5) */
2158 0x0000, /* R581 */
2159 0x0000, /* R582 */
2160 0x0000, /* R583 */
2161 0x0000, /* R584 */
2162 0x0000, /* R585 */
2163 0x0000, /* R586 */
2164 0x0000, /* R587 */
2165 0x0000, /* R588 */
2166 0x0000, /* R589 */
2167 0x0000, /* R590 */
2168 0x0000, /* R591 */
2169 0x0000, /* R592 */
2170 0x0000, /* R593 */
2171 0x0000, /* R594 */
2172 0x0000, /* R595 */
2173 0x0000, /* R596 */
2174 0x0000, /* R597 */
2175 0x0000, /* R598 */
2176 0x0000, /* R599 */
2177 0x0000, /* R600 */
2178 0x0000, /* R601 */
2179 0x0000, /* R602 */
2180 0x0000, /* R603 */
2181 0x0000, /* R604 */
2182 0x0000, /* R605 */
2183 0x0000, /* R606 */
2184 0x0000, /* R607 */
2185 0x0000, /* R608 */
2186 0x0000, /* R609 */
2187 0x0000, /* R610 */
2188 0x0000, /* R611 */
2189 0x0000, /* R612 */
2190 0x0000, /* R613 */
2191 0x0000, /* R614 */
2192 0x0000, /* R615 */
2193 0x0000, /* R616 */
2194 0x0000, /* R617 */
2195 0x0000, /* R618 */
2196 0x0000, /* R619 */
2197 0x0000, /* R620 */
2198 0x0000, /* R621 */
2199 0x0000, /* R622 */
2200 0x0000, /* R623 */
2201 0x0000, /* R624 */
2202 0x0000, /* R625 */
2203 0x0000, /* R626 */
2204 0x0000, /* R627 */
2205 0x0000, /* R628 */
2206 0x0000, /* R629 */
2207 0x0000, /* R630 */
2208 0x0000, /* R631 */
2209 0x0000, /* R632 */
2210 0x0000, /* R633 */
2211 0x0000, /* R634 */
2212 0x0000, /* R635 */
2213 0x0000, /* R636 */
2214 0x0000, /* R637 */
2215 0x0000, /* R638 */
2216 0x0000, /* R639 */
2217 0x0000, /* R640 */
2218 0x0000, /* R641 */
2219 0x0000, /* R642 */
2220 0x0000, /* R643 */
2221 0x0000, /* R644 */
2222 0x0000, /* R645 */
2223 0x0000, /* R646 */
2224 0x0000, /* R647 */
2225 0x0000, /* R648 */
2226 0x0000, /* R649 */
2227 0x0000, /* R650 */
2228 0x0000, /* R651 */
2229 0x0000, /* R652 */
2230 0x0000, /* R653 */
2231 0x0000, /* R654 */
2232 0x0000, /* R655 */
2233 0x0000, /* R656 */
2234 0x0000, /* R657 */
2235 0x0000, /* R658 */
2236 0x0000, /* R659 */
2237 0x0000, /* R660 */
2238 0x0000, /* R661 */
2239 0x0000, /* R662 */
2240 0x0000, /* R663 */
2241 0x0000, /* R664 */
2242 0x0000, /* R665 */
2243 0x0000, /* R666 */
2244 0x0000, /* R667 */
2245 0x0000, /* R668 */
2246 0x0000, /* R669 */
2247 0x0000, /* R670 */
2248 0x0000, /* R671 */
2249 0x0000, /* R672 */
2250 0x0000, /* R673 */
2251 0x0000, /* R674 */
2252 0x0000, /* R675 */
2253 0x0000, /* R676 */
2254 0x0000, /* R677 */
2255 0x0000, /* R678 */
2256 0x0000, /* R679 */
2257 0x0000, /* R680 */
2258 0x0000, /* R681 */
2259 0x0000, /* R682 */
2260 0x0000, /* R683 */
2261 0x0000, /* R684 */
2262 0x0000, /* R685 */
2263 0x0000, /* R686 */
2264 0x0000, /* R687 */
2265 0x0000, /* R688 */
2266 0x0000, /* R689 */
2267 0x0000, /* R690 */
2268 0x0000, /* R691 */
2269 0x0000, /* R692 */
2270 0x0000, /* R693 */
2271 0x0000, /* R694 */
2272 0x0000, /* R695 */
2273 0x0000, /* R696 */
2274 0x0000, /* R697 */
2275 0x0000, /* R698 */
2276 0x0000, /* R699 */
2277 0x0000, /* R700 */
2278 0x0000, /* R701 */
2279 0x0000, /* R702 */
2280 0x0000, /* R703 */
2281 0x0000, /* R704 */
2282 0x0000, /* R705 */
2283 0x0000, /* R706 */
2284 0x0000, /* R707 */
2285 0x0000, /* R708 */
2286 0x0000, /* R709 */
2287 0x0000, /* R710 */
2288 0x0000, /* R711 */
2289 0x0000, /* R712 */
2290 0x0000, /* R713 */
2291 0x0000, /* R714 */
2292 0x0000, /* R715 */
2293 0x0000, /* R716 */
2294 0x0000, /* R717 */
2295 0x0000, /* R718 */
2296 0x0000, /* R719 */
2297 0x0000, /* R720 */
2298 0x0000, /* R721 */
2299 0x0000, /* R722 */
2300 0x0000, /* R723 */
2301 0x0000, /* R724 */
2302 0x0000, /* R725 */
2303 0x0000, /* R726 */
2304 0x0000, /* R727 */
2305 0x0000, /* R728 */
2306 0x0000, /* R729 */
2307 0x0000, /* R730 */
2308 0x0000, /* R731 */
2309 0x0000, /* R732 */
2310 0x0000, /* R733 */
2311 0x0000, /* R734 */
2312 0x0000, /* R735 */
2313 0x0000, /* R736 */
2314 0x0000, /* R737 */
2315 0x0000, /* R738 */
2316 0x0000, /* R739 */
2317 0x0000, /* R740 */
2318 0x0000, /* R741 */
2319 0x0000, /* R742 */
2320 0x0000, /* R743 */
2321 0x0000, /* R744 */
2322 0x0000, /* R745 */
2323 0x0000, /* R746 */
2324 0x0000, /* R747 */
2325 0x0000, /* R748 */
2326 0x0000, /* R749 */
2327 0x0000, /* R750 */
2328 0x0000, /* R751 */
2329 0x0000, /* R752 */
2330 0x0000, /* R753 */
2331 0x0000, /* R754 */
2332 0x0000, /* R755 */
2333 0x0000, /* R756 */
2334 0x0000, /* R757 */
2335 0x0000, /* R758 */
2336 0x0000, /* R759 */
2337 0x0000, /* R760 */
2338 0x0000, /* R761 */
2339 0x0000, /* R762 */
2340 0x0000, /* R763 */
2341 0x0000, /* R764 */
2342 0x0000, /* R765 */
2343 0x0000, /* R766 */
2344 0x0000, /* R767 */
2345 0x4050, /* R768 - AIF1 Control (1) */
2346 0x4000, /* R769 - AIF1 Control (2) */
2347 0x0000, /* R770 - AIF1 Master/Slave */
2348 0x0040, /* R771 - AIF1 BCLK */
2349 0x0040, /* R772 - AIF1ADC LRCLK */
2350 0x0040, /* R773 - AIF1DAC LRCLK */
2351 0x0004, /* R774 - AIF1DAC Data */
2352 0x0100, /* R775 - AIF1ADC Data */
2353 0x0000, /* R776 */
2354 0x0000, /* R777 */
2355 0x0000, /* R778 */
2356 0x0000, /* R779 */
2357 0x0000, /* R780 */
2358 0x0000, /* R781 */
2359 0x0000, /* R782 */
2360 0x0000, /* R783 */
2361 0x4050, /* R784 - AIF2 Control (1) */
2362 0x4000, /* R785 - AIF2 Control (2) */
2363 0x0000, /* R786 - AIF2 Master/Slave */
2364 0x0040, /* R787 - AIF2 BCLK */
2365 0x0040, /* R788 - AIF2ADC LRCLK */
2366 0x0040, /* R789 - AIF2DAC LRCLK */
2367 0x0000, /* R790 - AIF2DAC Data */
2368 0x0000, /* R791 - AIF2ADC Data */
2369 0x0000, /* R792 */
2370 0x0000, /* R793 */
2371 0x0000, /* R794 */
2372 0x0000, /* R795 */
2373 0x0000, /* R796 */
2374 0x0000, /* R797 */
2375 0x0000, /* R798 */
2376 0x0000, /* R799 */
2377 0x0000, /* R800 */
2378 0x0000, /* R801 */
2379 0x0000, /* R802 */
2380 0x0000, /* R803 */
2381 0x0000, /* R804 */
2382 0x0000, /* R805 */
2383 0x0000, /* R806 */
2384 0x0000, /* R807 */
2385 0x0000, /* R808 */
2386 0x0000, /* R809 */
2387 0x0000, /* R810 */
2388 0x0000, /* R811 */
2389 0x0000, /* R812 */
2390 0x0000, /* R813 */
2391 0x0000, /* R814 */
2392 0x0000, /* R815 */
2393 0x0000, /* R816 */
2394 0x0000, /* R817 */
2395 0x0000, /* R818 */
2396 0x0000, /* R819 */
2397 0x0000, /* R820 */
2398 0x0000, /* R821 */
2399 0x0000, /* R822 */
2400 0x0000, /* R823 */
2401 0x0000, /* R824 */
2402 0x0000, /* R825 */
2403 0x0000, /* R826 */
2404 0x0000, /* R827 */
2405 0x0000, /* R828 */
2406 0x0000, /* R829 */
2407 0x0000, /* R830 */
2408 0x0000, /* R831 */
2409 0x0000, /* R832 */
2410 0x0000, /* R833 */
2411 0x0000, /* R834 */
2412 0x0000, /* R835 */
2413 0x0000, /* R836 */
2414 0x0000, /* R837 */
2415 0x0000, /* R838 */
2416 0x0000, /* R839 */
2417 0x0000, /* R840 */
2418 0x0000, /* R841 */
2419 0x0000, /* R842 */
2420 0x0000, /* R843 */
2421 0x0000, /* R844 */
2422 0x0000, /* R845 */
2423 0x0000, /* R846 */
2424 0x0000, /* R847 */
2425 0x0000, /* R848 */
2426 0x0000, /* R849 */
2427 0x0000, /* R850 */
2428 0x0000, /* R851 */
2429 0x0000, /* R852 */
2430 0x0000, /* R853 */
2431 0x0000, /* R854 */
2432 0x0000, /* R855 */
2433 0x0000, /* R856 */
2434 0x0000, /* R857 */
2435 0x0000, /* R858 */
2436 0x0000, /* R859 */
2437 0x0000, /* R860 */
2438 0x0000, /* R861 */
2439 0x0000, /* R862 */
2440 0x0000, /* R863 */
2441 0x0000, /* R864 */
2442 0x0000, /* R865 */
2443 0x0000, /* R866 */
2444 0x0000, /* R867 */
2445 0x0000, /* R868 */
2446 0x0000, /* R869 */
2447 0x0000, /* R870 */
2448 0x0000, /* R871 */
2449 0x0000, /* R872 */
2450 0x0000, /* R873 */
2451 0x0000, /* R874 */
2452 0x0000, /* R875 */
2453 0x0000, /* R876 */
2454 0x0000, /* R877 */
2455 0x0000, /* R878 */
2456 0x0000, /* R879 */
2457 0x0000, /* R880 */
2458 0x0000, /* R881 */
2459 0x0000, /* R882 */
2460 0x0000, /* R883 */
2461 0x0000, /* R884 */
2462 0x0000, /* R885 */
2463 0x0000, /* R886 */
2464 0x0000, /* R887 */
2465 0x0000, /* R888 */
2466 0x0000, /* R889 */
2467 0x0000, /* R890 */
2468 0x0000, /* R891 */
2469 0x0000, /* R892 */
2470 0x0000, /* R893 */
2471 0x0000, /* R894 */
2472 0x0000, /* R895 */
2473 0x0000, /* R896 */
2474 0x0000, /* R897 */
2475 0x0000, /* R898 */
2476 0x0000, /* R899 */
2477 0x0000, /* R900 */
2478 0x0000, /* R901 */
2479 0x0000, /* R902 */
2480 0x0000, /* R903 */
2481 0x0000, /* R904 */
2482 0x0000, /* R905 */
2483 0x0000, /* R906 */
2484 0x0000, /* R907 */
2485 0x0000, /* R908 */
2486 0x0000, /* R909 */
2487 0x0000, /* R910 */
2488 0x0000, /* R911 */
2489 0x0000, /* R912 */
2490 0x0000, /* R913 */
2491 0x0000, /* R914 */
2492 0x0000, /* R915 */
2493 0x0000, /* R916 */
2494 0x0000, /* R917 */
2495 0x0000, /* R918 */
2496 0x0000, /* R919 */
2497 0x0000, /* R920 */
2498 0x0000, /* R921 */
2499 0x0000, /* R922 */
2500 0x0000, /* R923 */
2501 0x0000, /* R924 */
2502 0x0000, /* R925 */
2503 0x0000, /* R926 */
2504 0x0000, /* R927 */
2505 0x0000, /* R928 */
2506 0x0000, /* R929 */
2507 0x0000, /* R930 */
2508 0x0000, /* R931 */
2509 0x0000, /* R932 */
2510 0x0000, /* R933 */
2511 0x0000, /* R934 */
2512 0x0000, /* R935 */
2513 0x0000, /* R936 */
2514 0x0000, /* R937 */
2515 0x0000, /* R938 */
2516 0x0000, /* R939 */
2517 0x0000, /* R940 */
2518 0x0000, /* R941 */
2519 0x0000, /* R942 */
2520 0x0000, /* R943 */
2521 0x0000, /* R944 */
2522 0x0000, /* R945 */
2523 0x0000, /* R946 */
2524 0x0000, /* R947 */
2525 0x0000, /* R948 */
2526 0x0000, /* R949 */
2527 0x0000, /* R950 */
2528 0x0000, /* R951 */
2529 0x0000, /* R952 */
2530 0x0000, /* R953 */
2531 0x0000, /* R954 */
2532 0x0000, /* R955 */
2533 0x0000, /* R956 */
2534 0x0000, /* R957 */
2535 0x0000, /* R958 */
2536 0x0000, /* R959 */
2537 0x0000, /* R960 */
2538 0x0000, /* R961 */
2539 0x0000, /* R962 */
2540 0x0000, /* R963 */
2541 0x0000, /* R964 */
2542 0x0000, /* R965 */
2543 0x0000, /* R966 */
2544 0x0000, /* R967 */
2545 0x0000, /* R968 */
2546 0x0000, /* R969 */
2547 0x0000, /* R970 */
2548 0x0000, /* R971 */
2549 0x0000, /* R972 */
2550 0x0000, /* R973 */
2551 0x0000, /* R974 */
2552 0x0000, /* R975 */
2553 0x0000, /* R976 */
2554 0x0000, /* R977 */
2555 0x0000, /* R978 */
2556 0x0000, /* R979 */
2557 0x0000, /* R980 */
2558 0x0000, /* R981 */
2559 0x0000, /* R982 */
2560 0x0000, /* R983 */
2561 0x0000, /* R984 */
2562 0x0000, /* R985 */
2563 0x0000, /* R986 */
2564 0x0000, /* R987 */
2565 0x0000, /* R988 */
2566 0x0000, /* R989 */
2567 0x0000, /* R990 */
2568 0x0000, /* R991 */
2569 0x0000, /* R992 */
2570 0x0000, /* R993 */
2571 0x0000, /* R994 */
2572 0x0000, /* R995 */
2573 0x0000, /* R996 */
2574 0x0000, /* R997 */
2575 0x0000, /* R998 */
2576 0x0000, /* R999 */
2577 0x0000, /* R1000 */
2578 0x0000, /* R1001 */
2579 0x0000, /* R1002 */
2580 0x0000, /* R1003 */
2581 0x0000, /* R1004 */
2582 0x0000, /* R1005 */
2583 0x0000, /* R1006 */
2584 0x0000, /* R1007 */
2585 0x0000, /* R1008 */
2586 0x0000, /* R1009 */
2587 0x0000, /* R1010 */
2588 0x0000, /* R1011 */
2589 0x0000, /* R1012 */
2590 0x0000, /* R1013 */
2591 0x0000, /* R1014 */
2592 0x0000, /* R1015 */
2593 0x0000, /* R1016 */
2594 0x0000, /* R1017 */
2595 0x0000, /* R1018 */
2596 0x0000, /* R1019 */
2597 0x0000, /* R1020 */
2598 0x0000, /* R1021 */
2599 0x0000, /* R1022 */
2600 0x0000, /* R1023 */
2601 0x00C0, /* R1024 - AIF1 ADC1 Left Volume */
2602 0x00C0, /* R1025 - AIF1 ADC1 Right Volume */
2603 0x00C0, /* R1026 - AIF1 DAC1 Left Volume */
2604 0x00C0, /* R1027 - AIF1 DAC1 Right Volume */
2605 0x00C0, /* R1028 - AIF1 ADC2 Left Volume */
2606 0x00C0, /* R1029 - AIF1 ADC2 Right Volume */
2607 0x00C0, /* R1030 - AIF1 DAC2 Left Volume */
2608 0x00C0, /* R1031 - AIF1 DAC2 Right Volume */
2609 0x0000, /* R1032 */
2610 0x0000, /* R1033 */
2611 0x0000, /* R1034 */
2612 0x0000, /* R1035 */
2613 0x0000, /* R1036 */
2614 0x0000, /* R1037 */
2615 0x0000, /* R1038 */
2616 0x0000, /* R1039 */
2617 0x0000, /* R1040 - AIF1 ADC1 Filters */
2618 0x0000, /* R1041 - AIF1 ADC2 Filters */
2619 0x0000, /* R1042 */
2620 0x0000, /* R1043 */
2621 0x0000, /* R1044 */
2622 0x0000, /* R1045 */
2623 0x0000, /* R1046 */
2624 0x0000, /* R1047 */
2625 0x0000, /* R1048 */
2626 0x0000, /* R1049 */
2627 0x0000, /* R1050 */
2628 0x0000, /* R1051 */
2629 0x0000, /* R1052 */
2630 0x0000, /* R1053 */
2631 0x0000, /* R1054 */
2632 0x0000, /* R1055 */
2633 0x0200, /* R1056 - AIF1 DAC1 Filters (1) */
2634 0x0010, /* R1057 - AIF1 DAC1 Filters (2) */
2635 0x0200, /* R1058 - AIF1 DAC2 Filters (1) */
2636 0x0010, /* R1059 - AIF1 DAC2 Filters (2) */
2637 0x0000, /* R1060 */
2638 0x0000, /* R1061 */
2639 0x0000, /* R1062 */
2640 0x0000, /* R1063 */
2641 0x0000, /* R1064 */
2642 0x0000, /* R1065 */
2643 0x0000, /* R1066 */
2644 0x0000, /* R1067 */
2645 0x0000, /* R1068 */
2646 0x0000, /* R1069 */
2647 0x0000, /* R1070 */
2648 0x0000, /* R1071 */
2649 0x0000, /* R1072 */
2650 0x0000, /* R1073 */
2651 0x0000, /* R1074 */
2652 0x0000, /* R1075 */
2653 0x0000, /* R1076 */
2654 0x0000, /* R1077 */
2655 0x0000, /* R1078 */
2656 0x0000, /* R1079 */
2657 0x0000, /* R1080 */
2658 0x0000, /* R1081 */
2659 0x0000, /* R1082 */
2660 0x0000, /* R1083 */
2661 0x0000, /* R1084 */
2662 0x0000, /* R1085 */
2663 0x0000, /* R1086 */
2664 0x0000, /* R1087 */
2665 0x0098, /* R1088 - AIF1 DRC1 (1) */
2666 0x0845, /* R1089 - AIF1 DRC1 (2) */
2667 0x0000, /* R1090 - AIF1 DRC1 (3) */
2668 0x0000, /* R1091 - AIF1 DRC1 (4) */
2669 0x0000, /* R1092 - AIF1 DRC1 (5) */
2670 0x0000, /* R1093 */
2671 0x0000, /* R1094 */
2672 0x0000, /* R1095 */
2673 0x0000, /* R1096 */
2674 0x0000, /* R1097 */
2675 0x0000, /* R1098 */
2676 0x0000, /* R1099 */
2677 0x0000, /* R1100 */
2678 0x0000, /* R1101 */
2679 0x0000, /* R1102 */
2680 0x0000, /* R1103 */
2681 0x0098, /* R1104 - AIF1 DRC2 (1) */
2682 0x0845, /* R1105 - AIF1 DRC2 (2) */
2683 0x0000, /* R1106 - AIF1 DRC2 (3) */
2684 0x0000, /* R1107 - AIF1 DRC2 (4) */
2685 0x0000, /* R1108 - AIF1 DRC2 (5) */
2686 0x0000, /* R1109 */
2687 0x0000, /* R1110 */
2688 0x0000, /* R1111 */
2689 0x0000, /* R1112 */
2690 0x0000, /* R1113 */
2691 0x0000, /* R1114 */
2692 0x0000, /* R1115 */
2693 0x0000, /* R1116 */
2694 0x0000, /* R1117 */
2695 0x0000, /* R1118 */
2696 0x0000, /* R1119 */
2697 0x0000, /* R1120 */
2698 0x0000, /* R1121 */
2699 0x0000, /* R1122 */
2700 0x0000, /* R1123 */
2701 0x0000, /* R1124 */
2702 0x0000, /* R1125 */
2703 0x0000, /* R1126 */
2704 0x0000, /* R1127 */
2705 0x0000, /* R1128 */
2706 0x0000, /* R1129 */
2707 0x0000, /* R1130 */
2708 0x0000, /* R1131 */
2709 0x0000, /* R1132 */
2710 0x0000, /* R1133 */
2711 0x0000, /* R1134 */
2712 0x0000, /* R1135 */
2713 0x0000, /* R1136 */
2714 0x0000, /* R1137 */
2715 0x0000, /* R1138 */
2716 0x0000, /* R1139 */
2717 0x0000, /* R1140 */
2718 0x0000, /* R1141 */
2719 0x0000, /* R1142 */
2720 0x0000, /* R1143 */
2721 0x0000, /* R1144 */
2722 0x0000, /* R1145 */
2723 0x0000, /* R1146 */
2724 0x0000, /* R1147 */
2725 0x0000, /* R1148 */
2726 0x0000, /* R1149 */
2727 0x0000, /* R1150 */
2728 0x0000, /* R1151 */
2729 0x6318, /* R1152 - AIF1 DAC1 EQ Gains (1) */
2730 0x6300, /* R1153 - AIF1 DAC1 EQ Gains (2) */
2731 0x0FCA, /* R1154 - AIF1 DAC1 EQ Band 1 A */
2732 0x0400, /* R1155 - AIF1 DAC1 EQ Band 1 B */
2733 0x00D8, /* R1156 - AIF1 DAC1 EQ Band 1 PG */
2734 0x1EB5, /* R1157 - AIF1 DAC1 EQ Band 2 A */
2735 0xF145, /* R1158 - AIF1 DAC1 EQ Band 2 B */
2736 0x0B75, /* R1159 - AIF1 DAC1 EQ Band 2 C */
2737 0x01C5, /* R1160 - AIF1 DAC1 EQ Band 2 PG */
2738 0x1C58, /* R1161 - AIF1 DAC1 EQ Band 3 A */
2739 0xF373, /* R1162 - AIF1 DAC1 EQ Band 3 B */
2740 0x0A54, /* R1163 - AIF1 DAC1 EQ Band 3 C */
2741 0x0558, /* R1164 - AIF1 DAC1 EQ Band 3 PG */
2742 0x168E, /* R1165 - AIF1 DAC1 EQ Band 4 A */
2743 0xF829, /* R1166 - AIF1 DAC1 EQ Band 4 B */
2744 0x07AD, /* R1167 - AIF1 DAC1 EQ Band 4 C */
2745 0x1103, /* R1168 - AIF1 DAC1 EQ Band 4 PG */
2746 0x0564, /* R1169 - AIF1 DAC1 EQ Band 5 A */
2747 0x0559, /* R1170 - AIF1 DAC1 EQ Band 5 B */
2748 0x4000, /* R1171 - AIF1 DAC1 EQ Band 5 PG */
2749 0x0000, /* R1172 */
2750 0x0000, /* R1173 */
2751 0x0000, /* R1174 */
2752 0x0000, /* R1175 */
2753 0x0000, /* R1176 */
2754 0x0000, /* R1177 */
2755 0x0000, /* R1178 */
2756 0x0000, /* R1179 */
2757 0x0000, /* R1180 */
2758 0x0000, /* R1181 */
2759 0x0000, /* R1182 */
2760 0x0000, /* R1183 */
2761 0x6318, /* R1184 - AIF1 DAC2 EQ Gains (1) */
2762 0x6300, /* R1185 - AIF1 DAC2 EQ Gains (2) */
2763 0x0FCA, /* R1186 - AIF1 DAC2 EQ Band 1 A */
2764 0x0400, /* R1187 - AIF1 DAC2 EQ Band 1 B */
2765 0x00D8, /* R1188 - AIF1 DAC2 EQ Band 1 PG */
2766 0x1EB5, /* R1189 - AIF1 DAC2 EQ Band 2 A */
2767 0xF145, /* R1190 - AIF1 DAC2 EQ Band 2 B */
2768 0x0B75, /* R1191 - AIF1 DAC2 EQ Band 2 C */
2769 0x01C5, /* R1192 - AIF1 DAC2 EQ Band 2 PG */
2770 0x1C58, /* R1193 - AIF1 DAC2 EQ Band 3 A */
2771 0xF373, /* R1194 - AIF1 DAC2 EQ Band 3 B */
2772 0x0A54, /* R1195 - AIF1 DAC2 EQ Band 3 C */
2773 0x0558, /* R1196 - AIF1 DAC2 EQ Band 3 PG */
2774 0x168E, /* R1197 - AIF1 DAC2 EQ Band 4 A */
2775 0xF829, /* R1198 - AIF1 DAC2 EQ Band 4 B */
2776 0x07AD, /* R1199 - AIF1 DAC2 EQ Band 4 C */
2777 0x1103, /* R1200 - AIF1 DAC2 EQ Band 4 PG */
2778 0x0564, /* R1201 - AIF1 DAC2 EQ Band 5 A */
2779 0x0559, /* R1202 - AIF1 DAC2 EQ Band 5 B */
2780 0x4000, /* R1203 - AIF1 DAC2 EQ Band 5 PG */
2781 0x0000, /* R1204 */
2782 0x0000, /* R1205 */
2783 0x0000, /* R1206 */
2784 0x0000, /* R1207 */
2785 0x0000, /* R1208 */
2786 0x0000, /* R1209 */
2787 0x0000, /* R1210 */
2788 0x0000, /* R1211 */
2789 0x0000, /* R1212 */
2790 0x0000, /* R1213 */
2791 0x0000, /* R1214 */
2792 0x0000, /* R1215 */
2793 0x0000, /* R1216 */
2794 0x0000, /* R1217 */
2795 0x0000, /* R1218 */
2796 0x0000, /* R1219 */
2797 0x0000, /* R1220 */
2798 0x0000, /* R1221 */
2799 0x0000, /* R1222 */
2800 0x0000, /* R1223 */
2801 0x0000, /* R1224 */
2802 0x0000, /* R1225 */
2803 0x0000, /* R1226 */
2804 0x0000, /* R1227 */
2805 0x0000, /* R1228 */
2806 0x0000, /* R1229 */
2807 0x0000, /* R1230 */
2808 0x0000, /* R1231 */
2809 0x0000, /* R1232 */
2810 0x0000, /* R1233 */
2811 0x0000, /* R1234 */
2812 0x0000, /* R1235 */
2813 0x0000, /* R1236 */
2814 0x0000, /* R1237 */
2815 0x0000, /* R1238 */
2816 0x0000, /* R1239 */
2817 0x0000, /* R1240 */
2818 0x0000, /* R1241 */
2819 0x0000, /* R1242 */
2820 0x0000, /* R1243 */
2821 0x0000, /* R1244 */
2822 0x0000, /* R1245 */
2823 0x0000, /* R1246 */
2824 0x0000, /* R1247 */
2825 0x0000, /* R1248 */
2826 0x0000, /* R1249 */
2827 0x0000, /* R1250 */
2828 0x0000, /* R1251 */
2829 0x0000, /* R1252 */
2830 0x0000, /* R1253 */
2831 0x0000, /* R1254 */
2832 0x0000, /* R1255 */
2833 0x0000, /* R1256 */
2834 0x0000, /* R1257 */
2835 0x0000, /* R1258 */
2836 0x0000, /* R1259 */
2837 0x0000, /* R1260 */
2838 0x0000, /* R1261 */
2839 0x0000, /* R1262 */
2840 0x0000, /* R1263 */
2841 0x0000, /* R1264 */
2842 0x0000, /* R1265 */
2843 0x0000, /* R1266 */
2844 0x0000, /* R1267 */
2845 0x0000, /* R1268 */
2846 0x0000, /* R1269 */
2847 0x0000, /* R1270 */
2848 0x0000, /* R1271 */
2849 0x0000, /* R1272 */
2850 0x0000, /* R1273 */
2851 0x0000, /* R1274 */
2852 0x0000, /* R1275 */
2853 0x0000, /* R1276 */
2854 0x0000, /* R1277 */
2855 0x0000, /* R1278 */
2856 0x0000, /* R1279 */
2857 0x00C0, /* R1280 - AIF2 ADC Left Volume */
2858 0x00C0, /* R1281 - AIF2 ADC Right Volume */
2859 0x00C0, /* R1282 - AIF2 DAC Left Volume */
2860 0x00C0, /* R1283 - AIF2 DAC Right Volume */
2861 0x0000, /* R1284 */
2862 0x0000, /* R1285 */
2863 0x0000, /* R1286 */
2864 0x0000, /* R1287 */
2865 0x0000, /* R1288 */
2866 0x0000, /* R1289 */
2867 0x0000, /* R1290 */
2868 0x0000, /* R1291 */
2869 0x0000, /* R1292 */
2870 0x0000, /* R1293 */
2871 0x0000, /* R1294 */
2872 0x0000, /* R1295 */
2873 0x0000, /* R1296 - AIF2 ADC Filters */
2874 0x0000, /* R1297 */
2875 0x0000, /* R1298 */
2876 0x0000, /* R1299 */
2877 0x0000, /* R1300 */
2878 0x0000, /* R1301 */
2879 0x0000, /* R1302 */
2880 0x0000, /* R1303 */
2881 0x0000, /* R1304 */
2882 0x0000, /* R1305 */
2883 0x0000, /* R1306 */
2884 0x0000, /* R1307 */
2885 0x0000, /* R1308 */
2886 0x0000, /* R1309 */
2887 0x0000, /* R1310 */
2888 0x0000, /* R1311 */
2889 0x0200, /* R1312 - AIF2 DAC Filters (1) */
2890 0x0010, /* R1313 - AIF2 DAC Filters (2) */
2891 0x0000, /* R1314 */
2892 0x0000, /* R1315 */
2893 0x0000, /* R1316 */
2894 0x0000, /* R1317 */
2895 0x0000, /* R1318 */
2896 0x0000, /* R1319 */
2897 0x0000, /* R1320 */
2898 0x0000, /* R1321 */
2899 0x0000, /* R1322 */
2900 0x0000, /* R1323 */
2901 0x0000, /* R1324 */
2902 0x0000, /* R1325 */
2903 0x0000, /* R1326 */
2904 0x0000, /* R1327 */
2905 0x0000, /* R1328 */
2906 0x0000, /* R1329 */
2907 0x0000, /* R1330 */
2908 0x0000, /* R1331 */
2909 0x0000, /* R1332 */
2910 0x0000, /* R1333 */
2911 0x0000, /* R1334 */
2912 0x0000, /* R1335 */
2913 0x0000, /* R1336 */
2914 0x0000, /* R1337 */
2915 0x0000, /* R1338 */
2916 0x0000, /* R1339 */
2917 0x0000, /* R1340 */
2918 0x0000, /* R1341 */
2919 0x0000, /* R1342 */
2920 0x0000, /* R1343 */
2921 0x0098, /* R1344 - AIF2 DRC (1) */
2922 0x0845, /* R1345 - AIF2 DRC (2) */
2923 0x0000, /* R1346 - AIF2 DRC (3) */
2924 0x0000, /* R1347 - AIF2 DRC (4) */
2925 0x0000, /* R1348 - AIF2 DRC (5) */
2926 0x0000, /* R1349 */
2927 0x0000, /* R1350 */
2928 0x0000, /* R1351 */
2929 0x0000, /* R1352 */
2930 0x0000, /* R1353 */
2931 0x0000, /* R1354 */
2932 0x0000, /* R1355 */
2933 0x0000, /* R1356 */
2934 0x0000, /* R1357 */
2935 0x0000, /* R1358 */
2936 0x0000, /* R1359 */
2937 0x0000, /* R1360 */
2938 0x0000, /* R1361 */
2939 0x0000, /* R1362 */
2940 0x0000, /* R1363 */
2941 0x0000, /* R1364 */
2942 0x0000, /* R1365 */
2943 0x0000, /* R1366 */
2944 0x0000, /* R1367 */
2945 0x0000, /* R1368 */
2946 0x0000, /* R1369 */
2947 0x0000, /* R1370 */
2948 0x0000, /* R1371 */
2949 0x0000, /* R1372 */
2950 0x0000, /* R1373 */
2951 0x0000, /* R1374 */
2952 0x0000, /* R1375 */
2953 0x0000, /* R1376 */
2954 0x0000, /* R1377 */
2955 0x0000, /* R1378 */
2956 0x0000, /* R1379 */
2957 0x0000, /* R1380 */
2958 0x0000, /* R1381 */
2959 0x0000, /* R1382 */
2960 0x0000, /* R1383 */
2961 0x0000, /* R1384 */
2962 0x0000, /* R1385 */
2963 0x0000, /* R1386 */
2964 0x0000, /* R1387 */
2965 0x0000, /* R1388 */
2966 0x0000, /* R1389 */
2967 0x0000, /* R1390 */
2968 0x0000, /* R1391 */
2969 0x0000, /* R1392 */
2970 0x0000, /* R1393 */
2971 0x0000, /* R1394 */
2972 0x0000, /* R1395 */
2973 0x0000, /* R1396 */
2974 0x0000, /* R1397 */
2975 0x0000, /* R1398 */
2976 0x0000, /* R1399 */
2977 0x0000, /* R1400 */
2978 0x0000, /* R1401 */
2979 0x0000, /* R1402 */
2980 0x0000, /* R1403 */
2981 0x0000, /* R1404 */
2982 0x0000, /* R1405 */
2983 0x0000, /* R1406 */
2984 0x0000, /* R1407 */
2985 0x6318, /* R1408 - AIF2 EQ Gains (1) */
2986 0x6300, /* R1409 - AIF2 EQ Gains (2) */
2987 0x0FCA, /* R1410 - AIF2 EQ Band 1 A */
2988 0x0400, /* R1411 - AIF2 EQ Band 1 B */
2989 0x00D8, /* R1412 - AIF2 EQ Band 1 PG */
2990 0x1EB5, /* R1413 - AIF2 EQ Band 2 A */
2991 0xF145, /* R1414 - AIF2 EQ Band 2 B */
2992 0x0B75, /* R1415 - AIF2 EQ Band 2 C */
2993 0x01C5, /* R1416 - AIF2 EQ Band 2 PG */
2994 0x1C58, /* R1417 - AIF2 EQ Band 3 A */
2995 0xF373, /* R1418 - AIF2 EQ Band 3 B */
2996 0x0A54, /* R1419 - AIF2 EQ Band 3 C */
2997 0x0558, /* R1420 - AIF2 EQ Band 3 PG */
2998 0x168E, /* R1421 - AIF2 EQ Band 4 A */
2999 0xF829, /* R1422 - AIF2 EQ Band 4 B */
3000 0x07AD, /* R1423 - AIF2 EQ Band 4 C */
3001 0x1103, /* R1424 - AIF2 EQ Band 4 PG */
3002 0x0564, /* R1425 - AIF2 EQ Band 5 A */
3003 0x0559, /* R1426 - AIF2 EQ Band 5 B */
3004 0x4000, /* R1427 - AIF2 EQ Band 5 PG */
3005 0x0000, /* R1428 */
3006 0x0000, /* R1429 */
3007 0x0000, /* R1430 */
3008 0x0000, /* R1431 */
3009 0x0000, /* R1432 */
3010 0x0000, /* R1433 */
3011 0x0000, /* R1434 */
3012 0x0000, /* R1435 */
3013 0x0000, /* R1436 */
3014 0x0000, /* R1437 */
3015 0x0000, /* R1438 */
3016 0x0000, /* R1439 */
3017 0x0000, /* R1440 */
3018 0x0000, /* R1441 */
3019 0x0000, /* R1442 */
3020 0x0000, /* R1443 */
3021 0x0000, /* R1444 */
3022 0x0000, /* R1445 */
3023 0x0000, /* R1446 */
3024 0x0000, /* R1447 */
3025 0x0000, /* R1448 */
3026 0x0000, /* R1449 */
3027 0x0000, /* R1450 */
3028 0x0000, /* R1451 */
3029 0x0000, /* R1452 */
3030 0x0000, /* R1453 */
3031 0x0000, /* R1454 */
3032 0x0000, /* R1455 */
3033 0x0000, /* R1456 */
3034 0x0000, /* R1457 */
3035 0x0000, /* R1458 */
3036 0x0000, /* R1459 */
3037 0x0000, /* R1460 */
3038 0x0000, /* R1461 */
3039 0x0000, /* R1462 */
3040 0x0000, /* R1463 */
3041 0x0000, /* R1464 */
3042 0x0000, /* R1465 */
3043 0x0000, /* R1466 */
3044 0x0000, /* R1467 */
3045 0x0000, /* R1468 */
3046 0x0000, /* R1469 */
3047 0x0000, /* R1470 */
3048 0x0000, /* R1471 */
3049 0x0000, /* R1472 */
3050 0x0000, /* R1473 */
3051 0x0000, /* R1474 */
3052 0x0000, /* R1475 */
3053 0x0000, /* R1476 */
3054 0x0000, /* R1477 */
3055 0x0000, /* R1478 */
3056 0x0000, /* R1479 */
3057 0x0000, /* R1480 */
3058 0x0000, /* R1481 */
3059 0x0000, /* R1482 */
3060 0x0000, /* R1483 */
3061 0x0000, /* R1484 */
3062 0x0000, /* R1485 */
3063 0x0000, /* R1486 */
3064 0x0000, /* R1487 */
3065 0x0000, /* R1488 */
3066 0x0000, /* R1489 */
3067 0x0000, /* R1490 */
3068 0x0000, /* R1491 */
3069 0x0000, /* R1492 */
3070 0x0000, /* R1493 */
3071 0x0000, /* R1494 */
3072 0x0000, /* R1495 */
3073 0x0000, /* R1496 */
3074 0x0000, /* R1497 */
3075 0x0000, /* R1498 */
3076 0x0000, /* R1499 */
3077 0x0000, /* R1500 */
3078 0x0000, /* R1501 */
3079 0x0000, /* R1502 */
3080 0x0000, /* R1503 */
3081 0x0000, /* R1504 */
3082 0x0000, /* R1505 */
3083 0x0000, /* R1506 */
3084 0x0000, /* R1507 */
3085 0x0000, /* R1508 */
3086 0x0000, /* R1509 */
3087 0x0000, /* R1510 */
3088 0x0000, /* R1511 */
3089 0x0000, /* R1512 */
3090 0x0000, /* R1513 */
3091 0x0000, /* R1514 */
3092 0x0000, /* R1515 */
3093 0x0000, /* R1516 */
3094 0x0000, /* R1517 */
3095 0x0000, /* R1518 */
3096 0x0000, /* R1519 */
3097 0x0000, /* R1520 */
3098 0x0000, /* R1521 */
3099 0x0000, /* R1522 */
3100 0x0000, /* R1523 */
3101 0x0000, /* R1524 */
3102 0x0000, /* R1525 */
3103 0x0000, /* R1526 */
3104 0x0000, /* R1527 */
3105 0x0000, /* R1528 */
3106 0x0000, /* R1529 */
3107 0x0000, /* R1530 */
3108 0x0000, /* R1531 */
3109 0x0000, /* R1532 */
3110 0x0000, /* R1533 */
3111 0x0000, /* R1534 */
3112 0x0000, /* R1535 */
3113 0x0000, /* R1536 - DAC1 Mixer Volumes */
3114 0x0000, /* R1537 - DAC1 Left Mixer Routing */
3115 0x0000, /* R1538 - DAC1 Right Mixer Routing */
3116 0x0000, /* R1539 - DAC2 Mixer Volumes */
3117 0x0000, /* R1540 - DAC2 Left Mixer Routing */
3118 0x0000, /* R1541 - DAC2 Right Mixer Routing */
3119 0x0000, /* R1542 - AIF1 ADC1 Left Mixer Routing */
3120 0x0000, /* R1543 - AIF1 ADC1 Right Mixer Routing */
3121 0x0000, /* R1544 - AIF1 ADC2 Left Mixer Routing */
3122 0x0000, /* R1545 - AIF1 ADC2 Right mixer Routing */
3123 0x0000, /* R1546 */
3124 0x0000, /* R1547 */
3125 0x0000, /* R1548 */
3126 0x0000, /* R1549 */
3127 0x0000, /* R1550 */
3128 0x0000, /* R1551 */
3129 0x02C0, /* R1552 - DAC1 Left Volume */
3130 0x02C0, /* R1553 - DAC1 Right Volume */
3131 0x02C0, /* R1554 - DAC2 Left Volume */
3132 0x02C0, /* R1555 - DAC2 Right Volume */
3133 0x0000, /* R1556 - DAC Softmute */
3134 0x0000, /* R1557 */
3135 0x0000, /* R1558 */
3136 0x0000, /* R1559 */
3137 0x0000, /* R1560 */
3138 0x0000, /* R1561 */
3139 0x0000, /* R1562 */
3140 0x0000, /* R1563 */
3141 0x0000, /* R1564 */
3142 0x0000, /* R1565 */
3143 0x0000, /* R1566 */
3144 0x0000, /* R1567 */
3145 0x0002, /* R1568 - Oversampling */
3146 0x0000, /* R1569 - Sidetone */
3147};
diff --git a/sound/soc/codecs/wm8994.c b/sound/soc/codecs/wm8994.c
index 4d3e6f1ac584..247a6a99feb8 100644
--- a/sound/soc/codecs/wm8994.c
+++ b/sound/soc/codecs/wm8994.c
@@ -18,15 +18,17 @@
18#include <linux/pm.h> 18#include <linux/pm.h>
19#include <linux/i2c.h> 19#include <linux/i2c.h>
20#include <linux/platform_device.h> 20#include <linux/platform_device.h>
21#include <linux/pm_runtime.h>
21#include <linux/regulator/consumer.h> 22#include <linux/regulator/consumer.h>
22#include <linux/slab.h> 23#include <linux/slab.h>
23#include <sound/core.h> 24#include <sound/core.h>
25#include <sound/jack.h>
24#include <sound/pcm.h> 26#include <sound/pcm.h>
25#include <sound/pcm_params.h> 27#include <sound/pcm_params.h>
26#include <sound/soc.h> 28#include <sound/soc.h>
27#include <sound/soc-dapm.h>
28#include <sound/initval.h> 29#include <sound/initval.h>
29#include <sound/tlv.h> 30#include <sound/tlv.h>
31#include <trace/events/asoc.h>
30 32
31#include <linux/mfd/wm8994/core.h> 33#include <linux/mfd/wm8994/core.h>
32#include <linux/mfd/wm8994/registers.h> 34#include <linux/mfd/wm8994/registers.h>
@@ -57,8 +59,6 @@ static int wm8994_retune_mobile_base[] = {
57 WM8994_AIF2_EQ_GAINS_1, 59 WM8994_AIF2_EQ_GAINS_1,
58}; 60};
59 61
60#define WM8994_REG_CACHE_SIZE 0x621
61
62struct wm8994_micdet { 62struct wm8994_micdet {
63 struct snd_soc_jack *jack; 63 struct snd_soc_jack *jack;
64 int det; 64 int det;
@@ -71,7 +71,6 @@ struct wm8994_priv {
71 enum snd_soc_control_type control_type; 71 enum snd_soc_control_type control_type;
72 void *control_data; 72 void *control_data;
73 struct snd_soc_codec *codec; 73 struct snd_soc_codec *codec;
74 u16 reg_cache[WM8994_REG_CACHE_SIZE + 1];
75 int sysclk[2]; 74 int sysclk[2];
76 int sysclk_rate[2]; 75 int sysclk_rate[2];
77 int mclk[2]; 76 int mclk[2];
@@ -81,6 +80,8 @@ struct wm8994_priv {
81 int dac_rates[2]; 80 int dac_rates[2];
82 int lrclk_shared[2]; 81 int lrclk_shared[2];
83 82
83 int mbc_ena[3];
84
84 /* Platform dependant DRC configuration */ 85 /* Platform dependant DRC configuration */
85 const char **drc_texts; 86 const char **drc_texts;
86 int drc_cfg[WM8994_NUM_DRC]; 87 int drc_cfg[WM8994_NUM_DRC];
@@ -92,1588 +93,22 @@ struct wm8994_priv {
92 int retune_mobile_cfg[WM8994_NUM_EQ]; 93 int retune_mobile_cfg[WM8994_NUM_EQ];
93 struct soc_enum retune_mobile_enum; 94 struct soc_enum retune_mobile_enum;
94 95
96 /* Platform dependant MBC configuration */
97 int mbc_cfg;
98 const char **mbc_texts;
99 struct soc_enum mbc_enum;
100
95 struct wm8994_micdet micdet[2]; 101 struct wm8994_micdet micdet[2];
96 102
103 wm8958_micdet_cb jack_cb;
104 void *jack_cb_data;
105 bool jack_is_mic;
106 bool jack_is_video;
107
97 int revision; 108 int revision;
98 struct wm8994_pdata *pdata; 109 struct wm8994_pdata *pdata;
99}; 110};
100 111
101static const struct {
102 unsigned short readable; /* Mask of readable bits */
103 unsigned short writable; /* Mask of writable bits */
104} access_masks[] = {
105 { 0xFFFF, 0xFFFF }, /* R0 - Software Reset */
106 { 0x3B37, 0x3B37 }, /* R1 - Power Management (1) */
107 { 0x6BF0, 0x6BF0 }, /* R2 - Power Management (2) */
108 { 0x3FF0, 0x3FF0 }, /* R3 - Power Management (3) */
109 { 0x3F3F, 0x3F3F }, /* R4 - Power Management (4) */
110 { 0x3F0F, 0x3F0F }, /* R5 - Power Management (5) */
111 { 0x003F, 0x003F }, /* R6 - Power Management (6) */
112 { 0x0000, 0x0000 }, /* R7 */
113 { 0x0000, 0x0000 }, /* R8 */
114 { 0x0000, 0x0000 }, /* R9 */
115 { 0x0000, 0x0000 }, /* R10 */
116 { 0x0000, 0x0000 }, /* R11 */
117 { 0x0000, 0x0000 }, /* R12 */
118 { 0x0000, 0x0000 }, /* R13 */
119 { 0x0000, 0x0000 }, /* R14 */
120 { 0x0000, 0x0000 }, /* R15 */
121 { 0x0000, 0x0000 }, /* R16 */
122 { 0x0000, 0x0000 }, /* R17 */
123 { 0x0000, 0x0000 }, /* R18 */
124 { 0x0000, 0x0000 }, /* R19 */
125 { 0x0000, 0x0000 }, /* R20 */
126 { 0x01C0, 0x01C0 }, /* R21 - Input Mixer (1) */
127 { 0x0000, 0x0000 }, /* R22 */
128 { 0x0000, 0x0000 }, /* R23 */
129 { 0x00DF, 0x01DF }, /* R24 - Left Line Input 1&2 Volume */
130 { 0x00DF, 0x01DF }, /* R25 - Left Line Input 3&4 Volume */
131 { 0x00DF, 0x01DF }, /* R26 - Right Line Input 1&2 Volume */
132 { 0x00DF, 0x01DF }, /* R27 - Right Line Input 3&4 Volume */
133 { 0x00FF, 0x01FF }, /* R28 - Left Output Volume */
134 { 0x00FF, 0x01FF }, /* R29 - Right Output Volume */
135 { 0x0077, 0x0077 }, /* R30 - Line Outputs Volume */
136 { 0x0030, 0x0030 }, /* R31 - HPOUT2 Volume */
137 { 0x00FF, 0x01FF }, /* R32 - Left OPGA Volume */
138 { 0x00FF, 0x01FF }, /* R33 - Right OPGA Volume */
139 { 0x007F, 0x007F }, /* R34 - SPKMIXL Attenuation */
140 { 0x017F, 0x017F }, /* R35 - SPKMIXR Attenuation */
141 { 0x003F, 0x003F }, /* R36 - SPKOUT Mixers */
142 { 0x003F, 0x003F }, /* R37 - ClassD */
143 { 0x00FF, 0x01FF }, /* R38 - Speaker Volume Left */
144 { 0x00FF, 0x01FF }, /* R39 - Speaker Volume Right */
145 { 0x00FF, 0x00FF }, /* R40 - Input Mixer (2) */
146 { 0x01B7, 0x01B7 }, /* R41 - Input Mixer (3) */
147 { 0x01B7, 0x01B7 }, /* R42 - Input Mixer (4) */
148 { 0x01C7, 0x01C7 }, /* R43 - Input Mixer (5) */
149 { 0x01C7, 0x01C7 }, /* R44 - Input Mixer (6) */
150 { 0x01FF, 0x01FF }, /* R45 - Output Mixer (1) */
151 { 0x01FF, 0x01FF }, /* R46 - Output Mixer (2) */
152 { 0x0FFF, 0x0FFF }, /* R47 - Output Mixer (3) */
153 { 0x0FFF, 0x0FFF }, /* R48 - Output Mixer (4) */
154 { 0x0FFF, 0x0FFF }, /* R49 - Output Mixer (5) */
155 { 0x0FFF, 0x0FFF }, /* R50 - Output Mixer (6) */
156 { 0x0038, 0x0038 }, /* R51 - HPOUT2 Mixer */
157 { 0x0077, 0x0077 }, /* R52 - Line Mixer (1) */
158 { 0x0077, 0x0077 }, /* R53 - Line Mixer (2) */
159 { 0x03FF, 0x03FF }, /* R54 - Speaker Mixer */
160 { 0x00C1, 0x00C1 }, /* R55 - Additional Control */
161 { 0x00F0, 0x00F0 }, /* R56 - AntiPOP (1) */
162 { 0x01EF, 0x01EF }, /* R57 - AntiPOP (2) */
163 { 0x00FF, 0x00FF }, /* R58 - MICBIAS */
164 { 0x000F, 0x000F }, /* R59 - LDO 1 */
165 { 0x0007, 0x0007 }, /* R60 - LDO 2 */
166 { 0x0000, 0x0000 }, /* R61 */
167 { 0x0000, 0x0000 }, /* R62 */
168 { 0x0000, 0x0000 }, /* R63 */
169 { 0x0000, 0x0000 }, /* R64 */
170 { 0x0000, 0x0000 }, /* R65 */
171 { 0x0000, 0x0000 }, /* R66 */
172 { 0x0000, 0x0000 }, /* R67 */
173 { 0x0000, 0x0000 }, /* R68 */
174 { 0x0000, 0x0000 }, /* R69 */
175 { 0x0000, 0x0000 }, /* R70 */
176 { 0x0000, 0x0000 }, /* R71 */
177 { 0x0000, 0x0000 }, /* R72 */
178 { 0x0000, 0x0000 }, /* R73 */
179 { 0x0000, 0x0000 }, /* R74 */
180 { 0x0000, 0x0000 }, /* R75 */
181 { 0x8000, 0x8000 }, /* R76 - Charge Pump (1) */
182 { 0x0000, 0x0000 }, /* R77 */
183 { 0x0000, 0x0000 }, /* R78 */
184 { 0x0000, 0x0000 }, /* R79 */
185 { 0x0000, 0x0000 }, /* R80 */
186 { 0x0301, 0x0301 }, /* R81 - Class W (1) */
187 { 0x0000, 0x0000 }, /* R82 */
188 { 0x0000, 0x0000 }, /* R83 */
189 { 0x333F, 0x333F }, /* R84 - DC Servo (1) */
190 { 0x0FEF, 0x0FEF }, /* R85 - DC Servo (2) */
191 { 0x0000, 0x0000 }, /* R86 */
192 { 0xFFFF, 0xFFFF }, /* R87 - DC Servo (4) */
193 { 0x0333, 0x0000 }, /* R88 - DC Servo Readback */
194 { 0x0000, 0x0000 }, /* R89 */
195 { 0x0000, 0x0000 }, /* R90 */
196 { 0x0000, 0x0000 }, /* R91 */
197 { 0x0000, 0x0000 }, /* R92 */
198 { 0x0000, 0x0000 }, /* R93 */
199 { 0x0000, 0x0000 }, /* R94 */
200 { 0x0000, 0x0000 }, /* R95 */
201 { 0x00EE, 0x00EE }, /* R96 - Analogue HP (1) */
202 { 0x0000, 0x0000 }, /* R97 */
203 { 0x0000, 0x0000 }, /* R98 */
204 { 0x0000, 0x0000 }, /* R99 */
205 { 0x0000, 0x0000 }, /* R100 */
206 { 0x0000, 0x0000 }, /* R101 */
207 { 0x0000, 0x0000 }, /* R102 */
208 { 0x0000, 0x0000 }, /* R103 */
209 { 0x0000, 0x0000 }, /* R104 */
210 { 0x0000, 0x0000 }, /* R105 */
211 { 0x0000, 0x0000 }, /* R106 */
212 { 0x0000, 0x0000 }, /* R107 */
213 { 0x0000, 0x0000 }, /* R108 */
214 { 0x0000, 0x0000 }, /* R109 */
215 { 0x0000, 0x0000 }, /* R110 */
216 { 0x0000, 0x0000 }, /* R111 */
217 { 0x0000, 0x0000 }, /* R112 */
218 { 0x0000, 0x0000 }, /* R113 */
219 { 0x0000, 0x0000 }, /* R114 */
220 { 0x0000, 0x0000 }, /* R115 */
221 { 0x0000, 0x0000 }, /* R116 */
222 { 0x0000, 0x0000 }, /* R117 */
223 { 0x0000, 0x0000 }, /* R118 */
224 { 0x0000, 0x0000 }, /* R119 */
225 { 0x0000, 0x0000 }, /* R120 */
226 { 0x0000, 0x0000 }, /* R121 */
227 { 0x0000, 0x0000 }, /* R122 */
228 { 0x0000, 0x0000 }, /* R123 */
229 { 0x0000, 0x0000 }, /* R124 */
230 { 0x0000, 0x0000 }, /* R125 */
231 { 0x0000, 0x0000 }, /* R126 */
232 { 0x0000, 0x0000 }, /* R127 */
233 { 0x0000, 0x0000 }, /* R128 */
234 { 0x0000, 0x0000 }, /* R129 */
235 { 0x0000, 0x0000 }, /* R130 */
236 { 0x0000, 0x0000 }, /* R131 */
237 { 0x0000, 0x0000 }, /* R132 */
238 { 0x0000, 0x0000 }, /* R133 */
239 { 0x0000, 0x0000 }, /* R134 */
240 { 0x0000, 0x0000 }, /* R135 */
241 { 0x0000, 0x0000 }, /* R136 */
242 { 0x0000, 0x0000 }, /* R137 */
243 { 0x0000, 0x0000 }, /* R138 */
244 { 0x0000, 0x0000 }, /* R139 */
245 { 0x0000, 0x0000 }, /* R140 */
246 { 0x0000, 0x0000 }, /* R141 */
247 { 0x0000, 0x0000 }, /* R142 */
248 { 0x0000, 0x0000 }, /* R143 */
249 { 0x0000, 0x0000 }, /* R144 */
250 { 0x0000, 0x0000 }, /* R145 */
251 { 0x0000, 0x0000 }, /* R146 */
252 { 0x0000, 0x0000 }, /* R147 */
253 { 0x0000, 0x0000 }, /* R148 */
254 { 0x0000, 0x0000 }, /* R149 */
255 { 0x0000, 0x0000 }, /* R150 */
256 { 0x0000, 0x0000 }, /* R151 */
257 { 0x0000, 0x0000 }, /* R152 */
258 { 0x0000, 0x0000 }, /* R153 */
259 { 0x0000, 0x0000 }, /* R154 */
260 { 0x0000, 0x0000 }, /* R155 */
261 { 0x0000, 0x0000 }, /* R156 */
262 { 0x0000, 0x0000 }, /* R157 */
263 { 0x0000, 0x0000 }, /* R158 */
264 { 0x0000, 0x0000 }, /* R159 */
265 { 0x0000, 0x0000 }, /* R160 */
266 { 0x0000, 0x0000 }, /* R161 */
267 { 0x0000, 0x0000 }, /* R162 */
268 { 0x0000, 0x0000 }, /* R163 */
269 { 0x0000, 0x0000 }, /* R164 */
270 { 0x0000, 0x0000 }, /* R165 */
271 { 0x0000, 0x0000 }, /* R166 */
272 { 0x0000, 0x0000 }, /* R167 */
273 { 0x0000, 0x0000 }, /* R168 */
274 { 0x0000, 0x0000 }, /* R169 */
275 { 0x0000, 0x0000 }, /* R170 */
276 { 0x0000, 0x0000 }, /* R171 */
277 { 0x0000, 0x0000 }, /* R172 */
278 { 0x0000, 0x0000 }, /* R173 */
279 { 0x0000, 0x0000 }, /* R174 */
280 { 0x0000, 0x0000 }, /* R175 */
281 { 0x0000, 0x0000 }, /* R176 */
282 { 0x0000, 0x0000 }, /* R177 */
283 { 0x0000, 0x0000 }, /* R178 */
284 { 0x0000, 0x0000 }, /* R179 */
285 { 0x0000, 0x0000 }, /* R180 */
286 { 0x0000, 0x0000 }, /* R181 */
287 { 0x0000, 0x0000 }, /* R182 */
288 { 0x0000, 0x0000 }, /* R183 */
289 { 0x0000, 0x0000 }, /* R184 */
290 { 0x0000, 0x0000 }, /* R185 */
291 { 0x0000, 0x0000 }, /* R186 */
292 { 0x0000, 0x0000 }, /* R187 */
293 { 0x0000, 0x0000 }, /* R188 */
294 { 0x0000, 0x0000 }, /* R189 */
295 { 0x0000, 0x0000 }, /* R190 */
296 { 0x0000, 0x0000 }, /* R191 */
297 { 0x0000, 0x0000 }, /* R192 */
298 { 0x0000, 0x0000 }, /* R193 */
299 { 0x0000, 0x0000 }, /* R194 */
300 { 0x0000, 0x0000 }, /* R195 */
301 { 0x0000, 0x0000 }, /* R196 */
302 { 0x0000, 0x0000 }, /* R197 */
303 { 0x0000, 0x0000 }, /* R198 */
304 { 0x0000, 0x0000 }, /* R199 */
305 { 0x0000, 0x0000 }, /* R200 */
306 { 0x0000, 0x0000 }, /* R201 */
307 { 0x0000, 0x0000 }, /* R202 */
308 { 0x0000, 0x0000 }, /* R203 */
309 { 0x0000, 0x0000 }, /* R204 */
310 { 0x0000, 0x0000 }, /* R205 */
311 { 0x0000, 0x0000 }, /* R206 */
312 { 0x0000, 0x0000 }, /* R207 */
313 { 0x0000, 0x0000 }, /* R208 */
314 { 0x0000, 0x0000 }, /* R209 */
315 { 0x0000, 0x0000 }, /* R210 */
316 { 0x0000, 0x0000 }, /* R211 */
317 { 0x0000, 0x0000 }, /* R212 */
318 { 0x0000, 0x0000 }, /* R213 */
319 { 0x0000, 0x0000 }, /* R214 */
320 { 0x0000, 0x0000 }, /* R215 */
321 { 0x0000, 0x0000 }, /* R216 */
322 { 0x0000, 0x0000 }, /* R217 */
323 { 0x0000, 0x0000 }, /* R218 */
324 { 0x0000, 0x0000 }, /* R219 */
325 { 0x0000, 0x0000 }, /* R220 */
326 { 0x0000, 0x0000 }, /* R221 */
327 { 0x0000, 0x0000 }, /* R222 */
328 { 0x0000, 0x0000 }, /* R223 */
329 { 0x0000, 0x0000 }, /* R224 */
330 { 0x0000, 0x0000 }, /* R225 */
331 { 0x0000, 0x0000 }, /* R226 */
332 { 0x0000, 0x0000 }, /* R227 */
333 { 0x0000, 0x0000 }, /* R228 */
334 { 0x0000, 0x0000 }, /* R229 */
335 { 0x0000, 0x0000 }, /* R230 */
336 { 0x0000, 0x0000 }, /* R231 */
337 { 0x0000, 0x0000 }, /* R232 */
338 { 0x0000, 0x0000 }, /* R233 */
339 { 0x0000, 0x0000 }, /* R234 */
340 { 0x0000, 0x0000 }, /* R235 */
341 { 0x0000, 0x0000 }, /* R236 */
342 { 0x0000, 0x0000 }, /* R237 */
343 { 0x0000, 0x0000 }, /* R238 */
344 { 0x0000, 0x0000 }, /* R239 */
345 { 0x0000, 0x0000 }, /* R240 */
346 { 0x0000, 0x0000 }, /* R241 */
347 { 0x0000, 0x0000 }, /* R242 */
348 { 0x0000, 0x0000 }, /* R243 */
349 { 0x0000, 0x0000 }, /* R244 */
350 { 0x0000, 0x0000 }, /* R245 */
351 { 0x0000, 0x0000 }, /* R246 */
352 { 0x0000, 0x0000 }, /* R247 */
353 { 0x0000, 0x0000 }, /* R248 */
354 { 0x0000, 0x0000 }, /* R249 */
355 { 0x0000, 0x0000 }, /* R250 */
356 { 0x0000, 0x0000 }, /* R251 */
357 { 0x0000, 0x0000 }, /* R252 */
358 { 0x0000, 0x0000 }, /* R253 */
359 { 0x0000, 0x0000 }, /* R254 */
360 { 0x0000, 0x0000 }, /* R255 */
361 { 0x000F, 0x0000 }, /* R256 - Chip Revision */
362 { 0x0074, 0x0074 }, /* R257 - Control Interface */
363 { 0x0000, 0x0000 }, /* R258 */
364 { 0x0000, 0x0000 }, /* R259 */
365 { 0x0000, 0x0000 }, /* R260 */
366 { 0x0000, 0x0000 }, /* R261 */
367 { 0x0000, 0x0000 }, /* R262 */
368 { 0x0000, 0x0000 }, /* R263 */
369 { 0x0000, 0x0000 }, /* R264 */
370 { 0x0000, 0x0000 }, /* R265 */
371 { 0x0000, 0x0000 }, /* R266 */
372 { 0x0000, 0x0000 }, /* R267 */
373 { 0x0000, 0x0000 }, /* R268 */
374 { 0x0000, 0x0000 }, /* R269 */
375 { 0x0000, 0x0000 }, /* R270 */
376 { 0x0000, 0x0000 }, /* R271 */
377 { 0x807F, 0x837F }, /* R272 - Write Sequencer Ctrl (1) */
378 { 0x017F, 0x0000 }, /* R273 - Write Sequencer Ctrl (2) */
379 { 0x0000, 0x0000 }, /* R274 */
380 { 0x0000, 0x0000 }, /* R275 */
381 { 0x0000, 0x0000 }, /* R276 */
382 { 0x0000, 0x0000 }, /* R277 */
383 { 0x0000, 0x0000 }, /* R278 */
384 { 0x0000, 0x0000 }, /* R279 */
385 { 0x0000, 0x0000 }, /* R280 */
386 { 0x0000, 0x0000 }, /* R281 */
387 { 0x0000, 0x0000 }, /* R282 */
388 { 0x0000, 0x0000 }, /* R283 */
389 { 0x0000, 0x0000 }, /* R284 */
390 { 0x0000, 0x0000 }, /* R285 */
391 { 0x0000, 0x0000 }, /* R286 */
392 { 0x0000, 0x0000 }, /* R287 */
393 { 0x0000, 0x0000 }, /* R288 */
394 { 0x0000, 0x0000 }, /* R289 */
395 { 0x0000, 0x0000 }, /* R290 */
396 { 0x0000, 0x0000 }, /* R291 */
397 { 0x0000, 0x0000 }, /* R292 */
398 { 0x0000, 0x0000 }, /* R293 */
399 { 0x0000, 0x0000 }, /* R294 */
400 { 0x0000, 0x0000 }, /* R295 */
401 { 0x0000, 0x0000 }, /* R296 */
402 { 0x0000, 0x0000 }, /* R297 */
403 { 0x0000, 0x0000 }, /* R298 */
404 { 0x0000, 0x0000 }, /* R299 */
405 { 0x0000, 0x0000 }, /* R300 */
406 { 0x0000, 0x0000 }, /* R301 */
407 { 0x0000, 0x0000 }, /* R302 */
408 { 0x0000, 0x0000 }, /* R303 */
409 { 0x0000, 0x0000 }, /* R304 */
410 { 0x0000, 0x0000 }, /* R305 */
411 { 0x0000, 0x0000 }, /* R306 */
412 { 0x0000, 0x0000 }, /* R307 */
413 { 0x0000, 0x0000 }, /* R308 */
414 { 0x0000, 0x0000 }, /* R309 */
415 { 0x0000, 0x0000 }, /* R310 */
416 { 0x0000, 0x0000 }, /* R311 */
417 { 0x0000, 0x0000 }, /* R312 */
418 { 0x0000, 0x0000 }, /* R313 */
419 { 0x0000, 0x0000 }, /* R314 */
420 { 0x0000, 0x0000 }, /* R315 */
421 { 0x0000, 0x0000 }, /* R316 */
422 { 0x0000, 0x0000 }, /* R317 */
423 { 0x0000, 0x0000 }, /* R318 */
424 { 0x0000, 0x0000 }, /* R319 */
425 { 0x0000, 0x0000 }, /* R320 */
426 { 0x0000, 0x0000 }, /* R321 */
427 { 0x0000, 0x0000 }, /* R322 */
428 { 0x0000, 0x0000 }, /* R323 */
429 { 0x0000, 0x0000 }, /* R324 */
430 { 0x0000, 0x0000 }, /* R325 */
431 { 0x0000, 0x0000 }, /* R326 */
432 { 0x0000, 0x0000 }, /* R327 */
433 { 0x0000, 0x0000 }, /* R328 */
434 { 0x0000, 0x0000 }, /* R329 */
435 { 0x0000, 0x0000 }, /* R330 */
436 { 0x0000, 0x0000 }, /* R331 */
437 { 0x0000, 0x0000 }, /* R332 */
438 { 0x0000, 0x0000 }, /* R333 */
439 { 0x0000, 0x0000 }, /* R334 */
440 { 0x0000, 0x0000 }, /* R335 */
441 { 0x0000, 0x0000 }, /* R336 */
442 { 0x0000, 0x0000 }, /* R337 */
443 { 0x0000, 0x0000 }, /* R338 */
444 { 0x0000, 0x0000 }, /* R339 */
445 { 0x0000, 0x0000 }, /* R340 */
446 { 0x0000, 0x0000 }, /* R341 */
447 { 0x0000, 0x0000 }, /* R342 */
448 { 0x0000, 0x0000 }, /* R343 */
449 { 0x0000, 0x0000 }, /* R344 */
450 { 0x0000, 0x0000 }, /* R345 */
451 { 0x0000, 0x0000 }, /* R346 */
452 { 0x0000, 0x0000 }, /* R347 */
453 { 0x0000, 0x0000 }, /* R348 */
454 { 0x0000, 0x0000 }, /* R349 */
455 { 0x0000, 0x0000 }, /* R350 */
456 { 0x0000, 0x0000 }, /* R351 */
457 { 0x0000, 0x0000 }, /* R352 */
458 { 0x0000, 0x0000 }, /* R353 */
459 { 0x0000, 0x0000 }, /* R354 */
460 { 0x0000, 0x0000 }, /* R355 */
461 { 0x0000, 0x0000 }, /* R356 */
462 { 0x0000, 0x0000 }, /* R357 */
463 { 0x0000, 0x0000 }, /* R358 */
464 { 0x0000, 0x0000 }, /* R359 */
465 { 0x0000, 0x0000 }, /* R360 */
466 { 0x0000, 0x0000 }, /* R361 */
467 { 0x0000, 0x0000 }, /* R362 */
468 { 0x0000, 0x0000 }, /* R363 */
469 { 0x0000, 0x0000 }, /* R364 */
470 { 0x0000, 0x0000 }, /* R365 */
471 { 0x0000, 0x0000 }, /* R366 */
472 { 0x0000, 0x0000 }, /* R367 */
473 { 0x0000, 0x0000 }, /* R368 */
474 { 0x0000, 0x0000 }, /* R369 */
475 { 0x0000, 0x0000 }, /* R370 */
476 { 0x0000, 0x0000 }, /* R371 */
477 { 0x0000, 0x0000 }, /* R372 */
478 { 0x0000, 0x0000 }, /* R373 */
479 { 0x0000, 0x0000 }, /* R374 */
480 { 0x0000, 0x0000 }, /* R375 */
481 { 0x0000, 0x0000 }, /* R376 */
482 { 0x0000, 0x0000 }, /* R377 */
483 { 0x0000, 0x0000 }, /* R378 */
484 { 0x0000, 0x0000 }, /* R379 */
485 { 0x0000, 0x0000 }, /* R380 */
486 { 0x0000, 0x0000 }, /* R381 */
487 { 0x0000, 0x0000 }, /* R382 */
488 { 0x0000, 0x0000 }, /* R383 */
489 { 0x0000, 0x0000 }, /* R384 */
490 { 0x0000, 0x0000 }, /* R385 */
491 { 0x0000, 0x0000 }, /* R386 */
492 { 0x0000, 0x0000 }, /* R387 */
493 { 0x0000, 0x0000 }, /* R388 */
494 { 0x0000, 0x0000 }, /* R389 */
495 { 0x0000, 0x0000 }, /* R390 */
496 { 0x0000, 0x0000 }, /* R391 */
497 { 0x0000, 0x0000 }, /* R392 */
498 { 0x0000, 0x0000 }, /* R393 */
499 { 0x0000, 0x0000 }, /* R394 */
500 { 0x0000, 0x0000 }, /* R395 */
501 { 0x0000, 0x0000 }, /* R396 */
502 { 0x0000, 0x0000 }, /* R397 */
503 { 0x0000, 0x0000 }, /* R398 */
504 { 0x0000, 0x0000 }, /* R399 */
505 { 0x0000, 0x0000 }, /* R400 */
506 { 0x0000, 0x0000 }, /* R401 */
507 { 0x0000, 0x0000 }, /* R402 */
508 { 0x0000, 0x0000 }, /* R403 */
509 { 0x0000, 0x0000 }, /* R404 */
510 { 0x0000, 0x0000 }, /* R405 */
511 { 0x0000, 0x0000 }, /* R406 */
512 { 0x0000, 0x0000 }, /* R407 */
513 { 0x0000, 0x0000 }, /* R408 */
514 { 0x0000, 0x0000 }, /* R409 */
515 { 0x0000, 0x0000 }, /* R410 */
516 { 0x0000, 0x0000 }, /* R411 */
517 { 0x0000, 0x0000 }, /* R412 */
518 { 0x0000, 0x0000 }, /* R413 */
519 { 0x0000, 0x0000 }, /* R414 */
520 { 0x0000, 0x0000 }, /* R415 */
521 { 0x0000, 0x0000 }, /* R416 */
522 { 0x0000, 0x0000 }, /* R417 */
523 { 0x0000, 0x0000 }, /* R418 */
524 { 0x0000, 0x0000 }, /* R419 */
525 { 0x0000, 0x0000 }, /* R420 */
526 { 0x0000, 0x0000 }, /* R421 */
527 { 0x0000, 0x0000 }, /* R422 */
528 { 0x0000, 0x0000 }, /* R423 */
529 { 0x0000, 0x0000 }, /* R424 */
530 { 0x0000, 0x0000 }, /* R425 */
531 { 0x0000, 0x0000 }, /* R426 */
532 { 0x0000, 0x0000 }, /* R427 */
533 { 0x0000, 0x0000 }, /* R428 */
534 { 0x0000, 0x0000 }, /* R429 */
535 { 0x0000, 0x0000 }, /* R430 */
536 { 0x0000, 0x0000 }, /* R431 */
537 { 0x0000, 0x0000 }, /* R432 */
538 { 0x0000, 0x0000 }, /* R433 */
539 { 0x0000, 0x0000 }, /* R434 */
540 { 0x0000, 0x0000 }, /* R435 */
541 { 0x0000, 0x0000 }, /* R436 */
542 { 0x0000, 0x0000 }, /* R437 */
543 { 0x0000, 0x0000 }, /* R438 */
544 { 0x0000, 0x0000 }, /* R439 */
545 { 0x0000, 0x0000 }, /* R440 */
546 { 0x0000, 0x0000 }, /* R441 */
547 { 0x0000, 0x0000 }, /* R442 */
548 { 0x0000, 0x0000 }, /* R443 */
549 { 0x0000, 0x0000 }, /* R444 */
550 { 0x0000, 0x0000 }, /* R445 */
551 { 0x0000, 0x0000 }, /* R446 */
552 { 0x0000, 0x0000 }, /* R447 */
553 { 0x0000, 0x0000 }, /* R448 */
554 { 0x0000, 0x0000 }, /* R449 */
555 { 0x0000, 0x0000 }, /* R450 */
556 { 0x0000, 0x0000 }, /* R451 */
557 { 0x0000, 0x0000 }, /* R452 */
558 { 0x0000, 0x0000 }, /* R453 */
559 { 0x0000, 0x0000 }, /* R454 */
560 { 0x0000, 0x0000 }, /* R455 */
561 { 0x0000, 0x0000 }, /* R456 */
562 { 0x0000, 0x0000 }, /* R457 */
563 { 0x0000, 0x0000 }, /* R458 */
564 { 0x0000, 0x0000 }, /* R459 */
565 { 0x0000, 0x0000 }, /* R460 */
566 { 0x0000, 0x0000 }, /* R461 */
567 { 0x0000, 0x0000 }, /* R462 */
568 { 0x0000, 0x0000 }, /* R463 */
569 { 0x0000, 0x0000 }, /* R464 */
570 { 0x0000, 0x0000 }, /* R465 */
571 { 0x0000, 0x0000 }, /* R466 */
572 { 0x0000, 0x0000 }, /* R467 */
573 { 0x0000, 0x0000 }, /* R468 */
574 { 0x0000, 0x0000 }, /* R469 */
575 { 0x0000, 0x0000 }, /* R470 */
576 { 0x0000, 0x0000 }, /* R471 */
577 { 0x0000, 0x0000 }, /* R472 */
578 { 0x0000, 0x0000 }, /* R473 */
579 { 0x0000, 0x0000 }, /* R474 */
580 { 0x0000, 0x0000 }, /* R475 */
581 { 0x0000, 0x0000 }, /* R476 */
582 { 0x0000, 0x0000 }, /* R477 */
583 { 0x0000, 0x0000 }, /* R478 */
584 { 0x0000, 0x0000 }, /* R479 */
585 { 0x0000, 0x0000 }, /* R480 */
586 { 0x0000, 0x0000 }, /* R481 */
587 { 0x0000, 0x0000 }, /* R482 */
588 { 0x0000, 0x0000 }, /* R483 */
589 { 0x0000, 0x0000 }, /* R484 */
590 { 0x0000, 0x0000 }, /* R485 */
591 { 0x0000, 0x0000 }, /* R486 */
592 { 0x0000, 0x0000 }, /* R487 */
593 { 0x0000, 0x0000 }, /* R488 */
594 { 0x0000, 0x0000 }, /* R489 */
595 { 0x0000, 0x0000 }, /* R490 */
596 { 0x0000, 0x0000 }, /* R491 */
597 { 0x0000, 0x0000 }, /* R492 */
598 { 0x0000, 0x0000 }, /* R493 */
599 { 0x0000, 0x0000 }, /* R494 */
600 { 0x0000, 0x0000 }, /* R495 */
601 { 0x0000, 0x0000 }, /* R496 */
602 { 0x0000, 0x0000 }, /* R497 */
603 { 0x0000, 0x0000 }, /* R498 */
604 { 0x0000, 0x0000 }, /* R499 */
605 { 0x0000, 0x0000 }, /* R500 */
606 { 0x0000, 0x0000 }, /* R501 */
607 { 0x0000, 0x0000 }, /* R502 */
608 { 0x0000, 0x0000 }, /* R503 */
609 { 0x0000, 0x0000 }, /* R504 */
610 { 0x0000, 0x0000 }, /* R505 */
611 { 0x0000, 0x0000 }, /* R506 */
612 { 0x0000, 0x0000 }, /* R507 */
613 { 0x0000, 0x0000 }, /* R508 */
614 { 0x0000, 0x0000 }, /* R509 */
615 { 0x0000, 0x0000 }, /* R510 */
616 { 0x0000, 0x0000 }, /* R511 */
617 { 0x001F, 0x001F }, /* R512 - AIF1 Clocking (1) */
618 { 0x003F, 0x003F }, /* R513 - AIF1 Clocking (2) */
619 { 0x0000, 0x0000 }, /* R514 */
620 { 0x0000, 0x0000 }, /* R515 */
621 { 0x001F, 0x001F }, /* R516 - AIF2 Clocking (1) */
622 { 0x003F, 0x003F }, /* R517 - AIF2 Clocking (2) */
623 { 0x0000, 0x0000 }, /* R518 */
624 { 0x0000, 0x0000 }, /* R519 */
625 { 0x001F, 0x001F }, /* R520 - Clocking (1) */
626 { 0x0777, 0x0777 }, /* R521 - Clocking (2) */
627 { 0x0000, 0x0000 }, /* R522 */
628 { 0x0000, 0x0000 }, /* R523 */
629 { 0x0000, 0x0000 }, /* R524 */
630 { 0x0000, 0x0000 }, /* R525 */
631 { 0x0000, 0x0000 }, /* R526 */
632 { 0x0000, 0x0000 }, /* R527 */
633 { 0x00FF, 0x00FF }, /* R528 - AIF1 Rate */
634 { 0x00FF, 0x00FF }, /* R529 - AIF2 Rate */
635 { 0x000F, 0x0000 }, /* R530 - Rate Status */
636 { 0x0000, 0x0000 }, /* R531 */
637 { 0x0000, 0x0000 }, /* R532 */
638 { 0x0000, 0x0000 }, /* R533 */
639 { 0x0000, 0x0000 }, /* R534 */
640 { 0x0000, 0x0000 }, /* R535 */
641 { 0x0000, 0x0000 }, /* R536 */
642 { 0x0000, 0x0000 }, /* R537 */
643 { 0x0000, 0x0000 }, /* R538 */
644 { 0x0000, 0x0000 }, /* R539 */
645 { 0x0000, 0x0000 }, /* R540 */
646 { 0x0000, 0x0000 }, /* R541 */
647 { 0x0000, 0x0000 }, /* R542 */
648 { 0x0000, 0x0000 }, /* R543 */
649 { 0x0007, 0x0007 }, /* R544 - FLL1 Control (1) */
650 { 0x3F77, 0x3F77 }, /* R545 - FLL1 Control (2) */
651 { 0xFFFF, 0xFFFF }, /* R546 - FLL1 Control (3) */
652 { 0x7FEF, 0x7FEF }, /* R547 - FLL1 Control (4) */
653 { 0x1FDB, 0x1FDB }, /* R548 - FLL1 Control (5) */
654 { 0x0000, 0x0000 }, /* R549 */
655 { 0x0000, 0x0000 }, /* R550 */
656 { 0x0000, 0x0000 }, /* R551 */
657 { 0x0000, 0x0000 }, /* R552 */
658 { 0x0000, 0x0000 }, /* R553 */
659 { 0x0000, 0x0000 }, /* R554 */
660 { 0x0000, 0x0000 }, /* R555 */
661 { 0x0000, 0x0000 }, /* R556 */
662 { 0x0000, 0x0000 }, /* R557 */
663 { 0x0000, 0x0000 }, /* R558 */
664 { 0x0000, 0x0000 }, /* R559 */
665 { 0x0000, 0x0000 }, /* R560 */
666 { 0x0000, 0x0000 }, /* R561 */
667 { 0x0000, 0x0000 }, /* R562 */
668 { 0x0000, 0x0000 }, /* R563 */
669 { 0x0000, 0x0000 }, /* R564 */
670 { 0x0000, 0x0000 }, /* R565 */
671 { 0x0000, 0x0000 }, /* R566 */
672 { 0x0000, 0x0000 }, /* R567 */
673 { 0x0000, 0x0000 }, /* R568 */
674 { 0x0000, 0x0000 }, /* R569 */
675 { 0x0000, 0x0000 }, /* R570 */
676 { 0x0000, 0x0000 }, /* R571 */
677 { 0x0000, 0x0000 }, /* R572 */
678 { 0x0000, 0x0000 }, /* R573 */
679 { 0x0000, 0x0000 }, /* R574 */
680 { 0x0000, 0x0000 }, /* R575 */
681 { 0x0007, 0x0007 }, /* R576 - FLL2 Control (1) */
682 { 0x3F77, 0x3F77 }, /* R577 - FLL2 Control (2) */
683 { 0xFFFF, 0xFFFF }, /* R578 - FLL2 Control (3) */
684 { 0x7FEF, 0x7FEF }, /* R579 - FLL2 Control (4) */
685 { 0x1FDB, 0x1FDB }, /* R580 - FLL2 Control (5) */
686 { 0x0000, 0x0000 }, /* R581 */
687 { 0x0000, 0x0000 }, /* R582 */
688 { 0x0000, 0x0000 }, /* R583 */
689 { 0x0000, 0x0000 }, /* R584 */
690 { 0x0000, 0x0000 }, /* R585 */
691 { 0x0000, 0x0000 }, /* R586 */
692 { 0x0000, 0x0000 }, /* R587 */
693 { 0x0000, 0x0000 }, /* R588 */
694 { 0x0000, 0x0000 }, /* R589 */
695 { 0x0000, 0x0000 }, /* R590 */
696 { 0x0000, 0x0000 }, /* R591 */
697 { 0x0000, 0x0000 }, /* R592 */
698 { 0x0000, 0x0000 }, /* R593 */
699 { 0x0000, 0x0000 }, /* R594 */
700 { 0x0000, 0x0000 }, /* R595 */
701 { 0x0000, 0x0000 }, /* R596 */
702 { 0x0000, 0x0000 }, /* R597 */
703 { 0x0000, 0x0000 }, /* R598 */
704 { 0x0000, 0x0000 }, /* R599 */
705 { 0x0000, 0x0000 }, /* R600 */
706 { 0x0000, 0x0000 }, /* R601 */
707 { 0x0000, 0x0000 }, /* R602 */
708 { 0x0000, 0x0000 }, /* R603 */
709 { 0x0000, 0x0000 }, /* R604 */
710 { 0x0000, 0x0000 }, /* R605 */
711 { 0x0000, 0x0000 }, /* R606 */
712 { 0x0000, 0x0000 }, /* R607 */
713 { 0x0000, 0x0000 }, /* R608 */
714 { 0x0000, 0x0000 }, /* R609 */
715 { 0x0000, 0x0000 }, /* R610 */
716 { 0x0000, 0x0000 }, /* R611 */
717 { 0x0000, 0x0000 }, /* R612 */
718 { 0x0000, 0x0000 }, /* R613 */
719 { 0x0000, 0x0000 }, /* R614 */
720 { 0x0000, 0x0000 }, /* R615 */
721 { 0x0000, 0x0000 }, /* R616 */
722 { 0x0000, 0x0000 }, /* R617 */
723 { 0x0000, 0x0000 }, /* R618 */
724 { 0x0000, 0x0000 }, /* R619 */
725 { 0x0000, 0x0000 }, /* R620 */
726 { 0x0000, 0x0000 }, /* R621 */
727 { 0x0000, 0x0000 }, /* R622 */
728 { 0x0000, 0x0000 }, /* R623 */
729 { 0x0000, 0x0000 }, /* R624 */
730 { 0x0000, 0x0000 }, /* R625 */
731 { 0x0000, 0x0000 }, /* R626 */
732 { 0x0000, 0x0000 }, /* R627 */
733 { 0x0000, 0x0000 }, /* R628 */
734 { 0x0000, 0x0000 }, /* R629 */
735 { 0x0000, 0x0000 }, /* R630 */
736 { 0x0000, 0x0000 }, /* R631 */
737 { 0x0000, 0x0000 }, /* R632 */
738 { 0x0000, 0x0000 }, /* R633 */
739 { 0x0000, 0x0000 }, /* R634 */
740 { 0x0000, 0x0000 }, /* R635 */
741 { 0x0000, 0x0000 }, /* R636 */
742 { 0x0000, 0x0000 }, /* R637 */
743 { 0x0000, 0x0000 }, /* R638 */
744 { 0x0000, 0x0000 }, /* R639 */
745 { 0x0000, 0x0000 }, /* R640 */
746 { 0x0000, 0x0000 }, /* R641 */
747 { 0x0000, 0x0000 }, /* R642 */
748 { 0x0000, 0x0000 }, /* R643 */
749 { 0x0000, 0x0000 }, /* R644 */
750 { 0x0000, 0x0000 }, /* R645 */
751 { 0x0000, 0x0000 }, /* R646 */
752 { 0x0000, 0x0000 }, /* R647 */
753 { 0x0000, 0x0000 }, /* R648 */
754 { 0x0000, 0x0000 }, /* R649 */
755 { 0x0000, 0x0000 }, /* R650 */
756 { 0x0000, 0x0000 }, /* R651 */
757 { 0x0000, 0x0000 }, /* R652 */
758 { 0x0000, 0x0000 }, /* R653 */
759 { 0x0000, 0x0000 }, /* R654 */
760 { 0x0000, 0x0000 }, /* R655 */
761 { 0x0000, 0x0000 }, /* R656 */
762 { 0x0000, 0x0000 }, /* R657 */
763 { 0x0000, 0x0000 }, /* R658 */
764 { 0x0000, 0x0000 }, /* R659 */
765 { 0x0000, 0x0000 }, /* R660 */
766 { 0x0000, 0x0000 }, /* R661 */
767 { 0x0000, 0x0000 }, /* R662 */
768 { 0x0000, 0x0000 }, /* R663 */
769 { 0x0000, 0x0000 }, /* R664 */
770 { 0x0000, 0x0000 }, /* R665 */
771 { 0x0000, 0x0000 }, /* R666 */
772 { 0x0000, 0x0000 }, /* R667 */
773 { 0x0000, 0x0000 }, /* R668 */
774 { 0x0000, 0x0000 }, /* R669 */
775 { 0x0000, 0x0000 }, /* R670 */
776 { 0x0000, 0x0000 }, /* R671 */
777 { 0x0000, 0x0000 }, /* R672 */
778 { 0x0000, 0x0000 }, /* R673 */
779 { 0x0000, 0x0000 }, /* R674 */
780 { 0x0000, 0x0000 }, /* R675 */
781 { 0x0000, 0x0000 }, /* R676 */
782 { 0x0000, 0x0000 }, /* R677 */
783 { 0x0000, 0x0000 }, /* R678 */
784 { 0x0000, 0x0000 }, /* R679 */
785 { 0x0000, 0x0000 }, /* R680 */
786 { 0x0000, 0x0000 }, /* R681 */
787 { 0x0000, 0x0000 }, /* R682 */
788 { 0x0000, 0x0000 }, /* R683 */
789 { 0x0000, 0x0000 }, /* R684 */
790 { 0x0000, 0x0000 }, /* R685 */
791 { 0x0000, 0x0000 }, /* R686 */
792 { 0x0000, 0x0000 }, /* R687 */
793 { 0x0000, 0x0000 }, /* R688 */
794 { 0x0000, 0x0000 }, /* R689 */
795 { 0x0000, 0x0000 }, /* R690 */
796 { 0x0000, 0x0000 }, /* R691 */
797 { 0x0000, 0x0000 }, /* R692 */
798 { 0x0000, 0x0000 }, /* R693 */
799 { 0x0000, 0x0000 }, /* R694 */
800 { 0x0000, 0x0000 }, /* R695 */
801 { 0x0000, 0x0000 }, /* R696 */
802 { 0x0000, 0x0000 }, /* R697 */
803 { 0x0000, 0x0000 }, /* R698 */
804 { 0x0000, 0x0000 }, /* R699 */
805 { 0x0000, 0x0000 }, /* R700 */
806 { 0x0000, 0x0000 }, /* R701 */
807 { 0x0000, 0x0000 }, /* R702 */
808 { 0x0000, 0x0000 }, /* R703 */
809 { 0x0000, 0x0000 }, /* R704 */
810 { 0x0000, 0x0000 }, /* R705 */
811 { 0x0000, 0x0000 }, /* R706 */
812 { 0x0000, 0x0000 }, /* R707 */
813 { 0x0000, 0x0000 }, /* R708 */
814 { 0x0000, 0x0000 }, /* R709 */
815 { 0x0000, 0x0000 }, /* R710 */
816 { 0x0000, 0x0000 }, /* R711 */
817 { 0x0000, 0x0000 }, /* R712 */
818 { 0x0000, 0x0000 }, /* R713 */
819 { 0x0000, 0x0000 }, /* R714 */
820 { 0x0000, 0x0000 }, /* R715 */
821 { 0x0000, 0x0000 }, /* R716 */
822 { 0x0000, 0x0000 }, /* R717 */
823 { 0x0000, 0x0000 }, /* R718 */
824 { 0x0000, 0x0000 }, /* R719 */
825 { 0x0000, 0x0000 }, /* R720 */
826 { 0x0000, 0x0000 }, /* R721 */
827 { 0x0000, 0x0000 }, /* R722 */
828 { 0x0000, 0x0000 }, /* R723 */
829 { 0x0000, 0x0000 }, /* R724 */
830 { 0x0000, 0x0000 }, /* R725 */
831 { 0x0000, 0x0000 }, /* R726 */
832 { 0x0000, 0x0000 }, /* R727 */
833 { 0x0000, 0x0000 }, /* R728 */
834 { 0x0000, 0x0000 }, /* R729 */
835 { 0x0000, 0x0000 }, /* R730 */
836 { 0x0000, 0x0000 }, /* R731 */
837 { 0x0000, 0x0000 }, /* R732 */
838 { 0x0000, 0x0000 }, /* R733 */
839 { 0x0000, 0x0000 }, /* R734 */
840 { 0x0000, 0x0000 }, /* R735 */
841 { 0x0000, 0x0000 }, /* R736 */
842 { 0x0000, 0x0000 }, /* R737 */
843 { 0x0000, 0x0000 }, /* R738 */
844 { 0x0000, 0x0000 }, /* R739 */
845 { 0x0000, 0x0000 }, /* R740 */
846 { 0x0000, 0x0000 }, /* R741 */
847 { 0x0000, 0x0000 }, /* R742 */
848 { 0x0000, 0x0000 }, /* R743 */
849 { 0x0000, 0x0000 }, /* R744 */
850 { 0x0000, 0x0000 }, /* R745 */
851 { 0x0000, 0x0000 }, /* R746 */
852 { 0x0000, 0x0000 }, /* R747 */
853 { 0x0000, 0x0000 }, /* R748 */
854 { 0x0000, 0x0000 }, /* R749 */
855 { 0x0000, 0x0000 }, /* R750 */
856 { 0x0000, 0x0000 }, /* R751 */
857 { 0x0000, 0x0000 }, /* R752 */
858 { 0x0000, 0x0000 }, /* R753 */
859 { 0x0000, 0x0000 }, /* R754 */
860 { 0x0000, 0x0000 }, /* R755 */
861 { 0x0000, 0x0000 }, /* R756 */
862 { 0x0000, 0x0000 }, /* R757 */
863 { 0x0000, 0x0000 }, /* R758 */
864 { 0x0000, 0x0000 }, /* R759 */
865 { 0x0000, 0x0000 }, /* R760 */
866 { 0x0000, 0x0000 }, /* R761 */
867 { 0x0000, 0x0000 }, /* R762 */
868 { 0x0000, 0x0000 }, /* R763 */
869 { 0x0000, 0x0000 }, /* R764 */
870 { 0x0000, 0x0000 }, /* R765 */
871 { 0x0000, 0x0000 }, /* R766 */
872 { 0x0000, 0x0000 }, /* R767 */
873 { 0xE1F8, 0xE1F8 }, /* R768 - AIF1 Control (1) */
874 { 0xCD1F, 0xCD1F }, /* R769 - AIF1 Control (2) */
875 { 0xF000, 0xF000 }, /* R770 - AIF1 Master/Slave */
876 { 0x01F0, 0x01F0 }, /* R771 - AIF1 BCLK */
877 { 0x0FFF, 0x0FFF }, /* R772 - AIF1ADC LRCLK */
878 { 0x0FFF, 0x0FFF }, /* R773 - AIF1DAC LRCLK */
879 { 0x0003, 0x0003 }, /* R774 - AIF1DAC Data */
880 { 0x0003, 0x0003 }, /* R775 - AIF1ADC Data */
881 { 0x0000, 0x0000 }, /* R776 */
882 { 0x0000, 0x0000 }, /* R777 */
883 { 0x0000, 0x0000 }, /* R778 */
884 { 0x0000, 0x0000 }, /* R779 */
885 { 0x0000, 0x0000 }, /* R780 */
886 { 0x0000, 0x0000 }, /* R781 */
887 { 0x0000, 0x0000 }, /* R782 */
888 { 0x0000, 0x0000 }, /* R783 */
889 { 0xF1F8, 0xF1F8 }, /* R784 - AIF2 Control (1) */
890 { 0xFD1F, 0xFD1F }, /* R785 - AIF2 Control (2) */
891 { 0xF000, 0xF000 }, /* R786 - AIF2 Master/Slave */
892 { 0x01F0, 0x01F0 }, /* R787 - AIF2 BCLK */
893 { 0x0FFF, 0x0FFF }, /* R788 - AIF2ADC LRCLK */
894 { 0x0FFF, 0x0FFF }, /* R789 - AIF2DAC LRCLK */
895 { 0x0003, 0x0003 }, /* R790 - AIF2DAC Data */
896 { 0x0003, 0x0003 }, /* R791 - AIF2ADC Data */
897 { 0x0000, 0x0000 }, /* R792 */
898 { 0x0000, 0x0000 }, /* R793 */
899 { 0x0000, 0x0000 }, /* R794 */
900 { 0x0000, 0x0000 }, /* R795 */
901 { 0x0000, 0x0000 }, /* R796 */
902 { 0x0000, 0x0000 }, /* R797 */
903 { 0x0000, 0x0000 }, /* R798 */
904 { 0x0000, 0x0000 }, /* R799 */
905 { 0x0000, 0x0000 }, /* R800 */
906 { 0x0000, 0x0000 }, /* R801 */
907 { 0x0000, 0x0000 }, /* R802 */
908 { 0x0000, 0x0000 }, /* R803 */
909 { 0x0000, 0x0000 }, /* R804 */
910 { 0x0000, 0x0000 }, /* R805 */
911 { 0x0000, 0x0000 }, /* R806 */
912 { 0x0000, 0x0000 }, /* R807 */
913 { 0x0000, 0x0000 }, /* R808 */
914 { 0x0000, 0x0000 }, /* R809 */
915 { 0x0000, 0x0000 }, /* R810 */
916 { 0x0000, 0x0000 }, /* R811 */
917 { 0x0000, 0x0000 }, /* R812 */
918 { 0x0000, 0x0000 }, /* R813 */
919 { 0x0000, 0x0000 }, /* R814 */
920 { 0x0000, 0x0000 }, /* R815 */
921 { 0x0000, 0x0000 }, /* R816 */
922 { 0x0000, 0x0000 }, /* R817 */
923 { 0x0000, 0x0000 }, /* R818 */
924 { 0x0000, 0x0000 }, /* R819 */
925 { 0x0000, 0x0000 }, /* R820 */
926 { 0x0000, 0x0000 }, /* R821 */
927 { 0x0000, 0x0000 }, /* R822 */
928 { 0x0000, 0x0000 }, /* R823 */
929 { 0x0000, 0x0000 }, /* R824 */
930 { 0x0000, 0x0000 }, /* R825 */
931 { 0x0000, 0x0000 }, /* R826 */
932 { 0x0000, 0x0000 }, /* R827 */
933 { 0x0000, 0x0000 }, /* R828 */
934 { 0x0000, 0x0000 }, /* R829 */
935 { 0x0000, 0x0000 }, /* R830 */
936 { 0x0000, 0x0000 }, /* R831 */
937 { 0x0000, 0x0000 }, /* R832 */
938 { 0x0000, 0x0000 }, /* R833 */
939 { 0x0000, 0x0000 }, /* R834 */
940 { 0x0000, 0x0000 }, /* R835 */
941 { 0x0000, 0x0000 }, /* R836 */
942 { 0x0000, 0x0000 }, /* R837 */
943 { 0x0000, 0x0000 }, /* R838 */
944 { 0x0000, 0x0000 }, /* R839 */
945 { 0x0000, 0x0000 }, /* R840 */
946 { 0x0000, 0x0000 }, /* R841 */
947 { 0x0000, 0x0000 }, /* R842 */
948 { 0x0000, 0x0000 }, /* R843 */
949 { 0x0000, 0x0000 }, /* R844 */
950 { 0x0000, 0x0000 }, /* R845 */
951 { 0x0000, 0x0000 }, /* R846 */
952 { 0x0000, 0x0000 }, /* R847 */
953 { 0x0000, 0x0000 }, /* R848 */
954 { 0x0000, 0x0000 }, /* R849 */
955 { 0x0000, 0x0000 }, /* R850 */
956 { 0x0000, 0x0000 }, /* R851 */
957 { 0x0000, 0x0000 }, /* R852 */
958 { 0x0000, 0x0000 }, /* R853 */
959 { 0x0000, 0x0000 }, /* R854 */
960 { 0x0000, 0x0000 }, /* R855 */
961 { 0x0000, 0x0000 }, /* R856 */
962 { 0x0000, 0x0000 }, /* R857 */
963 { 0x0000, 0x0000 }, /* R858 */
964 { 0x0000, 0x0000 }, /* R859 */
965 { 0x0000, 0x0000 }, /* R860 */
966 { 0x0000, 0x0000 }, /* R861 */
967 { 0x0000, 0x0000 }, /* R862 */
968 { 0x0000, 0x0000 }, /* R863 */
969 { 0x0000, 0x0000 }, /* R864 */
970 { 0x0000, 0x0000 }, /* R865 */
971 { 0x0000, 0x0000 }, /* R866 */
972 { 0x0000, 0x0000 }, /* R867 */
973 { 0x0000, 0x0000 }, /* R868 */
974 { 0x0000, 0x0000 }, /* R869 */
975 { 0x0000, 0x0000 }, /* R870 */
976 { 0x0000, 0x0000 }, /* R871 */
977 { 0x0000, 0x0000 }, /* R872 */
978 { 0x0000, 0x0000 }, /* R873 */
979 { 0x0000, 0x0000 }, /* R874 */
980 { 0x0000, 0x0000 }, /* R875 */
981 { 0x0000, 0x0000 }, /* R876 */
982 { 0x0000, 0x0000 }, /* R877 */
983 { 0x0000, 0x0000 }, /* R878 */
984 { 0x0000, 0x0000 }, /* R879 */
985 { 0x0000, 0x0000 }, /* R880 */
986 { 0x0000, 0x0000 }, /* R881 */
987 { 0x0000, 0x0000 }, /* R882 */
988 { 0x0000, 0x0000 }, /* R883 */
989 { 0x0000, 0x0000 }, /* R884 */
990 { 0x0000, 0x0000 }, /* R885 */
991 { 0x0000, 0x0000 }, /* R886 */
992 { 0x0000, 0x0000 }, /* R887 */
993 { 0x0000, 0x0000 }, /* R888 */
994 { 0x0000, 0x0000 }, /* R889 */
995 { 0x0000, 0x0000 }, /* R890 */
996 { 0x0000, 0x0000 }, /* R891 */
997 { 0x0000, 0x0000 }, /* R892 */
998 { 0x0000, 0x0000 }, /* R893 */
999 { 0x0000, 0x0000 }, /* R894 */
1000 { 0x0000, 0x0000 }, /* R895 */
1001 { 0x0000, 0x0000 }, /* R896 */
1002 { 0x0000, 0x0000 }, /* R897 */
1003 { 0x0000, 0x0000 }, /* R898 */
1004 { 0x0000, 0x0000 }, /* R899 */
1005 { 0x0000, 0x0000 }, /* R900 */
1006 { 0x0000, 0x0000 }, /* R901 */
1007 { 0x0000, 0x0000 }, /* R902 */
1008 { 0x0000, 0x0000 }, /* R903 */
1009 { 0x0000, 0x0000 }, /* R904 */
1010 { 0x0000, 0x0000 }, /* R905 */
1011 { 0x0000, 0x0000 }, /* R906 */
1012 { 0x0000, 0x0000 }, /* R907 */
1013 { 0x0000, 0x0000 }, /* R908 */
1014 { 0x0000, 0x0000 }, /* R909 */
1015 { 0x0000, 0x0000 }, /* R910 */
1016 { 0x0000, 0x0000 }, /* R911 */
1017 { 0x0000, 0x0000 }, /* R912 */
1018 { 0x0000, 0x0000 }, /* R913 */
1019 { 0x0000, 0x0000 }, /* R914 */
1020 { 0x0000, 0x0000 }, /* R915 */
1021 { 0x0000, 0x0000 }, /* R916 */
1022 { 0x0000, 0x0000 }, /* R917 */
1023 { 0x0000, 0x0000 }, /* R918 */
1024 { 0x0000, 0x0000 }, /* R919 */
1025 { 0x0000, 0x0000 }, /* R920 */
1026 { 0x0000, 0x0000 }, /* R921 */
1027 { 0x0000, 0x0000 }, /* R922 */
1028 { 0x0000, 0x0000 }, /* R923 */
1029 { 0x0000, 0x0000 }, /* R924 */
1030 { 0x0000, 0x0000 }, /* R925 */
1031 { 0x0000, 0x0000 }, /* R926 */
1032 { 0x0000, 0x0000 }, /* R927 */
1033 { 0x0000, 0x0000 }, /* R928 */
1034 { 0x0000, 0x0000 }, /* R929 */
1035 { 0x0000, 0x0000 }, /* R930 */
1036 { 0x0000, 0x0000 }, /* R931 */
1037 { 0x0000, 0x0000 }, /* R932 */
1038 { 0x0000, 0x0000 }, /* R933 */
1039 { 0x0000, 0x0000 }, /* R934 */
1040 { 0x0000, 0x0000 }, /* R935 */
1041 { 0x0000, 0x0000 }, /* R936 */
1042 { 0x0000, 0x0000 }, /* R937 */
1043 { 0x0000, 0x0000 }, /* R938 */
1044 { 0x0000, 0x0000 }, /* R939 */
1045 { 0x0000, 0x0000 }, /* R940 */
1046 { 0x0000, 0x0000 }, /* R941 */
1047 { 0x0000, 0x0000 }, /* R942 */
1048 { 0x0000, 0x0000 }, /* R943 */
1049 { 0x0000, 0x0000 }, /* R944 */
1050 { 0x0000, 0x0000 }, /* R945 */
1051 { 0x0000, 0x0000 }, /* R946 */
1052 { 0x0000, 0x0000 }, /* R947 */
1053 { 0x0000, 0x0000 }, /* R948 */
1054 { 0x0000, 0x0000 }, /* R949 */
1055 { 0x0000, 0x0000 }, /* R950 */
1056 { 0x0000, 0x0000 }, /* R951 */
1057 { 0x0000, 0x0000 }, /* R952 */
1058 { 0x0000, 0x0000 }, /* R953 */
1059 { 0x0000, 0x0000 }, /* R954 */
1060 { 0x0000, 0x0000 }, /* R955 */
1061 { 0x0000, 0x0000 }, /* R956 */
1062 { 0x0000, 0x0000 }, /* R957 */
1063 { 0x0000, 0x0000 }, /* R958 */
1064 { 0x0000, 0x0000 }, /* R959 */
1065 { 0x0000, 0x0000 }, /* R960 */
1066 { 0x0000, 0x0000 }, /* R961 */
1067 { 0x0000, 0x0000 }, /* R962 */
1068 { 0x0000, 0x0000 }, /* R963 */
1069 { 0x0000, 0x0000 }, /* R964 */
1070 { 0x0000, 0x0000 }, /* R965 */
1071 { 0x0000, 0x0000 }, /* R966 */
1072 { 0x0000, 0x0000 }, /* R967 */
1073 { 0x0000, 0x0000 }, /* R968 */
1074 { 0x0000, 0x0000 }, /* R969 */
1075 { 0x0000, 0x0000 }, /* R970 */
1076 { 0x0000, 0x0000 }, /* R971 */
1077 { 0x0000, 0x0000 }, /* R972 */
1078 { 0x0000, 0x0000 }, /* R973 */
1079 { 0x0000, 0x0000 }, /* R974 */
1080 { 0x0000, 0x0000 }, /* R975 */
1081 { 0x0000, 0x0000 }, /* R976 */
1082 { 0x0000, 0x0000 }, /* R977 */
1083 { 0x0000, 0x0000 }, /* R978 */
1084 { 0x0000, 0x0000 }, /* R979 */
1085 { 0x0000, 0x0000 }, /* R980 */
1086 { 0x0000, 0x0000 }, /* R981 */
1087 { 0x0000, 0x0000 }, /* R982 */
1088 { 0x0000, 0x0000 }, /* R983 */
1089 { 0x0000, 0x0000 }, /* R984 */
1090 { 0x0000, 0x0000 }, /* R985 */
1091 { 0x0000, 0x0000 }, /* R986 */
1092 { 0x0000, 0x0000 }, /* R987 */
1093 { 0x0000, 0x0000 }, /* R988 */
1094 { 0x0000, 0x0000 }, /* R989 */
1095 { 0x0000, 0x0000 }, /* R990 */
1096 { 0x0000, 0x0000 }, /* R991 */
1097 { 0x0000, 0x0000 }, /* R992 */
1098 { 0x0000, 0x0000 }, /* R993 */
1099 { 0x0000, 0x0000 }, /* R994 */
1100 { 0x0000, 0x0000 }, /* R995 */
1101 { 0x0000, 0x0000 }, /* R996 */
1102 { 0x0000, 0x0000 }, /* R997 */
1103 { 0x0000, 0x0000 }, /* R998 */
1104 { 0x0000, 0x0000 }, /* R999 */
1105 { 0x0000, 0x0000 }, /* R1000 */
1106 { 0x0000, 0x0000 }, /* R1001 */
1107 { 0x0000, 0x0000 }, /* R1002 */
1108 { 0x0000, 0x0000 }, /* R1003 */
1109 { 0x0000, 0x0000 }, /* R1004 */
1110 { 0x0000, 0x0000 }, /* R1005 */
1111 { 0x0000, 0x0000 }, /* R1006 */
1112 { 0x0000, 0x0000 }, /* R1007 */
1113 { 0x0000, 0x0000 }, /* R1008 */
1114 { 0x0000, 0x0000 }, /* R1009 */
1115 { 0x0000, 0x0000 }, /* R1010 */
1116 { 0x0000, 0x0000 }, /* R1011 */
1117 { 0x0000, 0x0000 }, /* R1012 */
1118 { 0x0000, 0x0000 }, /* R1013 */
1119 { 0x0000, 0x0000 }, /* R1014 */
1120 { 0x0000, 0x0000 }, /* R1015 */
1121 { 0x0000, 0x0000 }, /* R1016 */
1122 { 0x0000, 0x0000 }, /* R1017 */
1123 { 0x0000, 0x0000 }, /* R1018 */
1124 { 0x0000, 0x0000 }, /* R1019 */
1125 { 0x0000, 0x0000 }, /* R1020 */
1126 { 0x0000, 0x0000 }, /* R1021 */
1127 { 0x0000, 0x0000 }, /* R1022 */
1128 { 0x0000, 0x0000 }, /* R1023 */
1129 { 0x00FF, 0x01FF }, /* R1024 - AIF1 ADC1 Left Volume */
1130 { 0x00FF, 0x01FF }, /* R1025 - AIF1 ADC1 Right Volume */
1131 { 0x00FF, 0x01FF }, /* R1026 - AIF1 DAC1 Left Volume */
1132 { 0x00FF, 0x01FF }, /* R1027 - AIF1 DAC1 Right Volume */
1133 { 0x00FF, 0x01FF }, /* R1028 - AIF1 ADC2 Left Volume */
1134 { 0x00FF, 0x01FF }, /* R1029 - AIF1 ADC2 Right Volume */
1135 { 0x00FF, 0x01FF }, /* R1030 - AIF1 DAC2 Left Volume */
1136 { 0x00FF, 0x01FF }, /* R1031 - AIF1 DAC2 Right Volume */
1137 { 0x0000, 0x0000 }, /* R1032 */
1138 { 0x0000, 0x0000 }, /* R1033 */
1139 { 0x0000, 0x0000 }, /* R1034 */
1140 { 0x0000, 0x0000 }, /* R1035 */
1141 { 0x0000, 0x0000 }, /* R1036 */
1142 { 0x0000, 0x0000 }, /* R1037 */
1143 { 0x0000, 0x0000 }, /* R1038 */
1144 { 0x0000, 0x0000 }, /* R1039 */
1145 { 0xF800, 0xF800 }, /* R1040 - AIF1 ADC1 Filters */
1146 { 0x7800, 0x7800 }, /* R1041 - AIF1 ADC2 Filters */
1147 { 0x0000, 0x0000 }, /* R1042 */
1148 { 0x0000, 0x0000 }, /* R1043 */
1149 { 0x0000, 0x0000 }, /* R1044 */
1150 { 0x0000, 0x0000 }, /* R1045 */
1151 { 0x0000, 0x0000 }, /* R1046 */
1152 { 0x0000, 0x0000 }, /* R1047 */
1153 { 0x0000, 0x0000 }, /* R1048 */
1154 { 0x0000, 0x0000 }, /* R1049 */
1155 { 0x0000, 0x0000 }, /* R1050 */
1156 { 0x0000, 0x0000 }, /* R1051 */
1157 { 0x0000, 0x0000 }, /* R1052 */
1158 { 0x0000, 0x0000 }, /* R1053 */
1159 { 0x0000, 0x0000 }, /* R1054 */
1160 { 0x0000, 0x0000 }, /* R1055 */
1161 { 0x02B6, 0x02B6 }, /* R1056 - AIF1 DAC1 Filters (1) */
1162 { 0x3F00, 0x3F00 }, /* R1057 - AIF1 DAC1 Filters (2) */
1163 { 0x02B6, 0x02B6 }, /* R1058 - AIF1 DAC2 Filters (1) */
1164 { 0x3F00, 0x3F00 }, /* R1059 - AIF1 DAC2 Filters (2) */
1165 { 0x0000, 0x0000 }, /* R1060 */
1166 { 0x0000, 0x0000 }, /* R1061 */
1167 { 0x0000, 0x0000 }, /* R1062 */
1168 { 0x0000, 0x0000 }, /* R1063 */
1169 { 0x0000, 0x0000 }, /* R1064 */
1170 { 0x0000, 0x0000 }, /* R1065 */
1171 { 0x0000, 0x0000 }, /* R1066 */
1172 { 0x0000, 0x0000 }, /* R1067 */
1173 { 0x0000, 0x0000 }, /* R1068 */
1174 { 0x0000, 0x0000 }, /* R1069 */
1175 { 0x0000, 0x0000 }, /* R1070 */
1176 { 0x0000, 0x0000 }, /* R1071 */
1177 { 0x0000, 0x0000 }, /* R1072 */
1178 { 0x0000, 0x0000 }, /* R1073 */
1179 { 0x0000, 0x0000 }, /* R1074 */
1180 { 0x0000, 0x0000 }, /* R1075 */
1181 { 0x0000, 0x0000 }, /* R1076 */
1182 { 0x0000, 0x0000 }, /* R1077 */
1183 { 0x0000, 0x0000 }, /* R1078 */
1184 { 0x0000, 0x0000 }, /* R1079 */
1185 { 0x0000, 0x0000 }, /* R1080 */
1186 { 0x0000, 0x0000 }, /* R1081 */
1187 { 0x0000, 0x0000 }, /* R1082 */
1188 { 0x0000, 0x0000 }, /* R1083 */
1189 { 0x0000, 0x0000 }, /* R1084 */
1190 { 0x0000, 0x0000 }, /* R1085 */
1191 { 0x0000, 0x0000 }, /* R1086 */
1192 { 0x0000, 0x0000 }, /* R1087 */
1193 { 0xFFFF, 0xFFFF }, /* R1088 - AIF1 DRC1 (1) */
1194 { 0x1FFF, 0x1FFF }, /* R1089 - AIF1 DRC1 (2) */
1195 { 0xFFFF, 0xFFFF }, /* R1090 - AIF1 DRC1 (3) */
1196 { 0x07FF, 0x07FF }, /* R1091 - AIF1 DRC1 (4) */
1197 { 0x03FF, 0x03FF }, /* R1092 - AIF1 DRC1 (5) */
1198 { 0x0000, 0x0000 }, /* R1093 */
1199 { 0x0000, 0x0000 }, /* R1094 */
1200 { 0x0000, 0x0000 }, /* R1095 */
1201 { 0x0000, 0x0000 }, /* R1096 */
1202 { 0x0000, 0x0000 }, /* R1097 */
1203 { 0x0000, 0x0000 }, /* R1098 */
1204 { 0x0000, 0x0000 }, /* R1099 */
1205 { 0x0000, 0x0000 }, /* R1100 */
1206 { 0x0000, 0x0000 }, /* R1101 */
1207 { 0x0000, 0x0000 }, /* R1102 */
1208 { 0x0000, 0x0000 }, /* R1103 */
1209 { 0xFFFF, 0xFFFF }, /* R1104 - AIF1 DRC2 (1) */
1210 { 0x1FFF, 0x1FFF }, /* R1105 - AIF1 DRC2 (2) */
1211 { 0xFFFF, 0xFFFF }, /* R1106 - AIF1 DRC2 (3) */
1212 { 0x07FF, 0x07FF }, /* R1107 - AIF1 DRC2 (4) */
1213 { 0x03FF, 0x03FF }, /* R1108 - AIF1 DRC2 (5) */
1214 { 0x0000, 0x0000 }, /* R1109 */
1215 { 0x0000, 0x0000 }, /* R1110 */
1216 { 0x0000, 0x0000 }, /* R1111 */
1217 { 0x0000, 0x0000 }, /* R1112 */
1218 { 0x0000, 0x0000 }, /* R1113 */
1219 { 0x0000, 0x0000 }, /* R1114 */
1220 { 0x0000, 0x0000 }, /* R1115 */
1221 { 0x0000, 0x0000 }, /* R1116 */
1222 { 0x0000, 0x0000 }, /* R1117 */
1223 { 0x0000, 0x0000 }, /* R1118 */
1224 { 0x0000, 0x0000 }, /* R1119 */
1225 { 0x0000, 0x0000 }, /* R1120 */
1226 { 0x0000, 0x0000 }, /* R1121 */
1227 { 0x0000, 0x0000 }, /* R1122 */
1228 { 0x0000, 0x0000 }, /* R1123 */
1229 { 0x0000, 0x0000 }, /* R1124 */
1230 { 0x0000, 0x0000 }, /* R1125 */
1231 { 0x0000, 0x0000 }, /* R1126 */
1232 { 0x0000, 0x0000 }, /* R1127 */
1233 { 0x0000, 0x0000 }, /* R1128 */
1234 { 0x0000, 0x0000 }, /* R1129 */
1235 { 0x0000, 0x0000 }, /* R1130 */
1236 { 0x0000, 0x0000 }, /* R1131 */
1237 { 0x0000, 0x0000 }, /* R1132 */
1238 { 0x0000, 0x0000 }, /* R1133 */
1239 { 0x0000, 0x0000 }, /* R1134 */
1240 { 0x0000, 0x0000 }, /* R1135 */
1241 { 0x0000, 0x0000 }, /* R1136 */
1242 { 0x0000, 0x0000 }, /* R1137 */
1243 { 0x0000, 0x0000 }, /* R1138 */
1244 { 0x0000, 0x0000 }, /* R1139 */
1245 { 0x0000, 0x0000 }, /* R1140 */
1246 { 0x0000, 0x0000 }, /* R1141 */
1247 { 0x0000, 0x0000 }, /* R1142 */
1248 { 0x0000, 0x0000 }, /* R1143 */
1249 { 0x0000, 0x0000 }, /* R1144 */
1250 { 0x0000, 0x0000 }, /* R1145 */
1251 { 0x0000, 0x0000 }, /* R1146 */
1252 { 0x0000, 0x0000 }, /* R1147 */
1253 { 0x0000, 0x0000 }, /* R1148 */
1254 { 0x0000, 0x0000 }, /* R1149 */
1255 { 0x0000, 0x0000 }, /* R1150 */
1256 { 0x0000, 0x0000 }, /* R1151 */
1257 { 0xFFFF, 0xFFFF }, /* R1152 - AIF1 DAC1 EQ Gains (1) */
1258 { 0xFFC0, 0xFFC0 }, /* R1153 - AIF1 DAC1 EQ Gains (2) */
1259 { 0xFFFF, 0xFFFF }, /* R1154 - AIF1 DAC1 EQ Band 1 A */
1260 { 0xFFFF, 0xFFFF }, /* R1155 - AIF1 DAC1 EQ Band 1 B */
1261 { 0xFFFF, 0xFFFF }, /* R1156 - AIF1 DAC1 EQ Band 1 PG */
1262 { 0xFFFF, 0xFFFF }, /* R1157 - AIF1 DAC1 EQ Band 2 A */
1263 { 0xFFFF, 0xFFFF }, /* R1158 - AIF1 DAC1 EQ Band 2 B */
1264 { 0xFFFF, 0xFFFF }, /* R1159 - AIF1 DAC1 EQ Band 2 C */
1265 { 0xFFFF, 0xFFFF }, /* R1160 - AIF1 DAC1 EQ Band 2 PG */
1266 { 0xFFFF, 0xFFFF }, /* R1161 - AIF1 DAC1 EQ Band 3 A */
1267 { 0xFFFF, 0xFFFF }, /* R1162 - AIF1 DAC1 EQ Band 3 B */
1268 { 0xFFFF, 0xFFFF }, /* R1163 - AIF1 DAC1 EQ Band 3 C */
1269 { 0xFFFF, 0xFFFF }, /* R1164 - AIF1 DAC1 EQ Band 3 PG */
1270 { 0xFFFF, 0xFFFF }, /* R1165 - AIF1 DAC1 EQ Band 4 A */
1271 { 0xFFFF, 0xFFFF }, /* R1166 - AIF1 DAC1 EQ Band 4 B */
1272 { 0xFFFF, 0xFFFF }, /* R1167 - AIF1 DAC1 EQ Band 4 C */
1273 { 0xFFFF, 0xFFFF }, /* R1168 - AIF1 DAC1 EQ Band 4 PG */
1274 { 0xFFFF, 0xFFFF }, /* R1169 - AIF1 DAC1 EQ Band 5 A */
1275 { 0xFFFF, 0xFFFF }, /* R1170 - AIF1 DAC1 EQ Band 5 B */
1276 { 0xFFFF, 0xFFFF }, /* R1171 - AIF1 DAC1 EQ Band 5 PG */
1277 { 0x0000, 0x0000 }, /* R1172 */
1278 { 0x0000, 0x0000 }, /* R1173 */
1279 { 0x0000, 0x0000 }, /* R1174 */
1280 { 0x0000, 0x0000 }, /* R1175 */
1281 { 0x0000, 0x0000 }, /* R1176 */
1282 { 0x0000, 0x0000 }, /* R1177 */
1283 { 0x0000, 0x0000 }, /* R1178 */
1284 { 0x0000, 0x0000 }, /* R1179 */
1285 { 0x0000, 0x0000 }, /* R1180 */
1286 { 0x0000, 0x0000 }, /* R1181 */
1287 { 0x0000, 0x0000 }, /* R1182 */
1288 { 0x0000, 0x0000 }, /* R1183 */
1289 { 0xFFFF, 0xFFFF }, /* R1184 - AIF1 DAC2 EQ Gains (1) */
1290 { 0xFFC0, 0xFFC0 }, /* R1185 - AIF1 DAC2 EQ Gains (2) */
1291 { 0xFFFF, 0xFFFF }, /* R1186 - AIF1 DAC2 EQ Band 1 A */
1292 { 0xFFFF, 0xFFFF }, /* R1187 - AIF1 DAC2 EQ Band 1 B */
1293 { 0xFFFF, 0xFFFF }, /* R1188 - AIF1 DAC2 EQ Band 1 PG */
1294 { 0xFFFF, 0xFFFF }, /* R1189 - AIF1 DAC2 EQ Band 2 A */
1295 { 0xFFFF, 0xFFFF }, /* R1190 - AIF1 DAC2 EQ Band 2 B */
1296 { 0xFFFF, 0xFFFF }, /* R1191 - AIF1 DAC2 EQ Band 2 C */
1297 { 0xFFFF, 0xFFFF }, /* R1192 - AIF1 DAC2 EQ Band 2 PG */
1298 { 0xFFFF, 0xFFFF }, /* R1193 - AIF1 DAC2 EQ Band 3 A */
1299 { 0xFFFF, 0xFFFF }, /* R1194 - AIF1 DAC2 EQ Band 3 B */
1300 { 0xFFFF, 0xFFFF }, /* R1195 - AIF1 DAC2 EQ Band 3 C */
1301 { 0xFFFF, 0xFFFF }, /* R1196 - AIF1 DAC2 EQ Band 3 PG */
1302 { 0xFFFF, 0xFFFF }, /* R1197 - AIF1 DAC2 EQ Band 4 A */
1303 { 0xFFFF, 0xFFFF }, /* R1198 - AIF1 DAC2 EQ Band 4 B */
1304 { 0xFFFF, 0xFFFF }, /* R1199 - AIF1 DAC2 EQ Band 4 C */
1305 { 0xFFFF, 0xFFFF }, /* R1200 - AIF1 DAC2 EQ Band 4 PG */
1306 { 0xFFFF, 0xFFFF }, /* R1201 - AIF1 DAC2 EQ Band 5 A */
1307 { 0xFFFF, 0xFFFF }, /* R1202 - AIF1 DAC2 EQ Band 5 B */
1308 { 0xFFFF, 0xFFFF }, /* R1203 - AIF1 DAC2 EQ Band 5 PG */
1309 { 0x0000, 0x0000 }, /* R1204 */
1310 { 0x0000, 0x0000 }, /* R1205 */
1311 { 0x0000, 0x0000 }, /* R1206 */
1312 { 0x0000, 0x0000 }, /* R1207 */
1313 { 0x0000, 0x0000 }, /* R1208 */
1314 { 0x0000, 0x0000 }, /* R1209 */
1315 { 0x0000, 0x0000 }, /* R1210 */
1316 { 0x0000, 0x0000 }, /* R1211 */
1317 { 0x0000, 0x0000 }, /* R1212 */
1318 { 0x0000, 0x0000 }, /* R1213 */
1319 { 0x0000, 0x0000 }, /* R1214 */
1320 { 0x0000, 0x0000 }, /* R1215 */
1321 { 0x0000, 0x0000 }, /* R1216 */
1322 { 0x0000, 0x0000 }, /* R1217 */
1323 { 0x0000, 0x0000 }, /* R1218 */
1324 { 0x0000, 0x0000 }, /* R1219 */
1325 { 0x0000, 0x0000 }, /* R1220 */
1326 { 0x0000, 0x0000 }, /* R1221 */
1327 { 0x0000, 0x0000 }, /* R1222 */
1328 { 0x0000, 0x0000 }, /* R1223 */
1329 { 0x0000, 0x0000 }, /* R1224 */
1330 { 0x0000, 0x0000 }, /* R1225 */
1331 { 0x0000, 0x0000 }, /* R1226 */
1332 { 0x0000, 0x0000 }, /* R1227 */
1333 { 0x0000, 0x0000 }, /* R1228 */
1334 { 0x0000, 0x0000 }, /* R1229 */
1335 { 0x0000, 0x0000 }, /* R1230 */
1336 { 0x0000, 0x0000 }, /* R1231 */
1337 { 0x0000, 0x0000 }, /* R1232 */
1338 { 0x0000, 0x0000 }, /* R1233 */
1339 { 0x0000, 0x0000 }, /* R1234 */
1340 { 0x0000, 0x0000 }, /* R1235 */
1341 { 0x0000, 0x0000 }, /* R1236 */
1342 { 0x0000, 0x0000 }, /* R1237 */
1343 { 0x0000, 0x0000 }, /* R1238 */
1344 { 0x0000, 0x0000 }, /* R1239 */
1345 { 0x0000, 0x0000 }, /* R1240 */
1346 { 0x0000, 0x0000 }, /* R1241 */
1347 { 0x0000, 0x0000 }, /* R1242 */
1348 { 0x0000, 0x0000 }, /* R1243 */
1349 { 0x0000, 0x0000 }, /* R1244 */
1350 { 0x0000, 0x0000 }, /* R1245 */
1351 { 0x0000, 0x0000 }, /* R1246 */
1352 { 0x0000, 0x0000 }, /* R1247 */
1353 { 0x0000, 0x0000 }, /* R1248 */
1354 { 0x0000, 0x0000 }, /* R1249 */
1355 { 0x0000, 0x0000 }, /* R1250 */
1356 { 0x0000, 0x0000 }, /* R1251 */
1357 { 0x0000, 0x0000 }, /* R1252 */
1358 { 0x0000, 0x0000 }, /* R1253 */
1359 { 0x0000, 0x0000 }, /* R1254 */
1360 { 0x0000, 0x0000 }, /* R1255 */
1361 { 0x0000, 0x0000 }, /* R1256 */
1362 { 0x0000, 0x0000 }, /* R1257 */
1363 { 0x0000, 0x0000 }, /* R1258 */
1364 { 0x0000, 0x0000 }, /* R1259 */
1365 { 0x0000, 0x0000 }, /* R1260 */
1366 { 0x0000, 0x0000 }, /* R1261 */
1367 { 0x0000, 0x0000 }, /* R1262 */
1368 { 0x0000, 0x0000 }, /* R1263 */
1369 { 0x0000, 0x0000 }, /* R1264 */
1370 { 0x0000, 0x0000 }, /* R1265 */
1371 { 0x0000, 0x0000 }, /* R1266 */
1372 { 0x0000, 0x0000 }, /* R1267 */
1373 { 0x0000, 0x0000 }, /* R1268 */
1374 { 0x0000, 0x0000 }, /* R1269 */
1375 { 0x0000, 0x0000 }, /* R1270 */
1376 { 0x0000, 0x0000 }, /* R1271 */
1377 { 0x0000, 0x0000 }, /* R1272 */
1378 { 0x0000, 0x0000 }, /* R1273 */
1379 { 0x0000, 0x0000 }, /* R1274 */
1380 { 0x0000, 0x0000 }, /* R1275 */
1381 { 0x0000, 0x0000 }, /* R1276 */
1382 { 0x0000, 0x0000 }, /* R1277 */
1383 { 0x0000, 0x0000 }, /* R1278 */
1384 { 0x0000, 0x0000 }, /* R1279 */
1385 { 0x00FF, 0x01FF }, /* R1280 - AIF2 ADC Left Volume */
1386 { 0x00FF, 0x01FF }, /* R1281 - AIF2 ADC Right Volume */
1387 { 0x00FF, 0x01FF }, /* R1282 - AIF2 DAC Left Volume */
1388 { 0x00FF, 0x01FF }, /* R1283 - AIF2 DAC Right Volume */
1389 { 0x0000, 0x0000 }, /* R1284 */
1390 { 0x0000, 0x0000 }, /* R1285 */
1391 { 0x0000, 0x0000 }, /* R1286 */
1392 { 0x0000, 0x0000 }, /* R1287 */
1393 { 0x0000, 0x0000 }, /* R1288 */
1394 { 0x0000, 0x0000 }, /* R1289 */
1395 { 0x0000, 0x0000 }, /* R1290 */
1396 { 0x0000, 0x0000 }, /* R1291 */
1397 { 0x0000, 0x0000 }, /* R1292 */
1398 { 0x0000, 0x0000 }, /* R1293 */
1399 { 0x0000, 0x0000 }, /* R1294 */
1400 { 0x0000, 0x0000 }, /* R1295 */
1401 { 0xF800, 0xF800 }, /* R1296 - AIF2 ADC Filters */
1402 { 0x0000, 0x0000 }, /* R1297 */
1403 { 0x0000, 0x0000 }, /* R1298 */
1404 { 0x0000, 0x0000 }, /* R1299 */
1405 { 0x0000, 0x0000 }, /* R1300 */
1406 { 0x0000, 0x0000 }, /* R1301 */
1407 { 0x0000, 0x0000 }, /* R1302 */
1408 { 0x0000, 0x0000 }, /* R1303 */
1409 { 0x0000, 0x0000 }, /* R1304 */
1410 { 0x0000, 0x0000 }, /* R1305 */
1411 { 0x0000, 0x0000 }, /* R1306 */
1412 { 0x0000, 0x0000 }, /* R1307 */
1413 { 0x0000, 0x0000 }, /* R1308 */
1414 { 0x0000, 0x0000 }, /* R1309 */
1415 { 0x0000, 0x0000 }, /* R1310 */
1416 { 0x0000, 0x0000 }, /* R1311 */
1417 { 0x02B6, 0x02B6 }, /* R1312 - AIF2 DAC Filters (1) */
1418 { 0x3F00, 0x3F00 }, /* R1313 - AIF2 DAC Filters (2) */
1419 { 0x0000, 0x0000 }, /* R1314 */
1420 { 0x0000, 0x0000 }, /* R1315 */
1421 { 0x0000, 0x0000 }, /* R1316 */
1422 { 0x0000, 0x0000 }, /* R1317 */
1423 { 0x0000, 0x0000 }, /* R1318 */
1424 { 0x0000, 0x0000 }, /* R1319 */
1425 { 0x0000, 0x0000 }, /* R1320 */
1426 { 0x0000, 0x0000 }, /* R1321 */
1427 { 0x0000, 0x0000 }, /* R1322 */
1428 { 0x0000, 0x0000 }, /* R1323 */
1429 { 0x0000, 0x0000 }, /* R1324 */
1430 { 0x0000, 0x0000 }, /* R1325 */
1431 { 0x0000, 0x0000 }, /* R1326 */
1432 { 0x0000, 0x0000 }, /* R1327 */
1433 { 0x0000, 0x0000 }, /* R1328 */
1434 { 0x0000, 0x0000 }, /* R1329 */
1435 { 0x0000, 0x0000 }, /* R1330 */
1436 { 0x0000, 0x0000 }, /* R1331 */
1437 { 0x0000, 0x0000 }, /* R1332 */
1438 { 0x0000, 0x0000 }, /* R1333 */
1439 { 0x0000, 0x0000 }, /* R1334 */
1440 { 0x0000, 0x0000 }, /* R1335 */
1441 { 0x0000, 0x0000 }, /* R1336 */
1442 { 0x0000, 0x0000 }, /* R1337 */
1443 { 0x0000, 0x0000 }, /* R1338 */
1444 { 0x0000, 0x0000 }, /* R1339 */
1445 { 0x0000, 0x0000 }, /* R1340 */
1446 { 0x0000, 0x0000 }, /* R1341 */
1447 { 0x0000, 0x0000 }, /* R1342 */
1448 { 0x0000, 0x0000 }, /* R1343 */
1449 { 0xFFFF, 0xFFFF }, /* R1344 - AIF2 DRC (1) */
1450 { 0x1FFF, 0x1FFF }, /* R1345 - AIF2 DRC (2) */
1451 { 0xFFFF, 0xFFFF }, /* R1346 - AIF2 DRC (3) */
1452 { 0x07FF, 0x07FF }, /* R1347 - AIF2 DRC (4) */
1453 { 0x03FF, 0x03FF }, /* R1348 - AIF2 DRC (5) */
1454 { 0x0000, 0x0000 }, /* R1349 */
1455 { 0x0000, 0x0000 }, /* R1350 */
1456 { 0x0000, 0x0000 }, /* R1351 */
1457 { 0x0000, 0x0000 }, /* R1352 */
1458 { 0x0000, 0x0000 }, /* R1353 */
1459 { 0x0000, 0x0000 }, /* R1354 */
1460 { 0x0000, 0x0000 }, /* R1355 */
1461 { 0x0000, 0x0000 }, /* R1356 */
1462 { 0x0000, 0x0000 }, /* R1357 */
1463 { 0x0000, 0x0000 }, /* R1358 */
1464 { 0x0000, 0x0000 }, /* R1359 */
1465 { 0x0000, 0x0000 }, /* R1360 */
1466 { 0x0000, 0x0000 }, /* R1361 */
1467 { 0x0000, 0x0000 }, /* R1362 */
1468 { 0x0000, 0x0000 }, /* R1363 */
1469 { 0x0000, 0x0000 }, /* R1364 */
1470 { 0x0000, 0x0000 }, /* R1365 */
1471 { 0x0000, 0x0000 }, /* R1366 */
1472 { 0x0000, 0x0000 }, /* R1367 */
1473 { 0x0000, 0x0000 }, /* R1368 */
1474 { 0x0000, 0x0000 }, /* R1369 */
1475 { 0x0000, 0x0000 }, /* R1370 */
1476 { 0x0000, 0x0000 }, /* R1371 */
1477 { 0x0000, 0x0000 }, /* R1372 */
1478 { 0x0000, 0x0000 }, /* R1373 */
1479 { 0x0000, 0x0000 }, /* R1374 */
1480 { 0x0000, 0x0000 }, /* R1375 */
1481 { 0x0000, 0x0000 }, /* R1376 */
1482 { 0x0000, 0x0000 }, /* R1377 */
1483 { 0x0000, 0x0000 }, /* R1378 */
1484 { 0x0000, 0x0000 }, /* R1379 */
1485 { 0x0000, 0x0000 }, /* R1380 */
1486 { 0x0000, 0x0000 }, /* R1381 */
1487 { 0x0000, 0x0000 }, /* R1382 */
1488 { 0x0000, 0x0000 }, /* R1383 */
1489 { 0x0000, 0x0000 }, /* R1384 */
1490 { 0x0000, 0x0000 }, /* R1385 */
1491 { 0x0000, 0x0000 }, /* R1386 */
1492 { 0x0000, 0x0000 }, /* R1387 */
1493 { 0x0000, 0x0000 }, /* R1388 */
1494 { 0x0000, 0x0000 }, /* R1389 */
1495 { 0x0000, 0x0000 }, /* R1390 */
1496 { 0x0000, 0x0000 }, /* R1391 */
1497 { 0x0000, 0x0000 }, /* R1392 */
1498 { 0x0000, 0x0000 }, /* R1393 */
1499 { 0x0000, 0x0000 }, /* R1394 */
1500 { 0x0000, 0x0000 }, /* R1395 */
1501 { 0x0000, 0x0000 }, /* R1396 */
1502 { 0x0000, 0x0000 }, /* R1397 */
1503 { 0x0000, 0x0000 }, /* R1398 */
1504 { 0x0000, 0x0000 }, /* R1399 */
1505 { 0x0000, 0x0000 }, /* R1400 */
1506 { 0x0000, 0x0000 }, /* R1401 */
1507 { 0x0000, 0x0000 }, /* R1402 */
1508 { 0x0000, 0x0000 }, /* R1403 */
1509 { 0x0000, 0x0000 }, /* R1404 */
1510 { 0x0000, 0x0000 }, /* R1405 */
1511 { 0x0000, 0x0000 }, /* R1406 */
1512 { 0x0000, 0x0000 }, /* R1407 */
1513 { 0xFFFF, 0xFFFF }, /* R1408 - AIF2 EQ Gains (1) */
1514 { 0xFFC0, 0xFFC0 }, /* R1409 - AIF2 EQ Gains (2) */
1515 { 0xFFFF, 0xFFFF }, /* R1410 - AIF2 EQ Band 1 A */
1516 { 0xFFFF, 0xFFFF }, /* R1411 - AIF2 EQ Band 1 B */
1517 { 0xFFFF, 0xFFFF }, /* R1412 - AIF2 EQ Band 1 PG */
1518 { 0xFFFF, 0xFFFF }, /* R1413 - AIF2 EQ Band 2 A */
1519 { 0xFFFF, 0xFFFF }, /* R1414 - AIF2 EQ Band 2 B */
1520 { 0xFFFF, 0xFFFF }, /* R1415 - AIF2 EQ Band 2 C */
1521 { 0xFFFF, 0xFFFF }, /* R1416 - AIF2 EQ Band 2 PG */
1522 { 0xFFFF, 0xFFFF }, /* R1417 - AIF2 EQ Band 3 A */
1523 { 0xFFFF, 0xFFFF }, /* R1418 - AIF2 EQ Band 3 B */
1524 { 0xFFFF, 0xFFFF }, /* R1419 - AIF2 EQ Band 3 C */
1525 { 0xFFFF, 0xFFFF }, /* R1420 - AIF2 EQ Band 3 PG */
1526 { 0xFFFF, 0xFFFF }, /* R1421 - AIF2 EQ Band 4 A */
1527 { 0xFFFF, 0xFFFF }, /* R1422 - AIF2 EQ Band 4 B */
1528 { 0xFFFF, 0xFFFF }, /* R1423 - AIF2 EQ Band 4 C */
1529 { 0xFFFF, 0xFFFF }, /* R1424 - AIF2 EQ Band 4 PG */
1530 { 0xFFFF, 0xFFFF }, /* R1425 - AIF2 EQ Band 5 A */
1531 { 0xFFFF, 0xFFFF }, /* R1426 - AIF2 EQ Band 5 B */
1532 { 0xFFFF, 0xFFFF }, /* R1427 - AIF2 EQ Band 5 PG */
1533 { 0x0000, 0x0000 }, /* R1428 */
1534 { 0x0000, 0x0000 }, /* R1429 */
1535 { 0x0000, 0x0000 }, /* R1430 */
1536 { 0x0000, 0x0000 }, /* R1431 */
1537 { 0x0000, 0x0000 }, /* R1432 */
1538 { 0x0000, 0x0000 }, /* R1433 */
1539 { 0x0000, 0x0000 }, /* R1434 */
1540 { 0x0000, 0x0000 }, /* R1435 */
1541 { 0x0000, 0x0000 }, /* R1436 */
1542 { 0x0000, 0x0000 }, /* R1437 */
1543 { 0x0000, 0x0000 }, /* R1438 */
1544 { 0x0000, 0x0000 }, /* R1439 */
1545 { 0x0000, 0x0000 }, /* R1440 */
1546 { 0x0000, 0x0000 }, /* R1441 */
1547 { 0x0000, 0x0000 }, /* R1442 */
1548 { 0x0000, 0x0000 }, /* R1443 */
1549 { 0x0000, 0x0000 }, /* R1444 */
1550 { 0x0000, 0x0000 }, /* R1445 */
1551 { 0x0000, 0x0000 }, /* R1446 */
1552 { 0x0000, 0x0000 }, /* R1447 */
1553 { 0x0000, 0x0000 }, /* R1448 */
1554 { 0x0000, 0x0000 }, /* R1449 */
1555 { 0x0000, 0x0000 }, /* R1450 */
1556 { 0x0000, 0x0000 }, /* R1451 */
1557 { 0x0000, 0x0000 }, /* R1452 */
1558 { 0x0000, 0x0000 }, /* R1453 */
1559 { 0x0000, 0x0000 }, /* R1454 */
1560 { 0x0000, 0x0000 }, /* R1455 */
1561 { 0x0000, 0x0000 }, /* R1456 */
1562 { 0x0000, 0x0000 }, /* R1457 */
1563 { 0x0000, 0x0000 }, /* R1458 */
1564 { 0x0000, 0x0000 }, /* R1459 */
1565 { 0x0000, 0x0000 }, /* R1460 */
1566 { 0x0000, 0x0000 }, /* R1461 */
1567 { 0x0000, 0x0000 }, /* R1462 */
1568 { 0x0000, 0x0000 }, /* R1463 */
1569 { 0x0000, 0x0000 }, /* R1464 */
1570 { 0x0000, 0x0000 }, /* R1465 */
1571 { 0x0000, 0x0000 }, /* R1466 */
1572 { 0x0000, 0x0000 }, /* R1467 */
1573 { 0x0000, 0x0000 }, /* R1468 */
1574 { 0x0000, 0x0000 }, /* R1469 */
1575 { 0x0000, 0x0000 }, /* R1470 */
1576 { 0x0000, 0x0000 }, /* R1471 */
1577 { 0x0000, 0x0000 }, /* R1472 */
1578 { 0x0000, 0x0000 }, /* R1473 */
1579 { 0x0000, 0x0000 }, /* R1474 */
1580 { 0x0000, 0x0000 }, /* R1475 */
1581 { 0x0000, 0x0000 }, /* R1476 */
1582 { 0x0000, 0x0000 }, /* R1477 */
1583 { 0x0000, 0x0000 }, /* R1478 */
1584 { 0x0000, 0x0000 }, /* R1479 */
1585 { 0x0000, 0x0000 }, /* R1480 */
1586 { 0x0000, 0x0000 }, /* R1481 */
1587 { 0x0000, 0x0000 }, /* R1482 */
1588 { 0x0000, 0x0000 }, /* R1483 */
1589 { 0x0000, 0x0000 }, /* R1484 */
1590 { 0x0000, 0x0000 }, /* R1485 */
1591 { 0x0000, 0x0000 }, /* R1486 */
1592 { 0x0000, 0x0000 }, /* R1487 */
1593 { 0x0000, 0x0000 }, /* R1488 */
1594 { 0x0000, 0x0000 }, /* R1489 */
1595 { 0x0000, 0x0000 }, /* R1490 */
1596 { 0x0000, 0x0000 }, /* R1491 */
1597 { 0x0000, 0x0000 }, /* R1492 */
1598 { 0x0000, 0x0000 }, /* R1493 */
1599 { 0x0000, 0x0000 }, /* R1494 */
1600 { 0x0000, 0x0000 }, /* R1495 */
1601 { 0x0000, 0x0000 }, /* R1496 */
1602 { 0x0000, 0x0000 }, /* R1497 */
1603 { 0x0000, 0x0000 }, /* R1498 */
1604 { 0x0000, 0x0000 }, /* R1499 */
1605 { 0x0000, 0x0000 }, /* R1500 */
1606 { 0x0000, 0x0000 }, /* R1501 */
1607 { 0x0000, 0x0000 }, /* R1502 */
1608 { 0x0000, 0x0000 }, /* R1503 */
1609 { 0x0000, 0x0000 }, /* R1504 */
1610 { 0x0000, 0x0000 }, /* R1505 */
1611 { 0x0000, 0x0000 }, /* R1506 */
1612 { 0x0000, 0x0000 }, /* R1507 */
1613 { 0x0000, 0x0000 }, /* R1508 */
1614 { 0x0000, 0x0000 }, /* R1509 */
1615 { 0x0000, 0x0000 }, /* R1510 */
1616 { 0x0000, 0x0000 }, /* R1511 */
1617 { 0x0000, 0x0000 }, /* R1512 */
1618 { 0x0000, 0x0000 }, /* R1513 */
1619 { 0x0000, 0x0000 }, /* R1514 */
1620 { 0x0000, 0x0000 }, /* R1515 */
1621 { 0x0000, 0x0000 }, /* R1516 */
1622 { 0x0000, 0x0000 }, /* R1517 */
1623 { 0x0000, 0x0000 }, /* R1518 */
1624 { 0x0000, 0x0000 }, /* R1519 */
1625 { 0x0000, 0x0000 }, /* R1520 */
1626 { 0x0000, 0x0000 }, /* R1521 */
1627 { 0x0000, 0x0000 }, /* R1522 */
1628 { 0x0000, 0x0000 }, /* R1523 */
1629 { 0x0000, 0x0000 }, /* R1524 */
1630 { 0x0000, 0x0000 }, /* R1525 */
1631 { 0x0000, 0x0000 }, /* R1526 */
1632 { 0x0000, 0x0000 }, /* R1527 */
1633 { 0x0000, 0x0000 }, /* R1528 */
1634 { 0x0000, 0x0000 }, /* R1529 */
1635 { 0x0000, 0x0000 }, /* R1530 */
1636 { 0x0000, 0x0000 }, /* R1531 */
1637 { 0x0000, 0x0000 }, /* R1532 */
1638 { 0x0000, 0x0000 }, /* R1533 */
1639 { 0x0000, 0x0000 }, /* R1534 */
1640 { 0x0000, 0x0000 }, /* R1535 */
1641 { 0x01EF, 0x01EF }, /* R1536 - DAC1 Mixer Volumes */
1642 { 0x0037, 0x0037 }, /* R1537 - DAC1 Left Mixer Routing */
1643 { 0x0037, 0x0037 }, /* R1538 - DAC1 Right Mixer Routing */
1644 { 0x01EF, 0x01EF }, /* R1539 - DAC2 Mixer Volumes */
1645 { 0x0037, 0x0037 }, /* R1540 - DAC2 Left Mixer Routing */
1646 { 0x0037, 0x0037 }, /* R1541 - DAC2 Right Mixer Routing */
1647 { 0x0003, 0x0003 }, /* R1542 - AIF1 ADC1 Left Mixer Routing */
1648 { 0x0003, 0x0003 }, /* R1543 - AIF1 ADC1 Right Mixer Routing */
1649 { 0x0003, 0x0003 }, /* R1544 - AIF1 ADC2 Left Mixer Routing */
1650 { 0x0003, 0x0003 }, /* R1545 - AIF1 ADC2 Right mixer Routing */
1651 { 0x0000, 0x0000 }, /* R1546 */
1652 { 0x0000, 0x0000 }, /* R1547 */
1653 { 0x0000, 0x0000 }, /* R1548 */
1654 { 0x0000, 0x0000 }, /* R1549 */
1655 { 0x0000, 0x0000 }, /* R1550 */
1656 { 0x0000, 0x0000 }, /* R1551 */
1657 { 0x02FF, 0x03FF }, /* R1552 - DAC1 Left Volume */
1658 { 0x02FF, 0x03FF }, /* R1553 - DAC1 Right Volume */
1659 { 0x02FF, 0x03FF }, /* R1554 - DAC2 Left Volume */
1660 { 0x02FF, 0x03FF }, /* R1555 - DAC2 Right Volume */
1661 { 0x0003, 0x0003 }, /* R1556 - DAC Softmute */
1662 { 0x0000, 0x0000 }, /* R1557 */
1663 { 0x0000, 0x0000 }, /* R1558 */
1664 { 0x0000, 0x0000 }, /* R1559 */
1665 { 0x0000, 0x0000 }, /* R1560 */
1666 { 0x0000, 0x0000 }, /* R1561 */
1667 { 0x0000, 0x0000 }, /* R1562 */
1668 { 0x0000, 0x0000 }, /* R1563 */
1669 { 0x0000, 0x0000 }, /* R1564 */
1670 { 0x0000, 0x0000 }, /* R1565 */
1671 { 0x0000, 0x0000 }, /* R1566 */
1672 { 0x0000, 0x0000 }, /* R1567 */
1673 { 0x0003, 0x0003 }, /* R1568 - Oversampling */
1674 { 0x03C3, 0x03C3 }, /* R1569 - Sidetone */
1675};
1676
1677static int wm8994_readable(unsigned int reg) 112static int wm8994_readable(unsigned int reg)
1678{ 113{
1679 switch (reg) { 114 switch (reg) {
@@ -1696,14 +131,14 @@ static int wm8994_readable(unsigned int reg)
1696 break; 131 break;
1697 } 132 }
1698 133
1699 if (reg >= ARRAY_SIZE(access_masks)) 134 if (reg >= WM8994_CACHE_SIZE)
1700 return 0; 135 return 0;
1701 return access_masks[reg].readable != 0; 136 return wm8994_access_masks[reg].readable != 0;
1702} 137}
1703 138
1704static int wm8994_volatile(unsigned int reg) 139static int wm8994_volatile(unsigned int reg)
1705{ 140{
1706 if (reg >= WM8994_REG_CACHE_SIZE) 141 if (reg >= WM8994_CACHE_SIZE)
1707 return 1; 142 return 1;
1708 143
1709 switch (reg) { 144 switch (reg) {
@@ -1714,6 +149,8 @@ static int wm8994_volatile(unsigned int reg)
1714 case WM8994_RATE_STATUS: 149 case WM8994_RATE_STATUS:
1715 case WM8994_LDO_1: 150 case WM8994_LDO_1:
1716 case WM8994_LDO_2: 151 case WM8994_LDO_2:
152 case WM8958_DSP2_EXECCONTROL:
153 case WM8958_MIC_DETECT_3:
1717 return 1; 154 return 1;
1718 default: 155 default:
1719 return 0; 156 return 0;
@@ -1723,14 +160,16 @@ static int wm8994_volatile(unsigned int reg)
1723static int wm8994_write(struct snd_soc_codec *codec, unsigned int reg, 160static int wm8994_write(struct snd_soc_codec *codec, unsigned int reg,
1724 unsigned int value) 161 unsigned int value)
1725{ 162{
1726 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec); 163 int ret;
1727 164
1728 BUG_ON(reg > WM8994_MAX_REGISTER); 165 BUG_ON(reg > WM8994_MAX_REGISTER);
1729 166
1730 if (!wm8994_volatile(reg)) 167 if (!wm8994_volatile(reg)) {
1731 wm8994->reg_cache[reg] = value; 168 ret = snd_soc_cache_write(codec, reg, value);
1732 169 if (ret != 0)
1733 dev_dbg(codec->dev, "0x%x = 0x%x\n", reg, value); 170 dev_err(codec->dev, "Cache write to %x failed: %d\n",
171 reg, ret);
172 }
1734 173
1735 return wm8994_reg_write(codec->control_data, reg, value); 174 return wm8994_reg_write(codec->control_data, reg, value);
1736} 175}
@@ -1738,14 +177,22 @@ static int wm8994_write(struct snd_soc_codec *codec, unsigned int reg,
1738static unsigned int wm8994_read(struct snd_soc_codec *codec, 177static unsigned int wm8994_read(struct snd_soc_codec *codec,
1739 unsigned int reg) 178 unsigned int reg)
1740{ 179{
1741 u16 *reg_cache = codec->reg_cache; 180 unsigned int val;
181 int ret;
1742 182
1743 BUG_ON(reg > WM8994_MAX_REGISTER); 183 BUG_ON(reg > WM8994_MAX_REGISTER);
1744 184
1745 if (wm8994_volatile(reg)) 185 if (!wm8994_volatile(reg) && wm8994_readable(reg) &&
1746 return wm8994_reg_read(codec->control_data, reg); 186 reg < codec->driver->reg_cache_size) {
1747 else 187 ret = snd_soc_cache_read(codec, reg, &val);
1748 return reg_cache[reg]; 188 if (ret >= 0)
189 return val;
190 else
191 dev_err(codec->dev, "Cache read from %x failed: %d\n",
192 reg, ret);
193 }
194
195 return wm8994_reg_read(codec->control_data, reg);
1749} 196}
1750 197
1751static int configure_aif_clock(struct snd_soc_codec *codec, int aif) 198static int configure_aif_clock(struct snd_soc_codec *codec, int aif)
@@ -1837,7 +284,7 @@ static int configure_clock(struct snd_soc_codec *codec)
1837 284
1838 snd_soc_update_bits(codec, WM8994_CLOCKING_1, WM8994_SYSCLK_SRC, new); 285 snd_soc_update_bits(codec, WM8994_CLOCKING_1, WM8994_SYSCLK_SRC, new);
1839 286
1840 snd_soc_dapm_sync(codec); 287 snd_soc_dapm_sync(&codec->dapm);
1841 288
1842 return 0; 289 return 0;
1843} 290}
@@ -1864,6 +311,19 @@ static const char *sidetone_hpf_text[] = {
1864static const struct soc_enum sidetone_hpf = 311static const struct soc_enum sidetone_hpf =
1865 SOC_ENUM_SINGLE(WM8994_SIDETONE, 7, 7, sidetone_hpf_text); 312 SOC_ENUM_SINGLE(WM8994_SIDETONE, 7, 7, sidetone_hpf_text);
1866 313
314static const char *adc_hpf_text[] = {
315 "HiFi", "Voice 1", "Voice 2", "Voice 3"
316};
317
318static const struct soc_enum aif1adc1_hpf =
319 SOC_ENUM_SINGLE(WM8994_AIF1_ADC1_FILTERS, 13, 4, adc_hpf_text);
320
321static const struct soc_enum aif1adc2_hpf =
322 SOC_ENUM_SINGLE(WM8994_AIF1_ADC2_FILTERS, 13, 4, adc_hpf_text);
323
324static const struct soc_enum aif2adc_hpf =
325 SOC_ENUM_SINGLE(WM8994_AIF2_ADC_FILTERS, 13, 4, adc_hpf_text);
326
1867static const DECLARE_TLV_DB_SCALE(aif_tlv, 0, 600, 0); 327static const DECLARE_TLV_DB_SCALE(aif_tlv, 0, 600, 0);
1868static const DECLARE_TLV_DB_SCALE(digital_tlv, -7200, 75, 1); 328static const DECLARE_TLV_DB_SCALE(digital_tlv, -7200, 75, 1);
1869static const DECLARE_TLV_DB_SCALE(st_tlv, -3600, 300, 0); 329static const DECLARE_TLV_DB_SCALE(st_tlv, -3600, 300, 0);
@@ -2071,21 +531,252 @@ static int wm8994_get_retune_mobile_enum(struct snd_kcontrol *kcontrol,
2071 return 0; 531 return 0;
2072} 532}
2073 533
2074static const char *aifdac_src_text[] = { 534static const char *aif_chan_src_text[] = {
2075 "Left", "Right" 535 "Left", "Right"
2076}; 536};
2077 537
538static const struct soc_enum aif1adcl_src =
539 SOC_ENUM_SINGLE(WM8994_AIF1_CONTROL_1, 15, 2, aif_chan_src_text);
540
541static const struct soc_enum aif1adcr_src =
542 SOC_ENUM_SINGLE(WM8994_AIF1_CONTROL_1, 14, 2, aif_chan_src_text);
543
544static const struct soc_enum aif2adcl_src =
545 SOC_ENUM_SINGLE(WM8994_AIF2_CONTROL_1, 15, 2, aif_chan_src_text);
546
547static const struct soc_enum aif2adcr_src =
548 SOC_ENUM_SINGLE(WM8994_AIF2_CONTROL_1, 14, 2, aif_chan_src_text);
549
2078static const struct soc_enum aif1dacl_src = 550static const struct soc_enum aif1dacl_src =
2079 SOC_ENUM_SINGLE(WM8994_AIF1_CONTROL_2, 15, 2, aifdac_src_text); 551 SOC_ENUM_SINGLE(WM8994_AIF1_CONTROL_2, 15, 2, aif_chan_src_text);
2080 552
2081static const struct soc_enum aif1dacr_src = 553static const struct soc_enum aif1dacr_src =
2082 SOC_ENUM_SINGLE(WM8994_AIF1_CONTROL_2, 14, 2, aifdac_src_text); 554 SOC_ENUM_SINGLE(WM8994_AIF1_CONTROL_2, 14, 2, aif_chan_src_text);
2083 555
2084static const struct soc_enum aif2dacl_src = 556static const struct soc_enum aif2dacl_src =
2085 SOC_ENUM_SINGLE(WM8994_AIF2_CONTROL_2, 15, 2, aifdac_src_text); 557 SOC_ENUM_SINGLE(WM8994_AIF2_CONTROL_2, 15, 2, aif_chan_src_text);
2086 558
2087static const struct soc_enum aif2dacr_src = 559static const struct soc_enum aif2dacr_src =
2088 SOC_ENUM_SINGLE(WM8994_AIF2_CONTROL_2, 14, 2, aifdac_src_text); 560 SOC_ENUM_SINGLE(WM8994_AIF2_CONTROL_2, 14, 2, aif_chan_src_text);
561
562static const char *osr_text[] = {
563 "Low Power", "High Performance",
564};
565
566static const struct soc_enum dac_osr =
567 SOC_ENUM_SINGLE(WM8994_OVERSAMPLING, 0, 2, osr_text);
568
569static const struct soc_enum adc_osr =
570 SOC_ENUM_SINGLE(WM8994_OVERSAMPLING, 1, 2, osr_text);
571
572static void wm8958_mbc_apply(struct snd_soc_codec *codec, int mbc, int start)
573{
574 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
575 struct wm8994_pdata *pdata = wm8994->pdata;
576 int pwr_reg = snd_soc_read(codec, WM8994_POWER_MANAGEMENT_5);
577 int ena, reg, aif, i;
578
579 switch (mbc) {
580 case 0:
581 pwr_reg &= (WM8994_AIF1DAC1L_ENA | WM8994_AIF1DAC1R_ENA);
582 aif = 0;
583 break;
584 case 1:
585 pwr_reg &= (WM8994_AIF1DAC2L_ENA | WM8994_AIF1DAC2R_ENA);
586 aif = 0;
587 break;
588 case 2:
589 pwr_reg &= (WM8994_AIF2DACL_ENA | WM8994_AIF2DACR_ENA);
590 aif = 1;
591 break;
592 default:
593 BUG();
594 return;
595 }
596
597 /* We can only enable the MBC if the AIF is enabled and we
598 * want it to be enabled. */
599 ena = pwr_reg && wm8994->mbc_ena[mbc];
600
601 reg = snd_soc_read(codec, WM8958_DSP2_PROGRAM);
602
603 dev_dbg(codec->dev, "MBC %d startup: %d, power: %x, DSP: %x\n",
604 mbc, start, pwr_reg, reg);
605
606 if (start && ena) {
607 /* If the DSP is already running then noop */
608 if (reg & WM8958_DSP2_ENA)
609 return;
610
611 /* Switch the clock over to the appropriate AIF */
612 snd_soc_update_bits(codec, WM8994_CLOCKING_1,
613 WM8958_DSP2CLK_SRC | WM8958_DSP2CLK_ENA,
614 aif << WM8958_DSP2CLK_SRC_SHIFT |
615 WM8958_DSP2CLK_ENA);
616
617 snd_soc_update_bits(codec, WM8958_DSP2_PROGRAM,
618 WM8958_DSP2_ENA, WM8958_DSP2_ENA);
619
620 /* If we've got user supplied MBC settings use them */
621 if (pdata && pdata->num_mbc_cfgs) {
622 struct wm8958_mbc_cfg *cfg
623 = &pdata->mbc_cfgs[wm8994->mbc_cfg];
624
625 for (i = 0; i < ARRAY_SIZE(cfg->coeff_regs); i++)
626 snd_soc_write(codec, i + WM8958_MBC_BAND_1_K_1,
627 cfg->coeff_regs[i]);
628
629 for (i = 0; i < ARRAY_SIZE(cfg->cutoff_regs); i++)
630 snd_soc_write(codec,
631 i + WM8958_MBC_BAND_2_LOWER_CUTOFF_C1_1,
632 cfg->cutoff_regs[i]);
633 }
634
635 /* Run the DSP */
636 snd_soc_write(codec, WM8958_DSP2_EXECCONTROL,
637 WM8958_DSP2_RUNR);
638
639 /* And we're off! */
640 snd_soc_update_bits(codec, WM8958_DSP2_CONFIG,
641 WM8958_MBC_ENA | WM8958_MBC_SEL_MASK,
642 mbc << WM8958_MBC_SEL_SHIFT |
643 WM8958_MBC_ENA);
644 } else {
645 /* If the DSP is already stopped then noop */
646 if (!(reg & WM8958_DSP2_ENA))
647 return;
648
649 snd_soc_update_bits(codec, WM8958_DSP2_CONFIG,
650 WM8958_MBC_ENA, 0);
651 snd_soc_update_bits(codec, WM8958_DSP2_PROGRAM,
652 WM8958_DSP2_ENA, 0);
653 snd_soc_update_bits(codec, WM8994_CLOCKING_1,
654 WM8958_DSP2CLK_ENA, 0);
655 }
656}
657
658static int wm8958_aif_ev(struct snd_soc_dapm_widget *w,
659 struct snd_kcontrol *kcontrol, int event)
660{
661 struct snd_soc_codec *codec = w->codec;
662 int mbc;
663
664 switch (w->shift) {
665 case 13:
666 case 12:
667 mbc = 2;
668 break;
669 case 11:
670 case 10:
671 mbc = 1;
672 break;
673 case 9:
674 case 8:
675 mbc = 0;
676 break;
677 default:
678 BUG();
679 return -EINVAL;
680 }
681
682 switch (event) {
683 case SND_SOC_DAPM_POST_PMU:
684 wm8958_mbc_apply(codec, mbc, 1);
685 break;
686 case SND_SOC_DAPM_POST_PMD:
687 wm8958_mbc_apply(codec, mbc, 0);
688 break;
689 }
690
691 return 0;
692}
693
694static int wm8958_put_mbc_enum(struct snd_kcontrol *kcontrol,
695 struct snd_ctl_elem_value *ucontrol)
696{
697 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
698 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
699 struct wm8994_pdata *pdata = wm8994->pdata;
700 int value = ucontrol->value.integer.value[0];
701 int reg;
702
703 /* Don't allow on the fly reconfiguration */
704 reg = snd_soc_read(codec, WM8994_CLOCKING_1);
705 if (reg < 0 || reg & WM8958_DSP2CLK_ENA)
706 return -EBUSY;
707
708 if (value >= pdata->num_mbc_cfgs)
709 return -EINVAL;
710
711 wm8994->mbc_cfg = value;
712
713 return 0;
714}
715
716static int wm8958_get_mbc_enum(struct snd_kcontrol *kcontrol,
717 struct snd_ctl_elem_value *ucontrol)
718{
719 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
720 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
721
722 ucontrol->value.enumerated.item[0] = wm8994->mbc_cfg;
723
724 return 0;
725}
726
727static int wm8958_mbc_info(struct snd_kcontrol *kcontrol,
728 struct snd_ctl_elem_info *uinfo)
729{
730 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
731 uinfo->count = 1;
732 uinfo->value.integer.min = 0;
733 uinfo->value.integer.max = 1;
734 return 0;
735}
736
737static int wm8958_mbc_get(struct snd_kcontrol *kcontrol,
738 struct snd_ctl_elem_value *ucontrol)
739{
740 int mbc = kcontrol->private_value;
741 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
742 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
743
744 ucontrol->value.integer.value[0] = wm8994->mbc_ena[mbc];
745
746 return 0;
747}
748
749static int wm8958_mbc_put(struct snd_kcontrol *kcontrol,
750 struct snd_ctl_elem_value *ucontrol)
751{
752 int mbc = kcontrol->private_value;
753 int i;
754 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
755 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
756
757 if (ucontrol->value.integer.value[0] > 1)
758 return -EINVAL;
759
760 for (i = 0; i < ARRAY_SIZE(wm8994->mbc_ena); i++) {
761 if (mbc != i && wm8994->mbc_ena[i]) {
762 dev_dbg(codec->dev, "MBC %d active already\n", mbc);
763 return -EBUSY;
764 }
765 }
766
767 wm8994->mbc_ena[mbc] = ucontrol->value.integer.value[0];
768
769 wm8958_mbc_apply(codec, mbc, wm8994->mbc_ena[mbc]);
770
771 return 0;
772}
773
774#define WM8958_MBC_SWITCH(xname, xval) {\
775 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname), \
776 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,\
777 .info = wm8958_mbc_info, \
778 .get = wm8958_mbc_get, .put = wm8958_mbc_put, \
779 .private_value = xval }
2089 780
2090static const struct snd_kcontrol_new wm8994_snd_controls[] = { 781static const struct snd_kcontrol_new wm8994_snd_controls[] = {
2091SOC_DOUBLE_R_TLV("AIF1ADC1 Volume", WM8994_AIF1_ADC1_LEFT_VOLUME, 782SOC_DOUBLE_R_TLV("AIF1ADC1 Volume", WM8994_AIF1_ADC1_LEFT_VOLUME,
@@ -2098,10 +789,15 @@ SOC_DOUBLE_R_TLV("AIF2ADC Volume", WM8994_AIF2_ADC_LEFT_VOLUME,
2098 WM8994_AIF2_ADC_RIGHT_VOLUME, 789 WM8994_AIF2_ADC_RIGHT_VOLUME,
2099 1, 119, 0, digital_tlv), 790 1, 119, 0, digital_tlv),
2100 791
792SOC_ENUM("AIF1ADCL Source", aif1adcl_src),
793SOC_ENUM("AIF1ADCR Source", aif1adcr_src),
794SOC_ENUM("AIF2ADCL Source", aif2adcl_src),
795SOC_ENUM("AIF2ADCR Source", aif2adcr_src),
796
2101SOC_ENUM("AIF1DACL Source", aif1dacl_src), 797SOC_ENUM("AIF1DACL Source", aif1dacl_src),
2102SOC_ENUM("AIF1DACR Source", aif1dacr_src), 798SOC_ENUM("AIF1DACR Source", aif1dacr_src),
2103SOC_ENUM("AIF2DACL Source", aif1dacl_src), 799SOC_ENUM("AIF2DACL Source", aif2dacl_src),
2104SOC_ENUM("AIF2DACR Source", aif1dacr_src), 800SOC_ENUM("AIF2DACR Source", aif2dacr_src),
2105 801
2106SOC_DOUBLE_R_TLV("AIF1DAC1 Volume", WM8994_AIF1_DAC1_LEFT_VOLUME, 802SOC_DOUBLE_R_TLV("AIF1DAC1 Volume", WM8994_AIF1_DAC1_LEFT_VOLUME,
2107 WM8994_AIF1_DAC1_RIGHT_VOLUME, 1, 96, 0, digital_tlv), 803 WM8994_AIF1_DAC1_RIGHT_VOLUME, 1, 96, 0, digital_tlv),
@@ -2140,6 +836,18 @@ SOC_SINGLE_TLV("DAC2 Left Sidetone Volume", WM8994_DAC2_MIXER_VOLUMES,
2140SOC_ENUM("Sidetone HPF Mux", sidetone_hpf), 836SOC_ENUM("Sidetone HPF Mux", sidetone_hpf),
2141SOC_SINGLE("Sidetone HPF Switch", WM8994_SIDETONE, 6, 1, 0), 837SOC_SINGLE("Sidetone HPF Switch", WM8994_SIDETONE, 6, 1, 0),
2142 838
839SOC_ENUM("AIF1ADC1 HPF Mode", aif1adc1_hpf),
840SOC_DOUBLE("AIF1ADC1 HPF Switch", WM8994_AIF1_ADC1_FILTERS, 12, 11, 1, 0),
841
842SOC_ENUM("AIF1ADC2 HPF Mode", aif1adc2_hpf),
843SOC_DOUBLE("AIF1ADC2 HPF Switch", WM8994_AIF1_ADC2_FILTERS, 12, 11, 1, 0),
844
845SOC_ENUM("AIF2ADC HPF Mode", aif2adc_hpf),
846SOC_DOUBLE("AIF2ADC HPF Switch", WM8994_AIF2_ADC_FILTERS, 12, 11, 1, 0),
847
848SOC_ENUM("ADC OSR", adc_osr),
849SOC_ENUM("DAC OSR", dac_osr),
850
2143SOC_DOUBLE_R_TLV("DAC1 Volume", WM8994_DAC1_LEFT_VOLUME, 851SOC_DOUBLE_R_TLV("DAC1 Volume", WM8994_DAC1_LEFT_VOLUME,
2144 WM8994_DAC1_RIGHT_VOLUME, 1, 96, 0, digital_tlv), 852 WM8994_DAC1_RIGHT_VOLUME, 1, 96, 0, digital_tlv),
2145SOC_DOUBLE_R("DAC1 Switch", WM8994_DAC1_LEFT_VOLUME, 853SOC_DOUBLE_R("DAC1 Switch", WM8994_DAC1_LEFT_VOLUME,
@@ -2162,15 +870,15 @@ SOC_SINGLE_TLV("SPKR DAC1 Volume", WM8994_SPKMIXR_ATTENUATION,
2162 870
2163SOC_SINGLE_TLV("AIF1DAC1 3D Stereo Volume", WM8994_AIF1_DAC1_FILTERS_2, 871SOC_SINGLE_TLV("AIF1DAC1 3D Stereo Volume", WM8994_AIF1_DAC1_FILTERS_2,
2164 10, 15, 0, wm8994_3d_tlv), 872 10, 15, 0, wm8994_3d_tlv),
2165SOC_SINGLE("AIF1DAC1 3D Stereo Switch", WM8994_AIF1_DAC2_FILTERS_2, 873SOC_SINGLE("AIF1DAC1 3D Stereo Switch", WM8994_AIF1_DAC1_FILTERS_2,
2166 8, 1, 0), 874 8, 1, 0),
2167SOC_SINGLE_TLV("AIF1DAC2 3D Stereo Volume", WM8994_AIF1_DAC2_FILTERS_2, 875SOC_SINGLE_TLV("AIF1DAC2 3D Stereo Volume", WM8994_AIF1_DAC2_FILTERS_2,
2168 10, 15, 0, wm8994_3d_tlv), 876 10, 15, 0, wm8994_3d_tlv),
2169SOC_SINGLE("AIF1DAC2 3D Stereo Switch", WM8994_AIF1_DAC2_FILTERS_2, 877SOC_SINGLE("AIF1DAC2 3D Stereo Switch", WM8994_AIF1_DAC2_FILTERS_2,
2170 8, 1, 0), 878 8, 1, 0),
2171SOC_SINGLE_TLV("AIF2DAC 3D Stereo Volume", WM8994_AIF1_DAC1_FILTERS_2, 879SOC_SINGLE_TLV("AIF2DAC 3D Stereo Volume", WM8994_AIF2_DAC_FILTERS_2,
2172 10, 15, 0, wm8994_3d_tlv), 880 10, 15, 0, wm8994_3d_tlv),
2173SOC_SINGLE("AIF2DAC 3D Stereo Switch", WM8994_AIF1_DAC2_FILTERS_2, 881SOC_SINGLE("AIF2DAC 3D Stereo Switch", WM8994_AIF2_DAC_FILTERS_2,
2174 8, 1, 0), 882 8, 1, 0),
2175}; 883};
2176 884
@@ -2209,6 +917,13 @@ SOC_SINGLE_TLV("AIF2 EQ5 Volume", WM8994_AIF2_EQ_GAINS_2, 6, 31, 0,
2209 eq_tlv), 917 eq_tlv),
2210}; 918};
2211 919
920static const struct snd_kcontrol_new wm8958_snd_controls[] = {
921SOC_SINGLE_TLV("AIF3 Boost Volume", WM8958_AIF3_CONTROL_2, 10, 3, 0, aif_tlv),
922WM8958_MBC_SWITCH("AIF1DAC1 MBC Switch", 0),
923WM8958_MBC_SWITCH("AIF1DAC2 MBC Switch", 1),
924WM8958_MBC_SWITCH("AIF2DAC MBC Switch", 2),
925};
926
2212static int clk_sys_event(struct snd_soc_dapm_widget *w, 927static int clk_sys_event(struct snd_soc_dapm_widget *w,
2213 struct snd_kcontrol *kcontrol, int event) 928 struct snd_kcontrol *kcontrol, int event)
2214{ 929{
@@ -2228,6 +943,7 @@ static int clk_sys_event(struct snd_soc_dapm_widget *w,
2228 943
2229static void wm8994_update_class_w(struct snd_soc_codec *codec) 944static void wm8994_update_class_w(struct snd_soc_codec *codec)
2230{ 945{
946 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
2231 int enable = 1; 947 int enable = 1;
2232 int source = 0; /* GCC flow analysis can't track enable */ 948 int source = 0; /* GCC flow analysis can't track enable */
2233 int reg, reg_r; 949 int reg, reg_r;
@@ -2278,11 +994,13 @@ static void wm8994_update_class_w(struct snd_soc_codec *codec)
2278 WM8994_CP_DYN_PWR | 994 WM8994_CP_DYN_PWR |
2279 WM8994_CP_DYN_SRC_SEL_MASK, 995 WM8994_CP_DYN_SRC_SEL_MASK,
2280 source | WM8994_CP_DYN_PWR); 996 source | WM8994_CP_DYN_PWR);
997 wm8994->hubs.class_w = true;
2281 998
2282 } else { 999 } else {
2283 dev_dbg(codec->dev, "Class W disabled\n"); 1000 dev_dbg(codec->dev, "Class W disabled\n");
2284 snd_soc_update_bits(codec, WM8994_CLASS_W_1, 1001 snd_soc_update_bits(codec, WM8994_CLASS_W_1,
2285 WM8994_CP_DYN_PWR, 0); 1002 WM8994_CP_DYN_PWR, 0);
1003 wm8994->hubs.class_w = false;
2286 } 1004 }
2287} 1005}
2288 1006
@@ -2512,14 +1230,47 @@ static const struct snd_kcontrol_new aif2adc_mux =
2512 SOC_DAPM_ENUM("AIF2ADC Mux", aif2adc_enum); 1230 SOC_DAPM_ENUM("AIF2ADC Mux", aif2adc_enum);
2513 1231
2514static const char *aif3adc_text[] = { 1232static const char *aif3adc_text[] = {
2515 "AIF1ADCDAT", "AIF2ADCDAT", "AIF2DACDAT", 1233 "AIF1ADCDAT", "AIF2ADCDAT", "AIF2DACDAT", "Mono PCM",
2516}; 1234};
2517 1235
2518static const struct soc_enum aif3adc_enum = 1236static const struct soc_enum wm8994_aif3adc_enum =
2519 SOC_ENUM_SINGLE(WM8994_POWER_MANAGEMENT_6, 3, 3, aif3adc_text); 1237 SOC_ENUM_SINGLE(WM8994_POWER_MANAGEMENT_6, 3, 3, aif3adc_text);
2520 1238
2521static const struct snd_kcontrol_new aif3adc_mux = 1239static const struct snd_kcontrol_new wm8994_aif3adc_mux =
2522 SOC_DAPM_ENUM("AIF3ADC Mux", aif3adc_enum); 1240 SOC_DAPM_ENUM("AIF3ADC Mux", wm8994_aif3adc_enum);
1241
1242static const struct soc_enum wm8958_aif3adc_enum =
1243 SOC_ENUM_SINGLE(WM8994_POWER_MANAGEMENT_6, 3, 4, aif3adc_text);
1244
1245static const struct snd_kcontrol_new wm8958_aif3adc_mux =
1246 SOC_DAPM_ENUM("AIF3ADC Mux", wm8958_aif3adc_enum);
1247
1248static const char *mono_pcm_out_text[] = {
1249 "None", "AIF2ADCL", "AIF2ADCR",
1250};
1251
1252static const struct soc_enum mono_pcm_out_enum =
1253 SOC_ENUM_SINGLE(WM8994_POWER_MANAGEMENT_6, 9, 3, mono_pcm_out_text);
1254
1255static const struct snd_kcontrol_new mono_pcm_out_mux =
1256 SOC_DAPM_ENUM("Mono PCM Out Mux", mono_pcm_out_enum);
1257
1258static const char *aif2dac_src_text[] = {
1259 "AIF2", "AIF3",
1260};
1261
1262/* Note that these two control shouldn't be simultaneously switched to AIF3 */
1263static const struct soc_enum aif2dacl_src_enum =
1264 SOC_ENUM_SINGLE(WM8994_POWER_MANAGEMENT_6, 7, 2, aif2dac_src_text);
1265
1266static const struct snd_kcontrol_new aif2dacl_src_mux =
1267 SOC_DAPM_ENUM("AIF2DACL Mux", aif2dacl_src_enum);
1268
1269static const struct soc_enum aif2dacr_src_enum =
1270 SOC_ENUM_SINGLE(WM8994_POWER_MANAGEMENT_6, 8, 2, aif2dac_src_text);
1271
1272static const struct snd_kcontrol_new aif2dacr_src_mux =
1273 SOC_DAPM_ENUM("AIF2DACR Mux", aif2dacr_src_enum);
2523 1274
2524static const struct snd_soc_dapm_widget wm8994_dapm_widgets[] = { 1275static const struct snd_soc_dapm_widget wm8994_dapm_widgets[] = {
2525SND_SOC_DAPM_INPUT("DMIC1DAT"), 1276SND_SOC_DAPM_INPUT("DMIC1DAT"),
@@ -2540,19 +1291,23 @@ SND_SOC_DAPM_AIF_OUT("AIF1ADC1L", "AIF1 Capture",
2540 0, WM8994_POWER_MANAGEMENT_4, 9, 0), 1291 0, WM8994_POWER_MANAGEMENT_4, 9, 0),
2541SND_SOC_DAPM_AIF_OUT("AIF1ADC1R", "AIF1 Capture", 1292SND_SOC_DAPM_AIF_OUT("AIF1ADC1R", "AIF1 Capture",
2542 0, WM8994_POWER_MANAGEMENT_4, 8, 0), 1293 0, WM8994_POWER_MANAGEMENT_4, 8, 0),
2543SND_SOC_DAPM_AIF_IN("AIF1DAC1L", NULL, 0, 1294SND_SOC_DAPM_AIF_IN_E("AIF1DAC1L", NULL, 0,
2544 WM8994_POWER_MANAGEMENT_5, 9, 0), 1295 WM8994_POWER_MANAGEMENT_5, 9, 0, wm8958_aif_ev,
2545SND_SOC_DAPM_AIF_IN("AIF1DAC1R", NULL, 0, 1296 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
2546 WM8994_POWER_MANAGEMENT_5, 8, 0), 1297SND_SOC_DAPM_AIF_IN_E("AIF1DAC1R", NULL, 0,
1298 WM8994_POWER_MANAGEMENT_5, 8, 0, wm8958_aif_ev,
1299 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
2547 1300
2548SND_SOC_DAPM_AIF_OUT("AIF1ADC2L", "AIF1 Capture", 1301SND_SOC_DAPM_AIF_OUT("AIF1ADC2L", "AIF1 Capture",
2549 0, WM8994_POWER_MANAGEMENT_4, 11, 0), 1302 0, WM8994_POWER_MANAGEMENT_4, 11, 0),
2550SND_SOC_DAPM_AIF_OUT("AIF1ADC2R", "AIF1 Capture", 1303SND_SOC_DAPM_AIF_OUT("AIF1ADC2R", "AIF1 Capture",
2551 0, WM8994_POWER_MANAGEMENT_4, 10, 0), 1304 0, WM8994_POWER_MANAGEMENT_4, 10, 0),
2552SND_SOC_DAPM_AIF_IN("AIF1DAC2L", NULL, 0, 1305SND_SOC_DAPM_AIF_IN_E("AIF1DAC2L", NULL, 0,
2553 WM8994_POWER_MANAGEMENT_5, 11, 0), 1306 WM8994_POWER_MANAGEMENT_5, 11, 0, wm8958_aif_ev,
2554SND_SOC_DAPM_AIF_IN("AIF1DAC2R", NULL, 0, 1307 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
2555 WM8994_POWER_MANAGEMENT_5, 10, 0), 1308SND_SOC_DAPM_AIF_IN_E("AIF1DAC2R", NULL, 0,
1309 WM8994_POWER_MANAGEMENT_5, 10, 0, wm8958_aif_ev,
1310 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
2556 1311
2557SND_SOC_DAPM_MIXER("AIF1ADC1L Mixer", SND_SOC_NOPM, 0, 0, 1312SND_SOC_DAPM_MIXER("AIF1ADC1L Mixer", SND_SOC_NOPM, 0, 0,
2558 aif1adc1l_mix, ARRAY_SIZE(aif1adc1l_mix)), 1313 aif1adc1l_mix, ARRAY_SIZE(aif1adc1l_mix)),
@@ -2581,10 +1336,12 @@ SND_SOC_DAPM_AIF_OUT("AIF2ADCL", NULL, 0,
2581 WM8994_POWER_MANAGEMENT_4, 13, 0), 1336 WM8994_POWER_MANAGEMENT_4, 13, 0),
2582SND_SOC_DAPM_AIF_OUT("AIF2ADCR", NULL, 0, 1337SND_SOC_DAPM_AIF_OUT("AIF2ADCR", NULL, 0,
2583 WM8994_POWER_MANAGEMENT_4, 12, 0), 1338 WM8994_POWER_MANAGEMENT_4, 12, 0),
2584SND_SOC_DAPM_AIF_IN("AIF2DACL", NULL, 0, 1339SND_SOC_DAPM_AIF_IN_E("AIF2DACL", NULL, 0,
2585 WM8994_POWER_MANAGEMENT_5, 13, 0), 1340 WM8994_POWER_MANAGEMENT_5, 13, 0, wm8958_aif_ev,
2586SND_SOC_DAPM_AIF_IN("AIF2DACR", NULL, 0, 1341 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD),
2587 WM8994_POWER_MANAGEMENT_5, 12, 0), 1342SND_SOC_DAPM_AIF_IN_E("AIF2DACR", NULL, 0,
1343 WM8994_POWER_MANAGEMENT_5, 12, 0, wm8958_aif_ev,
1344 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD),
2588 1345
2589SND_SOC_DAPM_AIF_IN("AIF1DACDAT", "AIF1 Playback", 0, SND_SOC_NOPM, 0, 0), 1346SND_SOC_DAPM_AIF_IN("AIF1DACDAT", "AIF1 Playback", 0, SND_SOC_NOPM, 0, 0),
2590SND_SOC_DAPM_AIF_IN("AIF2DACDAT", "AIF2 Playback", 0, SND_SOC_NOPM, 0, 0), 1347SND_SOC_DAPM_AIF_IN("AIF2DACDAT", "AIF2 Playback", 0, SND_SOC_NOPM, 0, 0),
@@ -2593,7 +1350,6 @@ SND_SOC_DAPM_AIF_OUT("AIF2ADCDAT", "AIF2 Capture", 0, SND_SOC_NOPM, 0, 0),
2593SND_SOC_DAPM_MUX("AIF1DAC Mux", SND_SOC_NOPM, 0, 0, &aif1dac_mux), 1350SND_SOC_DAPM_MUX("AIF1DAC Mux", SND_SOC_NOPM, 0, 0, &aif1dac_mux),
2594SND_SOC_DAPM_MUX("AIF2DAC Mux", SND_SOC_NOPM, 0, 0, &aif2dac_mux), 1351SND_SOC_DAPM_MUX("AIF2DAC Mux", SND_SOC_NOPM, 0, 0, &aif2dac_mux),
2595SND_SOC_DAPM_MUX("AIF2ADC Mux", SND_SOC_NOPM, 0, 0, &aif2adc_mux), 1352SND_SOC_DAPM_MUX("AIF2ADC Mux", SND_SOC_NOPM, 0, 0, &aif2adc_mux),
2596SND_SOC_DAPM_MUX("AIF3ADC Mux", SND_SOC_NOPM, 0, 0, &aif3adc_mux),
2597 1353
2598SND_SOC_DAPM_AIF_IN("AIF3DACDAT", "AIF3 Playback", 0, SND_SOC_NOPM, 0, 0), 1354SND_SOC_DAPM_AIF_IN("AIF3DACDAT", "AIF3 Playback", 0, SND_SOC_NOPM, 0, 0),
2599SND_SOC_DAPM_AIF_IN("AIF3ADCDAT", "AIF3 Capture", 0, SND_SOC_NOPM, 0, 0), 1355SND_SOC_DAPM_AIF_IN("AIF3ADCDAT", "AIF3 Capture", 0, SND_SOC_NOPM, 0, 0),
@@ -2631,8 +1387,18 @@ SND_SOC_DAPM_MIXER("SPKR", WM8994_POWER_MANAGEMENT_3, 9, 0,
2631SND_SOC_DAPM_POST("Debug log", post_ev), 1387SND_SOC_DAPM_POST("Debug log", post_ev),
2632}; 1388};
2633 1389
2634static const struct snd_soc_dapm_route intercon[] = { 1390static const struct snd_soc_dapm_widget wm8994_specific_dapm_widgets[] = {
1391SND_SOC_DAPM_MUX("AIF3ADC Mux", SND_SOC_NOPM, 0, 0, &wm8994_aif3adc_mux),
1392};
1393
1394static const struct snd_soc_dapm_widget wm8958_dapm_widgets[] = {
1395SND_SOC_DAPM_MUX("Mono PCM Out Mux", SND_SOC_NOPM, 0, 0, &mono_pcm_out_mux),
1396SND_SOC_DAPM_MUX("AIF2DACL Mux", SND_SOC_NOPM, 0, 0, &aif2dacl_src_mux),
1397SND_SOC_DAPM_MUX("AIF2DACR Mux", SND_SOC_NOPM, 0, 0, &aif2dacr_src_mux),
1398SND_SOC_DAPM_MUX("AIF3ADC Mux", SND_SOC_NOPM, 0, 0, &wm8958_aif3adc_mux),
1399};
2635 1400
1401static const struct snd_soc_dapm_route intercon[] = {
2636 { "CLK_SYS", NULL, "AIF1CLK", check_clk_sys }, 1402 { "CLK_SYS", NULL, "AIF1CLK", check_clk_sys },
2637 { "CLK_SYS", NULL, "AIF2CLK", check_clk_sys }, 1403 { "CLK_SYS", NULL, "AIF2CLK", check_clk_sys },
2638 1404
@@ -2740,9 +1506,6 @@ static const struct snd_soc_dapm_route intercon[] = {
2740 { "AIF1DAC2L", NULL, "AIF1DAC Mux" }, 1506 { "AIF1DAC2L", NULL, "AIF1DAC Mux" },
2741 { "AIF1DAC2R", NULL, "AIF1DAC Mux" }, 1507 { "AIF1DAC2R", NULL, "AIF1DAC Mux" },
2742 1508
2743 { "AIF2DACL", NULL, "AIF2DAC Mux" },
2744 { "AIF2DACR", NULL, "AIF2DAC Mux" },
2745
2746 { "AIF1DAC Mux", "AIF1DACDAT", "AIF1DACDAT" }, 1509 { "AIF1DAC Mux", "AIF1DACDAT", "AIF1DACDAT" },
2747 { "AIF1DAC Mux", "AIF3DACDAT", "AIF3DACDAT" }, 1510 { "AIF1DAC Mux", "AIF3DACDAT", "AIF3DACDAT" },
2748 { "AIF2DAC Mux", "AIF2DACDAT", "AIF2DACDAT" }, 1511 { "AIF2DAC Mux", "AIF2DACDAT", "AIF2DACDAT" },
@@ -2815,6 +1578,26 @@ static const struct snd_soc_dapm_route intercon[] = {
2815 { "Right Headphone Mux", "DAC", "DAC1R" }, 1578 { "Right Headphone Mux", "DAC", "DAC1R" },
2816}; 1579};
2817 1580
1581static const struct snd_soc_dapm_route wm8994_intercon[] = {
1582 { "AIF2DACL", NULL, "AIF2DAC Mux" },
1583 { "AIF2DACR", NULL, "AIF2DAC Mux" },
1584};
1585
1586static const struct snd_soc_dapm_route wm8958_intercon[] = {
1587 { "AIF2DACL", NULL, "AIF2DACL Mux" },
1588 { "AIF2DACR", NULL, "AIF2DACR Mux" },
1589
1590 { "AIF2DACL Mux", "AIF2", "AIF2DAC Mux" },
1591 { "AIF2DACL Mux", "AIF3", "AIF3DACDAT" },
1592 { "AIF2DACR Mux", "AIF2", "AIF2DAC Mux" },
1593 { "AIF2DACR Mux", "AIF3", "AIF3DACDAT" },
1594
1595 { "Mono PCM Out Mux", "AIF2ADCL", "AIF2ADCL" },
1596 { "Mono PCM Out Mux", "AIF2ADCR", "AIF2ADCR" },
1597
1598 { "AIF3ADC Mux", "Mono PCM", "Mono PCM Out Mux" },
1599};
1600
2818/* The size in bits of the FLL divide multiplied by 10 1601/* The size in bits of the FLL divide multiplied by 10
2819 * to allow rounding later */ 1602 * to allow rounding later */
2820#define FIXED_FLL_SIZE ((1 << 16) * 10) 1603#define FIXED_FLL_SIZE ((1 << 16) * 10)
@@ -2930,6 +1713,7 @@ static int _wm8994_set_fll(struct snd_soc_codec *codec, int id, int src,
2930 /* Allow no source specification when stopping */ 1713 /* Allow no source specification when stopping */
2931 if (freq_out) 1714 if (freq_out)
2932 return -EINVAL; 1715 return -EINVAL;
1716 src = wm8994->fll[id].src;
2933 break; 1717 break;
2934 case WM8994_FLL_SRC_MCLK1: 1718 case WM8994_FLL_SRC_MCLK1:
2935 case WM8994_FLL_SRC_MCLK2: 1719 case WM8994_FLL_SRC_MCLK2:
@@ -3094,6 +1878,7 @@ static int wm8994_set_dai_sysclk(struct snd_soc_dai *dai,
3094static int wm8994_set_bias_level(struct snd_soc_codec *codec, 1878static int wm8994_set_bias_level(struct snd_soc_codec *codec,
3095 enum snd_soc_bias_level level) 1879 enum snd_soc_bias_level level)
3096{ 1880{
1881 struct wm8994 *control = codec->control_data;
3097 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec); 1882 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
3098 1883
3099 switch (level) { 1884 switch (level) {
@@ -3107,16 +1892,36 @@ static int wm8994_set_bias_level(struct snd_soc_codec *codec,
3107 break; 1892 break;
3108 1893
3109 case SND_SOC_BIAS_STANDBY: 1894 case SND_SOC_BIAS_STANDBY:
3110 if (codec->bias_level == SND_SOC_BIAS_OFF) { 1895 if (codec->dapm.bias_level == SND_SOC_BIAS_OFF) {
3111 /* Tweak DC servo and DSP configuration for 1896 pm_runtime_get_sync(codec->dev);
3112 * improved performance. */ 1897
3113 if (wm8994->revision < 4) { 1898 switch (control->type) {
3114 /* Tweak DC servo and DSP configuration for 1899 case WM8994:
3115 * improved performance. */ 1900 if (wm8994->revision < 4) {
3116 snd_soc_write(codec, 0x102, 0x3); 1901 /* Tweak DC servo and DSP
3117 snd_soc_write(codec, 0x56, 0x3); 1902 * configuration for improved
3118 snd_soc_write(codec, 0x817, 0); 1903 * performance. */
3119 snd_soc_write(codec, 0x102, 0); 1904 snd_soc_write(codec, 0x102, 0x3);
1905 snd_soc_write(codec, 0x56, 0x3);
1906 snd_soc_write(codec, 0x817, 0);
1907 snd_soc_write(codec, 0x102, 0);
1908 }
1909 break;
1910
1911 case WM8958:
1912 if (wm8994->revision == 0) {
1913 /* Optimise performance for rev A */
1914 snd_soc_write(codec, 0x102, 0x3);
1915 snd_soc_write(codec, 0xcb, 0x81);
1916 snd_soc_write(codec, 0x817, 0);
1917 snd_soc_write(codec, 0x102, 0);
1918
1919 snd_soc_update_bits(codec,
1920 WM8958_CHARGE_PUMP_2,
1921 WM8958_CP_DISCH,
1922 WM8958_CP_DISCH);
1923 }
1924 break;
3120 } 1925 }
3121 1926
3122 /* Discharge LINEOUT1 & 2 */ 1927 /* Discharge LINEOUT1 & 2 */
@@ -3151,7 +1956,7 @@ static int wm8994_set_bias_level(struct snd_soc_codec *codec,
3151 break; 1956 break;
3152 1957
3153 case SND_SOC_BIAS_OFF: 1958 case SND_SOC_BIAS_OFF:
3154 if (codec->bias_level == SND_SOC_BIAS_STANDBY) { 1959 if (codec->dapm.bias_level == SND_SOC_BIAS_STANDBY) {
3155 /* Switch over to startup biases */ 1960 /* Switch over to startup biases */
3156 snd_soc_update_bits(codec, WM8994_ANTIPOP_2, 1961 snd_soc_update_bits(codec, WM8994_ANTIPOP_2,
3157 WM8994_BIAS_SRC | 1962 WM8994_BIAS_SRC |
@@ -3183,16 +1988,19 @@ static int wm8994_set_bias_level(struct snd_soc_codec *codec,
3183 WM8994_STARTUP_BIAS_ENA | 1988 WM8994_STARTUP_BIAS_ENA |
3184 WM8994_VMID_BUF_ENA | 1989 WM8994_VMID_BUF_ENA |
3185 WM8994_VMID_RAMP_MASK, 0); 1990 WM8994_VMID_RAMP_MASK, 0);
1991
1992 pm_runtime_put(codec->dev);
3186 } 1993 }
3187 break; 1994 break;
3188 } 1995 }
3189 codec->bias_level = level; 1996 codec->dapm.bias_level = level;
3190 return 0; 1997 return 0;
3191} 1998}
3192 1999
3193static int wm8994_set_dai_fmt(struct snd_soc_dai *dai, unsigned int fmt) 2000static int wm8994_set_dai_fmt(struct snd_soc_dai *dai, unsigned int fmt)
3194{ 2001{
3195 struct snd_soc_codec *codec = dai->codec; 2002 struct snd_soc_codec *codec = dai->codec;
2003 struct wm8994 *control = codec->control_data;
3196 int ms_reg; 2004 int ms_reg;
3197 int aif1_reg; 2005 int aif1_reg;
3198 int ms = 0; 2006 int ms = 0;
@@ -3277,6 +2085,13 @@ static int wm8994_set_dai_fmt(struct snd_soc_dai *dai, unsigned int fmt)
3277 return -EINVAL; 2085 return -EINVAL;
3278 } 2086 }
3279 2087
2088 /* The AIF2 format configuration needs to be mirrored to AIF3
2089 * on WM8958 if it's in use so just do it all the time. */
2090 if (control->type == WM8958 && dai->id == 2)
2091 snd_soc_update_bits(codec, WM8958_AIF3_CONTROL_1,
2092 WM8994_AIF1_LRCLK_INV |
2093 WM8958_AIF3_FMT_MASK, aif1);
2094
3280 snd_soc_update_bits(codec, aif1_reg, 2095 snd_soc_update_bits(codec, aif1_reg,
3281 WM8994_AIF1_BCLK_INV | WM8994_AIF1_LRCLK_INV | 2096 WM8994_AIF1_BCLK_INV | WM8994_AIF1_LRCLK_INV |
3282 WM8994_AIF1_FMT_MASK, 2097 WM8994_AIF1_FMT_MASK,
@@ -3317,12 +2132,15 @@ static int wm8994_hw_params(struct snd_pcm_substream *substream,
3317 struct snd_soc_dai *dai) 2132 struct snd_soc_dai *dai)
3318{ 2133{
3319 struct snd_soc_codec *codec = dai->codec; 2134 struct snd_soc_codec *codec = dai->codec;
2135 struct wm8994 *control = codec->control_data;
3320 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec); 2136 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
3321 int aif1_reg; 2137 int aif1_reg;
2138 int aif2_reg;
3322 int bclk_reg; 2139 int bclk_reg;
3323 int lrclk_reg; 2140 int lrclk_reg;
3324 int rate_reg; 2141 int rate_reg;
3325 int aif1 = 0; 2142 int aif1 = 0;
2143 int aif2 = 0;
3326 int bclk = 0; 2144 int bclk = 0;
3327 int lrclk = 0; 2145 int lrclk = 0;
3328 int rate_val = 0; 2146 int rate_val = 0;
@@ -3333,6 +2151,7 @@ static int wm8994_hw_params(struct snd_pcm_substream *substream,
3333 switch (dai->id) { 2151 switch (dai->id) {
3334 case 1: 2152 case 1:
3335 aif1_reg = WM8994_AIF1_CONTROL_1; 2153 aif1_reg = WM8994_AIF1_CONTROL_1;
2154 aif2_reg = WM8994_AIF1_CONTROL_2;
3336 bclk_reg = WM8994_AIF1_BCLK; 2155 bclk_reg = WM8994_AIF1_BCLK;
3337 rate_reg = WM8994_AIF1_RATE; 2156 rate_reg = WM8994_AIF1_RATE;
3338 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK || 2157 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK ||
@@ -3345,6 +2164,7 @@ static int wm8994_hw_params(struct snd_pcm_substream *substream,
3345 break; 2164 break;
3346 case 2: 2165 case 2:
3347 aif1_reg = WM8994_AIF2_CONTROL_1; 2166 aif1_reg = WM8994_AIF2_CONTROL_1;
2167 aif2_reg = WM8994_AIF2_CONTROL_2;
3348 bclk_reg = WM8994_AIF2_BCLK; 2168 bclk_reg = WM8994_AIF2_BCLK;
3349 rate_reg = WM8994_AIF2_RATE; 2169 rate_reg = WM8994_AIF2_RATE;
3350 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK || 2170 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK ||
@@ -3355,6 +2175,14 @@ static int wm8994_hw_params(struct snd_pcm_substream *substream,
3355 dev_dbg(codec->dev, "AIF2 using split LRCLK\n"); 2175 dev_dbg(codec->dev, "AIF2 using split LRCLK\n");
3356 } 2176 }
3357 break; 2177 break;
2178 case 3:
2179 switch (control->type) {
2180 case WM8958:
2181 aif1_reg = WM8958_AIF3_CONTROL_1;
2182 break;
2183 default:
2184 return 0;
2185 }
3358 default: 2186 default:
3359 return -EINVAL; 2187 return -EINVAL;
3360 } 2188 }
@@ -3392,6 +2220,10 @@ static int wm8994_hw_params(struct snd_pcm_substream *substream,
3392 dev_dbg(dai->dev, "AIF%dCLK is %dHz, target BCLK %dHz\n", 2220 dev_dbg(dai->dev, "AIF%dCLK is %dHz, target BCLK %dHz\n",
3393 dai->id, wm8994->aifclk[id], bclk_rate); 2221 dai->id, wm8994->aifclk[id], bclk_rate);
3394 2222
2223 if (params_channels(params) == 1 &&
2224 (snd_soc_read(codec, aif1_reg) & 0x18) == 0x18)
2225 aif2 |= WM8994_AIF1_MONO;
2226
3395 if (wm8994->aifclk[id] == 0) { 2227 if (wm8994->aifclk[id] == 0) {
3396 dev_err(dai->dev, "AIF%dCLK not configured\n", dai->id); 2228 dev_err(dai->dev, "AIF%dCLK not configured\n", dai->id);
3397 return -EINVAL; 2229 return -EINVAL;
@@ -3435,6 +2267,7 @@ static int wm8994_hw_params(struct snd_pcm_substream *substream,
3435 lrclk, bclk_rate / lrclk); 2267 lrclk, bclk_rate / lrclk);
3436 2268
3437 snd_soc_update_bits(codec, aif1_reg, WM8994_AIF1_WL_MASK, aif1); 2269 snd_soc_update_bits(codec, aif1_reg, WM8994_AIF1_WL_MASK, aif1);
2270 snd_soc_update_bits(codec, aif2_reg, WM8994_AIF1_MONO, aif2);
3438 snd_soc_update_bits(codec, bclk_reg, WM8994_AIF1_BCLK_DIV_MASK, bclk); 2271 snd_soc_update_bits(codec, bclk_reg, WM8994_AIF1_BCLK_DIV_MASK, bclk);
3439 snd_soc_update_bits(codec, lrclk_reg, WM8994_AIF1DAC_RATE_MASK, 2272 snd_soc_update_bits(codec, lrclk_reg, WM8994_AIF1DAC_RATE_MASK,
3440 lrclk); 2273 lrclk);
@@ -3458,6 +2291,47 @@ static int wm8994_hw_params(struct snd_pcm_substream *substream,
3458 return 0; 2291 return 0;
3459} 2292}
3460 2293
2294static int wm8994_aif3_hw_params(struct snd_pcm_substream *substream,
2295 struct snd_pcm_hw_params *params,
2296 struct snd_soc_dai *dai)
2297{
2298 struct snd_soc_codec *codec = dai->codec;
2299 struct wm8994 *control = codec->control_data;
2300 int aif1_reg;
2301 int aif1 = 0;
2302
2303 switch (dai->id) {
2304 case 3:
2305 switch (control->type) {
2306 case WM8958:
2307 aif1_reg = WM8958_AIF3_CONTROL_1;
2308 break;
2309 default:
2310 return 0;
2311 }
2312 default:
2313 return 0;
2314 }
2315
2316 switch (params_format(params)) {
2317 case SNDRV_PCM_FORMAT_S16_LE:
2318 break;
2319 case SNDRV_PCM_FORMAT_S20_3LE:
2320 aif1 |= 0x20;
2321 break;
2322 case SNDRV_PCM_FORMAT_S24_LE:
2323 aif1 |= 0x40;
2324 break;
2325 case SNDRV_PCM_FORMAT_S32_LE:
2326 aif1 |= 0x60;
2327 break;
2328 default:
2329 return -EINVAL;
2330 }
2331
2332 return snd_soc_update_bits(codec, aif1_reg, WM8994_AIF1_WL_MASK, aif1);
2333}
2334
3461static int wm8994_aif_mute(struct snd_soc_dai *codec_dai, int mute) 2335static int wm8994_aif_mute(struct snd_soc_dai *codec_dai, int mute)
3462{ 2336{
3463 struct snd_soc_codec *codec = codec_dai->codec; 2337 struct snd_soc_codec *codec = codec_dai->codec;
@@ -3539,6 +2413,7 @@ static struct snd_soc_dai_ops wm8994_aif2_dai_ops = {
3539}; 2413};
3540 2414
3541static struct snd_soc_dai_ops wm8994_aif3_dai_ops = { 2415static struct snd_soc_dai_ops wm8994_aif3_dai_ops = {
2416 .hw_params = wm8994_aif3_hw_params,
3542 .set_tristate = wm8994_set_tristate, 2417 .set_tristate = wm8994_set_tristate,
3543}; 2418};
3544 2419
@@ -3548,14 +2423,14 @@ static struct snd_soc_dai_driver wm8994_dai[] = {
3548 .id = 1, 2423 .id = 1,
3549 .playback = { 2424 .playback = {
3550 .stream_name = "AIF1 Playback", 2425 .stream_name = "AIF1 Playback",
3551 .channels_min = 2, 2426 .channels_min = 1,
3552 .channels_max = 2, 2427 .channels_max = 2,
3553 .rates = WM8994_RATES, 2428 .rates = WM8994_RATES,
3554 .formats = WM8994_FORMATS, 2429 .formats = WM8994_FORMATS,
3555 }, 2430 },
3556 .capture = { 2431 .capture = {
3557 .stream_name = "AIF1 Capture", 2432 .stream_name = "AIF1 Capture",
3558 .channels_min = 2, 2433 .channels_min = 1,
3559 .channels_max = 2, 2434 .channels_max = 2,
3560 .rates = WM8994_RATES, 2435 .rates = WM8994_RATES,
3561 .formats = WM8994_FORMATS, 2436 .formats = WM8994_FORMATS,
@@ -3567,14 +2442,14 @@ static struct snd_soc_dai_driver wm8994_dai[] = {
3567 .id = 2, 2442 .id = 2,
3568 .playback = { 2443 .playback = {
3569 .stream_name = "AIF2 Playback", 2444 .stream_name = "AIF2 Playback",
3570 .channels_min = 2, 2445 .channels_min = 1,
3571 .channels_max = 2, 2446 .channels_max = 2,
3572 .rates = WM8994_RATES, 2447 .rates = WM8994_RATES,
3573 .formats = WM8994_FORMATS, 2448 .formats = WM8994_FORMATS,
3574 }, 2449 },
3575 .capture = { 2450 .capture = {
3576 .stream_name = "AIF2 Capture", 2451 .stream_name = "AIF2 Capture",
3577 .channels_min = 2, 2452 .channels_min = 1,
3578 .channels_max = 2, 2453 .channels_max = 2,
3579 .rates = WM8994_RATES, 2454 .rates = WM8994_RATES,
3580 .formats = WM8994_FORMATS, 2455 .formats = WM8994_FORMATS,
@@ -3586,14 +2461,14 @@ static struct snd_soc_dai_driver wm8994_dai[] = {
3586 .id = 3, 2461 .id = 3,
3587 .playback = { 2462 .playback = {
3588 .stream_name = "AIF3 Playback", 2463 .stream_name = "AIF3 Playback",
3589 .channels_min = 2, 2464 .channels_min = 1,
3590 .channels_max = 2, 2465 .channels_max = 2,
3591 .rates = WM8994_RATES, 2466 .rates = WM8994_RATES,
3592 .formats = WM8994_FORMATS, 2467 .formats = WM8994_FORMATS,
3593 }, 2468 },
3594 .capture = { 2469 .capture = {
3595 .stream_name = "AIF3 Capture", 2470 .stream_name = "AIF3 Capture",
3596 .channels_min = 2, 2471 .channels_min = 1,
3597 .channels_max = 2, 2472 .channels_max = 2,
3598 .rates = WM8994_RATES, 2473 .rates = WM8994_RATES,
3599 .formats = WM8994_FORMATS, 2474 .formats = WM8994_FORMATS,
@@ -3625,26 +2500,12 @@ static int wm8994_suspend(struct snd_soc_codec *codec, pm_message_t state)
3625static int wm8994_resume(struct snd_soc_codec *codec) 2500static int wm8994_resume(struct snd_soc_codec *codec)
3626{ 2501{
3627 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec); 2502 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
3628 u16 *reg_cache = codec->reg_cache;
3629 int i, ret; 2503 int i, ret;
3630 2504
3631 /* Restore the registers */ 2505 /* Restore the registers */
3632 for (i = 1; i < ARRAY_SIZE(wm8994->reg_cache); i++) { 2506 ret = snd_soc_cache_sync(codec);
3633 switch (i) { 2507 if (ret != 0)
3634 case WM8994_LDO_1: 2508 dev_err(codec->dev, "Failed to sync cache: %d\n", ret);
3635 case WM8994_LDO_2:
3636 case WM8994_SOFTWARE_RESET:
3637 /* Handled by other MFD drivers */
3638 continue;
3639 default:
3640 break;
3641 }
3642
3643 if (!access_masks[i].writable)
3644 continue;
3645
3646 wm8994_reg_write(codec->control_data, i, reg_cache[i]);
3647 }
3648 2509
3649 wm8994_set_bias_level(codec, SND_SOC_BIAS_STANDBY); 2510 wm8994_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
3650 2511
@@ -3794,6 +2655,34 @@ static void wm8994_handle_pdata(struct wm8994_priv *wm8994)
3794 dev_dbg(codec->dev, "%d ReTune Mobile configurations\n", 2655 dev_dbg(codec->dev, "%d ReTune Mobile configurations\n",
3795 pdata->num_retune_mobile_cfgs); 2656 pdata->num_retune_mobile_cfgs);
3796 2657
2658 if (pdata->num_mbc_cfgs) {
2659 struct snd_kcontrol_new control[] = {
2660 SOC_ENUM_EXT("MBC Mode", wm8994->mbc_enum,
2661 wm8958_get_mbc_enum, wm8958_put_mbc_enum),
2662 };
2663
2664 /* We need an array of texts for the enum API */
2665 wm8994->mbc_texts = kmalloc(sizeof(char *)
2666 * pdata->num_mbc_cfgs, GFP_KERNEL);
2667 if (!wm8994->mbc_texts) {
2668 dev_err(wm8994->codec->dev,
2669 "Failed to allocate %d MBC config texts\n",
2670 pdata->num_mbc_cfgs);
2671 return;
2672 }
2673
2674 for (i = 0; i < pdata->num_mbc_cfgs; i++)
2675 wm8994->mbc_texts[i] = pdata->mbc_cfgs[i].name;
2676
2677 wm8994->mbc_enum.max = pdata->num_mbc_cfgs;
2678 wm8994->mbc_enum.texts = wm8994->mbc_texts;
2679
2680 ret = snd_soc_add_controls(wm8994->codec, control, 1);
2681 if (ret != 0)
2682 dev_err(wm8994->codec->dev,
2683 "Failed to add MBC mode controls: %d\n", ret);
2684 }
2685
3797 if (pdata->num_retune_mobile_cfgs) 2686 if (pdata->num_retune_mobile_cfgs)
3798 wm8994_handle_retune_mobile_pdata(wm8994); 2687 wm8994_handle_retune_mobile_pdata(wm8994);
3799 else 2688 else
@@ -3823,8 +2712,12 @@ int wm8994_mic_detect(struct snd_soc_codec *codec, struct snd_soc_jack *jack,
3823{ 2712{
3824 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec); 2713 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
3825 struct wm8994_micdet *micdet; 2714 struct wm8994_micdet *micdet;
2715 struct wm8994 *control = codec->control_data;
3826 int reg; 2716 int reg;
3827 2717
2718 if (control->type != WM8994)
2719 return -EINVAL;
2720
3828 switch (micbias) { 2721 switch (micbias) {
3829 case 1: 2722 case 1:
3830 micdet = &wm8994->micdet[0]; 2723 micdet = &wm8994->micdet[0];
@@ -3863,6 +2756,10 @@ static irqreturn_t wm8994_mic_irq(int irq, void *data)
3863 int reg; 2756 int reg;
3864 int report; 2757 int report;
3865 2758
2759#ifndef CONFIG_SND_SOC_WM8994_MODULE
2760 trace_snd_soc_jack_irq(dev_name(codec->dev));
2761#endif
2762
3866 reg = snd_soc_read(codec, WM8994_INTERRUPT_RAW_STATUS_2); 2763 reg = snd_soc_read(codec, WM8994_INTERRUPT_RAW_STATUS_2);
3867 if (reg < 0) { 2764 if (reg < 0) {
3868 dev_err(codec->dev, "Failed to read microphone status: %d\n", 2765 dev_err(codec->dev, "Failed to read microphone status: %d\n",
@@ -3891,77 +2788,251 @@ static irqreturn_t wm8994_mic_irq(int irq, void *data)
3891 return IRQ_HANDLED; 2788 return IRQ_HANDLED;
3892} 2789}
3893 2790
2791/* Default microphone detection handler for WM8958 - the user can
2792 * override this if they wish.
2793 */
2794static void wm8958_default_micdet(u16 status, void *data)
2795{
2796 struct snd_soc_codec *codec = data;
2797 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
2798 int report = 0;
2799
2800 /* If nothing present then clear our statuses */
2801 if (!(status & WM8958_MICD_STS)) {
2802 wm8994->jack_is_video = false;
2803 wm8994->jack_is_mic = false;
2804 goto done;
2805 }
2806
2807 /* Assume anything over 475 ohms is a microphone and remember
2808 * that we've seen one (since buttons override it) */
2809 if (status & 0x600)
2810 wm8994->jack_is_mic = true;
2811 if (wm8994->jack_is_mic)
2812 report |= SND_JACK_MICROPHONE;
2813
2814 /* Video has an impedence of approximately 75 ohms; assume
2815 * this isn't used as a button and remember it since buttons
2816 * override it. */
2817 if (status & 0x40)
2818 wm8994->jack_is_video = true;
2819 if (wm8994->jack_is_video)
2820 report |= SND_JACK_VIDEOOUT;
2821
2822 /* Everything else is buttons; just assign slots */
2823 if (status & 0x4)
2824 report |= SND_JACK_BTN_0;
2825 if (status & 0x8)
2826 report |= SND_JACK_BTN_1;
2827 if (status & 0x10)
2828 report |= SND_JACK_BTN_2;
2829 if (status & 0x20)
2830 report |= SND_JACK_BTN_3;
2831 if (status & 0x80)
2832 report |= SND_JACK_BTN_4;
2833 if (status & 0x100)
2834 report |= SND_JACK_BTN_5;
2835
2836done:
2837 snd_soc_jack_report(wm8994->micdet[0].jack,
2838 SND_JACK_BTN_0 | SND_JACK_BTN_1 | SND_JACK_BTN_2 |
2839 SND_JACK_BTN_3 | SND_JACK_BTN_4 | SND_JACK_BTN_5 |
2840 SND_JACK_MICROPHONE | SND_JACK_VIDEOOUT,
2841 report);
2842}
2843
2844/**
2845 * wm8958_mic_detect - Enable microphone detection via the WM8958 IRQ
2846 *
2847 * @codec: WM8958 codec
2848 * @jack: jack to report detection events on
2849 *
2850 * Enable microphone detection functionality for the WM8958. By
2851 * default simple detection which supports the detection of up to 6
2852 * buttons plus video and microphone functionality is supported.
2853 *
2854 * The WM8958 has an advanced jack detection facility which is able to
2855 * support complex accessory detection, especially when used in
2856 * conjunction with external circuitry. In order to provide maximum
2857 * flexiblity a callback is provided which allows a completely custom
2858 * detection algorithm.
2859 */
2860int wm8958_mic_detect(struct snd_soc_codec *codec, struct snd_soc_jack *jack,
2861 wm8958_micdet_cb cb, void *cb_data)
2862{
2863 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
2864 struct wm8994 *control = codec->control_data;
2865
2866 if (control->type != WM8958)
2867 return -EINVAL;
2868
2869 if (jack) {
2870 if (!cb) {
2871 dev_dbg(codec->dev, "Using default micdet callback\n");
2872 cb = wm8958_default_micdet;
2873 cb_data = codec;
2874 }
2875
2876 wm8994->micdet[0].jack = jack;
2877 wm8994->jack_cb = cb;
2878 wm8994->jack_cb_data = cb_data;
2879
2880 snd_soc_update_bits(codec, WM8958_MIC_DETECT_1,
2881 WM8958_MICD_ENA, WM8958_MICD_ENA);
2882 } else {
2883 snd_soc_update_bits(codec, WM8958_MIC_DETECT_1,
2884 WM8958_MICD_ENA, 0);
2885 }
2886
2887 return 0;
2888}
2889EXPORT_SYMBOL_GPL(wm8958_mic_detect);
2890
2891static irqreturn_t wm8958_mic_irq(int irq, void *data)
2892{
2893 struct wm8994_priv *wm8994 = data;
2894 struct snd_soc_codec *codec = wm8994->codec;
2895 int reg;
2896
2897 reg = snd_soc_read(codec, WM8958_MIC_DETECT_3);
2898 if (reg < 0) {
2899 dev_err(codec->dev, "Failed to read mic detect status: %d\n",
2900 reg);
2901 return IRQ_NONE;
2902 }
2903
2904 if (!(reg & WM8958_MICD_VALID)) {
2905 dev_dbg(codec->dev, "Mic detect data not valid\n");
2906 goto out;
2907 }
2908
2909#ifndef CONFIG_SND_SOC_WM8994_MODULE
2910 trace_snd_soc_jack_irq(dev_name(codec->dev));
2911#endif
2912
2913 if (wm8994->jack_cb)
2914 wm8994->jack_cb(reg, wm8994->jack_cb_data);
2915 else
2916 dev_warn(codec->dev, "Accessory detection with no callback\n");
2917
2918out:
2919 return IRQ_HANDLED;
2920}
2921
3894static int wm8994_codec_probe(struct snd_soc_codec *codec) 2922static int wm8994_codec_probe(struct snd_soc_codec *codec)
3895{ 2923{
2924 struct wm8994 *control;
3896 struct wm8994_priv *wm8994; 2925 struct wm8994_priv *wm8994;
2926 struct snd_soc_dapm_context *dapm = &codec->dapm;
3897 int ret, i; 2927 int ret, i;
3898 2928
3899 codec->control_data = dev_get_drvdata(codec->dev->parent); 2929 codec->control_data = dev_get_drvdata(codec->dev->parent);
2930 control = codec->control_data;
3900 2931
3901 wm8994 = kzalloc(sizeof(struct wm8994_priv), GFP_KERNEL); 2932 wm8994 = kzalloc(sizeof(struct wm8994_priv), GFP_KERNEL);
3902 if (wm8994 == NULL) 2933 if (wm8994 == NULL)
3903 return -ENOMEM; 2934 return -ENOMEM;
3904 snd_soc_codec_set_drvdata(codec, wm8994); 2935 snd_soc_codec_set_drvdata(codec, wm8994);
3905 2936
3906 codec->reg_cache = &wm8994->reg_cache;
3907
3908 wm8994->pdata = dev_get_platdata(codec->dev->parent); 2937 wm8994->pdata = dev_get_platdata(codec->dev->parent);
3909 wm8994->codec = codec; 2938 wm8994->codec = codec;
3910 2939
3911 /* Fill the cache with physical values we inherited; don't reset */ 2940 pm_runtime_enable(codec->dev);
3912 ret = wm8994_bulk_read(codec->control_data, 0, 2941 pm_runtime_resume(codec->dev);
3913 ARRAY_SIZE(wm8994->reg_cache) - 1,
3914 codec->reg_cache);
3915 if (ret < 0) {
3916 dev_err(codec->dev, "Failed to fill register cache: %d\n",
3917 ret);
3918 goto err;
3919 }
3920 2942
3921 /* Clear the cached values for unreadable/volatile registers to 2943 /* Read our current status back from the chip - we don't want to
3922 * avoid potential confusion. 2944 * reset as this may interfere with the GPIO or LDO operation. */
3923 */ 2945 for (i = 0; i < WM8994_CACHE_SIZE; i++) {
3924 for (i = 0; i < ARRAY_SIZE(wm8994->reg_cache); i++) 2946 if (!wm8994_readable(i) || wm8994_volatile(i))
3925 if (wm8994_volatile(i) || !wm8994_readable(i)) 2947 continue;
3926 wm8994->reg_cache[i] = 0; 2948
2949 ret = wm8994_reg_read(codec->control_data, i);
2950 if (ret <= 0)
2951 continue;
2952
2953 ret = snd_soc_cache_write(codec, i, ret);
2954 if (ret != 0) {
2955 dev_err(codec->dev,
2956 "Failed to initialise cache for 0x%x: %d\n",
2957 i, ret);
2958 goto err;
2959 }
2960 }
3927 2961
3928 /* Set revision-specific configuration */ 2962 /* Set revision-specific configuration */
3929 wm8994->revision = snd_soc_read(codec, WM8994_CHIP_REVISION); 2963 wm8994->revision = snd_soc_read(codec, WM8994_CHIP_REVISION);
3930 switch (wm8994->revision) { 2964 switch (control->type) {
3931 case 2: 2965 case WM8994:
3932 case 3: 2966 switch (wm8994->revision) {
3933 wm8994->hubs.dcs_codes = -5; 2967 case 2:
3934 wm8994->hubs.hp_startup_mode = 1; 2968 case 3:
2969 wm8994->hubs.dcs_codes = -5;
2970 wm8994->hubs.hp_startup_mode = 1;
2971 wm8994->hubs.dcs_readback_mode = 1;
2972 break;
2973 default:
2974 wm8994->hubs.dcs_readback_mode = 1;
2975 break;
2976 }
2977
2978 case WM8958:
3935 wm8994->hubs.dcs_readback_mode = 1; 2979 wm8994->hubs.dcs_readback_mode = 1;
3936 break; 2980 break;
2981
3937 default: 2982 default:
3938 wm8994->hubs.dcs_readback_mode = 1;
3939 break; 2983 break;
3940 } 2984 }
3941 2985
3942 ret = wm8994_request_irq(codec->control_data, WM8994_IRQ_MIC1_DET, 2986 switch (control->type) {
3943 wm8994_mic_irq, "Mic 1 detect", wm8994); 2987 case WM8994:
3944 if (ret != 0) 2988 ret = wm8994_request_irq(codec->control_data,
3945 dev_warn(codec->dev, 2989 WM8994_IRQ_MIC1_DET,
3946 "Failed to request Mic1 detect IRQ: %d\n", ret); 2990 wm8994_mic_irq, "Mic 1 detect",
3947 2991 wm8994);
3948 ret = wm8994_request_irq(codec->control_data, WM8994_IRQ_MIC1_SHRT, 2992 if (ret != 0)
3949 wm8994_mic_irq, "Mic 1 short", wm8994); 2993 dev_warn(codec->dev,
3950 if (ret != 0) 2994 "Failed to request Mic1 detect IRQ: %d\n",
3951 dev_warn(codec->dev, 2995 ret);
3952 "Failed to request Mic1 short IRQ: %d\n", ret); 2996
3953 2997 ret = wm8994_request_irq(codec->control_data,
3954 ret = wm8994_request_irq(codec->control_data, WM8994_IRQ_MIC2_DET, 2998 WM8994_IRQ_MIC1_SHRT,
3955 wm8994_mic_irq, "Mic 2 detect", wm8994); 2999 wm8994_mic_irq, "Mic 1 short",
3956 if (ret != 0) 3000 wm8994);
3957 dev_warn(codec->dev, 3001 if (ret != 0)
3958 "Failed to request Mic2 detect IRQ: %d\n", ret); 3002 dev_warn(codec->dev,
3003 "Failed to request Mic1 short IRQ: %d\n",
3004 ret);
3005
3006 ret = wm8994_request_irq(codec->control_data,
3007 WM8994_IRQ_MIC2_DET,
3008 wm8994_mic_irq, "Mic 2 detect",
3009 wm8994);
3010 if (ret != 0)
3011 dev_warn(codec->dev,
3012 "Failed to request Mic2 detect IRQ: %d\n",
3013 ret);
3014
3015 ret = wm8994_request_irq(codec->control_data,
3016 WM8994_IRQ_MIC2_SHRT,
3017 wm8994_mic_irq, "Mic 2 short",
3018 wm8994);
3019 if (ret != 0)
3020 dev_warn(codec->dev,
3021 "Failed to request Mic2 short IRQ: %d\n",
3022 ret);
3023 break;
3959 3024
3960 ret = wm8994_request_irq(codec->control_data, WM8994_IRQ_MIC2_SHRT, 3025 case WM8958:
3961 wm8994_mic_irq, "Mic 2 short", wm8994); 3026 ret = wm8994_request_irq(codec->control_data,
3962 if (ret != 0) 3027 WM8994_IRQ_MIC1_DET,
3963 dev_warn(codec->dev, 3028 wm8958_mic_irq, "Mic detect",
3964 "Failed to request Mic2 short IRQ: %d\n", ret); 3029 wm8994);
3030 if (ret != 0)
3031 dev_warn(codec->dev,
3032 "Failed to request Mic detect IRQ: %d\n",
3033 ret);
3034 break;
3035 }
3965 3036
3966 /* Remember if AIFnLRCLK is configured as a GPIO. This should be 3037 /* Remember if AIFnLRCLK is configured as a GPIO. This should be
3967 * configured on init - if a system wants to do this dynamically 3038 * configured on init - if a system wants to do this dynamically
@@ -4034,10 +3105,36 @@ static int wm8994_codec_probe(struct snd_soc_codec *codec)
4034 wm_hubs_add_analogue_controls(codec); 3105 wm_hubs_add_analogue_controls(codec);
4035 snd_soc_add_controls(codec, wm8994_snd_controls, 3106 snd_soc_add_controls(codec, wm8994_snd_controls,
4036 ARRAY_SIZE(wm8994_snd_controls)); 3107 ARRAY_SIZE(wm8994_snd_controls));
4037 snd_soc_dapm_new_controls(codec, wm8994_dapm_widgets, 3108 snd_soc_dapm_new_controls(dapm, wm8994_dapm_widgets,
4038 ARRAY_SIZE(wm8994_dapm_widgets)); 3109 ARRAY_SIZE(wm8994_dapm_widgets));
3110
3111 switch (control->type) {
3112 case WM8994:
3113 snd_soc_dapm_new_controls(dapm, wm8994_specific_dapm_widgets,
3114 ARRAY_SIZE(wm8994_specific_dapm_widgets));
3115 break;
3116 case WM8958:
3117 snd_soc_add_controls(codec, wm8958_snd_controls,
3118 ARRAY_SIZE(wm8958_snd_controls));
3119 snd_soc_dapm_new_controls(dapm, wm8958_dapm_widgets,
3120 ARRAY_SIZE(wm8958_dapm_widgets));
3121 break;
3122 }
3123
3124
4039 wm_hubs_add_analogue_routes(codec, 0, 0); 3125 wm_hubs_add_analogue_routes(codec, 0, 0);
4040 snd_soc_dapm_add_routes(codec, intercon, ARRAY_SIZE(intercon)); 3126 snd_soc_dapm_add_routes(dapm, intercon, ARRAY_SIZE(intercon));
3127
3128 switch (control->type) {
3129 case WM8994:
3130 snd_soc_dapm_add_routes(dapm, wm8994_intercon,
3131 ARRAY_SIZE(wm8994_intercon));
3132 break;
3133 case WM8958:
3134 snd_soc_dapm_add_routes(dapm, wm8958_intercon,
3135 ARRAY_SIZE(wm8958_intercon));
3136 break;
3137 }
4041 3138
4042 return 0; 3139 return 0;
4043 3140
@@ -4054,13 +3151,29 @@ err:
4054static int wm8994_codec_remove(struct snd_soc_codec *codec) 3151static int wm8994_codec_remove(struct snd_soc_codec *codec)
4055{ 3152{
4056 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec); 3153 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
3154 struct wm8994 *control = codec->control_data;
4057 3155
4058 wm8994_set_bias_level(codec, SND_SOC_BIAS_OFF); 3156 wm8994_set_bias_level(codec, SND_SOC_BIAS_OFF);
4059 3157
4060 wm8994_free_irq(codec->control_data, WM8994_IRQ_MIC2_SHRT, wm8994); 3158 pm_runtime_disable(codec->dev);
4061 wm8994_free_irq(codec->control_data, WM8994_IRQ_MIC2_DET, wm8994); 3159
4062 wm8994_free_irq(codec->control_data, WM8994_IRQ_MIC1_SHRT, wm8994); 3160 switch (control->type) {
4063 wm8994_free_irq(codec->control_data, WM8994_IRQ_MIC1_DET, wm8994); 3161 case WM8994:
3162 wm8994_free_irq(codec->control_data, WM8994_IRQ_MIC2_SHRT,
3163 wm8994);
3164 wm8994_free_irq(codec->control_data, WM8994_IRQ_MIC2_DET,
3165 wm8994);
3166 wm8994_free_irq(codec->control_data, WM8994_IRQ_MIC1_SHRT,
3167 wm8994);
3168 wm8994_free_irq(codec->control_data, WM8994_IRQ_MIC1_DET,
3169 wm8994);
3170 break;
3171
3172 case WM8958:
3173 wm8994_free_irq(codec->control_data, WM8994_IRQ_MIC1_DET,
3174 wm8994);
3175 break;
3176 }
4064 kfree(wm8994->retune_mobile_texts); 3177 kfree(wm8994->retune_mobile_texts);
4065 kfree(wm8994->drc_texts); 3178 kfree(wm8994->drc_texts);
4066 kfree(wm8994); 3179 kfree(wm8994);
@@ -4073,11 +3186,16 @@ static struct snd_soc_codec_driver soc_codec_dev_wm8994 = {
4073 .remove = wm8994_codec_remove, 3186 .remove = wm8994_codec_remove,
4074 .suspend = wm8994_suspend, 3187 .suspend = wm8994_suspend,
4075 .resume = wm8994_resume, 3188 .resume = wm8994_resume,
4076 .read = wm8994_read, 3189 .read = wm8994_read,
4077 .write = wm8994_write, 3190 .write = wm8994_write,
4078 .readable_register = wm8994_readable, 3191 .readable_register = wm8994_readable,
4079 .volatile_register = wm8994_volatile, 3192 .volatile_register = wm8994_volatile,
4080 .set_bias_level = wm8994_set_bias_level, 3193 .set_bias_level = wm8994_set_bias_level,
3194
3195 .reg_cache_size = WM8994_CACHE_SIZE,
3196 .reg_cache_default = wm8994_reg_defaults,
3197 .reg_word_size = 2,
3198 .compress_type = SND_SOC_RBTREE_COMPRESSION,
4081}; 3199};
4082 3200
4083static int __devinit wm8994_probe(struct platform_device *pdev) 3201static int __devinit wm8994_probe(struct platform_device *pdev)
diff --git a/sound/soc/codecs/wm8994.h b/sound/soc/codecs/wm8994.h
index d8dce260c430..0c355bfc88f1 100644
--- a/sound/soc/codecs/wm8994.h
+++ b/sound/soc/codecs/wm8994.h
@@ -28,7 +28,21 @@
28#define WM8994_FLL_SRC_LRCLK 3 28#define WM8994_FLL_SRC_LRCLK 3
29#define WM8994_FLL_SRC_BCLK 4 29#define WM8994_FLL_SRC_BCLK 4
30 30
31typedef void (*wm8958_micdet_cb)(u16 status, void *data);
32
31int wm8994_mic_detect(struct snd_soc_codec *codec, struct snd_soc_jack *jack, 33int wm8994_mic_detect(struct snd_soc_codec *codec, struct snd_soc_jack *jack,
32 int micbias, int det, int shrt); 34 int micbias, int det, int shrt);
35int wm8958_mic_detect(struct snd_soc_codec *codec, struct snd_soc_jack *jack,
36 wm8958_micdet_cb cb, void *cb_data);
37
38#define WM8994_CACHE_SIZE 1570
39
40struct wm8994_access_mask {
41 unsigned short readable; /* Mask of readable bits */
42 unsigned short writable; /* Mask of writable bits */
43};
44
45extern const struct wm8994_access_mask wm8994_access_masks[WM8994_CACHE_SIZE];
46extern const __devinitdata u16 wm8994_reg_defaults[WM8994_CACHE_SIZE];
33 47
34#endif 48#endif
diff --git a/sound/soc/codecs/wm8995.c b/sound/soc/codecs/wm8995.c
new file mode 100644
index 000000000000..6045cbde492b
--- /dev/null
+++ b/sound/soc/codecs/wm8995.c
@@ -0,0 +1,1818 @@
1/*
2 * wm8995.c -- WM8995 ALSA SoC Audio driver
3 *
4 * Copyright 2010 Wolfson Microelectronics plc
5 *
6 * Author: Dimitris Papastamos <dp@opensource.wolfsonmicro.com>
7 *
8 * Based on wm8994.c and wm_hubs.c by Mark Brown
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License version 2 as
12 * published by the Free Software Foundation.
13 */
14
15#include <linux/module.h>
16#include <linux/moduleparam.h>
17#include <linux/init.h>
18#include <linux/delay.h>
19#include <linux/pm.h>
20#include <linux/i2c.h>
21#include <linux/spi/spi.h>
22#include <linux/slab.h>
23#include <sound/core.h>
24#include <sound/pcm.h>
25#include <sound/pcm_params.h>
26#include <sound/soc.h>
27#include <sound/soc-dapm.h>
28#include <sound/initval.h>
29#include <sound/tlv.h>
30
31#include "wm8995.h"
32
33static const u16 wm8995_reg_defs[WM8995_MAX_REGISTER + 1] = {
34 [0] = 0x8995, [5] = 0x0100, [16] = 0x000b, [17] = 0x000b,
35 [24] = 0x02c0, [25] = 0x02c0, [26] = 0x02c0, [27] = 0x02c0,
36 [28] = 0x000f, [32] = 0x0005, [33] = 0x0005, [40] = 0x0003,
37 [41] = 0x0013, [48] = 0x0004, [56] = 0x09f8, [64] = 0x1f25,
38 [69] = 0x0004, [82] = 0xaaaa, [84] = 0x2a2a, [146] = 0x0060,
39 [256] = 0x0002, [257] = 0x8004, [520] = 0x0010, [528] = 0x0083,
40 [529] = 0x0083, [548] = 0x0c80, [580] = 0x0c80, [768] = 0x4050,
41 [769] = 0x4000, [771] = 0x0040, [772] = 0x0040, [773] = 0x0040,
42 [774] = 0x0004, [775] = 0x0100, [784] = 0x4050, [785] = 0x4000,
43 [787] = 0x0040, [788] = 0x0040, [789] = 0x0040, [1024] = 0x00c0,
44 [1025] = 0x00c0, [1026] = 0x00c0, [1027] = 0x00c0, [1028] = 0x00c0,
45 [1029] = 0x00c0, [1030] = 0x00c0, [1031] = 0x00c0, [1056] = 0x0200,
46 [1057] = 0x0010, [1058] = 0x0200, [1059] = 0x0010, [1088] = 0x0098,
47 [1089] = 0x0845, [1104] = 0x0098, [1105] = 0x0845, [1152] = 0x6318,
48 [1153] = 0x6300, [1154] = 0x0fca, [1155] = 0x0400, [1156] = 0x00d8,
49 [1157] = 0x1eb5, [1158] = 0xf145, [1159] = 0x0b75, [1160] = 0x01c5,
50 [1161] = 0x1c58, [1162] = 0xf373, [1163] = 0x0a54, [1164] = 0x0558,
51 [1165] = 0x168e, [1166] = 0xf829, [1167] = 0x07ad, [1168] = 0x1103,
52 [1169] = 0x0564, [1170] = 0x0559, [1171] = 0x4000, [1184] = 0x6318,
53 [1185] = 0x6300, [1186] = 0x0fca, [1187] = 0x0400, [1188] = 0x00d8,
54 [1189] = 0x1eb5, [1190] = 0xf145, [1191] = 0x0b75, [1192] = 0x01c5,
55 [1193] = 0x1c58, [1194] = 0xf373, [1195] = 0x0a54, [1196] = 0x0558,
56 [1197] = 0x168e, [1198] = 0xf829, [1199] = 0x07ad, [1200] = 0x1103,
57 [1201] = 0x0564, [1202] = 0x0559, [1203] = 0x4000, [1280] = 0x00c0,
58 [1281] = 0x00c0, [1282] = 0x00c0, [1283] = 0x00c0, [1312] = 0x0200,
59 [1313] = 0x0010, [1344] = 0x0098, [1345] = 0x0845, [1408] = 0x6318,
60 [1409] = 0x6300, [1410] = 0x0fca, [1411] = 0x0400, [1412] = 0x00d8,
61 [1413] = 0x1eb5, [1414] = 0xf145, [1415] = 0x0b75, [1416] = 0x01c5,
62 [1417] = 0x1c58, [1418] = 0xf373, [1419] = 0x0a54, [1420] = 0x0558,
63 [1421] = 0x168e, [1422] = 0xf829, [1423] = 0x07ad, [1424] = 0x1103,
64 [1425] = 0x0564, [1426] = 0x0559, [1427] = 0x4000, [1568] = 0x0002,
65 [1792] = 0xa100, [1793] = 0xa101, [1794] = 0xa101, [1795] = 0xa101,
66 [1796] = 0xa101, [1797] = 0xa101, [1798] = 0xa101, [1799] = 0xa101,
67 [1800] = 0xa101, [1801] = 0xa101, [1802] = 0xa101, [1803] = 0xa101,
68 [1804] = 0xa101, [1805] = 0xa101, [1825] = 0x0055, [1848] = 0x3fff,
69 [1849] = 0x1fff, [2049] = 0x0001, [2050] = 0x0069, [2056] = 0x0002,
70 [2057] = 0x0003, [2058] = 0x0069, [12288] = 0x0001, [12289] = 0x0001,
71 [12291] = 0x0006, [12292] = 0x0040, [12293] = 0x0001, [12294] = 0x000f,
72 [12295] = 0x0006, [12296] = 0x0001, [12297] = 0x0003, [12298] = 0x0104,
73 [12300] = 0x0060, [12301] = 0x0011, [12302] = 0x0401, [12304] = 0x0050,
74 [12305] = 0x0003, [12306] = 0x0100, [12308] = 0x0051, [12309] = 0x0003,
75 [12310] = 0x0104, [12311] = 0x000a, [12312] = 0x0060, [12313] = 0x003b,
76 [12314] = 0x0502, [12315] = 0x0100, [12316] = 0x2fff, [12320] = 0x2fff,
77 [12324] = 0x2fff, [12328] = 0x2fff, [12332] = 0x2fff, [12336] = 0x2fff,
78 [12340] = 0x2fff, [12344] = 0x2fff, [12348] = 0x2fff, [12352] = 0x0001,
79 [12353] = 0x0001, [12355] = 0x0006, [12356] = 0x0040, [12357] = 0x0001,
80 [12358] = 0x000f, [12359] = 0x0006, [12360] = 0x0001, [12361] = 0x0003,
81 [12362] = 0x0104, [12364] = 0x0060, [12365] = 0x0011, [12366] = 0x0401,
82 [12368] = 0x0050, [12369] = 0x0003, [12370] = 0x0100, [12372] = 0x0060,
83 [12373] = 0x003b, [12374] = 0x0502, [12375] = 0x0100, [12376] = 0x2fff,
84 [12380] = 0x2fff, [12384] = 0x2fff, [12388] = 0x2fff, [12392] = 0x2fff,
85 [12396] = 0x2fff, [12400] = 0x2fff, [12404] = 0x2fff, [12408] = 0x2fff,
86 [12412] = 0x2fff, [12416] = 0x0001, [12417] = 0x0001, [12419] = 0x0006,
87 [12420] = 0x0040, [12421] = 0x0001, [12422] = 0x000f, [12423] = 0x0006,
88 [12424] = 0x0001, [12425] = 0x0003, [12426] = 0x0106, [12428] = 0x0061,
89 [12429] = 0x0011, [12430] = 0x0401, [12432] = 0x0050, [12433] = 0x0003,
90 [12434] = 0x0102, [12436] = 0x0051, [12437] = 0x0003, [12438] = 0x0106,
91 [12439] = 0x000a, [12440] = 0x0061, [12441] = 0x003b, [12442] = 0x0502,
92 [12443] = 0x0100, [12444] = 0x2fff, [12448] = 0x2fff, [12452] = 0x2fff,
93 [12456] = 0x2fff, [12460] = 0x2fff, [12464] = 0x2fff, [12468] = 0x2fff,
94 [12472] = 0x2fff, [12476] = 0x2fff, [12480] = 0x0001, [12481] = 0x0001,
95 [12483] = 0x0006, [12484] = 0x0040, [12485] = 0x0001, [12486] = 0x000f,
96 [12487] = 0x0006, [12488] = 0x0001, [12489] = 0x0003, [12490] = 0x0106,
97 [12492] = 0x0061, [12493] = 0x0011, [12494] = 0x0401, [12496] = 0x0050,
98 [12497] = 0x0003, [12498] = 0x0102, [12500] = 0x0061, [12501] = 0x003b,
99 [12502] = 0x0502, [12503] = 0x0100, [12504] = 0x2fff, [12508] = 0x2fff,
100 [12512] = 0x2fff, [12516] = 0x2fff, [12520] = 0x2fff, [12524] = 0x2fff,
101 [12528] = 0x2fff, [12532] = 0x2fff, [12536] = 0x2fff, [12540] = 0x2fff,
102 [12544] = 0x0060, [12546] = 0x0601, [12548] = 0x0050, [12550] = 0x0100,
103 [12552] = 0x0001, [12554] = 0x0104, [12555] = 0x0100, [12556] = 0x2fff,
104 [12560] = 0x2fff, [12564] = 0x2fff, [12568] = 0x2fff, [12572] = 0x2fff,
105 [12576] = 0x2fff, [12580] = 0x2fff, [12584] = 0x2fff, [12588] = 0x2fff,
106 [12592] = 0x2fff, [12596] = 0x2fff, [12600] = 0x2fff, [12604] = 0x2fff,
107 [12608] = 0x0061, [12610] = 0x0601, [12612] = 0x0050, [12614] = 0x0102,
108 [12616] = 0x0001, [12618] = 0x0106, [12619] = 0x0100, [12620] = 0x2fff,
109 [12624] = 0x2fff, [12628] = 0x2fff, [12632] = 0x2fff, [12636] = 0x2fff,
110 [12640] = 0x2fff, [12644] = 0x2fff, [12648] = 0x2fff, [12652] = 0x2fff,
111 [12656] = 0x2fff, [12660] = 0x2fff, [12664] = 0x2fff, [12668] = 0x2fff,
112 [12672] = 0x0060, [12674] = 0x0601, [12676] = 0x0061, [12678] = 0x0601,
113 [12680] = 0x0050, [12682] = 0x0300, [12684] = 0x0001, [12686] = 0x0304,
114 [12688] = 0x0040, [12690] = 0x000f, [12692] = 0x0001, [12695] = 0x0100
115};
116
117struct fll_config {
118 int src;
119 int in;
120 int out;
121};
122
123struct wm8995_priv {
124 enum snd_soc_control_type control_type;
125 int sysclk[2];
126 int mclk[2];
127 int aifclk[2];
128 struct fll_config fll[2], fll_suspend[2];
129};
130
131static const DECLARE_TLV_DB_SCALE(digital_tlv, -7200, 75, 1);
132static const DECLARE_TLV_DB_SCALE(in1lr_pga_tlv, -1650, 150, 0);
133static const DECLARE_TLV_DB_SCALE(in1l_boost_tlv, 0, 600, 0);
134static const DECLARE_TLV_DB_SCALE(sidetone_tlv, -3600, 150, 0);
135
136static const char *in1l_text[] = {
137 "Differential", "Single-ended IN1LN", "Single-ended IN1LP"
138};
139
140static const SOC_ENUM_SINGLE_DECL(in1l_enum, WM8995_LEFT_LINE_INPUT_CONTROL,
141 2, in1l_text);
142
143static const char *in1r_text[] = {
144 "Differential", "Single-ended IN1RN", "Single-ended IN1RP"
145};
146
147static const SOC_ENUM_SINGLE_DECL(in1r_enum, WM8995_LEFT_LINE_INPUT_CONTROL,
148 0, in1r_text);
149
150static const char *dmic_src_text[] = {
151 "DMICDAT1", "DMICDAT2", "DMICDAT3"
152};
153
154static const SOC_ENUM_SINGLE_DECL(dmic_src1_enum, WM8995_POWER_MANAGEMENT_5,
155 8, dmic_src_text);
156static const SOC_ENUM_SINGLE_DECL(dmic_src2_enum, WM8995_POWER_MANAGEMENT_5,
157 6, dmic_src_text);
158
159static const struct snd_kcontrol_new wm8995_snd_controls[] = {
160 SOC_DOUBLE_R_TLV("DAC1 Volume", WM8995_DAC1_LEFT_VOLUME,
161 WM8995_DAC1_RIGHT_VOLUME, 0, 96, 0, digital_tlv),
162 SOC_DOUBLE_R("DAC1 Switch", WM8995_DAC1_LEFT_VOLUME,
163 WM8995_DAC1_RIGHT_VOLUME, 9, 1, 1),
164
165 SOC_DOUBLE_R_TLV("DAC2 Volume", WM8995_DAC2_LEFT_VOLUME,
166 WM8995_DAC2_RIGHT_VOLUME, 0, 96, 0, digital_tlv),
167 SOC_DOUBLE_R("DAC2 Switch", WM8995_DAC2_LEFT_VOLUME,
168 WM8995_DAC2_RIGHT_VOLUME, 9, 1, 1),
169
170 SOC_DOUBLE_R_TLV("AIF1DAC1 Volume", WM8995_AIF1_DAC1_LEFT_VOLUME,
171 WM8995_AIF1_DAC1_RIGHT_VOLUME, 0, 96, 0, digital_tlv),
172 SOC_DOUBLE_R_TLV("AIF1DAC2 Volume", WM8995_AIF1_DAC2_LEFT_VOLUME,
173 WM8995_AIF1_DAC2_RIGHT_VOLUME, 0, 96, 0, digital_tlv),
174 SOC_DOUBLE_R_TLV("AIF2DAC Volume", WM8995_AIF2_DAC_LEFT_VOLUME,
175 WM8995_AIF2_DAC_RIGHT_VOLUME, 0, 96, 0, digital_tlv),
176
177 SOC_DOUBLE_R_TLV("IN1LR Volume", WM8995_LEFT_LINE_INPUT_1_VOLUME,
178 WM8995_RIGHT_LINE_INPUT_1_VOLUME, 0, 31, 0, in1lr_pga_tlv),
179
180 SOC_SINGLE_TLV("IN1L Boost", WM8995_LEFT_LINE_INPUT_CONTROL,
181 4, 3, 0, in1l_boost_tlv),
182
183 SOC_ENUM("IN1L Mode", in1l_enum),
184 SOC_ENUM("IN1R Mode", in1r_enum),
185
186 SOC_ENUM("DMIC1 SRC", dmic_src1_enum),
187 SOC_ENUM("DMIC2 SRC", dmic_src2_enum),
188
189 SOC_DOUBLE_TLV("DAC1 Sidetone Volume", WM8995_DAC1_MIXER_VOLUMES, 0, 5,
190 24, 0, sidetone_tlv),
191 SOC_DOUBLE_TLV("DAC2 Sidetone Volume", WM8995_DAC2_MIXER_VOLUMES, 0, 5,
192 24, 0, sidetone_tlv),
193
194 SOC_DOUBLE_R_TLV("AIF1ADC1 Volume", WM8995_AIF1_ADC1_LEFT_VOLUME,
195 WM8995_AIF1_ADC1_RIGHT_VOLUME, 0, 96, 0, digital_tlv),
196 SOC_DOUBLE_R_TLV("AIF1ADC2 Volume", WM8995_AIF1_ADC2_LEFT_VOLUME,
197 WM8995_AIF1_ADC2_RIGHT_VOLUME, 0, 96, 0, digital_tlv),
198 SOC_DOUBLE_R_TLV("AIF2ADC Volume", WM8995_AIF2_ADC_LEFT_VOLUME,
199 WM8995_AIF2_ADC_RIGHT_VOLUME, 0, 96, 0, digital_tlv)
200};
201
202static void wm8995_update_class_w(struct snd_soc_codec *codec)
203{
204 int enable = 1;
205 int source = 0; /* GCC flow analysis can't track enable */
206 int reg, reg_r;
207
208 /* We also need the same setting for L/R and only one path */
209 reg = snd_soc_read(codec, WM8995_DAC1_LEFT_MIXER_ROUTING);
210 switch (reg) {
211 case WM8995_AIF2DACL_TO_DAC1L:
212 dev_dbg(codec->dev, "Class W source AIF2DAC\n");
213 source = 2 << WM8995_CP_DYN_SRC_SEL_SHIFT;
214 break;
215 case WM8995_AIF1DAC2L_TO_DAC1L:
216 dev_dbg(codec->dev, "Class W source AIF1DAC2\n");
217 source = 1 << WM8995_CP_DYN_SRC_SEL_SHIFT;
218 break;
219 case WM8995_AIF1DAC1L_TO_DAC1L:
220 dev_dbg(codec->dev, "Class W source AIF1DAC1\n");
221 source = 0 << WM8995_CP_DYN_SRC_SEL_SHIFT;
222 break;
223 default:
224 dev_dbg(codec->dev, "DAC mixer setting: %x\n", reg);
225 enable = 0;
226 break;
227 }
228
229 reg_r = snd_soc_read(codec, WM8995_DAC1_RIGHT_MIXER_ROUTING);
230 if (reg_r != reg) {
231 dev_dbg(codec->dev, "Left and right DAC mixers different\n");
232 enable = 0;
233 }
234
235 if (enable) {
236 dev_dbg(codec->dev, "Class W enabled\n");
237 snd_soc_update_bits(codec, WM8995_CLASS_W_1,
238 WM8995_CP_DYN_PWR_MASK |
239 WM8995_CP_DYN_SRC_SEL_MASK,
240 source | WM8995_CP_DYN_PWR);
241 } else {
242 dev_dbg(codec->dev, "Class W disabled\n");
243 snd_soc_update_bits(codec, WM8995_CLASS_W_1,
244 WM8995_CP_DYN_PWR_MASK, 0);
245 }
246}
247
248static int check_clk_sys(struct snd_soc_dapm_widget *source,
249 struct snd_soc_dapm_widget *sink)
250{
251 unsigned int reg;
252 const char *clk;
253
254 reg = snd_soc_read(source->codec, WM8995_CLOCKING_1);
255 /* Check what we're currently using for CLK_SYS */
256 if (reg & WM8995_SYSCLK_SRC)
257 clk = "AIF2CLK";
258 else
259 clk = "AIF1CLK";
260 return !strcmp(source->name, clk);
261}
262
263static int wm8995_put_class_w(struct snd_kcontrol *kcontrol,
264 struct snd_ctl_elem_value *ucontrol)
265{
266 struct snd_soc_dapm_widget *w;
267 struct snd_soc_codec *codec;
268 int ret;
269
270 w = snd_kcontrol_chip(kcontrol);
271 codec = w->codec;
272 ret = snd_soc_dapm_put_volsw(kcontrol, ucontrol);
273 wm8995_update_class_w(codec);
274 return ret;
275}
276
277static int hp_supply_event(struct snd_soc_dapm_widget *w,
278 struct snd_kcontrol *kcontrol, int event)
279{
280 struct snd_soc_codec *codec;
281 struct wm8995_priv *wm8995;
282
283 codec = w->codec;
284 wm8995 = snd_soc_codec_get_drvdata(codec);
285
286 switch (event) {
287 case SND_SOC_DAPM_PRE_PMU:
288 /* Enable the headphone amp */
289 snd_soc_update_bits(codec, WM8995_POWER_MANAGEMENT_1,
290 WM8995_HPOUT1L_ENA_MASK |
291 WM8995_HPOUT1R_ENA_MASK,
292 WM8995_HPOUT1L_ENA |
293 WM8995_HPOUT1R_ENA);
294
295 /* Enable the second stage */
296 snd_soc_update_bits(codec, WM8995_ANALOGUE_HP_1,
297 WM8995_HPOUT1L_DLY_MASK |
298 WM8995_HPOUT1R_DLY_MASK,
299 WM8995_HPOUT1L_DLY |
300 WM8995_HPOUT1R_DLY);
301 break;
302 case SND_SOC_DAPM_PRE_PMD:
303 snd_soc_update_bits(codec, WM8995_CHARGE_PUMP_1,
304 WM8995_CP_ENA_MASK, 0);
305 break;
306 }
307
308 return 0;
309}
310
311static void dc_servo_cmd(struct snd_soc_codec *codec,
312 unsigned int reg, unsigned int val, unsigned int mask)
313{
314 int timeout = 10;
315
316 dev_dbg(codec->dev, "%s: reg = %#x, val = %#x, mask = %#x\n",
317 __func__, reg, val, mask);
318
319 snd_soc_write(codec, reg, val);
320 while (timeout--) {
321 msleep(10);
322 val = snd_soc_read(codec, WM8995_DC_SERVO_READBACK_0);
323 if ((val & mask) == mask)
324 return;
325 }
326
327 dev_err(codec->dev, "Timed out waiting for DC Servo\n");
328}
329
330static int hp_event(struct snd_soc_dapm_widget *w,
331 struct snd_kcontrol *kcontrol, int event)
332{
333 struct snd_soc_codec *codec;
334 unsigned int reg;
335
336 codec = w->codec;
337 reg = snd_soc_read(codec, WM8995_ANALOGUE_HP_1);
338
339 switch (event) {
340 case SND_SOC_DAPM_POST_PMU:
341 snd_soc_update_bits(codec, WM8995_CHARGE_PUMP_1,
342 WM8995_CP_ENA_MASK, WM8995_CP_ENA);
343
344 msleep(5);
345
346 snd_soc_update_bits(codec, WM8995_POWER_MANAGEMENT_1,
347 WM8995_HPOUT1L_ENA_MASK |
348 WM8995_HPOUT1R_ENA_MASK,
349 WM8995_HPOUT1L_ENA | WM8995_HPOUT1R_ENA);
350
351 udelay(20);
352
353 reg |= WM8995_HPOUT1L_DLY | WM8995_HPOUT1R_DLY;
354 snd_soc_write(codec, WM8995_ANALOGUE_HP_1, reg);
355
356 snd_soc_write(codec, WM8995_DC_SERVO_1, WM8995_DCS_ENA_CHAN_0 |
357 WM8995_DCS_ENA_CHAN_1);
358
359 dc_servo_cmd(codec, WM8995_DC_SERVO_2,
360 WM8995_DCS_TRIG_STARTUP_0 |
361 WM8995_DCS_TRIG_STARTUP_1,
362 WM8995_DCS_TRIG_DAC_WR_0 |
363 WM8995_DCS_TRIG_DAC_WR_1);
364
365 reg |= WM8995_HPOUT1R_OUTP | WM8995_HPOUT1R_RMV_SHORT |
366 WM8995_HPOUT1L_OUTP | WM8995_HPOUT1L_RMV_SHORT;
367 snd_soc_write(codec, WM8995_ANALOGUE_HP_1, reg);
368
369 break;
370 case SND_SOC_DAPM_PRE_PMD:
371 snd_soc_update_bits(codec, WM8995_ANALOGUE_HP_1,
372 WM8995_HPOUT1L_OUTP_MASK |
373 WM8995_HPOUT1R_OUTP_MASK |
374 WM8995_HPOUT1L_RMV_SHORT_MASK |
375 WM8995_HPOUT1R_RMV_SHORT_MASK, 0);
376
377 snd_soc_update_bits(codec, WM8995_ANALOGUE_HP_1,
378 WM8995_HPOUT1L_DLY_MASK |
379 WM8995_HPOUT1R_DLY_MASK, 0);
380
381 snd_soc_write(codec, WM8995_DC_SERVO_1, 0);
382
383 snd_soc_update_bits(codec, WM8995_POWER_MANAGEMENT_1,
384 WM8995_HPOUT1L_ENA_MASK |
385 WM8995_HPOUT1R_ENA_MASK,
386 0);
387 break;
388 }
389
390 return 0;
391}
392
393static int configure_aif_clock(struct snd_soc_codec *codec, int aif)
394{
395 struct wm8995_priv *wm8995;
396 int rate;
397 int reg1 = 0;
398 int offset;
399
400 wm8995 = snd_soc_codec_get_drvdata(codec);
401
402 if (aif)
403 offset = 4;
404 else
405 offset = 0;
406
407 switch (wm8995->sysclk[aif]) {
408 case WM8995_SYSCLK_MCLK1:
409 rate = wm8995->mclk[0];
410 break;
411 case WM8995_SYSCLK_MCLK2:
412 reg1 |= 0x8;
413 rate = wm8995->mclk[1];
414 break;
415 case WM8995_SYSCLK_FLL1:
416 reg1 |= 0x10;
417 rate = wm8995->fll[0].out;
418 break;
419 case WM8995_SYSCLK_FLL2:
420 reg1 |= 0x18;
421 rate = wm8995->fll[1].out;
422 break;
423 default:
424 return -EINVAL;
425 }
426
427 if (rate >= 13500000) {
428 rate /= 2;
429 reg1 |= WM8995_AIF1CLK_DIV;
430
431 dev_dbg(codec->dev, "Dividing AIF%d clock to %dHz\n",
432 aif + 1, rate);
433 }
434
435 wm8995->aifclk[aif] = rate;
436
437 snd_soc_update_bits(codec, WM8995_AIF1_CLOCKING_1 + offset,
438 WM8995_AIF1CLK_SRC_MASK | WM8995_AIF1CLK_DIV_MASK,
439 reg1);
440 return 0;
441}
442
443static int configure_clock(struct snd_soc_codec *codec)
444{
445 struct wm8995_priv *wm8995;
446 int old, new;
447
448 wm8995 = snd_soc_codec_get_drvdata(codec);
449
450 /* Bring up the AIF clocks first */
451 configure_aif_clock(codec, 0);
452 configure_aif_clock(codec, 1);
453
454 /*
455 * Then switch CLK_SYS over to the higher of them; a change
456 * can only happen as a result of a clocking change which can
457 * only be made outside of DAPM so we can safely redo the
458 * clocking.
459 */
460
461 /* If they're equal it doesn't matter which is used */
462 if (wm8995->aifclk[0] == wm8995->aifclk[1])
463 return 0;
464
465 if (wm8995->aifclk[0] < wm8995->aifclk[1])
466 new = WM8995_SYSCLK_SRC;
467 else
468 new = 0;
469
470 old = snd_soc_read(codec, WM8995_CLOCKING_1) & WM8995_SYSCLK_SRC;
471
472 /* If there's no change then we're done. */
473 if (old == new)
474 return 0;
475
476 snd_soc_update_bits(codec, WM8995_CLOCKING_1,
477 WM8995_SYSCLK_SRC_MASK, new);
478
479 snd_soc_dapm_sync(&codec->dapm);
480
481 return 0;
482}
483
484static int clk_sys_event(struct snd_soc_dapm_widget *w,
485 struct snd_kcontrol *kcontrol, int event)
486{
487 struct snd_soc_codec *codec;
488
489 codec = w->codec;
490
491 switch (event) {
492 case SND_SOC_DAPM_PRE_PMU:
493 return configure_clock(codec);
494
495 case SND_SOC_DAPM_POST_PMD:
496 configure_clock(codec);
497 break;
498 }
499
500 return 0;
501}
502
503static const char *sidetone_text[] = {
504 "ADC/DMIC1", "DMIC2",
505};
506
507static const struct soc_enum sidetone1_enum =
508 SOC_ENUM_SINGLE(WM8995_SIDETONE, 0, 2, sidetone_text);
509
510static const struct snd_kcontrol_new sidetone1_mux =
511 SOC_DAPM_ENUM("Left Sidetone Mux", sidetone1_enum);
512
513static const struct soc_enum sidetone2_enum =
514 SOC_ENUM_SINGLE(WM8995_SIDETONE, 1, 2, sidetone_text);
515
516static const struct snd_kcontrol_new sidetone2_mux =
517 SOC_DAPM_ENUM("Right Sidetone Mux", sidetone2_enum);
518
519static const struct snd_kcontrol_new aif1adc1l_mix[] = {
520 SOC_DAPM_SINGLE("ADC/DMIC Switch", WM8995_AIF1_ADC1_LEFT_MIXER_ROUTING,
521 1, 1, 0),
522 SOC_DAPM_SINGLE("AIF2 Switch", WM8995_AIF1_ADC1_LEFT_MIXER_ROUTING,
523 0, 1, 0),
524};
525
526static const struct snd_kcontrol_new aif1adc1r_mix[] = {
527 SOC_DAPM_SINGLE("ADC/DMIC Switch", WM8995_AIF1_ADC1_RIGHT_MIXER_ROUTING,
528 1, 1, 0),
529 SOC_DAPM_SINGLE("AIF2 Switch", WM8995_AIF1_ADC1_RIGHT_MIXER_ROUTING,
530 0, 1, 0),
531};
532
533static const struct snd_kcontrol_new aif1adc2l_mix[] = {
534 SOC_DAPM_SINGLE("DMIC Switch", WM8995_AIF1_ADC2_LEFT_MIXER_ROUTING,
535 1, 1, 0),
536 SOC_DAPM_SINGLE("AIF2 Switch", WM8995_AIF1_ADC2_LEFT_MIXER_ROUTING,
537 0, 1, 0),
538};
539
540static const struct snd_kcontrol_new aif1adc2r_mix[] = {
541 SOC_DAPM_SINGLE("DMIC Switch", WM8995_AIF1_ADC2_RIGHT_MIXER_ROUTING,
542 1, 1, 0),
543 SOC_DAPM_SINGLE("AIF2 Switch", WM8995_AIF1_ADC2_RIGHT_MIXER_ROUTING,
544 0, 1, 0),
545};
546
547static const struct snd_kcontrol_new dac1l_mix[] = {
548 WM8995_CLASS_W_SWITCH("Right Sidetone Switch", WM8995_DAC1_LEFT_MIXER_ROUTING,
549 5, 1, 0),
550 WM8995_CLASS_W_SWITCH("Left Sidetone Switch", WM8995_DAC1_LEFT_MIXER_ROUTING,
551 4, 1, 0),
552 WM8995_CLASS_W_SWITCH("AIF2 Switch", WM8995_DAC1_LEFT_MIXER_ROUTING,
553 2, 1, 0),
554 WM8995_CLASS_W_SWITCH("AIF1.2 Switch", WM8995_DAC1_LEFT_MIXER_ROUTING,
555 1, 1, 0),
556 WM8995_CLASS_W_SWITCH("AIF1.1 Switch", WM8995_DAC1_LEFT_MIXER_ROUTING,
557 0, 1, 0),
558};
559
560static const struct snd_kcontrol_new dac1r_mix[] = {
561 WM8995_CLASS_W_SWITCH("Right Sidetone Switch", WM8995_DAC1_RIGHT_MIXER_ROUTING,
562 5, 1, 0),
563 WM8995_CLASS_W_SWITCH("Left Sidetone Switch", WM8995_DAC1_RIGHT_MIXER_ROUTING,
564 4, 1, 0),
565 WM8995_CLASS_W_SWITCH("AIF2 Switch", WM8995_DAC1_RIGHT_MIXER_ROUTING,
566 2, 1, 0),
567 WM8995_CLASS_W_SWITCH("AIF1.2 Switch", WM8995_DAC1_RIGHT_MIXER_ROUTING,
568 1, 1, 0),
569 WM8995_CLASS_W_SWITCH("AIF1.1 Switch", WM8995_DAC1_RIGHT_MIXER_ROUTING,
570 0, 1, 0),
571};
572
573static const struct snd_kcontrol_new aif2dac2l_mix[] = {
574 SOC_DAPM_SINGLE("Right Sidetone Switch", WM8995_DAC2_LEFT_MIXER_ROUTING,
575 5, 1, 0),
576 SOC_DAPM_SINGLE("Left Sidetone Switch", WM8995_DAC2_LEFT_MIXER_ROUTING,
577 4, 1, 0),
578 SOC_DAPM_SINGLE("AIF2 Switch", WM8995_DAC2_LEFT_MIXER_ROUTING,
579 2, 1, 0),
580 SOC_DAPM_SINGLE("AIF1.2 Switch", WM8995_DAC2_LEFT_MIXER_ROUTING,
581 1, 1, 0),
582 SOC_DAPM_SINGLE("AIF1.1 Switch", WM8995_DAC2_LEFT_MIXER_ROUTING,
583 0, 1, 0),
584};
585
586static const struct snd_kcontrol_new aif2dac2r_mix[] = {
587 SOC_DAPM_SINGLE("Right Sidetone Switch", WM8995_DAC2_RIGHT_MIXER_ROUTING,
588 5, 1, 0),
589 SOC_DAPM_SINGLE("Left Sidetone Switch", WM8995_DAC2_RIGHT_MIXER_ROUTING,
590 4, 1, 0),
591 SOC_DAPM_SINGLE("AIF2 Switch", WM8995_DAC2_RIGHT_MIXER_ROUTING,
592 2, 1, 0),
593 SOC_DAPM_SINGLE("AIF1.2 Switch", WM8995_DAC2_RIGHT_MIXER_ROUTING,
594 1, 1, 0),
595 SOC_DAPM_SINGLE("AIF1.1 Switch", WM8995_DAC2_RIGHT_MIXER_ROUTING,
596 0, 1, 0),
597};
598
599static const struct snd_kcontrol_new in1l_pga =
600 SOC_DAPM_SINGLE("IN1L Switch", WM8995_POWER_MANAGEMENT_2, 5, 1, 0);
601
602static const struct snd_kcontrol_new in1r_pga =
603 SOC_DAPM_SINGLE("IN1R Switch", WM8995_POWER_MANAGEMENT_2, 4, 1, 0);
604
605static const char *adc_mux_text[] = {
606 "ADC",
607 "DMIC",
608};
609
610static const struct soc_enum adc_enum =
611 SOC_ENUM_SINGLE(0, 0, 2, adc_mux_text);
612
613static const struct snd_kcontrol_new adcl_mux =
614 SOC_DAPM_ENUM_VIRT("ADCL Mux", adc_enum);
615
616static const struct snd_kcontrol_new adcr_mux =
617 SOC_DAPM_ENUM_VIRT("ADCR Mux", adc_enum);
618
619static const char *spk_src_text[] = {
620 "DAC1L", "DAC1R", "DAC2L", "DAC2R"
621};
622
623static const SOC_ENUM_SINGLE_DECL(spk1l_src_enum, WM8995_LEFT_PDM_SPEAKER_1,
624 0, spk_src_text);
625static const SOC_ENUM_SINGLE_DECL(spk1r_src_enum, WM8995_RIGHT_PDM_SPEAKER_1,
626 0, spk_src_text);
627static const SOC_ENUM_SINGLE_DECL(spk2l_src_enum, WM8995_LEFT_PDM_SPEAKER_2,
628 0, spk_src_text);
629static const SOC_ENUM_SINGLE_DECL(spk2r_src_enum, WM8995_RIGHT_PDM_SPEAKER_2,
630 0, spk_src_text);
631
632static const struct snd_kcontrol_new spk1l_mux =
633 SOC_DAPM_ENUM("SPK1L SRC", spk1l_src_enum);
634static const struct snd_kcontrol_new spk1r_mux =
635 SOC_DAPM_ENUM("SPK1R SRC", spk1r_src_enum);
636static const struct snd_kcontrol_new spk2l_mux =
637 SOC_DAPM_ENUM("SPK2L SRC", spk2l_src_enum);
638static const struct snd_kcontrol_new spk2r_mux =
639 SOC_DAPM_ENUM("SPK2R SRC", spk2r_src_enum);
640
641static const struct snd_soc_dapm_widget wm8995_dapm_widgets[] = {
642 SND_SOC_DAPM_INPUT("DMIC1DAT"),
643 SND_SOC_DAPM_INPUT("DMIC2DAT"),
644
645 SND_SOC_DAPM_INPUT("IN1L"),
646 SND_SOC_DAPM_INPUT("IN1R"),
647
648 SND_SOC_DAPM_MIXER("IN1L PGA", SND_SOC_NOPM, 0, 0,
649 &in1l_pga, 1),
650 SND_SOC_DAPM_MIXER("IN1R PGA", SND_SOC_NOPM, 0, 0,
651 &in1r_pga, 1),
652
653 SND_SOC_DAPM_MICBIAS("MICBIAS1", WM8995_POWER_MANAGEMENT_1, 8, 0),
654 SND_SOC_DAPM_MICBIAS("MICBIAS2", WM8995_POWER_MANAGEMENT_1, 9, 0),
655
656 SND_SOC_DAPM_SUPPLY("AIF1CLK", WM8995_AIF1_CLOCKING_1, 0, 0, NULL, 0),
657 SND_SOC_DAPM_SUPPLY("AIF2CLK", WM8995_AIF2_CLOCKING_1, 0, 0, NULL, 0),
658 SND_SOC_DAPM_SUPPLY("DSP1CLK", WM8995_CLOCKING_1, 3, 0, NULL, 0),
659 SND_SOC_DAPM_SUPPLY("DSP2CLK", WM8995_CLOCKING_1, 2, 0, NULL, 0),
660 SND_SOC_DAPM_SUPPLY("SYSDSPCLK", WM8995_CLOCKING_1, 1, 0, NULL, 0),
661 SND_SOC_DAPM_SUPPLY("CLK_SYS", SND_SOC_NOPM, 0, 0, clk_sys_event,
662 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD),
663
664 SND_SOC_DAPM_AIF_OUT("AIF1ADC1L", "AIF1 Capture", 0,
665 WM8995_POWER_MANAGEMENT_3, 9, 0),
666 SND_SOC_DAPM_AIF_OUT("AIF1ADC1R", "AIF1 Capture", 0,
667 WM8995_POWER_MANAGEMENT_3, 8, 0),
668 SND_SOC_DAPM_AIF_OUT("AIF1ADCDAT", "AIF1 Capture", 0,
669 SND_SOC_NOPM, 0, 0),
670 SND_SOC_DAPM_AIF_OUT("AIF1ADC2L", "AIF1 Capture",
671 0, WM8995_POWER_MANAGEMENT_3, 11, 0),
672 SND_SOC_DAPM_AIF_OUT("AIF1ADC2R", "AIF1 Capture",
673 0, WM8995_POWER_MANAGEMENT_3, 10, 0),
674
675 SND_SOC_DAPM_VIRT_MUX("ADCL Mux", SND_SOC_NOPM, 1, 0,
676 &adcl_mux),
677 SND_SOC_DAPM_VIRT_MUX("ADCR Mux", SND_SOC_NOPM, 0, 0,
678 &adcr_mux),
679
680 SND_SOC_DAPM_ADC("DMIC2L", NULL, WM8995_POWER_MANAGEMENT_3, 5, 0),
681 SND_SOC_DAPM_ADC("DMIC2R", NULL, WM8995_POWER_MANAGEMENT_3, 4, 0),
682 SND_SOC_DAPM_ADC("DMIC1L", NULL, WM8995_POWER_MANAGEMENT_3, 3, 0),
683 SND_SOC_DAPM_ADC("DMIC1R", NULL, WM8995_POWER_MANAGEMENT_3, 2, 0),
684
685 SND_SOC_DAPM_ADC("ADCL", NULL, WM8995_POWER_MANAGEMENT_3, 1, 0),
686 SND_SOC_DAPM_ADC("ADCR", NULL, WM8995_POWER_MANAGEMENT_3, 0, 0),
687
688 SND_SOC_DAPM_MIXER("AIF1ADC1L Mixer", SND_SOC_NOPM, 0, 0,
689 aif1adc1l_mix, ARRAY_SIZE(aif1adc1l_mix)),
690 SND_SOC_DAPM_MIXER("AIF1ADC1R Mixer", SND_SOC_NOPM, 0, 0,
691 aif1adc1r_mix, ARRAY_SIZE(aif1adc1r_mix)),
692 SND_SOC_DAPM_MIXER("AIF1ADC2L Mixer", SND_SOC_NOPM, 0, 0,
693 aif1adc2l_mix, ARRAY_SIZE(aif1adc2l_mix)),
694 SND_SOC_DAPM_MIXER("AIF1ADC2R Mixer", SND_SOC_NOPM, 0, 0,
695 aif1adc2r_mix, ARRAY_SIZE(aif1adc2r_mix)),
696
697 SND_SOC_DAPM_AIF_IN("AIF1DAC1L", NULL, 0, WM8995_POWER_MANAGEMENT_4,
698 9, 0),
699 SND_SOC_DAPM_AIF_IN("AIF1DAC1R", NULL, 0, WM8995_POWER_MANAGEMENT_4,
700 8, 0),
701 SND_SOC_DAPM_AIF_IN("AIF1DACDAT", "AIF1 Playback", 0, SND_SOC_NOPM,
702 0, 0),
703
704 SND_SOC_DAPM_AIF_IN("AIF1DAC2L", NULL, 0, WM8995_POWER_MANAGEMENT_4,
705 11, 0),
706 SND_SOC_DAPM_AIF_IN("AIF1DAC2R", NULL, 0, WM8995_POWER_MANAGEMENT_4,
707 10, 0),
708
709 SND_SOC_DAPM_MIXER("AIF2DAC2L Mixer", SND_SOC_NOPM, 0, 0,
710 aif2dac2l_mix, ARRAY_SIZE(aif2dac2l_mix)),
711 SND_SOC_DAPM_MIXER("AIF2DAC2R Mixer", SND_SOC_NOPM, 0, 0,
712 aif2dac2r_mix, ARRAY_SIZE(aif2dac2r_mix)),
713
714 SND_SOC_DAPM_DAC("DAC2L", NULL, WM8995_POWER_MANAGEMENT_4, 3, 0),
715 SND_SOC_DAPM_DAC("DAC2R", NULL, WM8995_POWER_MANAGEMENT_4, 2, 0),
716 SND_SOC_DAPM_DAC("DAC1L", NULL, WM8995_POWER_MANAGEMENT_4, 1, 0),
717 SND_SOC_DAPM_DAC("DAC1R", NULL, WM8995_POWER_MANAGEMENT_4, 0, 0),
718
719 SND_SOC_DAPM_MIXER("DAC1L Mixer", SND_SOC_NOPM, 0, 0, dac1l_mix,
720 ARRAY_SIZE(dac1l_mix)),
721 SND_SOC_DAPM_MIXER("DAC1R Mixer", SND_SOC_NOPM, 0, 0, dac1r_mix,
722 ARRAY_SIZE(dac1r_mix)),
723
724 SND_SOC_DAPM_MUX("Left Sidetone", SND_SOC_NOPM, 0, 0, &sidetone1_mux),
725 SND_SOC_DAPM_MUX("Right Sidetone", SND_SOC_NOPM, 0, 0, &sidetone2_mux),
726
727 SND_SOC_DAPM_PGA_E("Headphone PGA", SND_SOC_NOPM, 0, 0, NULL, 0,
728 hp_event, SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD),
729
730 SND_SOC_DAPM_SUPPLY("Headphone Supply", SND_SOC_NOPM, 0, 0,
731 hp_supply_event, SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_PRE_PMD),
732
733 SND_SOC_DAPM_MUX("SPK1L Driver", WM8995_LEFT_PDM_SPEAKER_1,
734 4, 0, &spk1l_mux),
735 SND_SOC_DAPM_MUX("SPK1R Driver", WM8995_RIGHT_PDM_SPEAKER_1,
736 4, 0, &spk1r_mux),
737 SND_SOC_DAPM_MUX("SPK2L Driver", WM8995_LEFT_PDM_SPEAKER_2,
738 4, 0, &spk2l_mux),
739 SND_SOC_DAPM_MUX("SPK2R Driver", WM8995_RIGHT_PDM_SPEAKER_2,
740 4, 0, &spk2r_mux),
741
742 SND_SOC_DAPM_SUPPLY("LDO2", WM8995_POWER_MANAGEMENT_2, 1, 0, NULL, 0),
743
744 SND_SOC_DAPM_OUTPUT("HP1L"),
745 SND_SOC_DAPM_OUTPUT("HP1R"),
746 SND_SOC_DAPM_OUTPUT("SPK1L"),
747 SND_SOC_DAPM_OUTPUT("SPK1R"),
748 SND_SOC_DAPM_OUTPUT("SPK2L"),
749 SND_SOC_DAPM_OUTPUT("SPK2R")
750};
751
752static const struct snd_soc_dapm_route wm8995_intercon[] = {
753 { "CLK_SYS", NULL, "AIF1CLK", check_clk_sys },
754 { "CLK_SYS", NULL, "AIF2CLK", check_clk_sys },
755
756 { "DSP1CLK", NULL, "CLK_SYS" },
757 { "DSP2CLK", NULL, "CLK_SYS" },
758 { "SYSDSPCLK", NULL, "CLK_SYS" },
759
760 { "AIF1ADC1L", NULL, "AIF1CLK" },
761 { "AIF1ADC1L", NULL, "DSP1CLK" },
762 { "AIF1ADC1R", NULL, "AIF1CLK" },
763 { "AIF1ADC1R", NULL, "DSP1CLK" },
764 { "AIF1ADC1R", NULL, "SYSDSPCLK" },
765
766 { "AIF1ADC2L", NULL, "AIF1CLK" },
767 { "AIF1ADC2L", NULL, "DSP1CLK" },
768 { "AIF1ADC2R", NULL, "AIF1CLK" },
769 { "AIF1ADC2R", NULL, "DSP1CLK" },
770 { "AIF1ADC2R", NULL, "SYSDSPCLK" },
771
772 { "DMIC1L", NULL, "DMIC1DAT" },
773 { "DMIC1L", NULL, "CLK_SYS" },
774 { "DMIC1R", NULL, "DMIC1DAT" },
775 { "DMIC1R", NULL, "CLK_SYS" },
776 { "DMIC2L", NULL, "DMIC2DAT" },
777 { "DMIC2L", NULL, "CLK_SYS" },
778 { "DMIC2R", NULL, "DMIC2DAT" },
779 { "DMIC2R", NULL, "CLK_SYS" },
780
781 { "ADCL", NULL, "AIF1CLK" },
782 { "ADCL", NULL, "DSP1CLK" },
783 { "ADCL", NULL, "SYSDSPCLK" },
784
785 { "ADCR", NULL, "AIF1CLK" },
786 { "ADCR", NULL, "DSP1CLK" },
787 { "ADCR", NULL, "SYSDSPCLK" },
788
789 { "IN1L PGA", "IN1L Switch", "IN1L" },
790 { "IN1R PGA", "IN1R Switch", "IN1R" },
791 { "IN1L PGA", NULL, "LDO2" },
792 { "IN1R PGA", NULL, "LDO2" },
793
794 { "ADCL", NULL, "IN1L PGA" },
795 { "ADCR", NULL, "IN1R PGA" },
796
797 { "ADCL Mux", "ADC", "ADCL" },
798 { "ADCL Mux", "DMIC", "DMIC1L" },
799 { "ADCR Mux", "ADC", "ADCR" },
800 { "ADCR Mux", "DMIC", "DMIC1R" },
801
802 /* AIF1 outputs */
803 { "AIF1ADC1L", NULL, "AIF1ADC1L Mixer" },
804 { "AIF1ADC1L Mixer", "ADC/DMIC Switch", "ADCL Mux" },
805
806 { "AIF1ADC1R", NULL, "AIF1ADC1R Mixer" },
807 { "AIF1ADC1R Mixer", "ADC/DMIC Switch", "ADCR Mux" },
808
809 { "AIF1ADC2L", NULL, "AIF1ADC2L Mixer" },
810 { "AIF1ADC2L Mixer", "DMIC Switch", "DMIC2L" },
811
812 { "AIF1ADC2R", NULL, "AIF1ADC2R Mixer" },
813 { "AIF1ADC2R Mixer", "DMIC Switch", "DMIC2R" },
814
815 /* Sidetone */
816 { "Left Sidetone", "ADC/DMIC1", "AIF1ADC1L" },
817 { "Left Sidetone", "DMIC2", "AIF1ADC2L" },
818 { "Right Sidetone", "ADC/DMIC1", "AIF1ADC1R" },
819 { "Right Sidetone", "DMIC2", "AIF1ADC2R" },
820
821 { "AIF1DAC1L", NULL, "AIF1CLK" },
822 { "AIF1DAC1L", NULL, "DSP1CLK" },
823 { "AIF1DAC1R", NULL, "AIF1CLK" },
824 { "AIF1DAC1R", NULL, "DSP1CLK" },
825 { "AIF1DAC1R", NULL, "SYSDSPCLK" },
826
827 { "AIF1DAC2L", NULL, "AIF1CLK" },
828 { "AIF1DAC2L", NULL, "DSP1CLK" },
829 { "AIF1DAC2R", NULL, "AIF1CLK" },
830 { "AIF1DAC2R", NULL, "DSP1CLK" },
831 { "AIF1DAC2R", NULL, "SYSDSPCLK" },
832
833 { "DAC1L", NULL, "AIF1CLK" },
834 { "DAC1L", NULL, "DSP1CLK" },
835 { "DAC1L", NULL, "SYSDSPCLK" },
836
837 { "DAC1R", NULL, "AIF1CLK" },
838 { "DAC1R", NULL, "DSP1CLK" },
839 { "DAC1R", NULL, "SYSDSPCLK" },
840
841 { "AIF1DAC1L", NULL, "AIF1DACDAT" },
842 { "AIF1DAC1R", NULL, "AIF1DACDAT" },
843 { "AIF1DAC2L", NULL, "AIF1DACDAT" },
844 { "AIF1DAC2R", NULL, "AIF1DACDAT" },
845
846 /* DAC1 inputs */
847 { "DAC1L", NULL, "DAC1L Mixer" },
848 { "DAC1L Mixer", "AIF1.1 Switch", "AIF1DAC1L" },
849 { "DAC1L Mixer", "AIF1.2 Switch", "AIF1DAC2L" },
850 { "DAC1L Mixer", "Left Sidetone Switch", "Left Sidetone" },
851 { "DAC1L Mixer", "Right Sidetone Switch", "Right Sidetone" },
852
853 { "DAC1R", NULL, "DAC1R Mixer" },
854 { "DAC1R Mixer", "AIF1.1 Switch", "AIF1DAC1R" },
855 { "DAC1R Mixer", "AIF1.2 Switch", "AIF1DAC2R" },
856 { "DAC1R Mixer", "Left Sidetone Switch", "Left Sidetone" },
857 { "DAC1R Mixer", "Right Sidetone Switch", "Right Sidetone" },
858
859 /* DAC2/AIF2 outputs */
860 { "DAC2L", NULL, "AIF2DAC2L Mixer" },
861 { "AIF2DAC2L Mixer", "AIF1.2 Switch", "AIF1DAC2L" },
862 { "AIF2DAC2L Mixer", "AIF1.1 Switch", "AIF1DAC1L" },
863
864 { "DAC2R", NULL, "AIF2DAC2R Mixer" },
865 { "AIF2DAC2R Mixer", "AIF1.2 Switch", "AIF1DAC2R" },
866 { "AIF2DAC2R Mixer", "AIF1.1 Switch", "AIF1DAC1R" },
867
868 /* Output stages */
869 { "Headphone PGA", NULL, "DAC1L" },
870 { "Headphone PGA", NULL, "DAC1R" },
871
872 { "Headphone PGA", NULL, "DAC2L" },
873 { "Headphone PGA", NULL, "DAC2R" },
874
875 { "Headphone PGA", NULL, "Headphone Supply" },
876 { "Headphone PGA", NULL, "CLK_SYS" },
877 { "Headphone PGA", NULL, "LDO2" },
878
879 { "HP1L", NULL, "Headphone PGA" },
880 { "HP1R", NULL, "Headphone PGA" },
881
882 { "SPK1L Driver", "DAC1L", "DAC1L" },
883 { "SPK1L Driver", "DAC1R", "DAC1R" },
884 { "SPK1L Driver", "DAC2L", "DAC2L" },
885 { "SPK1L Driver", "DAC2R", "DAC2R" },
886 { "SPK1L Driver", NULL, "CLK_SYS" },
887
888 { "SPK1R Driver", "DAC1L", "DAC1L" },
889 { "SPK1R Driver", "DAC1R", "DAC1R" },
890 { "SPK1R Driver", "DAC2L", "DAC2L" },
891 { "SPK1R Driver", "DAC2R", "DAC2R" },
892 { "SPK1R Driver", NULL, "CLK_SYS" },
893
894 { "SPK2L Driver", "DAC1L", "DAC1L" },
895 { "SPK2L Driver", "DAC1R", "DAC1R" },
896 { "SPK2L Driver", "DAC2L", "DAC2L" },
897 { "SPK2L Driver", "DAC2R", "DAC2R" },
898 { "SPK2L Driver", NULL, "CLK_SYS" },
899
900 { "SPK2R Driver", "DAC1L", "DAC1L" },
901 { "SPK2R Driver", "DAC1R", "DAC1R" },
902 { "SPK2R Driver", "DAC2L", "DAC2L" },
903 { "SPK2R Driver", "DAC2R", "DAC2R" },
904 { "SPK2R Driver", NULL, "CLK_SYS" },
905
906 { "SPK1L", NULL, "SPK1L Driver" },
907 { "SPK1R", NULL, "SPK1R Driver" },
908 { "SPK2L", NULL, "SPK2L Driver" },
909 { "SPK2R", NULL, "SPK2R Driver" }
910};
911
912static int wm8995_volatile(unsigned int reg)
913{
914 /* out of bounds registers are generally considered
915 * volatile to support register banks that are partially
916 * owned by something else for e.g. a DSP
917 */
918 if (reg > WM8995_MAX_CACHED_REGISTER)
919 return 1;
920
921 switch (reg) {
922 case WM8995_SOFTWARE_RESET:
923 case WM8995_DC_SERVO_READBACK_0:
924 case WM8995_INTERRUPT_STATUS_1:
925 case WM8995_INTERRUPT_STATUS_2:
926 case WM8995_INTERRUPT_STATUS_1_MASK:
927 case WM8995_INTERRUPT_STATUS_2_MASK:
928 case WM8995_INTERRUPT_CONTROL:
929 case WM8995_ACCESSORY_DETECT_MODE1:
930 case WM8995_ACCESSORY_DETECT_MODE2:
931 case WM8995_HEADPHONE_DETECT1:
932 case WM8995_HEADPHONE_DETECT2:
933 return 1;
934 }
935
936 return 0;
937}
938
939static int wm8995_aif_mute(struct snd_soc_dai *dai, int mute)
940{
941 struct snd_soc_codec *codec = dai->codec;
942 int mute_reg;
943
944 switch (dai->id) {
945 case 0:
946 mute_reg = WM8995_AIF1_DAC1_FILTERS_1;
947 break;
948 case 1:
949 mute_reg = WM8995_AIF2_DAC_FILTERS_1;
950 break;
951 default:
952 return -EINVAL;
953 }
954
955 snd_soc_update_bits(codec, mute_reg, WM8995_AIF1DAC1_MUTE_MASK,
956 !!mute << WM8995_AIF1DAC1_MUTE_SHIFT);
957 return 0;
958}
959
960static int wm8995_set_dai_fmt(struct snd_soc_dai *dai, unsigned int fmt)
961{
962 struct snd_soc_codec *codec;
963 int master;
964 int aif;
965
966 codec = dai->codec;
967
968 master = 0;
969 switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
970 case SND_SOC_DAIFMT_CBS_CFS:
971 break;
972 case SND_SOC_DAIFMT_CBM_CFM:
973 master = WM8995_AIF1_MSTR;
974 break;
975 default:
976 dev_err(dai->dev, "Unknown master/slave configuration\n");
977 return -EINVAL;
978 }
979
980 aif = 0;
981 switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
982 case SND_SOC_DAIFMT_DSP_B:
983 aif |= WM8995_AIF1_LRCLK_INV;
984 case SND_SOC_DAIFMT_DSP_A:
985 aif |= (0x3 << WM8995_AIF1_FMT_SHIFT);
986 break;
987 case SND_SOC_DAIFMT_I2S:
988 aif |= (0x2 << WM8995_AIF1_FMT_SHIFT);
989 break;
990 case SND_SOC_DAIFMT_RIGHT_J:
991 break;
992 case SND_SOC_DAIFMT_LEFT_J:
993 aif |= (0x1 << WM8995_AIF1_FMT_SHIFT);
994 break;
995 default:
996 dev_err(dai->dev, "Unknown dai format\n");
997 return -EINVAL;
998 }
999
1000 switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
1001 case SND_SOC_DAIFMT_DSP_A:
1002 case SND_SOC_DAIFMT_DSP_B:
1003 /* frame inversion not valid for DSP modes */
1004 switch (fmt & SND_SOC_DAIFMT_INV_MASK) {
1005 case SND_SOC_DAIFMT_NB_NF:
1006 break;
1007 case SND_SOC_DAIFMT_IB_NF:
1008 aif |= WM8995_AIF1_BCLK_INV;
1009 break;
1010 default:
1011 return -EINVAL;
1012 }
1013 break;
1014
1015 case SND_SOC_DAIFMT_I2S:
1016 case SND_SOC_DAIFMT_RIGHT_J:
1017 case SND_SOC_DAIFMT_LEFT_J:
1018 switch (fmt & SND_SOC_DAIFMT_INV_MASK) {
1019 case SND_SOC_DAIFMT_NB_NF:
1020 break;
1021 case SND_SOC_DAIFMT_IB_IF:
1022 aif |= WM8995_AIF1_BCLK_INV | WM8995_AIF1_LRCLK_INV;
1023 break;
1024 case SND_SOC_DAIFMT_IB_NF:
1025 aif |= WM8995_AIF1_BCLK_INV;
1026 break;
1027 case SND_SOC_DAIFMT_NB_IF:
1028 aif |= WM8995_AIF1_LRCLK_INV;
1029 break;
1030 default:
1031 return -EINVAL;
1032 }
1033 break;
1034 default:
1035 return -EINVAL;
1036 }
1037
1038 snd_soc_update_bits(codec, WM8995_AIF1_CONTROL_1,
1039 WM8995_AIF1_BCLK_INV_MASK |
1040 WM8995_AIF1_LRCLK_INV_MASK |
1041 WM8995_AIF1_FMT_MASK, aif);
1042 snd_soc_update_bits(codec, WM8995_AIF1_MASTER_SLAVE,
1043 WM8995_AIF1_MSTR_MASK, master);
1044 return 0;
1045}
1046
1047static const int srs[] = {
1048 8000, 11025, 12000, 16000, 22050, 24000, 32000, 44100,
1049 48000, 88200, 96000
1050};
1051
1052static const int fs_ratios[] = {
1053 -1 /* reserved */,
1054 128, 192, 256, 384, 512, 768, 1024, 1408, 1536
1055};
1056
1057static const int bclk_divs[] = {
1058 10, 15, 20, 30, 40, 55, 60, 80, 110, 120, 160, 220, 240, 320, 440, 480
1059};
1060
1061static int wm8995_hw_params(struct snd_pcm_substream *substream,
1062 struct snd_pcm_hw_params *params,
1063 struct snd_soc_dai *dai)
1064{
1065 struct snd_soc_codec *codec;
1066 struct wm8995_priv *wm8995;
1067 int aif1_reg;
1068 int bclk_reg;
1069 int lrclk_reg;
1070 int rate_reg;
1071 int bclk_rate;
1072 int aif1;
1073 int lrclk, bclk;
1074 int i, rate_val, best, best_val, cur_val;
1075
1076 codec = dai->codec;
1077 wm8995 = snd_soc_codec_get_drvdata(codec);
1078
1079 switch (dai->id) {
1080 case 0:
1081 aif1_reg = WM8995_AIF1_CONTROL_1;
1082 bclk_reg = WM8995_AIF1_BCLK;
1083 rate_reg = WM8995_AIF1_RATE;
1084 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK /* ||
1085 wm8995->lrclk_shared[0] */) {
1086 lrclk_reg = WM8995_AIF1DAC_LRCLK;
1087 } else {
1088 lrclk_reg = WM8995_AIF1ADC_LRCLK;
1089 dev_dbg(codec->dev, "AIF1 using split LRCLK\n");
1090 }
1091 break;
1092 case 1:
1093 aif1_reg = WM8995_AIF2_CONTROL_1;
1094 bclk_reg = WM8995_AIF2_BCLK;
1095 rate_reg = WM8995_AIF2_RATE;
1096 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK /* ||
1097 wm8995->lrclk_shared[1] */) {
1098 lrclk_reg = WM8995_AIF2DAC_LRCLK;
1099 } else {
1100 lrclk_reg = WM8995_AIF2ADC_LRCLK;
1101 dev_dbg(codec->dev, "AIF2 using split LRCLK\n");
1102 }
1103 break;
1104 default:
1105 return -EINVAL;
1106 }
1107
1108 bclk_rate = snd_soc_params_to_bclk(params);
1109 if (bclk_rate < 0)
1110 return bclk_rate;
1111
1112 aif1 = 0;
1113 switch (params_format(params)) {
1114 case SNDRV_PCM_FORMAT_S16_LE:
1115 break;
1116 case SNDRV_PCM_FORMAT_S20_3LE:
1117 aif1 |= (0x1 << WM8995_AIF1_WL_SHIFT);
1118 break;
1119 case SNDRV_PCM_FORMAT_S24_LE:
1120 aif1 |= (0x2 << WM8995_AIF1_WL_SHIFT);
1121 break;
1122 case SNDRV_PCM_FORMAT_S32_LE:
1123 aif1 |= (0x3 << WM8995_AIF1_WL_SHIFT);
1124 break;
1125 default:
1126 dev_err(dai->dev, "Unsupported word length %u\n",
1127 params_format(params));
1128 return -EINVAL;
1129 }
1130
1131 /* try to find a suitable sample rate */
1132 for (i = 0; i < ARRAY_SIZE(srs); ++i)
1133 if (srs[i] == params_rate(params))
1134 break;
1135 if (i == ARRAY_SIZE(srs)) {
1136 dev_err(dai->dev, "Sample rate %d is not supported\n",
1137 params_rate(params));
1138 return -EINVAL;
1139 }
1140 rate_val = i << WM8995_AIF1_SR_SHIFT;
1141
1142 dev_dbg(dai->dev, "Sample rate is %dHz\n", srs[i]);
1143 dev_dbg(dai->dev, "AIF%dCLK is %dHz, target BCLK %dHz\n",
1144 dai->id + 1, wm8995->aifclk[dai->id], bclk_rate);
1145
1146 /* AIFCLK/fs ratio; look for a close match in either direction */
1147 best = 1;
1148 best_val = abs((fs_ratios[1] * params_rate(params))
1149 - wm8995->aifclk[dai->id]);
1150 for (i = 2; i < ARRAY_SIZE(fs_ratios); i++) {
1151 cur_val = abs((fs_ratios[i] * params_rate(params))
1152 - wm8995->aifclk[dai->id]);
1153 if (cur_val >= best_val)
1154 continue;
1155 best = i;
1156 best_val = cur_val;
1157 }
1158 rate_val |= best;
1159
1160 dev_dbg(dai->dev, "Selected AIF%dCLK/fs = %d\n",
1161 dai->id + 1, fs_ratios[best]);
1162
1163 /*
1164 * We may not get quite the right frequency if using
1165 * approximate clocks so look for the closest match that is
1166 * higher than the target (we need to ensure that there enough
1167 * BCLKs to clock out the samples).
1168 */
1169 best = 0;
1170 bclk = 0;
1171 for (i = 0; i < ARRAY_SIZE(bclk_divs); i++) {
1172 cur_val = (wm8995->aifclk[dai->id] * 10 / bclk_divs[i]) - bclk_rate;
1173 if (cur_val < 0) /* BCLK table is sorted */
1174 break;
1175 best = i;
1176 }
1177 bclk |= best << WM8995_AIF1_BCLK_DIV_SHIFT;
1178
1179 bclk_rate = wm8995->aifclk[dai->id] * 10 / bclk_divs[best];
1180 dev_dbg(dai->dev, "Using BCLK_DIV %d for actual BCLK %dHz\n",
1181 bclk_divs[best], bclk_rate);
1182
1183 lrclk = bclk_rate / params_rate(params);
1184 dev_dbg(dai->dev, "Using LRCLK rate %d for actual LRCLK %dHz\n",
1185 lrclk, bclk_rate / lrclk);
1186
1187 snd_soc_update_bits(codec, aif1_reg,
1188 WM8995_AIF1_WL_MASK, aif1);
1189 snd_soc_update_bits(codec, bclk_reg,
1190 WM8995_AIF1_BCLK_DIV_MASK, bclk);
1191 snd_soc_update_bits(codec, lrclk_reg,
1192 WM8995_AIF1DAC_RATE_MASK, lrclk);
1193 snd_soc_update_bits(codec, rate_reg,
1194 WM8995_AIF1_SR_MASK |
1195 WM8995_AIF1CLK_RATE_MASK, rate_val);
1196 return 0;
1197}
1198
1199static int wm8995_set_tristate(struct snd_soc_dai *codec_dai, int tristate)
1200{
1201 struct snd_soc_codec *codec = codec_dai->codec;
1202 int reg, val, mask;
1203
1204 switch (codec_dai->id) {
1205 case 0:
1206 reg = WM8995_AIF1_MASTER_SLAVE;
1207 mask = WM8995_AIF1_TRI;
1208 break;
1209 case 1:
1210 reg = WM8995_AIF2_MASTER_SLAVE;
1211 mask = WM8995_AIF2_TRI;
1212 break;
1213 case 2:
1214 reg = WM8995_POWER_MANAGEMENT_5;
1215 mask = WM8995_AIF3_TRI;
1216 break;
1217 default:
1218 return -EINVAL;
1219 }
1220
1221 if (tristate)
1222 val = mask;
1223 else
1224 val = 0;
1225
1226 return snd_soc_update_bits(codec, reg, mask, reg);
1227}
1228
1229/* The size in bits of the FLL divide multiplied by 10
1230 * to allow rounding later */
1231#define FIXED_FLL_SIZE ((1 << 16) * 10)
1232
1233struct fll_div {
1234 u16 outdiv;
1235 u16 n;
1236 u16 k;
1237 u16 clk_ref_div;
1238 u16 fll_fratio;
1239};
1240
1241static int wm8995_get_fll_config(struct fll_div *fll,
1242 int freq_in, int freq_out)
1243{
1244 u64 Kpart;
1245 unsigned int K, Ndiv, Nmod;
1246
1247 pr_debug("FLL input=%dHz, output=%dHz\n", freq_in, freq_out);
1248
1249 /* Scale the input frequency down to <= 13.5MHz */
1250 fll->clk_ref_div = 0;
1251 while (freq_in > 13500000) {
1252 fll->clk_ref_div++;
1253 freq_in /= 2;
1254
1255 if (fll->clk_ref_div > 3)
1256 return -EINVAL;
1257 }
1258 pr_debug("CLK_REF_DIV=%d, Fref=%dHz\n", fll->clk_ref_div, freq_in);
1259
1260 /* Scale the output to give 90MHz<=Fvco<=100MHz */
1261 fll->outdiv = 3;
1262 while (freq_out * (fll->outdiv + 1) < 90000000) {
1263 fll->outdiv++;
1264 if (fll->outdiv > 63)
1265 return -EINVAL;
1266 }
1267 freq_out *= fll->outdiv + 1;
1268 pr_debug("OUTDIV=%d, Fvco=%dHz\n", fll->outdiv, freq_out);
1269
1270 if (freq_in > 1000000) {
1271 fll->fll_fratio = 0;
1272 } else if (freq_in > 256000) {
1273 fll->fll_fratio = 1;
1274 freq_in *= 2;
1275 } else if (freq_in > 128000) {
1276 fll->fll_fratio = 2;
1277 freq_in *= 4;
1278 } else if (freq_in > 64000) {
1279 fll->fll_fratio = 3;
1280 freq_in *= 8;
1281 } else {
1282 fll->fll_fratio = 4;
1283 freq_in *= 16;
1284 }
1285 pr_debug("FLL_FRATIO=%d, Fref=%dHz\n", fll->fll_fratio, freq_in);
1286
1287 /* Now, calculate N.K */
1288 Ndiv = freq_out / freq_in;
1289
1290 fll->n = Ndiv;
1291 Nmod = freq_out % freq_in;
1292 pr_debug("Nmod=%d\n", Nmod);
1293
1294 /* Calculate fractional part - scale up so we can round. */
1295 Kpart = FIXED_FLL_SIZE * (long long)Nmod;
1296
1297 do_div(Kpart, freq_in);
1298
1299 K = Kpart & 0xFFFFFFFF;
1300
1301 if ((K % 10) >= 5)
1302 K += 5;
1303
1304 /* Move down to proper range now rounding is done */
1305 fll->k = K / 10;
1306
1307 pr_debug("N=%x K=%x\n", fll->n, fll->k);
1308
1309 return 0;
1310}
1311
1312static int wm8995_set_fll(struct snd_soc_dai *dai, int id,
1313 int src, unsigned int freq_in,
1314 unsigned int freq_out)
1315{
1316 struct snd_soc_codec *codec;
1317 struct wm8995_priv *wm8995;
1318 int reg_offset, ret;
1319 struct fll_div fll;
1320 u16 reg, aif1, aif2;
1321
1322 codec = dai->codec;
1323 wm8995 = snd_soc_codec_get_drvdata(codec);
1324
1325 aif1 = snd_soc_read(codec, WM8995_AIF1_CLOCKING_1)
1326 & WM8995_AIF1CLK_ENA;
1327
1328 aif2 = snd_soc_read(codec, WM8995_AIF2_CLOCKING_1)
1329 & WM8995_AIF2CLK_ENA;
1330
1331 switch (id) {
1332 case WM8995_FLL1:
1333 reg_offset = 0;
1334 id = 0;
1335 break;
1336 case WM8995_FLL2:
1337 reg_offset = 0x20;
1338 id = 1;
1339 break;
1340 default:
1341 return -EINVAL;
1342 }
1343
1344 switch (src) {
1345 case 0:
1346 /* Allow no source specification when stopping */
1347 if (freq_out)
1348 return -EINVAL;
1349 break;
1350 case WM8995_FLL_SRC_MCLK1:
1351 case WM8995_FLL_SRC_MCLK2:
1352 case WM8995_FLL_SRC_LRCLK:
1353 case WM8995_FLL_SRC_BCLK:
1354 break;
1355 default:
1356 return -EINVAL;
1357 }
1358
1359 /* Are we changing anything? */
1360 if (wm8995->fll[id].src == src &&
1361 wm8995->fll[id].in == freq_in && wm8995->fll[id].out == freq_out)
1362 return 0;
1363
1364 /* If we're stopping the FLL redo the old config - no
1365 * registers will actually be written but we avoid GCC flow
1366 * analysis bugs spewing warnings.
1367 */
1368 if (freq_out)
1369 ret = wm8995_get_fll_config(&fll, freq_in, freq_out);
1370 else
1371 ret = wm8995_get_fll_config(&fll, wm8995->fll[id].in,
1372 wm8995->fll[id].out);
1373 if (ret < 0)
1374 return ret;
1375
1376 /* Gate the AIF clocks while we reclock */
1377 snd_soc_update_bits(codec, WM8995_AIF1_CLOCKING_1,
1378 WM8995_AIF1CLK_ENA_MASK, 0);
1379 snd_soc_update_bits(codec, WM8995_AIF2_CLOCKING_1,
1380 WM8995_AIF2CLK_ENA_MASK, 0);
1381
1382 /* We always need to disable the FLL while reconfiguring */
1383 snd_soc_update_bits(codec, WM8995_FLL1_CONTROL_1 + reg_offset,
1384 WM8995_FLL1_ENA_MASK, 0);
1385
1386 reg = (fll.outdiv << WM8995_FLL1_OUTDIV_SHIFT) |
1387 (fll.fll_fratio << WM8995_FLL1_FRATIO_SHIFT);
1388 snd_soc_update_bits(codec, WM8995_FLL1_CONTROL_2 + reg_offset,
1389 WM8995_FLL1_OUTDIV_MASK |
1390 WM8995_FLL1_FRATIO_MASK, reg);
1391
1392 snd_soc_write(codec, WM8995_FLL1_CONTROL_3 + reg_offset, fll.k);
1393
1394 snd_soc_update_bits(codec, WM8995_FLL1_CONTROL_4 + reg_offset,
1395 WM8995_FLL1_N_MASK,
1396 fll.n << WM8995_FLL1_N_SHIFT);
1397
1398 snd_soc_update_bits(codec, WM8995_FLL1_CONTROL_5 + reg_offset,
1399 WM8995_FLL1_REFCLK_DIV_MASK |
1400 WM8995_FLL1_REFCLK_SRC_MASK,
1401 (fll.clk_ref_div << WM8995_FLL1_REFCLK_DIV_SHIFT) |
1402 (src - 1));
1403
1404 if (freq_out)
1405 snd_soc_update_bits(codec, WM8995_FLL1_CONTROL_1 + reg_offset,
1406 WM8995_FLL1_ENA_MASK, WM8995_FLL1_ENA);
1407
1408 wm8995->fll[id].in = freq_in;
1409 wm8995->fll[id].out = freq_out;
1410 wm8995->fll[id].src = src;
1411
1412 /* Enable any gated AIF clocks */
1413 snd_soc_update_bits(codec, WM8995_AIF1_CLOCKING_1,
1414 WM8995_AIF1CLK_ENA_MASK, aif1);
1415 snd_soc_update_bits(codec, WM8995_AIF2_CLOCKING_1,
1416 WM8995_AIF2CLK_ENA_MASK, aif2);
1417
1418 configure_clock(codec);
1419
1420 return 0;
1421}
1422
1423static int wm8995_set_dai_sysclk(struct snd_soc_dai *dai,
1424 int clk_id, unsigned int freq, int dir)
1425{
1426 struct snd_soc_codec *codec;
1427 struct wm8995_priv *wm8995;
1428
1429 codec = dai->codec;
1430 wm8995 = snd_soc_codec_get_drvdata(codec);
1431
1432 switch (dai->id) {
1433 case 0:
1434 case 1:
1435 break;
1436 default:
1437 /* AIF3 shares clocking with AIF1/2 */
1438 return -EINVAL;
1439 }
1440
1441 switch (clk_id) {
1442 case WM8995_SYSCLK_MCLK1:
1443 wm8995->sysclk[dai->id] = WM8995_SYSCLK_MCLK1;
1444 wm8995->mclk[0] = freq;
1445 dev_dbg(dai->dev, "AIF%d using MCLK1 at %uHz\n",
1446 dai->id + 1, freq);
1447 break;
1448 case WM8995_SYSCLK_MCLK2:
1449 wm8995->sysclk[dai->id] = WM8995_SYSCLK_MCLK1;
1450 wm8995->mclk[1] = freq;
1451 dev_dbg(dai->dev, "AIF%d using MCLK2 at %uHz\n",
1452 dai->id + 1, freq);
1453 break;
1454 case WM8995_SYSCLK_FLL1:
1455 wm8995->sysclk[dai->id] = WM8995_SYSCLK_FLL1;
1456 dev_dbg(dai->dev, "AIF%d using FLL1\n", dai->id + 1);
1457 break;
1458 case WM8995_SYSCLK_FLL2:
1459 wm8995->sysclk[dai->id] = WM8995_SYSCLK_FLL2;
1460 dev_dbg(dai->dev, "AIF%d using FLL2\n", dai->id + 1);
1461 break;
1462 case WM8995_SYSCLK_OPCLK:
1463 default:
1464 dev_err(dai->dev, "Unknown clock source %d\n", clk_id);
1465 return -EINVAL;
1466 }
1467
1468 configure_clock(codec);
1469
1470 return 0;
1471}
1472
1473static int wm8995_set_bias_level(struct snd_soc_codec *codec,
1474 enum snd_soc_bias_level level)
1475{
1476 struct wm8995_priv *wm8995;
1477 int ret;
1478
1479 wm8995 = snd_soc_codec_get_drvdata(codec);
1480 switch (level) {
1481 case SND_SOC_BIAS_ON:
1482 case SND_SOC_BIAS_PREPARE:
1483 break;
1484 case SND_SOC_BIAS_STANDBY:
1485 if (codec->dapm.bias_level == SND_SOC_BIAS_OFF) {
1486 ret = snd_soc_cache_sync(codec);
1487 if (ret) {
1488 dev_err(codec->dev,
1489 "Failed to sync cache: %d\n", ret);
1490 return ret;
1491 }
1492
1493 snd_soc_update_bits(codec, WM8995_POWER_MANAGEMENT_1,
1494 WM8995_BG_ENA_MASK, WM8995_BG_ENA);
1495
1496 }
1497 break;
1498 case SND_SOC_BIAS_OFF:
1499 snd_soc_update_bits(codec, WM8995_POWER_MANAGEMENT_1,
1500 WM8995_BG_ENA_MASK, 0);
1501 break;
1502 }
1503
1504 codec->dapm.bias_level = level;
1505 return 0;
1506}
1507
1508#ifdef CONFIG_PM
1509static int wm8995_suspend(struct snd_soc_codec *codec, pm_message_t state)
1510{
1511 wm8995_set_bias_level(codec, SND_SOC_BIAS_OFF);
1512 return 0;
1513}
1514
1515static int wm8995_resume(struct snd_soc_codec *codec)
1516{
1517 wm8995_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
1518 return 0;
1519}
1520#else
1521#define wm8995_suspend NULL
1522#define wm8995_resume NULL
1523#endif
1524
1525static int wm8995_remove(struct snd_soc_codec *codec)
1526{
1527 struct wm8995_priv *wm8995;
1528 struct i2c_client *i2c;
1529
1530 i2c = container_of(codec->dev, struct i2c_client, dev);
1531 wm8995 = snd_soc_codec_get_drvdata(codec);
1532 wm8995_set_bias_level(codec, SND_SOC_BIAS_OFF);
1533 return 0;
1534}
1535
1536static int wm8995_probe(struct snd_soc_codec *codec)
1537{
1538 struct wm8995_priv *wm8995;
1539 int ret;
1540
1541 codec->dapm.idle_bias_off = 1;
1542 wm8995 = snd_soc_codec_get_drvdata(codec);
1543
1544 ret = snd_soc_codec_set_cache_io(codec, 16, 16, wm8995->control_type);
1545 if (ret < 0) {
1546 dev_err(codec->dev, "Failed to set cache i/o: %d\n", ret);
1547 return ret;
1548 }
1549
1550 ret = snd_soc_read(codec, WM8995_SOFTWARE_RESET);
1551 if (ret < 0) {
1552 dev_err(codec->dev, "Failed to read device ID: %d\n", ret);
1553 return ret;
1554 }
1555
1556 if (ret != 0x8995) {
1557 dev_err(codec->dev, "Invalid device ID: %#x\n", ret);
1558 return -EINVAL;
1559 }
1560
1561 ret = snd_soc_write(codec, WM8995_SOFTWARE_RESET, 0);
1562 if (ret < 0) {
1563 dev_err(codec->dev, "Failed to issue reset: %d\n", ret);
1564 return ret;
1565 }
1566
1567 wm8995_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
1568
1569 /* Latch volume updates (right only; we always do left then right). */
1570 snd_soc_update_bits(codec, WM8995_AIF1_DAC1_RIGHT_VOLUME,
1571 WM8995_AIF1DAC1_VU_MASK, WM8995_AIF1DAC1_VU);
1572 snd_soc_update_bits(codec, WM8995_AIF1_DAC2_RIGHT_VOLUME,
1573 WM8995_AIF1DAC2_VU_MASK, WM8995_AIF1DAC2_VU);
1574 snd_soc_update_bits(codec, WM8995_AIF2_DAC_RIGHT_VOLUME,
1575 WM8995_AIF2DAC_VU_MASK, WM8995_AIF2DAC_VU);
1576 snd_soc_update_bits(codec, WM8995_AIF1_ADC1_RIGHT_VOLUME,
1577 WM8995_AIF1ADC1_VU_MASK, WM8995_AIF1ADC1_VU);
1578 snd_soc_update_bits(codec, WM8995_AIF1_ADC2_RIGHT_VOLUME,
1579 WM8995_AIF1ADC2_VU_MASK, WM8995_AIF1ADC2_VU);
1580 snd_soc_update_bits(codec, WM8995_AIF2_ADC_RIGHT_VOLUME,
1581 WM8995_AIF2ADC_VU_MASK, WM8995_AIF1ADC2_VU);
1582 snd_soc_update_bits(codec, WM8995_DAC1_RIGHT_VOLUME,
1583 WM8995_DAC1_VU_MASK, WM8995_DAC1_VU);
1584 snd_soc_update_bits(codec, WM8995_DAC2_RIGHT_VOLUME,
1585 WM8995_DAC2_VU_MASK, WM8995_DAC2_VU);
1586 snd_soc_update_bits(codec, WM8995_RIGHT_LINE_INPUT_1_VOLUME,
1587 WM8995_IN1_VU_MASK, WM8995_IN1_VU);
1588
1589 wm8995_update_class_w(codec);
1590
1591 snd_soc_add_controls(codec, wm8995_snd_controls,
1592 ARRAY_SIZE(wm8995_snd_controls));
1593 snd_soc_dapm_new_controls(&codec->dapm, wm8995_dapm_widgets,
1594 ARRAY_SIZE(wm8995_dapm_widgets));
1595 snd_soc_dapm_add_routes(&codec->dapm, wm8995_intercon,
1596 ARRAY_SIZE(wm8995_intercon));
1597
1598 return 0;
1599}
1600
1601#define WM8995_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE |\
1602 SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S32_LE)
1603
1604static struct snd_soc_dai_ops wm8995_aif1_dai_ops = {
1605 .set_sysclk = wm8995_set_dai_sysclk,
1606 .set_fmt = wm8995_set_dai_fmt,
1607 .hw_params = wm8995_hw_params,
1608 .digital_mute = wm8995_aif_mute,
1609 .set_pll = wm8995_set_fll,
1610 .set_tristate = wm8995_set_tristate,
1611};
1612
1613static struct snd_soc_dai_ops wm8995_aif2_dai_ops = {
1614 .set_sysclk = wm8995_set_dai_sysclk,
1615 .set_fmt = wm8995_set_dai_fmt,
1616 .hw_params = wm8995_hw_params,
1617 .digital_mute = wm8995_aif_mute,
1618 .set_pll = wm8995_set_fll,
1619 .set_tristate = wm8995_set_tristate,
1620};
1621
1622static struct snd_soc_dai_ops wm8995_aif3_dai_ops = {
1623 .set_tristate = wm8995_set_tristate,
1624};
1625
1626static struct snd_soc_dai_driver wm8995_dai[] = {
1627 {
1628 .name = "wm8995-aif1",
1629 .playback = {
1630 .stream_name = "AIF1 Playback",
1631 .channels_min = 2,
1632 .channels_max = 2,
1633 .rates = SNDRV_PCM_RATE_8000_96000,
1634 .formats = WM8995_FORMATS
1635 },
1636 .capture = {
1637 .stream_name = "AIF1 Capture",
1638 .channels_min = 2,
1639 .channels_max = 2,
1640 .rates = SNDRV_PCM_RATE_8000_48000,
1641 .formats = WM8995_FORMATS
1642 },
1643 .ops = &wm8995_aif1_dai_ops
1644 },
1645 {
1646 .name = "wm8995-aif2",
1647 .playback = {
1648 .stream_name = "AIF2 Playback",
1649 .channels_min = 2,
1650 .channels_max = 2,
1651 .rates = SNDRV_PCM_RATE_8000_96000,
1652 .formats = WM8995_FORMATS
1653 },
1654 .capture = {
1655 .stream_name = "AIF2 Capture",
1656 .channels_min = 2,
1657 .channels_max = 2,
1658 .rates = SNDRV_PCM_RATE_8000_48000,
1659 .formats = WM8995_FORMATS
1660 },
1661 .ops = &wm8995_aif2_dai_ops
1662 },
1663 {
1664 .name = "wm8995-aif3",
1665 .playback = {
1666 .stream_name = "AIF3 Playback",
1667 .channels_min = 2,
1668 .channels_max = 2,
1669 .rates = SNDRV_PCM_RATE_8000_96000,
1670 .formats = WM8995_FORMATS
1671 },
1672 .capture = {
1673 .stream_name = "AIF3 Capture",
1674 .channels_min = 2,
1675 .channels_max = 2,
1676 .rates = SNDRV_PCM_RATE_8000_48000,
1677 .formats = WM8995_FORMATS
1678 },
1679 .ops = &wm8995_aif3_dai_ops
1680 }
1681};
1682
1683static struct snd_soc_codec_driver soc_codec_dev_wm8995 = {
1684 .probe = wm8995_probe,
1685 .remove = wm8995_remove,
1686 .suspend = wm8995_suspend,
1687 .resume = wm8995_resume,
1688 .set_bias_level = wm8995_set_bias_level,
1689 .reg_cache_size = ARRAY_SIZE(wm8995_reg_defs),
1690 .reg_word_size = sizeof(u16),
1691 .reg_cache_default = wm8995_reg_defs,
1692 .volatile_register = wm8995_volatile,
1693 .compress_type = SND_SOC_RBTREE_COMPRESSION
1694};
1695
1696#if defined(CONFIG_SPI_MASTER)
1697static int __devinit wm8995_spi_probe(struct spi_device *spi)
1698{
1699 struct wm8995_priv *wm8995;
1700 int ret;
1701
1702 wm8995 = kzalloc(sizeof *wm8995, GFP_KERNEL);
1703 if (!wm8995)
1704 return -ENOMEM;
1705
1706 wm8995->control_type = SND_SOC_SPI;
1707 spi_set_drvdata(spi, wm8995);
1708
1709 ret = snd_soc_register_codec(&spi->dev,
1710 &soc_codec_dev_wm8995, wm8995_dai,
1711 ARRAY_SIZE(wm8995_dai));
1712 if (ret < 0)
1713 kfree(wm8995);
1714 return ret;
1715}
1716
1717static int __devexit wm8995_spi_remove(struct spi_device *spi)
1718{
1719 snd_soc_unregister_codec(&spi->dev);
1720 kfree(spi_get_drvdata(spi));
1721 return 0;
1722}
1723
1724static struct spi_driver wm8995_spi_driver = {
1725 .driver = {
1726 .name = "wm8995",
1727 .owner = THIS_MODULE,
1728 },
1729 .probe = wm8995_spi_probe,
1730 .remove = __devexit_p(wm8995_spi_remove)
1731};
1732#endif
1733
1734#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
1735static __devinit int wm8995_i2c_probe(struct i2c_client *i2c,
1736 const struct i2c_device_id *id)
1737{
1738 struct wm8995_priv *wm8995;
1739 int ret;
1740
1741 wm8995 = kzalloc(sizeof *wm8995, GFP_KERNEL);
1742 if (!wm8995)
1743 return -ENOMEM;
1744
1745 wm8995->control_type = SND_SOC_I2C;
1746 i2c_set_clientdata(i2c, wm8995);
1747
1748 ret = snd_soc_register_codec(&i2c->dev,
1749 &soc_codec_dev_wm8995, wm8995_dai,
1750 ARRAY_SIZE(wm8995_dai));
1751 if (ret < 0)
1752 kfree(wm8995);
1753 return ret;
1754}
1755
1756static __devexit int wm8995_i2c_remove(struct i2c_client *client)
1757{
1758 snd_soc_unregister_codec(&client->dev);
1759 kfree(i2c_get_clientdata(client));
1760 return 0;
1761}
1762
1763static const struct i2c_device_id wm8995_i2c_id[] = {
1764 {"wm8995", 0},
1765 {}
1766};
1767
1768MODULE_DEVICE_TABLE(i2c, wm8995_i2c_id);
1769
1770static struct i2c_driver wm8995_i2c_driver = {
1771 .driver = {
1772 .name = "wm8995",
1773 .owner = THIS_MODULE,
1774 },
1775 .probe = wm8995_i2c_probe,
1776 .remove = __devexit_p(wm8995_i2c_remove),
1777 .id_table = wm8995_i2c_id
1778};
1779#endif
1780
1781static int __init wm8995_modinit(void)
1782{
1783 int ret = 0;
1784
1785#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
1786 ret = i2c_add_driver(&wm8995_i2c_driver);
1787 if (ret) {
1788 printk(KERN_ERR "Failed to register wm8995 I2C driver: %d\n",
1789 ret);
1790 }
1791#endif
1792#if defined(CONFIG_SPI_MASTER)
1793 ret = spi_register_driver(&wm8995_spi_driver);
1794 if (ret) {
1795 printk(KERN_ERR "Failed to register wm8995 SPI driver: %d\n",
1796 ret);
1797 }
1798#endif
1799 return ret;
1800}
1801
1802module_init(wm8995_modinit);
1803
1804static void __exit wm8995_exit(void)
1805{
1806#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
1807 i2c_del_driver(&wm8995_i2c_driver);
1808#endif
1809#if defined(CONFIG_SPI_MASTER)
1810 spi_unregister_driver(&wm8995_spi_driver);
1811#endif
1812}
1813
1814module_exit(wm8995_exit);
1815
1816MODULE_DESCRIPTION("ASoC WM8995 driver");
1817MODULE_AUTHOR("Dimitris Papastamos <dp@opensource.wolfsonmicro.com>");
1818MODULE_LICENSE("GPL");
diff --git a/sound/soc/codecs/wm8995.h b/sound/soc/codecs/wm8995.h
new file mode 100644
index 000000000000..5642121c4977
--- /dev/null
+++ b/sound/soc/codecs/wm8995.h
@@ -0,0 +1,4269 @@
1/*
2 * wm8995.h -- WM8995 ALSA SoC Audio driver
3 *
4 * Copyright 2010 Wolfson Microelectronics plc
5 *
6 * Author: Dimitris Papastamos <dp@opensource.wolfsonmicro.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#ifndef _WM8995_H
14#define _WM8995_H
15
16#include <asm/types.h>
17
18/*
19 * Register values.
20 */
21#define WM8995_SOFTWARE_RESET 0x00
22#define WM8995_POWER_MANAGEMENT_1 0x01
23#define WM8995_POWER_MANAGEMENT_2 0x02
24#define WM8995_POWER_MANAGEMENT_3 0x03
25#define WM8995_POWER_MANAGEMENT_4 0x04
26#define WM8995_POWER_MANAGEMENT_5 0x05
27#define WM8995_LEFT_LINE_INPUT_1_VOLUME 0x10
28#define WM8995_RIGHT_LINE_INPUT_1_VOLUME 0x11
29#define WM8995_LEFT_LINE_INPUT_CONTROL 0x12
30#define WM8995_DAC1_LEFT_VOLUME 0x18
31#define WM8995_DAC1_RIGHT_VOLUME 0x19
32#define WM8995_DAC2_LEFT_VOLUME 0x1A
33#define WM8995_DAC2_RIGHT_VOLUME 0x1B
34#define WM8995_OUTPUT_VOLUME_ZC_1 0x1C
35#define WM8995_MICBIAS_1 0x20
36#define WM8995_MICBIAS_2 0x21
37#define WM8995_LDO_1 0x28
38#define WM8995_LDO_2 0x29
39#define WM8995_ACCESSORY_DETECT_MODE1 0x30
40#define WM8995_ACCESSORY_DETECT_MODE2 0x31
41#define WM8995_HEADPHONE_DETECT1 0x34
42#define WM8995_HEADPHONE_DETECT2 0x35
43#define WM8995_MIC_DETECT_1 0x38
44#define WM8995_MIC_DETECT_2 0x39
45#define WM8995_CHARGE_PUMP_1 0x40
46#define WM8995_CLASS_W_1 0x45
47#define WM8995_DC_SERVO_1 0x50
48#define WM8995_DC_SERVO_2 0x51
49#define WM8995_DC_SERVO_3 0x52
50#define WM8995_DC_SERVO_5 0x54
51#define WM8995_DC_SERVO_6 0x55
52#define WM8995_DC_SERVO_7 0x56
53#define WM8995_DC_SERVO_READBACK_0 0x57
54#define WM8995_ANALOGUE_HP_1 0x60
55#define WM8995_ANALOGUE_HP_2 0x61
56#define WM8995_CHIP_REVISION 0x100
57#define WM8995_CONTROL_INTERFACE_1 0x101
58#define WM8995_CONTROL_INTERFACE_2 0x102
59#define WM8995_WRITE_SEQUENCER_CTRL_1 0x110
60#define WM8995_WRITE_SEQUENCER_CTRL_2 0x111
61#define WM8995_AIF1_CLOCKING_1 0x200
62#define WM8995_AIF1_CLOCKING_2 0x201
63#define WM8995_AIF2_CLOCKING_1 0x204
64#define WM8995_AIF2_CLOCKING_2 0x205
65#define WM8995_CLOCKING_1 0x208
66#define WM8995_CLOCKING_2 0x209
67#define WM8995_AIF1_RATE 0x210
68#define WM8995_AIF2_RATE 0x211
69#define WM8995_RATE_STATUS 0x212
70#define WM8995_FLL1_CONTROL_1 0x220
71#define WM8995_FLL1_CONTROL_2 0x221
72#define WM8995_FLL1_CONTROL_3 0x222
73#define WM8995_FLL1_CONTROL_4 0x223
74#define WM8995_FLL1_CONTROL_5 0x224
75#define WM8995_FLL2_CONTROL_1 0x240
76#define WM8995_FLL2_CONTROL_2 0x241
77#define WM8995_FLL2_CONTROL_3 0x242
78#define WM8995_FLL2_CONTROL_4 0x243
79#define WM8995_FLL2_CONTROL_5 0x244
80#define WM8995_AIF1_CONTROL_1 0x300
81#define WM8995_AIF1_CONTROL_2 0x301
82#define WM8995_AIF1_MASTER_SLAVE 0x302
83#define WM8995_AIF1_BCLK 0x303
84#define WM8995_AIF1ADC_LRCLK 0x304
85#define WM8995_AIF1DAC_LRCLK 0x305
86#define WM8995_AIF1DAC_DATA 0x306
87#define WM8995_AIF1ADC_DATA 0x307
88#define WM8995_AIF2_CONTROL_1 0x310
89#define WM8995_AIF2_CONTROL_2 0x311
90#define WM8995_AIF2_MASTER_SLAVE 0x312
91#define WM8995_AIF2_BCLK 0x313
92#define WM8995_AIF2ADC_LRCLK 0x314
93#define WM8995_AIF2DAC_LRCLK 0x315
94#define WM8995_AIF2DAC_DATA 0x316
95#define WM8995_AIF2ADC_DATA 0x317
96#define WM8995_AIF1_ADC1_LEFT_VOLUME 0x400
97#define WM8995_AIF1_ADC1_RIGHT_VOLUME 0x401
98#define WM8995_AIF1_DAC1_LEFT_VOLUME 0x402
99#define WM8995_AIF1_DAC1_RIGHT_VOLUME 0x403
100#define WM8995_AIF1_ADC2_LEFT_VOLUME 0x404
101#define WM8995_AIF1_ADC2_RIGHT_VOLUME 0x405
102#define WM8995_AIF1_DAC2_LEFT_VOLUME 0x406
103#define WM8995_AIF1_DAC2_RIGHT_VOLUME 0x407
104#define WM8995_AIF1_ADC1_FILTERS 0x410
105#define WM8995_AIF1_ADC2_FILTERS 0x411
106#define WM8995_AIF1_DAC1_FILTERS_1 0x420
107#define WM8995_AIF1_DAC1_FILTERS_2 0x421
108#define WM8995_AIF1_DAC2_FILTERS_1 0x422
109#define WM8995_AIF1_DAC2_FILTERS_2 0x423
110#define WM8995_AIF1_DRC1_1 0x440
111#define WM8995_AIF1_DRC1_2 0x441
112#define WM8995_AIF1_DRC1_3 0x442
113#define WM8995_AIF1_DRC1_4 0x443
114#define WM8995_AIF1_DRC1_5 0x444
115#define WM8995_AIF1_DRC2_1 0x450
116#define WM8995_AIF1_DRC2_2 0x451
117#define WM8995_AIF1_DRC2_3 0x452
118#define WM8995_AIF1_DRC2_4 0x453
119#define WM8995_AIF1_DRC2_5 0x454
120#define WM8995_AIF1_DAC1_EQ_GAINS_1 0x480
121#define WM8995_AIF1_DAC1_EQ_GAINS_2 0x481
122#define WM8995_AIF1_DAC1_EQ_BAND_1_A 0x482
123#define WM8995_AIF1_DAC1_EQ_BAND_1_B 0x483
124#define WM8995_AIF1_DAC1_EQ_BAND_1_PG 0x484
125#define WM8995_AIF1_DAC1_EQ_BAND_2_A 0x485
126#define WM8995_AIF1_DAC1_EQ_BAND_2_B 0x486
127#define WM8995_AIF1_DAC1_EQ_BAND_2_C 0x487
128#define WM8995_AIF1_DAC1_EQ_BAND_2_PG 0x488
129#define WM8995_AIF1_DAC1_EQ_BAND_3_A 0x489
130#define WM8995_AIF1_DAC1_EQ_BAND_3_B 0x48A
131#define WM8995_AIF1_DAC1_EQ_BAND_3_C 0x48B
132#define WM8995_AIF1_DAC1_EQ_BAND_3_PG 0x48C
133#define WM8995_AIF1_DAC1_EQ_BAND_4_A 0x48D
134#define WM8995_AIF1_DAC1_EQ_BAND_4_B 0x48E
135#define WM8995_AIF1_DAC1_EQ_BAND_4_C 0x48F
136#define WM8995_AIF1_DAC1_EQ_BAND_4_PG 0x490
137#define WM8995_AIF1_DAC1_EQ_BAND_5_A 0x491
138#define WM8995_AIF1_DAC1_EQ_BAND_5_B 0x492
139#define WM8995_AIF1_DAC1_EQ_BAND_5_PG 0x493
140#define WM8995_AIF1_DAC2_EQ_GAINS_1 0x4A0
141#define WM8995_AIF1_DAC2_EQ_GAINS_2 0x4A1
142#define WM8995_AIF1_DAC2_EQ_BAND_1_A 0x4A2
143#define WM8995_AIF1_DAC2_EQ_BAND_1_B 0x4A3
144#define WM8995_AIF1_DAC2_EQ_BAND_1_PG 0x4A4
145#define WM8995_AIF1_DAC2_EQ_BAND_2_A 0x4A5
146#define WM8995_AIF1_DAC2_EQ_BAND_2_B 0x4A6
147#define WM8995_AIF1_DAC2_EQ_BAND_2_C 0x4A7
148#define WM8995_AIF1_DAC2_EQ_BAND_2_PG 0x4A8
149#define WM8995_AIF1_DAC2_EQ_BAND_3_A 0x4A9
150#define WM8995_AIF1_DAC2_EQ_BAND_3_B 0x4AA
151#define WM8995_AIF1_DAC2_EQ_BAND_3_C 0x4AB
152#define WM8995_AIF1_DAC2_EQ_BAND_3_PG 0x4AC
153#define WM8995_AIF1_DAC2_EQ_BAND_4_A 0x4AD
154#define WM8995_AIF1_DAC2_EQ_BAND_4_B 0x4AE
155#define WM8995_AIF1_DAC2_EQ_BAND_4_C 0x4AF
156#define WM8995_AIF1_DAC2_EQ_BAND_4_PG 0x4B0
157#define WM8995_AIF1_DAC2_EQ_BAND_5_A 0x4B1
158#define WM8995_AIF1_DAC2_EQ_BAND_5_B 0x4B2
159#define WM8995_AIF1_DAC2_EQ_BAND_5_PG 0x4B3
160#define WM8995_AIF2_ADC_LEFT_VOLUME 0x500
161#define WM8995_AIF2_ADC_RIGHT_VOLUME 0x501
162#define WM8995_AIF2_DAC_LEFT_VOLUME 0x502
163#define WM8995_AIF2_DAC_RIGHT_VOLUME 0x503
164#define WM8995_AIF2_ADC_FILTERS 0x510
165#define WM8995_AIF2_DAC_FILTERS_1 0x520
166#define WM8995_AIF2_DAC_FILTERS_2 0x521
167#define WM8995_AIF2_DRC_1 0x540
168#define WM8995_AIF2_DRC_2 0x541
169#define WM8995_AIF2_DRC_3 0x542
170#define WM8995_AIF2_DRC_4 0x543
171#define WM8995_AIF2_DRC_5 0x544
172#define WM8995_AIF2_EQ_GAINS_1 0x580
173#define WM8995_AIF2_EQ_GAINS_2 0x581
174#define WM8995_AIF2_EQ_BAND_1_A 0x582
175#define WM8995_AIF2_EQ_BAND_1_B 0x583
176#define WM8995_AIF2_EQ_BAND_1_PG 0x584
177#define WM8995_AIF2_EQ_BAND_2_A 0x585
178#define WM8995_AIF2_EQ_BAND_2_B 0x586
179#define WM8995_AIF2_EQ_BAND_2_C 0x587
180#define WM8995_AIF2_EQ_BAND_2_PG 0x588
181#define WM8995_AIF2_EQ_BAND_3_A 0x589
182#define WM8995_AIF2_EQ_BAND_3_B 0x58A
183#define WM8995_AIF2_EQ_BAND_3_C 0x58B
184#define WM8995_AIF2_EQ_BAND_3_PG 0x58C
185#define WM8995_AIF2_EQ_BAND_4_A 0x58D
186#define WM8995_AIF2_EQ_BAND_4_B 0x58E
187#define WM8995_AIF2_EQ_BAND_4_C 0x58F
188#define WM8995_AIF2_EQ_BAND_4_PG 0x590
189#define WM8995_AIF2_EQ_BAND_5_A 0x591
190#define WM8995_AIF2_EQ_BAND_5_B 0x592
191#define WM8995_AIF2_EQ_BAND_5_PG 0x593
192#define WM8995_DAC1_MIXER_VOLUMES 0x600
193#define WM8995_DAC1_LEFT_MIXER_ROUTING 0x601
194#define WM8995_DAC1_RIGHT_MIXER_ROUTING 0x602
195#define WM8995_DAC2_MIXER_VOLUMES 0x603
196#define WM8995_DAC2_LEFT_MIXER_ROUTING 0x604
197#define WM8995_DAC2_RIGHT_MIXER_ROUTING 0x605
198#define WM8995_AIF1_ADC1_LEFT_MIXER_ROUTING 0x606
199#define WM8995_AIF1_ADC1_RIGHT_MIXER_ROUTING 0x607
200#define WM8995_AIF1_ADC2_LEFT_MIXER_ROUTING 0x608
201#define WM8995_AIF1_ADC2_RIGHT_MIXER_ROUTING 0x609
202#define WM8995_DAC_SOFTMUTE 0x610
203#define WM8995_OVERSAMPLING 0x620
204#define WM8995_SIDETONE 0x621
205#define WM8995_GPIO_1 0x700
206#define WM8995_GPIO_2 0x701
207#define WM8995_GPIO_3 0x702
208#define WM8995_GPIO_4 0x703
209#define WM8995_GPIO_5 0x704
210#define WM8995_GPIO_6 0x705
211#define WM8995_GPIO_7 0x706
212#define WM8995_GPIO_8 0x707
213#define WM8995_GPIO_9 0x708
214#define WM8995_GPIO_10 0x709
215#define WM8995_GPIO_11 0x70A
216#define WM8995_GPIO_12 0x70B
217#define WM8995_GPIO_13 0x70C
218#define WM8995_GPIO_14 0x70D
219#define WM8995_PULL_CONTROL_1 0x720
220#define WM8995_PULL_CONTROL_2 0x721
221#define WM8995_INTERRUPT_STATUS_1 0x730
222#define WM8995_INTERRUPT_STATUS_2 0x731
223#define WM8995_INTERRUPT_RAW_STATUS_2 0x732
224#define WM8995_INTERRUPT_STATUS_1_MASK 0x738
225#define WM8995_INTERRUPT_STATUS_2_MASK 0x739
226#define WM8995_INTERRUPT_CONTROL 0x740
227#define WM8995_LEFT_PDM_SPEAKER_1 0x800
228#define WM8995_RIGHT_PDM_SPEAKER_1 0x801
229#define WM8995_PDM_SPEAKER_1_MUTE_SEQUENCE 0x802
230#define WM8995_LEFT_PDM_SPEAKER_2 0x808
231#define WM8995_RIGHT_PDM_SPEAKER_2 0x809
232#define WM8995_PDM_SPEAKER_2_MUTE_SEQUENCE 0x80A
233#define WM8995_WRITE_SEQUENCER_0 0x3000
234#define WM8995_WRITE_SEQUENCER_1 0x3001
235#define WM8995_WRITE_SEQUENCER_2 0x3002
236#define WM8995_WRITE_SEQUENCER_3 0x3003
237#define WM8995_WRITE_SEQUENCER_4 0x3004
238#define WM8995_WRITE_SEQUENCER_5 0x3005
239#define WM8995_WRITE_SEQUENCER_6 0x3006
240#define WM8995_WRITE_SEQUENCER_7 0x3007
241#define WM8995_WRITE_SEQUENCER_8 0x3008
242#define WM8995_WRITE_SEQUENCER_9 0x3009
243#define WM8995_WRITE_SEQUENCER_10 0x300A
244#define WM8995_WRITE_SEQUENCER_11 0x300B
245#define WM8995_WRITE_SEQUENCER_12 0x300C
246#define WM8995_WRITE_SEQUENCER_13 0x300D
247#define WM8995_WRITE_SEQUENCER_14 0x300E
248#define WM8995_WRITE_SEQUENCER_15 0x300F
249#define WM8995_WRITE_SEQUENCER_16 0x3010
250#define WM8995_WRITE_SEQUENCER_17 0x3011
251#define WM8995_WRITE_SEQUENCER_18 0x3012
252#define WM8995_WRITE_SEQUENCER_19 0x3013
253#define WM8995_WRITE_SEQUENCER_20 0x3014
254#define WM8995_WRITE_SEQUENCER_21 0x3015
255#define WM8995_WRITE_SEQUENCER_22 0x3016
256#define WM8995_WRITE_SEQUENCER_23 0x3017
257#define WM8995_WRITE_SEQUENCER_24 0x3018
258#define WM8995_WRITE_SEQUENCER_25 0x3019
259#define WM8995_WRITE_SEQUENCER_26 0x301A
260#define WM8995_WRITE_SEQUENCER_27 0x301B
261#define WM8995_WRITE_SEQUENCER_28 0x301C
262#define WM8995_WRITE_SEQUENCER_29 0x301D
263#define WM8995_WRITE_SEQUENCER_30 0x301E
264#define WM8995_WRITE_SEQUENCER_31 0x301F
265#define WM8995_WRITE_SEQUENCER_32 0x3020
266#define WM8995_WRITE_SEQUENCER_33 0x3021
267#define WM8995_WRITE_SEQUENCER_34 0x3022
268#define WM8995_WRITE_SEQUENCER_35 0x3023
269#define WM8995_WRITE_SEQUENCER_36 0x3024
270#define WM8995_WRITE_SEQUENCER_37 0x3025
271#define WM8995_WRITE_SEQUENCER_38 0x3026
272#define WM8995_WRITE_SEQUENCER_39 0x3027
273#define WM8995_WRITE_SEQUENCER_40 0x3028
274#define WM8995_WRITE_SEQUENCER_41 0x3029
275#define WM8995_WRITE_SEQUENCER_42 0x302A
276#define WM8995_WRITE_SEQUENCER_43 0x302B
277#define WM8995_WRITE_SEQUENCER_44 0x302C
278#define WM8995_WRITE_SEQUENCER_45 0x302D
279#define WM8995_WRITE_SEQUENCER_46 0x302E
280#define WM8995_WRITE_SEQUENCER_47 0x302F
281#define WM8995_WRITE_SEQUENCER_48 0x3030
282#define WM8995_WRITE_SEQUENCER_49 0x3031
283#define WM8995_WRITE_SEQUENCER_50 0x3032
284#define WM8995_WRITE_SEQUENCER_51 0x3033
285#define WM8995_WRITE_SEQUENCER_52 0x3034
286#define WM8995_WRITE_SEQUENCER_53 0x3035
287#define WM8995_WRITE_SEQUENCER_54 0x3036
288#define WM8995_WRITE_SEQUENCER_55 0x3037
289#define WM8995_WRITE_SEQUENCER_56 0x3038
290#define WM8995_WRITE_SEQUENCER_57 0x3039
291#define WM8995_WRITE_SEQUENCER_58 0x303A
292#define WM8995_WRITE_SEQUENCER_59 0x303B
293#define WM8995_WRITE_SEQUENCER_60 0x303C
294#define WM8995_WRITE_SEQUENCER_61 0x303D
295#define WM8995_WRITE_SEQUENCER_62 0x303E
296#define WM8995_WRITE_SEQUENCER_63 0x303F
297#define WM8995_WRITE_SEQUENCER_64 0x3040
298#define WM8995_WRITE_SEQUENCER_65 0x3041
299#define WM8995_WRITE_SEQUENCER_66 0x3042
300#define WM8995_WRITE_SEQUENCER_67 0x3043
301#define WM8995_WRITE_SEQUENCER_68 0x3044
302#define WM8995_WRITE_SEQUENCER_69 0x3045
303#define WM8995_WRITE_SEQUENCER_70 0x3046
304#define WM8995_WRITE_SEQUENCER_71 0x3047
305#define WM8995_WRITE_SEQUENCER_72 0x3048
306#define WM8995_WRITE_SEQUENCER_73 0x3049
307#define WM8995_WRITE_SEQUENCER_74 0x304A
308#define WM8995_WRITE_SEQUENCER_75 0x304B
309#define WM8995_WRITE_SEQUENCER_76 0x304C
310#define WM8995_WRITE_SEQUENCER_77 0x304D
311#define WM8995_WRITE_SEQUENCER_78 0x304E
312#define WM8995_WRITE_SEQUENCER_79 0x304F
313#define WM8995_WRITE_SEQUENCER_80 0x3050
314#define WM8995_WRITE_SEQUENCER_81 0x3051
315#define WM8995_WRITE_SEQUENCER_82 0x3052
316#define WM8995_WRITE_SEQUENCER_83 0x3053
317#define WM8995_WRITE_SEQUENCER_84 0x3054
318#define WM8995_WRITE_SEQUENCER_85 0x3055
319#define WM8995_WRITE_SEQUENCER_86 0x3056
320#define WM8995_WRITE_SEQUENCER_87 0x3057
321#define WM8995_WRITE_SEQUENCER_88 0x3058
322#define WM8995_WRITE_SEQUENCER_89 0x3059
323#define WM8995_WRITE_SEQUENCER_90 0x305A
324#define WM8995_WRITE_SEQUENCER_91 0x305B
325#define WM8995_WRITE_SEQUENCER_92 0x305C
326#define WM8995_WRITE_SEQUENCER_93 0x305D
327#define WM8995_WRITE_SEQUENCER_94 0x305E
328#define WM8995_WRITE_SEQUENCER_95 0x305F
329#define WM8995_WRITE_SEQUENCER_96 0x3060
330#define WM8995_WRITE_SEQUENCER_97 0x3061
331#define WM8995_WRITE_SEQUENCER_98 0x3062
332#define WM8995_WRITE_SEQUENCER_99 0x3063
333#define WM8995_WRITE_SEQUENCER_100 0x3064
334#define WM8995_WRITE_SEQUENCER_101 0x3065
335#define WM8995_WRITE_SEQUENCER_102 0x3066
336#define WM8995_WRITE_SEQUENCER_103 0x3067
337#define WM8995_WRITE_SEQUENCER_104 0x3068
338#define WM8995_WRITE_SEQUENCER_105 0x3069
339#define WM8995_WRITE_SEQUENCER_106 0x306A
340#define WM8995_WRITE_SEQUENCER_107 0x306B
341#define WM8995_WRITE_SEQUENCER_108 0x306C
342#define WM8995_WRITE_SEQUENCER_109 0x306D
343#define WM8995_WRITE_SEQUENCER_110 0x306E
344#define WM8995_WRITE_SEQUENCER_111 0x306F
345#define WM8995_WRITE_SEQUENCER_112 0x3070
346#define WM8995_WRITE_SEQUENCER_113 0x3071
347#define WM8995_WRITE_SEQUENCER_114 0x3072
348#define WM8995_WRITE_SEQUENCER_115 0x3073
349#define WM8995_WRITE_SEQUENCER_116 0x3074
350#define WM8995_WRITE_SEQUENCER_117 0x3075
351#define WM8995_WRITE_SEQUENCER_118 0x3076
352#define WM8995_WRITE_SEQUENCER_119 0x3077
353#define WM8995_WRITE_SEQUENCER_120 0x3078
354#define WM8995_WRITE_SEQUENCER_121 0x3079
355#define WM8995_WRITE_SEQUENCER_122 0x307A
356#define WM8995_WRITE_SEQUENCER_123 0x307B
357#define WM8995_WRITE_SEQUENCER_124 0x307C
358#define WM8995_WRITE_SEQUENCER_125 0x307D
359#define WM8995_WRITE_SEQUENCER_126 0x307E
360#define WM8995_WRITE_SEQUENCER_127 0x307F
361#define WM8995_WRITE_SEQUENCER_128 0x3080
362#define WM8995_WRITE_SEQUENCER_129 0x3081
363#define WM8995_WRITE_SEQUENCER_130 0x3082
364#define WM8995_WRITE_SEQUENCER_131 0x3083
365#define WM8995_WRITE_SEQUENCER_132 0x3084
366#define WM8995_WRITE_SEQUENCER_133 0x3085
367#define WM8995_WRITE_SEQUENCER_134 0x3086
368#define WM8995_WRITE_SEQUENCER_135 0x3087
369#define WM8995_WRITE_SEQUENCER_136 0x3088
370#define WM8995_WRITE_SEQUENCER_137 0x3089
371#define WM8995_WRITE_SEQUENCER_138 0x308A
372#define WM8995_WRITE_SEQUENCER_139 0x308B
373#define WM8995_WRITE_SEQUENCER_140 0x308C
374#define WM8995_WRITE_SEQUENCER_141 0x308D
375#define WM8995_WRITE_SEQUENCER_142 0x308E
376#define WM8995_WRITE_SEQUENCER_143 0x308F
377#define WM8995_WRITE_SEQUENCER_144 0x3090
378#define WM8995_WRITE_SEQUENCER_145 0x3091
379#define WM8995_WRITE_SEQUENCER_146 0x3092
380#define WM8995_WRITE_SEQUENCER_147 0x3093
381#define WM8995_WRITE_SEQUENCER_148 0x3094
382#define WM8995_WRITE_SEQUENCER_149 0x3095
383#define WM8995_WRITE_SEQUENCER_150 0x3096
384#define WM8995_WRITE_SEQUENCER_151 0x3097
385#define WM8995_WRITE_SEQUENCER_152 0x3098
386#define WM8995_WRITE_SEQUENCER_153 0x3099
387#define WM8995_WRITE_SEQUENCER_154 0x309A
388#define WM8995_WRITE_SEQUENCER_155 0x309B
389#define WM8995_WRITE_SEQUENCER_156 0x309C
390#define WM8995_WRITE_SEQUENCER_157 0x309D
391#define WM8995_WRITE_SEQUENCER_158 0x309E
392#define WM8995_WRITE_SEQUENCER_159 0x309F
393#define WM8995_WRITE_SEQUENCER_160 0x30A0
394#define WM8995_WRITE_SEQUENCER_161 0x30A1
395#define WM8995_WRITE_SEQUENCER_162 0x30A2
396#define WM8995_WRITE_SEQUENCER_163 0x30A3
397#define WM8995_WRITE_SEQUENCER_164 0x30A4
398#define WM8995_WRITE_SEQUENCER_165 0x30A5
399#define WM8995_WRITE_SEQUENCER_166 0x30A6
400#define WM8995_WRITE_SEQUENCER_167 0x30A7
401#define WM8995_WRITE_SEQUENCER_168 0x30A8
402#define WM8995_WRITE_SEQUENCER_169 0x30A9
403#define WM8995_WRITE_SEQUENCER_170 0x30AA
404#define WM8995_WRITE_SEQUENCER_171 0x30AB
405#define WM8995_WRITE_SEQUENCER_172 0x30AC
406#define WM8995_WRITE_SEQUENCER_173 0x30AD
407#define WM8995_WRITE_SEQUENCER_174 0x30AE
408#define WM8995_WRITE_SEQUENCER_175 0x30AF
409#define WM8995_WRITE_SEQUENCER_176 0x30B0
410#define WM8995_WRITE_SEQUENCER_177 0x30B1
411#define WM8995_WRITE_SEQUENCER_178 0x30B2
412#define WM8995_WRITE_SEQUENCER_179 0x30B3
413#define WM8995_WRITE_SEQUENCER_180 0x30B4
414#define WM8995_WRITE_SEQUENCER_181 0x30B5
415#define WM8995_WRITE_SEQUENCER_182 0x30B6
416#define WM8995_WRITE_SEQUENCER_183 0x30B7
417#define WM8995_WRITE_SEQUENCER_184 0x30B8
418#define WM8995_WRITE_SEQUENCER_185 0x30B9
419#define WM8995_WRITE_SEQUENCER_186 0x30BA
420#define WM8995_WRITE_SEQUENCER_187 0x30BB
421#define WM8995_WRITE_SEQUENCER_188 0x30BC
422#define WM8995_WRITE_SEQUENCER_189 0x30BD
423#define WM8995_WRITE_SEQUENCER_190 0x30BE
424#define WM8995_WRITE_SEQUENCER_191 0x30BF
425#define WM8995_WRITE_SEQUENCER_192 0x30C0
426#define WM8995_WRITE_SEQUENCER_193 0x30C1
427#define WM8995_WRITE_SEQUENCER_194 0x30C2
428#define WM8995_WRITE_SEQUENCER_195 0x30C3
429#define WM8995_WRITE_SEQUENCER_196 0x30C4
430#define WM8995_WRITE_SEQUENCER_197 0x30C5
431#define WM8995_WRITE_SEQUENCER_198 0x30C6
432#define WM8995_WRITE_SEQUENCER_199 0x30C7
433#define WM8995_WRITE_SEQUENCER_200 0x30C8
434#define WM8995_WRITE_SEQUENCER_201 0x30C9
435#define WM8995_WRITE_SEQUENCER_202 0x30CA
436#define WM8995_WRITE_SEQUENCER_203 0x30CB
437#define WM8995_WRITE_SEQUENCER_204 0x30CC
438#define WM8995_WRITE_SEQUENCER_205 0x30CD
439#define WM8995_WRITE_SEQUENCER_206 0x30CE
440#define WM8995_WRITE_SEQUENCER_207 0x30CF
441#define WM8995_WRITE_SEQUENCER_208 0x30D0
442#define WM8995_WRITE_SEQUENCER_209 0x30D1
443#define WM8995_WRITE_SEQUENCER_210 0x30D2
444#define WM8995_WRITE_SEQUENCER_211 0x30D3
445#define WM8995_WRITE_SEQUENCER_212 0x30D4
446#define WM8995_WRITE_SEQUENCER_213 0x30D5
447#define WM8995_WRITE_SEQUENCER_214 0x30D6
448#define WM8995_WRITE_SEQUENCER_215 0x30D7
449#define WM8995_WRITE_SEQUENCER_216 0x30D8
450#define WM8995_WRITE_SEQUENCER_217 0x30D9
451#define WM8995_WRITE_SEQUENCER_218 0x30DA
452#define WM8995_WRITE_SEQUENCER_219 0x30DB
453#define WM8995_WRITE_SEQUENCER_220 0x30DC
454#define WM8995_WRITE_SEQUENCER_221 0x30DD
455#define WM8995_WRITE_SEQUENCER_222 0x30DE
456#define WM8995_WRITE_SEQUENCER_223 0x30DF
457#define WM8995_WRITE_SEQUENCER_224 0x30E0
458#define WM8995_WRITE_SEQUENCER_225 0x30E1
459#define WM8995_WRITE_SEQUENCER_226 0x30E2
460#define WM8995_WRITE_SEQUENCER_227 0x30E3
461#define WM8995_WRITE_SEQUENCER_228 0x30E4
462#define WM8995_WRITE_SEQUENCER_229 0x30E5
463#define WM8995_WRITE_SEQUENCER_230 0x30E6
464#define WM8995_WRITE_SEQUENCER_231 0x30E7
465#define WM8995_WRITE_SEQUENCER_232 0x30E8
466#define WM8995_WRITE_SEQUENCER_233 0x30E9
467#define WM8995_WRITE_SEQUENCER_234 0x30EA
468#define WM8995_WRITE_SEQUENCER_235 0x30EB
469#define WM8995_WRITE_SEQUENCER_236 0x30EC
470#define WM8995_WRITE_SEQUENCER_237 0x30ED
471#define WM8995_WRITE_SEQUENCER_238 0x30EE
472#define WM8995_WRITE_SEQUENCER_239 0x30EF
473#define WM8995_WRITE_SEQUENCER_240 0x30F0
474#define WM8995_WRITE_SEQUENCER_241 0x30F1
475#define WM8995_WRITE_SEQUENCER_242 0x30F2
476#define WM8995_WRITE_SEQUENCER_243 0x30F3
477#define WM8995_WRITE_SEQUENCER_244 0x30F4
478#define WM8995_WRITE_SEQUENCER_245 0x30F5
479#define WM8995_WRITE_SEQUENCER_246 0x30F6
480#define WM8995_WRITE_SEQUENCER_247 0x30F7
481#define WM8995_WRITE_SEQUENCER_248 0x30F8
482#define WM8995_WRITE_SEQUENCER_249 0x30F9
483#define WM8995_WRITE_SEQUENCER_250 0x30FA
484#define WM8995_WRITE_SEQUENCER_251 0x30FB
485#define WM8995_WRITE_SEQUENCER_252 0x30FC
486#define WM8995_WRITE_SEQUENCER_253 0x30FD
487#define WM8995_WRITE_SEQUENCER_254 0x30FE
488#define WM8995_WRITE_SEQUENCER_255 0x30FF
489#define WM8995_WRITE_SEQUENCER_256 0x3100
490#define WM8995_WRITE_SEQUENCER_257 0x3101
491#define WM8995_WRITE_SEQUENCER_258 0x3102
492#define WM8995_WRITE_SEQUENCER_259 0x3103
493#define WM8995_WRITE_SEQUENCER_260 0x3104
494#define WM8995_WRITE_SEQUENCER_261 0x3105
495#define WM8995_WRITE_SEQUENCER_262 0x3106
496#define WM8995_WRITE_SEQUENCER_263 0x3107
497#define WM8995_WRITE_SEQUENCER_264 0x3108
498#define WM8995_WRITE_SEQUENCER_265 0x3109
499#define WM8995_WRITE_SEQUENCER_266 0x310A
500#define WM8995_WRITE_SEQUENCER_267 0x310B
501#define WM8995_WRITE_SEQUENCER_268 0x310C
502#define WM8995_WRITE_SEQUENCER_269 0x310D
503#define WM8995_WRITE_SEQUENCER_270 0x310E
504#define WM8995_WRITE_SEQUENCER_271 0x310F
505#define WM8995_WRITE_SEQUENCER_272 0x3110
506#define WM8995_WRITE_SEQUENCER_273 0x3111
507#define WM8995_WRITE_SEQUENCER_274 0x3112
508#define WM8995_WRITE_SEQUENCER_275 0x3113
509#define WM8995_WRITE_SEQUENCER_276 0x3114
510#define WM8995_WRITE_SEQUENCER_277 0x3115
511#define WM8995_WRITE_SEQUENCER_278 0x3116
512#define WM8995_WRITE_SEQUENCER_279 0x3117
513#define WM8995_WRITE_SEQUENCER_280 0x3118
514#define WM8995_WRITE_SEQUENCER_281 0x3119
515#define WM8995_WRITE_SEQUENCER_282 0x311A
516#define WM8995_WRITE_SEQUENCER_283 0x311B
517#define WM8995_WRITE_SEQUENCER_284 0x311C
518#define WM8995_WRITE_SEQUENCER_285 0x311D
519#define WM8995_WRITE_SEQUENCER_286 0x311E
520#define WM8995_WRITE_SEQUENCER_287 0x311F
521#define WM8995_WRITE_SEQUENCER_288 0x3120
522#define WM8995_WRITE_SEQUENCER_289 0x3121
523#define WM8995_WRITE_SEQUENCER_290 0x3122
524#define WM8995_WRITE_SEQUENCER_291 0x3123
525#define WM8995_WRITE_SEQUENCER_292 0x3124
526#define WM8995_WRITE_SEQUENCER_293 0x3125
527#define WM8995_WRITE_SEQUENCER_294 0x3126
528#define WM8995_WRITE_SEQUENCER_295 0x3127
529#define WM8995_WRITE_SEQUENCER_296 0x3128
530#define WM8995_WRITE_SEQUENCER_297 0x3129
531#define WM8995_WRITE_SEQUENCER_298 0x312A
532#define WM8995_WRITE_SEQUENCER_299 0x312B
533#define WM8995_WRITE_SEQUENCER_300 0x312C
534#define WM8995_WRITE_SEQUENCER_301 0x312D
535#define WM8995_WRITE_SEQUENCER_302 0x312E
536#define WM8995_WRITE_SEQUENCER_303 0x312F
537#define WM8995_WRITE_SEQUENCER_304 0x3130
538#define WM8995_WRITE_SEQUENCER_305 0x3131
539#define WM8995_WRITE_SEQUENCER_306 0x3132
540#define WM8995_WRITE_SEQUENCER_307 0x3133
541#define WM8995_WRITE_SEQUENCER_308 0x3134
542#define WM8995_WRITE_SEQUENCER_309 0x3135
543#define WM8995_WRITE_SEQUENCER_310 0x3136
544#define WM8995_WRITE_SEQUENCER_311 0x3137
545#define WM8995_WRITE_SEQUENCER_312 0x3138
546#define WM8995_WRITE_SEQUENCER_313 0x3139
547#define WM8995_WRITE_SEQUENCER_314 0x313A
548#define WM8995_WRITE_SEQUENCER_315 0x313B
549#define WM8995_WRITE_SEQUENCER_316 0x313C
550#define WM8995_WRITE_SEQUENCER_317 0x313D
551#define WM8995_WRITE_SEQUENCER_318 0x313E
552#define WM8995_WRITE_SEQUENCER_319 0x313F
553#define WM8995_WRITE_SEQUENCER_320 0x3140
554#define WM8995_WRITE_SEQUENCER_321 0x3141
555#define WM8995_WRITE_SEQUENCER_322 0x3142
556#define WM8995_WRITE_SEQUENCER_323 0x3143
557#define WM8995_WRITE_SEQUENCER_324 0x3144
558#define WM8995_WRITE_SEQUENCER_325 0x3145
559#define WM8995_WRITE_SEQUENCER_326 0x3146
560#define WM8995_WRITE_SEQUENCER_327 0x3147
561#define WM8995_WRITE_SEQUENCER_328 0x3148
562#define WM8995_WRITE_SEQUENCER_329 0x3149
563#define WM8995_WRITE_SEQUENCER_330 0x314A
564#define WM8995_WRITE_SEQUENCER_331 0x314B
565#define WM8995_WRITE_SEQUENCER_332 0x314C
566#define WM8995_WRITE_SEQUENCER_333 0x314D
567#define WM8995_WRITE_SEQUENCER_334 0x314E
568#define WM8995_WRITE_SEQUENCER_335 0x314F
569#define WM8995_WRITE_SEQUENCER_336 0x3150
570#define WM8995_WRITE_SEQUENCER_337 0x3151
571#define WM8995_WRITE_SEQUENCER_338 0x3152
572#define WM8995_WRITE_SEQUENCER_339 0x3153
573#define WM8995_WRITE_SEQUENCER_340 0x3154
574#define WM8995_WRITE_SEQUENCER_341 0x3155
575#define WM8995_WRITE_SEQUENCER_342 0x3156
576#define WM8995_WRITE_SEQUENCER_343 0x3157
577#define WM8995_WRITE_SEQUENCER_344 0x3158
578#define WM8995_WRITE_SEQUENCER_345 0x3159
579#define WM8995_WRITE_SEQUENCER_346 0x315A
580#define WM8995_WRITE_SEQUENCER_347 0x315B
581#define WM8995_WRITE_SEQUENCER_348 0x315C
582#define WM8995_WRITE_SEQUENCER_349 0x315D
583#define WM8995_WRITE_SEQUENCER_350 0x315E
584#define WM8995_WRITE_SEQUENCER_351 0x315F
585#define WM8995_WRITE_SEQUENCER_352 0x3160
586#define WM8995_WRITE_SEQUENCER_353 0x3161
587#define WM8995_WRITE_SEQUENCER_354 0x3162
588#define WM8995_WRITE_SEQUENCER_355 0x3163
589#define WM8995_WRITE_SEQUENCER_356 0x3164
590#define WM8995_WRITE_SEQUENCER_357 0x3165
591#define WM8995_WRITE_SEQUENCER_358 0x3166
592#define WM8995_WRITE_SEQUENCER_359 0x3167
593#define WM8995_WRITE_SEQUENCER_360 0x3168
594#define WM8995_WRITE_SEQUENCER_361 0x3169
595#define WM8995_WRITE_SEQUENCER_362 0x316A
596#define WM8995_WRITE_SEQUENCER_363 0x316B
597#define WM8995_WRITE_SEQUENCER_364 0x316C
598#define WM8995_WRITE_SEQUENCER_365 0x316D
599#define WM8995_WRITE_SEQUENCER_366 0x316E
600#define WM8995_WRITE_SEQUENCER_367 0x316F
601#define WM8995_WRITE_SEQUENCER_368 0x3170
602#define WM8995_WRITE_SEQUENCER_369 0x3171
603#define WM8995_WRITE_SEQUENCER_370 0x3172
604#define WM8995_WRITE_SEQUENCER_371 0x3173
605#define WM8995_WRITE_SEQUENCER_372 0x3174
606#define WM8995_WRITE_SEQUENCER_373 0x3175
607#define WM8995_WRITE_SEQUENCER_374 0x3176
608#define WM8995_WRITE_SEQUENCER_375 0x3177
609#define WM8995_WRITE_SEQUENCER_376 0x3178
610#define WM8995_WRITE_SEQUENCER_377 0x3179
611#define WM8995_WRITE_SEQUENCER_378 0x317A
612#define WM8995_WRITE_SEQUENCER_379 0x317B
613#define WM8995_WRITE_SEQUENCER_380 0x317C
614#define WM8995_WRITE_SEQUENCER_381 0x317D
615#define WM8995_WRITE_SEQUENCER_382 0x317E
616#define WM8995_WRITE_SEQUENCER_383 0x317F
617#define WM8995_WRITE_SEQUENCER_384 0x3180
618#define WM8995_WRITE_SEQUENCER_385 0x3181
619#define WM8995_WRITE_SEQUENCER_386 0x3182
620#define WM8995_WRITE_SEQUENCER_387 0x3183
621#define WM8995_WRITE_SEQUENCER_388 0x3184
622#define WM8995_WRITE_SEQUENCER_389 0x3185
623#define WM8995_WRITE_SEQUENCER_390 0x3186
624#define WM8995_WRITE_SEQUENCER_391 0x3187
625#define WM8995_WRITE_SEQUENCER_392 0x3188
626#define WM8995_WRITE_SEQUENCER_393 0x3189
627#define WM8995_WRITE_SEQUENCER_394 0x318A
628#define WM8995_WRITE_SEQUENCER_395 0x318B
629#define WM8995_WRITE_SEQUENCER_396 0x318C
630#define WM8995_WRITE_SEQUENCER_397 0x318D
631#define WM8995_WRITE_SEQUENCER_398 0x318E
632#define WM8995_WRITE_SEQUENCER_399 0x318F
633#define WM8995_WRITE_SEQUENCER_400 0x3190
634#define WM8995_WRITE_SEQUENCER_401 0x3191
635#define WM8995_WRITE_SEQUENCER_402 0x3192
636#define WM8995_WRITE_SEQUENCER_403 0x3193
637#define WM8995_WRITE_SEQUENCER_404 0x3194
638#define WM8995_WRITE_SEQUENCER_405 0x3195
639#define WM8995_WRITE_SEQUENCER_406 0x3196
640#define WM8995_WRITE_SEQUENCER_407 0x3197
641#define WM8995_WRITE_SEQUENCER_408 0x3198
642#define WM8995_WRITE_SEQUENCER_409 0x3199
643#define WM8995_WRITE_SEQUENCER_410 0x319A
644#define WM8995_WRITE_SEQUENCER_411 0x319B
645#define WM8995_WRITE_SEQUENCER_412 0x319C
646#define WM8995_WRITE_SEQUENCER_413 0x319D
647#define WM8995_WRITE_SEQUENCER_414 0x319E
648#define WM8995_WRITE_SEQUENCER_415 0x319F
649#define WM8995_WRITE_SEQUENCER_416 0x31A0
650#define WM8995_WRITE_SEQUENCER_417 0x31A1
651#define WM8995_WRITE_SEQUENCER_418 0x31A2
652#define WM8995_WRITE_SEQUENCER_419 0x31A3
653#define WM8995_WRITE_SEQUENCER_420 0x31A4
654#define WM8995_WRITE_SEQUENCER_421 0x31A5
655#define WM8995_WRITE_SEQUENCER_422 0x31A6
656#define WM8995_WRITE_SEQUENCER_423 0x31A7
657#define WM8995_WRITE_SEQUENCER_424 0x31A8
658#define WM8995_WRITE_SEQUENCER_425 0x31A9
659#define WM8995_WRITE_SEQUENCER_426 0x31AA
660#define WM8995_WRITE_SEQUENCER_427 0x31AB
661#define WM8995_WRITE_SEQUENCER_428 0x31AC
662#define WM8995_WRITE_SEQUENCER_429 0x31AD
663#define WM8995_WRITE_SEQUENCER_430 0x31AE
664#define WM8995_WRITE_SEQUENCER_431 0x31AF
665#define WM8995_WRITE_SEQUENCER_432 0x31B0
666#define WM8995_WRITE_SEQUENCER_433 0x31B1
667#define WM8995_WRITE_SEQUENCER_434 0x31B2
668#define WM8995_WRITE_SEQUENCER_435 0x31B3
669#define WM8995_WRITE_SEQUENCER_436 0x31B4
670#define WM8995_WRITE_SEQUENCER_437 0x31B5
671#define WM8995_WRITE_SEQUENCER_438 0x31B6
672#define WM8995_WRITE_SEQUENCER_439 0x31B7
673#define WM8995_WRITE_SEQUENCER_440 0x31B8
674#define WM8995_WRITE_SEQUENCER_441 0x31B9
675#define WM8995_WRITE_SEQUENCER_442 0x31BA
676#define WM8995_WRITE_SEQUENCER_443 0x31BB
677#define WM8995_WRITE_SEQUENCER_444 0x31BC
678#define WM8995_WRITE_SEQUENCER_445 0x31BD
679#define WM8995_WRITE_SEQUENCER_446 0x31BE
680#define WM8995_WRITE_SEQUENCER_447 0x31BF
681#define WM8995_WRITE_SEQUENCER_448 0x31C0
682#define WM8995_WRITE_SEQUENCER_449 0x31C1
683#define WM8995_WRITE_SEQUENCER_450 0x31C2
684#define WM8995_WRITE_SEQUENCER_451 0x31C3
685#define WM8995_WRITE_SEQUENCER_452 0x31C4
686#define WM8995_WRITE_SEQUENCER_453 0x31C5
687#define WM8995_WRITE_SEQUENCER_454 0x31C6
688#define WM8995_WRITE_SEQUENCER_455 0x31C7
689#define WM8995_WRITE_SEQUENCER_456 0x31C8
690#define WM8995_WRITE_SEQUENCER_457 0x31C9
691#define WM8995_WRITE_SEQUENCER_458 0x31CA
692#define WM8995_WRITE_SEQUENCER_459 0x31CB
693#define WM8995_WRITE_SEQUENCER_460 0x31CC
694#define WM8995_WRITE_SEQUENCER_461 0x31CD
695#define WM8995_WRITE_SEQUENCER_462 0x31CE
696#define WM8995_WRITE_SEQUENCER_463 0x31CF
697#define WM8995_WRITE_SEQUENCER_464 0x31D0
698#define WM8995_WRITE_SEQUENCER_465 0x31D1
699#define WM8995_WRITE_SEQUENCER_466 0x31D2
700#define WM8995_WRITE_SEQUENCER_467 0x31D3
701#define WM8995_WRITE_SEQUENCER_468 0x31D4
702#define WM8995_WRITE_SEQUENCER_469 0x31D5
703#define WM8995_WRITE_SEQUENCER_470 0x31D6
704#define WM8995_WRITE_SEQUENCER_471 0x31D7
705#define WM8995_WRITE_SEQUENCER_472 0x31D8
706#define WM8995_WRITE_SEQUENCER_473 0x31D9
707#define WM8995_WRITE_SEQUENCER_474 0x31DA
708#define WM8995_WRITE_SEQUENCER_475 0x31DB
709#define WM8995_WRITE_SEQUENCER_476 0x31DC
710#define WM8995_WRITE_SEQUENCER_477 0x31DD
711#define WM8995_WRITE_SEQUENCER_478 0x31DE
712#define WM8995_WRITE_SEQUENCER_479 0x31DF
713#define WM8995_WRITE_SEQUENCER_480 0x31E0
714#define WM8995_WRITE_SEQUENCER_481 0x31E1
715#define WM8995_WRITE_SEQUENCER_482 0x31E2
716#define WM8995_WRITE_SEQUENCER_483 0x31E3
717#define WM8995_WRITE_SEQUENCER_484 0x31E4
718#define WM8995_WRITE_SEQUENCER_485 0x31E5
719#define WM8995_WRITE_SEQUENCER_486 0x31E6
720#define WM8995_WRITE_SEQUENCER_487 0x31E7
721#define WM8995_WRITE_SEQUENCER_488 0x31E8
722#define WM8995_WRITE_SEQUENCER_489 0x31E9
723#define WM8995_WRITE_SEQUENCER_490 0x31EA
724#define WM8995_WRITE_SEQUENCER_491 0x31EB
725#define WM8995_WRITE_SEQUENCER_492 0x31EC
726#define WM8995_WRITE_SEQUENCER_493 0x31ED
727#define WM8995_WRITE_SEQUENCER_494 0x31EE
728#define WM8995_WRITE_SEQUENCER_495 0x31EF
729#define WM8995_WRITE_SEQUENCER_496 0x31F0
730#define WM8995_WRITE_SEQUENCER_497 0x31F1
731#define WM8995_WRITE_SEQUENCER_498 0x31F2
732#define WM8995_WRITE_SEQUENCER_499 0x31F3
733#define WM8995_WRITE_SEQUENCER_500 0x31F4
734#define WM8995_WRITE_SEQUENCER_501 0x31F5
735#define WM8995_WRITE_SEQUENCER_502 0x31F6
736#define WM8995_WRITE_SEQUENCER_503 0x31F7
737#define WM8995_WRITE_SEQUENCER_504 0x31F8
738#define WM8995_WRITE_SEQUENCER_505 0x31F9
739#define WM8995_WRITE_SEQUENCER_506 0x31FA
740#define WM8995_WRITE_SEQUENCER_507 0x31FB
741#define WM8995_WRITE_SEQUENCER_508 0x31FC
742#define WM8995_WRITE_SEQUENCER_509 0x31FD
743#define WM8995_WRITE_SEQUENCER_510 0x31FE
744#define WM8995_WRITE_SEQUENCER_511 0x31FF
745
746#define WM8995_REGISTER_COUNT 725
747#define WM8995_MAX_REGISTER 0x31FF
748
749#define WM8995_MAX_CACHED_REGISTER WM8995_MAX_REGISTER
750
751/*
752 * Field Definitions.
753 */
754
755/*
756 * R0 (0x00) - Software Reset
757 */
758#define WM8995_SW_RESET_MASK 0xFFFF /* SW_RESET - [15:0] */
759#define WM8995_SW_RESET_SHIFT 0 /* SW_RESET - [15:0] */
760#define WM8995_SW_RESET_WIDTH 16 /* SW_RESET - [15:0] */
761
762/*
763 * R1 (0x01) - Power Management (1)
764 */
765#define WM8995_MICB2_ENA 0x0200 /* MICB2_ENA */
766#define WM8995_MICB2_ENA_MASK 0x0200 /* MICB2_ENA */
767#define WM8995_MICB2_ENA_SHIFT 9 /* MICB2_ENA */
768#define WM8995_MICB2_ENA_WIDTH 1 /* MICB2_ENA */
769#define WM8995_MICB1_ENA 0x0100 /* MICB1_ENA */
770#define WM8995_MICB1_ENA_MASK 0x0100 /* MICB1_ENA */
771#define WM8995_MICB1_ENA_SHIFT 8 /* MICB1_ENA */
772#define WM8995_MICB1_ENA_WIDTH 1 /* MICB1_ENA */
773#define WM8995_HPOUT2L_ENA 0x0080 /* HPOUT2L_ENA */
774#define WM8995_HPOUT2L_ENA_MASK 0x0080 /* HPOUT2L_ENA */
775#define WM8995_HPOUT2L_ENA_SHIFT 7 /* HPOUT2L_ENA */
776#define WM8995_HPOUT2L_ENA_WIDTH 1 /* HPOUT2L_ENA */
777#define WM8995_HPOUT2R_ENA 0x0040 /* HPOUT2R_ENA */
778#define WM8995_HPOUT2R_ENA_MASK 0x0040 /* HPOUT2R_ENA */
779#define WM8995_HPOUT2R_ENA_SHIFT 6 /* HPOUT2R_ENA */
780#define WM8995_HPOUT2R_ENA_WIDTH 1 /* HPOUT2R_ENA */
781#define WM8995_HPOUT1L_ENA 0x0020 /* HPOUT1L_ENA */
782#define WM8995_HPOUT1L_ENA_MASK 0x0020 /* HPOUT1L_ENA */
783#define WM8995_HPOUT1L_ENA_SHIFT 5 /* HPOUT1L_ENA */
784#define WM8995_HPOUT1L_ENA_WIDTH 1 /* HPOUT1L_ENA */
785#define WM8995_HPOUT1R_ENA 0x0010 /* HPOUT1R_ENA */
786#define WM8995_HPOUT1R_ENA_MASK 0x0010 /* HPOUT1R_ENA */
787#define WM8995_HPOUT1R_ENA_SHIFT 4 /* HPOUT1R_ENA */
788#define WM8995_HPOUT1R_ENA_WIDTH 1 /* HPOUT1R_ENA */
789#define WM8995_BG_ENA 0x0001 /* BG_ENA */
790#define WM8995_BG_ENA_MASK 0x0001 /* BG_ENA */
791#define WM8995_BG_ENA_SHIFT 0 /* BG_ENA */
792#define WM8995_BG_ENA_WIDTH 1 /* BG_ENA */
793
794/*
795 * R2 (0x02) - Power Management (2)
796 */
797#define WM8995_OPCLK_ENA 0x0800 /* OPCLK_ENA */
798#define WM8995_OPCLK_ENA_MASK 0x0800 /* OPCLK_ENA */
799#define WM8995_OPCLK_ENA_SHIFT 11 /* OPCLK_ENA */
800#define WM8995_OPCLK_ENA_WIDTH 1 /* OPCLK_ENA */
801#define WM8995_IN1L_ENA 0x0020 /* IN1L_ENA */
802#define WM8995_IN1L_ENA_MASK 0x0020 /* IN1L_ENA */
803#define WM8995_IN1L_ENA_SHIFT 5 /* IN1L_ENA */
804#define WM8995_IN1L_ENA_WIDTH 1 /* IN1L_ENA */
805#define WM8995_IN1R_ENA 0x0010 /* IN1R_ENA */
806#define WM8995_IN1R_ENA_MASK 0x0010 /* IN1R_ENA */
807#define WM8995_IN1R_ENA_SHIFT 4 /* IN1R_ENA */
808#define WM8995_IN1R_ENA_WIDTH 1 /* IN1R_ENA */
809#define WM8995_LDO2_ENA 0x0002 /* LDO2_ENA */
810#define WM8995_LDO2_ENA_MASK 0x0002 /* LDO2_ENA */
811#define WM8995_LDO2_ENA_SHIFT 1 /* LDO2_ENA */
812#define WM8995_LDO2_ENA_WIDTH 1 /* LDO2_ENA */
813
814/*
815 * R3 (0x03) - Power Management (3)
816 */
817#define WM8995_AIF2ADCL_ENA 0x2000 /* AIF2ADCL_ENA */
818#define WM8995_AIF2ADCL_ENA_MASK 0x2000 /* AIF2ADCL_ENA */
819#define WM8995_AIF2ADCL_ENA_SHIFT 13 /* AIF2ADCL_ENA */
820#define WM8995_AIF2ADCL_ENA_WIDTH 1 /* AIF2ADCL_ENA */
821#define WM8995_AIF2ADCR_ENA 0x1000 /* AIF2ADCR_ENA */
822#define WM8995_AIF2ADCR_ENA_MASK 0x1000 /* AIF2ADCR_ENA */
823#define WM8995_AIF2ADCR_ENA_SHIFT 12 /* AIF2ADCR_ENA */
824#define WM8995_AIF2ADCR_ENA_WIDTH 1 /* AIF2ADCR_ENA */
825#define WM8995_AIF1ADC2L_ENA 0x0800 /* AIF1ADC2L_ENA */
826#define WM8995_AIF1ADC2L_ENA_MASK 0x0800 /* AIF1ADC2L_ENA */
827#define WM8995_AIF1ADC2L_ENA_SHIFT 11 /* AIF1ADC2L_ENA */
828#define WM8995_AIF1ADC2L_ENA_WIDTH 1 /* AIF1ADC2L_ENA */
829#define WM8995_AIF1ADC2R_ENA 0x0400 /* AIF1ADC2R_ENA */
830#define WM8995_AIF1ADC2R_ENA_MASK 0x0400 /* AIF1ADC2R_ENA */
831#define WM8995_AIF1ADC2R_ENA_SHIFT 10 /* AIF1ADC2R_ENA */
832#define WM8995_AIF1ADC2R_ENA_WIDTH 1 /* AIF1ADC2R_ENA */
833#define WM8995_AIF1ADC1L_ENA 0x0200 /* AIF1ADC1L_ENA */
834#define WM8995_AIF1ADC1L_ENA_MASK 0x0200 /* AIF1ADC1L_ENA */
835#define WM8995_AIF1ADC1L_ENA_SHIFT 9 /* AIF1ADC1L_ENA */
836#define WM8995_AIF1ADC1L_ENA_WIDTH 1 /* AIF1ADC1L_ENA */
837#define WM8995_AIF1ADC1R_ENA 0x0100 /* AIF1ADC1R_ENA */
838#define WM8995_AIF1ADC1R_ENA_MASK 0x0100 /* AIF1ADC1R_ENA */
839#define WM8995_AIF1ADC1R_ENA_SHIFT 8 /* AIF1ADC1R_ENA */
840#define WM8995_AIF1ADC1R_ENA_WIDTH 1 /* AIF1ADC1R_ENA */
841#define WM8995_DMIC3L_ENA 0x0080 /* DMIC3L_ENA */
842#define WM8995_DMIC3L_ENA_MASK 0x0080 /* DMIC3L_ENA */
843#define WM8995_DMIC3L_ENA_SHIFT 7 /* DMIC3L_ENA */
844#define WM8995_DMIC3L_ENA_WIDTH 1 /* DMIC3L_ENA */
845#define WM8995_DMIC3R_ENA 0x0040 /* DMIC3R_ENA */
846#define WM8995_DMIC3R_ENA_MASK 0x0040 /* DMIC3R_ENA */
847#define WM8995_DMIC3R_ENA_SHIFT 6 /* DMIC3R_ENA */
848#define WM8995_DMIC3R_ENA_WIDTH 1 /* DMIC3R_ENA */
849#define WM8995_DMIC2L_ENA 0x0020 /* DMIC2L_ENA */
850#define WM8995_DMIC2L_ENA_MASK 0x0020 /* DMIC2L_ENA */
851#define WM8995_DMIC2L_ENA_SHIFT 5 /* DMIC2L_ENA */
852#define WM8995_DMIC2L_ENA_WIDTH 1 /* DMIC2L_ENA */
853#define WM8995_DMIC2R_ENA 0x0010 /* DMIC2R_ENA */
854#define WM8995_DMIC2R_ENA_MASK 0x0010 /* DMIC2R_ENA */
855#define WM8995_DMIC2R_ENA_SHIFT 4 /* DMIC2R_ENA */
856#define WM8995_DMIC2R_ENA_WIDTH 1 /* DMIC2R_ENA */
857#define WM8995_DMIC1L_ENA 0x0008 /* DMIC1L_ENA */
858#define WM8995_DMIC1L_ENA_MASK 0x0008 /* DMIC1L_ENA */
859#define WM8995_DMIC1L_ENA_SHIFT 3 /* DMIC1L_ENA */
860#define WM8995_DMIC1L_ENA_WIDTH 1 /* DMIC1L_ENA */
861#define WM8995_DMIC1R_ENA 0x0004 /* DMIC1R_ENA */
862#define WM8995_DMIC1R_ENA_MASK 0x0004 /* DMIC1R_ENA */
863#define WM8995_DMIC1R_ENA_SHIFT 2 /* DMIC1R_ENA */
864#define WM8995_DMIC1R_ENA_WIDTH 1 /* DMIC1R_ENA */
865#define WM8995_ADCL_ENA 0x0002 /* ADCL_ENA */
866#define WM8995_ADCL_ENA_MASK 0x0002 /* ADCL_ENA */
867#define WM8995_ADCL_ENA_SHIFT 1 /* ADCL_ENA */
868#define WM8995_ADCL_ENA_WIDTH 1 /* ADCL_ENA */
869#define WM8995_ADCR_ENA 0x0001 /* ADCR_ENA */
870#define WM8995_ADCR_ENA_MASK 0x0001 /* ADCR_ENA */
871#define WM8995_ADCR_ENA_SHIFT 0 /* ADCR_ENA */
872#define WM8995_ADCR_ENA_WIDTH 1 /* ADCR_ENA */
873
874/*
875 * R4 (0x04) - Power Management (4)
876 */
877#define WM8995_AIF2DACL_ENA 0x2000 /* AIF2DACL_ENA */
878#define WM8995_AIF2DACL_ENA_MASK 0x2000 /* AIF2DACL_ENA */
879#define WM8995_AIF2DACL_ENA_SHIFT 13 /* AIF2DACL_ENA */
880#define WM8995_AIF2DACL_ENA_WIDTH 1 /* AIF2DACL_ENA */
881#define WM8995_AIF2DACR_ENA 0x1000 /* AIF2DACR_ENA */
882#define WM8995_AIF2DACR_ENA_MASK 0x1000 /* AIF2DACR_ENA */
883#define WM8995_AIF2DACR_ENA_SHIFT 12 /* AIF2DACR_ENA */
884#define WM8995_AIF2DACR_ENA_WIDTH 1 /* AIF2DACR_ENA */
885#define WM8995_AIF1DAC2L_ENA 0x0800 /* AIF1DAC2L_ENA */
886#define WM8995_AIF1DAC2L_ENA_MASK 0x0800 /* AIF1DAC2L_ENA */
887#define WM8995_AIF1DAC2L_ENA_SHIFT 11 /* AIF1DAC2L_ENA */
888#define WM8995_AIF1DAC2L_ENA_WIDTH 1 /* AIF1DAC2L_ENA */
889#define WM8995_AIF1DAC2R_ENA 0x0400 /* AIF1DAC2R_ENA */
890#define WM8995_AIF1DAC2R_ENA_MASK 0x0400 /* AIF1DAC2R_ENA */
891#define WM8995_AIF1DAC2R_ENA_SHIFT 10 /* AIF1DAC2R_ENA */
892#define WM8995_AIF1DAC2R_ENA_WIDTH 1 /* AIF1DAC2R_ENA */
893#define WM8995_AIF1DAC1L_ENA 0x0200 /* AIF1DAC1L_ENA */
894#define WM8995_AIF1DAC1L_ENA_MASK 0x0200 /* AIF1DAC1L_ENA */
895#define WM8995_AIF1DAC1L_ENA_SHIFT 9 /* AIF1DAC1L_ENA */
896#define WM8995_AIF1DAC1L_ENA_WIDTH 1 /* AIF1DAC1L_ENA */
897#define WM8995_AIF1DAC1R_ENA 0x0100 /* AIF1DAC1R_ENA */
898#define WM8995_AIF1DAC1R_ENA_MASK 0x0100 /* AIF1DAC1R_ENA */
899#define WM8995_AIF1DAC1R_ENA_SHIFT 8 /* AIF1DAC1R_ENA */
900#define WM8995_AIF1DAC1R_ENA_WIDTH 1 /* AIF1DAC1R_ENA */
901#define WM8995_DAC2L_ENA 0x0008 /* DAC2L_ENA */
902#define WM8995_DAC2L_ENA_MASK 0x0008 /* DAC2L_ENA */
903#define WM8995_DAC2L_ENA_SHIFT 3 /* DAC2L_ENA */
904#define WM8995_DAC2L_ENA_WIDTH 1 /* DAC2L_ENA */
905#define WM8995_DAC2R_ENA 0x0004 /* DAC2R_ENA */
906#define WM8995_DAC2R_ENA_MASK 0x0004 /* DAC2R_ENA */
907#define WM8995_DAC2R_ENA_SHIFT 2 /* DAC2R_ENA */
908#define WM8995_DAC2R_ENA_WIDTH 1 /* DAC2R_ENA */
909#define WM8995_DAC1L_ENA 0x0002 /* DAC1L_ENA */
910#define WM8995_DAC1L_ENA_MASK 0x0002 /* DAC1L_ENA */
911#define WM8995_DAC1L_ENA_SHIFT 1 /* DAC1L_ENA */
912#define WM8995_DAC1L_ENA_WIDTH 1 /* DAC1L_ENA */
913#define WM8995_DAC1R_ENA 0x0001 /* DAC1R_ENA */
914#define WM8995_DAC1R_ENA_MASK 0x0001 /* DAC1R_ENA */
915#define WM8995_DAC1R_ENA_SHIFT 0 /* DAC1R_ENA */
916#define WM8995_DAC1R_ENA_WIDTH 1 /* DAC1R_ENA */
917
918/*
919 * R5 (0x05) - Power Management (5)
920 */
921#define WM8995_DMIC_SRC2_MASK 0x0300 /* DMIC_SRC2 - [9:8] */
922#define WM8995_DMIC_SRC2_SHIFT 8 /* DMIC_SRC2 - [9:8] */
923#define WM8995_DMIC_SRC2_WIDTH 2 /* DMIC_SRC2 - [9:8] */
924#define WM8995_DMIC_SRC1_MASK 0x00C0 /* DMIC_SRC1 - [7:6] */
925#define WM8995_DMIC_SRC1_SHIFT 6 /* DMIC_SRC1 - [7:6] */
926#define WM8995_DMIC_SRC1_WIDTH 2 /* DMIC_SRC1 - [7:6] */
927#define WM8995_AIF3_TRI 0x0020 /* AIF3_TRI */
928#define WM8995_AIF3_TRI_MASK 0x0020 /* AIF3_TRI */
929#define WM8995_AIF3_TRI_SHIFT 5 /* AIF3_TRI */
930#define WM8995_AIF3_TRI_WIDTH 1 /* AIF3_TRI */
931#define WM8995_AIF3_ADCDAT_SRC_MASK 0x0018 /* AIF3_ADCDAT_SRC - [4:3] */
932#define WM8995_AIF3_ADCDAT_SRC_SHIFT 3 /* AIF3_ADCDAT_SRC - [4:3] */
933#define WM8995_AIF3_ADCDAT_SRC_WIDTH 2 /* AIF3_ADCDAT_SRC - [4:3] */
934#define WM8995_AIF2_ADCDAT_SRC 0x0004 /* AIF2_ADCDAT_SRC */
935#define WM8995_AIF2_ADCDAT_SRC_MASK 0x0004 /* AIF2_ADCDAT_SRC */
936#define WM8995_AIF2_ADCDAT_SRC_SHIFT 2 /* AIF2_ADCDAT_SRC */
937#define WM8995_AIF2_ADCDAT_SRC_WIDTH 1 /* AIF2_ADCDAT_SRC */
938#define WM8995_AIF2_DACDAT_SRC 0x0002 /* AIF2_DACDAT_SRC */
939#define WM8995_AIF2_DACDAT_SRC_MASK 0x0002 /* AIF2_DACDAT_SRC */
940#define WM8995_AIF2_DACDAT_SRC_SHIFT 1 /* AIF2_DACDAT_SRC */
941#define WM8995_AIF2_DACDAT_SRC_WIDTH 1 /* AIF2_DACDAT_SRC */
942#define WM8995_AIF1_DACDAT_SRC 0x0001 /* AIF1_DACDAT_SRC */
943#define WM8995_AIF1_DACDAT_SRC_MASK 0x0001 /* AIF1_DACDAT_SRC */
944#define WM8995_AIF1_DACDAT_SRC_SHIFT 0 /* AIF1_DACDAT_SRC */
945#define WM8995_AIF1_DACDAT_SRC_WIDTH 1 /* AIF1_DACDAT_SRC */
946
947/*
948 * R16 (0x10) - Left Line Input 1 Volume
949 */
950#define WM8995_IN1_VU 0x0080 /* IN1_VU */
951#define WM8995_IN1_VU_MASK 0x0080 /* IN1_VU */
952#define WM8995_IN1_VU_SHIFT 7 /* IN1_VU */
953#define WM8995_IN1_VU_WIDTH 1 /* IN1_VU */
954#define WM8995_IN1L_ZC 0x0020 /* IN1L_ZC */
955#define WM8995_IN1L_ZC_MASK 0x0020 /* IN1L_ZC */
956#define WM8995_IN1L_ZC_SHIFT 5 /* IN1L_ZC */
957#define WM8995_IN1L_ZC_WIDTH 1 /* IN1L_ZC */
958#define WM8995_IN1L_VOL_MASK 0x001F /* IN1L_VOL - [4:0] */
959#define WM8995_IN1L_VOL_SHIFT 0 /* IN1L_VOL - [4:0] */
960#define WM8995_IN1L_VOL_WIDTH 5 /* IN1L_VOL - [4:0] */
961
962/*
963 * R17 (0x11) - Right Line Input 1 Volume
964 */
965#define WM8995_IN1_VU 0x0080 /* IN1_VU */
966#define WM8995_IN1_VU_MASK 0x0080 /* IN1_VU */
967#define WM8995_IN1_VU_SHIFT 7 /* IN1_VU */
968#define WM8995_IN1_VU_WIDTH 1 /* IN1_VU */
969#define WM8995_IN1R_ZC 0x0020 /* IN1R_ZC */
970#define WM8995_IN1R_ZC_MASK 0x0020 /* IN1R_ZC */
971#define WM8995_IN1R_ZC_SHIFT 5 /* IN1R_ZC */
972#define WM8995_IN1R_ZC_WIDTH 1 /* IN1R_ZC */
973#define WM8995_IN1R_VOL_MASK 0x001F /* IN1R_VOL - [4:0] */
974#define WM8995_IN1R_VOL_SHIFT 0 /* IN1R_VOL - [4:0] */
975#define WM8995_IN1R_VOL_WIDTH 5 /* IN1R_VOL - [4:0] */
976
977/*
978 * R18 (0x12) - Left Line Input Control
979 */
980#define WM8995_IN1L_BOOST_MASK 0x0030 /* IN1L_BOOST - [5:4] */
981#define WM8995_IN1L_BOOST_SHIFT 4 /* IN1L_BOOST - [5:4] */
982#define WM8995_IN1L_BOOST_WIDTH 2 /* IN1L_BOOST - [5:4] */
983#define WM8995_IN1L_MODE_MASK 0x000C /* IN1L_MODE - [3:2] */
984#define WM8995_IN1L_MODE_SHIFT 2 /* IN1L_MODE - [3:2] */
985#define WM8995_IN1L_MODE_WIDTH 2 /* IN1L_MODE - [3:2] */
986#define WM8995_IN1R_MODE_MASK 0x0003 /* IN1R_MODE - [1:0] */
987#define WM8995_IN1R_MODE_SHIFT 0 /* IN1R_MODE - [1:0] */
988#define WM8995_IN1R_MODE_WIDTH 2 /* IN1R_MODE - [1:0] */
989
990/*
991 * R24 (0x18) - DAC1 Left Volume
992 */
993#define WM8995_DAC1L_MUTE 0x0200 /* DAC1L_MUTE */
994#define WM8995_DAC1L_MUTE_MASK 0x0200 /* DAC1L_MUTE */
995#define WM8995_DAC1L_MUTE_SHIFT 9 /* DAC1L_MUTE */
996#define WM8995_DAC1L_MUTE_WIDTH 1 /* DAC1L_MUTE */
997#define WM8995_DAC1_VU 0x0100 /* DAC1_VU */
998#define WM8995_DAC1_VU_MASK 0x0100 /* DAC1_VU */
999#define WM8995_DAC1_VU_SHIFT 8 /* DAC1_VU */
1000#define WM8995_DAC1_VU_WIDTH 1 /* DAC1_VU */
1001#define WM8995_DAC1L_VOL_MASK 0x00FF /* DAC1L_VOL - [7:0] */
1002#define WM8995_DAC1L_VOL_SHIFT 0 /* DAC1L_VOL - [7:0] */
1003#define WM8995_DAC1L_VOL_WIDTH 8 /* DAC1L_VOL - [7:0] */
1004
1005/*
1006 * R25 (0x19) - DAC1 Right Volume
1007 */
1008#define WM8995_DAC1R_MUTE 0x0200 /* DAC1R_MUTE */
1009#define WM8995_DAC1R_MUTE_MASK 0x0200 /* DAC1R_MUTE */
1010#define WM8995_DAC1R_MUTE_SHIFT 9 /* DAC1R_MUTE */
1011#define WM8995_DAC1R_MUTE_WIDTH 1 /* DAC1R_MUTE */
1012#define WM8995_DAC1_VU 0x0100 /* DAC1_VU */
1013#define WM8995_DAC1_VU_MASK 0x0100 /* DAC1_VU */
1014#define WM8995_DAC1_VU_SHIFT 8 /* DAC1_VU */
1015#define WM8995_DAC1_VU_WIDTH 1 /* DAC1_VU */
1016#define WM8995_DAC1R_VOL_MASK 0x00FF /* DAC1R_VOL - [7:0] */
1017#define WM8995_DAC1R_VOL_SHIFT 0 /* DAC1R_VOL - [7:0] */
1018#define WM8995_DAC1R_VOL_WIDTH 8 /* DAC1R_VOL - [7:0] */
1019
1020/*
1021 * R26 (0x1A) - DAC2 Left Volume
1022 */
1023#define WM8995_DAC2L_MUTE 0x0200 /* DAC2L_MUTE */
1024#define WM8995_DAC2L_MUTE_MASK 0x0200 /* DAC2L_MUTE */
1025#define WM8995_DAC2L_MUTE_SHIFT 9 /* DAC2L_MUTE */
1026#define WM8995_DAC2L_MUTE_WIDTH 1 /* DAC2L_MUTE */
1027#define WM8995_DAC2_VU 0x0100 /* DAC2_VU */
1028#define WM8995_DAC2_VU_MASK 0x0100 /* DAC2_VU */
1029#define WM8995_DAC2_VU_SHIFT 8 /* DAC2_VU */
1030#define WM8995_DAC2_VU_WIDTH 1 /* DAC2_VU */
1031#define WM8995_DAC2L_VOL_MASK 0x00FF /* DAC2L_VOL - [7:0] */
1032#define WM8995_DAC2L_VOL_SHIFT 0 /* DAC2L_VOL - [7:0] */
1033#define WM8995_DAC2L_VOL_WIDTH 8 /* DAC2L_VOL - [7:0] */
1034
1035/*
1036 * R27 (0x1B) - DAC2 Right Volume
1037 */
1038#define WM8995_DAC2R_MUTE 0x0200 /* DAC2R_MUTE */
1039#define WM8995_DAC2R_MUTE_MASK 0x0200 /* DAC2R_MUTE */
1040#define WM8995_DAC2R_MUTE_SHIFT 9 /* DAC2R_MUTE */
1041#define WM8995_DAC2R_MUTE_WIDTH 1 /* DAC2R_MUTE */
1042#define WM8995_DAC2_VU 0x0100 /* DAC2_VU */
1043#define WM8995_DAC2_VU_MASK 0x0100 /* DAC2_VU */
1044#define WM8995_DAC2_VU_SHIFT 8 /* DAC2_VU */
1045#define WM8995_DAC2_VU_WIDTH 1 /* DAC2_VU */
1046#define WM8995_DAC2R_VOL_MASK 0x00FF /* DAC2R_VOL - [7:0] */
1047#define WM8995_DAC2R_VOL_SHIFT 0 /* DAC2R_VOL - [7:0] */
1048#define WM8995_DAC2R_VOL_WIDTH 8 /* DAC2R_VOL - [7:0] */
1049
1050/*
1051 * R28 (0x1C) - Output Volume ZC (1)
1052 */
1053#define WM8995_HPOUT2L_ZC 0x0008 /* HPOUT2L_ZC */
1054#define WM8995_HPOUT2L_ZC_MASK 0x0008 /* HPOUT2L_ZC */
1055#define WM8995_HPOUT2L_ZC_SHIFT 3 /* HPOUT2L_ZC */
1056#define WM8995_HPOUT2L_ZC_WIDTH 1 /* HPOUT2L_ZC */
1057#define WM8995_HPOUT2R_ZC 0x0004 /* HPOUT2R_ZC */
1058#define WM8995_HPOUT2R_ZC_MASK 0x0004 /* HPOUT2R_ZC */
1059#define WM8995_HPOUT2R_ZC_SHIFT 2 /* HPOUT2R_ZC */
1060#define WM8995_HPOUT2R_ZC_WIDTH 1 /* HPOUT2R_ZC */
1061#define WM8995_HPOUT1L_ZC 0x0002 /* HPOUT1L_ZC */
1062#define WM8995_HPOUT1L_ZC_MASK 0x0002 /* HPOUT1L_ZC */
1063#define WM8995_HPOUT1L_ZC_SHIFT 1 /* HPOUT1L_ZC */
1064#define WM8995_HPOUT1L_ZC_WIDTH 1 /* HPOUT1L_ZC */
1065#define WM8995_HPOUT1R_ZC 0x0001 /* HPOUT1R_ZC */
1066#define WM8995_HPOUT1R_ZC_MASK 0x0001 /* HPOUT1R_ZC */
1067#define WM8995_HPOUT1R_ZC_SHIFT 0 /* HPOUT1R_ZC */
1068#define WM8995_HPOUT1R_ZC_WIDTH 1 /* HPOUT1R_ZC */
1069
1070/*
1071 * R32 (0x20) - MICBIAS (1)
1072 */
1073#define WM8995_MICB1_MODE 0x0008 /* MICB1_MODE */
1074#define WM8995_MICB1_MODE_MASK 0x0008 /* MICB1_MODE */
1075#define WM8995_MICB1_MODE_SHIFT 3 /* MICB1_MODE */
1076#define WM8995_MICB1_MODE_WIDTH 1 /* MICB1_MODE */
1077#define WM8995_MICB1_LVL_MASK 0x0006 /* MICB1_LVL - [2:1] */
1078#define WM8995_MICB1_LVL_SHIFT 1 /* MICB1_LVL - [2:1] */
1079#define WM8995_MICB1_LVL_WIDTH 2 /* MICB1_LVL - [2:1] */
1080#define WM8995_MICB1_DISCH 0x0001 /* MICB1_DISCH */
1081#define WM8995_MICB1_DISCH_MASK 0x0001 /* MICB1_DISCH */
1082#define WM8995_MICB1_DISCH_SHIFT 0 /* MICB1_DISCH */
1083#define WM8995_MICB1_DISCH_WIDTH 1 /* MICB1_DISCH */
1084
1085/*
1086 * R33 (0x21) - MICBIAS (2)
1087 */
1088#define WM8995_MICB2_MODE 0x0008 /* MICB2_MODE */
1089#define WM8995_MICB2_MODE_MASK 0x0008 /* MICB2_MODE */
1090#define WM8995_MICB2_MODE_SHIFT 3 /* MICB2_MODE */
1091#define WM8995_MICB2_MODE_WIDTH 1 /* MICB2_MODE */
1092#define WM8995_MICB2_LVL_MASK 0x0006 /* MICB2_LVL - [2:1] */
1093#define WM8995_MICB2_LVL_SHIFT 1 /* MICB2_LVL - [2:1] */
1094#define WM8995_MICB2_LVL_WIDTH 2 /* MICB2_LVL - [2:1] */
1095#define WM8995_MICB2_DISCH 0x0001 /* MICB2_DISCH */
1096#define WM8995_MICB2_DISCH_MASK 0x0001 /* MICB2_DISCH */
1097#define WM8995_MICB2_DISCH_SHIFT 0 /* MICB2_DISCH */
1098#define WM8995_MICB2_DISCH_WIDTH 1 /* MICB2_DISCH */
1099
1100/*
1101 * R40 (0x28) - LDO 1
1102 */
1103#define WM8995_LDO1_MODE 0x0020 /* LDO1_MODE */
1104#define WM8995_LDO1_MODE_MASK 0x0020 /* LDO1_MODE */
1105#define WM8995_LDO1_MODE_SHIFT 5 /* LDO1_MODE */
1106#define WM8995_LDO1_MODE_WIDTH 1 /* LDO1_MODE */
1107#define WM8995_LDO1_VSEL_MASK 0x0006 /* LDO1_VSEL - [2:1] */
1108#define WM8995_LDO1_VSEL_SHIFT 1 /* LDO1_VSEL - [2:1] */
1109#define WM8995_LDO1_VSEL_WIDTH 2 /* LDO1_VSEL - [2:1] */
1110#define WM8995_LDO1_DISCH 0x0001 /* LDO1_DISCH */
1111#define WM8995_LDO1_DISCH_MASK 0x0001 /* LDO1_DISCH */
1112#define WM8995_LDO1_DISCH_SHIFT 0 /* LDO1_DISCH */
1113#define WM8995_LDO1_DISCH_WIDTH 1 /* LDO1_DISCH */
1114
1115/*
1116 * R41 (0x29) - LDO 2
1117 */
1118#define WM8995_LDO2_MODE 0x0020 /* LDO2_MODE */
1119#define WM8995_LDO2_MODE_MASK 0x0020 /* LDO2_MODE */
1120#define WM8995_LDO2_MODE_SHIFT 5 /* LDO2_MODE */
1121#define WM8995_LDO2_MODE_WIDTH 1 /* LDO2_MODE */
1122#define WM8995_LDO2_VSEL_MASK 0x001E /* LDO2_VSEL - [4:1] */
1123#define WM8995_LDO2_VSEL_SHIFT 1 /* LDO2_VSEL - [4:1] */
1124#define WM8995_LDO2_VSEL_WIDTH 4 /* LDO2_VSEL - [4:1] */
1125#define WM8995_LDO2_DISCH 0x0001 /* LDO2_DISCH */
1126#define WM8995_LDO2_DISCH_MASK 0x0001 /* LDO2_DISCH */
1127#define WM8995_LDO2_DISCH_SHIFT 0 /* LDO2_DISCH */
1128#define WM8995_LDO2_DISCH_WIDTH 1 /* LDO2_DISCH */
1129
1130/*
1131 * R48 (0x30) - Accessory Detect Mode1
1132 */
1133#define WM8995_JD_MODE_MASK 0x0003 /* JD_MODE - [1:0] */
1134#define WM8995_JD_MODE_SHIFT 0 /* JD_MODE - [1:0] */
1135#define WM8995_JD_MODE_WIDTH 2 /* JD_MODE - [1:0] */
1136
1137/*
1138 * R49 (0x31) - Accessory Detect Mode2
1139 */
1140#define WM8995_VID_ENA 0x0001 /* VID_ENA */
1141#define WM8995_VID_ENA_MASK 0x0001 /* VID_ENA */
1142#define WM8995_VID_ENA_SHIFT 0 /* VID_ENA */
1143#define WM8995_VID_ENA_WIDTH 1 /* VID_ENA */
1144
1145/*
1146 * R52 (0x34) - Headphone Detect1
1147 */
1148#define WM8995_HP_RAMPRATE 0x0002 /* HP_RAMPRATE */
1149#define WM8995_HP_RAMPRATE_MASK 0x0002 /* HP_RAMPRATE */
1150#define WM8995_HP_RAMPRATE_SHIFT 1 /* HP_RAMPRATE */
1151#define WM8995_HP_RAMPRATE_WIDTH 1 /* HP_RAMPRATE */
1152#define WM8995_HP_POLL 0x0001 /* HP_POLL */
1153#define WM8995_HP_POLL_MASK 0x0001 /* HP_POLL */
1154#define WM8995_HP_POLL_SHIFT 0 /* HP_POLL */
1155#define WM8995_HP_POLL_WIDTH 1 /* HP_POLL */
1156
1157/*
1158 * R53 (0x35) - Headphone Detect2
1159 */
1160#define WM8995_HP_DONE 0x0080 /* HP_DONE */
1161#define WM8995_HP_DONE_MASK 0x0080 /* HP_DONE */
1162#define WM8995_HP_DONE_SHIFT 7 /* HP_DONE */
1163#define WM8995_HP_DONE_WIDTH 1 /* HP_DONE */
1164#define WM8995_HP_LVL_MASK 0x007F /* HP_LVL - [6:0] */
1165#define WM8995_HP_LVL_SHIFT 0 /* HP_LVL - [6:0] */
1166#define WM8995_HP_LVL_WIDTH 7 /* HP_LVL - [6:0] */
1167
1168/*
1169 * R56 (0x38) - Mic Detect (1)
1170 */
1171#define WM8995_MICD_RATE_MASK 0x7800 /* MICD_RATE - [14:11] */
1172#define WM8995_MICD_RATE_SHIFT 11 /* MICD_RATE - [14:11] */
1173#define WM8995_MICD_RATE_WIDTH 4 /* MICD_RATE - [14:11] */
1174#define WM8995_MICD_LVL_SEL_MASK 0x01F8 /* MICD_LVL_SEL - [8:3] */
1175#define WM8995_MICD_LVL_SEL_SHIFT 3 /* MICD_LVL_SEL - [8:3] */
1176#define WM8995_MICD_LVL_SEL_WIDTH 6 /* MICD_LVL_SEL - [8:3] */
1177#define WM8995_MICD_DBTIME 0x0002 /* MICD_DBTIME */
1178#define WM8995_MICD_DBTIME_MASK 0x0002 /* MICD_DBTIME */
1179#define WM8995_MICD_DBTIME_SHIFT 1 /* MICD_DBTIME */
1180#define WM8995_MICD_DBTIME_WIDTH 1 /* MICD_DBTIME */
1181#define WM8995_MICD_ENA 0x0001 /* MICD_ENA */
1182#define WM8995_MICD_ENA_MASK 0x0001 /* MICD_ENA */
1183#define WM8995_MICD_ENA_SHIFT 0 /* MICD_ENA */
1184#define WM8995_MICD_ENA_WIDTH 1 /* MICD_ENA */
1185
1186/*
1187 * R57 (0x39) - Mic Detect (2)
1188 */
1189#define WM8995_MICD_LVL_MASK 0x01FC /* MICD_LVL - [8:2] */
1190#define WM8995_MICD_LVL_SHIFT 2 /* MICD_LVL - [8:2] */
1191#define WM8995_MICD_LVL_WIDTH 7 /* MICD_LVL - [8:2] */
1192#define WM8995_MICD_VALID 0x0002 /* MICD_VALID */
1193#define WM8995_MICD_VALID_MASK 0x0002 /* MICD_VALID */
1194#define WM8995_MICD_VALID_SHIFT 1 /* MICD_VALID */
1195#define WM8995_MICD_VALID_WIDTH 1 /* MICD_VALID */
1196#define WM8995_MICD_STS 0x0001 /* MICD_STS */
1197#define WM8995_MICD_STS_MASK 0x0001 /* MICD_STS */
1198#define WM8995_MICD_STS_SHIFT 0 /* MICD_STS */
1199#define WM8995_MICD_STS_WIDTH 1 /* MICD_STS */
1200
1201/*
1202 * R64 (0x40) - Charge Pump (1)
1203 */
1204#define WM8995_CP_ENA 0x8000 /* CP_ENA */
1205#define WM8995_CP_ENA_MASK 0x8000 /* CP_ENA */
1206#define WM8995_CP_ENA_SHIFT 15 /* CP_ENA */
1207#define WM8995_CP_ENA_WIDTH 1 /* CP_ENA */
1208
1209/*
1210 * R69 (0x45) - Class W (1)
1211 */
1212#define WM8995_CP_DYN_SRC_SEL_MASK 0x0300 /* CP_DYN_SRC_SEL - [9:8] */
1213#define WM8995_CP_DYN_SRC_SEL_SHIFT 8 /* CP_DYN_SRC_SEL - [9:8] */
1214#define WM8995_CP_DYN_SRC_SEL_WIDTH 2 /* CP_DYN_SRC_SEL - [9:8] */
1215#define WM8995_CP_DYN_PWR 0x0001 /* CP_DYN_PWR */
1216#define WM8995_CP_DYN_PWR_MASK 0x0001 /* CP_DYN_PWR */
1217#define WM8995_CP_DYN_PWR_SHIFT 0 /* CP_DYN_PWR */
1218#define WM8995_CP_DYN_PWR_WIDTH 1 /* CP_DYN_PWR */
1219
1220/*
1221 * R80 (0x50) - DC Servo (1)
1222 */
1223#define WM8995_DCS_ENA_CHAN_3 0x0008 /* DCS_ENA_CHAN_3 */
1224#define WM8995_DCS_ENA_CHAN_3_MASK 0x0008 /* DCS_ENA_CHAN_3 */
1225#define WM8995_DCS_ENA_CHAN_3_SHIFT 3 /* DCS_ENA_CHAN_3 */
1226#define WM8995_DCS_ENA_CHAN_3_WIDTH 1 /* DCS_ENA_CHAN_3 */
1227#define WM8995_DCS_ENA_CHAN_2 0x0004 /* DCS_ENA_CHAN_2 */
1228#define WM8995_DCS_ENA_CHAN_2_MASK 0x0004 /* DCS_ENA_CHAN_2 */
1229#define WM8995_DCS_ENA_CHAN_2_SHIFT 2 /* DCS_ENA_CHAN_2 */
1230#define WM8995_DCS_ENA_CHAN_2_WIDTH 1 /* DCS_ENA_CHAN_2 */
1231#define WM8995_DCS_ENA_CHAN_1 0x0002 /* DCS_ENA_CHAN_1 */
1232#define WM8995_DCS_ENA_CHAN_1_MASK 0x0002 /* DCS_ENA_CHAN_1 */
1233#define WM8995_DCS_ENA_CHAN_1_SHIFT 1 /* DCS_ENA_CHAN_1 */
1234#define WM8995_DCS_ENA_CHAN_1_WIDTH 1 /* DCS_ENA_CHAN_1 */
1235#define WM8995_DCS_ENA_CHAN_0 0x0001 /* DCS_ENA_CHAN_0 */
1236#define WM8995_DCS_ENA_CHAN_0_MASK 0x0001 /* DCS_ENA_CHAN_0 */
1237#define WM8995_DCS_ENA_CHAN_0_SHIFT 0 /* DCS_ENA_CHAN_0 */
1238#define WM8995_DCS_ENA_CHAN_0_WIDTH 1 /* DCS_ENA_CHAN_0 */
1239
1240/*
1241 * R81 (0x51) - DC Servo (2)
1242 */
1243#define WM8995_DCS_TRIG_SINGLE_3 0x8000 /* DCS_TRIG_SINGLE_3 */
1244#define WM8995_DCS_TRIG_SINGLE_3_MASK 0x8000 /* DCS_TRIG_SINGLE_3 */
1245#define WM8995_DCS_TRIG_SINGLE_3_SHIFT 15 /* DCS_TRIG_SINGLE_3 */
1246#define WM8995_DCS_TRIG_SINGLE_3_WIDTH 1 /* DCS_TRIG_SINGLE_3 */
1247#define WM8995_DCS_TRIG_SINGLE_2 0x4000 /* DCS_TRIG_SINGLE_2 */
1248#define WM8995_DCS_TRIG_SINGLE_2_MASK 0x4000 /* DCS_TRIG_SINGLE_2 */
1249#define WM8995_DCS_TRIG_SINGLE_2_SHIFT 14 /* DCS_TRIG_SINGLE_2 */
1250#define WM8995_DCS_TRIG_SINGLE_2_WIDTH 1 /* DCS_TRIG_SINGLE_2 */
1251#define WM8995_DCS_TRIG_SINGLE_1 0x2000 /* DCS_TRIG_SINGLE_1 */
1252#define WM8995_DCS_TRIG_SINGLE_1_MASK 0x2000 /* DCS_TRIG_SINGLE_1 */
1253#define WM8995_DCS_TRIG_SINGLE_1_SHIFT 13 /* DCS_TRIG_SINGLE_1 */
1254#define WM8995_DCS_TRIG_SINGLE_1_WIDTH 1 /* DCS_TRIG_SINGLE_1 */
1255#define WM8995_DCS_TRIG_SINGLE_0 0x1000 /* DCS_TRIG_SINGLE_0 */
1256#define WM8995_DCS_TRIG_SINGLE_0_MASK 0x1000 /* DCS_TRIG_SINGLE_0 */
1257#define WM8995_DCS_TRIG_SINGLE_0_SHIFT 12 /* DCS_TRIG_SINGLE_0 */
1258#define WM8995_DCS_TRIG_SINGLE_0_WIDTH 1 /* DCS_TRIG_SINGLE_0 */
1259#define WM8995_DCS_TRIG_SERIES_3 0x0800 /* DCS_TRIG_SERIES_3 */
1260#define WM8995_DCS_TRIG_SERIES_3_MASK 0x0800 /* DCS_TRIG_SERIES_3 */
1261#define WM8995_DCS_TRIG_SERIES_3_SHIFT 11 /* DCS_TRIG_SERIES_3 */
1262#define WM8995_DCS_TRIG_SERIES_3_WIDTH 1 /* DCS_TRIG_SERIES_3 */
1263#define WM8995_DCS_TRIG_SERIES_2 0x0400 /* DCS_TRIG_SERIES_2 */
1264#define WM8995_DCS_TRIG_SERIES_2_MASK 0x0400 /* DCS_TRIG_SERIES_2 */
1265#define WM8995_DCS_TRIG_SERIES_2_SHIFT 10 /* DCS_TRIG_SERIES_2 */
1266#define WM8995_DCS_TRIG_SERIES_2_WIDTH 1 /* DCS_TRIG_SERIES_2 */
1267#define WM8995_DCS_TRIG_SERIES_1 0x0200 /* DCS_TRIG_SERIES_1 */
1268#define WM8995_DCS_TRIG_SERIES_1_MASK 0x0200 /* DCS_TRIG_SERIES_1 */
1269#define WM8995_DCS_TRIG_SERIES_1_SHIFT 9 /* DCS_TRIG_SERIES_1 */
1270#define WM8995_DCS_TRIG_SERIES_1_WIDTH 1 /* DCS_TRIG_SERIES_1 */
1271#define WM8995_DCS_TRIG_SERIES_0 0x0100 /* DCS_TRIG_SERIES_0 */
1272#define WM8995_DCS_TRIG_SERIES_0_MASK 0x0100 /* DCS_TRIG_SERIES_0 */
1273#define WM8995_DCS_TRIG_SERIES_0_SHIFT 8 /* DCS_TRIG_SERIES_0 */
1274#define WM8995_DCS_TRIG_SERIES_0_WIDTH 1 /* DCS_TRIG_SERIES_0 */
1275#define WM8995_DCS_TRIG_STARTUP_3 0x0080 /* DCS_TRIG_STARTUP_3 */
1276#define WM8995_DCS_TRIG_STARTUP_3_MASK 0x0080 /* DCS_TRIG_STARTUP_3 */
1277#define WM8995_DCS_TRIG_STARTUP_3_SHIFT 7 /* DCS_TRIG_STARTUP_3 */
1278#define WM8995_DCS_TRIG_STARTUP_3_WIDTH 1 /* DCS_TRIG_STARTUP_3 */
1279#define WM8995_DCS_TRIG_STARTUP_2 0x0040 /* DCS_TRIG_STARTUP_2 */
1280#define WM8995_DCS_TRIG_STARTUP_2_MASK 0x0040 /* DCS_TRIG_STARTUP_2 */
1281#define WM8995_DCS_TRIG_STARTUP_2_SHIFT 6 /* DCS_TRIG_STARTUP_2 */
1282#define WM8995_DCS_TRIG_STARTUP_2_WIDTH 1 /* DCS_TRIG_STARTUP_2 */
1283#define WM8995_DCS_TRIG_STARTUP_1 0x0020 /* DCS_TRIG_STARTUP_1 */
1284#define WM8995_DCS_TRIG_STARTUP_1_MASK 0x0020 /* DCS_TRIG_STARTUP_1 */
1285#define WM8995_DCS_TRIG_STARTUP_1_SHIFT 5 /* DCS_TRIG_STARTUP_1 */
1286#define WM8995_DCS_TRIG_STARTUP_1_WIDTH 1 /* DCS_TRIG_STARTUP_1 */
1287#define WM8995_DCS_TRIG_STARTUP_0 0x0010 /* DCS_TRIG_STARTUP_0 */
1288#define WM8995_DCS_TRIG_STARTUP_0_MASK 0x0010 /* DCS_TRIG_STARTUP_0 */
1289#define WM8995_DCS_TRIG_STARTUP_0_SHIFT 4 /* DCS_TRIG_STARTUP_0 */
1290#define WM8995_DCS_TRIG_STARTUP_0_WIDTH 1 /* DCS_TRIG_STARTUP_0 */
1291#define WM8995_DCS_TRIG_DAC_WR_3 0x0008 /* DCS_TRIG_DAC_WR_3 */
1292#define WM8995_DCS_TRIG_DAC_WR_3_MASK 0x0008 /* DCS_TRIG_DAC_WR_3 */
1293#define WM8995_DCS_TRIG_DAC_WR_3_SHIFT 3 /* DCS_TRIG_DAC_WR_3 */
1294#define WM8995_DCS_TRIG_DAC_WR_3_WIDTH 1 /* DCS_TRIG_DAC_WR_3 */
1295#define WM8995_DCS_TRIG_DAC_WR_2 0x0004 /* DCS_TRIG_DAC_WR_2 */
1296#define WM8995_DCS_TRIG_DAC_WR_2_MASK 0x0004 /* DCS_TRIG_DAC_WR_2 */
1297#define WM8995_DCS_TRIG_DAC_WR_2_SHIFT 2 /* DCS_TRIG_DAC_WR_2 */
1298#define WM8995_DCS_TRIG_DAC_WR_2_WIDTH 1 /* DCS_TRIG_DAC_WR_2 */
1299#define WM8995_DCS_TRIG_DAC_WR_1 0x0002 /* DCS_TRIG_DAC_WR_1 */
1300#define WM8995_DCS_TRIG_DAC_WR_1_MASK 0x0002 /* DCS_TRIG_DAC_WR_1 */
1301#define WM8995_DCS_TRIG_DAC_WR_1_SHIFT 1 /* DCS_TRIG_DAC_WR_1 */
1302#define WM8995_DCS_TRIG_DAC_WR_1_WIDTH 1 /* DCS_TRIG_DAC_WR_1 */
1303#define WM8995_DCS_TRIG_DAC_WR_0 0x0001 /* DCS_TRIG_DAC_WR_0 */
1304#define WM8995_DCS_TRIG_DAC_WR_0_MASK 0x0001 /* DCS_TRIG_DAC_WR_0 */
1305#define WM8995_DCS_TRIG_DAC_WR_0_SHIFT 0 /* DCS_TRIG_DAC_WR_0 */
1306#define WM8995_DCS_TRIG_DAC_WR_0_WIDTH 1 /* DCS_TRIG_DAC_WR_0 */
1307
1308/*
1309 * R82 (0x52) - DC Servo (3)
1310 */
1311#define WM8995_DCS_TIMER_PERIOD_23_MASK 0x0F00 /* DCS_TIMER_PERIOD_23 - [11:8] */
1312#define WM8995_DCS_TIMER_PERIOD_23_SHIFT 8 /* DCS_TIMER_PERIOD_23 - [11:8] */
1313#define WM8995_DCS_TIMER_PERIOD_23_WIDTH 4 /* DCS_TIMER_PERIOD_23 - [11:8] */
1314#define WM8995_DCS_TIMER_PERIOD_01_MASK 0x000F /* DCS_TIMER_PERIOD_01 - [3:0] */
1315#define WM8995_DCS_TIMER_PERIOD_01_SHIFT 0 /* DCS_TIMER_PERIOD_01 - [3:0] */
1316#define WM8995_DCS_TIMER_PERIOD_01_WIDTH 4 /* DCS_TIMER_PERIOD_01 - [3:0] */
1317
1318/*
1319 * R84 (0x54) - DC Servo (5)
1320 */
1321#define WM8995_DCS_SERIES_NO_23_MASK 0x7F00 /* DCS_SERIES_NO_23 - [14:8] */
1322#define WM8995_DCS_SERIES_NO_23_SHIFT 8 /* DCS_SERIES_NO_23 - [14:8] */
1323#define WM8995_DCS_SERIES_NO_23_WIDTH 7 /* DCS_SERIES_NO_23 - [14:8] */
1324#define WM8995_DCS_SERIES_NO_01_MASK 0x007F /* DCS_SERIES_NO_01 - [6:0] */
1325#define WM8995_DCS_SERIES_NO_01_SHIFT 0 /* DCS_SERIES_NO_01 - [6:0] */
1326#define WM8995_DCS_SERIES_NO_01_WIDTH 7 /* DCS_SERIES_NO_01 - [6:0] */
1327
1328/*
1329 * R85 (0x55) - DC Servo (6)
1330 */
1331#define WM8995_DCS_DAC_WR_VAL_3_MASK 0xFF00 /* DCS_DAC_WR_VAL_3 - [15:8] */
1332#define WM8995_DCS_DAC_WR_VAL_3_SHIFT 8 /* DCS_DAC_WR_VAL_3 - [15:8] */
1333#define WM8995_DCS_DAC_WR_VAL_3_WIDTH 8 /* DCS_DAC_WR_VAL_3 - [15:8] */
1334#define WM8995_DCS_DAC_WR_VAL_2_MASK 0x00FF /* DCS_DAC_WR_VAL_2 - [7:0] */
1335#define WM8995_DCS_DAC_WR_VAL_2_SHIFT 0 /* DCS_DAC_WR_VAL_2 - [7:0] */
1336#define WM8995_DCS_DAC_WR_VAL_2_WIDTH 8 /* DCS_DAC_WR_VAL_2 - [7:0] */
1337
1338/*
1339 * R86 (0x56) - DC Servo (7)
1340 */
1341#define WM8995_DCS_DAC_WR_VAL_1_MASK 0xFF00 /* DCS_DAC_WR_VAL_1 - [15:8] */
1342#define WM8995_DCS_DAC_WR_VAL_1_SHIFT 8 /* DCS_DAC_WR_VAL_1 - [15:8] */
1343#define WM8995_DCS_DAC_WR_VAL_1_WIDTH 8 /* DCS_DAC_WR_VAL_1 - [15:8] */
1344#define WM8995_DCS_DAC_WR_VAL_0_MASK 0x00FF /* DCS_DAC_WR_VAL_0 - [7:0] */
1345#define WM8995_DCS_DAC_WR_VAL_0_SHIFT 0 /* DCS_DAC_WR_VAL_0 - [7:0] */
1346#define WM8995_DCS_DAC_WR_VAL_0_WIDTH 8 /* DCS_DAC_WR_VAL_0 - [7:0] */
1347
1348/*
1349 * R87 (0x57) - DC Servo Readback 0
1350 */
1351#define WM8995_DCS_CAL_COMPLETE_MASK 0x0F00 /* DCS_CAL_COMPLETE - [11:8] */
1352#define WM8995_DCS_CAL_COMPLETE_SHIFT 8 /* DCS_CAL_COMPLETE - [11:8] */
1353#define WM8995_DCS_CAL_COMPLETE_WIDTH 4 /* DCS_CAL_COMPLETE - [11:8] */
1354#define WM8995_DCS_DAC_WR_COMPLETE_MASK 0x00F0 /* DCS_DAC_WR_COMPLETE - [7:4] */
1355#define WM8995_DCS_DAC_WR_COMPLETE_SHIFT 4 /* DCS_DAC_WR_COMPLETE - [7:4] */
1356#define WM8995_DCS_DAC_WR_COMPLETE_WIDTH 4 /* DCS_DAC_WR_COMPLETE - [7:4] */
1357#define WM8995_DCS_STARTUP_COMPLETE_MASK 0x000F /* DCS_STARTUP_COMPLETE - [3:0] */
1358#define WM8995_DCS_STARTUP_COMPLETE_SHIFT 0 /* DCS_STARTUP_COMPLETE - [3:0] */
1359#define WM8995_DCS_STARTUP_COMPLETE_WIDTH 4 /* DCS_STARTUP_COMPLETE - [3:0] */
1360
1361/*
1362 * R96 (0x60) - Analogue HP (1)
1363 */
1364#define WM8995_HPOUT1L_RMV_SHORT 0x0080 /* HPOUT1L_RMV_SHORT */
1365#define WM8995_HPOUT1L_RMV_SHORT_MASK 0x0080 /* HPOUT1L_RMV_SHORT */
1366#define WM8995_HPOUT1L_RMV_SHORT_SHIFT 7 /* HPOUT1L_RMV_SHORT */
1367#define WM8995_HPOUT1L_RMV_SHORT_WIDTH 1 /* HPOUT1L_RMV_SHORT */
1368#define WM8995_HPOUT1L_OUTP 0x0040 /* HPOUT1L_OUTP */
1369#define WM8995_HPOUT1L_OUTP_MASK 0x0040 /* HPOUT1L_OUTP */
1370#define WM8995_HPOUT1L_OUTP_SHIFT 6 /* HPOUT1L_OUTP */
1371#define WM8995_HPOUT1L_OUTP_WIDTH 1 /* HPOUT1L_OUTP */
1372#define WM8995_HPOUT1L_DLY 0x0020 /* HPOUT1L_DLY */
1373#define WM8995_HPOUT1L_DLY_MASK 0x0020 /* HPOUT1L_DLY */
1374#define WM8995_HPOUT1L_DLY_SHIFT 5 /* HPOUT1L_DLY */
1375#define WM8995_HPOUT1L_DLY_WIDTH 1 /* HPOUT1L_DLY */
1376#define WM8995_HPOUT1R_RMV_SHORT 0x0008 /* HPOUT1R_RMV_SHORT */
1377#define WM8995_HPOUT1R_RMV_SHORT_MASK 0x0008 /* HPOUT1R_RMV_SHORT */
1378#define WM8995_HPOUT1R_RMV_SHORT_SHIFT 3 /* HPOUT1R_RMV_SHORT */
1379#define WM8995_HPOUT1R_RMV_SHORT_WIDTH 1 /* HPOUT1R_RMV_SHORT */
1380#define WM8995_HPOUT1R_OUTP 0x0004 /* HPOUT1R_OUTP */
1381#define WM8995_HPOUT1R_OUTP_MASK 0x0004 /* HPOUT1R_OUTP */
1382#define WM8995_HPOUT1R_OUTP_SHIFT 2 /* HPOUT1R_OUTP */
1383#define WM8995_HPOUT1R_OUTP_WIDTH 1 /* HPOUT1R_OUTP */
1384#define WM8995_HPOUT1R_DLY 0x0002 /* HPOUT1R_DLY */
1385#define WM8995_HPOUT1R_DLY_MASK 0x0002 /* HPOUT1R_DLY */
1386#define WM8995_HPOUT1R_DLY_SHIFT 1 /* HPOUT1R_DLY */
1387#define WM8995_HPOUT1R_DLY_WIDTH 1 /* HPOUT1R_DLY */
1388
1389/*
1390 * R97 (0x61) - Analogue HP (2)
1391 */
1392#define WM8995_HPOUT2L_RMV_SHORT 0x0080 /* HPOUT2L_RMV_SHORT */
1393#define WM8995_HPOUT2L_RMV_SHORT_MASK 0x0080 /* HPOUT2L_RMV_SHORT */
1394#define WM8995_HPOUT2L_RMV_SHORT_SHIFT 7 /* HPOUT2L_RMV_SHORT */
1395#define WM8995_HPOUT2L_RMV_SHORT_WIDTH 1 /* HPOUT2L_RMV_SHORT */
1396#define WM8995_HPOUT2L_OUTP 0x0040 /* HPOUT2L_OUTP */
1397#define WM8995_HPOUT2L_OUTP_MASK 0x0040 /* HPOUT2L_OUTP */
1398#define WM8995_HPOUT2L_OUTP_SHIFT 6 /* HPOUT2L_OUTP */
1399#define WM8995_HPOUT2L_OUTP_WIDTH 1 /* HPOUT2L_OUTP */
1400#define WM8995_HPOUT2L_DLY 0x0020 /* HPOUT2L_DLY */
1401#define WM8995_HPOUT2L_DLY_MASK 0x0020 /* HPOUT2L_DLY */
1402#define WM8995_HPOUT2L_DLY_SHIFT 5 /* HPOUT2L_DLY */
1403#define WM8995_HPOUT2L_DLY_WIDTH 1 /* HPOUT2L_DLY */
1404#define WM8995_HPOUT2R_RMV_SHORT 0x0008 /* HPOUT2R_RMV_SHORT */
1405#define WM8995_HPOUT2R_RMV_SHORT_MASK 0x0008 /* HPOUT2R_RMV_SHORT */
1406#define WM8995_HPOUT2R_RMV_SHORT_SHIFT 3 /* HPOUT2R_RMV_SHORT */
1407#define WM8995_HPOUT2R_RMV_SHORT_WIDTH 1 /* HPOUT2R_RMV_SHORT */
1408#define WM8995_HPOUT2R_OUTP 0x0004 /* HPOUT2R_OUTP */
1409#define WM8995_HPOUT2R_OUTP_MASK 0x0004 /* HPOUT2R_OUTP */
1410#define WM8995_HPOUT2R_OUTP_SHIFT 2 /* HPOUT2R_OUTP */
1411#define WM8995_HPOUT2R_OUTP_WIDTH 1 /* HPOUT2R_OUTP */
1412#define WM8995_HPOUT2R_DLY 0x0002 /* HPOUT2R_DLY */
1413#define WM8995_HPOUT2R_DLY_MASK 0x0002 /* HPOUT2R_DLY */
1414#define WM8995_HPOUT2R_DLY_SHIFT 1 /* HPOUT2R_DLY */
1415#define WM8995_HPOUT2R_DLY_WIDTH 1 /* HPOUT2R_DLY */
1416
1417/*
1418 * R256 (0x100) - Chip Revision
1419 */
1420#define WM8995_CHIP_REV_MASK 0x000F /* CHIP_REV - [3:0] */
1421#define WM8995_CHIP_REV_SHIFT 0 /* CHIP_REV - [3:0] */
1422#define WM8995_CHIP_REV_WIDTH 4 /* CHIP_REV - [3:0] */
1423
1424/*
1425 * R257 (0x101) - Control Interface (1)
1426 */
1427#define WM8995_REG_SYNC 0x8000 /* REG_SYNC */
1428#define WM8995_REG_SYNC_MASK 0x8000 /* REG_SYNC */
1429#define WM8995_REG_SYNC_SHIFT 15 /* REG_SYNC */
1430#define WM8995_REG_SYNC_WIDTH 1 /* REG_SYNC */
1431#define WM8995_SPI_CONTRD 0x0040 /* SPI_CONTRD */
1432#define WM8995_SPI_CONTRD_MASK 0x0040 /* SPI_CONTRD */
1433#define WM8995_SPI_CONTRD_SHIFT 6 /* SPI_CONTRD */
1434#define WM8995_SPI_CONTRD_WIDTH 1 /* SPI_CONTRD */
1435#define WM8995_SPI_4WIRE 0x0020 /* SPI_4WIRE */
1436#define WM8995_SPI_4WIRE_MASK 0x0020 /* SPI_4WIRE */
1437#define WM8995_SPI_4WIRE_SHIFT 5 /* SPI_4WIRE */
1438#define WM8995_SPI_4WIRE_WIDTH 1 /* SPI_4WIRE */
1439#define WM8995_SPI_CFG 0x0010 /* SPI_CFG */
1440#define WM8995_SPI_CFG_MASK 0x0010 /* SPI_CFG */
1441#define WM8995_SPI_CFG_SHIFT 4 /* SPI_CFG */
1442#define WM8995_SPI_CFG_WIDTH 1 /* SPI_CFG */
1443#define WM8995_AUTO_INC 0x0004 /* AUTO_INC */
1444#define WM8995_AUTO_INC_MASK 0x0004 /* AUTO_INC */
1445#define WM8995_AUTO_INC_SHIFT 2 /* AUTO_INC */
1446#define WM8995_AUTO_INC_WIDTH 1 /* AUTO_INC */
1447
1448/*
1449 * R258 (0x102) - Control Interface (2)
1450 */
1451#define WM8995_CTRL_IF_SRC 0x0001 /* CTRL_IF_SRC */
1452#define WM8995_CTRL_IF_SRC_MASK 0x0001 /* CTRL_IF_SRC */
1453#define WM8995_CTRL_IF_SRC_SHIFT 0 /* CTRL_IF_SRC */
1454#define WM8995_CTRL_IF_SRC_WIDTH 1 /* CTRL_IF_SRC */
1455
1456/*
1457 * R272 (0x110) - Write Sequencer Ctrl (1)
1458 */
1459#define WM8995_WSEQ_ENA 0x8000 /* WSEQ_ENA */
1460#define WM8995_WSEQ_ENA_MASK 0x8000 /* WSEQ_ENA */
1461#define WM8995_WSEQ_ENA_SHIFT 15 /* WSEQ_ENA */
1462#define WM8995_WSEQ_ENA_WIDTH 1 /* WSEQ_ENA */
1463#define WM8995_WSEQ_ABORT 0x0200 /* WSEQ_ABORT */
1464#define WM8995_WSEQ_ABORT_MASK 0x0200 /* WSEQ_ABORT */
1465#define WM8995_WSEQ_ABORT_SHIFT 9 /* WSEQ_ABORT */
1466#define WM8995_WSEQ_ABORT_WIDTH 1 /* WSEQ_ABORT */
1467#define WM8995_WSEQ_START 0x0100 /* WSEQ_START */
1468#define WM8995_WSEQ_START_MASK 0x0100 /* WSEQ_START */
1469#define WM8995_WSEQ_START_SHIFT 8 /* WSEQ_START */
1470#define WM8995_WSEQ_START_WIDTH 1 /* WSEQ_START */
1471#define WM8995_WSEQ_START_INDEX_MASK 0x007F /* WSEQ_START_INDEX - [6:0] */
1472#define WM8995_WSEQ_START_INDEX_SHIFT 0 /* WSEQ_START_INDEX - [6:0] */
1473#define WM8995_WSEQ_START_INDEX_WIDTH 7 /* WSEQ_START_INDEX - [6:0] */
1474
1475/*
1476 * R273 (0x111) - Write Sequencer Ctrl (2)
1477 */
1478#define WM8995_WSEQ_BUSY 0x0100 /* WSEQ_BUSY */
1479#define WM8995_WSEQ_BUSY_MASK 0x0100 /* WSEQ_BUSY */
1480#define WM8995_WSEQ_BUSY_SHIFT 8 /* WSEQ_BUSY */
1481#define WM8995_WSEQ_BUSY_WIDTH 1 /* WSEQ_BUSY */
1482#define WM8995_WSEQ_CURRENT_INDEX_MASK 0x007F /* WSEQ_CURRENT_INDEX - [6:0] */
1483#define WM8995_WSEQ_CURRENT_INDEX_SHIFT 0 /* WSEQ_CURRENT_INDEX - [6:0] */
1484#define WM8995_WSEQ_CURRENT_INDEX_WIDTH 7 /* WSEQ_CURRENT_INDEX - [6:0] */
1485
1486/*
1487 * R512 (0x200) - AIF1 Clocking (1)
1488 */
1489#define WM8995_AIF1CLK_SRC_MASK 0x0018 /* AIF1CLK_SRC - [4:3] */
1490#define WM8995_AIF1CLK_SRC_SHIFT 3 /* AIF1CLK_SRC - [4:3] */
1491#define WM8995_AIF1CLK_SRC_WIDTH 2 /* AIF1CLK_SRC - [4:3] */
1492#define WM8995_AIF1CLK_INV 0x0004 /* AIF1CLK_INV */
1493#define WM8995_AIF1CLK_INV_MASK 0x0004 /* AIF1CLK_INV */
1494#define WM8995_AIF1CLK_INV_SHIFT 2 /* AIF1CLK_INV */
1495#define WM8995_AIF1CLK_INV_WIDTH 1 /* AIF1CLK_INV */
1496#define WM8995_AIF1CLK_DIV 0x0002 /* AIF1CLK_DIV */
1497#define WM8995_AIF1CLK_DIV_MASK 0x0002 /* AIF1CLK_DIV */
1498#define WM8995_AIF1CLK_DIV_SHIFT 1 /* AIF1CLK_DIV */
1499#define WM8995_AIF1CLK_DIV_WIDTH 1 /* AIF1CLK_DIV */
1500#define WM8995_AIF1CLK_ENA 0x0001 /* AIF1CLK_ENA */
1501#define WM8995_AIF1CLK_ENA_MASK 0x0001 /* AIF1CLK_ENA */
1502#define WM8995_AIF1CLK_ENA_SHIFT 0 /* AIF1CLK_ENA */
1503#define WM8995_AIF1CLK_ENA_WIDTH 1 /* AIF1CLK_ENA */
1504
1505/*
1506 * R513 (0x201) - AIF1 Clocking (2)
1507 */
1508#define WM8995_AIF1DAC_DIV_MASK 0x0038 /* AIF1DAC_DIV - [5:3] */
1509#define WM8995_AIF1DAC_DIV_SHIFT 3 /* AIF1DAC_DIV - [5:3] */
1510#define WM8995_AIF1DAC_DIV_WIDTH 3 /* AIF1DAC_DIV - [5:3] */
1511#define WM8995_AIF1ADC_DIV_MASK 0x0007 /* AIF1ADC_DIV - [2:0] */
1512#define WM8995_AIF1ADC_DIV_SHIFT 0 /* AIF1ADC_DIV - [2:0] */
1513#define WM8995_AIF1ADC_DIV_WIDTH 3 /* AIF1ADC_DIV - [2:0] */
1514
1515/*
1516 * R516 (0x204) - AIF2 Clocking (1)
1517 */
1518#define WM8995_AIF2CLK_SRC_MASK 0x0018 /* AIF2CLK_SRC - [4:3] */
1519#define WM8995_AIF2CLK_SRC_SHIFT 3 /* AIF2CLK_SRC - [4:3] */
1520#define WM8995_AIF2CLK_SRC_WIDTH 2 /* AIF2CLK_SRC - [4:3] */
1521#define WM8995_AIF2CLK_INV 0x0004 /* AIF2CLK_INV */
1522#define WM8995_AIF2CLK_INV_MASK 0x0004 /* AIF2CLK_INV */
1523#define WM8995_AIF2CLK_INV_SHIFT 2 /* AIF2CLK_INV */
1524#define WM8995_AIF2CLK_INV_WIDTH 1 /* AIF2CLK_INV */
1525#define WM8995_AIF2CLK_DIV 0x0002 /* AIF2CLK_DIV */
1526#define WM8995_AIF2CLK_DIV_MASK 0x0002 /* AIF2CLK_DIV */
1527#define WM8995_AIF2CLK_DIV_SHIFT 1 /* AIF2CLK_DIV */
1528#define WM8995_AIF2CLK_DIV_WIDTH 1 /* AIF2CLK_DIV */
1529#define WM8995_AIF2CLK_ENA 0x0001 /* AIF2CLK_ENA */
1530#define WM8995_AIF2CLK_ENA_MASK 0x0001 /* AIF2CLK_ENA */
1531#define WM8995_AIF2CLK_ENA_SHIFT 0 /* AIF2CLK_ENA */
1532#define WM8995_AIF2CLK_ENA_WIDTH 1 /* AIF2CLK_ENA */
1533
1534/*
1535 * R517 (0x205) - AIF2 Clocking (2)
1536 */
1537#define WM8995_AIF2DAC_DIV_MASK 0x0038 /* AIF2DAC_DIV - [5:3] */
1538#define WM8995_AIF2DAC_DIV_SHIFT 3 /* AIF2DAC_DIV - [5:3] */
1539#define WM8995_AIF2DAC_DIV_WIDTH 3 /* AIF2DAC_DIV - [5:3] */
1540#define WM8995_AIF2ADC_DIV_MASK 0x0007 /* AIF2ADC_DIV - [2:0] */
1541#define WM8995_AIF2ADC_DIV_SHIFT 0 /* AIF2ADC_DIV - [2:0] */
1542#define WM8995_AIF2ADC_DIV_WIDTH 3 /* AIF2ADC_DIV - [2:0] */
1543
1544/*
1545 * R520 (0x208) - Clocking (1)
1546 */
1547#define WM8995_LFCLK_ENA 0x0020 /* LFCLK_ENA */
1548#define WM8995_LFCLK_ENA_MASK 0x0020 /* LFCLK_ENA */
1549#define WM8995_LFCLK_ENA_SHIFT 5 /* LFCLK_ENA */
1550#define WM8995_LFCLK_ENA_WIDTH 1 /* LFCLK_ENA */
1551#define WM8995_TOCLK_ENA 0x0010 /* TOCLK_ENA */
1552#define WM8995_TOCLK_ENA_MASK 0x0010 /* TOCLK_ENA */
1553#define WM8995_TOCLK_ENA_SHIFT 4 /* TOCLK_ENA */
1554#define WM8995_TOCLK_ENA_WIDTH 1 /* TOCLK_ENA */
1555#define WM8995_AIF1DSPCLK_ENA 0x0008 /* AIF1DSPCLK_ENA */
1556#define WM8995_AIF1DSPCLK_ENA_MASK 0x0008 /* AIF1DSPCLK_ENA */
1557#define WM8995_AIF1DSPCLK_ENA_SHIFT 3 /* AIF1DSPCLK_ENA */
1558#define WM8995_AIF1DSPCLK_ENA_WIDTH 1 /* AIF1DSPCLK_ENA */
1559#define WM8995_AIF2DSPCLK_ENA 0x0004 /* AIF2DSPCLK_ENA */
1560#define WM8995_AIF2DSPCLK_ENA_MASK 0x0004 /* AIF2DSPCLK_ENA */
1561#define WM8995_AIF2DSPCLK_ENA_SHIFT 2 /* AIF2DSPCLK_ENA */
1562#define WM8995_AIF2DSPCLK_ENA_WIDTH 1 /* AIF2DSPCLK_ENA */
1563#define WM8995_SYSDSPCLK_ENA 0x0002 /* SYSDSPCLK_ENA */
1564#define WM8995_SYSDSPCLK_ENA_MASK 0x0002 /* SYSDSPCLK_ENA */
1565#define WM8995_SYSDSPCLK_ENA_SHIFT 1 /* SYSDSPCLK_ENA */
1566#define WM8995_SYSDSPCLK_ENA_WIDTH 1 /* SYSDSPCLK_ENA */
1567#define WM8995_SYSCLK_SRC 0x0001 /* SYSCLK_SRC */
1568#define WM8995_SYSCLK_SRC_MASK 0x0001 /* SYSCLK_SRC */
1569#define WM8995_SYSCLK_SRC_SHIFT 0 /* SYSCLK_SRC */
1570#define WM8995_SYSCLK_SRC_WIDTH 1 /* SYSCLK_SRC */
1571
1572/*
1573 * R521 (0x209) - Clocking (2)
1574 */
1575#define WM8995_TOCLK_DIV_MASK 0x0700 /* TOCLK_DIV - [10:8] */
1576#define WM8995_TOCLK_DIV_SHIFT 8 /* TOCLK_DIV - [10:8] */
1577#define WM8995_TOCLK_DIV_WIDTH 3 /* TOCLK_DIV - [10:8] */
1578#define WM8995_DBCLK_DIV_MASK 0x00F0 /* DBCLK_DIV - [7:4] */
1579#define WM8995_DBCLK_DIV_SHIFT 4 /* DBCLK_DIV - [7:4] */
1580#define WM8995_DBCLK_DIV_WIDTH 4 /* DBCLK_DIV - [7:4] */
1581#define WM8995_OPCLK_DIV_MASK 0x0007 /* OPCLK_DIV - [2:0] */
1582#define WM8995_OPCLK_DIV_SHIFT 0 /* OPCLK_DIV - [2:0] */
1583#define WM8995_OPCLK_DIV_WIDTH 3 /* OPCLK_DIV - [2:0] */
1584
1585/*
1586 * R528 (0x210) - AIF1 Rate
1587 */
1588#define WM8995_AIF1_SR_MASK 0x00F0 /* AIF1_SR - [7:4] */
1589#define WM8995_AIF1_SR_SHIFT 4 /* AIF1_SR - [7:4] */
1590#define WM8995_AIF1_SR_WIDTH 4 /* AIF1_SR - [7:4] */
1591#define WM8995_AIF1CLK_RATE_MASK 0x000F /* AIF1CLK_RATE - [3:0] */
1592#define WM8995_AIF1CLK_RATE_SHIFT 0 /* AIF1CLK_RATE - [3:0] */
1593#define WM8995_AIF1CLK_RATE_WIDTH 4 /* AIF1CLK_RATE - [3:0] */
1594
1595/*
1596 * R529 (0x211) - AIF2 Rate
1597 */
1598#define WM8995_AIF2_SR_MASK 0x00F0 /* AIF2_SR - [7:4] */
1599#define WM8995_AIF2_SR_SHIFT 4 /* AIF2_SR - [7:4] */
1600#define WM8995_AIF2_SR_WIDTH 4 /* AIF2_SR - [7:4] */
1601#define WM8995_AIF2CLK_RATE_MASK 0x000F /* AIF2CLK_RATE - [3:0] */
1602#define WM8995_AIF2CLK_RATE_SHIFT 0 /* AIF2CLK_RATE - [3:0] */
1603#define WM8995_AIF2CLK_RATE_WIDTH 4 /* AIF2CLK_RATE - [3:0] */
1604
1605/*
1606 * R530 (0x212) - Rate Status
1607 */
1608#define WM8995_SR_ERROR_MASK 0x000F /* SR_ERROR - [3:0] */
1609#define WM8995_SR_ERROR_SHIFT 0 /* SR_ERROR - [3:0] */
1610#define WM8995_SR_ERROR_WIDTH 4 /* SR_ERROR - [3:0] */
1611
1612/*
1613 * R544 (0x220) - FLL1 Control (1)
1614 */
1615#define WM8995_FLL1_OSC_ENA 0x0002 /* FLL1_OSC_ENA */
1616#define WM8995_FLL1_OSC_ENA_MASK 0x0002 /* FLL1_OSC_ENA */
1617#define WM8995_FLL1_OSC_ENA_SHIFT 1 /* FLL1_OSC_ENA */
1618#define WM8995_FLL1_OSC_ENA_WIDTH 1 /* FLL1_OSC_ENA */
1619#define WM8995_FLL1_ENA 0x0001 /* FLL1_ENA */
1620#define WM8995_FLL1_ENA_MASK 0x0001 /* FLL1_ENA */
1621#define WM8995_FLL1_ENA_SHIFT 0 /* FLL1_ENA */
1622#define WM8995_FLL1_ENA_WIDTH 1 /* FLL1_ENA */
1623
1624/*
1625 * R545 (0x221) - FLL1 Control (2)
1626 */
1627#define WM8995_FLL1_OUTDIV_MASK 0x3F00 /* FLL1_OUTDIV - [13:8] */
1628#define WM8995_FLL1_OUTDIV_SHIFT 8 /* FLL1_OUTDIV - [13:8] */
1629#define WM8995_FLL1_OUTDIV_WIDTH 6 /* FLL1_OUTDIV - [13:8] */
1630#define WM8995_FLL1_CTRL_RATE_MASK 0x0070 /* FLL1_CTRL_RATE - [6:4] */
1631#define WM8995_FLL1_CTRL_RATE_SHIFT 4 /* FLL1_CTRL_RATE - [6:4] */
1632#define WM8995_FLL1_CTRL_RATE_WIDTH 3 /* FLL1_CTRL_RATE - [6:4] */
1633#define WM8995_FLL1_FRATIO_MASK 0x0007 /* FLL1_FRATIO - [2:0] */
1634#define WM8995_FLL1_FRATIO_SHIFT 0 /* FLL1_FRATIO - [2:0] */
1635#define WM8995_FLL1_FRATIO_WIDTH 3 /* FLL1_FRATIO - [2:0] */
1636
1637/*
1638 * R546 (0x222) - FLL1 Control (3)
1639 */
1640#define WM8995_FLL1_K_MASK 0xFFFF /* FLL1_K - [15:0] */
1641#define WM8995_FLL1_K_SHIFT 0 /* FLL1_K - [15:0] */
1642#define WM8995_FLL1_K_WIDTH 16 /* FLL1_K - [15:0] */
1643
1644/*
1645 * R547 (0x223) - FLL1 Control (4)
1646 */
1647#define WM8995_FLL1_N_MASK 0x7FE0 /* FLL1_N - [14:5] */
1648#define WM8995_FLL1_N_SHIFT 5 /* FLL1_N - [14:5] */
1649#define WM8995_FLL1_N_WIDTH 10 /* FLL1_N - [14:5] */
1650#define WM8995_FLL1_LOOP_GAIN_MASK 0x000F /* FLL1_LOOP_GAIN - [3:0] */
1651#define WM8995_FLL1_LOOP_GAIN_SHIFT 0 /* FLL1_LOOP_GAIN - [3:0] */
1652#define WM8995_FLL1_LOOP_GAIN_WIDTH 4 /* FLL1_LOOP_GAIN - [3:0] */
1653
1654/*
1655 * R548 (0x224) - FLL1 Control (5)
1656 */
1657#define WM8995_FLL1_FRC_NCO_VAL_MASK 0x1F80 /* FLL1_FRC_NCO_VAL - [12:7] */
1658#define WM8995_FLL1_FRC_NCO_VAL_SHIFT 7 /* FLL1_FRC_NCO_VAL - [12:7] */
1659#define WM8995_FLL1_FRC_NCO_VAL_WIDTH 6 /* FLL1_FRC_NCO_VAL - [12:7] */
1660#define WM8995_FLL1_FRC_NCO 0x0040 /* FLL1_FRC_NCO */
1661#define WM8995_FLL1_FRC_NCO_MASK 0x0040 /* FLL1_FRC_NCO */
1662#define WM8995_FLL1_FRC_NCO_SHIFT 6 /* FLL1_FRC_NCO */
1663#define WM8995_FLL1_FRC_NCO_WIDTH 1 /* FLL1_FRC_NCO */
1664#define WM8995_FLL1_REFCLK_DIV_MASK 0x0018 /* FLL1_REFCLK_DIV - [4:3] */
1665#define WM8995_FLL1_REFCLK_DIV_SHIFT 3 /* FLL1_REFCLK_DIV - [4:3] */
1666#define WM8995_FLL1_REFCLK_DIV_WIDTH 2 /* FLL1_REFCLK_DIV - [4:3] */
1667#define WM8995_FLL1_REFCLK_SRC_MASK 0x0003 /* FLL1_REFCLK_SRC - [1:0] */
1668#define WM8995_FLL1_REFCLK_SRC_SHIFT 0 /* FLL1_REFCLK_SRC - [1:0] */
1669#define WM8995_FLL1_REFCLK_SRC_WIDTH 2 /* FLL1_REFCLK_SRC - [1:0] */
1670
1671/*
1672 * R576 (0x240) - FLL2 Control (1)
1673 */
1674#define WM8995_FLL2_OSC_ENA 0x0002 /* FLL2_OSC_ENA */
1675#define WM8995_FLL2_OSC_ENA_MASK 0x0002 /* FLL2_OSC_ENA */
1676#define WM8995_FLL2_OSC_ENA_SHIFT 1 /* FLL2_OSC_ENA */
1677#define WM8995_FLL2_OSC_ENA_WIDTH 1 /* FLL2_OSC_ENA */
1678#define WM8995_FLL2_ENA 0x0001 /* FLL2_ENA */
1679#define WM8995_FLL2_ENA_MASK 0x0001 /* FLL2_ENA */
1680#define WM8995_FLL2_ENA_SHIFT 0 /* FLL2_ENA */
1681#define WM8995_FLL2_ENA_WIDTH 1 /* FLL2_ENA */
1682
1683/*
1684 * R577 (0x241) - FLL2 Control (2)
1685 */
1686#define WM8995_FLL2_OUTDIV_MASK 0x3F00 /* FLL2_OUTDIV - [13:8] */
1687#define WM8995_FLL2_OUTDIV_SHIFT 8 /* FLL2_OUTDIV - [13:8] */
1688#define WM8995_FLL2_OUTDIV_WIDTH 6 /* FLL2_OUTDIV - [13:8] */
1689#define WM8995_FLL2_CTRL_RATE_MASK 0x0070 /* FLL2_CTRL_RATE - [6:4] */
1690#define WM8995_FLL2_CTRL_RATE_SHIFT 4 /* FLL2_CTRL_RATE - [6:4] */
1691#define WM8995_FLL2_CTRL_RATE_WIDTH 3 /* FLL2_CTRL_RATE - [6:4] */
1692#define WM8995_FLL2_FRATIO_MASK 0x0007 /* FLL2_FRATIO - [2:0] */
1693#define WM8995_FLL2_FRATIO_SHIFT 0 /* FLL2_FRATIO - [2:0] */
1694#define WM8995_FLL2_FRATIO_WIDTH 3 /* FLL2_FRATIO - [2:0] */
1695
1696/*
1697 * R578 (0x242) - FLL2 Control (3)
1698 */
1699#define WM8995_FLL2_K_MASK 0xFFFF /* FLL2_K - [15:0] */
1700#define WM8995_FLL2_K_SHIFT 0 /* FLL2_K - [15:0] */
1701#define WM8995_FLL2_K_WIDTH 16 /* FLL2_K - [15:0] */
1702
1703/*
1704 * R579 (0x243) - FLL2 Control (4)
1705 */
1706#define WM8995_FLL2_N_MASK 0x7FE0 /* FLL2_N - [14:5] */
1707#define WM8995_FLL2_N_SHIFT 5 /* FLL2_N - [14:5] */
1708#define WM8995_FLL2_N_WIDTH 10 /* FLL2_N - [14:5] */
1709#define WM8995_FLL2_LOOP_GAIN_MASK 0x000F /* FLL2_LOOP_GAIN - [3:0] */
1710#define WM8995_FLL2_LOOP_GAIN_SHIFT 0 /* FLL2_LOOP_GAIN - [3:0] */
1711#define WM8995_FLL2_LOOP_GAIN_WIDTH 4 /* FLL2_LOOP_GAIN - [3:0] */
1712
1713/*
1714 * R580 (0x244) - FLL2 Control (5)
1715 */
1716#define WM8995_FLL2_FRC_NCO_VAL_MASK 0x1F80 /* FLL2_FRC_NCO_VAL - [12:7] */
1717#define WM8995_FLL2_FRC_NCO_VAL_SHIFT 7 /* FLL2_FRC_NCO_VAL - [12:7] */
1718#define WM8995_FLL2_FRC_NCO_VAL_WIDTH 6 /* FLL2_FRC_NCO_VAL - [12:7] */
1719#define WM8995_FLL2_FRC_NCO 0x0040 /* FLL2_FRC_NCO */
1720#define WM8995_FLL2_FRC_NCO_MASK 0x0040 /* FLL2_FRC_NCO */
1721#define WM8995_FLL2_FRC_NCO_SHIFT 6 /* FLL2_FRC_NCO */
1722#define WM8995_FLL2_FRC_NCO_WIDTH 1 /* FLL2_FRC_NCO */
1723#define WM8995_FLL2_REFCLK_DIV_MASK 0x0018 /* FLL2_REFCLK_DIV - [4:3] */
1724#define WM8995_FLL2_REFCLK_DIV_SHIFT 3 /* FLL2_REFCLK_DIV - [4:3] */
1725#define WM8995_FLL2_REFCLK_DIV_WIDTH 2 /* FLL2_REFCLK_DIV - [4:3] */
1726#define WM8995_FLL2_REFCLK_SRC_MASK 0x0003 /* FLL2_REFCLK_SRC - [1:0] */
1727#define WM8995_FLL2_REFCLK_SRC_SHIFT 0 /* FLL2_REFCLK_SRC - [1:0] */
1728#define WM8995_FLL2_REFCLK_SRC_WIDTH 2 /* FLL2_REFCLK_SRC - [1:0] */
1729
1730/*
1731 * R768 (0x300) - AIF1 Control (1)
1732 */
1733#define WM8995_AIF1ADCL_SRC 0x8000 /* AIF1ADCL_SRC */
1734#define WM8995_AIF1ADCL_SRC_MASK 0x8000 /* AIF1ADCL_SRC */
1735#define WM8995_AIF1ADCL_SRC_SHIFT 15 /* AIF1ADCL_SRC */
1736#define WM8995_AIF1ADCL_SRC_WIDTH 1 /* AIF1ADCL_SRC */
1737#define WM8995_AIF1ADCR_SRC 0x4000 /* AIF1ADCR_SRC */
1738#define WM8995_AIF1ADCR_SRC_MASK 0x4000 /* AIF1ADCR_SRC */
1739#define WM8995_AIF1ADCR_SRC_SHIFT 14 /* AIF1ADCR_SRC */
1740#define WM8995_AIF1ADCR_SRC_WIDTH 1 /* AIF1ADCR_SRC */
1741#define WM8995_AIF1ADC_TDM 0x2000 /* AIF1ADC_TDM */
1742#define WM8995_AIF1ADC_TDM_MASK 0x2000 /* AIF1ADC_TDM */
1743#define WM8995_AIF1ADC_TDM_SHIFT 13 /* AIF1ADC_TDM */
1744#define WM8995_AIF1ADC_TDM_WIDTH 1 /* AIF1ADC_TDM */
1745#define WM8995_AIF1_BCLK_INV 0x0100 /* AIF1_BCLK_INV */
1746#define WM8995_AIF1_BCLK_INV_MASK 0x0100 /* AIF1_BCLK_INV */
1747#define WM8995_AIF1_BCLK_INV_SHIFT 8 /* AIF1_BCLK_INV */
1748#define WM8995_AIF1_BCLK_INV_WIDTH 1 /* AIF1_BCLK_INV */
1749#define WM8995_AIF1_LRCLK_INV 0x0080 /* AIF1_LRCLK_INV */
1750#define WM8995_AIF1_LRCLK_INV_MASK 0x0080 /* AIF1_LRCLK_INV */
1751#define WM8995_AIF1_LRCLK_INV_SHIFT 7 /* AIF1_LRCLK_INV */
1752#define WM8995_AIF1_LRCLK_INV_WIDTH 1 /* AIF1_LRCLK_INV */
1753#define WM8995_AIF1_WL_MASK 0x0060 /* AIF1_WL - [6:5] */
1754#define WM8995_AIF1_WL_SHIFT 5 /* AIF1_WL - [6:5] */
1755#define WM8995_AIF1_WL_WIDTH 2 /* AIF1_WL - [6:5] */
1756#define WM8995_AIF1_FMT_MASK 0x0018 /* AIF1_FMT - [4:3] */
1757#define WM8995_AIF1_FMT_SHIFT 3 /* AIF1_FMT - [4:3] */
1758#define WM8995_AIF1_FMT_WIDTH 2 /* AIF1_FMT - [4:3] */
1759
1760/*
1761 * R769 (0x301) - AIF1 Control (2)
1762 */
1763#define WM8995_AIF1DACL_SRC 0x8000 /* AIF1DACL_SRC */
1764#define WM8995_AIF1DACL_SRC_MASK 0x8000 /* AIF1DACL_SRC */
1765#define WM8995_AIF1DACL_SRC_SHIFT 15 /* AIF1DACL_SRC */
1766#define WM8995_AIF1DACL_SRC_WIDTH 1 /* AIF1DACL_SRC */
1767#define WM8995_AIF1DACR_SRC 0x4000 /* AIF1DACR_SRC */
1768#define WM8995_AIF1DACR_SRC_MASK 0x4000 /* AIF1DACR_SRC */
1769#define WM8995_AIF1DACR_SRC_SHIFT 14 /* AIF1DACR_SRC */
1770#define WM8995_AIF1DACR_SRC_WIDTH 1 /* AIF1DACR_SRC */
1771#define WM8995_AIF1DAC_BOOST_MASK 0x0C00 /* AIF1DAC_BOOST - [11:10] */
1772#define WM8995_AIF1DAC_BOOST_SHIFT 10 /* AIF1DAC_BOOST - [11:10] */
1773#define WM8995_AIF1DAC_BOOST_WIDTH 2 /* AIF1DAC_BOOST - [11:10] */
1774#define WM8995_AIF1DAC_COMP 0x0010 /* AIF1DAC_COMP */
1775#define WM8995_AIF1DAC_COMP_MASK 0x0010 /* AIF1DAC_COMP */
1776#define WM8995_AIF1DAC_COMP_SHIFT 4 /* AIF1DAC_COMP */
1777#define WM8995_AIF1DAC_COMP_WIDTH 1 /* AIF1DAC_COMP */
1778#define WM8995_AIF1DAC_COMPMODE 0x0008 /* AIF1DAC_COMPMODE */
1779#define WM8995_AIF1DAC_COMPMODE_MASK 0x0008 /* AIF1DAC_COMPMODE */
1780#define WM8995_AIF1DAC_COMPMODE_SHIFT 3 /* AIF1DAC_COMPMODE */
1781#define WM8995_AIF1DAC_COMPMODE_WIDTH 1 /* AIF1DAC_COMPMODE */
1782#define WM8995_AIF1ADC_COMP 0x0004 /* AIF1ADC_COMP */
1783#define WM8995_AIF1ADC_COMP_MASK 0x0004 /* AIF1ADC_COMP */
1784#define WM8995_AIF1ADC_COMP_SHIFT 2 /* AIF1ADC_COMP */
1785#define WM8995_AIF1ADC_COMP_WIDTH 1 /* AIF1ADC_COMP */
1786#define WM8995_AIF1ADC_COMPMODE 0x0002 /* AIF1ADC_COMPMODE */
1787#define WM8995_AIF1ADC_COMPMODE_MASK 0x0002 /* AIF1ADC_COMPMODE */
1788#define WM8995_AIF1ADC_COMPMODE_SHIFT 1 /* AIF1ADC_COMPMODE */
1789#define WM8995_AIF1ADC_COMPMODE_WIDTH 1 /* AIF1ADC_COMPMODE */
1790#define WM8995_AIF1_LOOPBACK 0x0001 /* AIF1_LOOPBACK */
1791#define WM8995_AIF1_LOOPBACK_MASK 0x0001 /* AIF1_LOOPBACK */
1792#define WM8995_AIF1_LOOPBACK_SHIFT 0 /* AIF1_LOOPBACK */
1793#define WM8995_AIF1_LOOPBACK_WIDTH 1 /* AIF1_LOOPBACK */
1794
1795/*
1796 * R770 (0x302) - AIF1 Master/Slave
1797 */
1798#define WM8995_AIF1_TRI 0x8000 /* AIF1_TRI */
1799#define WM8995_AIF1_TRI_MASK 0x8000 /* AIF1_TRI */
1800#define WM8995_AIF1_TRI_SHIFT 15 /* AIF1_TRI */
1801#define WM8995_AIF1_TRI_WIDTH 1 /* AIF1_TRI */
1802#define WM8995_AIF1_MSTR 0x4000 /* AIF1_MSTR */
1803#define WM8995_AIF1_MSTR_MASK 0x4000 /* AIF1_MSTR */
1804#define WM8995_AIF1_MSTR_SHIFT 14 /* AIF1_MSTR */
1805#define WM8995_AIF1_MSTR_WIDTH 1 /* AIF1_MSTR */
1806#define WM8995_AIF1_CLK_FRC 0x2000 /* AIF1_CLK_FRC */
1807#define WM8995_AIF1_CLK_FRC_MASK 0x2000 /* AIF1_CLK_FRC */
1808#define WM8995_AIF1_CLK_FRC_SHIFT 13 /* AIF1_CLK_FRC */
1809#define WM8995_AIF1_CLK_FRC_WIDTH 1 /* AIF1_CLK_FRC */
1810#define WM8995_AIF1_LRCLK_FRC 0x1000 /* AIF1_LRCLK_FRC */
1811#define WM8995_AIF1_LRCLK_FRC_MASK 0x1000 /* AIF1_LRCLK_FRC */
1812#define WM8995_AIF1_LRCLK_FRC_SHIFT 12 /* AIF1_LRCLK_FRC */
1813#define WM8995_AIF1_LRCLK_FRC_WIDTH 1 /* AIF1_LRCLK_FRC */
1814
1815/*
1816 * R771 (0x303) - AIF1 BCLK
1817 */
1818#define WM8995_AIF1_BCLK_DIV_MASK 0x00F0 /* AIF1_BCLK_DIV - [7:4] */
1819#define WM8995_AIF1_BCLK_DIV_SHIFT 4 /* AIF1_BCLK_DIV - [7:4] */
1820#define WM8995_AIF1_BCLK_DIV_WIDTH 4 /* AIF1_BCLK_DIV - [7:4] */
1821
1822/*
1823 * R772 (0x304) - AIF1ADC LRCLK
1824 */
1825#define WM8995_AIF1ADC_LRCLK_DIR 0x0800 /* AIF1ADC_LRCLK_DIR */
1826#define WM8995_AIF1ADC_LRCLK_DIR_MASK 0x0800 /* AIF1ADC_LRCLK_DIR */
1827#define WM8995_AIF1ADC_LRCLK_DIR_SHIFT 11 /* AIF1ADC_LRCLK_DIR */
1828#define WM8995_AIF1ADC_LRCLK_DIR_WIDTH 1 /* AIF1ADC_LRCLK_DIR */
1829#define WM8995_AIF1ADC_RATE_MASK 0x07FF /* AIF1ADC_RATE - [10:0] */
1830#define WM8995_AIF1ADC_RATE_SHIFT 0 /* AIF1ADC_RATE - [10:0] */
1831#define WM8995_AIF1ADC_RATE_WIDTH 11 /* AIF1ADC_RATE - [10:0] */
1832
1833/*
1834 * R773 (0x305) - AIF1DAC LRCLK
1835 */
1836#define WM8995_AIF1DAC_LRCLK_DIR 0x0800 /* AIF1DAC_LRCLK_DIR */
1837#define WM8995_AIF1DAC_LRCLK_DIR_MASK 0x0800 /* AIF1DAC_LRCLK_DIR */
1838#define WM8995_AIF1DAC_LRCLK_DIR_SHIFT 11 /* AIF1DAC_LRCLK_DIR */
1839#define WM8995_AIF1DAC_LRCLK_DIR_WIDTH 1 /* AIF1DAC_LRCLK_DIR */
1840#define WM8995_AIF1DAC_RATE_MASK 0x07FF /* AIF1DAC_RATE - [10:0] */
1841#define WM8995_AIF1DAC_RATE_SHIFT 0 /* AIF1DAC_RATE - [10:0] */
1842#define WM8995_AIF1DAC_RATE_WIDTH 11 /* AIF1DAC_RATE - [10:0] */
1843
1844/*
1845 * R774 (0x306) - AIF1DAC Data
1846 */
1847#define WM8995_AIF1DACL_DAT_INV 0x0002 /* AIF1DACL_DAT_INV */
1848#define WM8995_AIF1DACL_DAT_INV_MASK 0x0002 /* AIF1DACL_DAT_INV */
1849#define WM8995_AIF1DACL_DAT_INV_SHIFT 1 /* AIF1DACL_DAT_INV */
1850#define WM8995_AIF1DACL_DAT_INV_WIDTH 1 /* AIF1DACL_DAT_INV */
1851#define WM8995_AIF1DACR_DAT_INV 0x0001 /* AIF1DACR_DAT_INV */
1852#define WM8995_AIF1DACR_DAT_INV_MASK 0x0001 /* AIF1DACR_DAT_INV */
1853#define WM8995_AIF1DACR_DAT_INV_SHIFT 0 /* AIF1DACR_DAT_INV */
1854#define WM8995_AIF1DACR_DAT_INV_WIDTH 1 /* AIF1DACR_DAT_INV */
1855
1856/*
1857 * R775 (0x307) - AIF1ADC Data
1858 */
1859#define WM8995_AIF1ADCL_DAT_INV 0x0002 /* AIF1ADCL_DAT_INV */
1860#define WM8995_AIF1ADCL_DAT_INV_MASK 0x0002 /* AIF1ADCL_DAT_INV */
1861#define WM8995_AIF1ADCL_DAT_INV_SHIFT 1 /* AIF1ADCL_DAT_INV */
1862#define WM8995_AIF1ADCL_DAT_INV_WIDTH 1 /* AIF1ADCL_DAT_INV */
1863#define WM8995_AIF1ADCR_DAT_INV 0x0001 /* AIF1ADCR_DAT_INV */
1864#define WM8995_AIF1ADCR_DAT_INV_MASK 0x0001 /* AIF1ADCR_DAT_INV */
1865#define WM8995_AIF1ADCR_DAT_INV_SHIFT 0 /* AIF1ADCR_DAT_INV */
1866#define WM8995_AIF1ADCR_DAT_INV_WIDTH 1 /* AIF1ADCR_DAT_INV */
1867
1868/*
1869 * R784 (0x310) - AIF2 Control (1)
1870 */
1871#define WM8995_AIF2ADCL_SRC 0x8000 /* AIF2ADCL_SRC */
1872#define WM8995_AIF2ADCL_SRC_MASK 0x8000 /* AIF2ADCL_SRC */
1873#define WM8995_AIF2ADCL_SRC_SHIFT 15 /* AIF2ADCL_SRC */
1874#define WM8995_AIF2ADCL_SRC_WIDTH 1 /* AIF2ADCL_SRC */
1875#define WM8995_AIF2ADCR_SRC 0x4000 /* AIF2ADCR_SRC */
1876#define WM8995_AIF2ADCR_SRC_MASK 0x4000 /* AIF2ADCR_SRC */
1877#define WM8995_AIF2ADCR_SRC_SHIFT 14 /* AIF2ADCR_SRC */
1878#define WM8995_AIF2ADCR_SRC_WIDTH 1 /* AIF2ADCR_SRC */
1879#define WM8995_AIF2ADC_TDM 0x2000 /* AIF2ADC_TDM */
1880#define WM8995_AIF2ADC_TDM_MASK 0x2000 /* AIF2ADC_TDM */
1881#define WM8995_AIF2ADC_TDM_SHIFT 13 /* AIF2ADC_TDM */
1882#define WM8995_AIF2ADC_TDM_WIDTH 1 /* AIF2ADC_TDM */
1883#define WM8995_AIF2ADC_TDM_CHAN 0x1000 /* AIF2ADC_TDM_CHAN */
1884#define WM8995_AIF2ADC_TDM_CHAN_MASK 0x1000 /* AIF2ADC_TDM_CHAN */
1885#define WM8995_AIF2ADC_TDM_CHAN_SHIFT 12 /* AIF2ADC_TDM_CHAN */
1886#define WM8995_AIF2ADC_TDM_CHAN_WIDTH 1 /* AIF2ADC_TDM_CHAN */
1887#define WM8995_AIF2_BCLK_INV 0x0100 /* AIF2_BCLK_INV */
1888#define WM8995_AIF2_BCLK_INV_MASK 0x0100 /* AIF2_BCLK_INV */
1889#define WM8995_AIF2_BCLK_INV_SHIFT 8 /* AIF2_BCLK_INV */
1890#define WM8995_AIF2_BCLK_INV_WIDTH 1 /* AIF2_BCLK_INV */
1891#define WM8995_AIF2_LRCLK_INV 0x0080 /* AIF2_LRCLK_INV */
1892#define WM8995_AIF2_LRCLK_INV_MASK 0x0080 /* AIF2_LRCLK_INV */
1893#define WM8995_AIF2_LRCLK_INV_SHIFT 7 /* AIF2_LRCLK_INV */
1894#define WM8995_AIF2_LRCLK_INV_WIDTH 1 /* AIF2_LRCLK_INV */
1895#define WM8995_AIF2_WL_MASK 0x0060 /* AIF2_WL - [6:5] */
1896#define WM8995_AIF2_WL_SHIFT 5 /* AIF2_WL - [6:5] */
1897#define WM8995_AIF2_WL_WIDTH 2 /* AIF2_WL - [6:5] */
1898#define WM8995_AIF2_FMT_MASK 0x0018 /* AIF2_FMT - [4:3] */
1899#define WM8995_AIF2_FMT_SHIFT 3 /* AIF2_FMT - [4:3] */
1900#define WM8995_AIF2_FMT_WIDTH 2 /* AIF2_FMT - [4:3] */
1901
1902/*
1903 * R785 (0x311) - AIF2 Control (2)
1904 */
1905#define WM8995_AIF2DACL_SRC 0x8000 /* AIF2DACL_SRC */
1906#define WM8995_AIF2DACL_SRC_MASK 0x8000 /* AIF2DACL_SRC */
1907#define WM8995_AIF2DACL_SRC_SHIFT 15 /* AIF2DACL_SRC */
1908#define WM8995_AIF2DACL_SRC_WIDTH 1 /* AIF2DACL_SRC */
1909#define WM8995_AIF2DACR_SRC 0x4000 /* AIF2DACR_SRC */
1910#define WM8995_AIF2DACR_SRC_MASK 0x4000 /* AIF2DACR_SRC */
1911#define WM8995_AIF2DACR_SRC_SHIFT 14 /* AIF2DACR_SRC */
1912#define WM8995_AIF2DACR_SRC_WIDTH 1 /* AIF2DACR_SRC */
1913#define WM8995_AIF2DAC_TDM 0x2000 /* AIF2DAC_TDM */
1914#define WM8995_AIF2DAC_TDM_MASK 0x2000 /* AIF2DAC_TDM */
1915#define WM8995_AIF2DAC_TDM_SHIFT 13 /* AIF2DAC_TDM */
1916#define WM8995_AIF2DAC_TDM_WIDTH 1 /* AIF2DAC_TDM */
1917#define WM8995_AIF2DAC_TDM_CHAN 0x1000 /* AIF2DAC_TDM_CHAN */
1918#define WM8995_AIF2DAC_TDM_CHAN_MASK 0x1000 /* AIF2DAC_TDM_CHAN */
1919#define WM8995_AIF2DAC_TDM_CHAN_SHIFT 12 /* AIF2DAC_TDM_CHAN */
1920#define WM8995_AIF2DAC_TDM_CHAN_WIDTH 1 /* AIF2DAC_TDM_CHAN */
1921#define WM8995_AIF2DAC_BOOST_MASK 0x0C00 /* AIF2DAC_BOOST - [11:10] */
1922#define WM8995_AIF2DAC_BOOST_SHIFT 10 /* AIF2DAC_BOOST - [11:10] */
1923#define WM8995_AIF2DAC_BOOST_WIDTH 2 /* AIF2DAC_BOOST - [11:10] */
1924#define WM8995_AIF2DAC_COMP 0x0010 /* AIF2DAC_COMP */
1925#define WM8995_AIF2DAC_COMP_MASK 0x0010 /* AIF2DAC_COMP */
1926#define WM8995_AIF2DAC_COMP_SHIFT 4 /* AIF2DAC_COMP */
1927#define WM8995_AIF2DAC_COMP_WIDTH 1 /* AIF2DAC_COMP */
1928#define WM8995_AIF2DAC_COMPMODE 0x0008 /* AIF2DAC_COMPMODE */
1929#define WM8995_AIF2DAC_COMPMODE_MASK 0x0008 /* AIF2DAC_COMPMODE */
1930#define WM8995_AIF2DAC_COMPMODE_SHIFT 3 /* AIF2DAC_COMPMODE */
1931#define WM8995_AIF2DAC_COMPMODE_WIDTH 1 /* AIF2DAC_COMPMODE */
1932#define WM8995_AIF2ADC_COMP 0x0004 /* AIF2ADC_COMP */
1933#define WM8995_AIF2ADC_COMP_MASK 0x0004 /* AIF2ADC_COMP */
1934#define WM8995_AIF2ADC_COMP_SHIFT 2 /* AIF2ADC_COMP */
1935#define WM8995_AIF2ADC_COMP_WIDTH 1 /* AIF2ADC_COMP */
1936#define WM8995_AIF2ADC_COMPMODE 0x0002 /* AIF2ADC_COMPMODE */
1937#define WM8995_AIF2ADC_COMPMODE_MASK 0x0002 /* AIF2ADC_COMPMODE */
1938#define WM8995_AIF2ADC_COMPMODE_SHIFT 1 /* AIF2ADC_COMPMODE */
1939#define WM8995_AIF2ADC_COMPMODE_WIDTH 1 /* AIF2ADC_COMPMODE */
1940#define WM8995_AIF2_LOOPBACK 0x0001 /* AIF2_LOOPBACK */
1941#define WM8995_AIF2_LOOPBACK_MASK 0x0001 /* AIF2_LOOPBACK */
1942#define WM8995_AIF2_LOOPBACK_SHIFT 0 /* AIF2_LOOPBACK */
1943#define WM8995_AIF2_LOOPBACK_WIDTH 1 /* AIF2_LOOPBACK */
1944
1945/*
1946 * R786 (0x312) - AIF2 Master/Slave
1947 */
1948#define WM8995_AIF2_TRI 0x8000 /* AIF2_TRI */
1949#define WM8995_AIF2_TRI_MASK 0x8000 /* AIF2_TRI */
1950#define WM8995_AIF2_TRI_SHIFT 15 /* AIF2_TRI */
1951#define WM8995_AIF2_TRI_WIDTH 1 /* AIF2_TRI */
1952#define WM8995_AIF2_MSTR 0x4000 /* AIF2_MSTR */
1953#define WM8995_AIF2_MSTR_MASK 0x4000 /* AIF2_MSTR */
1954#define WM8995_AIF2_MSTR_SHIFT 14 /* AIF2_MSTR */
1955#define WM8995_AIF2_MSTR_WIDTH 1 /* AIF2_MSTR */
1956#define WM8995_AIF2_CLK_FRC 0x2000 /* AIF2_CLK_FRC */
1957#define WM8995_AIF2_CLK_FRC_MASK 0x2000 /* AIF2_CLK_FRC */
1958#define WM8995_AIF2_CLK_FRC_SHIFT 13 /* AIF2_CLK_FRC */
1959#define WM8995_AIF2_CLK_FRC_WIDTH 1 /* AIF2_CLK_FRC */
1960#define WM8995_AIF2_LRCLK_FRC 0x1000 /* AIF2_LRCLK_FRC */
1961#define WM8995_AIF2_LRCLK_FRC_MASK 0x1000 /* AIF2_LRCLK_FRC */
1962#define WM8995_AIF2_LRCLK_FRC_SHIFT 12 /* AIF2_LRCLK_FRC */
1963#define WM8995_AIF2_LRCLK_FRC_WIDTH 1 /* AIF2_LRCLK_FRC */
1964
1965/*
1966 * R787 (0x313) - AIF2 BCLK
1967 */
1968#define WM8995_AIF2_BCLK_DIV_MASK 0x00F0 /* AIF2_BCLK_DIV - [7:4] */
1969#define WM8995_AIF2_BCLK_DIV_SHIFT 4 /* AIF2_BCLK_DIV - [7:4] */
1970#define WM8995_AIF2_BCLK_DIV_WIDTH 4 /* AIF2_BCLK_DIV - [7:4] */
1971
1972/*
1973 * R788 (0x314) - AIF2ADC LRCLK
1974 */
1975#define WM8995_AIF2ADC_LRCLK_DIR 0x0800 /* AIF2ADC_LRCLK_DIR */
1976#define WM8995_AIF2ADC_LRCLK_DIR_MASK 0x0800 /* AIF2ADC_LRCLK_DIR */
1977#define WM8995_AIF2ADC_LRCLK_DIR_SHIFT 11 /* AIF2ADC_LRCLK_DIR */
1978#define WM8995_AIF2ADC_LRCLK_DIR_WIDTH 1 /* AIF2ADC_LRCLK_DIR */
1979#define WM8995_AIF2ADC_RATE_MASK 0x07FF /* AIF2ADC_RATE - [10:0] */
1980#define WM8995_AIF2ADC_RATE_SHIFT 0 /* AIF2ADC_RATE - [10:0] */
1981#define WM8995_AIF2ADC_RATE_WIDTH 11 /* AIF2ADC_RATE - [10:0] */
1982
1983/*
1984 * R789 (0x315) - AIF2DAC LRCLK
1985 */
1986#define WM8995_AIF2DAC_LRCLK_DIR 0x0800 /* AIF2DAC_LRCLK_DIR */
1987#define WM8995_AIF2DAC_LRCLK_DIR_MASK 0x0800 /* AIF2DAC_LRCLK_DIR */
1988#define WM8995_AIF2DAC_LRCLK_DIR_SHIFT 11 /* AIF2DAC_LRCLK_DIR */
1989#define WM8995_AIF2DAC_LRCLK_DIR_WIDTH 1 /* AIF2DAC_LRCLK_DIR */
1990#define WM8995_AIF2DAC_RATE_MASK 0x07FF /* AIF2DAC_RATE - [10:0] */
1991#define WM8995_AIF2DAC_RATE_SHIFT 0 /* AIF2DAC_RATE - [10:0] */
1992#define WM8995_AIF2DAC_RATE_WIDTH 11 /* AIF2DAC_RATE - [10:0] */
1993
1994/*
1995 * R790 (0x316) - AIF2DAC Data
1996 */
1997#define WM8995_AIF2DACL_DAT_INV 0x0002 /* AIF2DACL_DAT_INV */
1998#define WM8995_AIF2DACL_DAT_INV_MASK 0x0002 /* AIF2DACL_DAT_INV */
1999#define WM8995_AIF2DACL_DAT_INV_SHIFT 1 /* AIF2DACL_DAT_INV */
2000#define WM8995_AIF2DACL_DAT_INV_WIDTH 1 /* AIF2DACL_DAT_INV */
2001#define WM8995_AIF2DACR_DAT_INV 0x0001 /* AIF2DACR_DAT_INV */
2002#define WM8995_AIF2DACR_DAT_INV_MASK 0x0001 /* AIF2DACR_DAT_INV */
2003#define WM8995_AIF2DACR_DAT_INV_SHIFT 0 /* AIF2DACR_DAT_INV */
2004#define WM8995_AIF2DACR_DAT_INV_WIDTH 1 /* AIF2DACR_DAT_INV */
2005
2006/*
2007 * R791 (0x317) - AIF2ADC Data
2008 */
2009#define WM8995_AIF2ADCL_DAT_INV 0x0002 /* AIF2ADCL_DAT_INV */
2010#define WM8995_AIF2ADCL_DAT_INV_MASK 0x0002 /* AIF2ADCL_DAT_INV */
2011#define WM8995_AIF2ADCL_DAT_INV_SHIFT 1 /* AIF2ADCL_DAT_INV */
2012#define WM8995_AIF2ADCL_DAT_INV_WIDTH 1 /* AIF2ADCL_DAT_INV */
2013#define WM8995_AIF2ADCR_DAT_INV 0x0001 /* AIF2ADCR_DAT_INV */
2014#define WM8995_AIF2ADCR_DAT_INV_MASK 0x0001 /* AIF2ADCR_DAT_INV */
2015#define WM8995_AIF2ADCR_DAT_INV_SHIFT 0 /* AIF2ADCR_DAT_INV */
2016#define WM8995_AIF2ADCR_DAT_INV_WIDTH 1 /* AIF2ADCR_DAT_INV */
2017
2018/*
2019 * R1024 (0x400) - AIF1 ADC1 Left Volume
2020 */
2021#define WM8995_AIF1ADC1_VU 0x0100 /* AIF1ADC1_VU */
2022#define WM8995_AIF1ADC1_VU_MASK 0x0100 /* AIF1ADC1_VU */
2023#define WM8995_AIF1ADC1_VU_SHIFT 8 /* AIF1ADC1_VU */
2024#define WM8995_AIF1ADC1_VU_WIDTH 1 /* AIF1ADC1_VU */
2025#define WM8995_AIF1ADC1L_VOL_MASK 0x00FF /* AIF1ADC1L_VOL - [7:0] */
2026#define WM8995_AIF1ADC1L_VOL_SHIFT 0 /* AIF1ADC1L_VOL - [7:0] */
2027#define WM8995_AIF1ADC1L_VOL_WIDTH 8 /* AIF1ADC1L_VOL - [7:0] */
2028
2029/*
2030 * R1025 (0x401) - AIF1 ADC1 Right Volume
2031 */
2032#define WM8995_AIF1ADC1_VU 0x0100 /* AIF1ADC1_VU */
2033#define WM8995_AIF1ADC1_VU_MASK 0x0100 /* AIF1ADC1_VU */
2034#define WM8995_AIF1ADC1_VU_SHIFT 8 /* AIF1ADC1_VU */
2035#define WM8995_AIF1ADC1_VU_WIDTH 1 /* AIF1ADC1_VU */
2036#define WM8995_AIF1ADC1R_VOL_MASK 0x00FF /* AIF1ADC1R_VOL - [7:0] */
2037#define WM8995_AIF1ADC1R_VOL_SHIFT 0 /* AIF1ADC1R_VOL - [7:0] */
2038#define WM8995_AIF1ADC1R_VOL_WIDTH 8 /* AIF1ADC1R_VOL - [7:0] */
2039
2040/*
2041 * R1026 (0x402) - AIF1 DAC1 Left Volume
2042 */
2043#define WM8995_AIF1DAC1_VU 0x0100 /* AIF1DAC1_VU */
2044#define WM8995_AIF1DAC1_VU_MASK 0x0100 /* AIF1DAC1_VU */
2045#define WM8995_AIF1DAC1_VU_SHIFT 8 /* AIF1DAC1_VU */
2046#define WM8995_AIF1DAC1_VU_WIDTH 1 /* AIF1DAC1_VU */
2047#define WM8995_AIF1DAC1L_VOL_MASK 0x00FF /* AIF1DAC1L_VOL - [7:0] */
2048#define WM8995_AIF1DAC1L_VOL_SHIFT 0 /* AIF1DAC1L_VOL - [7:0] */
2049#define WM8995_AIF1DAC1L_VOL_WIDTH 8 /* AIF1DAC1L_VOL - [7:0] */
2050
2051/*
2052 * R1027 (0x403) - AIF1 DAC1 Right Volume
2053 */
2054#define WM8995_AIF1DAC1_VU 0x0100 /* AIF1DAC1_VU */
2055#define WM8995_AIF1DAC1_VU_MASK 0x0100 /* AIF1DAC1_VU */
2056#define WM8995_AIF1DAC1_VU_SHIFT 8 /* AIF1DAC1_VU */
2057#define WM8995_AIF1DAC1_VU_WIDTH 1 /* AIF1DAC1_VU */
2058#define WM8995_AIF1DAC1R_VOL_MASK 0x00FF /* AIF1DAC1R_VOL - [7:0] */
2059#define WM8995_AIF1DAC1R_VOL_SHIFT 0 /* AIF1DAC1R_VOL - [7:0] */
2060#define WM8995_AIF1DAC1R_VOL_WIDTH 8 /* AIF1DAC1R_VOL - [7:0] */
2061
2062/*
2063 * R1028 (0x404) - AIF1 ADC2 Left Volume
2064 */
2065#define WM8995_AIF1ADC2_VU 0x0100 /* AIF1ADC2_VU */
2066#define WM8995_AIF1ADC2_VU_MASK 0x0100 /* AIF1ADC2_VU */
2067#define WM8995_AIF1ADC2_VU_SHIFT 8 /* AIF1ADC2_VU */
2068#define WM8995_AIF1ADC2_VU_WIDTH 1 /* AIF1ADC2_VU */
2069#define WM8995_AIF1ADC2L_VOL_MASK 0x00FF /* AIF1ADC2L_VOL - [7:0] */
2070#define WM8995_AIF1ADC2L_VOL_SHIFT 0 /* AIF1ADC2L_VOL - [7:0] */
2071#define WM8995_AIF1ADC2L_VOL_WIDTH 8 /* AIF1ADC2L_VOL - [7:0] */
2072
2073/*
2074 * R1029 (0x405) - AIF1 ADC2 Right Volume
2075 */
2076#define WM8995_AIF1ADC2_VU 0x0100 /* AIF1ADC2_VU */
2077#define WM8995_AIF1ADC2_VU_MASK 0x0100 /* AIF1ADC2_VU */
2078#define WM8995_AIF1ADC2_VU_SHIFT 8 /* AIF1ADC2_VU */
2079#define WM8995_AIF1ADC2_VU_WIDTH 1 /* AIF1ADC2_VU */
2080#define WM8995_AIF1ADC2R_VOL_MASK 0x00FF /* AIF1ADC2R_VOL - [7:0] */
2081#define WM8995_AIF1ADC2R_VOL_SHIFT 0 /* AIF1ADC2R_VOL - [7:0] */
2082#define WM8995_AIF1ADC2R_VOL_WIDTH 8 /* AIF1ADC2R_VOL - [7:0] */
2083
2084/*
2085 * R1030 (0x406) - AIF1 DAC2 Left Volume
2086 */
2087#define WM8995_AIF1DAC2_VU 0x0100 /* AIF1DAC2_VU */
2088#define WM8995_AIF1DAC2_VU_MASK 0x0100 /* AIF1DAC2_VU */
2089#define WM8995_AIF1DAC2_VU_SHIFT 8 /* AIF1DAC2_VU */
2090#define WM8995_AIF1DAC2_VU_WIDTH 1 /* AIF1DAC2_VU */
2091#define WM8995_AIF1DAC2L_VOL_MASK 0x00FF /* AIF1DAC2L_VOL - [7:0] */
2092#define WM8995_AIF1DAC2L_VOL_SHIFT 0 /* AIF1DAC2L_VOL - [7:0] */
2093#define WM8995_AIF1DAC2L_VOL_WIDTH 8 /* AIF1DAC2L_VOL - [7:0] */
2094
2095/*
2096 * R1031 (0x407) - AIF1 DAC2 Right Volume
2097 */
2098#define WM8995_AIF1DAC2_VU 0x0100 /* AIF1DAC2_VU */
2099#define WM8995_AIF1DAC2_VU_MASK 0x0100 /* AIF1DAC2_VU */
2100#define WM8995_AIF1DAC2_VU_SHIFT 8 /* AIF1DAC2_VU */
2101#define WM8995_AIF1DAC2_VU_WIDTH 1 /* AIF1DAC2_VU */
2102#define WM8995_AIF1DAC2R_VOL_MASK 0x00FF /* AIF1DAC2R_VOL - [7:0] */
2103#define WM8995_AIF1DAC2R_VOL_SHIFT 0 /* AIF1DAC2R_VOL - [7:0] */
2104#define WM8995_AIF1DAC2R_VOL_WIDTH 8 /* AIF1DAC2R_VOL - [7:0] */
2105
2106/*
2107 * R1040 (0x410) - AIF1 ADC1 Filters
2108 */
2109#define WM8995_AIF1ADC_4FS 0x8000 /* AIF1ADC_4FS */
2110#define WM8995_AIF1ADC_4FS_MASK 0x8000 /* AIF1ADC_4FS */
2111#define WM8995_AIF1ADC_4FS_SHIFT 15 /* AIF1ADC_4FS */
2112#define WM8995_AIF1ADC_4FS_WIDTH 1 /* AIF1ADC_4FS */
2113#define WM8995_AIF1ADC1L_HPF 0x1000 /* AIF1ADC1L_HPF */
2114#define WM8995_AIF1ADC1L_HPF_MASK 0x1000 /* AIF1ADC1L_HPF */
2115#define WM8995_AIF1ADC1L_HPF_SHIFT 12 /* AIF1ADC1L_HPF */
2116#define WM8995_AIF1ADC1L_HPF_WIDTH 1 /* AIF1ADC1L_HPF */
2117#define WM8995_AIF1ADC1R_HPF 0x0800 /* AIF1ADC1R_HPF */
2118#define WM8995_AIF1ADC1R_HPF_MASK 0x0800 /* AIF1ADC1R_HPF */
2119#define WM8995_AIF1ADC1R_HPF_SHIFT 11 /* AIF1ADC1R_HPF */
2120#define WM8995_AIF1ADC1R_HPF_WIDTH 1 /* AIF1ADC1R_HPF */
2121#define WM8995_AIF1ADC1_HPF_MODE 0x0008 /* AIF1ADC1_HPF_MODE */
2122#define WM8995_AIF1ADC1_HPF_MODE_MASK 0x0008 /* AIF1ADC1_HPF_MODE */
2123#define WM8995_AIF1ADC1_HPF_MODE_SHIFT 3 /* AIF1ADC1_HPF_MODE */
2124#define WM8995_AIF1ADC1_HPF_MODE_WIDTH 1 /* AIF1ADC1_HPF_MODE */
2125#define WM8995_AIF1ADC1_HPF_CUT_MASK 0x0007 /* AIF1ADC1_HPF_CUT - [2:0] */
2126#define WM8995_AIF1ADC1_HPF_CUT_SHIFT 0 /* AIF1ADC1_HPF_CUT - [2:0] */
2127#define WM8995_AIF1ADC1_HPF_CUT_WIDTH 3 /* AIF1ADC1_HPF_CUT - [2:0] */
2128
2129/*
2130 * R1041 (0x411) - AIF1 ADC2 Filters
2131 */
2132#define WM8995_AIF1ADC2L_HPF 0x1000 /* AIF1ADC2L_HPF */
2133#define WM8995_AIF1ADC2L_HPF_MASK 0x1000 /* AIF1ADC2L_HPF */
2134#define WM8995_AIF1ADC2L_HPF_SHIFT 12 /* AIF1ADC2L_HPF */
2135#define WM8995_AIF1ADC2L_HPF_WIDTH 1 /* AIF1ADC2L_HPF */
2136#define WM8995_AIF1ADC2R_HPF 0x0800 /* AIF1ADC2R_HPF */
2137#define WM8995_AIF1ADC2R_HPF_MASK 0x0800 /* AIF1ADC2R_HPF */
2138#define WM8995_AIF1ADC2R_HPF_SHIFT 11 /* AIF1ADC2R_HPF */
2139#define WM8995_AIF1ADC2R_HPF_WIDTH 1 /* AIF1ADC2R_HPF */
2140#define WM8995_AIF1ADC2_HPF_MODE 0x0008 /* AIF1ADC2_HPF_MODE */
2141#define WM8995_AIF1ADC2_HPF_MODE_MASK 0x0008 /* AIF1ADC2_HPF_MODE */
2142#define WM8995_AIF1ADC2_HPF_MODE_SHIFT 3 /* AIF1ADC2_HPF_MODE */
2143#define WM8995_AIF1ADC2_HPF_MODE_WIDTH 1 /* AIF1ADC2_HPF_MODE */
2144#define WM8995_AIF1ADC2_HPF_CUT_MASK 0x0007 /* AIF1ADC2_HPF_CUT - [2:0] */
2145#define WM8995_AIF1ADC2_HPF_CUT_SHIFT 0 /* AIF1ADC2_HPF_CUT - [2:0] */
2146#define WM8995_AIF1ADC2_HPF_CUT_WIDTH 3 /* AIF1ADC2_HPF_CUT - [2:0] */
2147
2148/*
2149 * R1056 (0x420) - AIF1 DAC1 Filters (1)
2150 */
2151#define WM8995_AIF1DAC1_MUTE 0x0200 /* AIF1DAC1_MUTE */
2152#define WM8995_AIF1DAC1_MUTE_MASK 0x0200 /* AIF1DAC1_MUTE */
2153#define WM8995_AIF1DAC1_MUTE_SHIFT 9 /* AIF1DAC1_MUTE */
2154#define WM8995_AIF1DAC1_MUTE_WIDTH 1 /* AIF1DAC1_MUTE */
2155#define WM8995_AIF1DAC1_MONO 0x0080 /* AIF1DAC1_MONO */
2156#define WM8995_AIF1DAC1_MONO_MASK 0x0080 /* AIF1DAC1_MONO */
2157#define WM8995_AIF1DAC1_MONO_SHIFT 7 /* AIF1DAC1_MONO */
2158#define WM8995_AIF1DAC1_MONO_WIDTH 1 /* AIF1DAC1_MONO */
2159#define WM8995_AIF1DAC1_MUTERATE 0x0020 /* AIF1DAC1_MUTERATE */
2160#define WM8995_AIF1DAC1_MUTERATE_MASK 0x0020 /* AIF1DAC1_MUTERATE */
2161#define WM8995_AIF1DAC1_MUTERATE_SHIFT 5 /* AIF1DAC1_MUTERATE */
2162#define WM8995_AIF1DAC1_MUTERATE_WIDTH 1 /* AIF1DAC1_MUTERATE */
2163#define WM8995_AIF1DAC1_UNMUTE_RAMP 0x0010 /* AIF1DAC1_UNMUTE_RAMP */
2164#define WM8995_AIF1DAC1_UNMUTE_RAMP_MASK 0x0010 /* AIF1DAC1_UNMUTE_RAMP */
2165#define WM8995_AIF1DAC1_UNMUTE_RAMP_SHIFT 4 /* AIF1DAC1_UNMUTE_RAMP */
2166#define WM8995_AIF1DAC1_UNMUTE_RAMP_WIDTH 1 /* AIF1DAC1_UNMUTE_RAMP */
2167#define WM8995_AIF1DAC1_DEEMP_MASK 0x0006 /* AIF1DAC1_DEEMP - [2:1] */
2168#define WM8995_AIF1DAC1_DEEMP_SHIFT 1 /* AIF1DAC1_DEEMP - [2:1] */
2169#define WM8995_AIF1DAC1_DEEMP_WIDTH 2 /* AIF1DAC1_DEEMP - [2:1] */
2170
2171/*
2172 * R1057 (0x421) - AIF1 DAC1 Filters (2)
2173 */
2174#define WM8995_AIF1DAC1_3D_GAIN_MASK 0x3E00 /* AIF1DAC1_3D_GAIN - [13:9] */
2175#define WM8995_AIF1DAC1_3D_GAIN_SHIFT 9 /* AIF1DAC1_3D_GAIN - [13:9] */
2176#define WM8995_AIF1DAC1_3D_GAIN_WIDTH 5 /* AIF1DAC1_3D_GAIN - [13:9] */
2177#define WM8995_AIF1DAC1_3D_ENA 0x0100 /* AIF1DAC1_3D_ENA */
2178#define WM8995_AIF1DAC1_3D_ENA_MASK 0x0100 /* AIF1DAC1_3D_ENA */
2179#define WM8995_AIF1DAC1_3D_ENA_SHIFT 8 /* AIF1DAC1_3D_ENA */
2180#define WM8995_AIF1DAC1_3D_ENA_WIDTH 1 /* AIF1DAC1_3D_ENA */
2181
2182/*
2183 * R1058 (0x422) - AIF1 DAC2 Filters (1)
2184 */
2185#define WM8995_AIF1DAC2_MUTE 0x0200 /* AIF1DAC2_MUTE */
2186#define WM8995_AIF1DAC2_MUTE_MASK 0x0200 /* AIF1DAC2_MUTE */
2187#define WM8995_AIF1DAC2_MUTE_SHIFT 9 /* AIF1DAC2_MUTE */
2188#define WM8995_AIF1DAC2_MUTE_WIDTH 1 /* AIF1DAC2_MUTE */
2189#define WM8995_AIF1DAC2_MONO 0x0080 /* AIF1DAC2_MONO */
2190#define WM8995_AIF1DAC2_MONO_MASK 0x0080 /* AIF1DAC2_MONO */
2191#define WM8995_AIF1DAC2_MONO_SHIFT 7 /* AIF1DAC2_MONO */
2192#define WM8995_AIF1DAC2_MONO_WIDTH 1 /* AIF1DAC2_MONO */
2193#define WM8995_AIF1DAC2_MUTERATE 0x0020 /* AIF1DAC2_MUTERATE */
2194#define WM8995_AIF1DAC2_MUTERATE_MASK 0x0020 /* AIF1DAC2_MUTERATE */
2195#define WM8995_AIF1DAC2_MUTERATE_SHIFT 5 /* AIF1DAC2_MUTERATE */
2196#define WM8995_AIF1DAC2_MUTERATE_WIDTH 1 /* AIF1DAC2_MUTERATE */
2197#define WM8995_AIF1DAC2_UNMUTE_RAMP 0x0010 /* AIF1DAC2_UNMUTE_RAMP */
2198#define WM8995_AIF1DAC2_UNMUTE_RAMP_MASK 0x0010 /* AIF1DAC2_UNMUTE_RAMP */
2199#define WM8995_AIF1DAC2_UNMUTE_RAMP_SHIFT 4 /* AIF1DAC2_UNMUTE_RAMP */
2200#define WM8995_AIF1DAC2_UNMUTE_RAMP_WIDTH 1 /* AIF1DAC2_UNMUTE_RAMP */
2201#define WM8995_AIF1DAC2_DEEMP_MASK 0x0006 /* AIF1DAC2_DEEMP - [2:1] */
2202#define WM8995_AIF1DAC2_DEEMP_SHIFT 1 /* AIF1DAC2_DEEMP - [2:1] */
2203#define WM8995_AIF1DAC2_DEEMP_WIDTH 2 /* AIF1DAC2_DEEMP - [2:1] */
2204
2205/*
2206 * R1059 (0x423) - AIF1 DAC2 Filters (2)
2207 */
2208#define WM8995_AIF1DAC2_3D_GAIN_MASK 0x3E00 /* AIF1DAC2_3D_GAIN - [13:9] */
2209#define WM8995_AIF1DAC2_3D_GAIN_SHIFT 9 /* AIF1DAC2_3D_GAIN - [13:9] */
2210#define WM8995_AIF1DAC2_3D_GAIN_WIDTH 5 /* AIF1DAC2_3D_GAIN - [13:9] */
2211#define WM8995_AIF1DAC2_3D_ENA 0x0100 /* AIF1DAC2_3D_ENA */
2212#define WM8995_AIF1DAC2_3D_ENA_MASK 0x0100 /* AIF1DAC2_3D_ENA */
2213#define WM8995_AIF1DAC2_3D_ENA_SHIFT 8 /* AIF1DAC2_3D_ENA */
2214#define WM8995_AIF1DAC2_3D_ENA_WIDTH 1 /* AIF1DAC2_3D_ENA */
2215
2216/*
2217 * R1088 (0x440) - AIF1 DRC1 (1)
2218 */
2219#define WM8995_AIF1DRC1_SIG_DET_RMS_MASK 0xF800 /* AIF1DRC1_SIG_DET_RMS - [15:11] */
2220#define WM8995_AIF1DRC1_SIG_DET_RMS_SHIFT 11 /* AIF1DRC1_SIG_DET_RMS - [15:11] */
2221#define WM8995_AIF1DRC1_SIG_DET_RMS_WIDTH 5 /* AIF1DRC1_SIG_DET_RMS - [15:11] */
2222#define WM8995_AIF1DRC1_SIG_DET_PK_MASK 0x0600 /* AIF1DRC1_SIG_DET_PK - [10:9] */
2223#define WM8995_AIF1DRC1_SIG_DET_PK_SHIFT 9 /* AIF1DRC1_SIG_DET_PK - [10:9] */
2224#define WM8995_AIF1DRC1_SIG_DET_PK_WIDTH 2 /* AIF1DRC1_SIG_DET_PK - [10:9] */
2225#define WM8995_AIF1DRC1_NG_ENA 0x0100 /* AIF1DRC1_NG_ENA */
2226#define WM8995_AIF1DRC1_NG_ENA_MASK 0x0100 /* AIF1DRC1_NG_ENA */
2227#define WM8995_AIF1DRC1_NG_ENA_SHIFT 8 /* AIF1DRC1_NG_ENA */
2228#define WM8995_AIF1DRC1_NG_ENA_WIDTH 1 /* AIF1DRC1_NG_ENA */
2229#define WM8995_AIF1DRC1_SIG_DET_MODE 0x0080 /* AIF1DRC1_SIG_DET_MODE */
2230#define WM8995_AIF1DRC1_SIG_DET_MODE_MASK 0x0080 /* AIF1DRC1_SIG_DET_MODE */
2231#define WM8995_AIF1DRC1_SIG_DET_MODE_SHIFT 7 /* AIF1DRC1_SIG_DET_MODE */
2232#define WM8995_AIF1DRC1_SIG_DET_MODE_WIDTH 1 /* AIF1DRC1_SIG_DET_MODE */
2233#define WM8995_AIF1DRC1_SIG_DET 0x0040 /* AIF1DRC1_SIG_DET */
2234#define WM8995_AIF1DRC1_SIG_DET_MASK 0x0040 /* AIF1DRC1_SIG_DET */
2235#define WM8995_AIF1DRC1_SIG_DET_SHIFT 6 /* AIF1DRC1_SIG_DET */
2236#define WM8995_AIF1DRC1_SIG_DET_WIDTH 1 /* AIF1DRC1_SIG_DET */
2237#define WM8995_AIF1DRC1_KNEE2_OP_ENA 0x0020 /* AIF1DRC1_KNEE2_OP_ENA */
2238#define WM8995_AIF1DRC1_KNEE2_OP_ENA_MASK 0x0020 /* AIF1DRC1_KNEE2_OP_ENA */
2239#define WM8995_AIF1DRC1_KNEE2_OP_ENA_SHIFT 5 /* AIF1DRC1_KNEE2_OP_ENA */
2240#define WM8995_AIF1DRC1_KNEE2_OP_ENA_WIDTH 1 /* AIF1DRC1_KNEE2_OP_ENA */
2241#define WM8995_AIF1DRC1_QR 0x0010 /* AIF1DRC1_QR */
2242#define WM8995_AIF1DRC1_QR_MASK 0x0010 /* AIF1DRC1_QR */
2243#define WM8995_AIF1DRC1_QR_SHIFT 4 /* AIF1DRC1_QR */
2244#define WM8995_AIF1DRC1_QR_WIDTH 1 /* AIF1DRC1_QR */
2245#define WM8995_AIF1DRC1_ANTICLIP 0x0008 /* AIF1DRC1_ANTICLIP */
2246#define WM8995_AIF1DRC1_ANTICLIP_MASK 0x0008 /* AIF1DRC1_ANTICLIP */
2247#define WM8995_AIF1DRC1_ANTICLIP_SHIFT 3 /* AIF1DRC1_ANTICLIP */
2248#define WM8995_AIF1DRC1_ANTICLIP_WIDTH 1 /* AIF1DRC1_ANTICLIP */
2249#define WM8995_AIF1DAC1_DRC_ENA 0x0004 /* AIF1DAC1_DRC_ENA */
2250#define WM8995_AIF1DAC1_DRC_ENA_MASK 0x0004 /* AIF1DAC1_DRC_ENA */
2251#define WM8995_AIF1DAC1_DRC_ENA_SHIFT 2 /* AIF1DAC1_DRC_ENA */
2252#define WM8995_AIF1DAC1_DRC_ENA_WIDTH 1 /* AIF1DAC1_DRC_ENA */
2253#define WM8995_AIF1ADC1L_DRC_ENA 0x0002 /* AIF1ADC1L_DRC_ENA */
2254#define WM8995_AIF1ADC1L_DRC_ENA_MASK 0x0002 /* AIF1ADC1L_DRC_ENA */
2255#define WM8995_AIF1ADC1L_DRC_ENA_SHIFT 1 /* AIF1ADC1L_DRC_ENA */
2256#define WM8995_AIF1ADC1L_DRC_ENA_WIDTH 1 /* AIF1ADC1L_DRC_ENA */
2257#define WM8995_AIF1ADC1R_DRC_ENA 0x0001 /* AIF1ADC1R_DRC_ENA */
2258#define WM8995_AIF1ADC1R_DRC_ENA_MASK 0x0001 /* AIF1ADC1R_DRC_ENA */
2259#define WM8995_AIF1ADC1R_DRC_ENA_SHIFT 0 /* AIF1ADC1R_DRC_ENA */
2260#define WM8995_AIF1ADC1R_DRC_ENA_WIDTH 1 /* AIF1ADC1R_DRC_ENA */
2261
2262/*
2263 * R1089 (0x441) - AIF1 DRC1 (2)
2264 */
2265#define WM8995_AIF1DRC1_ATK_MASK 0x1E00 /* AIF1DRC1_ATK - [12:9] */
2266#define WM8995_AIF1DRC1_ATK_SHIFT 9 /* AIF1DRC1_ATK - [12:9] */
2267#define WM8995_AIF1DRC1_ATK_WIDTH 4 /* AIF1DRC1_ATK - [12:9] */
2268#define WM8995_AIF1DRC1_DCY_MASK 0x01E0 /* AIF1DRC1_DCY - [8:5] */
2269#define WM8995_AIF1DRC1_DCY_SHIFT 5 /* AIF1DRC1_DCY - [8:5] */
2270#define WM8995_AIF1DRC1_DCY_WIDTH 4 /* AIF1DRC1_DCY - [8:5] */
2271#define WM8995_AIF1DRC1_MINGAIN_MASK 0x001C /* AIF1DRC1_MINGAIN - [4:2] */
2272#define WM8995_AIF1DRC1_MINGAIN_SHIFT 2 /* AIF1DRC1_MINGAIN - [4:2] */
2273#define WM8995_AIF1DRC1_MINGAIN_WIDTH 3 /* AIF1DRC1_MINGAIN - [4:2] */
2274#define WM8995_AIF1DRC1_MAXGAIN_MASK 0x0003 /* AIF1DRC1_MAXGAIN - [1:0] */
2275#define WM8995_AIF1DRC1_MAXGAIN_SHIFT 0 /* AIF1DRC1_MAXGAIN - [1:0] */
2276#define WM8995_AIF1DRC1_MAXGAIN_WIDTH 2 /* AIF1DRC1_MAXGAIN - [1:0] */
2277
2278/*
2279 * R1090 (0x442) - AIF1 DRC1 (3)
2280 */
2281#define WM8995_AIF1DRC1_NG_MINGAIN_MASK 0xF000 /* AIF1DRC1_NG_MINGAIN - [15:12] */
2282#define WM8995_AIF1DRC1_NG_MINGAIN_SHIFT 12 /* AIF1DRC1_NG_MINGAIN - [15:12] */
2283#define WM8995_AIF1DRC1_NG_MINGAIN_WIDTH 4 /* AIF1DRC1_NG_MINGAIN - [15:12] */
2284#define WM8995_AIF1DRC1_NG_EXP_MASK 0x0C00 /* AIF1DRC1_NG_EXP - [11:10] */
2285#define WM8995_AIF1DRC1_NG_EXP_SHIFT 10 /* AIF1DRC1_NG_EXP - [11:10] */
2286#define WM8995_AIF1DRC1_NG_EXP_WIDTH 2 /* AIF1DRC1_NG_EXP - [11:10] */
2287#define WM8995_AIF1DRC1_QR_THR_MASK 0x0300 /* AIF1DRC1_QR_THR - [9:8] */
2288#define WM8995_AIF1DRC1_QR_THR_SHIFT 8 /* AIF1DRC1_QR_THR - [9:8] */
2289#define WM8995_AIF1DRC1_QR_THR_WIDTH 2 /* AIF1DRC1_QR_THR - [9:8] */
2290#define WM8995_AIF1DRC1_QR_DCY_MASK 0x00C0 /* AIF1DRC1_QR_DCY - [7:6] */
2291#define WM8995_AIF1DRC1_QR_DCY_SHIFT 6 /* AIF1DRC1_QR_DCY - [7:6] */
2292#define WM8995_AIF1DRC1_QR_DCY_WIDTH 2 /* AIF1DRC1_QR_DCY - [7:6] */
2293#define WM8995_AIF1DRC1_HI_COMP_MASK 0x0038 /* AIF1DRC1_HI_COMP - [5:3] */
2294#define WM8995_AIF1DRC1_HI_COMP_SHIFT 3 /* AIF1DRC1_HI_COMP - [5:3] */
2295#define WM8995_AIF1DRC1_HI_COMP_WIDTH 3 /* AIF1DRC1_HI_COMP - [5:3] */
2296#define WM8995_AIF1DRC1_LO_COMP_MASK 0x0007 /* AIF1DRC1_LO_COMP - [2:0] */
2297#define WM8995_AIF1DRC1_LO_COMP_SHIFT 0 /* AIF1DRC1_LO_COMP - [2:0] */
2298#define WM8995_AIF1DRC1_LO_COMP_WIDTH 3 /* AIF1DRC1_LO_COMP - [2:0] */
2299
2300/*
2301 * R1091 (0x443) - AIF1 DRC1 (4)
2302 */
2303#define WM8995_AIF1DRC1_KNEE_IP_MASK 0x07E0 /* AIF1DRC1_KNEE_IP - [10:5] */
2304#define WM8995_AIF1DRC1_KNEE_IP_SHIFT 5 /* AIF1DRC1_KNEE_IP - [10:5] */
2305#define WM8995_AIF1DRC1_KNEE_IP_WIDTH 6 /* AIF1DRC1_KNEE_IP - [10:5] */
2306#define WM8995_AIF1DRC1_KNEE_OP_MASK 0x001F /* AIF1DRC1_KNEE_OP - [4:0] */
2307#define WM8995_AIF1DRC1_KNEE_OP_SHIFT 0 /* AIF1DRC1_KNEE_OP - [4:0] */
2308#define WM8995_AIF1DRC1_KNEE_OP_WIDTH 5 /* AIF1DRC1_KNEE_OP - [4:0] */
2309
2310/*
2311 * R1092 (0x444) - AIF1 DRC1 (5)
2312 */
2313#define WM8995_AIF1DRC1_KNEE2_IP_MASK 0x03E0 /* AIF1DRC1_KNEE2_IP - [9:5] */
2314#define WM8995_AIF1DRC1_KNEE2_IP_SHIFT 5 /* AIF1DRC1_KNEE2_IP - [9:5] */
2315#define WM8995_AIF1DRC1_KNEE2_IP_WIDTH 5 /* AIF1DRC1_KNEE2_IP - [9:5] */
2316#define WM8995_AIF1DRC1_KNEE2_OP_MASK 0x001F /* AIF1DRC1_KNEE2_OP - [4:0] */
2317#define WM8995_AIF1DRC1_KNEE2_OP_SHIFT 0 /* AIF1DRC1_KNEE2_OP - [4:0] */
2318#define WM8995_AIF1DRC1_KNEE2_OP_WIDTH 5 /* AIF1DRC1_KNEE2_OP - [4:0] */
2319
2320/*
2321 * R1104 (0x450) - AIF1 DRC2 (1)
2322 */
2323#define WM8995_AIF1DRC2_SIG_DET_RMS_MASK 0xF800 /* AIF1DRC2_SIG_DET_RMS - [15:11] */
2324#define WM8995_AIF1DRC2_SIG_DET_RMS_SHIFT 11 /* AIF1DRC2_SIG_DET_RMS - [15:11] */
2325#define WM8995_AIF1DRC2_SIG_DET_RMS_WIDTH 5 /* AIF1DRC2_SIG_DET_RMS - [15:11] */
2326#define WM8995_AIF1DRC2_SIG_DET_PK_MASK 0x0600 /* AIF1DRC2_SIG_DET_PK - [10:9] */
2327#define WM8995_AIF1DRC2_SIG_DET_PK_SHIFT 9 /* AIF1DRC2_SIG_DET_PK - [10:9] */
2328#define WM8995_AIF1DRC2_SIG_DET_PK_WIDTH 2 /* AIF1DRC2_SIG_DET_PK - [10:9] */
2329#define WM8995_AIF1DRC2_NG_ENA 0x0100 /* AIF1DRC2_NG_ENA */
2330#define WM8995_AIF1DRC2_NG_ENA_MASK 0x0100 /* AIF1DRC2_NG_ENA */
2331#define WM8995_AIF1DRC2_NG_ENA_SHIFT 8 /* AIF1DRC2_NG_ENA */
2332#define WM8995_AIF1DRC2_NG_ENA_WIDTH 1 /* AIF1DRC2_NG_ENA */
2333#define WM8995_AIF1DRC2_SIG_DET_MODE 0x0080 /* AIF1DRC2_SIG_DET_MODE */
2334#define WM8995_AIF1DRC2_SIG_DET_MODE_MASK 0x0080 /* AIF1DRC2_SIG_DET_MODE */
2335#define WM8995_AIF1DRC2_SIG_DET_MODE_SHIFT 7 /* AIF1DRC2_SIG_DET_MODE */
2336#define WM8995_AIF1DRC2_SIG_DET_MODE_WIDTH 1 /* AIF1DRC2_SIG_DET_MODE */
2337#define WM8995_AIF1DRC2_SIG_DET 0x0040 /* AIF1DRC2_SIG_DET */
2338#define WM8995_AIF1DRC2_SIG_DET_MASK 0x0040 /* AIF1DRC2_SIG_DET */
2339#define WM8995_AIF1DRC2_SIG_DET_SHIFT 6 /* AIF1DRC2_SIG_DET */
2340#define WM8995_AIF1DRC2_SIG_DET_WIDTH 1 /* AIF1DRC2_SIG_DET */
2341#define WM8995_AIF1DRC2_KNEE2_OP_ENA 0x0020 /* AIF1DRC2_KNEE2_OP_ENA */
2342#define WM8995_AIF1DRC2_KNEE2_OP_ENA_MASK 0x0020 /* AIF1DRC2_KNEE2_OP_ENA */
2343#define WM8995_AIF1DRC2_KNEE2_OP_ENA_SHIFT 5 /* AIF1DRC2_KNEE2_OP_ENA */
2344#define WM8995_AIF1DRC2_KNEE2_OP_ENA_WIDTH 1 /* AIF1DRC2_KNEE2_OP_ENA */
2345#define WM8995_AIF1DRC2_QR 0x0010 /* AIF1DRC2_QR */
2346#define WM8995_AIF1DRC2_QR_MASK 0x0010 /* AIF1DRC2_QR */
2347#define WM8995_AIF1DRC2_QR_SHIFT 4 /* AIF1DRC2_QR */
2348#define WM8995_AIF1DRC2_QR_WIDTH 1 /* AIF1DRC2_QR */
2349#define WM8995_AIF1DRC2_ANTICLIP 0x0008 /* AIF1DRC2_ANTICLIP */
2350#define WM8995_AIF1DRC2_ANTICLIP_MASK 0x0008 /* AIF1DRC2_ANTICLIP */
2351#define WM8995_AIF1DRC2_ANTICLIP_SHIFT 3 /* AIF1DRC2_ANTICLIP */
2352#define WM8995_AIF1DRC2_ANTICLIP_WIDTH 1 /* AIF1DRC2_ANTICLIP */
2353#define WM8995_AIF1DAC2_DRC_ENA 0x0004 /* AIF1DAC2_DRC_ENA */
2354#define WM8995_AIF1DAC2_DRC_ENA_MASK 0x0004 /* AIF1DAC2_DRC_ENA */
2355#define WM8995_AIF1DAC2_DRC_ENA_SHIFT 2 /* AIF1DAC2_DRC_ENA */
2356#define WM8995_AIF1DAC2_DRC_ENA_WIDTH 1 /* AIF1DAC2_DRC_ENA */
2357#define WM8995_AIF1ADC2L_DRC_ENA 0x0002 /* AIF1ADC2L_DRC_ENA */
2358#define WM8995_AIF1ADC2L_DRC_ENA_MASK 0x0002 /* AIF1ADC2L_DRC_ENA */
2359#define WM8995_AIF1ADC2L_DRC_ENA_SHIFT 1 /* AIF1ADC2L_DRC_ENA */
2360#define WM8995_AIF1ADC2L_DRC_ENA_WIDTH 1 /* AIF1ADC2L_DRC_ENA */
2361#define WM8995_AIF1ADC2R_DRC_ENA 0x0001 /* AIF1ADC2R_DRC_ENA */
2362#define WM8995_AIF1ADC2R_DRC_ENA_MASK 0x0001 /* AIF1ADC2R_DRC_ENA */
2363#define WM8995_AIF1ADC2R_DRC_ENA_SHIFT 0 /* AIF1ADC2R_DRC_ENA */
2364#define WM8995_AIF1ADC2R_DRC_ENA_WIDTH 1 /* AIF1ADC2R_DRC_ENA */
2365
2366/*
2367 * R1105 (0x451) - AIF1 DRC2 (2)
2368 */
2369#define WM8995_AIF1DRC2_ATK_MASK 0x1E00 /* AIF1DRC2_ATK - [12:9] */
2370#define WM8995_AIF1DRC2_ATK_SHIFT 9 /* AIF1DRC2_ATK - [12:9] */
2371#define WM8995_AIF1DRC2_ATK_WIDTH 4 /* AIF1DRC2_ATK - [12:9] */
2372#define WM8995_AIF1DRC2_DCY_MASK 0x01E0 /* AIF1DRC2_DCY - [8:5] */
2373#define WM8995_AIF1DRC2_DCY_SHIFT 5 /* AIF1DRC2_DCY - [8:5] */
2374#define WM8995_AIF1DRC2_DCY_WIDTH 4 /* AIF1DRC2_DCY - [8:5] */
2375#define WM8995_AIF1DRC2_MINGAIN_MASK 0x001C /* AIF1DRC2_MINGAIN - [4:2] */
2376#define WM8995_AIF1DRC2_MINGAIN_SHIFT 2 /* AIF1DRC2_MINGAIN - [4:2] */
2377#define WM8995_AIF1DRC2_MINGAIN_WIDTH 3 /* AIF1DRC2_MINGAIN - [4:2] */
2378#define WM8995_AIF1DRC2_MAXGAIN_MASK 0x0003 /* AIF1DRC2_MAXGAIN - [1:0] */
2379#define WM8995_AIF1DRC2_MAXGAIN_SHIFT 0 /* AIF1DRC2_MAXGAIN - [1:0] */
2380#define WM8995_AIF1DRC2_MAXGAIN_WIDTH 2 /* AIF1DRC2_MAXGAIN - [1:0] */
2381
2382/*
2383 * R1106 (0x452) - AIF1 DRC2 (3)
2384 */
2385#define WM8995_AIF1DRC2_NG_MINGAIN_MASK 0xF000 /* AIF1DRC2_NG_MINGAIN - [15:12] */
2386#define WM8995_AIF1DRC2_NG_MINGAIN_SHIFT 12 /* AIF1DRC2_NG_MINGAIN - [15:12] */
2387#define WM8995_AIF1DRC2_NG_MINGAIN_WIDTH 4 /* AIF1DRC2_NG_MINGAIN - [15:12] */
2388#define WM8995_AIF1DRC2_NG_EXP_MASK 0x0C00 /* AIF1DRC2_NG_EXP - [11:10] */
2389#define WM8995_AIF1DRC2_NG_EXP_SHIFT 10 /* AIF1DRC2_NG_EXP - [11:10] */
2390#define WM8995_AIF1DRC2_NG_EXP_WIDTH 2 /* AIF1DRC2_NG_EXP - [11:10] */
2391#define WM8995_AIF1DRC2_QR_THR_MASK 0x0300 /* AIF1DRC2_QR_THR - [9:8] */
2392#define WM8995_AIF1DRC2_QR_THR_SHIFT 8 /* AIF1DRC2_QR_THR - [9:8] */
2393#define WM8995_AIF1DRC2_QR_THR_WIDTH 2 /* AIF1DRC2_QR_THR - [9:8] */
2394#define WM8995_AIF1DRC2_QR_DCY_MASK 0x00C0 /* AIF1DRC2_QR_DCY - [7:6] */
2395#define WM8995_AIF1DRC2_QR_DCY_SHIFT 6 /* AIF1DRC2_QR_DCY - [7:6] */
2396#define WM8995_AIF1DRC2_QR_DCY_WIDTH 2 /* AIF1DRC2_QR_DCY - [7:6] */
2397#define WM8995_AIF1DRC2_HI_COMP_MASK 0x0038 /* AIF1DRC2_HI_COMP - [5:3] */
2398#define WM8995_AIF1DRC2_HI_COMP_SHIFT 3 /* AIF1DRC2_HI_COMP - [5:3] */
2399#define WM8995_AIF1DRC2_HI_COMP_WIDTH 3 /* AIF1DRC2_HI_COMP - [5:3] */
2400#define WM8995_AIF1DRC2_LO_COMP_MASK 0x0007 /* AIF1DRC2_LO_COMP - [2:0] */
2401#define WM8995_AIF1DRC2_LO_COMP_SHIFT 0 /* AIF1DRC2_LO_COMP - [2:0] */
2402#define WM8995_AIF1DRC2_LO_COMP_WIDTH 3 /* AIF1DRC2_LO_COMP - [2:0] */
2403
2404/*
2405 * R1107 (0x453) - AIF1 DRC2 (4)
2406 */
2407#define WM8995_AIF1DRC2_KNEE_IP_MASK 0x07E0 /* AIF1DRC2_KNEE_IP - [10:5] */
2408#define WM8995_AIF1DRC2_KNEE_IP_SHIFT 5 /* AIF1DRC2_KNEE_IP - [10:5] */
2409#define WM8995_AIF1DRC2_KNEE_IP_WIDTH 6 /* AIF1DRC2_KNEE_IP - [10:5] */
2410#define WM8995_AIF1DRC2_KNEE_OP_MASK 0x001F /* AIF1DRC2_KNEE_OP - [4:0] */
2411#define WM8995_AIF1DRC2_KNEE_OP_SHIFT 0 /* AIF1DRC2_KNEE_OP - [4:0] */
2412#define WM8995_AIF1DRC2_KNEE_OP_WIDTH 5 /* AIF1DRC2_KNEE_OP - [4:0] */
2413
2414/*
2415 * R1108 (0x454) - AIF1 DRC2 (5)
2416 */
2417#define WM8995_AIF1DRC2_KNEE2_IP_MASK 0x03E0 /* AIF1DRC2_KNEE2_IP - [9:5] */
2418#define WM8995_AIF1DRC2_KNEE2_IP_SHIFT 5 /* AIF1DRC2_KNEE2_IP - [9:5] */
2419#define WM8995_AIF1DRC2_KNEE2_IP_WIDTH 5 /* AIF1DRC2_KNEE2_IP - [9:5] */
2420#define WM8995_AIF1DRC2_KNEE2_OP_MASK 0x001F /* AIF1DRC2_KNEE2_OP - [4:0] */
2421#define WM8995_AIF1DRC2_KNEE2_OP_SHIFT 0 /* AIF1DRC2_KNEE2_OP - [4:0] */
2422#define WM8995_AIF1DRC2_KNEE2_OP_WIDTH 5 /* AIF1DRC2_KNEE2_OP - [4:0] */
2423
2424/*
2425 * R1152 (0x480) - AIF1 DAC1 EQ Gains (1)
2426 */
2427#define WM8995_AIF1DAC1_EQ_B1_GAIN_MASK 0xF800 /* AIF1DAC1_EQ_B1_GAIN - [15:11] */
2428#define WM8995_AIF1DAC1_EQ_B1_GAIN_SHIFT 11 /* AIF1DAC1_EQ_B1_GAIN - [15:11] */
2429#define WM8995_AIF1DAC1_EQ_B1_GAIN_WIDTH 5 /* AIF1DAC1_EQ_B1_GAIN - [15:11] */
2430#define WM8995_AIF1DAC1_EQ_B2_GAIN_MASK 0x07C0 /* AIF1DAC1_EQ_B2_GAIN - [10:6] */
2431#define WM8995_AIF1DAC1_EQ_B2_GAIN_SHIFT 6 /* AIF1DAC1_EQ_B2_GAIN - [10:6] */
2432#define WM8995_AIF1DAC1_EQ_B2_GAIN_WIDTH 5 /* AIF1DAC1_EQ_B2_GAIN - [10:6] */
2433#define WM8995_AIF1DAC1_EQ_B3_GAIN_MASK 0x003E /* AIF1DAC1_EQ_B3_GAIN - [5:1] */
2434#define WM8995_AIF1DAC1_EQ_B3_GAIN_SHIFT 1 /* AIF1DAC1_EQ_B3_GAIN - [5:1] */
2435#define WM8995_AIF1DAC1_EQ_B3_GAIN_WIDTH 5 /* AIF1DAC1_EQ_B3_GAIN - [5:1] */
2436#define WM8995_AIF1DAC1_EQ_ENA 0x0001 /* AIF1DAC1_EQ_ENA */
2437#define WM8995_AIF1DAC1_EQ_ENA_MASK 0x0001 /* AIF1DAC1_EQ_ENA */
2438#define WM8995_AIF1DAC1_EQ_ENA_SHIFT 0 /* AIF1DAC1_EQ_ENA */
2439#define WM8995_AIF1DAC1_EQ_ENA_WIDTH 1 /* AIF1DAC1_EQ_ENA */
2440
2441/*
2442 * R1153 (0x481) - AIF1 DAC1 EQ Gains (2)
2443 */
2444#define WM8995_AIF1DAC1_EQ_B4_GAIN_MASK 0xF800 /* AIF1DAC1_EQ_B4_GAIN - [15:11] */
2445#define WM8995_AIF1DAC1_EQ_B4_GAIN_SHIFT 11 /* AIF1DAC1_EQ_B4_GAIN - [15:11] */
2446#define WM8995_AIF1DAC1_EQ_B4_GAIN_WIDTH 5 /* AIF1DAC1_EQ_B4_GAIN - [15:11] */
2447#define WM8995_AIF1DAC1_EQ_B5_GAIN_MASK 0x07C0 /* AIF1DAC1_EQ_B5_GAIN - [10:6] */
2448#define WM8995_AIF1DAC1_EQ_B5_GAIN_SHIFT 6 /* AIF1DAC1_EQ_B5_GAIN - [10:6] */
2449#define WM8995_AIF1DAC1_EQ_B5_GAIN_WIDTH 5 /* AIF1DAC1_EQ_B5_GAIN - [10:6] */
2450
2451/*
2452 * R1154 (0x482) - AIF1 DAC1 EQ Band 1 A
2453 */
2454#define WM8995_AIF1DAC1_EQ_B1_A_MASK 0xFFFF /* AIF1DAC1_EQ_B1_A - [15:0] */
2455#define WM8995_AIF1DAC1_EQ_B1_A_SHIFT 0 /* AIF1DAC1_EQ_B1_A - [15:0] */
2456#define WM8995_AIF1DAC1_EQ_B1_A_WIDTH 16 /* AIF1DAC1_EQ_B1_A - [15:0] */
2457
2458/*
2459 * R1155 (0x483) - AIF1 DAC1 EQ Band 1 B
2460 */
2461#define WM8995_AIF1DAC1_EQ_B1_B_MASK 0xFFFF /* AIF1DAC1_EQ_B1_B - [15:0] */
2462#define WM8995_AIF1DAC1_EQ_B1_B_SHIFT 0 /* AIF1DAC1_EQ_B1_B - [15:0] */
2463#define WM8995_AIF1DAC1_EQ_B1_B_WIDTH 16 /* AIF1DAC1_EQ_B1_B - [15:0] */
2464
2465/*
2466 * R1156 (0x484) - AIF1 DAC1 EQ Band 1 PG
2467 */
2468#define WM8995_AIF1DAC1_EQ_B1_PG_MASK 0xFFFF /* AIF1DAC1_EQ_B1_PG - [15:0] */
2469#define WM8995_AIF1DAC1_EQ_B1_PG_SHIFT 0 /* AIF1DAC1_EQ_B1_PG - [15:0] */
2470#define WM8995_AIF1DAC1_EQ_B1_PG_WIDTH 16 /* AIF1DAC1_EQ_B1_PG - [15:0] */
2471
2472/*
2473 * R1157 (0x485) - AIF1 DAC1 EQ Band 2 A
2474 */
2475#define WM8995_AIF1DAC1_EQ_B2_A_MASK 0xFFFF /* AIF1DAC1_EQ_B2_A - [15:0] */
2476#define WM8995_AIF1DAC1_EQ_B2_A_SHIFT 0 /* AIF1DAC1_EQ_B2_A - [15:0] */
2477#define WM8995_AIF1DAC1_EQ_B2_A_WIDTH 16 /* AIF1DAC1_EQ_B2_A - [15:0] */
2478
2479/*
2480 * R1158 (0x486) - AIF1 DAC1 EQ Band 2 B
2481 */
2482#define WM8995_AIF1DAC1_EQ_B2_B_MASK 0xFFFF /* AIF1DAC1_EQ_B2_B - [15:0] */
2483#define WM8995_AIF1DAC1_EQ_B2_B_SHIFT 0 /* AIF1DAC1_EQ_B2_B - [15:0] */
2484#define WM8995_AIF1DAC1_EQ_B2_B_WIDTH 16 /* AIF1DAC1_EQ_B2_B - [15:0] */
2485
2486/*
2487 * R1159 (0x487) - AIF1 DAC1 EQ Band 2 C
2488 */
2489#define WM8995_AIF1DAC1_EQ_B2_C_MASK 0xFFFF /* AIF1DAC1_EQ_B2_C - [15:0] */
2490#define WM8995_AIF1DAC1_EQ_B2_C_SHIFT 0 /* AIF1DAC1_EQ_B2_C - [15:0] */
2491#define WM8995_AIF1DAC1_EQ_B2_C_WIDTH 16 /* AIF1DAC1_EQ_B2_C - [15:0] */
2492
2493/*
2494 * R1160 (0x488) - AIF1 DAC1 EQ Band 2 PG
2495 */
2496#define WM8995_AIF1DAC1_EQ_B2_PG_MASK 0xFFFF /* AIF1DAC1_EQ_B2_PG - [15:0] */
2497#define WM8995_AIF1DAC1_EQ_B2_PG_SHIFT 0 /* AIF1DAC1_EQ_B2_PG - [15:0] */
2498#define WM8995_AIF1DAC1_EQ_B2_PG_WIDTH 16 /* AIF1DAC1_EQ_B2_PG - [15:0] */
2499
2500/*
2501 * R1161 (0x489) - AIF1 DAC1 EQ Band 3 A
2502 */
2503#define WM8995_AIF1DAC1_EQ_B3_A_MASK 0xFFFF /* AIF1DAC1_EQ_B3_A - [15:0] */
2504#define WM8995_AIF1DAC1_EQ_B3_A_SHIFT 0 /* AIF1DAC1_EQ_B3_A - [15:0] */
2505#define WM8995_AIF1DAC1_EQ_B3_A_WIDTH 16 /* AIF1DAC1_EQ_B3_A - [15:0] */
2506
2507/*
2508 * R1162 (0x48A) - AIF1 DAC1 EQ Band 3 B
2509 */
2510#define WM8995_AIF1DAC1_EQ_B3_B_MASK 0xFFFF /* AIF1DAC1_EQ_B3_B - [15:0] */
2511#define WM8995_AIF1DAC1_EQ_B3_B_SHIFT 0 /* AIF1DAC1_EQ_B3_B - [15:0] */
2512#define WM8995_AIF1DAC1_EQ_B3_B_WIDTH 16 /* AIF1DAC1_EQ_B3_B - [15:0] */
2513
2514/*
2515 * R1163 (0x48B) - AIF1 DAC1 EQ Band 3 C
2516 */
2517#define WM8995_AIF1DAC1_EQ_B3_C_MASK 0xFFFF /* AIF1DAC1_EQ_B3_C - [15:0] */
2518#define WM8995_AIF1DAC1_EQ_B3_C_SHIFT 0 /* AIF1DAC1_EQ_B3_C - [15:0] */
2519#define WM8995_AIF1DAC1_EQ_B3_C_WIDTH 16 /* AIF1DAC1_EQ_B3_C - [15:0] */
2520
2521/*
2522 * R1164 (0x48C) - AIF1 DAC1 EQ Band 3 PG
2523 */
2524#define WM8995_AIF1DAC1_EQ_B3_PG_MASK 0xFFFF /* AIF1DAC1_EQ_B3_PG - [15:0] */
2525#define WM8995_AIF1DAC1_EQ_B3_PG_SHIFT 0 /* AIF1DAC1_EQ_B3_PG - [15:0] */
2526#define WM8995_AIF1DAC1_EQ_B3_PG_WIDTH 16 /* AIF1DAC1_EQ_B3_PG - [15:0] */
2527
2528/*
2529 * R1165 (0x48D) - AIF1 DAC1 EQ Band 4 A
2530 */
2531#define WM8995_AIF1DAC1_EQ_B4_A_MASK 0xFFFF /* AIF1DAC1_EQ_B4_A - [15:0] */
2532#define WM8995_AIF1DAC1_EQ_B4_A_SHIFT 0 /* AIF1DAC1_EQ_B4_A - [15:0] */
2533#define WM8995_AIF1DAC1_EQ_B4_A_WIDTH 16 /* AIF1DAC1_EQ_B4_A - [15:0] */
2534
2535/*
2536 * R1166 (0x48E) - AIF1 DAC1 EQ Band 4 B
2537 */
2538#define WM8995_AIF1DAC1_EQ_B4_B_MASK 0xFFFF /* AIF1DAC1_EQ_B4_B - [15:0] */
2539#define WM8995_AIF1DAC1_EQ_B4_B_SHIFT 0 /* AIF1DAC1_EQ_B4_B - [15:0] */
2540#define WM8995_AIF1DAC1_EQ_B4_B_WIDTH 16 /* AIF1DAC1_EQ_B4_B - [15:0] */
2541
2542/*
2543 * R1167 (0x48F) - AIF1 DAC1 EQ Band 4 C
2544 */
2545#define WM8995_AIF1DAC1_EQ_B4_C_MASK 0xFFFF /* AIF1DAC1_EQ_B4_C - [15:0] */
2546#define WM8995_AIF1DAC1_EQ_B4_C_SHIFT 0 /* AIF1DAC1_EQ_B4_C - [15:0] */
2547#define WM8995_AIF1DAC1_EQ_B4_C_WIDTH 16 /* AIF1DAC1_EQ_B4_C - [15:0] */
2548
2549/*
2550 * R1168 (0x490) - AIF1 DAC1 EQ Band 4 PG
2551 */
2552#define WM8995_AIF1DAC1_EQ_B4_PG_MASK 0xFFFF /* AIF1DAC1_EQ_B4_PG - [15:0] */
2553#define WM8995_AIF1DAC1_EQ_B4_PG_SHIFT 0 /* AIF1DAC1_EQ_B4_PG - [15:0] */
2554#define WM8995_AIF1DAC1_EQ_B4_PG_WIDTH 16 /* AIF1DAC1_EQ_B4_PG - [15:0] */
2555
2556/*
2557 * R1169 (0x491) - AIF1 DAC1 EQ Band 5 A
2558 */
2559#define WM8995_AIF1DAC1_EQ_B5_A_MASK 0xFFFF /* AIF1DAC1_EQ_B5_A - [15:0] */
2560#define WM8995_AIF1DAC1_EQ_B5_A_SHIFT 0 /* AIF1DAC1_EQ_B5_A - [15:0] */
2561#define WM8995_AIF1DAC1_EQ_B5_A_WIDTH 16 /* AIF1DAC1_EQ_B5_A - [15:0] */
2562
2563/*
2564 * R1170 (0x492) - AIF1 DAC1 EQ Band 5 B
2565 */
2566#define WM8995_AIF1DAC1_EQ_B5_B_MASK 0xFFFF /* AIF1DAC1_EQ_B5_B - [15:0] */
2567#define WM8995_AIF1DAC1_EQ_B5_B_SHIFT 0 /* AIF1DAC1_EQ_B5_B - [15:0] */
2568#define WM8995_AIF1DAC1_EQ_B5_B_WIDTH 16 /* AIF1DAC1_EQ_B5_B - [15:0] */
2569
2570/*
2571 * R1171 (0x493) - AIF1 DAC1 EQ Band 5 PG
2572 */
2573#define WM8995_AIF1DAC1_EQ_B5_PG_MASK 0xFFFF /* AIF1DAC1_EQ_B5_PG - [15:0] */
2574#define WM8995_AIF1DAC1_EQ_B5_PG_SHIFT 0 /* AIF1DAC1_EQ_B5_PG - [15:0] */
2575#define WM8995_AIF1DAC1_EQ_B5_PG_WIDTH 16 /* AIF1DAC1_EQ_B5_PG - [15:0] */
2576
2577/*
2578 * R1184 (0x4A0) - AIF1 DAC2 EQ Gains (1)
2579 */
2580#define WM8995_AIF1DAC2_EQ_B1_GAIN_MASK 0xF800 /* AIF1DAC2_EQ_B1_GAIN - [15:11] */
2581#define WM8995_AIF1DAC2_EQ_B1_GAIN_SHIFT 11 /* AIF1DAC2_EQ_B1_GAIN - [15:11] */
2582#define WM8995_AIF1DAC2_EQ_B1_GAIN_WIDTH 5 /* AIF1DAC2_EQ_B1_GAIN - [15:11] */
2583#define WM8995_AIF1DAC2_EQ_B2_GAIN_MASK 0x07C0 /* AIF1DAC2_EQ_B2_GAIN - [10:6] */
2584#define WM8995_AIF1DAC2_EQ_B2_GAIN_SHIFT 6 /* AIF1DAC2_EQ_B2_GAIN - [10:6] */
2585#define WM8995_AIF1DAC2_EQ_B2_GAIN_WIDTH 5 /* AIF1DAC2_EQ_B2_GAIN - [10:6] */
2586#define WM8995_AIF1DAC2_EQ_B3_GAIN_MASK 0x003E /* AIF1DAC2_EQ_B3_GAIN - [5:1] */
2587#define WM8995_AIF1DAC2_EQ_B3_GAIN_SHIFT 1 /* AIF1DAC2_EQ_B3_GAIN - [5:1] */
2588#define WM8995_AIF1DAC2_EQ_B3_GAIN_WIDTH 5 /* AIF1DAC2_EQ_B3_GAIN - [5:1] */
2589#define WM8995_AIF1DAC2_EQ_ENA 0x0001 /* AIF1DAC2_EQ_ENA */
2590#define WM8995_AIF1DAC2_EQ_ENA_MASK 0x0001 /* AIF1DAC2_EQ_ENA */
2591#define WM8995_AIF1DAC2_EQ_ENA_SHIFT 0 /* AIF1DAC2_EQ_ENA */
2592#define WM8995_AIF1DAC2_EQ_ENA_WIDTH 1 /* AIF1DAC2_EQ_ENA */
2593
2594/*
2595 * R1185 (0x4A1) - AIF1 DAC2 EQ Gains (2)
2596 */
2597#define WM8995_AIF1DAC2_EQ_B4_GAIN_MASK 0xF800 /* AIF1DAC2_EQ_B4_GAIN - [15:11] */
2598#define WM8995_AIF1DAC2_EQ_B4_GAIN_SHIFT 11 /* AIF1DAC2_EQ_B4_GAIN - [15:11] */
2599#define WM8995_AIF1DAC2_EQ_B4_GAIN_WIDTH 5 /* AIF1DAC2_EQ_B4_GAIN - [15:11] */
2600#define WM8995_AIF1DAC2_EQ_B5_GAIN_MASK 0x07C0 /* AIF1DAC2_EQ_B5_GAIN - [10:6] */
2601#define WM8995_AIF1DAC2_EQ_B5_GAIN_SHIFT 6 /* AIF1DAC2_EQ_B5_GAIN - [10:6] */
2602#define WM8995_AIF1DAC2_EQ_B5_GAIN_WIDTH 5 /* AIF1DAC2_EQ_B5_GAIN - [10:6] */
2603
2604/*
2605 * R1186 (0x4A2) - AIF1 DAC2 EQ Band 1 A
2606 */
2607#define WM8995_AIF1DAC2_EQ_B1_A_MASK 0xFFFF /* AIF1DAC2_EQ_B1_A - [15:0] */
2608#define WM8995_AIF1DAC2_EQ_B1_A_SHIFT 0 /* AIF1DAC2_EQ_B1_A - [15:0] */
2609#define WM8995_AIF1DAC2_EQ_B1_A_WIDTH 16 /* AIF1DAC2_EQ_B1_A - [15:0] */
2610
2611/*
2612 * R1187 (0x4A3) - AIF1 DAC2 EQ Band 1 B
2613 */
2614#define WM8995_AIF1DAC2_EQ_B1_B_MASK 0xFFFF /* AIF1DAC2_EQ_B1_B - [15:0] */
2615#define WM8995_AIF1DAC2_EQ_B1_B_SHIFT 0 /* AIF1DAC2_EQ_B1_B - [15:0] */
2616#define WM8995_AIF1DAC2_EQ_B1_B_WIDTH 16 /* AIF1DAC2_EQ_B1_B - [15:0] */
2617
2618/*
2619 * R1188 (0x4A4) - AIF1 DAC2 EQ Band 1 PG
2620 */
2621#define WM8995_AIF1DAC2_EQ_B1_PG_MASK 0xFFFF /* AIF1DAC2_EQ_B1_PG - [15:0] */
2622#define WM8995_AIF1DAC2_EQ_B1_PG_SHIFT 0 /* AIF1DAC2_EQ_B1_PG - [15:0] */
2623#define WM8995_AIF1DAC2_EQ_B1_PG_WIDTH 16 /* AIF1DAC2_EQ_B1_PG - [15:0] */
2624
2625/*
2626 * R1189 (0x4A5) - AIF1 DAC2 EQ Band 2 A
2627 */
2628#define WM8995_AIF1DAC2_EQ_B2_A_MASK 0xFFFF /* AIF1DAC2_EQ_B2_A - [15:0] */
2629#define WM8995_AIF1DAC2_EQ_B2_A_SHIFT 0 /* AIF1DAC2_EQ_B2_A - [15:0] */
2630#define WM8995_AIF1DAC2_EQ_B2_A_WIDTH 16 /* AIF1DAC2_EQ_B2_A - [15:0] */
2631
2632/*
2633 * R1190 (0x4A6) - AIF1 DAC2 EQ Band 2 B
2634 */
2635#define WM8995_AIF1DAC2_EQ_B2_B_MASK 0xFFFF /* AIF1DAC2_EQ_B2_B - [15:0] */
2636#define WM8995_AIF1DAC2_EQ_B2_B_SHIFT 0 /* AIF1DAC2_EQ_B2_B - [15:0] */
2637#define WM8995_AIF1DAC2_EQ_B2_B_WIDTH 16 /* AIF1DAC2_EQ_B2_B - [15:0] */
2638
2639/*
2640 * R1191 (0x4A7) - AIF1 DAC2 EQ Band 2 C
2641 */
2642#define WM8995_AIF1DAC2_EQ_B2_C_MASK 0xFFFF /* AIF1DAC2_EQ_B2_C - [15:0] */
2643#define WM8995_AIF1DAC2_EQ_B2_C_SHIFT 0 /* AIF1DAC2_EQ_B2_C - [15:0] */
2644#define WM8995_AIF1DAC2_EQ_B2_C_WIDTH 16 /* AIF1DAC2_EQ_B2_C - [15:0] */
2645
2646/*
2647 * R1192 (0x4A8) - AIF1 DAC2 EQ Band 2 PG
2648 */
2649#define WM8995_AIF1DAC2_EQ_B2_PG_MASK 0xFFFF /* AIF1DAC2_EQ_B2_PG - [15:0] */
2650#define WM8995_AIF1DAC2_EQ_B2_PG_SHIFT 0 /* AIF1DAC2_EQ_B2_PG - [15:0] */
2651#define WM8995_AIF1DAC2_EQ_B2_PG_WIDTH 16 /* AIF1DAC2_EQ_B2_PG - [15:0] */
2652
2653/*
2654 * R1193 (0x4A9) - AIF1 DAC2 EQ Band 3 A
2655 */
2656#define WM8995_AIF1DAC2_EQ_B3_A_MASK 0xFFFF /* AIF1DAC2_EQ_B3_A - [15:0] */
2657#define WM8995_AIF1DAC2_EQ_B3_A_SHIFT 0 /* AIF1DAC2_EQ_B3_A - [15:0] */
2658#define WM8995_AIF1DAC2_EQ_B3_A_WIDTH 16 /* AIF1DAC2_EQ_B3_A - [15:0] */
2659
2660/*
2661 * R1194 (0x4AA) - AIF1 DAC2 EQ Band 3 B
2662 */
2663#define WM8995_AIF1DAC2_EQ_B3_B_MASK 0xFFFF /* AIF1DAC2_EQ_B3_B - [15:0] */
2664#define WM8995_AIF1DAC2_EQ_B3_B_SHIFT 0 /* AIF1DAC2_EQ_B3_B - [15:0] */
2665#define WM8995_AIF1DAC2_EQ_B3_B_WIDTH 16 /* AIF1DAC2_EQ_B3_B - [15:0] */
2666
2667/*
2668 * R1195 (0x4AB) - AIF1 DAC2 EQ Band 3 C
2669 */
2670#define WM8995_AIF1DAC2_EQ_B3_C_MASK 0xFFFF /* AIF1DAC2_EQ_B3_C - [15:0] */
2671#define WM8995_AIF1DAC2_EQ_B3_C_SHIFT 0 /* AIF1DAC2_EQ_B3_C - [15:0] */
2672#define WM8995_AIF1DAC2_EQ_B3_C_WIDTH 16 /* AIF1DAC2_EQ_B3_C - [15:0] */
2673
2674/*
2675 * R1196 (0x4AC) - AIF1 DAC2 EQ Band 3 PG
2676 */
2677#define WM8995_AIF1DAC2_EQ_B3_PG_MASK 0xFFFF /* AIF1DAC2_EQ_B3_PG - [15:0] */
2678#define WM8995_AIF1DAC2_EQ_B3_PG_SHIFT 0 /* AIF1DAC2_EQ_B3_PG - [15:0] */
2679#define WM8995_AIF1DAC2_EQ_B3_PG_WIDTH 16 /* AIF1DAC2_EQ_B3_PG - [15:0] */
2680
2681/*
2682 * R1197 (0x4AD) - AIF1 DAC2 EQ Band 4 A
2683 */
2684#define WM8995_AIF1DAC2_EQ_B4_A_MASK 0xFFFF /* AIF1DAC2_EQ_B4_A - [15:0] */
2685#define WM8995_AIF1DAC2_EQ_B4_A_SHIFT 0 /* AIF1DAC2_EQ_B4_A - [15:0] */
2686#define WM8995_AIF1DAC2_EQ_B4_A_WIDTH 16 /* AIF1DAC2_EQ_B4_A - [15:0] */
2687
2688/*
2689 * R1198 (0x4AE) - AIF1 DAC2 EQ Band 4 B
2690 */
2691#define WM8995_AIF1DAC2_EQ_B4_B_MASK 0xFFFF /* AIF1DAC2_EQ_B4_B - [15:0] */
2692#define WM8995_AIF1DAC2_EQ_B4_B_SHIFT 0 /* AIF1DAC2_EQ_B4_B - [15:0] */
2693#define WM8995_AIF1DAC2_EQ_B4_B_WIDTH 16 /* AIF1DAC2_EQ_B4_B - [15:0] */
2694
2695/*
2696 * R1199 (0x4AF) - AIF1 DAC2 EQ Band 4 C
2697 */
2698#define WM8995_AIF1DAC2_EQ_B4_C_MASK 0xFFFF /* AIF1DAC2_EQ_B4_C - [15:0] */
2699#define WM8995_AIF1DAC2_EQ_B4_C_SHIFT 0 /* AIF1DAC2_EQ_B4_C - [15:0] */
2700#define WM8995_AIF1DAC2_EQ_B4_C_WIDTH 16 /* AIF1DAC2_EQ_B4_C - [15:0] */
2701
2702/*
2703 * R1200 (0x4B0) - AIF1 DAC2 EQ Band 4 PG
2704 */
2705#define WM8995_AIF1DAC2_EQ_B4_PG_MASK 0xFFFF /* AIF1DAC2_EQ_B4_PG - [15:0] */
2706#define WM8995_AIF1DAC2_EQ_B4_PG_SHIFT 0 /* AIF1DAC2_EQ_B4_PG - [15:0] */
2707#define WM8995_AIF1DAC2_EQ_B4_PG_WIDTH 16 /* AIF1DAC2_EQ_B4_PG - [15:0] */
2708
2709/*
2710 * R1201 (0x4B1) - AIF1 DAC2 EQ Band 5 A
2711 */
2712#define WM8995_AIF1DAC2_EQ_B5_A_MASK 0xFFFF /* AIF1DAC2_EQ_B5_A - [15:0] */
2713#define WM8995_AIF1DAC2_EQ_B5_A_SHIFT 0 /* AIF1DAC2_EQ_B5_A - [15:0] */
2714#define WM8995_AIF1DAC2_EQ_B5_A_WIDTH 16 /* AIF1DAC2_EQ_B5_A - [15:0] */
2715
2716/*
2717 * R1202 (0x4B2) - AIF1 DAC2 EQ Band 5 B
2718 */
2719#define WM8995_AIF1DAC2_EQ_B5_B_MASK 0xFFFF /* AIF1DAC2_EQ_B5_B - [15:0] */
2720#define WM8995_AIF1DAC2_EQ_B5_B_SHIFT 0 /* AIF1DAC2_EQ_B5_B - [15:0] */
2721#define WM8995_AIF1DAC2_EQ_B5_B_WIDTH 16 /* AIF1DAC2_EQ_B5_B - [15:0] */
2722
2723/*
2724 * R1203 (0x4B3) - AIF1 DAC2 EQ Band 5 PG
2725 */
2726#define WM8995_AIF1DAC2_EQ_B5_PG_MASK 0xFFFF /* AIF1DAC2_EQ_B5_PG - [15:0] */
2727#define WM8995_AIF1DAC2_EQ_B5_PG_SHIFT 0 /* AIF1DAC2_EQ_B5_PG - [15:0] */
2728#define WM8995_AIF1DAC2_EQ_B5_PG_WIDTH 16 /* AIF1DAC2_EQ_B5_PG - [15:0] */
2729
2730/*
2731 * R1280 (0x500) - AIF2 ADC Left Volume
2732 */
2733#define WM8995_AIF2ADC_VU 0x0100 /* AIF2ADC_VU */
2734#define WM8995_AIF2ADC_VU_MASK 0x0100 /* AIF2ADC_VU */
2735#define WM8995_AIF2ADC_VU_SHIFT 8 /* AIF2ADC_VU */
2736#define WM8995_AIF2ADC_VU_WIDTH 1 /* AIF2ADC_VU */
2737#define WM8995_AIF2ADCL_VOL_MASK 0x00FF /* AIF2ADCL_VOL - [7:0] */
2738#define WM8995_AIF2ADCL_VOL_SHIFT 0 /* AIF2ADCL_VOL - [7:0] */
2739#define WM8995_AIF2ADCL_VOL_WIDTH 8 /* AIF2ADCL_VOL - [7:0] */
2740
2741/*
2742 * R1281 (0x501) - AIF2 ADC Right Volume
2743 */
2744#define WM8995_AIF2ADC_VU 0x0100 /* AIF2ADC_VU */
2745#define WM8995_AIF2ADC_VU_MASK 0x0100 /* AIF2ADC_VU */
2746#define WM8995_AIF2ADC_VU_SHIFT 8 /* AIF2ADC_VU */
2747#define WM8995_AIF2ADC_VU_WIDTH 1 /* AIF2ADC_VU */
2748#define WM8995_AIF2ADCR_VOL_MASK 0x00FF /* AIF2ADCR_VOL - [7:0] */
2749#define WM8995_AIF2ADCR_VOL_SHIFT 0 /* AIF2ADCR_VOL - [7:0] */
2750#define WM8995_AIF2ADCR_VOL_WIDTH 8 /* AIF2ADCR_VOL - [7:0] */
2751
2752/*
2753 * R1282 (0x502) - AIF2 DAC Left Volume
2754 */
2755#define WM8995_AIF2DAC_VU 0x0100 /* AIF2DAC_VU */
2756#define WM8995_AIF2DAC_VU_MASK 0x0100 /* AIF2DAC_VU */
2757#define WM8995_AIF2DAC_VU_SHIFT 8 /* AIF2DAC_VU */
2758#define WM8995_AIF2DAC_VU_WIDTH 1 /* AIF2DAC_VU */
2759#define WM8995_AIF2DACL_VOL_MASK 0x00FF /* AIF2DACL_VOL - [7:0] */
2760#define WM8995_AIF2DACL_VOL_SHIFT 0 /* AIF2DACL_VOL - [7:0] */
2761#define WM8995_AIF2DACL_VOL_WIDTH 8 /* AIF2DACL_VOL - [7:0] */
2762
2763/*
2764 * R1283 (0x503) - AIF2 DAC Right Volume
2765 */
2766#define WM8995_AIF2DAC_VU 0x0100 /* AIF2DAC_VU */
2767#define WM8995_AIF2DAC_VU_MASK 0x0100 /* AIF2DAC_VU */
2768#define WM8995_AIF2DAC_VU_SHIFT 8 /* AIF2DAC_VU */
2769#define WM8995_AIF2DAC_VU_WIDTH 1 /* AIF2DAC_VU */
2770#define WM8995_AIF2DACR_VOL_MASK 0x00FF /* AIF2DACR_VOL - [7:0] */
2771#define WM8995_AIF2DACR_VOL_SHIFT 0 /* AIF2DACR_VOL - [7:0] */
2772#define WM8995_AIF2DACR_VOL_WIDTH 8 /* AIF2DACR_VOL - [7:0] */
2773
2774/*
2775 * R1296 (0x510) - AIF2 ADC Filters
2776 */
2777#define WM8995_AIF2ADC_4FS 0x8000 /* AIF2ADC_4FS */
2778#define WM8995_AIF2ADC_4FS_MASK 0x8000 /* AIF2ADC_4FS */
2779#define WM8995_AIF2ADC_4FS_SHIFT 15 /* AIF2ADC_4FS */
2780#define WM8995_AIF2ADC_4FS_WIDTH 1 /* AIF2ADC_4FS */
2781#define WM8995_AIF2ADCL_HPF 0x1000 /* AIF2ADCL_HPF */
2782#define WM8995_AIF2ADCL_HPF_MASK 0x1000 /* AIF2ADCL_HPF */
2783#define WM8995_AIF2ADCL_HPF_SHIFT 12 /* AIF2ADCL_HPF */
2784#define WM8995_AIF2ADCL_HPF_WIDTH 1 /* AIF2ADCL_HPF */
2785#define WM8995_AIF2ADCR_HPF 0x0800 /* AIF2ADCR_HPF */
2786#define WM8995_AIF2ADCR_HPF_MASK 0x0800 /* AIF2ADCR_HPF */
2787#define WM8995_AIF2ADCR_HPF_SHIFT 11 /* AIF2ADCR_HPF */
2788#define WM8995_AIF2ADCR_HPF_WIDTH 1 /* AIF2ADCR_HPF */
2789#define WM8995_AIF2ADC_HPF_MODE 0x0008 /* AIF2ADC_HPF_MODE */
2790#define WM8995_AIF2ADC_HPF_MODE_MASK 0x0008 /* AIF2ADC_HPF_MODE */
2791#define WM8995_AIF2ADC_HPF_MODE_SHIFT 3 /* AIF2ADC_HPF_MODE */
2792#define WM8995_AIF2ADC_HPF_MODE_WIDTH 1 /* AIF2ADC_HPF_MODE */
2793#define WM8995_AIF2ADC_HPF_CUT_MASK 0x0007 /* AIF2ADC_HPF_CUT - [2:0] */
2794#define WM8995_AIF2ADC_HPF_CUT_SHIFT 0 /* AIF2ADC_HPF_CUT - [2:0] */
2795#define WM8995_AIF2ADC_HPF_CUT_WIDTH 3 /* AIF2ADC_HPF_CUT - [2:0] */
2796
2797/*
2798 * R1312 (0x520) - AIF2 DAC Filters (1)
2799 */
2800#define WM8995_AIF2DAC_MUTE 0x0200 /* AIF2DAC_MUTE */
2801#define WM8995_AIF2DAC_MUTE_MASK 0x0200 /* AIF2DAC_MUTE */
2802#define WM8995_AIF2DAC_MUTE_SHIFT 9 /* AIF2DAC_MUTE */
2803#define WM8995_AIF2DAC_MUTE_WIDTH 1 /* AIF2DAC_MUTE */
2804#define WM8995_AIF2DAC_MONO 0x0080 /* AIF2DAC_MONO */
2805#define WM8995_AIF2DAC_MONO_MASK 0x0080 /* AIF2DAC_MONO */
2806#define WM8995_AIF2DAC_MONO_SHIFT 7 /* AIF2DAC_MONO */
2807#define WM8995_AIF2DAC_MONO_WIDTH 1 /* AIF2DAC_MONO */
2808#define WM8995_AIF2DAC_MUTERATE 0x0020 /* AIF2DAC_MUTERATE */
2809#define WM8995_AIF2DAC_MUTERATE_MASK 0x0020 /* AIF2DAC_MUTERATE */
2810#define WM8995_AIF2DAC_MUTERATE_SHIFT 5 /* AIF2DAC_MUTERATE */
2811#define WM8995_AIF2DAC_MUTERATE_WIDTH 1 /* AIF2DAC_MUTERATE */
2812#define WM8995_AIF2DAC_UNMUTE_RAMP 0x0010 /* AIF2DAC_UNMUTE_RAMP */
2813#define WM8995_AIF2DAC_UNMUTE_RAMP_MASK 0x0010 /* AIF2DAC_UNMUTE_RAMP */
2814#define WM8995_AIF2DAC_UNMUTE_RAMP_SHIFT 4 /* AIF2DAC_UNMUTE_RAMP */
2815#define WM8995_AIF2DAC_UNMUTE_RAMP_WIDTH 1 /* AIF2DAC_UNMUTE_RAMP */
2816#define WM8995_AIF2DAC_DEEMP_MASK 0x0006 /* AIF2DAC_DEEMP - [2:1] */
2817#define WM8995_AIF2DAC_DEEMP_SHIFT 1 /* AIF2DAC_DEEMP - [2:1] */
2818#define WM8995_AIF2DAC_DEEMP_WIDTH 2 /* AIF2DAC_DEEMP - [2:1] */
2819
2820/*
2821 * R1313 (0x521) - AIF2 DAC Filters (2)
2822 */
2823#define WM8995_AIF2DAC_3D_GAIN_MASK 0x3E00 /* AIF2DAC_3D_GAIN - [13:9] */
2824#define WM8995_AIF2DAC_3D_GAIN_SHIFT 9 /* AIF2DAC_3D_GAIN - [13:9] */
2825#define WM8995_AIF2DAC_3D_GAIN_WIDTH 5 /* AIF2DAC_3D_GAIN - [13:9] */
2826#define WM8995_AIF2DAC_3D_ENA 0x0100 /* AIF2DAC_3D_ENA */
2827#define WM8995_AIF2DAC_3D_ENA_MASK 0x0100 /* AIF2DAC_3D_ENA */
2828#define WM8995_AIF2DAC_3D_ENA_SHIFT 8 /* AIF2DAC_3D_ENA */
2829#define WM8995_AIF2DAC_3D_ENA_WIDTH 1 /* AIF2DAC_3D_ENA */
2830
2831/*
2832 * R1344 (0x540) - AIF2 DRC (1)
2833 */
2834#define WM8995_AIF2DRC_SIG_DET_RMS_MASK 0xF800 /* AIF2DRC_SIG_DET_RMS - [15:11] */
2835#define WM8995_AIF2DRC_SIG_DET_RMS_SHIFT 11 /* AIF2DRC_SIG_DET_RMS - [15:11] */
2836#define WM8995_AIF2DRC_SIG_DET_RMS_WIDTH 5 /* AIF2DRC_SIG_DET_RMS - [15:11] */
2837#define WM8995_AIF2DRC_SIG_DET_PK_MASK 0x0600 /* AIF2DRC_SIG_DET_PK - [10:9] */
2838#define WM8995_AIF2DRC_SIG_DET_PK_SHIFT 9 /* AIF2DRC_SIG_DET_PK - [10:9] */
2839#define WM8995_AIF2DRC_SIG_DET_PK_WIDTH 2 /* AIF2DRC_SIG_DET_PK - [10:9] */
2840#define WM8995_AIF2DRC_NG_ENA 0x0100 /* AIF2DRC_NG_ENA */
2841#define WM8995_AIF2DRC_NG_ENA_MASK 0x0100 /* AIF2DRC_NG_ENA */
2842#define WM8995_AIF2DRC_NG_ENA_SHIFT 8 /* AIF2DRC_NG_ENA */
2843#define WM8995_AIF2DRC_NG_ENA_WIDTH 1 /* AIF2DRC_NG_ENA */
2844#define WM8995_AIF2DRC_SIG_DET_MODE 0x0080 /* AIF2DRC_SIG_DET_MODE */
2845#define WM8995_AIF2DRC_SIG_DET_MODE_MASK 0x0080 /* AIF2DRC_SIG_DET_MODE */
2846#define WM8995_AIF2DRC_SIG_DET_MODE_SHIFT 7 /* AIF2DRC_SIG_DET_MODE */
2847#define WM8995_AIF2DRC_SIG_DET_MODE_WIDTH 1 /* AIF2DRC_SIG_DET_MODE */
2848#define WM8995_AIF2DRC_SIG_DET 0x0040 /* AIF2DRC_SIG_DET */
2849#define WM8995_AIF2DRC_SIG_DET_MASK 0x0040 /* AIF2DRC_SIG_DET */
2850#define WM8995_AIF2DRC_SIG_DET_SHIFT 6 /* AIF2DRC_SIG_DET */
2851#define WM8995_AIF2DRC_SIG_DET_WIDTH 1 /* AIF2DRC_SIG_DET */
2852#define WM8995_AIF2DRC_KNEE2_OP_ENA 0x0020 /* AIF2DRC_KNEE2_OP_ENA */
2853#define WM8995_AIF2DRC_KNEE2_OP_ENA_MASK 0x0020 /* AIF2DRC_KNEE2_OP_ENA */
2854#define WM8995_AIF2DRC_KNEE2_OP_ENA_SHIFT 5 /* AIF2DRC_KNEE2_OP_ENA */
2855#define WM8995_AIF2DRC_KNEE2_OP_ENA_WIDTH 1 /* AIF2DRC_KNEE2_OP_ENA */
2856#define WM8995_AIF2DRC_QR 0x0010 /* AIF2DRC_QR */
2857#define WM8995_AIF2DRC_QR_MASK 0x0010 /* AIF2DRC_QR */
2858#define WM8995_AIF2DRC_QR_SHIFT 4 /* AIF2DRC_QR */
2859#define WM8995_AIF2DRC_QR_WIDTH 1 /* AIF2DRC_QR */
2860#define WM8995_AIF2DRC_ANTICLIP 0x0008 /* AIF2DRC_ANTICLIP */
2861#define WM8995_AIF2DRC_ANTICLIP_MASK 0x0008 /* AIF2DRC_ANTICLIP */
2862#define WM8995_AIF2DRC_ANTICLIP_SHIFT 3 /* AIF2DRC_ANTICLIP */
2863#define WM8995_AIF2DRC_ANTICLIP_WIDTH 1 /* AIF2DRC_ANTICLIP */
2864#define WM8995_AIF2DAC_DRC_ENA 0x0004 /* AIF2DAC_DRC_ENA */
2865#define WM8995_AIF2DAC_DRC_ENA_MASK 0x0004 /* AIF2DAC_DRC_ENA */
2866#define WM8995_AIF2DAC_DRC_ENA_SHIFT 2 /* AIF2DAC_DRC_ENA */
2867#define WM8995_AIF2DAC_DRC_ENA_WIDTH 1 /* AIF2DAC_DRC_ENA */
2868#define WM8995_AIF2ADCL_DRC_ENA 0x0002 /* AIF2ADCL_DRC_ENA */
2869#define WM8995_AIF2ADCL_DRC_ENA_MASK 0x0002 /* AIF2ADCL_DRC_ENA */
2870#define WM8995_AIF2ADCL_DRC_ENA_SHIFT 1 /* AIF2ADCL_DRC_ENA */
2871#define WM8995_AIF2ADCL_DRC_ENA_WIDTH 1 /* AIF2ADCL_DRC_ENA */
2872#define WM8995_AIF2ADCR_DRC_ENA 0x0001 /* AIF2ADCR_DRC_ENA */
2873#define WM8995_AIF2ADCR_DRC_ENA_MASK 0x0001 /* AIF2ADCR_DRC_ENA */
2874#define WM8995_AIF2ADCR_DRC_ENA_SHIFT 0 /* AIF2ADCR_DRC_ENA */
2875#define WM8995_AIF2ADCR_DRC_ENA_WIDTH 1 /* AIF2ADCR_DRC_ENA */
2876
2877/*
2878 * R1345 (0x541) - AIF2 DRC (2)
2879 */
2880#define WM8995_AIF2DRC_ATK_MASK 0x1E00 /* AIF2DRC_ATK - [12:9] */
2881#define WM8995_AIF2DRC_ATK_SHIFT 9 /* AIF2DRC_ATK - [12:9] */
2882#define WM8995_AIF2DRC_ATK_WIDTH 4 /* AIF2DRC_ATK - [12:9] */
2883#define WM8995_AIF2DRC_DCY_MASK 0x01E0 /* AIF2DRC_DCY - [8:5] */
2884#define WM8995_AIF2DRC_DCY_SHIFT 5 /* AIF2DRC_DCY - [8:5] */
2885#define WM8995_AIF2DRC_DCY_WIDTH 4 /* AIF2DRC_DCY - [8:5] */
2886#define WM8995_AIF2DRC_MINGAIN_MASK 0x001C /* AIF2DRC_MINGAIN - [4:2] */
2887#define WM8995_AIF2DRC_MINGAIN_SHIFT 2 /* AIF2DRC_MINGAIN - [4:2] */
2888#define WM8995_AIF2DRC_MINGAIN_WIDTH 3 /* AIF2DRC_MINGAIN - [4:2] */
2889#define WM8995_AIF2DRC_MAXGAIN_MASK 0x0003 /* AIF2DRC_MAXGAIN - [1:0] */
2890#define WM8995_AIF2DRC_MAXGAIN_SHIFT 0 /* AIF2DRC_MAXGAIN - [1:0] */
2891#define WM8995_AIF2DRC_MAXGAIN_WIDTH 2 /* AIF2DRC_MAXGAIN - [1:0] */
2892
2893/*
2894 * R1346 (0x542) - AIF2 DRC (3)
2895 */
2896#define WM8995_AIF2DRC_NG_MINGAIN_MASK 0xF000 /* AIF2DRC_NG_MINGAIN - [15:12] */
2897#define WM8995_AIF2DRC_NG_MINGAIN_SHIFT 12 /* AIF2DRC_NG_MINGAIN - [15:12] */
2898#define WM8995_AIF2DRC_NG_MINGAIN_WIDTH 4 /* AIF2DRC_NG_MINGAIN - [15:12] */
2899#define WM8995_AIF2DRC_NG_EXP_MASK 0x0C00 /* AIF2DRC_NG_EXP - [11:10] */
2900#define WM8995_AIF2DRC_NG_EXP_SHIFT 10 /* AIF2DRC_NG_EXP - [11:10] */
2901#define WM8995_AIF2DRC_NG_EXP_WIDTH 2 /* AIF2DRC_NG_EXP - [11:10] */
2902#define WM8995_AIF2DRC_QR_THR_MASK 0x0300 /* AIF2DRC_QR_THR - [9:8] */
2903#define WM8995_AIF2DRC_QR_THR_SHIFT 8 /* AIF2DRC_QR_THR - [9:8] */
2904#define WM8995_AIF2DRC_QR_THR_WIDTH 2 /* AIF2DRC_QR_THR - [9:8] */
2905#define WM8995_AIF2DRC_QR_DCY_MASK 0x00C0 /* AIF2DRC_QR_DCY - [7:6] */
2906#define WM8995_AIF2DRC_QR_DCY_SHIFT 6 /* AIF2DRC_QR_DCY - [7:6] */
2907#define WM8995_AIF2DRC_QR_DCY_WIDTH 2 /* AIF2DRC_QR_DCY - [7:6] */
2908#define WM8995_AIF2DRC_HI_COMP_MASK 0x0038 /* AIF2DRC_HI_COMP - [5:3] */
2909#define WM8995_AIF2DRC_HI_COMP_SHIFT 3 /* AIF2DRC_HI_COMP - [5:3] */
2910#define WM8995_AIF2DRC_HI_COMP_WIDTH 3 /* AIF2DRC_HI_COMP - [5:3] */
2911#define WM8995_AIF2DRC_LO_COMP_MASK 0x0007 /* AIF2DRC_LO_COMP - [2:0] */
2912#define WM8995_AIF2DRC_LO_COMP_SHIFT 0 /* AIF2DRC_LO_COMP - [2:0] */
2913#define WM8995_AIF2DRC_LO_COMP_WIDTH 3 /* AIF2DRC_LO_COMP - [2:0] */
2914
2915/*
2916 * R1347 (0x543) - AIF2 DRC (4)
2917 */
2918#define WM8995_AIF2DRC_KNEE_IP_MASK 0x07E0 /* AIF2DRC_KNEE_IP - [10:5] */
2919#define WM8995_AIF2DRC_KNEE_IP_SHIFT 5 /* AIF2DRC_KNEE_IP - [10:5] */
2920#define WM8995_AIF2DRC_KNEE_IP_WIDTH 6 /* AIF2DRC_KNEE_IP - [10:5] */
2921#define WM8995_AIF2DRC_KNEE_OP_MASK 0x001F /* AIF2DRC_KNEE_OP - [4:0] */
2922#define WM8995_AIF2DRC_KNEE_OP_SHIFT 0 /* AIF2DRC_KNEE_OP - [4:0] */
2923#define WM8995_AIF2DRC_KNEE_OP_WIDTH 5 /* AIF2DRC_KNEE_OP - [4:0] */
2924
2925/*
2926 * R1348 (0x544) - AIF2 DRC (5)
2927 */
2928#define WM8995_AIF2DRC_KNEE2_IP_MASK 0x03E0 /* AIF2DRC_KNEE2_IP - [9:5] */
2929#define WM8995_AIF2DRC_KNEE2_IP_SHIFT 5 /* AIF2DRC_KNEE2_IP - [9:5] */
2930#define WM8995_AIF2DRC_KNEE2_IP_WIDTH 5 /* AIF2DRC_KNEE2_IP - [9:5] */
2931#define WM8995_AIF2DRC_KNEE2_OP_MASK 0x001F /* AIF2DRC_KNEE2_OP - [4:0] */
2932#define WM8995_AIF2DRC_KNEE2_OP_SHIFT 0 /* AIF2DRC_KNEE2_OP - [4:0] */
2933#define WM8995_AIF2DRC_KNEE2_OP_WIDTH 5 /* AIF2DRC_KNEE2_OP - [4:0] */
2934
2935/*
2936 * R1408 (0x580) - AIF2 EQ Gains (1)
2937 */
2938#define WM8995_AIF2DAC_EQ_B1_GAIN_MASK 0xF800 /* AIF2DAC_EQ_B1_GAIN - [15:11] */
2939#define WM8995_AIF2DAC_EQ_B1_GAIN_SHIFT 11 /* AIF2DAC_EQ_B1_GAIN - [15:11] */
2940#define WM8995_AIF2DAC_EQ_B1_GAIN_WIDTH 5 /* AIF2DAC_EQ_B1_GAIN - [15:11] */
2941#define WM8995_AIF2DAC_EQ_B2_GAIN_MASK 0x07C0 /* AIF2DAC_EQ_B2_GAIN - [10:6] */
2942#define WM8995_AIF2DAC_EQ_B2_GAIN_SHIFT 6 /* AIF2DAC_EQ_B2_GAIN - [10:6] */
2943#define WM8995_AIF2DAC_EQ_B2_GAIN_WIDTH 5 /* AIF2DAC_EQ_B2_GAIN - [10:6] */
2944#define WM8995_AIF2DAC_EQ_B3_GAIN_MASK 0x003E /* AIF2DAC_EQ_B3_GAIN - [5:1] */
2945#define WM8995_AIF2DAC_EQ_B3_GAIN_SHIFT 1 /* AIF2DAC_EQ_B3_GAIN - [5:1] */
2946#define WM8995_AIF2DAC_EQ_B3_GAIN_WIDTH 5 /* AIF2DAC_EQ_B3_GAIN - [5:1] */
2947#define WM8995_AIF2DAC_EQ_ENA 0x0001 /* AIF2DAC_EQ_ENA */
2948#define WM8995_AIF2DAC_EQ_ENA_MASK 0x0001 /* AIF2DAC_EQ_ENA */
2949#define WM8995_AIF2DAC_EQ_ENA_SHIFT 0 /* AIF2DAC_EQ_ENA */
2950#define WM8995_AIF2DAC_EQ_ENA_WIDTH 1 /* AIF2DAC_EQ_ENA */
2951
2952/*
2953 * R1409 (0x581) - AIF2 EQ Gains (2)
2954 */
2955#define WM8995_AIF2DAC_EQ_B4_GAIN_MASK 0xF800 /* AIF2DAC_EQ_B4_GAIN - [15:11] */
2956#define WM8995_AIF2DAC_EQ_B4_GAIN_SHIFT 11 /* AIF2DAC_EQ_B4_GAIN - [15:11] */
2957#define WM8995_AIF2DAC_EQ_B4_GAIN_WIDTH 5 /* AIF2DAC_EQ_B4_GAIN - [15:11] */
2958#define WM8995_AIF2DAC_EQ_B5_GAIN_MASK 0x07C0 /* AIF2DAC_EQ_B5_GAIN - [10:6] */
2959#define WM8995_AIF2DAC_EQ_B5_GAIN_SHIFT 6 /* AIF2DAC_EQ_B5_GAIN - [10:6] */
2960#define WM8995_AIF2DAC_EQ_B5_GAIN_WIDTH 5 /* AIF2DAC_EQ_B5_GAIN - [10:6] */
2961
2962/*
2963 * R1410 (0x582) - AIF2 EQ Band 1 A
2964 */
2965#define WM8995_AIF2DAC_EQ_B1_A_MASK 0xFFFF /* AIF2DAC_EQ_B1_A - [15:0] */
2966#define WM8995_AIF2DAC_EQ_B1_A_SHIFT 0 /* AIF2DAC_EQ_B1_A - [15:0] */
2967#define WM8995_AIF2DAC_EQ_B1_A_WIDTH 16 /* AIF2DAC_EQ_B1_A - [15:0] */
2968
2969/*
2970 * R1411 (0x583) - AIF2 EQ Band 1 B
2971 */
2972#define WM8995_AIF2DAC_EQ_B1_B_MASK 0xFFFF /* AIF2DAC_EQ_B1_B - [15:0] */
2973#define WM8995_AIF2DAC_EQ_B1_B_SHIFT 0 /* AIF2DAC_EQ_B1_B - [15:0] */
2974#define WM8995_AIF2DAC_EQ_B1_B_WIDTH 16 /* AIF2DAC_EQ_B1_B - [15:0] */
2975
2976/*
2977 * R1412 (0x584) - AIF2 EQ Band 1 PG
2978 */
2979#define WM8995_AIF2DAC_EQ_B1_PG_MASK 0xFFFF /* AIF2DAC_EQ_B1_PG - [15:0] */
2980#define WM8995_AIF2DAC_EQ_B1_PG_SHIFT 0 /* AIF2DAC_EQ_B1_PG - [15:0] */
2981#define WM8995_AIF2DAC_EQ_B1_PG_WIDTH 16 /* AIF2DAC_EQ_B1_PG - [15:0] */
2982
2983/*
2984 * R1413 (0x585) - AIF2 EQ Band 2 A
2985 */
2986#define WM8995_AIF2DAC_EQ_B2_A_MASK 0xFFFF /* AIF2DAC_EQ_B2_A - [15:0] */
2987#define WM8995_AIF2DAC_EQ_B2_A_SHIFT 0 /* AIF2DAC_EQ_B2_A - [15:0] */
2988#define WM8995_AIF2DAC_EQ_B2_A_WIDTH 16 /* AIF2DAC_EQ_B2_A - [15:0] */
2989
2990/*
2991 * R1414 (0x586) - AIF2 EQ Band 2 B
2992 */
2993#define WM8995_AIF2DAC_EQ_B2_B_MASK 0xFFFF /* AIF2DAC_EQ_B2_B - [15:0] */
2994#define WM8995_AIF2DAC_EQ_B2_B_SHIFT 0 /* AIF2DAC_EQ_B2_B - [15:0] */
2995#define WM8995_AIF2DAC_EQ_B2_B_WIDTH 16 /* AIF2DAC_EQ_B2_B - [15:0] */
2996
2997/*
2998 * R1415 (0x587) - AIF2 EQ Band 2 C
2999 */
3000#define WM8995_AIF2DAC_EQ_B2_C_MASK 0xFFFF /* AIF2DAC_EQ_B2_C - [15:0] */
3001#define WM8995_AIF2DAC_EQ_B2_C_SHIFT 0 /* AIF2DAC_EQ_B2_C - [15:0] */
3002#define WM8995_AIF2DAC_EQ_B2_C_WIDTH 16 /* AIF2DAC_EQ_B2_C - [15:0] */
3003
3004/*
3005 * R1416 (0x588) - AIF2 EQ Band 2 PG
3006 */
3007#define WM8995_AIF2DAC_EQ_B2_PG_MASK 0xFFFF /* AIF2DAC_EQ_B2_PG - [15:0] */
3008#define WM8995_AIF2DAC_EQ_B2_PG_SHIFT 0 /* AIF2DAC_EQ_B2_PG - [15:0] */
3009#define WM8995_AIF2DAC_EQ_B2_PG_WIDTH 16 /* AIF2DAC_EQ_B2_PG - [15:0] */
3010
3011/*
3012 * R1417 (0x589) - AIF2 EQ Band 3 A
3013 */
3014#define WM8995_AIF2DAC_EQ_B3_A_MASK 0xFFFF /* AIF2DAC_EQ_B3_A - [15:0] */
3015#define WM8995_AIF2DAC_EQ_B3_A_SHIFT 0 /* AIF2DAC_EQ_B3_A - [15:0] */
3016#define WM8995_AIF2DAC_EQ_B3_A_WIDTH 16 /* AIF2DAC_EQ_B3_A - [15:0] */
3017
3018/*
3019 * R1418 (0x58A) - AIF2 EQ Band 3 B
3020 */
3021#define WM8995_AIF2DAC_EQ_B3_B_MASK 0xFFFF /* AIF2DAC_EQ_B3_B - [15:0] */
3022#define WM8995_AIF2DAC_EQ_B3_B_SHIFT 0 /* AIF2DAC_EQ_B3_B - [15:0] */
3023#define WM8995_AIF2DAC_EQ_B3_B_WIDTH 16 /* AIF2DAC_EQ_B3_B - [15:0] */
3024
3025/*
3026 * R1419 (0x58B) - AIF2 EQ Band 3 C
3027 */
3028#define WM8995_AIF2DAC_EQ_B3_C_MASK 0xFFFF /* AIF2DAC_EQ_B3_C - [15:0] */
3029#define WM8995_AIF2DAC_EQ_B3_C_SHIFT 0 /* AIF2DAC_EQ_B3_C - [15:0] */
3030#define WM8995_AIF2DAC_EQ_B3_C_WIDTH 16 /* AIF2DAC_EQ_B3_C - [15:0] */
3031
3032/*
3033 * R1420 (0x58C) - AIF2 EQ Band 3 PG
3034 */
3035#define WM8995_AIF2DAC_EQ_B3_PG_MASK 0xFFFF /* AIF2DAC_EQ_B3_PG - [15:0] */
3036#define WM8995_AIF2DAC_EQ_B3_PG_SHIFT 0 /* AIF2DAC_EQ_B3_PG - [15:0] */
3037#define WM8995_AIF2DAC_EQ_B3_PG_WIDTH 16 /* AIF2DAC_EQ_B3_PG - [15:0] */
3038
3039/*
3040 * R1421 (0x58D) - AIF2 EQ Band 4 A
3041 */
3042#define WM8995_AIF2DAC_EQ_B4_A_MASK 0xFFFF /* AIF2DAC_EQ_B4_A - [15:0] */
3043#define WM8995_AIF2DAC_EQ_B4_A_SHIFT 0 /* AIF2DAC_EQ_B4_A - [15:0] */
3044#define WM8995_AIF2DAC_EQ_B4_A_WIDTH 16 /* AIF2DAC_EQ_B4_A - [15:0] */
3045
3046/*
3047 * R1422 (0x58E) - AIF2 EQ Band 4 B
3048 */
3049#define WM8995_AIF2DAC_EQ_B4_B_MASK 0xFFFF /* AIF2DAC_EQ_B4_B - [15:0] */
3050#define WM8995_AIF2DAC_EQ_B4_B_SHIFT 0 /* AIF2DAC_EQ_B4_B - [15:0] */
3051#define WM8995_AIF2DAC_EQ_B4_B_WIDTH 16 /* AIF2DAC_EQ_B4_B - [15:0] */
3052
3053/*
3054 * R1423 (0x58F) - AIF2 EQ Band 4 C
3055 */
3056#define WM8995_AIF2DAC_EQ_B4_C_MASK 0xFFFF /* AIF2DAC_EQ_B4_C - [15:0] */
3057#define WM8995_AIF2DAC_EQ_B4_C_SHIFT 0 /* AIF2DAC_EQ_B4_C - [15:0] */
3058#define WM8995_AIF2DAC_EQ_B4_C_WIDTH 16 /* AIF2DAC_EQ_B4_C - [15:0] */
3059
3060/*
3061 * R1424 (0x590) - AIF2 EQ Band 4 PG
3062 */
3063#define WM8995_AIF2DAC_EQ_B4_PG_MASK 0xFFFF /* AIF2DAC_EQ_B4_PG - [15:0] */
3064#define WM8995_AIF2DAC_EQ_B4_PG_SHIFT 0 /* AIF2DAC_EQ_B4_PG - [15:0] */
3065#define WM8995_AIF2DAC_EQ_B4_PG_WIDTH 16 /* AIF2DAC_EQ_B4_PG - [15:0] */
3066
3067/*
3068 * R1425 (0x591) - AIF2 EQ Band 5 A
3069 */
3070#define WM8995_AIF2DAC_EQ_B5_A_MASK 0xFFFF /* AIF2DAC_EQ_B5_A - [15:0] */
3071#define WM8995_AIF2DAC_EQ_B5_A_SHIFT 0 /* AIF2DAC_EQ_B5_A - [15:0] */
3072#define WM8995_AIF2DAC_EQ_B5_A_WIDTH 16 /* AIF2DAC_EQ_B5_A - [15:0] */
3073
3074/*
3075 * R1426 (0x592) - AIF2 EQ Band 5 B
3076 */
3077#define WM8995_AIF2DAC_EQ_B5_B_MASK 0xFFFF /* AIF2DAC_EQ_B5_B - [15:0] */
3078#define WM8995_AIF2DAC_EQ_B5_B_SHIFT 0 /* AIF2DAC_EQ_B5_B - [15:0] */
3079#define WM8995_AIF2DAC_EQ_B5_B_WIDTH 16 /* AIF2DAC_EQ_B5_B - [15:0] */
3080
3081/*
3082 * R1427 (0x593) - AIF2 EQ Band 5 PG
3083 */
3084#define WM8995_AIF2DAC_EQ_B5_PG_MASK 0xFFFF /* AIF2DAC_EQ_B5_PG - [15:0] */
3085#define WM8995_AIF2DAC_EQ_B5_PG_SHIFT 0 /* AIF2DAC_EQ_B5_PG - [15:0] */
3086#define WM8995_AIF2DAC_EQ_B5_PG_WIDTH 16 /* AIF2DAC_EQ_B5_PG - [15:0] */
3087
3088/*
3089 * R1536 (0x600) - DAC1 Mixer Volumes
3090 */
3091#define WM8995_ADCR_DAC1_VOL_MASK 0x03E0 /* ADCR_DAC1_VOL - [9:5] */
3092#define WM8995_ADCR_DAC1_VOL_SHIFT 5 /* ADCR_DAC1_VOL - [9:5] */
3093#define WM8995_ADCR_DAC1_VOL_WIDTH 5 /* ADCR_DAC1_VOL - [9:5] */
3094#define WM8995_ADCL_DAC1_VOL_MASK 0x001F /* ADCL_DAC1_VOL - [4:0] */
3095#define WM8995_ADCL_DAC1_VOL_SHIFT 0 /* ADCL_DAC1_VOL - [4:0] */
3096#define WM8995_ADCL_DAC1_VOL_WIDTH 5 /* ADCL_DAC1_VOL - [4:0] */
3097
3098/*
3099 * R1537 (0x601) - DAC1 Left Mixer Routing
3100 */
3101#define WM8995_ADCR_TO_DAC1L 0x0020 /* ADCR_TO_DAC1L */
3102#define WM8995_ADCR_TO_DAC1L_MASK 0x0020 /* ADCR_TO_DAC1L */
3103#define WM8995_ADCR_TO_DAC1L_SHIFT 5 /* ADCR_TO_DAC1L */
3104#define WM8995_ADCR_TO_DAC1L_WIDTH 1 /* ADCR_TO_DAC1L */
3105#define WM8995_ADCL_TO_DAC1L 0x0010 /* ADCL_TO_DAC1L */
3106#define WM8995_ADCL_TO_DAC1L_MASK 0x0010 /* ADCL_TO_DAC1L */
3107#define WM8995_ADCL_TO_DAC1L_SHIFT 4 /* ADCL_TO_DAC1L */
3108#define WM8995_ADCL_TO_DAC1L_WIDTH 1 /* ADCL_TO_DAC1L */
3109#define WM8995_AIF2DACL_TO_DAC1L 0x0004 /* AIF2DACL_TO_DAC1L */
3110#define WM8995_AIF2DACL_TO_DAC1L_MASK 0x0004 /* AIF2DACL_TO_DAC1L */
3111#define WM8995_AIF2DACL_TO_DAC1L_SHIFT 2 /* AIF2DACL_TO_DAC1L */
3112#define WM8995_AIF2DACL_TO_DAC1L_WIDTH 1 /* AIF2DACL_TO_DAC1L */
3113#define WM8995_AIF1DAC2L_TO_DAC1L 0x0002 /* AIF1DAC2L_TO_DAC1L */
3114#define WM8995_AIF1DAC2L_TO_DAC1L_MASK 0x0002 /* AIF1DAC2L_TO_DAC1L */
3115#define WM8995_AIF1DAC2L_TO_DAC1L_SHIFT 1 /* AIF1DAC2L_TO_DAC1L */
3116#define WM8995_AIF1DAC2L_TO_DAC1L_WIDTH 1 /* AIF1DAC2L_TO_DAC1L */
3117#define WM8995_AIF1DAC1L_TO_DAC1L 0x0001 /* AIF1DAC1L_TO_DAC1L */
3118#define WM8995_AIF1DAC1L_TO_DAC1L_MASK 0x0001 /* AIF1DAC1L_TO_DAC1L */
3119#define WM8995_AIF1DAC1L_TO_DAC1L_SHIFT 0 /* AIF1DAC1L_TO_DAC1L */
3120#define WM8995_AIF1DAC1L_TO_DAC1L_WIDTH 1 /* AIF1DAC1L_TO_DAC1L */
3121
3122/*
3123 * R1538 (0x602) - DAC1 Right Mixer Routing
3124 */
3125#define WM8995_ADCR_TO_DAC1R 0x0020 /* ADCR_TO_DAC1R */
3126#define WM8995_ADCR_TO_DAC1R_MASK 0x0020 /* ADCR_TO_DAC1R */
3127#define WM8995_ADCR_TO_DAC1R_SHIFT 5 /* ADCR_TO_DAC1R */
3128#define WM8995_ADCR_TO_DAC1R_WIDTH 1 /* ADCR_TO_DAC1R */
3129#define WM8995_ADCL_TO_DAC1R 0x0010 /* ADCL_TO_DAC1R */
3130#define WM8995_ADCL_TO_DAC1R_MASK 0x0010 /* ADCL_TO_DAC1R */
3131#define WM8995_ADCL_TO_DAC1R_SHIFT 4 /* ADCL_TO_DAC1R */
3132#define WM8995_ADCL_TO_DAC1R_WIDTH 1 /* ADCL_TO_DAC1R */
3133#define WM8995_AIF2DACR_TO_DAC1R 0x0004 /* AIF2DACR_TO_DAC1R */
3134#define WM8995_AIF2DACR_TO_DAC1R_MASK 0x0004 /* AIF2DACR_TO_DAC1R */
3135#define WM8995_AIF2DACR_TO_DAC1R_SHIFT 2 /* AIF2DACR_TO_DAC1R */
3136#define WM8995_AIF2DACR_TO_DAC1R_WIDTH 1 /* AIF2DACR_TO_DAC1R */
3137#define WM8995_AIF1DAC2R_TO_DAC1R 0x0002 /* AIF1DAC2R_TO_DAC1R */
3138#define WM8995_AIF1DAC2R_TO_DAC1R_MASK 0x0002 /* AIF1DAC2R_TO_DAC1R */
3139#define WM8995_AIF1DAC2R_TO_DAC1R_SHIFT 1 /* AIF1DAC2R_TO_DAC1R */
3140#define WM8995_AIF1DAC2R_TO_DAC1R_WIDTH 1 /* AIF1DAC2R_TO_DAC1R */
3141#define WM8995_AIF1DAC1R_TO_DAC1R 0x0001 /* AIF1DAC1R_TO_DAC1R */
3142#define WM8995_AIF1DAC1R_TO_DAC1R_MASK 0x0001 /* AIF1DAC1R_TO_DAC1R */
3143#define WM8995_AIF1DAC1R_TO_DAC1R_SHIFT 0 /* AIF1DAC1R_TO_DAC1R */
3144#define WM8995_AIF1DAC1R_TO_DAC1R_WIDTH 1 /* AIF1DAC1R_TO_DAC1R */
3145
3146/*
3147 * R1539 (0x603) - DAC2 Mixer Volumes
3148 */
3149#define WM8995_ADCR_DAC2_VOL_MASK 0x03E0 /* ADCR_DAC2_VOL - [9:5] */
3150#define WM8995_ADCR_DAC2_VOL_SHIFT 5 /* ADCR_DAC2_VOL - [9:5] */
3151#define WM8995_ADCR_DAC2_VOL_WIDTH 5 /* ADCR_DAC2_VOL - [9:5] */
3152#define WM8995_ADCL_DAC2_VOL_MASK 0x001F /* ADCL_DAC2_VOL - [4:0] */
3153#define WM8995_ADCL_DAC2_VOL_SHIFT 0 /* ADCL_DAC2_VOL - [4:0] */
3154#define WM8995_ADCL_DAC2_VOL_WIDTH 5 /* ADCL_DAC2_VOL - [4:0] */
3155
3156/*
3157 * R1540 (0x604) - DAC2 Left Mixer Routing
3158 */
3159#define WM8995_ADCR_TO_DAC2L 0x0020 /* ADCR_TO_DAC2L */
3160#define WM8995_ADCR_TO_DAC2L_MASK 0x0020 /* ADCR_TO_DAC2L */
3161#define WM8995_ADCR_TO_DAC2L_SHIFT 5 /* ADCR_TO_DAC2L */
3162#define WM8995_ADCR_TO_DAC2L_WIDTH 1 /* ADCR_TO_DAC2L */
3163#define WM8995_ADCL_TO_DAC2L 0x0010 /* ADCL_TO_DAC2L */
3164#define WM8995_ADCL_TO_DAC2L_MASK 0x0010 /* ADCL_TO_DAC2L */
3165#define WM8995_ADCL_TO_DAC2L_SHIFT 4 /* ADCL_TO_DAC2L */
3166#define WM8995_ADCL_TO_DAC2L_WIDTH 1 /* ADCL_TO_DAC2L */
3167#define WM8995_AIF2DACL_TO_DAC2L 0x0004 /* AIF2DACL_TO_DAC2L */
3168#define WM8995_AIF2DACL_TO_DAC2L_MASK 0x0004 /* AIF2DACL_TO_DAC2L */
3169#define WM8995_AIF2DACL_TO_DAC2L_SHIFT 2 /* AIF2DACL_TO_DAC2L */
3170#define WM8995_AIF2DACL_TO_DAC2L_WIDTH 1 /* AIF2DACL_TO_DAC2L */
3171#define WM8995_AIF1DAC2L_TO_DAC2L 0x0002 /* AIF1DAC2L_TO_DAC2L */
3172#define WM8995_AIF1DAC2L_TO_DAC2L_MASK 0x0002 /* AIF1DAC2L_TO_DAC2L */
3173#define WM8995_AIF1DAC2L_TO_DAC2L_SHIFT 1 /* AIF1DAC2L_TO_DAC2L */
3174#define WM8995_AIF1DAC2L_TO_DAC2L_WIDTH 1 /* AIF1DAC2L_TO_DAC2L */
3175#define WM8995_AIF1DAC1L_TO_DAC2L 0x0001 /* AIF1DAC1L_TO_DAC2L */
3176#define WM8995_AIF1DAC1L_TO_DAC2L_MASK 0x0001 /* AIF1DAC1L_TO_DAC2L */
3177#define WM8995_AIF1DAC1L_TO_DAC2L_SHIFT 0 /* AIF1DAC1L_TO_DAC2L */
3178#define WM8995_AIF1DAC1L_TO_DAC2L_WIDTH 1 /* AIF1DAC1L_TO_DAC2L */
3179
3180/*
3181 * R1541 (0x605) - DAC2 Right Mixer Routing
3182 */
3183#define WM8995_ADCR_TO_DAC2R 0x0020 /* ADCR_TO_DAC2R */
3184#define WM8995_ADCR_TO_DAC2R_MASK 0x0020 /* ADCR_TO_DAC2R */
3185#define WM8995_ADCR_TO_DAC2R_SHIFT 5 /* ADCR_TO_DAC2R */
3186#define WM8995_ADCR_TO_DAC2R_WIDTH 1 /* ADCR_TO_DAC2R */
3187#define WM8995_ADCL_TO_DAC2R 0x0010 /* ADCL_TO_DAC2R */
3188#define WM8995_ADCL_TO_DAC2R_MASK 0x0010 /* ADCL_TO_DAC2R */
3189#define WM8995_ADCL_TO_DAC2R_SHIFT 4 /* ADCL_TO_DAC2R */
3190#define WM8995_ADCL_TO_DAC2R_WIDTH 1 /* ADCL_TO_DAC2R */
3191#define WM8995_AIF2DACR_TO_DAC2R 0x0004 /* AIF2DACR_TO_DAC2R */
3192#define WM8995_AIF2DACR_TO_DAC2R_MASK 0x0004 /* AIF2DACR_TO_DAC2R */
3193#define WM8995_AIF2DACR_TO_DAC2R_SHIFT 2 /* AIF2DACR_TO_DAC2R */
3194#define WM8995_AIF2DACR_TO_DAC2R_WIDTH 1 /* AIF2DACR_TO_DAC2R */
3195#define WM8995_AIF1DAC2R_TO_DAC2R 0x0002 /* AIF1DAC2R_TO_DAC2R */
3196#define WM8995_AIF1DAC2R_TO_DAC2R_MASK 0x0002 /* AIF1DAC2R_TO_DAC2R */
3197#define WM8995_AIF1DAC2R_TO_DAC2R_SHIFT 1 /* AIF1DAC2R_TO_DAC2R */
3198#define WM8995_AIF1DAC2R_TO_DAC2R_WIDTH 1 /* AIF1DAC2R_TO_DAC2R */
3199#define WM8995_AIF1DAC1R_TO_DAC2R 0x0001 /* AIF1DAC1R_TO_DAC2R */
3200#define WM8995_AIF1DAC1R_TO_DAC2R_MASK 0x0001 /* AIF1DAC1R_TO_DAC2R */
3201#define WM8995_AIF1DAC1R_TO_DAC2R_SHIFT 0 /* AIF1DAC1R_TO_DAC2R */
3202#define WM8995_AIF1DAC1R_TO_DAC2R_WIDTH 1 /* AIF1DAC1R_TO_DAC2R */
3203
3204/*
3205 * R1542 (0x606) - AIF1 ADC1 Left Mixer Routing
3206 */
3207#define WM8995_ADC1L_TO_AIF1ADC1L 0x0002 /* ADC1L_TO_AIF1ADC1L */
3208#define WM8995_ADC1L_TO_AIF1ADC1L_MASK 0x0002 /* ADC1L_TO_AIF1ADC1L */
3209#define WM8995_ADC1L_TO_AIF1ADC1L_SHIFT 1 /* ADC1L_TO_AIF1ADC1L */
3210#define WM8995_ADC1L_TO_AIF1ADC1L_WIDTH 1 /* ADC1L_TO_AIF1ADC1L */
3211#define WM8995_AIF2DACL_TO_AIF1ADC1L 0x0001 /* AIF2DACL_TO_AIF1ADC1L */
3212#define WM8995_AIF2DACL_TO_AIF1ADC1L_MASK 0x0001 /* AIF2DACL_TO_AIF1ADC1L */
3213#define WM8995_AIF2DACL_TO_AIF1ADC1L_SHIFT 0 /* AIF2DACL_TO_AIF1ADC1L */
3214#define WM8995_AIF2DACL_TO_AIF1ADC1L_WIDTH 1 /* AIF2DACL_TO_AIF1ADC1L */
3215
3216/*
3217 * R1543 (0x607) - AIF1 ADC1 Right Mixer Routing
3218 */
3219#define WM8995_ADC1R_TO_AIF1ADC1R 0x0002 /* ADC1R_TO_AIF1ADC1R */
3220#define WM8995_ADC1R_TO_AIF1ADC1R_MASK 0x0002 /* ADC1R_TO_AIF1ADC1R */
3221#define WM8995_ADC1R_TO_AIF1ADC1R_SHIFT 1 /* ADC1R_TO_AIF1ADC1R */
3222#define WM8995_ADC1R_TO_AIF1ADC1R_WIDTH 1 /* ADC1R_TO_AIF1ADC1R */
3223#define WM8995_AIF2DACR_TO_AIF1ADC1R 0x0001 /* AIF2DACR_TO_AIF1ADC1R */
3224#define WM8995_AIF2DACR_TO_AIF1ADC1R_MASK 0x0001 /* AIF2DACR_TO_AIF1ADC1R */
3225#define WM8995_AIF2DACR_TO_AIF1ADC1R_SHIFT 0 /* AIF2DACR_TO_AIF1ADC1R */
3226#define WM8995_AIF2DACR_TO_AIF1ADC1R_WIDTH 1 /* AIF2DACR_TO_AIF1ADC1R */
3227
3228/*
3229 * R1544 (0x608) - AIF1 ADC2 Left Mixer Routing
3230 */
3231#define WM8995_ADC2L_TO_AIF1ADC2L 0x0002 /* ADC2L_TO_AIF1ADC2L */
3232#define WM8995_ADC2L_TO_AIF1ADC2L_MASK 0x0002 /* ADC2L_TO_AIF1ADC2L */
3233#define WM8995_ADC2L_TO_AIF1ADC2L_SHIFT 1 /* ADC2L_TO_AIF1ADC2L */
3234#define WM8995_ADC2L_TO_AIF1ADC2L_WIDTH 1 /* ADC2L_TO_AIF1ADC2L */
3235#define WM8995_AIF2DACL_TO_AIF1ADC2L 0x0001 /* AIF2DACL_TO_AIF1ADC2L */
3236#define WM8995_AIF2DACL_TO_AIF1ADC2L_MASK 0x0001 /* AIF2DACL_TO_AIF1ADC2L */
3237#define WM8995_AIF2DACL_TO_AIF1ADC2L_SHIFT 0 /* AIF2DACL_TO_AIF1ADC2L */
3238#define WM8995_AIF2DACL_TO_AIF1ADC2L_WIDTH 1 /* AIF2DACL_TO_AIF1ADC2L */
3239
3240/*
3241 * R1545 (0x609) - AIF1 ADC2 Right mixer Routing
3242 */
3243#define WM8995_ADC2R_TO_AIF1ADC2R 0x0002 /* ADC2R_TO_AIF1ADC2R */
3244#define WM8995_ADC2R_TO_AIF1ADC2R_MASK 0x0002 /* ADC2R_TO_AIF1ADC2R */
3245#define WM8995_ADC2R_TO_AIF1ADC2R_SHIFT 1 /* ADC2R_TO_AIF1ADC2R */
3246#define WM8995_ADC2R_TO_AIF1ADC2R_WIDTH 1 /* ADC2R_TO_AIF1ADC2R */
3247#define WM8995_AIF2DACR_TO_AIF1ADC2R 0x0001 /* AIF2DACR_TO_AIF1ADC2R */
3248#define WM8995_AIF2DACR_TO_AIF1ADC2R_MASK 0x0001 /* AIF2DACR_TO_AIF1ADC2R */
3249#define WM8995_AIF2DACR_TO_AIF1ADC2R_SHIFT 0 /* AIF2DACR_TO_AIF1ADC2R */
3250#define WM8995_AIF2DACR_TO_AIF1ADC2R_WIDTH 1 /* AIF2DACR_TO_AIF1ADC2R */
3251
3252/*
3253 * R1552 (0x610) - DAC Softmute
3254 */
3255#define WM8995_DAC_SOFTMUTEMODE 0x0002 /* DAC_SOFTMUTEMODE */
3256#define WM8995_DAC_SOFTMUTEMODE_MASK 0x0002 /* DAC_SOFTMUTEMODE */
3257#define WM8995_DAC_SOFTMUTEMODE_SHIFT 1 /* DAC_SOFTMUTEMODE */
3258#define WM8995_DAC_SOFTMUTEMODE_WIDTH 1 /* DAC_SOFTMUTEMODE */
3259#define WM8995_DAC_MUTERATE 0x0001 /* DAC_MUTERATE */
3260#define WM8995_DAC_MUTERATE_MASK 0x0001 /* DAC_MUTERATE */
3261#define WM8995_DAC_MUTERATE_SHIFT 0 /* DAC_MUTERATE */
3262#define WM8995_DAC_MUTERATE_WIDTH 1 /* DAC_MUTERATE */
3263
3264/*
3265 * R1568 (0x620) - Oversampling
3266 */
3267#define WM8995_ADC_OSR128 0x0002 /* ADC_OSR128 */
3268#define WM8995_ADC_OSR128_MASK 0x0002 /* ADC_OSR128 */
3269#define WM8995_ADC_OSR128_SHIFT 1 /* ADC_OSR128 */
3270#define WM8995_ADC_OSR128_WIDTH 1 /* ADC_OSR128 */
3271#define WM8995_DAC_OSR128 0x0001 /* DAC_OSR128 */
3272#define WM8995_DAC_OSR128_MASK 0x0001 /* DAC_OSR128 */
3273#define WM8995_DAC_OSR128_SHIFT 0 /* DAC_OSR128 */
3274#define WM8995_DAC_OSR128_WIDTH 1 /* DAC_OSR128 */
3275
3276/*
3277 * R1569 (0x621) - Sidetone
3278 */
3279#define WM8995_ST_LPF 0x1000 /* ST_LPF */
3280#define WM8995_ST_LPF_MASK 0x1000 /* ST_LPF */
3281#define WM8995_ST_LPF_SHIFT 12 /* ST_LPF */
3282#define WM8995_ST_LPF_WIDTH 1 /* ST_LPF */
3283#define WM8995_ST_HPF_CUT_MASK 0x0380 /* ST_HPF_CUT - [9:7] */
3284#define WM8995_ST_HPF_CUT_SHIFT 7 /* ST_HPF_CUT - [9:7] */
3285#define WM8995_ST_HPF_CUT_WIDTH 3 /* ST_HPF_CUT - [9:7] */
3286#define WM8995_ST_HPF 0x0040 /* ST_HPF */
3287#define WM8995_ST_HPF_MASK 0x0040 /* ST_HPF */
3288#define WM8995_ST_HPF_SHIFT 6 /* ST_HPF */
3289#define WM8995_ST_HPF_WIDTH 1 /* ST_HPF */
3290#define WM8995_STR_SEL 0x0002 /* STR_SEL */
3291#define WM8995_STR_SEL_MASK 0x0002 /* STR_SEL */
3292#define WM8995_STR_SEL_SHIFT 1 /* STR_SEL */
3293#define WM8995_STR_SEL_WIDTH 1 /* STR_SEL */
3294#define WM8995_STL_SEL 0x0001 /* STL_SEL */
3295#define WM8995_STL_SEL_MASK 0x0001 /* STL_SEL */
3296#define WM8995_STL_SEL_SHIFT 0 /* STL_SEL */
3297#define WM8995_STL_SEL_WIDTH 1 /* STL_SEL */
3298
3299/*
3300 * R1792 (0x700) - GPIO 1
3301 */
3302#define WM8995_GP1_DIR 0x8000 /* GP1_DIR */
3303#define WM8995_GP1_DIR_MASK 0x8000 /* GP1_DIR */
3304#define WM8995_GP1_DIR_SHIFT 15 /* GP1_DIR */
3305#define WM8995_GP1_DIR_WIDTH 1 /* GP1_DIR */
3306#define WM8995_GP1_PU 0x4000 /* GP1_PU */
3307#define WM8995_GP1_PU_MASK 0x4000 /* GP1_PU */
3308#define WM8995_GP1_PU_SHIFT 14 /* GP1_PU */
3309#define WM8995_GP1_PU_WIDTH 1 /* GP1_PU */
3310#define WM8995_GP1_PD 0x2000 /* GP1_PD */
3311#define WM8995_GP1_PD_MASK 0x2000 /* GP1_PD */
3312#define WM8995_GP1_PD_SHIFT 13 /* GP1_PD */
3313#define WM8995_GP1_PD_WIDTH 1 /* GP1_PD */
3314#define WM8995_GP1_POL 0x0400 /* GP1_POL */
3315#define WM8995_GP1_POL_MASK 0x0400 /* GP1_POL */
3316#define WM8995_GP1_POL_SHIFT 10 /* GP1_POL */
3317#define WM8995_GP1_POL_WIDTH 1 /* GP1_POL */
3318#define WM8995_GP1_OP_CFG 0x0200 /* GP1_OP_CFG */
3319#define WM8995_GP1_OP_CFG_MASK 0x0200 /* GP1_OP_CFG */
3320#define WM8995_GP1_OP_CFG_SHIFT 9 /* GP1_OP_CFG */
3321#define WM8995_GP1_OP_CFG_WIDTH 1 /* GP1_OP_CFG */
3322#define WM8995_GP1_DB 0x0100 /* GP1_DB */
3323#define WM8995_GP1_DB_MASK 0x0100 /* GP1_DB */
3324#define WM8995_GP1_DB_SHIFT 8 /* GP1_DB */
3325#define WM8995_GP1_DB_WIDTH 1 /* GP1_DB */
3326#define WM8995_GP1_LVL 0x0040 /* GP1_LVL */
3327#define WM8995_GP1_LVL_MASK 0x0040 /* GP1_LVL */
3328#define WM8995_GP1_LVL_SHIFT 6 /* GP1_LVL */
3329#define WM8995_GP1_LVL_WIDTH 1 /* GP1_LVL */
3330#define WM8995_GP1_FN_MASK 0x001F /* GP1_FN - [4:0] */
3331#define WM8995_GP1_FN_SHIFT 0 /* GP1_FN - [4:0] */
3332#define WM8995_GP1_FN_WIDTH 5 /* GP1_FN - [4:0] */
3333
3334/*
3335 * R1793 (0x701) - GPIO 2
3336 */
3337#define WM8995_GP2_DIR 0x8000 /* GP2_DIR */
3338#define WM8995_GP2_DIR_MASK 0x8000 /* GP2_DIR */
3339#define WM8995_GP2_DIR_SHIFT 15 /* GP2_DIR */
3340#define WM8995_GP2_DIR_WIDTH 1 /* GP2_DIR */
3341#define WM8995_GP2_PU 0x4000 /* GP2_PU */
3342#define WM8995_GP2_PU_MASK 0x4000 /* GP2_PU */
3343#define WM8995_GP2_PU_SHIFT 14 /* GP2_PU */
3344#define WM8995_GP2_PU_WIDTH 1 /* GP2_PU */
3345#define WM8995_GP2_PD 0x2000 /* GP2_PD */
3346#define WM8995_GP2_PD_MASK 0x2000 /* GP2_PD */
3347#define WM8995_GP2_PD_SHIFT 13 /* GP2_PD */
3348#define WM8995_GP2_PD_WIDTH 1 /* GP2_PD */
3349#define WM8995_GP2_POL 0x0400 /* GP2_POL */
3350#define WM8995_GP2_POL_MASK 0x0400 /* GP2_POL */
3351#define WM8995_GP2_POL_SHIFT 10 /* GP2_POL */
3352#define WM8995_GP2_POL_WIDTH 1 /* GP2_POL */
3353#define WM8995_GP2_OP_CFG 0x0200 /* GP2_OP_CFG */
3354#define WM8995_GP2_OP_CFG_MASK 0x0200 /* GP2_OP_CFG */
3355#define WM8995_GP2_OP_CFG_SHIFT 9 /* GP2_OP_CFG */
3356#define WM8995_GP2_OP_CFG_WIDTH 1 /* GP2_OP_CFG */
3357#define WM8995_GP2_DB 0x0100 /* GP2_DB */
3358#define WM8995_GP2_DB_MASK 0x0100 /* GP2_DB */
3359#define WM8995_GP2_DB_SHIFT 8 /* GP2_DB */
3360#define WM8995_GP2_DB_WIDTH 1 /* GP2_DB */
3361#define WM8995_GP2_LVL 0x0040 /* GP2_LVL */
3362#define WM8995_GP2_LVL_MASK 0x0040 /* GP2_LVL */
3363#define WM8995_GP2_LVL_SHIFT 6 /* GP2_LVL */
3364#define WM8995_GP2_LVL_WIDTH 1 /* GP2_LVL */
3365#define WM8995_GP2_FN_MASK 0x001F /* GP2_FN - [4:0] */
3366#define WM8995_GP2_FN_SHIFT 0 /* GP2_FN - [4:0] */
3367#define WM8995_GP2_FN_WIDTH 5 /* GP2_FN - [4:0] */
3368
3369/*
3370 * R1794 (0x702) - GPIO 3
3371 */
3372#define WM8995_GP3_DIR 0x8000 /* GP3_DIR */
3373#define WM8995_GP3_DIR_MASK 0x8000 /* GP3_DIR */
3374#define WM8995_GP3_DIR_SHIFT 15 /* GP3_DIR */
3375#define WM8995_GP3_DIR_WIDTH 1 /* GP3_DIR */
3376#define WM8995_GP3_PU 0x4000 /* GP3_PU */
3377#define WM8995_GP3_PU_MASK 0x4000 /* GP3_PU */
3378#define WM8995_GP3_PU_SHIFT 14 /* GP3_PU */
3379#define WM8995_GP3_PU_WIDTH 1 /* GP3_PU */
3380#define WM8995_GP3_PD 0x2000 /* GP3_PD */
3381#define WM8995_GP3_PD_MASK 0x2000 /* GP3_PD */
3382#define WM8995_GP3_PD_SHIFT 13 /* GP3_PD */
3383#define WM8995_GP3_PD_WIDTH 1 /* GP3_PD */
3384#define WM8995_GP3_POL 0x0400 /* GP3_POL */
3385#define WM8995_GP3_POL_MASK 0x0400 /* GP3_POL */
3386#define WM8995_GP3_POL_SHIFT 10 /* GP3_POL */
3387#define WM8995_GP3_POL_WIDTH 1 /* GP3_POL */
3388#define WM8995_GP3_OP_CFG 0x0200 /* GP3_OP_CFG */
3389#define WM8995_GP3_OP_CFG_MASK 0x0200 /* GP3_OP_CFG */
3390#define WM8995_GP3_OP_CFG_SHIFT 9 /* GP3_OP_CFG */
3391#define WM8995_GP3_OP_CFG_WIDTH 1 /* GP3_OP_CFG */
3392#define WM8995_GP3_DB 0x0100 /* GP3_DB */
3393#define WM8995_GP3_DB_MASK 0x0100 /* GP3_DB */
3394#define WM8995_GP3_DB_SHIFT 8 /* GP3_DB */
3395#define WM8995_GP3_DB_WIDTH 1 /* GP3_DB */
3396#define WM8995_GP3_LVL 0x0040 /* GP3_LVL */
3397#define WM8995_GP3_LVL_MASK 0x0040 /* GP3_LVL */
3398#define WM8995_GP3_LVL_SHIFT 6 /* GP3_LVL */
3399#define WM8995_GP3_LVL_WIDTH 1 /* GP3_LVL */
3400#define WM8995_GP3_FN_MASK 0x001F /* GP3_FN - [4:0] */
3401#define WM8995_GP3_FN_SHIFT 0 /* GP3_FN - [4:0] */
3402#define WM8995_GP3_FN_WIDTH 5 /* GP3_FN - [4:0] */
3403
3404/*
3405 * R1795 (0x703) - GPIO 4
3406 */
3407#define WM8995_GP4_DIR 0x8000 /* GP4_DIR */
3408#define WM8995_GP4_DIR_MASK 0x8000 /* GP4_DIR */
3409#define WM8995_GP4_DIR_SHIFT 15 /* GP4_DIR */
3410#define WM8995_GP4_DIR_WIDTH 1 /* GP4_DIR */
3411#define WM8995_GP4_PU 0x4000 /* GP4_PU */
3412#define WM8995_GP4_PU_MASK 0x4000 /* GP4_PU */
3413#define WM8995_GP4_PU_SHIFT 14 /* GP4_PU */
3414#define WM8995_GP4_PU_WIDTH 1 /* GP4_PU */
3415#define WM8995_GP4_PD 0x2000 /* GP4_PD */
3416#define WM8995_GP4_PD_MASK 0x2000 /* GP4_PD */
3417#define WM8995_GP4_PD_SHIFT 13 /* GP4_PD */
3418#define WM8995_GP4_PD_WIDTH 1 /* GP4_PD */
3419#define WM8995_GP4_POL 0x0400 /* GP4_POL */
3420#define WM8995_GP4_POL_MASK 0x0400 /* GP4_POL */
3421#define WM8995_GP4_POL_SHIFT 10 /* GP4_POL */
3422#define WM8995_GP4_POL_WIDTH 1 /* GP4_POL */
3423#define WM8995_GP4_OP_CFG 0x0200 /* GP4_OP_CFG */
3424#define WM8995_GP4_OP_CFG_MASK 0x0200 /* GP4_OP_CFG */
3425#define WM8995_GP4_OP_CFG_SHIFT 9 /* GP4_OP_CFG */
3426#define WM8995_GP4_OP_CFG_WIDTH 1 /* GP4_OP_CFG */
3427#define WM8995_GP4_DB 0x0100 /* GP4_DB */
3428#define WM8995_GP4_DB_MASK 0x0100 /* GP4_DB */
3429#define WM8995_GP4_DB_SHIFT 8 /* GP4_DB */
3430#define WM8995_GP4_DB_WIDTH 1 /* GP4_DB */
3431#define WM8995_GP4_LVL 0x0040 /* GP4_LVL */
3432#define WM8995_GP4_LVL_MASK 0x0040 /* GP4_LVL */
3433#define WM8995_GP4_LVL_SHIFT 6 /* GP4_LVL */
3434#define WM8995_GP4_LVL_WIDTH 1 /* GP4_LVL */
3435#define WM8995_GP4_FN_MASK 0x001F /* GP4_FN - [4:0] */
3436#define WM8995_GP4_FN_SHIFT 0 /* GP4_FN - [4:0] */
3437#define WM8995_GP4_FN_WIDTH 5 /* GP4_FN - [4:0] */
3438
3439/*
3440 * R1796 (0x704) - GPIO 5
3441 */
3442#define WM8995_GP5_DIR 0x8000 /* GP5_DIR */
3443#define WM8995_GP5_DIR_MASK 0x8000 /* GP5_DIR */
3444#define WM8995_GP5_DIR_SHIFT 15 /* GP5_DIR */
3445#define WM8995_GP5_DIR_WIDTH 1 /* GP5_DIR */
3446#define WM8995_GP5_PU 0x4000 /* GP5_PU */
3447#define WM8995_GP5_PU_MASK 0x4000 /* GP5_PU */
3448#define WM8995_GP5_PU_SHIFT 14 /* GP5_PU */
3449#define WM8995_GP5_PU_WIDTH 1 /* GP5_PU */
3450#define WM8995_GP5_PD 0x2000 /* GP5_PD */
3451#define WM8995_GP5_PD_MASK 0x2000 /* GP5_PD */
3452#define WM8995_GP5_PD_SHIFT 13 /* GP5_PD */
3453#define WM8995_GP5_PD_WIDTH 1 /* GP5_PD */
3454#define WM8995_GP5_POL 0x0400 /* GP5_POL */
3455#define WM8995_GP5_POL_MASK 0x0400 /* GP5_POL */
3456#define WM8995_GP5_POL_SHIFT 10 /* GP5_POL */
3457#define WM8995_GP5_POL_WIDTH 1 /* GP5_POL */
3458#define WM8995_GP5_OP_CFG 0x0200 /* GP5_OP_CFG */
3459#define WM8995_GP5_OP_CFG_MASK 0x0200 /* GP5_OP_CFG */
3460#define WM8995_GP5_OP_CFG_SHIFT 9 /* GP5_OP_CFG */
3461#define WM8995_GP5_OP_CFG_WIDTH 1 /* GP5_OP_CFG */
3462#define WM8995_GP5_DB 0x0100 /* GP5_DB */
3463#define WM8995_GP5_DB_MASK 0x0100 /* GP5_DB */
3464#define WM8995_GP5_DB_SHIFT 8 /* GP5_DB */
3465#define WM8995_GP5_DB_WIDTH 1 /* GP5_DB */
3466#define WM8995_GP5_LVL 0x0040 /* GP5_LVL */
3467#define WM8995_GP5_LVL_MASK 0x0040 /* GP5_LVL */
3468#define WM8995_GP5_LVL_SHIFT 6 /* GP5_LVL */
3469#define WM8995_GP5_LVL_WIDTH 1 /* GP5_LVL */
3470#define WM8995_GP5_FN_MASK 0x001F /* GP5_FN - [4:0] */
3471#define WM8995_GP5_FN_SHIFT 0 /* GP5_FN - [4:0] */
3472#define WM8995_GP5_FN_WIDTH 5 /* GP5_FN - [4:0] */
3473
3474/*
3475 * R1797 (0x705) - GPIO 6
3476 */
3477#define WM8995_GP6_DIR 0x8000 /* GP6_DIR */
3478#define WM8995_GP6_DIR_MASK 0x8000 /* GP6_DIR */
3479#define WM8995_GP6_DIR_SHIFT 15 /* GP6_DIR */
3480#define WM8995_GP6_DIR_WIDTH 1 /* GP6_DIR */
3481#define WM8995_GP6_PU 0x4000 /* GP6_PU */
3482#define WM8995_GP6_PU_MASK 0x4000 /* GP6_PU */
3483#define WM8995_GP6_PU_SHIFT 14 /* GP6_PU */
3484#define WM8995_GP6_PU_WIDTH 1 /* GP6_PU */
3485#define WM8995_GP6_PD 0x2000 /* GP6_PD */
3486#define WM8995_GP6_PD_MASK 0x2000 /* GP6_PD */
3487#define WM8995_GP6_PD_SHIFT 13 /* GP6_PD */
3488#define WM8995_GP6_PD_WIDTH 1 /* GP6_PD */
3489#define WM8995_GP6_POL 0x0400 /* GP6_POL */
3490#define WM8995_GP6_POL_MASK 0x0400 /* GP6_POL */
3491#define WM8995_GP6_POL_SHIFT 10 /* GP6_POL */
3492#define WM8995_GP6_POL_WIDTH 1 /* GP6_POL */
3493#define WM8995_GP6_OP_CFG 0x0200 /* GP6_OP_CFG */
3494#define WM8995_GP6_OP_CFG_MASK 0x0200 /* GP6_OP_CFG */
3495#define WM8995_GP6_OP_CFG_SHIFT 9 /* GP6_OP_CFG */
3496#define WM8995_GP6_OP_CFG_WIDTH 1 /* GP6_OP_CFG */
3497#define WM8995_GP6_DB 0x0100 /* GP6_DB */
3498#define WM8995_GP6_DB_MASK 0x0100 /* GP6_DB */
3499#define WM8995_GP6_DB_SHIFT 8 /* GP6_DB */
3500#define WM8995_GP6_DB_WIDTH 1 /* GP6_DB */
3501#define WM8995_GP6_LVL 0x0040 /* GP6_LVL */
3502#define WM8995_GP6_LVL_MASK 0x0040 /* GP6_LVL */
3503#define WM8995_GP6_LVL_SHIFT 6 /* GP6_LVL */
3504#define WM8995_GP6_LVL_WIDTH 1 /* GP6_LVL */
3505#define WM8995_GP6_FN_MASK 0x001F /* GP6_FN - [4:0] */
3506#define WM8995_GP6_FN_SHIFT 0 /* GP6_FN - [4:0] */
3507#define WM8995_GP6_FN_WIDTH 5 /* GP6_FN - [4:0] */
3508
3509/*
3510 * R1798 (0x706) - GPIO 7
3511 */
3512#define WM8995_GP7_DIR 0x8000 /* GP7_DIR */
3513#define WM8995_GP7_DIR_MASK 0x8000 /* GP7_DIR */
3514#define WM8995_GP7_DIR_SHIFT 15 /* GP7_DIR */
3515#define WM8995_GP7_DIR_WIDTH 1 /* GP7_DIR */
3516#define WM8995_GP7_PU 0x4000 /* GP7_PU */
3517#define WM8995_GP7_PU_MASK 0x4000 /* GP7_PU */
3518#define WM8995_GP7_PU_SHIFT 14 /* GP7_PU */
3519#define WM8995_GP7_PU_WIDTH 1 /* GP7_PU */
3520#define WM8995_GP7_PD 0x2000 /* GP7_PD */
3521#define WM8995_GP7_PD_MASK 0x2000 /* GP7_PD */
3522#define WM8995_GP7_PD_SHIFT 13 /* GP7_PD */
3523#define WM8995_GP7_PD_WIDTH 1 /* GP7_PD */
3524#define WM8995_GP7_POL 0x0400 /* GP7_POL */
3525#define WM8995_GP7_POL_MASK 0x0400 /* GP7_POL */
3526#define WM8995_GP7_POL_SHIFT 10 /* GP7_POL */
3527#define WM8995_GP7_POL_WIDTH 1 /* GP7_POL */
3528#define WM8995_GP7_OP_CFG 0x0200 /* GP7_OP_CFG */
3529#define WM8995_GP7_OP_CFG_MASK 0x0200 /* GP7_OP_CFG */
3530#define WM8995_GP7_OP_CFG_SHIFT 9 /* GP7_OP_CFG */
3531#define WM8995_GP7_OP_CFG_WIDTH 1 /* GP7_OP_CFG */
3532#define WM8995_GP7_DB 0x0100 /* GP7_DB */
3533#define WM8995_GP7_DB_MASK 0x0100 /* GP7_DB */
3534#define WM8995_GP7_DB_SHIFT 8 /* GP7_DB */
3535#define WM8995_GP7_DB_WIDTH 1 /* GP7_DB */
3536#define WM8995_GP7_LVL 0x0040 /* GP7_LVL */
3537#define WM8995_GP7_LVL_MASK 0x0040 /* GP7_LVL */
3538#define WM8995_GP7_LVL_SHIFT 6 /* GP7_LVL */
3539#define WM8995_GP7_LVL_WIDTH 1 /* GP7_LVL */
3540#define WM8995_GP7_FN_MASK 0x001F /* GP7_FN - [4:0] */
3541#define WM8995_GP7_FN_SHIFT 0 /* GP7_FN - [4:0] */
3542#define WM8995_GP7_FN_WIDTH 5 /* GP7_FN - [4:0] */
3543
3544/*
3545 * R1799 (0x707) - GPIO 8
3546 */
3547#define WM8995_GP8_DIR 0x8000 /* GP8_DIR */
3548#define WM8995_GP8_DIR_MASK 0x8000 /* GP8_DIR */
3549#define WM8995_GP8_DIR_SHIFT 15 /* GP8_DIR */
3550#define WM8995_GP8_DIR_WIDTH 1 /* GP8_DIR */
3551#define WM8995_GP8_PU 0x4000 /* GP8_PU */
3552#define WM8995_GP8_PU_MASK 0x4000 /* GP8_PU */
3553#define WM8995_GP8_PU_SHIFT 14 /* GP8_PU */
3554#define WM8995_GP8_PU_WIDTH 1 /* GP8_PU */
3555#define WM8995_GP8_PD 0x2000 /* GP8_PD */
3556#define WM8995_GP8_PD_MASK 0x2000 /* GP8_PD */
3557#define WM8995_GP8_PD_SHIFT 13 /* GP8_PD */
3558#define WM8995_GP8_PD_WIDTH 1 /* GP8_PD */
3559#define WM8995_GP8_POL 0x0400 /* GP8_POL */
3560#define WM8995_GP8_POL_MASK 0x0400 /* GP8_POL */
3561#define WM8995_GP8_POL_SHIFT 10 /* GP8_POL */
3562#define WM8995_GP8_POL_WIDTH 1 /* GP8_POL */
3563#define WM8995_GP8_OP_CFG 0x0200 /* GP8_OP_CFG */
3564#define WM8995_GP8_OP_CFG_MASK 0x0200 /* GP8_OP_CFG */
3565#define WM8995_GP8_OP_CFG_SHIFT 9 /* GP8_OP_CFG */
3566#define WM8995_GP8_OP_CFG_WIDTH 1 /* GP8_OP_CFG */
3567#define WM8995_GP8_DB 0x0100 /* GP8_DB */
3568#define WM8995_GP8_DB_MASK 0x0100 /* GP8_DB */
3569#define WM8995_GP8_DB_SHIFT 8 /* GP8_DB */
3570#define WM8995_GP8_DB_WIDTH 1 /* GP8_DB */
3571#define WM8995_GP8_LVL 0x0040 /* GP8_LVL */
3572#define WM8995_GP8_LVL_MASK 0x0040 /* GP8_LVL */
3573#define WM8995_GP8_LVL_SHIFT 6 /* GP8_LVL */
3574#define WM8995_GP8_LVL_WIDTH 1 /* GP8_LVL */
3575#define WM8995_GP8_FN_MASK 0x001F /* GP8_FN - [4:0] */
3576#define WM8995_GP8_FN_SHIFT 0 /* GP8_FN - [4:0] */
3577#define WM8995_GP8_FN_WIDTH 5 /* GP8_FN - [4:0] */
3578
3579/*
3580 * R1800 (0x708) - GPIO 9
3581 */
3582#define WM8995_GP9_DIR 0x8000 /* GP9_DIR */
3583#define WM8995_GP9_DIR_MASK 0x8000 /* GP9_DIR */
3584#define WM8995_GP9_DIR_SHIFT 15 /* GP9_DIR */
3585#define WM8995_GP9_DIR_WIDTH 1 /* GP9_DIR */
3586#define WM8995_GP9_PU 0x4000 /* GP9_PU */
3587#define WM8995_GP9_PU_MASK 0x4000 /* GP9_PU */
3588#define WM8995_GP9_PU_SHIFT 14 /* GP9_PU */
3589#define WM8995_GP9_PU_WIDTH 1 /* GP9_PU */
3590#define WM8995_GP9_PD 0x2000 /* GP9_PD */
3591#define WM8995_GP9_PD_MASK 0x2000 /* GP9_PD */
3592#define WM8995_GP9_PD_SHIFT 13 /* GP9_PD */
3593#define WM8995_GP9_PD_WIDTH 1 /* GP9_PD */
3594#define WM8995_GP9_POL 0x0400 /* GP9_POL */
3595#define WM8995_GP9_POL_MASK 0x0400 /* GP9_POL */
3596#define WM8995_GP9_POL_SHIFT 10 /* GP9_POL */
3597#define WM8995_GP9_POL_WIDTH 1 /* GP9_POL */
3598#define WM8995_GP9_OP_CFG 0x0200 /* GP9_OP_CFG */
3599#define WM8995_GP9_OP_CFG_MASK 0x0200 /* GP9_OP_CFG */
3600#define WM8995_GP9_OP_CFG_SHIFT 9 /* GP9_OP_CFG */
3601#define WM8995_GP9_OP_CFG_WIDTH 1 /* GP9_OP_CFG */
3602#define WM8995_GP9_DB 0x0100 /* GP9_DB */
3603#define WM8995_GP9_DB_MASK 0x0100 /* GP9_DB */
3604#define WM8995_GP9_DB_SHIFT 8 /* GP9_DB */
3605#define WM8995_GP9_DB_WIDTH 1 /* GP9_DB */
3606#define WM8995_GP9_LVL 0x0040 /* GP9_LVL */
3607#define WM8995_GP9_LVL_MASK 0x0040 /* GP9_LVL */
3608#define WM8995_GP9_LVL_SHIFT 6 /* GP9_LVL */
3609#define WM8995_GP9_LVL_WIDTH 1 /* GP9_LVL */
3610#define WM8995_GP9_FN_MASK 0x001F /* GP9_FN - [4:0] */
3611#define WM8995_GP9_FN_SHIFT 0 /* GP9_FN - [4:0] */
3612#define WM8995_GP9_FN_WIDTH 5 /* GP9_FN - [4:0] */
3613
3614/*
3615 * R1801 (0x709) - GPIO 10
3616 */
3617#define WM8995_GP10_DIR 0x8000 /* GP10_DIR */
3618#define WM8995_GP10_DIR_MASK 0x8000 /* GP10_DIR */
3619#define WM8995_GP10_DIR_SHIFT 15 /* GP10_DIR */
3620#define WM8995_GP10_DIR_WIDTH 1 /* GP10_DIR */
3621#define WM8995_GP10_PU 0x4000 /* GP10_PU */
3622#define WM8995_GP10_PU_MASK 0x4000 /* GP10_PU */
3623#define WM8995_GP10_PU_SHIFT 14 /* GP10_PU */
3624#define WM8995_GP10_PU_WIDTH 1 /* GP10_PU */
3625#define WM8995_GP10_PD 0x2000 /* GP10_PD */
3626#define WM8995_GP10_PD_MASK 0x2000 /* GP10_PD */
3627#define WM8995_GP10_PD_SHIFT 13 /* GP10_PD */
3628#define WM8995_GP10_PD_WIDTH 1 /* GP10_PD */
3629#define WM8995_GP10_POL 0x0400 /* GP10_POL */
3630#define WM8995_GP10_POL_MASK 0x0400 /* GP10_POL */
3631#define WM8995_GP10_POL_SHIFT 10 /* GP10_POL */
3632#define WM8995_GP10_POL_WIDTH 1 /* GP10_POL */
3633#define WM8995_GP10_OP_CFG 0x0200 /* GP10_OP_CFG */
3634#define WM8995_GP10_OP_CFG_MASK 0x0200 /* GP10_OP_CFG */
3635#define WM8995_GP10_OP_CFG_SHIFT 9 /* GP10_OP_CFG */
3636#define WM8995_GP10_OP_CFG_WIDTH 1 /* GP10_OP_CFG */
3637#define WM8995_GP10_DB 0x0100 /* GP10_DB */
3638#define WM8995_GP10_DB_MASK 0x0100 /* GP10_DB */
3639#define WM8995_GP10_DB_SHIFT 8 /* GP10_DB */
3640#define WM8995_GP10_DB_WIDTH 1 /* GP10_DB */
3641#define WM8995_GP10_LVL 0x0040 /* GP10_LVL */
3642#define WM8995_GP10_LVL_MASK 0x0040 /* GP10_LVL */
3643#define WM8995_GP10_LVL_SHIFT 6 /* GP10_LVL */
3644#define WM8995_GP10_LVL_WIDTH 1 /* GP10_LVL */
3645#define WM8995_GP10_FN_MASK 0x001F /* GP10_FN - [4:0] */
3646#define WM8995_GP10_FN_SHIFT 0 /* GP10_FN - [4:0] */
3647#define WM8995_GP10_FN_WIDTH 5 /* GP10_FN - [4:0] */
3648
3649/*
3650 * R1802 (0x70A) - GPIO 11
3651 */
3652#define WM8995_GP11_DIR 0x8000 /* GP11_DIR */
3653#define WM8995_GP11_DIR_MASK 0x8000 /* GP11_DIR */
3654#define WM8995_GP11_DIR_SHIFT 15 /* GP11_DIR */
3655#define WM8995_GP11_DIR_WIDTH 1 /* GP11_DIR */
3656#define WM8995_GP11_PU 0x4000 /* GP11_PU */
3657#define WM8995_GP11_PU_MASK 0x4000 /* GP11_PU */
3658#define WM8995_GP11_PU_SHIFT 14 /* GP11_PU */
3659#define WM8995_GP11_PU_WIDTH 1 /* GP11_PU */
3660#define WM8995_GP11_PD 0x2000 /* GP11_PD */
3661#define WM8995_GP11_PD_MASK 0x2000 /* GP11_PD */
3662#define WM8995_GP11_PD_SHIFT 13 /* GP11_PD */
3663#define WM8995_GP11_PD_WIDTH 1 /* GP11_PD */
3664#define WM8995_GP11_POL 0x0400 /* GP11_POL */
3665#define WM8995_GP11_POL_MASK 0x0400 /* GP11_POL */
3666#define WM8995_GP11_POL_SHIFT 10 /* GP11_POL */
3667#define WM8995_GP11_POL_WIDTH 1 /* GP11_POL */
3668#define WM8995_GP11_OP_CFG 0x0200 /* GP11_OP_CFG */
3669#define WM8995_GP11_OP_CFG_MASK 0x0200 /* GP11_OP_CFG */
3670#define WM8995_GP11_OP_CFG_SHIFT 9 /* GP11_OP_CFG */
3671#define WM8995_GP11_OP_CFG_WIDTH 1 /* GP11_OP_CFG */
3672#define WM8995_GP11_DB 0x0100 /* GP11_DB */
3673#define WM8995_GP11_DB_MASK 0x0100 /* GP11_DB */
3674#define WM8995_GP11_DB_SHIFT 8 /* GP11_DB */
3675#define WM8995_GP11_DB_WIDTH 1 /* GP11_DB */
3676#define WM8995_GP11_LVL 0x0040 /* GP11_LVL */
3677#define WM8995_GP11_LVL_MASK 0x0040 /* GP11_LVL */
3678#define WM8995_GP11_LVL_SHIFT 6 /* GP11_LVL */
3679#define WM8995_GP11_LVL_WIDTH 1 /* GP11_LVL */
3680#define WM8995_GP11_FN_MASK 0x001F /* GP11_FN - [4:0] */
3681#define WM8995_GP11_FN_SHIFT 0 /* GP11_FN - [4:0] */
3682#define WM8995_GP11_FN_WIDTH 5 /* GP11_FN - [4:0] */
3683
3684/*
3685 * R1803 (0x70B) - GPIO 12
3686 */
3687#define WM8995_GP12_DIR 0x8000 /* GP12_DIR */
3688#define WM8995_GP12_DIR_MASK 0x8000 /* GP12_DIR */
3689#define WM8995_GP12_DIR_SHIFT 15 /* GP12_DIR */
3690#define WM8995_GP12_DIR_WIDTH 1 /* GP12_DIR */
3691#define WM8995_GP12_PU 0x4000 /* GP12_PU */
3692#define WM8995_GP12_PU_MASK 0x4000 /* GP12_PU */
3693#define WM8995_GP12_PU_SHIFT 14 /* GP12_PU */
3694#define WM8995_GP12_PU_WIDTH 1 /* GP12_PU */
3695#define WM8995_GP12_PD 0x2000 /* GP12_PD */
3696#define WM8995_GP12_PD_MASK 0x2000 /* GP12_PD */
3697#define WM8995_GP12_PD_SHIFT 13 /* GP12_PD */
3698#define WM8995_GP12_PD_WIDTH 1 /* GP12_PD */
3699#define WM8995_GP12_POL 0x0400 /* GP12_POL */
3700#define WM8995_GP12_POL_MASK 0x0400 /* GP12_POL */
3701#define WM8995_GP12_POL_SHIFT 10 /* GP12_POL */
3702#define WM8995_GP12_POL_WIDTH 1 /* GP12_POL */
3703#define WM8995_GP12_OP_CFG 0x0200 /* GP12_OP_CFG */
3704#define WM8995_GP12_OP_CFG_MASK 0x0200 /* GP12_OP_CFG */
3705#define WM8995_GP12_OP_CFG_SHIFT 9 /* GP12_OP_CFG */
3706#define WM8995_GP12_OP_CFG_WIDTH 1 /* GP12_OP_CFG */
3707#define WM8995_GP12_DB 0x0100 /* GP12_DB */
3708#define WM8995_GP12_DB_MASK 0x0100 /* GP12_DB */
3709#define WM8995_GP12_DB_SHIFT 8 /* GP12_DB */
3710#define WM8995_GP12_DB_WIDTH 1 /* GP12_DB */
3711#define WM8995_GP12_LVL 0x0040 /* GP12_LVL */
3712#define WM8995_GP12_LVL_MASK 0x0040 /* GP12_LVL */
3713#define WM8995_GP12_LVL_SHIFT 6 /* GP12_LVL */
3714#define WM8995_GP12_LVL_WIDTH 1 /* GP12_LVL */
3715#define WM8995_GP12_FN_MASK 0x001F /* GP12_FN - [4:0] */
3716#define WM8995_GP12_FN_SHIFT 0 /* GP12_FN - [4:0] */
3717#define WM8995_GP12_FN_WIDTH 5 /* GP12_FN - [4:0] */
3718
3719/*
3720 * R1804 (0x70C) - GPIO 13
3721 */
3722#define WM8995_GP13_DIR 0x8000 /* GP13_DIR */
3723#define WM8995_GP13_DIR_MASK 0x8000 /* GP13_DIR */
3724#define WM8995_GP13_DIR_SHIFT 15 /* GP13_DIR */
3725#define WM8995_GP13_DIR_WIDTH 1 /* GP13_DIR */
3726#define WM8995_GP13_PU 0x4000 /* GP13_PU */
3727#define WM8995_GP13_PU_MASK 0x4000 /* GP13_PU */
3728#define WM8995_GP13_PU_SHIFT 14 /* GP13_PU */
3729#define WM8995_GP13_PU_WIDTH 1 /* GP13_PU */
3730#define WM8995_GP13_PD 0x2000 /* GP13_PD */
3731#define WM8995_GP13_PD_MASK 0x2000 /* GP13_PD */
3732#define WM8995_GP13_PD_SHIFT 13 /* GP13_PD */
3733#define WM8995_GP13_PD_WIDTH 1 /* GP13_PD */
3734#define WM8995_GP13_POL 0x0400 /* GP13_POL */
3735#define WM8995_GP13_POL_MASK 0x0400 /* GP13_POL */
3736#define WM8995_GP13_POL_SHIFT 10 /* GP13_POL */
3737#define WM8995_GP13_POL_WIDTH 1 /* GP13_POL */
3738#define WM8995_GP13_OP_CFG 0x0200 /* GP13_OP_CFG */
3739#define WM8995_GP13_OP_CFG_MASK 0x0200 /* GP13_OP_CFG */
3740#define WM8995_GP13_OP_CFG_SHIFT 9 /* GP13_OP_CFG */
3741#define WM8995_GP13_OP_CFG_WIDTH 1 /* GP13_OP_CFG */
3742#define WM8995_GP13_DB 0x0100 /* GP13_DB */
3743#define WM8995_GP13_DB_MASK 0x0100 /* GP13_DB */
3744#define WM8995_GP13_DB_SHIFT 8 /* GP13_DB */
3745#define WM8995_GP13_DB_WIDTH 1 /* GP13_DB */
3746#define WM8995_GP13_LVL 0x0040 /* GP13_LVL */
3747#define WM8995_GP13_LVL_MASK 0x0040 /* GP13_LVL */
3748#define WM8995_GP13_LVL_SHIFT 6 /* GP13_LVL */
3749#define WM8995_GP13_LVL_WIDTH 1 /* GP13_LVL */
3750#define WM8995_GP13_FN_MASK 0x001F /* GP13_FN - [4:0] */
3751#define WM8995_GP13_FN_SHIFT 0 /* GP13_FN - [4:0] */
3752#define WM8995_GP13_FN_WIDTH 5 /* GP13_FN - [4:0] */
3753
3754/*
3755 * R1805 (0x70D) - GPIO 14
3756 */
3757#define WM8995_GP14_DIR 0x8000 /* GP14_DIR */
3758#define WM8995_GP14_DIR_MASK 0x8000 /* GP14_DIR */
3759#define WM8995_GP14_DIR_SHIFT 15 /* GP14_DIR */
3760#define WM8995_GP14_DIR_WIDTH 1 /* GP14_DIR */
3761#define WM8995_GP14_PU 0x4000 /* GP14_PU */
3762#define WM8995_GP14_PU_MASK 0x4000 /* GP14_PU */
3763#define WM8995_GP14_PU_SHIFT 14 /* GP14_PU */
3764#define WM8995_GP14_PU_WIDTH 1 /* GP14_PU */
3765#define WM8995_GP14_PD 0x2000 /* GP14_PD */
3766#define WM8995_GP14_PD_MASK 0x2000 /* GP14_PD */
3767#define WM8995_GP14_PD_SHIFT 13 /* GP14_PD */
3768#define WM8995_GP14_PD_WIDTH 1 /* GP14_PD */
3769#define WM8995_GP14_POL 0x0400 /* GP14_POL */
3770#define WM8995_GP14_POL_MASK 0x0400 /* GP14_POL */
3771#define WM8995_GP14_POL_SHIFT 10 /* GP14_POL */
3772#define WM8995_GP14_POL_WIDTH 1 /* GP14_POL */
3773#define WM8995_GP14_OP_CFG 0x0200 /* GP14_OP_CFG */
3774#define WM8995_GP14_OP_CFG_MASK 0x0200 /* GP14_OP_CFG */
3775#define WM8995_GP14_OP_CFG_SHIFT 9 /* GP14_OP_CFG */
3776#define WM8995_GP14_OP_CFG_WIDTH 1 /* GP14_OP_CFG */
3777#define WM8995_GP14_DB 0x0100 /* GP14_DB */
3778#define WM8995_GP14_DB_MASK 0x0100 /* GP14_DB */
3779#define WM8995_GP14_DB_SHIFT 8 /* GP14_DB */
3780#define WM8995_GP14_DB_WIDTH 1 /* GP14_DB */
3781#define WM8995_GP14_LVL 0x0040 /* GP14_LVL */
3782#define WM8995_GP14_LVL_MASK 0x0040 /* GP14_LVL */
3783#define WM8995_GP14_LVL_SHIFT 6 /* GP14_LVL */
3784#define WM8995_GP14_LVL_WIDTH 1 /* GP14_LVL */
3785#define WM8995_GP14_FN_MASK 0x001F /* GP14_FN - [4:0] */
3786#define WM8995_GP14_FN_SHIFT 0 /* GP14_FN - [4:0] */
3787#define WM8995_GP14_FN_WIDTH 5 /* GP14_FN - [4:0] */
3788
3789/*
3790 * R1824 (0x720) - Pull Control (1)
3791 */
3792#define WM8995_DMICDAT3_PD 0x4000 /* DMICDAT3_PD */
3793#define WM8995_DMICDAT3_PD_MASK 0x4000 /* DMICDAT3_PD */
3794#define WM8995_DMICDAT3_PD_SHIFT 14 /* DMICDAT3_PD */
3795#define WM8995_DMICDAT3_PD_WIDTH 1 /* DMICDAT3_PD */
3796#define WM8995_DMICDAT2_PD 0x1000 /* DMICDAT2_PD */
3797#define WM8995_DMICDAT2_PD_MASK 0x1000 /* DMICDAT2_PD */
3798#define WM8995_DMICDAT2_PD_SHIFT 12 /* DMICDAT2_PD */
3799#define WM8995_DMICDAT2_PD_WIDTH 1 /* DMICDAT2_PD */
3800#define WM8995_DMICDAT1_PD 0x0400 /* DMICDAT1_PD */
3801#define WM8995_DMICDAT1_PD_MASK 0x0400 /* DMICDAT1_PD */
3802#define WM8995_DMICDAT1_PD_SHIFT 10 /* DMICDAT1_PD */
3803#define WM8995_DMICDAT1_PD_WIDTH 1 /* DMICDAT1_PD */
3804#define WM8995_MCLK2_PU 0x0200 /* MCLK2_PU */
3805#define WM8995_MCLK2_PU_MASK 0x0200 /* MCLK2_PU */
3806#define WM8995_MCLK2_PU_SHIFT 9 /* MCLK2_PU */
3807#define WM8995_MCLK2_PU_WIDTH 1 /* MCLK2_PU */
3808#define WM8995_MCLK2_PD 0x0100 /* MCLK2_PD */
3809#define WM8995_MCLK2_PD_MASK 0x0100 /* MCLK2_PD */
3810#define WM8995_MCLK2_PD_SHIFT 8 /* MCLK2_PD */
3811#define WM8995_MCLK2_PD_WIDTH 1 /* MCLK2_PD */
3812#define WM8995_MCLK1_PU 0x0080 /* MCLK1_PU */
3813#define WM8995_MCLK1_PU_MASK 0x0080 /* MCLK1_PU */
3814#define WM8995_MCLK1_PU_SHIFT 7 /* MCLK1_PU */
3815#define WM8995_MCLK1_PU_WIDTH 1 /* MCLK1_PU */
3816#define WM8995_MCLK1_PD 0x0040 /* MCLK1_PD */
3817#define WM8995_MCLK1_PD_MASK 0x0040 /* MCLK1_PD */
3818#define WM8995_MCLK1_PD_SHIFT 6 /* MCLK1_PD */
3819#define WM8995_MCLK1_PD_WIDTH 1 /* MCLK1_PD */
3820#define WM8995_DACDAT1_PU 0x0020 /* DACDAT1_PU */
3821#define WM8995_DACDAT1_PU_MASK 0x0020 /* DACDAT1_PU */
3822#define WM8995_DACDAT1_PU_SHIFT 5 /* DACDAT1_PU */
3823#define WM8995_DACDAT1_PU_WIDTH 1 /* DACDAT1_PU */
3824#define WM8995_DACDAT1_PD 0x0010 /* DACDAT1_PD */
3825#define WM8995_DACDAT1_PD_MASK 0x0010 /* DACDAT1_PD */
3826#define WM8995_DACDAT1_PD_SHIFT 4 /* DACDAT1_PD */
3827#define WM8995_DACDAT1_PD_WIDTH 1 /* DACDAT1_PD */
3828#define WM8995_DACLRCLK1_PU 0x0008 /* DACLRCLK1_PU */
3829#define WM8995_DACLRCLK1_PU_MASK 0x0008 /* DACLRCLK1_PU */
3830#define WM8995_DACLRCLK1_PU_SHIFT 3 /* DACLRCLK1_PU */
3831#define WM8995_DACLRCLK1_PU_WIDTH 1 /* DACLRCLK1_PU */
3832#define WM8995_DACLRCLK1_PD 0x0004 /* DACLRCLK1_PD */
3833#define WM8995_DACLRCLK1_PD_MASK 0x0004 /* DACLRCLK1_PD */
3834#define WM8995_DACLRCLK1_PD_SHIFT 2 /* DACLRCLK1_PD */
3835#define WM8995_DACLRCLK1_PD_WIDTH 1 /* DACLRCLK1_PD */
3836#define WM8995_BCLK1_PU 0x0002 /* BCLK1_PU */
3837#define WM8995_BCLK1_PU_MASK 0x0002 /* BCLK1_PU */
3838#define WM8995_BCLK1_PU_SHIFT 1 /* BCLK1_PU */
3839#define WM8995_BCLK1_PU_WIDTH 1 /* BCLK1_PU */
3840#define WM8995_BCLK1_PD 0x0001 /* BCLK1_PD */
3841#define WM8995_BCLK1_PD_MASK 0x0001 /* BCLK1_PD */
3842#define WM8995_BCLK1_PD_SHIFT 0 /* BCLK1_PD */
3843#define WM8995_BCLK1_PD_WIDTH 1 /* BCLK1_PD */
3844
3845/*
3846 * R1825 (0x721) - Pull Control (2)
3847 */
3848#define WM8995_LDO1ENA_PD 0x0010 /* LDO1ENA_PD */
3849#define WM8995_LDO1ENA_PD_MASK 0x0010 /* LDO1ENA_PD */
3850#define WM8995_LDO1ENA_PD_SHIFT 4 /* LDO1ENA_PD */
3851#define WM8995_LDO1ENA_PD_WIDTH 1 /* LDO1ENA_PD */
3852#define WM8995_MODE_PD 0x0004 /* MODE_PD */
3853#define WM8995_MODE_PD_MASK 0x0004 /* MODE_PD */
3854#define WM8995_MODE_PD_SHIFT 2 /* MODE_PD */
3855#define WM8995_MODE_PD_WIDTH 1 /* MODE_PD */
3856#define WM8995_CSNADDR_PD 0x0001 /* CSNADDR_PD */
3857#define WM8995_CSNADDR_PD_MASK 0x0001 /* CSNADDR_PD */
3858#define WM8995_CSNADDR_PD_SHIFT 0 /* CSNADDR_PD */
3859#define WM8995_CSNADDR_PD_WIDTH 1 /* CSNADDR_PD */
3860
3861/*
3862 * R1840 (0x730) - Interrupt Status 1
3863 */
3864#define WM8995_GP14_EINT 0x2000 /* GP14_EINT */
3865#define WM8995_GP14_EINT_MASK 0x2000 /* GP14_EINT */
3866#define WM8995_GP14_EINT_SHIFT 13 /* GP14_EINT */
3867#define WM8995_GP14_EINT_WIDTH 1 /* GP14_EINT */
3868#define WM8995_GP13_EINT 0x1000 /* GP13_EINT */
3869#define WM8995_GP13_EINT_MASK 0x1000 /* GP13_EINT */
3870#define WM8995_GP13_EINT_SHIFT 12 /* GP13_EINT */
3871#define WM8995_GP13_EINT_WIDTH 1 /* GP13_EINT */
3872#define WM8995_GP12_EINT 0x0800 /* GP12_EINT */
3873#define WM8995_GP12_EINT_MASK 0x0800 /* GP12_EINT */
3874#define WM8995_GP12_EINT_SHIFT 11 /* GP12_EINT */
3875#define WM8995_GP12_EINT_WIDTH 1 /* GP12_EINT */
3876#define WM8995_GP11_EINT 0x0400 /* GP11_EINT */
3877#define WM8995_GP11_EINT_MASK 0x0400 /* GP11_EINT */
3878#define WM8995_GP11_EINT_SHIFT 10 /* GP11_EINT */
3879#define WM8995_GP11_EINT_WIDTH 1 /* GP11_EINT */
3880#define WM8995_GP10_EINT 0x0200 /* GP10_EINT */
3881#define WM8995_GP10_EINT_MASK 0x0200 /* GP10_EINT */
3882#define WM8995_GP10_EINT_SHIFT 9 /* GP10_EINT */
3883#define WM8995_GP10_EINT_WIDTH 1 /* GP10_EINT */
3884#define WM8995_GP9_EINT 0x0100 /* GP9_EINT */
3885#define WM8995_GP9_EINT_MASK 0x0100 /* GP9_EINT */
3886#define WM8995_GP9_EINT_SHIFT 8 /* GP9_EINT */
3887#define WM8995_GP9_EINT_WIDTH 1 /* GP9_EINT */
3888#define WM8995_GP8_EINT 0x0080 /* GP8_EINT */
3889#define WM8995_GP8_EINT_MASK 0x0080 /* GP8_EINT */
3890#define WM8995_GP8_EINT_SHIFT 7 /* GP8_EINT */
3891#define WM8995_GP8_EINT_WIDTH 1 /* GP8_EINT */
3892#define WM8995_GP7_EINT 0x0040 /* GP7_EINT */
3893#define WM8995_GP7_EINT_MASK 0x0040 /* GP7_EINT */
3894#define WM8995_GP7_EINT_SHIFT 6 /* GP7_EINT */
3895#define WM8995_GP7_EINT_WIDTH 1 /* GP7_EINT */
3896#define WM8995_GP6_EINT 0x0020 /* GP6_EINT */
3897#define WM8995_GP6_EINT_MASK 0x0020 /* GP6_EINT */
3898#define WM8995_GP6_EINT_SHIFT 5 /* GP6_EINT */
3899#define WM8995_GP6_EINT_WIDTH 1 /* GP6_EINT */
3900#define WM8995_GP5_EINT 0x0010 /* GP5_EINT */
3901#define WM8995_GP5_EINT_MASK 0x0010 /* GP5_EINT */
3902#define WM8995_GP5_EINT_SHIFT 4 /* GP5_EINT */
3903#define WM8995_GP5_EINT_WIDTH 1 /* GP5_EINT */
3904#define WM8995_GP4_EINT 0x0008 /* GP4_EINT */
3905#define WM8995_GP4_EINT_MASK 0x0008 /* GP4_EINT */
3906#define WM8995_GP4_EINT_SHIFT 3 /* GP4_EINT */
3907#define WM8995_GP4_EINT_WIDTH 1 /* GP4_EINT */
3908#define WM8995_GP3_EINT 0x0004 /* GP3_EINT */
3909#define WM8995_GP3_EINT_MASK 0x0004 /* GP3_EINT */
3910#define WM8995_GP3_EINT_SHIFT 2 /* GP3_EINT */
3911#define WM8995_GP3_EINT_WIDTH 1 /* GP3_EINT */
3912#define WM8995_GP2_EINT 0x0002 /* GP2_EINT */
3913#define WM8995_GP2_EINT_MASK 0x0002 /* GP2_EINT */
3914#define WM8995_GP2_EINT_SHIFT 1 /* GP2_EINT */
3915#define WM8995_GP2_EINT_WIDTH 1 /* GP2_EINT */
3916#define WM8995_GP1_EINT 0x0001 /* GP1_EINT */
3917#define WM8995_GP1_EINT_MASK 0x0001 /* GP1_EINT */
3918#define WM8995_GP1_EINT_SHIFT 0 /* GP1_EINT */
3919#define WM8995_GP1_EINT_WIDTH 1 /* GP1_EINT */
3920
3921/*
3922 * R1841 (0x731) - Interrupt Status 2
3923 */
3924#define WM8995_DCS_DONE_23_EINT 0x1000 /* DCS_DONE_23_EINT */
3925#define WM8995_DCS_DONE_23_EINT_MASK 0x1000 /* DCS_DONE_23_EINT */
3926#define WM8995_DCS_DONE_23_EINT_SHIFT 12 /* DCS_DONE_23_EINT */
3927#define WM8995_DCS_DONE_23_EINT_WIDTH 1 /* DCS_DONE_23_EINT */
3928#define WM8995_DCS_DONE_01_EINT 0x0800 /* DCS_DONE_01_EINT */
3929#define WM8995_DCS_DONE_01_EINT_MASK 0x0800 /* DCS_DONE_01_EINT */
3930#define WM8995_DCS_DONE_01_EINT_SHIFT 11 /* DCS_DONE_01_EINT */
3931#define WM8995_DCS_DONE_01_EINT_WIDTH 1 /* DCS_DONE_01_EINT */
3932#define WM8995_WSEQ_DONE_EINT 0x0400 /* WSEQ_DONE_EINT */
3933#define WM8995_WSEQ_DONE_EINT_MASK 0x0400 /* WSEQ_DONE_EINT */
3934#define WM8995_WSEQ_DONE_EINT_SHIFT 10 /* WSEQ_DONE_EINT */
3935#define WM8995_WSEQ_DONE_EINT_WIDTH 1 /* WSEQ_DONE_EINT */
3936#define WM8995_FIFOS_ERR_EINT 0x0200 /* FIFOS_ERR_EINT */
3937#define WM8995_FIFOS_ERR_EINT_MASK 0x0200 /* FIFOS_ERR_EINT */
3938#define WM8995_FIFOS_ERR_EINT_SHIFT 9 /* FIFOS_ERR_EINT */
3939#define WM8995_FIFOS_ERR_EINT_WIDTH 1 /* FIFOS_ERR_EINT */
3940#define WM8995_AIF2DRC_SIG_DET_EINT 0x0100 /* AIF2DRC_SIG_DET_EINT */
3941#define WM8995_AIF2DRC_SIG_DET_EINT_MASK 0x0100 /* AIF2DRC_SIG_DET_EINT */
3942#define WM8995_AIF2DRC_SIG_DET_EINT_SHIFT 8 /* AIF2DRC_SIG_DET_EINT */
3943#define WM8995_AIF2DRC_SIG_DET_EINT_WIDTH 1 /* AIF2DRC_SIG_DET_EINT */
3944#define WM8995_AIF1DRC2_SIG_DET_EINT 0x0080 /* AIF1DRC2_SIG_DET_EINT */
3945#define WM8995_AIF1DRC2_SIG_DET_EINT_MASK 0x0080 /* AIF1DRC2_SIG_DET_EINT */
3946#define WM8995_AIF1DRC2_SIG_DET_EINT_SHIFT 7 /* AIF1DRC2_SIG_DET_EINT */
3947#define WM8995_AIF1DRC2_SIG_DET_EINT_WIDTH 1 /* AIF1DRC2_SIG_DET_EINT */
3948#define WM8995_AIF1DRC1_SIG_DET_EINT 0x0040 /* AIF1DRC1_SIG_DET_EINT */
3949#define WM8995_AIF1DRC1_SIG_DET_EINT_MASK 0x0040 /* AIF1DRC1_SIG_DET_EINT */
3950#define WM8995_AIF1DRC1_SIG_DET_EINT_SHIFT 6 /* AIF1DRC1_SIG_DET_EINT */
3951#define WM8995_AIF1DRC1_SIG_DET_EINT_WIDTH 1 /* AIF1DRC1_SIG_DET_EINT */
3952#define WM8995_SRC2_LOCK_EINT 0x0020 /* SRC2_LOCK_EINT */
3953#define WM8995_SRC2_LOCK_EINT_MASK 0x0020 /* SRC2_LOCK_EINT */
3954#define WM8995_SRC2_LOCK_EINT_SHIFT 5 /* SRC2_LOCK_EINT */
3955#define WM8995_SRC2_LOCK_EINT_WIDTH 1 /* SRC2_LOCK_EINT */
3956#define WM8995_SRC1_LOCK_EINT 0x0010 /* SRC1_LOCK_EINT */
3957#define WM8995_SRC1_LOCK_EINT_MASK 0x0010 /* SRC1_LOCK_EINT */
3958#define WM8995_SRC1_LOCK_EINT_SHIFT 4 /* SRC1_LOCK_EINT */
3959#define WM8995_SRC1_LOCK_EINT_WIDTH 1 /* SRC1_LOCK_EINT */
3960#define WM8995_FLL2_LOCK_EINT 0x0008 /* FLL2_LOCK_EINT */
3961#define WM8995_FLL2_LOCK_EINT_MASK 0x0008 /* FLL2_LOCK_EINT */
3962#define WM8995_FLL2_LOCK_EINT_SHIFT 3 /* FLL2_LOCK_EINT */
3963#define WM8995_FLL2_LOCK_EINT_WIDTH 1 /* FLL2_LOCK_EINT */
3964#define WM8995_FLL1_LOCK_EINT 0x0004 /* FLL1_LOCK_EINT */
3965#define WM8995_FLL1_LOCK_EINT_MASK 0x0004 /* FLL1_LOCK_EINT */
3966#define WM8995_FLL1_LOCK_EINT_SHIFT 2 /* FLL1_LOCK_EINT */
3967#define WM8995_FLL1_LOCK_EINT_WIDTH 1 /* FLL1_LOCK_EINT */
3968#define WM8995_HP_DONE_EINT 0x0002 /* HP_DONE_EINT */
3969#define WM8995_HP_DONE_EINT_MASK 0x0002 /* HP_DONE_EINT */
3970#define WM8995_HP_DONE_EINT_SHIFT 1 /* HP_DONE_EINT */
3971#define WM8995_HP_DONE_EINT_WIDTH 1 /* HP_DONE_EINT */
3972#define WM8995_MICD_EINT 0x0001 /* MICD_EINT */
3973#define WM8995_MICD_EINT_MASK 0x0001 /* MICD_EINT */
3974#define WM8995_MICD_EINT_SHIFT 0 /* MICD_EINT */
3975#define WM8995_MICD_EINT_WIDTH 1 /* MICD_EINT */
3976
3977/*
3978 * R1842 (0x732) - Interrupt Raw Status 2
3979 */
3980#define WM8995_DCS_DONE_23_STS 0x1000 /* DCS_DONE_23_STS */
3981#define WM8995_DCS_DONE_23_STS_MASK 0x1000 /* DCS_DONE_23_STS */
3982#define WM8995_DCS_DONE_23_STS_SHIFT 12 /* DCS_DONE_23_STS */
3983#define WM8995_DCS_DONE_23_STS_WIDTH 1 /* DCS_DONE_23_STS */
3984#define WM8995_DCS_DONE_01_STS 0x0800 /* DCS_DONE_01_STS */
3985#define WM8995_DCS_DONE_01_STS_MASK 0x0800 /* DCS_DONE_01_STS */
3986#define WM8995_DCS_DONE_01_STS_SHIFT 11 /* DCS_DONE_01_STS */
3987#define WM8995_DCS_DONE_01_STS_WIDTH 1 /* DCS_DONE_01_STS */
3988#define WM8995_WSEQ_DONE_STS 0x0400 /* WSEQ_DONE_STS */
3989#define WM8995_WSEQ_DONE_STS_MASK 0x0400 /* WSEQ_DONE_STS */
3990#define WM8995_WSEQ_DONE_STS_SHIFT 10 /* WSEQ_DONE_STS */
3991#define WM8995_WSEQ_DONE_STS_WIDTH 1 /* WSEQ_DONE_STS */
3992#define WM8995_FIFOS_ERR_STS 0x0200 /* FIFOS_ERR_STS */
3993#define WM8995_FIFOS_ERR_STS_MASK 0x0200 /* FIFOS_ERR_STS */
3994#define WM8995_FIFOS_ERR_STS_SHIFT 9 /* FIFOS_ERR_STS */
3995#define WM8995_FIFOS_ERR_STS_WIDTH 1 /* FIFOS_ERR_STS */
3996#define WM8995_AIF2DRC_SIG_DET_STS 0x0100 /* AIF2DRC_SIG_DET_STS */
3997#define WM8995_AIF2DRC_SIG_DET_STS_MASK 0x0100 /* AIF2DRC_SIG_DET_STS */
3998#define WM8995_AIF2DRC_SIG_DET_STS_SHIFT 8 /* AIF2DRC_SIG_DET_STS */
3999#define WM8995_AIF2DRC_SIG_DET_STS_WIDTH 1 /* AIF2DRC_SIG_DET_STS */
4000#define WM8995_AIF1DRC2_SIG_DET_STS 0x0080 /* AIF1DRC2_SIG_DET_STS */
4001#define WM8995_AIF1DRC2_SIG_DET_STS_MASK 0x0080 /* AIF1DRC2_SIG_DET_STS */
4002#define WM8995_AIF1DRC2_SIG_DET_STS_SHIFT 7 /* AIF1DRC2_SIG_DET_STS */
4003#define WM8995_AIF1DRC2_SIG_DET_STS_WIDTH 1 /* AIF1DRC2_SIG_DET_STS */
4004#define WM8995_AIF1DRC1_SIG_DET_STS 0x0040 /* AIF1DRC1_SIG_DET_STS */
4005#define WM8995_AIF1DRC1_SIG_DET_STS_MASK 0x0040 /* AIF1DRC1_SIG_DET_STS */
4006#define WM8995_AIF1DRC1_SIG_DET_STS_SHIFT 6 /* AIF1DRC1_SIG_DET_STS */
4007#define WM8995_AIF1DRC1_SIG_DET_STS_WIDTH 1 /* AIF1DRC1_SIG_DET_STS */
4008#define WM8995_SRC2_LOCK_STS 0x0020 /* SRC2_LOCK_STS */
4009#define WM8995_SRC2_LOCK_STS_MASK 0x0020 /* SRC2_LOCK_STS */
4010#define WM8995_SRC2_LOCK_STS_SHIFT 5 /* SRC2_LOCK_STS */
4011#define WM8995_SRC2_LOCK_STS_WIDTH 1 /* SRC2_LOCK_STS */
4012#define WM8995_SRC1_LOCK_STS 0x0010 /* SRC1_LOCK_STS */
4013#define WM8995_SRC1_LOCK_STS_MASK 0x0010 /* SRC1_LOCK_STS */
4014#define WM8995_SRC1_LOCK_STS_SHIFT 4 /* SRC1_LOCK_STS */
4015#define WM8995_SRC1_LOCK_STS_WIDTH 1 /* SRC1_LOCK_STS */
4016#define WM8995_FLL2_LOCK_STS 0x0008 /* FLL2_LOCK_STS */
4017#define WM8995_FLL2_LOCK_STS_MASK 0x0008 /* FLL2_LOCK_STS */
4018#define WM8995_FLL2_LOCK_STS_SHIFT 3 /* FLL2_LOCK_STS */
4019#define WM8995_FLL2_LOCK_STS_WIDTH 1 /* FLL2_LOCK_STS */
4020#define WM8995_FLL1_LOCK_STS 0x0004 /* FLL1_LOCK_STS */
4021#define WM8995_FLL1_LOCK_STS_MASK 0x0004 /* FLL1_LOCK_STS */
4022#define WM8995_FLL1_LOCK_STS_SHIFT 2 /* FLL1_LOCK_STS */
4023#define WM8995_FLL1_LOCK_STS_WIDTH 1 /* FLL1_LOCK_STS */
4024
4025/*
4026 * R1848 (0x738) - Interrupt Status 1 Mask
4027 */
4028#define WM8995_IM_GP14_EINT 0x2000 /* IM_GP14_EINT */
4029#define WM8995_IM_GP14_EINT_MASK 0x2000 /* IM_GP14_EINT */
4030#define WM8995_IM_GP14_EINT_SHIFT 13 /* IM_GP14_EINT */
4031#define WM8995_IM_GP14_EINT_WIDTH 1 /* IM_GP14_EINT */
4032#define WM8995_IM_GP13_EINT 0x1000 /* IM_GP13_EINT */
4033#define WM8995_IM_GP13_EINT_MASK 0x1000 /* IM_GP13_EINT */
4034#define WM8995_IM_GP13_EINT_SHIFT 12 /* IM_GP13_EINT */
4035#define WM8995_IM_GP13_EINT_WIDTH 1 /* IM_GP13_EINT */
4036#define WM8995_IM_GP12_EINT 0x0800 /* IM_GP12_EINT */
4037#define WM8995_IM_GP12_EINT_MASK 0x0800 /* IM_GP12_EINT */
4038#define WM8995_IM_GP12_EINT_SHIFT 11 /* IM_GP12_EINT */
4039#define WM8995_IM_GP12_EINT_WIDTH 1 /* IM_GP12_EINT */
4040#define WM8995_IM_GP11_EINT 0x0400 /* IM_GP11_EINT */
4041#define WM8995_IM_GP11_EINT_MASK 0x0400 /* IM_GP11_EINT */
4042#define WM8995_IM_GP11_EINT_SHIFT 10 /* IM_GP11_EINT */
4043#define WM8995_IM_GP11_EINT_WIDTH 1 /* IM_GP11_EINT */
4044#define WM8995_IM_GP10_EINT 0x0200 /* IM_GP10_EINT */
4045#define WM8995_IM_GP10_EINT_MASK 0x0200 /* IM_GP10_EINT */
4046#define WM8995_IM_GP10_EINT_SHIFT 9 /* IM_GP10_EINT */
4047#define WM8995_IM_GP10_EINT_WIDTH 1 /* IM_GP10_EINT */
4048#define WM8995_IM_GP9_EINT 0x0100 /* IM_GP9_EINT */
4049#define WM8995_IM_GP9_EINT_MASK 0x0100 /* IM_GP9_EINT */
4050#define WM8995_IM_GP9_EINT_SHIFT 8 /* IM_GP9_EINT */
4051#define WM8995_IM_GP9_EINT_WIDTH 1 /* IM_GP9_EINT */
4052#define WM8995_IM_GP8_EINT 0x0080 /* IM_GP8_EINT */
4053#define WM8995_IM_GP8_EINT_MASK 0x0080 /* IM_GP8_EINT */
4054#define WM8995_IM_GP8_EINT_SHIFT 7 /* IM_GP8_EINT */
4055#define WM8995_IM_GP8_EINT_WIDTH 1 /* IM_GP8_EINT */
4056#define WM8995_IM_GP7_EINT 0x0040 /* IM_GP7_EINT */
4057#define WM8995_IM_GP7_EINT_MASK 0x0040 /* IM_GP7_EINT */
4058#define WM8995_IM_GP7_EINT_SHIFT 6 /* IM_GP7_EINT */
4059#define WM8995_IM_GP7_EINT_WIDTH 1 /* IM_GP7_EINT */
4060#define WM8995_IM_GP6_EINT 0x0020 /* IM_GP6_EINT */
4061#define WM8995_IM_GP6_EINT_MASK 0x0020 /* IM_GP6_EINT */
4062#define WM8995_IM_GP6_EINT_SHIFT 5 /* IM_GP6_EINT */
4063#define WM8995_IM_GP6_EINT_WIDTH 1 /* IM_GP6_EINT */
4064#define WM8995_IM_GP5_EINT 0x0010 /* IM_GP5_EINT */
4065#define WM8995_IM_GP5_EINT_MASK 0x0010 /* IM_GP5_EINT */
4066#define WM8995_IM_GP5_EINT_SHIFT 4 /* IM_GP5_EINT */
4067#define WM8995_IM_GP5_EINT_WIDTH 1 /* IM_GP5_EINT */
4068#define WM8995_IM_GP4_EINT 0x0008 /* IM_GP4_EINT */
4069#define WM8995_IM_GP4_EINT_MASK 0x0008 /* IM_GP4_EINT */
4070#define WM8995_IM_GP4_EINT_SHIFT 3 /* IM_GP4_EINT */
4071#define WM8995_IM_GP4_EINT_WIDTH 1 /* IM_GP4_EINT */
4072#define WM8995_IM_GP3_EINT 0x0004 /* IM_GP3_EINT */
4073#define WM8995_IM_GP3_EINT_MASK 0x0004 /* IM_GP3_EINT */
4074#define WM8995_IM_GP3_EINT_SHIFT 2 /* IM_GP3_EINT */
4075#define WM8995_IM_GP3_EINT_WIDTH 1 /* IM_GP3_EINT */
4076#define WM8995_IM_GP2_EINT 0x0002 /* IM_GP2_EINT */
4077#define WM8995_IM_GP2_EINT_MASK 0x0002 /* IM_GP2_EINT */
4078#define WM8995_IM_GP2_EINT_SHIFT 1 /* IM_GP2_EINT */
4079#define WM8995_IM_GP2_EINT_WIDTH 1 /* IM_GP2_EINT */
4080#define WM8995_IM_GP1_EINT 0x0001 /* IM_GP1_EINT */
4081#define WM8995_IM_GP1_EINT_MASK 0x0001 /* IM_GP1_EINT */
4082#define WM8995_IM_GP1_EINT_SHIFT 0 /* IM_GP1_EINT */
4083#define WM8995_IM_GP1_EINT_WIDTH 1 /* IM_GP1_EINT */
4084
4085/*
4086 * R1849 (0x739) - Interrupt Status 2 Mask
4087 */
4088#define WM8995_IM_DCS_DONE_23_EINT 0x1000 /* IM_DCS_DONE_23_EINT */
4089#define WM8995_IM_DCS_DONE_23_EINT_MASK 0x1000 /* IM_DCS_DONE_23_EINT */
4090#define WM8995_IM_DCS_DONE_23_EINT_SHIFT 12 /* IM_DCS_DONE_23_EINT */
4091#define WM8995_IM_DCS_DONE_23_EINT_WIDTH 1 /* IM_DCS_DONE_23_EINT */
4092#define WM8995_IM_DCS_DONE_01_EINT 0x0800 /* IM_DCS_DONE_01_EINT */
4093#define WM8995_IM_DCS_DONE_01_EINT_MASK 0x0800 /* IM_DCS_DONE_01_EINT */
4094#define WM8995_IM_DCS_DONE_01_EINT_SHIFT 11 /* IM_DCS_DONE_01_EINT */
4095#define WM8995_IM_DCS_DONE_01_EINT_WIDTH 1 /* IM_DCS_DONE_01_EINT */
4096#define WM8995_IM_WSEQ_DONE_EINT 0x0400 /* IM_WSEQ_DONE_EINT */
4097#define WM8995_IM_WSEQ_DONE_EINT_MASK 0x0400 /* IM_WSEQ_DONE_EINT */
4098#define WM8995_IM_WSEQ_DONE_EINT_SHIFT 10 /* IM_WSEQ_DONE_EINT */
4099#define WM8995_IM_WSEQ_DONE_EINT_WIDTH 1 /* IM_WSEQ_DONE_EINT */
4100#define WM8995_IM_FIFOS_ERR_EINT 0x0200 /* IM_FIFOS_ERR_EINT */
4101#define WM8995_IM_FIFOS_ERR_EINT_MASK 0x0200 /* IM_FIFOS_ERR_EINT */
4102#define WM8995_IM_FIFOS_ERR_EINT_SHIFT 9 /* IM_FIFOS_ERR_EINT */
4103#define WM8995_IM_FIFOS_ERR_EINT_WIDTH 1 /* IM_FIFOS_ERR_EINT */
4104#define WM8995_IM_AIF2DRC_SIG_DET_EINT 0x0100 /* IM_AIF2DRC_SIG_DET_EINT */
4105#define WM8995_IM_AIF2DRC_SIG_DET_EINT_MASK 0x0100 /* IM_AIF2DRC_SIG_DET_EINT */
4106#define WM8995_IM_AIF2DRC_SIG_DET_EINT_SHIFT 8 /* IM_AIF2DRC_SIG_DET_EINT */
4107#define WM8995_IM_AIF2DRC_SIG_DET_EINT_WIDTH 1 /* IM_AIF2DRC_SIG_DET_EINT */
4108#define WM8995_IM_AIF1DRC2_SIG_DET_EINT 0x0080 /* IM_AIF1DRC2_SIG_DET_EINT */
4109#define WM8995_IM_AIF1DRC2_SIG_DET_EINT_MASK 0x0080 /* IM_AIF1DRC2_SIG_DET_EINT */
4110#define WM8995_IM_AIF1DRC2_SIG_DET_EINT_SHIFT 7 /* IM_AIF1DRC2_SIG_DET_EINT */
4111#define WM8995_IM_AIF1DRC2_SIG_DET_EINT_WIDTH 1 /* IM_AIF1DRC2_SIG_DET_EINT */
4112#define WM8995_IM_AIF1DRC1_SIG_DET_EINT 0x0040 /* IM_AIF1DRC1_SIG_DET_EINT */
4113#define WM8995_IM_AIF1DRC1_SIG_DET_EINT_MASK 0x0040 /* IM_AIF1DRC1_SIG_DET_EINT */
4114#define WM8995_IM_AIF1DRC1_SIG_DET_EINT_SHIFT 6 /* IM_AIF1DRC1_SIG_DET_EINT */
4115#define WM8995_IM_AIF1DRC1_SIG_DET_EINT_WIDTH 1 /* IM_AIF1DRC1_SIG_DET_EINT */
4116#define WM8995_IM_SRC2_LOCK_EINT 0x0020 /* IM_SRC2_LOCK_EINT */
4117#define WM8995_IM_SRC2_LOCK_EINT_MASK 0x0020 /* IM_SRC2_LOCK_EINT */
4118#define WM8995_IM_SRC2_LOCK_EINT_SHIFT 5 /* IM_SRC2_LOCK_EINT */
4119#define WM8995_IM_SRC2_LOCK_EINT_WIDTH 1 /* IM_SRC2_LOCK_EINT */
4120#define WM8995_IM_SRC1_LOCK_EINT 0x0010 /* IM_SRC1_LOCK_EINT */
4121#define WM8995_IM_SRC1_LOCK_EINT_MASK 0x0010 /* IM_SRC1_LOCK_EINT */
4122#define WM8995_IM_SRC1_LOCK_EINT_SHIFT 4 /* IM_SRC1_LOCK_EINT */
4123#define WM8995_IM_SRC1_LOCK_EINT_WIDTH 1 /* IM_SRC1_LOCK_EINT */
4124#define WM8995_IM_FLL2_LOCK_EINT 0x0008 /* IM_FLL2_LOCK_EINT */
4125#define WM8995_IM_FLL2_LOCK_EINT_MASK 0x0008 /* IM_FLL2_LOCK_EINT */
4126#define WM8995_IM_FLL2_LOCK_EINT_SHIFT 3 /* IM_FLL2_LOCK_EINT */
4127#define WM8995_IM_FLL2_LOCK_EINT_WIDTH 1 /* IM_FLL2_LOCK_EINT */
4128#define WM8995_IM_FLL1_LOCK_EINT 0x0004 /* IM_FLL1_LOCK_EINT */
4129#define WM8995_IM_FLL1_LOCK_EINT_MASK 0x0004 /* IM_FLL1_LOCK_EINT */
4130#define WM8995_IM_FLL1_LOCK_EINT_SHIFT 2 /* IM_FLL1_LOCK_EINT */
4131#define WM8995_IM_FLL1_LOCK_EINT_WIDTH 1 /* IM_FLL1_LOCK_EINT */
4132#define WM8995_IM_HP_DONE_EINT 0x0002 /* IM_HP_DONE_EINT */
4133#define WM8995_IM_HP_DONE_EINT_MASK 0x0002 /* IM_HP_DONE_EINT */
4134#define WM8995_IM_HP_DONE_EINT_SHIFT 1 /* IM_HP_DONE_EINT */
4135#define WM8995_IM_HP_DONE_EINT_WIDTH 1 /* IM_HP_DONE_EINT */
4136#define WM8995_IM_MICD_EINT 0x0001 /* IM_MICD_EINT */
4137#define WM8995_IM_MICD_EINT_MASK 0x0001 /* IM_MICD_EINT */
4138#define WM8995_IM_MICD_EINT_SHIFT 0 /* IM_MICD_EINT */
4139#define WM8995_IM_MICD_EINT_WIDTH 1 /* IM_MICD_EINT */
4140
4141/*
4142 * R1856 (0x740) - Interrupt Control
4143 */
4144#define WM8995_IM_IRQ 0x0001 /* IM_IRQ */
4145#define WM8995_IM_IRQ_MASK 0x0001 /* IM_IRQ */
4146#define WM8995_IM_IRQ_SHIFT 0 /* IM_IRQ */
4147#define WM8995_IM_IRQ_WIDTH 1 /* IM_IRQ */
4148
4149/*
4150 * R2048 (0x800) - Left PDM Speaker 1
4151 */
4152#define WM8995_SPK1L_ENA 0x0010 /* SPK1L_ENA */
4153#define WM8995_SPK1L_ENA_MASK 0x0010 /* SPK1L_ENA */
4154#define WM8995_SPK1L_ENA_SHIFT 4 /* SPK1L_ENA */
4155#define WM8995_SPK1L_ENA_WIDTH 1 /* SPK1L_ENA */
4156#define WM8995_SPK1L_MUTE 0x0008 /* SPK1L_MUTE */
4157#define WM8995_SPK1L_MUTE_MASK 0x0008 /* SPK1L_MUTE */
4158#define WM8995_SPK1L_MUTE_SHIFT 3 /* SPK1L_MUTE */
4159#define WM8995_SPK1L_MUTE_WIDTH 1 /* SPK1L_MUTE */
4160#define WM8995_SPK1L_MUTE_ZC 0x0004 /* SPK1L_MUTE_ZC */
4161#define WM8995_SPK1L_MUTE_ZC_MASK 0x0004 /* SPK1L_MUTE_ZC */
4162#define WM8995_SPK1L_MUTE_ZC_SHIFT 2 /* SPK1L_MUTE_ZC */
4163#define WM8995_SPK1L_MUTE_ZC_WIDTH 1 /* SPK1L_MUTE_ZC */
4164#define WM8995_SPK1L_SRC_MASK 0x0003 /* SPK1L_SRC - [1:0] */
4165#define WM8995_SPK1L_SRC_SHIFT 0 /* SPK1L_SRC - [1:0] */
4166#define WM8995_SPK1L_SRC_WIDTH 2 /* SPK1L_SRC - [1:0] */
4167
4168/*
4169 * R2049 (0x801) - Right PDM Speaker 1
4170 */
4171#define WM8995_SPK1R_ENA 0x0010 /* SPK1R_ENA */
4172#define WM8995_SPK1R_ENA_MASK 0x0010 /* SPK1R_ENA */
4173#define WM8995_SPK1R_ENA_SHIFT 4 /* SPK1R_ENA */
4174#define WM8995_SPK1R_ENA_WIDTH 1 /* SPK1R_ENA */
4175#define WM8995_SPK1R_MUTE 0x0008 /* SPK1R_MUTE */
4176#define WM8995_SPK1R_MUTE_MASK 0x0008 /* SPK1R_MUTE */
4177#define WM8995_SPK1R_MUTE_SHIFT 3 /* SPK1R_MUTE */
4178#define WM8995_SPK1R_MUTE_WIDTH 1 /* SPK1R_MUTE */
4179#define WM8995_SPK1R_MUTE_ZC 0x0004 /* SPK1R_MUTE_ZC */
4180#define WM8995_SPK1R_MUTE_ZC_MASK 0x0004 /* SPK1R_MUTE_ZC */
4181#define WM8995_SPK1R_MUTE_ZC_SHIFT 2 /* SPK1R_MUTE_ZC */
4182#define WM8995_SPK1R_MUTE_ZC_WIDTH 1 /* SPK1R_MUTE_ZC */
4183#define WM8995_SPK1R_SRC_MASK 0x0003 /* SPK1R_SRC - [1:0] */
4184#define WM8995_SPK1R_SRC_SHIFT 0 /* SPK1R_SRC - [1:0] */
4185#define WM8995_SPK1R_SRC_WIDTH 2 /* SPK1R_SRC - [1:0] */
4186
4187/*
4188 * R2050 (0x802) - PDM Speaker 1 Mute Sequence
4189 */
4190#define WM8995_SPK1_MUTE_SEQ1_MASK 0x00FF /* SPK1_MUTE_SEQ1 - [7:0] */
4191#define WM8995_SPK1_MUTE_SEQ1_SHIFT 0 /* SPK1_MUTE_SEQ1 - [7:0] */
4192#define WM8995_SPK1_MUTE_SEQ1_WIDTH 8 /* SPK1_MUTE_SEQ1 - [7:0] */
4193
4194/*
4195 * R2056 (0x808) - Left PDM Speaker 2
4196 */
4197#define WM8995_SPK2L_ENA 0x0010 /* SPK2L_ENA */
4198#define WM8995_SPK2L_ENA_MASK 0x0010 /* SPK2L_ENA */
4199#define WM8995_SPK2L_ENA_SHIFT 4 /* SPK2L_ENA */
4200#define WM8995_SPK2L_ENA_WIDTH 1 /* SPK2L_ENA */
4201#define WM8995_SPK2L_MUTE 0x0008 /* SPK2L_MUTE */
4202#define WM8995_SPK2L_MUTE_MASK 0x0008 /* SPK2L_MUTE */
4203#define WM8995_SPK2L_MUTE_SHIFT 3 /* SPK2L_MUTE */
4204#define WM8995_SPK2L_MUTE_WIDTH 1 /* SPK2L_MUTE */
4205#define WM8995_SPK2L_MUTE_ZC 0x0004 /* SPK2L_MUTE_ZC */
4206#define WM8995_SPK2L_MUTE_ZC_MASK 0x0004 /* SPK2L_MUTE_ZC */
4207#define WM8995_SPK2L_MUTE_ZC_SHIFT 2 /* SPK2L_MUTE_ZC */
4208#define WM8995_SPK2L_MUTE_ZC_WIDTH 1 /* SPK2L_MUTE_ZC */
4209#define WM8995_SPK2L_SRC_MASK 0x0003 /* SPK2L_SRC - [1:0] */
4210#define WM8995_SPK2L_SRC_SHIFT 0 /* SPK2L_SRC - [1:0] */
4211#define WM8995_SPK2L_SRC_WIDTH 2 /* SPK2L_SRC - [1:0] */
4212
4213/*
4214 * R2057 (0x809) - Right PDM Speaker 2
4215 */
4216#define WM8995_SPK2R_ENA 0x0010 /* SPK2R_ENA */
4217#define WM8995_SPK2R_ENA_MASK 0x0010 /* SPK2R_ENA */
4218#define WM8995_SPK2R_ENA_SHIFT 4 /* SPK2R_ENA */
4219#define WM8995_SPK2R_ENA_WIDTH 1 /* SPK2R_ENA */
4220#define WM8995_SPK2R_MUTE 0x0008 /* SPK2R_MUTE */
4221#define WM8995_SPK2R_MUTE_MASK 0x0008 /* SPK2R_MUTE */
4222#define WM8995_SPK2R_MUTE_SHIFT 3 /* SPK2R_MUTE */
4223#define WM8995_SPK2R_MUTE_WIDTH 1 /* SPK2R_MUTE */
4224#define WM8995_SPK2R_MUTE_ZC 0x0004 /* SPK2R_MUTE_ZC */
4225#define WM8995_SPK2R_MUTE_ZC_MASK 0x0004 /* SPK2R_MUTE_ZC */
4226#define WM8995_SPK2R_MUTE_ZC_SHIFT 2 /* SPK2R_MUTE_ZC */
4227#define WM8995_SPK2R_MUTE_ZC_WIDTH 1 /* SPK2R_MUTE_ZC */
4228#define WM8995_SPK2R_SRC_MASK 0x0003 /* SPK2R_SRC - [1:0] */
4229#define WM8995_SPK2R_SRC_SHIFT 0 /* SPK2R_SRC - [1:0] */
4230#define WM8995_SPK2R_SRC_WIDTH 2 /* SPK2R_SRC - [1:0] */
4231
4232/*
4233 * R2058 (0x80A) - PDM Speaker 2 Mute Sequence
4234 */
4235#define WM8995_SPK2_MUTE_SEQ1_MASK 0x00FF /* SPK2_MUTE_SEQ1 - [7:0] */
4236#define WM8995_SPK2_MUTE_SEQ1_SHIFT 0 /* SPK2_MUTE_SEQ1 - [7:0] */
4237#define WM8995_SPK2_MUTE_SEQ1_WIDTH 8 /* SPK2_MUTE_SEQ1 - [7:0] */
4238
4239#define WM8995_CLASS_W_SWITCH(xname, reg, shift, max, invert) \
4240{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
4241 .info = snd_soc_info_volsw, \
4242 .get = snd_soc_dapm_get_volsw, .put = wm8995_put_class_w, \
4243 .private_value = SOC_SINGLE_VALUE(reg, shift, max, invert) \
4244}
4245
4246struct wm8995_reg_access {
4247 u16 read;
4248 u16 write;
4249 u16 vol;
4250};
4251
4252/* Sources for AIF1/2 SYSCLK - use with set_dai_sysclk() */
4253enum clk_src {
4254 WM8995_SYSCLK_MCLK1 = 1,
4255 WM8995_SYSCLK_MCLK2,
4256 WM8995_SYSCLK_FLL1,
4257 WM8995_SYSCLK_FLL2,
4258 WM8995_SYSCLK_OPCLK
4259};
4260
4261#define WM8995_FLL1 1
4262#define WM8995_FLL2 2
4263
4264#define WM8995_FLL_SRC_MCLK1 1
4265#define WM8995_FLL_SRC_MCLK2 2
4266#define WM8995_FLL_SRC_LRCLK 3
4267#define WM8995_FLL_SRC_BCLK 4
4268
4269#endif /* _WM8995_H */
diff --git a/sound/soc/codecs/wm9081.c b/sound/soc/codecs/wm9081.c
index a486670966bd..43825b2102a5 100644
--- a/sound/soc/codecs/wm9081.c
+++ b/sound/soc/codecs/wm9081.c
@@ -23,7 +23,6 @@
23#include <sound/pcm.h> 23#include <sound/pcm.h>
24#include <sound/pcm_params.h> 24#include <sound/pcm_params.h>
25#include <sound/soc.h> 25#include <sound/soc.h>
26#include <sound/soc-dapm.h>
27#include <sound/initval.h> 26#include <sound/initval.h>
28#include <sound/tlv.h> 27#include <sound/tlv.h>
29 28
@@ -158,7 +157,6 @@ static struct {
158struct wm9081_priv { 157struct wm9081_priv {
159 enum snd_soc_control_type control_type; 158 enum snd_soc_control_type control_type;
160 void *control_data; 159 void *control_data;
161 u16 reg_cache[WM9081_MAX_REGISTER + 1];
162 int sysclk_source; 160 int sysclk_source;
163 int mclk_rate; 161 int mclk_rate;
164 int sysclk_rate; 162 int sysclk_rate;
@@ -591,6 +589,10 @@ static int wm9081_set_fll(struct snd_soc_codec *codec, int fll_id,
591 reg5 |= fll_div.fll_clk_ref_div << WM9081_FLL_CLK_REF_DIV_SHIFT; 589 reg5 |= fll_div.fll_clk_ref_div << WM9081_FLL_CLK_REF_DIV_SHIFT;
592 snd_soc_write(codec, WM9081_FLL_CONTROL_5, reg5); 590 snd_soc_write(codec, WM9081_FLL_CONTROL_5, reg5);
593 591
592 /* Set gain to the recommended value */
593 snd_soc_update_bits(codec, WM9081_FLL_CONTROL_4,
594 WM9081_FLL_GAIN_MASK, 0);
595
594 /* Enable the FLL */ 596 /* Enable the FLL */
595 snd_soc_write(codec, WM9081_FLL_CONTROL_1, reg1 | WM9081_FLL_ENA); 597 snd_soc_write(codec, WM9081_FLL_CONTROL_1, reg1 | WM9081_FLL_ENA);
596 598
@@ -805,7 +807,7 @@ static int wm9081_set_bias_level(struct snd_soc_codec *codec,
805 807
806 case SND_SOC_BIAS_STANDBY: 808 case SND_SOC_BIAS_STANDBY:
807 /* Initial cold start */ 809 /* Initial cold start */
808 if (codec->bias_level == SND_SOC_BIAS_OFF) { 810 if (codec->dapm.bias_level == SND_SOC_BIAS_OFF) {
809 /* Disable LINEOUT discharge */ 811 /* Disable LINEOUT discharge */
810 reg = snd_soc_read(codec, WM9081_ANTI_POP_CONTROL); 812 reg = snd_soc_read(codec, WM9081_ANTI_POP_CONTROL);
811 reg &= ~WM9081_LINEOUT_DISCH; 813 reg &= ~WM9081_LINEOUT_DISCH;
@@ -865,7 +867,7 @@ static int wm9081_set_bias_level(struct snd_soc_codec *codec,
865 break; 867 break;
866 } 868 }
867 869
868 codec->bias_level = level; 870 codec->dapm.bias_level = level;
869 871
870 return 0; 872 return 0;
871} 873}
@@ -1228,6 +1230,7 @@ static struct snd_soc_dai_driver wm9081_dai = {
1228static int wm9081_probe(struct snd_soc_codec *codec) 1230static int wm9081_probe(struct snd_soc_codec *codec)
1229{ 1231{
1230 struct wm9081_priv *wm9081 = snd_soc_codec_get_drvdata(codec); 1232 struct wm9081_priv *wm9081 = snd_soc_codec_get_drvdata(codec);
1233 struct snd_soc_dapm_context *dapm = &codec->dapm;
1231 int ret; 1234 int ret;
1232 u16 reg; 1235 u16 reg;
1233 1236
@@ -1269,9 +1272,9 @@ static int wm9081_probe(struct snd_soc_codec *codec)
1269 ARRAY_SIZE(wm9081_eq_controls)); 1272 ARRAY_SIZE(wm9081_eq_controls));
1270 } 1273 }
1271 1274
1272 snd_soc_dapm_new_controls(codec, wm9081_dapm_widgets, 1275 snd_soc_dapm_new_controls(dapm, wm9081_dapm_widgets,
1273 ARRAY_SIZE(wm9081_dapm_widgets)); 1276 ARRAY_SIZE(wm9081_dapm_widgets));
1274 snd_soc_dapm_add_routes(codec, audio_paths, ARRAY_SIZE(audio_paths)); 1277 snd_soc_dapm_add_routes(dapm, audio_paths, ARRAY_SIZE(audio_paths));
1275 1278
1276 return ret; 1279 return ret;
1277} 1280}
diff --git a/sound/soc/codecs/wm9090.c b/sound/soc/codecs/wm9090.c
index 6e5f64f627cb..a788c4297046 100644
--- a/sound/soc/codecs/wm9090.c
+++ b/sound/soc/codecs/wm9090.c
@@ -28,7 +28,6 @@
28#include <linux/slab.h> 28#include <linux/slab.h>
29#include <sound/initval.h> 29#include <sound/initval.h>
30#include <sound/soc.h> 30#include <sound/soc.h>
31#include <sound/soc-dapm.h>
32#include <sound/tlv.h> 31#include <sound/tlv.h>
33#include <sound/wm9090.h> 32#include <sound/wm9090.h>
34 33
@@ -442,31 +441,32 @@ static const struct snd_soc_dapm_route audio_map_in2_diff[] = {
442static int wm9090_add_controls(struct snd_soc_codec *codec) 441static int wm9090_add_controls(struct snd_soc_codec *codec)
443{ 442{
444 struct wm9090_priv *wm9090 = snd_soc_codec_get_drvdata(codec); 443 struct wm9090_priv *wm9090 = snd_soc_codec_get_drvdata(codec);
444 struct snd_soc_dapm_context *dapm = &codec->dapm;
445 int i; 445 int i;
446 446
447 snd_soc_dapm_new_controls(codec, wm9090_dapm_widgets, 447 snd_soc_dapm_new_controls(dapm, wm9090_dapm_widgets,
448 ARRAY_SIZE(wm9090_dapm_widgets)); 448 ARRAY_SIZE(wm9090_dapm_widgets));
449 449
450 snd_soc_dapm_add_routes(codec, audio_map, ARRAY_SIZE(audio_map)); 450 snd_soc_dapm_add_routes(dapm, audio_map, ARRAY_SIZE(audio_map));
451 451
452 snd_soc_add_controls(codec, wm9090_controls, 452 snd_soc_add_controls(codec, wm9090_controls,
453 ARRAY_SIZE(wm9090_controls)); 453 ARRAY_SIZE(wm9090_controls));
454 454
455 if (wm9090->pdata.lin1_diff) { 455 if (wm9090->pdata.lin1_diff) {
456 snd_soc_dapm_add_routes(codec, audio_map_in1_diff, 456 snd_soc_dapm_add_routes(dapm, audio_map_in1_diff,
457 ARRAY_SIZE(audio_map_in1_diff)); 457 ARRAY_SIZE(audio_map_in1_diff));
458 } else { 458 } else {
459 snd_soc_dapm_add_routes(codec, audio_map_in1_se, 459 snd_soc_dapm_add_routes(dapm, audio_map_in1_se,
460 ARRAY_SIZE(audio_map_in1_se)); 460 ARRAY_SIZE(audio_map_in1_se));
461 snd_soc_add_controls(codec, wm9090_in1_se_controls, 461 snd_soc_add_controls(codec, wm9090_in1_se_controls,
462 ARRAY_SIZE(wm9090_in1_se_controls)); 462 ARRAY_SIZE(wm9090_in1_se_controls));
463 } 463 }
464 464
465 if (wm9090->pdata.lin2_diff) { 465 if (wm9090->pdata.lin2_diff) {
466 snd_soc_dapm_add_routes(codec, audio_map_in2_diff, 466 snd_soc_dapm_add_routes(dapm, audio_map_in2_diff,
467 ARRAY_SIZE(audio_map_in2_diff)); 467 ARRAY_SIZE(audio_map_in2_diff));
468 } else { 468 } else {
469 snd_soc_dapm_add_routes(codec, audio_map_in2_se, 469 snd_soc_dapm_add_routes(dapm, audio_map_in2_se,
470 ARRAY_SIZE(audio_map_in2_se)); 470 ARRAY_SIZE(audio_map_in2_se));
471 snd_soc_add_controls(codec, wm9090_in2_se_controls, 471 snd_soc_add_controls(codec, wm9090_in2_se_controls,
472 ARRAY_SIZE(wm9090_in2_se_controls)); 472 ARRAY_SIZE(wm9090_in2_se_controls));
@@ -513,7 +513,7 @@ static int wm9090_set_bias_level(struct snd_soc_codec *codec,
513 break; 513 break;
514 514
515 case SND_SOC_BIAS_STANDBY: 515 case SND_SOC_BIAS_STANDBY:
516 if (codec->bias_level == SND_SOC_BIAS_OFF) { 516 if (codec->dapm.bias_level == SND_SOC_BIAS_OFF) {
517 /* Restore the register cache */ 517 /* Restore the register cache */
518 for (i = 1; i < codec->driver->reg_cache_size; i++) { 518 for (i = 1; i < codec->driver->reg_cache_size; i++) {
519 if (reg_cache[i] == wm9090_reg_defaults[i]) 519 if (reg_cache[i] == wm9090_reg_defaults[i])
@@ -543,7 +543,7 @@ static int wm9090_set_bias_level(struct snd_soc_codec *codec,
543 break; 543 break;
544 } 544 }
545 545
546 codec->bias_level = level; 546 codec->dapm.bias_level = level;
547 547
548 return 0; 548 return 0;
549} 549}
diff --git a/sound/soc/codecs/wm9705.c b/sound/soc/codecs/wm9705.c
index a144acda751c..47b357adabdd 100644
--- a/sound/soc/codecs/wm9705.c
+++ b/sound/soc/codecs/wm9705.c
@@ -19,7 +19,6 @@
19#include <sound/ac97_codec.h> 19#include <sound/ac97_codec.h>
20#include <sound/initval.h> 20#include <sound/initval.h>
21#include <sound/soc.h> 21#include <sound/soc.h>
22#include <sound/soc-dapm.h>
23 22
24#include "wm9705.h" 23#include "wm9705.h"
25 24
@@ -203,9 +202,11 @@ static const struct snd_soc_dapm_route audio_map[] = {
203 202
204static int wm9705_add_widgets(struct snd_soc_codec *codec) 203static int wm9705_add_widgets(struct snd_soc_codec *codec)
205{ 204{
206 snd_soc_dapm_new_controls(codec, wm9705_dapm_widgets, 205 struct snd_soc_dapm_context *dapm = &codec->dapm;
206
207 snd_soc_dapm_new_controls(dapm, wm9705_dapm_widgets,
207 ARRAY_SIZE(wm9705_dapm_widgets)); 208 ARRAY_SIZE(wm9705_dapm_widgets));
208 snd_soc_dapm_add_routes(codec, audio_map, ARRAY_SIZE(audio_map)); 209 snd_soc_dapm_add_routes(dapm, audio_map, ARRAY_SIZE(audio_map));
209 210
210 return 0; 211 return 0;
211} 212}
diff --git a/sound/soc/codecs/wm9712.c b/sound/soc/codecs/wm9712.c
index d2f224d62744..bf5d4ef1a2a6 100644
--- a/sound/soc/codecs/wm9712.c
+++ b/sound/soc/codecs/wm9712.c
@@ -20,7 +20,6 @@
20#include <sound/ac97_codec.h> 20#include <sound/ac97_codec.h>
21#include <sound/initval.h> 21#include <sound/initval.h>
22#include <sound/soc.h> 22#include <sound/soc.h>
23#include <sound/soc-dapm.h>
24#include "wm9712.h" 23#include "wm9712.h"
25 24
26#define WM9712_VERSION "0.4" 25#define WM9712_VERSION "0.4"
@@ -432,10 +431,11 @@ static const struct snd_soc_dapm_route audio_map[] = {
432 431
433static int wm9712_add_widgets(struct snd_soc_codec *codec) 432static int wm9712_add_widgets(struct snd_soc_codec *codec)
434{ 433{
435 snd_soc_dapm_new_controls(codec, wm9712_dapm_widgets, 434 struct snd_soc_dapm_context *dapm = &codec->dapm;
436 ARRAY_SIZE(wm9712_dapm_widgets));
437 435
438 snd_soc_dapm_add_routes(codec, audio_map, ARRAY_SIZE(audio_map)); 436 snd_soc_dapm_new_controls(dapm, wm9712_dapm_widgets,
437 ARRAY_SIZE(wm9712_dapm_widgets));
438 snd_soc_dapm_add_routes(dapm, audio_map, ARRAY_SIZE(audio_map));
439 439
440 return 0; 440 return 0;
441} 441}
@@ -570,7 +570,7 @@ static int wm9712_set_bias_level(struct snd_soc_codec *codec,
570 ac97_write(codec, AC97_POWERDOWN, 0xffff); 570 ac97_write(codec, AC97_POWERDOWN, 0xffff);
571 break; 571 break;
572 } 572 }
573 codec->bias_level = level; 573 codec->dapm.bias_level = level;
574 return 0; 574 return 0;
575} 575}
576 576
diff --git a/sound/soc/codecs/wm9713.c b/sound/soc/codecs/wm9713.c
index 7da13b07a53d..38ed98558718 100644
--- a/sound/soc/codecs/wm9713.c
+++ b/sound/soc/codecs/wm9713.c
@@ -26,7 +26,6 @@
26#include <sound/pcm_params.h> 26#include <sound/pcm_params.h>
27#include <sound/tlv.h> 27#include <sound/tlv.h>
28#include <sound/soc.h> 28#include <sound/soc.h>
29#include <sound/soc-dapm.h>
30 29
31#include "wm9713.h" 30#include "wm9713.h"
32 31
@@ -647,10 +646,12 @@ static const struct snd_soc_dapm_route audio_map[] = {
647 646
648static int wm9713_add_widgets(struct snd_soc_codec *codec) 647static int wm9713_add_widgets(struct snd_soc_codec *codec)
649{ 648{
650 snd_soc_dapm_new_controls(codec, wm9713_dapm_widgets, 649 struct snd_soc_dapm_context *dapm = &codec->dapm;
650
651 snd_soc_dapm_new_controls(dapm, wm9713_dapm_widgets,
651 ARRAY_SIZE(wm9713_dapm_widgets)); 652 ARRAY_SIZE(wm9713_dapm_widgets));
652 653
653 snd_soc_dapm_add_routes(codec, audio_map, ARRAY_SIZE(audio_map)); 654 snd_soc_dapm_add_routes(dapm, audio_map, ARRAY_SIZE(audio_map));
654 655
655 return 0; 656 return 0;
656} 657}
@@ -1147,7 +1148,7 @@ static int wm9713_set_bias_level(struct snd_soc_codec *codec,
1147 ac97_write(codec, AC97_POWERDOWN, 0xffff); 1148 ac97_write(codec, AC97_POWERDOWN, 0xffff);
1148 break; 1149 break;
1149 } 1150 }
1150 codec->bias_level = level; 1151 codec->dapm.bias_level = level;
1151 return 0; 1152 return 0;
1152} 1153}
1153 1154
diff --git a/sound/soc/codecs/wm_hubs.c b/sound/soc/codecs/wm_hubs.c
index 0e24092722c3..c466982eed23 100644
--- a/sound/soc/codecs/wm_hubs.c
+++ b/sound/soc/codecs/wm_hubs.c
@@ -22,7 +22,6 @@
22#include <sound/pcm.h> 22#include <sound/pcm.h>
23#include <sound/pcm_params.h> 23#include <sound/pcm_params.h>
24#include <sound/soc.h> 24#include <sound/soc.h>
25#include <sound/soc-dapm.h>
26#include <sound/initval.h> 25#include <sound/initval.h>
27#include <sound/tlv.h> 26#include <sound/tlv.h>
28 27
@@ -94,41 +93,61 @@ static void calibrate_dc_servo(struct snd_soc_codec *codec)
94 struct wm_hubs_data *hubs = snd_soc_codec_get_drvdata(codec); 93 struct wm_hubs_data *hubs = snd_soc_codec_get_drvdata(codec);
95 u16 reg, reg_l, reg_r, dcs_cfg; 94 u16 reg, reg_l, reg_r, dcs_cfg;
96 95
97 /* Set for 32 series updates */ 96 /* If we're using a digital only path and have a previously
98 snd_soc_update_bits(codec, WM8993_DC_SERVO_1, 97 * callibrated DC servo offset stored then use that. */
99 WM8993_DCS_SERIES_NO_01_MASK, 98 if (hubs->class_w && hubs->class_w_dcs) {
100 32 << WM8993_DCS_SERIES_NO_01_SHIFT); 99 dev_dbg(codec->dev, "Using cached DC servo offset %x\n",
101 wait_for_dc_servo(codec, 100 hubs->class_w_dcs);
102 WM8993_DCS_TRIG_SERIES_0 | WM8993_DCS_TRIG_SERIES_1); 101 snd_soc_write(codec, WM8993_DC_SERVO_3, hubs->class_w_dcs);
102 wait_for_dc_servo(codec,
103 WM8993_DCS_TRIG_DAC_WR_0 |
104 WM8993_DCS_TRIG_DAC_WR_1);
105 return;
106 }
107
108 /* Devices not using a DCS code correction have startup mode */
109 if (hubs->dcs_codes) {
110 /* Set for 32 series updates */
111 snd_soc_update_bits(codec, WM8993_DC_SERVO_1,
112 WM8993_DCS_SERIES_NO_01_MASK,
113 32 << WM8993_DCS_SERIES_NO_01_SHIFT);
114 wait_for_dc_servo(codec,
115 WM8993_DCS_TRIG_SERIES_0 |
116 WM8993_DCS_TRIG_SERIES_1);
117 } else {
118 wait_for_dc_servo(codec,
119 WM8993_DCS_TRIG_STARTUP_0 |
120 WM8993_DCS_TRIG_STARTUP_1);
121 }
122
123 /* Different chips in the family support different readback
124 * methods.
125 */
126 switch (hubs->dcs_readback_mode) {
127 case 0:
128 reg_l = snd_soc_read(codec, WM8993_DC_SERVO_READBACK_1)
129 & WM8993_DCS_INTEG_CHAN_0_MASK;
130 reg_r = snd_soc_read(codec, WM8993_DC_SERVO_READBACK_2)
131 & WM8993_DCS_INTEG_CHAN_1_MASK;
132 break;
133 case 1:
134 reg = snd_soc_read(codec, WM8993_DC_SERVO_3);
135 reg_l = (reg & WM8993_DCS_DAC_WR_VAL_1_MASK)
136 >> WM8993_DCS_DAC_WR_VAL_1_SHIFT;
137 reg_r = reg & WM8993_DCS_DAC_WR_VAL_0_MASK;
138 break;
139 default:
140 WARN(1, "Unknown DCS readback method\n");
141 break;
142 }
143
144 dev_dbg(codec->dev, "DCS input: %x %x\n", reg_l, reg_r);
103 145
104 /* Apply correction to DC servo result */ 146 /* Apply correction to DC servo result */
105 if (hubs->dcs_codes) { 147 if (hubs->dcs_codes) {
106 dev_dbg(codec->dev, "Applying %d code DC servo correction\n", 148 dev_dbg(codec->dev, "Applying %d code DC servo correction\n",
107 hubs->dcs_codes); 149 hubs->dcs_codes);
108 150
109 /* Different chips in the family support different
110 * readback methods.
111 */
112 switch (hubs->dcs_readback_mode) {
113 case 0:
114 reg_l = snd_soc_read(codec, WM8993_DC_SERVO_READBACK_1)
115 & WM8993_DCS_INTEG_CHAN_0_MASK;;
116 reg_r = snd_soc_read(codec, WM8993_DC_SERVO_READBACK_2)
117 & WM8993_DCS_INTEG_CHAN_1_MASK;
118 break;
119 case 1:
120 reg = snd_soc_read(codec, WM8993_DC_SERVO_3);
121 reg_l = (reg & WM8993_DCS_DAC_WR_VAL_1_MASK)
122 >> WM8993_DCS_DAC_WR_VAL_1_SHIFT;
123 reg_r = reg & WM8993_DCS_DAC_WR_VAL_0_MASK;
124 break;
125 default:
126 WARN(1, "Unknown DCS readback method\n");
127 break;
128 }
129
130 dev_dbg(codec->dev, "DCS input: %x %x\n", reg_l, reg_r);
131
132 /* HPOUT1L */ 151 /* HPOUT1L */
133 if (reg_l + hubs->dcs_codes > 0 && 152 if (reg_l + hubs->dcs_codes > 0 &&
134 reg_l + hubs->dcs_codes < 0xff) 153 reg_l + hubs->dcs_codes < 0xff)
@@ -148,7 +167,15 @@ static void calibrate_dc_servo(struct snd_soc_codec *codec)
148 wait_for_dc_servo(codec, 167 wait_for_dc_servo(codec,
149 WM8993_DCS_TRIG_DAC_WR_0 | 168 WM8993_DCS_TRIG_DAC_WR_0 |
150 WM8993_DCS_TRIG_DAC_WR_1); 169 WM8993_DCS_TRIG_DAC_WR_1);
170 } else {
171 dcs_cfg = reg_l << WM8993_DCS_DAC_WR_VAL_1_SHIFT;
172 dcs_cfg |= reg_r;
151 } 173 }
174
175 /* Save the callibrated offset if we're in class W mode and
176 * therefore don't have any analogue signal mixed in. */
177 if (hubs->class_w)
178 hubs->class_w_dcs = dcs_cfg;
152} 179}
153 180
154/* 181/*
@@ -163,6 +190,9 @@ static int wm8993_put_dc_servo(struct snd_kcontrol *kcontrol,
163 190
164 ret = snd_soc_put_volsw_2r(kcontrol, ucontrol); 191 ret = snd_soc_put_volsw_2r(kcontrol, ucontrol);
165 192
193 /* Updating the analogue gains invalidates the DC servo cache */
194 hubs->class_w_dcs = 0;
195
166 /* If we're applying an offset correction then updating the 196 /* If we're applying an offset correction then updating the
167 * callibration would be likely to introduce further offsets. */ 197 * callibration would be likely to introduce further offsets. */
168 if (hubs->dcs_codes) 198 if (hubs->dcs_codes)
@@ -791,6 +821,8 @@ static const struct snd_soc_dapm_route lineout2_se_routes[] = {
791 821
792int wm_hubs_add_analogue_controls(struct snd_soc_codec *codec) 822int wm_hubs_add_analogue_controls(struct snd_soc_codec *codec)
793{ 823{
824 struct snd_soc_dapm_context *dapm = &codec->dapm;
825
794 /* Latch volume update bits & default ZC on */ 826 /* Latch volume update bits & default ZC on */
795 snd_soc_update_bits(codec, WM8993_LEFT_LINE_INPUT_1_2_VOLUME, 827 snd_soc_update_bits(codec, WM8993_LEFT_LINE_INPUT_1_2_VOLUME,
796 WM8993_IN1_VU, WM8993_IN1_VU); 828 WM8993_IN1_VU, WM8993_IN1_VU);
@@ -819,7 +851,7 @@ int wm_hubs_add_analogue_controls(struct snd_soc_codec *codec)
819 snd_soc_add_controls(codec, analogue_snd_controls, 851 snd_soc_add_controls(codec, analogue_snd_controls,
820 ARRAY_SIZE(analogue_snd_controls)); 852 ARRAY_SIZE(analogue_snd_controls));
821 853
822 snd_soc_dapm_new_controls(codec, analogue_dapm_widgets, 854 snd_soc_dapm_new_controls(dapm, analogue_dapm_widgets,
823 ARRAY_SIZE(analogue_dapm_widgets)); 855 ARRAY_SIZE(analogue_dapm_widgets));
824 return 0; 856 return 0;
825} 857}
@@ -828,24 +860,26 @@ EXPORT_SYMBOL_GPL(wm_hubs_add_analogue_controls);
828int wm_hubs_add_analogue_routes(struct snd_soc_codec *codec, 860int wm_hubs_add_analogue_routes(struct snd_soc_codec *codec,
829 int lineout1_diff, int lineout2_diff) 861 int lineout1_diff, int lineout2_diff)
830{ 862{
831 snd_soc_dapm_add_routes(codec, analogue_routes, 863 struct snd_soc_dapm_context *dapm = &codec->dapm;
864
865 snd_soc_dapm_add_routes(dapm, analogue_routes,
832 ARRAY_SIZE(analogue_routes)); 866 ARRAY_SIZE(analogue_routes));
833 867
834 if (lineout1_diff) 868 if (lineout1_diff)
835 snd_soc_dapm_add_routes(codec, 869 snd_soc_dapm_add_routes(dapm,
836 lineout1_diff_routes, 870 lineout1_diff_routes,
837 ARRAY_SIZE(lineout1_diff_routes)); 871 ARRAY_SIZE(lineout1_diff_routes));
838 else 872 else
839 snd_soc_dapm_add_routes(codec, 873 snd_soc_dapm_add_routes(dapm,
840 lineout1_se_routes, 874 lineout1_se_routes,
841 ARRAY_SIZE(lineout1_se_routes)); 875 ARRAY_SIZE(lineout1_se_routes));
842 876
843 if (lineout2_diff) 877 if (lineout2_diff)
844 snd_soc_dapm_add_routes(codec, 878 snd_soc_dapm_add_routes(dapm,
845 lineout2_diff_routes, 879 lineout2_diff_routes,
846 ARRAY_SIZE(lineout2_diff_routes)); 880 ARRAY_SIZE(lineout2_diff_routes));
847 else 881 else
848 snd_soc_dapm_add_routes(codec, 882 snd_soc_dapm_add_routes(dapm,
849 lineout2_se_routes, 883 lineout2_se_routes,
850 ARRAY_SIZE(lineout2_se_routes)); 884 ARRAY_SIZE(lineout2_se_routes));
851 885
@@ -872,7 +906,7 @@ int wm_hubs_handle_analogue_pdata(struct snd_soc_codec *codec,
872 * VMID as an output and can disable it. 906 * VMID as an output and can disable it.
873 */ 907 */
874 if (lineout1_diff && lineout2_diff) 908 if (lineout1_diff && lineout2_diff)
875 codec->idle_bias_off = 1; 909 codec->dapm.idle_bias_off = 1;
876 910
877 if (lineout1fb) 911 if (lineout1fb)
878 snd_soc_update_bits(codec, WM8993_ADDITIONAL_CONTROL, 912 snd_soc_update_bits(codec, WM8993_ADDITIONAL_CONTROL,
diff --git a/sound/soc/codecs/wm_hubs.h b/sound/soc/codecs/wm_hubs.h
index e51c16683589..f8a5e976b5e6 100644
--- a/sound/soc/codecs/wm_hubs.h
+++ b/sound/soc/codecs/wm_hubs.h
@@ -23,6 +23,9 @@ struct wm_hubs_data {
23 int dcs_codes; 23 int dcs_codes;
24 int dcs_readback_mode; 24 int dcs_readback_mode;
25 int hp_startup_mode; 25 int hp_startup_mode;
26
27 bool class_w;
28 u16 class_w_dcs;
26}; 29};
27 30
28extern int wm_hubs_add_analogue_controls(struct snd_soc_codec *); 31extern int wm_hubs_add_analogue_controls(struct snd_soc_codec *);
diff --git a/sound/soc/davinci/davinci-evm.c b/sound/soc/davinci/davinci-evm.c
index bc9e6b0b3f6f..0c2d6bacc681 100644
--- a/sound/soc/davinci/davinci-evm.c
+++ b/sound/soc/davinci/davinci-evm.c
@@ -18,7 +18,6 @@
18#include <sound/core.h> 18#include <sound/core.h>
19#include <sound/pcm.h> 19#include <sound/pcm.h>
20#include <sound/soc.h> 20#include <sound/soc.h>
21#include <sound/soc-dapm.h>
22 21
23#include <asm/dma.h> 22#include <asm/dma.h>
24#include <asm/mach-types.h> 23#include <asm/mach-types.h>
@@ -27,7 +26,6 @@
27#include <mach/edma.h> 26#include <mach/edma.h>
28#include <mach/mux.h> 27#include <mach/mux.h>
29 28
30#include "../codecs/tlv320aic3x.h"
31#include "davinci-pcm.h" 29#include "davinci-pcm.h"
32#include "davinci-i2s.h" 30#include "davinci-i2s.h"
33#include "davinci-mcasp.h" 31#include "davinci-mcasp.h"
@@ -132,26 +130,27 @@ static const struct snd_soc_dapm_route audio_map[] = {
132static int evm_aic3x_init(struct snd_soc_pcm_runtime *rtd) 130static int evm_aic3x_init(struct snd_soc_pcm_runtime *rtd)
133{ 131{
134 struct snd_soc_codec *codec = rtd->codec; 132 struct snd_soc_codec *codec = rtd->codec;
133 struct snd_soc_dapm_context *dapm = &codec->dapm;
135 134
136 /* Add davinci-evm specific widgets */ 135 /* Add davinci-evm specific widgets */
137 snd_soc_dapm_new_controls(codec, aic3x_dapm_widgets, 136 snd_soc_dapm_new_controls(dapm, aic3x_dapm_widgets,
138 ARRAY_SIZE(aic3x_dapm_widgets)); 137 ARRAY_SIZE(aic3x_dapm_widgets));
139 138
140 /* Set up davinci-evm specific audio path audio_map */ 139 /* Set up davinci-evm specific audio path audio_map */
141 snd_soc_dapm_add_routes(codec, audio_map, ARRAY_SIZE(audio_map)); 140 snd_soc_dapm_add_routes(dapm, audio_map, ARRAY_SIZE(audio_map));
142 141
143 /* not connected */ 142 /* not connected */
144 snd_soc_dapm_disable_pin(codec, "MONO_LOUT"); 143 snd_soc_dapm_disable_pin(dapm, "MONO_LOUT");
145 snd_soc_dapm_disable_pin(codec, "HPLCOM"); 144 snd_soc_dapm_disable_pin(dapm, "HPLCOM");
146 snd_soc_dapm_disable_pin(codec, "HPRCOM"); 145 snd_soc_dapm_disable_pin(dapm, "HPRCOM");
147 146
148 /* always connected */ 147 /* always connected */
149 snd_soc_dapm_enable_pin(codec, "Headphone Jack"); 148 snd_soc_dapm_enable_pin(dapm, "Headphone Jack");
150 snd_soc_dapm_enable_pin(codec, "Line Out"); 149 snd_soc_dapm_enable_pin(dapm, "Line Out");
151 snd_soc_dapm_enable_pin(codec, "Mic Jack"); 150 snd_soc_dapm_enable_pin(dapm, "Mic Jack");
152 snd_soc_dapm_enable_pin(codec, "Line In"); 151 snd_soc_dapm_enable_pin(dapm, "Line In");
153 152
154 snd_soc_dapm_sync(codec); 153 snd_soc_dapm_sync(dapm);
155 154
156 return 0; 155 return 0;
157} 156}
diff --git a/sound/soc/davinci/davinci-sffsdr.c b/sound/soc/davinci/davinci-sffsdr.c
index 6c6666a1f942..0fe558c65145 100644
--- a/sound/soc/davinci/davinci-sffsdr.c
+++ b/sound/soc/davinci/davinci-sffsdr.c
@@ -21,7 +21,6 @@
21#include <sound/core.h> 21#include <sound/core.h>
22#include <sound/pcm.h> 22#include <sound/pcm.h>
23#include <sound/soc.h> 23#include <sound/soc.h>
24#include <sound/soc-dapm.h>
25 24
26#include <asm/dma.h> 25#include <asm/dma.h>
27#include <asm/mach-types.h> 26#include <asm/mach-types.h>
diff --git a/sound/soc/ep93xx/ep93xx-i2s.c b/sound/soc/ep93xx/ep93xx-i2s.c
index 4f4873359613..9ac93f6b4f85 100644
--- a/sound/soc/ep93xx/ep93xx-i2s.c
+++ b/sound/soc/ep93xx/ep93xx-i2s.c
@@ -352,13 +352,13 @@ static struct snd_soc_dai_driver ep93xx_i2s_dai = {
352 .playback = { 352 .playback = {
353 .channels_min = 2, 353 .channels_min = 2,
354 .channels_max = 2, 354 .channels_max = 2,
355 .rates = SNDRV_PCM_RATE_8000_48000, 355 .rates = SNDRV_PCM_RATE_8000_96000,
356 .formats = EP93XX_I2S_FORMATS, 356 .formats = EP93XX_I2S_FORMATS,
357 }, 357 },
358 .capture = { 358 .capture = {
359 .channels_min = 2, 359 .channels_min = 2,
360 .channels_max = 2, 360 .channels_max = 2,
361 .rates = SNDRV_PCM_RATE_8000_48000, 361 .rates = SNDRV_PCM_RATE_8000_96000,
362 .formats = EP93XX_I2S_FORMATS, 362 .formats = EP93XX_I2S_FORMATS,
363 }, 363 },
364 .ops = &ep93xx_i2s_dai_ops, 364 .ops = &ep93xx_i2s_dai_ops,
diff --git a/sound/soc/ep93xx/ep93xx-pcm.c b/sound/soc/ep93xx/ep93xx-pcm.c
index 2f121ddbe4bb..06670776f649 100644
--- a/sound/soc/ep93xx/ep93xx-pcm.c
+++ b/sound/soc/ep93xx/ep93xx-pcm.c
@@ -35,9 +35,9 @@ static const struct snd_pcm_hardware ep93xx_pcm_hardware = {
35 SNDRV_PCM_INFO_INTERLEAVED | 35 SNDRV_PCM_INFO_INTERLEAVED |
36 SNDRV_PCM_INFO_BLOCK_TRANSFER), 36 SNDRV_PCM_INFO_BLOCK_TRANSFER),
37 37
38 .rates = SNDRV_PCM_RATE_8000_48000, 38 .rates = SNDRV_PCM_RATE_8000_96000,
39 .rate_min = SNDRV_PCM_RATE_8000, 39 .rate_min = SNDRV_PCM_RATE_8000,
40 .rate_max = SNDRV_PCM_RATE_48000, 40 .rate_max = SNDRV_PCM_RATE_96000,
41 41
42 .formats = (SNDRV_PCM_FMTBIT_S16_LE | 42 .formats = (SNDRV_PCM_FMTBIT_S16_LE |
43 SNDRV_PCM_FMTBIT_S24_LE | 43 SNDRV_PCM_FMTBIT_S24_LE |
diff --git a/sound/soc/ep93xx/snappercl15.c b/sound/soc/ep93xx/snappercl15.c
index 28ab5ff772ac..dfe1d7f74ea6 100644
--- a/sound/soc/ep93xx/snappercl15.c
+++ b/sound/soc/ep93xx/snappercl15.c
@@ -15,7 +15,6 @@
15#include <sound/core.h> 15#include <sound/core.h>
16#include <sound/pcm.h> 16#include <sound/pcm.h>
17#include <sound/soc.h> 17#include <sound/soc.h>
18#include <sound/soc-dapm.h>
19 18
20#include <asm/mach-types.h> 19#include <asm/mach-types.h>
21#include <mach/hardware.h> 20#include <mach/hardware.h>
@@ -79,11 +78,12 @@ static const struct snd_soc_dapm_route audio_map[] = {
79static int snappercl15_tlv320aic23_init(struct snd_soc_pcm_runtime *rtd) 78static int snappercl15_tlv320aic23_init(struct snd_soc_pcm_runtime *rtd)
80{ 79{
81 struct snd_soc_codec *codec = rtd->codec; 80 struct snd_soc_codec *codec = rtd->codec;
81 struct snd_soc_dapm_context *dapm = &codec->dapm;
82 82
83 snd_soc_dapm_new_controls(codec, tlv320aic23_dapm_widgets, 83 snd_soc_dapm_new_controls(dapm, tlv320aic23_dapm_widgets,
84 ARRAY_SIZE(tlv320aic23_dapm_widgets)); 84 ARRAY_SIZE(tlv320aic23_dapm_widgets));
85 85
86 snd_soc_dapm_add_routes(codec, audio_map, ARRAY_SIZE(audio_map)); 86 snd_soc_dapm_add_routes(dapm, audio_map, ARRAY_SIZE(audio_map));
87 return 0; 87 return 0;
88} 88}
89 89
diff --git a/sound/soc/imx/eukrea-tlv320.c b/sound/soc/imx/eukrea-tlv320.c
index dd4fffdbd177..e20c9e1457c0 100644
--- a/sound/soc/imx/eukrea-tlv320.c
+++ b/sound/soc/imx/eukrea-tlv320.c
@@ -22,7 +22,6 @@
22#include <sound/core.h> 22#include <sound/core.h>
23#include <sound/pcm.h> 23#include <sound/pcm.h>
24#include <sound/soc.h> 24#include <sound/soc.h>
25#include <sound/soc-dapm.h>
26#include <asm/mach-types.h> 25#include <asm/mach-types.h>
27 26
28#include "../codecs/tlv320aic23.h" 27#include "../codecs/tlv320aic23.h"
diff --git a/sound/soc/imx/imx-ssi.c b/sound/soc/imx/imx-ssi.c
index 390b6ffc2658..30894ea7f333 100644
--- a/sound/soc/imx/imx-ssi.c
+++ b/sound/soc/imx/imx-ssi.c
@@ -456,13 +456,13 @@ static int imx_ssi_dai_probe(struct snd_soc_dai *dai)
456static struct snd_soc_dai_driver imx_ssi_dai = { 456static struct snd_soc_dai_driver imx_ssi_dai = {
457 .probe = imx_ssi_dai_probe, 457 .probe = imx_ssi_dai_probe,
458 .playback = { 458 .playback = {
459 .channels_min = 2, 459 .channels_min = 1,
460 .channels_max = 2, 460 .channels_max = 2,
461 .rates = SNDRV_PCM_RATE_8000_96000, 461 .rates = SNDRV_PCM_RATE_8000_96000,
462 .formats = SNDRV_PCM_FMTBIT_S16_LE, 462 .formats = SNDRV_PCM_FMTBIT_S16_LE,
463 }, 463 },
464 .capture = { 464 .capture = {
465 .channels_min = 2, 465 .channels_min = 1,
466 .channels_max = 2, 466 .channels_max = 2,
467 .rates = SNDRV_PCM_RATE_8000_96000, 467 .rates = SNDRV_PCM_RATE_8000_96000,
468 .formats = SNDRV_PCM_FMTBIT_S16_LE, 468 .formats = SNDRV_PCM_FMTBIT_S16_LE,
diff --git a/sound/soc/imx/phycore-ac97.c b/sound/soc/imx/phycore-ac97.c
index 9eabc28667e6..a7deb5cb2433 100644
--- a/sound/soc/imx/phycore-ac97.c
+++ b/sound/soc/imx/phycore-ac97.c
@@ -17,7 +17,6 @@
17#include <sound/core.h> 17#include <sound/core.h>
18#include <sound/pcm.h> 18#include <sound/pcm.h>
19#include <sound/soc.h> 19#include <sound/soc.h>
20#include <sound/soc-dapm.h>
21#include <asm/mach-types.h> 20#include <asm/mach-types.h>
22 21
23static struct snd_soc_card imx_phycore; 22static struct snd_soc_card imx_phycore;
diff --git a/sound/soc/imx/wm1133-ev1.c b/sound/soc/imx/wm1133-ev1.c
index 30fdb15065be..75b4c72787e2 100644
--- a/sound/soc/imx/wm1133-ev1.c
+++ b/sound/soc/imx/wm1133-ev1.c
@@ -19,7 +19,6 @@
19#include <sound/pcm.h> 19#include <sound/pcm.h>
20#include <sound/pcm_params.h> 20#include <sound/pcm_params.h>
21#include <sound/soc.h> 21#include <sound/soc.h>
22#include <sound/soc-dapm.h>
23 22
24#include <mach/audmux.h> 23#include <mach/audmux.h>
25 24
@@ -213,11 +212,12 @@ static struct snd_soc_jack_pin mic_jack_pins[] = {
213static int wm1133_ev1_init(struct snd_soc_pcm_runtime *rtd) 212static int wm1133_ev1_init(struct snd_soc_pcm_runtime *rtd)
214{ 213{
215 struct snd_soc_codec *codec = rtd->codec; 214 struct snd_soc_codec *codec = rtd->codec;
215 struct snd_soc_dapm_context *dapm = &codec->dapm;
216 216
217 snd_soc_dapm_new_controls(codec, wm1133_ev1_widgets, 217 snd_soc_dapm_new_controls(dapm, wm1133_ev1_widgets,
218 ARRAY_SIZE(wm1133_ev1_widgets)); 218 ARRAY_SIZE(wm1133_ev1_widgets));
219 219
220 snd_soc_dapm_add_routes(codec, wm1133_ev1_map, 220 snd_soc_dapm_add_routes(dapm, wm1133_ev1_map,
221 ARRAY_SIZE(wm1133_ev1_map)); 221 ARRAY_SIZE(wm1133_ev1_map));
222 222
223 /* Headphone jack detection */ 223 /* Headphone jack detection */
@@ -234,7 +234,7 @@ static int wm1133_ev1_init(struct snd_soc_pcm_runtime *rtd)
234 wm8350_mic_jack_detect(codec, &mic_jack, SND_JACK_MICROPHONE, 234 wm8350_mic_jack_detect(codec, &mic_jack, SND_JACK_MICROPHONE,
235 SND_JACK_BTN_0); 235 SND_JACK_BTN_0);
236 236
237 snd_soc_dapm_force_enable_pin(codec, "Mic Bias"); 237 snd_soc_dapm_force_enable_pin(dapm, "Mic Bias");
238 238
239 return 0; 239 return 0;
240} 240}
diff --git a/sound/soc/jz4740/jz4740-i2s.c b/sound/soc/jz4740/jz4740-i2s.c
index f3cffd183401..419bf4f5534a 100644
--- a/sound/soc/jz4740/jz4740-i2s.c
+++ b/sound/soc/jz4740/jz4740-i2s.c
@@ -28,7 +28,6 @@
28#include <sound/pcm.h> 28#include <sound/pcm.h>
29#include <sound/pcm_params.h> 29#include <sound/pcm_params.h>
30#include <sound/soc.h> 30#include <sound/soc.h>
31#include <sound/soc-dapm.h>
32#include <sound/initval.h> 31#include <sound/initval.h>
33 32
34#include "jz4740-i2s.h" 33#include "jz4740-i2s.h"
diff --git a/sound/soc/jz4740/qi_lb60.c b/sound/soc/jz4740/qi_lb60.c
index ef1a99e6a3bd..49723e3e7e38 100644
--- a/sound/soc/jz4740/qi_lb60.c
+++ b/sound/soc/jz4740/qi_lb60.c
@@ -19,7 +19,6 @@
19#include <sound/core.h> 19#include <sound/core.h>
20#include <sound/pcm.h> 20#include <sound/pcm.h>
21#include <sound/soc.h> 21#include <sound/soc.h>
22#include <sound/soc-dapm.h>
23#include <linux/gpio.h> 22#include <linux/gpio.h>
24 23
25#define QI_LB60_SND_GPIO JZ_GPIO_PORTB(29) 24#define QI_LB60_SND_GPIO JZ_GPIO_PORTB(29)
@@ -59,10 +58,11 @@ static int qi_lb60_codec_init(struct snd_soc_pcm_runtime *rtd)
59{ 58{
60 struct snd_soc_codec *codec = rtd->codec; 59 struct snd_soc_codec *codec = rtd->codec;
61 struct snd_soc_dai *cpu_dai = rtd->cpu_dai; 60 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
61 struct snd_soc_dapm_context *dapm = &codec->dapm;
62 int ret; 62 int ret;
63 63
64 snd_soc_dapm_nc_pin(codec, "LIN"); 64 snd_soc_dapm_nc_pin(dapm, "LIN");
65 snd_soc_dapm_nc_pin(codec, "RIN"); 65 snd_soc_dapm_nc_pin(dapm, "RIN");
66 66
67 ret = snd_soc_dai_set_fmt(cpu_dai, QI_LB60_DAIFMT); 67 ret = snd_soc_dai_set_fmt(cpu_dai, QI_LB60_DAIFMT);
68 if (ret < 0) { 68 if (ret < 0) {
@@ -70,9 +70,11 @@ static int qi_lb60_codec_init(struct snd_soc_pcm_runtime *rtd)
70 return ret; 70 return ret;
71 } 71 }
72 72
73 snd_soc_dapm_new_controls(codec, qi_lb60_widgets, ARRAY_SIZE(qi_lb60_widgets)); 73 snd_soc_dapm_new_controls(dapm, qi_lb60_widgets,
74 snd_soc_dapm_add_routes(codec, qi_lb60_routes, ARRAY_SIZE(qi_lb60_routes)); 74 ARRAY_SIZE(qi_lb60_widgets));
75 snd_soc_dapm_sync(codec); 75 snd_soc_dapm_add_routes(dapm, qi_lb60_routes,
76 ARRAY_SIZE(qi_lb60_routes));
77 snd_soc_dapm_sync(dapm);
76 78
77 return 0; 79 return 0;
78} 80}
diff --git a/sound/soc/kirkwood/Kconfig b/sound/soc/kirkwood/Kconfig
index 16ec2a2dba4d..8f49e165f4d1 100644
--- a/sound/soc/kirkwood/Kconfig
+++ b/sound/soc/kirkwood/Kconfig
@@ -11,10 +11,19 @@ config SND_KIRKWOOD_SOC_I2S
11 11
12config SND_KIRKWOOD_SOC_OPENRD 12config SND_KIRKWOOD_SOC_OPENRD
13 tristate "SoC Audio support for Kirkwood Openrd Client" 13 tristate "SoC Audio support for Kirkwood Openrd Client"
14 depends on SND_KIRKWOOD_SOC && MACH_OPENRD_CLIENT 14 depends on SND_KIRKWOOD_SOC && (MACH_OPENRD_CLIENT || MACH_OPENRD_ULTIMATE)
15 select SND_KIRKWOOD_SOC_I2S 15 select SND_KIRKWOOD_SOC_I2S
16 select SND_SOC_CS42L51 16 select SND_SOC_CS42L51
17 help 17 help
18 Say Y if you want to add support for SoC audio on 18 Say Y if you want to add support for SoC audio on
19 Openrd Client. 19 Openrd Client.
20 20
21config SND_KIRKWOOD_SOC_T5325
22 tristate "SoC Audio support for HP t5325"
23 depends on SND_KIRKWOOD_SOC && MACH_T5325
24 select SND_KIRKWOOD_SOC_I2S
25 select SND_SOC_ALC5623
26 help
27 Say Y if you want to add support for SoC audio on
28 the HP t5325 thin client.
29
diff --git a/sound/soc/kirkwood/Makefile b/sound/soc/kirkwood/Makefile
index 33a16dcab5b5..3e62ae9e7bbe 100644
--- a/sound/soc/kirkwood/Makefile
+++ b/sound/soc/kirkwood/Makefile
@@ -5,5 +5,7 @@ obj-$(CONFIG_SND_KIRKWOOD_SOC) += snd-soc-kirkwood.o
5obj-$(CONFIG_SND_KIRKWOOD_SOC_I2S) += snd-soc-kirkwood-i2s.o 5obj-$(CONFIG_SND_KIRKWOOD_SOC_I2S) += snd-soc-kirkwood-i2s.o
6 6
7snd-soc-openrd-objs := kirkwood-openrd.o 7snd-soc-openrd-objs := kirkwood-openrd.o
8snd-soc-t5325-objs := kirkwood-t5325.o
8 9
9obj-$(CONFIG_SND_KIRKWOOD_SOC_OPENRD) += snd-soc-openrd.o 10obj-$(CONFIG_SND_KIRKWOOD_SOC_OPENRD) += snd-soc-openrd.o
11obj-$(CONFIG_SND_KIRKWOOD_SOC_T5325) += snd-soc-t5325.o
diff --git a/sound/soc/kirkwood/kirkwood-openrd.c b/sound/soc/kirkwood/kirkwood-openrd.c
index 9d7c81e921f1..d863afb3ee52 100644
--- a/sound/soc/kirkwood/kirkwood-openrd.c
+++ b/sound/soc/kirkwood/kirkwood-openrd.c
@@ -86,7 +86,7 @@ static int __init openrd_client_init(void)
86{ 86{
87 int ret; 87 int ret;
88 88
89 if (!machine_is_openrd_client()) 89 if (!machine_is_openrd_client() && !machine_is_openrd_ultimate())
90 return 0; 90 return 0;
91 91
92 openrd_client_snd_device = platform_device_alloc("soc-audio", -1); 92 openrd_client_snd_device = platform_device_alloc("soc-audio", -1);
diff --git a/sound/soc/kirkwood/kirkwood-t5325.c b/sound/soc/kirkwood/kirkwood-t5325.c
new file mode 100644
index 000000000000..c8d21956ab52
--- /dev/null
+++ b/sound/soc/kirkwood/kirkwood-t5325.c
@@ -0,0 +1,141 @@
1/*
2 * kirkwood-t5325.c
3 *
4 * (c) 2010 Arnaud Patard <arnaud.patard@rtp-net.org>
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; either version 2 of the License, or (at your
9 * option) any later version.
10 */
11
12#include <linux/module.h>
13#include <linux/moduleparam.h>
14#include <linux/interrupt.h>
15#include <linux/platform_device.h>
16#include <linux/slab.h>
17#include <sound/soc.h>
18#include <mach/kirkwood.h>
19#include <plat/audio.h>
20#include <asm/mach-types.h>
21#include "../codecs/alc5623.h"
22
23static int t5325_hw_params(struct snd_pcm_substream *substream,
24 struct snd_pcm_hw_params *params)
25{
26 struct snd_soc_pcm_runtime *rtd = substream->private_data;
27 struct snd_soc_dai *codec_dai = rtd->codec_dai;
28 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
29 int ret;
30 unsigned int freq, fmt;
31
32 fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_CBS_CFS;
33 ret = snd_soc_dai_set_fmt(cpu_dai, fmt);
34 if (ret < 0)
35 return ret;
36
37 ret = snd_soc_dai_set_fmt(codec_dai, fmt);
38 if (ret < 0)
39 return ret;
40
41 freq = params_rate(params) * 256;
42
43 return snd_soc_dai_set_sysclk(codec_dai, 0, freq, SND_SOC_CLOCK_IN);
44
45}
46
47static struct snd_soc_ops t5325_ops = {
48 .hw_params = t5325_hw_params,
49};
50
51static const struct snd_soc_dapm_widget t5325_dapm_widgets[] = {
52 SND_SOC_DAPM_HP("Headphone Jack", NULL),
53 SND_SOC_DAPM_SPK("Speaker", NULL),
54 SND_SOC_DAPM_MIC("Mic Jack", NULL),
55};
56
57static const struct snd_soc_dapm_route t5325_route[] = {
58 { "Headphone Jack", NULL, "HPL" },
59 { "Headphone Jack", NULL, "HPR" },
60
61 {"Speaker", NULL, "SPKOUT"},
62 {"Speaker", NULL, "SPKOUTN"},
63
64 { "MIC1", NULL, "Mic Jack" },
65 { "MIC2", NULL, "Mic Jack" },
66};
67
68static int t5325_dai_init(struct snd_soc_pcm_runtime *rtd)
69{
70 struct snd_soc_codec *codec = rtd->codec;
71 struct snd_soc_dapm_context *dapm = &codec->dapm;
72
73 snd_soc_dapm_new_controls(dapm, t5325_dapm_widgets,
74 ARRAY_SIZE(t5325_dapm_widgets));
75
76 snd_soc_dapm_add_routes(dapm, t5325_route, ARRAY_SIZE(t5325_route));
77
78 snd_soc_dapm_enable_pin(dapm, "Mic Jack");
79 snd_soc_dapm_enable_pin(dapm, "Headphone Jack");
80 snd_soc_dapm_enable_pin(dapm, "Speaker");
81
82 snd_soc_dapm_sync(dapm);
83
84 return 0;
85}
86
87static struct snd_soc_dai_link t5325_dai[] = {
88{
89 .name = "ALC5621",
90 .stream_name = "ALC5621 HiFi",
91 .cpu_dai_name = "kirkwood-i2s",
92 .platform_name = "kirkwood-pcm-audio",
93 .codec_dai_name = "alc5621-hifi",
94 .codec_name = "alc562x-codec.0-001a",
95 .ops = &t5325_ops,
96 .init = t5325_dai_init,
97},
98};
99
100
101static struct snd_soc_card t5325 = {
102 .name = "t5325",
103 .dai_link = t5325_dai,
104 .num_links = ARRAY_SIZE(t5325_dai),
105};
106
107static struct platform_device *t5325_snd_device;
108
109static int __init t5325_init(void)
110{
111 int ret;
112
113 if (!machine_is_t5325())
114 return 0;
115
116 t5325_snd_device = platform_device_alloc("soc-audio", -1);
117 if (!t5325_snd_device)
118 return -ENOMEM;
119
120 platform_set_drvdata(t5325_snd_device,
121 &t5325);
122
123 ret = platform_device_add(t5325_snd_device);
124 if (ret) {
125 printk(KERN_ERR "%s: platform_device_add failed\n", __func__);
126 platform_device_put(t5325_snd_device);
127 }
128
129 return ret;
130}
131module_init(t5325_init);
132
133static void __exit t5325_exit(void)
134{
135 platform_device_unregister(t5325_snd_device);
136}
137module_exit(t5325_exit);
138
139MODULE_AUTHOR("Arnaud Patard <arnaud.patard@rtp-net.org>");
140MODULE_DESCRIPTION("ALSA SoC t5325 audio client");
141MODULE_LICENSE("GPL");
diff --git a/sound/soc/nuc900/nuc900-audio.c b/sound/soc/nuc900/nuc900-audio.c
index 161f5b667d7b..38a2d0d883b5 100644
--- a/sound/soc/nuc900/nuc900-audio.c
+++ b/sound/soc/nuc900/nuc900-audio.c
@@ -18,7 +18,6 @@
18#include <sound/core.h> 18#include <sound/core.h>
19#include <sound/pcm.h> 19#include <sound/pcm.h>
20#include <sound/soc.h> 20#include <sound/soc.h>
21#include <sound/soc-dapm.h>
22 21
23#include "nuc900-audio.h" 22#include "nuc900-audio.h"
24 23
diff --git a/sound/soc/omap/am3517evm.c b/sound/soc/omap/am3517evm.c
index 979dd508305f..161750443ebc 100644
--- a/sound/soc/omap/am3517evm.c
+++ b/sound/soc/omap/am3517evm.c
@@ -22,7 +22,6 @@
22#include <sound/core.h> 22#include <sound/core.h>
23#include <sound/pcm.h> 23#include <sound/pcm.h>
24#include <sound/soc.h> 24#include <sound/soc.h>
25#include <sound/soc-dapm.h>
26 25
27#include <asm/mach-types.h> 26#include <asm/mach-types.h>
28#include <mach/hardware.h> 27#include <mach/hardware.h>
@@ -114,20 +113,21 @@ static const struct snd_soc_dapm_route audio_map[] = {
114static int am3517evm_aic23_init(struct snd_soc_pcm_runtime *rtd) 113static int am3517evm_aic23_init(struct snd_soc_pcm_runtime *rtd)
115{ 114{
116 struct snd_soc_codec *codec = rtd->codec; 115 struct snd_soc_codec *codec = rtd->codec;
116 struct snd_soc_dapm_context *dapm = &codec->dapm;
117 117
118 /* Add am3517-evm specific widgets */ 118 /* Add am3517-evm specific widgets */
119 snd_soc_dapm_new_controls(codec, tlv320aic23_dapm_widgets, 119 snd_soc_dapm_new_controls(dapm, tlv320aic23_dapm_widgets,
120 ARRAY_SIZE(tlv320aic23_dapm_widgets)); 120 ARRAY_SIZE(tlv320aic23_dapm_widgets));
121 121
122 /* Set up davinci-evm specific audio path audio_map */ 122 /* Set up davinci-evm specific audio path audio_map */
123 snd_soc_dapm_add_routes(codec, audio_map, ARRAY_SIZE(audio_map)); 123 snd_soc_dapm_add_routes(dapm, audio_map, ARRAY_SIZE(audio_map));
124 124
125 /* always connected */ 125 /* always connected */
126 snd_soc_dapm_enable_pin(codec, "Line Out"); 126 snd_soc_dapm_enable_pin(dapm, "Line Out");
127 snd_soc_dapm_enable_pin(codec, "Line In"); 127 snd_soc_dapm_enable_pin(dapm, "Line In");
128 snd_soc_dapm_enable_pin(codec, "Mic In"); 128 snd_soc_dapm_enable_pin(dapm, "Mic In");
129 129
130 snd_soc_dapm_sync(codec); 130 snd_soc_dapm_sync(dapm);
131 131
132 return 0; 132 return 0;
133} 133}
diff --git a/sound/soc/omap/ams-delta.c b/sound/soc/omap/ams-delta.c
index 438146addbb8..2101bdcee21f 100644
--- a/sound/soc/omap/ams-delta.c
+++ b/sound/soc/omap/ams-delta.c
@@ -26,7 +26,7 @@
26#include <linux/spinlock.h> 26#include <linux/spinlock.h>
27#include <linux/tty.h> 27#include <linux/tty.h>
28 28
29#include <sound/soc-dapm.h> 29#include <sound/soc.h>
30#include <sound/jack.h> 30#include <sound/jack.h>
31 31
32#include <asm/mach-types.h> 32#include <asm/mach-types.h>
@@ -94,6 +94,7 @@ static int ams_delta_set_audio_mode(struct snd_kcontrol *kcontrol,
94 struct snd_ctl_elem_value *ucontrol) 94 struct snd_ctl_elem_value *ucontrol)
95{ 95{
96 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); 96 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
97 struct snd_soc_dapm_context *dapm = &codec->dapm;
97 struct soc_enum *control = (struct soc_enum *)kcontrol->private_value; 98 struct soc_enum *control = (struct soc_enum *)kcontrol->private_value;
98 unsigned short pins; 99 unsigned short pins;
99 int pin, changed = 0; 100 int pin, changed = 0;
@@ -112,48 +113,48 @@ static int ams_delta_set_audio_mode(struct snd_kcontrol *kcontrol,
112 113
113 /* Setup pins after corresponding bits if changed */ 114 /* Setup pins after corresponding bits if changed */
114 pin = !!(pins & (1 << AMS_DELTA_MOUTHPIECE)); 115 pin = !!(pins & (1 << AMS_DELTA_MOUTHPIECE));
115 if (pin != snd_soc_dapm_get_pin_status(codec, "Mouthpiece")) { 116 if (pin != snd_soc_dapm_get_pin_status(dapm, "Mouthpiece")) {
116 changed = 1; 117 changed = 1;
117 if (pin) 118 if (pin)
118 snd_soc_dapm_enable_pin(codec, "Mouthpiece"); 119 snd_soc_dapm_enable_pin(dapm, "Mouthpiece");
119 else 120 else
120 snd_soc_dapm_disable_pin(codec, "Mouthpiece"); 121 snd_soc_dapm_disable_pin(dapm, "Mouthpiece");
121 } 122 }
122 pin = !!(pins & (1 << AMS_DELTA_EARPIECE)); 123 pin = !!(pins & (1 << AMS_DELTA_EARPIECE));
123 if (pin != snd_soc_dapm_get_pin_status(codec, "Earpiece")) { 124 if (pin != snd_soc_dapm_get_pin_status(dapm, "Earpiece")) {
124 changed = 1; 125 changed = 1;
125 if (pin) 126 if (pin)
126 snd_soc_dapm_enable_pin(codec, "Earpiece"); 127 snd_soc_dapm_enable_pin(dapm, "Earpiece");
127 else 128 else
128 snd_soc_dapm_disable_pin(codec, "Earpiece"); 129 snd_soc_dapm_disable_pin(dapm, "Earpiece");
129 } 130 }
130 pin = !!(pins & (1 << AMS_DELTA_MICROPHONE)); 131 pin = !!(pins & (1 << AMS_DELTA_MICROPHONE));
131 if (pin != snd_soc_dapm_get_pin_status(codec, "Microphone")) { 132 if (pin != snd_soc_dapm_get_pin_status(dapm, "Microphone")) {
132 changed = 1; 133 changed = 1;
133 if (pin) 134 if (pin)
134 snd_soc_dapm_enable_pin(codec, "Microphone"); 135 snd_soc_dapm_enable_pin(dapm, "Microphone");
135 else 136 else
136 snd_soc_dapm_disable_pin(codec, "Microphone"); 137 snd_soc_dapm_disable_pin(dapm, "Microphone");
137 } 138 }
138 pin = !!(pins & (1 << AMS_DELTA_SPEAKER)); 139 pin = !!(pins & (1 << AMS_DELTA_SPEAKER));
139 if (pin != snd_soc_dapm_get_pin_status(codec, "Speaker")) { 140 if (pin != snd_soc_dapm_get_pin_status(dapm, "Speaker")) {
140 changed = 1; 141 changed = 1;
141 if (pin) 142 if (pin)
142 snd_soc_dapm_enable_pin(codec, "Speaker"); 143 snd_soc_dapm_enable_pin(dapm, "Speaker");
143 else 144 else
144 snd_soc_dapm_disable_pin(codec, "Speaker"); 145 snd_soc_dapm_disable_pin(dapm, "Speaker");
145 } 146 }
146 pin = !!(pins & (1 << AMS_DELTA_AGC)); 147 pin = !!(pins & (1 << AMS_DELTA_AGC));
147 if (pin != ams_delta_audio_agc) { 148 if (pin != ams_delta_audio_agc) {
148 ams_delta_audio_agc = pin; 149 ams_delta_audio_agc = pin;
149 changed = 1; 150 changed = 1;
150 if (pin) 151 if (pin)
151 snd_soc_dapm_enable_pin(codec, "AGCIN"); 152 snd_soc_dapm_enable_pin(dapm, "AGCIN");
152 else 153 else
153 snd_soc_dapm_disable_pin(codec, "AGCIN"); 154 snd_soc_dapm_disable_pin(dapm, "AGCIN");
154 } 155 }
155 if (changed) 156 if (changed)
156 snd_soc_dapm_sync(codec); 157 snd_soc_dapm_sync(dapm);
157 158
158 mutex_unlock(&codec->mutex); 159 mutex_unlock(&codec->mutex);
159 160
@@ -164,19 +165,20 @@ static int ams_delta_get_audio_mode(struct snd_kcontrol *kcontrol,
164 struct snd_ctl_elem_value *ucontrol) 165 struct snd_ctl_elem_value *ucontrol)
165{ 166{
166 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); 167 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
168 struct snd_soc_dapm_context *dapm = &codec->dapm;
167 unsigned short pins, mode; 169 unsigned short pins, mode;
168 170
169 pins = ((snd_soc_dapm_get_pin_status(codec, "Mouthpiece") << 171 pins = ((snd_soc_dapm_get_pin_status(dapm, "Mouthpiece") <<
170 AMS_DELTA_MOUTHPIECE) | 172 AMS_DELTA_MOUTHPIECE) |
171 (snd_soc_dapm_get_pin_status(codec, "Earpiece") << 173 (snd_soc_dapm_get_pin_status(dapm, "Earpiece") <<
172 AMS_DELTA_EARPIECE)); 174 AMS_DELTA_EARPIECE));
173 if (pins) 175 if (pins)
174 pins |= (snd_soc_dapm_get_pin_status(codec, "Microphone") << 176 pins |= (snd_soc_dapm_get_pin_status(dapm, "Microphone") <<
175 AMS_DELTA_MICROPHONE); 177 AMS_DELTA_MICROPHONE);
176 else 178 else
177 pins = ((snd_soc_dapm_get_pin_status(codec, "Microphone") << 179 pins = ((snd_soc_dapm_get_pin_status(dapm, "Microphone") <<
178 AMS_DELTA_MICROPHONE) | 180 AMS_DELTA_MICROPHONE) |
179 (snd_soc_dapm_get_pin_status(codec, "Speaker") << 181 (snd_soc_dapm_get_pin_status(dapm, "Speaker") <<
180 AMS_DELTA_SPEAKER) | 182 AMS_DELTA_SPEAKER) |
181 (ams_delta_audio_agc << AMS_DELTA_AGC)); 183 (ams_delta_audio_agc << AMS_DELTA_AGC));
182 184
@@ -300,6 +302,7 @@ static int cx81801_open(struct tty_struct *tty)
300static void cx81801_close(struct tty_struct *tty) 302static void cx81801_close(struct tty_struct *tty)
301{ 303{
302 struct snd_soc_codec *codec = tty->disc_data; 304 struct snd_soc_codec *codec = tty->disc_data;
305 struct snd_soc_dapm_context *dapm = &codec->dapm;
303 306
304 del_timer_sync(&cx81801_timer); 307 del_timer_sync(&cx81801_timer);
305 308
@@ -312,12 +315,12 @@ static void cx81801_close(struct tty_struct *tty)
312 v253_ops.close(tty); 315 v253_ops.close(tty);
313 316
314 /* Revert back to default audio input/output constellation */ 317 /* Revert back to default audio input/output constellation */
315 snd_soc_dapm_disable_pin(codec, "Mouthpiece"); 318 snd_soc_dapm_disable_pin(dapm, "Mouthpiece");
316 snd_soc_dapm_enable_pin(codec, "Earpiece"); 319 snd_soc_dapm_enable_pin(dapm, "Earpiece");
317 snd_soc_dapm_enable_pin(codec, "Microphone"); 320 snd_soc_dapm_enable_pin(dapm, "Microphone");
318 snd_soc_dapm_disable_pin(codec, "Speaker"); 321 snd_soc_dapm_disable_pin(dapm, "Speaker");
319 snd_soc_dapm_disable_pin(codec, "AGCIN"); 322 snd_soc_dapm_disable_pin(dapm, "AGCIN");
320 snd_soc_dapm_sync(codec); 323 snd_soc_dapm_sync(dapm);
321} 324}
322 325
323/* Line discipline .hangup() */ 326/* Line discipline .hangup() */
@@ -432,16 +435,16 @@ static int ams_delta_set_bias_level(struct snd_soc_card *card,
432 case SND_SOC_BIAS_ON: 435 case SND_SOC_BIAS_ON:
433 case SND_SOC_BIAS_PREPARE: 436 case SND_SOC_BIAS_PREPARE:
434 case SND_SOC_BIAS_STANDBY: 437 case SND_SOC_BIAS_STANDBY:
435 if (codec->bias_level == SND_SOC_BIAS_OFF) 438 if (codec->dapm.bias_level == SND_SOC_BIAS_OFF)
436 ams_delta_latch2_write(AMS_DELTA_LATCH2_MODEM_NRESET, 439 ams_delta_latch2_write(AMS_DELTA_LATCH2_MODEM_NRESET,
437 AMS_DELTA_LATCH2_MODEM_NRESET); 440 AMS_DELTA_LATCH2_MODEM_NRESET);
438 break; 441 break;
439 case SND_SOC_BIAS_OFF: 442 case SND_SOC_BIAS_OFF:
440 if (codec->bias_level != SND_SOC_BIAS_OFF) 443 if (codec->dapm.bias_level != SND_SOC_BIAS_OFF)
441 ams_delta_latch2_write(AMS_DELTA_LATCH2_MODEM_NRESET, 444 ams_delta_latch2_write(AMS_DELTA_LATCH2_MODEM_NRESET,
442 0); 445 0);
443 } 446 }
444 codec->bias_level = level; 447 codec->dapm.bias_level = level;
445 448
446 return 0; 449 return 0;
447} 450}
@@ -492,6 +495,7 @@ static void ams_delta_shutdown(struct snd_pcm_substream *substream)
492static int ams_delta_cx20442_init(struct snd_soc_pcm_runtime *rtd) 495static int ams_delta_cx20442_init(struct snd_soc_pcm_runtime *rtd)
493{ 496{
494 struct snd_soc_codec *codec = rtd->codec; 497 struct snd_soc_codec *codec = rtd->codec;
498 struct snd_soc_dapm_context *dapm = &codec->dapm;
495 struct snd_soc_dai *codec_dai = rtd->codec_dai; 499 struct snd_soc_dai *codec_dai = rtd->codec_dai;
496 struct snd_soc_card *card = rtd->card; 500 struct snd_soc_card *card = rtd->card;
497 int ret; 501 int ret;
@@ -541,7 +545,7 @@ static int ams_delta_cx20442_init(struct snd_soc_pcm_runtime *rtd)
541 } 545 }
542 546
543 /* Add board specific DAPM widgets and routes */ 547 /* Add board specific DAPM widgets and routes */
544 ret = snd_soc_dapm_new_controls(codec, ams_delta_dapm_widgets, 548 ret = snd_soc_dapm_new_controls(dapm, ams_delta_dapm_widgets,
545 ARRAY_SIZE(ams_delta_dapm_widgets)); 549 ARRAY_SIZE(ams_delta_dapm_widgets));
546 if (ret) { 550 if (ret) {
547 dev_warn(card->dev, 551 dev_warn(card->dev,
@@ -550,7 +554,7 @@ static int ams_delta_cx20442_init(struct snd_soc_pcm_runtime *rtd)
550 return 0; 554 return 0;
551 } 555 }
552 556
553 ret = snd_soc_dapm_add_routes(codec, ams_delta_audio_map, 557 ret = snd_soc_dapm_add_routes(dapm, ams_delta_audio_map,
554 ARRAY_SIZE(ams_delta_audio_map)); 558 ARRAY_SIZE(ams_delta_audio_map));
555 if (ret) { 559 if (ret) {
556 dev_warn(card->dev, 560 dev_warn(card->dev,
@@ -560,13 +564,13 @@ static int ams_delta_cx20442_init(struct snd_soc_pcm_runtime *rtd)
560 } 564 }
561 565
562 /* Set up initial pin constellation */ 566 /* Set up initial pin constellation */
563 snd_soc_dapm_disable_pin(codec, "Mouthpiece"); 567 snd_soc_dapm_disable_pin(dapm, "Mouthpiece");
564 snd_soc_dapm_enable_pin(codec, "Earpiece"); 568 snd_soc_dapm_enable_pin(dapm, "Earpiece");
565 snd_soc_dapm_enable_pin(codec, "Microphone"); 569 snd_soc_dapm_enable_pin(dapm, "Microphone");
566 snd_soc_dapm_disable_pin(codec, "Speaker"); 570 snd_soc_dapm_disable_pin(dapm, "Speaker");
567 snd_soc_dapm_disable_pin(codec, "AGCIN"); 571 snd_soc_dapm_disable_pin(dapm, "AGCIN");
568 snd_soc_dapm_disable_pin(codec, "AGCOUT"); 572 snd_soc_dapm_disable_pin(dapm, "AGCOUT");
569 snd_soc_dapm_sync(codec); 573 snd_soc_dapm_sync(dapm);
570 574
571 /* Add virtual switch */ 575 /* Add virtual switch */
572 ret = snd_soc_add_controls(codec, ams_delta_audio_controls, 576 ret = snd_soc_add_controls(codec, ams_delta_audio_controls,
diff --git a/sound/soc/omap/igep0020.c b/sound/soc/omap/igep0020.c
index fd3a40f309c8..0ae34702995b 100644
--- a/sound/soc/omap/igep0020.c
+++ b/sound/soc/omap/igep0020.c
@@ -24,7 +24,6 @@
24#include <sound/core.h> 24#include <sound/core.h>
25#include <sound/pcm.h> 25#include <sound/pcm.h>
26#include <sound/soc.h> 26#include <sound/soc.h>
27#include <sound/soc-dapm.h>
28 27
29#include <asm/mach-types.h> 28#include <asm/mach-types.h>
30#include <mach/hardware.h> 29#include <mach/hardware.h>
diff --git a/sound/soc/omap/n810.c b/sound/soc/omap/n810.c
index a3b6d897ad84..83d213bfd3d1 100644
--- a/sound/soc/omap/n810.c
+++ b/sound/soc/omap/n810.c
@@ -27,7 +27,6 @@
27#include <sound/core.h> 27#include <sound/core.h>
28#include <sound/pcm.h> 28#include <sound/pcm.h>
29#include <sound/soc.h> 29#include <sound/soc.h>
30#include <sound/soc-dapm.h>
31 30
32#include <asm/mach-types.h> 31#include <asm/mach-types.h>
33#include <mach/hardware.h> 32#include <mach/hardware.h>
@@ -36,7 +35,6 @@
36 35
37#include "omap-mcbsp.h" 36#include "omap-mcbsp.h"
38#include "omap-pcm.h" 37#include "omap-pcm.h"
39#include "../codecs/tlv320aic3x.h"
40 38
41#define N810_HEADSET_AMP_GPIO 10 39#define N810_HEADSET_AMP_GPIO 10
42#define N810_SPEAKER_AMP_GPIO 101 40#define N810_SPEAKER_AMP_GPIO 101
@@ -58,6 +56,7 @@ static int n810_dmic_func;
58 56
59static void n810_ext_control(struct snd_soc_codec *codec) 57static void n810_ext_control(struct snd_soc_codec *codec)
60{ 58{
59 struct snd_soc_dapm_context *dapm = &codec->dapm;
61 int hp = 0, line1l = 0; 60 int hp = 0, line1l = 0;
62 61
63 switch (n810_jack_func) { 62 switch (n810_jack_func) {
@@ -72,25 +71,25 @@ static void n810_ext_control(struct snd_soc_codec *codec)
72 } 71 }
73 72
74 if (n810_spk_func) 73 if (n810_spk_func)
75 snd_soc_dapm_enable_pin(codec, "Ext Spk"); 74 snd_soc_dapm_enable_pin(dapm, "Ext Spk");
76 else 75 else
77 snd_soc_dapm_disable_pin(codec, "Ext Spk"); 76 snd_soc_dapm_disable_pin(dapm, "Ext Spk");
78 77
79 if (hp) 78 if (hp)
80 snd_soc_dapm_enable_pin(codec, "Headphone Jack"); 79 snd_soc_dapm_enable_pin(dapm, "Headphone Jack");
81 else 80 else
82 snd_soc_dapm_disable_pin(codec, "Headphone Jack"); 81 snd_soc_dapm_disable_pin(dapm, "Headphone Jack");
83 if (line1l) 82 if (line1l)
84 snd_soc_dapm_enable_pin(codec, "LINE1L"); 83 snd_soc_dapm_enable_pin(dapm, "LINE1L");
85 else 84 else
86 snd_soc_dapm_disable_pin(codec, "LINE1L"); 85 snd_soc_dapm_disable_pin(dapm, "LINE1L");
87 86
88 if (n810_dmic_func) 87 if (n810_dmic_func)
89 snd_soc_dapm_enable_pin(codec, "DMic"); 88 snd_soc_dapm_enable_pin(dapm, "DMic");
90 else 89 else
91 snd_soc_dapm_disable_pin(codec, "DMic"); 90 snd_soc_dapm_disable_pin(dapm, "DMic");
92 91
93 snd_soc_dapm_sync(codec); 92 snd_soc_dapm_sync(dapm);
94} 93}
95 94
96static int n810_startup(struct snd_pcm_substream *substream) 95static int n810_startup(struct snd_pcm_substream *substream)
@@ -274,17 +273,18 @@ static const struct snd_kcontrol_new aic33_n810_controls[] = {
274static int n810_aic33_init(struct snd_soc_pcm_runtime *rtd) 273static int n810_aic33_init(struct snd_soc_pcm_runtime *rtd)
275{ 274{
276 struct snd_soc_codec *codec = rtd->codec; 275 struct snd_soc_codec *codec = rtd->codec;
276 struct snd_soc_dapm_context *dapm = &codec->dapm;
277 int err; 277 int err;
278 278
279 /* Not connected */ 279 /* Not connected */
280 snd_soc_dapm_nc_pin(codec, "MONO_LOUT"); 280 snd_soc_dapm_nc_pin(dapm, "MONO_LOUT");
281 snd_soc_dapm_nc_pin(codec, "HPLCOM"); 281 snd_soc_dapm_nc_pin(dapm, "HPLCOM");
282 snd_soc_dapm_nc_pin(codec, "HPRCOM"); 282 snd_soc_dapm_nc_pin(dapm, "HPRCOM");
283 snd_soc_dapm_nc_pin(codec, "MIC3L"); 283 snd_soc_dapm_nc_pin(dapm, "MIC3L");
284 snd_soc_dapm_nc_pin(codec, "MIC3R"); 284 snd_soc_dapm_nc_pin(dapm, "MIC3R");
285 snd_soc_dapm_nc_pin(codec, "LINE1R"); 285 snd_soc_dapm_nc_pin(dapm, "LINE1R");
286 snd_soc_dapm_nc_pin(codec, "LINE2L"); 286 snd_soc_dapm_nc_pin(dapm, "LINE2L");
287 snd_soc_dapm_nc_pin(codec, "LINE2R"); 287 snd_soc_dapm_nc_pin(dapm, "LINE2R");
288 288
289 /* Add N810 specific controls */ 289 /* Add N810 specific controls */
290 err = snd_soc_add_controls(codec, aic33_n810_controls, 290 err = snd_soc_add_controls(codec, aic33_n810_controls,
@@ -293,13 +293,13 @@ static int n810_aic33_init(struct snd_soc_pcm_runtime *rtd)
293 return err; 293 return err;
294 294
295 /* Add N810 specific widgets */ 295 /* Add N810 specific widgets */
296 snd_soc_dapm_new_controls(codec, aic33_dapm_widgets, 296 snd_soc_dapm_new_controls(dapm, aic33_dapm_widgets,
297 ARRAY_SIZE(aic33_dapm_widgets)); 297 ARRAY_SIZE(aic33_dapm_widgets));
298 298
299 /* Set up N810 specific audio path audio_map */ 299 /* Set up N810 specific audio path audio_map */
300 snd_soc_dapm_add_routes(codec, audio_map, ARRAY_SIZE(audio_map)); 300 snd_soc_dapm_add_routes(dapm, audio_map, ARRAY_SIZE(audio_map));
301 301
302 snd_soc_dapm_sync(codec); 302 snd_soc_dapm_sync(dapm);
303 303
304 return 0; 304 return 0;
305} 305}
diff --git a/sound/soc/omap/omap-mcbsp.c b/sound/soc/omap/omap-mcbsp.c
index 7e84f24b9a88..d203f4da18a0 100644
--- a/sound/soc/omap/omap-mcbsp.c
+++ b/sound/soc/omap/omap-mcbsp.c
@@ -102,6 +102,17 @@ static const int omap24xx_dma_reqs[][2] = {
102static const int omap24xx_dma_reqs[][2] = {}; 102static const int omap24xx_dma_reqs[][2] = {};
103#endif 103#endif
104 104
105#if defined(CONFIG_ARCH_OMAP4)
106static const int omap44xx_dma_reqs[][2] = {
107 { OMAP44XX_DMA_MCBSP1_TX, OMAP44XX_DMA_MCBSP1_RX },
108 { OMAP44XX_DMA_MCBSP2_TX, OMAP44XX_DMA_MCBSP2_RX },
109 { OMAP44XX_DMA_MCBSP3_TX, OMAP44XX_DMA_MCBSP3_RX },
110 { OMAP44XX_DMA_MCBSP4_TX, OMAP44XX_DMA_MCBSP4_RX },
111};
112#else
113static const int omap44xx_dma_reqs[][2] = {};
114#endif
115
105#if defined(CONFIG_ARCH_OMAP2420) 116#if defined(CONFIG_ARCH_OMAP2420)
106static const unsigned long omap2420_mcbsp_port[][2] = { 117static const unsigned long omap2420_mcbsp_port[][2] = {
107 { OMAP24XX_MCBSP1_BASE + OMAP_MCBSP_REG_DXR1, 118 { OMAP24XX_MCBSP1_BASE + OMAP_MCBSP_REG_DXR1,
@@ -147,6 +158,21 @@ static const unsigned long omap34xx_mcbsp_port[][2] = {
147static const unsigned long omap34xx_mcbsp_port[][2] = {}; 158static const unsigned long omap34xx_mcbsp_port[][2] = {};
148#endif 159#endif
149 160
161#if defined(CONFIG_ARCH_OMAP4)
162static const unsigned long omap44xx_mcbsp_port[][2] = {
163 { OMAP44XX_MCBSP1_BASE + OMAP_MCBSP_REG_DXR,
164 OMAP44XX_MCBSP1_BASE + OMAP_MCBSP_REG_DRR },
165 { OMAP44XX_MCBSP2_BASE + OMAP_MCBSP_REG_DXR,
166 OMAP44XX_MCBSP2_BASE + OMAP_MCBSP_REG_DRR },
167 { OMAP44XX_MCBSP3_BASE + OMAP_MCBSP_REG_DXR,
168 OMAP44XX_MCBSP3_BASE + OMAP_MCBSP_REG_DRR },
169 { OMAP44XX_MCBSP4_BASE + OMAP_MCBSP_REG_DXR,
170 OMAP44XX_MCBSP4_BASE + OMAP_MCBSP_REG_DRR },
171};
172#else
173static const unsigned long omap44xx_mcbsp_port[][2] = {};
174#endif
175
150static void omap_mcbsp_set_threshold(struct snd_pcm_substream *substream) 176static void omap_mcbsp_set_threshold(struct snd_pcm_substream *substream)
151{ 177{
152 struct snd_soc_pcm_runtime *rtd = substream->private_data; 178 struct snd_soc_pcm_runtime *rtd = substream->private_data;
@@ -224,7 +250,7 @@ static int omap_mcbsp_dai_startup(struct snd_pcm_substream *substream,
224 * 2 channels (stereo): size is 128 / 2 = 64 frames (2 * 64 words) 250 * 2 channels (stereo): size is 128 / 2 = 64 frames (2 * 64 words)
225 * 4 channels: size is 128 / 4 = 32 frames (4 * 32 words) 251 * 4 channels: size is 128 / 4 = 32 frames (4 * 32 words)
226 */ 252 */
227 if (cpu_is_omap343x()) { 253 if (cpu_is_omap343x() || cpu_is_omap44xx()) {
228 /* 254 /*
229 * Rule for the buffer size. We should not allow 255 * Rule for the buffer size. We should not allow
230 * smaller buffer than the FIFO size to avoid underruns 256 * smaller buffer than the FIFO size to avoid underruns
@@ -332,6 +358,9 @@ static int omap_mcbsp_dai_hw_params(struct snd_pcm_substream *substream,
332 } else if (cpu_is_omap343x()) { 358 } else if (cpu_is_omap343x()) {
333 dma = omap24xx_dma_reqs[bus_id][substream->stream]; 359 dma = omap24xx_dma_reqs[bus_id][substream->stream];
334 port = omap34xx_mcbsp_port[bus_id][substream->stream]; 360 port = omap34xx_mcbsp_port[bus_id][substream->stream];
361 } else if (cpu_is_omap44xx()) {
362 dma = omap44xx_dma_reqs[bus_id][substream->stream];
363 port = omap44xx_mcbsp_port[bus_id][substream->stream];
335 } else { 364 } else {
336 return -ENODEV; 365 return -ENODEV;
337 } 366 }
@@ -498,11 +527,11 @@ static int omap_mcbsp_dai_set_dai_fmt(struct snd_soc_dai *cpu_dai,
498 regs->spcr2 |= XINTM(3) | FREE; 527 regs->spcr2 |= XINTM(3) | FREE;
499 regs->spcr1 |= RINTM(3); 528 regs->spcr1 |= RINTM(3);
500 /* RFIG and XFIG are not defined in 34xx */ 529 /* RFIG and XFIG are not defined in 34xx */
501 if (!cpu_is_omap34xx()) { 530 if (!cpu_is_omap34xx() && !cpu_is_omap44xx()) {
502 regs->rcr2 |= RFIG; 531 regs->rcr2 |= RFIG;
503 regs->xcr2 |= XFIG; 532 regs->xcr2 |= XFIG;
504 } 533 }
505 if (cpu_is_omap2430() || cpu_is_omap34xx()) { 534 if (cpu_is_omap2430() || cpu_is_omap34xx() || cpu_is_omap44xx()) {
506 regs->xccr = DXENDLY(1) | XDMAEN | XDISABLE; 535 regs->xccr = DXENDLY(1) | XDMAEN | XDISABLE;
507 regs->rccr = RFULL_CYCLE | RDMAEN | RDISABLE; 536 regs->rccr = RFULL_CYCLE | RDMAEN | RDISABLE;
508 } 537 }
diff --git a/sound/soc/omap/omap-mcbsp.h b/sound/soc/omap/omap-mcbsp.h
index ffdcc5abb7b9..110c106611d3 100644
--- a/sound/soc/omap/omap-mcbsp.h
+++ b/sound/soc/omap/omap-mcbsp.h
@@ -50,6 +50,10 @@ enum omap_mcbsp_div {
50#undef NUM_LINKS 50#undef NUM_LINKS
51#define NUM_LINKS 3 51#define NUM_LINKS 3
52#endif 52#endif
53#if defined(CONFIG_ARCH_OMAP4)
54#undef NUM_LINKS
55#define NUM_LINKS 4
56#endif
53#if defined(CONFIG_ARCH_OMAP2430) || defined(CONFIG_ARCH_OMAP3) 57#if defined(CONFIG_ARCH_OMAP2430) || defined(CONFIG_ARCH_OMAP3)
54#undef NUM_LINKS 58#undef NUM_LINKS
55#define NUM_LINKS 5 59#define NUM_LINKS 5
diff --git a/sound/soc/omap/omap2evm.c b/sound/soc/omap/omap2evm.c
index cf3fc8a675b5..29b60d6796e7 100644
--- a/sound/soc/omap/omap2evm.c
+++ b/sound/soc/omap/omap2evm.c
@@ -26,7 +26,6 @@
26#include <sound/core.h> 26#include <sound/core.h>
27#include <sound/pcm.h> 27#include <sound/pcm.h>
28#include <sound/soc.h> 28#include <sound/soc.h>
29#include <sound/soc-dapm.h>
30 29
31#include <asm/mach-types.h> 30#include <asm/mach-types.h>
32#include <mach/hardware.h> 31#include <mach/hardware.h>
diff --git a/sound/soc/omap/omap3beagle.c b/sound/soc/omap/omap3beagle.c
index e56832b0c444..40db813c0795 100644
--- a/sound/soc/omap/omap3beagle.c
+++ b/sound/soc/omap/omap3beagle.c
@@ -24,7 +24,6 @@
24#include <sound/core.h> 24#include <sound/core.h>
25#include <sound/pcm.h> 25#include <sound/pcm.h>
26#include <sound/soc.h> 26#include <sound/soc.h>
27#include <sound/soc-dapm.h>
28 27
29#include <asm/mach-types.h> 28#include <asm/mach-types.h>
30#include <mach/hardware.h> 29#include <mach/hardware.h>
diff --git a/sound/soc/omap/omap3evm.c b/sound/soc/omap/omap3evm.c
index 810f1e36da21..0daa04469836 100644
--- a/sound/soc/omap/omap3evm.c
+++ b/sound/soc/omap/omap3evm.c
@@ -22,7 +22,6 @@
22#include <sound/core.h> 22#include <sound/core.h>
23#include <sound/pcm.h> 23#include <sound/pcm.h>
24#include <sound/soc.h> 24#include <sound/soc.h>
25#include <sound/soc-dapm.h>
26 25
27#include <asm/mach-types.h> 26#include <asm/mach-types.h>
28#include <mach/hardware.h> 27#include <mach/hardware.h>
diff --git a/sound/soc/omap/omap3pandora.c b/sound/soc/omap/omap3pandora.c
index 4ee33ce2cb98..8047c521e318 100644
--- a/sound/soc/omap/omap3pandora.c
+++ b/sound/soc/omap/omap3pandora.c
@@ -28,7 +28,6 @@
28#include <sound/core.h> 28#include <sound/core.h>
29#include <sound/pcm.h> 29#include <sound/pcm.h>
30#include <sound/soc.h> 30#include <sound/soc.h>
31#include <sound/soc-dapm.h>
32 31
33#include <asm/mach-types.h> 32#include <asm/mach-types.h>
34#include <plat/mcbsp.h> 33#include <plat/mcbsp.h>
@@ -170,51 +169,53 @@ static const struct snd_soc_dapm_route omap3pandora_in_map[] = {
170static int omap3pandora_out_init(struct snd_soc_pcm_runtime *rtd) 169static int omap3pandora_out_init(struct snd_soc_pcm_runtime *rtd)
171{ 170{
172 struct snd_soc_codec *codec = rtd->codec; 171 struct snd_soc_codec *codec = rtd->codec;
172 struct snd_soc_dapm_context *dapm = &codec->dapm;
173 int ret; 173 int ret;
174 174
175 /* All TWL4030 output pins are floating */ 175 /* All TWL4030 output pins are floating */
176 snd_soc_dapm_nc_pin(codec, "EARPIECE"); 176 snd_soc_dapm_nc_pin(dapm, "EARPIECE");
177 snd_soc_dapm_nc_pin(codec, "PREDRIVEL"); 177 snd_soc_dapm_nc_pin(dapm, "PREDRIVEL");
178 snd_soc_dapm_nc_pin(codec, "PREDRIVER"); 178 snd_soc_dapm_nc_pin(dapm, "PREDRIVER");
179 snd_soc_dapm_nc_pin(codec, "HSOL"); 179 snd_soc_dapm_nc_pin(dapm, "HSOL");
180 snd_soc_dapm_nc_pin(codec, "HSOR"); 180 snd_soc_dapm_nc_pin(dapm, "HSOR");
181 snd_soc_dapm_nc_pin(codec, "CARKITL"); 181 snd_soc_dapm_nc_pin(dapm, "CARKITL");
182 snd_soc_dapm_nc_pin(codec, "CARKITR"); 182 snd_soc_dapm_nc_pin(dapm, "CARKITR");
183 snd_soc_dapm_nc_pin(codec, "HFL"); 183 snd_soc_dapm_nc_pin(dapm, "HFL");
184 snd_soc_dapm_nc_pin(codec, "HFR"); 184 snd_soc_dapm_nc_pin(dapm, "HFR");
185 snd_soc_dapm_nc_pin(codec, "VIBRA"); 185 snd_soc_dapm_nc_pin(dapm, "VIBRA");
186 186
187 ret = snd_soc_dapm_new_controls(codec, omap3pandora_out_dapm_widgets, 187 ret = snd_soc_dapm_new_controls(dapm, omap3pandora_out_dapm_widgets,
188 ARRAY_SIZE(omap3pandora_out_dapm_widgets)); 188 ARRAY_SIZE(omap3pandora_out_dapm_widgets));
189 if (ret < 0) 189 if (ret < 0)
190 return ret; 190 return ret;
191 191
192 snd_soc_dapm_add_routes(codec, omap3pandora_out_map, 192 snd_soc_dapm_add_routes(dapm, omap3pandora_out_map,
193 ARRAY_SIZE(omap3pandora_out_map)); 193 ARRAY_SIZE(omap3pandora_out_map));
194 194
195 return snd_soc_dapm_sync(codec); 195 return snd_soc_dapm_sync(dapm);
196} 196}
197 197
198static int omap3pandora_in_init(struct snd_soc_pcm_runtime *rtd) 198static int omap3pandora_in_init(struct snd_soc_pcm_runtime *rtd)
199{ 199{
200 struct snd_soc_codec *codec = rtd->codec; 200 struct snd_soc_codec *codec = rtd->codec;
201 struct snd_soc_dapm_context *dapm = &codec->dapm;
201 int ret; 202 int ret;
202 203
203 /* Not comnnected */ 204 /* Not comnnected */
204 snd_soc_dapm_nc_pin(codec, "HSMIC"); 205 snd_soc_dapm_nc_pin(dapm, "HSMIC");
205 snd_soc_dapm_nc_pin(codec, "CARKITMIC"); 206 snd_soc_dapm_nc_pin(dapm, "CARKITMIC");
206 snd_soc_dapm_nc_pin(codec, "DIGIMIC0"); 207 snd_soc_dapm_nc_pin(dapm, "DIGIMIC0");
207 snd_soc_dapm_nc_pin(codec, "DIGIMIC1"); 208 snd_soc_dapm_nc_pin(dapm, "DIGIMIC1");
208 209
209 ret = snd_soc_dapm_new_controls(codec, omap3pandora_in_dapm_widgets, 210 ret = snd_soc_dapm_new_controls(dapm, omap3pandora_in_dapm_widgets,
210 ARRAY_SIZE(omap3pandora_in_dapm_widgets)); 211 ARRAY_SIZE(omap3pandora_in_dapm_widgets));
211 if (ret < 0) 212 if (ret < 0)
212 return ret; 213 return ret;
213 214
214 snd_soc_dapm_add_routes(codec, omap3pandora_in_map, 215 snd_soc_dapm_add_routes(dapm, omap3pandora_in_map,
215 ARRAY_SIZE(omap3pandora_in_map)); 216 ARRAY_SIZE(omap3pandora_in_map));
216 217
217 return snd_soc_dapm_sync(codec); 218 return snd_soc_dapm_sync(dapm);
218} 219}
219 220
220static struct snd_soc_ops omap3pandora_ops = { 221static struct snd_soc_ops omap3pandora_ops = {
diff --git a/sound/soc/omap/osk5912.c b/sound/soc/omap/osk5912.c
index 65ae00e976ef..7e75e775fb4a 100644
--- a/sound/soc/omap/osk5912.c
+++ b/sound/soc/omap/osk5912.c
@@ -26,7 +26,6 @@
26#include <sound/core.h> 26#include <sound/core.h>
27#include <sound/pcm.h> 27#include <sound/pcm.h>
28#include <sound/soc.h> 28#include <sound/soc.h>
29#include <sound/soc-dapm.h>
30 29
31#include <asm/mach-types.h> 30#include <asm/mach-types.h>
32#include <mach/hardware.h> 31#include <mach/hardware.h>
@@ -116,19 +115,20 @@ static const struct snd_soc_dapm_route audio_map[] = {
116static int osk_tlv320aic23_init(struct snd_soc_pcm_runtime *rtd) 115static int osk_tlv320aic23_init(struct snd_soc_pcm_runtime *rtd)
117{ 116{
118 struct snd_soc_codec *codec = rtd->codec; 117 struct snd_soc_codec *codec = rtd->codec;
118 struct snd_soc_dapm_context *dapm = &codec->dapm;
119 119
120 /* Add osk5912 specific widgets */ 120 /* Add osk5912 specific widgets */
121 snd_soc_dapm_new_controls(codec, tlv320aic23_dapm_widgets, 121 snd_soc_dapm_new_controls(dapm, tlv320aic23_dapm_widgets,
122 ARRAY_SIZE(tlv320aic23_dapm_widgets)); 122 ARRAY_SIZE(tlv320aic23_dapm_widgets));
123 123
124 /* Set up osk5912 specific audio path audio_map */ 124 /* Set up osk5912 specific audio path audio_map */
125 snd_soc_dapm_add_routes(codec, audio_map, ARRAY_SIZE(audio_map)); 125 snd_soc_dapm_add_routes(dapm, audio_map, ARRAY_SIZE(audio_map));
126 126
127 snd_soc_dapm_enable_pin(codec, "Headphone Jack"); 127 snd_soc_dapm_enable_pin(dapm, "Headphone Jack");
128 snd_soc_dapm_enable_pin(codec, "Line In"); 128 snd_soc_dapm_enable_pin(dapm, "Line In");
129 snd_soc_dapm_enable_pin(codec, "Mic Jack"); 129 snd_soc_dapm_enable_pin(dapm, "Mic Jack");
130 130
131 snd_soc_dapm_sync(codec); 131 snd_soc_dapm_sync(dapm);
132 132
133 return 0; 133 return 0;
134} 134}
diff --git a/sound/soc/omap/overo.c b/sound/soc/omap/overo.c
index e95a607937de..bbcf380bfb56 100644
--- a/sound/soc/omap/overo.c
+++ b/sound/soc/omap/overo.c
@@ -24,7 +24,6 @@
24#include <sound/core.h> 24#include <sound/core.h>
25#include <sound/pcm.h> 25#include <sound/pcm.h>
26#include <sound/soc.h> 26#include <sound/soc.h>
27#include <sound/soc-dapm.h>
28 27
29#include <asm/mach-types.h> 28#include <asm/mach-types.h>
30#include <mach/hardware.h> 29#include <mach/hardware.h>
diff --git a/sound/soc/omap/rx51.c b/sound/soc/omap/rx51.c
index 04b5723bf89b..09fb0df8d416 100644
--- a/sound/soc/omap/rx51.c
+++ b/sound/soc/omap/rx51.c
@@ -30,14 +30,12 @@
30#include <sound/jack.h> 30#include <sound/jack.h>
31#include <sound/pcm.h> 31#include <sound/pcm.h>
32#include <sound/soc.h> 32#include <sound/soc.h>
33#include <sound/soc-dapm.h>
34#include <plat/mcbsp.h> 33#include <plat/mcbsp.h>
35 34
36#include <asm/mach-types.h> 35#include <asm/mach-types.h>
37 36
38#include "omap-mcbsp.h" 37#include "omap-mcbsp.h"
39#include "omap-pcm.h" 38#include "omap-pcm.h"
40#include "../codecs/tlv320aic3x.h"
41 39
42#define RX51_TVOUT_SEL_GPIO 40 40#define RX51_TVOUT_SEL_GPIO 40
43#define RX51_JACK_DETECT_GPIO 177 41#define RX51_JACK_DETECT_GPIO 177
@@ -58,19 +56,21 @@ static int rx51_jack_func;
58 56
59static void rx51_ext_control(struct snd_soc_codec *codec) 57static void rx51_ext_control(struct snd_soc_codec *codec)
60{ 58{
59 struct snd_soc_dapm_context *dapm = &codec->dapm;
60
61 if (rx51_spk_func) 61 if (rx51_spk_func)
62 snd_soc_dapm_enable_pin(codec, "Ext Spk"); 62 snd_soc_dapm_enable_pin(dapm, "Ext Spk");
63 else 63 else
64 snd_soc_dapm_disable_pin(codec, "Ext Spk"); 64 snd_soc_dapm_disable_pin(dapm, "Ext Spk");
65 if (rx51_dmic_func) 65 if (rx51_dmic_func)
66 snd_soc_dapm_enable_pin(codec, "DMic"); 66 snd_soc_dapm_enable_pin(dapm, "DMic");
67 else 67 else
68 snd_soc_dapm_disable_pin(codec, "DMic"); 68 snd_soc_dapm_disable_pin(dapm, "DMic");
69 69
70 gpio_set_value(RX51_TVOUT_SEL_GPIO, 70 gpio_set_value(RX51_TVOUT_SEL_GPIO,
71 rx51_jack_func == RX51_JACK_TVOUT); 71 rx51_jack_func == RX51_JACK_TVOUT);
72 72
73 snd_soc_dapm_sync(codec); 73 snd_soc_dapm_sync(dapm);
74} 74}
75 75
76static int rx51_startup(struct snd_pcm_substream *substream) 76static int rx51_startup(struct snd_pcm_substream *substream)
@@ -244,12 +244,13 @@ static const struct snd_kcontrol_new aic34_rx51_controls[] = {
244static int rx51_aic34_init(struct snd_soc_pcm_runtime *rtd) 244static int rx51_aic34_init(struct snd_soc_pcm_runtime *rtd)
245{ 245{
246 struct snd_soc_codec *codec = rtd->codec; 246 struct snd_soc_codec *codec = rtd->codec;
247 struct snd_soc_dapm_context *dapm = &codec->dapm;
247 int err; 248 int err;
248 249
249 /* Set up NC codec pins */ 250 /* Set up NC codec pins */
250 snd_soc_dapm_nc_pin(codec, "MIC3L"); 251 snd_soc_dapm_nc_pin(dapm, "MIC3L");
251 snd_soc_dapm_nc_pin(codec, "MIC3R"); 252 snd_soc_dapm_nc_pin(dapm, "MIC3R");
252 snd_soc_dapm_nc_pin(codec, "LINE1R"); 253 snd_soc_dapm_nc_pin(dapm, "LINE1R");
253 254
254 /* Add RX-51 specific controls */ 255 /* Add RX-51 specific controls */
255 err = snd_soc_add_controls(codec, aic34_rx51_controls, 256 err = snd_soc_add_controls(codec, aic34_rx51_controls,
@@ -258,13 +259,13 @@ static int rx51_aic34_init(struct snd_soc_pcm_runtime *rtd)
258 return err; 259 return err;
259 260
260 /* Add RX-51 specific widgets */ 261 /* Add RX-51 specific widgets */
261 snd_soc_dapm_new_controls(codec, aic34_dapm_widgets, 262 snd_soc_dapm_new_controls(dapm, aic34_dapm_widgets,
262 ARRAY_SIZE(aic34_dapm_widgets)); 263 ARRAY_SIZE(aic34_dapm_widgets));
263 264
264 /* Set up RX-51 specific audio path audio_map */ 265 /* Set up RX-51 specific audio path audio_map */
265 snd_soc_dapm_add_routes(codec, audio_map, ARRAY_SIZE(audio_map)); 266 snd_soc_dapm_add_routes(dapm, audio_map, ARRAY_SIZE(audio_map));
266 267
267 snd_soc_dapm_sync(codec); 268 snd_soc_dapm_sync(dapm);
268 269
269 /* AV jack detection */ 270 /* AV jack detection */
270 err = snd_soc_jack_new(codec, "AV Jack", 271 err = snd_soc_jack_new(codec, "AV Jack",
diff --git a/sound/soc/omap/sdp3430.c b/sound/soc/omap/sdp3430.c
index 07fbcf7d2411..3f72d17d1ef0 100644
--- a/sound/soc/omap/sdp3430.c
+++ b/sound/soc/omap/sdp3430.c
@@ -28,7 +28,6 @@
28#include <sound/core.h> 28#include <sound/core.h>
29#include <sound/pcm.h> 29#include <sound/pcm.h>
30#include <sound/soc.h> 30#include <sound/soc.h>
31#include <sound/soc-dapm.h>
32#include <sound/jack.h> 31#include <sound/jack.h>
33 32
34#include <asm/mach-types.h> 33#include <asm/mach-types.h>
@@ -191,39 +190,40 @@ static const struct snd_soc_dapm_route audio_map[] = {
191static int sdp3430_twl4030_init(struct snd_soc_pcm_runtime *rtd) 190static int sdp3430_twl4030_init(struct snd_soc_pcm_runtime *rtd)
192{ 191{
193 struct snd_soc_codec *codec = rtd->codec; 192 struct snd_soc_codec *codec = rtd->codec;
193 struct snd_soc_dapm_context *dapm = &codec->dapm;
194 int ret; 194 int ret;
195 195
196 /* Add SDP3430 specific widgets */ 196 /* Add SDP3430 specific widgets */
197 ret = snd_soc_dapm_new_controls(codec, sdp3430_twl4030_dapm_widgets, 197 ret = snd_soc_dapm_new_controls(dapm, sdp3430_twl4030_dapm_widgets,
198 ARRAY_SIZE(sdp3430_twl4030_dapm_widgets)); 198 ARRAY_SIZE(sdp3430_twl4030_dapm_widgets));
199 if (ret) 199 if (ret)
200 return ret; 200 return ret;
201 201
202 /* Set up SDP3430 specific audio path audio_map */ 202 /* Set up SDP3430 specific audio path audio_map */
203 snd_soc_dapm_add_routes(codec, audio_map, ARRAY_SIZE(audio_map)); 203 snd_soc_dapm_add_routes(dapm, audio_map, ARRAY_SIZE(audio_map));
204 204
205 /* SDP3430 connected pins */ 205 /* SDP3430 connected pins */
206 snd_soc_dapm_enable_pin(codec, "Ext Mic"); 206 snd_soc_dapm_enable_pin(dapm, "Ext Mic");
207 snd_soc_dapm_enable_pin(codec, "Ext Spk"); 207 snd_soc_dapm_enable_pin(dapm, "Ext Spk");
208 snd_soc_dapm_disable_pin(codec, "Headset Mic"); 208 snd_soc_dapm_disable_pin(dapm, "Headset Mic");
209 snd_soc_dapm_disable_pin(codec, "Headset Stereophone"); 209 snd_soc_dapm_disable_pin(dapm, "Headset Stereophone");
210 210
211 /* TWL4030 not connected pins */ 211 /* TWL4030 not connected pins */
212 snd_soc_dapm_nc_pin(codec, "AUXL"); 212 snd_soc_dapm_nc_pin(dapm, "AUXL");
213 snd_soc_dapm_nc_pin(codec, "AUXR"); 213 snd_soc_dapm_nc_pin(dapm, "AUXR");
214 snd_soc_dapm_nc_pin(codec, "CARKITMIC"); 214 snd_soc_dapm_nc_pin(dapm, "CARKITMIC");
215 snd_soc_dapm_nc_pin(codec, "DIGIMIC0"); 215 snd_soc_dapm_nc_pin(dapm, "DIGIMIC0");
216 snd_soc_dapm_nc_pin(codec, "DIGIMIC1"); 216 snd_soc_dapm_nc_pin(dapm, "DIGIMIC1");
217 217
218 snd_soc_dapm_nc_pin(codec, "OUTL"); 218 snd_soc_dapm_nc_pin(dapm, "OUTL");
219 snd_soc_dapm_nc_pin(codec, "OUTR"); 219 snd_soc_dapm_nc_pin(dapm, "OUTR");
220 snd_soc_dapm_nc_pin(codec, "EARPIECE"); 220 snd_soc_dapm_nc_pin(dapm, "EARPIECE");
221 snd_soc_dapm_nc_pin(codec, "PREDRIVEL"); 221 snd_soc_dapm_nc_pin(dapm, "PREDRIVEL");
222 snd_soc_dapm_nc_pin(codec, "PREDRIVER"); 222 snd_soc_dapm_nc_pin(dapm, "PREDRIVER");
223 snd_soc_dapm_nc_pin(codec, "CARKITL"); 223 snd_soc_dapm_nc_pin(dapm, "CARKITL");
224 snd_soc_dapm_nc_pin(codec, "CARKITR"); 224 snd_soc_dapm_nc_pin(dapm, "CARKITR");
225 225
226 ret = snd_soc_dapm_sync(codec); 226 ret = snd_soc_dapm_sync(dapm);
227 if (ret) 227 if (ret)
228 return ret; 228 return ret;
229 229
diff --git a/sound/soc/omap/sdp4430.c b/sound/soc/omap/sdp4430.c
index 4b4463db6ba0..189e03900637 100644
--- a/sound/soc/omap/sdp4430.c
+++ b/sound/soc/omap/sdp4430.c
@@ -24,7 +24,7 @@
24#include <sound/core.h> 24#include <sound/core.h>
25#include <sound/pcm.h> 25#include <sound/pcm.h>
26#include <sound/soc.h> 26#include <sound/soc.h>
27#include <sound/soc-dapm.h> 27#include <sound/jack.h>
28 28
29#include <asm/mach-types.h> 29#include <asm/mach-types.h>
30#include <plat/hardware.h> 30#include <plat/hardware.h>
@@ -66,6 +66,21 @@ static struct snd_soc_ops sdp4430_ops = {
66 .hw_params = sdp4430_hw_params, 66 .hw_params = sdp4430_hw_params,
67}; 67};
68 68
69/* Headset jack */
70static struct snd_soc_jack hs_jack;
71
72/*Headset jack detection DAPM pins */
73static struct snd_soc_jack_pin hs_jack_pins[] = {
74 {
75 .pin = "Headset Mic",
76 .mask = SND_JACK_MICROPHONE,
77 },
78 {
79 .pin = "Headset Stereophone",
80 .mask = SND_JACK_HEADPHONE,
81 },
82};
83
69static int sdp4430_get_power_mode(struct snd_kcontrol *kcontrol, 84static int sdp4430_get_power_mode(struct snd_kcontrol *kcontrol,
70 struct snd_ctl_elem_value *ucontrol) 85 struct snd_ctl_elem_value *ucontrol)
71{ 86{
@@ -102,6 +117,7 @@ static const struct snd_soc_dapm_widget sdp4430_twl6040_dapm_widgets[] = {
102 SND_SOC_DAPM_MIC("Headset Mic", NULL), 117 SND_SOC_DAPM_MIC("Headset Mic", NULL),
103 SND_SOC_DAPM_HP("Headset Stereophone", NULL), 118 SND_SOC_DAPM_HP("Headset Stereophone", NULL),
104 SND_SOC_DAPM_SPK("Earphone Spk", NULL), 119 SND_SOC_DAPM_SPK("Earphone Spk", NULL),
120 SND_SOC_DAPM_INPUT("Aux/FM Stereo In"),
105}; 121};
106 122
107static const struct snd_soc_dapm_route audio_map[] = { 123static const struct snd_soc_dapm_route audio_map[] = {
@@ -124,11 +140,16 @@ static const struct snd_soc_dapm_route audio_map[] = {
124 140
125 /* Earphone speaker */ 141 /* Earphone speaker */
126 {"Earphone Spk", NULL, "EP"}, 142 {"Earphone Spk", NULL, "EP"},
143
144 /* Aux/FM Stereo In: AFML, AFMR */
145 {"AFML", NULL, "Aux/FM Stereo In"},
146 {"AFMR", NULL, "Aux/FM Stereo In"},
127}; 147};
128 148
129static int sdp4430_twl6040_init(struct snd_soc_pcm_runtime *rtd) 149static int sdp4430_twl6040_init(struct snd_soc_pcm_runtime *rtd)
130{ 150{
131 struct snd_soc_codec *codec = rtd->codec; 151 struct snd_soc_codec *codec = rtd->codec;
152 struct snd_soc_dapm_context *dapm = &codec->dapm;
132 int ret; 153 int ret;
133 154
134 /* Add SDP4430 specific controls */ 155 /* Add SDP4430 specific controls */
@@ -138,25 +159,39 @@ static int sdp4430_twl6040_init(struct snd_soc_pcm_runtime *rtd)
138 return ret; 159 return ret;
139 160
140 /* Add SDP4430 specific widgets */ 161 /* Add SDP4430 specific widgets */
141 ret = snd_soc_dapm_new_controls(codec, sdp4430_twl6040_dapm_widgets, 162 ret = snd_soc_dapm_new_controls(dapm, sdp4430_twl6040_dapm_widgets,
142 ARRAY_SIZE(sdp4430_twl6040_dapm_widgets)); 163 ARRAY_SIZE(sdp4430_twl6040_dapm_widgets));
143 if (ret) 164 if (ret)
144 return ret; 165 return ret;
145 166
146 /* Set up SDP4430 specific audio path audio_map */ 167 /* Set up SDP4430 specific audio path audio_map */
147 snd_soc_dapm_add_routes(codec, audio_map, ARRAY_SIZE(audio_map)); 168 snd_soc_dapm_add_routes(dapm, audio_map, ARRAY_SIZE(audio_map));
148 169
149 /* SDP4430 connected pins */ 170 /* SDP4430 connected pins */
150 snd_soc_dapm_enable_pin(codec, "Ext Mic"); 171 snd_soc_dapm_enable_pin(dapm, "Ext Mic");
151 snd_soc_dapm_enable_pin(codec, "Ext Spk"); 172 snd_soc_dapm_enable_pin(dapm, "Ext Spk");
152 snd_soc_dapm_enable_pin(codec, "Headset Mic"); 173 snd_soc_dapm_enable_pin(dapm, "AFML");
153 snd_soc_dapm_enable_pin(codec, "Headset Stereophone"); 174 snd_soc_dapm_enable_pin(dapm, "AFMR");
175 snd_soc_dapm_enable_pin(dapm, "Headset Mic");
176 snd_soc_dapm_enable_pin(dapm, "Headset Stereophone");
177
178 ret = snd_soc_dapm_sync(dapm);
179 if (ret)
180 return ret;
181
182 /* Headset jack detection */
183 ret = snd_soc_jack_new(codec, "Headset Jack",
184 SND_JACK_HEADSET, &hs_jack);
185 if (ret)
186 return ret;
154 187
155 /* TWL6040 not connected pins */ 188 ret = snd_soc_jack_add_pins(&hs_jack, ARRAY_SIZE(hs_jack_pins),
156 snd_soc_dapm_nc_pin(codec, "AFML"); 189 hs_jack_pins);
157 snd_soc_dapm_nc_pin(codec, "AFMR");
158 190
159 ret = snd_soc_dapm_sync(codec); 191 if (machine_is_omap_4430sdp())
192 twl6040_hs_jack_detect(codec, &hs_jack, SND_JACK_HEADSET);
193 else
194 snd_soc_jack_report(&hs_jack, SND_JACK_HEADSET, SND_JACK_HEADSET);
160 195
161 return ret; 196 return ret;
162} 197}
diff --git a/sound/soc/omap/zoom2.c b/sound/soc/omap/zoom2.c
index 718031eeac34..01709940a43c 100644
--- a/sound/soc/omap/zoom2.c
+++ b/sound/soc/omap/zoom2.c
@@ -24,7 +24,6 @@
24#include <sound/core.h> 24#include <sound/core.h>
25#include <sound/pcm.h> 25#include <sound/pcm.h>
26#include <sound/soc.h> 26#include <sound/soc.h>
27#include <sound/soc-dapm.h>
28 27
29#include <asm/mach-types.h> 28#include <asm/mach-types.h>
30#include <mach/hardware.h> 29#include <mach/hardware.h>
@@ -162,35 +161,36 @@ static const struct snd_soc_dapm_route audio_map[] = {
162static int zoom2_twl4030_init(struct snd_soc_pcm_runtime *rtd) 161static int zoom2_twl4030_init(struct snd_soc_pcm_runtime *rtd)
163{ 162{
164 struct snd_soc_codec *codec = rtd->codec; 163 struct snd_soc_codec *codec = rtd->codec;
164 struct snd_soc_dapm_context *dapm = &codec->dapm;
165 int ret; 165 int ret;
166 166
167 /* Add Zoom2 specific widgets */ 167 /* Add Zoom2 specific widgets */
168 ret = snd_soc_dapm_new_controls(codec, zoom2_twl4030_dapm_widgets, 168 ret = snd_soc_dapm_new_controls(dapm, zoom2_twl4030_dapm_widgets,
169 ARRAY_SIZE(zoom2_twl4030_dapm_widgets)); 169 ARRAY_SIZE(zoom2_twl4030_dapm_widgets));
170 if (ret) 170 if (ret)
171 return ret; 171 return ret;
172 172
173 /* Set up Zoom2 specific audio path audio_map */ 173 /* Set up Zoom2 specific audio path audio_map */
174 snd_soc_dapm_add_routes(codec, audio_map, ARRAY_SIZE(audio_map)); 174 snd_soc_dapm_add_routes(dapm, audio_map, ARRAY_SIZE(audio_map));
175 175
176 /* Zoom2 connected pins */ 176 /* Zoom2 connected pins */
177 snd_soc_dapm_enable_pin(codec, "Ext Mic"); 177 snd_soc_dapm_enable_pin(dapm, "Ext Mic");
178 snd_soc_dapm_enable_pin(codec, "Ext Spk"); 178 snd_soc_dapm_enable_pin(dapm, "Ext Spk");
179 snd_soc_dapm_enable_pin(codec, "Headset Mic"); 179 snd_soc_dapm_enable_pin(dapm, "Headset Mic");
180 snd_soc_dapm_enable_pin(codec, "Headset Stereophone"); 180 snd_soc_dapm_enable_pin(dapm, "Headset Stereophone");
181 snd_soc_dapm_enable_pin(codec, "Aux In"); 181 snd_soc_dapm_enable_pin(dapm, "Aux In");
182 182
183 /* TWL4030 not connected pins */ 183 /* TWL4030 not connected pins */
184 snd_soc_dapm_nc_pin(codec, "CARKITMIC"); 184 snd_soc_dapm_nc_pin(dapm, "CARKITMIC");
185 snd_soc_dapm_nc_pin(codec, "DIGIMIC0"); 185 snd_soc_dapm_nc_pin(dapm, "DIGIMIC0");
186 snd_soc_dapm_nc_pin(codec, "DIGIMIC1"); 186 snd_soc_dapm_nc_pin(dapm, "DIGIMIC1");
187 snd_soc_dapm_nc_pin(codec, "EARPIECE"); 187 snd_soc_dapm_nc_pin(dapm, "EARPIECE");
188 snd_soc_dapm_nc_pin(codec, "PREDRIVEL"); 188 snd_soc_dapm_nc_pin(dapm, "PREDRIVEL");
189 snd_soc_dapm_nc_pin(codec, "PREDRIVER"); 189 snd_soc_dapm_nc_pin(dapm, "PREDRIVER");
190 snd_soc_dapm_nc_pin(codec, "CARKITL"); 190 snd_soc_dapm_nc_pin(dapm, "CARKITL");
191 snd_soc_dapm_nc_pin(codec, "CARKITR"); 191 snd_soc_dapm_nc_pin(dapm, "CARKITR");
192 192
193 ret = snd_soc_dapm_sync(codec); 193 ret = snd_soc_dapm_sync(dapm);
194 194
195 return ret; 195 return ret;
196} 196}
diff --git a/sound/soc/pxa/corgi.c b/sound/soc/pxa/corgi.c
index f451acd4935b..fc592f0d5fc7 100644
--- a/sound/soc/pxa/corgi.c
+++ b/sound/soc/pxa/corgi.c
@@ -23,7 +23,6 @@
23#include <sound/core.h> 23#include <sound/core.h>
24#include <sound/pcm.h> 24#include <sound/pcm.h>
25#include <sound/soc.h> 25#include <sound/soc.h>
26#include <sound/soc-dapm.h>
27 26
28#include <asm/mach-types.h> 27#include <asm/mach-types.h>
29#include <mach/corgi.h> 28#include <mach/corgi.h>
@@ -48,51 +47,53 @@ static int corgi_spk_func;
48 47
49static void corgi_ext_control(struct snd_soc_codec *codec) 48static void corgi_ext_control(struct snd_soc_codec *codec)
50{ 49{
50 struct snd_soc_dapm_context *dapm = &codec->dapm;
51
51 /* set up jack connection */ 52 /* set up jack connection */
52 switch (corgi_jack_func) { 53 switch (corgi_jack_func) {
53 case CORGI_HP: 54 case CORGI_HP:
54 /* set = unmute headphone */ 55 /* set = unmute headphone */
55 gpio_set_value(CORGI_GPIO_MUTE_L, 1); 56 gpio_set_value(CORGI_GPIO_MUTE_L, 1);
56 gpio_set_value(CORGI_GPIO_MUTE_R, 1); 57 gpio_set_value(CORGI_GPIO_MUTE_R, 1);
57 snd_soc_dapm_disable_pin(codec, "Mic Jack"); 58 snd_soc_dapm_disable_pin(dapm, "Mic Jack");
58 snd_soc_dapm_disable_pin(codec, "Line Jack"); 59 snd_soc_dapm_disable_pin(dapm, "Line Jack");
59 snd_soc_dapm_enable_pin(codec, "Headphone Jack"); 60 snd_soc_dapm_enable_pin(dapm, "Headphone Jack");
60 snd_soc_dapm_disable_pin(codec, "Headset Jack"); 61 snd_soc_dapm_disable_pin(dapm, "Headset Jack");
61 break; 62 break;
62 case CORGI_MIC: 63 case CORGI_MIC:
63 /* reset = mute headphone */ 64 /* reset = mute headphone */
64 gpio_set_value(CORGI_GPIO_MUTE_L, 0); 65 gpio_set_value(CORGI_GPIO_MUTE_L, 0);
65 gpio_set_value(CORGI_GPIO_MUTE_R, 0); 66 gpio_set_value(CORGI_GPIO_MUTE_R, 0);
66 snd_soc_dapm_enable_pin(codec, "Mic Jack"); 67 snd_soc_dapm_enable_pin(dapm, "Mic Jack");
67 snd_soc_dapm_disable_pin(codec, "Line Jack"); 68 snd_soc_dapm_disable_pin(dapm, "Line Jack");
68 snd_soc_dapm_disable_pin(codec, "Headphone Jack"); 69 snd_soc_dapm_disable_pin(dapm, "Headphone Jack");
69 snd_soc_dapm_disable_pin(codec, "Headset Jack"); 70 snd_soc_dapm_disable_pin(dapm, "Headset Jack");
70 break; 71 break;
71 case CORGI_LINE: 72 case CORGI_LINE:
72 gpio_set_value(CORGI_GPIO_MUTE_L, 0); 73 gpio_set_value(CORGI_GPIO_MUTE_L, 0);
73 gpio_set_value(CORGI_GPIO_MUTE_R, 0); 74 gpio_set_value(CORGI_GPIO_MUTE_R, 0);
74 snd_soc_dapm_disable_pin(codec, "Mic Jack"); 75 snd_soc_dapm_disable_pin(dapm, "Mic Jack");
75 snd_soc_dapm_enable_pin(codec, "Line Jack"); 76 snd_soc_dapm_enable_pin(dapm, "Line Jack");
76 snd_soc_dapm_disable_pin(codec, "Headphone Jack"); 77 snd_soc_dapm_disable_pin(dapm, "Headphone Jack");
77 snd_soc_dapm_disable_pin(codec, "Headset Jack"); 78 snd_soc_dapm_disable_pin(dapm, "Headset Jack");
78 break; 79 break;
79 case CORGI_HEADSET: 80 case CORGI_HEADSET:
80 gpio_set_value(CORGI_GPIO_MUTE_L, 0); 81 gpio_set_value(CORGI_GPIO_MUTE_L, 0);
81 gpio_set_value(CORGI_GPIO_MUTE_R, 1); 82 gpio_set_value(CORGI_GPIO_MUTE_R, 1);
82 snd_soc_dapm_enable_pin(codec, "Mic Jack"); 83 snd_soc_dapm_enable_pin(dapm, "Mic Jack");
83 snd_soc_dapm_disable_pin(codec, "Line Jack"); 84 snd_soc_dapm_disable_pin(dapm, "Line Jack");
84 snd_soc_dapm_disable_pin(codec, "Headphone Jack"); 85 snd_soc_dapm_disable_pin(dapm, "Headphone Jack");
85 snd_soc_dapm_enable_pin(codec, "Headset Jack"); 86 snd_soc_dapm_enable_pin(dapm, "Headset Jack");
86 break; 87 break;
87 } 88 }
88 89
89 if (corgi_spk_func == CORGI_SPK_ON) 90 if (corgi_spk_func == CORGI_SPK_ON)
90 snd_soc_dapm_enable_pin(codec, "Ext Spk"); 91 snd_soc_dapm_enable_pin(dapm, "Ext Spk");
91 else 92 else
92 snd_soc_dapm_disable_pin(codec, "Ext Spk"); 93 snd_soc_dapm_disable_pin(dapm, "Ext Spk");
93 94
94 /* signal a DAPM event */ 95 /* signal a DAPM event */
95 snd_soc_dapm_sync(codec); 96 snd_soc_dapm_sync(dapm);
96} 97}
97 98
98static int corgi_startup(struct snd_pcm_substream *substream) 99static int corgi_startup(struct snd_pcm_substream *substream)
@@ -279,10 +280,11 @@ static const struct snd_kcontrol_new wm8731_corgi_controls[] = {
279static int corgi_wm8731_init(struct snd_soc_pcm_runtime *rtd) 280static int corgi_wm8731_init(struct snd_soc_pcm_runtime *rtd)
280{ 281{
281 struct snd_soc_codec *codec = rtd->codec; 282 struct snd_soc_codec *codec = rtd->codec;
283 struct snd_soc_dapm_context *dapm = &codec->dapm;
282 int err; 284 int err;
283 285
284 snd_soc_dapm_nc_pin(codec, "LLINEIN"); 286 snd_soc_dapm_nc_pin(dapm, "LLINEIN");
285 snd_soc_dapm_nc_pin(codec, "RLINEIN"); 287 snd_soc_dapm_nc_pin(dapm, "RLINEIN");
286 288
287 /* Add corgi specific controls */ 289 /* Add corgi specific controls */
288 err = snd_soc_add_controls(codec, wm8731_corgi_controls, 290 err = snd_soc_add_controls(codec, wm8731_corgi_controls,
@@ -291,13 +293,13 @@ static int corgi_wm8731_init(struct snd_soc_pcm_runtime *rtd)
291 return err; 293 return err;
292 294
293 /* Add corgi specific widgets */ 295 /* Add corgi specific widgets */
294 snd_soc_dapm_new_controls(codec, wm8731_dapm_widgets, 296 snd_soc_dapm_new_controls(dapm, wm8731_dapm_widgets,
295 ARRAY_SIZE(wm8731_dapm_widgets)); 297 ARRAY_SIZE(wm8731_dapm_widgets));
296 298
297 /* Set up corgi specific audio path audio_map */ 299 /* Set up corgi specific audio path audio_map */
298 snd_soc_dapm_add_routes(codec, audio_map, ARRAY_SIZE(audio_map)); 300 snd_soc_dapm_add_routes(dapm, audio_map, ARRAY_SIZE(audio_map));
299 301
300 snd_soc_dapm_sync(codec); 302 snd_soc_dapm_sync(dapm);
301 return 0; 303 return 0;
302} 304}
303 305
diff --git a/sound/soc/pxa/e740_wm9705.c b/sound/soc/pxa/e740_wm9705.c
index c82cedb602fd..28333e7d9c50 100644
--- a/sound/soc/pxa/e740_wm9705.c
+++ b/sound/soc/pxa/e740_wm9705.c
@@ -16,7 +16,6 @@
16#include <sound/core.h> 16#include <sound/core.h>
17#include <sound/pcm.h> 17#include <sound/pcm.h>
18#include <sound/soc.h> 18#include <sound/soc.h>
19#include <sound/soc-dapm.h>
20 19
21#include <mach/audio.h> 20#include <mach/audio.h>
22#include <mach/eseries-gpio.h> 21#include <mach/eseries-gpio.h>
@@ -92,23 +91,24 @@ static const struct snd_soc_dapm_route audio_map[] = {
92static int e740_ac97_init(struct snd_soc_pcm_runtime *rtd) 91static int e740_ac97_init(struct snd_soc_pcm_runtime *rtd)
93{ 92{
94 struct snd_soc_codec *codec = rtd->codec; 93 struct snd_soc_codec *codec = rtd->codec;
95 94 struct snd_soc_dapm_context *dapm = &codec->dapm;
96 snd_soc_dapm_nc_pin(codec, "HPOUTL"); 95
97 snd_soc_dapm_nc_pin(codec, "HPOUTR"); 96 snd_soc_dapm_nc_pin(dapm, "HPOUTL");
98 snd_soc_dapm_nc_pin(codec, "PHONE"); 97 snd_soc_dapm_nc_pin(dapm, "HPOUTR");
99 snd_soc_dapm_nc_pin(codec, "LINEINL"); 98 snd_soc_dapm_nc_pin(dapm, "PHONE");
100 snd_soc_dapm_nc_pin(codec, "LINEINR"); 99 snd_soc_dapm_nc_pin(dapm, "LINEINL");
101 snd_soc_dapm_nc_pin(codec, "CDINL"); 100 snd_soc_dapm_nc_pin(dapm, "LINEINR");
102 snd_soc_dapm_nc_pin(codec, "CDINR"); 101 snd_soc_dapm_nc_pin(dapm, "CDINL");
103 snd_soc_dapm_nc_pin(codec, "PCBEEP"); 102 snd_soc_dapm_nc_pin(dapm, "CDINR");
104 snd_soc_dapm_nc_pin(codec, "MIC2"); 103 snd_soc_dapm_nc_pin(dapm, "PCBEEP");
105 104 snd_soc_dapm_nc_pin(dapm, "MIC2");
106 snd_soc_dapm_new_controls(codec, e740_dapm_widgets, 105
106 snd_soc_dapm_new_controls(dapm, e740_dapm_widgets,
107 ARRAY_SIZE(e740_dapm_widgets)); 107 ARRAY_SIZE(e740_dapm_widgets));
108 108
109 snd_soc_dapm_add_routes(codec, audio_map, ARRAY_SIZE(audio_map)); 109 snd_soc_dapm_add_routes(dapm, audio_map, ARRAY_SIZE(audio_map));
110 110
111 snd_soc_dapm_sync(codec); 111 snd_soc_dapm_sync(dapm);
112 112
113 return 0; 113 return 0;
114} 114}
diff --git a/sound/soc/pxa/e750_wm9705.c b/sound/soc/pxa/e750_wm9705.c
index 4c143803a75e..01bf31675c55 100644
--- a/sound/soc/pxa/e750_wm9705.c
+++ b/sound/soc/pxa/e750_wm9705.c
@@ -16,7 +16,6 @@
16#include <sound/core.h> 16#include <sound/core.h>
17#include <sound/pcm.h> 17#include <sound/pcm.h>
18#include <sound/soc.h> 18#include <sound/soc.h>
19#include <sound/soc-dapm.h>
20 19
21#include <mach/audio.h> 20#include <mach/audio.h>
22#include <mach/eseries-gpio.h> 21#include <mach/eseries-gpio.h>
@@ -74,23 +73,24 @@ static const struct snd_soc_dapm_route audio_map[] = {
74static int e750_ac97_init(struct snd_soc_pcm_runtime *rtd) 73static int e750_ac97_init(struct snd_soc_pcm_runtime *rtd)
75{ 74{
76 struct snd_soc_codec *codec = rtd->codec; 75 struct snd_soc_codec *codec = rtd->codec;
77 76 struct snd_soc_dapm_context *dapm = &codec->dapm;
78 snd_soc_dapm_nc_pin(codec, "LOUT"); 77
79 snd_soc_dapm_nc_pin(codec, "ROUT"); 78 snd_soc_dapm_nc_pin(dapm, "LOUT");
80 snd_soc_dapm_nc_pin(codec, "PHONE"); 79 snd_soc_dapm_nc_pin(dapm, "ROUT");
81 snd_soc_dapm_nc_pin(codec, "LINEINL"); 80 snd_soc_dapm_nc_pin(dapm, "PHONE");
82 snd_soc_dapm_nc_pin(codec, "LINEINR"); 81 snd_soc_dapm_nc_pin(dapm, "LINEINL");
83 snd_soc_dapm_nc_pin(codec, "CDINL"); 82 snd_soc_dapm_nc_pin(dapm, "LINEINR");
84 snd_soc_dapm_nc_pin(codec, "CDINR"); 83 snd_soc_dapm_nc_pin(dapm, "CDINL");
85 snd_soc_dapm_nc_pin(codec, "PCBEEP"); 84 snd_soc_dapm_nc_pin(dapm, "CDINR");
86 snd_soc_dapm_nc_pin(codec, "MIC2"); 85 snd_soc_dapm_nc_pin(dapm, "PCBEEP");
87 86 snd_soc_dapm_nc_pin(dapm, "MIC2");
88 snd_soc_dapm_new_controls(codec, e750_dapm_widgets, 87
88 snd_soc_dapm_new_controls(dapm, e750_dapm_widgets,
89 ARRAY_SIZE(e750_dapm_widgets)); 89 ARRAY_SIZE(e750_dapm_widgets));
90 90
91 snd_soc_dapm_add_routes(codec, audio_map, ARRAY_SIZE(audio_map)); 91 snd_soc_dapm_add_routes(dapm, audio_map, ARRAY_SIZE(audio_map));
92 92
93 snd_soc_dapm_sync(codec); 93 snd_soc_dapm_sync(dapm);
94 94
95 return 0; 95 return 0;
96} 96}
diff --git a/sound/soc/pxa/e800_wm9712.c b/sound/soc/pxa/e800_wm9712.c
index d42e5fe832c5..c6a37c6ef23b 100644
--- a/sound/soc/pxa/e800_wm9712.c
+++ b/sound/soc/pxa/e800_wm9712.c
@@ -16,7 +16,6 @@
16#include <sound/core.h> 16#include <sound/core.h>
17#include <sound/pcm.h> 17#include <sound/pcm.h>
18#include <sound/soc.h> 18#include <sound/soc.h>
19#include <sound/soc-dapm.h>
20 19
21#include <asm/mach-types.h> 20#include <asm/mach-types.h>
22#include <mach/audio.h> 21#include <mach/audio.h>
@@ -75,12 +74,13 @@ static const struct snd_soc_dapm_route audio_map[] = {
75static int e800_ac97_init(struct snd_soc_pcm_runtime *rtd) 74static int e800_ac97_init(struct snd_soc_pcm_runtime *rtd)
76{ 75{
77 struct snd_soc_codec *codec = rtd->codec; 76 struct snd_soc_codec *codec = rtd->codec;
77 struct snd_soc_dapm_context *dapm = &codec->dapm;
78 78
79 snd_soc_dapm_new_controls(codec, e800_dapm_widgets, 79 snd_soc_dapm_new_controls(dapm, e800_dapm_widgets,
80 ARRAY_SIZE(e800_dapm_widgets)); 80 ARRAY_SIZE(e800_dapm_widgets));
81 81
82 snd_soc_dapm_add_routes(codec, audio_map, ARRAY_SIZE(audio_map)); 82 snd_soc_dapm_add_routes(dapm, audio_map, ARRAY_SIZE(audio_map));
83 snd_soc_dapm_sync(codec); 83 snd_soc_dapm_sync(dapm);
84 84
85 return 0; 85 return 0;
86} 86}
diff --git a/sound/soc/pxa/em-x270.c b/sound/soc/pxa/em-x270.c
index eadf9d351a04..fc22e6eefc98 100644
--- a/sound/soc/pxa/em-x270.c
+++ b/sound/soc/pxa/em-x270.c
@@ -26,7 +26,6 @@
26#include <sound/core.h> 26#include <sound/core.h>
27#include <sound/pcm.h> 27#include <sound/pcm.h>
28#include <sound/soc.h> 28#include <sound/soc.h>
29#include <sound/soc-dapm.h>
30 29
31#include <asm/mach-types.h> 30#include <asm/mach-types.h>
32#include <mach/audio.h> 31#include <mach/audio.h>
diff --git a/sound/soc/pxa/magician.c b/sound/soc/pxa/magician.c
index 5ef0526924b9..67dcc36cd621 100644
--- a/sound/soc/pxa/magician.c
+++ b/sound/soc/pxa/magician.c
@@ -26,7 +26,6 @@
26#include <sound/pcm.h> 26#include <sound/pcm.h>
27#include <sound/pcm_params.h> 27#include <sound/pcm_params.h>
28#include <sound/soc.h> 28#include <sound/soc.h>
29#include <sound/soc-dapm.h>
30#include <sound/uda1380.h> 29#include <sound/uda1380.h>
31 30
32#include <mach/magician.h> 31#include <mach/magician.h>
@@ -44,27 +43,29 @@ static int magician_in_sel = MAGICIAN_MIC;
44 43
45static void magician_ext_control(struct snd_soc_codec *codec) 44static void magician_ext_control(struct snd_soc_codec *codec)
46{ 45{
46 struct snd_soc_dapm_context *dapm = &codec->dapm;
47
47 if (magician_spk_switch) 48 if (magician_spk_switch)
48 snd_soc_dapm_enable_pin(codec, "Speaker"); 49 snd_soc_dapm_enable_pin(dapm, "Speaker");
49 else 50 else
50 snd_soc_dapm_disable_pin(codec, "Speaker"); 51 snd_soc_dapm_disable_pin(dapm, "Speaker");
51 if (magician_hp_switch) 52 if (magician_hp_switch)
52 snd_soc_dapm_enable_pin(codec, "Headphone Jack"); 53 snd_soc_dapm_enable_pin(dapm, "Headphone Jack");
53 else 54 else
54 snd_soc_dapm_disable_pin(codec, "Headphone Jack"); 55 snd_soc_dapm_disable_pin(dapm, "Headphone Jack");
55 56
56 switch (magician_in_sel) { 57 switch (magician_in_sel) {
57 case MAGICIAN_MIC: 58 case MAGICIAN_MIC:
58 snd_soc_dapm_disable_pin(codec, "Headset Mic"); 59 snd_soc_dapm_disable_pin(dapm, "Headset Mic");
59 snd_soc_dapm_enable_pin(codec, "Call Mic"); 60 snd_soc_dapm_enable_pin(dapm, "Call Mic");
60 break; 61 break;
61 case MAGICIAN_MIC_EXT: 62 case MAGICIAN_MIC_EXT:
62 snd_soc_dapm_disable_pin(codec, "Call Mic"); 63 snd_soc_dapm_disable_pin(dapm, "Call Mic");
63 snd_soc_dapm_enable_pin(codec, "Headset Mic"); 64 snd_soc_dapm_enable_pin(dapm, "Headset Mic");
64 break; 65 break;
65 } 66 }
66 67
67 snd_soc_dapm_sync(codec); 68 snd_soc_dapm_sync(dapm);
68} 69}
69 70
70static int magician_startup(struct snd_pcm_substream *substream) 71static int magician_startup(struct snd_pcm_substream *substream)
@@ -399,15 +400,16 @@ static const struct snd_kcontrol_new uda1380_magician_controls[] = {
399static int magician_uda1380_init(struct snd_soc_pcm_runtime *rtd) 400static int magician_uda1380_init(struct snd_soc_pcm_runtime *rtd)
400{ 401{
401 struct snd_soc_codec *codec = rtd->codec; 402 struct snd_soc_codec *codec = rtd->codec;
403 struct snd_soc_dapm_context *dapm = &codec->dapm;
402 int err; 404 int err;
403 405
404 /* NC codec pins */ 406 /* NC codec pins */
405 snd_soc_dapm_nc_pin(codec, "VOUTLHP"); 407 snd_soc_dapm_nc_pin(dapm, "VOUTLHP");
406 snd_soc_dapm_nc_pin(codec, "VOUTRHP"); 408 snd_soc_dapm_nc_pin(dapm, "VOUTRHP");
407 409
408 /* FIXME: is anything connected here? */ 410 /* FIXME: is anything connected here? */
409 snd_soc_dapm_nc_pin(codec, "VINL"); 411 snd_soc_dapm_nc_pin(dapm, "VINL");
410 snd_soc_dapm_nc_pin(codec, "VINR"); 412 snd_soc_dapm_nc_pin(dapm, "VINR");
411 413
412 /* Add magician specific controls */ 414 /* Add magician specific controls */
413 err = snd_soc_add_controls(codec, uda1380_magician_controls, 415 err = snd_soc_add_controls(codec, uda1380_magician_controls,
@@ -416,13 +418,13 @@ static int magician_uda1380_init(struct snd_soc_pcm_runtime *rtd)
416 return err; 418 return err;
417 419
418 /* Add magician specific widgets */ 420 /* Add magician specific widgets */
419 snd_soc_dapm_new_controls(codec, uda1380_dapm_widgets, 421 snd_soc_dapm_new_controls(dapm, uda1380_dapm_widgets,
420 ARRAY_SIZE(uda1380_dapm_widgets)); 422 ARRAY_SIZE(uda1380_dapm_widgets));
421 423
422 /* Set up magician specific audio path interconnects */ 424 /* Set up magician specific audio path interconnects */
423 snd_soc_dapm_add_routes(codec, audio_map, ARRAY_SIZE(audio_map)); 425 snd_soc_dapm_add_routes(dapm, audio_map, ARRAY_SIZE(audio_map));
424 426
425 snd_soc_dapm_sync(codec); 427 snd_soc_dapm_sync(dapm);
426 return 0; 428 return 0;
427} 429}
428 430
diff --git a/sound/soc/pxa/mioa701_wm9713.c b/sound/soc/pxa/mioa701_wm9713.c
index f284cc54bc80..0d70fc8c12bd 100644
--- a/sound/soc/pxa/mioa701_wm9713.c
+++ b/sound/soc/pxa/mioa701_wm9713.c
@@ -50,7 +50,6 @@
50#include <sound/core.h> 50#include <sound/core.h>
51#include <sound/pcm.h> 51#include <sound/pcm.h>
52#include <sound/soc.h> 52#include <sound/soc.h>
53#include <sound/soc-dapm.h>
54#include <sound/initval.h> 53#include <sound/initval.h>
55#include <sound/ac97_codec.h> 54#include <sound/ac97_codec.h>
56 55
@@ -130,13 +129,14 @@ static const struct snd_soc_dapm_route audio_map[] = {
130static int mioa701_wm9713_init(struct snd_soc_pcm_runtime *rtd) 129static int mioa701_wm9713_init(struct snd_soc_pcm_runtime *rtd)
131{ 130{
132 struct snd_soc_codec *codec = rtd->codec; 131 struct snd_soc_codec *codec = rtd->codec;
132 struct snd_soc_dapm_context *dapm = &codec->dapm;
133 unsigned short reg; 133 unsigned short reg;
134 134
135 /* Add mioa701 specific widgets */ 135 /* Add mioa701 specific widgets */
136 snd_soc_dapm_new_controls(codec, ARRAY_AND_SIZE(mioa701_dapm_widgets)); 136 snd_soc_dapm_new_controls(dapm, ARRAY_AND_SIZE(mioa701_dapm_widgets));
137 137
138 /* Set up mioa701 specific audio path audio_mapnects */ 138 /* Set up mioa701 specific audio path audio_mapnects */
139 snd_soc_dapm_add_routes(codec, ARRAY_AND_SIZE(audio_map)); 139 snd_soc_dapm_add_routes(dapm, ARRAY_AND_SIZE(audio_map));
140 140
141 /* Prepare GPIO8 for rear speaker amplifier */ 141 /* Prepare GPIO8 for rear speaker amplifier */
142 reg = codec->driver->read(codec, AC97_GPIO_CFG); 142 reg = codec->driver->read(codec, AC97_GPIO_CFG);
@@ -146,12 +146,12 @@ static int mioa701_wm9713_init(struct snd_soc_pcm_runtime *rtd)
146 reg = codec->driver->read(codec, AC97_3D_CONTROL); 146 reg = codec->driver->read(codec, AC97_3D_CONTROL);
147 codec->driver->write(codec, AC97_3D_CONTROL, reg | 0xc000); 147 codec->driver->write(codec, AC97_3D_CONTROL, reg | 0xc000);
148 148
149 snd_soc_dapm_enable_pin(codec, "Front Speaker"); 149 snd_soc_dapm_enable_pin(dapm, "Front Speaker");
150 snd_soc_dapm_enable_pin(codec, "Rear Speaker"); 150 snd_soc_dapm_enable_pin(dapm, "Rear Speaker");
151 snd_soc_dapm_enable_pin(codec, "Front Mic"); 151 snd_soc_dapm_enable_pin(dapm, "Front Mic");
152 snd_soc_dapm_enable_pin(codec, "GSM Line In"); 152 snd_soc_dapm_enable_pin(dapm, "GSM Line In");
153 snd_soc_dapm_enable_pin(codec, "GSM Line Out"); 153 snd_soc_dapm_enable_pin(dapm, "GSM Line Out");
154 snd_soc_dapm_sync(codec); 154 snd_soc_dapm_sync(dapm);
155 155
156 return 0; 156 return 0;
157} 157}
diff --git a/sound/soc/pxa/palm27x.c b/sound/soc/pxa/palm27x.c
index 13f6d485d571..857db96d4a4f 100644
--- a/sound/soc/pxa/palm27x.c
+++ b/sound/soc/pxa/palm27x.c
@@ -21,7 +21,6 @@
21#include <sound/core.h> 21#include <sound/core.h>
22#include <sound/pcm.h> 22#include <sound/pcm.h>
23#include <sound/soc.h> 23#include <sound/soc.h>
24#include <sound/soc-dapm.h>
25#include <sound/jack.h> 24#include <sound/jack.h>
26 25
27#include <asm/mach-types.h> 26#include <asm/mach-types.h>
@@ -77,37 +76,38 @@ static struct snd_soc_card palm27x_asoc;
77static int palm27x_ac97_init(struct snd_soc_pcm_runtime *rtd) 76static int palm27x_ac97_init(struct snd_soc_pcm_runtime *rtd)
78{ 77{
79 struct snd_soc_codec *codec = rtd->codec; 78 struct snd_soc_codec *codec = rtd->codec;
79 struct snd_soc_dapm_context *dapm = &codec->dapm;
80 int err; 80 int err;
81 81
82 /* add palm27x specific widgets */ 82 /* add palm27x specific widgets */
83 err = snd_soc_dapm_new_controls(codec, palm27x_dapm_widgets, 83 err = snd_soc_dapm_new_controls(dapm, palm27x_dapm_widgets,
84 ARRAY_SIZE(palm27x_dapm_widgets)); 84 ARRAY_SIZE(palm27x_dapm_widgets));
85 if (err) 85 if (err)
86 return err; 86 return err;
87 87
88 /* set up palm27x specific audio path audio_map */ 88 /* set up palm27x specific audio path audio_map */
89 err = snd_soc_dapm_add_routes(codec, audio_map, ARRAY_SIZE(audio_map)); 89 err = snd_soc_dapm_add_routes(dapm, audio_map, ARRAY_SIZE(audio_map));
90 if (err) 90 if (err)
91 return err; 91 return err;
92 92
93 /* connected pins */ 93 /* connected pins */
94 if (machine_is_palmld()) 94 if (machine_is_palmld())
95 snd_soc_dapm_enable_pin(codec, "MIC1"); 95 snd_soc_dapm_enable_pin(dapm, "MIC1");
96 snd_soc_dapm_enable_pin(codec, "HPOUTL"); 96 snd_soc_dapm_enable_pin(dapm, "HPOUTL");
97 snd_soc_dapm_enable_pin(codec, "HPOUTR"); 97 snd_soc_dapm_enable_pin(dapm, "HPOUTR");
98 snd_soc_dapm_enable_pin(codec, "LOUT2"); 98 snd_soc_dapm_enable_pin(dapm, "LOUT2");
99 snd_soc_dapm_enable_pin(codec, "ROUT2"); 99 snd_soc_dapm_enable_pin(dapm, "ROUT2");
100 100
101 /* not connected pins */ 101 /* not connected pins */
102 snd_soc_dapm_nc_pin(codec, "OUT3"); 102 snd_soc_dapm_nc_pin(dapm, "OUT3");
103 snd_soc_dapm_nc_pin(codec, "MONOOUT"); 103 snd_soc_dapm_nc_pin(dapm, "MONOOUT");
104 snd_soc_dapm_nc_pin(codec, "LINEINL"); 104 snd_soc_dapm_nc_pin(dapm, "LINEINL");
105 snd_soc_dapm_nc_pin(codec, "LINEINR"); 105 snd_soc_dapm_nc_pin(dapm, "LINEINR");
106 snd_soc_dapm_nc_pin(codec, "PCBEEP"); 106 snd_soc_dapm_nc_pin(dapm, "PCBEEP");
107 snd_soc_dapm_nc_pin(codec, "PHONE"); 107 snd_soc_dapm_nc_pin(dapm, "PHONE");
108 snd_soc_dapm_nc_pin(codec, "MIC2"); 108 snd_soc_dapm_nc_pin(dapm, "MIC2");
109 109
110 err = snd_soc_dapm_sync(codec); 110 err = snd_soc_dapm_sync(dapm);
111 if (err) 111 if (err)
112 return err; 112 return err;
113 113
diff --git a/sound/soc/pxa/poodle.c b/sound/soc/pxa/poodle.c
index 84edd0385a21..6298ee115e27 100644
--- a/sound/soc/pxa/poodle.c
+++ b/sound/soc/pxa/poodle.c
@@ -23,7 +23,6 @@
23#include <sound/core.h> 23#include <sound/core.h>
24#include <sound/pcm.h> 24#include <sound/pcm.h>
25#include <sound/soc.h> 25#include <sound/soc.h>
26#include <sound/soc-dapm.h>
27 26
28#include <asm/mach-types.h> 27#include <asm/mach-types.h>
29#include <asm/hardware/locomo.h> 28#include <asm/hardware/locomo.h>
@@ -46,6 +45,8 @@ static int poodle_spk_func;
46 45
47static void poodle_ext_control(struct snd_soc_codec *codec) 46static void poodle_ext_control(struct snd_soc_codec *codec)
48{ 47{
48 struct snd_soc_dapm_context *dapm = &codec->dapm;
49
49 /* set up jack connection */ 50 /* set up jack connection */
50 if (poodle_jack_func == POODLE_HP) { 51 if (poodle_jack_func == POODLE_HP) {
51 /* set = unmute headphone */ 52 /* set = unmute headphone */
@@ -53,23 +54,23 @@ static void poodle_ext_control(struct snd_soc_codec *codec)
53 POODLE_LOCOMO_GPIO_MUTE_L, 1); 54 POODLE_LOCOMO_GPIO_MUTE_L, 1);
54 locomo_gpio_write(&poodle_locomo_device.dev, 55 locomo_gpio_write(&poodle_locomo_device.dev,
55 POODLE_LOCOMO_GPIO_MUTE_R, 1); 56 POODLE_LOCOMO_GPIO_MUTE_R, 1);
56 snd_soc_dapm_enable_pin(codec, "Headphone Jack"); 57 snd_soc_dapm_enable_pin(dapm, "Headphone Jack");
57 } else { 58 } else {
58 locomo_gpio_write(&poodle_locomo_device.dev, 59 locomo_gpio_write(&poodle_locomo_device.dev,
59 POODLE_LOCOMO_GPIO_MUTE_L, 0); 60 POODLE_LOCOMO_GPIO_MUTE_L, 0);
60 locomo_gpio_write(&poodle_locomo_device.dev, 61 locomo_gpio_write(&poodle_locomo_device.dev,
61 POODLE_LOCOMO_GPIO_MUTE_R, 0); 62 POODLE_LOCOMO_GPIO_MUTE_R, 0);
62 snd_soc_dapm_disable_pin(codec, "Headphone Jack"); 63 snd_soc_dapm_disable_pin(dapm, "Headphone Jack");
63 } 64 }
64 65
65 /* set the enpoints to their new connetion states */ 66 /* set the enpoints to their new connetion states */
66 if (poodle_spk_func == POODLE_SPK_ON) 67 if (poodle_spk_func == POODLE_SPK_ON)
67 snd_soc_dapm_enable_pin(codec, "Ext Spk"); 68 snd_soc_dapm_enable_pin(dapm, "Ext Spk");
68 else 69 else
69 snd_soc_dapm_disable_pin(codec, "Ext Spk"); 70 snd_soc_dapm_disable_pin(dapm, "Ext Spk");
70 71
71 /* signal a DAPM event */ 72 /* signal a DAPM event */
72 snd_soc_dapm_sync(codec); 73 snd_soc_dapm_sync(dapm);
73} 74}
74 75
75static int poodle_startup(struct snd_pcm_substream *substream) 76static int poodle_startup(struct snd_pcm_substream *substream)
@@ -244,11 +245,12 @@ static const struct snd_kcontrol_new wm8731_poodle_controls[] = {
244static int poodle_wm8731_init(struct snd_soc_pcm_runtime *rtd) 245static int poodle_wm8731_init(struct snd_soc_pcm_runtime *rtd)
245{ 246{
246 struct snd_soc_codec *codec = rtd->codec; 247 struct snd_soc_codec *codec = rtd->codec;
248 struct snd_soc_dapm_context *dapm = &codec->dapm;
247 int err; 249 int err;
248 250
249 snd_soc_dapm_nc_pin(codec, "LLINEIN"); 251 snd_soc_dapm_nc_pin(dapm, "LLINEIN");
250 snd_soc_dapm_nc_pin(codec, "RLINEIN"); 252 snd_soc_dapm_nc_pin(dapm, "RLINEIN");
251 snd_soc_dapm_enable_pin(codec, "MICIN"); 253 snd_soc_dapm_enable_pin(dapm, "MICIN");
252 254
253 /* Add poodle specific controls */ 255 /* Add poodle specific controls */
254 err = snd_soc_add_controls(codec, wm8731_poodle_controls, 256 err = snd_soc_add_controls(codec, wm8731_poodle_controls,
@@ -257,13 +259,13 @@ static int poodle_wm8731_init(struct snd_soc_pcm_runtime *rtd)
257 return err; 259 return err;
258 260
259 /* Add poodle specific widgets */ 261 /* Add poodle specific widgets */
260 snd_soc_dapm_new_controls(codec, wm8731_dapm_widgets, 262 snd_soc_dapm_new_controls(dapm, wm8731_dapm_widgets,
261 ARRAY_SIZE(wm8731_dapm_widgets)); 263 ARRAY_SIZE(wm8731_dapm_widgets));
262 264
263 /* Set up poodle specific audio path audio_map */ 265 /* Set up poodle specific audio path audio_map */
264 snd_soc_dapm_add_routes(codec, audio_map, ARRAY_SIZE(audio_map)); 266 snd_soc_dapm_add_routes(dapm, audio_map, ARRAY_SIZE(audio_map));
265 267
266 snd_soc_dapm_sync(codec); 268 snd_soc_dapm_sync(dapm);
267 return 0; 269 return 0;
268} 270}
269 271
diff --git a/sound/soc/pxa/raumfeld.c b/sound/soc/pxa/raumfeld.c
index 2cda82bc5d2e..0fd60f423036 100644
--- a/sound/soc/pxa/raumfeld.c
+++ b/sound/soc/pxa/raumfeld.c
@@ -22,7 +22,6 @@
22#include <linux/gpio.h> 22#include <linux/gpio.h>
23#include <sound/pcm.h> 23#include <sound/pcm.h>
24#include <sound/soc.h> 24#include <sound/soc.h>
25#include <sound/soc-dapm.h>
26 25
27#include <asm/mach-types.h> 26#include <asm/mach-types.h>
28 27
diff --git a/sound/soc/pxa/saarb.c b/sound/soc/pxa/saarb.c
index d63cb474b4e1..9595189fc681 100644
--- a/sound/soc/pxa/saarb.c
+++ b/sound/soc/pxa/saarb.c
@@ -18,7 +18,6 @@
18#include <sound/pcm.h> 18#include <sound/pcm.h>
19#include <sound/pcm_params.h> 19#include <sound/pcm_params.h>
20#include <sound/soc.h> 20#include <sound/soc.h>
21#include <sound/soc-dapm.h>
22#include <sound/jack.h> 21#include <sound/jack.h>
23 22
24#include <asm/mach-types.h> 23#include <asm/mach-types.h>
@@ -133,20 +132,21 @@ static struct snd_soc_card snd_soc_card_saarb = {
133static int saarb_pm860x_init(struct snd_soc_pcm_runtime *rtd) 132static int saarb_pm860x_init(struct snd_soc_pcm_runtime *rtd)
134{ 133{
135 struct snd_soc_codec *codec = rtd->codec; 134 struct snd_soc_codec *codec = rtd->codec;
135 struct snd_soc_dapm_context *dapm = &codec->dapm;
136 int ret; 136 int ret;
137 137
138 snd_soc_dapm_new_controls(codec, saarb_dapm_widgets, 138 snd_soc_dapm_new_controls(dapm, saarb_dapm_widgets,
139 ARRAY_SIZE(saarb_dapm_widgets)); 139 ARRAY_SIZE(saarb_dapm_widgets));
140 snd_soc_dapm_add_routes(codec, audio_map, ARRAY_SIZE(audio_map)); 140 snd_soc_dapm_add_routes(dapm, audio_map, ARRAY_SIZE(audio_map));
141 141
142 /* connected pins */ 142 /* connected pins */
143 snd_soc_dapm_enable_pin(codec, "Ext Speaker"); 143 snd_soc_dapm_enable_pin(dapm, "Ext Speaker");
144 snd_soc_dapm_enable_pin(codec, "Ext Mic 1"); 144 snd_soc_dapm_enable_pin(dapm, "Ext Mic 1");
145 snd_soc_dapm_enable_pin(codec, "Ext Mic 3"); 145 snd_soc_dapm_enable_pin(dapm, "Ext Mic 3");
146 snd_soc_dapm_disable_pin(codec, "Headset Mic 2"); 146 snd_soc_dapm_disable_pin(dapm, "Headset Mic 2");
147 snd_soc_dapm_disable_pin(codec, "Headset Stereophone"); 147 snd_soc_dapm_disable_pin(dapm, "Headset Stereophone");
148 148
149 ret = snd_soc_dapm_sync(codec); 149 ret = snd_soc_dapm_sync(dapm);
150 if (ret) 150 if (ret)
151 return ret; 151 return ret;
152 152
diff --git a/sound/soc/pxa/spitz.c b/sound/soc/pxa/spitz.c
index 0b30d7de24ec..c2acb69b957a 100644
--- a/sound/soc/pxa/spitz.c
+++ b/sound/soc/pxa/spitz.c
@@ -23,7 +23,6 @@
23#include <sound/core.h> 23#include <sound/core.h>
24#include <sound/pcm.h> 24#include <sound/pcm.h>
25#include <sound/soc.h> 25#include <sound/soc.h>
26#include <sound/soc-dapm.h>
27 26
28#include <asm/mach-types.h> 27#include <asm/mach-types.h>
29#include <mach/spitz.h> 28#include <mach/spitz.h>
@@ -46,61 +45,63 @@ static int spitz_spk_func;
46 45
47static void spitz_ext_control(struct snd_soc_codec *codec) 46static void spitz_ext_control(struct snd_soc_codec *codec)
48{ 47{
48 struct snd_soc_dapm_context *dapm = &codec->dapm;
49
49 if (spitz_spk_func == SPITZ_SPK_ON) 50 if (spitz_spk_func == SPITZ_SPK_ON)
50 snd_soc_dapm_enable_pin(codec, "Ext Spk"); 51 snd_soc_dapm_enable_pin(dapm, "Ext Spk");
51 else 52 else
52 snd_soc_dapm_disable_pin(codec, "Ext Spk"); 53 snd_soc_dapm_disable_pin(dapm, "Ext Spk");
53 54
54 /* set up jack connection */ 55 /* set up jack connection */
55 switch (spitz_jack_func) { 56 switch (spitz_jack_func) {
56 case SPITZ_HP: 57 case SPITZ_HP:
57 /* enable and unmute hp jack, disable mic bias */ 58 /* enable and unmute hp jack, disable mic bias */
58 snd_soc_dapm_disable_pin(codec, "Headset Jack"); 59 snd_soc_dapm_disable_pin(dapm, "Headset Jack");
59 snd_soc_dapm_disable_pin(codec, "Mic Jack"); 60 snd_soc_dapm_disable_pin(dapm, "Mic Jack");
60 snd_soc_dapm_disable_pin(codec, "Line Jack"); 61 snd_soc_dapm_disable_pin(dapm, "Line Jack");
61 snd_soc_dapm_enable_pin(codec, "Headphone Jack"); 62 snd_soc_dapm_enable_pin(dapm, "Headphone Jack");
62 gpio_set_value(SPITZ_GPIO_MUTE_L, 1); 63 gpio_set_value(SPITZ_GPIO_MUTE_L, 1);
63 gpio_set_value(SPITZ_GPIO_MUTE_R, 1); 64 gpio_set_value(SPITZ_GPIO_MUTE_R, 1);
64 break; 65 break;
65 case SPITZ_MIC: 66 case SPITZ_MIC:
66 /* enable mic jack and bias, mute hp */ 67 /* enable mic jack and bias, mute hp */
67 snd_soc_dapm_disable_pin(codec, "Headphone Jack"); 68 snd_soc_dapm_disable_pin(dapm, "Headphone Jack");
68 snd_soc_dapm_disable_pin(codec, "Headset Jack"); 69 snd_soc_dapm_disable_pin(dapm, "Headset Jack");
69 snd_soc_dapm_disable_pin(codec, "Line Jack"); 70 snd_soc_dapm_disable_pin(dapm, "Line Jack");
70 snd_soc_dapm_enable_pin(codec, "Mic Jack"); 71 snd_soc_dapm_enable_pin(dapm, "Mic Jack");
71 gpio_set_value(SPITZ_GPIO_MUTE_L, 0); 72 gpio_set_value(SPITZ_GPIO_MUTE_L, 0);
72 gpio_set_value(SPITZ_GPIO_MUTE_R, 0); 73 gpio_set_value(SPITZ_GPIO_MUTE_R, 0);
73 break; 74 break;
74 case SPITZ_LINE: 75 case SPITZ_LINE:
75 /* enable line jack, disable mic bias and mute hp */ 76 /* enable line jack, disable mic bias and mute hp */
76 snd_soc_dapm_disable_pin(codec, "Headphone Jack"); 77 snd_soc_dapm_disable_pin(dapm, "Headphone Jack");
77 snd_soc_dapm_disable_pin(codec, "Headset Jack"); 78 snd_soc_dapm_disable_pin(dapm, "Headset Jack");
78 snd_soc_dapm_disable_pin(codec, "Mic Jack"); 79 snd_soc_dapm_disable_pin(dapm, "Mic Jack");
79 snd_soc_dapm_enable_pin(codec, "Line Jack"); 80 snd_soc_dapm_enable_pin(dapm, "Line Jack");
80 gpio_set_value(SPITZ_GPIO_MUTE_L, 0); 81 gpio_set_value(SPITZ_GPIO_MUTE_L, 0);
81 gpio_set_value(SPITZ_GPIO_MUTE_R, 0); 82 gpio_set_value(SPITZ_GPIO_MUTE_R, 0);
82 break; 83 break;
83 case SPITZ_HEADSET: 84 case SPITZ_HEADSET:
84 /* enable and unmute headset jack enable mic bias, mute L hp */ 85 /* enable and unmute headset jack enable mic bias, mute L hp */
85 snd_soc_dapm_disable_pin(codec, "Headphone Jack"); 86 snd_soc_dapm_disable_pin(dapm, "Headphone Jack");
86 snd_soc_dapm_enable_pin(codec, "Mic Jack"); 87 snd_soc_dapm_enable_pin(dapm, "Mic Jack");
87 snd_soc_dapm_disable_pin(codec, "Line Jack"); 88 snd_soc_dapm_disable_pin(dapm, "Line Jack");
88 snd_soc_dapm_enable_pin(codec, "Headset Jack"); 89 snd_soc_dapm_enable_pin(dapm, "Headset Jack");
89 gpio_set_value(SPITZ_GPIO_MUTE_L, 0); 90 gpio_set_value(SPITZ_GPIO_MUTE_L, 0);
90 gpio_set_value(SPITZ_GPIO_MUTE_R, 1); 91 gpio_set_value(SPITZ_GPIO_MUTE_R, 1);
91 break; 92 break;
92 case SPITZ_HP_OFF: 93 case SPITZ_HP_OFF:
93 94
94 /* jack removed, everything off */ 95 /* jack removed, everything off */
95 snd_soc_dapm_disable_pin(codec, "Headphone Jack"); 96 snd_soc_dapm_disable_pin(dapm, "Headphone Jack");
96 snd_soc_dapm_disable_pin(codec, "Headset Jack"); 97 snd_soc_dapm_disable_pin(dapm, "Headset Jack");
97 snd_soc_dapm_disable_pin(codec, "Mic Jack"); 98 snd_soc_dapm_disable_pin(dapm, "Mic Jack");
98 snd_soc_dapm_disable_pin(codec, "Line Jack"); 99 snd_soc_dapm_disable_pin(dapm, "Line Jack");
99 gpio_set_value(SPITZ_GPIO_MUTE_L, 0); 100 gpio_set_value(SPITZ_GPIO_MUTE_L, 0);
100 gpio_set_value(SPITZ_GPIO_MUTE_R, 0); 101 gpio_set_value(SPITZ_GPIO_MUTE_R, 0);
101 break; 102 break;
102 } 103 }
103 snd_soc_dapm_sync(codec); 104 snd_soc_dapm_sync(dapm);
104} 105}
105 106
106static int spitz_startup(struct snd_pcm_substream *substream) 107static int spitz_startup(struct snd_pcm_substream *substream)
@@ -281,16 +282,17 @@ static const struct snd_kcontrol_new wm8750_spitz_controls[] = {
281static int spitz_wm8750_init(struct snd_soc_pcm_runtime *rtd) 282static int spitz_wm8750_init(struct snd_soc_pcm_runtime *rtd)
282{ 283{
283 struct snd_soc_codec *codec = rtd->codec; 284 struct snd_soc_codec *codec = rtd->codec;
285 struct snd_soc_dapm_context *dapm = &codec->dapm;
284 int err; 286 int err;
285 287
286 /* NC codec pins */ 288 /* NC codec pins */
287 snd_soc_dapm_nc_pin(codec, "RINPUT1"); 289 snd_soc_dapm_nc_pin(dapm, "RINPUT1");
288 snd_soc_dapm_nc_pin(codec, "LINPUT2"); 290 snd_soc_dapm_nc_pin(dapm, "LINPUT2");
289 snd_soc_dapm_nc_pin(codec, "RINPUT2"); 291 snd_soc_dapm_nc_pin(dapm, "RINPUT2");
290 snd_soc_dapm_nc_pin(codec, "LINPUT3"); 292 snd_soc_dapm_nc_pin(dapm, "LINPUT3");
291 snd_soc_dapm_nc_pin(codec, "RINPUT3"); 293 snd_soc_dapm_nc_pin(dapm, "RINPUT3");
292 snd_soc_dapm_nc_pin(codec, "OUT3"); 294 snd_soc_dapm_nc_pin(dapm, "OUT3");
293 snd_soc_dapm_nc_pin(codec, "MONO1"); 295 snd_soc_dapm_nc_pin(dapm, "MONO1");
294 296
295 /* Add spitz specific controls */ 297 /* Add spitz specific controls */
296 err = snd_soc_add_controls(codec, wm8750_spitz_controls, 298 err = snd_soc_add_controls(codec, wm8750_spitz_controls,
@@ -299,13 +301,13 @@ static int spitz_wm8750_init(struct snd_soc_pcm_runtime *rtd)
299 return err; 301 return err;
300 302
301 /* Add spitz specific widgets */ 303 /* Add spitz specific widgets */
302 snd_soc_dapm_new_controls(codec, wm8750_dapm_widgets, 304 snd_soc_dapm_new_controls(dapm, wm8750_dapm_widgets,
303 ARRAY_SIZE(wm8750_dapm_widgets)); 305 ARRAY_SIZE(wm8750_dapm_widgets));
304 306
305 /* Set up spitz specific audio paths */ 307 /* Set up spitz specific audio paths */
306 snd_soc_dapm_add_routes(codec, audio_map, ARRAY_SIZE(audio_map)); 308 snd_soc_dapm_add_routes(dapm, audio_map, ARRAY_SIZE(audio_map));
307 309
308 snd_soc_dapm_sync(codec); 310 snd_soc_dapm_sync(dapm);
309 return 0; 311 return 0;
310} 312}
311 313
diff --git a/sound/soc/pxa/tavorevb3.c b/sound/soc/pxa/tavorevb3.c
index 248c283fc4df..f881f65ec172 100644
--- a/sound/soc/pxa/tavorevb3.c
+++ b/sound/soc/pxa/tavorevb3.c
@@ -18,7 +18,6 @@
18#include <sound/pcm.h> 18#include <sound/pcm.h>
19#include <sound/pcm_params.h> 19#include <sound/pcm_params.h>
20#include <sound/soc.h> 20#include <sound/soc.h>
21#include <sound/soc-dapm.h>
22#include <sound/jack.h> 21#include <sound/jack.h>
23 22
24#include <asm/mach-types.h> 23#include <asm/mach-types.h>
@@ -133,20 +132,21 @@ static struct snd_soc_card snd_soc_card_evb3 = {
133static int evb3_pm860x_init(struct snd_soc_pcm_runtime *rtd) 132static int evb3_pm860x_init(struct snd_soc_pcm_runtime *rtd)
134{ 133{
135 struct snd_soc_codec *codec = rtd->codec; 134 struct snd_soc_codec *codec = rtd->codec;
135 struct snd_soc_dapm_context *dapm = &codec->dapm;
136 int ret; 136 int ret;
137 137
138 snd_soc_dapm_new_controls(codec, evb3_dapm_widgets, 138 snd_soc_dapm_new_controls(dapm, evb3_dapm_widgets,
139 ARRAY_SIZE(evb3_dapm_widgets)); 139 ARRAY_SIZE(evb3_dapm_widgets));
140 snd_soc_dapm_add_routes(codec, audio_map, ARRAY_SIZE(audio_map)); 140 snd_soc_dapm_add_routes(dapm, audio_map, ARRAY_SIZE(audio_map));
141 141
142 /* connected pins */ 142 /* connected pins */
143 snd_soc_dapm_enable_pin(codec, "Ext Speaker"); 143 snd_soc_dapm_enable_pin(dapm, "Ext Speaker");
144 snd_soc_dapm_enable_pin(codec, "Ext Mic 1"); 144 snd_soc_dapm_enable_pin(dapm, "Ext Mic 1");
145 snd_soc_dapm_enable_pin(codec, "Ext Mic 3"); 145 snd_soc_dapm_enable_pin(dapm, "Ext Mic 3");
146 snd_soc_dapm_disable_pin(codec, "Headset Mic 2"); 146 snd_soc_dapm_disable_pin(dapm, "Headset Mic 2");
147 snd_soc_dapm_disable_pin(codec, "Headset Stereophone"); 147 snd_soc_dapm_disable_pin(dapm, "Headset Stereophone");
148 148
149 ret = snd_soc_dapm_sync(codec); 149 ret = snd_soc_dapm_sync(dapm);
150 if (ret) 150 if (ret)
151 return ret; 151 return ret;
152 152
diff --git a/sound/soc/pxa/tosa.c b/sound/soc/pxa/tosa.c
index 7b983f935454..f75804ef0897 100644
--- a/sound/soc/pxa/tosa.c
+++ b/sound/soc/pxa/tosa.c
@@ -26,7 +26,6 @@
26#include <sound/core.h> 26#include <sound/core.h>
27#include <sound/pcm.h> 27#include <sound/pcm.h>
28#include <sound/soc.h> 28#include <sound/soc.h>
29#include <sound/soc-dapm.h>
30 29
31#include <asm/mach-types.h> 30#include <asm/mach-types.h>
32#include <mach/tosa.h> 31#include <mach/tosa.h>
@@ -49,31 +48,33 @@ static int tosa_spk_func;
49 48
50static void tosa_ext_control(struct snd_soc_codec *codec) 49static void tosa_ext_control(struct snd_soc_codec *codec)
51{ 50{
51 struct snd_soc_dapm_context *dapm = &codec->dapm;
52
52 /* set up jack connection */ 53 /* set up jack connection */
53 switch (tosa_jack_func) { 54 switch (tosa_jack_func) {
54 case TOSA_HP: 55 case TOSA_HP:
55 snd_soc_dapm_disable_pin(codec, "Mic (Internal)"); 56 snd_soc_dapm_disable_pin(dapm, "Mic (Internal)");
56 snd_soc_dapm_enable_pin(codec, "Headphone Jack"); 57 snd_soc_dapm_enable_pin(dapm, "Headphone Jack");
57 snd_soc_dapm_disable_pin(codec, "Headset Jack"); 58 snd_soc_dapm_disable_pin(dapm, "Headset Jack");
58 break; 59 break;
59 case TOSA_MIC_INT: 60 case TOSA_MIC_INT:
60 snd_soc_dapm_enable_pin(codec, "Mic (Internal)"); 61 snd_soc_dapm_enable_pin(dapm, "Mic (Internal)");
61 snd_soc_dapm_disable_pin(codec, "Headphone Jack"); 62 snd_soc_dapm_disable_pin(dapm, "Headphone Jack");
62 snd_soc_dapm_disable_pin(codec, "Headset Jack"); 63 snd_soc_dapm_disable_pin(dapm, "Headset Jack");
63 break; 64 break;
64 case TOSA_HEADSET: 65 case TOSA_HEADSET:
65 snd_soc_dapm_disable_pin(codec, "Mic (Internal)"); 66 snd_soc_dapm_disable_pin(dapm, "Mic (Internal)");
66 snd_soc_dapm_disable_pin(codec, "Headphone Jack"); 67 snd_soc_dapm_disable_pin(dapm, "Headphone Jack");
67 snd_soc_dapm_enable_pin(codec, "Headset Jack"); 68 snd_soc_dapm_enable_pin(dapm, "Headset Jack");
68 break; 69 break;
69 } 70 }
70 71
71 if (tosa_spk_func == TOSA_SPK_ON) 72 if (tosa_spk_func == TOSA_SPK_ON)
72 snd_soc_dapm_enable_pin(codec, "Speaker"); 73 snd_soc_dapm_enable_pin(dapm, "Speaker");
73 else 74 else
74 snd_soc_dapm_disable_pin(codec, "Speaker"); 75 snd_soc_dapm_disable_pin(dapm, "Speaker");
75 76
76 snd_soc_dapm_sync(codec); 77 snd_soc_dapm_sync(dapm);
77} 78}
78 79
79static int tosa_startup(struct snd_pcm_substream *substream) 80static int tosa_startup(struct snd_pcm_substream *substream)
@@ -191,10 +192,11 @@ static const struct snd_kcontrol_new tosa_controls[] = {
191static int tosa_ac97_init(struct snd_soc_pcm_runtime *rtd) 192static int tosa_ac97_init(struct snd_soc_pcm_runtime *rtd)
192{ 193{
193 struct snd_soc_codec *codec = rtd->codec; 194 struct snd_soc_codec *codec = rtd->codec;
195 struct snd_soc_dapm_context *dapm = &codec->dapm;
194 int err; 196 int err;
195 197
196 snd_soc_dapm_nc_pin(codec, "OUT3"); 198 snd_soc_dapm_nc_pin(dapm, "OUT3");
197 snd_soc_dapm_nc_pin(codec, "MONOOUT"); 199 snd_soc_dapm_nc_pin(dapm, "MONOOUT");
198 200
199 /* add tosa specific controls */ 201 /* add tosa specific controls */
200 err = snd_soc_add_controls(codec, tosa_controls, 202 err = snd_soc_add_controls(codec, tosa_controls,
@@ -203,13 +205,13 @@ static int tosa_ac97_init(struct snd_soc_pcm_runtime *rtd)
203 return err; 205 return err;
204 206
205 /* add tosa specific widgets */ 207 /* add tosa specific widgets */
206 snd_soc_dapm_new_controls(codec, tosa_dapm_widgets, 208 snd_soc_dapm_new_controls(dapm, tosa_dapm_widgets,
207 ARRAY_SIZE(tosa_dapm_widgets)); 209 ARRAY_SIZE(tosa_dapm_widgets));
208 210
209 /* set up tosa specific audio path audio_map */ 211 /* set up tosa specific audio path audio_map */
210 snd_soc_dapm_add_routes(codec, audio_map, ARRAY_SIZE(audio_map)); 212 snd_soc_dapm_add_routes(dapm, audio_map, ARRAY_SIZE(audio_map));
211 213
212 snd_soc_dapm_sync(codec); 214 snd_soc_dapm_sync(dapm);
213 return 0; 215 return 0;
214} 216}
215 217
diff --git a/sound/soc/pxa/z2.c b/sound/soc/pxa/z2.c
index 4cc841b44182..2d4f896d7fec 100644
--- a/sound/soc/pxa/z2.c
+++ b/sound/soc/pxa/z2.c
@@ -21,7 +21,6 @@
21#include <sound/core.h> 21#include <sound/core.h>
22#include <sound/pcm.h> 22#include <sound/pcm.h>
23#include <sound/soc.h> 23#include <sound/soc.h>
24#include <sound/soc-dapm.h>
25#include <sound/jack.h> 24#include <sound/jack.h>
26 25
27#include <asm/mach-types.h> 26#include <asm/mach-types.h>
@@ -140,22 +139,23 @@ static const struct snd_soc_dapm_route audio_map[] = {
140static int z2_wm8750_init(struct snd_soc_pcm_runtime *rtd) 139static int z2_wm8750_init(struct snd_soc_pcm_runtime *rtd)
141{ 140{
142 struct snd_soc_codec *codec = rtd->codec; 141 struct snd_soc_codec *codec = rtd->codec;
142 struct snd_soc_dapm_context *dapm = &codec->dapm;
143 int ret; 143 int ret;
144 144
145 /* NC codec pins */ 145 /* NC codec pins */
146 snd_soc_dapm_disable_pin(codec, "LINPUT3"); 146 snd_soc_dapm_disable_pin(dapm, "LINPUT3");
147 snd_soc_dapm_disable_pin(codec, "RINPUT3"); 147 snd_soc_dapm_disable_pin(dapm, "RINPUT3");
148 snd_soc_dapm_disable_pin(codec, "OUT3"); 148 snd_soc_dapm_disable_pin(dapm, "OUT3");
149 snd_soc_dapm_disable_pin(codec, "MONO"); 149 snd_soc_dapm_disable_pin(dapm, "MONO");
150 150
151 /* Add z2 specific widgets */ 151 /* Add z2 specific widgets */
152 snd_soc_dapm_new_controls(codec, wm8750_dapm_widgets, 152 snd_soc_dapm_new_controls(dapm, wm8750_dapm_widgets,
153 ARRAY_SIZE(wm8750_dapm_widgets)); 153 ARRAY_SIZE(wm8750_dapm_widgets));
154 154
155 /* Set up z2 specific audio paths */ 155 /* Set up z2 specific audio paths */
156 snd_soc_dapm_add_routes(codec, audio_map, ARRAY_SIZE(audio_map)); 156 snd_soc_dapm_add_routes(dapm, audio_map, ARRAY_SIZE(audio_map));
157 157
158 ret = snd_soc_dapm_sync(codec); 158 ret = snd_soc_dapm_sync(dapm);
159 if (ret) 159 if (ret)
160 goto err; 160 goto err;
161 161
diff --git a/sound/soc/pxa/zylonite.c b/sound/soc/pxa/zylonite.c
index d27e05af7759..b222a7d72027 100644
--- a/sound/soc/pxa/zylonite.c
+++ b/sound/soc/pxa/zylonite.c
@@ -20,7 +20,6 @@
20#include <sound/pcm.h> 20#include <sound/pcm.h>
21#include <sound/pcm_params.h> 21#include <sound/pcm_params.h>
22#include <sound/soc.h> 22#include <sound/soc.h>
23#include <sound/soc-dapm.h>
24 23
25#include "../codecs/wm9713.h" 24#include "../codecs/wm9713.h"
26#include "pxa2xx-ac97.h" 25#include "pxa2xx-ac97.h"
@@ -73,21 +72,22 @@ static const struct snd_soc_dapm_route audio_map[] = {
73static int zylonite_wm9713_init(struct snd_soc_pcm_runtime *rtd) 72static int zylonite_wm9713_init(struct snd_soc_pcm_runtime *rtd)
74{ 73{
75 struct snd_soc_codec *codec = rtd->codec; 74 struct snd_soc_codec *codec = rtd->codec;
75 struct snd_soc_dapm_context *dapm = &codec->dapm;
76 76
77 if (clk_pout) 77 if (clk_pout)
78 snd_soc_dai_set_pll(rtd->codec_dai, 0, 0, 78 snd_soc_dai_set_pll(rtd->codec_dai, 0, 0,
79 clk_get_rate(pout), 0); 79 clk_get_rate(pout), 0);
80 80
81 snd_soc_dapm_new_controls(codec, zylonite_dapm_widgets, 81 snd_soc_dapm_new_controls(dapm, zylonite_dapm_widgets,
82 ARRAY_SIZE(zylonite_dapm_widgets)); 82 ARRAY_SIZE(zylonite_dapm_widgets));
83 83
84 snd_soc_dapm_add_routes(codec, audio_map, ARRAY_SIZE(audio_map)); 84 snd_soc_dapm_add_routes(dapm, audio_map, ARRAY_SIZE(audio_map));
85 85
86 /* Static setup for now */ 86 /* Static setup for now */
87 snd_soc_dapm_enable_pin(codec, "Headphone"); 87 snd_soc_dapm_enable_pin(dapm, "Headphone");
88 snd_soc_dapm_enable_pin(codec, "Headset Earpiece"); 88 snd_soc_dapm_enable_pin(dapm, "Headset Earpiece");
89 89
90 snd_soc_dapm_sync(codec); 90 snd_soc_dapm_sync(dapm);
91 return 0; 91 return 0;
92} 92}
93 93
diff --git a/sound/soc/s3c24xx/Kconfig b/sound/soc/s3c24xx/Kconfig
deleted file mode 100644
index d85bf8a0abb2..000000000000
--- a/sound/soc/s3c24xx/Kconfig
+++ /dev/null
@@ -1,171 +0,0 @@
1config SND_S3C24XX_SOC
2 tristate "SoC Audio for the Samsung S3CXXXX chips"
3 depends on ARCH_S3C2410 || ARCH_S3C64XX || ARCH_S5PC100 || ARCH_S5PV210
4 select S3C64XX_DMA if ARCH_S3C64XX
5 select S3C2410_DMA if ARCH_S3C2410
6 help
7 Say Y or M if you want to add support for codecs attached to
8 the S3C24XX AC97 or I2S interfaces. You will also need to
9 select the audio interfaces to support below.
10
11config SND_S3C24XX_SOC_I2S
12 tristate
13 select S3C2410_DMA
14
15config SND_S3C_I2SV2_SOC
16 tristate
17
18config SND_S3C2412_SOC_I2S
19 tristate
20 select SND_S3C_I2SV2_SOC
21 select S3C2410_DMA
22
23config SND_S3C64XX_SOC_I2S
24 tristate
25 select SND_S3C_I2SV2_SOC
26 select S3C64XX_DMA
27
28config SND_S3C64XX_SOC_I2S_V4
29 tristate
30 select SND_S3C_I2SV2_SOC
31 select S3C64XX_DMA
32
33config SND_S3C_SOC_PCM
34 tristate
35
36config SND_S3C_SOC_AC97
37 tristate
38 select SND_SOC_AC97_BUS
39
40config SND_S5P_SOC_SPDIF
41 tristate
42 select SND_SOC_SPDIF
43
44config SND_S3C24XX_SOC_NEO1973_WM8753
45 tristate "SoC I2S Audio support for NEO1973 - WM8753"
46 depends on SND_S3C24XX_SOC && MACH_NEO1973_GTA01
47 select SND_S3C24XX_SOC_I2S
48 select SND_SOC_WM8753
49 help
50 Say Y if you want to add support for SoC audio on smdk2440
51 with the WM8753.
52
53config SND_S3C24XX_SOC_NEO1973_GTA02_WM8753
54 tristate "Audio support for the Openmoko Neo FreeRunner (GTA02)"
55 depends on SND_S3C24XX_SOC && MACH_NEO1973_GTA02
56 select SND_S3C24XX_SOC_I2S
57 select SND_SOC_WM8753
58 help
59 This driver provides audio support for the Openmoko Neo FreeRunner
60 smartphone.
61
62config SND_S3C24XX_SOC_JIVE_WM8750
63 tristate "SoC I2S Audio support for Jive"
64 depends on SND_S3C24XX_SOC && MACH_JIVE
65 select SND_SOC_WM8750
66 select SND_S3C2412_SOC_I2S
67 help
68 Sat Y if you want to add support for SoC audio on the Jive.
69
70config SND_S3C64XX_SOC_WM8580
71 tristate "SoC I2S Audio support for WM8580 on SMDK64XX"
72 depends on SND_S3C24XX_SOC && MACH_SMDK6410
73 select SND_SOC_WM8580
74 select SND_S3C64XX_SOC_I2S_V4
75 help
76 Say Y if you want to add support for SoC audio on the SMDK6410.
77
78config SND_S3C24XX_SOC_SMDK2443_WM9710
79 tristate "SoC AC97 Audio support for SMDK2443 - WM9710"
80 depends on SND_S3C24XX_SOC && MACH_SMDK2443
81 select S3C2410_DMA
82 select AC97_BUS
83 select SND_SOC_AC97_CODEC
84 select SND_S3C_SOC_AC97
85 help
86 Say Y if you want to add support for SoC audio on smdk2443
87 with the WM9710.
88
89config SND_S3C24XX_SOC_LN2440SBC_ALC650
90 tristate "SoC AC97 Audio support for LN2440SBC - ALC650"
91 depends on SND_S3C24XX_SOC && ARCH_S3C2410
92 select S3C2410_DMA
93 select AC97_BUS
94 select SND_SOC_AC97_CODEC
95 select SND_S3C_SOC_AC97
96 help
97 Say Y if you want to add support for SoC audio on ln2440sbc
98 with the ALC650.
99
100config SND_S3C24XX_SOC_S3C24XX_UDA134X
101 tristate "SoC I2S Audio support UDA134X wired to a S3C24XX"
102 depends on SND_S3C24XX_SOC && ARCH_S3C2410
103 select SND_S3C24XX_SOC_I2S
104 select SND_SOC_L3
105 select SND_SOC_UDA134X
106
107config SND_S3C24XX_SOC_SIMTEC
108 tristate
109 help
110 Internal node for common S3C24XX/Simtec suppor
111
112config SND_S3C24XX_SOC_SIMTEC_TLV320AIC23
113 tristate "SoC I2S Audio support for TLV320AIC23 on Simtec boards"
114 depends on SND_S3C24XX_SOC && ARCH_S3C2410
115 select SND_S3C24XX_SOC_I2S
116 select SND_SOC_TLV320AIC23
117 select SND_S3C24XX_SOC_SIMTEC
118
119config SND_S3C24XX_SOC_SIMTEC_HERMES
120 tristate "SoC I2S Audio support for Simtec Hermes board"
121 depends on SND_S3C24XX_SOC && ARCH_S3C2410
122 select SND_S3C24XX_SOC_I2S
123 select SND_SOC_TLV320AIC3X
124 select SND_S3C24XX_SOC_SIMTEC
125
126config SND_S3C24XX_SOC_RX1950_UDA1380
127 tristate "Audio support for the HP iPAQ RX1950"
128 depends on SND_S3C24XX_SOC && MACH_RX1950
129 select SND_S3C24XX_SOC_I2S
130 select SND_SOC_UDA1380
131 help
132 This driver provides audio support for HP iPAQ RX1950 PDA.
133
134config SND_SOC_SMDK_WM9713
135 tristate "SoC AC97 Audio support for SMDK with WM9713"
136 depends on SND_S3C24XX_SOC && (MACH_SMDK6410 || MACH_SMDKC100 || MACH_SMDKV210 || MACH_SMDKC110)
137 select SND_SOC_WM9713
138 select SND_S3C_SOC_AC97
139 help
140 Sat Y if you want to add support for SoC audio on the SMDK.
141
142config SND_S3C64XX_SOC_SMARTQ
143 tristate "SoC I2S Audio support for SmartQ board"
144 depends on SND_S3C24XX_SOC && MACH_SMARTQ
145 select SND_S3C64XX_SOC_I2S
146 select SND_SOC_WM8750
147
148config SND_S5PC110_SOC_AQUILA_WM8994
149 tristate "SoC I2S Audio support for AQUILA - WM8994"
150 depends on SND_S3C24XX_SOC && MACH_AQUILA
151 select SND_S3C64XX_SOC_I2S_V4
152 select SND_SOC_WM8994
153 help
154 Say Y if you want to add support for SoC audio on aquila
155 with the WM8994.
156
157config SND_S5PV210_SOC_GONI_WM8994
158 tristate "SoC I2S Audio support for GONI - WM8994"
159 depends on SND_S3C24XX_SOC && MACH_GONI
160 select SND_S3C64XX_SOC_I2S_V4
161 select SND_SOC_WM8994
162 help
163 Say Y if you want to add support for SoC audio on goni
164 with the WM8994.
165
166config SND_SOC_SMDK_SPDIF
167 tristate "SoC S/PDIF Audio support for SMDK"
168 depends on SND_S3C24XX_SOC && (MACH_SMDKC100 || MACH_SMDKC110 || MACH_SMDKV210)
169 select SND_S5P_SOC_SPDIF
170 help
171 Say Y if you want to add support for SoC S/PDIF audio on the SMDK.
diff --git a/sound/soc/s3c24xx/Makefile b/sound/soc/s3c24xx/Makefile
deleted file mode 100644
index ee8f41d6df99..000000000000
--- a/sound/soc/s3c24xx/Makefile
+++ /dev/null
@@ -1,55 +0,0 @@
1# S3c24XX Platform Support
2snd-soc-s3c24xx-objs := s3c-dma.o
3snd-soc-s3c24xx-i2s-objs := s3c24xx-i2s.o
4snd-soc-s3c2412-i2s-objs := s3c2412-i2s.o
5snd-soc-s3c64xx-i2s-objs := s3c64xx-i2s.o
6snd-soc-s3c-ac97-objs := s3c-ac97.o
7snd-soc-s3c64xx-i2s-v4-objs := s3c64xx-i2s-v4.o
8snd-soc-s3c-i2s-v2-objs := s3c-i2s-v2.o
9snd-soc-s3c-pcm-objs := s3c-pcm.o
10snd-soc-samsung-spdif-objs := spdif.o
11
12obj-$(CONFIG_SND_S3C24XX_SOC) += snd-soc-s3c24xx.o
13obj-$(CONFIG_SND_S3C24XX_SOC_I2S) += snd-soc-s3c24xx-i2s.o
14obj-$(CONFIG_SND_S3C_SOC_AC97) += snd-soc-s3c-ac97.o
15obj-$(CONFIG_SND_S3C2412_SOC_I2S) += snd-soc-s3c2412-i2s.o
16obj-$(CONFIG_SND_S3C64XX_SOC_I2S) += snd-soc-s3c64xx-i2s.o
17obj-$(CONFIG_SND_S3C64XX_SOC_I2S_V4) += snd-soc-s3c64xx-i2s-v4.o
18obj-$(CONFIG_SND_S3C_I2SV2_SOC) += snd-soc-s3c-i2s-v2.o
19obj-$(CONFIG_SND_S3C_SOC_PCM) += snd-soc-s3c-pcm.o
20obj-$(CONFIG_SND_S5P_SOC_SPDIF) += snd-soc-samsung-spdif.o
21
22# S3C24XX Machine Support
23snd-soc-jive-wm8750-objs := jive_wm8750.o
24snd-soc-neo1973-wm8753-objs := neo1973_wm8753.o
25snd-soc-neo1973-gta02-wm8753-objs := neo1973_gta02_wm8753.o
26snd-soc-smdk2443-wm9710-objs := smdk2443_wm9710.o
27snd-soc-ln2440sbc-alc650-objs := ln2440sbc_alc650.o
28snd-soc-s3c24xx-uda134x-objs := s3c24xx_uda134x.o
29snd-soc-s3c24xx-simtec-objs := s3c24xx_simtec.o
30snd-soc-s3c24xx-simtec-hermes-objs := s3c24xx_simtec_hermes.o
31snd-soc-s3c24xx-simtec-tlv320aic23-objs := s3c24xx_simtec_tlv320aic23.o
32snd-soc-rx1950-uda1380-objs := rx1950_uda1380.o
33snd-soc-smdk64xx-wm8580-objs := smdk64xx_wm8580.o
34snd-soc-smdk-wm9713-objs := smdk_wm9713.o
35snd-soc-s3c64xx-smartq-wm8987-objs := smartq_wm8987.o
36snd-soc-aquila-wm8994-objs := aquila_wm8994.o
37snd-soc-goni-wm8994-objs := goni_wm8994.o
38snd-soc-smdk-spdif-objs := smdk_spdif.o
39
40obj-$(CONFIG_SND_S3C24XX_SOC_JIVE_WM8750) += snd-soc-jive-wm8750.o
41obj-$(CONFIG_SND_S3C24XX_SOC_NEO1973_WM8753) += snd-soc-neo1973-wm8753.o
42obj-$(CONFIG_SND_S3C24XX_SOC_NEO1973_GTA02_WM8753) += snd-soc-neo1973-gta02-wm8753.o
43obj-$(CONFIG_SND_S3C24XX_SOC_SMDK2443_WM9710) += snd-soc-smdk2443-wm9710.o
44obj-$(CONFIG_SND_S3C24XX_SOC_LN2440SBC_ALC650) += snd-soc-ln2440sbc-alc650.o
45obj-$(CONFIG_SND_S3C24XX_SOC_S3C24XX_UDA134X) += snd-soc-s3c24xx-uda134x.o
46obj-$(CONFIG_SND_S3C24XX_SOC_SIMTEC) += snd-soc-s3c24xx-simtec.o
47obj-$(CONFIG_SND_S3C24XX_SOC_SIMTEC_HERMES) += snd-soc-s3c24xx-simtec-hermes.o
48obj-$(CONFIG_SND_S3C24XX_SOC_SIMTEC_TLV320AIC23) += snd-soc-s3c24xx-simtec-tlv320aic23.o
49obj-$(CONFIG_SND_S3C24XX_SOC_RX1950_UDA1380) += snd-soc-rx1950-uda1380.o
50obj-$(CONFIG_SND_S3C64XX_SOC_WM8580) += snd-soc-smdk64xx-wm8580.o
51obj-$(CONFIG_SND_SOC_SMDK_WM9713) += snd-soc-smdk-wm9713.o
52obj-$(CONFIG_SND_S3C64XX_SOC_SMARTQ) += snd-soc-s3c64xx-smartq-wm8987.o
53obj-$(CONFIG_SND_S5PC110_SOC_AQUILA_WM8994) += snd-soc-aquila-wm8994.o
54obj-$(CONFIG_SND_S5PV210_SOC_GONI_WM8994) += snd-soc-goni-wm8994.o
55obj-$(CONFIG_SND_SOC_SMDK_SPDIF) += snd-soc-smdk-spdif.o
diff --git a/sound/soc/s3c24xx/aquila_wm8994.c b/sound/soc/s3c24xx/aquila_wm8994.c
deleted file mode 100644
index 235d1973f7d0..000000000000
--- a/sound/soc/s3c24xx/aquila_wm8994.c
+++ /dev/null
@@ -1,295 +0,0 @@
1/*
2 * aquila_wm8994.c
3 *
4 * Copyright (C) 2010 Samsung Electronics Co.Ltd
5 * Author: Chanwoo Choi <cw00.choi@samsung.com>
6 *
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation; either version 2 of the License, or (at your
10 * option) any later version.
11 *
12 */
13
14#include <linux/module.h>
15#include <linux/moduleparam.h>
16#include <linux/io.h>
17#include <linux/platform_device.h>
18#include <sound/soc.h>
19#include <sound/soc-dapm.h>
20#include <sound/jack.h>
21#include <asm/mach-types.h>
22#include <mach/gpio.h>
23#include <mach/regs-clock.h>
24
25#include <linux/mfd/wm8994/core.h>
26#include <linux/mfd/wm8994/registers.h>
27#include "../codecs/wm8994.h"
28#include "s3c-dma.h"
29#include "s3c64xx-i2s.h"
30
31static struct snd_soc_card aquila;
32static struct platform_device *aquila_snd_device;
33
34/* 3.5 pie jack */
35static struct snd_soc_jack jack;
36
37/* 3.5 pie jack detection DAPM pins */
38static struct snd_soc_jack_pin jack_pins[] = {
39 {
40 .pin = "Headset Mic",
41 .mask = SND_JACK_MICROPHONE,
42 }, {
43 .pin = "Headset Stereophone",
44 .mask = SND_JACK_HEADPHONE | SND_JACK_MECHANICAL |
45 SND_JACK_AVOUT,
46 },
47};
48
49/* 3.5 pie jack detection gpios */
50static struct snd_soc_jack_gpio jack_gpios[] = {
51 {
52 .gpio = S5PV210_GPH0(6),
53 .name = "DET_3.5",
54 .report = SND_JACK_HEADSET | SND_JACK_MECHANICAL |
55 SND_JACK_AVOUT,
56 .debounce_time = 200,
57 },
58};
59
60static const struct snd_soc_dapm_widget aquila_dapm_widgets[] = {
61 SND_SOC_DAPM_SPK("Ext Spk", NULL),
62 SND_SOC_DAPM_SPK("Ext Rcv", NULL),
63 SND_SOC_DAPM_HP("Headset Stereophone", NULL),
64 SND_SOC_DAPM_MIC("Headset Mic", NULL),
65 SND_SOC_DAPM_MIC("Main Mic", NULL),
66 SND_SOC_DAPM_MIC("2nd Mic", NULL),
67 SND_SOC_DAPM_LINE("Radio In", NULL),
68};
69
70static const struct snd_soc_dapm_route aquila_dapm_routes[] = {
71 {"Ext Spk", NULL, "SPKOUTLP"},
72 {"Ext Spk", NULL, "SPKOUTLN"},
73
74 {"Ext Rcv", NULL, "HPOUT2N"},
75 {"Ext Rcv", NULL, "HPOUT2P"},
76
77 {"Headset Stereophone", NULL, "HPOUT1L"},
78 {"Headset Stereophone", NULL, "HPOUT1R"},
79
80 {"IN1RN", NULL, "Headset Mic"},
81 {"IN1RP", NULL, "Headset Mic"},
82
83 {"IN1RN", NULL, "2nd Mic"},
84 {"IN1RP", NULL, "2nd Mic"},
85
86 {"IN1LN", NULL, "Main Mic"},
87 {"IN1LP", NULL, "Main Mic"},
88
89 {"IN2LN", NULL, "Radio In"},
90 {"IN2RN", NULL, "Radio In"},
91};
92
93static int aquila_wm8994_init(struct snd_soc_pcm_runtime *rtd)
94{
95 struct snd_soc_codec *codec = rtd->codec;
96 int ret;
97
98 /* add aquila specific widgets */
99 snd_soc_dapm_new_controls(codec, aquila_dapm_widgets,
100 ARRAY_SIZE(aquila_dapm_widgets));
101
102 /* set up aquila specific audio routes */
103 snd_soc_dapm_add_routes(codec, aquila_dapm_routes,
104 ARRAY_SIZE(aquila_dapm_routes));
105
106 /* set endpoints to not connected */
107 snd_soc_dapm_nc_pin(codec, "IN2LP:VXRN");
108 snd_soc_dapm_nc_pin(codec, "IN2RP:VXRP");
109 snd_soc_dapm_nc_pin(codec, "LINEOUT1N");
110 snd_soc_dapm_nc_pin(codec, "LINEOUT1P");
111 snd_soc_dapm_nc_pin(codec, "LINEOUT2N");
112 snd_soc_dapm_nc_pin(codec, "LINEOUT2P");
113 snd_soc_dapm_nc_pin(codec, "SPKOUTRN");
114 snd_soc_dapm_nc_pin(codec, "SPKOUTRP");
115
116 snd_soc_dapm_sync(codec);
117
118 /* Headset jack detection */
119 ret = snd_soc_jack_new(&aquila, "Headset Jack",
120 SND_JACK_HEADSET | SND_JACK_MECHANICAL | SND_JACK_AVOUT,
121 &jack);
122 if (ret)
123 return ret;
124
125 ret = snd_soc_jack_add_pins(&jack, ARRAY_SIZE(jack_pins), jack_pins);
126 if (ret)
127 return ret;
128
129 ret = snd_soc_jack_add_gpios(&jack, ARRAY_SIZE(jack_gpios), jack_gpios);
130 if (ret)
131 return ret;
132
133 return 0;
134}
135
136static int aquila_hifi_hw_params(struct snd_pcm_substream *substream,
137 struct snd_pcm_hw_params *params)
138{
139 struct snd_soc_pcm_runtime *rtd = substream->private_data;
140 struct snd_soc_dai *codec_dai = rtd->codec_dai;
141 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
142 unsigned int pll_out = 24000000;
143 int ret = 0;
144
145 /* set the cpu DAI configuration */
146 ret = snd_soc_dai_set_fmt(cpu_dai, SND_SOC_DAIFMT_I2S |
147 SND_SOC_DAIFMT_NB_NF | SND_SOC_DAIFMT_CBM_CFM);
148 if (ret < 0)
149 return ret;
150
151 /* set the cpu system clock */
152 ret = snd_soc_dai_set_sysclk(cpu_dai, S3C64XX_CLKSRC_PCLK,
153 0, SND_SOC_CLOCK_IN);
154 if (ret < 0)
155 return ret;
156
157 /* set codec DAI configuration */
158 ret = snd_soc_dai_set_fmt(codec_dai, SND_SOC_DAIFMT_I2S |
159 SND_SOC_DAIFMT_NB_NF | SND_SOC_DAIFMT_CBM_CFM);
160 if (ret < 0)
161 return ret;
162
163 /* set the codec FLL */
164 ret = snd_soc_dai_set_pll(codec_dai, WM8994_FLL1, 0, pll_out,
165 params_rate(params) * 256);
166 if (ret < 0)
167 return ret;
168
169 /* set the codec system clock */
170 ret = snd_soc_dai_set_sysclk(codec_dai, WM8994_SYSCLK_FLL1,
171 params_rate(params) * 256, SND_SOC_CLOCK_IN);
172 if (ret < 0)
173 return ret;
174
175 return 0;
176}
177
178static struct snd_soc_ops aquila_hifi_ops = {
179 .hw_params = aquila_hifi_hw_params,
180};
181
182static int aquila_voice_hw_params(struct snd_pcm_substream *substream,
183 struct snd_pcm_hw_params *params)
184{
185 struct snd_soc_pcm_runtime *rtd = substream->private_data;
186 struct snd_soc_dai *codec_dai = rtd->codec_dai;
187 unsigned int pll_out = 24000000;
188 int ret = 0;
189
190 if (params_rate(params) != 8000)
191 return -EINVAL;
192
193 /* set codec DAI configuration */
194 ret = snd_soc_dai_set_fmt(codec_dai, SND_SOC_DAIFMT_LEFT_J |
195 SND_SOC_DAIFMT_IB_IF | SND_SOC_DAIFMT_CBM_CFM);
196 if (ret < 0)
197 return ret;
198
199 /* set the codec FLL */
200 ret = snd_soc_dai_set_pll(codec_dai, WM8994_FLL2, 0, pll_out,
201 params_rate(params) * 256);
202 if (ret < 0)
203 return ret;
204
205 /* set the codec system clock */
206 ret = snd_soc_dai_set_sysclk(codec_dai, WM8994_SYSCLK_FLL2,
207 params_rate(params) * 256, SND_SOC_CLOCK_IN);
208 if (ret < 0)
209 return ret;
210
211 return 0;
212}
213
214static struct snd_soc_dai_driver voice_dai = {
215 .name = "aquila-voice-dai",
216 .playback = {
217 .channels_min = 1,
218 .channels_max = 2,
219 .rates = SNDRV_PCM_RATE_8000,
220 .formats = SNDRV_PCM_FMTBIT_S16_LE,},
221 .capture = {
222 .channels_min = 1,
223 .channels_max = 2,
224 .rates = SNDRV_PCM_RATE_8000,
225 .formats = SNDRV_PCM_FMTBIT_S16_LE,},
226};
227
228static struct snd_soc_ops aquila_voice_ops = {
229 .hw_params = aquila_voice_hw_params,
230};
231
232static struct snd_soc_dai_link aquila_dai[] = {
233{
234 .name = "WM8994",
235 .stream_name = "WM8994 HiFi",
236 .cpu_dai_name = "s3c64xx-i2s-v4",
237 .codec_dai_name = "wm8994-hifi",
238 .platform_name = "s3c24xx-pcm-audio",
239 .codec_name = "wm8994-codec.0-0x1a",
240 .init = aquila_wm8994_init,
241 .ops = &aquila_hifi_ops,
242}, {
243 .name = "WM8994 Voice",
244 .stream_name = "Voice",
245 .cpu_dai_name = "aquila-voice-dai",
246 .codec_dai_name = "wm8994-voice",
247 .platform_name = "s3c24xx-pcm-audio",
248 .codec_name = "wm8994-codec.0-0x1a",
249 .ops = &aquila_voice_ops,
250},
251};
252
253static struct snd_soc_card aquila = {
254 .name = "aquila",
255 .dai_link = aquila_dai,
256 .num_links = ARRAY_SIZE(aquila_dai),
257};
258
259static int __init aquila_init(void)
260{
261 int ret;
262
263 if (!machine_is_aquila())
264 return -ENODEV;
265
266 aquila_snd_device = platform_device_alloc("soc-audio", -1);
267 if (!aquila_snd_device)
268 return -ENOMEM;
269
270 /* register voice DAI here */
271 ret = snd_soc_register_dai(&aquila_snd_device->dev, &voice_dai);
272 if (ret)
273 return ret;
274
275 platform_set_drvdata(aquila_snd_device, &aquila);
276 ret = platform_device_add(aquila_snd_device);
277
278 if (ret)
279 platform_device_put(aquila_snd_device);
280
281 return ret;
282}
283
284static void __exit aquila_exit(void)
285{
286 platform_device_unregister(aquila_snd_device);
287}
288
289module_init(aquila_init);
290module_exit(aquila_exit);
291
292/* Module information */
293MODULE_DESCRIPTION("ALSA SoC WM8994 Aquila(S5PC110)");
294MODULE_AUTHOR("Chanwoo Choi <cw00.choi@samsung.com>");
295MODULE_LICENSE("GPL");
diff --git a/sound/soc/s3c24xx/s3c64xx-i2s-v4.c b/sound/soc/s3c24xx/s3c64xx-i2s-v4.c
deleted file mode 100644
index a9628472ebfe..000000000000
--- a/sound/soc/s3c24xx/s3c64xx-i2s-v4.c
+++ /dev/null
@@ -1,230 +0,0 @@
1/* sound/soc/s3c24xx/s3c64xx-i2s-v4.c
2 *
3 * ALSA SoC Audio Layer - S3C64XX I2Sv4 driver
4 * Copyright (c) 2010 Samsung Electronics Co. Ltd
5 * Author: Jaswinder Singh <jassi.brar@samsung.com>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
10 */
11
12#include <linux/clk.h>
13#include <linux/gpio.h>
14#include <linux/io.h>
15
16#include <sound/soc.h>
17#include <sound/pcm_params.h>
18
19#include <plat/audio.h>
20
21#include <mach/map.h>
22#include <mach/dma.h>
23
24#include "s3c-dma.h"
25#include "regs-i2s-v2.h"
26#include "s3c64xx-i2s.h"
27
28static struct s3c2410_dma_client s3c64xx_dma_client_out = {
29 .name = "I2Sv4 PCM Stereo out"
30};
31
32static struct s3c2410_dma_client s3c64xx_dma_client_in = {
33 .name = "I2Sv4 PCM Stereo in"
34};
35
36static struct s3c_dma_params s3c64xx_i2sv4_pcm_stereo_out;
37static struct s3c_dma_params s3c64xx_i2sv4_pcm_stereo_in;
38static struct s3c_i2sv2_info s3c64xx_i2sv4;
39
40static int s3c64xx_i2sv4_probe(struct snd_soc_dai *dai)
41{
42 struct s3c_i2sv2_info *i2s = &s3c64xx_i2sv4;
43 int ret = 0;
44
45 snd_soc_dai_set_drvdata(dai, i2s);
46
47 ret = s3c_i2sv2_probe(dai, i2s, i2s->base);
48
49 return ret;
50}
51
52static int s3c_i2sv4_hw_params(struct snd_pcm_substream *substream,
53 struct snd_pcm_hw_params *params,
54 struct snd_soc_dai *cpu_dai)
55{
56 struct s3c_i2sv2_info *i2s = snd_soc_dai_get_drvdata(cpu_dai);
57 struct s3c_dma_params *dma_data;
58 u32 iismod;
59
60 dev_dbg(cpu_dai->dev, "Entered %s\n", __func__);
61
62 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
63 dma_data = i2s->dma_playback;
64 else
65 dma_data = i2s->dma_capture;
66
67 snd_soc_dai_set_dma_data(cpu_dai, substream, dma_data);
68
69 iismod = readl(i2s->regs + S3C2412_IISMOD);
70 dev_dbg(cpu_dai->dev, "%s: r: IISMOD: %x\n", __func__, iismod);
71
72 iismod &= ~S3C64XX_IISMOD_BLC_MASK;
73 switch (params_format(params)) {
74 case SNDRV_PCM_FORMAT_S8:
75 iismod |= S3C64XX_IISMOD_BLC_8BIT;
76 break;
77 case SNDRV_PCM_FORMAT_S16_LE:
78 break;
79 case SNDRV_PCM_FORMAT_S24_LE:
80 iismod |= S3C64XX_IISMOD_BLC_24BIT;
81 break;
82 }
83
84 writel(iismod, i2s->regs + S3C2412_IISMOD);
85 dev_dbg(cpu_dai->dev, "%s: w: IISMOD: %x\n", __func__, iismod);
86
87 return 0;
88}
89
90static struct snd_soc_dai_ops s3c64xx_i2sv4_dai_ops = {
91 .hw_params = s3c_i2sv4_hw_params,
92};
93
94static struct snd_soc_dai_driver s3c64xx_i2s_v4_dai = {
95 .symmetric_rates = 1,
96 .playback = {
97 .channels_min = 2,
98 .channels_max = 2,
99 .rates = S3C64XX_I2S_RATES,
100 .formats = S3C64XX_I2S_FMTS,
101 },
102 .capture = {
103 .channels_min = 2,
104 .channels_max = 2,
105 .rates = S3C64XX_I2S_RATES,
106 .formats = S3C64XX_I2S_FMTS,
107 },
108 .probe = s3c64xx_i2sv4_probe,
109 .ops = &s3c64xx_i2sv4_dai_ops,
110};
111
112static __devinit int s3c64xx_i2sv4_dev_probe(struct platform_device *pdev)
113{
114 struct s3c_audio_pdata *i2s_pdata;
115 struct s3c_i2sv2_info *i2s;
116 struct resource *res;
117 int ret;
118
119 i2s = &s3c64xx_i2sv4;
120
121 i2s->feature |= S3C_FEATURE_CDCLKCON;
122
123 i2s->dma_capture = &s3c64xx_i2sv4_pcm_stereo_in;
124 i2s->dma_playback = &s3c64xx_i2sv4_pcm_stereo_out;
125
126 res = platform_get_resource(pdev, IORESOURCE_DMA, 0);
127 if (!res) {
128 dev_err(&pdev->dev, "Unable to get I2S-TX dma resource\n");
129 return -ENXIO;
130 }
131 i2s->dma_playback->channel = res->start;
132
133 res = platform_get_resource(pdev, IORESOURCE_DMA, 1);
134 if (!res) {
135 dev_err(&pdev->dev, "Unable to get I2S-RX dma resource\n");
136 return -ENXIO;
137 }
138 i2s->dma_capture->channel = res->start;
139
140 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
141 if (!res) {
142 dev_err(&pdev->dev, "Unable to get I2S SFR address\n");
143 return -ENXIO;
144 }
145
146 if (!request_mem_region(res->start, resource_size(res),
147 "s3c64xx-i2s-v4")) {
148 dev_err(&pdev->dev, "Unable to request SFR region\n");
149 return -EBUSY;
150 }
151 i2s->dma_capture->dma_addr = res->start + S3C2412_IISRXD;
152 i2s->dma_playback->dma_addr = res->start + S3C2412_IISTXD;
153
154 i2s->dma_capture->client = &s3c64xx_dma_client_in;
155 i2s->dma_capture->dma_size = 4;
156 i2s->dma_playback->client = &s3c64xx_dma_client_out;
157 i2s->dma_playback->dma_size = 4;
158
159 i2s->base = res->start;
160
161 i2s_pdata = pdev->dev.platform_data;
162 if (i2s_pdata && i2s_pdata->cfg_gpio && i2s_pdata->cfg_gpio(pdev)) {
163 dev_err(&pdev->dev, "Unable to configure gpio\n");
164 return -EINVAL;
165 }
166
167 i2s->iis_cclk = clk_get(&pdev->dev, "audio-bus");
168 if (IS_ERR(i2s->iis_cclk)) {
169 dev_err(&pdev->dev, "failed to get audio-bus\n");
170 ret = PTR_ERR(i2s->iis_cclk);
171 goto err;
172 }
173
174 clk_enable(i2s->iis_cclk);
175
176 ret = s3c_i2sv2_register_dai(&pdev->dev, pdev->id, &s3c64xx_i2s_v4_dai);
177 if (ret != 0)
178 goto err_i2sv2;
179
180 return 0;
181
182err_i2sv2:
183 clk_put(i2s->iis_cclk);
184err:
185 return ret;
186}
187
188static __devexit int s3c64xx_i2sv4_dev_remove(struct platform_device *pdev)
189{
190 struct s3c_i2sv2_info *i2s = &s3c64xx_i2sv4;
191 struct resource *res;
192
193 snd_soc_unregister_dai(&pdev->dev);
194 clk_put(i2s->iis_cclk);
195
196 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
197 if (res)
198 release_mem_region(res->start, resource_size(res));
199 else
200 dev_warn(&pdev->dev, "Unable to get I2S SFR address\n");
201
202 return 0;
203}
204
205static struct platform_driver s3c64xx_i2sv4_driver = {
206 .probe = s3c64xx_i2sv4_dev_probe,
207 .remove = s3c64xx_i2sv4_dev_remove,
208 .driver = {
209 .name = "s3c64xx-iis-v4",
210 .owner = THIS_MODULE,
211 },
212};
213
214static int __init s3c64xx_i2sv4_init(void)
215{
216 return platform_driver_register(&s3c64xx_i2sv4_driver);
217}
218module_init(s3c64xx_i2sv4_init);
219
220static void __exit s3c64xx_i2sv4_exit(void)
221{
222 platform_driver_unregister(&s3c64xx_i2sv4_driver);
223}
224module_exit(s3c64xx_i2sv4_exit);
225
226/* Module information */
227MODULE_AUTHOR("Jaswinder Singh, <jassi.brar@samsung.com>");
228MODULE_DESCRIPTION("S3C64XX I2Sv4 SoC Interface");
229MODULE_LICENSE("GPL");
230MODULE_ALIAS("platform:s3c64xx-iis-v4");
diff --git a/sound/soc/s3c24xx/s3c64xx-i2s.c b/sound/soc/s3c24xx/s3c64xx-i2s.c
deleted file mode 100644
index ae7acb6c4f1d..000000000000
--- a/sound/soc/s3c24xx/s3c64xx-i2s.c
+++ /dev/null
@@ -1,242 +0,0 @@
1/* sound/soc/s3c24xx/s3c64xx-i2s.c
2 *
3 * ALSA SoC Audio Layer - S3C64XX I2S driver
4 *
5 * Copyright 2008 Openmoko, Inc.
6 * Copyright 2008 Simtec Electronics
7 * Ben Dooks <ben@simtec.co.uk>
8 * http://armlinux.simtec.co.uk/
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License version 2 as
12 * published by the Free Software Foundation.
13 */
14
15#include <linux/module.h>
16#include <linux/clk.h>
17#include <linux/gpio.h>
18#include <linux/io.h>
19#include <linux/slab.h>
20
21#include <sound/soc.h>
22
23#include <plat/audio.h>
24
25#include <mach/map.h>
26#include <mach/dma.h>
27
28#include "s3c-dma.h"
29#include "regs-i2s-v2.h"
30#include "s3c64xx-i2s.h"
31
32/* The value should be set to maximum of the total number
33 * of I2Sv3 controllers that any supported SoC has.
34 */
35#define MAX_I2SV3 2
36
37static struct s3c2410_dma_client s3c64xx_dma_client_out = {
38 .name = "I2S PCM Stereo out"
39};
40
41static struct s3c2410_dma_client s3c64xx_dma_client_in = {
42 .name = "I2S PCM Stereo in"
43};
44
45static struct s3c_dma_params s3c64xx_i2s_pcm_stereo_out[MAX_I2SV3];
46static struct s3c_dma_params s3c64xx_i2s_pcm_stereo_in[MAX_I2SV3];
47static struct s3c_i2sv2_info s3c64xx_i2s[MAX_I2SV3];
48
49struct clk *s3c64xx_i2s_get_clock(struct snd_soc_dai *dai)
50{
51 struct s3c_i2sv2_info *i2s = snd_soc_dai_get_drvdata(dai);
52 u32 iismod = readl(i2s->regs + S3C2412_IISMOD);
53
54 if (iismod & S3C2412_IISMOD_IMS_SYSMUX)
55 return i2s->iis_cclk;
56 else
57 return i2s->iis_pclk;
58}
59EXPORT_SYMBOL_GPL(s3c64xx_i2s_get_clock);
60
61static int s3c64xx_i2s_probe(struct snd_soc_dai *dai)
62{
63 struct s3c_i2sv2_info *i2s;
64 int ret;
65
66 if (dai->id >= MAX_I2SV3) {
67 dev_err(dai->dev, "id %d out of range\n", dai->id);
68 return -EINVAL;
69 }
70
71 i2s = &s3c64xx_i2s[dai->id];
72 snd_soc_dai_set_drvdata(dai, i2s);
73
74 i2s->iis_cclk = clk_get(dai->dev, "audio-bus");
75 if (IS_ERR(i2s->iis_cclk)) {
76 dev_err(dai->dev, "failed to get audio-bus\n");
77 ret = PTR_ERR(i2s->iis_cclk);
78 goto err;
79 }
80
81 clk_enable(i2s->iis_cclk);
82
83 ret = s3c_i2sv2_probe(dai, i2s, i2s->base);
84 if (ret)
85 goto err_clk;
86
87 return 0;
88
89err_clk:
90 clk_disable(i2s->iis_cclk);
91 clk_put(i2s->iis_cclk);
92err:
93 kfree(i2s);
94 return ret;
95}
96
97static int s3c64xx_i2s_remove(struct snd_soc_dai *dai)
98{
99 struct s3c_i2sv2_info *i2s = snd_soc_dai_get_drvdata(dai);
100
101 clk_disable(i2s->iis_cclk);
102 clk_put(i2s->iis_cclk);
103 kfree(i2s);
104 return 0;
105}
106
107static struct snd_soc_dai_ops s3c64xx_i2s_dai_ops;
108
109static struct snd_soc_dai_driver s3c64xx_i2s_dai[MAX_I2SV3] = {
110{
111 .name = "s3c64xx-i2s-0",
112 .probe = s3c64xx_i2s_probe,
113 .remove = s3c64xx_i2s_remove,
114 .playback = {
115 .channels_min = 2,
116 .channels_max = 2,
117 .rates = S3C64XX_I2S_RATES,
118 .formats = S3C64XX_I2S_FMTS,},
119 .capture = {
120 .channels_min = 2,
121 .channels_max = 2,
122 .rates = S3C64XX_I2S_RATES,
123 .formats = S3C64XX_I2S_FMTS,},
124 .ops = &s3c64xx_i2s_dai_ops,
125 .symmetric_rates = 1,
126}, {
127 .name = "s3c64xx-i2s-1",
128 .probe = s3c64xx_i2s_probe,
129 .remove = s3c64xx_i2s_remove,
130 .playback = {
131 .channels_min = 2,
132 .channels_max = 2,
133 .rates = S3C64XX_I2S_RATES,
134 .formats = S3C64XX_I2S_FMTS,},
135 .capture = {
136 .channels_min = 2,
137 .channels_max = 2,
138 .rates = S3C64XX_I2S_RATES,
139 .formats = S3C64XX_I2S_FMTS,},
140 .ops = &s3c64xx_i2s_dai_ops,
141 .symmetric_rates = 1,
142},};
143
144static __devinit int s3c64xx_iis_dev_probe(struct platform_device *pdev)
145{
146 struct s3c_audio_pdata *i2s_pdata;
147 struct s3c_i2sv2_info *i2s;
148 struct resource *res;
149 int i, ret;
150
151 if (pdev->id >= MAX_I2SV3) {
152 dev_err(&pdev->dev, "id %d out of range\n", pdev->id);
153 return -EINVAL;
154 }
155
156 i2s = &s3c64xx_i2s[pdev->id];
157
158 i2s->dma_capture = &s3c64xx_i2s_pcm_stereo_in[pdev->id];
159 i2s->dma_playback = &s3c64xx_i2s_pcm_stereo_out[pdev->id];
160
161 res = platform_get_resource(pdev, IORESOURCE_DMA, 0);
162 if (!res) {
163 dev_err(&pdev->dev, "Unable to get I2S-TX dma resource\n");
164 return -ENXIO;
165 }
166 i2s->dma_playback->channel = res->start;
167
168 res = platform_get_resource(pdev, IORESOURCE_DMA, 1);
169 if (!res) {
170 dev_err(&pdev->dev, "Unable to get I2S-RX dma resource\n");
171 return -ENXIO;
172 }
173 i2s->dma_capture->channel = res->start;
174
175 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
176 if (!res) {
177 dev_err(&pdev->dev, "Unable to get I2S SFR address\n");
178 return -ENXIO;
179 }
180
181 if (!request_mem_region(res->start, resource_size(res),
182 "s3c64xx-i2s")) {
183 dev_err(&pdev->dev, "Unable to request SFR region\n");
184 return -EBUSY;
185 }
186 i2s->base = res->start;
187
188 i2s_pdata = pdev->dev.platform_data;
189 if (i2s_pdata && i2s_pdata->cfg_gpio && i2s_pdata->cfg_gpio(pdev)) {
190 dev_err(&pdev->dev, "Unable to configure gpio\n");
191 return -EINVAL;
192 }
193 i2s->dma_capture->dma_addr = res->start + S3C2412_IISRXD;
194 i2s->dma_playback->dma_addr = res->start + S3C2412_IISTXD;
195
196 i2s->dma_capture->client = &s3c64xx_dma_client_in;
197 i2s->dma_capture->dma_size = 4;
198 i2s->dma_playback->client = &s3c64xx_dma_client_out;
199 i2s->dma_playback->dma_size = 4;
200
201 for (i = 0; i < ARRAY_SIZE(s3c64xx_i2s_dai); i++) {
202 ret = s3c_i2sv2_register_dai(&pdev->dev, i,
203 &s3c64xx_i2s_dai[i]);
204 if (ret != 0)
205 return ret;
206 }
207
208 return 0;
209}
210
211static __devexit int s3c64xx_iis_dev_remove(struct platform_device *pdev)
212{
213 snd_soc_unregister_dais(&pdev->dev, ARRAY_SIZE(s3c64xx_i2s_dai));
214 return 0;
215}
216
217static struct platform_driver s3c64xx_iis_driver = {
218 .probe = s3c64xx_iis_dev_probe,
219 .remove = s3c64xx_iis_dev_remove,
220 .driver = {
221 .name = "s3c64xx-iis",
222 .owner = THIS_MODULE,
223 },
224};
225
226static int __init s3c64xx_i2s_init(void)
227{
228 return platform_driver_register(&s3c64xx_iis_driver);
229}
230module_init(s3c64xx_i2s_init);
231
232static void __exit s3c64xx_i2s_exit(void)
233{
234 platform_driver_unregister(&s3c64xx_iis_driver);
235}
236module_exit(s3c64xx_i2s_exit);
237
238/* Module information */
239MODULE_AUTHOR("Ben Dooks, <ben@simtec.co.uk>");
240MODULE_DESCRIPTION("S3C64XX I2S SoC Interface");
241MODULE_LICENSE("GPL");
242MODULE_ALIAS("platform:s3c64xx-iis");
diff --git a/sound/soc/s3c24xx/s3c64xx-i2s.h b/sound/soc/s3c24xx/s3c64xx-i2s.h
deleted file mode 100644
index de4075d26f0c..000000000000
--- a/sound/soc/s3c24xx/s3c64xx-i2s.h
+++ /dev/null
@@ -1,41 +0,0 @@
1/* sound/soc/s3c24xx/s3c64xx-i2s.h
2 *
3 * ALSA SoC Audio Layer - S3C64XX I2S driver
4 *
5 * Copyright 2008 Openmoko, Inc.
6 * Copyright 2008 Simtec Electronics
7 * Ben Dooks <ben@simtec.co.uk>
8 * http://armlinux.simtec.co.uk/
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License version 2 as
12 * published by the Free Software Foundation.
13 */
14
15#ifndef __SND_SOC_S3C24XX_S3C64XX_I2S_H
16#define __SND_SOC_S3C24XX_S3C64XX_I2S_H __FILE__
17
18struct clk;
19
20#include "s3c-i2s-v2.h"
21
22#define S3C64XX_DIV_BCLK S3C_I2SV2_DIV_BCLK
23#define S3C64XX_DIV_RCLK S3C_I2SV2_DIV_RCLK
24#define S3C64XX_DIV_PRESCALER S3C_I2SV2_DIV_PRESCALER
25
26#define S3C64XX_CLKSRC_PCLK S3C_I2SV2_CLKSRC_PCLK
27#define S3C64XX_CLKSRC_MUX S3C_I2SV2_CLKSRC_AUDIOBUS
28#define S3C64XX_CLKSRC_CDCLK S3C_I2SV2_CLKSRC_CDCLK
29
30#define S3C64XX_I2S_RATES \
31 (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_11025 | SNDRV_PCM_RATE_16000 | \
32 SNDRV_PCM_RATE_22050 | SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_44100 | \
33 SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_88200 | SNDRV_PCM_RATE_96000)
34
35#define S3C64XX_I2S_FMTS \
36 (SNDRV_PCM_FMTBIT_S8 | SNDRV_PCM_FMTBIT_S16_LE |\
37 SNDRV_PCM_FMTBIT_S24_LE)
38
39struct clk *s3c64xx_i2s_get_clock(struct snd_soc_dai *dai);
40
41#endif /* __SND_SOC_S3C24XX_S3C64XX_I2S_H */
diff --git a/sound/soc/s6000/s6105-ipcam.c b/sound/soc/s6000/s6105-ipcam.c
index c1244c5bc730..5890e431852f 100644
--- a/sound/soc/s6000/s6105-ipcam.c
+++ b/sound/soc/s6000/s6105-ipcam.c
@@ -18,11 +18,9 @@
18#include <sound/core.h> 18#include <sound/core.h>
19#include <sound/pcm.h> 19#include <sound/pcm.h>
20#include <sound/soc.h> 20#include <sound/soc.h>
21#include <sound/soc-dapm.h>
22 21
23#include <variant/dmac.h> 22#include <variant/dmac.h>
24 23
25#include "../codecs/tlv320aic3x.h"
26#include "s6000-pcm.h" 24#include "s6000-pcm.h"
27#include "s6000-i2s.h" 25#include "s6000-i2s.h"
28 26
@@ -107,6 +105,7 @@ static int output_type_put(struct snd_kcontrol *kcontrol,
107 struct snd_ctl_elem_value *ucontrol) 105 struct snd_ctl_elem_value *ucontrol)
108{ 106{
109 struct snd_soc_codec *codec = kcontrol->private_data; 107 struct snd_soc_codec *codec = kcontrol->private_data;
108 struct snd_soc_dapm_context *dapm = &codec->dapm;
110 unsigned int val = (ucontrol->value.enumerated.item[0] != 0); 109 unsigned int val = (ucontrol->value.enumerated.item[0] != 0);
111 char *differential = "Audio Out Differential"; 110 char *differential = "Audio Out Differential";
112 char *stereo = "Audio Out Stereo"; 111 char *stereo = "Audio Out Stereo";
@@ -114,10 +113,10 @@ static int output_type_put(struct snd_kcontrol *kcontrol,
114 if (kcontrol->private_value == val) 113 if (kcontrol->private_value == val)
115 return 0; 114 return 0;
116 kcontrol->private_value = val; 115 kcontrol->private_value = val;
117 snd_soc_dapm_disable_pin(codec, val ? differential : stereo); 116 snd_soc_dapm_disable_pin(dapm, val ? differential : stereo);
118 snd_soc_dapm_sync(codec); 117 snd_soc_dapm_sync(dapm);
119 snd_soc_dapm_enable_pin(codec, val ? stereo : differential); 118 snd_soc_dapm_enable_pin(dapm, val ? stereo : differential);
120 snd_soc_dapm_sync(codec); 119 snd_soc_dapm_sync(dapm);
121 120
122 return 1; 121 return 1;
123} 122}
@@ -137,35 +136,36 @@ static const struct snd_kcontrol_new audio_out_mux = {
137static int s6105_aic3x_init(struct snd_soc_pcm_runtime *rtd) 136static int s6105_aic3x_init(struct snd_soc_pcm_runtime *rtd)
138{ 137{
139 struct snd_soc_codec *codec = rtd->codec; 138 struct snd_soc_codec *codec = rtd->codec;
139 struct snd_soc_dapm_context *dapm = &codec->dapm;
140 140
141 /* Add s6105 specific widgets */ 141 /* Add s6105 specific widgets */
142 snd_soc_dapm_new_controls(codec, aic3x_dapm_widgets, 142 snd_soc_dapm_new_controls(dapm, aic3x_dapm_widgets,
143 ARRAY_SIZE(aic3x_dapm_widgets)); 143 ARRAY_SIZE(aic3x_dapm_widgets));
144 144
145 /* Set up s6105 specific audio path audio_map */ 145 /* Set up s6105 specific audio path audio_map */
146 snd_soc_dapm_add_routes(codec, audio_map, ARRAY_SIZE(audio_map)); 146 snd_soc_dapm_add_routes(dapm, audio_map, ARRAY_SIZE(audio_map));
147 147
148 /* not present */ 148 /* not present */
149 snd_soc_dapm_nc_pin(codec, "MONO_LOUT"); 149 snd_soc_dapm_nc_pin(dapm, "MONO_LOUT");
150 snd_soc_dapm_nc_pin(codec, "LINE2L"); 150 snd_soc_dapm_nc_pin(dapm, "LINE2L");
151 snd_soc_dapm_nc_pin(codec, "LINE2R"); 151 snd_soc_dapm_nc_pin(dapm, "LINE2R");
152 152
153 /* not connected */ 153 /* not connected */
154 snd_soc_dapm_nc_pin(codec, "MIC3L"); /* LINE2L on this chip */ 154 snd_soc_dapm_nc_pin(dapm, "MIC3L"); /* LINE2L on this chip */
155 snd_soc_dapm_nc_pin(codec, "MIC3R"); /* LINE2R on this chip */ 155 snd_soc_dapm_nc_pin(dapm, "MIC3R"); /* LINE2R on this chip */
156 snd_soc_dapm_nc_pin(codec, "LLOUT"); 156 snd_soc_dapm_nc_pin(dapm, "LLOUT");
157 snd_soc_dapm_nc_pin(codec, "RLOUT"); 157 snd_soc_dapm_nc_pin(dapm, "RLOUT");
158 snd_soc_dapm_nc_pin(codec, "HPRCOM"); 158 snd_soc_dapm_nc_pin(dapm, "HPRCOM");
159 159
160 /* always connected */ 160 /* always connected */
161 snd_soc_dapm_enable_pin(codec, "Audio In"); 161 snd_soc_dapm_enable_pin(dapm, "Audio In");
162 162
163 /* must correspond to audio_out_mux.private_value initializer */ 163 /* must correspond to audio_out_mux.private_value initializer */
164 snd_soc_dapm_disable_pin(codec, "Audio Out Differential"); 164 snd_soc_dapm_disable_pin(dapm, "Audio Out Differential");
165 snd_soc_dapm_sync(codec); 165 snd_soc_dapm_sync(dapm);
166 snd_soc_dapm_enable_pin(codec, "Audio Out Stereo"); 166 snd_soc_dapm_enable_pin(dapm, "Audio Out Stereo");
167 167
168 snd_soc_dapm_sync(codec); 168 snd_soc_dapm_sync(dapm);
169 169
170 snd_ctl_add(codec->card->snd_card, snd_ctl_new1(&audio_out_mux, codec)); 170 snd_ctl_add(codec->card->snd_card, snd_ctl_new1(&audio_out_mux, codec));
171 171
diff --git a/sound/soc/samsung/Kconfig b/sound/soc/samsung/Kconfig
new file mode 100644
index 000000000000..a6a6b5fa2f2f
--- /dev/null
+++ b/sound/soc/samsung/Kconfig
@@ -0,0 +1,171 @@
1config SND_SOC_SAMSUNG
2 tristate "ASoC support for Samsung"
3 depends on ARCH_S3C2410 || ARCH_S3C64XX || ARCH_S5PC100 || ARCH_S5PV210 || ARCH_S5P64X0 || ARCH_S5P6442 || ARCH_S5PV310
4 select S3C64XX_DMA if ARCH_S3C64XX
5 select S3C2410_DMA if ARCH_S3C2410
6 help
7 Say Y or M if you want to add support for codecs attached to
8 the Samsung SoCs' Audio interfaces. You will also need to
9 select the audio interfaces to support below.
10
11config SND_S3C24XX_I2S
12 tristate
13 select S3C2410_DMA
14
15config SND_S3C_I2SV2_SOC
16 tristate
17
18config SND_S3C2412_SOC_I2S
19 tristate
20 select SND_S3C_I2SV2_SOC
21 select S3C2410_DMA
22
23config SND_SAMSUNG_PCM
24 tristate
25
26config SND_SAMSUNG_AC97
27 tristate
28 select SND_SOC_AC97_BUS
29
30config SND_SAMSUNG_SPDIF
31 tristate
32 select SND_SOC_SPDIF
33
34config SND_SAMSUNG_I2S
35 tristate
36
37config SND_SOC_SAMSUNG_NEO1973_WM8753
38 tristate "SoC I2S Audio support for NEO1973 - WM8753"
39 depends on SND_SOC_SAMSUNG && MACH_NEO1973_GTA01
40 select SND_S3C24XX_I2S
41 select SND_SOC_WM8753
42 help
43 Say Y if you want to add support for SoC audio on smdk2440
44 with the WM8753.
45
46config SND_SOC_SAMSUNG_NEO1973_GTA02_WM8753
47 tristate "Audio support for the Openmoko Neo FreeRunner (GTA02)"
48 depends on SND_SOC_SAMSUNG && MACH_NEO1973_GTA02
49 select SND_S3C24XX_I2S
50 select SND_SOC_WM8753
51 help
52 This driver provides audio support for the Openmoko Neo FreeRunner
53 smartphone.
54
55config SND_SOC_SAMSUNG_JIVE_WM8750
56 tristate "SoC I2S Audio support for Jive"
57 depends on SND_SOC_SAMSUNG && MACH_JIVE
58 select SND_SOC_WM8750
59 select SND_S3C2412_SOC_I2S
60 help
61 Sat Y if you want to add support for SoC audio on the Jive.
62
63config SND_SOC_SAMSUNG_SMDK_WM8580
64 tristate "SoC I2S Audio support for WM8580 on SMDK"
65 depends on SND_SOC_SAMSUNG && (MACH_SMDK6410 || MACH_SMDKC100 || MACH_SMDK6440 || MACH_SMDK6450 || MACH_SMDK6442 || MACH_SMDKV210 || MACH_SMDKC110)
66 select SND_SOC_WM8580
67 select SND_SAMSUNG_I2S
68 help
69 Say Y if you want to add support for SoC audio on the SMDKs.
70
71config SND_SOC_SAMSUNG_SMDK_WM8994
72 tristate "SoC I2S Audio support for WM8994 on SMDK"
73 depends on SND_SOC_SAMSUNG && (MACH_SMDKV310 || MACH_SMDKC210)
74 select SND_SOC_WM8994
75 select SND_SAMSUNG_I2S
76 help
77 Say Y if you want to add support for SoC audio on the SMDKs.
78
79config SND_SOC_SAMSUNG_SMDK2443_WM9710
80 tristate "SoC AC97 Audio support for SMDK2443 - WM9710"
81 depends on SND_SOC_SAMSUNG && MACH_SMDK2443
82 select S3C2410_DMA
83 select AC97_BUS
84 select SND_SOC_AC97_CODEC
85 select SND_SAMSUNG_AC97
86 help
87 Say Y if you want to add support for SoC audio on smdk2443
88 with the WM9710.
89
90config SND_SOC_SAMSUNG_LN2440SBC_ALC650
91 tristate "SoC AC97 Audio support for LN2440SBC - ALC650"
92 depends on SND_SOC_SAMSUNG && ARCH_S3C2410
93 select S3C2410_DMA
94 select AC97_BUS
95 select SND_SOC_AC97_CODEC
96 select SND_SAMSUNG_AC97
97 help
98 Say Y if you want to add support for SoC audio on ln2440sbc
99 with the ALC650.
100
101config SND_SOC_SAMSUNG_S3C24XX_UDA134X
102 tristate "SoC I2S Audio support UDA134X wired to a S3C24XX"
103 depends on SND_SOC_SAMSUNG && ARCH_S3C2410
104 select SND_S3C24XX_I2S
105 select SND_SOC_L3
106 select SND_SOC_UDA134X
107
108config SND_SOC_SAMSUNG_SIMTEC
109 tristate
110 help
111 Internal node for common S3C24XX/Simtec suppor
112
113config SND_SOC_SAMSUNG_SIMTEC_TLV320AIC23
114 tristate "SoC I2S Audio support for TLV320AIC23 on Simtec boards"
115 depends on SND_SOC_SAMSUNG && ARCH_S3C2410
116 select SND_S3C24XX_I2S
117 select SND_SOC_TLV320AIC23
118 select SND_SOC_SAMSUNG_SIMTEC
119
120config SND_SOC_SAMSUNG_SIMTEC_HERMES
121 tristate "SoC I2S Audio support for Simtec Hermes board"
122 depends on SND_SOC_SAMSUNG && ARCH_S3C2410
123 select SND_S3C24XX_I2S
124 select SND_SOC_TLV320AIC3X
125 select SND_SOC_SAMSUNG_SIMTEC
126
127config SND_SOC_SAMSUNG_H1940_UDA1380
128 tristate "Audio support for the HP iPAQ H1940"
129 depends on SND_SOC_SAMSUNG && ARCH_H1940
130 select SND_S3C24XX_I2S
131 select SND_SOC_UDA1380
132 help
133 This driver provides audio support for HP iPAQ h1940 PDA.
134
135config SND_SOC_SAMSUNG_RX1950_UDA1380
136 tristate "Audio support for the HP iPAQ RX1950"
137 depends on SND_SOC_SAMSUNG && MACH_RX1950
138 select SND_S3C24XX_I2S
139 select SND_SOC_UDA1380
140 help
141 This driver provides audio support for HP iPAQ RX1950 PDA.
142
143config SND_SOC_SAMSUNG_SMDK_WM9713
144 tristate "SoC AC97 Audio support for SMDK with WM9713"
145 depends on SND_SOC_SAMSUNG && (MACH_SMDK6410 || MACH_SMDKC100 || MACH_SMDKV210 || MACH_SMDKC110 || MACH_SMDKV310 || MACH_SMDKC210)
146 select SND_SOC_WM9713
147 select SND_SAMSUNG_AC97
148 help
149 Sat Y if you want to add support for SoC audio on the SMDK.
150
151config SND_SOC_SMARTQ
152 tristate "SoC I2S Audio support for SmartQ board"
153 depends on SND_SOC_SAMSUNG && MACH_SMARTQ
154 select SND_SAMSUNG_I2S
155 select SND_SOC_WM8750
156
157config SND_SOC_GONI_AQUILA_WM8994
158 tristate "SoC I2S Audio support for AQUILA/GONI - WM8994"
159 depends on SND_SOC_SAMSUNG && (MACH_GONI || MACH_AQUILA)
160 select SND_SAMSUNG_I2S
161 select SND_SOC_WM8994
162 help
163 Say Y if you want to add support for SoC audio on goni or aquila
164 with the WM8994.
165
166config SND_SOC_SAMSUNG_SMDK_SPDIF
167 tristate "SoC S/PDIF Audio support for SMDK"
168 depends on SND_SOC_SAMSUNG && (MACH_SMDKC100 || MACH_SMDKC110 || MACH_SMDKV210)
169 select SND_SAMSUNG_SPDIF
170 help
171 Say Y if you want to add support for SoC S/PDIF audio on the SMDK.
diff --git a/sound/soc/samsung/Makefile b/sound/soc/samsung/Makefile
new file mode 100644
index 000000000000..705d4e8a6724
--- /dev/null
+++ b/sound/soc/samsung/Makefile
@@ -0,0 +1,55 @@
1# S3c24XX Platform Support
2snd-soc-s3c24xx-objs := dma.o
3snd-soc-s3c24xx-i2s-objs := s3c24xx-i2s.o
4snd-soc-s3c2412-i2s-objs := s3c2412-i2s.o
5snd-soc-ac97-objs := ac97.o
6snd-soc-s3c-i2s-v2-objs := s3c-i2s-v2.o
7snd-soc-samsung-spdif-objs := spdif.o
8snd-soc-pcm-objs := pcm.o
9snd-soc-i2s-objs := i2s.o
10
11obj-$(CONFIG_SND_SOC_SAMSUNG) += snd-soc-s3c24xx.o
12obj-$(CONFIG_SND_S3C24XX_I2S) += snd-soc-s3c24xx-i2s.o
13obj-$(CONFIG_SND_SAMSUNG_AC97) += snd-soc-ac97.o
14obj-$(CONFIG_SND_S3C2412_SOC_I2S) += snd-soc-s3c2412-i2s.o
15obj-$(CONFIG_SND_S3C_I2SV2_SOC) += snd-soc-s3c-i2s-v2.o
16obj-$(CONFIG_SND_SAMSUNG_SPDIF) += snd-soc-samsung-spdif.o
17obj-$(CONFIG_SND_SAMSUNG_PCM) += snd-soc-pcm.o
18obj-$(CONFIG_SND_SAMSUNG_I2S) += snd-soc-i2s.o
19
20# S3C24XX Machine Support
21snd-soc-jive-wm8750-objs := jive_wm8750.o
22snd-soc-neo1973-wm8753-objs := neo1973_wm8753.o
23snd-soc-neo1973-gta02-wm8753-objs := neo1973_gta02_wm8753.o
24snd-soc-smdk2443-wm9710-objs := smdk2443_wm9710.o
25snd-soc-ln2440sbc-alc650-objs := ln2440sbc_alc650.o
26snd-soc-s3c24xx-uda134x-objs := s3c24xx_uda134x.o
27snd-soc-s3c24xx-simtec-objs := s3c24xx_simtec.o
28snd-soc-s3c24xx-simtec-hermes-objs := s3c24xx_simtec_hermes.o
29snd-soc-s3c24xx-simtec-tlv320aic23-objs := s3c24xx_simtec_tlv320aic23.o
30snd-soc-h1940-uda1380-objs := h1940_uda1380.o
31snd-soc-rx1950-uda1380-objs := rx1950_uda1380.o
32snd-soc-smdk-wm8580-objs := smdk_wm8580.o
33snd-soc-smdk-wm8994-objs := smdk_wm8994.o
34snd-soc-smdk-wm9713-objs := smdk_wm9713.o
35snd-soc-s3c64xx-smartq-wm8987-objs := smartq_wm8987.o
36snd-soc-goni-wm8994-objs := goni_wm8994.o
37snd-soc-smdk-spdif-objs := smdk_spdif.o
38
39obj-$(CONFIG_SND_SOC_SAMSUNG_JIVE_WM8750) += snd-soc-jive-wm8750.o
40obj-$(CONFIG_SND_SOC_SAMSUNG_NEO1973_WM8753) += snd-soc-neo1973-wm8753.o
41obj-$(CONFIG_SND_SOC_SAMSUNG_NEO1973_GTA02_WM8753) += snd-soc-neo1973-gta02-wm8753.o
42obj-$(CONFIG_SND_SOC_SAMSUNG_SMDK2443_WM9710) += snd-soc-smdk2443-wm9710.o
43obj-$(CONFIG_SND_SOC_SAMSUNG_LN2440SBC_ALC650) += snd-soc-ln2440sbc-alc650.o
44obj-$(CONFIG_SND_SOC_SAMSUNG_S3C24XX_UDA134X) += snd-soc-s3c24xx-uda134x.o
45obj-$(CONFIG_SND_SOC_SAMSUNG_SIMTEC) += snd-soc-s3c24xx-simtec.o
46obj-$(CONFIG_SND_SOC_SAMSUNG_SIMTEC_HERMES) += snd-soc-s3c24xx-simtec-hermes.o
47obj-$(CONFIG_SND_SOC_SAMSUNG_SIMTEC_TLV320AIC23) += snd-soc-s3c24xx-simtec-tlv320aic23.o
48obj-$(CONFIG_SND_SOC_SAMSUNG_H1940_UDA1380) += snd-soc-h1940-uda1380.o
49obj-$(CONFIG_SND_SOC_SAMSUNG_RX1950_UDA1380) += snd-soc-rx1950-uda1380.o
50obj-$(CONFIG_SND_SOC_SAMSUNG_SMDK_WM8580) += snd-soc-smdk-wm8580.o
51obj-$(CONFIG_SND_SOC_SAMSUNG_SMDK_WM8994) += snd-soc-smdk-wm8994.o
52obj-$(CONFIG_SND_SOC_SAMSUNG_SMDK_WM9713) += snd-soc-smdk-wm9713.o
53obj-$(CONFIG_SND_SOC_SMARTQ) += snd-soc-s3c64xx-smartq-wm8987.o
54obj-$(CONFIG_SND_SOC_SAMSUNG_SMDK_SPDIF) += snd-soc-smdk-spdif.o
55obj-$(CONFIG_SND_SOC_GONI_AQUILA_WM8994) += snd-soc-goni-wm8994.o
diff --git a/sound/soc/s3c24xx/s3c-ac97.c b/sound/soc/samsung/ac97.c
index f891eb79b575..4770a9550341 100644
--- a/sound/soc/s3c24xx/s3c-ac97.c
+++ b/sound/soc/samsung/ac97.c
@@ -1,4 +1,4 @@
1/* sound/soc/s3c24xx/s3c-ac97.c 1/* sound/soc/samsung/ac97.c
2 * 2 *
3 * ALSA SoC Audio Layer - S3C AC97 Controller driver 3 * ALSA SoC Audio Layer - S3C AC97 Controller driver
4 * Evolved from s3c2443-ac97.c 4 * Evolved from s3c2443-ac97.c
@@ -24,8 +24,8 @@
24#include <mach/dma.h> 24#include <mach/dma.h>
25#include <plat/audio.h> 25#include <plat/audio.h>
26 26
27#include "s3c-dma.h" 27#include "dma.h"
28#include "s3c-ac97.h" 28#include "ac97.h"
29 29
30#define AC_CMD_ADDR(x) (x << 16) 30#define AC_CMD_ADDR(x) (x << 16)
31#define AC_CMD_DATA(x) (x & 0xffff) 31#define AC_CMD_DATA(x) (x & 0xffff)
@@ -122,7 +122,7 @@ static unsigned short s3c_ac97_read(struct snd_ac97 *ac97,
122 data = (stat & 0xffff); 122 data = (stat & 0xffff);
123 123
124 if (addr != reg) 124 if (addr != reg)
125 pr_err("s3c-ac97: req addr = %02x, rep addr = %02x\n", 125 pr_err("ac97: req addr = %02x, rep addr = %02x\n",
126 reg, addr); 126 reg, addr);
127 127
128 mutex_unlock(&s3c_ac97.lock); 128 mutex_unlock(&s3c_ac97.lock);
@@ -334,7 +334,7 @@ static struct snd_soc_dai_ops s3c_ac97_mic_dai_ops = {
334 334
335static struct snd_soc_dai_driver s3c_ac97_dai[] = { 335static struct snd_soc_dai_driver s3c_ac97_dai[] = {
336 [S3C_AC97_DAI_PCM] = { 336 [S3C_AC97_DAI_PCM] = {
337 .name = "s3c-ac97", 337 .name = "samsung-ac97",
338 .ac97_control = 1, 338 .ac97_control = 1,
339 .playback = { 339 .playback = {
340 .stream_name = "AC97 Playback", 340 .stream_name = "AC97 Playback",
@@ -351,7 +351,7 @@ static struct snd_soc_dai_driver s3c_ac97_dai[] = {
351 .ops = &s3c_ac97_dai_ops, 351 .ops = &s3c_ac97_dai_ops,
352 }, 352 },
353 [S3C_AC97_DAI_MIC] = { 353 [S3C_AC97_DAI_MIC] = {
354 .name = "s3c-ac97-mic", 354 .name = "samsung-ac97-mic",
355 .ac97_control = 1, 355 .ac97_control = 1,
356 .capture = { 356 .capture = {
357 .stream_name = "AC97 Mic Capture", 357 .stream_name = "AC97 Mic Capture",
@@ -407,7 +407,7 @@ static __devinit int s3c_ac97_probe(struct platform_device *pdev)
407 } 407 }
408 408
409 if (!request_mem_region(mem_res->start, 409 if (!request_mem_region(mem_res->start,
410 resource_size(mem_res), "s3c-ac97")) { 410 resource_size(mem_res), "ac97")) {
411 dev_err(&pdev->dev, "Unable to request register region\n"); 411 dev_err(&pdev->dev, "Unable to request register region\n");
412 return -EBUSY; 412 return -EBUSY;
413 } 413 }
@@ -431,7 +431,7 @@ static __devinit int s3c_ac97_probe(struct platform_device *pdev)
431 431
432 s3c_ac97.ac97_clk = clk_get(&pdev->dev, "ac97"); 432 s3c_ac97.ac97_clk = clk_get(&pdev->dev, "ac97");
433 if (IS_ERR(s3c_ac97.ac97_clk)) { 433 if (IS_ERR(s3c_ac97.ac97_clk)) {
434 dev_err(&pdev->dev, "s3c-ac97 failed to get ac97_clock\n"); 434 dev_err(&pdev->dev, "ac97 failed to get ac97_clock\n");
435 ret = -ENODEV; 435 ret = -ENODEV;
436 goto err2; 436 goto err2;
437 } 437 }
@@ -446,7 +446,7 @@ static __devinit int s3c_ac97_probe(struct platform_device *pdev)
446 ret = request_irq(irq_res->start, s3c_ac97_irq, 446 ret = request_irq(irq_res->start, s3c_ac97_irq,
447 IRQF_DISABLED, "AC97", NULL); 447 IRQF_DISABLED, "AC97", NULL);
448 if (ret < 0) { 448 if (ret < 0) {
449 dev_err(&pdev->dev, "s3c-ac97: interrupt request failed.\n"); 449 dev_err(&pdev->dev, "ac97: interrupt request failed.\n");
450 goto err4; 450 goto err4;
451 } 451 }
452 452
@@ -497,7 +497,7 @@ static struct platform_driver s3c_ac97_driver = {
497 .probe = s3c_ac97_probe, 497 .probe = s3c_ac97_probe,
498 .remove = s3c_ac97_remove, 498 .remove = s3c_ac97_remove,
499 .driver = { 499 .driver = {
500 .name = "s3c-ac97", 500 .name = "samsung-ac97",
501 .owner = THIS_MODULE, 501 .owner = THIS_MODULE,
502 }, 502 },
503}; 503};
@@ -517,4 +517,4 @@ module_exit(s3c_ac97_exit);
517MODULE_AUTHOR("Jaswinder Singh, <jassi.brar@samsung.com>"); 517MODULE_AUTHOR("Jaswinder Singh, <jassi.brar@samsung.com>");
518MODULE_DESCRIPTION("AC97 driver for the Samsung SoC"); 518MODULE_DESCRIPTION("AC97 driver for the Samsung SoC");
519MODULE_LICENSE("GPL"); 519MODULE_LICENSE("GPL");
520MODULE_ALIAS("platform:s3c-ac97"); 520MODULE_ALIAS("platform:samsung-ac97");
diff --git a/sound/soc/s3c24xx/s3c-ac97.h b/sound/soc/samsung/ac97.h
index 5dcedd07fdbb..0d0e1b511457 100644
--- a/sound/soc/s3c24xx/s3c-ac97.h
+++ b/sound/soc/samsung/ac97.h
@@ -1,11 +1,11 @@
1/* sound/soc/s3c24xx/s3c-ac97.h 1/* sound/soc/samsung/ac97.h
2 * 2 *
3 * ALSA SoC Audio Layer - S3C AC97 Controller driver 3 * ALSA SoC Audio Layer - S3C AC97 Controller driver
4 * Evolved from s3c2443-ac97.h 4 * Evolved from s3c2443-ac97.h
5 * 5 *
6 * Copyright (c) 2010 Samsung Electronics Co. Ltd 6 * Copyright (c) 2010 Samsung Electronics Co. Ltd
7 * Author: Jaswinder Singh <jassi.brar@samsung.com> 7 * Author: Jaswinder Singh <jassi.brar@samsung.com>
8 * Credits: Graeme Gregory, Sean Choi 8 * Credits: Graeme Gregory, Sean Choi
9 * 9 *
10 * This program is free software; you can redistribute it and/or modify 10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License version 2 as 11 * it under the terms of the GNU General Public License version 2 as
diff --git a/sound/soc/s3c24xx/s3c-dma.c b/sound/soc/samsung/dma.c
index 243f79bf43bb..21240198c5d6 100644
--- a/sound/soc/s3c24xx/s3c-dma.c
+++ b/sound/soc/samsung/dma.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * s3c-dma.c -- ALSA Soc Audio Layer 2 * dma.c -- ALSA Soc Audio Layer
3 * 3 *
4 * (c) 2006 Wolfson Microelectronics PLC. 4 * (c) 2006 Wolfson Microelectronics PLC.
5 * Graeme Gregory graeme.gregory@wolfsonmicro.com or linux@wolfsonmicro.com 5 * Graeme Gregory graeme.gregory@wolfsonmicro.com or linux@wolfsonmicro.com
@@ -30,9 +30,9 @@
30#include <mach/hardware.h> 30#include <mach/hardware.h>
31#include <mach/dma.h> 31#include <mach/dma.h>
32 32
33#include "s3c-dma.h" 33#include "dma.h"
34 34
35static const struct snd_pcm_hardware s3c_dma_hardware = { 35static const struct snd_pcm_hardware dma_hardware = {
36 .info = SNDRV_PCM_INFO_INTERLEAVED | 36 .info = SNDRV_PCM_INFO_INTERLEAVED |
37 SNDRV_PCM_INFO_BLOCK_TRANSFER | 37 SNDRV_PCM_INFO_BLOCK_TRANSFER |
38 SNDRV_PCM_INFO_MMAP | 38 SNDRV_PCM_INFO_MMAP |
@@ -53,7 +53,7 @@ static const struct snd_pcm_hardware s3c_dma_hardware = {
53 .fifo_size = 32, 53 .fifo_size = 32,
54}; 54};
55 55
56struct s3c24xx_runtime_data { 56struct runtime_data {
57 spinlock_t lock; 57 spinlock_t lock;
58 int state; 58 int state;
59 unsigned int dma_loaded; 59 unsigned int dma_loaded;
@@ -65,14 +65,14 @@ struct s3c24xx_runtime_data {
65 struct s3c_dma_params *params; 65 struct s3c_dma_params *params;
66}; 66};
67 67
68/* s3c_dma_enqueue 68/* dma_enqueue
69 * 69 *
70 * place a dma buffer onto the queue for the dma system 70 * place a dma buffer onto the queue for the dma system
71 * to handle. 71 * to handle.
72*/ 72*/
73static void s3c_dma_enqueue(struct snd_pcm_substream *substream) 73static void dma_enqueue(struct snd_pcm_substream *substream)
74{ 74{
75 struct s3c24xx_runtime_data *prtd = substream->runtime->private_data; 75 struct runtime_data *prtd = substream->runtime->private_data;
76 dma_addr_t pos = prtd->dma_pos; 76 dma_addr_t pos = prtd->dma_pos;
77 unsigned int limit; 77 unsigned int limit;
78 int ret; 78 int ret;
@@ -112,12 +112,12 @@ static void s3c_dma_enqueue(struct snd_pcm_substream *substream)
112 prtd->dma_pos = pos; 112 prtd->dma_pos = pos;
113} 113}
114 114
115static void s3c24xx_audio_buffdone(struct s3c2410_dma_chan *channel, 115static void audio_buffdone(struct s3c2410_dma_chan *channel,
116 void *dev_id, int size, 116 void *dev_id, int size,
117 enum s3c2410_dma_buffresult result) 117 enum s3c2410_dma_buffresult result)
118{ 118{
119 struct snd_pcm_substream *substream = dev_id; 119 struct snd_pcm_substream *substream = dev_id;
120 struct s3c24xx_runtime_data *prtd; 120 struct runtime_data *prtd;
121 121
122 pr_debug("Entered %s\n", __func__); 122 pr_debug("Entered %s\n", __func__);
123 123
@@ -132,17 +132,17 @@ static void s3c24xx_audio_buffdone(struct s3c2410_dma_chan *channel,
132 spin_lock(&prtd->lock); 132 spin_lock(&prtd->lock);
133 if (prtd->state & ST_RUNNING && !s3c_dma_has_circular()) { 133 if (prtd->state & ST_RUNNING && !s3c_dma_has_circular()) {
134 prtd->dma_loaded--; 134 prtd->dma_loaded--;
135 s3c_dma_enqueue(substream); 135 dma_enqueue(substream);
136 } 136 }
137 137
138 spin_unlock(&prtd->lock); 138 spin_unlock(&prtd->lock);
139} 139}
140 140
141static int s3c_dma_hw_params(struct snd_pcm_substream *substream, 141static int dma_hw_params(struct snd_pcm_substream *substream,
142 struct snd_pcm_hw_params *params) 142 struct snd_pcm_hw_params *params)
143{ 143{
144 struct snd_pcm_runtime *runtime = substream->runtime; 144 struct snd_pcm_runtime *runtime = substream->runtime;
145 struct s3c24xx_runtime_data *prtd = runtime->private_data; 145 struct runtime_data *prtd = runtime->private_data;
146 struct snd_soc_pcm_runtime *rtd = substream->private_data; 146 struct snd_soc_pcm_runtime *rtd = substream->private_data;
147 unsigned long totbytes = params_buffer_bytes(params); 147 unsigned long totbytes = params_buffer_bytes(params);
148 struct s3c_dma_params *dma = 148 struct s3c_dma_params *dma =
@@ -181,7 +181,7 @@ static int s3c_dma_hw_params(struct snd_pcm_substream *substream,
181 } 181 }
182 182
183 s3c2410_dma_set_buffdone_fn(prtd->params->channel, 183 s3c2410_dma_set_buffdone_fn(prtd->params->channel,
184 s3c24xx_audio_buffdone); 184 audio_buffdone);
185 185
186 snd_pcm_set_runtime_buffer(substream, &substream->dma_buffer); 186 snd_pcm_set_runtime_buffer(substream, &substream->dma_buffer);
187 187
@@ -199,9 +199,9 @@ static int s3c_dma_hw_params(struct snd_pcm_substream *substream,
199 return 0; 199 return 0;
200} 200}
201 201
202static int s3c_dma_hw_free(struct snd_pcm_substream *substream) 202static int dma_hw_free(struct snd_pcm_substream *substream)
203{ 203{
204 struct s3c24xx_runtime_data *prtd = substream->runtime->private_data; 204 struct runtime_data *prtd = substream->runtime->private_data;
205 205
206 pr_debug("Entered %s\n", __func__); 206 pr_debug("Entered %s\n", __func__);
207 207
@@ -216,9 +216,9 @@ static int s3c_dma_hw_free(struct snd_pcm_substream *substream)
216 return 0; 216 return 0;
217} 217}
218 218
219static int s3c_dma_prepare(struct snd_pcm_substream *substream) 219static int dma_prepare(struct snd_pcm_substream *substream)
220{ 220{
221 struct s3c24xx_runtime_data *prtd = substream->runtime->private_data; 221 struct runtime_data *prtd = substream->runtime->private_data;
222 int ret = 0; 222 int ret = 0;
223 223
224 pr_debug("Entered %s\n", __func__); 224 pr_debug("Entered %s\n", __func__);
@@ -249,14 +249,14 @@ static int s3c_dma_prepare(struct snd_pcm_substream *substream)
249 prtd->dma_pos = prtd->dma_start; 249 prtd->dma_pos = prtd->dma_start;
250 250
251 /* enqueue dma buffers */ 251 /* enqueue dma buffers */
252 s3c_dma_enqueue(substream); 252 dma_enqueue(substream);
253 253
254 return ret; 254 return ret;
255} 255}
256 256
257static int s3c_dma_trigger(struct snd_pcm_substream *substream, int cmd) 257static int dma_trigger(struct snd_pcm_substream *substream, int cmd)
258{ 258{
259 struct s3c24xx_runtime_data *prtd = substream->runtime->private_data; 259 struct runtime_data *prtd = substream->runtime->private_data;
260 int ret = 0; 260 int ret = 0;
261 261
262 pr_debug("Entered %s\n", __func__); 262 pr_debug("Entered %s\n", __func__);
@@ -289,10 +289,10 @@ static int s3c_dma_trigger(struct snd_pcm_substream *substream, int cmd)
289} 289}
290 290
291static snd_pcm_uframes_t 291static snd_pcm_uframes_t
292s3c_dma_pointer(struct snd_pcm_substream *substream) 292dma_pointer(struct snd_pcm_substream *substream)
293{ 293{
294 struct snd_pcm_runtime *runtime = substream->runtime; 294 struct snd_pcm_runtime *runtime = substream->runtime;
295 struct s3c24xx_runtime_data *prtd = runtime->private_data; 295 struct runtime_data *prtd = runtime->private_data;
296 unsigned long res; 296 unsigned long res;
297 dma_addr_t src, dst; 297 dma_addr_t src, dst;
298 298
@@ -324,17 +324,17 @@ s3c_dma_pointer(struct snd_pcm_substream *substream)
324 return bytes_to_frames(substream->runtime, res); 324 return bytes_to_frames(substream->runtime, res);
325} 325}
326 326
327static int s3c_dma_open(struct snd_pcm_substream *substream) 327static int dma_open(struct snd_pcm_substream *substream)
328{ 328{
329 struct snd_pcm_runtime *runtime = substream->runtime; 329 struct snd_pcm_runtime *runtime = substream->runtime;
330 struct s3c24xx_runtime_data *prtd; 330 struct runtime_data *prtd;
331 331
332 pr_debug("Entered %s\n", __func__); 332 pr_debug("Entered %s\n", __func__);
333 333
334 snd_pcm_hw_constraint_integer(runtime, SNDRV_PCM_HW_PARAM_PERIODS); 334 snd_pcm_hw_constraint_integer(runtime, SNDRV_PCM_HW_PARAM_PERIODS);
335 snd_soc_set_runtime_hwparams(substream, &s3c_dma_hardware); 335 snd_soc_set_runtime_hwparams(substream, &dma_hardware);
336 336
337 prtd = kzalloc(sizeof(struct s3c24xx_runtime_data), GFP_KERNEL); 337 prtd = kzalloc(sizeof(struct runtime_data), GFP_KERNEL);
338 if (prtd == NULL) 338 if (prtd == NULL)
339 return -ENOMEM; 339 return -ENOMEM;
340 340
@@ -344,22 +344,22 @@ static int s3c_dma_open(struct snd_pcm_substream *substream)
344 return 0; 344 return 0;
345} 345}
346 346
347static int s3c_dma_close(struct snd_pcm_substream *substream) 347static int dma_close(struct snd_pcm_substream *substream)
348{ 348{
349 struct snd_pcm_runtime *runtime = substream->runtime; 349 struct snd_pcm_runtime *runtime = substream->runtime;
350 struct s3c24xx_runtime_data *prtd = runtime->private_data; 350 struct runtime_data *prtd = runtime->private_data;
351 351
352 pr_debug("Entered %s\n", __func__); 352 pr_debug("Entered %s\n", __func__);
353 353
354 if (!prtd) 354 if (!prtd)
355 pr_debug("s3c_dma_close called with prtd == NULL\n"); 355 pr_debug("dma_close called with prtd == NULL\n");
356 356
357 kfree(prtd); 357 kfree(prtd);
358 358
359 return 0; 359 return 0;
360} 360}
361 361
362static int s3c_dma_mmap(struct snd_pcm_substream *substream, 362static int dma_mmap(struct snd_pcm_substream *substream,
363 struct vm_area_struct *vma) 363 struct vm_area_struct *vma)
364{ 364{
365 struct snd_pcm_runtime *runtime = substream->runtime; 365 struct snd_pcm_runtime *runtime = substream->runtime;
@@ -372,23 +372,23 @@ static int s3c_dma_mmap(struct snd_pcm_substream *substream,
372 runtime->dma_bytes); 372 runtime->dma_bytes);
373} 373}
374 374
375static struct snd_pcm_ops s3c_dma_ops = { 375static struct snd_pcm_ops dma_ops = {
376 .open = s3c_dma_open, 376 .open = dma_open,
377 .close = s3c_dma_close, 377 .close = dma_close,
378 .ioctl = snd_pcm_lib_ioctl, 378 .ioctl = snd_pcm_lib_ioctl,
379 .hw_params = s3c_dma_hw_params, 379 .hw_params = dma_hw_params,
380 .hw_free = s3c_dma_hw_free, 380 .hw_free = dma_hw_free,
381 .prepare = s3c_dma_prepare, 381 .prepare = dma_prepare,
382 .trigger = s3c_dma_trigger, 382 .trigger = dma_trigger,
383 .pointer = s3c_dma_pointer, 383 .pointer = dma_pointer,
384 .mmap = s3c_dma_mmap, 384 .mmap = dma_mmap,
385}; 385};
386 386
387static int s3c_preallocate_dma_buffer(struct snd_pcm *pcm, int stream) 387static int preallocate_dma_buffer(struct snd_pcm *pcm, int stream)
388{ 388{
389 struct snd_pcm_substream *substream = pcm->streams[stream].substream; 389 struct snd_pcm_substream *substream = pcm->streams[stream].substream;
390 struct snd_dma_buffer *buf = &substream->dma_buffer; 390 struct snd_dma_buffer *buf = &substream->dma_buffer;
391 size_t size = s3c_dma_hardware.buffer_bytes_max; 391 size_t size = dma_hardware.buffer_bytes_max;
392 392
393 pr_debug("Entered %s\n", __func__); 393 pr_debug("Entered %s\n", __func__);
394 394
@@ -403,7 +403,7 @@ static int s3c_preallocate_dma_buffer(struct snd_pcm *pcm, int stream)
403 return 0; 403 return 0;
404} 404}
405 405
406static void s3c_dma_free_dma_buffers(struct snd_pcm *pcm) 406static void dma_free_dma_buffers(struct snd_pcm *pcm)
407{ 407{
408 struct snd_pcm_substream *substream; 408 struct snd_pcm_substream *substream;
409 struct snd_dma_buffer *buf; 409 struct snd_dma_buffer *buf;
@@ -426,9 +426,9 @@ static void s3c_dma_free_dma_buffers(struct snd_pcm *pcm)
426 } 426 }
427} 427}
428 428
429static u64 s3c_dma_mask = DMA_BIT_MASK(32); 429static u64 dma_mask = DMA_BIT_MASK(32);
430 430
431static int s3c_dma_new(struct snd_card *card, 431static int dma_new(struct snd_card *card,
432 struct snd_soc_dai *dai, struct snd_pcm *pcm) 432 struct snd_soc_dai *dai, struct snd_pcm *pcm)
433{ 433{
434 int ret = 0; 434 int ret = 0;
@@ -436,67 +436,67 @@ static int s3c_dma_new(struct snd_card *card,
436 pr_debug("Entered %s\n", __func__); 436 pr_debug("Entered %s\n", __func__);
437 437
438 if (!card->dev->dma_mask) 438 if (!card->dev->dma_mask)
439 card->dev->dma_mask = &s3c_dma_mask; 439 card->dev->dma_mask = &dma_mask;
440 if (!card->dev->coherent_dma_mask) 440 if (!card->dev->coherent_dma_mask)
441 card->dev->coherent_dma_mask = 0xffffffff; 441 card->dev->coherent_dma_mask = 0xffffffff;
442 442
443 if (dai->driver->playback.channels_min) { 443 if (dai->driver->playback.channels_min) {
444 ret = s3c_preallocate_dma_buffer(pcm, 444 ret = preallocate_dma_buffer(pcm,
445 SNDRV_PCM_STREAM_PLAYBACK); 445 SNDRV_PCM_STREAM_PLAYBACK);
446 if (ret) 446 if (ret)
447 goto out; 447 goto out;
448 } 448 }
449 449
450 if (dai->driver->capture.channels_min) { 450 if (dai->driver->capture.channels_min) {
451 ret = s3c_preallocate_dma_buffer(pcm, 451 ret = preallocate_dma_buffer(pcm,
452 SNDRV_PCM_STREAM_CAPTURE); 452 SNDRV_PCM_STREAM_CAPTURE);
453 if (ret) 453 if (ret)
454 goto out; 454 goto out;
455 } 455 }
456 out: 456out:
457 return ret; 457 return ret;
458} 458}
459 459
460static struct snd_soc_platform_driver s3c24xx_soc_platform = { 460static struct snd_soc_platform_driver samsung_asoc_platform = {
461 .ops = &s3c_dma_ops, 461 .ops = &dma_ops,
462 .pcm_new = s3c_dma_new, 462 .pcm_new = dma_new,
463 .pcm_free = s3c_dma_free_dma_buffers, 463 .pcm_free = dma_free_dma_buffers,
464}; 464};
465 465
466static int __devinit s3c24xx_soc_platform_probe(struct platform_device *pdev) 466static int __devinit samsung_asoc_platform_probe(struct platform_device *pdev)
467{ 467{
468 return snd_soc_register_platform(&pdev->dev, &s3c24xx_soc_platform); 468 return snd_soc_register_platform(&pdev->dev, &samsung_asoc_platform);
469} 469}
470 470
471static int __devexit s3c24xx_soc_platform_remove(struct platform_device *pdev) 471static int __devexit samsung_asoc_platform_remove(struct platform_device *pdev)
472{ 472{
473 snd_soc_unregister_platform(&pdev->dev); 473 snd_soc_unregister_platform(&pdev->dev);
474 return 0; 474 return 0;
475} 475}
476 476
477static struct platform_driver s3c24xx_pcm_driver = { 477static struct platform_driver asoc_dma_driver = {
478 .driver = { 478 .driver = {
479 .name = "s3c24xx-pcm-audio", 479 .name = "samsung-audio",
480 .owner = THIS_MODULE, 480 .owner = THIS_MODULE,
481 }, 481 },
482 482
483 .probe = s3c24xx_soc_platform_probe, 483 .probe = samsung_asoc_platform_probe,
484 .remove = __devexit_p(s3c24xx_soc_platform_remove), 484 .remove = __devexit_p(samsung_asoc_platform_remove),
485}; 485};
486 486
487static int __init snd_s3c24xx_pcm_init(void) 487static int __init samsung_asoc_init(void)
488{ 488{
489 return platform_driver_register(&s3c24xx_pcm_driver); 489 return platform_driver_register(&asoc_dma_driver);
490} 490}
491module_init(snd_s3c24xx_pcm_init); 491module_init(samsung_asoc_init);
492 492
493static void __exit snd_s3c24xx_pcm_exit(void) 493static void __exit samsung_asoc_exit(void)
494{ 494{
495 platform_driver_unregister(&s3c24xx_pcm_driver); 495 platform_driver_unregister(&asoc_dma_driver);
496} 496}
497module_exit(snd_s3c24xx_pcm_exit); 497module_exit(samsung_asoc_exit);
498 498
499MODULE_AUTHOR("Ben Dooks, <ben@simtec.co.uk>"); 499MODULE_AUTHOR("Ben Dooks, <ben@simtec.co.uk>");
500MODULE_DESCRIPTION("Samsung S3C Audio DMA module"); 500MODULE_DESCRIPTION("Samsung ASoC DMA Driver");
501MODULE_LICENSE("GPL"); 501MODULE_LICENSE("GPL");
502MODULE_ALIAS("platform:s3c24xx-pcm-audio"); 502MODULE_ALIAS("platform:samsung-audio");
diff --git a/sound/soc/s3c24xx/s3c-dma.h b/sound/soc/samsung/dma.h
index 748c07d7c075..f8cd2b4223af 100644
--- a/sound/soc/s3c24xx/s3c-dma.h
+++ b/sound/soc/samsung/dma.h
@@ -1,5 +1,5 @@
1/* 1/*
2 * s3c-dma.h -- 2 * dma.h --
3 * 3 *
4 * This program is free software; you can redistribute it and/or modify it 4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License as published by the 5 * under the terms of the GNU General Public License as published by the
diff --git a/sound/soc/s3c24xx/goni_wm8994.c b/sound/soc/samsung/goni_wm8994.c
index 694f702cc8e2..34dd9ef1b9c0 100644
--- a/sound/soc/s3c24xx/goni_wm8994.c
+++ b/sound/soc/samsung/goni_wm8994.c
@@ -16,7 +16,6 @@
16#include <linux/io.h> 16#include <linux/io.h>
17#include <linux/platform_device.h> 17#include <linux/platform_device.h>
18#include <sound/soc.h> 18#include <sound/soc.h>
19#include <sound/soc-dapm.h>
20#include <sound/jack.h> 19#include <sound/jack.h>
21#include <asm/mach-types.h> 20#include <asm/mach-types.h>
22#include <mach/gpio.h> 21#include <mach/gpio.h>
@@ -25,8 +24,16 @@
25#include <linux/mfd/wm8994/core.h> 24#include <linux/mfd/wm8994/core.h>
26#include <linux/mfd/wm8994/registers.h> 25#include <linux/mfd/wm8994/registers.h>
27#include "../codecs/wm8994.h" 26#include "../codecs/wm8994.h"
28#include "s3c-dma.h" 27#include "dma.h"
29#include "s3c64xx-i2s.h" 28#include "i2s.h"
29
30#define MACHINE_NAME 0
31#define CPU_VOICE_DAI 1
32
33static const char *aquila_str[] = {
34 [MACHINE_NAME] = "aquila",
35 [CPU_VOICE_DAI] = "aquila-voice-dai",
36};
30 37
31static struct snd_soc_card goni; 38static struct snd_soc_card goni;
32static struct platform_device *goni_snd_device; 39static struct platform_device *goni_snd_device;
@@ -97,28 +104,34 @@ static const struct snd_soc_dapm_route goni_dapm_routes[] = {
97static int goni_wm8994_init(struct snd_soc_pcm_runtime *rtd) 104static int goni_wm8994_init(struct snd_soc_pcm_runtime *rtd)
98{ 105{
99 struct snd_soc_codec *codec = rtd->codec; 106 struct snd_soc_codec *codec = rtd->codec;
107 struct snd_soc_dapm_context *dapm = &codec->dapm;
100 int ret; 108 int ret;
101 109
102 /* add goni specific widgets */ 110 /* add goni specific widgets */
103 snd_soc_dapm_new_controls(codec, goni_dapm_widgets, 111 snd_soc_dapm_new_controls(dapm, goni_dapm_widgets,
104 ARRAY_SIZE(goni_dapm_widgets)); 112 ARRAY_SIZE(goni_dapm_widgets));
105 113
106 /* set up goni specific audio routes */ 114 /* set up goni specific audio routes */
107 snd_soc_dapm_add_routes(codec, goni_dapm_routes, 115 snd_soc_dapm_add_routes(dapm, goni_dapm_routes,
108 ARRAY_SIZE(goni_dapm_routes)); 116 ARRAY_SIZE(goni_dapm_routes));
109 117
110 /* set endpoints to not connected */ 118 /* set endpoints to not connected */
111 snd_soc_dapm_nc_pin(codec, "IN2LP:VXRN"); 119 snd_soc_dapm_nc_pin(dapm, "IN2LP:VXRN");
112 snd_soc_dapm_nc_pin(codec, "IN2RP:VXRP"); 120 snd_soc_dapm_nc_pin(dapm, "IN2RP:VXRP");
113 snd_soc_dapm_nc_pin(codec, "LINEOUT1N"); 121 snd_soc_dapm_nc_pin(dapm, "LINEOUT1N");
114 snd_soc_dapm_nc_pin(codec, "LINEOUT1P"); 122 snd_soc_dapm_nc_pin(dapm, "LINEOUT1P");
115 snd_soc_dapm_nc_pin(codec, "LINEOUT2N"); 123 snd_soc_dapm_nc_pin(dapm, "LINEOUT2N");
116 snd_soc_dapm_nc_pin(codec, "LINEOUT2P"); 124 snd_soc_dapm_nc_pin(dapm, "LINEOUT2P");
117 125
118 snd_soc_dapm_sync(codec); 126 if (machine_is_aquila()) {
127 snd_soc_dapm_nc_pin(dapm, "SPKOUTRN");
128 snd_soc_dapm_nc_pin(dapm, "SPKOUTRP");
129 }
130
131 snd_soc_dapm_sync(dapm);
119 132
120 /* Headset jack detection */ 133 /* Headset jack detection */
121 ret = snd_soc_jack_new(&goni, "Headset Jack", 134 ret = snd_soc_jack_new(codec, "Headset Jack",
122 SND_JACK_HEADSET | SND_JACK_MECHANICAL | SND_JACK_AVOUT, 135 SND_JACK_HEADSET | SND_JACK_MECHANICAL | SND_JACK_AVOUT,
123 &jack); 136 &jack);
124 if (ret) 137 if (ret)
@@ -150,12 +163,6 @@ static int goni_hifi_hw_params(struct snd_pcm_substream *substream,
150 if (ret < 0) 163 if (ret < 0)
151 return ret; 164 return ret;
152 165
153 /* set the cpu system clock */
154 ret = snd_soc_dai_set_sysclk(cpu_dai, S3C64XX_CLKSRC_PCLK,
155 0, SND_SOC_CLOCK_IN);
156 if (ret < 0)
157 return ret;
158
159 /* set codec DAI configuration */ 166 /* set codec DAI configuration */
160 ret = snd_soc_dai_set_fmt(codec_dai, SND_SOC_DAIFMT_I2S | 167 ret = snd_soc_dai_set_fmt(codec_dai, SND_SOC_DAIFMT_I2S |
161 SND_SOC_DAIFMT_NB_NF | SND_SOC_DAIFMT_CBM_CFM); 168 SND_SOC_DAIFMT_NB_NF | SND_SOC_DAIFMT_CBM_CFM);
@@ -236,9 +243,9 @@ static struct snd_soc_dai_link goni_dai[] = {
236{ 243{
237 .name = "WM8994", 244 .name = "WM8994",
238 .stream_name = "WM8994 HiFi", 245 .stream_name = "WM8994 HiFi",
239 .cpu_dai_name = "s3c64xx-i2s-v4", 246 .cpu_dai_name = "samsung-i2s.0",
240 .codec_dai_name = "wm8994-hifi", 247 .codec_dai_name = "wm8994-hifi",
241 .platform_name = "s3c24xx-pcm-audio", 248 .platform_name = "samsung-audio",
242 .codec_name = "wm8994-codec.0-0x1a", 249 .codec_name = "wm8994-codec.0-0x1a",
243 .init = goni_wm8994_init, 250 .init = goni_wm8994_init,
244 .ops = &goni_hifi_ops, 251 .ops = &goni_hifi_ops,
@@ -247,7 +254,7 @@ static struct snd_soc_dai_link goni_dai[] = {
247 .stream_name = "Voice", 254 .stream_name = "Voice",
248 .cpu_dai_name = "goni-voice-dai", 255 .cpu_dai_name = "goni-voice-dai",
249 .codec_dai_name = "wm8994-voice", 256 .codec_dai_name = "wm8994-voice",
250 .platform_name = "s3c24xx-pcm-audio", 257 .platform_name = "samsung-audio",
251 .codec_name = "wm8994-codec.0-0x1a", 258 .codec_name = "wm8994-codec.0-0x1a",
252 .ops = &goni_voice_ops, 259 .ops = &goni_voice_ops,
253}, 260},
@@ -263,7 +270,11 @@ static int __init goni_init(void)
263{ 270{
264 int ret; 271 int ret;
265 272
266 if (!machine_is_goni()) 273 if (machine_is_aquila()) {
274 voice_dai.name = aquila_str[CPU_VOICE_DAI];
275 goni_dai[1].cpu_dai_name = aquila_str[CPU_VOICE_DAI];
276 goni.name = aquila_str[MACHINE_NAME];
277 } else if (!machine_is_goni())
267 return -ENODEV; 278 return -ENODEV;
268 279
269 goni_snd_device = platform_device_alloc("soc-audio", -1); 280 goni_snd_device = platform_device_alloc("soc-audio", -1);
@@ -272,20 +283,25 @@ static int __init goni_init(void)
272 283
273 /* register voice DAI here */ 284 /* register voice DAI here */
274 ret = snd_soc_register_dai(&goni_snd_device->dev, &voice_dai); 285 ret = snd_soc_register_dai(&goni_snd_device->dev, &voice_dai);
275 if (ret) 286 if (ret) {
287 platform_device_put(goni_snd_device);
276 return ret; 288 return ret;
289 }
277 290
278 platform_set_drvdata(goni_snd_device, &goni); 291 platform_set_drvdata(goni_snd_device, &goni);
279 ret = platform_device_add(goni_snd_device); 292 ret = platform_device_add(goni_snd_device);
280 293
281 if (ret) 294 if (ret) {
295 snd_soc_unregister_dai(&goni_snd_device->dev);
282 platform_device_put(goni_snd_device); 296 platform_device_put(goni_snd_device);
297 }
283 298
284 return ret; 299 return ret;
285} 300}
286 301
287static void __exit goni_exit(void) 302static void __exit goni_exit(void)
288{ 303{
304 snd_soc_unregister_dai(&goni_snd_device->dev);
289 platform_device_unregister(goni_snd_device); 305 platform_device_unregister(goni_snd_device);
290} 306}
291 307
diff --git a/sound/soc/samsung/h1940_uda1380.c b/sound/soc/samsung/h1940_uda1380.c
new file mode 100644
index 000000000000..c45f7ce14d61
--- /dev/null
+++ b/sound/soc/samsung/h1940_uda1380.c
@@ -0,0 +1,296 @@
1/*
2 * h1940-uda1380.c -- ALSA Soc Audio Layer
3 *
4 * Copyright (c) 2010 Arnaud Patard <arnaud.patard@rtp-net.org>
5 * Copyright (c) 2010 Vasily Khoruzhick <anarsoul@gmail.com>
6 *
7 * Based on version from Arnaud Patard <arnaud.patard@rtp-net.org>
8 *
9 * This program is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU General Public License as published by the
11 * Free Software Foundation; either version 2 of the License, or (at your
12 * option) any later version.
13 *
14 */
15
16#include <linux/module.h>
17#include <linux/moduleparam.h>
18#include <linux/platform_device.h>
19#include <linux/i2c.h>
20#include <linux/gpio.h>
21
22#include <sound/soc.h>
23#include <sound/uda1380.h>
24#include <sound/jack.h>
25
26#include <plat/regs-iis.h>
27
28#include <mach/h1940-latch.h>
29
30#include <asm/mach-types.h>
31
32#include "dma.h"
33#include "s3c24xx-i2s.h"
34#include "../codecs/uda1380.h"
35
36static unsigned int rates[] = {
37 11025,
38 22050,
39 44100,
40};
41
42static struct snd_pcm_hw_constraint_list hw_rates = {
43 .count = ARRAY_SIZE(rates),
44 .list = rates,
45 .mask = 0,
46};
47
48static struct snd_soc_jack hp_jack;
49
50static struct snd_soc_jack_pin hp_jack_pins[] = {
51 {
52 .pin = "Headphone Jack",
53 .mask = SND_JACK_HEADPHONE,
54 },
55 {
56 .pin = "Speaker",
57 .mask = SND_JACK_HEADPHONE,
58 .invert = 1,
59 },
60};
61
62static struct snd_soc_jack_gpio hp_jack_gpios[] = {
63 {
64 .gpio = S3C2410_GPG(4),
65 .name = "hp-gpio",
66 .report = SND_JACK_HEADPHONE,
67 .invert = 1,
68 .debounce_time = 200,
69 },
70};
71
72static int h1940_startup(struct snd_pcm_substream *substream)
73{
74 struct snd_pcm_runtime *runtime = substream->runtime;
75
76 runtime->hw.rate_min = hw_rates.list[0];
77 runtime->hw.rate_max = hw_rates.list[hw_rates.count - 1];
78 runtime->hw.rates = SNDRV_PCM_RATE_KNOT;
79
80 return snd_pcm_hw_constraint_list(runtime, 0,
81 SNDRV_PCM_HW_PARAM_RATE,
82 &hw_rates);
83}
84
85static int h1940_hw_params(struct snd_pcm_substream *substream,
86 struct snd_pcm_hw_params *params)
87{
88 struct snd_soc_pcm_runtime *rtd = substream->private_data;
89 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
90 struct snd_soc_dai *codec_dai = rtd->codec_dai;
91 int div;
92 int ret;
93 unsigned int rate = params_rate(params);
94
95 switch (rate) {
96 case 11025:
97 case 22050:
98 case 44100:
99 div = s3c24xx_i2s_get_clockrate() / (384 * rate);
100 if (s3c24xx_i2s_get_clockrate() % (384 * rate) > (192 * rate))
101 div++;
102 break;
103 default:
104 dev_err(&rtd->dev, "%s: rate %d is not supported\n",
105 __func__, rate);
106 return -EINVAL;
107 }
108
109 /* set codec DAI configuration */
110 ret = snd_soc_dai_set_fmt(codec_dai, SND_SOC_DAIFMT_I2S |
111 SND_SOC_DAIFMT_NB_NF | SND_SOC_DAIFMT_CBS_CFS);
112 if (ret < 0)
113 return ret;
114
115 /* set cpu DAI configuration */
116 ret = snd_soc_dai_set_fmt(cpu_dai, SND_SOC_DAIFMT_I2S |
117 SND_SOC_DAIFMT_NB_NF | SND_SOC_DAIFMT_CBS_CFS);
118 if (ret < 0)
119 return ret;
120
121 /* select clock source */
122 ret = snd_soc_dai_set_sysclk(cpu_dai, S3C24XX_CLKSRC_PCLK, rate,
123 SND_SOC_CLOCK_OUT);
124 if (ret < 0)
125 return ret;
126
127 /* set MCLK division for sample rate */
128 ret = snd_soc_dai_set_clkdiv(cpu_dai, S3C24XX_DIV_MCLK,
129 S3C2410_IISMOD_384FS);
130 if (ret < 0)
131 return ret;
132
133 /* set BCLK division for sample rate */
134 ret = snd_soc_dai_set_clkdiv(cpu_dai, S3C24XX_DIV_BCLK,
135 S3C2410_IISMOD_32FS);
136 if (ret < 0)
137 return ret;
138
139 /* set prescaler division for sample rate */
140 ret = snd_soc_dai_set_clkdiv(cpu_dai, S3C24XX_DIV_PRESCALER,
141 S3C24XX_PRESCALE(div, div));
142 if (ret < 0)
143 return ret;
144
145 return 0;
146}
147
148static struct snd_soc_ops h1940_ops = {
149 .startup = h1940_startup,
150 .hw_params = h1940_hw_params,
151};
152
153static int h1940_spk_power(struct snd_soc_dapm_widget *w,
154 struct snd_kcontrol *kcontrol, int event)
155{
156 if (SND_SOC_DAPM_EVENT_ON(event))
157 gpio_set_value(H1940_LATCH_AUDIO_POWER, 1);
158 else
159 gpio_set_value(H1940_LATCH_AUDIO_POWER, 0);
160
161 return 0;
162}
163
164/* h1940 machine dapm widgets */
165static const struct snd_soc_dapm_widget uda1380_dapm_widgets[] = {
166 SND_SOC_DAPM_HP("Headphone Jack", NULL),
167 SND_SOC_DAPM_MIC("Mic Jack", NULL),
168 SND_SOC_DAPM_SPK("Speaker", h1940_spk_power),
169};
170
171/* h1940 machine audio_map */
172static const struct snd_soc_dapm_route audio_map[] = {
173 /* headphone connected to VOUTLHP, VOUTRHP */
174 {"Headphone Jack", NULL, "VOUTLHP"},
175 {"Headphone Jack", NULL, "VOUTRHP"},
176
177 /* ext speaker connected to VOUTL, VOUTR */
178 {"Speaker", NULL, "VOUTL"},
179 {"Speaker", NULL, "VOUTR"},
180
181 /* mic is connected to VINM */
182 {"VINM", NULL, "Mic Jack"},
183};
184
185static struct platform_device *s3c24xx_snd_device;
186
187static int h1940_uda1380_init(struct snd_soc_pcm_runtime *rtd)
188{
189 struct snd_soc_codec *codec = rtd->codec;
190 struct snd_soc_dapm_context *dapm = &codec->dapm;
191 int err;
192
193 /* Add h1940 specific widgets */
194 err = snd_soc_dapm_new_controls(dapm, uda1380_dapm_widgets,
195 ARRAY_SIZE(uda1380_dapm_widgets));
196 if (err)
197 return err;
198
199 /* Set up h1940 specific audio path audio_mapnects */
200 err = snd_soc_dapm_add_routes(dapm, audio_map,
201 ARRAY_SIZE(audio_map));
202 if (err)
203 return err;
204
205 snd_soc_dapm_enable_pin(dapm, "Headphone Jack");
206 snd_soc_dapm_enable_pin(dapm, "Speaker");
207 snd_soc_dapm_enable_pin(dapm, "Mic Jack");
208
209 snd_soc_dapm_sync(dapm);
210
211 snd_soc_jack_new(codec, "Headphone Jack", SND_JACK_HEADPHONE,
212 &hp_jack);
213
214 snd_soc_jack_add_pins(&hp_jack, ARRAY_SIZE(hp_jack_pins),
215 hp_jack_pins);
216
217 snd_soc_jack_add_gpios(&hp_jack, ARRAY_SIZE(hp_jack_gpios),
218 hp_jack_gpios);
219
220 return 0;
221}
222
223/* s3c24xx digital audio interface glue - connects codec <--> CPU */
224static struct snd_soc_dai_link h1940_uda1380_dai[] = {
225 {
226 .name = "uda1380",
227 .stream_name = "UDA1380 Duplex",
228 .cpu_dai_name = "s3c24xx-iis",
229 .codec_dai_name = "uda1380-hifi",
230 .init = h1940_uda1380_init,
231 .platform_name = "samsung-audio",
232 .codec_name = "uda1380-codec.0-001a",
233 .ops = &h1940_ops,
234 },
235};
236
237static struct snd_soc_card h1940_asoc = {
238 .name = "h1940",
239 .dai_link = h1940_uda1380_dai,
240 .num_links = ARRAY_SIZE(h1940_uda1380_dai),
241};
242
243static int __init h1940_init(void)
244{
245 int ret;
246
247 if (!machine_is_h1940())
248 return -ENODEV;
249
250 /* configure some gpios */
251 ret = gpio_request(H1940_LATCH_AUDIO_POWER, "speaker-power");
252 if (ret)
253 goto err_out;
254
255 ret = gpio_direction_output(H1940_LATCH_AUDIO_POWER, 0);
256 if (ret)
257 goto err_gpio;
258
259 s3c24xx_snd_device = platform_device_alloc("soc-audio", -1);
260 if (!s3c24xx_snd_device) {
261 ret = -ENOMEM;
262 goto err_gpio;
263 }
264
265 platform_set_drvdata(s3c24xx_snd_device, &h1940_asoc);
266 ret = platform_device_add(s3c24xx_snd_device);
267
268 if (ret)
269 goto err_plat;
270
271 return 0;
272
273err_plat:
274 platform_device_put(s3c24xx_snd_device);
275err_gpio:
276 gpio_free(H1940_LATCH_AUDIO_POWER);
277
278err_out:
279 return ret;
280}
281
282static void __exit h1940_exit(void)
283{
284 platform_device_unregister(s3c24xx_snd_device);
285 snd_soc_jack_free_gpios(&hp_jack, ARRAY_SIZE(hp_jack_gpios),
286 hp_jack_gpios);
287 gpio_free(H1940_LATCH_AUDIO_POWER);
288}
289
290module_init(h1940_init);
291module_exit(h1940_exit);
292
293/* Module information */
294MODULE_AUTHOR("Arnaud Patard, Vasily Khoruzhick");
295MODULE_DESCRIPTION("ALSA SoC H1940");
296MODULE_LICENSE("GPL");
diff --git a/sound/soc/samsung/i2s.c b/sound/soc/samsung/i2s.c
new file mode 100644
index 000000000000..d00ac3a7102c
--- /dev/null
+++ b/sound/soc/samsung/i2s.c
@@ -0,0 +1,1258 @@
1/* sound/soc/samsung/i2s.c
2 *
3 * ALSA SoC Audio Layer - Samsung I2S Controller driver
4 *
5 * Copyright (c) 2010 Samsung Electronics Co. Ltd.
6 * Jaswinder Singh <jassi.brar@samsung.com>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation.
11 */
12
13#include <linux/delay.h>
14#include <linux/slab.h>
15#include <linux/clk.h>
16#include <linux/io.h>
17
18#include <sound/pcm.h>
19#include <sound/pcm_params.h>
20#include <sound/soc.h>
21
22#include <plat/audio.h>
23
24#include "dma.h"
25#include "i2s.h"
26
27#define I2SCON 0x0
28#define I2SMOD 0x4
29#define I2SFIC 0x8
30#define I2SPSR 0xc
31#define I2STXD 0x10
32#define I2SRXD 0x14
33#define I2SFICS 0x18
34#define I2STXDS 0x1c
35
36#define CON_RSTCLR (1 << 31)
37#define CON_FRXOFSTATUS (1 << 26)
38#define CON_FRXORINTEN (1 << 25)
39#define CON_FTXSURSTAT (1 << 24)
40#define CON_FTXSURINTEN (1 << 23)
41#define CON_TXSDMA_PAUSE (1 << 20)
42#define CON_TXSDMA_ACTIVE (1 << 18)
43
44#define CON_FTXURSTATUS (1 << 17)
45#define CON_FTXURINTEN (1 << 16)
46#define CON_TXFIFO2_EMPTY (1 << 15)
47#define CON_TXFIFO1_EMPTY (1 << 14)
48#define CON_TXFIFO2_FULL (1 << 13)
49#define CON_TXFIFO1_FULL (1 << 12)
50
51#define CON_LRINDEX (1 << 11)
52#define CON_TXFIFO_EMPTY (1 << 10)
53#define CON_RXFIFO_EMPTY (1 << 9)
54#define CON_TXFIFO_FULL (1 << 8)
55#define CON_RXFIFO_FULL (1 << 7)
56#define CON_TXDMA_PAUSE (1 << 6)
57#define CON_RXDMA_PAUSE (1 << 5)
58#define CON_TXCH_PAUSE (1 << 4)
59#define CON_RXCH_PAUSE (1 << 3)
60#define CON_TXDMA_ACTIVE (1 << 2)
61#define CON_RXDMA_ACTIVE (1 << 1)
62#define CON_ACTIVE (1 << 0)
63
64#define MOD_OPCLK_CDCLK_OUT (0 << 30)
65#define MOD_OPCLK_CDCLK_IN (1 << 30)
66#define MOD_OPCLK_BCLK_OUT (2 << 30)
67#define MOD_OPCLK_PCLK (3 << 30)
68#define MOD_OPCLK_MASK (3 << 30)
69#define MOD_TXS_IDMA (1 << 28) /* Sec_TXFIFO use I-DMA */
70
71#define MOD_BLCS_SHIFT 26
72#define MOD_BLCS_16BIT (0 << MOD_BLCS_SHIFT)
73#define MOD_BLCS_8BIT (1 << MOD_BLCS_SHIFT)
74#define MOD_BLCS_24BIT (2 << MOD_BLCS_SHIFT)
75#define MOD_BLCS_MASK (3 << MOD_BLCS_SHIFT)
76#define MOD_BLCP_SHIFT 24
77#define MOD_BLCP_16BIT (0 << MOD_BLCP_SHIFT)
78#define MOD_BLCP_8BIT (1 << MOD_BLCP_SHIFT)
79#define MOD_BLCP_24BIT (2 << MOD_BLCP_SHIFT)
80#define MOD_BLCP_MASK (3 << MOD_BLCP_SHIFT)
81
82#define MOD_C2DD_HHALF (1 << 21) /* Discard Higher-half */
83#define MOD_C2DD_LHALF (1 << 20) /* Discard Lower-half */
84#define MOD_C1DD_HHALF (1 << 19)
85#define MOD_C1DD_LHALF (1 << 18)
86#define MOD_DC2_EN (1 << 17)
87#define MOD_DC1_EN (1 << 16)
88#define MOD_BLC_16BIT (0 << 13)
89#define MOD_BLC_8BIT (1 << 13)
90#define MOD_BLC_24BIT (2 << 13)
91#define MOD_BLC_MASK (3 << 13)
92
93#define MOD_IMS_SYSMUX (1 << 10)
94#define MOD_SLAVE (1 << 11)
95#define MOD_TXONLY (0 << 8)
96#define MOD_RXONLY (1 << 8)
97#define MOD_TXRX (2 << 8)
98#define MOD_MASK (3 << 8)
99#define MOD_LR_LLOW (0 << 7)
100#define MOD_LR_RLOW (1 << 7)
101#define MOD_SDF_IIS (0 << 5)
102#define MOD_SDF_MSB (1 << 5)
103#define MOD_SDF_LSB (2 << 5)
104#define MOD_SDF_MASK (3 << 5)
105#define MOD_RCLK_256FS (0 << 3)
106#define MOD_RCLK_512FS (1 << 3)
107#define MOD_RCLK_384FS (2 << 3)
108#define MOD_RCLK_768FS (3 << 3)
109#define MOD_RCLK_MASK (3 << 3)
110#define MOD_BCLK_32FS (0 << 1)
111#define MOD_BCLK_48FS (1 << 1)
112#define MOD_BCLK_16FS (2 << 1)
113#define MOD_BCLK_24FS (3 << 1)
114#define MOD_BCLK_MASK (3 << 1)
115#define MOD_8BIT (1 << 0)
116
117#define MOD_CDCLKCON (1 << 12)
118
119#define PSR_PSREN (1 << 15)
120
121#define FIC_TX2COUNT(x) (((x) >> 24) & 0xf)
122#define FIC_TX1COUNT(x) (((x) >> 16) & 0xf)
123
124#define FIC_TXFLUSH (1 << 15)
125#define FIC_RXFLUSH (1 << 7)
126#define FIC_TXCOUNT(x) (((x) >> 8) & 0xf)
127#define FIC_RXCOUNT(x) (((x) >> 0) & 0xf)
128#define FICS_TXCOUNT(x) (((x) >> 8) & 0x7f)
129
130#define msecs_to_loops(t) (loops_per_jiffy / 1000 * HZ * t)
131
132struct i2s_dai {
133 /* Platform device for this DAI */
134 struct platform_device *pdev;
135 /* IOREMAP'd SFRs */
136 void __iomem *addr;
137 /* Physical base address of SFRs */
138 u32 base;
139 /* Rate of RCLK source clock */
140 unsigned long rclk_srcrate;
141 /* Frame Clock */
142 unsigned frmclk;
143 /*
144 * Specifically requested RCLK,BCLK by MACHINE Driver.
145 * 0 indicates CPU driver is free to choose any value.
146 */
147 unsigned rfs, bfs;
148 /* I2S Controller's core clock */
149 struct clk *clk;
150 /* Clock for generating I2S signals */
151 struct clk *op_clk;
152 /* Array of clock names for op_clk */
153 const char **src_clk;
154 /* Pointer to the Primary_Fifo if this is Sec_Fifo, NULL otherwise */
155 struct i2s_dai *pri_dai;
156 /* Pointer to the Secondary_Fifo if it has one, NULL otherwise */
157 struct i2s_dai *sec_dai;
158#define DAI_OPENED (1 << 0) /* Dai is opened */
159#define DAI_MANAGER (1 << 1) /* Dai is the manager */
160 unsigned mode;
161 /* Driver for this DAI */
162 struct snd_soc_dai_driver i2s_dai_drv;
163 /* DMA parameters */
164 struct s3c_dma_params dma_playback;
165 struct s3c_dma_params dma_capture;
166 u32 quirks;
167 u32 suspend_i2smod;
168 u32 suspend_i2scon;
169 u32 suspend_i2spsr;
170};
171
172/* Lock for cross i/f checks */
173static DEFINE_SPINLOCK(lock);
174
175/* If this is the 'overlay' stereo DAI */
176static inline bool is_secondary(struct i2s_dai *i2s)
177{
178 return i2s->pri_dai ? true : false;
179}
180
181/* If operating in SoC-Slave mode */
182static inline bool is_slave(struct i2s_dai *i2s)
183{
184 return (readl(i2s->addr + I2SMOD) & MOD_SLAVE) ? true : false;
185}
186
187/* If this interface of the controller is transmitting data */
188static inline bool tx_active(struct i2s_dai *i2s)
189{
190 u32 active;
191
192 if (!i2s)
193 return false;
194
195 active = readl(i2s->addr + I2SMOD);
196
197 if (is_secondary(i2s))
198 active &= CON_TXSDMA_ACTIVE;
199 else
200 active &= CON_TXDMA_ACTIVE;
201
202 return active ? true : false;
203}
204
205/* If the other interface of the controller is transmitting data */
206static inline bool other_tx_active(struct i2s_dai *i2s)
207{
208 struct i2s_dai *other = i2s->pri_dai ? : i2s->sec_dai;
209
210 return tx_active(other);
211}
212
213/* If any interface of the controller is transmitting data */
214static inline bool any_tx_active(struct i2s_dai *i2s)
215{
216 return tx_active(i2s) || other_tx_active(i2s);
217}
218
219/* If this interface of the controller is receiving data */
220static inline bool rx_active(struct i2s_dai *i2s)
221{
222 u32 active;
223
224 if (!i2s)
225 return false;
226
227 active = readl(i2s->addr + I2SMOD) & CON_RXDMA_ACTIVE;
228
229 return active ? true : false;
230}
231
232/* If the other interface of the controller is receiving data */
233static inline bool other_rx_active(struct i2s_dai *i2s)
234{
235 struct i2s_dai *other = i2s->pri_dai ? : i2s->sec_dai;
236
237 return rx_active(other);
238}
239
240/* If any interface of the controller is receiving data */
241static inline bool any_rx_active(struct i2s_dai *i2s)
242{
243 return rx_active(i2s) || other_rx_active(i2s);
244}
245
246/* If the other DAI is transmitting or receiving data */
247static inline bool other_active(struct i2s_dai *i2s)
248{
249 return other_rx_active(i2s) || other_tx_active(i2s);
250}
251
252/* If this DAI is transmitting or receiving data */
253static inline bool this_active(struct i2s_dai *i2s)
254{
255 return tx_active(i2s) || rx_active(i2s);
256}
257
258/* If the controller is active anyway */
259static inline bool any_active(struct i2s_dai *i2s)
260{
261 return this_active(i2s) || other_active(i2s);
262}
263
264static inline struct i2s_dai *to_info(struct snd_soc_dai *dai)
265{
266 return snd_soc_dai_get_drvdata(dai);
267}
268
269static inline bool is_opened(struct i2s_dai *i2s)
270{
271 if (i2s && (i2s->mode & DAI_OPENED))
272 return true;
273 else
274 return false;
275}
276
277static inline bool is_manager(struct i2s_dai *i2s)
278{
279 if (is_opened(i2s) && (i2s->mode & DAI_MANAGER))
280 return true;
281 else
282 return false;
283}
284
285/* Read RCLK of I2S (in multiples of LRCLK) */
286static inline unsigned get_rfs(struct i2s_dai *i2s)
287{
288 u32 rfs = (readl(i2s->addr + I2SMOD) >> 3) & 0x3;
289
290 switch (rfs) {
291 case 3: return 768;
292 case 2: return 384;
293 case 1: return 512;
294 default: return 256;
295 }
296}
297
298/* Write RCLK of I2S (in multiples of LRCLK) */
299static inline void set_rfs(struct i2s_dai *i2s, unsigned rfs)
300{
301 u32 mod = readl(i2s->addr + I2SMOD);
302
303 mod &= ~MOD_RCLK_MASK;
304
305 switch (rfs) {
306 case 768:
307 mod |= MOD_RCLK_768FS;
308 break;
309 case 512:
310 mod |= MOD_RCLK_512FS;
311 break;
312 case 384:
313 mod |= MOD_RCLK_384FS;
314 break;
315 default:
316 mod |= MOD_RCLK_256FS;
317 break;
318 }
319
320 writel(mod, i2s->addr + I2SMOD);
321}
322
323/* Read Bit-Clock of I2S (in multiples of LRCLK) */
324static inline unsigned get_bfs(struct i2s_dai *i2s)
325{
326 u32 bfs = (readl(i2s->addr + I2SMOD) >> 1) & 0x3;
327
328 switch (bfs) {
329 case 3: return 24;
330 case 2: return 16;
331 case 1: return 48;
332 default: return 32;
333 }
334}
335
336/* Write Bit-Clock of I2S (in multiples of LRCLK) */
337static inline void set_bfs(struct i2s_dai *i2s, unsigned bfs)
338{
339 u32 mod = readl(i2s->addr + I2SMOD);
340
341 mod &= ~MOD_BCLK_MASK;
342
343 switch (bfs) {
344 case 48:
345 mod |= MOD_BCLK_48FS;
346 break;
347 case 32:
348 mod |= MOD_BCLK_32FS;
349 break;
350 case 24:
351 mod |= MOD_BCLK_24FS;
352 break;
353 case 16:
354 mod |= MOD_BCLK_16FS;
355 break;
356 default:
357 dev_err(&i2s->pdev->dev, "Wrong BCLK Divider!\n");
358 return;
359 }
360
361 writel(mod, i2s->addr + I2SMOD);
362}
363
364/* Sample-Size */
365static inline int get_blc(struct i2s_dai *i2s)
366{
367 int blc = readl(i2s->addr + I2SMOD);
368
369 blc = (blc >> 13) & 0x3;
370
371 switch (blc) {
372 case 2: return 24;
373 case 1: return 8;
374 default: return 16;
375 }
376}
377
378/* TX Channel Control */
379static void i2s_txctrl(struct i2s_dai *i2s, int on)
380{
381 void __iomem *addr = i2s->addr;
382 u32 con = readl(addr + I2SCON);
383 u32 mod = readl(addr + I2SMOD) & ~MOD_MASK;
384
385 if (on) {
386 con |= CON_ACTIVE;
387 con &= ~CON_TXCH_PAUSE;
388
389 if (is_secondary(i2s)) {
390 con |= CON_TXSDMA_ACTIVE;
391 con &= ~CON_TXSDMA_PAUSE;
392 } else {
393 con |= CON_TXDMA_ACTIVE;
394 con &= ~CON_TXDMA_PAUSE;
395 }
396
397 if (any_rx_active(i2s))
398 mod |= MOD_TXRX;
399 else
400 mod |= MOD_TXONLY;
401 } else {
402 if (is_secondary(i2s)) {
403 con |= CON_TXSDMA_PAUSE;
404 con &= ~CON_TXSDMA_ACTIVE;
405 } else {
406 con |= CON_TXDMA_PAUSE;
407 con &= ~CON_TXDMA_ACTIVE;
408 }
409
410 if (other_tx_active(i2s)) {
411 writel(con, addr + I2SCON);
412 return;
413 }
414
415 con |= CON_TXCH_PAUSE;
416
417 if (any_rx_active(i2s))
418 mod |= MOD_RXONLY;
419 else
420 con &= ~CON_ACTIVE;
421 }
422
423 writel(mod, addr + I2SMOD);
424 writel(con, addr + I2SCON);
425}
426
427/* RX Channel Control */
428static void i2s_rxctrl(struct i2s_dai *i2s, int on)
429{
430 void __iomem *addr = i2s->addr;
431 u32 con = readl(addr + I2SCON);
432 u32 mod = readl(addr + I2SMOD) & ~MOD_MASK;
433
434 if (on) {
435 con |= CON_RXDMA_ACTIVE | CON_ACTIVE;
436 con &= ~(CON_RXDMA_PAUSE | CON_RXCH_PAUSE);
437
438 if (any_tx_active(i2s))
439 mod |= MOD_TXRX;
440 else
441 mod |= MOD_RXONLY;
442 } else {
443 con |= CON_RXDMA_PAUSE | CON_RXCH_PAUSE;
444 con &= ~CON_RXDMA_ACTIVE;
445
446 if (any_tx_active(i2s))
447 mod |= MOD_TXONLY;
448 else
449 con &= ~CON_ACTIVE;
450 }
451
452 writel(mod, addr + I2SMOD);
453 writel(con, addr + I2SCON);
454}
455
456/* Flush FIFO of an interface */
457static inline void i2s_fifo(struct i2s_dai *i2s, u32 flush)
458{
459 void __iomem *fic;
460 u32 val;
461
462 if (!i2s)
463 return;
464
465 if (is_secondary(i2s))
466 fic = i2s->addr + I2SFICS;
467 else
468 fic = i2s->addr + I2SFIC;
469
470 /* Flush the FIFO */
471 writel(readl(fic) | flush, fic);
472
473 /* Be patient */
474 val = msecs_to_loops(1) / 1000; /* 1 usec */
475 while (--val)
476 cpu_relax();
477
478 writel(readl(fic) & ~flush, fic);
479}
480
481static int i2s_set_sysclk(struct snd_soc_dai *dai,
482 int clk_id, unsigned int rfs, int dir)
483{
484 struct i2s_dai *i2s = to_info(dai);
485 struct i2s_dai *other = i2s->pri_dai ? : i2s->sec_dai;
486 u32 mod = readl(i2s->addr + I2SMOD);
487
488 switch (clk_id) {
489 case SAMSUNG_I2S_CDCLK:
490 /* Shouldn't matter in GATING(CLOCK_IN) mode */
491 if (dir == SND_SOC_CLOCK_IN)
492 rfs = 0;
493
494 if ((rfs && other->rfs && (other->rfs != rfs)) ||
495 (any_active(i2s) &&
496 (((dir == SND_SOC_CLOCK_IN)
497 && !(mod & MOD_CDCLKCON)) ||
498 ((dir == SND_SOC_CLOCK_OUT)
499 && (mod & MOD_CDCLKCON))))) {
500 dev_err(&i2s->pdev->dev,
501 "%s:%d Other DAI busy\n", __func__, __LINE__);
502 return -EAGAIN;
503 }
504
505 if (dir == SND_SOC_CLOCK_IN)
506 mod |= MOD_CDCLKCON;
507 else
508 mod &= ~MOD_CDCLKCON;
509
510 i2s->rfs = rfs;
511 break;
512
513 case SAMSUNG_I2S_RCLKSRC_0: /* clock corrsponding to IISMOD[10] := 0 */
514 case SAMSUNG_I2S_RCLKSRC_1: /* clock corrsponding to IISMOD[10] := 1 */
515 if ((i2s->quirks & QUIRK_NO_MUXPSR)
516 || (clk_id == SAMSUNG_I2S_RCLKSRC_0))
517 clk_id = 0;
518 else
519 clk_id = 1;
520
521 if (!any_active(i2s)) {
522 if (i2s->op_clk) {
523 if ((clk_id && !(mod & MOD_IMS_SYSMUX)) ||
524 (!clk_id && (mod & MOD_IMS_SYSMUX))) {
525 clk_disable(i2s->op_clk);
526 clk_put(i2s->op_clk);
527 } else {
528 i2s->rclk_srcrate =
529 clk_get_rate(i2s->op_clk);
530 return 0;
531 }
532 }
533
534 i2s->op_clk = clk_get(&i2s->pdev->dev,
535 i2s->src_clk[clk_id]);
536 clk_enable(i2s->op_clk);
537 i2s->rclk_srcrate = clk_get_rate(i2s->op_clk);
538
539 /* Over-ride the other's */
540 if (other) {
541 other->op_clk = i2s->op_clk;
542 other->rclk_srcrate = i2s->rclk_srcrate;
543 }
544 } else if ((!clk_id && (mod & MOD_IMS_SYSMUX))
545 || (clk_id && !(mod & MOD_IMS_SYSMUX))) {
546 dev_err(&i2s->pdev->dev,
547 "%s:%d Other DAI busy\n", __func__, __LINE__);
548 return -EAGAIN;
549 } else {
550 /* Call can't be on the active DAI */
551 i2s->op_clk = other->op_clk;
552 i2s->rclk_srcrate = other->rclk_srcrate;
553 return 0;
554 }
555
556 if (clk_id == 0)
557 mod &= ~MOD_IMS_SYSMUX;
558 else
559 mod |= MOD_IMS_SYSMUX;
560 break;
561
562 default:
563 dev_err(&i2s->pdev->dev, "We don't serve that!\n");
564 return -EINVAL;
565 }
566
567 writel(mod, i2s->addr + I2SMOD);
568
569 return 0;
570}
571
572static int i2s_set_fmt(struct snd_soc_dai *dai,
573 unsigned int fmt)
574{
575 struct i2s_dai *i2s = to_info(dai);
576 u32 mod = readl(i2s->addr + I2SMOD);
577 u32 tmp = 0;
578
579 /* Format is priority */
580 switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
581 case SND_SOC_DAIFMT_RIGHT_J:
582 tmp |= MOD_LR_RLOW;
583 tmp |= MOD_SDF_MSB;
584 break;
585 case SND_SOC_DAIFMT_LEFT_J:
586 tmp |= MOD_LR_RLOW;
587 tmp |= MOD_SDF_LSB;
588 break;
589 case SND_SOC_DAIFMT_I2S:
590 tmp |= MOD_SDF_IIS;
591 break;
592 default:
593 dev_err(&i2s->pdev->dev, "Format not supported\n");
594 return -EINVAL;
595 }
596
597 /*
598 * INV flag is relative to the FORMAT flag - if set it simply
599 * flips the polarity specified by the Standard
600 */
601 switch (fmt & SND_SOC_DAIFMT_INV_MASK) {
602 case SND_SOC_DAIFMT_NB_NF:
603 break;
604 case SND_SOC_DAIFMT_NB_IF:
605 if (tmp & MOD_LR_RLOW)
606 tmp &= ~MOD_LR_RLOW;
607 else
608 tmp |= MOD_LR_RLOW;
609 break;
610 default:
611 dev_err(&i2s->pdev->dev, "Polarity not supported\n");
612 return -EINVAL;
613 }
614
615 switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
616 case SND_SOC_DAIFMT_CBM_CFM:
617 tmp |= MOD_SLAVE;
618 break;
619 case SND_SOC_DAIFMT_CBS_CFS:
620 /* Set default source clock in Master mode */
621 if (i2s->rclk_srcrate == 0)
622 i2s_set_sysclk(dai, SAMSUNG_I2S_RCLKSRC_0,
623 0, SND_SOC_CLOCK_IN);
624 break;
625 default:
626 dev_err(&i2s->pdev->dev, "master/slave format not supported\n");
627 return -EINVAL;
628 }
629
630 if (any_active(i2s) &&
631 ((mod & (MOD_SDF_MASK | MOD_LR_RLOW
632 | MOD_SLAVE)) != tmp)) {
633 dev_err(&i2s->pdev->dev,
634 "%s:%d Other DAI busy\n", __func__, __LINE__);
635 return -EAGAIN;
636 }
637
638 mod &= ~(MOD_SDF_MASK | MOD_LR_RLOW | MOD_SLAVE);
639 mod |= tmp;
640 writel(mod, i2s->addr + I2SMOD);
641
642 return 0;
643}
644
645static int i2s_hw_params(struct snd_pcm_substream *substream,
646 struct snd_pcm_hw_params *params, struct snd_soc_dai *dai)
647{
648 struct i2s_dai *i2s = to_info(dai);
649 u32 mod = readl(i2s->addr + I2SMOD);
650
651 if (!is_secondary(i2s))
652 mod &= ~(MOD_DC2_EN | MOD_DC1_EN);
653
654 switch (params_channels(params)) {
655 case 6:
656 mod |= MOD_DC2_EN;
657 case 4:
658 mod |= MOD_DC1_EN;
659 break;
660 case 2:
661 break;
662 default:
663 dev_err(&i2s->pdev->dev, "%d channels not supported\n",
664 params_channels(params));
665 return -EINVAL;
666 }
667
668 if (is_secondary(i2s))
669 mod &= ~MOD_BLCS_MASK;
670 else
671 mod &= ~MOD_BLCP_MASK;
672
673 if (is_manager(i2s))
674 mod &= ~MOD_BLC_MASK;
675
676 switch (params_format(params)) {
677 case SNDRV_PCM_FORMAT_S8:
678 if (is_secondary(i2s))
679 mod |= MOD_BLCS_8BIT;
680 else
681 mod |= MOD_BLCP_8BIT;
682 if (is_manager(i2s))
683 mod |= MOD_BLC_8BIT;
684 break;
685 case SNDRV_PCM_FORMAT_S16_LE:
686 if (is_secondary(i2s))
687 mod |= MOD_BLCS_16BIT;
688 else
689 mod |= MOD_BLCP_16BIT;
690 if (is_manager(i2s))
691 mod |= MOD_BLC_16BIT;
692 break;
693 case SNDRV_PCM_FORMAT_S24_LE:
694 if (is_secondary(i2s))
695 mod |= MOD_BLCS_24BIT;
696 else
697 mod |= MOD_BLCP_24BIT;
698 if (is_manager(i2s))
699 mod |= MOD_BLC_24BIT;
700 break;
701 default:
702 dev_err(&i2s->pdev->dev, "Format(%d) not supported\n",
703 params_format(params));
704 return -EINVAL;
705 }
706 writel(mod, i2s->addr + I2SMOD);
707
708 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
709 snd_soc_dai_set_dma_data(dai, substream,
710 (void *)&i2s->dma_playback);
711 else
712 snd_soc_dai_set_dma_data(dai, substream,
713 (void *)&i2s->dma_capture);
714
715 i2s->frmclk = params_rate(params);
716
717 return 0;
718}
719
720/* We set constraints on the substream acc to the version of I2S */
721static int i2s_startup(struct snd_pcm_substream *substream,
722 struct snd_soc_dai *dai)
723{
724 struct i2s_dai *i2s = to_info(dai);
725 struct i2s_dai *other = i2s->pri_dai ? : i2s->sec_dai;
726 unsigned long flags;
727
728 spin_lock_irqsave(&lock, flags);
729
730 i2s->mode |= DAI_OPENED;
731
732 if (is_manager(other))
733 i2s->mode &= ~DAI_MANAGER;
734 else
735 i2s->mode |= DAI_MANAGER;
736
737 /* Enforce set_sysclk in Master mode */
738 i2s->rclk_srcrate = 0;
739
740 spin_unlock_irqrestore(&lock, flags);
741
742 return 0;
743}
744
745static void i2s_shutdown(struct snd_pcm_substream *substream,
746 struct snd_soc_dai *dai)
747{
748 struct i2s_dai *i2s = to_info(dai);
749 struct i2s_dai *other = i2s->pri_dai ? : i2s->sec_dai;
750 unsigned long flags;
751
752 spin_lock_irqsave(&lock, flags);
753
754 i2s->mode &= ~DAI_OPENED;
755 i2s->mode &= ~DAI_MANAGER;
756
757 if (is_opened(other))
758 other->mode |= DAI_MANAGER;
759
760 /* Reset any constraint on RFS and BFS */
761 i2s->rfs = 0;
762 i2s->bfs = 0;
763
764 spin_unlock_irqrestore(&lock, flags);
765
766 /* Gate CDCLK by default */
767 if (!is_opened(other))
768 i2s_set_sysclk(dai, SAMSUNG_I2S_CDCLK,
769 0, SND_SOC_CLOCK_IN);
770}
771
772static int config_setup(struct i2s_dai *i2s)
773{
774 struct i2s_dai *other = i2s->pri_dai ? : i2s->sec_dai;
775 unsigned rfs, bfs, blc;
776 u32 psr;
777
778 blc = get_blc(i2s);
779
780 bfs = i2s->bfs;
781
782 if (!bfs && other)
783 bfs = other->bfs;
784
785 /* Select least possible multiple(2) if no constraint set */
786 if (!bfs)
787 bfs = blc * 2;
788
789 rfs = i2s->rfs;
790
791 if (!rfs && other)
792 rfs = other->rfs;
793
794 if ((rfs == 256 || rfs == 512) && (blc == 24)) {
795 dev_err(&i2s->pdev->dev,
796 "%d-RFS not supported for 24-blc\n", rfs);
797 return -EINVAL;
798 }
799
800 if (!rfs) {
801 if (bfs == 16 || bfs == 32)
802 rfs = 256;
803 else
804 rfs = 384;
805 }
806
807 /* If already setup and running */
808 if (any_active(i2s) && (get_rfs(i2s) != rfs || get_bfs(i2s) != bfs)) {
809 dev_err(&i2s->pdev->dev,
810 "%s:%d Other DAI busy\n", __func__, __LINE__);
811 return -EAGAIN;
812 }
813
814 /* Don't bother RFS, BFS & PSR in Slave mode */
815 if (is_slave(i2s))
816 return 0;
817
818 set_bfs(i2s, bfs);
819 set_rfs(i2s, rfs);
820
821 if (!(i2s->quirks & QUIRK_NO_MUXPSR)) {
822 psr = i2s->rclk_srcrate / i2s->frmclk / rfs;
823 writel(((psr - 1) << 8) | PSR_PSREN, i2s->addr + I2SPSR);
824 dev_dbg(&i2s->pdev->dev,
825 "RCLK_SRC=%luHz PSR=%u, RCLK=%dfs, BCLK=%dfs\n",
826 i2s->rclk_srcrate, psr, rfs, bfs);
827 }
828
829 return 0;
830}
831
832static int i2s_trigger(struct snd_pcm_substream *substream,
833 int cmd, struct snd_soc_dai *dai)
834{
835 int capture = (substream->stream == SNDRV_PCM_STREAM_CAPTURE);
836 struct snd_soc_pcm_runtime *rtd = substream->private_data;
837 struct i2s_dai *i2s = to_info(rtd->cpu_dai);
838 unsigned long flags;
839
840 switch (cmd) {
841 case SNDRV_PCM_TRIGGER_START:
842 case SNDRV_PCM_TRIGGER_RESUME:
843 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
844 local_irq_save(flags);
845
846 if (config_setup(i2s)) {
847 local_irq_restore(flags);
848 return -EINVAL;
849 }
850
851 if (capture)
852 i2s_rxctrl(i2s, 1);
853 else
854 i2s_txctrl(i2s, 1);
855
856 local_irq_restore(flags);
857 break;
858 case SNDRV_PCM_TRIGGER_STOP:
859 case SNDRV_PCM_TRIGGER_SUSPEND:
860 case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
861 local_irq_save(flags);
862
863 if (capture)
864 i2s_rxctrl(i2s, 0);
865 else
866 i2s_txctrl(i2s, 0);
867
868 if (capture)
869 i2s_fifo(i2s, FIC_RXFLUSH);
870 else
871 i2s_fifo(i2s, FIC_TXFLUSH);
872
873 local_irq_restore(flags);
874 break;
875 }
876
877 return 0;
878}
879
880static int i2s_set_clkdiv(struct snd_soc_dai *dai,
881 int div_id, int div)
882{
883 struct i2s_dai *i2s = to_info(dai);
884 struct i2s_dai *other = i2s->pri_dai ? : i2s->sec_dai;
885
886 switch (div_id) {
887 case SAMSUNG_I2S_DIV_BCLK:
888 if ((any_active(i2s) && div && (get_bfs(i2s) != div))
889 || (other && other->bfs && (other->bfs != div))) {
890 dev_err(&i2s->pdev->dev,
891 "%s:%d Other DAI busy\n", __func__, __LINE__);
892 return -EAGAIN;
893 }
894 i2s->bfs = div;
895 break;
896 default:
897 dev_err(&i2s->pdev->dev,
898 "Invalid clock divider(%d)\n", div_id);
899 return -EINVAL;
900 }
901
902 return 0;
903}
904
905static snd_pcm_sframes_t
906i2s_delay(struct snd_pcm_substream *substream, struct snd_soc_dai *dai)
907{
908 struct i2s_dai *i2s = to_info(dai);
909 u32 reg = readl(i2s->addr + I2SFIC);
910 snd_pcm_sframes_t delay;
911
912 if (substream->stream == SNDRV_PCM_STREAM_CAPTURE)
913 delay = FIC_RXCOUNT(reg);
914 else if (is_secondary(i2s))
915 delay = FICS_TXCOUNT(readl(i2s->addr + I2SFICS));
916 else
917 delay = FIC_TXCOUNT(reg);
918
919 return delay;
920}
921
922#ifdef CONFIG_PM
923static int i2s_suspend(struct snd_soc_dai *dai)
924{
925 struct i2s_dai *i2s = to_info(dai);
926
927 if (dai->active) {
928 i2s->suspend_i2smod = readl(i2s->addr + I2SMOD);
929 i2s->suspend_i2scon = readl(i2s->addr + I2SCON);
930 i2s->suspend_i2spsr = readl(i2s->addr + I2SPSR);
931 }
932
933 return 0;
934}
935
936static int i2s_resume(struct snd_soc_dai *dai)
937{
938 struct i2s_dai *i2s = to_info(dai);
939
940 if (dai->active) {
941 writel(i2s->suspend_i2scon, i2s->addr + I2SCON);
942 writel(i2s->suspend_i2smod, i2s->addr + I2SMOD);
943 writel(i2s->suspend_i2spsr, i2s->addr + I2SPSR);
944 }
945
946 return 0;
947}
948#else
949#define i2s_suspend NULL
950#define i2s_resume NULL
951#endif
952
953static int samsung_i2s_dai_probe(struct snd_soc_dai *dai)
954{
955 struct i2s_dai *i2s = to_info(dai);
956 struct i2s_dai *other = i2s->pri_dai ? : i2s->sec_dai;
957
958 if (other && other->clk) /* If this is probe on secondary */
959 goto probe_exit;
960
961 i2s->addr = ioremap(i2s->base, 0x100);
962 if (i2s->addr == NULL) {
963 dev_err(&i2s->pdev->dev, "cannot ioremap registers\n");
964 return -ENXIO;
965 }
966
967 i2s->clk = clk_get(&i2s->pdev->dev, "iis");
968 if (IS_ERR(i2s->clk)) {
969 dev_err(&i2s->pdev->dev, "failed to get i2s_clock\n");
970 iounmap(i2s->addr);
971 return -ENOENT;
972 }
973 clk_enable(i2s->clk);
974
975 if (other) {
976 other->addr = i2s->addr;
977 other->clk = i2s->clk;
978 }
979
980 if (i2s->quirks & QUIRK_NEED_RSTCLR)
981 writel(CON_RSTCLR, i2s->addr + I2SCON);
982
983probe_exit:
984 /* Reset any constraint on RFS and BFS */
985 i2s->rfs = 0;
986 i2s->bfs = 0;
987 i2s_txctrl(i2s, 0);
988 i2s_rxctrl(i2s, 0);
989 i2s_fifo(i2s, FIC_TXFLUSH);
990 i2s_fifo(other, FIC_TXFLUSH);
991 i2s_fifo(i2s, FIC_RXFLUSH);
992
993 /* Gate CDCLK by default */
994 if (!is_opened(other))
995 i2s_set_sysclk(dai, SAMSUNG_I2S_CDCLK,
996 0, SND_SOC_CLOCK_IN);
997
998 return 0;
999}
1000
1001static int samsung_i2s_dai_remove(struct snd_soc_dai *dai)
1002{
1003 struct i2s_dai *i2s = snd_soc_dai_get_drvdata(dai);
1004 struct i2s_dai *other = i2s->pri_dai ? : i2s->sec_dai;
1005
1006 if (!other || !other->clk) {
1007
1008 if (i2s->quirks & QUIRK_NEED_RSTCLR)
1009 writel(0, i2s->addr + I2SCON);
1010
1011 clk_disable(i2s->clk);
1012 clk_put(i2s->clk);
1013
1014 iounmap(i2s->addr);
1015 }
1016
1017 i2s->clk = NULL;
1018
1019 return 0;
1020}
1021
1022static struct snd_soc_dai_ops samsung_i2s_dai_ops = {
1023 .trigger = i2s_trigger,
1024 .hw_params = i2s_hw_params,
1025 .set_fmt = i2s_set_fmt,
1026 .set_clkdiv = i2s_set_clkdiv,
1027 .set_sysclk = i2s_set_sysclk,
1028 .startup = i2s_startup,
1029 .shutdown = i2s_shutdown,
1030 .delay = i2s_delay,
1031};
1032
1033#define SAMSUNG_I2S_RATES SNDRV_PCM_RATE_8000_96000
1034
1035#define SAMSUNG_I2S_FMTS (SNDRV_PCM_FMTBIT_S8 | \
1036 SNDRV_PCM_FMTBIT_S16_LE | \
1037 SNDRV_PCM_FMTBIT_S24_LE)
1038
1039static __devinit
1040struct i2s_dai *i2s_alloc_dai(struct platform_device *pdev, bool sec)
1041{
1042 struct i2s_dai *i2s;
1043
1044 i2s = kzalloc(sizeof(struct i2s_dai), GFP_KERNEL);
1045 if (i2s == NULL)
1046 return NULL;
1047
1048 i2s->pdev = pdev;
1049 i2s->pri_dai = NULL;
1050 i2s->sec_dai = NULL;
1051 i2s->i2s_dai_drv.symmetric_rates = 1;
1052 i2s->i2s_dai_drv.probe = samsung_i2s_dai_probe;
1053 i2s->i2s_dai_drv.remove = samsung_i2s_dai_remove;
1054 i2s->i2s_dai_drv.ops = &samsung_i2s_dai_ops;
1055 i2s->i2s_dai_drv.suspend = i2s_suspend;
1056 i2s->i2s_dai_drv.resume = i2s_resume;
1057 i2s->i2s_dai_drv.playback.channels_min = 2;
1058 i2s->i2s_dai_drv.playback.channels_max = 2;
1059 i2s->i2s_dai_drv.playback.rates = SAMSUNG_I2S_RATES;
1060 i2s->i2s_dai_drv.playback.formats = SAMSUNG_I2S_FMTS;
1061
1062 if (!sec) {
1063 i2s->i2s_dai_drv.capture.channels_min = 2;
1064 i2s->i2s_dai_drv.capture.channels_max = 2;
1065 i2s->i2s_dai_drv.capture.rates = SAMSUNG_I2S_RATES;
1066 i2s->i2s_dai_drv.capture.formats = SAMSUNG_I2S_FMTS;
1067 } else { /* Create a new platform_device for Secondary */
1068 i2s->pdev = platform_device_register_resndata(NULL,
1069 pdev->name, pdev->id + SAMSUNG_I2S_SECOFF,
1070 NULL, 0, NULL, 0);
1071 if (IS_ERR(i2s->pdev)) {
1072 kfree(i2s);
1073 return NULL;
1074 }
1075 }
1076
1077 /* Pre-assign snd_soc_dai_set_drvdata */
1078 dev_set_drvdata(&i2s->pdev->dev, i2s);
1079
1080 return i2s;
1081}
1082
1083static __devinit int samsung_i2s_probe(struct platform_device *pdev)
1084{
1085 u32 dma_pl_chan, dma_cp_chan, dma_pl_sec_chan;
1086 struct i2s_dai *pri_dai, *sec_dai = NULL;
1087 struct s3c_audio_pdata *i2s_pdata;
1088 struct samsung_i2s *i2s_cfg;
1089 struct resource *res;
1090 u32 regs_base, quirks;
1091 int ret = 0;
1092
1093 /* Call during Seconday interface registration */
1094 if (pdev->id >= SAMSUNG_I2S_SECOFF) {
1095 sec_dai = dev_get_drvdata(&pdev->dev);
1096 snd_soc_register_dai(&sec_dai->pdev->dev,
1097 &sec_dai->i2s_dai_drv);
1098 return 0;
1099 }
1100
1101 i2s_pdata = pdev->dev.platform_data;
1102 if (i2s_pdata == NULL) {
1103 dev_err(&pdev->dev, "Can't work without s3c_audio_pdata\n");
1104 return -EINVAL;
1105 }
1106
1107 res = platform_get_resource(pdev, IORESOURCE_DMA, 0);
1108 if (!res) {
1109 dev_err(&pdev->dev, "Unable to get I2S-TX dma resource\n");
1110 return -ENXIO;
1111 }
1112 dma_pl_chan = res->start;
1113
1114 res = platform_get_resource(pdev, IORESOURCE_DMA, 1);
1115 if (!res) {
1116 dev_err(&pdev->dev, "Unable to get I2S-RX dma resource\n");
1117 return -ENXIO;
1118 }
1119 dma_cp_chan = res->start;
1120
1121 res = platform_get_resource(pdev, IORESOURCE_DMA, 2);
1122 if (res)
1123 dma_pl_sec_chan = res->start;
1124 else
1125 dma_pl_sec_chan = 0;
1126
1127 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1128 if (!res) {
1129 dev_err(&pdev->dev, "Unable to get I2S SFR address\n");
1130 return -ENXIO;
1131 }
1132
1133 if (!request_mem_region(res->start, resource_size(res),
1134 "samsung-i2s")) {
1135 dev_err(&pdev->dev, "Unable to request SFR region\n");
1136 return -EBUSY;
1137 }
1138 regs_base = res->start;
1139
1140 i2s_cfg = &i2s_pdata->type.i2s;
1141 quirks = i2s_cfg->quirks;
1142
1143 pri_dai = i2s_alloc_dai(pdev, false);
1144 if (!pri_dai) {
1145 dev_err(&pdev->dev, "Unable to alloc I2S_pri\n");
1146 ret = -ENOMEM;
1147 goto err1;
1148 }
1149
1150 pri_dai->dma_playback.dma_addr = regs_base + I2STXD;
1151 pri_dai->dma_capture.dma_addr = regs_base + I2SRXD;
1152 pri_dai->dma_playback.client =
1153 (struct s3c2410_dma_client *)&pri_dai->dma_playback;
1154 pri_dai->dma_capture.client =
1155 (struct s3c2410_dma_client *)&pri_dai->dma_capture;
1156 pri_dai->dma_playback.channel = dma_pl_chan;
1157 pri_dai->dma_capture.channel = dma_cp_chan;
1158 pri_dai->src_clk = i2s_cfg->src_clk;
1159 pri_dai->dma_playback.dma_size = 4;
1160 pri_dai->dma_capture.dma_size = 4;
1161 pri_dai->base = regs_base;
1162 pri_dai->quirks = quirks;
1163
1164 if (quirks & QUIRK_PRI_6CHAN)
1165 pri_dai->i2s_dai_drv.playback.channels_max = 6;
1166
1167 if (quirks & QUIRK_SEC_DAI) {
1168 sec_dai = i2s_alloc_dai(pdev, true);
1169 if (!sec_dai) {
1170 dev_err(&pdev->dev, "Unable to alloc I2S_sec\n");
1171 ret = -ENOMEM;
1172 goto err2;
1173 }
1174 sec_dai->dma_playback.dma_addr = regs_base + I2STXDS;
1175 sec_dai->dma_playback.client =
1176 (struct s3c2410_dma_client *)&sec_dai->dma_playback;
1177 /* Use iDMA always if SysDMA not provided */
1178 sec_dai->dma_playback.channel = dma_pl_sec_chan ? : -1;
1179 sec_dai->src_clk = i2s_cfg->src_clk;
1180 sec_dai->dma_playback.dma_size = 4;
1181 sec_dai->base = regs_base;
1182 sec_dai->quirks = quirks;
1183 sec_dai->pri_dai = pri_dai;
1184 pri_dai->sec_dai = sec_dai;
1185 }
1186
1187 if (i2s_pdata->cfg_gpio && i2s_pdata->cfg_gpio(pdev)) {
1188 dev_err(&pdev->dev, "Unable to configure gpio\n");
1189 ret = -EINVAL;
1190 goto err3;
1191 }
1192
1193 snd_soc_register_dai(&pri_dai->pdev->dev, &pri_dai->i2s_dai_drv);
1194
1195 return 0;
1196err3:
1197 kfree(sec_dai);
1198err2:
1199 kfree(pri_dai);
1200err1:
1201 release_mem_region(regs_base, resource_size(res));
1202
1203 return ret;
1204}
1205
1206static __devexit int samsung_i2s_remove(struct platform_device *pdev)
1207{
1208 struct i2s_dai *i2s, *other;
1209
1210 i2s = dev_get_drvdata(&pdev->dev);
1211 other = i2s->pri_dai ? : i2s->sec_dai;
1212
1213 if (other) {
1214 other->pri_dai = NULL;
1215 other->sec_dai = NULL;
1216 } else {
1217 struct resource *res;
1218 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1219 if (res)
1220 release_mem_region(res->start, resource_size(res));
1221 }
1222
1223 i2s->pri_dai = NULL;
1224 i2s->sec_dai = NULL;
1225
1226 kfree(i2s);
1227
1228 snd_soc_unregister_dai(&pdev->dev);
1229
1230 return 0;
1231}
1232
1233static struct platform_driver samsung_i2s_driver = {
1234 .probe = samsung_i2s_probe,
1235 .remove = samsung_i2s_remove,
1236 .driver = {
1237 .name = "samsung-i2s",
1238 .owner = THIS_MODULE,
1239 },
1240};
1241
1242static int __init samsung_i2s_init(void)
1243{
1244 return platform_driver_register(&samsung_i2s_driver);
1245}
1246module_init(samsung_i2s_init);
1247
1248static void __exit samsung_i2s_exit(void)
1249{
1250 platform_driver_unregister(&samsung_i2s_driver);
1251}
1252module_exit(samsung_i2s_exit);
1253
1254/* Module information */
1255MODULE_AUTHOR("Jaswinder Singh, <jassi.brar@samsung.com>");
1256MODULE_DESCRIPTION("Samsung I2S Interface");
1257MODULE_ALIAS("platform:samsung-i2s");
1258MODULE_LICENSE("GPL");
diff --git a/sound/soc/samsung/i2s.h b/sound/soc/samsung/i2s.h
new file mode 100644
index 000000000000..8e15f6a616d1
--- /dev/null
+++ b/sound/soc/samsung/i2s.h
@@ -0,0 +1,29 @@
1/* sound/soc/samsung/i2s.h
2 *
3 * ALSA SoC Audio Layer - Samsung I2S Controller driver
4 *
5 * Copyright (c) 2010 Samsung Electronics Co. Ltd.
6 * Jaswinder Singh <jassi.brar@samsung.com>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation.
11 */
12
13#ifndef __SND_SOC_SAMSUNG_I2S_H
14#define __SND_SOC_SAMSUNG_I2S_H
15
16/*
17 * Maximum number of I2S blocks that any SoC can have.
18 * The secondary interface of a CPU dai(if there exists any),
19 * is indexed at [cpu-dai's ID + SAMSUNG_I2S_SECOFF]
20 */
21#define SAMSUNG_I2S_SECOFF 4
22
23#define SAMSUNG_I2S_DIV_BCLK 1
24
25#define SAMSUNG_I2S_RCLKSRC_0 0
26#define SAMSUNG_I2S_RCLKSRC_1 1
27#define SAMSUNG_I2S_CDCLK 2
28
29#endif /* __SND_SOC_SAMSUNG_I2S_H */
diff --git a/sound/soc/s3c24xx/jive_wm8750.c b/sound/soc/samsung/jive_wm8750.c
index 49605cd83947..08802520e014 100644
--- a/sound/soc/s3c24xx/jive_wm8750.c
+++ b/sound/soc/samsung/jive_wm8750.c
@@ -1,4 +1,4 @@
1/* sound/soc/s3c24xx/jive_wm8750.c 1/* sound/soc/samsung/jive_wm8750.c
2 * 2 *
3 * Copyright 2007,2008 Simtec Electronics 3 * Copyright 2007,2008 Simtec Electronics
4 * 4 *
@@ -21,11 +21,10 @@
21#include <sound/core.h> 21#include <sound/core.h>
22#include <sound/pcm.h> 22#include <sound/pcm.h>
23#include <sound/soc.h> 23#include <sound/soc.h>
24#include <sound/soc-dapm.h>
25 24
26#include <asm/mach-types.h> 25#include <asm/mach-types.h>
27 26
28#include "s3c-dma.h" 27#include "dma.h"
29#include "s3c2412-i2s.h" 28#include "s3c2412-i2s.h"
30 29
31#include "../codecs/wm8750.h" 30#include "../codecs/wm8750.h"
@@ -111,18 +110,19 @@ static struct snd_soc_ops jive_ops = {
111static int jive_wm8750_init(struct snd_soc_pcm_runtime *rtd) 110static int jive_wm8750_init(struct snd_soc_pcm_runtime *rtd)
112{ 111{
113 struct snd_soc_codec *codec = rtd->codec; 112 struct snd_soc_codec *codec = rtd->codec;
113 struct snd_soc_dapm_context *dapm = &codec->dapm;
114 int err; 114 int err;
115 115
116 /* These endpoints are not being used. */ 116 /* These endpoints are not being used. */
117 snd_soc_dapm_nc_pin(codec, "LINPUT2"); 117 snd_soc_dapm_nc_pin(dapm, "LINPUT2");
118 snd_soc_dapm_nc_pin(codec, "RINPUT2"); 118 snd_soc_dapm_nc_pin(dapm, "RINPUT2");
119 snd_soc_dapm_nc_pin(codec, "LINPUT3"); 119 snd_soc_dapm_nc_pin(dapm, "LINPUT3");
120 snd_soc_dapm_nc_pin(codec, "RINPUT3"); 120 snd_soc_dapm_nc_pin(dapm, "RINPUT3");
121 snd_soc_dapm_nc_pin(codec, "OUT3"); 121 snd_soc_dapm_nc_pin(dapm, "OUT3");
122 snd_soc_dapm_nc_pin(codec, "MONO"); 122 snd_soc_dapm_nc_pin(dapm, "MONO");
123 123
124 /* Add jive specific widgets */ 124 /* Add jive specific widgets */
125 err = snd_soc_dapm_new_controls(codec, wm8750_dapm_widgets, 125 err = snd_soc_dapm_new_controls(dapm, wm8750_dapm_widgets,
126 ARRAY_SIZE(wm8750_dapm_widgets)); 126 ARRAY_SIZE(wm8750_dapm_widgets));
127 if (err) { 127 if (err) {
128 printk(KERN_ERR "%s: failed to add widgets (%d)\n", 128 printk(KERN_ERR "%s: failed to add widgets (%d)\n",
@@ -130,8 +130,8 @@ static int jive_wm8750_init(struct snd_soc_pcm_runtime *rtd)
130 return err; 130 return err;
131 } 131 }
132 132
133 snd_soc_dapm_add_routes(codec, audio_map, ARRAY_SIZE(audio_map)); 133 snd_soc_dapm_add_routes(dapm, audio_map, ARRAY_SIZE(audio_map));
134 snd_soc_dapm_sync(codec); 134 snd_soc_dapm_sync(dapm);
135 135
136 return 0; 136 return 0;
137} 137}
@@ -141,7 +141,7 @@ static struct snd_soc_dai_link jive_dai = {
141 .stream_name = "WM8750", 141 .stream_name = "WM8750",
142 .cpu_dai_name = "s3c2412-i2s", 142 .cpu_dai_name = "s3c2412-i2s",
143 .codec_dai_name = "wm8750-hifi", 143 .codec_dai_name = "wm8750-hifi",
144 .platform_name = "s3c24xx-pcm-audio", 144 .platform_name = "samsung-audio",
145 .codec_name = "wm8750-codec.0-0x1a", 145 .codec_name = "wm8750-codec.0-0x1a",
146 .init = jive_wm8750_init, 146 .init = jive_wm8750_init,
147 .ops = &jive_ops, 147 .ops = &jive_ops,
diff --git a/sound/soc/s3c24xx/lm4857.h b/sound/soc/samsung/lm4857.h
index 0cf5b7011d6f..0cf5b7011d6f 100644
--- a/sound/soc/s3c24xx/lm4857.h
+++ b/sound/soc/samsung/lm4857.h
diff --git a/sound/soc/s3c24xx/ln2440sbc_alc650.c b/sound/soc/samsung/ln2440sbc_alc650.c
index abe64abe8c84..a2bb34def740 100644
--- a/sound/soc/s3c24xx/ln2440sbc_alc650.c
+++ b/sound/soc/samsung/ln2440sbc_alc650.c
@@ -21,10 +21,9 @@
21#include <sound/core.h> 21#include <sound/core.h>
22#include <sound/pcm.h> 22#include <sound/pcm.h>
23#include <sound/soc.h> 23#include <sound/soc.h>
24#include <sound/soc-dapm.h>
25 24
26#include "s3c-dma.h" 25#include "dma.h"
27#include "s3c-ac97.h" 26#include "ac97.h"
28 27
29static struct snd_soc_card ln2440sbc; 28static struct snd_soc_card ln2440sbc;
30 29
@@ -32,10 +31,10 @@ static struct snd_soc_dai_link ln2440sbc_dai[] = {
32{ 31{
33 .name = "AC97", 32 .name = "AC97",
34 .stream_name = "AC97 HiFi", 33 .stream_name = "AC97 HiFi",
35 .cpu_dai_name = "s3c-ac97", 34 .cpu_dai_name = "samsung-ac97",
36 .codec_dai_name = "ac97-hifi", 35 .codec_dai_name = "ac97-hifi",
37 .codec_name = "ac97-codec", 36 .codec_name = "ac97-codec",
38 .platform_name = "s3c24xx-pcm-audio", 37 .platform_name = "samsung-audio",
39}, 38},
40}; 39};
41 40
diff --git a/sound/soc/s3c24xx/neo1973_gta02_wm8753.c b/sound/soc/samsung/neo1973_gta02_wm8753.c
index e97bdf150a03..3eec610c10f9 100644
--- a/sound/soc/s3c24xx/neo1973_gta02_wm8753.c
+++ b/sound/soc/samsung/neo1973_gta02_wm8753.c
@@ -22,7 +22,6 @@
22#include <sound/core.h> 22#include <sound/core.h>
23#include <sound/pcm.h> 23#include <sound/pcm.h>
24#include <sound/soc.h> 24#include <sound/soc.h>
25#include <sound/soc-dapm.h>
26 25
27#include <asm/mach-types.h> 26#include <asm/mach-types.h>
28 27
@@ -32,7 +31,7 @@
32#include <asm/io.h> 31#include <asm/io.h>
33#include <mach/gta02.h> 32#include <mach/gta02.h>
34#include "../codecs/wm8753.h" 33#include "../codecs/wm8753.h"
35#include "s3c-dma.h" 34#include "dma.h"
36#include "s3c24xx-i2s.h" 35#include "s3c24xx-i2s.h"
37 36
38static struct snd_soc_card neo1973_gta02; 37static struct snd_soc_card neo1973_gta02;
@@ -333,16 +332,17 @@ static const struct snd_kcontrol_new wm8753_neo1973_gta02_controls[] = {
333static int neo1973_gta02_wm8753_init(struct snd_soc_pcm_runtime *rtd) 332static int neo1973_gta02_wm8753_init(struct snd_soc_pcm_runtime *rtd)
334{ 333{
335 struct snd_soc_codec *codec = rtd->codec; 334 struct snd_soc_codec *codec = rtd->codec;
335 struct snd_soc_dapm_context *dapm = &codec->dapm;
336 int err; 336 int err;
337 337
338 /* set up NC codec pins */ 338 /* set up NC codec pins */
339 snd_soc_dapm_nc_pin(codec, "OUT3"); 339 snd_soc_dapm_nc_pin(dapm, "OUT3");
340 snd_soc_dapm_nc_pin(codec, "OUT4"); 340 snd_soc_dapm_nc_pin(dapm, "OUT4");
341 snd_soc_dapm_nc_pin(codec, "LINE1"); 341 snd_soc_dapm_nc_pin(dapm, "LINE1");
342 snd_soc_dapm_nc_pin(codec, "LINE2"); 342 snd_soc_dapm_nc_pin(dapm, "LINE2");
343 343
344 /* Add neo1973 gta02 specific widgets */ 344 /* Add neo1973 gta02 specific widgets */
345 snd_soc_dapm_new_controls(codec, wm8753_dapm_widgets, 345 snd_soc_dapm_new_controls(dapm, wm8753_dapm_widgets,
346 ARRAY_SIZE(wm8753_dapm_widgets)); 346 ARRAY_SIZE(wm8753_dapm_widgets));
347 347
348 /* add neo1973 gta02 specific controls */ 348 /* add neo1973 gta02 specific controls */
@@ -353,25 +353,25 @@ static int neo1973_gta02_wm8753_init(struct snd_soc_pcm_runtime *rtd)
353 return err; 353 return err;
354 354
355 /* set up neo1973 gta02 specific audio path audio_map */ 355 /* set up neo1973 gta02 specific audio path audio_map */
356 snd_soc_dapm_add_routes(codec, audio_map, ARRAY_SIZE(audio_map)); 356 snd_soc_dapm_add_routes(dapm, audio_map, ARRAY_SIZE(audio_map));
357 357
358 /* set endpoints to default off mode */ 358 /* set endpoints to default off mode */
359 snd_soc_dapm_disable_pin(codec, "Stereo Out"); 359 snd_soc_dapm_disable_pin(dapm, "Stereo Out");
360 snd_soc_dapm_disable_pin(codec, "GSM Line Out"); 360 snd_soc_dapm_disable_pin(dapm, "GSM Line Out");
361 snd_soc_dapm_disable_pin(codec, "GSM Line In"); 361 snd_soc_dapm_disable_pin(dapm, "GSM Line In");
362 snd_soc_dapm_disable_pin(codec, "Headset Mic"); 362 snd_soc_dapm_disable_pin(dapm, "Headset Mic");
363 snd_soc_dapm_disable_pin(codec, "Handset Mic"); 363 snd_soc_dapm_disable_pin(dapm, "Handset Mic");
364 snd_soc_dapm_disable_pin(codec, "Handset Spk"); 364 snd_soc_dapm_disable_pin(dapm, "Handset Spk");
365 365
366 /* allow audio paths from the GSM modem to run during suspend */ 366 /* allow audio paths from the GSM modem to run during suspend */
367 snd_soc_dapm_ignore_suspend(codec, "Stereo Out"); 367 snd_soc_dapm_ignore_suspend(dapm, "Stereo Out");
368 snd_soc_dapm_ignore_suspend(codec, "GSM Line Out"); 368 snd_soc_dapm_ignore_suspend(dapm, "GSM Line Out");
369 snd_soc_dapm_ignore_suspend(codec, "GSM Line In"); 369 snd_soc_dapm_ignore_suspend(dapm, "GSM Line In");
370 snd_soc_dapm_ignore_suspend(codec, "Headset Mic"); 370 snd_soc_dapm_ignore_suspend(dapm, "Headset Mic");
371 snd_soc_dapm_ignore_suspend(codec, "Handset Mic"); 371 snd_soc_dapm_ignore_suspend(dapm, "Handset Mic");
372 snd_soc_dapm_ignore_suspend(codec, "Handset Spk"); 372 snd_soc_dapm_ignore_suspend(dapm, "Handset Spk");
373 373
374 snd_soc_dapm_sync(codec); 374 snd_soc_dapm_sync(dapm);
375 375
376 return 0; 376 return 0;
377} 377}
@@ -400,7 +400,7 @@ static struct snd_soc_dai_link neo1973_gta02_dai[] = {
400 .cpu_dai_name = "s3c24xx-i2s", 400 .cpu_dai_name = "s3c24xx-i2s",
401 .codec_dai_name = "wm8753-hifi", 401 .codec_dai_name = "wm8753-hifi",
402 .init = neo1973_gta02_wm8753_init, 402 .init = neo1973_gta02_wm8753_init,
403 .platform_name = "s3c24xx-pcm-audio", 403 .platform_name = "samsung-audio",
404 .codec_name = "wm8753-codec.0-0x1a", 404 .codec_name = "wm8753-codec.0-0x1a",
405 .ops = &neo1973_gta02_hifi_ops, 405 .ops = &neo1973_gta02_hifi_ops,
406}, 406},
@@ -411,7 +411,7 @@ static struct snd_soc_dai_link neo1973_gta02_dai[] = {
411 .codec_dai_name = "wm8753-voice", 411 .codec_dai_name = "wm8753-voice",
412 .ops = &neo1973_gta02_voice_ops, 412 .ops = &neo1973_gta02_voice_ops,
413 .codec_name = "wm8753-codec.0-0x1a", 413 .codec_name = "wm8753-codec.0-0x1a",
414 .platform_name = "s3c24xx-pcm-audio", 414 .platform_name = "samsung-audio",
415}, 415},
416}; 416};
417 417
@@ -438,25 +438,21 @@ static int __init neo1973_gta02_init(void)
438 return -ENOMEM; 438 return -ENOMEM;
439 439
440 /* register bluetooth DAI here */ 440 /* register bluetooth DAI here */
441 ret = snd_soc_register_dai(&neo1973_gta02_snd_device->dev, -1, &bt_dai); 441 ret = snd_soc_register_dai(&neo1973_gta02_snd_device->dev, &bt_dai);
442 if (ret) { 442 if (ret)
443 platform_device_put(neo1973_gta02_snd_device); 443 goto err_put_device;
444 return ret;
445 }
446 444
447 platform_set_drvdata(neo1973_gta02_snd_device, &neo1973_gta02); 445 platform_set_drvdata(neo1973_gta02_snd_device, &neo1973_gta02);
448 ret = platform_device_add(neo1973_gta02_snd_device); 446 ret = platform_device_add(neo1973_gta02_snd_device);
449 447
450 if (ret) { 448 if (ret)
451 platform_device_put(neo1973_gta02_snd_device); 449 goto err_unregister_dai;
452 return ret;
453 }
454 450
455 /* Initialise GPIOs used by amp */ 451 /* Initialise GPIOs used by amp */
456 ret = gpio_request(GTA02_GPIO_HP_IN, "GTA02_HP_IN"); 452 ret = gpio_request(GTA02_GPIO_HP_IN, "GTA02_HP_IN");
457 if (ret) { 453 if (ret) {
458 pr_err("gta02_wm8753: Failed to register GPIO %d\n", GTA02_GPIO_HP_IN); 454 pr_err("gta02_wm8753: Failed to register GPIO %d\n", GTA02_GPIO_HP_IN);
459 goto err_unregister_device; 455 goto err_del_device;
460 } 456 }
461 457
462 ret = gpio_direction_output(GTA02_GPIO_HP_IN, 1); 458 ret = gpio_direction_output(GTA02_GPIO_HP_IN, 1);
@@ -483,15 +479,19 @@ err_free_gpio_amp_shut:
483 gpio_free(GTA02_GPIO_AMP_SHUT); 479 gpio_free(GTA02_GPIO_AMP_SHUT);
484err_free_gpio_hp_in: 480err_free_gpio_hp_in:
485 gpio_free(GTA02_GPIO_HP_IN); 481 gpio_free(GTA02_GPIO_HP_IN);
486err_unregister_device: 482err_del_device:
487 platform_device_unregister(neo1973_gta02_snd_device); 483 platform_device_del(neo1973_gta02_snd_device);
484err_unregister_dai:
485 snd_soc_unregister_dai(&neo1973_gta02_snd_device->dev);
486err_put_device:
487 platform_device_put(neo1973_gta02_snd_device);
488 return ret; 488 return ret;
489} 489}
490module_init(neo1973_gta02_init); 490module_init(neo1973_gta02_init);
491 491
492static void __exit neo1973_gta02_exit(void) 492static void __exit neo1973_gta02_exit(void)
493{ 493{
494 snd_soc_unregister_dai(&neo1973_gta02_snd_device->dev, -1); 494 snd_soc_unregister_dai(&neo1973_gta02_snd_device->dev);
495 platform_device_unregister(neo1973_gta02_snd_device); 495 platform_device_unregister(neo1973_gta02_snd_device);
496 gpio_free(GTA02_GPIO_HP_IN); 496 gpio_free(GTA02_GPIO_HP_IN);
497 gpio_free(GTA02_GPIO_AMP_SHUT); 497 gpio_free(GTA02_GPIO_AMP_SHUT);
diff --git a/sound/soc/s3c24xx/neo1973_wm8753.c b/sound/soc/samsung/neo1973_wm8753.c
index f4f2ee731f01..c7a24514beb5 100644
--- a/sound/soc/s3c24xx/neo1973_wm8753.c
+++ b/sound/soc/samsung/neo1973_wm8753.c
@@ -21,7 +21,6 @@
21#include <sound/core.h> 21#include <sound/core.h>
22#include <sound/pcm.h> 22#include <sound/pcm.h>
23#include <sound/soc.h> 23#include <sound/soc.h>
24#include <sound/soc-dapm.h>
25#include <sound/tlv.h> 24#include <sound/tlv.h>
26 25
27#include <asm/mach-types.h> 26#include <asm/mach-types.h>
@@ -36,7 +35,7 @@
36 35
37#include "../codecs/wm8753.h" 36#include "../codecs/wm8753.h"
38#include "lm4857.h" 37#include "lm4857.h"
39#include "s3c-dma.h" 38#include "dma.h"
40#include "s3c24xx-i2s.h" 39#include "s3c24xx-i2s.h"
41 40
42/* define the scenarios */ 41/* define the scenarios */
@@ -237,81 +236,83 @@ static int neo1973_get_scenario(struct snd_kcontrol *kcontrol,
237 236
238static int set_scenario_endpoints(struct snd_soc_codec *codec, int scenario) 237static int set_scenario_endpoints(struct snd_soc_codec *codec, int scenario)
239{ 238{
239 struct snd_soc_dapm_context *dapm = &codec->dapm;
240
240 pr_debug("Entered %s\n", __func__); 241 pr_debug("Entered %s\n", __func__);
241 242
242 switch (neo1973_scenario) { 243 switch (neo1973_scenario) {
243 case NEO_AUDIO_OFF: 244 case NEO_AUDIO_OFF:
244 snd_soc_dapm_disable_pin(codec, "Audio Out"); 245 snd_soc_dapm_disable_pin(dapm, "Audio Out");
245 snd_soc_dapm_disable_pin(codec, "GSM Line Out"); 246 snd_soc_dapm_disable_pin(dapm, "GSM Line Out");
246 snd_soc_dapm_disable_pin(codec, "GSM Line In"); 247 snd_soc_dapm_disable_pin(dapm, "GSM Line In");
247 snd_soc_dapm_disable_pin(codec, "Headset Mic"); 248 snd_soc_dapm_disable_pin(dapm, "Headset Mic");
248 snd_soc_dapm_disable_pin(codec, "Call Mic"); 249 snd_soc_dapm_disable_pin(dapm, "Call Mic");
249 break; 250 break;
250 case NEO_GSM_CALL_AUDIO_HANDSET: 251 case NEO_GSM_CALL_AUDIO_HANDSET:
251 snd_soc_dapm_enable_pin(codec, "Audio Out"); 252 snd_soc_dapm_enable_pin(dapm, "Audio Out");
252 snd_soc_dapm_enable_pin(codec, "GSM Line Out"); 253 snd_soc_dapm_enable_pin(dapm, "GSM Line Out");
253 snd_soc_dapm_enable_pin(codec, "GSM Line In"); 254 snd_soc_dapm_enable_pin(dapm, "GSM Line In");
254 snd_soc_dapm_disable_pin(codec, "Headset Mic"); 255 snd_soc_dapm_disable_pin(dapm, "Headset Mic");
255 snd_soc_dapm_enable_pin(codec, "Call Mic"); 256 snd_soc_dapm_enable_pin(dapm, "Call Mic");
256 break; 257 break;
257 case NEO_GSM_CALL_AUDIO_HEADSET: 258 case NEO_GSM_CALL_AUDIO_HEADSET:
258 snd_soc_dapm_enable_pin(codec, "Audio Out"); 259 snd_soc_dapm_enable_pin(dapm, "Audio Out");
259 snd_soc_dapm_enable_pin(codec, "GSM Line Out"); 260 snd_soc_dapm_enable_pin(dapm, "GSM Line Out");
260 snd_soc_dapm_enable_pin(codec, "GSM Line In"); 261 snd_soc_dapm_enable_pin(dapm, "GSM Line In");
261 snd_soc_dapm_enable_pin(codec, "Headset Mic"); 262 snd_soc_dapm_enable_pin(dapm, "Headset Mic");
262 snd_soc_dapm_disable_pin(codec, "Call Mic"); 263 snd_soc_dapm_disable_pin(dapm, "Call Mic");
263 break; 264 break;
264 case NEO_GSM_CALL_AUDIO_BLUETOOTH: 265 case NEO_GSM_CALL_AUDIO_BLUETOOTH:
265 snd_soc_dapm_disable_pin(codec, "Audio Out"); 266 snd_soc_dapm_disable_pin(dapm, "Audio Out");
266 snd_soc_dapm_enable_pin(codec, "GSM Line Out"); 267 snd_soc_dapm_enable_pin(dapm, "GSM Line Out");
267 snd_soc_dapm_enable_pin(codec, "GSM Line In"); 268 snd_soc_dapm_enable_pin(dapm, "GSM Line In");
268 snd_soc_dapm_disable_pin(codec, "Headset Mic"); 269 snd_soc_dapm_disable_pin(dapm, "Headset Mic");
269 snd_soc_dapm_disable_pin(codec, "Call Mic"); 270 snd_soc_dapm_disable_pin(dapm, "Call Mic");
270 break; 271 break;
271 case NEO_STEREO_TO_SPEAKERS: 272 case NEO_STEREO_TO_SPEAKERS:
272 snd_soc_dapm_enable_pin(codec, "Audio Out"); 273 snd_soc_dapm_enable_pin(dapm, "Audio Out");
273 snd_soc_dapm_disable_pin(codec, "GSM Line Out"); 274 snd_soc_dapm_disable_pin(dapm, "GSM Line Out");
274 snd_soc_dapm_disable_pin(codec, "GSM Line In"); 275 snd_soc_dapm_disable_pin(dapm, "GSM Line In");
275 snd_soc_dapm_disable_pin(codec, "Headset Mic"); 276 snd_soc_dapm_disable_pin(dapm, "Headset Mic");
276 snd_soc_dapm_disable_pin(codec, "Call Mic"); 277 snd_soc_dapm_disable_pin(dapm, "Call Mic");
277 break; 278 break;
278 case NEO_STEREO_TO_HEADPHONES: 279 case NEO_STEREO_TO_HEADPHONES:
279 snd_soc_dapm_enable_pin(codec, "Audio Out"); 280 snd_soc_dapm_enable_pin(dapm, "Audio Out");
280 snd_soc_dapm_disable_pin(codec, "GSM Line Out"); 281 snd_soc_dapm_disable_pin(dapm, "GSM Line Out");
281 snd_soc_dapm_disable_pin(codec, "GSM Line In"); 282 snd_soc_dapm_disable_pin(dapm, "GSM Line In");
282 snd_soc_dapm_disable_pin(codec, "Headset Mic"); 283 snd_soc_dapm_disable_pin(dapm, "Headset Mic");
283 snd_soc_dapm_disable_pin(codec, "Call Mic"); 284 snd_soc_dapm_disable_pin(dapm, "Call Mic");
284 break; 285 break;
285 case NEO_CAPTURE_HANDSET: 286 case NEO_CAPTURE_HANDSET:
286 snd_soc_dapm_disable_pin(codec, "Audio Out"); 287 snd_soc_dapm_disable_pin(dapm, "Audio Out");
287 snd_soc_dapm_disable_pin(codec, "GSM Line Out"); 288 snd_soc_dapm_disable_pin(dapm, "GSM Line Out");
288 snd_soc_dapm_disable_pin(codec, "GSM Line In"); 289 snd_soc_dapm_disable_pin(dapm, "GSM Line In");
289 snd_soc_dapm_disable_pin(codec, "Headset Mic"); 290 snd_soc_dapm_disable_pin(dapm, "Headset Mic");
290 snd_soc_dapm_enable_pin(codec, "Call Mic"); 291 snd_soc_dapm_enable_pin(dapm, "Call Mic");
291 break; 292 break;
292 case NEO_CAPTURE_HEADSET: 293 case NEO_CAPTURE_HEADSET:
293 snd_soc_dapm_disable_pin(codec, "Audio Out"); 294 snd_soc_dapm_disable_pin(dapm, "Audio Out");
294 snd_soc_dapm_disable_pin(codec, "GSM Line Out"); 295 snd_soc_dapm_disable_pin(dapm, "GSM Line Out");
295 snd_soc_dapm_disable_pin(codec, "GSM Line In"); 296 snd_soc_dapm_disable_pin(dapm, "GSM Line In");
296 snd_soc_dapm_enable_pin(codec, "Headset Mic"); 297 snd_soc_dapm_enable_pin(dapm, "Headset Mic");
297 snd_soc_dapm_disable_pin(codec, "Call Mic"); 298 snd_soc_dapm_disable_pin(dapm, "Call Mic");
298 break; 299 break;
299 case NEO_CAPTURE_BLUETOOTH: 300 case NEO_CAPTURE_BLUETOOTH:
300 snd_soc_dapm_disable_pin(codec, "Audio Out"); 301 snd_soc_dapm_disable_pin(dapm, "Audio Out");
301 snd_soc_dapm_disable_pin(codec, "GSM Line Out"); 302 snd_soc_dapm_disable_pin(dapm, "GSM Line Out");
302 snd_soc_dapm_disable_pin(codec, "GSM Line In"); 303 snd_soc_dapm_disable_pin(dapm, "GSM Line In");
303 snd_soc_dapm_disable_pin(codec, "Headset Mic"); 304 snd_soc_dapm_disable_pin(dapm, "Headset Mic");
304 snd_soc_dapm_disable_pin(codec, "Call Mic"); 305 snd_soc_dapm_disable_pin(dapm, "Call Mic");
305 break; 306 break;
306 default: 307 default:
307 snd_soc_dapm_disable_pin(codec, "Audio Out"); 308 snd_soc_dapm_disable_pin(dapm, "Audio Out");
308 snd_soc_dapm_disable_pin(codec, "GSM Line Out"); 309 snd_soc_dapm_disable_pin(dapm, "GSM Line Out");
309 snd_soc_dapm_disable_pin(codec, "GSM Line In"); 310 snd_soc_dapm_disable_pin(dapm, "GSM Line In");
310 snd_soc_dapm_disable_pin(codec, "Headset Mic"); 311 snd_soc_dapm_disable_pin(dapm, "Headset Mic");
311 snd_soc_dapm_disable_pin(codec, "Call Mic"); 312 snd_soc_dapm_disable_pin(dapm, "Call Mic");
312 } 313 }
313 314
314 snd_soc_dapm_sync(codec); 315 snd_soc_dapm_sync(dapm);
315 316
316 return 0; 317 return 0;
317} 318}
@@ -502,20 +503,21 @@ static const struct snd_kcontrol_new wm8753_neo1973_controls[] = {
502static int neo1973_wm8753_init(struct snd_soc_pcm_runtime *rtd) 503static int neo1973_wm8753_init(struct snd_soc_pcm_runtime *rtd)
503{ 504{
504 struct snd_soc_codec *codec = rtd->codec; 505 struct snd_soc_codec *codec = rtd->codec;
506 struct snd_soc_dapm_context *dapm = &codec->dapm;
505 int err; 507 int err;
506 508
507 pr_debug("Entered %s\n", __func__); 509 pr_debug("Entered %s\n", __func__);
508 510
509 /* set up NC codec pins */ 511 /* set up NC codec pins */
510 snd_soc_dapm_nc_pin(codec, "LOUT2"); 512 snd_soc_dapm_nc_pin(dapm, "LOUT2");
511 snd_soc_dapm_nc_pin(codec, "ROUT2"); 513 snd_soc_dapm_nc_pin(dapm, "ROUT2");
512 snd_soc_dapm_nc_pin(codec, "OUT3"); 514 snd_soc_dapm_nc_pin(dapm, "OUT3");
513 snd_soc_dapm_nc_pin(codec, "OUT4"); 515 snd_soc_dapm_nc_pin(dapm, "OUT4");
514 snd_soc_dapm_nc_pin(codec, "LINE1"); 516 snd_soc_dapm_nc_pin(dapm, "LINE1");
515 snd_soc_dapm_nc_pin(codec, "LINE2"); 517 snd_soc_dapm_nc_pin(dapm, "LINE2");
516 518
517 /* Add neo1973 specific widgets */ 519 /* Add neo1973 specific widgets */
518 snd_soc_dapm_new_controls(codec, wm8753_dapm_widgets, 520 snd_soc_dapm_new_controls(dapm, wm8753_dapm_widgets,
519 ARRAY_SIZE(wm8753_dapm_widgets)); 521 ARRAY_SIZE(wm8753_dapm_widgets));
520 522
521 /* set endpoints to default mode */ 523 /* set endpoints to default mode */
@@ -528,10 +530,10 @@ static int neo1973_wm8753_init(struct snd_soc_pcm_runtime *rtd)
528 return err; 530 return err;
529 531
530 /* set up neo1973 specific audio routes */ 532 /* set up neo1973 specific audio routes */
531 err = snd_soc_dapm_add_routes(codec, dapm_routes, 533 err = snd_soc_dapm_add_routes(dapm, dapm_routes,
532 ARRAY_SIZE(dapm_routes)); 534 ARRAY_SIZE(dapm_routes));
533 535
534 snd_soc_dapm_sync(codec); 536 snd_soc_dapm_sync(dapm);
535 return 0; 537 return 0;
536} 538}
537 539
@@ -556,7 +558,7 @@ static struct snd_soc_dai_link neo1973_dai[] = {
556{ /* Hifi Playback - for similatious use with voice below */ 558{ /* Hifi Playback - for similatious use with voice below */
557 .name = "WM8753", 559 .name = "WM8753",
558 .stream_name = "WM8753 HiFi", 560 .stream_name = "WM8753 HiFi",
559 .platform_name = "s3c24xx-pcm-audio", 561 .platform_name = "samsung-audio",
560 .cpu_dai_name = "s3c24xx-i2s", 562 .cpu_dai_name = "s3c24xx-i2s",
561 .codec_dai_name = "wm8753-hifi", 563 .codec_dai_name = "wm8753-hifi",
562 .codec_name = "wm8753-codec.0-0x1a", 564 .codec_name = "wm8753-codec.0-0x1a",
@@ -566,7 +568,7 @@ static struct snd_soc_dai_link neo1973_dai[] = {
566{ /* Voice via BT */ 568{ /* Voice via BT */
567 .name = "Bluetooth", 569 .name = "Bluetooth",
568 .stream_name = "Voice", 570 .stream_name = "Voice",
569 .platform_name = "s3c24xx-pcm-audio", 571 .platform_name = "samsung-audio",
570 .cpu_dai_name = "bluetooth-dai", 572 .cpu_dai_name = "bluetooth-dai",
571 .codec_dai_name = "wm8753-voice", 573 .codec_dai_name = "wm8753-voice",
572 .codec_name = "wm8753-codec.0-0x1a", 574 .codec_name = "wm8753-codec.0-0x1a",
diff --git a/sound/soc/s3c24xx/s3c-pcm.c b/sound/soc/samsung/pcm.c
index 2e020e1b4eab..48d0b750406b 100644
--- a/sound/soc/s3c24xx/s3c-pcm.c
+++ b/sound/soc/samsung/pcm.c
@@ -1,4 +1,4 @@
1/* sound/soc/s3c24xx/s3c-pcm.c 1/* sound/soc/samsung/pcm.c
2 * 2 *
3 * ALSA SoC Audio Layer - S3C PCM-Controller driver 3 * ALSA SoC Audio Layer - S3C PCM-Controller driver
4 * 4 *
@@ -29,8 +29,8 @@
29#include <plat/audio.h> 29#include <plat/audio.h>
30#include <plat/dma.h> 30#include <plat/dma.h>
31 31
32#include "s3c-dma.h" 32#include "dma.h"
33#include "s3c-pcm.h" 33#include "pcm.h"
34 34
35static struct s3c2410_dma_client s3c_pcm_dma_client_out = { 35static struct s3c2410_dma_client s3c_pcm_dma_client_out = {
36 .name = "PCM Stereo out" 36 .name = "PCM Stereo out"
diff --git a/sound/soc/s3c24xx/s3c-pcm.h b/sound/soc/samsung/pcm.h
index f60baa19387d..03393dcf852d 100644
--- a/sound/soc/s3c24xx/s3c-pcm.h
+++ b/sound/soc/samsung/pcm.h
@@ -1,4 +1,4 @@
1/* sound/soc/s3c24xx/s3c-pcm.h 1/* sound/soc/samsung/pcm.h
2 * 2 *
3 * This program is free software; you can redistribute it and/or modify 3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License version 2 as 4 * it under the terms of the GNU General Public License version 2 as
diff --git a/sound/soc/s3c24xx/regs-i2s-v2.h b/sound/soc/samsung/regs-i2s-v2.h
index 5e5e5680580b..5e5e5680580b 100644
--- a/sound/soc/s3c24xx/regs-i2s-v2.h
+++ b/sound/soc/samsung/regs-i2s-v2.h
diff --git a/sound/soc/s3c24xx/rx1950_uda1380.c b/sound/soc/samsung/rx1950_uda1380.c
index 468cc11fdf47..f40027445dda 100644
--- a/sound/soc/s3c24xx/rx1950_uda1380.c
+++ b/sound/soc/samsung/rx1950_uda1380.c
@@ -25,7 +25,6 @@
25#include <linux/clk.h> 25#include <linux/clk.h>
26 26
27#include <sound/soc.h> 27#include <sound/soc.h>
28#include <sound/soc-dapm.h>
29#include <sound/uda1380.h> 28#include <sound/uda1380.h>
30#include <sound/jack.h> 29#include <sound/jack.h>
31 30
@@ -35,7 +34,7 @@
35 34
36#include <asm/mach-types.h> 35#include <asm/mach-types.h>
37 36
38#include "s3c-dma.h" 37#include "dma.h"
39#include "s3c24xx-i2s.h" 38#include "s3c24xx-i2s.h"
40#include "../codecs/uda1380.h" 39#include "../codecs/uda1380.h"
41 40
@@ -95,7 +94,7 @@ static struct snd_soc_dai_link rx1950_uda1380_dai[] = {
95 .cpu_dai_name = "s3c24xx-iis", 94 .cpu_dai_name = "s3c24xx-iis",
96 .codec_dai_name = "uda1380-hifi", 95 .codec_dai_name = "uda1380-hifi",
97 .init = rx1950_uda1380_init, 96 .init = rx1950_uda1380_init,
98 .platform_name = "s3c24xx-pcm-audio", 97 .platform_name = "samsung-audio",
99 .codec_name = "uda1380-codec.0-001a", 98 .codec_name = "uda1380-codec.0-001a",
100 .ops = &rx1950_ops, 99 .ops = &rx1950_ops,
101 }, 100 },
@@ -228,26 +227,28 @@ static int rx1950_hw_params(struct snd_pcm_substream *substream,
228static int rx1950_uda1380_init(struct snd_soc_pcm_runtime *rtd) 227static int rx1950_uda1380_init(struct snd_soc_pcm_runtime *rtd)
229{ 228{
230 struct snd_soc_codec *codec = rtd->codec; 229 struct snd_soc_codec *codec = rtd->codec;
230 struct snd_soc_dapm_context *dapm = &codec->dapm;
231 int err; 231 int err;
232 232
233 /* Add rx1950 specific widgets */ 233 /* Add rx1950 specific widgets */
234 err = snd_soc_dapm_new_controls(codec, uda1380_dapm_widgets, 234 err = snd_soc_dapm_new_controls(dapm, uda1380_dapm_widgets,
235 ARRAY_SIZE(uda1380_dapm_widgets)); 235 ARRAY_SIZE(uda1380_dapm_widgets));
236 236
237 if (err) 237 if (err)
238 return err; 238 return err;
239 239
240 /* Set up rx1950 specific audio path audio_mapnects */ 240 /* Set up rx1950 specific audio path audio_mapnects */
241 err = snd_soc_dapm_add_routes(codec, audio_map, 241 err = snd_soc_dapm_add_routes(dapm, audio_map,
242 ARRAY_SIZE(audio_map)); 242 ARRAY_SIZE(audio_map));
243 243
244 if (err) 244 if (err)
245 return err; 245 return err;
246 246
247 snd_soc_dapm_enable_pin(codec, "Headphone Jack"); 247 snd_soc_dapm_enable_pin(dapm, "Headphone Jack");
248 snd_soc_dapm_enable_pin(codec, "Speaker"); 248 snd_soc_dapm_enable_pin(dapm, "Speaker");
249 snd_soc_dapm_enable_pin(dapm, "Mic Jack");
249 250
250 snd_soc_dapm_sync(codec); 251 snd_soc_dapm_sync(dapm);
251 252
252 snd_soc_jack_new(codec, "Headphone Jack", SND_JACK_HEADPHONE, 253 snd_soc_jack_new(codec, "Headphone Jack", SND_JACK_HEADPHONE,
253 &hp_jack); 254 &hp_jack);
diff --git a/sound/soc/s3c24xx/s3c-i2s-v2.c b/sound/soc/samsung/s3c-i2s-v2.c
index b3866d5b19e9..094f36e41e83 100644
--- a/sound/soc/s3c24xx/s3c-i2s-v2.c
+++ b/sound/soc/samsung/s3c-i2s-v2.c
@@ -1,4 +1,4 @@
1/* sound/soc/s3c24xx/s3c-i2c-v2.c 1/* sound/soc/samsung/s3c-i2c-v2.c
2 * 2 *
3 * ALSA Soc Audio Layer - I2S core for newer Samsung SoCs. 3 * ALSA Soc Audio Layer - I2S core for newer Samsung SoCs.
4 * 4 *
@@ -28,7 +28,7 @@
28 28
29#include "regs-i2s-v2.h" 29#include "regs-i2s-v2.h"
30#include "s3c-i2s-v2.h" 30#include "s3c-i2s-v2.h"
31#include "s3c-dma.h" 31#include "dma.h"
32 32
33#undef S3C_IIS_V2_SUPPORTED 33#undef S3C_IIS_V2_SUPPORTED
34 34
diff --git a/sound/soc/s3c24xx/s3c-i2s-v2.h b/sound/soc/samsung/s3c-i2s-v2.h
index d45830151484..f8297d9bb8a3 100644
--- a/sound/soc/s3c24xx/s3c-i2s-v2.h
+++ b/sound/soc/samsung/s3c-i2s-v2.h
@@ -1,4 +1,4 @@
1/* sound/soc/s3c24xx/s3c-i2s-v2.h 1/* sound/soc/samsung/s3c-i2s-v2.h
2 * 2 *
3 * ALSA Soc Audio Layer - S3C_I2SV2 I2S driver 3 * ALSA Soc Audio Layer - S3C_I2SV2 I2S driver
4 * 4 *
diff --git a/sound/soc/s3c24xx/s3c2412-i2s.c b/sound/soc/samsung/s3c2412-i2s.c
index 4a861cfa52c5..7ea837867124 100644
--- a/sound/soc/s3c24xx/s3c2412-i2s.c
+++ b/sound/soc/samsung/s3c2412-i2s.c
@@ -1,4 +1,4 @@
1/* sound/soc/s3c24xx/s3c2412-i2s.c 1/* sound/soc/samsung/s3c2412-i2s.c
2 * 2 *
3 * ALSA Soc Audio Layer - S3C2412 I2S driver 3 * ALSA Soc Audio Layer - S3C2412 I2S driver
4 * 4 *
@@ -35,7 +35,7 @@
35#include <mach/regs-gpio.h> 35#include <mach/regs-gpio.h>
36#include <mach/dma.h> 36#include <mach/dma.h>
37 37
38#include "s3c-dma.h" 38#include "dma.h"
39#include "regs-i2s-v2.h" 39#include "regs-i2s-v2.h"
40#include "s3c2412-i2s.h" 40#include "s3c2412-i2s.h"
41 41
diff --git a/sound/soc/s3c24xx/s3c2412-i2s.h b/sound/soc/samsung/s3c2412-i2s.h
index 01a0471ac65c..02ad5794c0a9 100644
--- a/sound/soc/s3c24xx/s3c2412-i2s.h
+++ b/sound/soc/samsung/s3c2412-i2s.h
@@ -1,4 +1,4 @@
1/* sound/soc/s3c24xx/s3c2412-i2s.c 1/* sound/soc/samsung/s3c2412-i2s.c
2 * 2 *
3 * ALSA Soc Audio Layer - S3C2412 I2S driver 3 * ALSA Soc Audio Layer - S3C2412 I2S driver
4 * 4 *
diff --git a/sound/soc/s3c24xx/s3c24xx-i2s.c b/sound/soc/samsung/s3c24xx-i2s.c
index e060daaa458f..13e41ed8e22b 100644
--- a/sound/soc/s3c24xx/s3c24xx-i2s.c
+++ b/sound/soc/samsung/s3c24xx-i2s.c
@@ -38,7 +38,7 @@
38 38
39#include <plat/regs-iis.h> 39#include <plat/regs-iis.h>
40 40
41#include "s3c-dma.h" 41#include "dma.h"
42#include "s3c24xx-i2s.h" 42#include "s3c24xx-i2s.h"
43 43
44static struct s3c2410_dma_client s3c24xx_dma_client_out = { 44static struct s3c2410_dma_client s3c24xx_dma_client_out = {
diff --git a/sound/soc/s3c24xx/s3c24xx-i2s.h b/sound/soc/samsung/s3c24xx-i2s.h
index f9ca04edacb7..f9ca04edacb7 100644
--- a/sound/soc/s3c24xx/s3c24xx-i2s.h
+++ b/sound/soc/samsung/s3c24xx-i2s.h
diff --git a/sound/soc/s3c24xx/s3c24xx_simtec.c b/sound/soc/samsung/s3c24xx_simtec.c
index c4c111442010..a434032d1832 100644
--- a/sound/soc/s3c24xx/s3c24xx_simtec.c
+++ b/sound/soc/samsung/s3c24xx_simtec.c
@@ -1,4 +1,4 @@
1/* sound/soc/s3c24xx/s3c24xx_simtec.c 1/* sound/soc/samsung/s3c24xx_simtec.c
2 * 2 *
3 * Copyright 2009 Simtec Electronics 3 * Copyright 2009 Simtec Electronics
4 * 4 *
@@ -17,11 +17,10 @@
17#include <sound/core.h> 17#include <sound/core.h>
18#include <sound/pcm.h> 18#include <sound/pcm.h>
19#include <sound/soc.h> 19#include <sound/soc.h>
20#include <sound/soc-dapm.h>
21 20
22#include <plat/audio-simtec.h> 21#include <plat/audio-simtec.h>
23 22
24#include "s3c-dma.h" 23#include "dma.h"
25#include "s3c24xx-i2s.h" 24#include "s3c24xx-i2s.h"
26#include "s3c24xx_simtec.h" 25#include "s3c24xx_simtec.h"
27 26
diff --git a/sound/soc/s3c24xx/s3c24xx_simtec.h b/sound/soc/samsung/s3c24xx_simtec.h
index e63d5ff9c41f..8270748a2c41 100644
--- a/sound/soc/s3c24xx/s3c24xx_simtec.h
+++ b/sound/soc/samsung/s3c24xx_simtec.h
@@ -1,4 +1,4 @@
1/* sound/soc/s3c24xx/s3c24xx_simtec.h 1/* sound/soc/samsung/s3c24xx_simtec.h
2 * 2 *
3 * Copyright 2009 Simtec Electronics 3 * Copyright 2009 Simtec Electronics
4 * 4 *
diff --git a/sound/soc/s3c24xx/s3c24xx_simtec_hermes.c b/sound/soc/samsung/s3c24xx_simtec_hermes.c
index f88453735ae2..bb4292e3596c 100644
--- a/sound/soc/s3c24xx/s3c24xx_simtec_hermes.c
+++ b/sound/soc/samsung/s3c24xx_simtec_hermes.c
@@ -1,4 +1,4 @@
1/* sound/soc/s3c24xx/s3c24xx_simtec_hermes.c 1/* sound/soc/samsung/s3c24xx_simtec_hermes.c
2 * 2 *
3 * Copyright 2009 Simtec Electronics 3 * Copyright 2009 Simtec Electronics
4 * 4 *
@@ -14,16 +14,13 @@
14#include <sound/core.h> 14#include <sound/core.h>
15#include <sound/pcm.h> 15#include <sound/pcm.h>
16#include <sound/soc.h> 16#include <sound/soc.h>
17#include <sound/soc-dapm.h>
18 17
19#include <plat/audio-simtec.h> 18#include <plat/audio-simtec.h>
20 19
21#include "s3c-dma.h" 20#include "dma.h"
22#include "s3c24xx-i2s.h" 21#include "s3c24xx-i2s.h"
23#include "s3c24xx_simtec.h" 22#include "s3c24xx_simtec.h"
24 23
25#include "../codecs/tlv320aic3x.h"
26
27static const struct snd_soc_dapm_widget dapm_widgets[] = { 24static const struct snd_soc_dapm_widget dapm_widgets[] = {
28 SND_SOC_DAPM_LINE("GSM Out", NULL), 25 SND_SOC_DAPM_LINE("GSM Out", NULL),
29 SND_SOC_DAPM_LINE("GSM In", NULL), 26 SND_SOC_DAPM_LINE("GSM In", NULL),
@@ -76,19 +73,20 @@ static const struct snd_soc_dapm_route base_map[] = {
76static int simtec_hermes_init(struct snd_soc_pcm_runtime *rtd) 73static int simtec_hermes_init(struct snd_soc_pcm_runtime *rtd)
77{ 74{
78 struct snd_soc_codec *codec = rtd->codec; 75 struct snd_soc_codec *codec = rtd->codec;
76 struct snd_soc_dapm_context *dapm = &codec->dapm;
79 77
80 snd_soc_dapm_new_controls(codec, dapm_widgets, 78 snd_soc_dapm_new_controls(dapm, dapm_widgets,
81 ARRAY_SIZE(dapm_widgets)); 79 ARRAY_SIZE(dapm_widgets));
82 80
83 snd_soc_dapm_add_routes(codec, base_map, ARRAY_SIZE(base_map)); 81 snd_soc_dapm_add_routes(dapm, base_map, ARRAY_SIZE(base_map));
84 82
85 snd_soc_dapm_enable_pin(codec, "Headphone Jack"); 83 snd_soc_dapm_enable_pin(dapm, "Headphone Jack");
86 snd_soc_dapm_enable_pin(codec, "Line In"); 84 snd_soc_dapm_enable_pin(dapm, "Line In");
87 snd_soc_dapm_enable_pin(codec, "Line Out"); 85 snd_soc_dapm_enable_pin(dapm, "Line Out");
88 snd_soc_dapm_enable_pin(codec, "Mic Jack"); 86 snd_soc_dapm_enable_pin(dapm, "Mic Jack");
89 87
90 simtec_audio_init(rtd); 88 simtec_audio_init(rtd);
91 snd_soc_dapm_sync(codec); 89 snd_soc_dapm_sync(dapm);
92 90
93 return 0; 91 return 0;
94} 92}
@@ -99,7 +97,7 @@ static struct snd_soc_dai_link simtec_dai_aic33 = {
99 .codec_name = "tlv320aic3x-codec.0-0x1a", 97 .codec_name = "tlv320aic3x-codec.0-0x1a",
100 .cpu_dai_name = "s3c24xx-i2s", 98 .cpu_dai_name = "s3c24xx-i2s",
101 .codec_dai_name = "tlv320aic3x-hifi", 99 .codec_dai_name = "tlv320aic3x-hifi",
102 .platform_name = "s3c24xx-pcm-audio", 100 .platform_name = "samsung-audio",
103 .init = simtec_hermes_init, 101 .init = simtec_hermes_init,
104}; 102};
105 103
diff --git a/sound/soc/s3c24xx/s3c24xx_simtec_tlv320aic23.c b/sound/soc/samsung/s3c24xx_simtec_tlv320aic23.c
index c0967593510d..fbba4e367729 100644
--- a/sound/soc/s3c24xx/s3c24xx_simtec_tlv320aic23.c
+++ b/sound/soc/samsung/s3c24xx_simtec_tlv320aic23.c
@@ -1,4 +1,4 @@
1/* sound/soc/s3c24xx/s3c24xx_simtec_tlv320aic23.c 1/* sound/soc/samsung/s3c24xx_simtec_tlv320aic23.c
2 * 2 *
3 * Copyright 2009 Simtec Electronics 3 * Copyright 2009 Simtec Electronics
4 * 4 *
@@ -14,11 +14,10 @@
14#include <sound/core.h> 14#include <sound/core.h>
15#include <sound/pcm.h> 15#include <sound/pcm.h>
16#include <sound/soc.h> 16#include <sound/soc.h>
17#include <sound/soc-dapm.h>
18 17
19#include <plat/audio-simtec.h> 18#include <plat/audio-simtec.h>
20 19
21#include "s3c-dma.h" 20#include "dma.h"
22#include "s3c24xx-i2s.h" 21#include "s3c24xx-i2s.h"
23#include "s3c24xx_simtec.h" 22#include "s3c24xx_simtec.h"
24 23
@@ -65,19 +64,20 @@ static const struct snd_soc_dapm_route base_map[] = {
65static int simtec_tlv320aic23_init(struct snd_soc_pcm_runtime *rtd) 64static int simtec_tlv320aic23_init(struct snd_soc_pcm_runtime *rtd)
66{ 65{
67 struct snd_soc_codec *codec = rtd->codec; 66 struct snd_soc_codec *codec = rtd->codec;
67 struct snd_soc_dapm_context *dapm = &codec->dapm;
68 68
69 snd_soc_dapm_new_controls(codec, dapm_widgets, 69 snd_soc_dapm_new_controls(dapm, dapm_widgets,
70 ARRAY_SIZE(dapm_widgets)); 70 ARRAY_SIZE(dapm_widgets));
71 71
72 snd_soc_dapm_add_routes(codec, base_map, ARRAY_SIZE(base_map)); 72 snd_soc_dapm_add_routes(dapm, base_map, ARRAY_SIZE(base_map));
73 73
74 snd_soc_dapm_enable_pin(codec, "Headphone Jack"); 74 snd_soc_dapm_enable_pin(dapm, "Headphone Jack");
75 snd_soc_dapm_enable_pin(codec, "Line In"); 75 snd_soc_dapm_enable_pin(dapm, "Line In");
76 snd_soc_dapm_enable_pin(codec, "Line Out"); 76 snd_soc_dapm_enable_pin(dapm, "Line Out");
77 snd_soc_dapm_enable_pin(codec, "Mic Jack"); 77 snd_soc_dapm_enable_pin(dapm, "Mic Jack");
78 78
79 simtec_audio_init(rtd); 79 simtec_audio_init(rtd);
80 snd_soc_dapm_sync(codec); 80 snd_soc_dapm_sync(dapm);
81 81
82 return 0; 82 return 0;
83} 83}
@@ -88,7 +88,7 @@ static struct snd_soc_dai_link simtec_dai_aic23 = {
88 .codec_name = "tlv320aic3x-codec.0-0x1a", 88 .codec_name = "tlv320aic3x-codec.0-0x1a",
89 .cpu_dai_name = "s3c24xx-i2s", 89 .cpu_dai_name = "s3c24xx-i2s",
90 .codec_dai_name = "tlv320aic3x-hifi", 90 .codec_dai_name = "tlv320aic3x-hifi",
91 .platform_name = "s3c24xx-pcm-audio", 91 .platform_name = "samsung-audio",
92 .init = simtec_tlv320aic23_init, 92 .init = simtec_tlv320aic23_init,
93}; 93};
94 94
diff --git a/sound/soc/s3c24xx/s3c24xx_uda134x.c b/sound/soc/samsung/s3c24xx_uda134x.c
index bd48ffbde880..cdc8ecbcb8ef 100644
--- a/sound/soc/s3c24xx/s3c24xx_uda134x.c
+++ b/sound/soc/samsung/s3c24xx_uda134x.c
@@ -18,13 +18,12 @@
18#include <sound/pcm.h> 18#include <sound/pcm.h>
19#include <sound/pcm_params.h> 19#include <sound/pcm_params.h>
20#include <sound/soc.h> 20#include <sound/soc.h>
21#include <sound/soc-dapm.h>
22#include <sound/s3c24xx_uda134x.h> 21#include <sound/s3c24xx_uda134x.h>
23#include <sound/uda134x.h> 22#include <sound/uda134x.h>
24 23
25#include <plat/regs-iis.h> 24#include <plat/regs-iis.h>
26 25
27#include "s3c-dma.h" 26#include "dma.h"
28#include "s3c24xx-i2s.h" 27#include "s3c24xx-i2s.h"
29#include "../codecs/uda134x.h" 28#include "../codecs/uda134x.h"
30 29
@@ -231,7 +230,7 @@ static struct snd_soc_dai_link s3c24xx_uda134x_dai_link = {
231 .codec_dai_name = "uda134x-hifi", 230 .codec_dai_name = "uda134x-hifi",
232 .cpu_dai_name = "s3c24xx-i2s", 231 .cpu_dai_name = "s3c24xx-i2s",
233 .ops = &s3c24xx_uda134x_ops, 232 .ops = &s3c24xx_uda134x_ops,
234 .platform_name = "s3c24xx-pcm-audio", 233 .platform_name = "samsung-audio",
235}; 234};
236 235
237static struct snd_soc_card snd_soc_s3c24xx_uda134x = { 236static struct snd_soc_card snd_soc_s3c24xx_uda134x = {
diff --git a/sound/soc/s3c24xx/smartq_wm8987.c b/sound/soc/samsung/smartq_wm8987.c
index dd20ca7f4681..61e2b5219d42 100644
--- a/sound/soc/s3c24xx/smartq_wm8987.c
+++ b/sound/soc/samsung/smartq_wm8987.c
@@ -1,4 +1,4 @@
1/* sound/soc/s3c24xx/smartq_wm8987.c 1/* sound/soc/samsung/smartq_wm8987.c
2 * 2 *
3 * Copyright 2010 Maurus Cuelenaere <mcuelenaere@gmail.com> 3 * Copyright 2010 Maurus Cuelenaere <mcuelenaere@gmail.com>
4 * 4 *
@@ -19,13 +19,13 @@
19 19
20#include <sound/pcm.h> 20#include <sound/pcm.h>
21#include <sound/pcm_params.h> 21#include <sound/pcm_params.h>
22#include <sound/soc-dapm.h> 22#include <sound/soc.h>
23#include <sound/jack.h> 23#include <sound/jack.h>
24 24
25#include <asm/mach-types.h> 25#include <asm/mach-types.h>
26 26
27#include "s3c-dma.h" 27#include "dma.h"
28#include "s3c64xx-i2s.h" 28#include "i2s.h"
29 29
30#include "../codecs/wm8750.h" 30#include "../codecs/wm8750.h"
31 31
@@ -39,15 +39,11 @@ static int smartq_hifi_hw_params(struct snd_pcm_substream *substream,
39 struct snd_pcm_hw_params *params) 39 struct snd_pcm_hw_params *params)
40{ 40{
41 struct snd_soc_pcm_runtime *rtd = substream->private_data; 41 struct snd_soc_pcm_runtime *rtd = substream->private_data;
42 struct snd_soc_dai *codec_dai = rtd->dai->codec_dai; 42 struct snd_soc_dai *codec_dai = rtd->codec_dai;
43 struct snd_soc_dai *cpu_dai = rtd->dai->cpu_dai; 43 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
44 struct s3c_i2sv2_rate_calc div;
45 unsigned int clk = 0; 44 unsigned int clk = 0;
46 int ret; 45 int ret;
47 46
48 s3c_i2sv2_iis_calc_rate(&div, NULL, params_rate(params),
49 s3c_i2sv2_get_clock(cpu_dai));
50
51 switch (params_rate(params)) { 47 switch (params_rate(params)) {
52 case 8000: 48 case 8000:
53 case 16000: 49 case 16000:
@@ -78,20 +74,21 @@ static int smartq_hifi_hw_params(struct snd_pcm_substream *substream,
78 if (ret < 0) 74 if (ret < 0)
79 return ret; 75 return ret;
80 76
81 /* set the codec system clock for DAC and ADC */ 77 /* Use PCLK for I2S signal generation */
82 ret = snd_soc_dai_set_sysclk(codec_dai, WM8750_SYSCLK, clk, 78 ret = snd_soc_dai_set_sysclk(cpu_dai, SAMSUNG_I2S_RCLKSRC_0,
83 SND_SOC_CLOCK_IN); 79 0, SND_SOC_CLOCK_IN);
84 if (ret < 0) 80 if (ret < 0)
85 return ret; 81 return ret;
86 82
87 /* set MCLK division for sample rate */ 83 /* Gate the RCLK output on PAD */
88 ret = snd_soc_dai_set_clkdiv(cpu_dai, S3C_I2SV2_DIV_RCLK, div.fs_div); 84 ret = snd_soc_dai_set_sysclk(cpu_dai, SAMSUNG_I2S_CDCLK,
85 0, SND_SOC_CLOCK_IN);
89 if (ret < 0) 86 if (ret < 0)
90 return ret; 87 return ret;
91 88
92 /* set prescaler division for sample rate */ 89 /* set the codec system clock for DAC and ADC */
93 ret = snd_soc_dai_set_clkdiv(cpu_dai, S3C_I2SV2_DIV_PRESCALER, 90 ret = snd_soc_dai_set_sysclk(codec_dai, WM8750_SYSCLK, clk,
94 div.clk_div - 1); 91 SND_SOC_CLOCK_IN);
95 if (ret < 0) 92 if (ret < 0)
96 return ret; 93 return ret;
97 94
@@ -156,12 +153,14 @@ static const struct snd_soc_dapm_route audio_map[] = {
156 {"LINPUT2", NULL, "Mic Bias"}, 153 {"LINPUT2", NULL, "Mic Bias"},
157}; 154};
158 155
159static int smartq_wm8987_init(struct snd_soc_codec *codec) 156static int smartq_wm8987_init(struct snd_soc_pcm_runtime *rtd)
160{ 157{
158 struct snd_soc_codec *codec = rtd->codec;
159 struct snd_soc_dapm_context *dapm = &codec->dapm;
161 int err = 0; 160 int err = 0;
162 161
163 /* Add SmartQ specific widgets */ 162 /* Add SmartQ specific widgets */
164 snd_soc_dapm_new_controls(codec, wm8987_dapm_widgets, 163 snd_soc_dapm_new_controls(dapm, wm8987_dapm_widgets,
165 ARRAY_SIZE(wm8987_dapm_widgets)); 164 ARRAY_SIZE(wm8987_dapm_widgets));
166 165
167 /* add SmartQ specific controls */ 166 /* add SmartQ specific controls */
@@ -172,25 +171,25 @@ static int smartq_wm8987_init(struct snd_soc_codec *codec)
172 return err; 171 return err;
173 172
174 /* setup SmartQ specific audio path */ 173 /* setup SmartQ specific audio path */
175 snd_soc_dapm_add_routes(codec, audio_map, ARRAY_SIZE(audio_map)); 174 snd_soc_dapm_add_routes(dapm, audio_map, ARRAY_SIZE(audio_map));
176 175
177 /* set endpoints to not connected */ 176 /* set endpoints to not connected */
178 snd_soc_dapm_nc_pin(codec, "LINPUT1"); 177 snd_soc_dapm_nc_pin(dapm, "LINPUT1");
179 snd_soc_dapm_nc_pin(codec, "RINPUT1"); 178 snd_soc_dapm_nc_pin(dapm, "RINPUT1");
180 snd_soc_dapm_nc_pin(codec, "OUT3"); 179 snd_soc_dapm_nc_pin(dapm, "OUT3");
181 snd_soc_dapm_nc_pin(codec, "ROUT1"); 180 snd_soc_dapm_nc_pin(dapm, "ROUT1");
182 181
183 /* set endpoints to default off mode */ 182 /* set endpoints to default off mode */
184 snd_soc_dapm_enable_pin(codec, "Internal Speaker"); 183 snd_soc_dapm_enable_pin(dapm, "Internal Speaker");
185 snd_soc_dapm_enable_pin(codec, "Internal Mic"); 184 snd_soc_dapm_enable_pin(dapm, "Internal Mic");
186 snd_soc_dapm_disable_pin(codec, "Headphone Jack"); 185 snd_soc_dapm_disable_pin(dapm, "Headphone Jack");
187 186
188 err = snd_soc_dapm_sync(codec); 187 err = snd_soc_dapm_sync(dapm);
189 if (err) 188 if (err)
190 return err; 189 return err;
191 190
192 /* Headphone jack detection */ 191 /* Headphone jack detection */
193 err = snd_soc_jack_new(&snd_soc_smartq, "Headphone Jack", 192 err = snd_soc_jack_new(codec, "Headphone Jack",
194 SND_JACK_HEADPHONE, &smartq_jack); 193 SND_JACK_HEADPHONE, &smartq_jack);
195 if (err) 194 if (err)
196 return err; 195 return err;
@@ -211,9 +210,9 @@ static struct snd_soc_dai_link smartq_dai[] = {
211 { 210 {
212 .name = "wm8987", 211 .name = "wm8987",
213 .stream_name = "SmartQ Hi-Fi", 212 .stream_name = "SmartQ Hi-Fi",
214 .cpu_dai_name = "s3c64xx-i2s.0", 213 .cpu_dai_name = "samsung-i2s.0",
215 .codec_dai_name = "wm8750-hifi", 214 .codec_dai_name = "wm8750-hifi",
216 .platform_name = "s3c24xx-pcm-audio", 215 .platform_name = "samsung-audio",
217 .codec_name = "wm8750-codec.0-0x1a", 216 .codec_name = "wm8750-codec.0-0x1a",
218 .init = smartq_wm8987_init, 217 .init = smartq_wm8987_init,
219 .ops = &smartq_hifi_ops, 218 .ops = &smartq_hifi_ops,
@@ -275,6 +274,7 @@ err_unregister_device:
275 274
276static void __exit smartq_exit(void) 275static void __exit smartq_exit(void)
277{ 276{
277 gpio_free(S3C64XX_GPK(12));
278 snd_soc_jack_free_gpios(&smartq_jack, ARRAY_SIZE(smartq_jack_gpios), 278 snd_soc_jack_free_gpios(&smartq_jack, ARRAY_SIZE(smartq_jack_gpios),
279 smartq_jack_gpios); 279 smartq_jack_gpios);
280 280
diff --git a/sound/soc/s3c24xx/smdk2443_wm9710.c b/sound/soc/samsung/smdk2443_wm9710.c
index 4613288c2772..3be7e7e92d6e 100644
--- a/sound/soc/s3c24xx/smdk2443_wm9710.c
+++ b/sound/soc/samsung/smdk2443_wm9710.c
@@ -17,10 +17,9 @@
17#include <sound/core.h> 17#include <sound/core.h>
18#include <sound/pcm.h> 18#include <sound/pcm.h>
19#include <sound/soc.h> 19#include <sound/soc.h>
20#include <sound/soc-dapm.h>
21 20
22#include "s3c-dma.h" 21#include "dma.h"
23#include "s3c-ac97.h" 22#include "ac97.h"
24 23
25static struct snd_soc_card smdk2443; 24static struct snd_soc_card smdk2443;
26 25
@@ -28,10 +27,10 @@ static struct snd_soc_dai_link smdk2443_dai[] = {
28{ 27{
29 .name = "AC97", 28 .name = "AC97",
30 .stream_name = "AC97 HiFi", 29 .stream_name = "AC97 HiFi",
31 .cpu_dai_name = "s3c-ac97", 30 .cpu_dai_name = "samsung-ac97",
32 .codec_dai_name = "ac97-hifi", 31 .codec_dai_name = "ac97-hifi",
33 .codec_name = "ac97-codec", 32 .codec_name = "ac97-codec",
34 .platform_name = "s3c24xx-pcm-audio", 33 .platform_name = "samsung-audio",
35}, 34},
36}; 35};
37 36
diff --git a/sound/soc/s3c24xx/smdk_spdif.c b/sound/soc/samsung/smdk_spdif.c
index c8bd90488a87..b5c3fad01bb8 100644
--- a/sound/soc/s3c24xx/smdk_spdif.c
+++ b/sound/soc/samsung/smdk_spdif.c
@@ -18,7 +18,7 @@
18 18
19#include <sound/soc.h> 19#include <sound/soc.h>
20 20
21#include "s3c-dma.h" 21#include "dma.h"
22#include "spdif.h" 22#include "spdif.h"
23 23
24/* Audio clock settings are belonged to board specific part. Every 24/* Audio clock settings are belonged to board specific part. Every
@@ -28,7 +28,7 @@
28static int set_audio_clock_heirachy(struct platform_device *pdev) 28static int set_audio_clock_heirachy(struct platform_device *pdev)
29{ 29{
30 struct clk *fout_epll, *mout_epll, *sclk_audio0, *sclk_spdif; 30 struct clk *fout_epll, *mout_epll, *sclk_audio0, *sclk_spdif;
31 int ret; 31 int ret = 0;
32 32
33 fout_epll = clk_get(NULL, "fout_epll"); 33 fout_epll = clk_get(NULL, "fout_epll");
34 if (IS_ERR(fout_epll)) { 34 if (IS_ERR(fout_epll)) {
@@ -61,7 +61,7 @@ static int set_audio_clock_heirachy(struct platform_device *pdev)
61 goto out3; 61 goto out3;
62 } 62 }
63 63
64 /* Set audio clock heirachy for S/PDIF */ 64 /* Set audio clock hierarchy for S/PDIF */
65 clk_set_parent(mout_epll, fout_epll); 65 clk_set_parent(mout_epll, fout_epll);
66 clk_set_parent(sclk_audio0, mout_epll); 66 clk_set_parent(sclk_audio0, mout_epll);
67 clk_set_parent(sclk_spdif, sclk_audio0); 67 clk_set_parent(sclk_spdif, sclk_audio0);
@@ -79,7 +79,7 @@ out1:
79 79
80/* We should haved to set clock directly on this part because of clock 80/* We should haved to set clock directly on this part because of clock
81 * scheme of Samsudng SoCs did not support to set rates from abstrct 81 * scheme of Samsudng SoCs did not support to set rates from abstrct
82 * clock of it's heirachy. 82 * clock of it's hierarchy.
83 */ 83 */
84static int set_audio_clock_rate(unsigned long epll_rate, 84static int set_audio_clock_rate(unsigned long epll_rate,
85 unsigned long audio_rate) 85 unsigned long audio_rate)
@@ -152,12 +152,10 @@ static struct snd_soc_ops smdk_spdif_ops = {
152 .hw_params = smdk_hw_params, 152 .hw_params = smdk_hw_params,
153}; 153};
154 154
155static struct snd_soc_card smdk;
156
157static struct snd_soc_dai_link smdk_dai = { 155static struct snd_soc_dai_link smdk_dai = {
158 .name = "S/PDIF", 156 .name = "S/PDIF",
159 .stream_name = "S/PDIF PCM Playback", 157 .stream_name = "S/PDIF PCM Playback",
160 .platform_name = "s3c24xx-pcm-audio", 158 .platform_name = "samsung-audio",
161 .cpu_dai_name = "samsung-spdif", 159 .cpu_dai_name = "samsung-spdif",
162 .codec_dai_name = "dit-hifi", 160 .codec_dai_name = "dit-hifi",
163 .codec_name = "spdif-dit", 161 .codec_name = "spdif-dit",
@@ -183,7 +181,7 @@ static int __init smdk_init(void)
183 181
184 ret = platform_device_add(smdk_snd_spdif_dit_device); 182 ret = platform_device_add(smdk_snd_spdif_dit_device);
185 if (ret) 183 if (ret)
186 goto err2; 184 goto err1;
187 185
188 smdk_snd_spdif_device = platform_device_alloc("soc-audio", -1); 186 smdk_snd_spdif_device = platform_device_alloc("soc-audio", -1);
189 if (!smdk_snd_spdif_device) { 187 if (!smdk_snd_spdif_device) {
@@ -195,17 +193,21 @@ static int __init smdk_init(void)
195 193
196 ret = platform_device_add(smdk_snd_spdif_device); 194 ret = platform_device_add(smdk_snd_spdif_device);
197 if (ret) 195 if (ret)
198 goto err1; 196 goto err3;
199 197
200 /* Set audio clock heirachy manually */ 198 /* Set audio clock hierarchy manually */
201 ret = set_audio_clock_heirachy(smdk_snd_spdif_device); 199 ret = set_audio_clock_heirachy(smdk_snd_spdif_device);
202 if (ret) 200 if (ret)
203 goto err1; 201 goto err4;
204 202
205 return 0; 203 return 0;
206err1: 204err4:
205 platform_device_del(smdk_snd_spdif_device);
206err3:
207 platform_device_put(smdk_snd_spdif_device); 207 platform_device_put(smdk_snd_spdif_device);
208err2: 208err2:
209 platform_device_del(smdk_snd_spdif_dit_device);
210err1:
209 platform_device_put(smdk_snd_spdif_dit_device); 211 platform_device_put(smdk_snd_spdif_dit_device);
210 return ret; 212 return ret;
211} 213}
@@ -213,6 +215,7 @@ err2:
213static void __exit smdk_exit(void) 215static void __exit smdk_exit(void)
214{ 216{
215 platform_device_unregister(smdk_snd_spdif_device); 217 platform_device_unregister(smdk_snd_spdif_device);
218 platform_device_unregister(smdk_snd_spdif_dit_device);
216} 219}
217 220
218module_init(smdk_init); 221module_init(smdk_init);
diff --git a/sound/soc/s3c24xx/smdk64xx_wm8580.c b/sound/soc/samsung/smdk_wm8580.c
index 052e499b68d1..b2cff1a44aed 100644
--- a/sound/soc/s3c24xx/smdk64xx_wm8580.c
+++ b/sound/soc/samsung/smdk_wm8580.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * smdk64xx_wm8580.c 2 * smdk_wm8580.c
3 * 3 *
4 * Copyright (c) 2009 Samsung Electronics Co. Ltd 4 * Copyright (c) 2009 Samsung Electronics Co. Ltd
5 * Author: Jaswinder Singh <jassi.brar@samsung.com> 5 * Author: Jaswinder Singh <jassi.brar@samsung.com>
@@ -16,11 +16,12 @@
16#include <sound/pcm.h> 16#include <sound/pcm.h>
17#include <sound/pcm_params.h> 17#include <sound/pcm_params.h>
18#include <sound/soc.h> 18#include <sound/soc.h>
19#include <sound/soc-dapm.h> 19
20#include <asm/mach-types.h>
20 21
21#include "../codecs/wm8580.h" 22#include "../codecs/wm8580.h"
22#include "s3c-dma.h" 23#include "dma.h"
23#include "s3c64xx-i2s.h" 24#include "i2s.h"
24 25
25/* 26/*
26 * Default CFG switch settings to use this driver: 27 * Default CFG switch settings to use this driver:
@@ -28,10 +29,10 @@
28 * SMDK6410: Set CFG1 1-3 Off, CFG2 1-4 On 29 * SMDK6410: Set CFG1 1-3 Off, CFG2 1-4 On
29 */ 30 */
30 31
31/* SMDK64XX has a 12MHZ crystal attached to WM8580 */ 32/* SMDK has a 12MHZ crystal attached to WM8580 */
32#define SMDK64XX_WM8580_FREQ 12000000 33#define SMDK_WM8580_FREQ 12000000
33 34
34static int smdk64xx_hw_params(struct snd_pcm_substream *substream, 35static int smdk_hw_params(struct snd_pcm_substream *substream,
35 struct snd_pcm_hw_params *params) 36 struct snd_pcm_hw_params *params)
36{ 37{
37 struct snd_soc_pcm_runtime *rtd = substream->private_data; 38 struct snd_soc_pcm_runtime *rtd = substream->private_data;
@@ -96,17 +97,6 @@ static int smdk64xx_hw_params(struct snd_pcm_substream *substream,
96 if (ret < 0) 97 if (ret < 0)
97 return ret; 98 return ret;
98 99
99 ret = snd_soc_dai_set_sysclk(cpu_dai, S3C64XX_CLKSRC_CDCLK,
100 0, SND_SOC_CLOCK_IN);
101 if (ret < 0)
102 return ret;
103
104 /* We use PCLK for basic ops in SoC-Slave mode */
105 ret = snd_soc_dai_set_sysclk(cpu_dai, S3C64XX_CLKSRC_PCLK,
106 0, SND_SOC_CLOCK_IN);
107 if (ret < 0)
108 return ret;
109
110 /* Set WM8580 to drive MCLK from its PLLA */ 100 /* Set WM8580 to drive MCLK from its PLLA */
111 ret = snd_soc_dai_set_clkdiv(codec_dai, WM8580_MCLK, 101 ret = snd_soc_dai_set_clkdiv(codec_dai, WM8580_MCLK,
112 WM8580_CLKSRC_PLLA); 102 WM8580_CLKSRC_PLLA);
@@ -114,7 +104,7 @@ static int smdk64xx_hw_params(struct snd_pcm_substream *substream,
114 return ret; 104 return ret;
115 105
116 ret = snd_soc_dai_set_pll(codec_dai, WM8580_PLLA, 0, 106 ret = snd_soc_dai_set_pll(codec_dai, WM8580_PLLA, 0,
117 SMDK64XX_WM8580_FREQ, pll_out); 107 SMDK_WM8580_FREQ, pll_out);
118 if (ret < 0) 108 if (ret < 0)
119 return ret; 109 return ret;
120 110
@@ -123,32 +113,24 @@ static int smdk64xx_hw_params(struct snd_pcm_substream *substream,
123 if (ret < 0) 113 if (ret < 0)
124 return ret; 114 return ret;
125 115
126 ret = snd_soc_dai_set_clkdiv(cpu_dai, S3C_I2SV2_DIV_BCLK, bfs);
127 if (ret < 0)
128 return ret;
129
130 ret = snd_soc_dai_set_clkdiv(cpu_dai, S3C_I2SV2_DIV_RCLK, rfs);
131 if (ret < 0)
132 return ret;
133
134 return 0; 116 return 0;
135} 117}
136 118
137/* 119/*
138 * SMDK64XX WM8580 DAI operations. 120 * SMDK WM8580 DAI operations.
139 */ 121 */
140static struct snd_soc_ops smdk64xx_ops = { 122static struct snd_soc_ops smdk_ops = {
141 .hw_params = smdk64xx_hw_params, 123 .hw_params = smdk_hw_params,
142}; 124};
143 125
144/* SMDK64xx Playback widgets */ 126/* SMDK Playback widgets */
145static const struct snd_soc_dapm_widget wm8580_dapm_widgets_pbk[] = { 127static const struct snd_soc_dapm_widget wm8580_dapm_widgets_pbk[] = {
146 SND_SOC_DAPM_HP("Front", NULL), 128 SND_SOC_DAPM_HP("Front", NULL),
147 SND_SOC_DAPM_HP("Center+Sub", NULL), 129 SND_SOC_DAPM_HP("Center+Sub", NULL),
148 SND_SOC_DAPM_HP("Rear", NULL), 130 SND_SOC_DAPM_HP("Rear", NULL),
149}; 131};
150 132
151/* SMDK64xx Capture widgets */ 133/* SMDK Capture widgets */
152static const struct snd_soc_dapm_widget wm8580_dapm_widgets_cpt[] = { 134static const struct snd_soc_dapm_widget wm8580_dapm_widgets_cpt[] = {
153 SND_SOC_DAPM_MIC("MicIn", NULL), 135 SND_SOC_DAPM_MIC("MicIn", NULL),
154 SND_SOC_DAPM_LINE("LineIn", NULL), 136 SND_SOC_DAPM_LINE("LineIn", NULL),
@@ -179,94 +161,132 @@ static const struct snd_soc_dapm_route audio_map_rx[] = {
179 {"Rear", NULL, "VOUT3R"}, 161 {"Rear", NULL, "VOUT3R"},
180}; 162};
181 163
182static int smdk64xx_wm8580_init_paiftx(struct snd_soc_pcm_runtime *rtd) 164static int smdk_wm8580_init_paiftx(struct snd_soc_pcm_runtime *rtd)
183{ 165{
184 struct snd_soc_codec *codec = rtd->codec; 166 struct snd_soc_codec *codec = rtd->codec;
167 struct snd_soc_dapm_context *dapm = &codec->dapm;
185 168
186 /* Add smdk64xx specific Capture widgets */ 169 /* Add smdk specific Capture widgets */
187 snd_soc_dapm_new_controls(codec, wm8580_dapm_widgets_cpt, 170 snd_soc_dapm_new_controls(dapm, wm8580_dapm_widgets_cpt,
188 ARRAY_SIZE(wm8580_dapm_widgets_cpt)); 171 ARRAY_SIZE(wm8580_dapm_widgets_cpt));
189 172
190 /* Set up PAIFTX audio path */ 173 /* Set up PAIFTX audio path */
191 snd_soc_dapm_add_routes(codec, audio_map_tx, ARRAY_SIZE(audio_map_tx)); 174 snd_soc_dapm_add_routes(dapm, audio_map_tx, ARRAY_SIZE(audio_map_tx));
192 175
193 /* Enabling the microphone requires the fitting of a 0R 176 /* Enabling the microphone requires the fitting of a 0R
194 * resistor to connect the line from the microphone jack. 177 * resistor to connect the line from the microphone jack.
195 */ 178 */
196 snd_soc_dapm_disable_pin(codec, "MicIn"); 179 snd_soc_dapm_disable_pin(dapm, "MicIn");
197 180
198 /* signal a DAPM event */ 181 /* signal a DAPM event */
199 snd_soc_dapm_sync(codec); 182 snd_soc_dapm_sync(dapm);
200 183
201 return 0; 184 return 0;
202} 185}
203 186
204static int smdk64xx_wm8580_init_paifrx(struct snd_soc_pcm_runtime *rtd) 187static int smdk_wm8580_init_paifrx(struct snd_soc_pcm_runtime *rtd)
205{ 188{
206 struct snd_soc_codec *codec = rtd->codec; 189 struct snd_soc_codec *codec = rtd->codec;
190 struct snd_soc_dapm_context *dapm = &codec->dapm;
207 191
208 /* Add smdk64xx specific Playback widgets */ 192 /* Add smdk specific Playback widgets */
209 snd_soc_dapm_new_controls(codec, wm8580_dapm_widgets_pbk, 193 snd_soc_dapm_new_controls(dapm, wm8580_dapm_widgets_pbk,
210 ARRAY_SIZE(wm8580_dapm_widgets_pbk)); 194 ARRAY_SIZE(wm8580_dapm_widgets_pbk));
211 195
212 /* Set up PAIFRX audio path */ 196 /* Set up PAIFRX audio path */
213 snd_soc_dapm_add_routes(codec, audio_map_rx, ARRAY_SIZE(audio_map_rx)); 197 snd_soc_dapm_add_routes(dapm, audio_map_rx, ARRAY_SIZE(audio_map_rx));
214 198
215 /* signal a DAPM event */ 199 /* signal a DAPM event */
216 snd_soc_dapm_sync(codec); 200 snd_soc_dapm_sync(dapm);
217 201
218 return 0; 202 return 0;
219} 203}
220 204
221static struct snd_soc_dai_link smdk64xx_dai[] = { 205enum {
222{ /* Primary Playback i/f */ 206 PRI_PLAYBACK = 0,
223 .name = "WM8580 PAIF RX", 207 PRI_CAPTURE,
224 .stream_name = "Playback", 208 SEC_PLAYBACK,
225 .cpu_dai_name = "s3c64xx-iis-v4", 209};
226 .codec_dai_name = "wm8580-hifi-playback", 210
227 .platform_name = "s3c24xx-pcm-audio", 211static struct snd_soc_dai_link smdk_dai[] = {
228 .codec_name = "wm8580-codec.0-001b", 212 [PRI_PLAYBACK] = { /* Primary Playback i/f */
229 .init = smdk64xx_wm8580_init_paifrx, 213 .name = "WM8580 PAIF RX",
230 .ops = &smdk64xx_ops, 214 .stream_name = "Playback",
231}, 215 .cpu_dai_name = "samsung-i2s.0",
232{ /* Primary Capture i/f */ 216 .codec_dai_name = "wm8580-hifi-playback",
233 .name = "WM8580 PAIF TX", 217 .platform_name = "samsung-audio",
234 .stream_name = "Capture", 218 .codec_name = "wm8580-codec.0-001b",
235 .cpu_dai_name = "s3c64xx-iis-v4", 219 .init = smdk_wm8580_init_paifrx,
236 .codec_dai_name = "wm8580-hifi-capture", 220 .ops = &smdk_ops,
237 .platform_name = "s3c24xx-pcm-audio", 221 },
238 .codec_name = "wm8580-codec.0-001b", 222 [PRI_CAPTURE] = { /* Primary Capture i/f */
239 .init = smdk64xx_wm8580_init_paiftx, 223 .name = "WM8580 PAIF TX",
240 .ops = &smdk64xx_ops, 224 .stream_name = "Capture",
241}, 225 .cpu_dai_name = "samsung-i2s.0",
226 .codec_dai_name = "wm8580-hifi-capture",
227 .platform_name = "samsung-audio",
228 .codec_name = "wm8580-codec.0-001b",
229 .init = smdk_wm8580_init_paiftx,
230 .ops = &smdk_ops,
231 },
232 [SEC_PLAYBACK] = { /* Sec_Fifo Playback i/f */
233 .name = "Sec_FIFO TX",
234 .stream_name = "Playback",
235 .cpu_dai_name = "samsung-i2s.x",
236 .codec_dai_name = "wm8580-hifi-playback",
237 .platform_name = "samsung-audio",
238 .codec_name = "wm8580-codec.0-001b",
239 .init = smdk_wm8580_init_paifrx,
240 .ops = &smdk_ops,
241 },
242}; 242};
243 243
244static struct snd_soc_card smdk64xx = { 244static struct snd_soc_card smdk = {
245 .name = "SMDK64xx 5.1", 245 .name = "SMDK-I2S",
246 .dai_link = smdk64xx_dai, 246 .dai_link = smdk_dai,
247 .num_links = ARRAY_SIZE(smdk64xx_dai), 247 .num_links = 2,
248}; 248};
249 249
250static struct platform_device *smdk64xx_snd_device; 250static struct platform_device *smdk_snd_device;
251 251
252static int __init smdk64xx_audio_init(void) 252static int __init smdk_audio_init(void)
253{ 253{
254 int ret; 254 int ret;
255 char *str;
256
257 if (machine_is_smdkc100() || machine_is_smdk6442()
258 || machine_is_smdkv210() || machine_is_smdkc110()) {
259 smdk.num_links = 3;
260 /* Secondary is at offset SAMSUNG_I2S_SECOFF from Primary */
261 str = (char *)smdk_dai[SEC_PLAYBACK].cpu_dai_name;
262 str[strlen(str) - 1] = '0' + SAMSUNG_I2S_SECOFF;
263 } else if (machine_is_smdk6410()) {
264 str = (char *)smdk_dai[PRI_PLAYBACK].cpu_dai_name;
265 str[strlen(str) - 1] = '2';
266 str = (char *)smdk_dai[PRI_CAPTURE].cpu_dai_name;
267 str[strlen(str) - 1] = '2';
268 }
255 269
256 smdk64xx_snd_device = platform_device_alloc("soc-audio", -1); 270 smdk_snd_device = platform_device_alloc("soc-audio", -1);
257 if (!smdk64xx_snd_device) 271 if (!smdk_snd_device)
258 return -ENOMEM; 272 return -ENOMEM;
259 273
260 platform_set_drvdata(smdk64xx_snd_device, &smdk64xx); 274 platform_set_drvdata(smdk_snd_device, &smdk);
261 ret = platform_device_add(smdk64xx_snd_device); 275 ret = platform_device_add(smdk_snd_device);
262 276
263 if (ret) 277 if (ret)
264 platform_device_put(smdk64xx_snd_device); 278 platform_device_put(smdk_snd_device);
265 279
266 return ret; 280 return ret;
267} 281}
268module_init(smdk64xx_audio_init); 282module_init(smdk_audio_init);
283
284static void __exit smdk_audio_exit(void)
285{
286 platform_device_unregister(smdk_snd_device);
287}
288module_exit(smdk_audio_exit);
269 289
270MODULE_AUTHOR("Jaswinder Singh, jassi.brar@samsung.com"); 290MODULE_AUTHOR("Jaswinder Singh, jassi.brar@samsung.com");
271MODULE_DESCRIPTION("ALSA SoC SMDK64XX WM8580"); 291MODULE_DESCRIPTION("ALSA SoC SMDK WM8580");
272MODULE_LICENSE("GPL"); 292MODULE_LICENSE("GPL");
diff --git a/sound/soc/samsung/smdk_wm8994.c b/sound/soc/samsung/smdk_wm8994.c
new file mode 100644
index 000000000000..e7c1009a1e1d
--- /dev/null
+++ b/sound/soc/samsung/smdk_wm8994.c
@@ -0,0 +1,176 @@
1/*
2 * smdk_wm8994.c
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License as published by the
6 * Free Software Foundation; either version 2 of the License, or (at your
7 * option) any later version.
8 */
9
10#include "../codecs/wm8994.h"
11
12 /*
13 * Default CFG switch settings to use this driver:
14 * SMDKV310: CFG5-1000, CFG7-111111
15 */
16
17 /*
18 * Configure audio route as :-
19 * $ amixer sset 'DAC1' on,on
20 * $ amixer sset 'Right Headphone Mux' 'DAC'
21 * $ amixer sset 'Left Headphone Mux' 'DAC'
22 * $ amixer sset 'DAC1R Mixer AIF1.1' on
23 * $ amixer sset 'DAC1L Mixer AIF1.1' on
24 * $ amixer sset 'IN2L' on
25 * $ amixer sset 'IN2L PGA IN2LN' on
26 * $ amixer sset 'MIXINL IN2L' on
27 * $ amixer sset 'AIF1ADC1L Mixer ADC/DMIC' on
28 * $ amixer sset 'IN2R' on
29 * $ amixer sset 'IN2R PGA IN2RN' on
30 * $ amixer sset 'MIXINR IN2R' on
31 * $ amixer sset 'AIF1ADC1R Mixer ADC/DMIC' on
32 */
33
34/* SMDK has a 16.934MHZ crystal attached to WM8994 */
35#define SMDK_WM8994_FREQ 16934000
36
37static int smdk_hw_params(struct snd_pcm_substream *substream,
38 struct snd_pcm_hw_params *params)
39{
40 struct snd_soc_pcm_runtime *rtd = substream->private_data;
41 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
42 struct snd_soc_dai *codec_dai = rtd->codec_dai;
43 unsigned int pll_out;
44 int ret;
45
46 /* AIF1CLK should be >=3MHz for optimal performance */
47 if (params_rate(params) == 8000 || params_rate(params) == 11025)
48 pll_out = params_rate(params) * 512;
49 else
50 pll_out = params_rate(params) * 256;
51
52 ret = snd_soc_dai_set_fmt(codec_dai, SND_SOC_DAIFMT_I2S
53 | SND_SOC_DAIFMT_NB_NF
54 | SND_SOC_DAIFMT_CBM_CFM);
55 if (ret < 0)
56 return ret;
57
58 ret = snd_soc_dai_set_fmt(cpu_dai, SND_SOC_DAIFMT_I2S
59 | SND_SOC_DAIFMT_NB_NF
60 | SND_SOC_DAIFMT_CBM_CFM);
61 if (ret < 0)
62 return ret;
63
64 ret = snd_soc_dai_set_pll(codec_dai, WM8994_FLL1, WM8994_FLL_SRC_MCLK1,
65 SMDK_WM8994_FREQ, pll_out);
66 if (ret < 0)
67 return ret;
68
69 ret = snd_soc_dai_set_sysclk(codec_dai, WM8994_SYSCLK_FLL1,
70 pll_out, SND_SOC_CLOCK_IN);
71 if (ret < 0)
72 return ret;
73
74 return 0;
75}
76
77/*
78 * SMDK WM8994 DAI operations.
79 */
80static struct snd_soc_ops smdk_ops = {
81 .hw_params = smdk_hw_params,
82};
83
84static int smdk_wm8994_init_paiftx(struct snd_soc_pcm_runtime *rtd)
85{
86 struct snd_soc_codec *codec = rtd->codec;
87 struct snd_soc_dapm_context *dapm = &codec->dapm;
88
89 /* HeadPhone */
90 snd_soc_dapm_enable_pin(dapm, "HPOUT1R");
91 snd_soc_dapm_enable_pin(dapm, "HPOUT1L");
92
93 /* MicIn */
94 snd_soc_dapm_enable_pin(dapm, "IN1LN");
95 snd_soc_dapm_enable_pin(dapm, "IN1RN");
96
97 /* LineIn */
98 snd_soc_dapm_enable_pin(dapm, "IN2LN");
99 snd_soc_dapm_enable_pin(dapm, "IN2RN");
100
101 /* Other pins NC */
102 snd_soc_dapm_nc_pin(dapm, "HPOUT2P");
103 snd_soc_dapm_nc_pin(dapm, "HPOUT2N");
104 snd_soc_dapm_nc_pin(dapm, "SPKOUTLN");
105 snd_soc_dapm_nc_pin(dapm, "SPKOUTLP");
106 snd_soc_dapm_nc_pin(dapm, "SPKOUTRP");
107 snd_soc_dapm_nc_pin(dapm, "SPKOUTRN");
108 snd_soc_dapm_nc_pin(dapm, "LINEOUT1N");
109 snd_soc_dapm_nc_pin(dapm, "LINEOUT1P");
110 snd_soc_dapm_nc_pin(dapm, "LINEOUT2N");
111 snd_soc_dapm_nc_pin(dapm, "LINEOUT2P");
112 snd_soc_dapm_nc_pin(dapm, "IN1LP");
113 snd_soc_dapm_nc_pin(dapm, "IN2LP:VXRN");
114 snd_soc_dapm_nc_pin(dapm, "IN1RP");
115 snd_soc_dapm_nc_pin(dapm, "IN2RP:VXRP");
116
117 snd_soc_dapm_sync(dapm);
118
119 return 0;
120}
121
122static struct snd_soc_dai_link smdk_dai[] = {
123 { /* Primary DAI i/f */
124 .name = "WM8994 AIF1",
125 .stream_name = "Pri_Dai",
126 .cpu_dai_name = "samsung-i2s.0",
127 .codec_dai_name = "wm8994-aif1",
128 .platform_name = "samsung-audio",
129 .codec_name = "wm8994-codec",
130 .init = smdk_wm8994_init_paiftx,
131 .ops = &smdk_ops,
132 }, { /* Sec_Fifo Playback i/f */
133 .name = "Sec_FIFO TX",
134 .stream_name = "Sec_Dai",
135 .cpu_dai_name = "samsung-i2s.4",
136 .codec_dai_name = "wm8994-aif1",
137 .platform_name = "samsung-audio",
138 .codec_name = "wm8994-codec",
139 .ops = &smdk_ops,
140 },
141};
142
143static struct snd_soc_card smdk = {
144 .name = "SMDK-I2S",
145 .dai_link = smdk_dai,
146 .num_links = ARRAY_SIZE(smdk_dai),
147};
148
149static struct platform_device *smdk_snd_device;
150
151static int __init smdk_audio_init(void)
152{
153 int ret;
154
155 smdk_snd_device = platform_device_alloc("soc-audio", -1);
156 if (!smdk_snd_device)
157 return -ENOMEM;
158
159 platform_set_drvdata(smdk_snd_device, &smdk);
160
161 ret = platform_device_add(smdk_snd_device);
162 if (ret)
163 platform_device_put(smdk_snd_device);
164
165 return ret;
166}
167module_init(smdk_audio_init);
168
169static void __exit smdk_audio_exit(void)
170{
171 platform_device_unregister(smdk_snd_device);
172}
173module_exit(smdk_audio_exit);
174
175MODULE_DESCRIPTION("ALSA SoC SMDK WM8994");
176MODULE_LICENSE("GPL");
diff --git a/sound/soc/s3c24xx/smdk_wm9713.c b/sound/soc/samsung/smdk_wm9713.c
index 33ba8fdbcf07..ae5fed6f772f 100644
--- a/sound/soc/s3c24xx/smdk_wm9713.c
+++ b/sound/soc/samsung/smdk_wm9713.c
@@ -15,8 +15,8 @@
15#include <linux/device.h> 15#include <linux/device.h>
16#include <sound/soc.h> 16#include <sound/soc.h>
17 17
18#include "s3c-dma.h" 18#include "dma.h"
19#include "s3c-ac97.h" 19#include "ac97.h"
20 20
21static struct snd_soc_card smdk; 21static struct snd_soc_card smdk;
22 22
@@ -27,6 +27,7 @@ static struct snd_soc_card smdk;
27 * SMDKC100: Set CFG6 1-3 On, CFG7 1 On 27 * SMDKC100: Set CFG6 1-3 On, CFG7 1 On
28 * SMDKC110: Set CFGB10 1-2 Off, CFGB12 1-3 On 28 * SMDKC110: Set CFGB10 1-2 Off, CFGB12 1-3 On
29 * SMDKV210: Set CFGB10 1-2 Off, CFGB12 1-3 On 29 * SMDKV210: Set CFGB10 1-2 Off, CFGB12 1-3 On
30 * SMDKV310: Set CFG2 1-2 Off, CFG4 All On, CFG7 All Off, CFG8 1-On
30 */ 31 */
31 32
32/* 33/*
@@ -45,8 +46,8 @@ static struct snd_soc_card smdk;
45static struct snd_soc_dai_link smdk_dai = { 46static struct snd_soc_dai_link smdk_dai = {
46 .name = "AC97", 47 .name = "AC97",
47 .stream_name = "AC97 PCM", 48 .stream_name = "AC97 PCM",
48 .platform_name = "s3c24xx-pcm-audio", 49 .platform_name = "samsung-audio",
49 .cpu_dai_name = "s3c-ac97", 50 .cpu_dai_name = "samsung-ac97",
50 .codec_dai_name = "wm9713-hifi", 51 .codec_dai_name = "wm9713-hifi",
51 .codec_name = "wm9713-codec", 52 .codec_name = "wm9713-codec",
52}; 53};
@@ -70,24 +71,27 @@ static int __init smdk_init(void)
70 71
71 ret = platform_device_add(smdk_snd_wm9713_device); 72 ret = platform_device_add(smdk_snd_wm9713_device);
72 if (ret) 73 if (ret)
73 goto err; 74 goto err1;
74 75
75 smdk_snd_ac97_device = platform_device_alloc("soc-audio", -1); 76 smdk_snd_ac97_device = platform_device_alloc("soc-audio", -1);
76 if (!smdk_snd_ac97_device) { 77 if (!smdk_snd_ac97_device) {
77 ret = -ENOMEM; 78 ret = -ENOMEM;
78 goto err; 79 goto err2;
79 } 80 }
80 81
81 platform_set_drvdata(smdk_snd_ac97_device, &smdk); 82 platform_set_drvdata(smdk_snd_ac97_device, &smdk);
82 83
83 ret = platform_device_add(smdk_snd_ac97_device); 84 ret = platform_device_add(smdk_snd_ac97_device);
84 if (ret) { 85 if (ret)
85 platform_device_put(smdk_snd_ac97_device); 86 goto err3;
86 goto err;
87 }
88 87
89 return 0; 88 return 0;
90err: 89
90err3:
91 platform_device_put(smdk_snd_ac97_device);
92err2:
93 platform_device_del(smdk_snd_wm9713_device);
94err1:
91 platform_device_put(smdk_snd_wm9713_device); 95 platform_device_put(smdk_snd_wm9713_device);
92 return ret; 96 return ret;
93} 97}
diff --git a/sound/soc/s3c24xx/spdif.c b/sound/soc/samsung/spdif.c
index ce554e9cabcc..f0816404ea3e 100644
--- a/sound/soc/s3c24xx/spdif.c
+++ b/sound/soc/samsung/spdif.c
@@ -1,4 +1,4 @@
1/* sound/soc/s3c24xx/spdif.c 1/* sound/soc/samsung/spdif.c
2 * 2 *
3 * ALSA SoC Audio Layer - Samsung S/PDIF Controller driver 3 * ALSA SoC Audio Layer - Samsung S/PDIF Controller driver
4 * 4 *
@@ -20,7 +20,7 @@
20#include <plat/audio.h> 20#include <plat/audio.h>
21#include <mach/dma.h> 21#include <mach/dma.h>
22 22
23#include "s3c-dma.h" 23#include "dma.h"
24#include "spdif.h" 24#include "spdif.h"
25 25
26/* Registers */ 26/* Registers */
diff --git a/sound/soc/s3c24xx/spdif.h b/sound/soc/samsung/spdif.h
index 3ed55592710f..4f72cb446dbf 100644
--- a/sound/soc/s3c24xx/spdif.h
+++ b/sound/soc/samsung/spdif.h
@@ -1,4 +1,4 @@
1/* sound/soc/s3c24xx/spdif.h 1/* sound/soc/samsung/spdif.h
2 * 2 *
3 * ALSA SoC Audio Layer - Samsung S/PDIF Controller driver 3 * ALSA SoC Audio Layer - Samsung S/PDIF Controller driver
4 * 4 *
diff --git a/sound/soc/sh/Kconfig b/sound/soc/sh/Kconfig
index 7f0a496e07ce..d8e06a607a22 100644
--- a/sound/soc/sh/Kconfig
+++ b/sound/soc/sh/Kconfig
@@ -48,7 +48,7 @@ config SND_SH7760_AC97
48 48
49config SND_FSI_AK4642 49config SND_FSI_AK4642
50 tristate "FSI-AK4642 sound support" 50 tristate "FSI-AK4642 sound support"
51 depends on SND_SOC_SH4_FSI && I2C_SH_MOBILE 51 depends on SND_SOC_SH4_FSI && I2C
52 select SND_SOC_AK4642 52 select SND_SOC_AK4642
53 help 53 help
54 This option enables generic sound support for the 54 This option enables generic sound support for the
@@ -56,7 +56,7 @@ config SND_FSI_AK4642
56 56
57config SND_FSI_DA7210 57config SND_FSI_DA7210
58 tristate "FSI-DA7210 sound support" 58 tristate "FSI-DA7210 sound support"
59 depends on SND_SOC_SH4_FSI && I2C_SH_MOBILE 59 depends on SND_SOC_SH4_FSI && I2C
60 select SND_SOC_DA7210 60 select SND_SOC_DA7210
61 help 61 help
62 This option enables generic sound support for the 62 This option enables generic sound support for the
diff --git a/sound/soc/sh/fsi-ak4642.c b/sound/soc/sh/fsi-ak4642.c
index d96602de71de..a14820ac9665 100644
--- a/sound/soc/sh/fsi-ak4642.c
+++ b/sound/soc/sh/fsi-ak4642.c
@@ -12,6 +12,14 @@
12#include <linux/platform_device.h> 12#include <linux/platform_device.h>
13#include <sound/sh_fsi.h> 13#include <sound/sh_fsi.h>
14 14
15struct fsi_ak4642_data {
16 const char *name;
17 const char *card;
18 const char *cpu_dai;
19 const char *codec;
20 const char *platform;
21};
22
15static int fsi_ak4642_dai_init(struct snd_soc_pcm_runtime *rtd) 23static int fsi_ak4642_dai_init(struct snd_soc_pcm_runtime *rtd)
16{ 24{
17 struct snd_soc_dai *dai = rtd->codec_dai; 25 struct snd_soc_dai *dai = rtd->codec_dai;
@@ -27,37 +35,42 @@ static int fsi_ak4642_dai_init(struct snd_soc_pcm_runtime *rtd)
27} 35}
28 36
29static struct snd_soc_dai_link fsi_dai_link = { 37static struct snd_soc_dai_link fsi_dai_link = {
30 .name = "AK4642",
31 .stream_name = "AK4642",
32 .cpu_dai_name = "fsia-dai", /* fsi A */
33 .codec_dai_name = "ak4642-hifi", 38 .codec_dai_name = "ak4642-hifi",
34#ifdef CONFIG_MACH_AP4EVB
35 .platform_name = "sh_fsi2",
36 .codec_name = "ak4642-codec.0-0013",
37#else
38 .platform_name = "sh_fsi.0",
39 .codec_name = "ak4642-codec.0-0012",
40#endif
41 .init = fsi_ak4642_dai_init, 39 .init = fsi_ak4642_dai_init,
42 .ops = NULL,
43}; 40};
44 41
45static struct snd_soc_card fsi_soc_card = { 42static struct snd_soc_card fsi_soc_card = {
46 .name = "FSI (AK4642)",
47 .dai_link = &fsi_dai_link, 43 .dai_link = &fsi_dai_link,
48 .num_links = 1, 44 .num_links = 1,
49}; 45};
50 46
51static struct platform_device *fsi_snd_device; 47static struct platform_device *fsi_snd_device;
52 48
53static int __init fsi_ak4642_init(void) 49static int fsi_ak4642_probe(struct platform_device *pdev)
54{ 50{
55 int ret = -ENOMEM; 51 int ret = -ENOMEM;
52 const struct platform_device_id *id_entry;
53 struct fsi_ak4642_data *pdata;
54
55 id_entry = pdev->id_entry;
56 if (!id_entry) {
57 dev_err(&pdev->dev, "unknown fsi ak4642\n");
58 return -ENODEV;
59 }
60
61 pdata = (struct fsi_ak4642_data *)id_entry->driver_data;
56 62
57 fsi_snd_device = platform_device_alloc("soc-audio", FSI_PORT_A); 63 fsi_snd_device = platform_device_alloc("soc-audio", FSI_PORT_A);
58 if (!fsi_snd_device) 64 if (!fsi_snd_device)
59 goto out; 65 goto out;
60 66
67 fsi_dai_link.name = pdata->name;
68 fsi_dai_link.stream_name = pdata->name;
69 fsi_dai_link.cpu_dai_name = pdata->cpu_dai;
70 fsi_dai_link.platform_name = pdata->platform;
71 fsi_dai_link.codec_name = pdata->codec;
72 fsi_soc_card.name = pdata->card;
73
61 platform_set_drvdata(fsi_snd_device, &fsi_soc_card); 74 platform_set_drvdata(fsi_snd_device, &fsi_soc_card);
62 ret = platform_device_add(fsi_snd_device); 75 ret = platform_device_add(fsi_snd_device);
63 76
@@ -68,9 +81,108 @@ out:
68 return ret; 81 return ret;
69} 82}
70 83
71static void __exit fsi_ak4642_exit(void) 84static int fsi_ak4642_remove(struct platform_device *pdev)
72{ 85{
73 platform_device_unregister(fsi_snd_device); 86 platform_device_unregister(fsi_snd_device);
87 return 0;
88}
89
90static struct fsi_ak4642_data fsi_a_ak4642 = {
91 .name = "AK4642",
92 .card = "FSIA (AK4642)",
93 .cpu_dai = "fsia-dai",
94 .codec = "ak4642-codec.0-0012",
95 .platform = "sh_fsi.0",
96};
97
98static struct fsi_ak4642_data fsi_b_ak4642 = {
99 .name = "AK4642",
100 .card = "FSIB (AK4642)",
101 .cpu_dai = "fsib-dai",
102 .codec = "ak4642-codec.0-0012",
103 .platform = "sh_fsi.0",
104};
105
106static struct fsi_ak4642_data fsi_a_ak4643 = {
107 .name = "AK4643",
108 .card = "FSIA (AK4643)",
109 .cpu_dai = "fsia-dai",
110 .codec = "ak4642-codec.0-0013",
111 .platform = "sh_fsi.0",
112};
113
114static struct fsi_ak4642_data fsi_b_ak4643 = {
115 .name = "AK4643",
116 .card = "FSIB (AK4643)",
117 .cpu_dai = "fsib-dai",
118 .codec = "ak4642-codec.0-0013",
119 .platform = "sh_fsi.0",
120};
121
122static struct fsi_ak4642_data fsi2_a_ak4642 = {
123 .name = "AK4642",
124 .card = "FSI2A (AK4642)",
125 .cpu_dai = "fsia-dai",
126 .codec = "ak4642-codec.0-0012",
127 .platform = "sh_fsi2",
128};
129
130static struct fsi_ak4642_data fsi2_b_ak4642 = {
131 .name = "AK4642",
132 .card = "FSI2B (AK4642)",
133 .cpu_dai = "fsib-dai",
134 .codec = "ak4642-codec.0-0012",
135 .platform = "sh_fsi2",
136};
137
138static struct fsi_ak4642_data fsi2_a_ak4643 = {
139 .name = "AK4643",
140 .card = "FSI2A (AK4643)",
141 .cpu_dai = "fsia-dai",
142 .codec = "ak4642-codec.0-0013",
143 .platform = "sh_fsi2",
144};
145
146static struct fsi_ak4642_data fsi2_b_ak4643 = {
147 .name = "AK4643",
148 .card = "FSI2B (AK4643)",
149 .cpu_dai = "fsib-dai",
150 .codec = "ak4642-codec.0-0013",
151 .platform = "sh_fsi2",
152};
153
154static struct platform_device_id fsi_id_table[] = {
155 /* FSI */
156 { "sh_fsi_a_ak4642", (kernel_ulong_t)&fsi_a_ak4642 },
157 { "sh_fsi_b_ak4642", (kernel_ulong_t)&fsi_b_ak4642 },
158 { "sh_fsi_a_ak4643", (kernel_ulong_t)&fsi_a_ak4643 },
159 { "sh_fsi_b_ak4643", (kernel_ulong_t)&fsi_b_ak4643 },
160
161 /* FSI 2 */
162 { "sh_fsi2_a_ak4642", (kernel_ulong_t)&fsi2_a_ak4642 },
163 { "sh_fsi2_b_ak4642", (kernel_ulong_t)&fsi2_b_ak4642 },
164 { "sh_fsi2_a_ak4643", (kernel_ulong_t)&fsi2_a_ak4643 },
165 { "sh_fsi2_b_ak4643", (kernel_ulong_t)&fsi2_b_ak4643 },
166 {},
167};
168
169static struct platform_driver fsi_ak4642 = {
170 .driver = {
171 .name = "fsi-ak4642-audio",
172 },
173 .probe = fsi_ak4642_probe,
174 .remove = fsi_ak4642_remove,
175 .id_table = fsi_id_table,
176};
177
178static int __init fsi_ak4642_init(void)
179{
180 return platform_driver_register(&fsi_ak4642);
181}
182
183static void __exit fsi_ak4642_exit(void)
184{
185 platform_driver_unregister(&fsi_ak4642);
74} 186}
75 187
76module_init(fsi_ak4642_init); 188module_init(fsi_ak4642_init);
diff --git a/sound/soc/sh/fsi-da7210.c b/sound/soc/sh/fsi-da7210.c
index a6adb6e43250..e8df9da92f71 100644
--- a/sound/soc/sh/fsi-da7210.c
+++ b/sound/soc/sh/fsi-da7210.c
@@ -18,7 +18,7 @@ static int fsi_da7210_init(struct snd_soc_pcm_runtime *rtd)
18 struct snd_soc_dai *dai = rtd->codec_dai; 18 struct snd_soc_dai *dai = rtd->codec_dai;
19 19
20 return snd_soc_dai_set_fmt(dai, 20 return snd_soc_dai_set_fmt(dai,
21 SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF | 21 SND_SOC_DAIFMT_I2S |
22 SND_SOC_DAIFMT_CBM_CFM); 22 SND_SOC_DAIFMT_CBM_CFM);
23} 23}
24 24
diff --git a/sound/soc/sh/fsi.c b/sound/soc/sh/fsi.c
index 4c2404b1b862..2b06402801ef 100644
--- a/sound/soc/sh/fsi.c
+++ b/sound/soc/sh/fsi.c
@@ -19,20 +19,26 @@
19#include <sound/soc.h> 19#include <sound/soc.h>
20#include <sound/sh_fsi.h> 20#include <sound/sh_fsi.h>
21 21
22#define DO_FMT 0x0000 22/* PortA/PortB register */
23#define DOFF_CTL 0x0004 23#define REG_DO_FMT 0x0000
24#define DOFF_ST 0x0008 24#define REG_DOFF_CTL 0x0004
25#define DI_FMT 0x000C 25#define REG_DOFF_ST 0x0008
26#define DIFF_CTL 0x0010 26#define REG_DI_FMT 0x000C
27#define DIFF_ST 0x0014 27#define REG_DIFF_CTL 0x0010
28#define CKG1 0x0018 28#define REG_DIFF_ST 0x0014
29#define CKG2 0x001C 29#define REG_CKG1 0x0018
30#define DIDT 0x0020 30#define REG_CKG2 0x001C
31#define DODT 0x0024 31#define REG_DIDT 0x0020
32#define MUTE_ST 0x0028 32#define REG_DODT 0x0024
33#define OUT_SEL 0x0030 33#define REG_MUTE_ST 0x0028
34#define REG_END OUT_SEL 34#define REG_OUT_SEL 0x0030
35 35
36/* master register */
37#define MST_CLK_RST 0x0210
38#define MST_SOFT_RST 0x0214
39#define MST_FIFO_SZ 0x0218
40
41/* core register (depend on FSI version) */
36#define A_MST_CTLR 0x0180 42#define A_MST_CTLR 0x0180
37#define B_MST_CTLR 0x01A0 43#define B_MST_CTLR 0x01A0
38#define CPU_INT_ST 0x01F4 44#define CPU_INT_ST 0x01F4
@@ -41,22 +47,23 @@
41#define INT_ST 0x0200 47#define INT_ST 0x0200
42#define IEMSK 0x0204 48#define IEMSK 0x0204
43#define IMSK 0x0208 49#define IMSK 0x0208
44#define MUTE 0x020C
45#define CLK_RST 0x0210
46#define SOFT_RST 0x0214
47#define FIFO_SZ 0x0218
48#define MREG_START A_MST_CTLR
49#define MREG_END FIFO_SZ
50 50
51/* DO_FMT */ 51/* DO_FMT */
52/* DI_FMT */ 52/* DI_FMT */
53#define CR_BWS_24 (0x0 << 20) /* FSI2 */
54#define CR_BWS_16 (0x1 << 20) /* FSI2 */
55#define CR_BWS_20 (0x2 << 20) /* FSI2 */
56
57#define CR_DTMD_PCM (0x0 << 8) /* FSI2 */
58#define CR_DTMD_SPDIF_PCM (0x1 << 8) /* FSI2 */
59#define CR_DTMD_SPDIF_STREAM (0x2 << 8) /* FSI2 */
60
53#define CR_MONO (0x0 << 4) 61#define CR_MONO (0x0 << 4)
54#define CR_MONO_D (0x1 << 4) 62#define CR_MONO_D (0x1 << 4)
55#define CR_PCM (0x2 << 4) 63#define CR_PCM (0x2 << 4)
56#define CR_I2S (0x3 << 4) 64#define CR_I2S (0x3 << 4)
57#define CR_TDM (0x4 << 4) 65#define CR_TDM (0x4 << 4)
58#define CR_TDM_D (0x5 << 4) 66#define CR_TDM_D (0x5 << 4)
59#define CR_SPDIF 0x00100120
60 67
61/* DOFF_CTL */ 68/* DOFF_CTL */
62/* DIFF_CTL */ 69/* DIFF_CTL */
@@ -93,6 +100,10 @@
93#define IR (1 << 4) /* Interrupt Reset */ 100#define IR (1 << 4) /* Interrupt Reset */
94#define FSISR (1 << 0) /* Software Reset */ 101#define FSISR (1 << 0) /* Software Reset */
95 102
103/* OUT_SEL (FSI2) */
104#define DMMD (1 << 4) /* SPDIF output timing 0: Biphase only */
105 /* 1: Biphase and serial */
106
96/* FIFO_SZ */ 107/* FIFO_SZ */
97#define FIFO_SZ_MASK 0x7 108#define FIFO_SZ_MASK 0x7
98 109
@@ -123,6 +134,9 @@ struct fsi_stream {
123 int buff_len; 134 int buff_len;
124 int period_len; 135 int period_len;
125 int period_num; 136 int period_num;
137
138 int uerr_num;
139 int oerr_num;
126}; 140};
127 141
128struct fsi_priv { 142struct fsi_priv {
@@ -133,8 +147,6 @@ struct fsi_priv {
133 struct fsi_stream capture; 147 struct fsi_stream capture;
134 148
135 long rate; 149 long rate;
136
137 u32 mst_ctrl;
138}; 150};
139 151
140struct fsi_core { 152struct fsi_core {
@@ -143,6 +155,8 @@ struct fsi_core {
143 u32 int_st; 155 u32 int_st;
144 u32 iemsk; 156 u32 iemsk;
145 u32 imsk; 157 u32 imsk;
158 u32 a_mclk;
159 u32 b_mclk;
146}; 160};
147 161
148struct fsi_master { 162struct fsi_master {
@@ -182,62 +196,22 @@ static void __fsi_reg_mask_set(u32 reg, u32 mask, u32 data)
182 __fsi_reg_write(reg, val); 196 __fsi_reg_write(reg, val);
183} 197}
184 198
185static void fsi_reg_write(struct fsi_priv *fsi, u32 reg, u32 data) 199#define fsi_reg_write(p, r, d)\
186{ 200 __fsi_reg_write((u32)(p->base + REG_##r), d)
187 if (reg > REG_END) {
188 pr_err("fsi: register access err (%s)\n", __func__);
189 return;
190 }
191 201
192 __fsi_reg_write((u32)(fsi->base + reg), data); 202#define fsi_reg_read(p, r)\
193} 203 __fsi_reg_read((u32)(p->base + REG_##r))
194 204
195static u32 fsi_reg_read(struct fsi_priv *fsi, u32 reg) 205#define fsi_reg_mask_set(p, r, m, d)\
196{ 206 __fsi_reg_mask_set((u32)(p->base + REG_##r), m, d)
197 if (reg > REG_END) {
198 pr_err("fsi: register access err (%s)\n", __func__);
199 return 0;
200 }
201 207
202 return __fsi_reg_read((u32)(fsi->base + reg)); 208#define fsi_master_read(p, r) _fsi_master_read(p, MST_##r)
203} 209#define fsi_core_read(p, r) _fsi_master_read(p, p->core->r)
204 210static u32 _fsi_master_read(struct fsi_master *master, u32 reg)
205static void fsi_reg_mask_set(struct fsi_priv *fsi, u32 reg, u32 mask, u32 data)
206{
207 if (reg > REG_END) {
208 pr_err("fsi: register access err (%s)\n", __func__);
209 return;
210 }
211
212 __fsi_reg_mask_set((u32)(fsi->base + reg), mask, data);
213}
214
215static void fsi_master_write(struct fsi_master *master, u32 reg, u32 data)
216{
217 unsigned long flags;
218
219 if ((reg < MREG_START) ||
220 (reg > MREG_END)) {
221 pr_err("fsi: register access err (%s)\n", __func__);
222 return;
223 }
224
225 spin_lock_irqsave(&master->lock, flags);
226 __fsi_reg_write((u32)(master->base + reg), data);
227 spin_unlock_irqrestore(&master->lock, flags);
228}
229
230static u32 fsi_master_read(struct fsi_master *master, u32 reg)
231{ 211{
232 u32 ret; 212 u32 ret;
233 unsigned long flags; 213 unsigned long flags;
234 214
235 if ((reg < MREG_START) ||
236 (reg > MREG_END)) {
237 pr_err("fsi: register access err (%s)\n", __func__);
238 return 0;
239 }
240
241 spin_lock_irqsave(&master->lock, flags); 215 spin_lock_irqsave(&master->lock, flags);
242 ret = __fsi_reg_read((u32)(master->base + reg)); 216 ret = __fsi_reg_read((u32)(master->base + reg));
243 spin_unlock_irqrestore(&master->lock, flags); 217 spin_unlock_irqrestore(&master->lock, flags);
@@ -245,17 +219,13 @@ static u32 fsi_master_read(struct fsi_master *master, u32 reg)
245 return ret; 219 return ret;
246} 220}
247 221
248static void fsi_master_mask_set(struct fsi_master *master, 222#define fsi_master_mask_set(p, r, m, d) _fsi_master_mask_set(p, MST_##r, m, d)
223#define fsi_core_mask_set(p, r, m, d) _fsi_master_mask_set(p, p->core->r, m, d)
224static void _fsi_master_mask_set(struct fsi_master *master,
249 u32 reg, u32 mask, u32 data) 225 u32 reg, u32 mask, u32 data)
250{ 226{
251 unsigned long flags; 227 unsigned long flags;
252 228
253 if ((reg < MREG_START) ||
254 (reg > MREG_END)) {
255 pr_err("fsi: register access err (%s)\n", __func__);
256 return;
257 }
258
259 spin_lock_irqsave(&master->lock, flags); 229 spin_lock_irqsave(&master->lock, flags);
260 __fsi_reg_mask_set((u32)(master->base + reg), mask, data); 230 __fsi_reg_mask_set((u32)(master->base + reg), mask, data);
261 spin_unlock_irqrestore(&master->lock, flags); 231 spin_unlock_irqrestore(&master->lock, flags);
@@ -359,27 +329,41 @@ static void fsi_stream_push(struct fsi_priv *fsi,
359 io->buff_offset = 0; 329 io->buff_offset = 0;
360 io->period_len = period_len; 330 io->period_len = period_len;
361 io->period_num = 0; 331 io->period_num = 0;
332 io->oerr_num = -1; /* ignore 1st err */
333 io->uerr_num = -1; /* ignore 1st err */
362} 334}
363 335
364static void fsi_stream_pop(struct fsi_priv *fsi, int is_play) 336static void fsi_stream_pop(struct fsi_priv *fsi, int is_play)
365{ 337{
366 struct fsi_stream *io = fsi_get_stream(fsi, is_play); 338 struct fsi_stream *io = fsi_get_stream(fsi, is_play);
339 struct snd_soc_dai *dai = fsi_get_dai(io->substream);
340
341
342 if (io->oerr_num > 0)
343 dev_err(dai->dev, "over_run = %d\n", io->oerr_num);
344
345 if (io->uerr_num > 0)
346 dev_err(dai->dev, "under_run = %d\n", io->uerr_num);
367 347
368 io->substream = NULL; 348 io->substream = NULL;
369 io->buff_len = 0; 349 io->buff_len = 0;
370 io->buff_offset = 0; 350 io->buff_offset = 0;
371 io->period_len = 0; 351 io->period_len = 0;
372 io->period_num = 0; 352 io->period_num = 0;
353 io->oerr_num = 0;
354 io->uerr_num = 0;
373} 355}
374 356
375static int fsi_get_fifo_data_num(struct fsi_priv *fsi, int is_play) 357static int fsi_get_fifo_data_num(struct fsi_priv *fsi, int is_play)
376{ 358{
377 u32 status; 359 u32 status;
378 u32 reg = is_play ? DOFF_ST : DIFF_ST;
379 struct fsi_stream *io = fsi_get_stream(fsi, is_play); 360 struct fsi_stream *io = fsi_get_stream(fsi, is_play);
380 int data_num; 361 int data_num;
381 362
382 status = fsi_reg_read(fsi, reg); 363 status = is_play ?
364 fsi_reg_read(fsi, DOFF_ST) :
365 fsi_reg_read(fsi, DIFF_ST);
366
383 data_num = 0x1ff & (status >> 8); 367 data_num = 0x1ff & (status >> 8);
384 data_num *= io->chan_num; 368 data_num *= io->chan_num;
385 369
@@ -406,6 +390,27 @@ static int fsi_get_frame_width(struct fsi_priv *fsi, int is_play)
406 return frames_to_bytes(runtime, 1) / io->chan_num; 390 return frames_to_bytes(runtime, 1) / io->chan_num;
407} 391}
408 392
393static void fsi_count_fifo_err(struct fsi_priv *fsi)
394{
395 u32 ostatus = fsi_reg_read(fsi, DOFF_ST);
396 u32 istatus = fsi_reg_read(fsi, DIFF_ST);
397
398 if (ostatus & ERR_OVER)
399 fsi->playback.oerr_num++;
400
401 if (ostatus & ERR_UNDER)
402 fsi->playback.uerr_num++;
403
404 if (istatus & ERR_OVER)
405 fsi->capture.oerr_num++;
406
407 if (istatus & ERR_UNDER)
408 fsi->capture.uerr_num++;
409
410 fsi_reg_write(fsi, DOFF_ST, 0);
411 fsi_reg_write(fsi, DIFF_ST, 0);
412}
413
409/* 414/*
410 * dma function 415 * dma function
411 */ 416 */
@@ -473,8 +478,8 @@ static void fsi_irq_enable(struct fsi_priv *fsi, int is_play)
473 u32 data = AB_IO(1, fsi_get_port_shift(fsi, is_play)); 478 u32 data = AB_IO(1, fsi_get_port_shift(fsi, is_play));
474 struct fsi_master *master = fsi_get_master(fsi); 479 struct fsi_master *master = fsi_get_master(fsi);
475 480
476 fsi_master_mask_set(master, master->core->imsk, data, data); 481 fsi_core_mask_set(master, imsk, data, data);
477 fsi_master_mask_set(master, master->core->iemsk, data, data); 482 fsi_core_mask_set(master, iemsk, data, data);
478} 483}
479 484
480static void fsi_irq_disable(struct fsi_priv *fsi, int is_play) 485static void fsi_irq_disable(struct fsi_priv *fsi, int is_play)
@@ -482,18 +487,13 @@ static void fsi_irq_disable(struct fsi_priv *fsi, int is_play)
482 u32 data = AB_IO(1, fsi_get_port_shift(fsi, is_play)); 487 u32 data = AB_IO(1, fsi_get_port_shift(fsi, is_play));
483 struct fsi_master *master = fsi_get_master(fsi); 488 struct fsi_master *master = fsi_get_master(fsi);
484 489
485 fsi_master_mask_set(master, master->core->imsk, data, 0); 490 fsi_core_mask_set(master, imsk, data, 0);
486 fsi_master_mask_set(master, master->core->iemsk, data, 0); 491 fsi_core_mask_set(master, iemsk, data, 0);
487} 492}
488 493
489static u32 fsi_irq_get_status(struct fsi_master *master) 494static u32 fsi_irq_get_status(struct fsi_master *master)
490{ 495{
491 return fsi_master_read(master, master->core->int_st); 496 return fsi_core_read(master, int_st);
492}
493
494static void fsi_irq_clear_all_status(struct fsi_master *master)
495{
496 fsi_master_write(master, master->core->int_st, 0);
497} 497}
498 498
499static void fsi_irq_clear_status(struct fsi_priv *fsi) 499static void fsi_irq_clear_status(struct fsi_priv *fsi)
@@ -505,7 +505,7 @@ static void fsi_irq_clear_status(struct fsi_priv *fsi)
505 data |= AB_IO(1, fsi_get_port_shift(fsi, 1)); 505 data |= AB_IO(1, fsi_get_port_shift(fsi, 1));
506 506
507 /* clear interrupt factor */ 507 /* clear interrupt factor */
508 fsi_master_mask_set(master, master->core->int_st, data, 0); 508 fsi_core_mask_set(master, int_st, data, 0);
509} 509}
510 510
511/* 511/*
@@ -516,17 +516,19 @@ static void fsi_irq_clear_status(struct fsi_priv *fsi)
516static void fsi_spdif_clk_ctrl(struct fsi_priv *fsi, int enable) 516static void fsi_spdif_clk_ctrl(struct fsi_priv *fsi, int enable)
517{ 517{
518 struct fsi_master *master = fsi_get_master(fsi); 518 struct fsi_master *master = fsi_get_master(fsi);
519 u32 val = BP | SE; 519 u32 mask, val;
520 520
521 if (master->core->ver < 2) { 521 if (master->core->ver < 2) {
522 pr_err("fsi: register access err (%s)\n", __func__); 522 pr_err("fsi: register access err (%s)\n", __func__);
523 return; 523 return;
524 } 524 }
525 525
526 if (enable) 526 mask = BP | SE;
527 fsi_master_mask_set(master, fsi->mst_ctrl, val, val); 527 val = enable ? mask : 0;
528 else 528
529 fsi_master_mask_set(master, fsi->mst_ctrl, val, 0); 529 fsi_is_port_a(fsi) ?
530 fsi_core_mask_set(master, a_mclk, mask, val) :
531 fsi_core_mask_set(master, b_mclk, mask, val);
530} 532}
531 533
532/* 534/*
@@ -550,7 +552,7 @@ static void fsi_fifo_init(struct fsi_priv *fsi,
550{ 552{
551 struct fsi_master *master = fsi_get_master(fsi); 553 struct fsi_master *master = fsi_get_master(fsi);
552 struct fsi_stream *io = fsi_get_stream(fsi, is_play); 554 struct fsi_stream *io = fsi_get_stream(fsi, is_play);
553 u32 ctrl, shift, i; 555 u32 shift, i;
554 556
555 /* get on-chip RAM capacity */ 557 /* get on-chip RAM capacity */
556 shift = fsi_master_read(master, FIFO_SZ); 558 shift = fsi_master_read(master, FIFO_SZ);
@@ -583,13 +585,17 @@ static void fsi_fifo_init(struct fsi_priv *fsi,
583 dev_dbg(dai->dev, "%d channel %d store\n", 585 dev_dbg(dai->dev, "%d channel %d store\n",
584 io->chan_num, io->fifo_max_num); 586 io->chan_num, io->fifo_max_num);
585 587
586 ctrl = is_play ? DOFF_CTL : DIFF_CTL; 588 /*
587 589 * set interrupt generation factor
588 /* set interrupt generation factor */ 590 * clear FIFO
589 fsi_reg_write(fsi, ctrl, IRQ_HALF); 591 */
590 592 if (is_play) {
591 /* clear FIFO */ 593 fsi_reg_write(fsi, DOFF_CTL, IRQ_HALF);
592 fsi_reg_mask_set(fsi, ctrl, FIFO_CLR, FIFO_CLR); 594 fsi_reg_mask_set(fsi, DOFF_CTL, FIFO_CLR, FIFO_CLR);
595 } else {
596 fsi_reg_write(fsi, DIFF_CTL, IRQ_HALF);
597 fsi_reg_mask_set(fsi, DIFF_CTL, FIFO_CLR, FIFO_CLR);
598 }
593} 599}
594 600
595static void fsi_soft_all_reset(struct fsi_master *master) 601static void fsi_soft_all_reset(struct fsi_master *master)
@@ -604,13 +610,12 @@ static void fsi_soft_all_reset(struct fsi_master *master)
604 mdelay(10); 610 mdelay(10);
605} 611}
606 612
607static int fsi_fifo_data_ctrl(struct fsi_priv *fsi, int startup, int stream) 613static int fsi_fifo_data_ctrl(struct fsi_priv *fsi, int stream)
608{ 614{
609 struct snd_pcm_runtime *runtime; 615 struct snd_pcm_runtime *runtime;
610 struct snd_pcm_substream *substream = NULL; 616 struct snd_pcm_substream *substream = NULL;
611 int is_play = fsi_stream_is_play(stream); 617 int is_play = fsi_stream_is_play(stream);
612 struct fsi_stream *io = fsi_get_stream(fsi, is_play); 618 struct fsi_stream *io = fsi_get_stream(fsi, is_play);
613 u32 status_reg = is_play ? DOFF_ST : DIFF_ST;
614 int data_residue_num; 619 int data_residue_num;
615 int data_num; 620 int data_num;
616 int data_num_max; 621 int data_num_max;
@@ -698,35 +703,20 @@ static int fsi_fifo_data_ctrl(struct fsi_priv *fsi, int startup, int stream)
698 /* update buff_offset */ 703 /* update buff_offset */
699 io->buff_offset += fsi_num2offset(data_num, ch_width); 704 io->buff_offset += fsi_num2offset(data_num, ch_width);
700 705
701 /* check fifo status */
702 if (!startup) {
703 struct snd_soc_dai *dai = fsi_get_dai(substream);
704 u32 status = fsi_reg_read(fsi, status_reg);
705
706 if (status & ERR_OVER)
707 dev_err(dai->dev, "over run\n");
708 if (status & ERR_UNDER)
709 dev_err(dai->dev, "under run\n");
710 }
711 fsi_reg_write(fsi, status_reg, 0);
712
713 /* re-enable irq */
714 fsi_irq_enable(fsi, is_play);
715
716 if (over_period) 706 if (over_period)
717 snd_pcm_period_elapsed(substream); 707 snd_pcm_period_elapsed(substream);
718 708
719 return 0; 709 return 0;
720} 710}
721 711
722static int fsi_data_pop(struct fsi_priv *fsi, int startup) 712static int fsi_data_pop(struct fsi_priv *fsi)
723{ 713{
724 return fsi_fifo_data_ctrl(fsi, startup, SNDRV_PCM_STREAM_CAPTURE); 714 return fsi_fifo_data_ctrl(fsi, SNDRV_PCM_STREAM_CAPTURE);
725} 715}
726 716
727static int fsi_data_push(struct fsi_priv *fsi, int startup) 717static int fsi_data_push(struct fsi_priv *fsi)
728{ 718{
729 return fsi_fifo_data_ctrl(fsi, startup, SNDRV_PCM_STREAM_PLAYBACK); 719 return fsi_fifo_data_ctrl(fsi, SNDRV_PCM_STREAM_PLAYBACK);
730} 720}
731 721
732static irqreturn_t fsi_interrupt(int irq, void *data) 722static irqreturn_t fsi_interrupt(int irq, void *data)
@@ -739,15 +729,19 @@ static irqreturn_t fsi_interrupt(int irq, void *data)
739 fsi_master_mask_set(master, SOFT_RST, IR, IR); 729 fsi_master_mask_set(master, SOFT_RST, IR, IR);
740 730
741 if (int_st & AB_IO(1, AO_SHIFT)) 731 if (int_st & AB_IO(1, AO_SHIFT))
742 fsi_data_push(&master->fsia, 0); 732 fsi_data_push(&master->fsia);
743 if (int_st & AB_IO(1, BO_SHIFT)) 733 if (int_st & AB_IO(1, BO_SHIFT))
744 fsi_data_push(&master->fsib, 0); 734 fsi_data_push(&master->fsib);
745 if (int_st & AB_IO(1, AI_SHIFT)) 735 if (int_st & AB_IO(1, AI_SHIFT))
746 fsi_data_pop(&master->fsia, 0); 736 fsi_data_pop(&master->fsia);
747 if (int_st & AB_IO(1, BI_SHIFT)) 737 if (int_st & AB_IO(1, BI_SHIFT))
748 fsi_data_pop(&master->fsib, 0); 738 fsi_data_pop(&master->fsib);
739
740 fsi_count_fifo_err(&master->fsia);
741 fsi_count_fifo_err(&master->fsib);
749 742
750 fsi_irq_clear_all_status(master); 743 fsi_irq_clear_status(&master->fsia);
744 fsi_irq_clear_status(&master->fsib);
751 745
752 return IRQ_HANDLED; 746 return IRQ_HANDLED;
753} 747}
@@ -764,7 +758,6 @@ static int fsi_dai_startup(struct snd_pcm_substream *substream,
764 struct fsi_stream *io; 758 struct fsi_stream *io;
765 u32 flags = fsi_get_info_flags(fsi); 759 u32 flags = fsi_get_info_flags(fsi);
766 u32 fmt; 760 u32 fmt;
767 u32 reg;
768 u32 data; 761 u32 data;
769 int is_play = fsi_is_play(substream); 762 int is_play = fsi_is_play(substream);
770 int is_master; 763 int is_master;
@@ -796,7 +789,6 @@ static int fsi_dai_startup(struct snd_pcm_substream *substream,
796 789
797 /* do fmt, di fmt */ 790 /* do fmt, di fmt */
798 data = 0; 791 data = 0;
799 reg = is_play ? DO_FMT : DI_FMT;
800 fmt = is_play ? SH_FSI_GET_OFMT(flags) : SH_FSI_GET_IFMT(flags); 792 fmt = is_play ? SH_FSI_GET_OFMT(flags) : SH_FSI_GET_IFMT(flags);
801 switch (fmt) { 793 switch (fmt) {
802 case SH_FSI_FMT_MONO: 794 case SH_FSI_FMT_MONO:
@@ -830,16 +822,18 @@ static int fsi_dai_startup(struct snd_pcm_substream *substream,
830 dev_err(dai->dev, "This FSI can not use SPDIF\n"); 822 dev_err(dai->dev, "This FSI can not use SPDIF\n");
831 return -EINVAL; 823 return -EINVAL;
832 } 824 }
833 data = CR_SPDIF; 825 data = CR_BWS_16 | CR_DTMD_SPDIF_PCM | CR_PCM;
834 io->chan_num = 2; 826 io->chan_num = 2;
835 fsi_spdif_clk_ctrl(fsi, 1); 827 fsi_spdif_clk_ctrl(fsi, 1);
836 fsi_reg_mask_set(fsi, OUT_SEL, 0x0010, 0x0010); 828 fsi_reg_mask_set(fsi, OUT_SEL, DMMD, DMMD);
837 break; 829 break;
838 default: 830 default:
839 dev_err(dai->dev, "unknown format.\n"); 831 dev_err(dai->dev, "unknown format.\n");
840 return -EINVAL; 832 return -EINVAL;
841 } 833 }
842 fsi_reg_write(fsi, reg, data); 834 is_play ?
835 fsi_reg_write(fsi, DO_FMT, data) :
836 fsi_reg_write(fsi, DI_FMT, data);
843 837
844 /* irq clear */ 838 /* irq clear */
845 fsi_irq_disable(fsi, is_play); 839 fsi_irq_disable(fsi, is_play);
@@ -883,7 +877,8 @@ static int fsi_dai_trigger(struct snd_pcm_substream *substream, int cmd,
883 fsi_stream_push(fsi, is_play, substream, 877 fsi_stream_push(fsi, is_play, substream,
884 frames_to_bytes(runtime, runtime->buffer_size), 878 frames_to_bytes(runtime, runtime->buffer_size),
885 frames_to_bytes(runtime, runtime->period_size)); 879 frames_to_bytes(runtime, runtime->period_size));
886 ret = is_play ? fsi_data_push(fsi, 1) : fsi_data_pop(fsi, 1); 880 ret = is_play ? fsi_data_push(fsi) : fsi_data_pop(fsi);
881 fsi_irq_enable(fsi, is_play);
887 break; 882 break;
888 case SNDRV_PCM_TRIGGER_STOP: 883 case SNDRV_PCM_TRIGGER_STOP:
889 fsi_irq_disable(fsi, is_play); 884 fsi_irq_disable(fsi, is_play);
@@ -1174,12 +1169,10 @@ static int fsi_probe(struct platform_device *pdev)
1174 /* FSI A setting */ 1169 /* FSI A setting */
1175 master->fsia.base = master->base; 1170 master->fsia.base = master->base;
1176 master->fsia.master = master; 1171 master->fsia.master = master;
1177 master->fsia.mst_ctrl = A_MST_CTLR;
1178 1172
1179 /* FSI B setting */ 1173 /* FSI B setting */
1180 master->fsib.base = master->base + 0x40; 1174 master->fsib.base = master->base + 0x40;
1181 master->fsib.master = master; 1175 master->fsib.master = master;
1182 master->fsib.mst_ctrl = B_MST_CTLR;
1183 1176
1184 pm_runtime_enable(&pdev->dev); 1177 pm_runtime_enable(&pdev->dev);
1185 pm_runtime_resume(&pdev->dev); 1178 pm_runtime_resume(&pdev->dev);
@@ -1266,6 +1259,8 @@ static struct fsi_core fsi2_core = {
1266 .int_st = CPU_INT_ST, 1259 .int_st = CPU_INT_ST,
1267 .iemsk = CPU_IEMSK, 1260 .iemsk = CPU_IEMSK,
1268 .imsk = CPU_IMSK, 1261 .imsk = CPU_IMSK,
1262 .a_mclk = A_MST_CTLR,
1263 .b_mclk = B_MST_CTLR,
1269}; 1264};
1270 1265
1271static struct platform_device_id fsi_id_table[] = { 1266static struct platform_device_id fsi_id_table[] = {
diff --git a/sound/soc/sh/migor.c b/sound/soc/sh/migor.c
index ac6c49ce6fdf..6088a6a3238a 100644
--- a/sound/soc/sh/migor.c
+++ b/sound/soc/sh/migor.c
@@ -8,11 +8,11 @@
8 * published by the Free Software Foundation. 8 * published by the Free Software Foundation.
9 */ 9 */
10 10
11#include <linux/clkdev.h>
11#include <linux/device.h> 12#include <linux/device.h>
12#include <linux/firmware.h> 13#include <linux/firmware.h>
13#include <linux/module.h> 14#include <linux/module.h>
14 15
15#include <asm/clkdev.h>
16#include <asm/clock.h> 16#include <asm/clock.h>
17 17
18#include <cpu/sh7722.h> 18#include <cpu/sh7722.h>
@@ -20,7 +20,6 @@
20#include <sound/core.h> 20#include <sound/core.h>
21#include <sound/pcm.h> 21#include <sound/pcm.h>
22#include <sound/soc.h> 22#include <sound/soc.h>
23#include <sound/soc-dapm.h>
24 23
25#include "../codecs/wm8978.h" 24#include "../codecs/wm8978.h"
26#include "siu.h" 25#include "siu.h"
@@ -140,11 +139,12 @@ static const struct snd_soc_dapm_route audio_map[] = {
140static int migor_dai_init(struct snd_soc_pcm_runtime *rtd) 139static int migor_dai_init(struct snd_soc_pcm_runtime *rtd)
141{ 140{
142 struct snd_soc_codec *codec = rtd->codec; 141 struct snd_soc_codec *codec = rtd->codec;
142 struct snd_soc_dapm_context *dapm = &codec->dapm;
143 143
144 snd_soc_dapm_new_controls(codec, migor_dapm_widgets, 144 snd_soc_dapm_new_controls(dapm, migor_dapm_widgets,
145 ARRAY_SIZE(migor_dapm_widgets)); 145 ARRAY_SIZE(migor_dapm_widgets));
146 146
147 snd_soc_dapm_add_routes(codec, audio_map, ARRAY_SIZE(audio_map)); 147 snd_soc_dapm_add_routes(dapm, audio_map, ARRAY_SIZE(audio_map));
148 148
149 return 0; 149 return 0;
150} 150}
diff --git a/sound/soc/sh/sh7760-ac97.c b/sound/soc/sh/sh7760-ac97.c
index f8e0ab82ef59..917d3ceadc9d 100644
--- a/sound/soc/sh/sh7760-ac97.c
+++ b/sound/soc/sh/sh7760-ac97.c
@@ -12,7 +12,6 @@
12#include <sound/core.h> 12#include <sound/core.h>
13#include <sound/pcm.h> 13#include <sound/pcm.h>
14#include <sound/soc.h> 14#include <sound/soc.h>
15#include <sound/soc-dapm.h>
16#include <asm/io.h> 15#include <asm/io.h>
17 16
18#define IPSEL 0xFE400034 17#define IPSEL 0xFE400034
@@ -23,7 +22,7 @@ extern struct snd_soc_platform_driver sh7760_soc_platform;
23 22
24static int machine_init(struct snd_soc_pcm_runtime *rtd) 23static int machine_init(struct snd_soc_pcm_runtime *rtd)
25{ 24{
26 snd_soc_dapm_sync(rtd->codec); 25 snd_soc_dapm_sync(&rtd->codec->dapm);
27 return 0; 26 return 0;
28} 27}
29 28
diff --git a/sound/soc/sh/siu.h b/sound/soc/sh/siu.h
index 9f4dcb921ff0..83c3430ad797 100644
--- a/sound/soc/sh/siu.h
+++ b/sound/soc/sh/siu.h
@@ -75,7 +75,7 @@ struct siu_firmware {
75 75
76#include <sound/core.h> 76#include <sound/core.h>
77#include <sound/pcm.h> 77#include <sound/pcm.h>
78#include <sound/soc-dai.h> 78#include <sound/soc.h>
79 79
80#define SIU_PERIOD_BYTES_MAX 8192 /* DMA transfer/period size */ 80#define SIU_PERIOD_BYTES_MAX 8192 /* DMA transfer/period size */
81#define SIU_PERIOD_BYTES_MIN 256 /* DMA transfer/period size */ 81#define SIU_PERIOD_BYTES_MIN 256 /* DMA transfer/period size */
diff --git a/sound/soc/sh/siu_dai.c b/sound/soc/sh/siu_dai.c
index af53b64d8af2..4973c2939d79 100644
--- a/sound/soc/sh/siu_dai.c
+++ b/sound/soc/sh/siu_dai.c
@@ -28,7 +28,7 @@
28#include <asm/siu.h> 28#include <asm/siu.h>
29 29
30#include <sound/control.h> 30#include <sound/control.h>
31#include <sound/soc-dai.h> 31#include <sound/soc.h>
32 32
33#include "siu.h" 33#include "siu.h"
34 34
diff --git a/sound/soc/sh/siu_pcm.c b/sound/soc/sh/siu_pcm.c
index ed29c9e1ed4e..a423babcf145 100644
--- a/sound/soc/sh/siu_pcm.c
+++ b/sound/soc/sh/siu_pcm.c
@@ -29,7 +29,7 @@
29#include <sound/core.h> 29#include <sound/core.h>
30#include <sound/pcm.h> 30#include <sound/pcm.h>
31#include <sound/pcm_params.h> 31#include <sound/pcm_params.h>
32#include <sound/soc-dai.h> 32#include <sound/soc.h>
33 33
34#include <asm/siu.h> 34#include <asm/siu.h>
35 35
diff --git a/sound/soc/soc-cache.c b/sound/soc/soc-cache.c
index d214f02cbb65..8c2a21a978ac 100644
--- a/sound/soc/soc-cache.c
+++ b/sound/soc/soc-cache.c
@@ -14,27 +14,34 @@
14#include <linux/i2c.h> 14#include <linux/i2c.h>
15#include <linux/spi/spi.h> 15#include <linux/spi/spi.h>
16#include <sound/soc.h> 16#include <sound/soc.h>
17#include <linux/lzo.h>
18#include <linux/bitmap.h>
19#include <linux/rbtree.h>
17 20
18static unsigned int snd_soc_4_12_read(struct snd_soc_codec *codec, 21static unsigned int snd_soc_4_12_read(struct snd_soc_codec *codec,
19 unsigned int reg) 22 unsigned int reg)
20{ 23{
21 u16 *cache = codec->reg_cache; 24 int ret;
25 unsigned int val;
22 26
23 if (reg >= codec->driver->reg_cache_size || 27 if (reg >= codec->driver->reg_cache_size ||
24 snd_soc_codec_volatile_register(codec, reg)) { 28 snd_soc_codec_volatile_register(codec, reg)) {
25 if (codec->cache_only) 29 if (codec->cache_only)
26 return -1; 30 return -1;
27 31
32 BUG_ON(!codec->hw_read);
28 return codec->hw_read(codec, reg); 33 return codec->hw_read(codec, reg);
29 } 34 }
30 35
31 return cache[reg]; 36 ret = snd_soc_cache_read(codec, reg, &val);
37 if (ret < 0)
38 return -1;
39 return val;
32} 40}
33 41
34static int snd_soc_4_12_write(struct snd_soc_codec *codec, unsigned int reg, 42static int snd_soc_4_12_write(struct snd_soc_codec *codec, unsigned int reg,
35 unsigned int value) 43 unsigned int value)
36{ 44{
37 u16 *cache = codec->reg_cache;
38 u8 data[2]; 45 u8 data[2];
39 int ret; 46 int ret;
40 47
@@ -42,16 +49,17 @@ static int snd_soc_4_12_write(struct snd_soc_codec *codec, unsigned int reg,
42 data[1] = value & 0x00ff; 49 data[1] = value & 0x00ff;
43 50
44 if (!snd_soc_codec_volatile_register(codec, reg) && 51 if (!snd_soc_codec_volatile_register(codec, reg) &&
45 reg < codec->driver->reg_cache_size) 52 reg < codec->driver->reg_cache_size) {
46 cache[reg] = value; 53 ret = snd_soc_cache_write(codec, reg, value);
54 if (ret < 0)
55 return -1;
56 }
47 57
48 if (codec->cache_only) { 58 if (codec->cache_only) {
49 codec->cache_sync = 1; 59 codec->cache_sync = 1;
50 return 0; 60 return 0;
51 } 61 }
52 62
53 dev_dbg(codec->dev, "0x%x = 0x%x\n", reg, value);
54
55 ret = codec->hw_write(codec->control_data, data, 2); 63 ret = codec->hw_write(codec->control_data, data, 2);
56 if (ret == 2) 64 if (ret == 2)
57 return 0; 65 return 0;
@@ -77,7 +85,7 @@ static int snd_soc_4_12_spi_write(void *control_data, const char *data,
77 msg[1] = data[0]; 85 msg[1] = data[0];
78 86
79 spi_message_init(&m); 87 spi_message_init(&m);
80 memset(&t, 0, (sizeof t)); 88 memset(&t, 0, sizeof t);
81 89
82 t.tx_buf = &msg[0]; 90 t.tx_buf = &msg[0];
83 t.len = len; 91 t.len = len;
@@ -94,23 +102,27 @@ static int snd_soc_4_12_spi_write(void *control_data, const char *data,
94static unsigned int snd_soc_7_9_read(struct snd_soc_codec *codec, 102static unsigned int snd_soc_7_9_read(struct snd_soc_codec *codec,
95 unsigned int reg) 103 unsigned int reg)
96{ 104{
97 u16 *cache = codec->reg_cache; 105 int ret;
106 unsigned int val;
98 107
99 if (reg >= codec->driver->reg_cache_size || 108 if (reg >= codec->driver->reg_cache_size ||
100 snd_soc_codec_volatile_register(codec, reg)) { 109 snd_soc_codec_volatile_register(codec, reg)) {
101 if (codec->cache_only) 110 if (codec->cache_only)
102 return -1; 111 return -1;
103 112
113 BUG_ON(!codec->hw_read);
104 return codec->hw_read(codec, reg); 114 return codec->hw_read(codec, reg);
105 } 115 }
106 116
107 return cache[reg]; 117 ret = snd_soc_cache_read(codec, reg, &val);
118 if (ret < 0)
119 return -1;
120 return val;
108} 121}
109 122
110static int snd_soc_7_9_write(struct snd_soc_codec *codec, unsigned int reg, 123static int snd_soc_7_9_write(struct snd_soc_codec *codec, unsigned int reg,
111 unsigned int value) 124 unsigned int value)
112{ 125{
113 u16 *cache = codec->reg_cache;
114 u8 data[2]; 126 u8 data[2];
115 int ret; 127 int ret;
116 128
@@ -118,16 +130,17 @@ static int snd_soc_7_9_write(struct snd_soc_codec *codec, unsigned int reg,
118 data[1] = value & 0x00ff; 130 data[1] = value & 0x00ff;
119 131
120 if (!snd_soc_codec_volatile_register(codec, reg) && 132 if (!snd_soc_codec_volatile_register(codec, reg) &&
121 reg < codec->driver->reg_cache_size) 133 reg < codec->driver->reg_cache_size) {
122 cache[reg] = value; 134 ret = snd_soc_cache_write(codec, reg, value);
135 if (ret < 0)
136 return -1;
137 }
123 138
124 if (codec->cache_only) { 139 if (codec->cache_only) {
125 codec->cache_sync = 1; 140 codec->cache_sync = 1;
126 return 0; 141 return 0;
127 } 142 }
128 143
129 dev_dbg(codec->dev, "0x%x = 0x%x\n", reg, value);
130
131 ret = codec->hw_write(codec->control_data, data, 2); 144 ret = codec->hw_write(codec->control_data, data, 2);
132 if (ret == 2) 145 if (ret == 2)
133 return 0; 146 return 0;
@@ -153,7 +166,7 @@ static int snd_soc_7_9_spi_write(void *control_data, const char *data,
153 msg[1] = data[1]; 166 msg[1] = data[1];
154 167
155 spi_message_init(&m); 168 spi_message_init(&m);
156 memset(&t, 0, (sizeof t)); 169 memset(&t, 0, sizeof t);
157 170
158 t.tx_buf = &msg[0]; 171 t.tx_buf = &msg[0];
159 t.len = len; 172 t.len = len;
@@ -170,24 +183,25 @@ static int snd_soc_7_9_spi_write(void *control_data, const char *data,
170static int snd_soc_8_8_write(struct snd_soc_codec *codec, unsigned int reg, 183static int snd_soc_8_8_write(struct snd_soc_codec *codec, unsigned int reg,
171 unsigned int value) 184 unsigned int value)
172{ 185{
173 u8 *cache = codec->reg_cache;
174 u8 data[2]; 186 u8 data[2];
187 int ret;
175 188
176 reg &= 0xff; 189 reg &= 0xff;
177 data[0] = reg; 190 data[0] = reg;
178 data[1] = value & 0xff; 191 data[1] = value & 0xff;
179 192
180 if (!snd_soc_codec_volatile_register(codec, reg) && 193 if (!snd_soc_codec_volatile_register(codec, reg) &&
181 reg < codec->driver->reg_cache_size) 194 reg < codec->driver->reg_cache_size) {
182 cache[reg] = value; 195 ret = snd_soc_cache_write(codec, reg, value);
196 if (ret < 0)
197 return -1;
198 }
183 199
184 if (codec->cache_only) { 200 if (codec->cache_only) {
185 codec->cache_sync = 1; 201 codec->cache_sync = 1;
186 return 0; 202 return 0;
187 } 203 }
188 204
189 dev_dbg(codec->dev, "0x%x = 0x%x\n", reg, value);
190
191 if (codec->hw_write(codec->control_data, data, 2) == 2) 205 if (codec->hw_write(codec->control_data, data, 2) == 2)
192 return 0; 206 return 0;
193 else 207 else
@@ -197,7 +211,8 @@ static int snd_soc_8_8_write(struct snd_soc_codec *codec, unsigned int reg,
197static unsigned int snd_soc_8_8_read(struct snd_soc_codec *codec, 211static unsigned int snd_soc_8_8_read(struct snd_soc_codec *codec,
198 unsigned int reg) 212 unsigned int reg)
199{ 213{
200 u8 *cache = codec->reg_cache; 214 int ret;
215 unsigned int val;
201 216
202 reg &= 0xff; 217 reg &= 0xff;
203 if (reg >= codec->driver->reg_cache_size || 218 if (reg >= codec->driver->reg_cache_size ||
@@ -205,10 +220,14 @@ static unsigned int snd_soc_8_8_read(struct snd_soc_codec *codec,
205 if (codec->cache_only) 220 if (codec->cache_only)
206 return -1; 221 return -1;
207 222
223 BUG_ON(!codec->hw_read);
208 return codec->hw_read(codec, reg); 224 return codec->hw_read(codec, reg);
209 } 225 }
210 226
211 return cache[reg]; 227 ret = snd_soc_cache_read(codec, reg, &val);
228 if (ret < 0)
229 return -1;
230 return val;
212} 231}
213 232
214#if defined(CONFIG_SPI_MASTER) 233#if defined(CONFIG_SPI_MASTER)
@@ -227,7 +246,7 @@ static int snd_soc_8_8_spi_write(void *control_data, const char *data,
227 msg[1] = data[1]; 246 msg[1] = data[1];
228 247
229 spi_message_init(&m); 248 spi_message_init(&m);
230 memset(&t, 0, (sizeof t)); 249 memset(&t, 0, sizeof t);
231 250
232 t.tx_buf = &msg[0]; 251 t.tx_buf = &msg[0];
233 t.len = len; 252 t.len = len;
@@ -244,24 +263,25 @@ static int snd_soc_8_8_spi_write(void *control_data, const char *data,
244static int snd_soc_8_16_write(struct snd_soc_codec *codec, unsigned int reg, 263static int snd_soc_8_16_write(struct snd_soc_codec *codec, unsigned int reg,
245 unsigned int value) 264 unsigned int value)
246{ 265{
247 u16 *reg_cache = codec->reg_cache;
248 u8 data[3]; 266 u8 data[3];
267 int ret;
249 268
250 data[0] = reg; 269 data[0] = reg;
251 data[1] = (value >> 8) & 0xff; 270 data[1] = (value >> 8) & 0xff;
252 data[2] = value & 0xff; 271 data[2] = value & 0xff;
253 272
254 if (!snd_soc_codec_volatile_register(codec, reg) && 273 if (!snd_soc_codec_volatile_register(codec, reg) &&
255 reg < codec->driver->reg_cache_size) 274 reg < codec->driver->reg_cache_size) {
256 reg_cache[reg] = value; 275 ret = snd_soc_cache_write(codec, reg, value);
276 if (ret < 0)
277 return -1;
278 }
257 279
258 if (codec->cache_only) { 280 if (codec->cache_only) {
259 codec->cache_sync = 1; 281 codec->cache_sync = 1;
260 return 0; 282 return 0;
261 } 283 }
262 284
263 dev_dbg(codec->dev, "0x%x = 0x%x\n", reg, value);
264
265 if (codec->hw_write(codec->control_data, data, 3) == 3) 285 if (codec->hw_write(codec->control_data, data, 3) == 3)
266 return 0; 286 return 0;
267 else 287 else
@@ -271,17 +291,22 @@ static int snd_soc_8_16_write(struct snd_soc_codec *codec, unsigned int reg,
271static unsigned int snd_soc_8_16_read(struct snd_soc_codec *codec, 291static unsigned int snd_soc_8_16_read(struct snd_soc_codec *codec,
272 unsigned int reg) 292 unsigned int reg)
273{ 293{
274 u16 *cache = codec->reg_cache; 294 int ret;
295 unsigned int val;
275 296
276 if (reg >= codec->driver->reg_cache_size || 297 if (reg >= codec->driver->reg_cache_size ||
277 snd_soc_codec_volatile_register(codec, reg)) { 298 snd_soc_codec_volatile_register(codec, reg)) {
278 if (codec->cache_only) 299 if (codec->cache_only)
279 return -1; 300 return -1;
280 301
302 BUG_ON(!codec->hw_read);
281 return codec->hw_read(codec, reg); 303 return codec->hw_read(codec, reg);
282 } else {
283 return cache[reg];
284 } 304 }
305
306 ret = snd_soc_cache_read(codec, reg, &val);
307 if (ret < 0)
308 return -1;
309 return val;
285} 310}
286 311
287#if defined(CONFIG_SPI_MASTER) 312#if defined(CONFIG_SPI_MASTER)
@@ -301,7 +326,7 @@ static int snd_soc_8_16_spi_write(void *control_data, const char *data,
301 msg[2] = data[2]; 326 msg[2] = data[2];
302 327
303 spi_message_init(&m); 328 spi_message_init(&m);
304 memset(&t, 0, (sizeof t)); 329 memset(&t, 0, sizeof t);
305 330
306 t.tx_buf = &msg[0]; 331 t.tx_buf = &msg[0];
307 t.len = len; 332 t.len = len;
@@ -420,7 +445,8 @@ static unsigned int snd_soc_16_8_read_i2c(struct snd_soc_codec *codec,
420static unsigned int snd_soc_16_8_read(struct snd_soc_codec *codec, 445static unsigned int snd_soc_16_8_read(struct snd_soc_codec *codec,
421 unsigned int reg) 446 unsigned int reg)
422{ 447{
423 u8 *cache = codec->reg_cache; 448 int ret;
449 unsigned int val;
424 450
425 reg &= 0xff; 451 reg &= 0xff;
426 if (reg >= codec->driver->reg_cache_size || 452 if (reg >= codec->driver->reg_cache_size ||
@@ -428,16 +454,19 @@ static unsigned int snd_soc_16_8_read(struct snd_soc_codec *codec,
428 if (codec->cache_only) 454 if (codec->cache_only)
429 return -1; 455 return -1;
430 456
457 BUG_ON(!codec->hw_read);
431 return codec->hw_read(codec, reg); 458 return codec->hw_read(codec, reg);
432 } 459 }
433 460
434 return cache[reg]; 461 ret = snd_soc_cache_read(codec, reg, &val);
462 if (ret < 0)
463 return -1;
464 return val;
435} 465}
436 466
437static int snd_soc_16_8_write(struct snd_soc_codec *codec, unsigned int reg, 467static int snd_soc_16_8_write(struct snd_soc_codec *codec, unsigned int reg,
438 unsigned int value) 468 unsigned int value)
439{ 469{
440 u8 *cache = codec->reg_cache;
441 u8 data[3]; 470 u8 data[3];
442 int ret; 471 int ret;
443 472
@@ -447,16 +476,17 @@ static int snd_soc_16_8_write(struct snd_soc_codec *codec, unsigned int reg,
447 476
448 reg &= 0xff; 477 reg &= 0xff;
449 if (!snd_soc_codec_volatile_register(codec, reg) && 478 if (!snd_soc_codec_volatile_register(codec, reg) &&
450 reg < codec->driver->reg_cache_size) 479 reg < codec->driver->reg_cache_size) {
451 cache[reg] = value; 480 ret = snd_soc_cache_write(codec, reg, value);
481 if (ret < 0)
482 return -1;
483 }
452 484
453 if (codec->cache_only) { 485 if (codec->cache_only) {
454 codec->cache_sync = 1; 486 codec->cache_sync = 1;
455 return 0; 487 return 0;
456 } 488 }
457 489
458 dev_dbg(codec->dev, "0x%x = 0x%x\n", reg, value);
459
460 ret = codec->hw_write(codec->control_data, data, 3); 490 ret = codec->hw_write(codec->control_data, data, 3);
461 if (ret == 3) 491 if (ret == 3)
462 return 0; 492 return 0;
@@ -483,7 +513,7 @@ static int snd_soc_16_8_spi_write(void *control_data, const char *data,
483 msg[2] = data[2]; 513 msg[2] = data[2];
484 514
485 spi_message_init(&m); 515 spi_message_init(&m);
486 memset(&t, 0, (sizeof t)); 516 memset(&t, 0, sizeof t);
487 517
488 t.tx_buf = &msg[0]; 518 t.tx_buf = &msg[0];
489 t.len = len; 519 t.len = len;
@@ -534,23 +564,28 @@ static unsigned int snd_soc_16_16_read_i2c(struct snd_soc_codec *codec,
534static unsigned int snd_soc_16_16_read(struct snd_soc_codec *codec, 564static unsigned int snd_soc_16_16_read(struct snd_soc_codec *codec,
535 unsigned int reg) 565 unsigned int reg)
536{ 566{
537 u16 *cache = codec->reg_cache; 567 int ret;
568 unsigned int val;
538 569
539 if (reg >= codec->driver->reg_cache_size || 570 if (reg >= codec->driver->reg_cache_size ||
540 snd_soc_codec_volatile_register(codec, reg)) { 571 snd_soc_codec_volatile_register(codec, reg)) {
541 if (codec->cache_only) 572 if (codec->cache_only)
542 return -1; 573 return -1;
543 574
575 BUG_ON(!codec->hw_read);
544 return codec->hw_read(codec, reg); 576 return codec->hw_read(codec, reg);
545 } 577 }
546 578
547 return cache[reg]; 579 ret = snd_soc_cache_read(codec, reg, &val);
580 if (ret < 0)
581 return -1;
582
583 return val;
548} 584}
549 585
550static int snd_soc_16_16_write(struct snd_soc_codec *codec, unsigned int reg, 586static int snd_soc_16_16_write(struct snd_soc_codec *codec, unsigned int reg,
551 unsigned int value) 587 unsigned int value)
552{ 588{
553 u16 *cache = codec->reg_cache;
554 u8 data[4]; 589 u8 data[4];
555 int ret; 590 int ret;
556 591
@@ -560,16 +595,17 @@ static int snd_soc_16_16_write(struct snd_soc_codec *codec, unsigned int reg,
560 data[3] = value & 0xff; 595 data[3] = value & 0xff;
561 596
562 if (!snd_soc_codec_volatile_register(codec, reg) && 597 if (!snd_soc_codec_volatile_register(codec, reg) &&
563 reg < codec->driver->reg_cache_size) 598 reg < codec->driver->reg_cache_size) {
564 cache[reg] = value; 599 ret = snd_soc_cache_write(codec, reg, value);
600 if (ret < 0)
601 return -1;
602 }
565 603
566 if (codec->cache_only) { 604 if (codec->cache_only) {
567 codec->cache_sync = 1; 605 codec->cache_sync = 1;
568 return 0; 606 return 0;
569 } 607 }
570 608
571 dev_dbg(codec->dev, "0x%x = 0x%x\n", reg, value);
572
573 ret = codec->hw_write(codec->control_data, data, 4); 609 ret = codec->hw_write(codec->control_data, data, 4);
574 if (ret == 4) 610 if (ret == 4)
575 return 0; 611 return 0;
@@ -597,7 +633,7 @@ static int snd_soc_16_16_spi_write(void *control_data, const char *data,
597 msg[3] = data[3]; 633 msg[3] = data[3];
598 634
599 spi_message_init(&m); 635 spi_message_init(&m);
600 memset(&t, 0, (sizeof t)); 636 memset(&t, 0, sizeof t);
601 637
602 t.tx_buf = &msg[0]; 638 t.tx_buf = &msg[0];
603 t.len = len; 639 t.len = len;
@@ -692,8 +728,8 @@ int snd_soc_codec_set_cache_io(struct snd_soc_codec *codec,
692 return -EINVAL; 728 return -EINVAL;
693 } 729 }
694 730
695 codec->driver->write = io_types[i].write; 731 codec->write = io_types[i].write;
696 codec->driver->read = io_types[i].read; 732 codec->read = io_types[i].read;
697 733
698 switch (control) { 734 switch (control) {
699 case SND_SOC_CUSTOM: 735 case SND_SOC_CUSTOM:
@@ -724,3 +760,930 @@ int snd_soc_codec_set_cache_io(struct snd_soc_codec *codec,
724 return 0; 760 return 0;
725} 761}
726EXPORT_SYMBOL_GPL(snd_soc_codec_set_cache_io); 762EXPORT_SYMBOL_GPL(snd_soc_codec_set_cache_io);
763
764struct snd_soc_rbtree_node {
765 struct rb_node node;
766 unsigned int reg;
767 unsigned int value;
768 unsigned int defval;
769} __attribute__ ((packed));
770
771struct snd_soc_rbtree_ctx {
772 struct rb_root root;
773};
774
775static struct snd_soc_rbtree_node *snd_soc_rbtree_lookup(
776 struct rb_root *root, unsigned int reg)
777{
778 struct rb_node *node;
779 struct snd_soc_rbtree_node *rbnode;
780
781 node = root->rb_node;
782 while (node) {
783 rbnode = container_of(node, struct snd_soc_rbtree_node, node);
784 if (rbnode->reg < reg)
785 node = node->rb_left;
786 else if (rbnode->reg > reg)
787 node = node->rb_right;
788 else
789 return rbnode;
790 }
791
792 return NULL;
793}
794
795static int snd_soc_rbtree_insert(struct rb_root *root,
796 struct snd_soc_rbtree_node *rbnode)
797{
798 struct rb_node **new, *parent;
799 struct snd_soc_rbtree_node *rbnode_tmp;
800
801 parent = NULL;
802 new = &root->rb_node;
803 while (*new) {
804 rbnode_tmp = container_of(*new, struct snd_soc_rbtree_node,
805 node);
806 parent = *new;
807 if (rbnode_tmp->reg < rbnode->reg)
808 new = &((*new)->rb_left);
809 else if (rbnode_tmp->reg > rbnode->reg)
810 new = &((*new)->rb_right);
811 else
812 return 0;
813 }
814
815 /* insert the node into the rbtree */
816 rb_link_node(&rbnode->node, parent, new);
817 rb_insert_color(&rbnode->node, root);
818
819 return 1;
820}
821
822static int snd_soc_rbtree_cache_sync(struct snd_soc_codec *codec)
823{
824 struct snd_soc_rbtree_ctx *rbtree_ctx;
825 struct rb_node *node;
826 struct snd_soc_rbtree_node *rbnode;
827 unsigned int val;
828 int ret;
829
830 rbtree_ctx = codec->reg_cache;
831 for (node = rb_first(&rbtree_ctx->root); node; node = rb_next(node)) {
832 rbnode = rb_entry(node, struct snd_soc_rbtree_node, node);
833 if (rbnode->value == rbnode->defval)
834 continue;
835 ret = snd_soc_cache_read(codec, rbnode->reg, &val);
836 if (ret)
837 return ret;
838 ret = snd_soc_write(codec, rbnode->reg, val);
839 if (ret)
840 return ret;
841 dev_dbg(codec->dev, "Synced register %#x, value = %#x\n",
842 rbnode->reg, val);
843 }
844
845 return 0;
846}
847
848static int snd_soc_rbtree_cache_write(struct snd_soc_codec *codec,
849 unsigned int reg, unsigned int value)
850{
851 struct snd_soc_rbtree_ctx *rbtree_ctx;
852 struct snd_soc_rbtree_node *rbnode;
853
854 rbtree_ctx = codec->reg_cache;
855 rbnode = snd_soc_rbtree_lookup(&rbtree_ctx->root, reg);
856 if (rbnode) {
857 if (rbnode->value == value)
858 return 0;
859 rbnode->value = value;
860 } else {
861 /* bail out early, no need to create the rbnode yet */
862 if (!value)
863 return 0;
864 /*
865 * for uninitialized registers whose value is changed
866 * from the default zero, create an rbnode and insert
867 * it into the tree.
868 */
869 rbnode = kzalloc(sizeof *rbnode, GFP_KERNEL);
870 if (!rbnode)
871 return -ENOMEM;
872 rbnode->reg = reg;
873 rbnode->value = value;
874 snd_soc_rbtree_insert(&rbtree_ctx->root, rbnode);
875 }
876
877 return 0;
878}
879
880static int snd_soc_rbtree_cache_read(struct snd_soc_codec *codec,
881 unsigned int reg, unsigned int *value)
882{
883 struct snd_soc_rbtree_ctx *rbtree_ctx;
884 struct snd_soc_rbtree_node *rbnode;
885
886 rbtree_ctx = codec->reg_cache;
887 rbnode = snd_soc_rbtree_lookup(&rbtree_ctx->root, reg);
888 if (rbnode) {
889 *value = rbnode->value;
890 } else {
891 /* uninitialized registers default to 0 */
892 *value = 0;
893 }
894
895 return 0;
896}
897
898static int snd_soc_rbtree_cache_exit(struct snd_soc_codec *codec)
899{
900 struct rb_node *next;
901 struct snd_soc_rbtree_ctx *rbtree_ctx;
902 struct snd_soc_rbtree_node *rbtree_node;
903
904 /* if we've already been called then just return */
905 rbtree_ctx = codec->reg_cache;
906 if (!rbtree_ctx)
907 return 0;
908
909 /* free up the rbtree */
910 next = rb_first(&rbtree_ctx->root);
911 while (next) {
912 rbtree_node = rb_entry(next, struct snd_soc_rbtree_node, node);
913 next = rb_next(&rbtree_node->node);
914 rb_erase(&rbtree_node->node, &rbtree_ctx->root);
915 kfree(rbtree_node);
916 }
917
918 /* release the resources */
919 kfree(codec->reg_cache);
920 codec->reg_cache = NULL;
921
922 return 0;
923}
924
925static int snd_soc_rbtree_cache_init(struct snd_soc_codec *codec)
926{
927 struct snd_soc_rbtree_ctx *rbtree_ctx;
928
929 codec->reg_cache = kmalloc(sizeof *rbtree_ctx, GFP_KERNEL);
930 if (!codec->reg_cache)
931 return -ENOMEM;
932
933 rbtree_ctx = codec->reg_cache;
934 rbtree_ctx->root = RB_ROOT;
935
936 if (!codec->reg_def_copy)
937 return 0;
938
939/*
940 * populate the rbtree with the initialized registers. All other
941 * registers will be inserted into the tree when they are first written.
942 *
943 * The reasoning behind this, is that we need to step through and
944 * dereference the cache in u8/u16 increments without sacrificing
945 * portability. This could also be done using memcpy() but that would
946 * be slightly more cryptic.
947 */
948#define snd_soc_rbtree_populate(cache) \
949({ \
950 int ret, i; \
951 struct snd_soc_rbtree_node *rbtree_node; \
952 \
953 ret = 0; \
954 cache = codec->reg_def_copy; \
955 for (i = 0; i < codec->driver->reg_cache_size; ++i) { \
956 if (!cache[i]) \
957 continue; \
958 rbtree_node = kzalloc(sizeof *rbtree_node, GFP_KERNEL); \
959 if (!rbtree_node) { \
960 ret = -ENOMEM; \
961 snd_soc_cache_exit(codec); \
962 break; \
963 } \
964 rbtree_node->reg = i; \
965 rbtree_node->value = cache[i]; \
966 rbtree_node->defval = cache[i]; \
967 snd_soc_rbtree_insert(&rbtree_ctx->root, \
968 rbtree_node); \
969 } \
970 ret; \
971})
972
973 switch (codec->driver->reg_word_size) {
974 case 1: {
975 const u8 *cache;
976
977 return snd_soc_rbtree_populate(cache);
978 }
979 case 2: {
980 const u16 *cache;
981
982 return snd_soc_rbtree_populate(cache);
983 }
984 default:
985 BUG();
986 }
987
988 return 0;
989}
990
991#ifdef CONFIG_SND_SOC_CACHE_LZO
992struct snd_soc_lzo_ctx {
993 void *wmem;
994 void *dst;
995 const void *src;
996 size_t src_len;
997 size_t dst_len;
998 size_t decompressed_size;
999 unsigned long *sync_bmp;
1000 int sync_bmp_nbits;
1001};
1002
1003#define LZO_BLOCK_NUM 8
1004static int snd_soc_lzo_block_count(void)
1005{
1006 return LZO_BLOCK_NUM;
1007}
1008
1009static int snd_soc_lzo_prepare(struct snd_soc_lzo_ctx *lzo_ctx)
1010{
1011 lzo_ctx->wmem = kmalloc(LZO1X_MEM_COMPRESS, GFP_KERNEL);
1012 if (!lzo_ctx->wmem)
1013 return -ENOMEM;
1014 return 0;
1015}
1016
1017static int snd_soc_lzo_compress(struct snd_soc_lzo_ctx *lzo_ctx)
1018{
1019 size_t compress_size;
1020 int ret;
1021
1022 ret = lzo1x_1_compress(lzo_ctx->src, lzo_ctx->src_len,
1023 lzo_ctx->dst, &compress_size, lzo_ctx->wmem);
1024 if (ret != LZO_E_OK || compress_size > lzo_ctx->dst_len)
1025 return -EINVAL;
1026 lzo_ctx->dst_len = compress_size;
1027 return 0;
1028}
1029
1030static int snd_soc_lzo_decompress(struct snd_soc_lzo_ctx *lzo_ctx)
1031{
1032 size_t dst_len;
1033 int ret;
1034
1035 dst_len = lzo_ctx->dst_len;
1036 ret = lzo1x_decompress_safe(lzo_ctx->src, lzo_ctx->src_len,
1037 lzo_ctx->dst, &dst_len);
1038 if (ret != LZO_E_OK || dst_len != lzo_ctx->dst_len)
1039 return -EINVAL;
1040 return 0;
1041}
1042
1043static int snd_soc_lzo_compress_cache_block(struct snd_soc_codec *codec,
1044 struct snd_soc_lzo_ctx *lzo_ctx)
1045{
1046 int ret;
1047
1048 lzo_ctx->dst_len = lzo1x_worst_compress(PAGE_SIZE);
1049 lzo_ctx->dst = kmalloc(lzo_ctx->dst_len, GFP_KERNEL);
1050 if (!lzo_ctx->dst) {
1051 lzo_ctx->dst_len = 0;
1052 return -ENOMEM;
1053 }
1054
1055 ret = snd_soc_lzo_compress(lzo_ctx);
1056 if (ret < 0)
1057 return ret;
1058 return 0;
1059}
1060
1061static int snd_soc_lzo_decompress_cache_block(struct snd_soc_codec *codec,
1062 struct snd_soc_lzo_ctx *lzo_ctx)
1063{
1064 int ret;
1065
1066 lzo_ctx->dst_len = lzo_ctx->decompressed_size;
1067 lzo_ctx->dst = kmalloc(lzo_ctx->dst_len, GFP_KERNEL);
1068 if (!lzo_ctx->dst) {
1069 lzo_ctx->dst_len = 0;
1070 return -ENOMEM;
1071 }
1072
1073 ret = snd_soc_lzo_decompress(lzo_ctx);
1074 if (ret < 0)
1075 return ret;
1076 return 0;
1077}
1078
1079static inline int snd_soc_lzo_get_blkindex(struct snd_soc_codec *codec,
1080 unsigned int reg)
1081{
1082 const struct snd_soc_codec_driver *codec_drv;
1083 size_t reg_size;
1084
1085 codec_drv = codec->driver;
1086 reg_size = codec_drv->reg_cache_size * codec_drv->reg_word_size;
1087 return (reg * codec_drv->reg_word_size) /
1088 DIV_ROUND_UP(reg_size, snd_soc_lzo_block_count());
1089}
1090
1091static inline int snd_soc_lzo_get_blkpos(struct snd_soc_codec *codec,
1092 unsigned int reg)
1093{
1094 const struct snd_soc_codec_driver *codec_drv;
1095 size_t reg_size;
1096
1097 codec_drv = codec->driver;
1098 reg_size = codec_drv->reg_cache_size * codec_drv->reg_word_size;
1099 return reg % (DIV_ROUND_UP(reg_size, snd_soc_lzo_block_count()) /
1100 codec_drv->reg_word_size);
1101}
1102
1103static inline int snd_soc_lzo_get_blksize(struct snd_soc_codec *codec)
1104{
1105 const struct snd_soc_codec_driver *codec_drv;
1106 size_t reg_size;
1107
1108 codec_drv = codec->driver;
1109 reg_size = codec_drv->reg_cache_size * codec_drv->reg_word_size;
1110 return DIV_ROUND_UP(reg_size, snd_soc_lzo_block_count());
1111}
1112
1113static int snd_soc_lzo_cache_sync(struct snd_soc_codec *codec)
1114{
1115 struct snd_soc_lzo_ctx **lzo_blocks;
1116 unsigned int val;
1117 int i;
1118 int ret;
1119
1120 lzo_blocks = codec->reg_cache;
1121 for_each_set_bit(i, lzo_blocks[0]->sync_bmp, lzo_blocks[0]->sync_bmp_nbits) {
1122 ret = snd_soc_cache_read(codec, i, &val);
1123 if (ret)
1124 return ret;
1125 ret = snd_soc_write(codec, i, val);
1126 if (ret)
1127 return ret;
1128 dev_dbg(codec->dev, "Synced register %#x, value = %#x\n",
1129 i, val);
1130 }
1131
1132 return 0;
1133}
1134
1135static int snd_soc_lzo_cache_write(struct snd_soc_codec *codec,
1136 unsigned int reg, unsigned int value)
1137{
1138 struct snd_soc_lzo_ctx *lzo_block, **lzo_blocks;
1139 int ret, blkindex, blkpos;
1140 size_t blksize, tmp_dst_len;
1141 void *tmp_dst;
1142
1143 /* index of the compressed lzo block */
1144 blkindex = snd_soc_lzo_get_blkindex(codec, reg);
1145 /* register index within the decompressed block */
1146 blkpos = snd_soc_lzo_get_blkpos(codec, reg);
1147 /* size of the compressed block */
1148 blksize = snd_soc_lzo_get_blksize(codec);
1149 lzo_blocks = codec->reg_cache;
1150 lzo_block = lzo_blocks[blkindex];
1151
1152 /* save the pointer and length of the compressed block */
1153 tmp_dst = lzo_block->dst;
1154 tmp_dst_len = lzo_block->dst_len;
1155
1156 /* prepare the source to be the compressed block */
1157 lzo_block->src = lzo_block->dst;
1158 lzo_block->src_len = lzo_block->dst_len;
1159
1160 /* decompress the block */
1161 ret = snd_soc_lzo_decompress_cache_block(codec, lzo_block);
1162 if (ret < 0) {
1163 kfree(lzo_block->dst);
1164 goto out;
1165 }
1166
1167 /* write the new value to the cache */
1168 switch (codec->driver->reg_word_size) {
1169 case 1: {
1170 u8 *cache;
1171 cache = lzo_block->dst;
1172 if (cache[blkpos] == value) {
1173 kfree(lzo_block->dst);
1174 goto out;
1175 }
1176 cache[blkpos] = value;
1177 }
1178 break;
1179 case 2: {
1180 u16 *cache;
1181 cache = lzo_block->dst;
1182 if (cache[blkpos] == value) {
1183 kfree(lzo_block->dst);
1184 goto out;
1185 }
1186 cache[blkpos] = value;
1187 }
1188 break;
1189 default:
1190 BUG();
1191 }
1192
1193 /* prepare the source to be the decompressed block */
1194 lzo_block->src = lzo_block->dst;
1195 lzo_block->src_len = lzo_block->dst_len;
1196
1197 /* compress the block */
1198 ret = snd_soc_lzo_compress_cache_block(codec, lzo_block);
1199 if (ret < 0) {
1200 kfree(lzo_block->dst);
1201 kfree(lzo_block->src);
1202 goto out;
1203 }
1204
1205 /* set the bit so we know we have to sync this register */
1206 set_bit(reg, lzo_block->sync_bmp);
1207 kfree(tmp_dst);
1208 kfree(lzo_block->src);
1209 return 0;
1210out:
1211 lzo_block->dst = tmp_dst;
1212 lzo_block->dst_len = tmp_dst_len;
1213 return ret;
1214}
1215
1216static int snd_soc_lzo_cache_read(struct snd_soc_codec *codec,
1217 unsigned int reg, unsigned int *value)
1218{
1219 struct snd_soc_lzo_ctx *lzo_block, **lzo_blocks;
1220 int ret, blkindex, blkpos;
1221 size_t blksize, tmp_dst_len;
1222 void *tmp_dst;
1223
1224 *value = 0;
1225 /* index of the compressed lzo block */
1226 blkindex = snd_soc_lzo_get_blkindex(codec, reg);
1227 /* register index within the decompressed block */
1228 blkpos = snd_soc_lzo_get_blkpos(codec, reg);
1229 /* size of the compressed block */
1230 blksize = snd_soc_lzo_get_blksize(codec);
1231 lzo_blocks = codec->reg_cache;
1232 lzo_block = lzo_blocks[blkindex];
1233
1234 /* save the pointer and length of the compressed block */
1235 tmp_dst = lzo_block->dst;
1236 tmp_dst_len = lzo_block->dst_len;
1237
1238 /* prepare the source to be the compressed block */
1239 lzo_block->src = lzo_block->dst;
1240 lzo_block->src_len = lzo_block->dst_len;
1241
1242 /* decompress the block */
1243 ret = snd_soc_lzo_decompress_cache_block(codec, lzo_block);
1244 if (ret >= 0) {
1245 /* fetch the value from the cache */
1246 switch (codec->driver->reg_word_size) {
1247 case 1: {
1248 u8 *cache;
1249 cache = lzo_block->dst;
1250 *value = cache[blkpos];
1251 }
1252 break;
1253 case 2: {
1254 u16 *cache;
1255 cache = lzo_block->dst;
1256 *value = cache[blkpos];
1257 }
1258 break;
1259 default:
1260 BUG();
1261 }
1262 }
1263
1264 kfree(lzo_block->dst);
1265 /* restore the pointer and length of the compressed block */
1266 lzo_block->dst = tmp_dst;
1267 lzo_block->dst_len = tmp_dst_len;
1268 return 0;
1269}
1270
1271static int snd_soc_lzo_cache_exit(struct snd_soc_codec *codec)
1272{
1273 struct snd_soc_lzo_ctx **lzo_blocks;
1274 int i, blkcount;
1275
1276 lzo_blocks = codec->reg_cache;
1277 if (!lzo_blocks)
1278 return 0;
1279
1280 blkcount = snd_soc_lzo_block_count();
1281 /*
1282 * the pointer to the bitmap used for syncing the cache
1283 * is shared amongst all lzo_blocks. Ensure it is freed
1284 * only once.
1285 */
1286 if (lzo_blocks[0])
1287 kfree(lzo_blocks[0]->sync_bmp);
1288 for (i = 0; i < blkcount; ++i) {
1289 if (lzo_blocks[i]) {
1290 kfree(lzo_blocks[i]->wmem);
1291 kfree(lzo_blocks[i]->dst);
1292 }
1293 /* each lzo_block is a pointer returned by kmalloc or NULL */
1294 kfree(lzo_blocks[i]);
1295 }
1296 kfree(lzo_blocks);
1297 codec->reg_cache = NULL;
1298 return 0;
1299}
1300
1301static int snd_soc_lzo_cache_init(struct snd_soc_codec *codec)
1302{
1303 struct snd_soc_lzo_ctx **lzo_blocks;
1304 size_t reg_size, bmp_size;
1305 const struct snd_soc_codec_driver *codec_drv;
1306 int ret, tofree, i, blksize, blkcount;
1307 const char *p, *end;
1308 unsigned long *sync_bmp;
1309
1310 ret = 0;
1311 codec_drv = codec->driver;
1312 reg_size = codec_drv->reg_cache_size * codec_drv->reg_word_size;
1313
1314 /*
1315 * If we have not been given a default register cache
1316 * then allocate a dummy zero-ed out region, compress it
1317 * and remember to free it afterwards.
1318 */
1319 tofree = 0;
1320 if (!codec->reg_def_copy)
1321 tofree = 1;
1322
1323 if (!codec->reg_def_copy) {
1324 codec->reg_def_copy = kzalloc(reg_size,
1325 GFP_KERNEL);
1326 if (!codec->reg_def_copy)
1327 return -ENOMEM;
1328 }
1329
1330 blkcount = snd_soc_lzo_block_count();
1331 codec->reg_cache = kzalloc(blkcount * sizeof *lzo_blocks,
1332 GFP_KERNEL);
1333 if (!codec->reg_cache) {
1334 ret = -ENOMEM;
1335 goto err_tofree;
1336 }
1337 lzo_blocks = codec->reg_cache;
1338
1339 /*
1340 * allocate a bitmap to be used when syncing the cache with
1341 * the hardware. Each time a register is modified, the corresponding
1342 * bit is set in the bitmap, so we know that we have to sync
1343 * that register.
1344 */
1345 bmp_size = codec_drv->reg_cache_size;
1346 sync_bmp = kmalloc(BITS_TO_LONGS(bmp_size) * sizeof(long),
1347 GFP_KERNEL);
1348 if (!sync_bmp) {
1349 ret = -ENOMEM;
1350 goto err;
1351 }
1352 bitmap_zero(sync_bmp, bmp_size);
1353
1354 /* allocate the lzo blocks and initialize them */
1355 for (i = 0; i < blkcount; ++i) {
1356 lzo_blocks[i] = kzalloc(sizeof **lzo_blocks,
1357 GFP_KERNEL);
1358 if (!lzo_blocks[i]) {
1359 kfree(sync_bmp);
1360 ret = -ENOMEM;
1361 goto err;
1362 }
1363 lzo_blocks[i]->sync_bmp = sync_bmp;
1364 lzo_blocks[i]->sync_bmp_nbits = bmp_size;
1365 /* alloc the working space for the compressed block */
1366 ret = snd_soc_lzo_prepare(lzo_blocks[i]);
1367 if (ret < 0)
1368 goto err;
1369 }
1370
1371 blksize = snd_soc_lzo_get_blksize(codec);
1372 p = codec->reg_def_copy;
1373 end = codec->reg_def_copy + reg_size;
1374 /* compress the register map and fill the lzo blocks */
1375 for (i = 0; i < blkcount; ++i, p += blksize) {
1376 lzo_blocks[i]->src = p;
1377 if (p + blksize > end)
1378 lzo_blocks[i]->src_len = end - p;
1379 else
1380 lzo_blocks[i]->src_len = blksize;
1381 ret = snd_soc_lzo_compress_cache_block(codec,
1382 lzo_blocks[i]);
1383 if (ret < 0)
1384 goto err;
1385 lzo_blocks[i]->decompressed_size =
1386 lzo_blocks[i]->src_len;
1387 }
1388
1389 if (tofree) {
1390 kfree(codec->reg_def_copy);
1391 codec->reg_def_copy = NULL;
1392 }
1393 return 0;
1394err:
1395 snd_soc_cache_exit(codec);
1396err_tofree:
1397 if (tofree) {
1398 kfree(codec->reg_def_copy);
1399 codec->reg_def_copy = NULL;
1400 }
1401 return ret;
1402}
1403#endif
1404
1405static int snd_soc_flat_cache_sync(struct snd_soc_codec *codec)
1406{
1407 int i;
1408 int ret;
1409 const struct snd_soc_codec_driver *codec_drv;
1410 unsigned int val;
1411
1412 codec_drv = codec->driver;
1413 for (i = 0; i < codec_drv->reg_cache_size; ++i) {
1414 ret = snd_soc_cache_read(codec, i, &val);
1415 if (ret)
1416 return ret;
1417 if (codec_drv->reg_cache_default) {
1418 switch (codec_drv->reg_word_size) {
1419 case 1: {
1420 const u8 *cache;
1421
1422 cache = codec_drv->reg_cache_default;
1423 if (cache[i] == val)
1424 continue;
1425 }
1426 break;
1427 case 2: {
1428 const u16 *cache;
1429
1430 cache = codec_drv->reg_cache_default;
1431 if (cache[i] == val)
1432 continue;
1433 }
1434 break;
1435 default:
1436 BUG();
1437 }
1438 }
1439 ret = snd_soc_write(codec, i, val);
1440 if (ret)
1441 return ret;
1442 dev_dbg(codec->dev, "Synced register %#x, value = %#x\n",
1443 i, val);
1444 }
1445 return 0;
1446}
1447
1448static int snd_soc_flat_cache_write(struct snd_soc_codec *codec,
1449 unsigned int reg, unsigned int value)
1450{
1451 switch (codec->driver->reg_word_size) {
1452 case 1: {
1453 u8 *cache;
1454
1455 cache = codec->reg_cache;
1456 cache[reg] = value;
1457 }
1458 break;
1459 case 2: {
1460 u16 *cache;
1461
1462 cache = codec->reg_cache;
1463 cache[reg] = value;
1464 }
1465 break;
1466 default:
1467 BUG();
1468 }
1469
1470 return 0;
1471}
1472
1473static int snd_soc_flat_cache_read(struct snd_soc_codec *codec,
1474 unsigned int reg, unsigned int *value)
1475{
1476 switch (codec->driver->reg_word_size) {
1477 case 1: {
1478 u8 *cache;
1479
1480 cache = codec->reg_cache;
1481 *value = cache[reg];
1482 }
1483 break;
1484 case 2: {
1485 u16 *cache;
1486
1487 cache = codec->reg_cache;
1488 *value = cache[reg];
1489 }
1490 break;
1491 default:
1492 BUG();
1493 }
1494
1495 return 0;
1496}
1497
1498static int snd_soc_flat_cache_exit(struct snd_soc_codec *codec)
1499{
1500 if (!codec->reg_cache)
1501 return 0;
1502 kfree(codec->reg_cache);
1503 codec->reg_cache = NULL;
1504 return 0;
1505}
1506
1507static int snd_soc_flat_cache_init(struct snd_soc_codec *codec)
1508{
1509 const struct snd_soc_codec_driver *codec_drv;
1510 size_t reg_size;
1511
1512 codec_drv = codec->driver;
1513 reg_size = codec_drv->reg_cache_size * codec_drv->reg_word_size;
1514
1515 /*
1516 * for flat compression, we don't need to keep a copy of the
1517 * original defaults register cache as it will definitely not
1518 * be marked as __devinitconst
1519 */
1520 kfree(codec->reg_def_copy);
1521 codec->reg_def_copy = NULL;
1522
1523 if (codec_drv->reg_cache_default)
1524 codec->reg_cache = kmemdup(codec_drv->reg_cache_default,
1525 reg_size, GFP_KERNEL);
1526 else
1527 codec->reg_cache = kzalloc(reg_size, GFP_KERNEL);
1528 if (!codec->reg_cache)
1529 return -ENOMEM;
1530
1531 return 0;
1532}
1533
1534/* an array of all supported compression types */
1535static const struct snd_soc_cache_ops cache_types[] = {
1536 /* Flat *must* be the first entry for fallback */
1537 {
1538 .id = SND_SOC_FLAT_COMPRESSION,
1539 .name = "flat",
1540 .init = snd_soc_flat_cache_init,
1541 .exit = snd_soc_flat_cache_exit,
1542 .read = snd_soc_flat_cache_read,
1543 .write = snd_soc_flat_cache_write,
1544 .sync = snd_soc_flat_cache_sync
1545 },
1546#ifdef CONFIG_SND_SOC_CACHE_LZO
1547 {
1548 .id = SND_SOC_LZO_COMPRESSION,
1549 .name = "LZO",
1550 .init = snd_soc_lzo_cache_init,
1551 .exit = snd_soc_lzo_cache_exit,
1552 .read = snd_soc_lzo_cache_read,
1553 .write = snd_soc_lzo_cache_write,
1554 .sync = snd_soc_lzo_cache_sync
1555 },
1556#endif
1557 {
1558 .id = SND_SOC_RBTREE_COMPRESSION,
1559 .name = "rbtree",
1560 .init = snd_soc_rbtree_cache_init,
1561 .exit = snd_soc_rbtree_cache_exit,
1562 .read = snd_soc_rbtree_cache_read,
1563 .write = snd_soc_rbtree_cache_write,
1564 .sync = snd_soc_rbtree_cache_sync
1565 }
1566};
1567
1568int snd_soc_cache_init(struct snd_soc_codec *codec)
1569{
1570 int i;
1571
1572 for (i = 0; i < ARRAY_SIZE(cache_types); ++i)
1573 if (cache_types[i].id == codec->compress_type)
1574 break;
1575
1576 /* Fall back to flat compression */
1577 if (i == ARRAY_SIZE(cache_types)) {
1578 dev_warn(codec->dev, "Could not match compress type: %d\n",
1579 codec->compress_type);
1580 i = 0;
1581 }
1582
1583 mutex_init(&codec->cache_rw_mutex);
1584 codec->cache_ops = &cache_types[i];
1585
1586 if (codec->cache_ops->init) {
1587 if (codec->cache_ops->name)
1588 dev_dbg(codec->dev, "Initializing %s cache for %s codec\n",
1589 codec->cache_ops->name, codec->name);
1590 return codec->cache_ops->init(codec);
1591 }
1592 return -EINVAL;
1593}
1594
1595/*
1596 * NOTE: keep in mind that this function might be called
1597 * multiple times.
1598 */
1599int snd_soc_cache_exit(struct snd_soc_codec *codec)
1600{
1601 if (codec->cache_ops && codec->cache_ops->exit) {
1602 if (codec->cache_ops->name)
1603 dev_dbg(codec->dev, "Destroying %s cache for %s codec\n",
1604 codec->cache_ops->name, codec->name);
1605 return codec->cache_ops->exit(codec);
1606 }
1607 return -EINVAL;
1608}
1609
1610/**
1611 * snd_soc_cache_read: Fetch the value of a given register from the cache.
1612 *
1613 * @codec: CODEC to configure.
1614 * @reg: The register index.
1615 * @value: The value to be returned.
1616 */
1617int snd_soc_cache_read(struct snd_soc_codec *codec,
1618 unsigned int reg, unsigned int *value)
1619{
1620 int ret;
1621
1622 mutex_lock(&codec->cache_rw_mutex);
1623
1624 if (value && codec->cache_ops && codec->cache_ops->read) {
1625 ret = codec->cache_ops->read(codec, reg, value);
1626 mutex_unlock(&codec->cache_rw_mutex);
1627 return ret;
1628 }
1629
1630 mutex_unlock(&codec->cache_rw_mutex);
1631 return -EINVAL;
1632}
1633EXPORT_SYMBOL_GPL(snd_soc_cache_read);
1634
1635/**
1636 * snd_soc_cache_write: Set the value of a given register in the cache.
1637 *
1638 * @codec: CODEC to configure.
1639 * @reg: The register index.
1640 * @value: The new register value.
1641 */
1642int snd_soc_cache_write(struct snd_soc_codec *codec,
1643 unsigned int reg, unsigned int value)
1644{
1645 int ret;
1646
1647 mutex_lock(&codec->cache_rw_mutex);
1648
1649 if (codec->cache_ops && codec->cache_ops->write) {
1650 ret = codec->cache_ops->write(codec, reg, value);
1651 mutex_unlock(&codec->cache_rw_mutex);
1652 return ret;
1653 }
1654
1655 mutex_unlock(&codec->cache_rw_mutex);
1656 return -EINVAL;
1657}
1658EXPORT_SYMBOL_GPL(snd_soc_cache_write);
1659
1660/**
1661 * snd_soc_cache_sync: Sync the register cache with the hardware.
1662 *
1663 * @codec: CODEC to configure.
1664 *
1665 * Any registers that should not be synced should be marked as
1666 * volatile. In general drivers can choose not to use the provided
1667 * syncing functionality if they so require.
1668 */
1669int snd_soc_cache_sync(struct snd_soc_codec *codec)
1670{
1671 int ret;
1672
1673 if (!codec->cache_sync) {
1674 return 0;
1675 }
1676
1677 if (codec->cache_ops && codec->cache_ops->sync) {
1678 if (codec->cache_ops->name)
1679 dev_dbg(codec->dev, "Syncing %s cache for %s codec\n",
1680 codec->cache_ops->name, codec->name);
1681 ret = codec->cache_ops->sync(codec);
1682 if (!ret)
1683 codec->cache_sync = 0;
1684 return ret;
1685 }
1686
1687 return -EINVAL;
1688}
1689EXPORT_SYMBOL_GPL(snd_soc_cache_sync);
diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c
index 85b7d548f167..bac7291b6ff6 100644
--- a/sound/soc/soc-core.c
+++ b/sound/soc/soc-core.c
@@ -33,12 +33,15 @@
33#include <linux/slab.h> 33#include <linux/slab.h>
34#include <sound/ac97_codec.h> 34#include <sound/ac97_codec.h>
35#include <sound/core.h> 35#include <sound/core.h>
36#include <sound/jack.h>
36#include <sound/pcm.h> 37#include <sound/pcm.h>
37#include <sound/pcm_params.h> 38#include <sound/pcm_params.h>
38#include <sound/soc.h> 39#include <sound/soc.h>
39#include <sound/soc-dapm.h>
40#include <sound/initval.h> 40#include <sound/initval.h>
41 41
42#define CREATE_TRACE_POINTS
43#include <trace/events/asoc.h>
44
42#define NAME_SIZE 32 45#define NAME_SIZE 32
43 46
44static DEFINE_MUTEX(pcm_mutex); 47static DEFINE_MUTEX(pcm_mutex);
@@ -67,25 +70,6 @@ static int pmdown_time = 5000;
67module_param(pmdown_time, int, 0); 70module_param(pmdown_time, int, 0);
68MODULE_PARM_DESC(pmdown_time, "DAPM stream powerdown time (msecs)"); 71MODULE_PARM_DESC(pmdown_time, "DAPM stream powerdown time (msecs)");
69 72
70/*
71 * This function forces any delayed work to be queued and run.
72 */
73static int run_delayed_work(struct delayed_work *dwork)
74{
75 int ret;
76
77 /* cancel any work waiting to be queued. */
78 ret = cancel_delayed_work(dwork);
79
80 /* if there was any work waiting then we run it now and
81 * wait for it's completion */
82 if (ret) {
83 schedule_delayed_work(dwork, 0);
84 flush_scheduled_work();
85 }
86 return ret;
87}
88
89/* codec register dump */ 73/* codec register dump */
90static ssize_t soc_codec_reg_show(struct snd_soc_codec *codec, char *buf) 74static ssize_t soc_codec_reg_show(struct snd_soc_codec *codec, char *buf)
91{ 75{
@@ -114,7 +98,7 @@ static ssize_t soc_codec_reg_show(struct snd_soc_codec *codec, char *buf)
114 * the register being volatile and the device being 98 * the register being volatile and the device being
115 * powered off. 99 * powered off.
116 */ 100 */
117 ret = codec->driver->read(codec, i); 101 ret = snd_soc_read(codec, i);
118 if (ret >= 0) 102 if (ret >= 0)
119 count += snprintf(buf + count, 103 count += snprintf(buf + count,
120 PAGE_SIZE - count, 104 PAGE_SIZE - count,
@@ -225,7 +209,7 @@ static ssize_t codec_reg_write_file(struct file *file,
225 start++; 209 start++;
226 if (strict_strtoul(start, 16, &value)) 210 if (strict_strtoul(start, 16, &value))
227 return -EINVAL; 211 return -EINVAL;
228 codec->driver->write(codec, reg, value); 212 snd_soc_write(codec, reg, value);
229 return buf_size; 213 return buf_size;
230} 214}
231 215
@@ -238,8 +222,10 @@ static const struct file_operations codec_reg_fops = {
238 222
239static void soc_init_codec_debugfs(struct snd_soc_codec *codec) 223static void soc_init_codec_debugfs(struct snd_soc_codec *codec)
240{ 224{
241 codec->debugfs_codec_root = debugfs_create_dir(codec->name , 225 struct dentry *debugfs_card_root = codec->card->debugfs_card_root;
242 debugfs_root); 226
227 codec->debugfs_codec_root = debugfs_create_dir(codec->name,
228 debugfs_card_root);
243 if (!codec->debugfs_codec_root) { 229 if (!codec->debugfs_codec_root) {
244 printk(KERN_WARNING 230 printk(KERN_WARNING
245 "ASoC: Failed to create codec debugfs directory\n"); 231 "ASoC: Failed to create codec debugfs directory\n");
@@ -253,20 +239,13 @@ static void soc_init_codec_debugfs(struct snd_soc_codec *codec)
253 printk(KERN_WARNING 239 printk(KERN_WARNING
254 "ASoC: Failed to create codec register debugfs file\n"); 240 "ASoC: Failed to create codec register debugfs file\n");
255 241
256 codec->debugfs_pop_time = debugfs_create_u32("dapm_pop_time", 0644, 242 codec->dapm.debugfs_dapm = debugfs_create_dir("dapm",
257 codec->debugfs_codec_root,
258 &codec->pop_time);
259 if (!codec->debugfs_pop_time)
260 printk(KERN_WARNING
261 "Failed to create pop time debugfs file\n");
262
263 codec->debugfs_dapm = debugfs_create_dir("dapm",
264 codec->debugfs_codec_root); 243 codec->debugfs_codec_root);
265 if (!codec->debugfs_dapm) 244 if (!codec->dapm.debugfs_dapm)
266 printk(KERN_WARNING 245 printk(KERN_WARNING
267 "Failed to create DAPM debugfs directory\n"); 246 "Failed to create DAPM debugfs directory\n");
268 247
269 snd_soc_dapm_debugfs_init(codec); 248 snd_soc_dapm_debugfs_init(&codec->dapm);
270} 249}
271 250
272static void soc_cleanup_codec_debugfs(struct snd_soc_codec *codec) 251static void soc_cleanup_codec_debugfs(struct snd_soc_codec *codec)
@@ -374,6 +353,29 @@ static const struct file_operations platform_list_fops = {
374 .llseek = default_llseek,/* read accesses f_pos */ 353 .llseek = default_llseek,/* read accesses f_pos */
375}; 354};
376 355
356static void soc_init_card_debugfs(struct snd_soc_card *card)
357{
358 card->debugfs_card_root = debugfs_create_dir(card->name,
359 debugfs_root);
360 if (!card->debugfs_card_root) {
361 dev_warn(card->dev,
362 "ASoC: Failed to create codec debugfs directory\n");
363 return;
364 }
365
366 card->debugfs_pop_time = debugfs_create_u32("dapm_pop_time", 0644,
367 card->debugfs_card_root,
368 &card->pop_time);
369 if (!card->debugfs_pop_time)
370 dev_warn(card->dev,
371 "Failed to create pop time debugfs file\n");
372}
373
374static void soc_cleanup_card_debugfs(struct snd_soc_card *card)
375{
376 debugfs_remove_recursive(card->debugfs_card_root);
377}
378
377#else 379#else
378 380
379static inline void soc_init_codec_debugfs(struct snd_soc_codec *codec) 381static inline void soc_init_codec_debugfs(struct snd_soc_codec *codec)
@@ -383,6 +385,14 @@ static inline void soc_init_codec_debugfs(struct snd_soc_codec *codec)
383static inline void soc_cleanup_codec_debugfs(struct snd_soc_codec *codec) 385static inline void soc_cleanup_codec_debugfs(struct snd_soc_codec *codec)
384{ 386{
385} 387}
388
389static inline void soc_init_card_debugfs(struct snd_soc_card *card)
390{
391}
392
393static inline void soc_cleanup_card_debugfs(struct snd_soc_card *card)
394{
395}
386#endif 396#endif
387 397
388#ifdef CONFIG_SND_SOC_AC97_BUS 398#ifdef CONFIG_SND_SOC_AC97_BUS
@@ -497,7 +507,7 @@ static int soc_pcm_open(struct snd_pcm_substream *substream)
497 } 507 }
498 } 508 }
499 509
500 /* Check that the codec and cpu DAI's are compatible */ 510 /* Check that the codec and cpu DAIs are compatible */
501 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { 511 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
502 runtime->hw.rate_min = 512 runtime->hw.rate_min =
503 max(codec_dai_drv->playback.rate_min, 513 max(codec_dai_drv->playback.rate_min,
@@ -846,7 +856,7 @@ codec_err:
846} 856}
847 857
848/* 858/*
849 * Free's resources allocated by hw_params, can be called multiple times 859 * Frees resources allocated by hw_params, can be called multiple times
850 */ 860 */
851static int soc_pcm_hw_free(struct snd_pcm_substream *substream) 861static int soc_pcm_hw_free(struct snd_pcm_substream *substream)
852{ 862{
@@ -870,7 +880,7 @@ static int soc_pcm_hw_free(struct snd_pcm_substream *substream)
870 if (platform->driver->ops->hw_free) 880 if (platform->driver->ops->hw_free)
871 platform->driver->ops->hw_free(substream); 881 platform->driver->ops->hw_free(substream);
872 882
873 /* now free hw params for the DAI's */ 883 /* now free hw params for the DAIs */
874 if (codec_dai->driver->ops->hw_free) 884 if (codec_dai->driver->ops->hw_free)
875 codec_dai->driver->ops->hw_free(substream, codec_dai); 885 codec_dai->driver->ops->hw_free(substream, codec_dai);
876 886
@@ -958,6 +968,7 @@ static int soc_suspend(struct device *dev)
958{ 968{
959 struct platform_device *pdev = to_platform_device(dev); 969 struct platform_device *pdev = to_platform_device(dev);
960 struct snd_soc_card *card = platform_get_drvdata(pdev); 970 struct snd_soc_card *card = platform_get_drvdata(pdev);
971 struct snd_soc_codec *codec;
961 int i; 972 int i;
962 973
963 /* If the initialization of this soc device failed, there is no codec 974 /* If the initialization of this soc device failed, there is no codec
@@ -976,7 +987,7 @@ static int soc_suspend(struct device *dev)
976 /* we're going to block userspace touching us until resume completes */ 987 /* we're going to block userspace touching us until resume completes */
977 snd_power_change_state(card->snd_card, SNDRV_CTL_POWER_D3hot); 988 snd_power_change_state(card->snd_card, SNDRV_CTL_POWER_D3hot);
978 989
979 /* mute any active DAC's */ 990 /* mute any active DACs */
980 for (i = 0; i < card->num_rtd; i++) { 991 for (i = 0; i < card->num_rtd; i++) {
981 struct snd_soc_dai *dai = card->rtd[i].codec_dai; 992 struct snd_soc_dai *dai = card->rtd[i].codec_dai;
982 struct snd_soc_dai_driver *drv = dai->driver; 993 struct snd_soc_dai_driver *drv = dai->driver;
@@ -1016,8 +1027,8 @@ static int soc_suspend(struct device *dev)
1016 1027
1017 /* close any waiting streams and save state */ 1028 /* close any waiting streams and save state */
1018 for (i = 0; i < card->num_rtd; i++) { 1029 for (i = 0; i < card->num_rtd; i++) {
1019 run_delayed_work(&card->rtd[i].delayed_work); 1030 flush_delayed_work_sync(&card->rtd[i].delayed_work);
1020 card->rtd[i].codec->suspend_bias_level = card->rtd[i].codec->bias_level; 1031 card->rtd[i].codec->dapm.suspend_bias_level = card->rtd[i].codec->dapm.bias_level;
1021 } 1032 }
1022 1033
1023 for (i = 0; i < card->num_rtd; i++) { 1034 for (i = 0; i < card->num_rtd; i++) {
@@ -1036,12 +1047,11 @@ static int soc_suspend(struct device *dev)
1036 } 1047 }
1037 1048
1038 /* suspend all CODECs */ 1049 /* suspend all CODECs */
1039 for (i = 0; i < card->num_rtd; i++) { 1050 list_for_each_entry(codec, &card->codec_dev_list, card_list) {
1040 struct snd_soc_codec *codec = card->rtd[i].codec;
1041 /* If there are paths active then the CODEC will be held with 1051 /* If there are paths active then the CODEC will be held with
1042 * bias _ON and should not be suspended. */ 1052 * bias _ON and should not be suspended. */
1043 if (!codec->suspended && codec->driver->suspend) { 1053 if (!codec->suspended && codec->driver->suspend) {
1044 switch (codec->bias_level) { 1054 switch (codec->dapm.bias_level) {
1045 case SND_SOC_BIAS_STANDBY: 1055 case SND_SOC_BIAS_STANDBY:
1046 case SND_SOC_BIAS_OFF: 1056 case SND_SOC_BIAS_OFF:
1047 codec->driver->suspend(codec, PMSG_SUSPEND); 1057 codec->driver->suspend(codec, PMSG_SUSPEND);
@@ -1078,6 +1088,7 @@ static void soc_resume_deferred(struct work_struct *work)
1078 struct snd_soc_card *card = 1088 struct snd_soc_card *card =
1079 container_of(work, struct snd_soc_card, deferred_resume_work); 1089 container_of(work, struct snd_soc_card, deferred_resume_work);
1080 struct platform_device *pdev = to_platform_device(card->dev); 1090 struct platform_device *pdev = to_platform_device(card->dev);
1091 struct snd_soc_codec *codec;
1081 int i; 1092 int i;
1082 1093
1083 /* our power state is still SNDRV_CTL_POWER_D3hot from suspend time, 1094 /* our power state is still SNDRV_CTL_POWER_D3hot from suspend time,
@@ -1103,14 +1114,13 @@ static void soc_resume_deferred(struct work_struct *work)
1103 cpu_dai->driver->resume(cpu_dai); 1114 cpu_dai->driver->resume(cpu_dai);
1104 } 1115 }
1105 1116
1106 for (i = 0; i < card->num_rtd; i++) { 1117 list_for_each_entry(codec, &card->codec_dev_list, card_list) {
1107 struct snd_soc_codec *codec = card->rtd[i].codec;
1108 /* If the CODEC was idle over suspend then it will have been 1118 /* If the CODEC was idle over suspend then it will have been
1109 * left with bias OFF or STANDBY and suspended so we must now 1119 * left with bias OFF or STANDBY and suspended so we must now
1110 * resume. Otherwise the suspend was suppressed. 1120 * resume. Otherwise the suspend was suppressed.
1111 */ 1121 */
1112 if (codec->driver->resume && codec->suspended) { 1122 if (codec->driver->resume && codec->suspended) {
1113 switch (codec->bias_level) { 1123 switch (codec->dapm.bias_level) {
1114 case SND_SOC_BIAS_STANDBY: 1124 case SND_SOC_BIAS_STANDBY:
1115 case SND_SOC_BIAS_OFF: 1125 case SND_SOC_BIAS_OFF:
1116 codec->driver->resume(codec); 1126 codec->driver->resume(codec);
@@ -1249,9 +1259,6 @@ find_codec:
1249 if (!strcmp(codec->name, dai_link->codec_name)) { 1259 if (!strcmp(codec->name, dai_link->codec_name)) {
1250 rtd->codec = codec; 1260 rtd->codec = codec;
1251 1261
1252 if (!try_module_get(codec->dev->driver->owner))
1253 return -ENODEV;
1254
1255 /* CODEC found, so find CODEC DAI from registered DAIs from this CODEC*/ 1262 /* CODEC found, so find CODEC DAI from registered DAIs from this CODEC*/
1256 list_for_each_entry(codec_dai, &dai_list, list) { 1263 list_for_each_entry(codec_dai, &dai_list, list) {
1257 if (codec->dev == codec_dai->dev && 1264 if (codec->dev == codec_dai->dev &&
@@ -1277,10 +1284,6 @@ find_platform:
1277 /* no, then find CPU DAI from registered DAIs*/ 1284 /* no, then find CPU DAI from registered DAIs*/
1278 list_for_each_entry(platform, &platform_list, list) { 1285 list_for_each_entry(platform, &platform_list, list) {
1279 if (!strcmp(platform->name, dai_link->platform_name)) { 1286 if (!strcmp(platform->name, dai_link->platform_name)) {
1280
1281 if (!try_module_get(platform->dev->driver->owner))
1282 return -ENODEV;
1283
1284 rtd->platform = platform; 1287 rtd->platform = platform;
1285 goto out; 1288 goto out;
1286 } 1289 }
@@ -1299,6 +1302,27 @@ out:
1299 return 1; 1302 return 1;
1300} 1303}
1301 1304
1305static void soc_remove_codec(struct snd_soc_codec *codec)
1306{
1307 int err;
1308
1309 if (codec->driver->remove) {
1310 err = codec->driver->remove(codec);
1311 if (err < 0)
1312 dev_err(codec->dev,
1313 "asoc: failed to remove %s: %d\n",
1314 codec->name, err);
1315 }
1316
1317 /* Make sure all DAPM widgets are freed */
1318 snd_soc_dapm_free(&codec->dapm);
1319
1320 soc_cleanup_codec_debugfs(codec);
1321 codec->probed = 0;
1322 list_del(&codec->card_list);
1323 module_put(codec->dev->driver->owner);
1324}
1325
1302static void soc_remove_dai_link(struct snd_soc_card *card, int num) 1326static void soc_remove_dai_link(struct snd_soc_card *card, int num)
1303{ 1327{
1304 struct snd_soc_pcm_runtime *rtd = &card->rtd[num]; 1328 struct snd_soc_pcm_runtime *rtd = &card->rtd[num];
@@ -1310,6 +1334,7 @@ static void soc_remove_dai_link(struct snd_soc_card *card, int num)
1310 /* unregister the rtd device */ 1334 /* unregister the rtd device */
1311 if (rtd->dev_registered) { 1335 if (rtd->dev_registered) {
1312 device_remove_file(&rtd->dev, &dev_attr_pmdown_time); 1336 device_remove_file(&rtd->dev, &dev_attr_pmdown_time);
1337 device_remove_file(&rtd->dev, &dev_attr_codec_reg);
1313 device_unregister(&rtd->dev); 1338 device_unregister(&rtd->dev);
1314 rtd->dev_registered = 0; 1339 rtd->dev_registered = 0;
1315 } 1340 }
@@ -1338,22 +1363,8 @@ static void soc_remove_dai_link(struct snd_soc_card *card, int num)
1338 } 1363 }
1339 1364
1340 /* remove the CODEC */ 1365 /* remove the CODEC */
1341 if (codec && codec->probed) { 1366 if (codec && codec->probed)
1342 if (codec->driver->remove) { 1367 soc_remove_codec(codec);
1343 err = codec->driver->remove(codec);
1344 if (err < 0)
1345 printk(KERN_ERR "asoc: failed to remove %s\n", codec->name);
1346 }
1347
1348 /* Make sure all DAPM widgets are freed */
1349 snd_soc_dapm_free(codec);
1350
1351 soc_cleanup_codec_debugfs(codec);
1352 device_remove_file(&rtd->dev, &dev_attr_codec_reg);
1353 codec->probed = 0;
1354 list_del(&codec->card_list);
1355 module_put(codec->dev->driver->owner);
1356 }
1357 1368
1358 /* remove the cpu_dai */ 1369 /* remove the cpu_dai */
1359 if (cpu_dai && cpu_dai->probed) { 1370 if (cpu_dai && cpu_dai->probed) {
@@ -1368,8 +1379,126 @@ static void soc_remove_dai_link(struct snd_soc_card *card, int num)
1368 } 1379 }
1369} 1380}
1370 1381
1382static void soc_set_name_prefix(struct snd_soc_card *card,
1383 struct snd_soc_codec *codec)
1384{
1385 int i;
1386
1387 if (card->codec_conf == NULL)
1388 return;
1389
1390 for (i = 0; i < card->num_configs; i++) {
1391 struct snd_soc_codec_conf *map = &card->codec_conf[i];
1392 if (map->dev_name && !strcmp(codec->name, map->dev_name)) {
1393 codec->name_prefix = map->name_prefix;
1394 break;
1395 }
1396 }
1397}
1398
1399static int soc_probe_codec(struct snd_soc_card *card,
1400 struct snd_soc_codec *codec)
1401{
1402 int ret = 0;
1403
1404 codec->card = card;
1405 codec->dapm.card = card;
1406 soc_set_name_prefix(card, codec);
1407
1408 if (codec->driver->probe) {
1409 ret = codec->driver->probe(codec);
1410 if (ret < 0) {
1411 dev_err(codec->dev,
1412 "asoc: failed to probe CODEC %s: %d\n",
1413 codec->name, ret);
1414 return ret;
1415 }
1416 }
1417
1418 soc_init_codec_debugfs(codec);
1419
1420 /* mark codec as probed and add to card codec list */
1421 if (!try_module_get(codec->dev->driver->owner))
1422 return -ENODEV;
1423
1424 codec->probed = 1;
1425 list_add(&codec->card_list, &card->codec_dev_list);
1426 list_add(&codec->dapm.list, &card->dapm_list);
1427
1428 return ret;
1429}
1430
1371static void rtd_release(struct device *dev) {} 1431static void rtd_release(struct device *dev) {}
1372 1432
1433static int soc_post_component_init(struct snd_soc_card *card,
1434 struct snd_soc_codec *codec,
1435 int num, int dailess)
1436{
1437 struct snd_soc_dai_link *dai_link = NULL;
1438 struct snd_soc_aux_dev *aux_dev = NULL;
1439 struct snd_soc_pcm_runtime *rtd;
1440 const char *temp, *name;
1441 int ret = 0;
1442
1443 if (!dailess) {
1444 dai_link = &card->dai_link[num];
1445 rtd = &card->rtd[num];
1446 name = dai_link->name;
1447 } else {
1448 aux_dev = &card->aux_dev[num];
1449 rtd = &card->rtd_aux[num];
1450 name = aux_dev->name;
1451 }
1452
1453 /* machine controls, routes and widgets are not prefixed */
1454 temp = codec->name_prefix;
1455 codec->name_prefix = NULL;
1456
1457 /* do machine specific initialization */
1458 if (!dailess && dai_link->init)
1459 ret = dai_link->init(rtd);
1460 else if (dailess && aux_dev->init)
1461 ret = aux_dev->init(&codec->dapm);
1462 if (ret < 0) {
1463 dev_err(card->dev, "asoc: failed to init %s: %d\n", name, ret);
1464 return ret;
1465 }
1466 codec->name_prefix = temp;
1467
1468 /* Make sure all DAPM widgets are instantiated */
1469 snd_soc_dapm_new_widgets(&codec->dapm);
1470 snd_soc_dapm_sync(&codec->dapm);
1471
1472 /* register the rtd device */
1473 rtd->codec = codec;
1474 rtd->card = card;
1475 rtd->dev.parent = card->dev;
1476 rtd->dev.release = rtd_release;
1477 rtd->dev.init_name = name;
1478 ret = device_register(&rtd->dev);
1479 if (ret < 0) {
1480 dev_err(card->dev,
1481 "asoc: failed to register runtime device: %d\n", ret);
1482 return ret;
1483 }
1484 rtd->dev_registered = 1;
1485
1486 /* add DAPM sysfs entries for this codec */
1487 ret = snd_soc_dapm_sys_add(&rtd->dev);
1488 if (ret < 0)
1489 dev_err(codec->dev,
1490 "asoc: failed to add codec dapm sysfs entries: %d\n",
1491 ret);
1492
1493 /* add codec sysfs entries */
1494 ret = device_create_file(&rtd->dev, &dev_attr_codec_reg);
1495 if (ret < 0)
1496 dev_err(codec->dev,
1497 "asoc: failed to add codec sysfs files: %d\n", ret);
1498
1499 return 0;
1500}
1501
1373static int soc_probe_dai_link(struct snd_soc_card *card, int num) 1502static int soc_probe_dai_link(struct snd_soc_card *card, int num)
1374{ 1503{
1375 struct snd_soc_dai_link *dai_link = &card->dai_link[num]; 1504 struct snd_soc_dai_link *dai_link = &card->dai_link[num];
@@ -1383,10 +1512,7 @@ static int soc_probe_dai_link(struct snd_soc_card *card, int num)
1383 1512
1384 /* config components */ 1513 /* config components */
1385 codec_dai->codec = codec; 1514 codec_dai->codec = codec;
1386 codec->card = card;
1387 cpu_dai->platform = platform; 1515 cpu_dai->platform = platform;
1388 rtd->card = card;
1389 rtd->dev.parent = card->dev;
1390 codec_dai->card = card; 1516 codec_dai->card = card;
1391 cpu_dai->card = card; 1517 cpu_dai->card = card;
1392 1518
@@ -1410,20 +1536,9 @@ static int soc_probe_dai_link(struct snd_soc_card *card, int num)
1410 1536
1411 /* probe the CODEC */ 1537 /* probe the CODEC */
1412 if (!codec->probed) { 1538 if (!codec->probed) {
1413 if (codec->driver->probe) { 1539 ret = soc_probe_codec(card, codec);
1414 ret = codec->driver->probe(codec); 1540 if (ret < 0)
1415 if (ret < 0) { 1541 return ret;
1416 printk(KERN_ERR "asoc: failed to probe CODEC %s\n",
1417 codec->name);
1418 return ret;
1419 }
1420 }
1421
1422 soc_init_codec_debugfs(codec);
1423
1424 /* mark codec as probed and add to card codec list */
1425 codec->probed = 1;
1426 list_add(&codec->card_list, &card->codec_dev_list);
1427 } 1542 }
1428 1543
1429 /* probe the platform */ 1544 /* probe the platform */
@@ -1437,6 +1552,10 @@ static int soc_probe_dai_link(struct snd_soc_card *card, int num)
1437 } 1552 }
1438 } 1553 }
1439 /* mark platform as probed and add to card platform list */ 1554 /* mark platform as probed and add to card platform list */
1555
1556 if (!try_module_get(platform->dev->driver->owner))
1557 return -ENODEV;
1558
1440 platform->probed = 1; 1559 platform->probed = 1;
1441 list_add(&platform->card_list, &card->platform_dev_list); 1560 list_add(&platform->card_list, &card->platform_dev_list);
1442 } 1561 }
@@ -1460,43 +1579,14 @@ static int soc_probe_dai_link(struct snd_soc_card *card, int num)
1460 /* DAPM dai link stream work */ 1579 /* DAPM dai link stream work */
1461 INIT_DELAYED_WORK(&rtd->delayed_work, close_delayed_work); 1580 INIT_DELAYED_WORK(&rtd->delayed_work, close_delayed_work);
1462 1581
1463 /* now that all clients have probed, initialise the DAI link */ 1582 ret = soc_post_component_init(card, codec, num, 0);
1464 if (dai_link->init) { 1583 if (ret)
1465 ret = dai_link->init(rtd);
1466 if (ret < 0) {
1467 printk(KERN_ERR "asoc: failed to init %s\n", dai_link->stream_name);
1468 return ret;
1469 }
1470 }
1471
1472 /* Make sure all DAPM widgets are instantiated */
1473 snd_soc_dapm_new_widgets(codec);
1474 snd_soc_dapm_sync(codec);
1475
1476 /* register the rtd device */
1477 rtd->dev.release = rtd_release;
1478 rtd->dev.init_name = dai_link->name;
1479 ret = device_register(&rtd->dev);
1480 if (ret < 0) {
1481 printk(KERN_ERR "asoc: failed to register DAI runtime device %d\n", ret);
1482 return ret; 1584 return ret;
1483 }
1484 1585
1485 rtd->dev_registered = 1;
1486 ret = device_create_file(&rtd->dev, &dev_attr_pmdown_time); 1586 ret = device_create_file(&rtd->dev, &dev_attr_pmdown_time);
1487 if (ret < 0) 1587 if (ret < 0)
1488 printk(KERN_WARNING "asoc: failed to add pmdown_time sysfs\n"); 1588 printk(KERN_WARNING "asoc: failed to add pmdown_time sysfs\n");
1489 1589
1490 /* add DAPM sysfs entries for this codec */
1491 ret = snd_soc_dapm_sys_add(&rtd->dev);
1492 if (ret < 0)
1493 printk(KERN_WARNING "asoc: failed to add codec dapm sysfs entries\n");
1494
1495 /* add codec sysfs entries */
1496 ret = device_create_file(&rtd->dev, &dev_attr_codec_reg);
1497 if (ret < 0)
1498 printk(KERN_WARNING "asoc: failed to add codec sysfs files\n");
1499
1500 /* create the pcm */ 1590 /* create the pcm */
1501 ret = soc_new_pcm(rtd, num); 1591 ret = soc_new_pcm(rtd, num);
1502 if (ret < 0) { 1592 if (ret < 0) {
@@ -1551,9 +1641,85 @@ static void soc_unregister_ac97_dai_link(struct snd_soc_codec *codec)
1551} 1641}
1552#endif 1642#endif
1553 1643
1644static int soc_probe_aux_dev(struct snd_soc_card *card, int num)
1645{
1646 struct snd_soc_aux_dev *aux_dev = &card->aux_dev[num];
1647 struct snd_soc_codec *codec;
1648 int ret = -ENODEV;
1649
1650 /* find CODEC from registered CODECs*/
1651 list_for_each_entry(codec, &codec_list, list) {
1652 if (!strcmp(codec->name, aux_dev->codec_name)) {
1653 if (codec->probed) {
1654 dev_err(codec->dev,
1655 "asoc: codec already probed");
1656 ret = -EBUSY;
1657 goto out;
1658 }
1659 goto found;
1660 }
1661 }
1662 /* codec not found */
1663 dev_err(card->dev, "asoc: codec %s not found", aux_dev->codec_name);
1664 goto out;
1665
1666found:
1667 if (!try_module_get(codec->dev->driver->owner))
1668 return -ENODEV;
1669
1670 ret = soc_probe_codec(card, codec);
1671 if (ret < 0)
1672 return ret;
1673
1674 ret = soc_post_component_init(card, codec, num, 1);
1675
1676out:
1677 return ret;
1678}
1679
1680static void soc_remove_aux_dev(struct snd_soc_card *card, int num)
1681{
1682 struct snd_soc_pcm_runtime *rtd = &card->rtd_aux[num];
1683 struct snd_soc_codec *codec = rtd->codec;
1684
1685 /* unregister the rtd device */
1686 if (rtd->dev_registered) {
1687 device_remove_file(&rtd->dev, &dev_attr_codec_reg);
1688 device_unregister(&rtd->dev);
1689 rtd->dev_registered = 0;
1690 }
1691
1692 if (codec && codec->probed)
1693 soc_remove_codec(codec);
1694}
1695
1696static int snd_soc_init_codec_cache(struct snd_soc_codec *codec,
1697 enum snd_soc_compress_type compress_type)
1698{
1699 int ret;
1700
1701 if (codec->cache_init)
1702 return 0;
1703
1704 /* override the compress_type if necessary */
1705 if (compress_type && codec->compress_type != compress_type)
1706 codec->compress_type = compress_type;
1707 ret = snd_soc_cache_init(codec);
1708 if (ret < 0) {
1709 dev_err(codec->dev, "Failed to set cache compression type: %d\n",
1710 ret);
1711 return ret;
1712 }
1713 codec->cache_init = 1;
1714 return 0;
1715}
1716
1554static void snd_soc_instantiate_card(struct snd_soc_card *card) 1717static void snd_soc_instantiate_card(struct snd_soc_card *card)
1555{ 1718{
1556 struct platform_device *pdev = to_platform_device(card->dev); 1719 struct platform_device *pdev = to_platform_device(card->dev);
1720 struct snd_soc_codec *codec;
1721 struct snd_soc_codec_conf *codec_conf;
1722 enum snd_soc_compress_type compress_type;
1557 int ret, i; 1723 int ret, i;
1558 1724
1559 mutex_lock(&card->mutex); 1725 mutex_lock(&card->mutex);
@@ -1573,6 +1739,39 @@ static void snd_soc_instantiate_card(struct snd_soc_card *card)
1573 return; 1739 return;
1574 } 1740 }
1575 1741
1742 /* initialize the register cache for each available codec */
1743 list_for_each_entry(codec, &codec_list, list) {
1744 if (codec->cache_init)
1745 continue;
1746 /* check to see if we need to override the compress_type */
1747 for (i = 0; i < card->num_configs; ++i) {
1748 codec_conf = &card->codec_conf[i];
1749 if (!strcmp(codec->name, codec_conf->dev_name)) {
1750 compress_type = codec_conf->compress_type;
1751 if (compress_type && compress_type
1752 != codec->compress_type)
1753 break;
1754 }
1755 }
1756 if (i == card->num_configs) {
1757 /* no need to override the compress_type so
1758 * go ahead and do the standard thing */
1759 ret = snd_soc_init_codec_cache(codec, 0);
1760 if (ret < 0) {
1761 mutex_unlock(&card->mutex);
1762 return;
1763 }
1764 continue;
1765 }
1766 /* override the compress_type with the one supplied in
1767 * the machine driver */
1768 ret = snd_soc_init_codec_cache(codec, compress_type);
1769 if (ret < 0) {
1770 mutex_unlock(&card->mutex);
1771 return;
1772 }
1773 }
1774
1576 /* card bind complete so register a sound card */ 1775 /* card bind complete so register a sound card */
1577 ret = snd_card_create(SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1, 1776 ret = snd_card_create(SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1,
1578 card->owner, 0, &card->snd_card); 1777 card->owner, 0, &card->snd_card);
@@ -1605,6 +1804,15 @@ static void snd_soc_instantiate_card(struct snd_soc_card *card)
1605 } 1804 }
1606 } 1805 }
1607 1806
1807 for (i = 0; i < card->num_aux_devs; i++) {
1808 ret = soc_probe_aux_dev(card, i);
1809 if (ret < 0) {
1810 pr_err("asoc: failed to add auxiliary devices %s: %d\n",
1811 card->name, ret);
1812 goto probe_aux_dev_err;
1813 }
1814 }
1815
1608 snprintf(card->snd_card->shortname, sizeof(card->snd_card->shortname), 1816 snprintf(card->snd_card->shortname, sizeof(card->snd_card->shortname),
1609 "%s", card->name); 1817 "%s", card->name);
1610 snprintf(card->snd_card->longname, sizeof(card->snd_card->longname), 1818 snprintf(card->snd_card->longname, sizeof(card->snd_card->longname),
@@ -1613,7 +1821,7 @@ static void snd_soc_instantiate_card(struct snd_soc_card *card)
1613 ret = snd_card_register(card->snd_card); 1821 ret = snd_card_register(card->snd_card);
1614 if (ret < 0) { 1822 if (ret < 0) {
1615 printk(KERN_ERR "asoc: failed to register soundcard for %s\n", card->name); 1823 printk(KERN_ERR "asoc: failed to register soundcard for %s\n", card->name);
1616 goto probe_dai_err; 1824 goto probe_aux_dev_err;
1617 } 1825 }
1618 1826
1619#ifdef CONFIG_SND_SOC_AC97_BUS 1827#ifdef CONFIG_SND_SOC_AC97_BUS
@@ -1623,8 +1831,8 @@ static void snd_soc_instantiate_card(struct snd_soc_card *card)
1623 if (ret < 0) { 1831 if (ret < 0) {
1624 printk(KERN_ERR "asoc: failed to register AC97 %s\n", card->name); 1832 printk(KERN_ERR "asoc: failed to register AC97 %s\n", card->name);
1625 while (--i >= 0) 1833 while (--i >= 0)
1626 soc_unregister_ac97_dai_link(&card->rtd[i]); 1834 soc_unregister_ac97_dai_link(card->rtd[i].codec);
1627 goto probe_dai_err; 1835 goto probe_aux_dev_err;
1628 } 1836 }
1629 } 1837 }
1630#endif 1838#endif
@@ -1633,6 +1841,10 @@ static void snd_soc_instantiate_card(struct snd_soc_card *card)
1633 mutex_unlock(&card->mutex); 1841 mutex_unlock(&card->mutex);
1634 return; 1842 return;
1635 1843
1844probe_aux_dev_err:
1845 for (i = 0; i < card->num_aux_devs; i++)
1846 soc_remove_aux_dev(card, i);
1847
1636probe_dai_err: 1848probe_dai_err:
1637 for (i = 0; i < card->num_links; i++) 1849 for (i = 0; i < card->num_links; i++)
1638 soc_remove_dai_link(card, i); 1850 soc_remove_dai_link(card, i);
@@ -1668,6 +1880,11 @@ static int soc_probe(struct platform_device *pdev)
1668 INIT_LIST_HEAD(&card->dai_dev_list); 1880 INIT_LIST_HEAD(&card->dai_dev_list);
1669 INIT_LIST_HEAD(&card->codec_dev_list); 1881 INIT_LIST_HEAD(&card->codec_dev_list);
1670 INIT_LIST_HEAD(&card->platform_dev_list); 1882 INIT_LIST_HEAD(&card->platform_dev_list);
1883 INIT_LIST_HEAD(&card->widgets);
1884 INIT_LIST_HEAD(&card->paths);
1885 INIT_LIST_HEAD(&card->dapm_list);
1886
1887 soc_init_card_debugfs(card);
1671 1888
1672 ret = snd_soc_register_card(card); 1889 ret = snd_soc_register_card(card);
1673 if (ret != 0) { 1890 if (ret != 0) {
@@ -1689,13 +1906,19 @@ static int soc_remove(struct platform_device *pdev)
1689 /* make sure any delayed work runs */ 1906 /* make sure any delayed work runs */
1690 for (i = 0; i < card->num_rtd; i++) { 1907 for (i = 0; i < card->num_rtd; i++) {
1691 struct snd_soc_pcm_runtime *rtd = &card->rtd[i]; 1908 struct snd_soc_pcm_runtime *rtd = &card->rtd[i];
1692 run_delayed_work(&rtd->delayed_work); 1909 flush_delayed_work_sync(&rtd->delayed_work);
1693 } 1910 }
1694 1911
1912 /* remove auxiliary devices */
1913 for (i = 0; i < card->num_aux_devs; i++)
1914 soc_remove_aux_dev(card, i);
1915
1695 /* remove and free each DAI */ 1916 /* remove and free each DAI */
1696 for (i = 0; i < card->num_rtd; i++) 1917 for (i = 0; i < card->num_rtd; i++)
1697 soc_remove_dai_link(card, i); 1918 soc_remove_dai_link(card, i);
1698 1919
1920 soc_cleanup_card_debugfs(card);
1921
1699 /* remove the card */ 1922 /* remove the card */
1700 if (card->remove) 1923 if (card->remove)
1701 card->remove(pdev); 1924 card->remove(pdev);
@@ -1720,7 +1943,7 @@ static int soc_poweroff(struct device *dev)
1720 * now, we're shutting down so no imminent restart. */ 1943 * now, we're shutting down so no imminent restart. */
1721 for (i = 0; i < card->num_rtd; i++) { 1944 for (i = 0; i < card->num_rtd; i++) {
1722 struct snd_soc_pcm_runtime *rtd = &card->rtd[i]; 1945 struct snd_soc_pcm_runtime *rtd = &card->rtd[i];
1723 run_delayed_work(&rtd->delayed_work); 1946 flush_delayed_work_sync(&rtd->delayed_work);
1724 } 1947 }
1725 1948
1726 snd_soc_dapm_shutdown(card); 1949 snd_soc_dapm_shutdown(card);
@@ -1879,6 +2102,27 @@ void snd_soc_free_ac97_codec(struct snd_soc_codec *codec)
1879} 2102}
1880EXPORT_SYMBOL_GPL(snd_soc_free_ac97_codec); 2103EXPORT_SYMBOL_GPL(snd_soc_free_ac97_codec);
1881 2104
2105unsigned int snd_soc_read(struct snd_soc_codec *codec, unsigned int reg)
2106{
2107 unsigned int ret;
2108
2109 ret = codec->read(codec, reg);
2110 dev_dbg(codec->dev, "read %x => %x\n", reg, ret);
2111 trace_snd_soc_reg_read(codec, reg, ret);
2112
2113 return ret;
2114}
2115EXPORT_SYMBOL_GPL(snd_soc_read);
2116
2117unsigned int snd_soc_write(struct snd_soc_codec *codec,
2118 unsigned int reg, unsigned int val)
2119{
2120 dev_dbg(codec->dev, "write %x = %x\n", reg, val);
2121 trace_snd_soc_reg_write(codec, reg, val);
2122 return codec->write(codec, reg, val);
2123}
2124EXPORT_SYMBOL_GPL(snd_soc_write);
2125
1882/** 2126/**
1883 * snd_soc_update_bits - update codec register bits 2127 * snd_soc_update_bits - update codec register bits
1884 * @codec: audio codec 2128 * @codec: audio codec
@@ -2019,14 +2263,22 @@ int snd_soc_add_controls(struct snd_soc_codec *codec,
2019 const struct snd_kcontrol_new *controls, int num_controls) 2263 const struct snd_kcontrol_new *controls, int num_controls)
2020{ 2264{
2021 struct snd_card *card = codec->card->snd_card; 2265 struct snd_card *card = codec->card->snd_card;
2266 char prefixed_name[44], *name;
2022 int err, i; 2267 int err, i;
2023 2268
2024 for (i = 0; i < num_controls; i++) { 2269 for (i = 0; i < num_controls; i++) {
2025 const struct snd_kcontrol_new *control = &controls[i]; 2270 const struct snd_kcontrol_new *control = &controls[i];
2026 err = snd_ctl_add(card, snd_soc_cnew(control, codec, NULL)); 2271 if (codec->name_prefix) {
2272 snprintf(prefixed_name, sizeof(prefixed_name), "%s %s",
2273 codec->name_prefix, control->name);
2274 name = prefixed_name;
2275 } else {
2276 name = control->name;
2277 }
2278 err = snd_ctl_add(card, snd_soc_cnew(control, codec, name));
2027 if (err < 0) { 2279 if (err < 0) {
2028 dev_err(codec->dev, "%s: Failed to add %s: %d\n", 2280 dev_err(codec->dev, "%s: Failed to add %s: %d\n",
2029 codec->name, control->name, err); 2281 codec->name, name, err);
2030 return err; 2282 return err;
2031 } 2283 }
2032 } 2284 }
@@ -2863,10 +3115,12 @@ static int snd_soc_register_card(struct snd_soc_card *card)
2863 if (!card->name || !card->dev) 3115 if (!card->name || !card->dev)
2864 return -EINVAL; 3116 return -EINVAL;
2865 3117
2866 card->rtd = kzalloc(sizeof(struct snd_soc_pcm_runtime) * card->num_links, 3118 card->rtd = kzalloc(sizeof(struct snd_soc_pcm_runtime) *
2867 GFP_KERNEL); 3119 (card->num_links + card->num_aux_devs),
3120 GFP_KERNEL);
2868 if (card->rtd == NULL) 3121 if (card->rtd == NULL)
2869 return -ENOMEM; 3122 return -ENOMEM;
3123 card->rtd_aux = &card->rtd[card->num_links];
2870 3124
2871 for (i = 0; i < card->num_links; i++) 3125 for (i = 0; i < card->num_links; i++)
2872 card->rtd[i].dai_link = &card->dai_link[i]; 3126 card->rtd[i].dai_link = &card->dai_link[i];
@@ -2908,7 +3162,7 @@ static int snd_soc_unregister_card(struct snd_soc_card *card)
2908 * Simplify DAI link configuration by removing ".-1" from device names 3162 * Simplify DAI link configuration by removing ".-1" from device names
2909 * and sanitizing names. 3163 * and sanitizing names.
2910 */ 3164 */
2911static inline char *fmt_single_name(struct device *dev, int *id) 3165static char *fmt_single_name(struct device *dev, int *id)
2912{ 3166{
2913 char *found, name[NAME_SIZE]; 3167 char *found, name[NAME_SIZE];
2914 int id1, id2; 3168 int id1, id2;
@@ -2916,7 +3170,7 @@ static inline char *fmt_single_name(struct device *dev, int *id)
2916 if (dev_name(dev) == NULL) 3170 if (dev_name(dev) == NULL)
2917 return NULL; 3171 return NULL;
2918 3172
2919 strncpy(name, dev_name(dev), NAME_SIZE); 3173 strlcpy(name, dev_name(dev), NAME_SIZE);
2920 3174
2921 /* are we a "%s.%d" name (platform and SPI components) */ 3175 /* are we a "%s.%d" name (platform and SPI components) */
2922 found = strstr(name, dev->driver->name); 3176 found = strstr(name, dev->driver->name);
@@ -2939,7 +3193,7 @@ static inline char *fmt_single_name(struct device *dev, int *id)
2939 3193
2940 /* sanitize component name for DAI link creation */ 3194 /* sanitize component name for DAI link creation */
2941 snprintf(tmp, NAME_SIZE, "%s.%s", dev->driver->name, name); 3195 snprintf(tmp, NAME_SIZE, "%s.%s", dev->driver->name, name);
2942 strncpy(name, tmp, NAME_SIZE); 3196 strlcpy(name, tmp, NAME_SIZE);
2943 } else 3197 } else
2944 *id = 0; 3198 *id = 0;
2945 } 3199 }
@@ -3204,9 +3458,11 @@ static void fixup_codec_formats(struct snd_soc_pcm_stream *stream)
3204 * @codec: codec to register 3458 * @codec: codec to register
3205 */ 3459 */
3206int snd_soc_register_codec(struct device *dev, 3460int snd_soc_register_codec(struct device *dev,
3207 struct snd_soc_codec_driver *codec_drv, 3461 const struct snd_soc_codec_driver *codec_drv,
3208 struct snd_soc_dai_driver *dai_drv, int num_dai) 3462 struct snd_soc_dai_driver *dai_drv,
3463 int num_dai)
3209{ 3464{
3465 size_t reg_size;
3210 struct snd_soc_codec *codec; 3466 struct snd_soc_codec *codec;
3211 int ret, i; 3467 int ret, i;
3212 3468
@@ -3223,30 +3479,37 @@ int snd_soc_register_codec(struct device *dev,
3223 return -ENOMEM; 3479 return -ENOMEM;
3224 } 3480 }
3225 3481
3226 /* allocate CODEC register cache */ 3482 if (codec_drv->compress_type)
3227 if (codec_drv->reg_cache_size && codec_drv->reg_word_size) { 3483 codec->compress_type = codec_drv->compress_type;
3228 3484 else
3229 if (codec_drv->reg_cache_default) 3485 codec->compress_type = SND_SOC_FLAT_COMPRESSION;
3230 codec->reg_cache = kmemdup(codec_drv->reg_cache_default,
3231 codec_drv->reg_cache_size * codec_drv->reg_word_size, GFP_KERNEL);
3232 else
3233 codec->reg_cache = kzalloc(codec_drv->reg_cache_size *
3234 codec_drv->reg_word_size, GFP_KERNEL);
3235
3236 if (codec->reg_cache == NULL) {
3237 kfree(codec->name);
3238 kfree(codec);
3239 return -ENOMEM;
3240 }
3241 }
3242 3486
3487 codec->write = codec_drv->write;
3488 codec->read = codec_drv->read;
3489 codec->dapm.bias_level = SND_SOC_BIAS_OFF;
3490 codec->dapm.dev = dev;
3491 codec->dapm.codec = codec;
3243 codec->dev = dev; 3492 codec->dev = dev;
3244 codec->driver = codec_drv; 3493 codec->driver = codec_drv;
3245 codec->bias_level = SND_SOC_BIAS_OFF;
3246 codec->num_dai = num_dai; 3494 codec->num_dai = num_dai;
3247 mutex_init(&codec->mutex); 3495 mutex_init(&codec->mutex);
3248 INIT_LIST_HEAD(&codec->dapm_widgets); 3496
3249 INIT_LIST_HEAD(&codec->dapm_paths); 3497 /* allocate CODEC register cache */
3498 if (codec_drv->reg_cache_size && codec_drv->reg_word_size) {
3499 reg_size = codec_drv->reg_cache_size * codec_drv->reg_word_size;
3500 /* it is necessary to make a copy of the default register cache
3501 * because in the case of using a compression type that requires
3502 * the default register cache to be marked as __devinitconst the
3503 * kernel might have freed the array by the time we initialize
3504 * the cache.
3505 */
3506 codec->reg_def_copy = kmemdup(codec_drv->reg_cache_default,
3507 reg_size, GFP_KERNEL);
3508 if (!codec->reg_def_copy) {
3509 ret = -ENOMEM;
3510 goto fail;
3511 }
3512 }
3250 3513
3251 for (i = 0; i < num_dai; i++) { 3514 for (i = 0; i < num_dai; i++) {
3252 fixup_codec_formats(&dai_drv[i].playback); 3515 fixup_codec_formats(&dai_drv[i].playback);
@@ -3257,7 +3520,7 @@ int snd_soc_register_codec(struct device *dev,
3257 if (num_dai) { 3520 if (num_dai) {
3258 ret = snd_soc_register_dais(dev, dai_drv, num_dai); 3521 ret = snd_soc_register_dais(dev, dai_drv, num_dai);
3259 if (ret < 0) 3522 if (ret < 0)
3260 goto error; 3523 goto fail;
3261 } 3524 }
3262 3525
3263 mutex_lock(&client_mutex); 3526 mutex_lock(&client_mutex);
@@ -3268,9 +3531,9 @@ int snd_soc_register_codec(struct device *dev,
3268 pr_debug("Registered codec '%s'\n", codec->name); 3531 pr_debug("Registered codec '%s'\n", codec->name);
3269 return 0; 3532 return 0;
3270 3533
3271error: 3534fail:
3272 if (codec->reg_cache) 3535 kfree(codec->reg_def_copy);
3273 kfree(codec->reg_cache); 3536 codec->reg_def_copy = NULL;
3274 kfree(codec->name); 3537 kfree(codec->name);
3275 kfree(codec); 3538 kfree(codec);
3276 return ret; 3539 return ret;
@@ -3304,8 +3567,8 @@ found:
3304 3567
3305 pr_debug("Unregistered codec '%s'\n", codec->name); 3568 pr_debug("Unregistered codec '%s'\n", codec->name);
3306 3569
3307 if (codec->reg_cache) 3570 snd_soc_cache_exit(codec);
3308 kfree(codec->reg_cache); 3571 kfree(codec->reg_def_copy);
3309 kfree(codec->name); 3572 kfree(codec->name);
3310 kfree(codec); 3573 kfree(codec);
3311} 3574}
diff --git a/sound/soc/soc-dapm.c b/sound/soc/soc-dapm.c
index c721502833bc..499730ab5638 100644
--- a/sound/soc/soc-dapm.c
+++ b/sound/soc/soc-dapm.c
@@ -42,9 +42,11 @@
42#include <sound/core.h> 42#include <sound/core.h>
43#include <sound/pcm.h> 43#include <sound/pcm.h>
44#include <sound/pcm_params.h> 44#include <sound/pcm_params.h>
45#include <sound/soc-dapm.h> 45#include <sound/soc.h>
46#include <sound/initval.h> 46#include <sound/initval.h>
47 47
48#include <trace/events/asoc.h>
49
48/* dapm power sequences - make this per codec in the future */ 50/* dapm power sequences - make this per codec in the future */
49static int dapm_up_seq[] = { 51static int dapm_up_seq[] = {
50 [snd_soc_dapm_pre] = 0, 52 [snd_soc_dapm_pre] = 0,
@@ -54,12 +56,14 @@ static int dapm_up_seq[] = {
54 [snd_soc_dapm_aif_out] = 3, 56 [snd_soc_dapm_aif_out] = 3,
55 [snd_soc_dapm_mic] = 4, 57 [snd_soc_dapm_mic] = 4,
56 [snd_soc_dapm_mux] = 5, 58 [snd_soc_dapm_mux] = 5,
59 [snd_soc_dapm_virt_mux] = 5,
57 [snd_soc_dapm_value_mux] = 5, 60 [snd_soc_dapm_value_mux] = 5,
58 [snd_soc_dapm_dac] = 6, 61 [snd_soc_dapm_dac] = 6,
59 [snd_soc_dapm_mixer] = 7, 62 [snd_soc_dapm_mixer] = 7,
60 [snd_soc_dapm_mixer_named_ctl] = 7, 63 [snd_soc_dapm_mixer_named_ctl] = 7,
61 [snd_soc_dapm_pga] = 8, 64 [snd_soc_dapm_pga] = 8,
62 [snd_soc_dapm_adc] = 9, 65 [snd_soc_dapm_adc] = 9,
66 [snd_soc_dapm_out_drv] = 10,
63 [snd_soc_dapm_hp] = 10, 67 [snd_soc_dapm_hp] = 10,
64 [snd_soc_dapm_spk] = 10, 68 [snd_soc_dapm_spk] = 10,
65 [snd_soc_dapm_post] = 11, 69 [snd_soc_dapm_post] = 11,
@@ -70,6 +74,7 @@ static int dapm_down_seq[] = {
70 [snd_soc_dapm_adc] = 1, 74 [snd_soc_dapm_adc] = 1,
71 [snd_soc_dapm_hp] = 2, 75 [snd_soc_dapm_hp] = 2,
72 [snd_soc_dapm_spk] = 2, 76 [snd_soc_dapm_spk] = 2,
77 [snd_soc_dapm_out_drv] = 2,
73 [snd_soc_dapm_pga] = 4, 78 [snd_soc_dapm_pga] = 4,
74 [snd_soc_dapm_mixer_named_ctl] = 5, 79 [snd_soc_dapm_mixer_named_ctl] = 5,
75 [snd_soc_dapm_mixer] = 5, 80 [snd_soc_dapm_mixer] = 5,
@@ -77,6 +82,7 @@ static int dapm_down_seq[] = {
77 [snd_soc_dapm_mic] = 7, 82 [snd_soc_dapm_mic] = 7,
78 [snd_soc_dapm_micbias] = 8, 83 [snd_soc_dapm_micbias] = 8,
79 [snd_soc_dapm_mux] = 9, 84 [snd_soc_dapm_mux] = 9,
85 [snd_soc_dapm_virt_mux] = 9,
80 [snd_soc_dapm_value_mux] = 9, 86 [snd_soc_dapm_value_mux] = 9,
81 [snd_soc_dapm_aif_in] = 10, 87 [snd_soc_dapm_aif_in] = 10,
82 [snd_soc_dapm_aif_out] = 10, 88 [snd_soc_dapm_aif_out] = 10,
@@ -90,17 +96,24 @@ static void pop_wait(u32 pop_time)
90 schedule_timeout_uninterruptible(msecs_to_jiffies(pop_time)); 96 schedule_timeout_uninterruptible(msecs_to_jiffies(pop_time));
91} 97}
92 98
93static void pop_dbg(u32 pop_time, const char *fmt, ...) 99static void pop_dbg(struct device *dev, u32 pop_time, const char *fmt, ...)
94{ 100{
95 va_list args; 101 va_list args;
102 char *buf;
96 103
97 va_start(args, fmt); 104 if (!pop_time)
105 return;
98 106
99 if (pop_time) { 107 buf = kmalloc(PAGE_SIZE, GFP_KERNEL);
100 vprintk(fmt, args); 108 if (buf == NULL)
101 } 109 return;
102 110
111 va_start(args, fmt);
112 vsnprintf(buf, PAGE_SIZE, fmt, args);
113 dev_info(dev, "%s", buf);
103 va_end(args); 114 va_end(args);
115
116 kfree(buf);
104} 117}
105 118
106/* create a new dapm widget */ 119/* create a new dapm widget */
@@ -120,36 +133,45 @@ static inline struct snd_soc_dapm_widget *dapm_cnew_widget(
120 * Returns 0 for success else error. 133 * Returns 0 for success else error.
121 */ 134 */
122static int snd_soc_dapm_set_bias_level(struct snd_soc_card *card, 135static int snd_soc_dapm_set_bias_level(struct snd_soc_card *card,
123 struct snd_soc_codec *codec, enum snd_soc_bias_level level) 136 struct snd_soc_dapm_context *dapm,
137 enum snd_soc_bias_level level)
124{ 138{
125 int ret = 0; 139 int ret = 0;
126 140
127 switch (level) { 141 switch (level) {
128 case SND_SOC_BIAS_ON: 142 case SND_SOC_BIAS_ON:
129 dev_dbg(codec->dev, "Setting full bias\n"); 143 dev_dbg(dapm->dev, "Setting full bias\n");
130 break; 144 break;
131 case SND_SOC_BIAS_PREPARE: 145 case SND_SOC_BIAS_PREPARE:
132 dev_dbg(codec->dev, "Setting bias prepare\n"); 146 dev_dbg(dapm->dev, "Setting bias prepare\n");
133 break; 147 break;
134 case SND_SOC_BIAS_STANDBY: 148 case SND_SOC_BIAS_STANDBY:
135 dev_dbg(codec->dev, "Setting standby bias\n"); 149 dev_dbg(dapm->dev, "Setting standby bias\n");
136 break; 150 break;
137 case SND_SOC_BIAS_OFF: 151 case SND_SOC_BIAS_OFF:
138 dev_dbg(codec->dev, "Setting bias off\n"); 152 dev_dbg(dapm->dev, "Setting bias off\n");
139 break; 153 break;
140 default: 154 default:
141 dev_err(codec->dev, "Setting invalid bias %d\n", level); 155 dev_err(dapm->dev, "Setting invalid bias %d\n", level);
142 return -EINVAL; 156 return -EINVAL;
143 } 157 }
144 158
159 trace_snd_soc_bias_level_start(card, level);
160
145 if (card && card->set_bias_level) 161 if (card && card->set_bias_level)
146 ret = card->set_bias_level(card, level); 162 ret = card->set_bias_level(card, level);
147 if (ret == 0) { 163 if (ret == 0) {
148 if (codec->driver->set_bias_level) 164 if (dapm->codec && dapm->codec->driver->set_bias_level)
149 ret = codec->driver->set_bias_level(codec, level); 165 ret = dapm->codec->driver->set_bias_level(dapm->codec, level);
150 else 166 else
151 codec->bias_level = level; 167 dapm->bias_level = level;
152 } 168 }
169 if (ret == 0) {
170 if (card && card->set_bias_level_post)
171 ret = card->set_bias_level_post(card, level);
172 }
173
174 trace_snd_soc_bias_level_done(card, level);
153 175
154 return ret; 176 return ret;
155} 177}
@@ -196,6 +218,20 @@ static void dapm_set_path_status(struct snd_soc_dapm_widget *w,
196 } 218 }
197 } 219 }
198 break; 220 break;
221 case snd_soc_dapm_virt_mux: {
222 struct soc_enum *e = (struct soc_enum *)w->kcontrols[i].private_value;
223
224 p->connect = 0;
225 /* since a virtual mux has no backing registers to
226 * decide which path to connect, it will try to match
227 * with the first enumeration. This is to ensure
228 * that the default mux choice (the first) will be
229 * correctly powered up during initialization.
230 */
231 if (!strcmp(p->name, e->texts[0]))
232 p->connect = 1;
233 }
234 break;
199 case snd_soc_dapm_value_mux: { 235 case snd_soc_dapm_value_mux: {
200 struct soc_enum *e = (struct soc_enum *) 236 struct soc_enum *e = (struct soc_enum *)
201 w->kcontrols[i].private_value; 237 w->kcontrols[i].private_value;
@@ -217,6 +253,7 @@ static void dapm_set_path_status(struct snd_soc_dapm_widget *w,
217 break; 253 break;
218 /* does not effect routing - always connected */ 254 /* does not effect routing - always connected */
219 case snd_soc_dapm_pga: 255 case snd_soc_dapm_pga:
256 case snd_soc_dapm_out_drv:
220 case snd_soc_dapm_output: 257 case snd_soc_dapm_output:
221 case snd_soc_dapm_adc: 258 case snd_soc_dapm_adc:
222 case snd_soc_dapm_input: 259 case snd_soc_dapm_input:
@@ -241,7 +278,7 @@ static void dapm_set_path_status(struct snd_soc_dapm_widget *w,
241} 278}
242 279
243/* connect mux widget to its interconnecting audio paths */ 280/* connect mux widget to its interconnecting audio paths */
244static int dapm_connect_mux(struct snd_soc_codec *codec, 281static int dapm_connect_mux(struct snd_soc_dapm_context *dapm,
245 struct snd_soc_dapm_widget *src, struct snd_soc_dapm_widget *dest, 282 struct snd_soc_dapm_widget *src, struct snd_soc_dapm_widget *dest,
246 struct snd_soc_dapm_path *path, const char *control_name, 283 struct snd_soc_dapm_path *path, const char *control_name,
247 const struct snd_kcontrol_new *kcontrol) 284 const struct snd_kcontrol_new *kcontrol)
@@ -251,7 +288,7 @@ static int dapm_connect_mux(struct snd_soc_codec *codec,
251 288
252 for (i = 0; i < e->max; i++) { 289 for (i = 0; i < e->max; i++) {
253 if (!(strcmp(control_name, e->texts[i]))) { 290 if (!(strcmp(control_name, e->texts[i]))) {
254 list_add(&path->list, &codec->dapm_paths); 291 list_add(&path->list, &dapm->card->paths);
255 list_add(&path->list_sink, &dest->sources); 292 list_add(&path->list_sink, &dest->sources);
256 list_add(&path->list_source, &src->sinks); 293 list_add(&path->list_source, &src->sinks);
257 path->name = (char*)e->texts[i]; 294 path->name = (char*)e->texts[i];
@@ -264,7 +301,7 @@ static int dapm_connect_mux(struct snd_soc_codec *codec,
264} 301}
265 302
266/* connect mixer widget to its interconnecting audio paths */ 303/* connect mixer widget to its interconnecting audio paths */
267static int dapm_connect_mixer(struct snd_soc_codec *codec, 304static int dapm_connect_mixer(struct snd_soc_dapm_context *dapm,
268 struct snd_soc_dapm_widget *src, struct snd_soc_dapm_widget *dest, 305 struct snd_soc_dapm_widget *src, struct snd_soc_dapm_widget *dest,
269 struct snd_soc_dapm_path *path, const char *control_name) 306 struct snd_soc_dapm_path *path, const char *control_name)
270{ 307{
@@ -273,7 +310,7 @@ static int dapm_connect_mixer(struct snd_soc_codec *codec,
273 /* search for mixer kcontrol */ 310 /* search for mixer kcontrol */
274 for (i = 0; i < dest->num_kcontrols; i++) { 311 for (i = 0; i < dest->num_kcontrols; i++) {
275 if (!strcmp(control_name, dest->kcontrols[i].name)) { 312 if (!strcmp(control_name, dest->kcontrols[i].name)) {
276 list_add(&path->list, &codec->dapm_paths); 313 list_add(&path->list, &dapm->card->paths);
277 list_add(&path->list_sink, &dest->sources); 314 list_add(&path->list_sink, &dest->sources);
278 list_add(&path->list_source, &src->sinks); 315 list_add(&path->list_source, &src->sinks);
279 path->name = dest->kcontrols[i].name; 316 path->name = dest->kcontrols[i].name;
@@ -290,6 +327,8 @@ static int dapm_update_bits(struct snd_soc_dapm_widget *widget)
290 int change, power; 327 int change, power;
291 unsigned int old, new; 328 unsigned int old, new;
292 struct snd_soc_codec *codec = widget->codec; 329 struct snd_soc_codec *codec = widget->codec;
330 struct snd_soc_dapm_context *dapm = widget->dapm;
331 struct snd_soc_card *card = dapm->card;
293 332
294 /* check for valid widgets */ 333 /* check for valid widgets */
295 if (widget->reg < 0 || widget->id == snd_soc_dapm_input || 334 if (widget->reg < 0 || widget->id == snd_soc_dapm_input ||
@@ -309,24 +348,26 @@ static int dapm_update_bits(struct snd_soc_dapm_widget *widget)
309 348
310 change = old != new; 349 change = old != new;
311 if (change) { 350 if (change) {
312 pop_dbg(codec->pop_time, "pop test %s : %s in %d ms\n", 351 pop_dbg(dapm->dev, card->pop_time,
352 "pop test %s : %s in %d ms\n",
313 widget->name, widget->power ? "on" : "off", 353 widget->name, widget->power ? "on" : "off",
314 codec->pop_time); 354 card->pop_time);
315 pop_wait(codec->pop_time); 355 pop_wait(card->pop_time);
316 snd_soc_write(codec, widget->reg, new); 356 snd_soc_write(codec, widget->reg, new);
317 } 357 }
318 pr_debug("reg %x old %x new %x change %d\n", widget->reg, 358 dev_dbg(dapm->dev, "reg %x old %x new %x change %d\n", widget->reg,
319 old, new, change); 359 old, new, change);
320 return change; 360 return change;
321} 361}
322 362
323/* create new dapm mixer control */ 363/* create new dapm mixer control */
324static int dapm_new_mixer(struct snd_soc_codec *codec, 364static int dapm_new_mixer(struct snd_soc_dapm_context *dapm,
325 struct snd_soc_dapm_widget *w) 365 struct snd_soc_dapm_widget *w)
326{ 366{
327 int i, ret = 0; 367 int i, ret = 0;
328 size_t name_len; 368 size_t name_len;
329 struct snd_soc_dapm_path *path; 369 struct snd_soc_dapm_path *path;
370 struct snd_card *card = dapm->codec->card->snd_card;
330 371
331 /* add kcontrol */ 372 /* add kcontrol */
332 for (i = 0; i < w->num_kcontrols; i++) { 373 for (i = 0; i < w->num_kcontrols; i++) {
@@ -368,11 +409,11 @@ static int dapm_new_mixer(struct snd_soc_codec *codec,
368 409
369 path->kcontrol = snd_soc_cnew(&w->kcontrols[i], w, 410 path->kcontrol = snd_soc_cnew(&w->kcontrols[i], w,
370 path->long_name); 411 path->long_name);
371 ret = snd_ctl_add(codec->card->snd_card, path->kcontrol); 412 ret = snd_ctl_add(card, path->kcontrol);
372 if (ret < 0) { 413 if (ret < 0) {
373 printk(KERN_ERR "asoc: failed to add dapm kcontrol %s: %d\n", 414 dev_err(dapm->dev,
374 path->long_name, 415 "asoc: failed to add dapm kcontrol %s: %d\n",
375 ret); 416 path->long_name, ret);
376 kfree(path->long_name); 417 kfree(path->long_name);
377 path->long_name = NULL; 418 path->long_name = NULL;
378 return ret; 419 return ret;
@@ -383,20 +424,22 @@ static int dapm_new_mixer(struct snd_soc_codec *codec,
383} 424}
384 425
385/* create new dapm mux control */ 426/* create new dapm mux control */
386static int dapm_new_mux(struct snd_soc_codec *codec, 427static int dapm_new_mux(struct snd_soc_dapm_context *dapm,
387 struct snd_soc_dapm_widget *w) 428 struct snd_soc_dapm_widget *w)
388{ 429{
389 struct snd_soc_dapm_path *path = NULL; 430 struct snd_soc_dapm_path *path = NULL;
390 struct snd_kcontrol *kcontrol; 431 struct snd_kcontrol *kcontrol;
432 struct snd_card *card = dapm->codec->card->snd_card;
391 int ret = 0; 433 int ret = 0;
392 434
393 if (!w->num_kcontrols) { 435 if (!w->num_kcontrols) {
394 printk(KERN_ERR "asoc: mux %s has no controls\n", w->name); 436 dev_err(dapm->dev, "asoc: mux %s has no controls\n", w->name);
395 return -EINVAL; 437 return -EINVAL;
396 } 438 }
397 439
398 kcontrol = snd_soc_cnew(&w->kcontrols[0], w, w->name); 440 kcontrol = snd_soc_cnew(&w->kcontrols[0], w, w->name);
399 ret = snd_ctl_add(codec->card->snd_card, kcontrol); 441 ret = snd_ctl_add(card, kcontrol);
442
400 if (ret < 0) 443 if (ret < 0)
401 goto err; 444 goto err;
402 445
@@ -406,26 +449,27 @@ static int dapm_new_mux(struct snd_soc_codec *codec,
406 return ret; 449 return ret;
407 450
408err: 451err:
409 printk(KERN_ERR "asoc: failed to add kcontrol %s\n", w->name); 452 dev_err(dapm->dev, "asoc: failed to add kcontrol %s\n", w->name);
410 return ret; 453 return ret;
411} 454}
412 455
413/* create new dapm volume control */ 456/* create new dapm volume control */
414static int dapm_new_pga(struct snd_soc_codec *codec, 457static int dapm_new_pga(struct snd_soc_dapm_context *dapm,
415 struct snd_soc_dapm_widget *w) 458 struct snd_soc_dapm_widget *w)
416{ 459{
417 if (w->num_kcontrols) 460 if (w->num_kcontrols)
418 pr_err("asoc: PGA controls not supported: '%s'\n", w->name); 461 dev_err(w->dapm->dev,
462 "asoc: PGA controls not supported: '%s'\n", w->name);
419 463
420 return 0; 464 return 0;
421} 465}
422 466
423/* reset 'walked' bit for each dapm path */ 467/* reset 'walked' bit for each dapm path */
424static inline void dapm_clear_walk(struct snd_soc_codec *codec) 468static inline void dapm_clear_walk(struct snd_soc_dapm_context *dapm)
425{ 469{
426 struct snd_soc_dapm_path *p; 470 struct snd_soc_dapm_path *p;
427 471
428 list_for_each_entry(p, &codec->dapm_paths, list) 472 list_for_each_entry(p, &dapm->card->paths, list)
429 p->walked = 0; 473 p->walked = 0;
430} 474}
431 475
@@ -435,13 +479,14 @@ static inline void dapm_clear_walk(struct snd_soc_codec *codec)
435 */ 479 */
436static int snd_soc_dapm_suspend_check(struct snd_soc_dapm_widget *widget) 480static int snd_soc_dapm_suspend_check(struct snd_soc_dapm_widget *widget)
437{ 481{
438 int level = snd_power_get_state(widget->codec->card->snd_card); 482 int level = snd_power_get_state(widget->dapm->codec->card->snd_card);
439 483
440 switch (level) { 484 switch (level) {
441 case SNDRV_CTL_POWER_D3hot: 485 case SNDRV_CTL_POWER_D3hot:
442 case SNDRV_CTL_POWER_D3cold: 486 case SNDRV_CTL_POWER_D3cold:
443 if (widget->ignore_suspend) 487 if (widget->ignore_suspend)
444 pr_debug("%s ignoring suspend\n", widget->name); 488 dev_dbg(widget->dapm->dev, "%s ignoring suspend\n",
489 widget->name);
445 return widget->ignore_suspend; 490 return widget->ignore_suspend;
446 default: 491 default:
447 return 1; 492 return 1;
@@ -572,7 +617,7 @@ static int dapm_generic_apply_power(struct snd_soc_dapm_widget *w)
572 617
573 /* call any power change event handlers */ 618 /* call any power change event handlers */
574 if (w->event) 619 if (w->event)
575 pr_debug("power %s event for %s flags %x\n", 620 dev_dbg(w->dapm->dev, "power %s event for %s flags %x\n",
576 w->power ? "on" : "off", 621 w->power ? "on" : "off",
577 w->name, w->event_flags); 622 w->name, w->event_flags);
578 623
@@ -621,9 +666,9 @@ static int dapm_generic_check_power(struct snd_soc_dapm_widget *w)
621 int in, out; 666 int in, out;
622 667
623 in = is_connected_input_ep(w); 668 in = is_connected_input_ep(w);
624 dapm_clear_walk(w->codec); 669 dapm_clear_walk(w->dapm);
625 out = is_connected_output_ep(w); 670 out = is_connected_output_ep(w);
626 dapm_clear_walk(w->codec); 671 dapm_clear_walk(w->dapm);
627 return out != 0 && in != 0; 672 return out != 0 && in != 0;
628} 673}
629 674
@@ -634,7 +679,7 @@ static int dapm_adc_check_power(struct snd_soc_dapm_widget *w)
634 679
635 if (w->active) { 680 if (w->active) {
636 in = is_connected_input_ep(w); 681 in = is_connected_input_ep(w);
637 dapm_clear_walk(w->codec); 682 dapm_clear_walk(w->dapm);
638 return in != 0; 683 return in != 0;
639 } else { 684 } else {
640 return dapm_generic_check_power(w); 685 return dapm_generic_check_power(w);
@@ -648,7 +693,7 @@ static int dapm_dac_check_power(struct snd_soc_dapm_widget *w)
648 693
649 if (w->active) { 694 if (w->active) {
650 out = is_connected_output_ep(w); 695 out = is_connected_output_ep(w);
651 dapm_clear_walk(w->codec); 696 dapm_clear_walk(w->dapm);
652 return out != 0; 697 return out != 0;
653 } else { 698 } else {
654 return dapm_generic_check_power(w); 699 return dapm_generic_check_power(w);
@@ -674,7 +719,7 @@ static int dapm_supply_check_power(struct snd_soc_dapm_widget *w)
674 } 719 }
675 } 720 }
676 721
677 dapm_clear_walk(w->codec); 722 dapm_clear_walk(w->dapm);
678 723
679 return power; 724 return power;
680} 725}
@@ -687,8 +732,8 @@ static int dapm_seq_compare(struct snd_soc_dapm_widget *a,
687 return sort[a->id] - sort[b->id]; 732 return sort[a->id] - sort[b->id];
688 if (a->reg != b->reg) 733 if (a->reg != b->reg)
689 return a->reg - b->reg; 734 return a->reg - b->reg;
690 if (a->codec != b->codec) 735 if (a->dapm != b->dapm)
691 return (unsigned long)a->codec - (unsigned long)b->codec; 736 return (unsigned long)a->dapm - (unsigned long)b->dapm;
692 737
693 return 0; 738 return 0;
694} 739}
@@ -709,12 +754,57 @@ static void dapm_seq_insert(struct snd_soc_dapm_widget *new_widget,
709 list_add_tail(&new_widget->power_list, list); 754 list_add_tail(&new_widget->power_list, list);
710} 755}
711 756
757static void dapm_seq_check_event(struct snd_soc_dapm_context *dapm,
758 struct snd_soc_dapm_widget *w, int event)
759{
760 struct snd_soc_card *card = dapm->card;
761 const char *ev_name;
762 int power, ret;
763
764 switch (event) {
765 case SND_SOC_DAPM_PRE_PMU:
766 ev_name = "PRE_PMU";
767 power = 1;
768 break;
769 case SND_SOC_DAPM_POST_PMU:
770 ev_name = "POST_PMU";
771 power = 1;
772 break;
773 case SND_SOC_DAPM_PRE_PMD:
774 ev_name = "PRE_PMD";
775 power = 0;
776 break;
777 case SND_SOC_DAPM_POST_PMD:
778 ev_name = "POST_PMD";
779 power = 0;
780 break;
781 default:
782 BUG();
783 return;
784 }
785
786 if (w->power != power)
787 return;
788
789 if (w->event && (w->event_flags & event)) {
790 pop_dbg(dapm->dev, card->pop_time, "pop test : %s %s\n",
791 w->name, ev_name);
792 trace_snd_soc_dapm_widget_event_start(w, event);
793 ret = w->event(w, NULL, event);
794 trace_snd_soc_dapm_widget_event_done(w, event);
795 if (ret < 0)
796 pr_err("%s: %s event failed: %d\n",
797 ev_name, w->name, ret);
798 }
799}
800
712/* Apply the coalesced changes from a DAPM sequence */ 801/* Apply the coalesced changes from a DAPM sequence */
713static void dapm_seq_run_coalesced(struct snd_soc_codec *codec, 802static void dapm_seq_run_coalesced(struct snd_soc_dapm_context *dapm,
714 struct list_head *pending) 803 struct list_head *pending)
715{ 804{
805 struct snd_soc_card *card = dapm->card;
716 struct snd_soc_dapm_widget *w; 806 struct snd_soc_dapm_widget *w;
717 int reg, power, ret; 807 int reg, power;
718 unsigned int value = 0; 808 unsigned int value = 0;
719 unsigned int mask = 0; 809 unsigned int mask = 0;
720 unsigned int cur_mask; 810 unsigned int cur_mask;
@@ -735,64 +825,26 @@ static void dapm_seq_run_coalesced(struct snd_soc_codec *codec,
735 if (power) 825 if (power)
736 value |= cur_mask; 826 value |= cur_mask;
737 827
738 pop_dbg(codec->pop_time, 828 pop_dbg(dapm->dev, card->pop_time,
739 "pop test : Queue %s: reg=0x%x, 0x%x/0x%x\n", 829 "pop test : Queue %s: reg=0x%x, 0x%x/0x%x\n",
740 w->name, reg, value, mask); 830 w->name, reg, value, mask);
741 831
742 /* power up pre event */ 832 /* Check for events */
743 if (w->power && w->event && 833 dapm_seq_check_event(dapm, w, SND_SOC_DAPM_PRE_PMU);
744 (w->event_flags & SND_SOC_DAPM_PRE_PMU)) { 834 dapm_seq_check_event(dapm, w, SND_SOC_DAPM_PRE_PMD);
745 pop_dbg(codec->pop_time, "pop test : %s PRE_PMU\n",
746 w->name);
747 ret = w->event(w, NULL, SND_SOC_DAPM_PRE_PMU);
748 if (ret < 0)
749 pr_err("%s: pre event failed: %d\n",
750 w->name, ret);
751 }
752
753 /* power down pre event */
754 if (!w->power && w->event &&
755 (w->event_flags & SND_SOC_DAPM_PRE_PMD)) {
756 pop_dbg(codec->pop_time, "pop test : %s PRE_PMD\n",
757 w->name);
758 ret = w->event(w, NULL, SND_SOC_DAPM_PRE_PMD);
759 if (ret < 0)
760 pr_err("%s: pre event failed: %d\n",
761 w->name, ret);
762 }
763 } 835 }
764 836
765 if (reg >= 0) { 837 if (reg >= 0) {
766 pop_dbg(codec->pop_time, 838 pop_dbg(dapm->dev, card->pop_time,
767 "pop test : Applying 0x%x/0x%x to %x in %dms\n", 839 "pop test : Applying 0x%x/0x%x to %x in %dms\n",
768 value, mask, reg, codec->pop_time); 840 value, mask, reg, card->pop_time);
769 pop_wait(codec->pop_time); 841 pop_wait(card->pop_time);
770 snd_soc_update_bits(codec, reg, mask, value); 842 snd_soc_update_bits(dapm->codec, reg, mask, value);
771 } 843 }
772 844
773 list_for_each_entry(w, pending, power_list) { 845 list_for_each_entry(w, pending, power_list) {
774 /* power up post event */ 846 dapm_seq_check_event(dapm, w, SND_SOC_DAPM_POST_PMU);
775 if (w->power && w->event && 847 dapm_seq_check_event(dapm, w, SND_SOC_DAPM_POST_PMD);
776 (w->event_flags & SND_SOC_DAPM_POST_PMU)) {
777 pop_dbg(codec->pop_time, "pop test : %s POST_PMU\n",
778 w->name);
779 ret = w->event(w,
780 NULL, SND_SOC_DAPM_POST_PMU);
781 if (ret < 0)
782 pr_err("%s: post event failed: %d\n",
783 w->name, ret);
784 }
785
786 /* power down post event */
787 if (!w->power && w->event &&
788 (w->event_flags & SND_SOC_DAPM_POST_PMD)) {
789 pop_dbg(codec->pop_time, "pop test : %s POST_PMD\n",
790 w->name);
791 ret = w->event(w, NULL, SND_SOC_DAPM_POST_PMD);
792 if (ret < 0)
793 pr_err("%s: post event failed: %d\n",
794 w->name, ret);
795 }
796 } 848 }
797} 849}
798 850
@@ -804,26 +856,29 @@ static void dapm_seq_run_coalesced(struct snd_soc_codec *codec,
804 * Currently anything that requires more than a single write is not 856 * Currently anything that requires more than a single write is not
805 * handled. 857 * handled.
806 */ 858 */
807static void dapm_seq_run(struct snd_soc_codec *codec, struct list_head *list, 859static void dapm_seq_run(struct snd_soc_dapm_context *dapm,
808 int event, int sort[]) 860 struct list_head *list, int event, int sort[])
809{ 861{
810 struct snd_soc_dapm_widget *w, *n; 862 struct snd_soc_dapm_widget *w, *n;
811 LIST_HEAD(pending); 863 LIST_HEAD(pending);
812 int cur_sort = -1; 864 int cur_sort = -1;
813 int cur_reg = SND_SOC_NOPM; 865 int cur_reg = SND_SOC_NOPM;
866 struct snd_soc_dapm_context *cur_dapm = NULL;
814 int ret; 867 int ret;
815 868
816 list_for_each_entry_safe(w, n, list, power_list) { 869 list_for_each_entry_safe(w, n, list, power_list) {
817 ret = 0; 870 ret = 0;
818 871
819 /* Do we need to apply any queued changes? */ 872 /* Do we need to apply any queued changes? */
820 if (sort[w->id] != cur_sort || w->reg != cur_reg) { 873 if (sort[w->id] != cur_sort || w->reg != cur_reg ||
874 w->dapm != cur_dapm) {
821 if (!list_empty(&pending)) 875 if (!list_empty(&pending))
822 dapm_seq_run_coalesced(codec, &pending); 876 dapm_seq_run_coalesced(cur_dapm, &pending);
823 877
824 INIT_LIST_HEAD(&pending); 878 INIT_LIST_HEAD(&pending);
825 cur_sort = -1; 879 cur_sort = -1;
826 cur_reg = SND_SOC_NOPM; 880 cur_reg = SND_SOC_NOPM;
881 cur_dapm = NULL;
827 } 882 }
828 883
829 switch (w->id) { 884 switch (w->id) {
@@ -867,19 +922,55 @@ static void dapm_seq_run(struct snd_soc_codec *codec, struct list_head *list,
867 /* Queue it up for application */ 922 /* Queue it up for application */
868 cur_sort = sort[w->id]; 923 cur_sort = sort[w->id];
869 cur_reg = w->reg; 924 cur_reg = w->reg;
925 cur_dapm = w->dapm;
870 list_move(&w->power_list, &pending); 926 list_move(&w->power_list, &pending);
871 break; 927 break;
872 } 928 }
873 929
874 if (ret < 0) 930 if (ret < 0)
875 pr_err("Failed to apply widget power: %d\n", 931 dev_err(w->dapm->dev,
876 ret); 932 "Failed to apply widget power: %d\n", ret);
877 } 933 }
878 934
879 if (!list_empty(&pending)) 935 if (!list_empty(&pending))
880 dapm_seq_run_coalesced(codec, &pending); 936 dapm_seq_run_coalesced(dapm, &pending);
937}
938
939static void dapm_widget_update(struct snd_soc_dapm_context *dapm)
940{
941 struct snd_soc_dapm_update *update = dapm->update;
942 struct snd_soc_dapm_widget *w;
943 int ret;
944
945 if (!update)
946 return;
947
948 w = update->widget;
949
950 if (w->event &&
951 (w->event_flags & SND_SOC_DAPM_PRE_REG)) {
952 ret = w->event(w, update->kcontrol, SND_SOC_DAPM_PRE_REG);
953 if (ret != 0)
954 pr_err("%s DAPM pre-event failed: %d\n",
955 w->name, ret);
956 }
957
958 ret = snd_soc_update_bits(w->codec, update->reg, update->mask,
959 update->val);
960 if (ret < 0)
961 pr_err("%s DAPM update failed: %d\n", w->name, ret);
962
963 if (w->event &&
964 (w->event_flags & SND_SOC_DAPM_POST_REG)) {
965 ret = w->event(w, update->kcontrol, SND_SOC_DAPM_POST_REG);
966 if (ret != 0)
967 pr_err("%s DAPM post-event failed: %d\n",
968 w->name, ret);
969 }
881} 970}
882 971
972
973
883/* 974/*
884 * Scan each dapm widget for complete audio path. 975 * Scan each dapm widget for complete audio path.
885 * A complete path is a route that has valid endpoints i.e.:- 976 * A complete path is a route that has valid endpoints i.e.:-
@@ -889,20 +980,26 @@ static void dapm_seq_run(struct snd_soc_codec *codec, struct list_head *list,
889 * o Input pin to Output pin (bypass, sidetone) 980 * o Input pin to Output pin (bypass, sidetone)
890 * o DAC to ADC (loopback). 981 * o DAC to ADC (loopback).
891 */ 982 */
892static int dapm_power_widgets(struct snd_soc_codec *codec, int event) 983static int dapm_power_widgets(struct snd_soc_dapm_context *dapm, int event)
893{ 984{
894 struct snd_soc_card *card = codec->card; 985 struct snd_soc_card *card = dapm->codec->card;
895 struct snd_soc_dapm_widget *w; 986 struct snd_soc_dapm_widget *w;
987 struct snd_soc_dapm_context *d;
896 LIST_HEAD(up_list); 988 LIST_HEAD(up_list);
897 LIST_HEAD(down_list); 989 LIST_HEAD(down_list);
898 int ret = 0; 990 int ret = 0;
899 int power; 991 int power;
900 int sys_power = 0; 992
993 trace_snd_soc_dapm_start(card);
994
995 list_for_each_entry(d, &card->dapm_list, list)
996 if (d->n_widgets)
997 d->dev_power = 0;
901 998
902 /* Check which widgets we need to power and store them in 999 /* Check which widgets we need to power and store them in
903 * lists indicating if they should be powered up or down. 1000 * lists indicating if they should be powered up or down.
904 */ 1001 */
905 list_for_each_entry(w, &codec->dapm_widgets, list) { 1002 list_for_each_entry(w, &card->widgets, list) {
906 switch (w->id) { 1003 switch (w->id) {
907 case snd_soc_dapm_pre: 1004 case snd_soc_dapm_pre:
908 dapm_seq_insert(w, &down_list, dapm_down_seq); 1005 dapm_seq_insert(w, &down_list, dapm_down_seq);
@@ -920,11 +1017,13 @@ static int dapm_power_widgets(struct snd_soc_codec *codec, int event)
920 else 1017 else
921 power = 1; 1018 power = 1;
922 if (power) 1019 if (power)
923 sys_power = 1; 1020 w->dapm->dev_power = 1;
924 1021
925 if (w->power == power) 1022 if (w->power == power)
926 continue; 1023 continue;
927 1024
1025 trace_snd_soc_dapm_widget_power(w, power);
1026
928 if (power) 1027 if (power)
929 dapm_seq_insert(w, &up_list, dapm_up_seq); 1028 dapm_seq_insert(w, &up_list, dapm_up_seq);
930 else 1029 else
@@ -938,26 +1037,26 @@ static int dapm_power_widgets(struct snd_soc_codec *codec, int event)
938 /* If there are no DAPM widgets then try to figure out power from the 1037 /* If there are no DAPM widgets then try to figure out power from the
939 * event type. 1038 * event type.
940 */ 1039 */
941 if (list_empty(&codec->dapm_widgets)) { 1040 if (!dapm->n_widgets) {
942 switch (event) { 1041 switch (event) {
943 case SND_SOC_DAPM_STREAM_START: 1042 case SND_SOC_DAPM_STREAM_START:
944 case SND_SOC_DAPM_STREAM_RESUME: 1043 case SND_SOC_DAPM_STREAM_RESUME:
945 sys_power = 1; 1044 dapm->dev_power = 1;
946 break; 1045 break;
947 case SND_SOC_DAPM_STREAM_STOP: 1046 case SND_SOC_DAPM_STREAM_STOP:
948 sys_power = !!codec->active; 1047 dapm->dev_power = !!dapm->codec->active;
949 break; 1048 break;
950 case SND_SOC_DAPM_STREAM_SUSPEND: 1049 case SND_SOC_DAPM_STREAM_SUSPEND:
951 sys_power = 0; 1050 dapm->dev_power = 0;
952 break; 1051 break;
953 case SND_SOC_DAPM_STREAM_NOP: 1052 case SND_SOC_DAPM_STREAM_NOP:
954 switch (codec->bias_level) { 1053 switch (dapm->bias_level) {
955 case SND_SOC_BIAS_STANDBY: 1054 case SND_SOC_BIAS_STANDBY:
956 case SND_SOC_BIAS_OFF: 1055 case SND_SOC_BIAS_OFF:
957 sys_power = 0; 1056 dapm->dev_power = 0;
958 break; 1057 break;
959 default: 1058 default:
960 sys_power = 1; 1059 dapm->dev_power = 1;
961 break; 1060 break;
962 } 1061 }
963 break; 1062 break;
@@ -966,52 +1065,71 @@ static int dapm_power_widgets(struct snd_soc_codec *codec, int event)
966 } 1065 }
967 } 1066 }
968 1067
969 if (sys_power && codec->bias_level == SND_SOC_BIAS_OFF) { 1068 list_for_each_entry(d, &dapm->card->dapm_list, list) {
970 ret = snd_soc_dapm_set_bias_level(card, codec, 1069 if (d->dev_power && d->bias_level == SND_SOC_BIAS_OFF) {
971 SND_SOC_BIAS_STANDBY); 1070 ret = snd_soc_dapm_set_bias_level(card, d,
972 if (ret != 0) 1071 SND_SOC_BIAS_STANDBY);
973 pr_err("Failed to turn on bias: %d\n", ret); 1072 if (ret != 0)
974 } 1073 dev_err(d->dev,
1074 "Failed to turn on bias: %d\n", ret);
1075 }
975 1076
976 /* If we're changing to all on or all off then prepare */ 1077 /* If we're changing to all on or all off then prepare */
977 if ((sys_power && codec->bias_level == SND_SOC_BIAS_STANDBY) || 1078 if ((d->dev_power && d->bias_level == SND_SOC_BIAS_STANDBY) ||
978 (!sys_power && codec->bias_level == SND_SOC_BIAS_ON)) { 1079 (!d->dev_power && d->bias_level == SND_SOC_BIAS_ON)) {
979 ret = snd_soc_dapm_set_bias_level(card, codec, SND_SOC_BIAS_PREPARE); 1080 ret = snd_soc_dapm_set_bias_level(card, d,
980 if (ret != 0) 1081 SND_SOC_BIAS_PREPARE);
981 pr_err("Failed to prepare bias: %d\n", ret); 1082 if (ret != 0)
1083 dev_err(d->dev,
1084 "Failed to prepare bias: %d\n", ret);
1085 }
982 } 1086 }
983 1087
984 /* Power down widgets first; try to avoid amplifying pops. */ 1088 /* Power down widgets first; try to avoid amplifying pops. */
985 dapm_seq_run(codec, &down_list, event, dapm_down_seq); 1089 dapm_seq_run(dapm, &down_list, event, dapm_down_seq);
1090
1091 dapm_widget_update(dapm);
986 1092
987 /* Now power up. */ 1093 /* Now power up. */
988 dapm_seq_run(codec, &up_list, event, dapm_up_seq); 1094 dapm_seq_run(dapm, &up_list, event, dapm_up_seq);
1095
1096 list_for_each_entry(d, &dapm->card->dapm_list, list) {
1097 /* If we just powered the last thing off drop to standby bias */
1098 if (d->bias_level == SND_SOC_BIAS_PREPARE && !d->dev_power) {
1099 ret = snd_soc_dapm_set_bias_level(card, d,
1100 SND_SOC_BIAS_STANDBY);
1101 if (ret != 0)
1102 dev_err(d->dev,
1103 "Failed to apply standby bias: %d\n",
1104 ret);
1105 }
989 1106
990 /* If we just powered the last thing off drop to standby bias */ 1107 /* If we're in standby and can support bias off then do that */
991 if (codec->bias_level == SND_SOC_BIAS_PREPARE && !sys_power) { 1108 if (d->bias_level == SND_SOC_BIAS_STANDBY &&
992 ret = snd_soc_dapm_set_bias_level(card, codec, SND_SOC_BIAS_STANDBY); 1109 d->idle_bias_off) {
993 if (ret != 0) 1110 ret = snd_soc_dapm_set_bias_level(card, d,
994 pr_err("Failed to apply standby bias: %d\n", ret); 1111 SND_SOC_BIAS_OFF);
995 } 1112 if (ret != 0)
1113 dev_err(d->dev,
1114 "Failed to turn off bias: %d\n", ret);
1115 }
996 1116
997 /* If we're in standby and can support bias off then do that */ 1117 /* If we just powered up then move to active bias */
998 if (codec->bias_level == SND_SOC_BIAS_STANDBY && 1118 if (d->bias_level == SND_SOC_BIAS_PREPARE && d->dev_power) {
999 codec->idle_bias_off) { 1119 ret = snd_soc_dapm_set_bias_level(card, d,
1000 ret = snd_soc_dapm_set_bias_level(card, codec, SND_SOC_BIAS_OFF); 1120 SND_SOC_BIAS_ON);
1001 if (ret != 0) 1121 if (ret != 0)
1002 pr_err("Failed to turn off bias: %d\n", ret); 1122 dev_err(d->dev,
1123 "Failed to apply active bias: %d\n",
1124 ret);
1125 }
1003 } 1126 }
1004 1127
1005 /* If we just powered up then move to active bias */ 1128 pop_dbg(dapm->dev, card->pop_time,
1006 if (codec->bias_level == SND_SOC_BIAS_PREPARE && sys_power) { 1129 "DAPM sequencing finished, waiting %dms\n", card->pop_time);
1007 ret = snd_soc_dapm_set_bias_level(card, codec, SND_SOC_BIAS_ON); 1130 pop_wait(card->pop_time);
1008 if (ret != 0)
1009 pr_err("Failed to apply active bias: %d\n", ret);
1010 }
1011 1131
1012 pop_dbg(codec->pop_time, "DAPM sequencing finished, waiting %dms\n", 1132 trace_snd_soc_dapm_done(card);
1013 codec->pop_time);
1014 pop_wait(codec->pop_time);
1015 1133
1016 return 0; 1134 return 0;
1017} 1135}
@@ -1038,9 +1156,9 @@ static ssize_t dapm_widget_power_read_file(struct file *file,
1038 return -ENOMEM; 1156 return -ENOMEM;
1039 1157
1040 in = is_connected_input_ep(w); 1158 in = is_connected_input_ep(w);
1041 dapm_clear_walk(w->codec); 1159 dapm_clear_walk(w->dapm);
1042 out = is_connected_output_ep(w); 1160 out = is_connected_output_ep(w);
1043 dapm_clear_walk(w->codec); 1161 dapm_clear_walk(w->dapm);
1044 1162
1045 ret = snprintf(buf, PAGE_SIZE, "%s: %s in %d out %d", 1163 ret = snprintf(buf, PAGE_SIZE, "%s: %s in %d out %d",
1046 w->name, w->power ? "On" : "Off", in, out); 1164 w->name, w->power ? "On" : "Off", in, out);
@@ -1090,29 +1208,29 @@ static const struct file_operations dapm_widget_power_fops = {
1090 .llseek = default_llseek, 1208 .llseek = default_llseek,
1091}; 1209};
1092 1210
1093void snd_soc_dapm_debugfs_init(struct snd_soc_codec *codec) 1211void snd_soc_dapm_debugfs_init(struct snd_soc_dapm_context *dapm)
1094{ 1212{
1095 struct snd_soc_dapm_widget *w; 1213 struct snd_soc_dapm_widget *w;
1096 struct dentry *d; 1214 struct dentry *d;
1097 1215
1098 if (!codec->debugfs_dapm) 1216 if (!dapm->debugfs_dapm)
1099 return; 1217 return;
1100 1218
1101 list_for_each_entry(w, &codec->dapm_widgets, list) { 1219 list_for_each_entry(w, &dapm->card->widgets, list) {
1102 if (!w->name) 1220 if (!w->name || w->dapm != dapm)
1103 continue; 1221 continue;
1104 1222
1105 d = debugfs_create_file(w->name, 0444, 1223 d = debugfs_create_file(w->name, 0444,
1106 codec->debugfs_dapm, w, 1224 dapm->debugfs_dapm, w,
1107 &dapm_widget_power_fops); 1225 &dapm_widget_power_fops);
1108 if (!d) 1226 if (!d)
1109 printk(KERN_WARNING 1227 dev_warn(w->dapm->dev,
1110 "ASoC: Failed to create %s debugfs file\n", 1228 "ASoC: Failed to create %s debugfs file\n",
1111 w->name); 1229 w->name);
1112 } 1230 }
1113} 1231}
1114#else 1232#else
1115void snd_soc_dapm_debugfs_init(struct snd_soc_codec *codec) 1233void snd_soc_dapm_debugfs_init(struct snd_soc_dapm_context *dapm)
1116{ 1234{
1117} 1235}
1118#endif 1236#endif
@@ -1126,6 +1244,7 @@ static int dapm_mux_update_power(struct snd_soc_dapm_widget *widget,
1126 int found = 0; 1244 int found = 0;
1127 1245
1128 if (widget->id != snd_soc_dapm_mux && 1246 if (widget->id != snd_soc_dapm_mux &&
1247 widget->id != snd_soc_dapm_virt_mux &&
1129 widget->id != snd_soc_dapm_value_mux) 1248 widget->id != snd_soc_dapm_value_mux)
1130 return -ENODEV; 1249 return -ENODEV;
1131 1250
@@ -1133,7 +1252,7 @@ static int dapm_mux_update_power(struct snd_soc_dapm_widget *widget,
1133 return 0; 1252 return 0;
1134 1253
1135 /* find dapm widget path assoc with kcontrol */ 1254 /* find dapm widget path assoc with kcontrol */
1136 list_for_each_entry(path, &widget->codec->dapm_paths, list) { 1255 list_for_each_entry(path, &widget->dapm->card->paths, list) {
1137 if (path->kcontrol != kcontrol) 1256 if (path->kcontrol != kcontrol)
1138 continue; 1257 continue;
1139 1258
@@ -1149,7 +1268,7 @@ static int dapm_mux_update_power(struct snd_soc_dapm_widget *widget,
1149 } 1268 }
1150 1269
1151 if (found) 1270 if (found)
1152 dapm_power_widgets(widget->codec, SND_SOC_DAPM_STREAM_NOP); 1271 dapm_power_widgets(widget->dapm, SND_SOC_DAPM_STREAM_NOP);
1153 1272
1154 return 0; 1273 return 0;
1155} 1274}
@@ -1167,7 +1286,7 @@ static int dapm_mixer_update_power(struct snd_soc_dapm_widget *widget,
1167 return -ENODEV; 1286 return -ENODEV;
1168 1287
1169 /* find dapm widget path assoc with kcontrol */ 1288 /* find dapm widget path assoc with kcontrol */
1170 list_for_each_entry(path, &widget->codec->dapm_paths, list) { 1289 list_for_each_entry(path, &widget->dapm->card->paths, list) {
1171 if (path->kcontrol != kcontrol) 1290 if (path->kcontrol != kcontrol)
1172 continue; 1291 continue;
1173 1292
@@ -1178,7 +1297,7 @@ static int dapm_mixer_update_power(struct snd_soc_dapm_widget *widget,
1178 } 1297 }
1179 1298
1180 if (found) 1299 if (found)
1181 dapm_power_widgets(widget->codec, SND_SOC_DAPM_STREAM_NOP); 1300 dapm_power_widgets(widget->dapm, SND_SOC_DAPM_STREAM_NOP);
1182 1301
1183 return 0; 1302 return 0;
1184} 1303}
@@ -1194,7 +1313,9 @@ static ssize_t dapm_widget_show(struct device *dev,
1194 int count = 0; 1313 int count = 0;
1195 char *state = "not set"; 1314 char *state = "not set";
1196 1315
1197 list_for_each_entry(w, &codec->dapm_widgets, list) { 1316 list_for_each_entry(w, &codec->card->widgets, list) {
1317 if (w->dapm != &codec->dapm)
1318 continue;
1198 1319
1199 /* only display widgets that burnm power */ 1320 /* only display widgets that burnm power */
1200 switch (w->id) { 1321 switch (w->id) {
@@ -1206,6 +1327,7 @@ static ssize_t dapm_widget_show(struct device *dev,
1206 case snd_soc_dapm_dac: 1327 case snd_soc_dapm_dac:
1207 case snd_soc_dapm_adc: 1328 case snd_soc_dapm_adc:
1208 case snd_soc_dapm_pga: 1329 case snd_soc_dapm_pga:
1330 case snd_soc_dapm_out_drv:
1209 case snd_soc_dapm_mixer: 1331 case snd_soc_dapm_mixer:
1210 case snd_soc_dapm_mixer_named_ctl: 1332 case snd_soc_dapm_mixer_named_ctl:
1211 case snd_soc_dapm_supply: 1333 case snd_soc_dapm_supply:
@@ -1218,7 +1340,7 @@ static ssize_t dapm_widget_show(struct device *dev,
1218 } 1340 }
1219 } 1341 }
1220 1342
1221 switch (codec->bias_level) { 1343 switch (codec->dapm.bias_level) {
1222 case SND_SOC_BIAS_ON: 1344 case SND_SOC_BIAS_ON:
1223 state = "On"; 1345 state = "On";
1224 break; 1346 break;
@@ -1250,31 +1372,50 @@ static void snd_soc_dapm_sys_remove(struct device *dev)
1250} 1372}
1251 1373
1252/* free all dapm widgets and resources */ 1374/* free all dapm widgets and resources */
1253static void dapm_free_widgets(struct snd_soc_codec *codec) 1375static void dapm_free_widgets(struct snd_soc_dapm_context *dapm)
1254{ 1376{
1255 struct snd_soc_dapm_widget *w, *next_w; 1377 struct snd_soc_dapm_widget *w, *next_w;
1256 struct snd_soc_dapm_path *p, *next_p; 1378 struct snd_soc_dapm_path *p, *next_p;
1257 1379
1258 list_for_each_entry_safe(w, next_w, &codec->dapm_widgets, list) { 1380 list_for_each_entry_safe(w, next_w, &dapm->card->widgets, list) {
1381 if (w->dapm != dapm)
1382 continue;
1259 list_del(&w->list); 1383 list_del(&w->list);
1384 /*
1385 * remove source and sink paths associated to this widget.
1386 * While removing the path, remove reference to it from both
1387 * source and sink widgets so that path is removed only once.
1388 */
1389 list_for_each_entry_safe(p, next_p, &w->sources, list_sink) {
1390 list_del(&p->list_sink);
1391 list_del(&p->list_source);
1392 list_del(&p->list);
1393 kfree(p->long_name);
1394 kfree(p);
1395 }
1396 list_for_each_entry_safe(p, next_p, &w->sinks, list_source) {
1397 list_del(&p->list_sink);
1398 list_del(&p->list_source);
1399 list_del(&p->list);
1400 kfree(p->long_name);
1401 kfree(p);
1402 }
1403 kfree(w->name);
1260 kfree(w); 1404 kfree(w);
1261 } 1405 }
1262
1263 list_for_each_entry_safe(p, next_p, &codec->dapm_paths, list) {
1264 list_del(&p->list);
1265 kfree(p->long_name);
1266 kfree(p);
1267 }
1268} 1406}
1269 1407
1270static int snd_soc_dapm_set_pin(struct snd_soc_codec *codec, 1408static int snd_soc_dapm_set_pin(struct snd_soc_dapm_context *dapm,
1271 const char *pin, int status) 1409 const char *pin, int status)
1272{ 1410{
1273 struct snd_soc_dapm_widget *w; 1411 struct snd_soc_dapm_widget *w;
1274 1412
1275 list_for_each_entry(w, &codec->dapm_widgets, list) { 1413 list_for_each_entry(w, &dapm->card->widgets, list) {
1414 if (w->dapm != dapm)
1415 continue;
1276 if (!strcmp(w->name, pin)) { 1416 if (!strcmp(w->name, pin)) {
1277 pr_debug("dapm: %s: pin %s\n", codec->name, pin); 1417 dev_dbg(w->dapm->dev, "dapm: pin %s = %d\n",
1418 pin, status);
1278 w->connected = status; 1419 w->connected = status;
1279 /* Allow disabling of forced pins */ 1420 /* Allow disabling of forced pins */
1280 if (status == 0) 1421 if (status == 0)
@@ -1283,46 +1424,72 @@ static int snd_soc_dapm_set_pin(struct snd_soc_codec *codec,
1283 } 1424 }
1284 } 1425 }
1285 1426
1286 pr_err("dapm: %s: configuring unknown pin %s\n", codec->name, pin); 1427 dev_err(dapm->dev, "dapm: unknown pin %s\n", pin);
1287 return -EINVAL; 1428 return -EINVAL;
1288} 1429}
1289 1430
1290/** 1431/**
1291 * snd_soc_dapm_sync - scan and power dapm paths 1432 * snd_soc_dapm_sync - scan and power dapm paths
1292 * @codec: audio codec 1433 * @dapm: DAPM context
1293 * 1434 *
1294 * Walks all dapm audio paths and powers widgets according to their 1435 * Walks all dapm audio paths and powers widgets according to their
1295 * stream or path usage. 1436 * stream or path usage.
1296 * 1437 *
1297 * Returns 0 for success. 1438 * Returns 0 for success.
1298 */ 1439 */
1299int snd_soc_dapm_sync(struct snd_soc_codec *codec) 1440int snd_soc_dapm_sync(struct snd_soc_dapm_context *dapm)
1300{ 1441{
1301 return dapm_power_widgets(codec, SND_SOC_DAPM_STREAM_NOP); 1442 return dapm_power_widgets(dapm, SND_SOC_DAPM_STREAM_NOP);
1302} 1443}
1303EXPORT_SYMBOL_GPL(snd_soc_dapm_sync); 1444EXPORT_SYMBOL_GPL(snd_soc_dapm_sync);
1304 1445
1305static int snd_soc_dapm_add_route(struct snd_soc_codec *codec, 1446static int snd_soc_dapm_add_route(struct snd_soc_dapm_context *dapm,
1306 const struct snd_soc_dapm_route *route) 1447 const struct snd_soc_dapm_route *route)
1307{ 1448{
1308 struct snd_soc_dapm_path *path; 1449 struct snd_soc_dapm_path *path;
1309 struct snd_soc_dapm_widget *wsource = NULL, *wsink = NULL, *w; 1450 struct snd_soc_dapm_widget *wsource = NULL, *wsink = NULL, *w;
1310 const char *sink = route->sink; 1451 struct snd_soc_dapm_widget *wtsource = NULL, *wtsink = NULL;
1452 const char *sink;
1311 const char *control = route->control; 1453 const char *control = route->control;
1312 const char *source = route->source; 1454 const char *source;
1455 char prefixed_sink[80];
1456 char prefixed_source[80];
1313 int ret = 0; 1457 int ret = 0;
1314 1458
1315 /* find src and dest widgets */ 1459 if (dapm->codec->name_prefix) {
1316 list_for_each_entry(w, &codec->dapm_widgets, list) { 1460 snprintf(prefixed_sink, sizeof(prefixed_sink), "%s %s",
1461 dapm->codec->name_prefix, route->sink);
1462 sink = prefixed_sink;
1463 snprintf(prefixed_source, sizeof(prefixed_source), "%s %s",
1464 dapm->codec->name_prefix, route->source);
1465 source = prefixed_source;
1466 } else {
1467 sink = route->sink;
1468 source = route->source;
1469 }
1317 1470
1471 /*
1472 * find src and dest widgets over all widgets but favor a widget from
1473 * current DAPM context
1474 */
1475 list_for_each_entry(w, &dapm->card->widgets, list) {
1318 if (!wsink && !(strcmp(w->name, sink))) { 1476 if (!wsink && !(strcmp(w->name, sink))) {
1319 wsink = w; 1477 wtsink = w;
1478 if (w->dapm == dapm)
1479 wsink = w;
1320 continue; 1480 continue;
1321 } 1481 }
1322 if (!wsource && !(strcmp(w->name, source))) { 1482 if (!wsource && !(strcmp(w->name, source))) {
1323 wsource = w; 1483 wtsource = w;
1484 if (w->dapm == dapm)
1485 wsource = w;
1324 } 1486 }
1325 } 1487 }
1488 /* use widget from another DAPM context if not found from this */
1489 if (!wsink)
1490 wsink = wtsink;
1491 if (!wsource)
1492 wsource = wtsource;
1326 1493
1327 if (wsource == NULL || wsink == NULL) 1494 if (wsource == NULL || wsink == NULL)
1328 return -ENODEV; 1495 return -ENODEV;
@@ -1356,7 +1523,7 @@ static int snd_soc_dapm_add_route(struct snd_soc_codec *codec,
1356 1523
1357 /* connect static paths */ 1524 /* connect static paths */
1358 if (control == NULL) { 1525 if (control == NULL) {
1359 list_add(&path->list, &codec->dapm_paths); 1526 list_add(&path->list, &dapm->card->paths);
1360 list_add(&path->list_sink, &wsink->sources); 1527 list_add(&path->list_sink, &wsink->sources);
1361 list_add(&path->list_source, &wsource->sinks); 1528 list_add(&path->list_source, &wsource->sinks);
1362 path->connect = 1; 1529 path->connect = 1;
@@ -1368,6 +1535,7 @@ static int snd_soc_dapm_add_route(struct snd_soc_codec *codec,
1368 case snd_soc_dapm_adc: 1535 case snd_soc_dapm_adc:
1369 case snd_soc_dapm_dac: 1536 case snd_soc_dapm_dac:
1370 case snd_soc_dapm_pga: 1537 case snd_soc_dapm_pga:
1538 case snd_soc_dapm_out_drv:
1371 case snd_soc_dapm_input: 1539 case snd_soc_dapm_input:
1372 case snd_soc_dapm_output: 1540 case snd_soc_dapm_output:
1373 case snd_soc_dapm_micbias: 1541 case snd_soc_dapm_micbias:
@@ -1377,14 +1545,15 @@ static int snd_soc_dapm_add_route(struct snd_soc_codec *codec,
1377 case snd_soc_dapm_supply: 1545 case snd_soc_dapm_supply:
1378 case snd_soc_dapm_aif_in: 1546 case snd_soc_dapm_aif_in:
1379 case snd_soc_dapm_aif_out: 1547 case snd_soc_dapm_aif_out:
1380 list_add(&path->list, &codec->dapm_paths); 1548 list_add(&path->list, &dapm->card->paths);
1381 list_add(&path->list_sink, &wsink->sources); 1549 list_add(&path->list_sink, &wsink->sources);
1382 list_add(&path->list_source, &wsource->sinks); 1550 list_add(&path->list_source, &wsource->sinks);
1383 path->connect = 1; 1551 path->connect = 1;
1384 return 0; 1552 return 0;
1385 case snd_soc_dapm_mux: 1553 case snd_soc_dapm_mux:
1554 case snd_soc_dapm_virt_mux:
1386 case snd_soc_dapm_value_mux: 1555 case snd_soc_dapm_value_mux:
1387 ret = dapm_connect_mux(codec, wsource, wsink, path, control, 1556 ret = dapm_connect_mux(dapm, wsource, wsink, path, control,
1388 &wsink->kcontrols[0]); 1557 &wsink->kcontrols[0]);
1389 if (ret != 0) 1558 if (ret != 0)
1390 goto err; 1559 goto err;
@@ -1392,7 +1561,7 @@ static int snd_soc_dapm_add_route(struct snd_soc_codec *codec,
1392 case snd_soc_dapm_switch: 1561 case snd_soc_dapm_switch:
1393 case snd_soc_dapm_mixer: 1562 case snd_soc_dapm_mixer:
1394 case snd_soc_dapm_mixer_named_ctl: 1563 case snd_soc_dapm_mixer_named_ctl:
1395 ret = dapm_connect_mixer(codec, wsource, wsink, path, control); 1564 ret = dapm_connect_mixer(dapm, wsource, wsink, path, control);
1396 if (ret != 0) 1565 if (ret != 0)
1397 goto err; 1566 goto err;
1398 break; 1567 break;
@@ -1400,7 +1569,7 @@ static int snd_soc_dapm_add_route(struct snd_soc_codec *codec,
1400 case snd_soc_dapm_mic: 1569 case snd_soc_dapm_mic:
1401 case snd_soc_dapm_line: 1570 case snd_soc_dapm_line:
1402 case snd_soc_dapm_spk: 1571 case snd_soc_dapm_spk:
1403 list_add(&path->list, &codec->dapm_paths); 1572 list_add(&path->list, &dapm->card->paths);
1404 list_add(&path->list_sink, &wsink->sources); 1573 list_add(&path->list_sink, &wsink->sources);
1405 list_add(&path->list_source, &wsource->sinks); 1574 list_add(&path->list_source, &wsource->sinks);
1406 path->connect = 0; 1575 path->connect = 0;
@@ -1409,15 +1578,15 @@ static int snd_soc_dapm_add_route(struct snd_soc_codec *codec,
1409 return 0; 1578 return 0;
1410 1579
1411err: 1580err:
1412 printk(KERN_WARNING "asoc: no dapm match for %s --> %s --> %s\n", source, 1581 dev_warn(dapm->dev, "asoc: no dapm match for %s --> %s --> %s\n",
1413 control, sink); 1582 source, control, sink);
1414 kfree(path); 1583 kfree(path);
1415 return ret; 1584 return ret;
1416} 1585}
1417 1586
1418/** 1587/**
1419 * snd_soc_dapm_add_routes - Add routes between DAPM widgets 1588 * snd_soc_dapm_add_routes - Add routes between DAPM widgets
1420 * @codec: codec 1589 * @dapm: DAPM context
1421 * @route: audio routes 1590 * @route: audio routes
1422 * @num: number of routes 1591 * @num: number of routes
1423 * 1592 *
@@ -1428,17 +1597,16 @@ err:
1428 * Returns 0 for success else error. On error all resources can be freed 1597 * Returns 0 for success else error. On error all resources can be freed
1429 * with a call to snd_soc_card_free(). 1598 * with a call to snd_soc_card_free().
1430 */ 1599 */
1431int snd_soc_dapm_add_routes(struct snd_soc_codec *codec, 1600int snd_soc_dapm_add_routes(struct snd_soc_dapm_context *dapm,
1432 const struct snd_soc_dapm_route *route, int num) 1601 const struct snd_soc_dapm_route *route, int num)
1433{ 1602{
1434 int i, ret; 1603 int i, ret;
1435 1604
1436 for (i = 0; i < num; i++) { 1605 for (i = 0; i < num; i++) {
1437 ret = snd_soc_dapm_add_route(codec, route); 1606 ret = snd_soc_dapm_add_route(dapm, route);
1438 if (ret < 0) { 1607 if (ret < 0) {
1439 printk(KERN_ERR "Failed to add route %s->%s\n", 1608 dev_err(dapm->dev, "Failed to add route %s->%s\n",
1440 route->source, 1609 route->source, route->sink);
1441 route->sink);
1442 return ret; 1610 return ret;
1443 } 1611 }
1444 route++; 1612 route++;
@@ -1450,17 +1618,17 @@ EXPORT_SYMBOL_GPL(snd_soc_dapm_add_routes);
1450 1618
1451/** 1619/**
1452 * snd_soc_dapm_new_widgets - add new dapm widgets 1620 * snd_soc_dapm_new_widgets - add new dapm widgets
1453 * @codec: audio codec 1621 * @dapm: DAPM context
1454 * 1622 *
1455 * Checks the codec for any new dapm widgets and creates them if found. 1623 * Checks the codec for any new dapm widgets and creates them if found.
1456 * 1624 *
1457 * Returns 0 for success. 1625 * Returns 0 for success.
1458 */ 1626 */
1459int snd_soc_dapm_new_widgets(struct snd_soc_codec *codec) 1627int snd_soc_dapm_new_widgets(struct snd_soc_dapm_context *dapm)
1460{ 1628{
1461 struct snd_soc_dapm_widget *w; 1629 struct snd_soc_dapm_widget *w;
1462 1630
1463 list_for_each_entry(w, &codec->dapm_widgets, list) 1631 list_for_each_entry(w, &dapm->card->widgets, list)
1464 { 1632 {
1465 if (w->new) 1633 if (w->new)
1466 continue; 1634 continue;
@@ -1470,12 +1638,13 @@ int snd_soc_dapm_new_widgets(struct snd_soc_codec *codec)
1470 case snd_soc_dapm_mixer: 1638 case snd_soc_dapm_mixer:
1471 case snd_soc_dapm_mixer_named_ctl: 1639 case snd_soc_dapm_mixer_named_ctl:
1472 w->power_check = dapm_generic_check_power; 1640 w->power_check = dapm_generic_check_power;
1473 dapm_new_mixer(codec, w); 1641 dapm_new_mixer(dapm, w);
1474 break; 1642 break;
1475 case snd_soc_dapm_mux: 1643 case snd_soc_dapm_mux:
1644 case snd_soc_dapm_virt_mux:
1476 case snd_soc_dapm_value_mux: 1645 case snd_soc_dapm_value_mux:
1477 w->power_check = dapm_generic_check_power; 1646 w->power_check = dapm_generic_check_power;
1478 dapm_new_mux(codec, w); 1647 dapm_new_mux(dapm, w);
1479 break; 1648 break;
1480 case snd_soc_dapm_adc: 1649 case snd_soc_dapm_adc:
1481 case snd_soc_dapm_aif_out: 1650 case snd_soc_dapm_aif_out:
@@ -1486,8 +1655,9 @@ int snd_soc_dapm_new_widgets(struct snd_soc_codec *codec)
1486 w->power_check = dapm_dac_check_power; 1655 w->power_check = dapm_dac_check_power;
1487 break; 1656 break;
1488 case snd_soc_dapm_pga: 1657 case snd_soc_dapm_pga:
1658 case snd_soc_dapm_out_drv:
1489 w->power_check = dapm_generic_check_power; 1659 w->power_check = dapm_generic_check_power;
1490 dapm_new_pga(codec, w); 1660 dapm_new_pga(dapm, w);
1491 break; 1661 break;
1492 case snd_soc_dapm_input: 1662 case snd_soc_dapm_input:
1493 case snd_soc_dapm_output: 1663 case snd_soc_dapm_output:
@@ -1508,7 +1678,7 @@ int snd_soc_dapm_new_widgets(struct snd_soc_codec *codec)
1508 w->new = 1; 1678 w->new = 1;
1509 } 1679 }
1510 1680
1511 dapm_power_widgets(codec, SND_SOC_DAPM_STREAM_NOP); 1681 dapm_power_widgets(dapm, SND_SOC_DAPM_STREAM_NOP);
1512 return 0; 1682 return 0;
1513} 1683}
1514EXPORT_SYMBOL_GPL(snd_soc_dapm_new_widgets); 1684EXPORT_SYMBOL_GPL(snd_soc_dapm_new_widgets);
@@ -1569,13 +1739,12 @@ int snd_soc_dapm_put_volsw(struct snd_kcontrol *kcontrol,
1569 (struct soc_mixer_control *)kcontrol->private_value; 1739 (struct soc_mixer_control *)kcontrol->private_value;
1570 unsigned int reg = mc->reg; 1740 unsigned int reg = mc->reg;
1571 unsigned int shift = mc->shift; 1741 unsigned int shift = mc->shift;
1572 unsigned int rshift = mc->rshift;
1573 int max = mc->max; 1742 int max = mc->max;
1574 unsigned int mask = (1 << fls(max)) - 1; 1743 unsigned int mask = (1 << fls(max)) - 1;
1575 unsigned int invert = mc->invert; 1744 unsigned int invert = mc->invert;
1576 unsigned int val, val2, val_mask; 1745 unsigned int val, val_mask;
1577 int connect; 1746 int connect, change;
1578 int ret; 1747 struct snd_soc_dapm_update update;
1579 1748
1580 val = (ucontrol->value.integer.value[0] & mask); 1749 val = (ucontrol->value.integer.value[0] & mask);
1581 1750
@@ -1583,18 +1752,12 @@ int snd_soc_dapm_put_volsw(struct snd_kcontrol *kcontrol,
1583 val = max - val; 1752 val = max - val;
1584 val_mask = mask << shift; 1753 val_mask = mask << shift;
1585 val = val << shift; 1754 val = val << shift;
1586 if (shift != rshift) {
1587 val2 = (ucontrol->value.integer.value[1] & mask);
1588 if (invert)
1589 val2 = max - val2;
1590 val_mask |= mask << rshift;
1591 val |= val2 << rshift;
1592 }
1593 1755
1594 mutex_lock(&widget->codec->mutex); 1756 mutex_lock(&widget->codec->mutex);
1595 widget->value = val; 1757 widget->value = val;
1596 1758
1597 if (snd_soc_test_bits(widget->codec, reg, val_mask, val)) { 1759 change = snd_soc_test_bits(widget->codec, reg, val_mask, val);
1760 if (change) {
1598 if (val) 1761 if (val)
1599 /* new connection */ 1762 /* new connection */
1600 connect = invert ? 0:1; 1763 connect = invert ? 0:1;
@@ -1602,28 +1765,20 @@ int snd_soc_dapm_put_volsw(struct snd_kcontrol *kcontrol,
1602 /* old connection must be powered down */ 1765 /* old connection must be powered down */
1603 connect = invert ? 1:0; 1766 connect = invert ? 1:0;
1604 1767
1768 update.kcontrol = kcontrol;
1769 update.widget = widget;
1770 update.reg = reg;
1771 update.mask = mask;
1772 update.val = val;
1773 widget->dapm->update = &update;
1774
1605 dapm_mixer_update_power(widget, kcontrol, connect); 1775 dapm_mixer_update_power(widget, kcontrol, connect);
1776
1777 widget->dapm->update = NULL;
1606 } 1778 }
1607 1779
1608 if (widget->event) {
1609 if (widget->event_flags & SND_SOC_DAPM_PRE_REG) {
1610 ret = widget->event(widget, kcontrol,
1611 SND_SOC_DAPM_PRE_REG);
1612 if (ret < 0) {
1613 ret = 1;
1614 goto out;
1615 }
1616 }
1617 ret = snd_soc_update_bits(widget->codec, reg, val_mask, val);
1618 if (widget->event_flags & SND_SOC_DAPM_POST_REG)
1619 ret = widget->event(widget, kcontrol,
1620 SND_SOC_DAPM_POST_REG);
1621 } else
1622 ret = snd_soc_update_bits(widget->codec, reg, val_mask, val);
1623
1624out:
1625 mutex_unlock(&widget->codec->mutex); 1780 mutex_unlock(&widget->codec->mutex);
1626 return ret; 1781 return 0;
1627} 1782}
1628EXPORT_SYMBOL_GPL(snd_soc_dapm_put_volsw); 1783EXPORT_SYMBOL_GPL(snd_soc_dapm_put_volsw);
1629 1784
@@ -1671,7 +1826,7 @@ int snd_soc_dapm_put_enum_double(struct snd_kcontrol *kcontrol,
1671 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value; 1826 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
1672 unsigned int val, mux, change; 1827 unsigned int val, mux, change;
1673 unsigned int mask, bitmask; 1828 unsigned int mask, bitmask;
1674 int ret = 0; 1829 struct snd_soc_dapm_update update;
1675 1830
1676 for (bitmask = 1; bitmask < e->max; bitmask <<= 1) 1831 for (bitmask = 1; bitmask < e->max; bitmask <<= 1)
1677 ; 1832 ;
@@ -1690,24 +1845,20 @@ int snd_soc_dapm_put_enum_double(struct snd_kcontrol *kcontrol,
1690 mutex_lock(&widget->codec->mutex); 1845 mutex_lock(&widget->codec->mutex);
1691 widget->value = val; 1846 widget->value = val;
1692 change = snd_soc_test_bits(widget->codec, e->reg, mask, val); 1847 change = snd_soc_test_bits(widget->codec, e->reg, mask, val);
1693 dapm_mux_update_power(widget, kcontrol, change, mux, e);
1694 1848
1695 if (widget->event_flags & SND_SOC_DAPM_PRE_REG) { 1849 update.kcontrol = kcontrol;
1696 ret = widget->event(widget, 1850 update.widget = widget;
1697 kcontrol, SND_SOC_DAPM_PRE_REG); 1851 update.reg = e->reg;
1698 if (ret < 0) 1852 update.mask = mask;
1699 goto out; 1853 update.val = val;
1700 } 1854 widget->dapm->update = &update;
1701 1855
1702 ret = snd_soc_update_bits(widget->codec, e->reg, mask, val); 1856 dapm_mux_update_power(widget, kcontrol, change, mux, e);
1703 1857
1704 if (widget->event_flags & SND_SOC_DAPM_POST_REG) 1858 widget->dapm->update = NULL;
1705 ret = widget->event(widget,
1706 kcontrol, SND_SOC_DAPM_POST_REG);
1707 1859
1708out:
1709 mutex_unlock(&widget->codec->mutex); 1860 mutex_unlock(&widget->codec->mutex);
1710 return ret; 1861 return change;
1711} 1862}
1712EXPORT_SYMBOL_GPL(snd_soc_dapm_put_enum_double); 1863EXPORT_SYMBOL_GPL(snd_soc_dapm_put_enum_double);
1713 1864
@@ -1819,7 +1970,7 @@ int snd_soc_dapm_put_value_enum_double(struct snd_kcontrol *kcontrol,
1819 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value; 1970 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
1820 unsigned int val, mux, change; 1971 unsigned int val, mux, change;
1821 unsigned int mask; 1972 unsigned int mask;
1822 int ret = 0; 1973 struct snd_soc_dapm_update update;
1823 1974
1824 if (ucontrol->value.enumerated.item[0] > e->max - 1) 1975 if (ucontrol->value.enumerated.item[0] > e->max - 1)
1825 return -EINVAL; 1976 return -EINVAL;
@@ -1836,24 +1987,20 @@ int snd_soc_dapm_put_value_enum_double(struct snd_kcontrol *kcontrol,
1836 mutex_lock(&widget->codec->mutex); 1987 mutex_lock(&widget->codec->mutex);
1837 widget->value = val; 1988 widget->value = val;
1838 change = snd_soc_test_bits(widget->codec, e->reg, mask, val); 1989 change = snd_soc_test_bits(widget->codec, e->reg, mask, val);
1839 dapm_mux_update_power(widget, kcontrol, change, mux, e);
1840 1990
1841 if (widget->event_flags & SND_SOC_DAPM_PRE_REG) { 1991 update.kcontrol = kcontrol;
1842 ret = widget->event(widget, 1992 update.widget = widget;
1843 kcontrol, SND_SOC_DAPM_PRE_REG); 1993 update.reg = e->reg;
1844 if (ret < 0) 1994 update.mask = mask;
1845 goto out; 1995 update.val = val;
1846 } 1996 widget->dapm->update = &update;
1847 1997
1848 ret = snd_soc_update_bits(widget->codec, e->reg, mask, val); 1998 dapm_mux_update_power(widget, kcontrol, change, mux, e);
1849 1999
1850 if (widget->event_flags & SND_SOC_DAPM_POST_REG) 2000 widget->dapm->update = NULL;
1851 ret = widget->event(widget,
1852 kcontrol, SND_SOC_DAPM_POST_REG);
1853 2001
1854out:
1855 mutex_unlock(&widget->codec->mutex); 2002 mutex_unlock(&widget->codec->mutex);
1856 return ret; 2003 return change;
1857} 2004}
1858EXPORT_SYMBOL_GPL(snd_soc_dapm_put_value_enum_double); 2005EXPORT_SYMBOL_GPL(snd_soc_dapm_put_value_enum_double);
1859 2006
@@ -1892,7 +2039,7 @@ int snd_soc_dapm_get_pin_switch(struct snd_kcontrol *kcontrol,
1892 mutex_lock(&codec->mutex); 2039 mutex_lock(&codec->mutex);
1893 2040
1894 ucontrol->value.integer.value[0] = 2041 ucontrol->value.integer.value[0] =
1895 snd_soc_dapm_get_pin_status(codec, pin); 2042 snd_soc_dapm_get_pin_status(&codec->dapm, pin);
1896 2043
1897 mutex_unlock(&codec->mutex); 2044 mutex_unlock(&codec->mutex);
1898 2045
@@ -1915,11 +2062,11 @@ int snd_soc_dapm_put_pin_switch(struct snd_kcontrol *kcontrol,
1915 mutex_lock(&codec->mutex); 2062 mutex_lock(&codec->mutex);
1916 2063
1917 if (ucontrol->value.integer.value[0]) 2064 if (ucontrol->value.integer.value[0])
1918 snd_soc_dapm_enable_pin(codec, pin); 2065 snd_soc_dapm_enable_pin(&codec->dapm, pin);
1919 else 2066 else
1920 snd_soc_dapm_disable_pin(codec, pin); 2067 snd_soc_dapm_disable_pin(&codec->dapm, pin);
1921 2068
1922 snd_soc_dapm_sync(codec); 2069 snd_soc_dapm_sync(&codec->dapm);
1923 2070
1924 mutex_unlock(&codec->mutex); 2071 mutex_unlock(&codec->mutex);
1925 2072
@@ -1929,26 +2076,43 @@ EXPORT_SYMBOL_GPL(snd_soc_dapm_put_pin_switch);
1929 2076
1930/** 2077/**
1931 * snd_soc_dapm_new_control - create new dapm control 2078 * snd_soc_dapm_new_control - create new dapm control
1932 * @codec: audio codec 2079 * @dapm: DAPM context
1933 * @widget: widget template 2080 * @widget: widget template
1934 * 2081 *
1935 * Creates a new dapm control based upon the template. 2082 * Creates a new dapm control based upon the template.
1936 * 2083 *
1937 * Returns 0 for success else error. 2084 * Returns 0 for success else error.
1938 */ 2085 */
1939int snd_soc_dapm_new_control(struct snd_soc_codec *codec, 2086int snd_soc_dapm_new_control(struct snd_soc_dapm_context *dapm,
1940 const struct snd_soc_dapm_widget *widget) 2087 const struct snd_soc_dapm_widget *widget)
1941{ 2088{
1942 struct snd_soc_dapm_widget *w; 2089 struct snd_soc_dapm_widget *w;
2090 size_t name_len;
1943 2091
1944 if ((w = dapm_cnew_widget(widget)) == NULL) 2092 if ((w = dapm_cnew_widget(widget)) == NULL)
1945 return -ENOMEM; 2093 return -ENOMEM;
1946 2094
1947 w->codec = codec; 2095 name_len = strlen(widget->name) + 1;
2096 if (dapm->codec->name_prefix)
2097 name_len += 1 + strlen(dapm->codec->name_prefix);
2098 w->name = kmalloc(name_len, GFP_KERNEL);
2099 if (w->name == NULL) {
2100 kfree(w);
2101 return -ENOMEM;
2102 }
2103 if (dapm->codec->name_prefix)
2104 snprintf(w->name, name_len, "%s %s",
2105 dapm->codec->name_prefix, widget->name);
2106 else
2107 snprintf(w->name, name_len, "%s", widget->name);
2108
2109 dapm->n_widgets++;
2110 w->dapm = dapm;
2111 w->codec = dapm->codec;
1948 INIT_LIST_HEAD(&w->sources); 2112 INIT_LIST_HEAD(&w->sources);
1949 INIT_LIST_HEAD(&w->sinks); 2113 INIT_LIST_HEAD(&w->sinks);
1950 INIT_LIST_HEAD(&w->list); 2114 INIT_LIST_HEAD(&w->list);
1951 list_add(&w->list, &codec->dapm_widgets); 2115 list_add(&w->list, &dapm->card->widgets);
1952 2116
1953 /* machine layer set ups unconnected pins and insertions */ 2117 /* machine layer set ups unconnected pins and insertions */
1954 w->connected = 1; 2118 w->connected = 1;
@@ -1958,7 +2122,7 @@ EXPORT_SYMBOL_GPL(snd_soc_dapm_new_control);
1958 2122
1959/** 2123/**
1960 * snd_soc_dapm_new_controls - create new dapm controls 2124 * snd_soc_dapm_new_controls - create new dapm controls
1961 * @codec: audio codec 2125 * @dapm: DAPM context
1962 * @widget: widget array 2126 * @widget: widget array
1963 * @num: number of widgets 2127 * @num: number of widgets
1964 * 2128 *
@@ -1966,18 +2130,18 @@ EXPORT_SYMBOL_GPL(snd_soc_dapm_new_control);
1966 * 2130 *
1967 * Returns 0 for success else error. 2131 * Returns 0 for success else error.
1968 */ 2132 */
1969int snd_soc_dapm_new_controls(struct snd_soc_codec *codec, 2133int snd_soc_dapm_new_controls(struct snd_soc_dapm_context *dapm,
1970 const struct snd_soc_dapm_widget *widget, 2134 const struct snd_soc_dapm_widget *widget,
1971 int num) 2135 int num)
1972{ 2136{
1973 int i, ret; 2137 int i, ret;
1974 2138
1975 for (i = 0; i < num; i++) { 2139 for (i = 0; i < num; i++) {
1976 ret = snd_soc_dapm_new_control(codec, widget); 2140 ret = snd_soc_dapm_new_control(dapm, widget);
1977 if (ret < 0) { 2141 if (ret < 0) {
1978 printk(KERN_ERR 2142 dev_err(dapm->dev,
1979 "ASoC: Failed to create DAPM control %s: %d\n", 2143 "ASoC: Failed to create DAPM control %s: %d\n",
1980 widget->name, ret); 2144 widget->name, ret);
1981 return ret; 2145 return ret;
1982 } 2146 }
1983 widget++; 2147 widget++;
@@ -1986,34 +2150,17 @@ int snd_soc_dapm_new_controls(struct snd_soc_codec *codec,
1986} 2150}
1987EXPORT_SYMBOL_GPL(snd_soc_dapm_new_controls); 2151EXPORT_SYMBOL_GPL(snd_soc_dapm_new_controls);
1988 2152
1989 2153static void soc_dapm_stream_event(struct snd_soc_dapm_context *dapm,
1990/**
1991 * snd_soc_dapm_stream_event - send a stream event to the dapm core
1992 * @codec: audio codec
1993 * @stream: stream name
1994 * @event: stream event
1995 *
1996 * Sends a stream event to the dapm core. The core then makes any
1997 * necessary widget power changes.
1998 *
1999 * Returns 0 for success else error.
2000 */
2001int snd_soc_dapm_stream_event(struct snd_soc_pcm_runtime *rtd,
2002 const char *stream, int event) 2154 const char *stream, int event)
2003{ 2155{
2004 struct snd_soc_codec *codec = rtd->codec;
2005 struct snd_soc_dapm_widget *w; 2156 struct snd_soc_dapm_widget *w;
2006 2157
2007 if (stream == NULL) 2158 list_for_each_entry(w, &dapm->card->widgets, list)
2008 return 0;
2009
2010 mutex_lock(&codec->mutex);
2011 list_for_each_entry(w, &codec->dapm_widgets, list)
2012 { 2159 {
2013 if (!w->sname) 2160 if (!w->sname || w->dapm != dapm)
2014 continue; 2161 continue;
2015 pr_debug("widget %s\n %s stream %s event %d\n", 2162 dev_dbg(w->dapm->dev, "widget %s\n %s stream %s event %d\n",
2016 w->name, w->sname, stream, event); 2163 w->name, w->sname, stream, event);
2017 if (strstr(w->sname, stream)) { 2164 if (strstr(w->sname, stream)) {
2018 switch(event) { 2165 switch(event) {
2019 case SND_SOC_DAPM_STREAM_START: 2166 case SND_SOC_DAPM_STREAM_START:
@@ -2031,7 +2178,30 @@ int snd_soc_dapm_stream_event(struct snd_soc_pcm_runtime *rtd,
2031 } 2178 }
2032 } 2179 }
2033 2180
2034 dapm_power_widgets(codec, event); 2181 dapm_power_widgets(dapm, event);
2182}
2183
2184/**
2185 * snd_soc_dapm_stream_event - send a stream event to the dapm core
2186 * @rtd: PCM runtime data
2187 * @stream: stream name
2188 * @event: stream event
2189 *
2190 * Sends a stream event to the dapm core. The core then makes any
2191 * necessary widget power changes.
2192 *
2193 * Returns 0 for success else error.
2194 */
2195int snd_soc_dapm_stream_event(struct snd_soc_pcm_runtime *rtd,
2196 const char *stream, int event)
2197{
2198 struct snd_soc_codec *codec = rtd->codec;
2199
2200 if (stream == NULL)
2201 return 0;
2202
2203 mutex_lock(&codec->mutex);
2204 soc_dapm_stream_event(&codec->dapm, stream, event);
2035 mutex_unlock(&codec->mutex); 2205 mutex_unlock(&codec->mutex);
2036 return 0; 2206 return 0;
2037} 2207}
@@ -2039,7 +2209,7 @@ EXPORT_SYMBOL_GPL(snd_soc_dapm_stream_event);
2039 2209
2040/** 2210/**
2041 * snd_soc_dapm_enable_pin - enable pin. 2211 * snd_soc_dapm_enable_pin - enable pin.
2042 * @codec: SoC codec 2212 * @dapm: DAPM context
2043 * @pin: pin name 2213 * @pin: pin name
2044 * 2214 *
2045 * Enables input/output pin and its parents or children widgets iff there is 2215 * Enables input/output pin and its parents or children widgets iff there is
@@ -2047,15 +2217,15 @@ EXPORT_SYMBOL_GPL(snd_soc_dapm_stream_event);
2047 * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to 2217 * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to
2048 * do any widget power switching. 2218 * do any widget power switching.
2049 */ 2219 */
2050int snd_soc_dapm_enable_pin(struct snd_soc_codec *codec, const char *pin) 2220int snd_soc_dapm_enable_pin(struct snd_soc_dapm_context *dapm, const char *pin)
2051{ 2221{
2052 return snd_soc_dapm_set_pin(codec, pin, 1); 2222 return snd_soc_dapm_set_pin(dapm, pin, 1);
2053} 2223}
2054EXPORT_SYMBOL_GPL(snd_soc_dapm_enable_pin); 2224EXPORT_SYMBOL_GPL(snd_soc_dapm_enable_pin);
2055 2225
2056/** 2226/**
2057 * snd_soc_dapm_force_enable_pin - force a pin to be enabled 2227 * snd_soc_dapm_force_enable_pin - force a pin to be enabled
2058 * @codec: SoC codec 2228 * @dapm: DAPM context
2059 * @pin: pin name 2229 * @pin: pin name
2060 * 2230 *
2061 * Enables input/output pin regardless of any other state. This is 2231 * Enables input/output pin regardless of any other state. This is
@@ -2065,42 +2235,47 @@ EXPORT_SYMBOL_GPL(snd_soc_dapm_enable_pin);
2065 * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to 2235 * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to
2066 * do any widget power switching. 2236 * do any widget power switching.
2067 */ 2237 */
2068int snd_soc_dapm_force_enable_pin(struct snd_soc_codec *codec, const char *pin) 2238int snd_soc_dapm_force_enable_pin(struct snd_soc_dapm_context *dapm,
2239 const char *pin)
2069{ 2240{
2070 struct snd_soc_dapm_widget *w; 2241 struct snd_soc_dapm_widget *w;
2071 2242
2072 list_for_each_entry(w, &codec->dapm_widgets, list) { 2243 list_for_each_entry(w, &dapm->card->widgets, list) {
2244 if (w->dapm != dapm)
2245 continue;
2073 if (!strcmp(w->name, pin)) { 2246 if (!strcmp(w->name, pin)) {
2074 pr_debug("dapm: %s: pin %s\n", codec->name, pin); 2247 dev_dbg(w->dapm->dev,
2248 "dapm: force enable pin %s\n", pin);
2075 w->connected = 1; 2249 w->connected = 1;
2076 w->force = 1; 2250 w->force = 1;
2077 return 0; 2251 return 0;
2078 } 2252 }
2079 } 2253 }
2080 2254
2081 pr_err("dapm: %s: configuring unknown pin %s\n", codec->name, pin); 2255 dev_err(dapm->dev, "dapm: unknown pin %s\n", pin);
2082 return -EINVAL; 2256 return -EINVAL;
2083} 2257}
2084EXPORT_SYMBOL_GPL(snd_soc_dapm_force_enable_pin); 2258EXPORT_SYMBOL_GPL(snd_soc_dapm_force_enable_pin);
2085 2259
2086/** 2260/**
2087 * snd_soc_dapm_disable_pin - disable pin. 2261 * snd_soc_dapm_disable_pin - disable pin.
2088 * @codec: SoC codec 2262 * @dapm: DAPM context
2089 * @pin: pin name 2263 * @pin: pin name
2090 * 2264 *
2091 * Disables input/output pin and its parents or children widgets. 2265 * Disables input/output pin and its parents or children widgets.
2092 * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to 2266 * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to
2093 * do any widget power switching. 2267 * do any widget power switching.
2094 */ 2268 */
2095int snd_soc_dapm_disable_pin(struct snd_soc_codec *codec, const char *pin) 2269int snd_soc_dapm_disable_pin(struct snd_soc_dapm_context *dapm,
2270 const char *pin)
2096{ 2271{
2097 return snd_soc_dapm_set_pin(codec, pin, 0); 2272 return snd_soc_dapm_set_pin(dapm, pin, 0);
2098} 2273}
2099EXPORT_SYMBOL_GPL(snd_soc_dapm_disable_pin); 2274EXPORT_SYMBOL_GPL(snd_soc_dapm_disable_pin);
2100 2275
2101/** 2276/**
2102 * snd_soc_dapm_nc_pin - permanently disable pin. 2277 * snd_soc_dapm_nc_pin - permanently disable pin.
2103 * @codec: SoC codec 2278 * @dapm: DAPM context
2104 * @pin: pin name 2279 * @pin: pin name
2105 * 2280 *
2106 * Marks the specified pin as being not connected, disabling it along 2281 * Marks the specified pin as being not connected, disabling it along
@@ -2112,26 +2287,29 @@ EXPORT_SYMBOL_GPL(snd_soc_dapm_disable_pin);
2112 * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to 2287 * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to
2113 * do any widget power switching. 2288 * do any widget power switching.
2114 */ 2289 */
2115int snd_soc_dapm_nc_pin(struct snd_soc_codec *codec, const char *pin) 2290int snd_soc_dapm_nc_pin(struct snd_soc_dapm_context *dapm, const char *pin)
2116{ 2291{
2117 return snd_soc_dapm_set_pin(codec, pin, 0); 2292 return snd_soc_dapm_set_pin(dapm, pin, 0);
2118} 2293}
2119EXPORT_SYMBOL_GPL(snd_soc_dapm_nc_pin); 2294EXPORT_SYMBOL_GPL(snd_soc_dapm_nc_pin);
2120 2295
2121/** 2296/**
2122 * snd_soc_dapm_get_pin_status - get audio pin status 2297 * snd_soc_dapm_get_pin_status - get audio pin status
2123 * @codec: audio codec 2298 * @dapm: DAPM context
2124 * @pin: audio signal pin endpoint (or start point) 2299 * @pin: audio signal pin endpoint (or start point)
2125 * 2300 *
2126 * Get audio pin status - connected or disconnected. 2301 * Get audio pin status - connected or disconnected.
2127 * 2302 *
2128 * Returns 1 for connected otherwise 0. 2303 * Returns 1 for connected otherwise 0.
2129 */ 2304 */
2130int snd_soc_dapm_get_pin_status(struct snd_soc_codec *codec, const char *pin) 2305int snd_soc_dapm_get_pin_status(struct snd_soc_dapm_context *dapm,
2306 const char *pin)
2131{ 2307{
2132 struct snd_soc_dapm_widget *w; 2308 struct snd_soc_dapm_widget *w;
2133 2309
2134 list_for_each_entry(w, &codec->dapm_widgets, list) { 2310 list_for_each_entry(w, &dapm->card->widgets, list) {
2311 if (w->dapm != dapm)
2312 continue;
2135 if (!strcmp(w->name, pin)) 2313 if (!strcmp(w->name, pin))
2136 return w->connected; 2314 return w->connected;
2137 } 2315 }
@@ -2142,7 +2320,7 @@ EXPORT_SYMBOL_GPL(snd_soc_dapm_get_pin_status);
2142 2320
2143/** 2321/**
2144 * snd_soc_dapm_ignore_suspend - ignore suspend status for DAPM endpoint 2322 * snd_soc_dapm_ignore_suspend - ignore suspend status for DAPM endpoint
2145 * @codec: audio codec 2323 * @dapm: DAPM context
2146 * @pin: audio signal pin endpoint (or start point) 2324 * @pin: audio signal pin endpoint (or start point)
2147 * 2325 *
2148 * Mark the given endpoint or pin as ignoring suspend. When the 2326 * Mark the given endpoint or pin as ignoring suspend. When the
@@ -2151,18 +2329,21 @@ EXPORT_SYMBOL_GPL(snd_soc_dapm_get_pin_status);
2151 * normal means at suspend time, it will not be turned on if it was not 2329 * normal means at suspend time, it will not be turned on if it was not
2152 * already enabled. 2330 * already enabled.
2153 */ 2331 */
2154int snd_soc_dapm_ignore_suspend(struct snd_soc_codec *codec, const char *pin) 2332int snd_soc_dapm_ignore_suspend(struct snd_soc_dapm_context *dapm,
2333 const char *pin)
2155{ 2334{
2156 struct snd_soc_dapm_widget *w; 2335 struct snd_soc_dapm_widget *w;
2157 2336
2158 list_for_each_entry(w, &codec->dapm_widgets, list) { 2337 list_for_each_entry(w, &dapm->card->widgets, list) {
2338 if (w->dapm != dapm)
2339 continue;
2159 if (!strcmp(w->name, pin)) { 2340 if (!strcmp(w->name, pin)) {
2160 w->ignore_suspend = 1; 2341 w->ignore_suspend = 1;
2161 return 0; 2342 return 0;
2162 } 2343 }
2163 } 2344 }
2164 2345
2165 pr_err("Unknown DAPM pin: %s\n", pin); 2346 dev_err(dapm->dev, "dapm: unknown pin %s\n", pin);
2166 return -EINVAL; 2347 return -EINVAL;
2167} 2348}
2168EXPORT_SYMBOL_GPL(snd_soc_dapm_ignore_suspend); 2349EXPORT_SYMBOL_GPL(snd_soc_dapm_ignore_suspend);
@@ -2173,20 +2354,23 @@ EXPORT_SYMBOL_GPL(snd_soc_dapm_ignore_suspend);
2173 * 2354 *
2174 * Free all dapm widgets and resources. 2355 * Free all dapm widgets and resources.
2175 */ 2356 */
2176void snd_soc_dapm_free(struct snd_soc_codec *codec) 2357void snd_soc_dapm_free(struct snd_soc_dapm_context *dapm)
2177{ 2358{
2178 snd_soc_dapm_sys_remove(codec->dev); 2359 snd_soc_dapm_sys_remove(dapm->dev);
2179 dapm_free_widgets(codec); 2360 dapm_free_widgets(dapm);
2361 list_del(&dapm->list);
2180} 2362}
2181EXPORT_SYMBOL_GPL(snd_soc_dapm_free); 2363EXPORT_SYMBOL_GPL(snd_soc_dapm_free);
2182 2364
2183static void soc_dapm_shutdown_codec(struct snd_soc_codec *codec) 2365static void soc_dapm_shutdown_codec(struct snd_soc_dapm_context *dapm)
2184{ 2366{
2185 struct snd_soc_dapm_widget *w; 2367 struct snd_soc_dapm_widget *w;
2186 LIST_HEAD(down_list); 2368 LIST_HEAD(down_list);
2187 int powerdown = 0; 2369 int powerdown = 0;
2188 2370
2189 list_for_each_entry(w, &codec->dapm_widgets, list) { 2371 list_for_each_entry(w, &dapm->card->widgets, list) {
2372 if (w->dapm != dapm)
2373 continue;
2190 if (w->power) { 2374 if (w->power) {
2191 dapm_seq_insert(w, &down_list, dapm_down_seq); 2375 dapm_seq_insert(w, &down_list, dapm_down_seq);
2192 w->power = 0; 2376 w->power = 0;
@@ -2198,9 +2382,9 @@ static void soc_dapm_shutdown_codec(struct snd_soc_codec *codec)
2198 * standby. 2382 * standby.
2199 */ 2383 */
2200 if (powerdown) { 2384 if (powerdown) {
2201 snd_soc_dapm_set_bias_level(NULL, codec, SND_SOC_BIAS_PREPARE); 2385 snd_soc_dapm_set_bias_level(NULL, dapm, SND_SOC_BIAS_PREPARE);
2202 dapm_seq_run(codec, &down_list, 0, dapm_down_seq); 2386 dapm_seq_run(dapm, &down_list, 0, dapm_down_seq);
2203 snd_soc_dapm_set_bias_level(NULL, codec, SND_SOC_BIAS_STANDBY); 2387 snd_soc_dapm_set_bias_level(NULL, dapm, SND_SOC_BIAS_STANDBY);
2204 } 2388 }
2205} 2389}
2206 2390
@@ -2211,10 +2395,10 @@ void snd_soc_dapm_shutdown(struct snd_soc_card *card)
2211{ 2395{
2212 struct snd_soc_codec *codec; 2396 struct snd_soc_codec *codec;
2213 2397
2214 list_for_each_entry(codec, &card->codec_dev_list, list) 2398 list_for_each_entry(codec, &card->codec_dev_list, list) {
2215 soc_dapm_shutdown_codec(codec); 2399 soc_dapm_shutdown_codec(&codec->dapm);
2216 2400 snd_soc_dapm_set_bias_level(card, &codec->dapm, SND_SOC_BIAS_OFF);
2217 snd_soc_dapm_set_bias_level(card, codec, SND_SOC_BIAS_OFF); 2401 }
2218} 2402}
2219 2403
2220/* Module information */ 2404/* Module information */
diff --git a/sound/soc/soc-jack.c b/sound/soc/soc-jack.c
index 8a0a9205b1e7..ac5a5bc7375a 100644
--- a/sound/soc/soc-jack.c
+++ b/sound/soc/soc-jack.c
@@ -13,11 +13,11 @@
13 13
14#include <sound/jack.h> 14#include <sound/jack.h>
15#include <sound/soc.h> 15#include <sound/soc.h>
16#include <sound/soc-dapm.h>
17#include <linux/gpio.h> 16#include <linux/gpio.h>
18#include <linux/interrupt.h> 17#include <linux/interrupt.h>
19#include <linux/workqueue.h> 18#include <linux/workqueue.h>
20#include <linux/delay.h> 19#include <linux/delay.h>
20#include <trace/events/asoc.h>
21 21
22/** 22/**
23 * snd_soc_jack_new - Create a new jack 23 * snd_soc_jack_new - Create a new jack
@@ -60,14 +60,18 @@ EXPORT_SYMBOL_GPL(snd_soc_jack_new);
60void snd_soc_jack_report(struct snd_soc_jack *jack, int status, int mask) 60void snd_soc_jack_report(struct snd_soc_jack *jack, int status, int mask)
61{ 61{
62 struct snd_soc_codec *codec; 62 struct snd_soc_codec *codec;
63 struct snd_soc_dapm_context *dapm;
63 struct snd_soc_jack_pin *pin; 64 struct snd_soc_jack_pin *pin;
64 int enable; 65 int enable;
65 int oldstatus; 66 int oldstatus;
66 67
68 trace_snd_soc_jack_report(jack, mask, status);
69
67 if (!jack) 70 if (!jack)
68 return; 71 return;
69 72
70 codec = jack->codec; 73 codec = jack->codec;
74 dapm = &codec->dapm;
71 75
72 mutex_lock(&codec->mutex); 76 mutex_lock(&codec->mutex);
73 77
@@ -81,6 +85,8 @@ void snd_soc_jack_report(struct snd_soc_jack *jack, int status, int mask)
81 if (mask && (jack->status == oldstatus)) 85 if (mask && (jack->status == oldstatus))
82 goto out; 86 goto out;
83 87
88 trace_snd_soc_jack_notify(jack, status);
89
84 list_for_each_entry(pin, &jack->pins, list) { 90 list_for_each_entry(pin, &jack->pins, list) {
85 enable = pin->mask & jack->status; 91 enable = pin->mask & jack->status;
86 92
@@ -88,15 +94,15 @@ void snd_soc_jack_report(struct snd_soc_jack *jack, int status, int mask)
88 enable = !enable; 94 enable = !enable;
89 95
90 if (enable) 96 if (enable)
91 snd_soc_dapm_enable_pin(codec, pin->pin); 97 snd_soc_dapm_enable_pin(dapm, pin->pin);
92 else 98 else
93 snd_soc_dapm_disable_pin(codec, pin->pin); 99 snd_soc_dapm_disable_pin(dapm, pin->pin);
94 } 100 }
95 101
96 /* Report before the DAPM sync to help users updating micbias status */ 102 /* Report before the DAPM sync to help users updating micbias status */
97 blocking_notifier_call_chain(&jack->notifier, status, NULL); 103 blocking_notifier_call_chain(&jack->notifier, status, NULL);
98 104
99 snd_soc_dapm_sync(codec); 105 snd_soc_dapm_sync(dapm);
100 106
101 snd_jack_report(jack->jack, status); 107 snd_jack_report(jack->jack, status);
102 108
@@ -207,6 +213,12 @@ static void snd_soc_jack_gpio_detect(struct snd_soc_jack_gpio *gpio)
207static irqreturn_t gpio_handler(int irq, void *data) 213static irqreturn_t gpio_handler(int irq, void *data)
208{ 214{
209 struct snd_soc_jack_gpio *gpio = data; 215 struct snd_soc_jack_gpio *gpio = data;
216 struct device *dev = gpio->jack->codec->card->dev;
217
218 trace_snd_soc_jack_irq(gpio->name);
219
220 if (device_may_wakeup(dev))
221 pm_wakeup_event(dev, gpio->debounce_time + 50);
210 222
211 schedule_delayed_work(&gpio->work, 223 schedule_delayed_work(&gpio->work,
212 msecs_to_jiffies(gpio->debounce_time)); 224 msecs_to_jiffies(gpio->debounce_time));
@@ -263,11 +275,12 @@ int snd_soc_jack_add_gpios(struct snd_soc_jack *jack, int count,
263 INIT_DELAYED_WORK(&gpios[i].work, gpio_work); 275 INIT_DELAYED_WORK(&gpios[i].work, gpio_work);
264 gpios[i].jack = jack; 276 gpios[i].jack = jack;
265 277
266 ret = request_irq(gpio_to_irq(gpios[i].gpio), 278 ret = request_any_context_irq(gpio_to_irq(gpios[i].gpio),
267 gpio_handler, 279 gpio_handler,
268 IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING, 280 IRQF_TRIGGER_RISING |
269 jack->codec->dev->driver->name, 281 IRQF_TRIGGER_FALLING,
270 &gpios[i]); 282 jack->codec->dev->driver->name,
283 &gpios[i]);
271 if (ret) 284 if (ret)
272 goto err; 285 goto err;
273 286
diff --git a/sound/usb/format.c b/sound/usb/format.c
index 69148212aa70..5b792d2c8061 100644
--- a/sound/usb/format.c
+++ b/sound/usb/format.c
@@ -76,7 +76,10 @@ static u64 parse_audio_format_i_type(struct snd_usb_audio *chip,
76 format = 1 << UAC_FORMAT_TYPE_I_PCM; 76 format = 1 << UAC_FORMAT_TYPE_I_PCM;
77 } 77 }
78 if (format & (1 << UAC_FORMAT_TYPE_I_PCM)) { 78 if (format & (1 << UAC_FORMAT_TYPE_I_PCM)) {
79 if (sample_width > sample_bytes * 8) { 79 if (chip->usb_id == USB_ID(0x0582, 0x0016) /* Edirol SD-90 */ &&
80 sample_width == 24 && sample_bytes == 2)
81 sample_bytes = 3;
82 else if (sample_width > sample_bytes * 8) {
80 snd_printk(KERN_INFO "%d:%u:%d : sample bitwidth %d in over sample bytes %d\n", 83 snd_printk(KERN_INFO "%d:%u:%d : sample bitwidth %d in over sample bytes %d\n",
81 chip->dev->devnum, fp->iface, fp->altsetting, 84 chip->dev->devnum, fp->iface, fp->altsetting,
82 sample_width, sample_bytes); 85 sample_width, sample_bytes);
diff --git a/sound/usb/midi.c b/sound/usb/midi.c
index 25bce7e5b1af..db2dc5ffe6dd 100644
--- a/sound/usb/midi.c
+++ b/sound/usb/midi.c
@@ -850,8 +850,8 @@ static void snd_usbmidi_us122l_output(struct snd_usb_midi_out_endpoint *ep,
850 return; 850 return;
851 } 851 }
852 852
853 memset(urb->transfer_buffer + count, 0xFD, 9 - count); 853 memset(urb->transfer_buffer + count, 0xFD, ep->max_transfer - count);
854 urb->transfer_buffer_length = count; 854 urb->transfer_buffer_length = ep->max_transfer;
855} 855}
856 856
857static struct usb_protocol_ops snd_usbmidi_122l_ops = { 857static struct usb_protocol_ops snd_usbmidi_122l_ops = {
@@ -1295,6 +1295,13 @@ static int snd_usbmidi_out_endpoint_create(struct snd_usb_midi* umidi,
1295 case USB_ID(0x1a86, 0x752d): /* QinHeng CH345 "USB2.0-MIDI" */ 1295 case USB_ID(0x1a86, 0x752d): /* QinHeng CH345 "USB2.0-MIDI" */
1296 ep->max_transfer = 4; 1296 ep->max_transfer = 4;
1297 break; 1297 break;
1298 /*
1299 * Some devices only work with 9 bytes packet size:
1300 */
1301 case USB_ID(0x0644, 0x800E): /* Tascam US-122L */
1302 case USB_ID(0x0644, 0x800F): /* Tascam US-144 */
1303 ep->max_transfer = 9;
1304 break;
1298 } 1305 }
1299 for (i = 0; i < OUTPUT_URBS; ++i) { 1306 for (i = 0; i < OUTPUT_URBS; ++i) {
1300 buffer = usb_alloc_coherent(umidi->dev, 1307 buffer = usb_alloc_coherent(umidi->dev,
@@ -1729,13 +1736,7 @@ static int roland_load_info(struct snd_kcontrol *kcontrol,
1729{ 1736{
1730 static const char *const names[] = { "High Load", "Light Load" }; 1737 static const char *const names[] = { "High Load", "Light Load" };
1731 1738
1732 info->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; 1739 return snd_ctl_enum_info(info, 1, 2, names);
1733 info->count = 1;
1734 info->value.enumerated.items = 2;
1735 if (info->value.enumerated.item > 1)
1736 info->value.enumerated.item = 1;
1737 strcpy(info->value.enumerated.name, names[info->value.enumerated.item]);
1738 return 0;
1739} 1740}
1740 1741
1741static int roland_load_get(struct snd_kcontrol *kcontrol, 1742static int roland_load_get(struct snd_kcontrol *kcontrol,
diff --git a/sound/usb/mixer.c b/sound/usb/mixer.c
index f2d74d654b3c..7df89b3d7ded 100644
--- a/sound/usb/mixer.c
+++ b/sound/usb/mixer.c
@@ -1633,18 +1633,11 @@ static int parse_audio_extension_unit(struct mixer_build *state, int unitid, voi
1633static int mixer_ctl_selector_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) 1633static int mixer_ctl_selector_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
1634{ 1634{
1635 struct usb_mixer_elem_info *cval = kcontrol->private_data; 1635 struct usb_mixer_elem_info *cval = kcontrol->private_data;
1636 char **itemlist = (char **)kcontrol->private_value; 1636 const char **itemlist = (const char **)kcontrol->private_value;
1637 1637
1638 if (snd_BUG_ON(!itemlist)) 1638 if (snd_BUG_ON(!itemlist))
1639 return -EINVAL; 1639 return -EINVAL;
1640 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; 1640 return snd_ctl_enum_info(uinfo, 1, cval->max, itemlist);
1641 uinfo->count = 1;
1642 uinfo->value.enumerated.items = cval->max;
1643 if (uinfo->value.enumerated.item >= cval->max)
1644 uinfo->value.enumerated.item = cval->max - 1;
1645 strlcpy(uinfo->value.enumerated.name, itemlist[uinfo->value.enumerated.item],
1646 sizeof(uinfo->value.enumerated.name));
1647 return 0;
1648} 1641}
1649 1642
1650/* get callback for selector unit */ 1643/* get callback for selector unit */
diff --git a/sound/usb/quirks-table.h b/sound/usb/quirks-table.h
index ad7079d1676c..35999874d301 100644
--- a/sound/usb/quirks-table.h
+++ b/sound/usb/quirks-table.h
@@ -705,11 +705,11 @@ YAMAHA_DEVICE(0x7010, "UB99"),
705 .data = (const struct snd_usb_audio_quirk[]) { 705 .data = (const struct snd_usb_audio_quirk[]) {
706 { 706 {
707 .ifnum = 0, 707 .ifnum = 0,
708 .type = QUIRK_IGNORE_INTERFACE 708 .type = QUIRK_AUDIO_STANDARD_INTERFACE
709 }, 709 },
710 { 710 {
711 .ifnum = 1, 711 .ifnum = 1,
712 .type = QUIRK_IGNORE_INTERFACE 712 .type = QUIRK_AUDIO_STANDARD_INTERFACE
713 }, 713 },
714 { 714 {
715 .ifnum = 2, 715 .ifnum = 2,
diff --git a/sound/usb/usx2y/us122l.c b/sound/usb/usx2y/us122l.c
index 6ef68e42138e..084e6fc8d5bf 100644
--- a/sound/usb/usx2y/us122l.c
+++ b/sound/usb/usx2y/us122l.c
@@ -273,29 +273,26 @@ static unsigned int usb_stream_hwdep_poll(struct snd_hwdep *hw,
273 struct file *file, poll_table *wait) 273 struct file *file, poll_table *wait)
274{ 274{
275 struct us122l *us122l = hw->private_data; 275 struct us122l *us122l = hw->private_data;
276 struct usb_stream *s = us122l->sk.s;
277 unsigned *polled; 276 unsigned *polled;
278 unsigned int mask; 277 unsigned int mask;
279 278
280 poll_wait(file, &us122l->sk.sleep, wait); 279 poll_wait(file, &us122l->sk.sleep, wait);
281 280
282 switch (s->state) { 281 mask = POLLIN | POLLOUT | POLLWRNORM | POLLERR;
283 case usb_stream_ready: 282 if (mutex_trylock(&us122l->mutex)) {
284 if (us122l->first == file) 283 struct usb_stream *s = us122l->sk.s;
285 polled = &s->periods_polled; 284 if (s && s->state == usb_stream_ready) {
286 else 285 if (us122l->first == file)
287 polled = &us122l->second_periods_polled; 286 polled = &s->periods_polled;
288 if (*polled != s->periods_done) { 287 else
289 *polled = s->periods_done; 288 polled = &us122l->second_periods_polled;
290 mask = POLLIN | POLLOUT | POLLWRNORM; 289 if (*polled != s->periods_done) {
291 break; 290 *polled = s->periods_done;
291 mask = POLLIN | POLLOUT | POLLWRNORM;
292 } else
293 mask = 0;
292 } 294 }
293 /* Fall through */ 295 mutex_unlock(&us122l->mutex);
294 mask = 0;
295 break;
296 default:
297 mask = POLLIN | POLLOUT | POLLWRNORM | POLLERR;
298 break;
299 } 296 }
300 return mask; 297 return mask;
301} 298}
@@ -381,6 +378,7 @@ static int usb_stream_hwdep_ioctl(struct snd_hwdep *hw, struct file *file,
381{ 378{
382 struct usb_stream_config *cfg; 379 struct usb_stream_config *cfg;
383 struct us122l *us122l = hw->private_data; 380 struct us122l *us122l = hw->private_data;
381 struct usb_stream *s;
384 unsigned min_period_frames; 382 unsigned min_period_frames;
385 int err = 0; 383 int err = 0;
386 bool high_speed; 384 bool high_speed;
@@ -426,18 +424,18 @@ static int usb_stream_hwdep_ioctl(struct snd_hwdep *hw, struct file *file,
426 snd_power_wait(hw->card, SNDRV_CTL_POWER_D0); 424 snd_power_wait(hw->card, SNDRV_CTL_POWER_D0);
427 425
428 mutex_lock(&us122l->mutex); 426 mutex_lock(&us122l->mutex);
427 s = us122l->sk.s;
429 if (!us122l->master) 428 if (!us122l->master)
430 us122l->master = file; 429 us122l->master = file;
431 else if (us122l->master != file) { 430 else if (us122l->master != file) {
432 if (memcmp(cfg, &us122l->sk.s->cfg, sizeof(*cfg))) { 431 if (!s || memcmp(cfg, &s->cfg, sizeof(*cfg))) {
433 err = -EIO; 432 err = -EIO;
434 goto unlock; 433 goto unlock;
435 } 434 }
436 us122l->slave = file; 435 us122l->slave = file;
437 } 436 }
438 if (!us122l->sk.s || 437 if (!s || memcmp(cfg, &s->cfg, sizeof(*cfg)) ||
439 memcmp(cfg, &us122l->sk.s->cfg, sizeof(*cfg)) || 438 s->state == usb_stream_xrun) {
440 us122l->sk.s->state == usb_stream_xrun) {
441 us122l_stop(us122l); 439 us122l_stop(us122l);
442 if (!us122l_start(us122l, cfg->sample_rate, cfg->period_frames)) 440 if (!us122l_start(us122l, cfg->sample_rate, cfg->period_frames))
443 err = -EIO; 441 err = -EIO;
@@ -448,6 +446,7 @@ unlock:
448 mutex_unlock(&us122l->mutex); 446 mutex_unlock(&us122l->mutex);
449free: 447free:
450 kfree(cfg); 448 kfree(cfg);
449 wake_up_all(&us122l->sk.sleep);
451 return err; 450 return err;
452} 451}
453 452
diff --git a/usr/Kconfig b/usr/Kconfig
index c2c7fe2f717d..4780deac5974 100644
--- a/usr/Kconfig
+++ b/usr/Kconfig
@@ -72,6 +72,15 @@ config RD_LZMA
72 Support loading of a LZMA encoded initial ramdisk or cpio buffer 72 Support loading of a LZMA encoded initial ramdisk or cpio buffer
73 If unsure, say N. 73 If unsure, say N.
74 74
75config RD_XZ
76 bool "Support initial ramdisks compressed using XZ" if EMBEDDED
77 default !EMBEDDED
78 depends on BLK_DEV_INITRD
79 select DECOMPRESS_XZ
80 help
81 Support loading of a XZ encoded initial ramdisk or cpio buffer.
82 If unsure, say N.
83
75config RD_LZO 84config RD_LZO
76 bool "Support initial ramdisks compressed using LZO" if EMBEDDED 85 bool "Support initial ramdisks compressed using LZO" if EMBEDDED
77 default !EMBEDDED 86 default !EMBEDDED
@@ -139,6 +148,15 @@ config INITRAMFS_COMPRESSION_LZMA
139 three. Compression is slowest. The initramfs size is about 33% 148 three. Compression is slowest. The initramfs size is about 33%
140 smaller with LZMA in comparison to gzip. 149 smaller with LZMA in comparison to gzip.
141 150
151config INITRAMFS_COMPRESSION_XZ
152 bool "XZ"
153 depends on RD_XZ
154 help
155 XZ uses the LZMA2 algorithm. The initramfs size is about 30%
156 smaller with XZ in comparison to gzip. Decompression speed
157 is better than that of bzip2 but worse than gzip and LZO.
158 Compression is slow.
159
142config INITRAMFS_COMPRESSION_LZO 160config INITRAMFS_COMPRESSION_LZO
143 bool "LZO" 161 bool "LZO"
144 depends on RD_LZO 162 depends on RD_LZO
diff --git a/usr/Makefile b/usr/Makefile
index 6faa444b7087..029ffe6cd0d8 100644
--- a/usr/Makefile
+++ b/usr/Makefile
@@ -15,6 +15,9 @@ suffix_$(CONFIG_INITRAMFS_COMPRESSION_BZIP2) = .bz2
15# Lzma 15# Lzma
16suffix_$(CONFIG_INITRAMFS_COMPRESSION_LZMA) = .lzma 16suffix_$(CONFIG_INITRAMFS_COMPRESSION_LZMA) = .lzma
17 17
18# XZ
19suffix_$(CONFIG_INITRAMFS_COMPRESSION_XZ) = .xz
20
18# Lzo 21# Lzo
19suffix_$(CONFIG_INITRAMFS_COMPRESSION_LZO) = .lzo 22suffix_$(CONFIG_INITRAMFS_COMPRESSION_LZO) = .lzo
20 23
@@ -50,7 +53,7 @@ endif
50quiet_cmd_initfs = GEN $@ 53quiet_cmd_initfs = GEN $@
51 cmd_initfs = $(initramfs) -o $@ $(ramfs-args) $(ramfs-input) 54 cmd_initfs = $(initramfs) -o $@ $(ramfs-args) $(ramfs-input)
52 55
53targets := initramfs_data.cpio.gz initramfs_data.cpio.bz2 initramfs_data.cpio.lzma initramfs_data.cpio.lzo initramfs_data.cpio 56targets := initramfs_data.cpio.gz initramfs_data.cpio.bz2 initramfs_data.cpio.lzma initramfs_data.cpio.xz initramfs_data.cpio.lzo initramfs_data.cpio
54# do not try to update files included in initramfs 57# do not try to update files included in initramfs
55$(deps_initramfs): ; 58$(deps_initramfs): ;
56 59
diff --git a/virt/kvm/Kconfig b/virt/kvm/Kconfig
index 7f1178f6b839..f63ccb0a5982 100644
--- a/virt/kvm/Kconfig
+++ b/virt/kvm/Kconfig
@@ -15,3 +15,6 @@ config KVM_APIC_ARCHITECTURE
15 15
16config KVM_MMIO 16config KVM_MMIO
17 bool 17 bool
18
19config KVM_ASYNC_PF
20 bool
diff --git a/virt/kvm/assigned-dev.c b/virt/kvm/assigned-dev.c
index 7c98928b09d9..ae72ae604c89 100644
--- a/virt/kvm/assigned-dev.c
+++ b/virt/kvm/assigned-dev.c
@@ -55,58 +55,31 @@ static int find_index_from_host_irq(struct kvm_assigned_dev_kernel
55 return index; 55 return index;
56} 56}
57 57
58static void kvm_assigned_dev_interrupt_work_handler(struct work_struct *work) 58static irqreturn_t kvm_assigned_dev_thread(int irq, void *dev_id)
59{ 59{
60 struct kvm_assigned_dev_kernel *assigned_dev; 60 struct kvm_assigned_dev_kernel *assigned_dev = dev_id;
61 int i; 61 u32 vector;
62 int index;
62 63
63 assigned_dev = container_of(work, struct kvm_assigned_dev_kernel, 64 if (assigned_dev->irq_requested_type & KVM_DEV_IRQ_HOST_INTX) {
64 interrupt_work); 65 spin_lock(&assigned_dev->intx_lock);
66 disable_irq_nosync(irq);
67 assigned_dev->host_irq_disabled = true;
68 spin_unlock(&assigned_dev->intx_lock);
69 }
65 70
66 spin_lock_irq(&assigned_dev->assigned_dev_lock);
67 if (assigned_dev->irq_requested_type & KVM_DEV_IRQ_HOST_MSIX) { 71 if (assigned_dev->irq_requested_type & KVM_DEV_IRQ_HOST_MSIX) {
68 struct kvm_guest_msix_entry *guest_entries = 72 index = find_index_from_host_irq(assigned_dev, irq);
69 assigned_dev->guest_msix_entries; 73 if (index >= 0) {
70 for (i = 0; i < assigned_dev->entries_nr; i++) { 74 vector = assigned_dev->
71 if (!(guest_entries[i].flags & 75 guest_msix_entries[index].vector;
72 KVM_ASSIGNED_MSIX_PENDING))
73 continue;
74 guest_entries[i].flags &= ~KVM_ASSIGNED_MSIX_PENDING;
75 kvm_set_irq(assigned_dev->kvm, 76 kvm_set_irq(assigned_dev->kvm,
76 assigned_dev->irq_source_id, 77 assigned_dev->irq_source_id, vector, 1);
77 guest_entries[i].vector, 1);
78 } 78 }
79 } else 79 } else
80 kvm_set_irq(assigned_dev->kvm, assigned_dev->irq_source_id, 80 kvm_set_irq(assigned_dev->kvm, assigned_dev->irq_source_id,
81 assigned_dev->guest_irq, 1); 81 assigned_dev->guest_irq, 1);
82 82
83 spin_unlock_irq(&assigned_dev->assigned_dev_lock);
84}
85
86static irqreturn_t kvm_assigned_dev_intr(int irq, void *dev_id)
87{
88 unsigned long flags;
89 struct kvm_assigned_dev_kernel *assigned_dev =
90 (struct kvm_assigned_dev_kernel *) dev_id;
91
92 spin_lock_irqsave(&assigned_dev->assigned_dev_lock, flags);
93 if (assigned_dev->irq_requested_type & KVM_DEV_IRQ_HOST_MSIX) {
94 int index = find_index_from_host_irq(assigned_dev, irq);
95 if (index < 0)
96 goto out;
97 assigned_dev->guest_msix_entries[index].flags |=
98 KVM_ASSIGNED_MSIX_PENDING;
99 }
100
101 schedule_work(&assigned_dev->interrupt_work);
102
103 if (assigned_dev->irq_requested_type & KVM_DEV_IRQ_GUEST_INTX) {
104 disable_irq_nosync(irq);
105 assigned_dev->host_irq_disabled = true;
106 }
107
108out:
109 spin_unlock_irqrestore(&assigned_dev->assigned_dev_lock, flags);
110 return IRQ_HANDLED; 83 return IRQ_HANDLED;
111} 84}
112 85
@@ -114,7 +87,6 @@ out:
114static void kvm_assigned_dev_ack_irq(struct kvm_irq_ack_notifier *kian) 87static void kvm_assigned_dev_ack_irq(struct kvm_irq_ack_notifier *kian)
115{ 88{
116 struct kvm_assigned_dev_kernel *dev; 89 struct kvm_assigned_dev_kernel *dev;
117 unsigned long flags;
118 90
119 if (kian->gsi == -1) 91 if (kian->gsi == -1)
120 return; 92 return;
@@ -127,12 +99,12 @@ static void kvm_assigned_dev_ack_irq(struct kvm_irq_ack_notifier *kian)
127 /* The guest irq may be shared so this ack may be 99 /* The guest irq may be shared so this ack may be
128 * from another device. 100 * from another device.
129 */ 101 */
130 spin_lock_irqsave(&dev->assigned_dev_lock, flags); 102 spin_lock(&dev->intx_lock);
131 if (dev->host_irq_disabled) { 103 if (dev->host_irq_disabled) {
132 enable_irq(dev->host_irq); 104 enable_irq(dev->host_irq);
133 dev->host_irq_disabled = false; 105 dev->host_irq_disabled = false;
134 } 106 }
135 spin_unlock_irqrestore(&dev->assigned_dev_lock, flags); 107 spin_unlock(&dev->intx_lock);
136} 108}
137 109
138static void deassign_guest_irq(struct kvm *kvm, 110static void deassign_guest_irq(struct kvm *kvm,
@@ -141,6 +113,9 @@ static void deassign_guest_irq(struct kvm *kvm,
141 kvm_unregister_irq_ack_notifier(kvm, &assigned_dev->ack_notifier); 113 kvm_unregister_irq_ack_notifier(kvm, &assigned_dev->ack_notifier);
142 assigned_dev->ack_notifier.gsi = -1; 114 assigned_dev->ack_notifier.gsi = -1;
143 115
116 kvm_set_irq(assigned_dev->kvm, assigned_dev->irq_source_id,
117 assigned_dev->guest_irq, 0);
118
144 if (assigned_dev->irq_source_id != -1) 119 if (assigned_dev->irq_source_id != -1)
145 kvm_free_irq_source_id(kvm, assigned_dev->irq_source_id); 120 kvm_free_irq_source_id(kvm, assigned_dev->irq_source_id);
146 assigned_dev->irq_source_id = -1; 121 assigned_dev->irq_source_id = -1;
@@ -152,28 +127,19 @@ static void deassign_host_irq(struct kvm *kvm,
152 struct kvm_assigned_dev_kernel *assigned_dev) 127 struct kvm_assigned_dev_kernel *assigned_dev)
153{ 128{
154 /* 129 /*
155 * In kvm_free_device_irq, cancel_work_sync return true if: 130 * We disable irq here to prevent further events.
156 * 1. work is scheduled, and then cancelled.
157 * 2. work callback is executed.
158 *
159 * The first one ensured that the irq is disabled and no more events
160 * would happen. But for the second one, the irq may be enabled (e.g.
161 * for MSI). So we disable irq here to prevent further events.
162 * 131 *
163 * Notice this maybe result in nested disable if the interrupt type is 132 * Notice this maybe result in nested disable if the interrupt type is
164 * INTx, but it's OK for we are going to free it. 133 * INTx, but it's OK for we are going to free it.
165 * 134 *
166 * If this function is a part of VM destroy, please ensure that till 135 * If this function is a part of VM destroy, please ensure that till
167 * now, the kvm state is still legal for probably we also have to wait 136 * now, the kvm state is still legal for probably we also have to wait
168 * interrupt_work done. 137 * on a currently running IRQ handler.
169 */ 138 */
170 if (assigned_dev->irq_requested_type & KVM_DEV_IRQ_HOST_MSIX) { 139 if (assigned_dev->irq_requested_type & KVM_DEV_IRQ_HOST_MSIX) {
171 int i; 140 int i;
172 for (i = 0; i < assigned_dev->entries_nr; i++) 141 for (i = 0; i < assigned_dev->entries_nr; i++)
173 disable_irq_nosync(assigned_dev-> 142 disable_irq(assigned_dev->host_msix_entries[i].vector);
174 host_msix_entries[i].vector);
175
176 cancel_work_sync(&assigned_dev->interrupt_work);
177 143
178 for (i = 0; i < assigned_dev->entries_nr; i++) 144 for (i = 0; i < assigned_dev->entries_nr; i++)
179 free_irq(assigned_dev->host_msix_entries[i].vector, 145 free_irq(assigned_dev->host_msix_entries[i].vector,
@@ -185,8 +151,7 @@ static void deassign_host_irq(struct kvm *kvm,
185 pci_disable_msix(assigned_dev->dev); 151 pci_disable_msix(assigned_dev->dev);
186 } else { 152 } else {
187 /* Deal with MSI and INTx */ 153 /* Deal with MSI and INTx */
188 disable_irq_nosync(assigned_dev->host_irq); 154 disable_irq(assigned_dev->host_irq);
189 cancel_work_sync(&assigned_dev->interrupt_work);
190 155
191 free_irq(assigned_dev->host_irq, (void *)assigned_dev); 156 free_irq(assigned_dev->host_irq, (void *)assigned_dev);
192 157
@@ -232,7 +197,8 @@ static void kvm_free_assigned_device(struct kvm *kvm,
232{ 197{
233 kvm_free_assigned_irq(kvm, assigned_dev); 198 kvm_free_assigned_irq(kvm, assigned_dev);
234 199
235 pci_reset_function(assigned_dev->dev); 200 __pci_reset_function(assigned_dev->dev);
201 pci_restore_state(assigned_dev->dev);
236 202
237 pci_release_regions(assigned_dev->dev); 203 pci_release_regions(assigned_dev->dev);
238 pci_disable_device(assigned_dev->dev); 204 pci_disable_device(assigned_dev->dev);
@@ -265,8 +231,8 @@ static int assigned_device_enable_host_intx(struct kvm *kvm,
265 * on the same interrupt line is not a happy situation: there 231 * on the same interrupt line is not a happy situation: there
266 * are going to be long delays in accepting, acking, etc. 232 * are going to be long delays in accepting, acking, etc.
267 */ 233 */
268 if (request_irq(dev->host_irq, kvm_assigned_dev_intr, 234 if (request_threaded_irq(dev->host_irq, NULL, kvm_assigned_dev_thread,
269 0, "kvm_assigned_intx_device", (void *)dev)) 235 IRQF_ONESHOT, dev->irq_name, (void *)dev))
270 return -EIO; 236 return -EIO;
271 return 0; 237 return 0;
272} 238}
@@ -284,8 +250,8 @@ static int assigned_device_enable_host_msi(struct kvm *kvm,
284 } 250 }
285 251
286 dev->host_irq = dev->dev->irq; 252 dev->host_irq = dev->dev->irq;
287 if (request_irq(dev->host_irq, kvm_assigned_dev_intr, 0, 253 if (request_threaded_irq(dev->host_irq, NULL, kvm_assigned_dev_thread,
288 "kvm_assigned_msi_device", (void *)dev)) { 254 0, dev->irq_name, (void *)dev)) {
289 pci_disable_msi(dev->dev); 255 pci_disable_msi(dev->dev);
290 return -EIO; 256 return -EIO;
291 } 257 }
@@ -310,10 +276,9 @@ static int assigned_device_enable_host_msix(struct kvm *kvm,
310 return r; 276 return r;
311 277
312 for (i = 0; i < dev->entries_nr; i++) { 278 for (i = 0; i < dev->entries_nr; i++) {
313 r = request_irq(dev->host_msix_entries[i].vector, 279 r = request_threaded_irq(dev->host_msix_entries[i].vector,
314 kvm_assigned_dev_intr, 0, 280 NULL, kvm_assigned_dev_thread,
315 "kvm_assigned_msix_device", 281 0, dev->irq_name, (void *)dev);
316 (void *)dev);
317 if (r) 282 if (r)
318 goto err; 283 goto err;
319 } 284 }
@@ -370,6 +335,9 @@ static int assign_host_irq(struct kvm *kvm,
370 if (dev->irq_requested_type & KVM_DEV_IRQ_HOST_MASK) 335 if (dev->irq_requested_type & KVM_DEV_IRQ_HOST_MASK)
371 return r; 336 return r;
372 337
338 snprintf(dev->irq_name, sizeof(dev->irq_name), "kvm:%s",
339 pci_name(dev->dev));
340
373 switch (host_irq_type) { 341 switch (host_irq_type) {
374 case KVM_DEV_IRQ_HOST_INTX: 342 case KVM_DEV_IRQ_HOST_INTX:
375 r = assigned_device_enable_host_intx(kvm, dev); 343 r = assigned_device_enable_host_intx(kvm, dev);
@@ -547,6 +515,7 @@ static int kvm_vm_ioctl_assign_device(struct kvm *kvm,
547 } 515 }
548 516
549 pci_reset_function(dev); 517 pci_reset_function(dev);
518 pci_save_state(dev);
550 519
551 match->assigned_dev_id = assigned_dev->assigned_dev_id; 520 match->assigned_dev_id = assigned_dev->assigned_dev_id;
552 match->host_segnr = assigned_dev->segnr; 521 match->host_segnr = assigned_dev->segnr;
@@ -554,12 +523,10 @@ static int kvm_vm_ioctl_assign_device(struct kvm *kvm,
554 match->host_devfn = assigned_dev->devfn; 523 match->host_devfn = assigned_dev->devfn;
555 match->flags = assigned_dev->flags; 524 match->flags = assigned_dev->flags;
556 match->dev = dev; 525 match->dev = dev;
557 spin_lock_init(&match->assigned_dev_lock); 526 spin_lock_init(&match->intx_lock);
558 match->irq_source_id = -1; 527 match->irq_source_id = -1;
559 match->kvm = kvm; 528 match->kvm = kvm;
560 match->ack_notifier.irq_acked = kvm_assigned_dev_ack_irq; 529 match->ack_notifier.irq_acked = kvm_assigned_dev_ack_irq;
561 INIT_WORK(&match->interrupt_work,
562 kvm_assigned_dev_interrupt_work_handler);
563 530
564 list_add(&match->list, &kvm->arch.assigned_dev_head); 531 list_add(&match->list, &kvm->arch.assigned_dev_head);
565 532
@@ -579,6 +546,7 @@ out:
579 mutex_unlock(&kvm->lock); 546 mutex_unlock(&kvm->lock);
580 return r; 547 return r;
581out_list_del: 548out_list_del:
549 pci_restore_state(dev);
582 list_del(&match->list); 550 list_del(&match->list);
583 pci_release_regions(dev); 551 pci_release_regions(dev);
584out_disable: 552out_disable:
@@ -651,9 +619,9 @@ static int kvm_vm_ioctl_set_msix_nr(struct kvm *kvm,
651 r = -ENOMEM; 619 r = -ENOMEM;
652 goto msix_nr_out; 620 goto msix_nr_out;
653 } 621 }
654 adev->guest_msix_entries = kzalloc( 622 adev->guest_msix_entries =
655 sizeof(struct kvm_guest_msix_entry) * 623 kzalloc(sizeof(struct msix_entry) * entry_nr->entry_nr,
656 entry_nr->entry_nr, GFP_KERNEL); 624 GFP_KERNEL);
657 if (!adev->guest_msix_entries) { 625 if (!adev->guest_msix_entries) {
658 kfree(adev->host_msix_entries); 626 kfree(adev->host_msix_entries);
659 r = -ENOMEM; 627 r = -ENOMEM;
@@ -706,7 +674,7 @@ long kvm_vm_ioctl_assigned_device(struct kvm *kvm, unsigned ioctl,
706 unsigned long arg) 674 unsigned long arg)
707{ 675{
708 void __user *argp = (void __user *)arg; 676 void __user *argp = (void __user *)arg;
709 int r = -ENOTTY; 677 int r;
710 678
711 switch (ioctl) { 679 switch (ioctl) {
712 case KVM_ASSIGN_PCI_DEVICE: { 680 case KVM_ASSIGN_PCI_DEVICE: {
@@ -724,7 +692,6 @@ long kvm_vm_ioctl_assigned_device(struct kvm *kvm, unsigned ioctl,
724 r = -EOPNOTSUPP; 692 r = -EOPNOTSUPP;
725 break; 693 break;
726 } 694 }
727#ifdef KVM_CAP_ASSIGN_DEV_IRQ
728 case KVM_ASSIGN_DEV_IRQ: { 695 case KVM_ASSIGN_DEV_IRQ: {
729 struct kvm_assigned_irq assigned_irq; 696 struct kvm_assigned_irq assigned_irq;
730 697
@@ -747,8 +714,6 @@ long kvm_vm_ioctl_assigned_device(struct kvm *kvm, unsigned ioctl,
747 goto out; 714 goto out;
748 break; 715 break;
749 } 716 }
750#endif
751#ifdef KVM_CAP_DEVICE_DEASSIGNMENT
752 case KVM_DEASSIGN_PCI_DEVICE: { 717 case KVM_DEASSIGN_PCI_DEVICE: {
753 struct kvm_assigned_pci_dev assigned_dev; 718 struct kvm_assigned_pci_dev assigned_dev;
754 719
@@ -760,7 +725,6 @@ long kvm_vm_ioctl_assigned_device(struct kvm *kvm, unsigned ioctl,
760 goto out; 725 goto out;
761 break; 726 break;
762 } 727 }
763#endif
764#ifdef KVM_CAP_IRQ_ROUTING 728#ifdef KVM_CAP_IRQ_ROUTING
765 case KVM_SET_GSI_ROUTING: { 729 case KVM_SET_GSI_ROUTING: {
766 struct kvm_irq_routing routing; 730 struct kvm_irq_routing routing;
@@ -813,6 +777,9 @@ long kvm_vm_ioctl_assigned_device(struct kvm *kvm, unsigned ioctl,
813 break; 777 break;
814 } 778 }
815#endif 779#endif
780 default:
781 r = -ENOTTY;
782 break;
816 } 783 }
817out: 784out:
818 return r; 785 return r;
diff --git a/virt/kvm/async_pf.c b/virt/kvm/async_pf.c
new file mode 100644
index 000000000000..74268b4c2ee1
--- /dev/null
+++ b/virt/kvm/async_pf.c
@@ -0,0 +1,216 @@
1/*
2 * kvm asynchronous fault support
3 *
4 * Copyright 2010 Red Hat, Inc.
5 *
6 * Author:
7 * Gleb Natapov <gleb@redhat.com>
8 *
9 * This file is free software; you can redistribute it and/or modify
10 * it under the terms of version 2 of the GNU General Public License
11 * as published by the Free Software Foundation.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software Foundation,
20 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
21 */
22
23#include <linux/kvm_host.h>
24#include <linux/slab.h>
25#include <linux/module.h>
26#include <linux/mmu_context.h>
27
28#include "async_pf.h"
29#include <trace/events/kvm.h>
30
31static struct kmem_cache *async_pf_cache;
32
33int kvm_async_pf_init(void)
34{
35 async_pf_cache = KMEM_CACHE(kvm_async_pf, 0);
36
37 if (!async_pf_cache)
38 return -ENOMEM;
39
40 return 0;
41}
42
43void kvm_async_pf_deinit(void)
44{
45 if (async_pf_cache)
46 kmem_cache_destroy(async_pf_cache);
47 async_pf_cache = NULL;
48}
49
50void kvm_async_pf_vcpu_init(struct kvm_vcpu *vcpu)
51{
52 INIT_LIST_HEAD(&vcpu->async_pf.done);
53 INIT_LIST_HEAD(&vcpu->async_pf.queue);
54 spin_lock_init(&vcpu->async_pf.lock);
55}
56
57static void async_pf_execute(struct work_struct *work)
58{
59 struct page *page = NULL;
60 struct kvm_async_pf *apf =
61 container_of(work, struct kvm_async_pf, work);
62 struct mm_struct *mm = apf->mm;
63 struct kvm_vcpu *vcpu = apf->vcpu;
64 unsigned long addr = apf->addr;
65 gva_t gva = apf->gva;
66
67 might_sleep();
68
69 use_mm(mm);
70 down_read(&mm->mmap_sem);
71 get_user_pages(current, mm, addr, 1, 1, 0, &page, NULL);
72 up_read(&mm->mmap_sem);
73 unuse_mm(mm);
74
75 spin_lock(&vcpu->async_pf.lock);
76 list_add_tail(&apf->link, &vcpu->async_pf.done);
77 apf->page = page;
78 apf->done = true;
79 spin_unlock(&vcpu->async_pf.lock);
80
81 /*
82 * apf may be freed by kvm_check_async_pf_completion() after
83 * this point
84 */
85
86 trace_kvm_async_pf_completed(addr, page, gva);
87
88 if (waitqueue_active(&vcpu->wq))
89 wake_up_interruptible(&vcpu->wq);
90
91 mmdrop(mm);
92 kvm_put_kvm(vcpu->kvm);
93}
94
95void kvm_clear_async_pf_completion_queue(struct kvm_vcpu *vcpu)
96{
97 /* cancel outstanding work queue item */
98 while (!list_empty(&vcpu->async_pf.queue)) {
99 struct kvm_async_pf *work =
100 list_entry(vcpu->async_pf.queue.next,
101 typeof(*work), queue);
102 cancel_work_sync(&work->work);
103 list_del(&work->queue);
104 if (!work->done) /* work was canceled */
105 kmem_cache_free(async_pf_cache, work);
106 }
107
108 spin_lock(&vcpu->async_pf.lock);
109 while (!list_empty(&vcpu->async_pf.done)) {
110 struct kvm_async_pf *work =
111 list_entry(vcpu->async_pf.done.next,
112 typeof(*work), link);
113 list_del(&work->link);
114 if (work->page)
115 put_page(work->page);
116 kmem_cache_free(async_pf_cache, work);
117 }
118 spin_unlock(&vcpu->async_pf.lock);
119
120 vcpu->async_pf.queued = 0;
121}
122
123void kvm_check_async_pf_completion(struct kvm_vcpu *vcpu)
124{
125 struct kvm_async_pf *work;
126
127 while (!list_empty_careful(&vcpu->async_pf.done) &&
128 kvm_arch_can_inject_async_page_present(vcpu)) {
129 spin_lock(&vcpu->async_pf.lock);
130 work = list_first_entry(&vcpu->async_pf.done, typeof(*work),
131 link);
132 list_del(&work->link);
133 spin_unlock(&vcpu->async_pf.lock);
134
135 if (work->page)
136 kvm_arch_async_page_ready(vcpu, work);
137 kvm_arch_async_page_present(vcpu, work);
138
139 list_del(&work->queue);
140 vcpu->async_pf.queued--;
141 if (work->page)
142 put_page(work->page);
143 kmem_cache_free(async_pf_cache, work);
144 }
145}
146
147int kvm_setup_async_pf(struct kvm_vcpu *vcpu, gva_t gva, gfn_t gfn,
148 struct kvm_arch_async_pf *arch)
149{
150 struct kvm_async_pf *work;
151
152 if (vcpu->async_pf.queued >= ASYNC_PF_PER_VCPU)
153 return 0;
154
155 /* setup delayed work */
156
157 /*
158 * do alloc nowait since if we are going to sleep anyway we
159 * may as well sleep faulting in page
160 */
161 work = kmem_cache_zalloc(async_pf_cache, GFP_NOWAIT);
162 if (!work)
163 return 0;
164
165 work->page = NULL;
166 work->done = false;
167 work->vcpu = vcpu;
168 work->gva = gva;
169 work->addr = gfn_to_hva(vcpu->kvm, gfn);
170 work->arch = *arch;
171 work->mm = current->mm;
172 atomic_inc(&work->mm->mm_count);
173 kvm_get_kvm(work->vcpu->kvm);
174
175 /* this can't really happen otherwise gfn_to_pfn_async
176 would succeed */
177 if (unlikely(kvm_is_error_hva(work->addr)))
178 goto retry_sync;
179
180 INIT_WORK(&work->work, async_pf_execute);
181 if (!schedule_work(&work->work))
182 goto retry_sync;
183
184 list_add_tail(&work->queue, &vcpu->async_pf.queue);
185 vcpu->async_pf.queued++;
186 kvm_arch_async_page_not_present(vcpu, work);
187 return 1;
188retry_sync:
189 kvm_put_kvm(work->vcpu->kvm);
190 mmdrop(work->mm);
191 kmem_cache_free(async_pf_cache, work);
192 return 0;
193}
194
195int kvm_async_pf_wakeup_all(struct kvm_vcpu *vcpu)
196{
197 struct kvm_async_pf *work;
198
199 if (!list_empty_careful(&vcpu->async_pf.done))
200 return 0;
201
202 work = kmem_cache_zalloc(async_pf_cache, GFP_ATOMIC);
203 if (!work)
204 return -ENOMEM;
205
206 work->page = bad_page;
207 get_page(bad_page);
208 INIT_LIST_HEAD(&work->queue); /* for list_del to work */
209
210 spin_lock(&vcpu->async_pf.lock);
211 list_add_tail(&work->link, &vcpu->async_pf.done);
212 spin_unlock(&vcpu->async_pf.lock);
213
214 vcpu->async_pf.queued++;
215 return 0;
216}
diff --git a/virt/kvm/async_pf.h b/virt/kvm/async_pf.h
new file mode 100644
index 000000000000..e7ef6447cb82
--- /dev/null
+++ b/virt/kvm/async_pf.h
@@ -0,0 +1,36 @@
1/*
2 * kvm asynchronous fault support
3 *
4 * Copyright 2010 Red Hat, Inc.
5 *
6 * Author:
7 * Gleb Natapov <gleb@redhat.com>
8 *
9 * This file is free software; you can redistribute it and/or modify
10 * it under the terms of version 2 of the GNU General Public License
11 * as published by the Free Software Foundation.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software Foundation,
20 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
21 */
22
23#ifndef __KVM_ASYNC_PF_H__
24#define __KVM_ASYNC_PF_H__
25
26#ifdef CONFIG_KVM_ASYNC_PF
27int kvm_async_pf_init(void);
28void kvm_async_pf_deinit(void);
29void kvm_async_pf_vcpu_init(struct kvm_vcpu *vcpu);
30#else
31#define kvm_async_pf_init() (0)
32#define kvm_async_pf_deinit() do{}while(0)
33#define kvm_async_pf_vcpu_init(C) do{}while(0)
34#endif
35
36#endif
diff --git a/virt/kvm/eventfd.c b/virt/kvm/eventfd.c
index c1f1e3c62984..2ca4535f4fb7 100644
--- a/virt/kvm/eventfd.c
+++ b/virt/kvm/eventfd.c
@@ -44,14 +44,19 @@
44 */ 44 */
45 45
46struct _irqfd { 46struct _irqfd {
47 struct kvm *kvm; 47 /* Used for MSI fast-path */
48 struct eventfd_ctx *eventfd; 48 struct kvm *kvm;
49 int gsi; 49 wait_queue_t wait;
50 struct list_head list; 50 /* Update side is protected by irqfds.lock */
51 poll_table pt; 51 struct kvm_kernel_irq_routing_entry __rcu *irq_entry;
52 wait_queue_t wait; 52 /* Used for level IRQ fast-path */
53 struct work_struct inject; 53 int gsi;
54 struct work_struct shutdown; 54 struct work_struct inject;
55 /* Used for setup/shutdown */
56 struct eventfd_ctx *eventfd;
57 struct list_head list;
58 poll_table pt;
59 struct work_struct shutdown;
55}; 60};
56 61
57static struct workqueue_struct *irqfd_cleanup_wq; 62static struct workqueue_struct *irqfd_cleanup_wq;
@@ -125,14 +130,22 @@ irqfd_wakeup(wait_queue_t *wait, unsigned mode, int sync, void *key)
125{ 130{
126 struct _irqfd *irqfd = container_of(wait, struct _irqfd, wait); 131 struct _irqfd *irqfd = container_of(wait, struct _irqfd, wait);
127 unsigned long flags = (unsigned long)key; 132 unsigned long flags = (unsigned long)key;
133 struct kvm_kernel_irq_routing_entry *irq;
134 struct kvm *kvm = irqfd->kvm;
128 135
129 if (flags & POLLIN) 136 if (flags & POLLIN) {
137 rcu_read_lock();
138 irq = rcu_dereference(irqfd->irq_entry);
130 /* An event has been signaled, inject an interrupt */ 139 /* An event has been signaled, inject an interrupt */
131 schedule_work(&irqfd->inject); 140 if (irq)
141 kvm_set_msi(irq, kvm, KVM_USERSPACE_IRQ_SOURCE_ID, 1);
142 else
143 schedule_work(&irqfd->inject);
144 rcu_read_unlock();
145 }
132 146
133 if (flags & POLLHUP) { 147 if (flags & POLLHUP) {
134 /* The eventfd is closing, detach from KVM */ 148 /* The eventfd is closing, detach from KVM */
135 struct kvm *kvm = irqfd->kvm;
136 unsigned long flags; 149 unsigned long flags;
137 150
138 spin_lock_irqsave(&kvm->irqfds.lock, flags); 151 spin_lock_irqsave(&kvm->irqfds.lock, flags);
@@ -163,9 +176,31 @@ irqfd_ptable_queue_proc(struct file *file, wait_queue_head_t *wqh,
163 add_wait_queue(wqh, &irqfd->wait); 176 add_wait_queue(wqh, &irqfd->wait);
164} 177}
165 178
179/* Must be called under irqfds.lock */
180static void irqfd_update(struct kvm *kvm, struct _irqfd *irqfd,
181 struct kvm_irq_routing_table *irq_rt)
182{
183 struct kvm_kernel_irq_routing_entry *e;
184 struct hlist_node *n;
185
186 if (irqfd->gsi >= irq_rt->nr_rt_entries) {
187 rcu_assign_pointer(irqfd->irq_entry, NULL);
188 return;
189 }
190
191 hlist_for_each_entry(e, n, &irq_rt->map[irqfd->gsi], link) {
192 /* Only fast-path MSI. */
193 if (e->type == KVM_IRQ_ROUTING_MSI)
194 rcu_assign_pointer(irqfd->irq_entry, e);
195 else
196 rcu_assign_pointer(irqfd->irq_entry, NULL);
197 }
198}
199
166static int 200static int
167kvm_irqfd_assign(struct kvm *kvm, int fd, int gsi) 201kvm_irqfd_assign(struct kvm *kvm, int fd, int gsi)
168{ 202{
203 struct kvm_irq_routing_table *irq_rt;
169 struct _irqfd *irqfd, *tmp; 204 struct _irqfd *irqfd, *tmp;
170 struct file *file = NULL; 205 struct file *file = NULL;
171 struct eventfd_ctx *eventfd = NULL; 206 struct eventfd_ctx *eventfd = NULL;
@@ -215,6 +250,10 @@ kvm_irqfd_assign(struct kvm *kvm, int fd, int gsi)
215 goto fail; 250 goto fail;
216 } 251 }
217 252
253 irq_rt = rcu_dereference_protected(kvm->irq_routing,
254 lockdep_is_held(&kvm->irqfds.lock));
255 irqfd_update(kvm, irqfd, irq_rt);
256
218 events = file->f_op->poll(file, &irqfd->pt); 257 events = file->f_op->poll(file, &irqfd->pt);
219 258
220 list_add_tail(&irqfd->list, &kvm->irqfds.items); 259 list_add_tail(&irqfd->list, &kvm->irqfds.items);
@@ -271,8 +310,17 @@ kvm_irqfd_deassign(struct kvm *kvm, int fd, int gsi)
271 spin_lock_irq(&kvm->irqfds.lock); 310 spin_lock_irq(&kvm->irqfds.lock);
272 311
273 list_for_each_entry_safe(irqfd, tmp, &kvm->irqfds.items, list) { 312 list_for_each_entry_safe(irqfd, tmp, &kvm->irqfds.items, list) {
274 if (irqfd->eventfd == eventfd && irqfd->gsi == gsi) 313 if (irqfd->eventfd == eventfd && irqfd->gsi == gsi) {
314 /*
315 * This rcu_assign_pointer is needed for when
316 * another thread calls kvm_irqfd_update before
317 * we flush workqueue below.
318 * It is paired with synchronize_rcu done by caller
319 * of that function.
320 */
321 rcu_assign_pointer(irqfd->irq_entry, NULL);
275 irqfd_deactivate(irqfd); 322 irqfd_deactivate(irqfd);
323 }
276 } 324 }
277 325
278 spin_unlock_irq(&kvm->irqfds.lock); 326 spin_unlock_irq(&kvm->irqfds.lock);
@@ -322,6 +370,25 @@ kvm_irqfd_release(struct kvm *kvm)
322} 370}
323 371
324/* 372/*
373 * Change irq_routing and irqfd.
374 * Caller must invoke synchronize_rcu afterwards.
375 */
376void kvm_irq_routing_update(struct kvm *kvm,
377 struct kvm_irq_routing_table *irq_rt)
378{
379 struct _irqfd *irqfd;
380
381 spin_lock_irq(&kvm->irqfds.lock);
382
383 rcu_assign_pointer(kvm->irq_routing, irq_rt);
384
385 list_for_each_entry(irqfd, &kvm->irqfds.items, list)
386 irqfd_update(kvm, irqfd, irq_rt);
387
388 spin_unlock_irq(&kvm->irqfds.lock);
389}
390
391/*
325 * create a host-wide workqueue for issuing deferred shutdown requests 392 * create a host-wide workqueue for issuing deferred shutdown requests
326 * aggregated from all vm* instances. We need our own isolated single-thread 393 * aggregated from all vm* instances. We need our own isolated single-thread
327 * queue to prevent deadlock against flushing the normal work-queue. 394 * queue to prevent deadlock against flushing the normal work-queue.
diff --git a/virt/kvm/irq_comm.c b/virt/kvm/irq_comm.c
index 8edca9141b78..9f614b4e365f 100644
--- a/virt/kvm/irq_comm.c
+++ b/virt/kvm/irq_comm.c
@@ -114,8 +114,8 @@ int kvm_irq_delivery_to_apic(struct kvm *kvm, struct kvm_lapic *src,
114 return r; 114 return r;
115} 115}
116 116
117static int kvm_set_msi(struct kvm_kernel_irq_routing_entry *e, 117int kvm_set_msi(struct kvm_kernel_irq_routing_entry *e,
118 struct kvm *kvm, int irq_source_id, int level) 118 struct kvm *kvm, int irq_source_id, int level)
119{ 119{
120 struct kvm_lapic_irq irq; 120 struct kvm_lapic_irq irq;
121 121
@@ -409,8 +409,9 @@ int kvm_set_irq_routing(struct kvm *kvm,
409 409
410 mutex_lock(&kvm->irq_lock); 410 mutex_lock(&kvm->irq_lock);
411 old = kvm->irq_routing; 411 old = kvm->irq_routing;
412 rcu_assign_pointer(kvm->irq_routing, new); 412 kvm_irq_routing_update(kvm, new);
413 mutex_unlock(&kvm->irq_lock); 413 mutex_unlock(&kvm->irq_lock);
414
414 synchronize_rcu(); 415 synchronize_rcu();
415 416
416 new = old; 417 new = old;
diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
index 5225052aebc1..7f686251f711 100644
--- a/virt/kvm/kvm_main.c
+++ b/virt/kvm/kvm_main.c
@@ -55,6 +55,7 @@
55#include <asm-generic/bitops/le.h> 55#include <asm-generic/bitops/le.h>
56 56
57#include "coalesced_mmio.h" 57#include "coalesced_mmio.h"
58#include "async_pf.h"
58 59
59#define CREATE_TRACE_POINTS 60#define CREATE_TRACE_POINTS
60#include <trace/events/kvm.h> 61#include <trace/events/kvm.h>
@@ -89,7 +90,8 @@ static void hardware_disable_all(void);
89 90
90static void kvm_io_bus_destroy(struct kvm_io_bus *bus); 91static void kvm_io_bus_destroy(struct kvm_io_bus *bus);
91 92
92static bool kvm_rebooting; 93bool kvm_rebooting;
94EXPORT_SYMBOL_GPL(kvm_rebooting);
93 95
94static bool largepages_enabled = true; 96static bool largepages_enabled = true;
95 97
@@ -167,8 +169,12 @@ static bool make_all_cpus_request(struct kvm *kvm, unsigned int req)
167 169
168void kvm_flush_remote_tlbs(struct kvm *kvm) 170void kvm_flush_remote_tlbs(struct kvm *kvm)
169{ 171{
172 int dirty_count = kvm->tlbs_dirty;
173
174 smp_mb();
170 if (make_all_cpus_request(kvm, KVM_REQ_TLB_FLUSH)) 175 if (make_all_cpus_request(kvm, KVM_REQ_TLB_FLUSH))
171 ++kvm->stat.remote_tlb_flush; 176 ++kvm->stat.remote_tlb_flush;
177 cmpxchg(&kvm->tlbs_dirty, dirty_count, 0);
172} 178}
173 179
174void kvm_reload_remote_mmus(struct kvm *kvm) 180void kvm_reload_remote_mmus(struct kvm *kvm)
@@ -186,6 +192,7 @@ int kvm_vcpu_init(struct kvm_vcpu *vcpu, struct kvm *kvm, unsigned id)
186 vcpu->kvm = kvm; 192 vcpu->kvm = kvm;
187 vcpu->vcpu_id = id; 193 vcpu->vcpu_id = id;
188 init_waitqueue_head(&vcpu->wq); 194 init_waitqueue_head(&vcpu->wq);
195 kvm_async_pf_vcpu_init(vcpu);
189 196
190 page = alloc_page(GFP_KERNEL | __GFP_ZERO); 197 page = alloc_page(GFP_KERNEL | __GFP_ZERO);
191 if (!page) { 198 if (!page) {
@@ -247,7 +254,7 @@ static void kvm_mmu_notifier_invalidate_page(struct mmu_notifier *mn,
247 idx = srcu_read_lock(&kvm->srcu); 254 idx = srcu_read_lock(&kvm->srcu);
248 spin_lock(&kvm->mmu_lock); 255 spin_lock(&kvm->mmu_lock);
249 kvm->mmu_notifier_seq++; 256 kvm->mmu_notifier_seq++;
250 need_tlb_flush = kvm_unmap_hva(kvm, address); 257 need_tlb_flush = kvm_unmap_hva(kvm, address) | kvm->tlbs_dirty;
251 spin_unlock(&kvm->mmu_lock); 258 spin_unlock(&kvm->mmu_lock);
252 srcu_read_unlock(&kvm->srcu, idx); 259 srcu_read_unlock(&kvm->srcu, idx);
253 260
@@ -291,6 +298,7 @@ static void kvm_mmu_notifier_invalidate_range_start(struct mmu_notifier *mn,
291 kvm->mmu_notifier_count++; 298 kvm->mmu_notifier_count++;
292 for (; start < end; start += PAGE_SIZE) 299 for (; start < end; start += PAGE_SIZE)
293 need_tlb_flush |= kvm_unmap_hva(kvm, start); 300 need_tlb_flush |= kvm_unmap_hva(kvm, start);
301 need_tlb_flush |= kvm->tlbs_dirty;
294 spin_unlock(&kvm->mmu_lock); 302 spin_unlock(&kvm->mmu_lock);
295 srcu_read_unlock(&kvm->srcu, idx); 303 srcu_read_unlock(&kvm->srcu, idx);
296 304
@@ -381,11 +389,15 @@ static int kvm_init_mmu_notifier(struct kvm *kvm)
381 389
382static struct kvm *kvm_create_vm(void) 390static struct kvm *kvm_create_vm(void)
383{ 391{
384 int r = 0, i; 392 int r, i;
385 struct kvm *kvm = kvm_arch_create_vm(); 393 struct kvm *kvm = kvm_arch_alloc_vm();
386 394
387 if (IS_ERR(kvm)) 395 if (!kvm)
388 goto out; 396 return ERR_PTR(-ENOMEM);
397
398 r = kvm_arch_init_vm(kvm);
399 if (r)
400 goto out_err_nodisable;
389 401
390 r = hardware_enable_all(); 402 r = hardware_enable_all();
391 if (r) 403 if (r)
@@ -399,23 +411,19 @@ static struct kvm *kvm_create_vm(void)
399 r = -ENOMEM; 411 r = -ENOMEM;
400 kvm->memslots = kzalloc(sizeof(struct kvm_memslots), GFP_KERNEL); 412 kvm->memslots = kzalloc(sizeof(struct kvm_memslots), GFP_KERNEL);
401 if (!kvm->memslots) 413 if (!kvm->memslots)
402 goto out_err; 414 goto out_err_nosrcu;
403 if (init_srcu_struct(&kvm->srcu)) 415 if (init_srcu_struct(&kvm->srcu))
404 goto out_err; 416 goto out_err_nosrcu;
405 for (i = 0; i < KVM_NR_BUSES; i++) { 417 for (i = 0; i < KVM_NR_BUSES; i++) {
406 kvm->buses[i] = kzalloc(sizeof(struct kvm_io_bus), 418 kvm->buses[i] = kzalloc(sizeof(struct kvm_io_bus),
407 GFP_KERNEL); 419 GFP_KERNEL);
408 if (!kvm->buses[i]) { 420 if (!kvm->buses[i])
409 cleanup_srcu_struct(&kvm->srcu);
410 goto out_err; 421 goto out_err;
411 }
412 } 422 }
413 423
414 r = kvm_init_mmu_notifier(kvm); 424 r = kvm_init_mmu_notifier(kvm);
415 if (r) { 425 if (r)
416 cleanup_srcu_struct(&kvm->srcu);
417 goto out_err; 426 goto out_err;
418 }
419 427
420 kvm->mm = current->mm; 428 kvm->mm = current->mm;
421 atomic_inc(&kvm->mm->mm_count); 429 atomic_inc(&kvm->mm->mm_count);
@@ -429,19 +437,35 @@ static struct kvm *kvm_create_vm(void)
429 spin_lock(&kvm_lock); 437 spin_lock(&kvm_lock);
430 list_add(&kvm->vm_list, &vm_list); 438 list_add(&kvm->vm_list, &vm_list);
431 spin_unlock(&kvm_lock); 439 spin_unlock(&kvm_lock);
432out: 440
433 return kvm; 441 return kvm;
434 442
435out_err: 443out_err:
444 cleanup_srcu_struct(&kvm->srcu);
445out_err_nosrcu:
436 hardware_disable_all(); 446 hardware_disable_all();
437out_err_nodisable: 447out_err_nodisable:
438 for (i = 0; i < KVM_NR_BUSES; i++) 448 for (i = 0; i < KVM_NR_BUSES; i++)
439 kfree(kvm->buses[i]); 449 kfree(kvm->buses[i]);
440 kfree(kvm->memslots); 450 kfree(kvm->memslots);
441 kfree(kvm); 451 kvm_arch_free_vm(kvm);
442 return ERR_PTR(r); 452 return ERR_PTR(r);
443} 453}
444 454
455static void kvm_destroy_dirty_bitmap(struct kvm_memory_slot *memslot)
456{
457 if (!memslot->dirty_bitmap)
458 return;
459
460 if (2 * kvm_dirty_bitmap_bytes(memslot) > PAGE_SIZE)
461 vfree(memslot->dirty_bitmap_head);
462 else
463 kfree(memslot->dirty_bitmap_head);
464
465 memslot->dirty_bitmap = NULL;
466 memslot->dirty_bitmap_head = NULL;
467}
468
445/* 469/*
446 * Free any memory in @free but not in @dont. 470 * Free any memory in @free but not in @dont.
447 */ 471 */
@@ -454,7 +478,7 @@ static void kvm_free_physmem_slot(struct kvm_memory_slot *free,
454 vfree(free->rmap); 478 vfree(free->rmap);
455 479
456 if (!dont || free->dirty_bitmap != dont->dirty_bitmap) 480 if (!dont || free->dirty_bitmap != dont->dirty_bitmap)
457 vfree(free->dirty_bitmap); 481 kvm_destroy_dirty_bitmap(free);
458 482
459 483
460 for (i = 0; i < KVM_NR_PAGE_SIZES - 1; ++i) { 484 for (i = 0; i < KVM_NR_PAGE_SIZES - 1; ++i) {
@@ -465,7 +489,6 @@ static void kvm_free_physmem_slot(struct kvm_memory_slot *free,
465 } 489 }
466 490
467 free->npages = 0; 491 free->npages = 0;
468 free->dirty_bitmap = NULL;
469 free->rmap = NULL; 492 free->rmap = NULL;
470} 493}
471 494
@@ -499,6 +522,9 @@ static void kvm_destroy_vm(struct kvm *kvm)
499 kvm_arch_flush_shadow(kvm); 522 kvm_arch_flush_shadow(kvm);
500#endif 523#endif
501 kvm_arch_destroy_vm(kvm); 524 kvm_arch_destroy_vm(kvm);
525 kvm_free_physmem(kvm);
526 cleanup_srcu_struct(&kvm->srcu);
527 kvm_arch_free_vm(kvm);
502 hardware_disable_all(); 528 hardware_disable_all();
503 mmdrop(mm); 529 mmdrop(mm);
504} 530}
@@ -528,6 +554,27 @@ static int kvm_vm_release(struct inode *inode, struct file *filp)
528} 554}
529 555
530/* 556/*
557 * Allocation size is twice as large as the actual dirty bitmap size.
558 * This makes it possible to do double buffering: see x86's
559 * kvm_vm_ioctl_get_dirty_log().
560 */
561static int kvm_create_dirty_bitmap(struct kvm_memory_slot *memslot)
562{
563 unsigned long dirty_bytes = 2 * kvm_dirty_bitmap_bytes(memslot);
564
565 if (dirty_bytes > PAGE_SIZE)
566 memslot->dirty_bitmap = vzalloc(dirty_bytes);
567 else
568 memslot->dirty_bitmap = kzalloc(dirty_bytes, GFP_KERNEL);
569
570 if (!memslot->dirty_bitmap)
571 return -ENOMEM;
572
573 memslot->dirty_bitmap_head = memslot->dirty_bitmap;
574 return 0;
575}
576
577/*
531 * Allocate some memory and give it an address in the guest physical address 578 * Allocate some memory and give it an address in the guest physical address
532 * space. 579 * space.
533 * 580 *
@@ -604,13 +651,11 @@ int __kvm_set_memory_region(struct kvm *kvm,
604 /* Allocate if a slot is being created */ 651 /* Allocate if a slot is being created */
605#ifndef CONFIG_S390 652#ifndef CONFIG_S390
606 if (npages && !new.rmap) { 653 if (npages && !new.rmap) {
607 new.rmap = vmalloc(npages * sizeof(*new.rmap)); 654 new.rmap = vzalloc(npages * sizeof(*new.rmap));
608 655
609 if (!new.rmap) 656 if (!new.rmap)
610 goto out_free; 657 goto out_free;
611 658
612 memset(new.rmap, 0, npages * sizeof(*new.rmap));
613
614 new.user_alloc = user_alloc; 659 new.user_alloc = user_alloc;
615 new.userspace_addr = mem->userspace_addr; 660 new.userspace_addr = mem->userspace_addr;
616 } 661 }
@@ -633,14 +678,11 @@ int __kvm_set_memory_region(struct kvm *kvm,
633 >> KVM_HPAGE_GFN_SHIFT(level)); 678 >> KVM_HPAGE_GFN_SHIFT(level));
634 lpages -= base_gfn >> KVM_HPAGE_GFN_SHIFT(level); 679 lpages -= base_gfn >> KVM_HPAGE_GFN_SHIFT(level);
635 680
636 new.lpage_info[i] = vmalloc(lpages * sizeof(*new.lpage_info[i])); 681 new.lpage_info[i] = vzalloc(lpages * sizeof(*new.lpage_info[i]));
637 682
638 if (!new.lpage_info[i]) 683 if (!new.lpage_info[i])
639 goto out_free; 684 goto out_free;
640 685
641 memset(new.lpage_info[i], 0,
642 lpages * sizeof(*new.lpage_info[i]));
643
644 if (base_gfn & (KVM_PAGES_PER_HPAGE(level) - 1)) 686 if (base_gfn & (KVM_PAGES_PER_HPAGE(level) - 1))
645 new.lpage_info[i][0].write_count = 1; 687 new.lpage_info[i][0].write_count = 1;
646 if ((base_gfn+npages) & (KVM_PAGES_PER_HPAGE(level) - 1)) 688 if ((base_gfn+npages) & (KVM_PAGES_PER_HPAGE(level) - 1))
@@ -661,12 +703,8 @@ skip_lpage:
661 703
662 /* Allocate page dirty bitmap if needed */ 704 /* Allocate page dirty bitmap if needed */
663 if ((new.flags & KVM_MEM_LOG_DIRTY_PAGES) && !new.dirty_bitmap) { 705 if ((new.flags & KVM_MEM_LOG_DIRTY_PAGES) && !new.dirty_bitmap) {
664 unsigned long dirty_bytes = kvm_dirty_bitmap_bytes(&new); 706 if (kvm_create_dirty_bitmap(&new) < 0)
665
666 new.dirty_bitmap = vmalloc(dirty_bytes);
667 if (!new.dirty_bitmap)
668 goto out_free; 707 goto out_free;
669 memset(new.dirty_bitmap, 0, dirty_bytes);
670 /* destroy any largepage mappings for dirty tracking */ 708 /* destroy any largepage mappings for dirty tracking */
671 if (old.npages) 709 if (old.npages)
672 flush_shadow = 1; 710 flush_shadow = 1;
@@ -685,6 +723,7 @@ skip_lpage:
685 memcpy(slots, kvm->memslots, sizeof(struct kvm_memslots)); 723 memcpy(slots, kvm->memslots, sizeof(struct kvm_memslots));
686 if (mem->slot >= slots->nmemslots) 724 if (mem->slot >= slots->nmemslots)
687 slots->nmemslots = mem->slot + 1; 725 slots->nmemslots = mem->slot + 1;
726 slots->generation++;
688 slots->memslots[mem->slot].flags |= KVM_MEMSLOT_INVALID; 727 slots->memslots[mem->slot].flags |= KVM_MEMSLOT_INVALID;
689 728
690 old_memslots = kvm->memslots; 729 old_memslots = kvm->memslots;
@@ -719,6 +758,7 @@ skip_lpage:
719 memcpy(slots, kvm->memslots, sizeof(struct kvm_memslots)); 758 memcpy(slots, kvm->memslots, sizeof(struct kvm_memslots));
720 if (mem->slot >= slots->nmemslots) 759 if (mem->slot >= slots->nmemslots)
721 slots->nmemslots = mem->slot + 1; 760 slots->nmemslots = mem->slot + 1;
761 slots->generation++;
722 762
723 /* actual memory is freed via old in kvm_free_physmem_slot below */ 763 /* actual memory is freed via old in kvm_free_physmem_slot below */
724 if (!npages) { 764 if (!npages) {
@@ -849,10 +889,10 @@ int kvm_is_error_hva(unsigned long addr)
849} 889}
850EXPORT_SYMBOL_GPL(kvm_is_error_hva); 890EXPORT_SYMBOL_GPL(kvm_is_error_hva);
851 891
852struct kvm_memory_slot *gfn_to_memslot(struct kvm *kvm, gfn_t gfn) 892static struct kvm_memory_slot *__gfn_to_memslot(struct kvm_memslots *slots,
893 gfn_t gfn)
853{ 894{
854 int i; 895 int i;
855 struct kvm_memslots *slots = kvm_memslots(kvm);
856 896
857 for (i = 0; i < slots->nmemslots; ++i) { 897 for (i = 0; i < slots->nmemslots; ++i) {
858 struct kvm_memory_slot *memslot = &slots->memslots[i]; 898 struct kvm_memory_slot *memslot = &slots->memslots[i];
@@ -863,6 +903,11 @@ struct kvm_memory_slot *gfn_to_memslot(struct kvm *kvm, gfn_t gfn)
863 } 903 }
864 return NULL; 904 return NULL;
865} 905}
906
907struct kvm_memory_slot *gfn_to_memslot(struct kvm *kvm, gfn_t gfn)
908{
909 return __gfn_to_memslot(kvm_memslots(kvm), gfn);
910}
866EXPORT_SYMBOL_GPL(gfn_to_memslot); 911EXPORT_SYMBOL_GPL(gfn_to_memslot);
867 912
868int kvm_is_visible_gfn(struct kvm *kvm, gfn_t gfn) 913int kvm_is_visible_gfn(struct kvm *kvm, gfn_t gfn)
@@ -925,12 +970,9 @@ int memslot_id(struct kvm *kvm, gfn_t gfn)
925 return memslot - slots->memslots; 970 return memslot - slots->memslots;
926} 971}
927 972
928static unsigned long gfn_to_hva_many(struct kvm *kvm, gfn_t gfn, 973static unsigned long gfn_to_hva_many(struct kvm_memory_slot *slot, gfn_t gfn,
929 gfn_t *nr_pages) 974 gfn_t *nr_pages)
930{ 975{
931 struct kvm_memory_slot *slot;
932
933 slot = gfn_to_memslot(kvm, gfn);
934 if (!slot || slot->flags & KVM_MEMSLOT_INVALID) 976 if (!slot || slot->flags & KVM_MEMSLOT_INVALID)
935 return bad_hva(); 977 return bad_hva();
936 978
@@ -942,28 +984,61 @@ static unsigned long gfn_to_hva_many(struct kvm *kvm, gfn_t gfn,
942 984
943unsigned long gfn_to_hva(struct kvm *kvm, gfn_t gfn) 985unsigned long gfn_to_hva(struct kvm *kvm, gfn_t gfn)
944{ 986{
945 return gfn_to_hva_many(kvm, gfn, NULL); 987 return gfn_to_hva_many(gfn_to_memslot(kvm, gfn), gfn, NULL);
946} 988}
947EXPORT_SYMBOL_GPL(gfn_to_hva); 989EXPORT_SYMBOL_GPL(gfn_to_hva);
948 990
949static pfn_t hva_to_pfn(struct kvm *kvm, unsigned long addr, bool atomic) 991static pfn_t get_fault_pfn(void)
992{
993 get_page(fault_page);
994 return fault_pfn;
995}
996
997static pfn_t hva_to_pfn(struct kvm *kvm, unsigned long addr, bool atomic,
998 bool *async, bool write_fault, bool *writable)
950{ 999{
951 struct page *page[1]; 1000 struct page *page[1];
952 int npages; 1001 int npages = 0;
953 pfn_t pfn; 1002 pfn_t pfn;
954 1003
955 if (atomic) 1004 /* we can do it either atomically or asynchronously, not both */
1005 BUG_ON(atomic && async);
1006
1007 BUG_ON(!write_fault && !writable);
1008
1009 if (writable)
1010 *writable = true;
1011
1012 if (atomic || async)
956 npages = __get_user_pages_fast(addr, 1, 1, page); 1013 npages = __get_user_pages_fast(addr, 1, 1, page);
957 else { 1014
1015 if (unlikely(npages != 1) && !atomic) {
958 might_sleep(); 1016 might_sleep();
959 npages = get_user_pages_fast(addr, 1, 1, page); 1017
1018 if (writable)
1019 *writable = write_fault;
1020
1021 npages = get_user_pages_fast(addr, 1, write_fault, page);
1022
1023 /* map read fault as writable if possible */
1024 if (unlikely(!write_fault) && npages == 1) {
1025 struct page *wpage[1];
1026
1027 npages = __get_user_pages_fast(addr, 1, 1, wpage);
1028 if (npages == 1) {
1029 *writable = true;
1030 put_page(page[0]);
1031 page[0] = wpage[0];
1032 }
1033 npages = 1;
1034 }
960 } 1035 }
961 1036
962 if (unlikely(npages != 1)) { 1037 if (unlikely(npages != 1)) {
963 struct vm_area_struct *vma; 1038 struct vm_area_struct *vma;
964 1039
965 if (atomic) 1040 if (atomic)
966 goto return_fault_page; 1041 return get_fault_pfn();
967 1042
968 down_read(&current->mm->mmap_sem); 1043 down_read(&current->mm->mmap_sem);
969 if (is_hwpoison_address(addr)) { 1044 if (is_hwpoison_address(addr)) {
@@ -972,19 +1047,20 @@ static pfn_t hva_to_pfn(struct kvm *kvm, unsigned long addr, bool atomic)
972 return page_to_pfn(hwpoison_page); 1047 return page_to_pfn(hwpoison_page);
973 } 1048 }
974 1049
975 vma = find_vma(current->mm, addr); 1050 vma = find_vma_intersection(current->mm, addr, addr+1);
976 1051
977 if (vma == NULL || addr < vma->vm_start || 1052 if (vma == NULL)
978 !(vma->vm_flags & VM_PFNMAP)) { 1053 pfn = get_fault_pfn();
979 up_read(&current->mm->mmap_sem); 1054 else if ((vma->vm_flags & VM_PFNMAP)) {
980return_fault_page: 1055 pfn = ((addr - vma->vm_start) >> PAGE_SHIFT) +
981 get_page(fault_page); 1056 vma->vm_pgoff;
982 return page_to_pfn(fault_page); 1057 BUG_ON(!kvm_is_mmio_pfn(pfn));
1058 } else {
1059 if (async && (vma->vm_flags & VM_WRITE))
1060 *async = true;
1061 pfn = get_fault_pfn();
983 } 1062 }
984
985 pfn = ((addr - vma->vm_start) >> PAGE_SHIFT) + vma->vm_pgoff;
986 up_read(&current->mm->mmap_sem); 1063 up_read(&current->mm->mmap_sem);
987 BUG_ON(!kvm_is_mmio_pfn(pfn));
988 } else 1064 } else
989 pfn = page_to_pfn(page[0]); 1065 pfn = page_to_pfn(page[0]);
990 1066
@@ -993,40 +1069,58 @@ return_fault_page:
993 1069
994pfn_t hva_to_pfn_atomic(struct kvm *kvm, unsigned long addr) 1070pfn_t hva_to_pfn_atomic(struct kvm *kvm, unsigned long addr)
995{ 1071{
996 return hva_to_pfn(kvm, addr, true); 1072 return hva_to_pfn(kvm, addr, true, NULL, true, NULL);
997} 1073}
998EXPORT_SYMBOL_GPL(hva_to_pfn_atomic); 1074EXPORT_SYMBOL_GPL(hva_to_pfn_atomic);
999 1075
1000static pfn_t __gfn_to_pfn(struct kvm *kvm, gfn_t gfn, bool atomic) 1076static pfn_t __gfn_to_pfn(struct kvm *kvm, gfn_t gfn, bool atomic, bool *async,
1077 bool write_fault, bool *writable)
1001{ 1078{
1002 unsigned long addr; 1079 unsigned long addr;
1003 1080
1081 if (async)
1082 *async = false;
1083
1004 addr = gfn_to_hva(kvm, gfn); 1084 addr = gfn_to_hva(kvm, gfn);
1005 if (kvm_is_error_hva(addr)) { 1085 if (kvm_is_error_hva(addr)) {
1006 get_page(bad_page); 1086 get_page(bad_page);
1007 return page_to_pfn(bad_page); 1087 return page_to_pfn(bad_page);
1008 } 1088 }
1009 1089
1010 return hva_to_pfn(kvm, addr, atomic); 1090 return hva_to_pfn(kvm, addr, atomic, async, write_fault, writable);
1011} 1091}
1012 1092
1013pfn_t gfn_to_pfn_atomic(struct kvm *kvm, gfn_t gfn) 1093pfn_t gfn_to_pfn_atomic(struct kvm *kvm, gfn_t gfn)
1014{ 1094{
1015 return __gfn_to_pfn(kvm, gfn, true); 1095 return __gfn_to_pfn(kvm, gfn, true, NULL, true, NULL);
1016} 1096}
1017EXPORT_SYMBOL_GPL(gfn_to_pfn_atomic); 1097EXPORT_SYMBOL_GPL(gfn_to_pfn_atomic);
1018 1098
1099pfn_t gfn_to_pfn_async(struct kvm *kvm, gfn_t gfn, bool *async,
1100 bool write_fault, bool *writable)
1101{
1102 return __gfn_to_pfn(kvm, gfn, false, async, write_fault, writable);
1103}
1104EXPORT_SYMBOL_GPL(gfn_to_pfn_async);
1105
1019pfn_t gfn_to_pfn(struct kvm *kvm, gfn_t gfn) 1106pfn_t gfn_to_pfn(struct kvm *kvm, gfn_t gfn)
1020{ 1107{
1021 return __gfn_to_pfn(kvm, gfn, false); 1108 return __gfn_to_pfn(kvm, gfn, false, NULL, true, NULL);
1022} 1109}
1023EXPORT_SYMBOL_GPL(gfn_to_pfn); 1110EXPORT_SYMBOL_GPL(gfn_to_pfn);
1024 1111
1112pfn_t gfn_to_pfn_prot(struct kvm *kvm, gfn_t gfn, bool write_fault,
1113 bool *writable)
1114{
1115 return __gfn_to_pfn(kvm, gfn, false, NULL, write_fault, writable);
1116}
1117EXPORT_SYMBOL_GPL(gfn_to_pfn_prot);
1118
1025pfn_t gfn_to_pfn_memslot(struct kvm *kvm, 1119pfn_t gfn_to_pfn_memslot(struct kvm *kvm,
1026 struct kvm_memory_slot *slot, gfn_t gfn) 1120 struct kvm_memory_slot *slot, gfn_t gfn)
1027{ 1121{
1028 unsigned long addr = gfn_to_hva_memslot(slot, gfn); 1122 unsigned long addr = gfn_to_hva_memslot(slot, gfn);
1029 return hva_to_pfn(kvm, addr, false); 1123 return hva_to_pfn(kvm, addr, false, NULL, true, NULL);
1030} 1124}
1031 1125
1032int gfn_to_page_many_atomic(struct kvm *kvm, gfn_t gfn, struct page **pages, 1126int gfn_to_page_many_atomic(struct kvm *kvm, gfn_t gfn, struct page **pages,
@@ -1035,7 +1129,7 @@ int gfn_to_page_many_atomic(struct kvm *kvm, gfn_t gfn, struct page **pages,
1035 unsigned long addr; 1129 unsigned long addr;
1036 gfn_t entry; 1130 gfn_t entry;
1037 1131
1038 addr = gfn_to_hva_many(kvm, gfn, &entry); 1132 addr = gfn_to_hva_many(gfn_to_memslot(kvm, gfn), gfn, &entry);
1039 if (kvm_is_error_hva(addr)) 1133 if (kvm_is_error_hva(addr))
1040 return -1; 1134 return -1;
1041 1135
@@ -1219,9 +1313,51 @@ int kvm_write_guest(struct kvm *kvm, gpa_t gpa, const void *data,
1219 return 0; 1313 return 0;
1220} 1314}
1221 1315
1316int kvm_gfn_to_hva_cache_init(struct kvm *kvm, struct gfn_to_hva_cache *ghc,
1317 gpa_t gpa)
1318{
1319 struct kvm_memslots *slots = kvm_memslots(kvm);
1320 int offset = offset_in_page(gpa);
1321 gfn_t gfn = gpa >> PAGE_SHIFT;
1322
1323 ghc->gpa = gpa;
1324 ghc->generation = slots->generation;
1325 ghc->memslot = __gfn_to_memslot(slots, gfn);
1326 ghc->hva = gfn_to_hva_many(ghc->memslot, gfn, NULL);
1327 if (!kvm_is_error_hva(ghc->hva))
1328 ghc->hva += offset;
1329 else
1330 return -EFAULT;
1331
1332 return 0;
1333}
1334EXPORT_SYMBOL_GPL(kvm_gfn_to_hva_cache_init);
1335
1336int kvm_write_guest_cached(struct kvm *kvm, struct gfn_to_hva_cache *ghc,
1337 void *data, unsigned long len)
1338{
1339 struct kvm_memslots *slots = kvm_memslots(kvm);
1340 int r;
1341
1342 if (slots->generation != ghc->generation)
1343 kvm_gfn_to_hva_cache_init(kvm, ghc, ghc->gpa);
1344
1345 if (kvm_is_error_hva(ghc->hva))
1346 return -EFAULT;
1347
1348 r = copy_to_user((void __user *)ghc->hva, data, len);
1349 if (r)
1350 return -EFAULT;
1351 mark_page_dirty_in_slot(kvm, ghc->memslot, ghc->gpa >> PAGE_SHIFT);
1352
1353 return 0;
1354}
1355EXPORT_SYMBOL_GPL(kvm_write_guest_cached);
1356
1222int kvm_clear_guest_page(struct kvm *kvm, gfn_t gfn, int offset, int len) 1357int kvm_clear_guest_page(struct kvm *kvm, gfn_t gfn, int offset, int len)
1223{ 1358{
1224 return kvm_write_guest_page(kvm, gfn, empty_zero_page, offset, len); 1359 return kvm_write_guest_page(kvm, gfn, (const void *) empty_zero_page,
1360 offset, len);
1225} 1361}
1226EXPORT_SYMBOL_GPL(kvm_clear_guest_page); 1362EXPORT_SYMBOL_GPL(kvm_clear_guest_page);
1227 1363
@@ -1244,11 +1380,9 @@ int kvm_clear_guest(struct kvm *kvm, gpa_t gpa, unsigned long len)
1244} 1380}
1245EXPORT_SYMBOL_GPL(kvm_clear_guest); 1381EXPORT_SYMBOL_GPL(kvm_clear_guest);
1246 1382
1247void mark_page_dirty(struct kvm *kvm, gfn_t gfn) 1383void mark_page_dirty_in_slot(struct kvm *kvm, struct kvm_memory_slot *memslot,
1384 gfn_t gfn)
1248{ 1385{
1249 struct kvm_memory_slot *memslot;
1250
1251 memslot = gfn_to_memslot(kvm, gfn);
1252 if (memslot && memslot->dirty_bitmap) { 1386 if (memslot && memslot->dirty_bitmap) {
1253 unsigned long rel_gfn = gfn - memslot->base_gfn; 1387 unsigned long rel_gfn = gfn - memslot->base_gfn;
1254 1388
@@ -1256,6 +1390,14 @@ void mark_page_dirty(struct kvm *kvm, gfn_t gfn)
1256 } 1390 }
1257} 1391}
1258 1392
1393void mark_page_dirty(struct kvm *kvm, gfn_t gfn)
1394{
1395 struct kvm_memory_slot *memslot;
1396
1397 memslot = gfn_to_memslot(kvm, gfn);
1398 mark_page_dirty_in_slot(kvm, memslot, gfn);
1399}
1400
1259/* 1401/*
1260 * The vCPU has executed a HLT instruction with in-kernel mode enabled. 1402 * The vCPU has executed a HLT instruction with in-kernel mode enabled.
1261 */ 1403 */
@@ -1457,6 +1599,7 @@ static long kvm_vcpu_ioctl(struct file *filp,
1457 if (arg) 1599 if (arg)
1458 goto out; 1600 goto out;
1459 r = kvm_arch_vcpu_ioctl_run(vcpu, vcpu->run); 1601 r = kvm_arch_vcpu_ioctl_run(vcpu, vcpu->run);
1602 trace_kvm_userspace_exit(vcpu->run->exit_reason, r);
1460 break; 1603 break;
1461 case KVM_GET_REGS: { 1604 case KVM_GET_REGS: {
1462 struct kvm_regs *kvm_regs; 1605 struct kvm_regs *kvm_regs;
@@ -1824,7 +1967,7 @@ static struct file_operations kvm_vm_fops = {
1824 1967
1825static int kvm_dev_ioctl_create_vm(void) 1968static int kvm_dev_ioctl_create_vm(void)
1826{ 1969{
1827 int fd, r; 1970 int r;
1828 struct kvm *kvm; 1971 struct kvm *kvm;
1829 1972
1830 kvm = kvm_create_vm(); 1973 kvm = kvm_create_vm();
@@ -1837,11 +1980,11 @@ static int kvm_dev_ioctl_create_vm(void)
1837 return r; 1980 return r;
1838 } 1981 }
1839#endif 1982#endif
1840 fd = anon_inode_getfd("kvm-vm", &kvm_vm_fops, kvm, O_RDWR); 1983 r = anon_inode_getfd("kvm-vm", &kvm_vm_fops, kvm, O_RDWR);
1841 if (fd < 0) 1984 if (r < 0)
1842 kvm_put_kvm(kvm); 1985 kvm_put_kvm(kvm);
1843 1986
1844 return fd; 1987 return r;
1845} 1988}
1846 1989
1847static long kvm_dev_ioctl_check_extension_generic(long arg) 1990static long kvm_dev_ioctl_check_extension_generic(long arg)
@@ -1922,7 +2065,7 @@ static struct miscdevice kvm_dev = {
1922 &kvm_chardev_ops, 2065 &kvm_chardev_ops,
1923}; 2066};
1924 2067
1925static void hardware_enable(void *junk) 2068static void hardware_enable_nolock(void *junk)
1926{ 2069{
1927 int cpu = raw_smp_processor_id(); 2070 int cpu = raw_smp_processor_id();
1928 int r; 2071 int r;
@@ -1942,7 +2085,14 @@ static void hardware_enable(void *junk)
1942 } 2085 }
1943} 2086}
1944 2087
1945static void hardware_disable(void *junk) 2088static void hardware_enable(void *junk)
2089{
2090 spin_lock(&kvm_lock);
2091 hardware_enable_nolock(junk);
2092 spin_unlock(&kvm_lock);
2093}
2094
2095static void hardware_disable_nolock(void *junk)
1946{ 2096{
1947 int cpu = raw_smp_processor_id(); 2097 int cpu = raw_smp_processor_id();
1948 2098
@@ -1952,13 +2102,20 @@ static void hardware_disable(void *junk)
1952 kvm_arch_hardware_disable(NULL); 2102 kvm_arch_hardware_disable(NULL);
1953} 2103}
1954 2104
2105static void hardware_disable(void *junk)
2106{
2107 spin_lock(&kvm_lock);
2108 hardware_disable_nolock(junk);
2109 spin_unlock(&kvm_lock);
2110}
2111
1955static void hardware_disable_all_nolock(void) 2112static void hardware_disable_all_nolock(void)
1956{ 2113{
1957 BUG_ON(!kvm_usage_count); 2114 BUG_ON(!kvm_usage_count);
1958 2115
1959 kvm_usage_count--; 2116 kvm_usage_count--;
1960 if (!kvm_usage_count) 2117 if (!kvm_usage_count)
1961 on_each_cpu(hardware_disable, NULL, 1); 2118 on_each_cpu(hardware_disable_nolock, NULL, 1);
1962} 2119}
1963 2120
1964static void hardware_disable_all(void) 2121static void hardware_disable_all(void)
@@ -1977,7 +2134,7 @@ static int hardware_enable_all(void)
1977 kvm_usage_count++; 2134 kvm_usage_count++;
1978 if (kvm_usage_count == 1) { 2135 if (kvm_usage_count == 1) {
1979 atomic_set(&hardware_enable_failed, 0); 2136 atomic_set(&hardware_enable_failed, 0);
1980 on_each_cpu(hardware_enable, NULL, 1); 2137 on_each_cpu(hardware_enable_nolock, NULL, 1);
1981 2138
1982 if (atomic_read(&hardware_enable_failed)) { 2139 if (atomic_read(&hardware_enable_failed)) {
1983 hardware_disable_all_nolock(); 2140 hardware_disable_all_nolock();
@@ -2008,27 +2165,19 @@ static int kvm_cpu_hotplug(struct notifier_block *notifier, unsigned long val,
2008 case CPU_STARTING: 2165 case CPU_STARTING:
2009 printk(KERN_INFO "kvm: enabling virtualization on CPU%d\n", 2166 printk(KERN_INFO "kvm: enabling virtualization on CPU%d\n",
2010 cpu); 2167 cpu);
2011 spin_lock(&kvm_lock);
2012 hardware_enable(NULL); 2168 hardware_enable(NULL);
2013 spin_unlock(&kvm_lock);
2014 break; 2169 break;
2015 } 2170 }
2016 return NOTIFY_OK; 2171 return NOTIFY_OK;
2017} 2172}
2018 2173
2019 2174
2020asmlinkage void kvm_handle_fault_on_reboot(void) 2175asmlinkage void kvm_spurious_fault(void)
2021{ 2176{
2022 if (kvm_rebooting) {
2023 /* spin while reset goes on */
2024 local_irq_enable();
2025 while (true)
2026 cpu_relax();
2027 }
2028 /* Fault while not rebooting. We want the trace. */ 2177 /* Fault while not rebooting. We want the trace. */
2029 BUG(); 2178 BUG();
2030} 2179}
2031EXPORT_SYMBOL_GPL(kvm_handle_fault_on_reboot); 2180EXPORT_SYMBOL_GPL(kvm_spurious_fault);
2032 2181
2033static int kvm_reboot(struct notifier_block *notifier, unsigned long val, 2182static int kvm_reboot(struct notifier_block *notifier, unsigned long val,
2034 void *v) 2183 void *v)
@@ -2041,7 +2190,7 @@ static int kvm_reboot(struct notifier_block *notifier, unsigned long val,
2041 */ 2190 */
2042 printk(KERN_INFO "kvm: exiting hardware virtualization\n"); 2191 printk(KERN_INFO "kvm: exiting hardware virtualization\n");
2043 kvm_rebooting = true; 2192 kvm_rebooting = true;
2044 on_each_cpu(hardware_disable, NULL, 1); 2193 on_each_cpu(hardware_disable_nolock, NULL, 1);
2045 return NOTIFY_OK; 2194 return NOTIFY_OK;
2046} 2195}
2047 2196
@@ -2211,7 +2360,7 @@ static void kvm_exit_debug(void)
2211static int kvm_suspend(struct sys_device *dev, pm_message_t state) 2360static int kvm_suspend(struct sys_device *dev, pm_message_t state)
2212{ 2361{
2213 if (kvm_usage_count) 2362 if (kvm_usage_count)
2214 hardware_disable(NULL); 2363 hardware_disable_nolock(NULL);
2215 return 0; 2364 return 0;
2216} 2365}
2217 2366
@@ -2219,7 +2368,7 @@ static int kvm_resume(struct sys_device *dev)
2219{ 2368{
2220 if (kvm_usage_count) { 2369 if (kvm_usage_count) {
2221 WARN_ON(spin_is_locked(&kvm_lock)); 2370 WARN_ON(spin_is_locked(&kvm_lock));
2222 hardware_enable(NULL); 2371 hardware_enable_nolock(NULL);
2223 } 2372 }
2224 return 0; 2373 return 0;
2225} 2374}
@@ -2336,6 +2485,10 @@ int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
2336 goto out_free_5; 2485 goto out_free_5;
2337 } 2486 }
2338 2487
2488 r = kvm_async_pf_init();
2489 if (r)
2490 goto out_free;
2491
2339 kvm_chardev_ops.owner = module; 2492 kvm_chardev_ops.owner = module;
2340 kvm_vm_fops.owner = module; 2493 kvm_vm_fops.owner = module;
2341 kvm_vcpu_fops.owner = module; 2494 kvm_vcpu_fops.owner = module;
@@ -2343,7 +2496,7 @@ int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
2343 r = misc_register(&kvm_dev); 2496 r = misc_register(&kvm_dev);
2344 if (r) { 2497 if (r) {
2345 printk(KERN_ERR "kvm: misc device register failed\n"); 2498 printk(KERN_ERR "kvm: misc device register failed\n");
2346 goto out_free; 2499 goto out_unreg;
2347 } 2500 }
2348 2501
2349 kvm_preempt_ops.sched_in = kvm_sched_in; 2502 kvm_preempt_ops.sched_in = kvm_sched_in;
@@ -2353,6 +2506,8 @@ int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
2353 2506
2354 return 0; 2507 return 0;
2355 2508
2509out_unreg:
2510 kvm_async_pf_deinit();
2356out_free: 2511out_free:
2357 kmem_cache_destroy(kvm_vcpu_cache); 2512 kmem_cache_destroy(kvm_vcpu_cache);
2358out_free_5: 2513out_free_5:
@@ -2385,11 +2540,12 @@ void kvm_exit(void)
2385 kvm_exit_debug(); 2540 kvm_exit_debug();
2386 misc_deregister(&kvm_dev); 2541 misc_deregister(&kvm_dev);
2387 kmem_cache_destroy(kvm_vcpu_cache); 2542 kmem_cache_destroy(kvm_vcpu_cache);
2543 kvm_async_pf_deinit();
2388 sysdev_unregister(&kvm_sysdev); 2544 sysdev_unregister(&kvm_sysdev);
2389 sysdev_class_unregister(&kvm_sysdev_class); 2545 sysdev_class_unregister(&kvm_sysdev_class);
2390 unregister_reboot_notifier(&kvm_reboot_notifier); 2546 unregister_reboot_notifier(&kvm_reboot_notifier);
2391 unregister_cpu_notifier(&kvm_cpu_notifier); 2547 unregister_cpu_notifier(&kvm_cpu_notifier);
2392 on_each_cpu(hardware_disable, NULL, 1); 2548 on_each_cpu(hardware_disable_nolock, NULL, 1);
2393 kvm_arch_hardware_unsetup(); 2549 kvm_arch_hardware_unsetup();
2394 kvm_arch_exit(); 2550 kvm_arch_exit();
2395 free_cpumask_var(cpus_hardware_enabled); 2551 free_cpumask_var(cpus_hardware_enabled);